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 HRESULT 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.
405 WARN("() : asking for un supported interface %s\n",debugstr_guid(riid
));
406 return E_NOINTERFACE
;
410 * Query Interface always increases the reference count by one when it is
413 OLEFontImpl_AddRef((IFont
*)this);
418 /************************************************************************
419 * OLEFontImpl_AddRef (IUnknown)
421 * See Windows documentation for more details on IUnknown methods.
423 ULONG WINAPI
OLEFontImpl_AddRef(
426 _ICOM_THIS(OLEFontImpl
, iface
);
433 /************************************************************************
434 * OLEFontImpl_Release (IUnknown)
436 * See Windows documentation for more details on IUnknown methods.
438 ULONG WINAPI
OLEFontImpl_Release(
441 _ICOM_THIS(OLEFontImpl
, iface
);
444 * Decrease the reference count on this object.
449 * If the reference count goes down to 0, perform suicide.
453 OLEFontImpl_Destroy(this);
461 /************************************************************************
462 * OLEFontImpl_get_Name (IFont)
464 * See Windows documentation for more details on IFont methods.
466 static HRESULT WINAPI
OLEFontImpl_get_Name(
470 _ICOM_THIS(OLEFontImpl
, iface
);
478 if (this->description
.lpstrName
!=0)
479 *pname
= SysAllocString(this->description
.lpstrName
);
486 /************************************************************************
487 * OLEFontImpl_put_Name (IFont)
489 * See Windows documentation for more details on IFont methods.
491 static HRESULT WINAPI
OLEFontImpl_put_Name(
495 _ICOM_THIS(OLEFontImpl
, iface
);
497 if (this->description
.lpstrName
==0)
499 this->description
.lpstrName
= HeapAlloc(GetProcessHeap(),
501 (lstrlenW(name
)+1) * sizeof(WCHAR
));
505 this->description
.lpstrName
= HeapReAlloc(GetProcessHeap(),
507 this->description
.lpstrName
,
508 (lstrlenW(name
)+1) * sizeof(WCHAR
));
511 if (this->description
.lpstrName
==0)
512 return E_OUTOFMEMORY
;
514 lstrcpyW(this->description
.lpstrName
, name
);
519 /************************************************************************
520 * OLEFontImpl_get_Size (IFont)
522 * See Windows documentation for more details on IFont methods.
524 static HRESULT WINAPI
OLEFontImpl_get_Size(
528 _ICOM_THIS(OLEFontImpl
, iface
);
537 psize
->s
.Lo
= this->description
.cySize
.s
.Lo
;
542 /************************************************************************
543 * OLEFontImpl_put_Size (IFont)
545 * See Windows documentation for more details on IFont methods.
547 static HRESULT WINAPI
OLEFontImpl_put_Size(
551 _ICOM_THIS(OLEFontImpl
, iface
);
553 this->description
.cySize
.s
.Hi
= 0;
554 this->description
.cySize
.s
.Lo
= this->description
.cySize
.s
.Lo
;
559 /************************************************************************
560 * OLEFontImpl_get_Bold (IFont)
562 * See Windows documentation for more details on IFont methods.
564 static HRESULT WINAPI
OLEFontImpl_get_Bold(
572 /************************************************************************
573 * OLEFontImpl_put_Bold (IFont)
575 * See Windows documentation for more details on IFont methods.
577 static HRESULT WINAPI
OLEFontImpl_put_Bold(
585 /************************************************************************
586 * OLEFontImpl_get_Italic (IFont)
588 * See Windows documentation for more details on IFont methods.
590 static HRESULT WINAPI
OLEFontImpl_get_Italic(
594 _ICOM_THIS(OLEFontImpl
, iface
);
602 *pitalic
= this->description
.fItalic
;
607 /************************************************************************
608 * OLEFontImpl_put_Italic (IFont)
610 * See Windows documentation for more details on IFont methods.
612 static HRESULT WINAPI
OLEFontImpl_put_Italic(
616 _ICOM_THIS(OLEFontImpl
, iface
);
618 this->description
.fItalic
= italic
;
623 /************************************************************************
624 * OLEFontImpl_get_Underline (IFont)
626 * See Windows documentation for more details on IFont methods.
628 static HRESULT WINAPI
OLEFontImpl_get_Underline(
632 _ICOM_THIS(OLEFontImpl
, iface
);
640 *punderline
= this->description
.fUnderline
;
645 /************************************************************************
646 * OLEFontImpl_put_Underline (IFont)
648 * See Windows documentation for more details on IFont methods.
650 static HRESULT WINAPI
OLEFontImpl_put_Underline(
654 _ICOM_THIS(OLEFontImpl
, iface
);
656 this->description
.fUnderline
= underline
;
661 /************************************************************************
662 * OLEFontImpl_get_Strikethrough (IFont)
664 * See Windows documentation for more details on IFont methods.
666 static HRESULT WINAPI
OLEFontImpl_get_Strikethrough(
668 BOOL
* pstrikethrough
)
670 _ICOM_THIS(OLEFontImpl
, iface
);
675 if (pstrikethrough
==0)
678 *pstrikethrough
= this->description
.fStrikethrough
;
683 /************************************************************************
684 * OLEFontImpl_put_Strikethrough (IFont)
686 * See Windows documentation for more details on IFont methods.
688 static HRESULT WINAPI
OLEFontImpl_put_Strikethrough(
692 _ICOM_THIS(OLEFontImpl
, iface
);
694 this->description
.fStrikethrough
= strikethrough
;
699 /************************************************************************
700 * OLEFontImpl_get_Weight (IFont)
702 * See Windows documentation for more details on IFont methods.
704 static HRESULT WINAPI
OLEFontImpl_get_Weight(
708 _ICOM_THIS(OLEFontImpl
, iface
);
716 *pweight
= this->description
.sWeight
;
721 /************************************************************************
722 * OLEFontImpl_put_Weight (IFont)
724 * See Windows documentation for more details on IFont methods.
726 static HRESULT WINAPI
OLEFontImpl_put_Weight(
730 _ICOM_THIS(OLEFontImpl
, iface
);
732 this->description
.sWeight
= weight
;
737 /************************************************************************
738 * OLEFontImpl_get_Charset (IFont)
740 * See Windows documentation for more details on IFont methods.
742 static HRESULT WINAPI
OLEFontImpl_get_Charset(
746 _ICOM_THIS(OLEFontImpl
, iface
);
754 *pcharset
= this->description
.sCharset
;
759 /************************************************************************
760 * OLEFontImpl_put_Charset (IFont)
762 * See Windows documentation for more details on IFont methods.
764 static HRESULT WINAPI
OLEFontImpl_put_Charset(
768 _ICOM_THIS(OLEFontImpl
, iface
);
770 this->description
.sCharset
= charset
;
775 /************************************************************************
776 * OLEFontImpl_get_hFont (IFont)
778 * See Windows documentation for more details on IFont methods.
780 static HRESULT WINAPI
OLEFontImpl_get_hFont(
784 _ICOM_THIS(OLEFontImpl
, iface
);
790 * Realize the font if necessary
792 if (this->gdiFont
==0)
799 * The height of the font returned by the get_Size property is the
800 * height of the font in points multiplied by 10000... Using some
801 * simple conversions and the ratio given by the application, it can
802 * be converted to a height in pixels.
804 IFont_get_Size(iface
, &cySize
);
806 fontHeight
= MulDiv(cySize
.s
.Lo
, 2540L, 72L);
807 fontHeight
= MulDiv(fontHeight
, this->cyLogical
,this->cyHimetric
);
809 memset(&logFont
, 0, sizeof(LOGFONTW
));
811 logFont
.lfHeight
= ((fontHeight
%10000L)>5000L) ? (-fontHeight
/10000L)-1 :
812 (-fontHeight
/10000L);
813 logFont
.lfItalic
= this->description
.fItalic
;
814 logFont
.lfUnderline
= this->description
.fUnderline
;
815 logFont
.lfStrikeOut
= this->description
.fStrikethrough
;
816 logFont
.lfWeight
= this->description
.sWeight
;
817 logFont
.lfCharSet
= this->description
.sCharset
;
818 logFont
.lfOutPrecision
= OUT_CHARACTER_PRECIS
;
819 logFont
.lfClipPrecision
= CLIP_DEFAULT_PRECIS
;
820 logFont
.lfQuality
= DEFAULT_QUALITY
;
821 logFont
.lfPitchAndFamily
= DEFAULT_PITCH
;
822 lstrcpyW(logFont
.lfFaceName
,this->description
.lpstrName
);
824 this->gdiFont
= CreateFontIndirectW(&logFont
);
827 *phfont
= this->gdiFont
;
832 /************************************************************************
833 * OLEFontImpl_Clone (IFont)
835 * See Windows documentation for more details on IFont methods.
837 static HRESULT WINAPI
OLEFontImpl_Clone(
841 OLEFontImpl
* newObject
= 0;
843 _ICOM_THIS(OLEFontImpl
, iface
);
851 * Allocate space for the object.
853 newObject
= HeapAlloc(GetProcessHeap(), 0, sizeof(OLEFontImpl
));
856 return E_OUTOFMEMORY
;
861 * That new object starts with a reference count of 1
865 *ppfont
= (IFont
*)newObject
;
870 /************************************************************************
871 * OLEFontImpl_IsEqual (IFont)
873 * See Windows documentation for more details on IFont methods.
875 static HRESULT WINAPI
OLEFontImpl_IsEqual(
883 /************************************************************************
884 * OLEFontImpl_SetRatio (IFont)
886 * See Windows documentation for more details on IFont methods.
888 static HRESULT WINAPI
OLEFontImpl_SetRatio(
893 _ICOM_THIS(OLEFontImpl
, iface
);
895 this->cyLogical
= cyLogical
;
896 this->cyHimetric
= cyHimetric
;
901 /************************************************************************
902 * OLEFontImpl_QueryTextMetrics (IFont)
904 * See Windows documentation for more details on IFont methods.
906 static HRESULT WINAPI
OLEFontImpl_QueryTextMetrics(
914 /************************************************************************
915 * OLEFontImpl_AddRefHfont (IFont)
917 * See Windows documentation for more details on IFont methods.
919 static HRESULT WINAPI
OLEFontImpl_AddRefHfont(
923 _ICOM_THIS(OLEFontImpl
, iface
);
926 (hfont
!= this->gdiFont
) )
934 /************************************************************************
935 * OLEFontImpl_ReleaseHfont (IFont)
937 * See Windows documentation for more details on IFont methods.
939 static HRESULT WINAPI
OLEFontImpl_ReleaseHfont(
943 _ICOM_THIS(OLEFontImpl
, iface
);
946 (hfont
!= this->gdiFont
) )
952 * If we just released our last font reference, destroy it.
954 if (this->fontLock
==0)
956 DeleteObject(this->gdiFont
);
963 /************************************************************************
964 * OLEFontImpl_SetHdc (IFont)
966 * See Windows documentation for more details on IFont methods.
968 static HRESULT WINAPI
OLEFontImpl_SetHdc(
976 /************************************************************************
977 * OLEFontImpl_IDispatch_QueryInterface (IUnknown)
979 * See Windows documentation for more details on IUnknown methods.
981 static HRESULT WINAPI
OLEFontImpl_IDispatch_QueryInterface(
986 _ICOM_THIS_From_IDispatch(IFont
, iface
);
988 return IFont_QueryInterface(this, riid
, ppvoid
);
991 /************************************************************************
992 * OLEFontImpl_IDispatch_Release (IUnknown)
994 * See Windows documentation for more details on IUnknown methods.
996 static ULONG WINAPI
OLEFontImpl_IDispatch_Release(
999 _ICOM_THIS_From_IDispatch(IFont
, iface
);
1001 return IFont_Release(this);
1004 /************************************************************************
1005 * OLEFontImpl_IDispatch_AddRef (IUnknown)
1007 * See Windows documentation for more details on IUnknown methods.
1009 static ULONG WINAPI
OLEFontImpl_IDispatch_AddRef(
1012 _ICOM_THIS_From_IDispatch(IFont
, iface
);
1014 return IFont_AddRef(this);
1017 /************************************************************************
1018 * OLEFontImpl_GetTypeInfoCount (IDispatch)
1020 * See Windows documentation for more details on IDispatch methods.
1022 static HRESULT WINAPI
OLEFontImpl_GetTypeInfoCount(
1024 unsigned int* pctinfo
)
1031 /************************************************************************
1032 * OLEFontImpl_GetTypeInfo (IDispatch)
1034 * See Windows documentation for more details on IDispatch methods.
1036 static HRESULT WINAPI
OLEFontImpl_GetTypeInfo(
1040 ITypeInfo
** ppTInfo
)
1047 /************************************************************************
1048 * OLEFontImpl_GetIDsOfNames (IDispatch)
1050 * See Windows documentation for more details on IDispatch methods.
1052 static HRESULT WINAPI
OLEFontImpl_GetIDsOfNames(
1055 LPOLESTR
* rgszNames
,
1065 /************************************************************************
1066 * OLEFontImpl_Invoke (IDispatch)
1068 * See Windows documentation for more details on IDispatch methods.
1070 static HRESULT WINAPI
OLEFontImpl_Invoke(
1072 DISPID dispIdMember
,
1076 DISPPARAMS
* pDispParams
,
1077 VARIANT
* pVarResult
,
1078 EXCEPINFO
* pExepInfo
,
1086 /************************************************************************
1087 * OLEFontImpl_IPersistStream_QueryInterface (IUnknown)
1089 * See Windows documentation for more details on IUnknown methods.
1091 static HRESULT WINAPI
OLEFontImpl_IPersistStream_QueryInterface(
1092 IPersistStream
* iface
,
1096 _ICOM_THIS_From_IPersistStream(IFont
, iface
);
1098 return IFont_QueryInterface(this, riid
, ppvoid
);
1101 /************************************************************************
1102 * OLEFontImpl_IPersistStream_Release (IUnknown)
1104 * See Windows documentation for more details on IUnknown methods.
1106 static ULONG WINAPI
OLEFontImpl_IPersistStream_Release(
1107 IPersistStream
* iface
)
1109 _ICOM_THIS_From_IPersistStream(IFont
, iface
);
1111 return IFont_Release(this);
1114 /************************************************************************
1115 * OLEFontImpl_IPersistStream_AddRef (IUnknown)
1117 * See Windows documentation for more details on IUnknown methods.
1119 static ULONG WINAPI
OLEFontImpl_IPersistStream_AddRef(
1120 IPersistStream
* iface
)
1122 _ICOM_THIS_From_IPersistStream(IFont
, iface
);
1124 return IFont_AddRef(this);
1127 /************************************************************************
1128 * OLEFontImpl_GetClassID (IPersistStream)
1130 * See Windows documentation for more details on IPersistStream methods.
1132 static HRESULT WINAPI
OLEFontImpl_GetClassID(
1133 IPersistStream
* iface
,
1139 memcpy(pClassID
, &CLSID_StdFont
, sizeof(CLSID_StdFont
));
1144 /************************************************************************
1145 * OLEFontImpl_IsDirty (IPersistStream)
1147 * See Windows documentation for more details on IPersistStream methods.
1149 static HRESULT WINAPI
OLEFontImpl_IsDirty(
1150 IPersistStream
* iface
)
1155 /************************************************************************
1156 * OLEFontImpl_Load (IPersistStream)
1158 * See Windows documentation for more details on IPersistStream methods.
1160 * This is the format of the standard font serialization as far as I
1163 * Offset Type Value Comment
1164 * 0x0000 Byte Unknown Probably a version number, contains 0x01
1165 * 0x0001 Short Charset Charset value from the FONTDESC structure
1166 * 0x0003 Byte Attributes Flags defined as follows:
1168 * 00000100 - Underline
1169 * 00001000 - Strikethrough
1170 * 0x0004 Short Weight Weight value from FONTDESC structure
1171 * 0x0006 DWORD size "Low" portion of the cySize member of the FONTDESC
1173 * 0x000A Byte name length Length of the font name string (no null character)
1174 * 0x000B String name Name of the font (ASCII, no nul character)
1176 static HRESULT WINAPI
OLEFontImpl_Load(
1177 IPersistStream
* iface
,
1178 IStream
* pLoadStream
)
1180 char readBuffer
[0x100];
1186 _ICOM_THIS_From_IPersistStream(OLEFontImpl
, iface
);
1189 * Read the version byte
1191 IStream_Read(pLoadStream
, &bVersion
, 1, &cbRead
);
1200 IStream_Read(pLoadStream
, &this->description
.sCharset
, 2, &cbRead
);
1208 IStream_Read(pLoadStream
, &bAttributes
, 1, &cbRead
);
1213 this->description
.fItalic
= (bAttributes
& FONTPERSIST_ITALIC
) != 0;
1214 this->description
.fStrikethrough
= (bAttributes
& FONTPERSIST_STRIKETHROUGH
) != 0;
1215 this->description
.fUnderline
= (bAttributes
& FONTPERSIST_UNDERLINE
) != 0;
1220 IStream_Read(pLoadStream
, &this->description
.sWeight
, 2, &cbRead
);
1228 IStream_Read(pLoadStream
, &this->description
.cySize
.s
.Lo
, 4, &cbRead
);
1233 this->description
.cySize
.s
.Hi
= 0;
1238 IStream_Read(pLoadStream
, &bStringSize
, 1, &cbRead
);
1243 memset(readBuffer
, 0, 0x100);
1244 IStream_Read(pLoadStream
, readBuffer
, bStringSize
, &cbRead
);
1246 if (cbRead
!=bStringSize
)
1249 if (this->description
.lpstrName
!=0)
1250 HeapFree(GetProcessHeap(), 0, this->description
.lpstrName
);
1252 this->description
.lpstrName
= HEAP_strdupAtoW(GetProcessHeap(),
1259 /************************************************************************
1260 * OLEFontImpl_Save (IPersistStream)
1262 * See Windows documentation for more details on IPersistStream methods.
1264 static HRESULT WINAPI
OLEFontImpl_Save(
1265 IPersistStream
* iface
,
1266 IStream
* pOutStream
,
1269 char* writeBuffer
= NULL
;
1271 BYTE bVersion
= 0x01;
1275 _ICOM_THIS_From_IPersistStream(OLEFontImpl
, iface
);
1278 * Read the version byte
1280 IStream_Write(pOutStream
, &bVersion
, 1, &cbWritten
);
1288 IStream_Write(pOutStream
, &this->description
.sCharset
, 2, &cbWritten
);
1298 if (this->description
.fItalic
)
1299 bAttributes
|= FONTPERSIST_ITALIC
;
1301 if (this->description
.fStrikethrough
)
1302 bAttributes
|= FONTPERSIST_STRIKETHROUGH
;
1304 if (this->description
.fUnderline
)
1305 bAttributes
|= FONTPERSIST_UNDERLINE
;
1307 IStream_Write(pOutStream
, &bAttributes
, 1, &cbWritten
);
1315 IStream_Write(pOutStream
, &this->description
.sWeight
, 2, &cbWritten
);
1323 IStream_Write(pOutStream
, &this->description
.cySize
.s
.Lo
, 4, &cbWritten
);
1331 if (this->description
.lpstrName
!=0)
1332 bStringSize
= lstrlenW(this->description
.lpstrName
);
1336 IStream_Write(pOutStream
, &bStringSize
, 1, &cbWritten
);
1343 writeBuffer
= HEAP_strdupWtoA(GetProcessHeap(),
1345 this->description
.lpstrName
);
1348 return E_OUTOFMEMORY
;
1350 IStream_Write(pOutStream
, writeBuffer
, bStringSize
, &cbWritten
);
1352 HeapFree(GetProcessHeap(), 0, writeBuffer
);
1354 if (cbWritten
!=bStringSize
)
1361 /************************************************************************
1362 * OLEFontImpl_GetSizeMax (IPersistStream)
1364 * See Windows documentation for more details on IPersistStream methods.
1366 static HRESULT WINAPI
OLEFontImpl_GetSizeMax(
1367 IPersistStream
* iface
,
1368 ULARGE_INTEGER
* pcbSize
)
1370 _ICOM_THIS_From_IPersistStream(OLEFontImpl
, iface
);
1375 pcbSize
->s
.HighPart
= 0;
1376 pcbSize
->s
.LowPart
= 0;
1378 pcbSize
->s
.LowPart
+= sizeof(BYTE
); /* Version */
1379 pcbSize
->s
.LowPart
+= sizeof(WORD
); /* Lang code */
1380 pcbSize
->s
.LowPart
+= sizeof(BYTE
); /* Flags */
1381 pcbSize
->s
.LowPart
+= sizeof(WORD
); /* Weight */
1382 pcbSize
->s
.LowPart
+= sizeof(DWORD
); /* Size */
1383 pcbSize
->s
.LowPart
+= sizeof(BYTE
); /* StrLength */
1385 if (this->description
.lpstrName
!=0)
1386 pcbSize
->s
.LowPart
+= lstrlenW(this->description
.lpstrName
);