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_base.h"
18 #include "wine/obj_olefont.h"
19 #include "wine/obj_storage.h"
22 #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;
956 _ICOM_THIS(OLEFontImpl, iface);
957 TRACE("(%p)->(%p)\n", this, ppfont);
965 * Allocate space for the object.
967 newObject = HeapAlloc(GetProcessHeap(), 0, sizeof(OLEFontImpl));
970 return E_OUTOFMEMORY;
974 /* We need to alloc new memory for the string, otherwise
975 * we free memory twice.
977 newObject->description.lpstrName = HeapAlloc(
979 (1+strlenW(this->description.lpstrName))*2
981 /* We need to clone the HFONT too. This is just cut & paste from above */
982 IFont_get_Size(iface, &cySize);
984 fontHeight = MulDiv(cySize.s.Lo, 2540L, 72L);
985 fontHeight = MulDiv(fontHeight, this->cyLogical,this->cyHimetric);
987 memset(&logFont, 0, sizeof(LOGFONTW));
989 logFont.lfHeight = ((fontHeight%10000L)>5000L) ? (-fontHeight/10000L)-1 :
990 (-fontHeight/10000L);
991 logFont.lfItalic = this->description.fItalic;
992 logFont.lfUnderline = this->description.fUnderline;
993 logFont.lfStrikeOut = this->description.fStrikethrough;
994 logFont.lfWeight = this->description.sWeight;
995 logFont.lfCharSet = this->description.sCharset;
996 logFont.lfOutPrecision = OUT_CHARACTER_PRECIS;
997 logFont.lfClipPrecision = CLIP_DEFAULT_PRECIS;
998 logFont.lfQuality = DEFAULT_QUALITY;
999 logFont.lfPitchAndFamily = DEFAULT_PITCH;
1000 strcpyW(logFont.lfFaceName,this->description.lpstrName);
1002 newObject->gdiFont = CreateFontIndirectW(&logFont);
1005 /* The cloned object starts with a reference count of 1 */
1008 *ppfont = (IFont*)newObject;
1013 /************************************************************************
1014 * OLEFontImpl_IsEqual (IFont)
1016 * See Windows documentation for more details on IFont methods.
1018 static HRESULT WINAPI OLEFontImpl_IsEqual(
1026 /************************************************************************
1027 * OLEFontImpl_SetRatio (IFont)
1029 * See Windows documentation for more details on IFont methods.
1031 static HRESULT WINAPI OLEFontImpl_SetRatio(
1036 _ICOM_THIS(OLEFontImpl, iface);
1037 TRACE("(%p)->(%ld, %ld)\n", this, cyLogical, cyHimetric);
1039 this->cyLogical = cyLogical;
1040 this->cyHimetric = cyHimetric;
1045 /************************************************************************
1046 * OLEFontImpl_QueryTextMetrics (IFont)
1048 * See Windows documentation for more details on IFont methods.
1050 static HRESULT WINAPI OLEFontImpl_QueryTextMetrics(
1058 /************************************************************************
1059 * OLEFontImpl_AddRefHfont (IFont)
1061 * See Windows documentation for more details on IFont methods.
1063 static HRESULT WINAPI OLEFontImpl_AddRefHfont(
1067 _ICOM_THIS(OLEFontImpl, iface);
1068 TRACE("(%p)->(%08x) (lock=%ld)\n", this, hfont, this->fontLock);
1070 if ( (hfont == 0) ||
1071 (hfont != this->gdiFont) )
1072 return E_INVALIDARG;
1079 /************************************************************************
1080 * OLEFontImpl_ReleaseHfont (IFont)
1082 * See Windows documentation for more details on IFont methods.
1084 static HRESULT WINAPI OLEFontImpl_ReleaseHfont(
1088 _ICOM_THIS(OLEFontImpl, iface);
1089 TRACE("(%p)->(%08x) (lock=%ld)\n", this, hfont, this->fontLock);
1091 if ( (hfont == 0) ||
1092 (hfont != this->gdiFont) )
1093 return E_INVALIDARG;
1098 * If we just released our last font reference, destroy it.
1100 if (this->fontLock==0)
1102 DeleteObject(this->gdiFont);
1109 /************************************************************************
1110 * OLEFontImpl_SetHdc (IFont)
1112 * See Windows documentation for more details on IFont methods.
1114 static HRESULT WINAPI OLEFontImpl_SetHdc(
1118 _ICOM_THIS(OLEFontImpl, iface);
1119 FIXME("(%p)->(%08x): Stub\n", this, hdc);
1123 /************************************************************************
1124 * OLEFontImpl_IDispatch_QueryInterface (IUnknown)
1126 * See Windows documentation for more details on IUnknown methods.
1128 static HRESULT WINAPI OLEFontImpl_IDispatch_QueryInterface(
1133 _ICOM_THIS_From_IDispatch(IFont, iface);
1135 return IFont_QueryInterface(this, riid, ppvoid);
1138 /************************************************************************
1139 * OLEFontImpl_IDispatch_Release (IUnknown)
1141 * See Windows documentation for more details on IUnknown methods.
1143 static ULONG WINAPI OLEFontImpl_IDispatch_Release(
1146 _ICOM_THIS_From_IDispatch(IFont, iface);
1148 return IFont_Release(this);
1151 /************************************************************************
1152 * OLEFontImpl_IDispatch_AddRef (IUnknown)
1154 * See Windows documentation for more details on IUnknown methods.
1156 static ULONG WINAPI OLEFontImpl_IDispatch_AddRef(
1159 _ICOM_THIS_From_IDispatch(IFont, iface);
1161 return IFont_AddRef(this);
1164 /************************************************************************
1165 * OLEFontImpl_GetTypeInfoCount (IDispatch)
1167 * See Windows documentation for more details on IDispatch methods.
1169 static HRESULT WINAPI OLEFontImpl_GetTypeInfoCount(
1171 unsigned int* pctinfo)
1173 _ICOM_THIS_From_IDispatch(IFont, iface);
1174 FIXME("(%p)->(%p): Stub\n", this, pctinfo);
1179 /************************************************************************
1180 * OLEFontImpl_GetTypeInfo (IDispatch)
1182 * See Windows documentation for more details on IDispatch methods.
1184 static HRESULT WINAPI OLEFontImpl_GetTypeInfo(
1188 ITypeInfo** ppTInfo)
1190 _ICOM_THIS_From_IDispatch(IFont, iface);
1191 FIXME("(%p):Stub\n", this);
1196 /************************************************************************
1197 * OLEFontImpl_GetIDsOfNames (IDispatch)
1199 * See Windows documentation for more details on IDispatch methods.
1201 static HRESULT WINAPI OLEFontImpl_GetIDsOfNames(
1204 LPOLESTR* rgszNames,
1209 _ICOM_THIS_From_IDispatch(IFont, iface);
1210 FIXME("(%p):Stub\n", this);
1215 /************************************************************************
1216 * OLEFontImpl_Invoke (IDispatch)
1218 * See Windows documentation for more details on IDispatch methods.
1220 static HRESULT WINAPI OLEFontImpl_Invoke(
1222 DISPID dispIdMember,
1226 DISPPARAMS* pDispParams,
1227 VARIANT* pVarResult,
1228 EXCEPINFO* pExepInfo,
1231 _ICOM_THIS_From_IDispatch(IFont, iface);
1232 FIXME("%p->(%ld,%s,%lx,%x), stub!\n", this,dispIdMember,debugstr_guid(riid),lcid,
1238 /************************************************************************
1239 * OLEFontImpl_IPersistStream_QueryInterface (IUnknown)
1241 * See Windows documentation for more details on IUnknown methods.
1243 static HRESULT WINAPI OLEFontImpl_IPersistStream_QueryInterface(
1244 IPersistStream* iface,
1248 _ICOM_THIS_From_IPersistStream(IFont, iface);
1250 return IFont_QueryInterface(this, riid, ppvoid);
1253 /************************************************************************
1254 * OLEFontImpl_IPersistStream_Release (IUnknown)
1256 * See Windows documentation for more details on IUnknown methods.
1258 static ULONG WINAPI OLEFontImpl_IPersistStream_Release(
1259 IPersistStream* iface)
1261 _ICOM_THIS_From_IPersistStream(IFont, iface);
1263 return IFont_Release(this);
1266 /************************************************************************
1267 * OLEFontImpl_IPersistStream_AddRef (IUnknown)
1269 * See Windows documentation for more details on IUnknown methods.
1271 static ULONG WINAPI OLEFontImpl_IPersistStream_AddRef(
1272 IPersistStream* iface)
1274 _ICOM_THIS_From_IPersistStream(IFont, iface);
1276 return IFont_AddRef(this);
1279 /************************************************************************
1280 * OLEFontImpl_GetClassID (IPersistStream)
1282 * See Windows documentation for more details on IPersistStream methods.
1284 static HRESULT WINAPI OLEFontImpl_GetClassID(
1285 IPersistStream* iface,
1291 memcpy(pClassID, &CLSID_StdFont, sizeof(CLSID_StdFont));
1296 /************************************************************************
1297 * OLEFontImpl_IsDirty (IPersistStream)
1299 * See Windows documentation for more details on IPersistStream methods.
1301 static HRESULT WINAPI OLEFontImpl_IsDirty(
1302 IPersistStream* iface)
1307 /************************************************************************
1308 * OLEFontImpl_Load (IPersistStream)
1310 * See Windows documentation for more details on IPersistStream methods.
1312 * This is the format of the standard font serialization as far as I
1315 * Offset Type Value Comment
1316 * 0x0000 Byte Unknown Probably a version number, contains 0x01
1317 * 0x0001 Short Charset Charset value from the FONTDESC structure
1318 * 0x0003 Byte Attributes Flags defined as follows:
1320 * 00000100 - Underline
1321 * 00001000 - Strikethrough
1322 * 0x0004 Short Weight Weight value from FONTDESC structure
1323 * 0x0006 DWORD size "Low" portion of the cySize member of the FONTDESC
1325 * 0x000A Byte name length Length of the font name string (no null character)
1326 * 0x000B String name Name of the font (ASCII, no nul character)
1328 static HRESULT WINAPI OLEFontImpl_Load(
1329 IPersistStream* iface,
1330 IStream* pLoadStream)
1332 char readBuffer[0x100];
1339 _ICOM_THIS_From_IPersistStream(OLEFontImpl, iface);
1342 * Read the version byte
1344 IStream_Read(pLoadStream, &bVersion, 1, &cbRead);
1353 IStream_Read(pLoadStream, &this->description.sCharset, 2, &cbRead);
1361 IStream_Read(pLoadStream, &bAttributes, 1, &cbRead);
1366 this->description.fItalic = (bAttributes & FONTPERSIST_ITALIC) != 0;
1367 this->description.fStrikethrough = (bAttributes & FONTPERSIST_STRIKETHROUGH) != 0;
1368 this->description.fUnderline = (bAttributes & FONTPERSIST_UNDERLINE) != 0;
1373 IStream_Read(pLoadStream, &this->description.sWeight, 2, &cbRead);
1381 IStream_Read(pLoadStream, &this->description.cySize.s.Lo, 4, &cbRead);
1386 this->description.cySize.s.Hi = 0;
1391 IStream_Read(pLoadStream, &bStringSize, 1, &cbRead);
1396 IStream_Read(pLoadStream, readBuffer, bStringSize, &cbRead);
1398 if (cbRead!=bStringSize)
1401 if (this->description.lpstrName!=0)
1402 HeapFree(GetProcessHeap(), 0, this->description.lpstrName);
1404 len = MultiByteToWideChar( CP_ACP, 0, readBuffer, bStringSize, NULL, 0 );
1405 this->description.lpstrName = HeapAlloc( GetProcessHeap(), 0, (len+1) * sizeof(WCHAR) );
1406 MultiByteToWideChar( CP_ACP, 0, readBuffer, bStringSize, this->description.lpstrName, len );
1407 this->description.lpstrName[len] = 0;
1412 /************************************************************************
1413 * OLEFontImpl_Save (IPersistStream)
1415 * See Windows documentation for more details on IPersistStream methods.
1417 static HRESULT WINAPI OLEFontImpl_Save(
1418 IPersistStream* iface,
1419 IStream* pOutStream,
1422 char* writeBuffer = NULL;
1424 BYTE bVersion = 0x01;
1428 _ICOM_THIS_From_IPersistStream(OLEFontImpl, iface);
1431 * Read the version byte
1433 IStream_Write(pOutStream, &bVersion, 1, &cbWritten);
1441 IStream_Write(pOutStream, &this->description.sCharset, 2, &cbWritten);
1451 if (this->description.fItalic)
1452 bAttributes |= FONTPERSIST_ITALIC;
1454 if (this->description.fStrikethrough)
1455 bAttributes |= FONTPERSIST_STRIKETHROUGH;
1457 if (this->description.fUnderline)
1458 bAttributes |= FONTPERSIST_UNDERLINE;
1460 IStream_Write(pOutStream, &bAttributes, 1, &cbWritten);
1468 IStream_Write(pOutStream, &this->description.sWeight, 2, &cbWritten);
1476 IStream_Write(pOutStream, &this->description.cySize.s.Lo, 4, &cbWritten);
1484 if (this->description.lpstrName!=0)
1485 bStringSize = WideCharToMultiByte( CP_ACP, 0, this->description.lpstrName,
1486 strlenW(this->description.lpstrName), NULL, 0, NULL, NULL );
1490 IStream_Write(pOutStream, &bStringSize, 1, &cbWritten);
1497 if (!(writeBuffer = HeapAlloc( GetProcessHeap(), 0, bStringSize ))) return E_OUTOFMEMORY;
1498 WideCharToMultiByte( CP_ACP, 0, this->description.lpstrName,
1499 strlenW(this->description.lpstrName),
1500 writeBuffer, bStringSize, NULL, NULL );
1502 IStream_Write(pOutStream, writeBuffer, bStringSize, &cbWritten);
1503 HeapFree(GetProcessHeap(), 0, writeBuffer);
1505 if (cbWritten!=bStringSize)
1512 /************************************************************************
1513 * OLEFontImpl_GetSizeMax (IPersistStream)
1515 * See Windows documentation for more details on IPersistStream methods.
1517 static HRESULT WINAPI OLEFontImpl_GetSizeMax(
1518 IPersistStream* iface,
1519 ULARGE_INTEGER* pcbSize)
1521 _ICOM_THIS_From_IPersistStream(OLEFontImpl, iface);
1526 pcbSize->s.HighPart = 0;
1527 pcbSize->s.LowPart = 0;
1529 pcbSize->s.LowPart += sizeof(BYTE); /* Version */
1530 pcbSize->s.LowPart += sizeof(WORD); /* Lang code */
1531 pcbSize->s.LowPart += sizeof(BYTE); /* Flags */
1532 pcbSize->s.LowPart += sizeof(WORD); /* Weight */
1533 pcbSize->s.LowPart += sizeof(DWORD); /* Size */
1534 pcbSize->s.LowPart += sizeof(BYTE); /* StrLength */
1536 if (this->description.lpstrName!=0)
1537 pcbSize->s.LowPart += lstrlenW(this->description.lpstrName);
1542 /************************************************************************
1543 * OLEFontImpl_IConnectionPointContainer_QueryInterface (IUnknown)
1545 * See Windows documentation for more details on IUnknown methods.
1547 static HRESULT WINAPI OLEFontImpl_IConnectionPointContainer_QueryInterface(
1548 IConnectionPointContainer* iface,
1552 _ICOM_THIS_From_IConnectionPointContainer(OLEFontImpl, iface);
1554 return IFont_QueryInterface((IFont*)this, riid, ppvoid);
1557 /************************************************************************
1558 * OLEFontImpl_IConnectionPointContainer_Release (IUnknown)
1560 * See Windows documentation for more details on IUnknown methods.
1562 static ULONG WINAPI OLEFontImpl_IConnectionPointContainer_Release(
1563 IConnectionPointContainer* iface)
1565 _ICOM_THIS_From_IConnectionPointContainer(OLEFontImpl, iface);
1567 return IFont_Release((IFont*)this);
1570 /************************************************************************
1571 * OLEFontImpl_IConnectionPointContainer_AddRef (IUnknown)
1573 * See Windows documentation for more details on IUnknown methods.
1575 static ULONG WINAPI OLEFontImpl_IConnectionPointContainer_AddRef(
1576 IConnectionPointContainer* iface)
1578 _ICOM_THIS_From_IConnectionPointContainer(OLEFontImpl, iface);
1580 return IFont_AddRef((IFont*)this);
1583 /************************************************************************
1584 * OLEFontImpl_EnumConnectionPoints (IConnectionPointContainer)
1586 * See Windows documentation for more details on IConnectionPointContainer
1589 static HRESULT WINAPI OLEFontImpl_EnumConnectionPoints(
1590 IConnectionPointContainer* iface,
1591 IEnumConnectionPoints **ppEnum)
1593 _ICOM_THIS_From_IConnectionPointContainer(OLEFontImpl, iface);
1595 FIXME("(%p)->(%p): stub\n", this, ppEnum);
1599 /************************************************************************
1600 * OLEFontImpl_FindConnectionPoint (IConnectionPointContainer)
1602 * See Windows documentation for more details on IConnectionPointContainer
1605 static HRESULT WINAPI OLEFontImpl_FindConnectionPoint(
1606 IConnectionPointContainer* iface,
1608 IConnectionPoint **ppCp)
1610 _ICOM_THIS_From_IConnectionPointContainer(OLEFontImpl, iface);
1611 TRACE("(%p)->(%s, %p): stub\n", this, debugstr_guid(riid), ppCp);
1613 if(memcmp(riid, &IID_IPropertyNotifySink, sizeof(IID_IPropertyNotifySink)) == 0) {
1614 return IConnectionPoint_QueryInterface(this->pCP, &IID_IConnectionPoint,
1617 FIXME("Tried to find connection point on %s\n", debugstr_guid(riid));
1618 return E_NOINTERFACE;
1622 /*******************************************************************************
1623 * StdFont ClassFactory
1627 /* IUnknown fields */
1628 ICOM_VFIELD(IClassFactory);
1630 } IClassFactoryImpl;
1632 static HRESULT WINAPI
1633 SFCF_QueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj) {
1634 ICOM_THIS(IClassFactoryImpl,iface);
1636 FIXME("(%p)->(%s,%p),stub!\n",This,debugstr_guid(riid),ppobj);
1637 return E_NOINTERFACE;
1641 SFCF_AddRef(LPCLASSFACTORY iface) {
1642 ICOM_THIS(IClassFactoryImpl,iface);
1643 return ++(This->ref);
1646 static ULONG WINAPI SFCF_Release(LPCLASSFACTORY iface) {
1647 ICOM_THIS(IClassFactoryImpl,iface);
1648 /* static class, won't be freed */
1649 return --(This->ref);
1652 static HRESULT WINAPI SFCF_CreateInstance(
1653 LPCLASSFACTORY iface,LPUNKNOWN pOuter,REFIID riid,LPVOID *ppobj
1655 ICOM_THIS(IClassFactoryImpl,iface);
1657 if (IsEqualGUID(riid,&IID_IFont)) {
1660 WCHAR fname[] = { 'S','y','s','t','e','m',0 };
1662 fd.cbSizeofstruct = sizeof(fd);
1663 fd.lpstrName = fname;
1664 fd.cySize.s.Lo = 80000;
1670 fd.fStrikethrough = 0;
1671 return OleCreateFontIndirect(&fd,riid,ppobj);
1674 FIXME("(%p)->(%p,%s,%p)\n",This,pOuter,debugstr_guid(riid),ppobj);
1675 return E_NOINTERFACE;
1678 static HRESULT WINAPI SFCF_LockServer(LPCLASSFACTORY iface,BOOL dolock) {
1679 ICOM_THIS(IClassFactoryImpl,iface);
1680 FIXME("(%p)->(%d),stub!\n",This,dolock);
1684 static ICOM_VTABLE(IClassFactory) SFCF_Vtbl = {
1685 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
1686 SFCF_QueryInterface,
1689 SFCF_CreateInstance,
1692 static IClassFactoryImpl STDFONT_CF = {&SFCF_Vtbl, 1 };
1694 void _get_STDFONT_CF(LPVOID *ppv) { *ppv = (LPVOID)&STDFONT_CF; }