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 "debugtools.h"
18 DEFAULT_DEBUG_CHANNEL(ole)
20 /***********************************************************************
21 * Declaration of constants used when serializing the font object.
23 #define FONTPERSIST_ITALIC 0x02
24 #define FONTPERSIST_UNDERLINE 0x04
25 #define FONTPERSIST_STRIKETHROUGH 0x08
27 /***********************************************************************
28 * Declaration of the implementation class for the IFont interface
30 typedef struct OLEFontImpl OLEFontImpl;
35 * This class supports many interfaces. IUnknown, IFont,
36 * IDispatch, IDispFont and IPersistStream. The first two are
37 * supported by the first vtablem the next two are supported by
38 * the second table and the last one has it's own.
40 ICOM_VTABLE(IFont)* lpvtbl1;
41 ICOM_VTABLE(IDispatch)* lpvtbl2;
42 ICOM_VTABLE(IPersistStream)* lpvtbl3;
45 * Reference count for that instance of the class.
50 * This structure contains the description of the class.
55 * Contain the font associated with this object.
72 * Here, I define utility macros to help with the casting of the
74 * There is a version to accomodate all of the VTables implemented
77 #define _ICOM_THIS(class,name) class* this = (class*)name;
78 #define _ICOM_THIS_From_IDispatch(class, name) class* this = (class*)(((char*)name)-sizeof(void*));
79 #define _ICOM_THIS_From_IPersistStream(class, name) class* this = (class*)(((char*)name)-2*sizeof(void*));
81 /***********************************************************************
82 * Prototypes for the implementation functions for the IFont
85 static OLEFontImpl* OLEFontImpl_Construct(LPFONTDESC fontDesc);
86 static void OLEFontImpl_Destroy(OLEFontImpl* fontDesc);
87 static HRESULT WINAPI OLEFontImpl_QueryInterface(IFont* iface, REFIID riid, VOID** ppvoid);
88 static ULONG WINAPI OLEFontImpl_AddRef(IFont* iface);
89 static ULONG WINAPI OLEFontImpl_Release(IFont* iface);
90 static HRESULT WINAPI OLEFontImpl_get_Name(IFont* iface, BSTR* pname);
91 static HRESULT WINAPI OLEFontImpl_put_Name(IFont* iface, BSTR name);
92 static HRESULT WINAPI OLEFontImpl_get_Size(IFont* iface, CY* psize);
93 static HRESULT WINAPI OLEFontImpl_put_Size(IFont* iface, CY size);
94 static HRESULT WINAPI OLEFontImpl_get_Bold(IFont* iface, BOOL* pbold);
95 static HRESULT WINAPI OLEFontImpl_put_Bold(IFont* iface, BOOL bold);
96 static HRESULT WINAPI OLEFontImpl_get_Italic(IFont* iface, BOOL* pitalic);
97 static HRESULT WINAPI OLEFontImpl_put_Italic(IFont* iface, BOOL italic);
98 static HRESULT WINAPI OLEFontImpl_get_Underline(IFont* iface, BOOL* punderline);
99 static HRESULT WINAPI OLEFontImpl_put_Underline(IFont* iface, BOOL underline);
100 static HRESULT WINAPI OLEFontImpl_get_Strikethrough(IFont* iface, BOOL* pstrikethrough);
101 static HRESULT WINAPI OLEFontImpl_put_Strikethrough(IFont* iface, BOOL strikethrough);
102 static HRESULT WINAPI OLEFontImpl_get_Weight(IFont* iface, short* pweight);
103 static HRESULT WINAPI OLEFontImpl_put_Weight(IFont* iface, short weight);
104 static HRESULT WINAPI OLEFontImpl_get_Charset(IFont* iface, short* pcharset);
105 static HRESULT WINAPI OLEFontImpl_put_Charset(IFont* iface, short charset);
106 static HRESULT WINAPI OLEFontImpl_get_hFont(IFont* iface, HFONT* phfont);
107 static HRESULT WINAPI OLEFontImpl_Clone(IFont* iface, IFont** ppfont);
108 static HRESULT WINAPI OLEFontImpl_IsEqual(IFont* iface, IFont* pFontOther);
109 static HRESULT WINAPI OLEFontImpl_SetRatio(IFont* iface, long cyLogical, long cyHimetric);
110 static HRESULT WINAPI OLEFontImpl_QueryTextMetrics(IFont* iface, TEXTMETRICOLE* ptm);
111 static HRESULT WINAPI OLEFontImpl_AddRefHfont(IFont* iface, HFONT hfont);
112 static HRESULT WINAPI OLEFontImpl_ReleaseHfont(IFont* iface, HFONT hfont);
113 static HRESULT WINAPI OLEFontImpl_SetHdc(IFont* iface, HDC hdc);
115 /***********************************************************************
116 * Prototypes for the implementation functions for the IDispatch
119 static HRESULT WINAPI OLEFontImpl_IDispatch_QueryInterface(IDispatch* iface,
122 static ULONG WINAPI OLEFontImpl_IDispatch_AddRef(IDispatch* iface);
123 static ULONG WINAPI OLEFontImpl_IDispatch_Release(IDispatch* iface);
124 static HRESULT WINAPI OLEFontImpl_GetTypeInfoCount(IDispatch* iface,
125 unsigned int* pctinfo);
126 static HRESULT WINAPI OLEFontImpl_GetTypeInfo(IDispatch* iface,
129 ITypeInfo** ppTInfo);
130 static HRESULT WINAPI OLEFontImpl_GetIDsOfNames(IDispatch* iface,
136 static HRESULT WINAPI OLEFontImpl_Invoke(IDispatch* iface,
141 DISPPARAMS* pDispParams,
143 EXCEPINFO* pExepInfo,
146 /***********************************************************************
147 * Prototypes for the implementation functions for the IPersistStream
150 static HRESULT WINAPI OLEFontImpl_IPersistStream_QueryInterface(IPersistStream* iface,
153 static ULONG WINAPI OLEFontImpl_IPersistStream_AddRef(IPersistStream* iface);
154 static ULONG WINAPI OLEFontImpl_IPersistStream_Release(IPersistStream* iface);
155 static HRESULT WINAPI OLEFontImpl_GetClassID(IPersistStream* iface,
157 static HRESULT WINAPI OLEFontImpl_IsDirty(IPersistStream* iface);
158 static HRESULT WINAPI OLEFontImpl_Load(IPersistStream* iface,
159 IStream* pLoadStream);
160 static HRESULT WINAPI OLEFontImpl_Save(IPersistStream* iface,
163 static HRESULT WINAPI OLEFontImpl_GetSizeMax(IPersistStream* iface,
164 ULARGE_INTEGER* pcbSize);
167 * Virtual function tables for the OLEFontImpl class.
169 static ICOM_VTABLE(IFont) OLEFontImpl_VTable =
171 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
172 OLEFontImpl_QueryInterface,
175 OLEFontImpl_get_Name,
176 OLEFontImpl_put_Name,
177 OLEFontImpl_get_Size,
178 OLEFontImpl_put_Size,
179 OLEFontImpl_get_Bold,
180 OLEFontImpl_put_Bold,
181 OLEFontImpl_get_Italic,
182 OLEFontImpl_put_Italic,
183 OLEFontImpl_get_Underline,
184 OLEFontImpl_put_Underline,
185 OLEFontImpl_get_Strikethrough,
186 OLEFontImpl_put_Strikethrough,
187 OLEFontImpl_get_Weight,
188 OLEFontImpl_put_Weight,
189 OLEFontImpl_get_Charset,
190 OLEFontImpl_put_Charset,
191 OLEFontImpl_get_hFont,
194 OLEFontImpl_SetRatio,
195 OLEFontImpl_QueryTextMetrics,
196 OLEFontImpl_AddRefHfont,
197 OLEFontImpl_ReleaseHfont,
201 static ICOM_VTABLE(IDispatch) OLEFontImpl_IDispatch_VTable =
203 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
204 OLEFontImpl_IDispatch_QueryInterface,
205 OLEFontImpl_IDispatch_AddRef,
206 OLEFontImpl_IDispatch_Release,
207 OLEFontImpl_GetTypeInfoCount,
208 OLEFontImpl_GetTypeInfo,
209 OLEFontImpl_GetIDsOfNames,
213 static ICOM_VTABLE(IPersistStream) OLEFontImpl_IPersistStream_VTable =
215 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
216 OLEFontImpl_IPersistStream_QueryInterface,
217 OLEFontImpl_IPersistStream_AddRef,
218 OLEFontImpl_IPersistStream_Release,
219 OLEFontImpl_GetClassID,
223 OLEFontImpl_GetSizeMax
226 /******************************************************************************
227 * OleCreateFontIndirect [OLEAUT32.420]
229 INT WINAPI OleCreateFontIndirect(
230 LPFONTDESC lpFontDesc,
234 OLEFontImpl* newFont = 0;
246 * Try to construct a new instance of the class.
248 newFont = OLEFontImpl_Construct(lpFontDesc);
251 return E_OUTOFMEMORY;
254 * Make sure it supports the interface required by the caller.
256 hr = IFont_QueryInterface((IFont*)newFont, riid, ppvObj);
259 * Release the reference obtained in the constructor. If
260 * the QueryInterface was unsuccessful, it will free the class.
262 IFont_Release((IFont*)newFont);
268 /***********************************************************************
269 * Implementation of the OLEFontImpl class.
272 /************************************************************************
273 * OLEFontImpl_Construct
275 * This method will construct a new instance of the OLEFontImpl
278 * The caller of this method must release the object when it's
281 static OLEFontImpl* OLEFontImpl_Construct(LPFONTDESC fontDesc)
283 OLEFontImpl* newObject = 0;
286 * Allocate space for the object.
288 newObject = HeapAlloc(GetProcessHeap(), 0, sizeof(OLEFontImpl));
294 * Initialize the virtual function table.
296 newObject->lpvtbl1 = &OLEFontImpl_VTable;
297 newObject->lpvtbl2 = &OLEFontImpl_IDispatch_VTable;
298 newObject->lpvtbl3 = &OLEFontImpl_IPersistStream_VTable;
301 * Start with one reference count. The caller of this function
302 * must release the interface pointer when it is done.
307 * Copy the description of the font in the object.
309 assert(fontDesc->cbSizeofstruct >= sizeof(FONTDESC));
311 newObject->description.cbSizeofstruct = sizeof(FONTDESC);
312 newObject->description.lpstrName = HeapAlloc(GetProcessHeap(),
314 (lstrlenW(fontDesc->lpstrName)+1) * sizeof(WCHAR));
315 lstrcpyW(newObject->description.lpstrName, fontDesc->lpstrName);
316 newObject->description.cySize = fontDesc->cySize;
317 newObject->description.sWeight = fontDesc->sWeight;
318 newObject->description.sCharset = fontDesc->sCharset;
319 newObject->description.fItalic = fontDesc->fItalic;
320 newObject->description.fUnderline = fontDesc->fUnderline;
321 newObject->description.fStrikethrough = fontDesc->fStrikethrough;
324 * Initializing all the other members.
326 newObject->gdiFont = 0;
327 newObject->fontLock = 0;
328 newObject->cyHimetric = 1;
329 newObject->cyLogical = 1;
334 /************************************************************************
335 * OLEFontImpl_Construct
337 * This method is called by the Release method when the reference
338 * count goes doen to 0. it will free all resources used by
341 static void OLEFontImpl_Destroy(OLEFontImpl* fontDesc)
343 if (fontDesc->description.lpstrName!=0)
344 HeapFree(GetProcessHeap(), 0, fontDesc->description.lpstrName);
346 if (fontDesc->gdiFont!=0)
347 DeleteObject(fontDesc->gdiFont);
349 HeapFree(GetProcessHeap(), 0, fontDesc);
352 /************************************************************************
353 * OLEFontImpl_QueryInterface (IUnknown)
355 * See Windows documentation for more details on IUnknown methods.
357 HRESULT WINAPI OLEFontImpl_QueryInterface(
362 _ICOM_THIS(OLEFontImpl, iface);
365 * Perform a sanity check on the parameters.
367 if ( (this==0) || (ppvObject==0) )
371 * Initialize the return parameter.
376 * Compare the riid with the interface IDs implemented by this object.
378 if (memcmp(&IID_IUnknown, riid, sizeof(IID_IUnknown)) == 0)
380 *ppvObject = (IFont*)this;
382 else if (memcmp(&IID_IFont, riid, sizeof(IID_IFont)) == 0)
384 *ppvObject = (IFont*)this;
386 else if (memcmp(&IID_IDispatch, riid, sizeof(IID_IDispatch)) == 0)
388 *ppvObject = (IDispatch*)&(this->lpvtbl2);
390 else if (memcmp(&IID_IFontDisp, riid, sizeof(IID_IFontDisp)) == 0)
392 *ppvObject = (IDispatch*)&(this->lpvtbl2);
394 else if (memcmp(&IID_IPersistStream, riid, sizeof(IID_IPersistStream)) == 0)
396 *ppvObject = (IPersistStream*)&(this->lpvtbl3);
400 * Check that we obtained an interface.
406 WINE_StringFromCLSID((LPCLSID)riid,clsid);
409 "() : asking for un supported interface %s\n",
412 return E_NOINTERFACE;
416 * Query Interface always increases the reference count by one when it is
419 OLEFontImpl_AddRef((IFont*)this);
424 /************************************************************************
425 * OLEFontImpl_AddRef (IUnknown)
427 * See Windows documentation for more details on IUnknown methods.
429 ULONG WINAPI OLEFontImpl_AddRef(
432 _ICOM_THIS(OLEFontImpl, iface);
439 /************************************************************************
440 * OLEFontImpl_Release (IUnknown)
442 * See Windows documentation for more details on IUnknown methods.
444 ULONG WINAPI OLEFontImpl_Release(
447 _ICOM_THIS(OLEFontImpl, iface);
450 * Decrease the reference count on this object.
455 * If the reference count goes down to 0, perform suicide.
459 OLEFontImpl_Destroy(this);
467 /************************************************************************
468 * OLEFontImpl_get_Name (IFont)
470 * See Windows documentation for more details on IFont methods.
472 static HRESULT WINAPI OLEFontImpl_get_Name(
476 _ICOM_THIS(OLEFontImpl, iface);
484 if (this->description.lpstrName!=0)
485 *pname = SysAllocString(this->description.lpstrName);
492 /************************************************************************
493 * OLEFontImpl_put_Name (IFont)
495 * See Windows documentation for more details on IFont methods.
497 static HRESULT WINAPI OLEFontImpl_put_Name(
501 _ICOM_THIS(OLEFontImpl, iface);
503 if (this->description.lpstrName==0)
505 this->description.lpstrName = HeapAlloc(GetProcessHeap(),
507 (lstrlenW(name)+1) * sizeof(WCHAR));
511 this->description.lpstrName = HeapReAlloc(GetProcessHeap(),
513 this->description.lpstrName,
514 (lstrlenW(name)+1) * sizeof(WCHAR));
517 if (this->description.lpstrName==0)
518 return E_OUTOFMEMORY;
520 lstrcpyW(this->description.lpstrName, name);
525 /************************************************************************
526 * OLEFontImpl_get_Size (IFont)
528 * See Windows documentation for more details on IFont methods.
530 static HRESULT WINAPI OLEFontImpl_get_Size(
534 _ICOM_THIS(OLEFontImpl, iface);
543 psize->u.Lo = this->description.cySize.u.Lo;
548 /************************************************************************
549 * OLEFontImpl_put_Size (IFont)
551 * See Windows documentation for more details on IFont methods.
553 static HRESULT WINAPI OLEFontImpl_put_Size(
557 _ICOM_THIS(OLEFontImpl, iface);
559 this->description.cySize.u.Hi = 0;
560 this->description.cySize.u.Lo = this->description.cySize.u.Lo;
565 /************************************************************************
566 * OLEFontImpl_get_Bold (IFont)
568 * See Windows documentation for more details on IFont methods.
570 static HRESULT WINAPI OLEFontImpl_get_Bold(
578 /************************************************************************
579 * OLEFontImpl_put_Bold (IFont)
581 * See Windows documentation for more details on IFont methods.
583 static HRESULT WINAPI OLEFontImpl_put_Bold(
591 /************************************************************************
592 * OLEFontImpl_get_Italic (IFont)
594 * See Windows documentation for more details on IFont methods.
596 static HRESULT WINAPI OLEFontImpl_get_Italic(
600 _ICOM_THIS(OLEFontImpl, iface);
608 *pitalic = this->description.fItalic;
613 /************************************************************************
614 * OLEFontImpl_put_Italic (IFont)
616 * See Windows documentation for more details on IFont methods.
618 static HRESULT WINAPI OLEFontImpl_put_Italic(
622 _ICOM_THIS(OLEFontImpl, iface);
624 this->description.fItalic = italic;
629 /************************************************************************
630 * OLEFontImpl_get_Underline (IFont)
632 * See Windows documentation for more details on IFont methods.
634 static HRESULT WINAPI OLEFontImpl_get_Underline(
638 _ICOM_THIS(OLEFontImpl, iface);
646 *punderline = this->description.fUnderline;
651 /************************************************************************
652 * OLEFontImpl_put_Underline (IFont)
654 * See Windows documentation for more details on IFont methods.
656 static HRESULT WINAPI OLEFontImpl_put_Underline(
660 _ICOM_THIS(OLEFontImpl, iface);
662 this->description.fUnderline = underline;
667 /************************************************************************
668 * OLEFontImpl_get_Strikethrough (IFont)
670 * See Windows documentation for more details on IFont methods.
672 static HRESULT WINAPI OLEFontImpl_get_Strikethrough(
674 BOOL* pstrikethrough)
676 _ICOM_THIS(OLEFontImpl, iface);
681 if (pstrikethrough==0)
684 *pstrikethrough = this->description.fStrikethrough;
689 /************************************************************************
690 * OLEFontImpl_put_Strikethrough (IFont)
692 * See Windows documentation for more details on IFont methods.
694 static HRESULT WINAPI OLEFontImpl_put_Strikethrough(
698 _ICOM_THIS(OLEFontImpl, iface);
700 this->description.fStrikethrough = strikethrough;
705 /************************************************************************
706 * OLEFontImpl_get_Weight (IFont)
708 * See Windows documentation for more details on IFont methods.
710 static HRESULT WINAPI OLEFontImpl_get_Weight(
714 _ICOM_THIS(OLEFontImpl, iface);
722 *pweight = this->description.sWeight;
727 /************************************************************************
728 * OLEFontImpl_put_Weight (IFont)
730 * See Windows documentation for more details on IFont methods.
732 static HRESULT WINAPI OLEFontImpl_put_Weight(
736 _ICOM_THIS(OLEFontImpl, iface);
738 this->description.sWeight = weight;
743 /************************************************************************
744 * OLEFontImpl_get_Charset (IFont)
746 * See Windows documentation for more details on IFont methods.
748 static HRESULT WINAPI OLEFontImpl_get_Charset(
752 _ICOM_THIS(OLEFontImpl, iface);
760 *pcharset = this->description.sCharset;
765 /************************************************************************
766 * OLEFontImpl_put_Charset (IFont)
768 * See Windows documentation for more details on IFont methods.
770 static HRESULT WINAPI OLEFontImpl_put_Charset(
774 _ICOM_THIS(OLEFontImpl, iface);
776 this->description.sCharset = charset;
781 /************************************************************************
782 * OLEFontImpl_get_hFont (IFont)
784 * See Windows documentation for more details on IFont methods.
786 static HRESULT WINAPI OLEFontImpl_get_hFont(
790 _ICOM_THIS(OLEFontImpl, iface);
796 * Realize the font if necessary
798 if (this->gdiFont==0)
805 * The height of the font returned by the get_Size property is the
806 * height of the font in points multiplied by 10000... Using some
807 * simple conversions and the ratio given by the application, it can
808 * be converted to a height in pixels.
810 IFont_get_Size(iface, &cySize);
812 fontHeight = MulDiv(cySize.u.Lo, 2540L, 72L);
813 fontHeight = MulDiv(fontHeight, this->cyLogical,this->cyHimetric);
815 memset(&logFont, 0, sizeof(LOGFONTW));
817 logFont.lfHeight = ((fontHeight%10000L)>5000L) ? (-fontHeight/10000L)-1 :
818 (-fontHeight/10000L);
819 logFont.lfItalic = this->description.fItalic;
820 logFont.lfUnderline = this->description.fUnderline;
821 logFont.lfStrikeOut = this->description.fStrikethrough;
822 logFont.lfWeight = this->description.sWeight;
823 logFont.lfCharSet = this->description.sCharset;
824 logFont.lfOutPrecision = OUT_CHARACTER_PRECIS;
825 logFont.lfClipPrecision = CLIP_DEFAULT_PRECIS;
826 logFont.lfQuality = DEFAULT_QUALITY;
827 logFont.lfPitchAndFamily = DEFAULT_PITCH;
828 lstrcpyW(logFont.lfFaceName,this->description.lpstrName);
830 this->gdiFont = CreateFontIndirectW(&logFont);
833 *phfont = this->gdiFont;
838 /************************************************************************
839 * OLEFontImpl_Clone (IFont)
841 * See Windows documentation for more details on IFont methods.
843 static HRESULT WINAPI OLEFontImpl_Clone(
847 OLEFontImpl* newObject = 0;
849 _ICOM_THIS(OLEFontImpl, iface);
857 * Allocate space for the object.
859 newObject = HeapAlloc(GetProcessHeap(), 0, sizeof(OLEFontImpl));
862 return E_OUTOFMEMORY;
867 * That new object starts with a reference count of 1
871 *ppfont = (IFont*)newObject;
876 /************************************************************************
877 * OLEFontImpl_IsEqual (IFont)
879 * See Windows documentation for more details on IFont methods.
881 static HRESULT WINAPI OLEFontImpl_IsEqual(
889 /************************************************************************
890 * OLEFontImpl_SetRatio (IFont)
892 * See Windows documentation for more details on IFont methods.
894 static HRESULT WINAPI OLEFontImpl_SetRatio(
899 _ICOM_THIS(OLEFontImpl, iface);
901 this->cyLogical = cyLogical;
902 this->cyHimetric = cyHimetric;
907 /************************************************************************
908 * OLEFontImpl_QueryTextMetrics (IFont)
910 * See Windows documentation for more details on IFont methods.
912 static HRESULT WINAPI OLEFontImpl_QueryTextMetrics(
920 /************************************************************************
921 * OLEFontImpl_AddRefHfont (IFont)
923 * See Windows documentation for more details on IFont methods.
925 static HRESULT WINAPI OLEFontImpl_AddRefHfont(
929 _ICOM_THIS(OLEFontImpl, iface);
932 (hfont != this->gdiFont) )
940 /************************************************************************
941 * OLEFontImpl_ReleaseHfont (IFont)
943 * See Windows documentation for more details on IFont methods.
945 static HRESULT WINAPI OLEFontImpl_ReleaseHfont(
949 _ICOM_THIS(OLEFontImpl, iface);
952 (hfont != this->gdiFont) )
958 * If we just released our last font reference, destroy it.
960 if (this->fontLock==0)
962 DeleteObject(this->gdiFont);
969 /************************************************************************
970 * OLEFontImpl_SetHdc (IFont)
972 * See Windows documentation for more details on IFont methods.
974 static HRESULT WINAPI OLEFontImpl_SetHdc(
982 /************************************************************************
983 * OLEFontImpl_IDispatch_QueryInterface (IUnknown)
985 * See Windows documentation for more details on IUnknown methods.
987 static HRESULT WINAPI OLEFontImpl_IDispatch_QueryInterface(
992 _ICOM_THIS_From_IDispatch(IFont, iface);
994 return IFont_QueryInterface(this, riid, ppvoid);
997 /************************************************************************
998 * OLEFontImpl_IDispatch_Release (IUnknown)
1000 * See Windows documentation for more details on IUnknown methods.
1002 static ULONG WINAPI OLEFontImpl_IDispatch_Release(
1005 _ICOM_THIS_From_IDispatch(IFont, iface);
1007 return IFont_Release(this);
1010 /************************************************************************
1011 * OLEFontImpl_IDispatch_AddRef (IUnknown)
1013 * See Windows documentation for more details on IUnknown methods.
1015 static ULONG WINAPI OLEFontImpl_IDispatch_AddRef(
1018 _ICOM_THIS_From_IDispatch(IFont, iface);
1020 return IFont_AddRef(this);
1023 /************************************************************************
1024 * OLEFontImpl_GetTypeInfoCount (IDispatch)
1026 * See Windows documentation for more details on IDispatch methods.
1028 static HRESULT WINAPI OLEFontImpl_GetTypeInfoCount(
1030 unsigned int* pctinfo)
1037 /************************************************************************
1038 * OLEFontImpl_GetTypeInfo (IDispatch)
1040 * See Windows documentation for more details on IDispatch methods.
1042 static HRESULT WINAPI OLEFontImpl_GetTypeInfo(
1046 ITypeInfo** ppTInfo)
1053 /************************************************************************
1054 * OLEFontImpl_GetIDsOfNames (IDispatch)
1056 * See Windows documentation for more details on IDispatch methods.
1058 static HRESULT WINAPI OLEFontImpl_GetIDsOfNames(
1061 LPOLESTR* rgszNames,
1071 /************************************************************************
1072 * OLEFontImpl_Invoke (IDispatch)
1074 * See Windows documentation for more details on IDispatch methods.
1076 static HRESULT WINAPI OLEFontImpl_Invoke(
1078 DISPID dispIdMember,
1082 DISPPARAMS* pDispParams,
1083 VARIANT* pVarResult,
1084 EXCEPINFO* pExepInfo,
1092 /************************************************************************
1093 * OLEFontImpl_IPersistStream_QueryInterface (IUnknown)
1095 * See Windows documentation for more details on IUnknown methods.
1097 static HRESULT WINAPI OLEFontImpl_IPersistStream_QueryInterface(
1098 IPersistStream* iface,
1102 _ICOM_THIS_From_IPersistStream(IFont, iface);
1104 return IFont_QueryInterface(this, riid, ppvoid);
1107 /************************************************************************
1108 * OLEFontImpl_IPersistStream_Release (IUnknown)
1110 * See Windows documentation for more details on IUnknown methods.
1112 static ULONG WINAPI OLEFontImpl_IPersistStream_Release(
1113 IPersistStream* iface)
1115 _ICOM_THIS_From_IPersistStream(IFont, iface);
1117 return IFont_Release(this);
1120 /************************************************************************
1121 * OLEFontImpl_IPersistStream_AddRef (IUnknown)
1123 * See Windows documentation for more details on IUnknown methods.
1125 static ULONG WINAPI OLEFontImpl_IPersistStream_AddRef(
1126 IPersistStream* iface)
1128 _ICOM_THIS_From_IPersistStream(IFont, iface);
1130 return IFont_AddRef(this);
1133 /************************************************************************
1134 * OLEFontImpl_GetClassID (IPersistStream)
1136 * See Windows documentation for more details on IPersistStream methods.
1138 static HRESULT WINAPI OLEFontImpl_GetClassID(
1139 IPersistStream* iface,
1145 memcpy(pClassID, &CLSID_StdFont, sizeof(CLSID_StdFont));
1150 /************************************************************************
1151 * OLEFontImpl_IsDirty (IPersistStream)
1153 * See Windows documentation for more details on IPersistStream methods.
1155 static HRESULT WINAPI OLEFontImpl_IsDirty(
1156 IPersistStream* iface)
1161 /************************************************************************
1162 * OLEFontImpl_Load (IPersistStream)
1164 * See Windows documentation for more details on IPersistStream methods.
1166 * This is the format of the standard font serialization as far as I
1169 * Offset Type Value Comment
1170 * 0x0000 Byte Unknown Probably a version number, contains 0x01
1171 * 0x0001 Short Charset Charset value from the FONTDESC structure
1172 * 0x0003 Byte Attributes Flags defined as follows:
1174 * 00000100 - Underline
1175 * 00001000 - Strikethrough
1176 * 0x0004 Short Weight Weight value from FONTDESC structure
1177 * 0x0006 DWORD size "Low" portion of the cySize member of the FONTDESC
1179 * 0x000A Byte name length Length of the font name string (no null character)
1180 * 0x000B String name Name of the font (ASCII, no nul character)
1182 static HRESULT WINAPI OLEFontImpl_Load(
1183 IPersistStream* iface,
1184 IStream* pLoadStream)
1186 char readBuffer[0x100];
1192 _ICOM_THIS_From_IPersistStream(OLEFontImpl, iface);
1195 * Read the version byte
1197 IStream_Read(pLoadStream, &bVersion, 1, &cbRead);
1206 IStream_Read(pLoadStream, &this->description.sCharset, 2, &cbRead);
1214 IStream_Read(pLoadStream, &bAttributes, 1, &cbRead);
1219 this->description.fItalic = (bAttributes & FONTPERSIST_ITALIC) != 0;
1220 this->description.fStrikethrough = (bAttributes & FONTPERSIST_STRIKETHROUGH) != 0;
1221 this->description.fUnderline = (bAttributes & FONTPERSIST_UNDERLINE) != 0;
1226 IStream_Read(pLoadStream, &this->description.sWeight, 2, &cbRead);
1234 IStream_Read(pLoadStream, &this->description.cySize.u.Lo, 4, &cbRead);
1239 this->description.cySize.u.Hi = 0;
1244 IStream_Read(pLoadStream, &bStringSize, 1, &cbRead);
1249 memset(readBuffer, 0, 0x100);
1250 IStream_Read(pLoadStream, readBuffer, bStringSize, &cbRead);
1252 if (cbRead!=bStringSize)
1255 if (this->description.lpstrName!=0)
1256 HeapFree(GetProcessHeap(), 0, this->description.lpstrName);
1258 this->description.lpstrName = HEAP_strdupAtoW(GetProcessHeap(),
1265 /************************************************************************
1266 * OLEFontImpl_Save (IPersistStream)
1268 * See Windows documentation for more details on IPersistStream methods.
1270 static HRESULT WINAPI OLEFontImpl_Save(
1271 IPersistStream* iface,
1272 IStream* pOutStream,
1275 char* writeBuffer = NULL;
1277 BYTE bVersion = 0x01;
1281 _ICOM_THIS_From_IPersistStream(OLEFontImpl, iface);
1284 * Read the version byte
1286 IStream_Write(pOutStream, &bVersion, 1, &cbWritten);
1294 IStream_Write(pOutStream, &this->description.sCharset, 2, &cbWritten);
1304 if (this->description.fItalic)
1305 bAttributes |= FONTPERSIST_ITALIC;
1307 if (this->description.fStrikethrough)
1308 bAttributes |= FONTPERSIST_STRIKETHROUGH;
1310 if (this->description.fUnderline)
1311 bAttributes |= FONTPERSIST_UNDERLINE;
1313 IStream_Write(pOutStream, &bAttributes, 1, &cbWritten);
1321 IStream_Write(pOutStream, &this->description.sWeight, 2, &cbWritten);
1329 IStream_Write(pOutStream, &this->description.cySize.u.Lo, 4, &cbWritten);
1337 if (this->description.lpstrName!=0)
1338 bStringSize = lstrlenW(this->description.lpstrName);
1342 IStream_Write(pOutStream, &bStringSize, 1, &cbWritten);
1349 writeBuffer = HEAP_strdupWtoA(GetProcessHeap(),
1351 this->description.lpstrName);
1354 return E_OUTOFMEMORY;
1356 IStream_Write(pOutStream, writeBuffer, bStringSize, &cbWritten);
1358 HeapFree(GetProcessHeap(), 0, writeBuffer);
1360 if (cbWritten!=bStringSize)
1367 /************************************************************************
1368 * OLEFontImpl_GetSizeMax (IPersistStream)
1370 * See Windows documentation for more details on IPersistStream methods.
1372 static HRESULT WINAPI OLEFontImpl_GetSizeMax(
1373 IPersistStream* iface,
1374 ULARGE_INTEGER* pcbSize)
1376 _ICOM_THIS_From_IPersistStream(OLEFontImpl, iface);
1381 pcbSize->HighPart = 0;
1382 pcbSize->LowPart = 0;
1384 pcbSize->LowPart += sizeof(BYTE); /* Version */
1385 pcbSize->LowPart += sizeof(WORD); /* Lang code */
1386 pcbSize->LowPart += sizeof(BYTE); /* Flags */
1387 pcbSize->LowPart += sizeof(WORD); /* Weight */
1388 pcbSize->LowPart += sizeof(DWORD); /* Size */
1389 pcbSize->LowPart += sizeof(BYTE); /* StrLength */
1391 if (this->description.lpstrName!=0)
1392 pcbSize->LowPart += lstrlenW(this->description.lpstrName);