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
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*)(((void*)name)-sizeof(void*));
79 #define _ICOM_THIS_From_IPersistStream(class, name) class* this = (class*)(((void*)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(const 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 OLEFontImpl_QueryInterface
,
174 OLEFontImpl_get_Name
,
175 OLEFontImpl_put_Name
,
176 OLEFontImpl_get_Size
,
177 OLEFontImpl_put_Size
,
178 OLEFontImpl_get_Bold
,
179 OLEFontImpl_put_Bold
,
180 OLEFontImpl_get_Italic
,
181 OLEFontImpl_put_Italic
,
182 OLEFontImpl_get_Underline
,
183 OLEFontImpl_put_Underline
,
184 OLEFontImpl_get_Strikethrough
,
185 OLEFontImpl_put_Strikethrough
,
186 OLEFontImpl_get_Weight
,
187 OLEFontImpl_put_Weight
,
188 OLEFontImpl_get_Charset
,
189 OLEFontImpl_put_Charset
,
190 OLEFontImpl_get_hFont
,
193 OLEFontImpl_SetRatio
,
194 OLEFontImpl_QueryTextMetrics
,
195 OLEFontImpl_AddRefHfont
,
196 OLEFontImpl_ReleaseHfont
,
200 static ICOM_VTABLE(IDispatch
) OLEFontImpl_IDispatch_VTable
=
202 OLEFontImpl_IDispatch_QueryInterface
,
203 OLEFontImpl_IDispatch_AddRef
,
204 OLEFontImpl_IDispatch_Release
,
205 OLEFontImpl_GetTypeInfoCount
,
206 OLEFontImpl_GetTypeInfo
,
207 OLEFontImpl_GetIDsOfNames
,
211 static ICOM_VTABLE(IPersistStream
) OLEFontImpl_IPersistStream_VTable
=
213 OLEFontImpl_IPersistStream_QueryInterface
,
214 OLEFontImpl_IPersistStream_AddRef
,
215 OLEFontImpl_IPersistStream_Release
,
216 OLEFontImpl_GetClassID
,
220 OLEFontImpl_GetSizeMax
223 /******************************************************************************
224 * OleCreateFontIndirect [OLEAUT32.420]
226 WINOLECTLAPI
OleCreateFontIndirect(
227 LPFONTDESC lpFontDesc
,
231 OLEFontImpl
* newFont
= 0;
243 * Try to construct a new instance of the class.
245 newFont
= OLEFontImpl_Construct(lpFontDesc
);
248 return E_OUTOFMEMORY
;
251 * Make sure it supports the interface required by the caller.
253 hr
= IFont_QueryInterface((IFont
*)newFont
, riid
, ppvObj
);
256 * Release the reference obtained in the constructor. If
257 * the QueryInterface was unsuccessful, it will free the class.
259 IFont_Release((IFont
*)newFont
);
265 /***********************************************************************
266 * Implementation of the OLEFontImpl class.
269 /************************************************************************
270 * OLEFontImpl_Construct
272 * This method will construct a new instance of the OLEFontImpl
275 * The caller of this method must release the object when it's
278 static OLEFontImpl
* OLEFontImpl_Construct(LPFONTDESC fontDesc
)
280 OLEFontImpl
* newObject
= 0;
283 * Allocate space for the object.
285 newObject
= HeapAlloc(GetProcessHeap(), 0, sizeof(OLEFontImpl
));
291 * Initialize the virtual function table.
293 newObject
->lpvtbl1
= &OLEFontImpl_VTable
;
294 newObject
->lpvtbl2
= &OLEFontImpl_IDispatch_VTable
;
295 newObject
->lpvtbl3
= &OLEFontImpl_IPersistStream_VTable
;
298 * Start with one reference count. The caller of this function
299 * must release the interface pointer when it is done.
304 * Copy the description of the font in the object.
306 assert(fontDesc
->cbSizeofstruct
>= sizeof(FONTDESC
));
308 newObject
->description
.cbSizeofstruct
= sizeof(FONTDESC
);
309 newObject
->description
.lpstrName
= HeapAlloc(GetProcessHeap(),
311 (lstrlenW(fontDesc
->lpstrName
)+1) * sizeof(WCHAR
));
312 lstrcpyW(newObject
->description
.lpstrName
, fontDesc
->lpstrName
);
313 newObject
->description
.cySize
= fontDesc
->cySize
;
314 newObject
->description
.sWeight
= fontDesc
->sWeight
;
315 newObject
->description
.sCharset
= fontDesc
->sCharset
;
316 newObject
->description
.fItalic
= fontDesc
->fItalic
;
317 newObject
->description
.fUnderline
= fontDesc
->fUnderline
;
318 newObject
->description
.fStrikethrough
= fontDesc
->fStrikethrough
;
321 * Initializing all the other members.
323 newObject
->gdiFont
= 0;
324 newObject
->fontLock
= 0;
325 newObject
->cyHimetric
= 1;
326 newObject
->cyLogical
= 1;
331 /************************************************************************
332 * OLEFontImpl_Construct
334 * This method is called by the Release method when the reference
335 * count goes doen to 0. it will free all resources used by
338 static void OLEFontImpl_Destroy(OLEFontImpl
* fontDesc
)
340 if (fontDesc
->description
.lpstrName
!=0)
341 HeapFree(GetProcessHeap(), 0, fontDesc
->description
.lpstrName
);
343 if (fontDesc
->gdiFont
!=0)
344 DeleteObject(fontDesc
->gdiFont
);
346 HeapFree(GetProcessHeap(), 0, fontDesc
);
349 /************************************************************************
350 * OLEFontImpl_QueryInterface (IUnknown)
352 * See Windows documentation for more details on IUnknown methods.
354 HRESULT WINAPI
OLEFontImpl_QueryInterface(
359 _ICOM_THIS(OLEFontImpl
, iface
);
362 * Perform a sanity check on the parameters.
364 if ( (this==0) || (ppvObject
==0) )
368 * Initialize the return parameter.
373 * Compare the riid with the interface IDs implemented by this object.
375 if (memcmp(&IID_IUnknown
, riid
, sizeof(IID_IUnknown
)) == 0)
377 *ppvObject
= (IFont
*)this;
379 else if (memcmp(&IID_IFont
, riid
, sizeof(IID_IFont
)) == 0)
381 *ppvObject
= (IFont
*)this;
383 else if (memcmp(&IID_IDispatch
, riid
, sizeof(IID_IDispatch
)) == 0)
385 *ppvObject
= (IDispatch
*)&(this->lpvtbl2
);
387 else if (memcmp(&IID_IFontDisp
, riid
, sizeof(IID_IFontDisp
)) == 0)
389 *ppvObject
= (IDispatch
*)&(this->lpvtbl2
);
391 else if (memcmp(&IID_IPersistStream
, riid
, sizeof(IID_IPersistStream
)) == 0)
393 *ppvObject
= (IPersistStream
*)&(this->lpvtbl3
);
397 * Check that we obtained an interface.
403 WINE_StringFromCLSID((LPCLSID
)riid
,clsid
);
406 "() : asking for un supported interface %s\n",
409 return E_NOINTERFACE
;
413 * Query Interface always increases the reference count by one when it is
416 OLEFontImpl_AddRef((IFont
*)this);
421 /************************************************************************
422 * OLEFontImpl_AddRef (IUnknown)
424 * See Windows documentation for more details on IUnknown methods.
426 ULONG WINAPI
OLEFontImpl_AddRef(
429 _ICOM_THIS(OLEFontImpl
, iface
);
436 /************************************************************************
437 * OLEFontImpl_Release (IUnknown)
439 * See Windows documentation for more details on IUnknown methods.
441 ULONG WINAPI
OLEFontImpl_Release(
444 _ICOM_THIS(OLEFontImpl
, iface
);
447 * Decrease the reference count on this object.
452 * If the reference count goes down to 0, perform suicide.
456 OLEFontImpl_Destroy(this);
464 /************************************************************************
465 * OLEFontImpl_get_Name (IFont)
467 * See Windows documentation for more details on IFont methods.
469 static HRESULT WINAPI
OLEFontImpl_get_Name(
473 _ICOM_THIS(OLEFontImpl
, iface
);
481 if (this->description
.lpstrName
!=0)
482 *pname
= SysAllocString(this->description
.lpstrName
);
489 /************************************************************************
490 * OLEFontImpl_put_Name (IFont)
492 * See Windows documentation for more details on IFont methods.
494 static HRESULT WINAPI
OLEFontImpl_put_Name(
498 _ICOM_THIS(OLEFontImpl
, iface
);
500 if (this->description
.lpstrName
==0)
502 this->description
.lpstrName
= HeapAlloc(GetProcessHeap(),
504 (lstrlenW(name
)+1) * sizeof(WCHAR
));
508 this->description
.lpstrName
= HeapReAlloc(GetProcessHeap(),
510 this->description
.lpstrName
,
511 (lstrlenW(name
)+1) * sizeof(WCHAR
));
514 if (this->description
.lpstrName
==0)
515 return E_OUTOFMEMORY
;
517 lstrcpyW(this->description
.lpstrName
, name
);
522 /************************************************************************
523 * OLEFontImpl_get_Size (IFont)
525 * See Windows documentation for more details on IFont methods.
527 static HRESULT WINAPI
OLEFontImpl_get_Size(
531 _ICOM_THIS(OLEFontImpl
, iface
);
540 psize
->u
.Lo
= this->description
.cySize
.u
.Lo
;
545 /************************************************************************
546 * OLEFontImpl_put_Size (IFont)
548 * See Windows documentation for more details on IFont methods.
550 static HRESULT WINAPI
OLEFontImpl_put_Size(
554 _ICOM_THIS(OLEFontImpl
, iface
);
556 this->description
.cySize
.u
.Hi
= 0;
557 this->description
.cySize
.u
.Lo
= this->description
.cySize
.u
.Lo
;
562 /************************************************************************
563 * OLEFontImpl_get_Bold (IFont)
565 * See Windows documentation for more details on IFont methods.
567 static HRESULT WINAPI
OLEFontImpl_get_Bold(
571 FIXME(ole
,"():Stub\n");
575 /************************************************************************
576 * OLEFontImpl_put_Bold (IFont)
578 * See Windows documentation for more details on IFont methods.
580 static HRESULT WINAPI
OLEFontImpl_put_Bold(
584 FIXME(ole
,"():Stub\n");
588 /************************************************************************
589 * OLEFontImpl_get_Italic (IFont)
591 * See Windows documentation for more details on IFont methods.
593 static HRESULT WINAPI
OLEFontImpl_get_Italic(
597 _ICOM_THIS(OLEFontImpl
, iface
);
605 *pitalic
= this->description
.fItalic
;
610 /************************************************************************
611 * OLEFontImpl_put_Italic (IFont)
613 * See Windows documentation for more details on IFont methods.
615 static HRESULT WINAPI
OLEFontImpl_put_Italic(
619 _ICOM_THIS(OLEFontImpl
, iface
);
621 this->description
.fItalic
= italic
;
626 /************************************************************************
627 * OLEFontImpl_get_Underline (IFont)
629 * See Windows documentation for more details on IFont methods.
631 static HRESULT WINAPI
OLEFontImpl_get_Underline(
635 _ICOM_THIS(OLEFontImpl
, iface
);
643 *punderline
= this->description
.fUnderline
;
648 /************************************************************************
649 * OLEFontImpl_put_Underline (IFont)
651 * See Windows documentation for more details on IFont methods.
653 static HRESULT WINAPI
OLEFontImpl_put_Underline(
657 _ICOM_THIS(OLEFontImpl
, iface
);
659 this->description
.fUnderline
= underline
;
664 /************************************************************************
665 * OLEFontImpl_get_Strikethrough (IFont)
667 * See Windows documentation for more details on IFont methods.
669 static HRESULT WINAPI
OLEFontImpl_get_Strikethrough(
671 BOOL
* pstrikethrough
)
673 _ICOM_THIS(OLEFontImpl
, iface
);
678 if (pstrikethrough
==0)
681 *pstrikethrough
= this->description
.fStrikethrough
;
686 /************************************************************************
687 * OLEFontImpl_put_Strikethrough (IFont)
689 * See Windows documentation for more details on IFont methods.
691 static HRESULT WINAPI
OLEFontImpl_put_Strikethrough(
695 _ICOM_THIS(OLEFontImpl
, iface
);
697 this->description
.fStrikethrough
= strikethrough
;
702 /************************************************************************
703 * OLEFontImpl_get_Weight (IFont)
705 * See Windows documentation for more details on IFont methods.
707 static HRESULT WINAPI
OLEFontImpl_get_Weight(
711 _ICOM_THIS(OLEFontImpl
, iface
);
719 *pweight
= this->description
.sWeight
;
724 /************************************************************************
725 * OLEFontImpl_put_Weight (IFont)
727 * See Windows documentation for more details on IFont methods.
729 static HRESULT WINAPI
OLEFontImpl_put_Weight(
733 _ICOM_THIS(OLEFontImpl
, iface
);
735 this->description
.sWeight
= weight
;
740 /************************************************************************
741 * OLEFontImpl_get_Charset (IFont)
743 * See Windows documentation for more details on IFont methods.
745 static HRESULT WINAPI
OLEFontImpl_get_Charset(
749 _ICOM_THIS(OLEFontImpl
, iface
);
757 *pcharset
= this->description
.sCharset
;
762 /************************************************************************
763 * OLEFontImpl_put_Charset (IFont)
765 * See Windows documentation for more details on IFont methods.
767 static HRESULT WINAPI
OLEFontImpl_put_Charset(
771 _ICOM_THIS(OLEFontImpl
, iface
);
773 this->description
.sCharset
= charset
;
778 /************************************************************************
779 * OLEFontImpl_get_hFont (IFont)
781 * See Windows documentation for more details on IFont methods.
783 static HRESULT WINAPI
OLEFontImpl_get_hFont(
787 _ICOM_THIS(OLEFontImpl
, iface
);
793 * Realize the font if necessary
795 if (this->gdiFont
==0)
802 * The height of the font returned by the get_Size property is the
803 * height of the font in points multiplied by 10000... Using some
804 * simple conversions and the ratio given by the application, it can
805 * be converted to a height in pixels.
807 IFont_get_Size(iface
, &cySize
);
809 fontHeight
= MulDiv(cySize
.u
.Lo
, 2540L, 72L);
810 fontHeight
= MulDiv(fontHeight
, this->cyLogical
,this->cyHimetric
);
812 memset(&logFont
, 0, sizeof(LOGFONTW
));
814 logFont
.lfHeight
= ((fontHeight
%10000L)>5000L) ? (-fontHeight
/10000L)-1 :
815 (-fontHeight
/10000L);
816 logFont
.lfItalic
= this->description
.fItalic
;
817 logFont
.lfUnderline
= this->description
.fUnderline
;
818 logFont
.lfStrikeOut
= this->description
.fStrikethrough
;
819 logFont
.lfWeight
= this->description
.sWeight
;
820 logFont
.lfCharSet
= this->description
.sCharset
;
821 logFont
.lfOutPrecision
= OUT_CHARACTER_PRECIS
;
822 logFont
.lfClipPrecision
= CLIP_DEFAULT_PRECIS
;
823 logFont
.lfQuality
= DEFAULT_QUALITY
;
824 logFont
.lfPitchAndFamily
= DEFAULT_PITCH
;
825 lstrcpyW(logFont
.lfFaceName
,this->description
.lpstrName
);
827 this->gdiFont
= CreateFontIndirectW(&logFont
);
830 *phfont
= this->gdiFont
;
835 /************************************************************************
836 * OLEFontImpl_Clone (IFont)
838 * See Windows documentation for more details on IFont methods.
840 static HRESULT WINAPI
OLEFontImpl_Clone(
844 OLEFontImpl
* newObject
= 0;
846 _ICOM_THIS(OLEFontImpl
, iface
);
854 * Allocate space for the object.
856 newObject
= HeapAlloc(GetProcessHeap(), 0, sizeof(OLEFontImpl
));
859 return E_OUTOFMEMORY
;
864 * That new object starts with a reference count of 1
868 *ppfont
= (IFont
*)newObject
;
873 /************************************************************************
874 * OLEFontImpl_IsEqual (IFont)
876 * See Windows documentation for more details on IFont methods.
878 static HRESULT WINAPI
OLEFontImpl_IsEqual(
882 FIXME(ole
,"():Stub\n");
886 /************************************************************************
887 * OLEFontImpl_SetRatio (IFont)
889 * See Windows documentation for more details on IFont methods.
891 static HRESULT WINAPI
OLEFontImpl_SetRatio(
896 _ICOM_THIS(OLEFontImpl
, iface
);
898 this->cyLogical
= cyLogical
;
899 this->cyHimetric
= cyHimetric
;
904 /************************************************************************
905 * OLEFontImpl_QueryTextMetrics (IFont)
907 * See Windows documentation for more details on IFont methods.
909 static HRESULT WINAPI
OLEFontImpl_QueryTextMetrics(
913 FIXME(ole
,"():Stub\n");
917 /************************************************************************
918 * OLEFontImpl_AddRefHfont (IFont)
920 * See Windows documentation for more details on IFont methods.
922 static HRESULT WINAPI
OLEFontImpl_AddRefHfont(
926 _ICOM_THIS(OLEFontImpl
, iface
);
929 (hfont
!= this->gdiFont
) )
937 /************************************************************************
938 * OLEFontImpl_ReleaseHfont (IFont)
940 * See Windows documentation for more details on IFont methods.
942 static HRESULT WINAPI
OLEFontImpl_ReleaseHfont(
946 _ICOM_THIS(OLEFontImpl
, iface
);
949 (hfont
!= this->gdiFont
) )
955 * If we just released our last font reference, destroy it.
957 if (this->fontLock
==0)
959 DeleteObject(this->gdiFont
);
966 /************************************************************************
967 * OLEFontImpl_SetHdc (IFont)
969 * See Windows documentation for more details on IFont methods.
971 static HRESULT WINAPI
OLEFontImpl_SetHdc(
975 FIXME(ole
,"():Stub\n");
979 /************************************************************************
980 * OLEFontImpl_IDispatch_QueryInterface (IUnknown)
982 * See Windows documentation for more details on IUnknown methods.
984 static HRESULT WINAPI
OLEFontImpl_IDispatch_QueryInterface(
989 _ICOM_THIS_From_IDispatch(IFont
, iface
);
991 return IFont_QueryInterface(this, riid
, ppvoid
);
994 /************************************************************************
995 * OLEFontImpl_IDispatch_Release (IUnknown)
997 * See Windows documentation for more details on IUnknown methods.
999 static ULONG WINAPI
OLEFontImpl_IDispatch_Release(
1002 _ICOM_THIS_From_IDispatch(IFont
, iface
);
1004 return IFont_Release(this);
1007 /************************************************************************
1008 * OLEFontImpl_IDispatch_AddRef (IUnknown)
1010 * See Windows documentation for more details on IUnknown methods.
1012 static ULONG WINAPI
OLEFontImpl_IDispatch_AddRef(
1015 _ICOM_THIS_From_IDispatch(IFont
, iface
);
1017 return IFont_AddRef(this);
1020 /************************************************************************
1021 * OLEFontImpl_GetTypeInfoCount (IDispatch)
1023 * See Windows documentation for more details on IDispatch methods.
1025 static HRESULT WINAPI
OLEFontImpl_GetTypeInfoCount(
1027 unsigned int* pctinfo
)
1029 FIXME(ole
,"():Stub\n");
1034 /************************************************************************
1035 * OLEFontImpl_GetTypeInfo (IDispatch)
1037 * See Windows documentation for more details on IDispatch methods.
1039 static HRESULT WINAPI
OLEFontImpl_GetTypeInfo(
1043 ITypeInfo
** ppTInfo
)
1045 FIXME(ole
,"():Stub\n");
1050 /************************************************************************
1051 * OLEFontImpl_GetIDsOfNames (IDispatch)
1053 * See Windows documentation for more details on IDispatch methods.
1055 static HRESULT WINAPI
OLEFontImpl_GetIDsOfNames(
1058 LPOLESTR
* rgszNames
,
1063 FIXME(ole
,"():Stub\n");
1068 /************************************************************************
1069 * OLEFontImpl_Invoke (IDispatch)
1071 * See Windows documentation for more details on IDispatch methods.
1073 static HRESULT WINAPI
OLEFontImpl_Invoke(
1075 DISPID dispIdMember
,
1079 DISPPARAMS
* pDispParams
,
1080 VARIANT
* pVarResult
,
1081 EXCEPINFO
* pExepInfo
,
1084 FIXME(ole
,"():Stub\n");
1089 /************************************************************************
1090 * OLEFontImpl_IPersistStream_QueryInterface (IUnknown)
1092 * See Windows documentation for more details on IUnknown methods.
1094 static HRESULT WINAPI
OLEFontImpl_IPersistStream_QueryInterface(
1095 IPersistStream
* iface
,
1099 _ICOM_THIS_From_IPersistStream(IFont
, iface
);
1101 return IFont_QueryInterface(this, riid
, ppvoid
);
1104 /************************************************************************
1105 * OLEFontImpl_IPersistStream_Release (IUnknown)
1107 * See Windows documentation for more details on IUnknown methods.
1109 static ULONG WINAPI
OLEFontImpl_IPersistStream_Release(
1110 IPersistStream
* iface
)
1112 _ICOM_THIS_From_IPersistStream(IFont
, iface
);
1114 return IFont_Release(this);
1117 /************************************************************************
1118 * OLEFontImpl_IPersistStream_AddRef (IUnknown)
1120 * See Windows documentation for more details on IUnknown methods.
1122 static ULONG WINAPI
OLEFontImpl_IPersistStream_AddRef(
1123 IPersistStream
* iface
)
1125 _ICOM_THIS_From_IPersistStream(IFont
, iface
);
1127 return IFont_AddRef(this);
1130 /************************************************************************
1131 * OLEFontImpl_GetClassID (IPersistStream)
1133 * See Windows documentation for more details on IPersistStream methods.
1135 static HRESULT WINAPI
OLEFontImpl_GetClassID(
1136 const IPersistStream
* iface
,
1142 memcpy(pClassID
, &CLSID_StdFont
, sizeof(CLSID_StdFont
));
1147 /************************************************************************
1148 * OLEFontImpl_IsDirty (IPersistStream)
1150 * See Windows documentation for more details on IPersistStream methods.
1152 static HRESULT WINAPI
OLEFontImpl_IsDirty(
1153 IPersistStream
* iface
)
1158 /************************************************************************
1159 * OLEFontImpl_Load (IPersistStream)
1161 * See Windows documentation for more details on IPersistStream methods.
1163 * This is the format of the standard font serialization as far as I
1166 * Offset Type Value Comment
1167 * 0x0000 Byte Unknown Probably a version number, contains 0x01
1168 * 0x0001 Short Charset Charset value from the FONTDESC structure
1169 * 0x0003 Byte Attributes Flags defined as follows:
1171 * 00000100 - Underline
1172 * 00001000 - Strikethrough
1173 * 0x0004 Short Weight Weight value from FONTDESC structure
1174 * 0x0006 DWORD size "Low" portion of the cySize member of the FONTDESC
1176 * 0x000A Byte name length Length of the font name string (no null character)
1177 * 0x000B String name Name of the font (ASCII, no nul character)
1179 static HRESULT WINAPI
OLEFontImpl_Load(
1180 IPersistStream
* iface
,
1181 IStream
* pLoadStream
)
1183 char readBuffer
[0x100];
1189 _ICOM_THIS_From_IPersistStream(OLEFontImpl
, iface
);
1192 * Read the version byte
1194 IStream_Read(pLoadStream
, &bVersion
, 1, &cbRead
);
1203 IStream_Read(pLoadStream
, &this->description
.sCharset
, 2, &cbRead
);
1211 IStream_Read(pLoadStream
, &bAttributes
, 1, &cbRead
);
1216 this->description
.fItalic
= (bAttributes
& FONTPERSIST_ITALIC
) != 0;
1217 this->description
.fStrikethrough
= (bAttributes
& FONTPERSIST_STRIKETHROUGH
) != 0;
1218 this->description
.fUnderline
= (bAttributes
& FONTPERSIST_UNDERLINE
) != 0;
1223 IStream_Read(pLoadStream
, &this->description
.sWeight
, 2, &cbRead
);
1231 IStream_Read(pLoadStream
, &this->description
.cySize
.u
.Lo
, 4, &cbRead
);
1236 this->description
.cySize
.u
.Hi
= 0;
1241 IStream_Read(pLoadStream
, &bStringSize
, 1, &cbRead
);
1246 memset(readBuffer
, 0, 0x100);
1247 IStream_Read(pLoadStream
, readBuffer
, bStringSize
, &cbRead
);
1249 if (cbRead
!=bStringSize
)
1252 if (this->description
.lpstrName
!=0)
1253 HeapFree(GetProcessHeap(), 0, this->description
.lpstrName
);
1255 this->description
.lpstrName
= HEAP_strdupAtoW(GetProcessHeap(),
1262 /************************************************************************
1263 * OLEFontImpl_Save (IPersistStream)
1265 * See Windows documentation for more details on IPersistStream methods.
1267 static HRESULT WINAPI
OLEFontImpl_Save(
1268 IPersistStream
* iface
,
1269 IStream
* pOutStream
,
1272 char* writeBuffer
= NULL
;
1274 BYTE bVersion
= 0x01;
1278 _ICOM_THIS_From_IPersistStream(OLEFontImpl
, iface
);
1281 * Read the version byte
1283 IStream_Write(pOutStream
, &bVersion
, 1, &cbWritten
);
1291 IStream_Write(pOutStream
, &this->description
.sCharset
, 2, &cbWritten
);
1301 if (this->description
.fItalic
)
1302 bAttributes
|= FONTPERSIST_ITALIC
;
1304 if (this->description
.fStrikethrough
)
1305 bAttributes
|= FONTPERSIST_STRIKETHROUGH
;
1307 if (this->description
.fUnderline
)
1308 bAttributes
|= FONTPERSIST_UNDERLINE
;
1310 IStream_Write(pOutStream
, &bAttributes
, 1, &cbWritten
);
1318 IStream_Write(pOutStream
, &this->description
.sWeight
, 2, &cbWritten
);
1326 IStream_Write(pOutStream
, &this->description
.cySize
.u
.Lo
, 4, &cbWritten
);
1334 if (this->description
.lpstrName
!=0)
1335 bStringSize
= lstrlenW(this->description
.lpstrName
);
1339 IStream_Write(pOutStream
, &bStringSize
, 1, &cbWritten
);
1346 writeBuffer
= HEAP_strdupWtoA(GetProcessHeap(),
1348 this->description
.lpstrName
);
1351 return E_OUTOFMEMORY
;
1353 IStream_Write(pOutStream
, writeBuffer
, bStringSize
, &cbWritten
);
1355 HeapFree(GetProcessHeap(), 0, writeBuffer
);
1357 if (cbWritten
!=bStringSize
)
1364 /************************************************************************
1365 * OLEFontImpl_GetSizeMax (IPersistStream)
1367 * See Windows documentation for more details on IPersistStream methods.
1369 static HRESULT WINAPI
OLEFontImpl_GetSizeMax(
1370 IPersistStream
* iface
,
1371 ULARGE_INTEGER
* pcbSize
)
1373 _ICOM_THIS_From_IPersistStream(OLEFontImpl
, iface
);
1378 pcbSize
->HighPart
= 0;
1379 pcbSize
->LowPart
= 0;
1381 pcbSize
->LowPart
+= sizeof(BYTE
); /* Version */
1382 pcbSize
->LowPart
+= sizeof(WORD
); /* Lang code */
1383 pcbSize
->LowPart
+= sizeof(BYTE
); /* Flags */
1384 pcbSize
->LowPart
+= sizeof(WORD
); /* Weight */
1385 pcbSize
->LowPart
+= sizeof(DWORD
); /* Size */
1386 pcbSize
->LowPart
+= sizeof(BYTE
); /* StrLength */
1388 if (this->description
.lpstrName
!=0)
1389 pcbSize
->LowPart
+= lstrlenW(this->description
.lpstrName
);