2 * OLE Font encapsulation implementation
4 * This file contains an implementation of the IFont
5 * interface and the OleCreateFontIndirect API call.
7 * Copyright 1999 Francis Beaudet
15 #include "wine/unicode.h"
16 #include "oleauto.h" /* for SysAllocString(....) */
17 #include "wine/obj_olefont.h"
18 #include "wine/obj_storage.h"
21 #include "debugtools.h"
23 #include "connpt.h" /* for CreateConnectionPoint */
25 DEFAULT_DEBUG_CHANNEL(ole);
27 /***********************************************************************
28 * Declaration of constants used when serializing the font object.
30 #define FONTPERSIST_ITALIC 0x02
31 #define FONTPERSIST_UNDERLINE 0x04
32 #define FONTPERSIST_STRIKETHROUGH 0x08
34 /***********************************************************************
35 * Declaration of the implementation class for the IFont interface
37 typedef struct OLEFontImpl OLEFontImpl;
42 * This class supports many interfaces. IUnknown, IFont,
43 * IDispatch, IDispFont IPersistStream and IConnectionPointContainer.
44 * The first two are supported by the first vtable, the next two are
45 * supported by the second table and the last two have their own.
47 ICOM_VTABLE(IFont)* lpvtbl1;
48 ICOM_VTABLE(IDispatch)* lpvtbl2;
49 ICOM_VTABLE(IPersistStream)* lpvtbl3;
50 ICOM_VTABLE(IConnectionPointContainer)* lpvtbl4;
52 * Reference count for that instance of the class.
57 * This structure contains the description of the class.
62 * Contain the font associated with this object.
77 IConnectionPoint *pCP;
81 * Here, I define utility macros to help with the casting of the
83 * There is a version to accomodate all of the VTables implemented
86 #define _ICOM_THIS(class,name) class* this = (class*)name;
87 #define _ICOM_THIS_From_IDispatch(class, name) class* this = (class*)(((char*)name)-sizeof(void*));
88 #define _ICOM_THIS_From_IPersistStream(class, name) class* this = (class*)(((char*)name)-2*sizeof(void*));
89 #define _ICOM_THIS_From_IConnectionPointContainer(class, name) class* this = (class*)(((char*)name)-3*sizeof(void*));
92 /***********************************************************************
93 * Prototypes for the implementation functions for the IFont
96 static OLEFontImpl* OLEFontImpl_Construct(LPFONTDESC fontDesc);
97 static void OLEFontImpl_Destroy(OLEFontImpl* fontDesc);
98 static HRESULT WINAPI OLEFontImpl_QueryInterface(IFont* iface, REFIID riid, VOID** ppvoid);
99 static ULONG WINAPI OLEFontImpl_AddRef(IFont* iface);
100 static ULONG WINAPI OLEFontImpl_Release(IFont* iface);
101 static HRESULT WINAPI OLEFontImpl_get_Name(IFont* iface, BSTR* pname);
102 static HRESULT WINAPI OLEFontImpl_put_Name(IFont* iface, BSTR name);
103 static HRESULT WINAPI OLEFontImpl_get_Size(IFont* iface, CY* psize);
104 static HRESULT WINAPI OLEFontImpl_put_Size(IFont* iface, CY size);
105 static HRESULT WINAPI OLEFontImpl_get_Bold(IFont* iface, BOOL* pbold);
106 static HRESULT WINAPI OLEFontImpl_put_Bold(IFont* iface, BOOL bold);
107 static HRESULT WINAPI OLEFontImpl_get_Italic(IFont* iface, BOOL* pitalic);
108 static HRESULT WINAPI OLEFontImpl_put_Italic(IFont* iface, BOOL italic);
109 static HRESULT WINAPI OLEFontImpl_get_Underline(IFont* iface, BOOL* punderline);
110 static HRESULT WINAPI OLEFontImpl_put_Underline(IFont* iface, BOOL underline);
111 static HRESULT WINAPI OLEFontImpl_get_Strikethrough(IFont* iface, BOOL* pstrikethrough);
112 static HRESULT WINAPI OLEFontImpl_put_Strikethrough(IFont* iface, BOOL strikethrough);
113 static HRESULT WINAPI OLEFontImpl_get_Weight(IFont* iface, short* pweight);
114 static HRESULT WINAPI OLEFontImpl_put_Weight(IFont* iface, short weight);
115 static HRESULT WINAPI OLEFontImpl_get_Charset(IFont* iface, short* pcharset);
116 static HRESULT WINAPI OLEFontImpl_put_Charset(IFont* iface, short charset);
117 static HRESULT WINAPI OLEFontImpl_get_hFont(IFont* iface, HFONT* phfont);
118 static HRESULT WINAPI OLEFontImpl_Clone(IFont* iface, IFont** ppfont);
119 static HRESULT WINAPI OLEFontImpl_IsEqual(IFont* iface, IFont* pFontOther);
120 static HRESULT WINAPI OLEFontImpl_SetRatio(IFont* iface, long cyLogical, long cyHimetric);
121 static HRESULT WINAPI OLEFontImpl_QueryTextMetrics(IFont* iface, TEXTMETRICOLE* ptm);
122 static HRESULT WINAPI OLEFontImpl_AddRefHfont(IFont* iface, HFONT hfont);
123 static HRESULT WINAPI OLEFontImpl_ReleaseHfont(IFont* iface, HFONT hfont);
124 static HRESULT WINAPI OLEFontImpl_SetHdc(IFont* iface, HDC hdc);
126 /***********************************************************************
127 * Prototypes for the implementation functions for the IDispatch
130 static HRESULT WINAPI OLEFontImpl_IDispatch_QueryInterface(IDispatch* iface,
133 static ULONG WINAPI OLEFontImpl_IDispatch_AddRef(IDispatch* iface);
134 static ULONG WINAPI OLEFontImpl_IDispatch_Release(IDispatch* iface);
135 static HRESULT WINAPI OLEFontImpl_GetTypeInfoCount(IDispatch* iface,
136 unsigned int* pctinfo);
137 static HRESULT WINAPI OLEFontImpl_GetTypeInfo(IDispatch* iface,
140 ITypeInfo** ppTInfo);
141 static HRESULT WINAPI OLEFontImpl_GetIDsOfNames(IDispatch* iface,
147 static HRESULT WINAPI OLEFontImpl_Invoke(IDispatch* iface,
152 DISPPARAMS* pDispParams,
154 EXCEPINFO* pExepInfo,
157 /***********************************************************************
158 * Prototypes for the implementation functions for the IPersistStream
161 static HRESULT WINAPI OLEFontImpl_IPersistStream_QueryInterface(IPersistStream* iface,
164 static ULONG WINAPI OLEFontImpl_IPersistStream_AddRef(IPersistStream* iface);
165 static ULONG WINAPI OLEFontImpl_IPersistStream_Release(IPersistStream* iface);
166 static HRESULT WINAPI OLEFontImpl_GetClassID(IPersistStream* iface,
168 static HRESULT WINAPI OLEFontImpl_IsDirty(IPersistStream* iface);
169 static HRESULT WINAPI OLEFontImpl_Load(IPersistStream* iface,
170 IStream* pLoadStream);
171 static HRESULT WINAPI OLEFontImpl_Save(IPersistStream* iface,
174 static HRESULT WINAPI OLEFontImpl_GetSizeMax(IPersistStream* iface,
175 ULARGE_INTEGER* pcbSize);
177 /***********************************************************************
178 * Prototypes for the implementation functions for the
179 * IConnectionPointContainer interface
181 static HRESULT WINAPI OLEFontImpl_IConnectionPointContainer_QueryInterface(
182 IConnectionPointContainer* iface,
185 static ULONG WINAPI OLEFontImpl_IConnectionPointContainer_AddRef(
186 IConnectionPointContainer* iface);
187 static ULONG WINAPI OLEFontImpl_IConnectionPointContainer_Release(
188 IConnectionPointContainer* iface);
189 static HRESULT WINAPI OLEFontImpl_EnumConnectionPoints(
190 IConnectionPointContainer* iface,
191 IEnumConnectionPoints **ppEnum);
192 static HRESULT WINAPI OLEFontImpl_FindConnectionPoint(
193 IConnectionPointContainer* iface,
195 IConnectionPoint **ppCp);
198 * Virtual function tables for the OLEFontImpl class.
200 static ICOM_VTABLE(IFont) OLEFontImpl_VTable =
202 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
203 OLEFontImpl_QueryInterface,
206 OLEFontImpl_get_Name,
207 OLEFontImpl_put_Name,
208 OLEFontImpl_get_Size,
209 OLEFontImpl_put_Size,
210 OLEFontImpl_get_Bold,
211 OLEFontImpl_put_Bold,
212 OLEFontImpl_get_Italic,
213 OLEFontImpl_put_Italic,
214 OLEFontImpl_get_Underline,
215 OLEFontImpl_put_Underline,
216 OLEFontImpl_get_Strikethrough,
217 OLEFontImpl_put_Strikethrough,
218 OLEFontImpl_get_Weight,
219 OLEFontImpl_put_Weight,
220 OLEFontImpl_get_Charset,
221 OLEFontImpl_put_Charset,
222 OLEFontImpl_get_hFont,
225 OLEFontImpl_SetRatio,
226 OLEFontImpl_QueryTextMetrics,
227 OLEFontImpl_AddRefHfont,
228 OLEFontImpl_ReleaseHfont,
232 static ICOM_VTABLE(IDispatch) OLEFontImpl_IDispatch_VTable =
234 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
235 OLEFontImpl_IDispatch_QueryInterface,
236 OLEFontImpl_IDispatch_AddRef,
237 OLEFontImpl_IDispatch_Release,
238 OLEFontImpl_GetTypeInfoCount,
239 OLEFontImpl_GetTypeInfo,
240 OLEFontImpl_GetIDsOfNames,
244 static ICOM_VTABLE(IPersistStream) OLEFontImpl_IPersistStream_VTable =
246 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
247 OLEFontImpl_IPersistStream_QueryInterface,
248 OLEFontImpl_IPersistStream_AddRef,
249 OLEFontImpl_IPersistStream_Release,
250 OLEFontImpl_GetClassID,
254 OLEFontImpl_GetSizeMax
257 static ICOM_VTABLE(IConnectionPointContainer)
258 OLEFontImpl_IConnectionPointContainer_VTable =
260 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
261 OLEFontImpl_IConnectionPointContainer_QueryInterface,
262 OLEFontImpl_IConnectionPointContainer_AddRef,
263 OLEFontImpl_IConnectionPointContainer_Release,
264 OLEFontImpl_EnumConnectionPoints,
265 OLEFontImpl_FindConnectionPoint
268 /******************************************************************************
269 * OleCreateFontIndirect [OLEAUT32.420]
271 HRESULT WINAPI OleCreateFontIndirect(
272 LPFONTDESC lpFontDesc,
276 OLEFontImpl* newFont = 0;
279 TRACE("(%p, %s, %p)\n", lpFontDesc, debugstr_guid(riid), ppvObj);
289 * Try to construct a new instance of the class.
291 newFont = OLEFontImpl_Construct(lpFontDesc);
294 return E_OUTOFMEMORY;
297 * Make sure it supports the interface required by the caller.
299 hr = IFont_QueryInterface((IFont*)newFont, riid, ppvObj);
302 * Release the reference obtained in the constructor. If
303 * the QueryInterface was unsuccessful, it will free the class.
305 IFont_Release((IFont*)newFont);
311 /***********************************************************************
312 * Implementation of the OLEFontImpl class.
315 /***********************************************************************
316 * OLEFont_SendNotify (internal)
318 * Sends notification messages of changed properties to any interested
321 static void OLEFont_SendNotify(OLEFontImpl* this, DISPID dispID)
323 IEnumConnections *pEnum;
326 IConnectionPoint_EnumConnections(this->pCP, &pEnum);
328 while(IEnumConnections_Next(pEnum, 1, &CD, NULL) == S_OK) {
329 IPropertyNotifySink *sink;
331 IUnknown_QueryInterface(CD.pUnk, &IID_IPropertyNotifySink, (LPVOID)&sink);
332 IPropertyNotifySink_OnChanged(sink, dispID);
333 IPropertyNotifySink_Release(sink);
334 IUnknown_Release(CD.pUnk);
336 IEnumConnections_Release(pEnum);
340 /************************************************************************
341 * OLEFontImpl_Construct
343 * This method will construct a new instance of the OLEFontImpl
346 * The caller of this method must release the object when it's
349 static OLEFontImpl* OLEFontImpl_Construct(LPFONTDESC fontDesc)
351 OLEFontImpl* newObject = 0;
354 * Allocate space for the object.
356 newObject = HeapAlloc(GetProcessHeap(), 0, sizeof(OLEFontImpl));
362 * Initialize the virtual function table.
364 newObject->lpvtbl1 = &OLEFontImpl_VTable;
365 newObject->lpvtbl2 = &OLEFontImpl_IDispatch_VTable;
366 newObject->lpvtbl3 = &OLEFontImpl_IPersistStream_VTable;
367 newObject->lpvtbl4 = &OLEFontImpl_IConnectionPointContainer_VTable;
370 * Start with one reference count. The caller of this function
371 * must release the interface pointer when it is done.
376 * Copy the description of the font in the object.
378 assert(fontDesc->cbSizeofstruct >= sizeof(FONTDESC));
380 newObject->description.cbSizeofstruct = sizeof(FONTDESC);
381 newObject->description.lpstrName = HeapAlloc(GetProcessHeap(),
383 (lstrlenW(fontDesc->lpstrName)+1) * sizeof(WCHAR));
384 strcpyW(newObject->description.lpstrName, fontDesc->lpstrName);
385 newObject->description.cySize = fontDesc->cySize;
386 newObject->description.sWeight = fontDesc->sWeight;
387 newObject->description.sCharset = fontDesc->sCharset;
388 newObject->description.fItalic = fontDesc->fItalic;
389 newObject->description.fUnderline = fontDesc->fUnderline;
390 newObject->description.fStrikethrough = fontDesc->fStrikethrough;
393 * Initializing all the other members.
395 newObject->gdiFont = 0;
396 newObject->fontLock = 0;
397 newObject->cyHimetric = 1;
398 newObject->cyLogical = 1;
400 CreateConnectionPoint((IUnknown*)newObject, &IID_IPropertyNotifySink, &newObject->pCP);
402 TRACE("returning %p\n", newObject);
406 /************************************************************************
407 * OLEFontImpl_Destroy
409 * This method is called by the Release method when the reference
410 * count goes down to 0. It will free all resources used by
413 static void OLEFontImpl_Destroy(OLEFontImpl* fontDesc)
415 TRACE("(%p)\n", fontDesc);
417 if (fontDesc->description.lpstrName!=0)
418 HeapFree(GetProcessHeap(), 0, fontDesc->description.lpstrName);
420 if (fontDesc->gdiFont!=0)
421 DeleteObject(fontDesc->gdiFont);
423 HeapFree(GetProcessHeap(), 0, fontDesc);
426 /************************************************************************
427 * OLEFontImpl_QueryInterface (IUnknown)
429 * See Windows documentation for more details on IUnknown methods.
431 HRESULT WINAPI OLEFontImpl_QueryInterface(
436 _ICOM_THIS(OLEFontImpl, iface);
437 TRACE("(%p)->(%s, %p)\n", this, debugstr_guid(riid), ppvObject);
440 * Perform a sanity check on the parameters.
442 if ( (this==0) || (ppvObject==0) )
446 * Initialize the return parameter.
451 * Compare the riid with the interface IDs implemented by this object.
453 if (memcmp(&IID_IUnknown, riid, sizeof(IID_IUnknown)) == 0)
455 *ppvObject = (IFont*)this;
457 else if (memcmp(&IID_IFont, riid, sizeof(IID_IFont)) == 0)
459 *ppvObject = (IFont*)this;
461 else if (memcmp(&IID_IDispatch, riid, sizeof(IID_IDispatch)) == 0)
463 *ppvObject = (IDispatch*)&(this->lpvtbl2);
465 else if (memcmp(&IID_IFontDisp, riid, sizeof(IID_IFontDisp)) == 0)
467 *ppvObject = (IDispatch*)&(this->lpvtbl2);
469 else if (memcmp(&IID_IPersistStream, riid, sizeof(IID_IPersistStream)) == 0)
471 *ppvObject = (IPersistStream*)&(this->lpvtbl3);
473 else if (memcmp(&IID_IConnectionPointContainer, riid,
474 sizeof(IID_IConnectionPointContainer)) == 0)
476 *ppvObject = (IPersistStream*)&(this->lpvtbl4);
480 * Check that we obtained an interface.
484 FIXME("() : asking for un supported interface %s\n",debugstr_guid(riid));
485 return E_NOINTERFACE;
489 * Query Interface always increases the reference count by one when it is
492 OLEFontImpl_AddRef((IFont*)this);
497 /************************************************************************
498 * OLEFontImpl_AddRef (IUnknown)
500 * See Windows documentation for more details on IUnknown methods.
502 ULONG WINAPI OLEFontImpl_AddRef(
505 _ICOM_THIS(OLEFontImpl, iface);
506 TRACE("(%p)->(ref=%ld)\n", this, this->ref);
512 /************************************************************************
513 * OLEFontImpl_Release (IUnknown)
515 * See Windows documentation for more details on IUnknown methods.
517 ULONG WINAPI OLEFontImpl_Release(
520 _ICOM_THIS(OLEFontImpl, iface);
521 TRACE("(%p)->(ref=%ld)\n", this, this->ref);
524 * Decrease the reference count on this object.
529 * If the reference count goes down to 0, perform suicide.
533 OLEFontImpl_Destroy(this);
541 /************************************************************************
542 * OLEFontImpl_get_Name (IFont)
544 * See Windows documentation for more details on IFont methods.
546 static HRESULT WINAPI OLEFontImpl_get_Name(
550 _ICOM_THIS(OLEFontImpl, iface);
551 TRACE("(%p)->(%p)\n", this, pname);
558 if (this->description.lpstrName!=0)
559 *pname = SysAllocString(this->description.lpstrName);
566 /************************************************************************
567 * OLEFontImpl_put_Name (IFont)
569 * See Windows documentation for more details on IFont methods.
571 static HRESULT WINAPI OLEFontImpl_put_Name(
575 _ICOM_THIS(OLEFontImpl, iface);
576 TRACE("(%p)->(%p)\n", this, name);
578 if (this->description.lpstrName==0)
580 this->description.lpstrName = HeapAlloc(GetProcessHeap(),
582 (lstrlenW(name)+1) * sizeof(WCHAR));
586 this->description.lpstrName = HeapReAlloc(GetProcessHeap(),
588 this->description.lpstrName,
589 (lstrlenW(name)+1) * sizeof(WCHAR));
592 if (this->description.lpstrName==0)
593 return E_OUTOFMEMORY;
595 strcpyW(this->description.lpstrName, name);
596 TRACE("new name %s\n", debugstr_w(this->description.lpstrName));
597 OLEFont_SendNotify(this, DISPID_FONT_NAME);
601 /************************************************************************
602 * OLEFontImpl_get_Size (IFont)
604 * See Windows documentation for more details on IFont methods.
606 static HRESULT WINAPI OLEFontImpl_get_Size(
610 _ICOM_THIS(OLEFontImpl, iface);
611 TRACE("(%p)->(%p)\n", this, psize);
620 psize->s.Lo = this->description.cySize.s.Lo;
625 /************************************************************************
626 * OLEFontImpl_put_Size (IFont)
628 * See Windows documentation for more details on IFont methods.
630 static HRESULT WINAPI OLEFontImpl_put_Size(
634 _ICOM_THIS(OLEFontImpl, iface);
635 TRACE("(%p)->(%ld)\n", this, size.s.Lo);
636 this->description.cySize.s.Hi = 0;
637 this->description.cySize.s.Lo = size.s.Lo;
638 OLEFont_SendNotify(this, DISPID_FONT_SIZE);
643 /************************************************************************
644 * OLEFontImpl_get_Bold (IFont)
646 * See Windows documentation for more details on IFont methods.
648 static HRESULT WINAPI OLEFontImpl_get_Bold(
652 _ICOM_THIS(OLEFontImpl, iface);
653 TRACE("(%p)->(%p)\n", this, pbold);
660 *pbold = this->description.sWeight > 550;
665 /************************************************************************
666 * OLEFontImpl_put_Bold (IFont)
668 * See Windows documentation for more details on IFont methods.
670 static HRESULT WINAPI OLEFontImpl_put_Bold(
674 _ICOM_THIS(OLEFontImpl, iface);
675 TRACE("(%p)->(%d)\n", this, bold);
676 this->description.sWeight = bold ? FW_BOLD : FW_NORMAL;
677 OLEFont_SendNotify(this, DISPID_FONT_BOLD);
682 /************************************************************************
683 * OLEFontImpl_get_Italic (IFont)
685 * See Windows documentation for more details on IFont methods.
687 static HRESULT WINAPI OLEFontImpl_get_Italic(
691 _ICOM_THIS(OLEFontImpl, iface);
692 TRACE("(%p)->(%p)\n", this, pitalic);
699 *pitalic = this->description.fItalic;
704 /************************************************************************
705 * OLEFontImpl_put_Italic (IFont)
707 * See Windows documentation for more details on IFont methods.
709 static HRESULT WINAPI OLEFontImpl_put_Italic(
713 _ICOM_THIS(OLEFontImpl, iface);
714 TRACE("(%p)->(%d)\n", this, italic);
716 this->description.fItalic = italic;
718 OLEFont_SendNotify(this, DISPID_FONT_ITALIC);
722 /************************************************************************
723 * OLEFontImpl_get_Underline (IFont)
725 * See Windows documentation for more details on IFont methods.
727 static HRESULT WINAPI OLEFontImpl_get_Underline(
731 _ICOM_THIS(OLEFontImpl, iface);
732 TRACE("(%p)->(%p)\n", this, punderline);
740 *punderline = this->description.fUnderline;
745 /************************************************************************
746 * OLEFontImpl_put_Underline (IFont)
748 * See Windows documentation for more details on IFont methods.
750 static HRESULT WINAPI OLEFontImpl_put_Underline(
754 _ICOM_THIS(OLEFontImpl, iface);
755 TRACE("(%p)->(%d)\n", this, underline);
757 this->description.fUnderline = underline;
759 OLEFont_SendNotify(this, DISPID_FONT_UNDER);
763 /************************************************************************
764 * OLEFontImpl_get_Strikethrough (IFont)
766 * See Windows documentation for more details on IFont methods.
768 static HRESULT WINAPI OLEFontImpl_get_Strikethrough(
770 BOOL* pstrikethrough)
772 _ICOM_THIS(OLEFontImpl, iface);
773 TRACE("(%p)->(%p)\n", this, pstrikethrough);
778 if (pstrikethrough==0)
781 *pstrikethrough = this->description.fStrikethrough;
786 /************************************************************************
787 * OLEFontImpl_put_Strikethrough (IFont)
789 * See Windows documentation for more details on IFont methods.
791 static HRESULT WINAPI OLEFontImpl_put_Strikethrough(
795 _ICOM_THIS(OLEFontImpl, iface);
796 TRACE("(%p)->(%d)\n", this, strikethrough);
798 this->description.fStrikethrough = strikethrough;
799 OLEFont_SendNotify(this, DISPID_FONT_STRIKE);
804 /************************************************************************
805 * OLEFontImpl_get_Weight (IFont)
807 * See Windows documentation for more details on IFont methods.
809 static HRESULT WINAPI OLEFontImpl_get_Weight(
813 _ICOM_THIS(OLEFontImpl, iface);
814 TRACE("(%p)->(%p)\n", this, pweight);
822 *pweight = this->description.sWeight;
827 /************************************************************************
828 * OLEFontImpl_put_Weight (IFont)
830 * See Windows documentation for more details on IFont methods.
832 static HRESULT WINAPI OLEFontImpl_put_Weight(
836 _ICOM_THIS(OLEFontImpl, iface);
837 TRACE("(%p)->(%d)\n", this, weight);
839 this->description.sWeight = weight;
841 OLEFont_SendNotify(this, DISPID_FONT_WEIGHT);
845 /************************************************************************
846 * OLEFontImpl_get_Charset (IFont)
848 * See Windows documentation for more details on IFont methods.
850 static HRESULT WINAPI OLEFontImpl_get_Charset(
854 _ICOM_THIS(OLEFontImpl, iface);
855 TRACE("(%p)->(%p)\n", this, pcharset);
863 *pcharset = this->description.sCharset;
868 /************************************************************************
869 * OLEFontImpl_put_Charset (IFont)
871 * See Windows documentation for more details on IFont methods.
873 static HRESULT WINAPI OLEFontImpl_put_Charset(
877 _ICOM_THIS(OLEFontImpl, iface);
878 TRACE("(%p)->(%d)\n", this, charset);
880 this->description.sCharset = charset;
881 OLEFont_SendNotify(this, DISPID_FONT_CHARSET);
886 /************************************************************************
887 * OLEFontImpl_get_hFont (IFont)
889 * See Windows documentation for more details on IFont methods.
891 static HRESULT WINAPI OLEFontImpl_get_hFont(
895 _ICOM_THIS(OLEFontImpl, iface);
896 TRACE("(%p)->(%p)\n", this, phfont);
901 * Realize the font if necessary
903 if (this->gdiFont==0)
910 * The height of the font returned by the get_Size property is the
911 * height of the font in points multiplied by 10000... Using some
912 * simple conversions and the ratio given by the application, it can
913 * be converted to a height in pixels.
915 IFont_get_Size(iface, &cySize);
917 fontHeight = MulDiv(cySize.s.Lo, 2540L, 72L);
918 fontHeight = MulDiv(fontHeight, this->cyLogical,this->cyHimetric);
920 memset(&logFont, 0, sizeof(LOGFONTW));
922 logFont.lfHeight = ((fontHeight%10000L)>5000L) ? (-fontHeight/10000L)-1 :
923 (-fontHeight/10000L);
924 logFont.lfItalic = this->description.fItalic;
925 logFont.lfUnderline = this->description.fUnderline;
926 logFont.lfStrikeOut = this->description.fStrikethrough;
927 logFont.lfWeight = this->description.sWeight;
928 logFont.lfCharSet = this->description.sCharset;
929 logFont.lfOutPrecision = OUT_CHARACTER_PRECIS;
930 logFont.lfClipPrecision = CLIP_DEFAULT_PRECIS;
931 logFont.lfQuality = DEFAULT_QUALITY;
932 logFont.lfPitchAndFamily = DEFAULT_PITCH;
933 strcpyW(logFont.lfFaceName,this->description.lpstrName);
935 this->gdiFont = CreateFontIndirectW(&logFont);
938 *phfont = this->gdiFont;
939 TRACE("Returning %08x\n", *phfont);
943 /************************************************************************
944 * OLEFontImpl_Clone (IFont)
946 * See Windows documentation for more details on IFont methods.
948 static HRESULT WINAPI OLEFontImpl_Clone(
952 OLEFontImpl* newObject = 0;
953 _ICOM_THIS(OLEFontImpl, iface);
954 TRACE("(%p)->(%p)\n", this, ppfont);
962 * Allocate space for the object.
964 newObject = HeapAlloc(GetProcessHeap(), 0, sizeof(OLEFontImpl));
967 return E_OUTOFMEMORY;
972 * That new object starts with a reference count of 1
976 *ppfont = (IFont*)newObject;
981 /************************************************************************
982 * OLEFontImpl_IsEqual (IFont)
984 * See Windows documentation for more details on IFont methods.
986 static HRESULT WINAPI OLEFontImpl_IsEqual(
994 /************************************************************************
995 * OLEFontImpl_SetRatio (IFont)
997 * See Windows documentation for more details on IFont methods.
999 static HRESULT WINAPI OLEFontImpl_SetRatio(
1004 _ICOM_THIS(OLEFontImpl, iface);
1005 TRACE("(%p)->(%ld, %ld)\n", this, cyLogical, cyHimetric);
1007 this->cyLogical = cyLogical;
1008 this->cyHimetric = cyHimetric;
1013 /************************************************************************
1014 * OLEFontImpl_QueryTextMetrics (IFont)
1016 * See Windows documentation for more details on IFont methods.
1018 static HRESULT WINAPI OLEFontImpl_QueryTextMetrics(
1026 /************************************************************************
1027 * OLEFontImpl_AddRefHfont (IFont)
1029 * See Windows documentation for more details on IFont methods.
1031 static HRESULT WINAPI OLEFontImpl_AddRefHfont(
1035 _ICOM_THIS(OLEFontImpl, iface);
1036 TRACE("(%p)->(%08x) (lock=%ld)\n", this, hfont, this->fontLock);
1038 if ( (hfont == 0) ||
1039 (hfont != this->gdiFont) )
1040 return E_INVALIDARG;
1047 /************************************************************************
1048 * OLEFontImpl_ReleaseHfont (IFont)
1050 * See Windows documentation for more details on IFont methods.
1052 static HRESULT WINAPI OLEFontImpl_ReleaseHfont(
1056 _ICOM_THIS(OLEFontImpl, iface);
1057 TRACE("(%p)->(%08x) (lock=%ld)\n", this, hfont, this->fontLock);
1059 if ( (hfont == 0) ||
1060 (hfont != this->gdiFont) )
1061 return E_INVALIDARG;
1066 * If we just released our last font reference, destroy it.
1068 if (this->fontLock==0)
1070 DeleteObject(this->gdiFont);
1077 /************************************************************************
1078 * OLEFontImpl_SetHdc (IFont)
1080 * See Windows documentation for more details on IFont methods.
1082 static HRESULT WINAPI OLEFontImpl_SetHdc(
1086 _ICOM_THIS(OLEFontImpl, iface);
1087 FIXME("(%p)->(%08x): Stub\n", this, hdc);
1091 /************************************************************************
1092 * OLEFontImpl_IDispatch_QueryInterface (IUnknown)
1094 * See Windows documentation for more details on IUnknown methods.
1096 static HRESULT WINAPI OLEFontImpl_IDispatch_QueryInterface(
1101 _ICOM_THIS_From_IDispatch(IFont, iface);
1103 return IFont_QueryInterface(this, riid, ppvoid);
1106 /************************************************************************
1107 * OLEFontImpl_IDispatch_Release (IUnknown)
1109 * See Windows documentation for more details on IUnknown methods.
1111 static ULONG WINAPI OLEFontImpl_IDispatch_Release(
1114 _ICOM_THIS_From_IDispatch(IFont, iface);
1116 return IFont_Release(this);
1119 /************************************************************************
1120 * OLEFontImpl_IDispatch_AddRef (IUnknown)
1122 * See Windows documentation for more details on IUnknown methods.
1124 static ULONG WINAPI OLEFontImpl_IDispatch_AddRef(
1127 _ICOM_THIS_From_IDispatch(IFont, iface);
1129 return IFont_AddRef(this);
1132 /************************************************************************
1133 * OLEFontImpl_GetTypeInfoCount (IDispatch)
1135 * See Windows documentation for more details on IDispatch methods.
1137 static HRESULT WINAPI OLEFontImpl_GetTypeInfoCount(
1139 unsigned int* pctinfo)
1141 _ICOM_THIS_From_IDispatch(IFont, iface);
1142 FIXME("(%p)->(%p): Stub\n", this, pctinfo);
1147 /************************************************************************
1148 * OLEFontImpl_GetTypeInfo (IDispatch)
1150 * See Windows documentation for more details on IDispatch methods.
1152 static HRESULT WINAPI OLEFontImpl_GetTypeInfo(
1156 ITypeInfo** ppTInfo)
1158 _ICOM_THIS_From_IDispatch(IFont, iface);
1159 FIXME("(%p):Stub\n", this);
1164 /************************************************************************
1165 * OLEFontImpl_GetIDsOfNames (IDispatch)
1167 * See Windows documentation for more details on IDispatch methods.
1169 static HRESULT WINAPI OLEFontImpl_GetIDsOfNames(
1172 LPOLESTR* rgszNames,
1177 _ICOM_THIS_From_IDispatch(IFont, iface);
1178 FIXME("(%p):Stub\n", this);
1183 /************************************************************************
1184 * OLEFontImpl_Invoke (IDispatch)
1186 * See Windows documentation for more details on IDispatch methods.
1188 static HRESULT WINAPI OLEFontImpl_Invoke(
1190 DISPID dispIdMember,
1194 DISPPARAMS* pDispParams,
1195 VARIANT* pVarResult,
1196 EXCEPINFO* pExepInfo,
1199 _ICOM_THIS_From_IDispatch(IFont, iface);
1200 FIXME("(%p):Stub\n", this);
1205 /************************************************************************
1206 * OLEFontImpl_IPersistStream_QueryInterface (IUnknown)
1208 * See Windows documentation for more details on IUnknown methods.
1210 static HRESULT WINAPI OLEFontImpl_IPersistStream_QueryInterface(
1211 IPersistStream* iface,
1215 _ICOM_THIS_From_IPersistStream(IFont, iface);
1217 return IFont_QueryInterface(this, riid, ppvoid);
1220 /************************************************************************
1221 * OLEFontImpl_IPersistStream_Release (IUnknown)
1223 * See Windows documentation for more details on IUnknown methods.
1225 static ULONG WINAPI OLEFontImpl_IPersistStream_Release(
1226 IPersistStream* iface)
1228 _ICOM_THIS_From_IPersistStream(IFont, iface);
1230 return IFont_Release(this);
1233 /************************************************************************
1234 * OLEFontImpl_IPersistStream_AddRef (IUnknown)
1236 * See Windows documentation for more details on IUnknown methods.
1238 static ULONG WINAPI OLEFontImpl_IPersistStream_AddRef(
1239 IPersistStream* iface)
1241 _ICOM_THIS_From_IPersistStream(IFont, iface);
1243 return IFont_AddRef(this);
1246 /************************************************************************
1247 * OLEFontImpl_GetClassID (IPersistStream)
1249 * See Windows documentation for more details on IPersistStream methods.
1251 static HRESULT WINAPI OLEFontImpl_GetClassID(
1252 IPersistStream* iface,
1258 memcpy(pClassID, &CLSID_StdFont, sizeof(CLSID_StdFont));
1263 /************************************************************************
1264 * OLEFontImpl_IsDirty (IPersistStream)
1266 * See Windows documentation for more details on IPersistStream methods.
1268 static HRESULT WINAPI OLEFontImpl_IsDirty(
1269 IPersistStream* iface)
1274 /************************************************************************
1275 * OLEFontImpl_Load (IPersistStream)
1277 * See Windows documentation for more details on IPersistStream methods.
1279 * This is the format of the standard font serialization as far as I
1282 * Offset Type Value Comment
1283 * 0x0000 Byte Unknown Probably a version number, contains 0x01
1284 * 0x0001 Short Charset Charset value from the FONTDESC structure
1285 * 0x0003 Byte Attributes Flags defined as follows:
1287 * 00000100 - Underline
1288 * 00001000 - Strikethrough
1289 * 0x0004 Short Weight Weight value from FONTDESC structure
1290 * 0x0006 DWORD size "Low" portion of the cySize member of the FONTDESC
1292 * 0x000A Byte name length Length of the font name string (no null character)
1293 * 0x000B String name Name of the font (ASCII, no nul character)
1295 static HRESULT WINAPI OLEFontImpl_Load(
1296 IPersistStream* iface,
1297 IStream* pLoadStream)
1299 char readBuffer[0x100];
1305 _ICOM_THIS_From_IPersistStream(OLEFontImpl, iface);
1308 * Read the version byte
1310 IStream_Read(pLoadStream, &bVersion, 1, &cbRead);
1319 IStream_Read(pLoadStream, &this->description.sCharset, 2, &cbRead);
1327 IStream_Read(pLoadStream, &bAttributes, 1, &cbRead);
1332 this->description.fItalic = (bAttributes & FONTPERSIST_ITALIC) != 0;
1333 this->description.fStrikethrough = (bAttributes & FONTPERSIST_STRIKETHROUGH) != 0;
1334 this->description.fUnderline = (bAttributes & FONTPERSIST_UNDERLINE) != 0;
1339 IStream_Read(pLoadStream, &this->description.sWeight, 2, &cbRead);
1347 IStream_Read(pLoadStream, &this->description.cySize.s.Lo, 4, &cbRead);
1352 this->description.cySize.s.Hi = 0;
1357 IStream_Read(pLoadStream, &bStringSize, 1, &cbRead);
1362 memset(readBuffer, 0, 0x100);
1363 IStream_Read(pLoadStream, readBuffer, bStringSize, &cbRead);
1365 if (cbRead!=bStringSize)
1368 if (this->description.lpstrName!=0)
1369 HeapFree(GetProcessHeap(), 0, this->description.lpstrName);
1371 this->description.lpstrName = HEAP_strdupAtoW(GetProcessHeap(),
1378 /************************************************************************
1379 * OLEFontImpl_Save (IPersistStream)
1381 * See Windows documentation for more details on IPersistStream methods.
1383 static HRESULT WINAPI OLEFontImpl_Save(
1384 IPersistStream* iface,
1385 IStream* pOutStream,
1388 char* writeBuffer = NULL;
1390 BYTE bVersion = 0x01;
1394 _ICOM_THIS_From_IPersistStream(OLEFontImpl, iface);
1397 * Read the version byte
1399 IStream_Write(pOutStream, &bVersion, 1, &cbWritten);
1407 IStream_Write(pOutStream, &this->description.sCharset, 2, &cbWritten);
1417 if (this->description.fItalic)
1418 bAttributes |= FONTPERSIST_ITALIC;
1420 if (this->description.fStrikethrough)
1421 bAttributes |= FONTPERSIST_STRIKETHROUGH;
1423 if (this->description.fUnderline)
1424 bAttributes |= FONTPERSIST_UNDERLINE;
1426 IStream_Write(pOutStream, &bAttributes, 1, &cbWritten);
1434 IStream_Write(pOutStream, &this->description.sWeight, 2, &cbWritten);
1442 IStream_Write(pOutStream, &this->description.cySize.s.Lo, 4, &cbWritten);
1450 if (this->description.lpstrName!=0)
1451 bStringSize = lstrlenW(this->description.lpstrName);
1455 IStream_Write(pOutStream, &bStringSize, 1, &cbWritten);
1462 writeBuffer = HEAP_strdupWtoA(GetProcessHeap(),
1464 this->description.lpstrName);
1467 return E_OUTOFMEMORY;
1469 IStream_Write(pOutStream, writeBuffer, bStringSize, &cbWritten);
1471 HeapFree(GetProcessHeap(), 0, writeBuffer);
1473 if (cbWritten!=bStringSize)
1480 /************************************************************************
1481 * OLEFontImpl_GetSizeMax (IPersistStream)
1483 * See Windows documentation for more details on IPersistStream methods.
1485 static HRESULT WINAPI OLEFontImpl_GetSizeMax(
1486 IPersistStream* iface,
1487 ULARGE_INTEGER* pcbSize)
1489 _ICOM_THIS_From_IPersistStream(OLEFontImpl, iface);
1494 pcbSize->s.HighPart = 0;
1495 pcbSize->s.LowPart = 0;
1497 pcbSize->s.LowPart += sizeof(BYTE); /* Version */
1498 pcbSize->s.LowPart += sizeof(WORD); /* Lang code */
1499 pcbSize->s.LowPart += sizeof(BYTE); /* Flags */
1500 pcbSize->s.LowPart += sizeof(WORD); /* Weight */
1501 pcbSize->s.LowPart += sizeof(DWORD); /* Size */
1502 pcbSize->s.LowPart += sizeof(BYTE); /* StrLength */
1504 if (this->description.lpstrName!=0)
1505 pcbSize->s.LowPart += lstrlenW(this->description.lpstrName);
1510 /************************************************************************
1511 * OLEFontImpl_IConnectionPointContainer_QueryInterface (IUnknown)
1513 * See Windows documentation for more details on IUnknown methods.
1515 static HRESULT WINAPI OLEFontImpl_IConnectionPointContainer_QueryInterface(
1516 IConnectionPointContainer* iface,
1520 _ICOM_THIS_From_IConnectionPointContainer(OLEFontImpl, iface);
1522 return IFont_QueryInterface((IFont*)this, riid, ppvoid);
1525 /************************************************************************
1526 * OLEFontImpl_IConnectionPointContainer_Release (IUnknown)
1528 * See Windows documentation for more details on IUnknown methods.
1530 static ULONG WINAPI OLEFontImpl_IConnectionPointContainer_Release(
1531 IConnectionPointContainer* iface)
1533 _ICOM_THIS_From_IConnectionPointContainer(OLEFontImpl, iface);
1535 return IFont_Release((IFont*)this);
1538 /************************************************************************
1539 * OLEFontImpl_IConnectionPointContainer_AddRef (IUnknown)
1541 * See Windows documentation for more details on IUnknown methods.
1543 static ULONG WINAPI OLEFontImpl_IConnectionPointContainer_AddRef(
1544 IConnectionPointContainer* iface)
1546 _ICOM_THIS_From_IConnectionPointContainer(OLEFontImpl, iface);
1548 return IFont_AddRef((IFont*)this);
1551 /************************************************************************
1552 * OLEFontImpl_EnumConnectionPoints (IConnectionPointContainer)
1554 * See Windows documentation for more details on IConnectionPointContainer
1557 static HRESULT WINAPI OLEFontImpl_EnumConnectionPoints(
1558 IConnectionPointContainer* iface,
1559 IEnumConnectionPoints **ppEnum)
1561 _ICOM_THIS_From_IConnectionPointContainer(OLEFontImpl, iface);
1563 FIXME("(%p)->(%p): stub\n", this, ppEnum);
1567 /************************************************************************
1568 * OLEFontImpl_FindConnectionPoint (IConnectionPointContainer)
1570 * See Windows documentation for more details on IConnectionPointContainer
1573 static HRESULT WINAPI OLEFontImpl_FindConnectionPoint(
1574 IConnectionPointContainer* iface,
1576 IConnectionPoint **ppCp)
1578 _ICOM_THIS_From_IConnectionPointContainer(OLEFontImpl, iface);
1579 TRACE("(%p)->(%s, %p): stub\n", this, debugstr_guid(riid), ppCp);
1581 if(memcmp(riid, &IID_IPropertyNotifySink, sizeof(IID_IPropertyNotifySink)) == 0) {
1582 return IConnectionPoint_QueryInterface(this->pCP, &IID_IConnectionPoint,
1585 FIXME("Tried to find connection point on %s\n", debugstr_guid(riid));
1586 return E_NOINTERFACE;