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
12 #include "oleauto.h" /* for SysAllocString(....) */
13 #include "wine/obj_olefont.h"
14 #include "wine/obj_storage.h"
16 #include "debugtools.h"
19 DEFAULT_DEBUG_CHANNEL(ole)
21 /***********************************************************************
22 * Declaration of constants used when serializing the font object.
24 #define FONTPERSIST_ITALIC 0x02
25 #define FONTPERSIST_UNDERLINE 0x04
26 #define FONTPERSIST_STRIKETHROUGH 0x08
28 /***********************************************************************
29 * Declaration of the implementation class for the IFont interface
31 typedef struct OLEFontImpl OLEFontImpl;
36 * This class supports many interfaces. IUnknown, IFont,
37 * IDispatch, IDispFont and IPersistStream. The first two are
38 * supported by the first vtablem the next two are supported by
39 * the second table and the last one has it's own.
41 ICOM_VTABLE(IFont)* lpvtbl1;
42 ICOM_VTABLE(IDispatch)* lpvtbl2;
43 ICOM_VTABLE(IPersistStream)* lpvtbl3;
46 * Reference count for that instance of the class.
51 * This structure contains the description of the class.
56 * Contain the font associated with this object.
73 * Here, I define utility macros to help with the casting of the
75 * There is a version to accomodate all of the VTables implemented
78 #define _ICOM_THIS(class,name) class* this = (class*)name;
79 #define _ICOM_THIS_From_IDispatch(class, name) class* this = (class*)(((char*)name)-sizeof(void*));
80 #define _ICOM_THIS_From_IPersistStream(class, name) class* this = (class*)(((char*)name)-2*sizeof(void*));
82 /***********************************************************************
83 * Prototypes for the implementation functions for the IFont
86 static OLEFontImpl* OLEFontImpl_Construct(LPFONTDESC fontDesc);
87 static void OLEFontImpl_Destroy(OLEFontImpl* fontDesc);
88 static HRESULT WINAPI OLEFontImpl_QueryInterface(IFont* iface, REFIID riid, VOID** ppvoid);
89 static ULONG WINAPI OLEFontImpl_AddRef(IFont* iface);
90 static ULONG WINAPI OLEFontImpl_Release(IFont* iface);
91 static HRESULT WINAPI OLEFontImpl_get_Name(IFont* iface, BSTR* pname);
92 static HRESULT WINAPI OLEFontImpl_put_Name(IFont* iface, BSTR name);
93 static HRESULT WINAPI OLEFontImpl_get_Size(IFont* iface, CY* psize);
94 static HRESULT WINAPI OLEFontImpl_put_Size(IFont* iface, CY size);
95 static HRESULT WINAPI OLEFontImpl_get_Bold(IFont* iface, BOOL* pbold);
96 static HRESULT WINAPI OLEFontImpl_put_Bold(IFont* iface, BOOL bold);
97 static HRESULT WINAPI OLEFontImpl_get_Italic(IFont* iface, BOOL* pitalic);
98 static HRESULT WINAPI OLEFontImpl_put_Italic(IFont* iface, BOOL italic);
99 static HRESULT WINAPI OLEFontImpl_get_Underline(IFont* iface, BOOL* punderline);
100 static HRESULT WINAPI OLEFontImpl_put_Underline(IFont* iface, BOOL underline);
101 static HRESULT WINAPI OLEFontImpl_get_Strikethrough(IFont* iface, BOOL* pstrikethrough);
102 static HRESULT WINAPI OLEFontImpl_put_Strikethrough(IFont* iface, BOOL strikethrough);
103 static HRESULT WINAPI OLEFontImpl_get_Weight(IFont* iface, short* pweight);
104 static HRESULT WINAPI OLEFontImpl_put_Weight(IFont* iface, short weight);
105 static HRESULT WINAPI OLEFontImpl_get_Charset(IFont* iface, short* pcharset);
106 static HRESULT WINAPI OLEFontImpl_put_Charset(IFont* iface, short charset);
107 static HRESULT WINAPI OLEFontImpl_get_hFont(IFont* iface, HFONT* phfont);
108 static HRESULT WINAPI OLEFontImpl_Clone(IFont* iface, IFont** ppfont);
109 static HRESULT WINAPI OLEFontImpl_IsEqual(IFont* iface, IFont* pFontOther);
110 static HRESULT WINAPI OLEFontImpl_SetRatio(IFont* iface, long cyLogical, long cyHimetric);
111 static HRESULT WINAPI OLEFontImpl_QueryTextMetrics(IFont* iface, TEXTMETRICOLE* ptm);
112 static HRESULT WINAPI OLEFontImpl_AddRefHfont(IFont* iface, HFONT hfont);
113 static HRESULT WINAPI OLEFontImpl_ReleaseHfont(IFont* iface, HFONT hfont);
114 static HRESULT WINAPI OLEFontImpl_SetHdc(IFont* iface, HDC hdc);
116 /***********************************************************************
117 * Prototypes for the implementation functions for the IDispatch
120 static HRESULT WINAPI OLEFontImpl_IDispatch_QueryInterface(IDispatch* iface,
123 static ULONG WINAPI OLEFontImpl_IDispatch_AddRef(IDispatch* iface);
124 static ULONG WINAPI OLEFontImpl_IDispatch_Release(IDispatch* iface);
125 static HRESULT WINAPI OLEFontImpl_GetTypeInfoCount(IDispatch* iface,
126 unsigned int* pctinfo);
127 static HRESULT WINAPI OLEFontImpl_GetTypeInfo(IDispatch* iface,
130 ITypeInfo** ppTInfo);
131 static HRESULT WINAPI OLEFontImpl_GetIDsOfNames(IDispatch* iface,
137 static HRESULT WINAPI OLEFontImpl_Invoke(IDispatch* iface,
142 DISPPARAMS* pDispParams,
144 EXCEPINFO* pExepInfo,
147 /***********************************************************************
148 * Prototypes for the implementation functions for the IPersistStream
151 static HRESULT WINAPI OLEFontImpl_IPersistStream_QueryInterface(IPersistStream* iface,
154 static ULONG WINAPI OLEFontImpl_IPersistStream_AddRef(IPersistStream* iface);
155 static ULONG WINAPI OLEFontImpl_IPersistStream_Release(IPersistStream* iface);
156 static HRESULT WINAPI OLEFontImpl_GetClassID(IPersistStream* iface,
158 static HRESULT WINAPI OLEFontImpl_IsDirty(IPersistStream* iface);
159 static HRESULT WINAPI OLEFontImpl_Load(IPersistStream* iface,
160 IStream* pLoadStream);
161 static HRESULT WINAPI OLEFontImpl_Save(IPersistStream* iface,
164 static HRESULT WINAPI OLEFontImpl_GetSizeMax(IPersistStream* iface,
165 ULARGE_INTEGER* pcbSize);
168 * Virtual function tables for the OLEFontImpl class.
170 static ICOM_VTABLE(IFont) OLEFontImpl_VTable =
172 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
173 OLEFontImpl_QueryInterface,
176 OLEFontImpl_get_Name,
177 OLEFontImpl_put_Name,
178 OLEFontImpl_get_Size,
179 OLEFontImpl_put_Size,
180 OLEFontImpl_get_Bold,
181 OLEFontImpl_put_Bold,
182 OLEFontImpl_get_Italic,
183 OLEFontImpl_put_Italic,
184 OLEFontImpl_get_Underline,
185 OLEFontImpl_put_Underline,
186 OLEFontImpl_get_Strikethrough,
187 OLEFontImpl_put_Strikethrough,
188 OLEFontImpl_get_Weight,
189 OLEFontImpl_put_Weight,
190 OLEFontImpl_get_Charset,
191 OLEFontImpl_put_Charset,
192 OLEFontImpl_get_hFont,
195 OLEFontImpl_SetRatio,
196 OLEFontImpl_QueryTextMetrics,
197 OLEFontImpl_AddRefHfont,
198 OLEFontImpl_ReleaseHfont,
202 static ICOM_VTABLE(IDispatch) OLEFontImpl_IDispatch_VTable =
204 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
205 OLEFontImpl_IDispatch_QueryInterface,
206 OLEFontImpl_IDispatch_AddRef,
207 OLEFontImpl_IDispatch_Release,
208 OLEFontImpl_GetTypeInfoCount,
209 OLEFontImpl_GetTypeInfo,
210 OLEFontImpl_GetIDsOfNames,
214 static ICOM_VTABLE(IPersistStream) OLEFontImpl_IPersistStream_VTable =
216 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
217 OLEFontImpl_IPersistStream_QueryInterface,
218 OLEFontImpl_IPersistStream_AddRef,
219 OLEFontImpl_IPersistStream_Release,
220 OLEFontImpl_GetClassID,
224 OLEFontImpl_GetSizeMax
227 /******************************************************************************
228 * OleCreateFontIndirect [OLEAUT32.420]
230 INT WINAPI OleCreateFontIndirect(
231 LPFONTDESC lpFontDesc,
235 OLEFontImpl* newFont = 0;
247 * Try to construct a new instance of the class.
249 newFont = OLEFontImpl_Construct(lpFontDesc);
252 return E_OUTOFMEMORY;
255 * Make sure it supports the interface required by the caller.
257 hr = IFont_QueryInterface((IFont*)newFont, riid, ppvObj);
260 * Release the reference obtained in the constructor. If
261 * the QueryInterface was unsuccessful, it will free the class.
263 IFont_Release((IFont*)newFont);
269 /***********************************************************************
270 * Implementation of the OLEFontImpl class.
273 /************************************************************************
274 * OLEFontImpl_Construct
276 * This method will construct a new instance of the OLEFontImpl
279 * The caller of this method must release the object when it's
282 static OLEFontImpl* OLEFontImpl_Construct(LPFONTDESC fontDesc)
284 OLEFontImpl* newObject = 0;
287 * Allocate space for the object.
289 newObject = HeapAlloc(GetProcessHeap(), 0, sizeof(OLEFontImpl));
295 * Initialize the virtual function table.
297 newObject->lpvtbl1 = &OLEFontImpl_VTable;
298 newObject->lpvtbl2 = &OLEFontImpl_IDispatch_VTable;
299 newObject->lpvtbl3 = &OLEFontImpl_IPersistStream_VTable;
302 * Start with one reference count. The caller of this function
303 * must release the interface pointer when it is done.
308 * Copy the description of the font in the object.
310 assert(fontDesc->cbSizeofstruct >= sizeof(FONTDESC));
312 newObject->description.cbSizeofstruct = sizeof(FONTDESC);
313 newObject->description.lpstrName = HeapAlloc(GetProcessHeap(),
315 (lstrlenW(fontDesc->lpstrName)+1) * sizeof(WCHAR));
316 lstrcpyW(newObject->description.lpstrName, fontDesc->lpstrName);
317 newObject->description.cySize = fontDesc->cySize;
318 newObject->description.sWeight = fontDesc->sWeight;
319 newObject->description.sCharset = fontDesc->sCharset;
320 newObject->description.fItalic = fontDesc->fItalic;
321 newObject->description.fUnderline = fontDesc->fUnderline;
322 newObject->description.fStrikethrough = fontDesc->fStrikethrough;
325 * Initializing all the other members.
327 newObject->gdiFont = 0;
328 newObject->fontLock = 0;
329 newObject->cyHimetric = 1;
330 newObject->cyLogical = 1;
335 /************************************************************************
336 * OLEFontImpl_Construct
338 * This method is called by the Release method when the reference
339 * count goes doen to 0. it will free all resources used by
342 static void OLEFontImpl_Destroy(OLEFontImpl* fontDesc)
344 if (fontDesc->description.lpstrName!=0)
345 HeapFree(GetProcessHeap(), 0, fontDesc->description.lpstrName);
347 if (fontDesc->gdiFont!=0)
348 DeleteObject(fontDesc->gdiFont);
350 HeapFree(GetProcessHeap(), 0, fontDesc);
353 /************************************************************************
354 * OLEFontImpl_QueryInterface (IUnknown)
356 * See Windows documentation for more details on IUnknown methods.
358 HRESULT WINAPI OLEFontImpl_QueryInterface(
363 _ICOM_THIS(OLEFontImpl, iface);
366 * Perform a sanity check on the parameters.
368 if ( (this==0) || (ppvObject==0) )
372 * Initialize the return parameter.
377 * Compare the riid with the interface IDs implemented by this object.
379 if (memcmp(&IID_IUnknown, riid, sizeof(IID_IUnknown)) == 0)
381 *ppvObject = (IFont*)this;
383 else if (memcmp(&IID_IFont, riid, sizeof(IID_IFont)) == 0)
385 *ppvObject = (IFont*)this;
387 else if (memcmp(&IID_IDispatch, riid, sizeof(IID_IDispatch)) == 0)
389 *ppvObject = (IDispatch*)&(this->lpvtbl2);
391 else if (memcmp(&IID_IFontDisp, riid, sizeof(IID_IFontDisp)) == 0)
393 *ppvObject = (IDispatch*)&(this->lpvtbl2);
395 else if (memcmp(&IID_IPersistStream, riid, sizeof(IID_IPersistStream)) == 0)
397 *ppvObject = (IPersistStream*)&(this->lpvtbl3);
401 * Check that we obtained an interface.
407 WINE_StringFromCLSID((LPCLSID)riid,clsid);
410 "() : asking for un supported interface %s\n",
413 return E_NOINTERFACE;
417 * Query Interface always increases the reference count by one when it is
420 OLEFontImpl_AddRef((IFont*)this);
425 /************************************************************************
426 * OLEFontImpl_AddRef (IUnknown)
428 * See Windows documentation for more details on IUnknown methods.
430 ULONG WINAPI OLEFontImpl_AddRef(
433 _ICOM_THIS(OLEFontImpl, iface);
440 /************************************************************************
441 * OLEFontImpl_Release (IUnknown)
443 * See Windows documentation for more details on IUnknown methods.
445 ULONG WINAPI OLEFontImpl_Release(
448 _ICOM_THIS(OLEFontImpl, iface);
451 * Decrease the reference count on this object.
456 * If the reference count goes down to 0, perform suicide.
460 OLEFontImpl_Destroy(this);
468 /************************************************************************
469 * OLEFontImpl_get_Name (IFont)
471 * See Windows documentation for more details on IFont methods.
473 static HRESULT WINAPI OLEFontImpl_get_Name(
477 _ICOM_THIS(OLEFontImpl, iface);
485 if (this->description.lpstrName!=0)
486 *pname = SysAllocString(this->description.lpstrName);
493 /************************************************************************
494 * OLEFontImpl_put_Name (IFont)
496 * See Windows documentation for more details on IFont methods.
498 static HRESULT WINAPI OLEFontImpl_put_Name(
502 _ICOM_THIS(OLEFontImpl, iface);
504 if (this->description.lpstrName==0)
506 this->description.lpstrName = HeapAlloc(GetProcessHeap(),
508 (lstrlenW(name)+1) * sizeof(WCHAR));
512 this->description.lpstrName = HeapReAlloc(GetProcessHeap(),
514 this->description.lpstrName,
515 (lstrlenW(name)+1) * sizeof(WCHAR));
518 if (this->description.lpstrName==0)
519 return E_OUTOFMEMORY;
521 lstrcpyW(this->description.lpstrName, name);
526 /************************************************************************
527 * OLEFontImpl_get_Size (IFont)
529 * See Windows documentation for more details on IFont methods.
531 static HRESULT WINAPI OLEFontImpl_get_Size(
535 _ICOM_THIS(OLEFontImpl, iface);
544 psize->u.Lo = this->description.cySize.u.Lo;
549 /************************************************************************
550 * OLEFontImpl_put_Size (IFont)
552 * See Windows documentation for more details on IFont methods.
554 static HRESULT WINAPI OLEFontImpl_put_Size(
558 _ICOM_THIS(OLEFontImpl, iface);
560 this->description.cySize.u.Hi = 0;
561 this->description.cySize.u.Lo = this->description.cySize.u.Lo;
566 /************************************************************************
567 * OLEFontImpl_get_Bold (IFont)
569 * See Windows documentation for more details on IFont methods.
571 static HRESULT WINAPI OLEFontImpl_get_Bold(
579 /************************************************************************
580 * OLEFontImpl_put_Bold (IFont)
582 * See Windows documentation for more details on IFont methods.
584 static HRESULT WINAPI OLEFontImpl_put_Bold(
592 /************************************************************************
593 * OLEFontImpl_get_Italic (IFont)
595 * See Windows documentation for more details on IFont methods.
597 static HRESULT WINAPI OLEFontImpl_get_Italic(
601 _ICOM_THIS(OLEFontImpl, iface);
609 *pitalic = this->description.fItalic;
614 /************************************************************************
615 * OLEFontImpl_put_Italic (IFont)
617 * See Windows documentation for more details on IFont methods.
619 static HRESULT WINAPI OLEFontImpl_put_Italic(
623 _ICOM_THIS(OLEFontImpl, iface);
625 this->description.fItalic = italic;
630 /************************************************************************
631 * OLEFontImpl_get_Underline (IFont)
633 * See Windows documentation for more details on IFont methods.
635 static HRESULT WINAPI OLEFontImpl_get_Underline(
639 _ICOM_THIS(OLEFontImpl, iface);
647 *punderline = this->description.fUnderline;
652 /************************************************************************
653 * OLEFontImpl_put_Underline (IFont)
655 * See Windows documentation for more details on IFont methods.
657 static HRESULT WINAPI OLEFontImpl_put_Underline(
661 _ICOM_THIS(OLEFontImpl, iface);
663 this->description.fUnderline = underline;
668 /************************************************************************
669 * OLEFontImpl_get_Strikethrough (IFont)
671 * See Windows documentation for more details on IFont methods.
673 static HRESULT WINAPI OLEFontImpl_get_Strikethrough(
675 BOOL* pstrikethrough)
677 _ICOM_THIS(OLEFontImpl, iface);
682 if (pstrikethrough==0)
685 *pstrikethrough = this->description.fStrikethrough;
690 /************************************************************************
691 * OLEFontImpl_put_Strikethrough (IFont)
693 * See Windows documentation for more details on IFont methods.
695 static HRESULT WINAPI OLEFontImpl_put_Strikethrough(
699 _ICOM_THIS(OLEFontImpl, iface);
701 this->description.fStrikethrough = strikethrough;
706 /************************************************************************
707 * OLEFontImpl_get_Weight (IFont)
709 * See Windows documentation for more details on IFont methods.
711 static HRESULT WINAPI OLEFontImpl_get_Weight(
715 _ICOM_THIS(OLEFontImpl, iface);
723 *pweight = this->description.sWeight;
728 /************************************************************************
729 * OLEFontImpl_put_Weight (IFont)
731 * See Windows documentation for more details on IFont methods.
733 static HRESULT WINAPI OLEFontImpl_put_Weight(
737 _ICOM_THIS(OLEFontImpl, iface);
739 this->description.sWeight = weight;
744 /************************************************************************
745 * OLEFontImpl_get_Charset (IFont)
747 * See Windows documentation for more details on IFont methods.
749 static HRESULT WINAPI OLEFontImpl_get_Charset(
753 _ICOM_THIS(OLEFontImpl, iface);
761 *pcharset = this->description.sCharset;
766 /************************************************************************
767 * OLEFontImpl_put_Charset (IFont)
769 * See Windows documentation for more details on IFont methods.
771 static HRESULT WINAPI OLEFontImpl_put_Charset(
775 _ICOM_THIS(OLEFontImpl, iface);
777 this->description.sCharset = charset;
782 /************************************************************************
783 * OLEFontImpl_get_hFont (IFont)
785 * See Windows documentation for more details on IFont methods.
787 static HRESULT WINAPI OLEFontImpl_get_hFont(
791 _ICOM_THIS(OLEFontImpl, iface);
797 * Realize the font if necessary
799 if (this->gdiFont==0)
806 * The height of the font returned by the get_Size property is the
807 * height of the font in points multiplied by 10000... Using some
808 * simple conversions and the ratio given by the application, it can
809 * be converted to a height in pixels.
811 IFont_get_Size(iface, &cySize);
813 fontHeight = MulDiv(cySize.u.Lo, 2540L, 72L);
814 fontHeight = MulDiv(fontHeight, this->cyLogical,this->cyHimetric);
816 memset(&logFont, 0, sizeof(LOGFONTW));
818 logFont.lfHeight = ((fontHeight%10000L)>5000L) ? (-fontHeight/10000L)-1 :
819 (-fontHeight/10000L);
820 logFont.lfItalic = this->description.fItalic;
821 logFont.lfUnderline = this->description.fUnderline;
822 logFont.lfStrikeOut = this->description.fStrikethrough;
823 logFont.lfWeight = this->description.sWeight;
824 logFont.lfCharSet = this->description.sCharset;
825 logFont.lfOutPrecision = OUT_CHARACTER_PRECIS;
826 logFont.lfClipPrecision = CLIP_DEFAULT_PRECIS;
827 logFont.lfQuality = DEFAULT_QUALITY;
828 logFont.lfPitchAndFamily = DEFAULT_PITCH;
829 lstrcpyW(logFont.lfFaceName,this->description.lpstrName);
831 this->gdiFont = CreateFontIndirectW(&logFont);
834 *phfont = this->gdiFont;
839 /************************************************************************
840 * OLEFontImpl_Clone (IFont)
842 * See Windows documentation for more details on IFont methods.
844 static HRESULT WINAPI OLEFontImpl_Clone(
848 OLEFontImpl* newObject = 0;
850 _ICOM_THIS(OLEFontImpl, iface);
858 * Allocate space for the object.
860 newObject = HeapAlloc(GetProcessHeap(), 0, sizeof(OLEFontImpl));
863 return E_OUTOFMEMORY;
868 * That new object starts with a reference count of 1
872 *ppfont = (IFont*)newObject;
877 /************************************************************************
878 * OLEFontImpl_IsEqual (IFont)
880 * See Windows documentation for more details on IFont methods.
882 static HRESULT WINAPI OLEFontImpl_IsEqual(
890 /************************************************************************
891 * OLEFontImpl_SetRatio (IFont)
893 * See Windows documentation for more details on IFont methods.
895 static HRESULT WINAPI OLEFontImpl_SetRatio(
900 _ICOM_THIS(OLEFontImpl, iface);
902 this->cyLogical = cyLogical;
903 this->cyHimetric = cyHimetric;
908 /************************************************************************
909 * OLEFontImpl_QueryTextMetrics (IFont)
911 * See Windows documentation for more details on IFont methods.
913 static HRESULT WINAPI OLEFontImpl_QueryTextMetrics(
921 /************************************************************************
922 * OLEFontImpl_AddRefHfont (IFont)
924 * See Windows documentation for more details on IFont methods.
926 static HRESULT WINAPI OLEFontImpl_AddRefHfont(
930 _ICOM_THIS(OLEFontImpl, iface);
933 (hfont != this->gdiFont) )
941 /************************************************************************
942 * OLEFontImpl_ReleaseHfont (IFont)
944 * See Windows documentation for more details on IFont methods.
946 static HRESULT WINAPI OLEFontImpl_ReleaseHfont(
950 _ICOM_THIS(OLEFontImpl, iface);
953 (hfont != this->gdiFont) )
959 * If we just released our last font reference, destroy it.
961 if (this->fontLock==0)
963 DeleteObject(this->gdiFont);
970 /************************************************************************
971 * OLEFontImpl_SetHdc (IFont)
973 * See Windows documentation for more details on IFont methods.
975 static HRESULT WINAPI OLEFontImpl_SetHdc(
983 /************************************************************************
984 * OLEFontImpl_IDispatch_QueryInterface (IUnknown)
986 * See Windows documentation for more details on IUnknown methods.
988 static HRESULT WINAPI OLEFontImpl_IDispatch_QueryInterface(
993 _ICOM_THIS_From_IDispatch(IFont, iface);
995 return IFont_QueryInterface(this, riid, ppvoid);
998 /************************************************************************
999 * OLEFontImpl_IDispatch_Release (IUnknown)
1001 * See Windows documentation for more details on IUnknown methods.
1003 static ULONG WINAPI OLEFontImpl_IDispatch_Release(
1006 _ICOM_THIS_From_IDispatch(IFont, iface);
1008 return IFont_Release(this);
1011 /************************************************************************
1012 * OLEFontImpl_IDispatch_AddRef (IUnknown)
1014 * See Windows documentation for more details on IUnknown methods.
1016 static ULONG WINAPI OLEFontImpl_IDispatch_AddRef(
1019 _ICOM_THIS_From_IDispatch(IFont, iface);
1021 return IFont_AddRef(this);
1024 /************************************************************************
1025 * OLEFontImpl_GetTypeInfoCount (IDispatch)
1027 * See Windows documentation for more details on IDispatch methods.
1029 static HRESULT WINAPI OLEFontImpl_GetTypeInfoCount(
1031 unsigned int* pctinfo)
1038 /************************************************************************
1039 * OLEFontImpl_GetTypeInfo (IDispatch)
1041 * See Windows documentation for more details on IDispatch methods.
1043 static HRESULT WINAPI OLEFontImpl_GetTypeInfo(
1047 ITypeInfo** ppTInfo)
1054 /************************************************************************
1055 * OLEFontImpl_GetIDsOfNames (IDispatch)
1057 * See Windows documentation for more details on IDispatch methods.
1059 static HRESULT WINAPI OLEFontImpl_GetIDsOfNames(
1062 LPOLESTR* rgszNames,
1072 /************************************************************************
1073 * OLEFontImpl_Invoke (IDispatch)
1075 * See Windows documentation for more details on IDispatch methods.
1077 static HRESULT WINAPI OLEFontImpl_Invoke(
1079 DISPID dispIdMember,
1083 DISPPARAMS* pDispParams,
1084 VARIANT* pVarResult,
1085 EXCEPINFO* pExepInfo,
1093 /************************************************************************
1094 * OLEFontImpl_IPersistStream_QueryInterface (IUnknown)
1096 * See Windows documentation for more details on IUnknown methods.
1098 static HRESULT WINAPI OLEFontImpl_IPersistStream_QueryInterface(
1099 IPersistStream* iface,
1103 _ICOM_THIS_From_IPersistStream(IFont, iface);
1105 return IFont_QueryInterface(this, riid, ppvoid);
1108 /************************************************************************
1109 * OLEFontImpl_IPersistStream_Release (IUnknown)
1111 * See Windows documentation for more details on IUnknown methods.
1113 static ULONG WINAPI OLEFontImpl_IPersistStream_Release(
1114 IPersistStream* iface)
1116 _ICOM_THIS_From_IPersistStream(IFont, iface);
1118 return IFont_Release(this);
1121 /************************************************************************
1122 * OLEFontImpl_IPersistStream_AddRef (IUnknown)
1124 * See Windows documentation for more details on IUnknown methods.
1126 static ULONG WINAPI OLEFontImpl_IPersistStream_AddRef(
1127 IPersistStream* iface)
1129 _ICOM_THIS_From_IPersistStream(IFont, iface);
1131 return IFont_AddRef(this);
1134 /************************************************************************
1135 * OLEFontImpl_GetClassID (IPersistStream)
1137 * See Windows documentation for more details on IPersistStream methods.
1139 static HRESULT WINAPI OLEFontImpl_GetClassID(
1140 IPersistStream* iface,
1146 memcpy(pClassID, &CLSID_StdFont, sizeof(CLSID_StdFont));
1151 /************************************************************************
1152 * OLEFontImpl_IsDirty (IPersistStream)
1154 * See Windows documentation for more details on IPersistStream methods.
1156 static HRESULT WINAPI OLEFontImpl_IsDirty(
1157 IPersistStream* iface)
1162 /************************************************************************
1163 * OLEFontImpl_Load (IPersistStream)
1165 * See Windows documentation for more details on IPersistStream methods.
1167 * This is the format of the standard font serialization as far as I
1170 * Offset Type Value Comment
1171 * 0x0000 Byte Unknown Probably a version number, contains 0x01
1172 * 0x0001 Short Charset Charset value from the FONTDESC structure
1173 * 0x0003 Byte Attributes Flags defined as follows:
1175 * 00000100 - Underline
1176 * 00001000 - Strikethrough
1177 * 0x0004 Short Weight Weight value from FONTDESC structure
1178 * 0x0006 DWORD size "Low" portion of the cySize member of the FONTDESC
1180 * 0x000A Byte name length Length of the font name string (no null character)
1181 * 0x000B String name Name of the font (ASCII, no nul character)
1183 static HRESULT WINAPI OLEFontImpl_Load(
1184 IPersistStream* iface,
1185 IStream* pLoadStream)
1187 char readBuffer[0x100];
1193 _ICOM_THIS_From_IPersistStream(OLEFontImpl, iface);
1196 * Read the version byte
1198 IStream_Read(pLoadStream, &bVersion, 1, &cbRead);
1207 IStream_Read(pLoadStream, &this->description.sCharset, 2, &cbRead);
1215 IStream_Read(pLoadStream, &bAttributes, 1, &cbRead);
1220 this->description.fItalic = (bAttributes & FONTPERSIST_ITALIC) != 0;
1221 this->description.fStrikethrough = (bAttributes & FONTPERSIST_STRIKETHROUGH) != 0;
1222 this->description.fUnderline = (bAttributes & FONTPERSIST_UNDERLINE) != 0;
1227 IStream_Read(pLoadStream, &this->description.sWeight, 2, &cbRead);
1235 IStream_Read(pLoadStream, &this->description.cySize.u.Lo, 4, &cbRead);
1240 this->description.cySize.u.Hi = 0;
1245 IStream_Read(pLoadStream, &bStringSize, 1, &cbRead);
1250 memset(readBuffer, 0, 0x100);
1251 IStream_Read(pLoadStream, readBuffer, bStringSize, &cbRead);
1253 if (cbRead!=bStringSize)
1256 if (this->description.lpstrName!=0)
1257 HeapFree(GetProcessHeap(), 0, this->description.lpstrName);
1259 this->description.lpstrName = HEAP_strdupAtoW(GetProcessHeap(),
1266 /************************************************************************
1267 * OLEFontImpl_Save (IPersistStream)
1269 * See Windows documentation for more details on IPersistStream methods.
1271 static HRESULT WINAPI OLEFontImpl_Save(
1272 IPersistStream* iface,
1273 IStream* pOutStream,
1276 char* writeBuffer = NULL;
1278 BYTE bVersion = 0x01;
1282 _ICOM_THIS_From_IPersistStream(OLEFontImpl, iface);
1285 * Read the version byte
1287 IStream_Write(pOutStream, &bVersion, 1, &cbWritten);
1295 IStream_Write(pOutStream, &this->description.sCharset, 2, &cbWritten);
1305 if (this->description.fItalic)
1306 bAttributes |= FONTPERSIST_ITALIC;
1308 if (this->description.fStrikethrough)
1309 bAttributes |= FONTPERSIST_STRIKETHROUGH;
1311 if (this->description.fUnderline)
1312 bAttributes |= FONTPERSIST_UNDERLINE;
1314 IStream_Write(pOutStream, &bAttributes, 1, &cbWritten);
1322 IStream_Write(pOutStream, &this->description.sWeight, 2, &cbWritten);
1330 IStream_Write(pOutStream, &this->description.cySize.u.Lo, 4, &cbWritten);
1338 if (this->description.lpstrName!=0)
1339 bStringSize = lstrlenW(this->description.lpstrName);
1343 IStream_Write(pOutStream, &bStringSize, 1, &cbWritten);
1350 writeBuffer = HEAP_strdupWtoA(GetProcessHeap(),
1352 this->description.lpstrName);
1355 return E_OUTOFMEMORY;
1357 IStream_Write(pOutStream, writeBuffer, bStringSize, &cbWritten);
1359 HeapFree(GetProcessHeap(), 0, writeBuffer);
1361 if (cbWritten!=bStringSize)
1368 /************************************************************************
1369 * OLEFontImpl_GetSizeMax (IPersistStream)
1371 * See Windows documentation for more details on IPersistStream methods.
1373 static HRESULT WINAPI OLEFontImpl_GetSizeMax(
1374 IPersistStream* iface,
1375 ULARGE_INTEGER* pcbSize)
1377 _ICOM_THIS_From_IPersistStream(OLEFontImpl, iface);
1382 pcbSize->HighPart = 0;
1383 pcbSize->LowPart = 0;
1385 pcbSize->LowPart += sizeof(BYTE); /* Version */
1386 pcbSize->LowPart += sizeof(WORD); /* Lang code */
1387 pcbSize->LowPart += sizeof(BYTE); /* Flags */
1388 pcbSize->LowPart += sizeof(WORD); /* Weight */
1389 pcbSize->LowPart += sizeof(DWORD); /* Size */
1390 pcbSize->LowPart += sizeof(BYTE); /* StrLength */
1392 if (this->description.lpstrName!=0)
1393 pcbSize->LowPart += lstrlenW(this->description.lpstrName);