Spelling fixes.
[wine.git] / dlls / oleaut32 / olefont.c
blob96264ade02c6af53955132807a769bf5b12eedcc
1 /*
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
8 */
9 #include <assert.h>
10 #include <string.h>
11 #include "winerror.h"
12 #include "oleauto.h" /* for SysAllocString(....) */
13 #include "wine/obj_olefont.h"
14 #include "wine/obj_storage.h"
15 #include "olectl.h"
16 #include "debugtools.h"
17 #include "heap.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;
33 struct 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.
48 ULONG ref;
51 * This structure contains the description of the class.
53 FONTDESC description;
56 * Contain the font associated with this object.
58 HFONT gdiFont;
61 * Font lock count.
63 DWORD fontLock;
66 * Size ratio
68 long cyLogical;
69 long cyHimetric;
73 * Here, I define utility macros to help with the casting of the
74 * "this" parameter.
75 * There is a version to accomodate all of the VTables implemented
76 * by this object.
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
84 * interface
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
118 * interface
120 static HRESULT WINAPI OLEFontImpl_IDispatch_QueryInterface(IDispatch* iface,
121 REFIID riid,
122 VOID** ppvoid);
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,
128 UINT iTInfo,
129 LCID lcid,
130 ITypeInfo** ppTInfo);
131 static HRESULT WINAPI OLEFontImpl_GetIDsOfNames(IDispatch* iface,
132 REFIID riid,
133 LPOLESTR* rgszNames,
134 UINT cNames,
135 LCID lcid,
136 DISPID* rgDispId);
137 static HRESULT WINAPI OLEFontImpl_Invoke(IDispatch* iface,
138 DISPID dispIdMember,
139 REFIID riid,
140 LCID lcid,
141 WORD wFlags,
142 DISPPARAMS* pDispParams,
143 VARIANT* pVarResult,
144 EXCEPINFO* pExepInfo,
145 UINT* puArgErr);
147 /***********************************************************************
148 * Prototypes for the implementation functions for the IPersistStream
149 * interface
151 static HRESULT WINAPI OLEFontImpl_IPersistStream_QueryInterface(IPersistStream* iface,
152 REFIID riid,
153 VOID** ppvoid);
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,
157 CLSID* pClassID);
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,
162 IStream* pOutStream,
163 BOOL fClearDirty);
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,
174 OLEFontImpl_AddRef,
175 OLEFontImpl_Release,
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,
193 OLEFontImpl_Clone,
194 OLEFontImpl_IsEqual,
195 OLEFontImpl_SetRatio,
196 OLEFontImpl_QueryTextMetrics,
197 OLEFontImpl_AddRefHfont,
198 OLEFontImpl_ReleaseHfont,
199 OLEFontImpl_SetHdc
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,
211 OLEFontImpl_Invoke
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,
221 OLEFontImpl_IsDirty,
222 OLEFontImpl_Load,
223 OLEFontImpl_Save,
224 OLEFontImpl_GetSizeMax
227 /******************************************************************************
228 * OleCreateFontIndirect [OLEAUT32.420]
230 HRESULT WINAPI OleCreateFontIndirect(
231 LPFONTDESC lpFontDesc,
232 REFIID riid,
233 LPVOID* ppvObj)
235 OLEFontImpl* newFont = 0;
236 HRESULT hr = S_OK;
239 * Sanity check
241 if (ppvObj==0)
242 return E_POINTER;
244 *ppvObj = 0;
247 * Try to construct a new instance of the class.
249 newFont = OLEFontImpl_Construct(lpFontDesc);
251 if (newFont == 0)
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);
265 return hr;
269 /***********************************************************************
270 * Implementation of the OLEFontImpl class.
273 /************************************************************************
274 * OLEFontImpl_Construct
276 * This method will construct a new instance of the OLEFontImpl
277 * class.
279 * The caller of this method must release the object when it's
280 * done with it.
282 static OLEFontImpl* OLEFontImpl_Construct(LPFONTDESC fontDesc)
284 OLEFontImpl* newObject = 0;
287 * Allocate space for the object.
289 newObject = HeapAlloc(GetProcessHeap(), 0, sizeof(OLEFontImpl));
291 if (newObject==0)
292 return newObject;
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.
305 newObject->ref = 1;
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;
332 return newObject;
335 /************************************************************************
336 * OLEFontImpl_Construct
338 * This method is called by the Release method when the reference
339 * count goes down to 0. It will free all resources used by
340 * this object.
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(
359 IFont* iface,
360 REFIID riid,
361 void** ppvObject)
363 _ICOM_THIS(OLEFontImpl, iface);
366 * Perform a sanity check on the parameters.
368 if ( (this==0) || (ppvObject==0) )
369 return E_INVALIDARG;
372 * Initialize the return parameter.
374 *ppvObject = 0;
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.
403 if ((*ppvObject)==0)
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
411 * successful
413 OLEFontImpl_AddRef((IFont*)this);
415 return S_OK;;
418 /************************************************************************
419 * OLEFontImpl_AddRef (IUnknown)
421 * See Windows documentation for more details on IUnknown methods.
423 ULONG WINAPI OLEFontImpl_AddRef(
424 IFont* iface)
426 _ICOM_THIS(OLEFontImpl, iface);
428 this->ref++;
430 return this->ref;
433 /************************************************************************
434 * OLEFontImpl_Release (IUnknown)
436 * See Windows documentation for more details on IUnknown methods.
438 ULONG WINAPI OLEFontImpl_Release(
439 IFont* iface)
441 _ICOM_THIS(OLEFontImpl, iface);
444 * Decrease the reference count on this object.
446 this->ref--;
449 * If the reference count goes down to 0, perform suicide.
451 if (this->ref==0)
453 OLEFontImpl_Destroy(this);
455 return 0;
458 return this->ref;
461 /************************************************************************
462 * OLEFontImpl_get_Name (IFont)
464 * See Windows documentation for more details on IFont methods.
466 static HRESULT WINAPI OLEFontImpl_get_Name(
467 IFont* iface,
468 BSTR* pname)
470 _ICOM_THIS(OLEFontImpl, iface);
473 * Sanity check.
475 if (pname==0)
476 return E_POINTER;
478 if (this->description.lpstrName!=0)
479 *pname = SysAllocString(this->description.lpstrName);
480 else
481 *pname = 0;
483 return S_OK;
486 /************************************************************************
487 * OLEFontImpl_put_Name (IFont)
489 * See Windows documentation for more details on IFont methods.
491 static HRESULT WINAPI OLEFontImpl_put_Name(
492 IFont* iface,
493 BSTR name)
495 _ICOM_THIS(OLEFontImpl, iface);
497 if (this->description.lpstrName==0)
499 this->description.lpstrName = HeapAlloc(GetProcessHeap(),
501 (lstrlenW(name)+1) * sizeof(WCHAR));
503 else
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);
516 return S_OK;
519 /************************************************************************
520 * OLEFontImpl_get_Size (IFont)
522 * See Windows documentation for more details on IFont methods.
524 static HRESULT WINAPI OLEFontImpl_get_Size(
525 IFont* iface,
526 CY* psize)
528 _ICOM_THIS(OLEFontImpl, iface);
531 * Sanity check
533 if (psize==0)
534 return E_POINTER;
536 psize->s.Hi = 0;
537 psize->s.Lo = this->description.cySize.s.Lo;
539 return S_OK;
542 /************************************************************************
543 * OLEFontImpl_put_Size (IFont)
545 * See Windows documentation for more details on IFont methods.
547 static HRESULT WINAPI OLEFontImpl_put_Size(
548 IFont* iface,
549 CY size)
551 _ICOM_THIS(OLEFontImpl, iface);
553 this->description.cySize.s.Hi = 0;
554 this->description.cySize.s.Lo = this->description.cySize.s.Lo;
556 return S_OK;
559 /************************************************************************
560 * OLEFontImpl_get_Bold (IFont)
562 * See Windows documentation for more details on IFont methods.
564 static HRESULT WINAPI OLEFontImpl_get_Bold(
565 IFont* iface,
566 BOOL* pbold)
568 FIXME("():Stub\n");
569 return E_NOTIMPL;
572 /************************************************************************
573 * OLEFontImpl_put_Bold (IFont)
575 * See Windows documentation for more details on IFont methods.
577 static HRESULT WINAPI OLEFontImpl_put_Bold(
578 IFont* iface,
579 BOOL bold)
581 FIXME("():Stub\n");
582 return E_NOTIMPL;
585 /************************************************************************
586 * OLEFontImpl_get_Italic (IFont)
588 * See Windows documentation for more details on IFont methods.
590 static HRESULT WINAPI OLEFontImpl_get_Italic(
591 IFont* iface,
592 BOOL* pitalic)
594 _ICOM_THIS(OLEFontImpl, iface);
597 * Sanity check
599 if (pitalic==0)
600 return E_POINTER;
602 *pitalic = this->description.fItalic;
604 return S_OK;
607 /************************************************************************
608 * OLEFontImpl_put_Italic (IFont)
610 * See Windows documentation for more details on IFont methods.
612 static HRESULT WINAPI OLEFontImpl_put_Italic(
613 IFont* iface,
614 BOOL italic)
616 _ICOM_THIS(OLEFontImpl, iface);
618 this->description.fItalic = italic;
620 return S_OK;
623 /************************************************************************
624 * OLEFontImpl_get_Underline (IFont)
626 * See Windows documentation for more details on IFont methods.
628 static HRESULT WINAPI OLEFontImpl_get_Underline(
629 IFont* iface,
630 BOOL* punderline)
632 _ICOM_THIS(OLEFontImpl, iface);
635 * Sanity check
637 if (punderline==0)
638 return E_POINTER;
640 *punderline = this->description.fUnderline;
642 return S_OK;
645 /************************************************************************
646 * OLEFontImpl_put_Underline (IFont)
648 * See Windows documentation for more details on IFont methods.
650 static HRESULT WINAPI OLEFontImpl_put_Underline(
651 IFont* iface,
652 BOOL underline)
654 _ICOM_THIS(OLEFontImpl, iface);
656 this->description.fUnderline = underline;
658 return S_OK;
661 /************************************************************************
662 * OLEFontImpl_get_Strikethrough (IFont)
664 * See Windows documentation for more details on IFont methods.
666 static HRESULT WINAPI OLEFontImpl_get_Strikethrough(
667 IFont* iface,
668 BOOL* pstrikethrough)
670 _ICOM_THIS(OLEFontImpl, iface);
673 * Sanity check
675 if (pstrikethrough==0)
676 return E_POINTER;
678 *pstrikethrough = this->description.fStrikethrough;
680 return S_OK;
683 /************************************************************************
684 * OLEFontImpl_put_Strikethrough (IFont)
686 * See Windows documentation for more details on IFont methods.
688 static HRESULT WINAPI OLEFontImpl_put_Strikethrough(
689 IFont* iface,
690 BOOL strikethrough)
692 _ICOM_THIS(OLEFontImpl, iface);
694 this->description.fStrikethrough = strikethrough;
696 return S_OK;
699 /************************************************************************
700 * OLEFontImpl_get_Weight (IFont)
702 * See Windows documentation for more details on IFont methods.
704 static HRESULT WINAPI OLEFontImpl_get_Weight(
705 IFont* iface,
706 short* pweight)
708 _ICOM_THIS(OLEFontImpl, iface);
711 * Sanity check
713 if (pweight==0)
714 return E_POINTER;
716 *pweight = this->description.sWeight;
718 return S_OK;
721 /************************************************************************
722 * OLEFontImpl_put_Weight (IFont)
724 * See Windows documentation for more details on IFont methods.
726 static HRESULT WINAPI OLEFontImpl_put_Weight(
727 IFont* iface,
728 short weight)
730 _ICOM_THIS(OLEFontImpl, iface);
732 this->description.sWeight = weight;
734 return S_OK;
737 /************************************************************************
738 * OLEFontImpl_get_Charset (IFont)
740 * See Windows documentation for more details on IFont methods.
742 static HRESULT WINAPI OLEFontImpl_get_Charset(
743 IFont* iface,
744 short* pcharset)
746 _ICOM_THIS(OLEFontImpl, iface);
749 * Sanity check
751 if (pcharset==0)
752 return E_POINTER;
754 *pcharset = this->description.sCharset;
756 return S_OK;
759 /************************************************************************
760 * OLEFontImpl_put_Charset (IFont)
762 * See Windows documentation for more details on IFont methods.
764 static HRESULT WINAPI OLEFontImpl_put_Charset(
765 IFont* iface,
766 short charset)
768 _ICOM_THIS(OLEFontImpl, iface);
770 this->description.sCharset = charset;
772 return S_OK;
775 /************************************************************************
776 * OLEFontImpl_get_hFont (IFont)
778 * See Windows documentation for more details on IFont methods.
780 static HRESULT WINAPI OLEFontImpl_get_hFont(
781 IFont* iface,
782 HFONT* phfont)
784 _ICOM_THIS(OLEFontImpl, iface);
786 if (phfont==NULL)
787 return E_POINTER;
790 * Realize the font if necessary
792 if (this->gdiFont==0)
794 LOGFONTW logFont;
795 INT fontHeight;
796 CY cySize;
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;
829 return S_OK;
832 /************************************************************************
833 * OLEFontImpl_Clone (IFont)
835 * See Windows documentation for more details on IFont methods.
837 static HRESULT WINAPI OLEFontImpl_Clone(
838 IFont* iface,
839 IFont** ppfont)
841 OLEFontImpl* newObject = 0;
843 _ICOM_THIS(OLEFontImpl, iface);
845 if (ppfont == NULL)
846 return E_POINTER;
848 *ppfont = NULL;
851 * Allocate space for the object.
853 newObject = HeapAlloc(GetProcessHeap(), 0, sizeof(OLEFontImpl));
855 if (newObject==NULL)
856 return E_OUTOFMEMORY;
858 *newObject = *this;
861 * That new object starts with a reference count of 1
863 newObject->ref = 1;
865 *ppfont = (IFont*)newObject;
867 return S_OK;
870 /************************************************************************
871 * OLEFontImpl_IsEqual (IFont)
873 * See Windows documentation for more details on IFont methods.
875 static HRESULT WINAPI OLEFontImpl_IsEqual(
876 IFont* iface,
877 IFont* pFontOther)
879 FIXME("():Stub\n");
880 return E_NOTIMPL;
883 /************************************************************************
884 * OLEFontImpl_SetRatio (IFont)
886 * See Windows documentation for more details on IFont methods.
888 static HRESULT WINAPI OLEFontImpl_SetRatio(
889 IFont* iface,
890 long cyLogical,
891 long cyHimetric)
893 _ICOM_THIS(OLEFontImpl, iface);
895 this->cyLogical = cyLogical;
896 this->cyHimetric = cyHimetric;
898 return S_OK;
901 /************************************************************************
902 * OLEFontImpl_QueryTextMetrics (IFont)
904 * See Windows documentation for more details on IFont methods.
906 static HRESULT WINAPI OLEFontImpl_QueryTextMetrics(
907 IFont* iface,
908 TEXTMETRICOLE* ptm)
910 FIXME("():Stub\n");
911 return E_NOTIMPL;
914 /************************************************************************
915 * OLEFontImpl_AddRefHfont (IFont)
917 * See Windows documentation for more details on IFont methods.
919 static HRESULT WINAPI OLEFontImpl_AddRefHfont(
920 IFont* iface,
921 HFONT hfont)
923 _ICOM_THIS(OLEFontImpl, iface);
925 if ( (hfont == 0) ||
926 (hfont != this->gdiFont) )
927 return E_INVALIDARG;
929 this->fontLock++;
931 return S_OK;
934 /************************************************************************
935 * OLEFontImpl_ReleaseHfont (IFont)
937 * See Windows documentation for more details on IFont methods.
939 static HRESULT WINAPI OLEFontImpl_ReleaseHfont(
940 IFont* iface,
941 HFONT hfont)
943 _ICOM_THIS(OLEFontImpl, iface);
945 if ( (hfont == 0) ||
946 (hfont != this->gdiFont) )
947 return E_INVALIDARG;
949 this->fontLock--;
952 * If we just released our last font reference, destroy it.
954 if (this->fontLock==0)
956 DeleteObject(this->gdiFont);
957 this->gdiFont = 0;
960 return S_OK;
963 /************************************************************************
964 * OLEFontImpl_SetHdc (IFont)
966 * See Windows documentation for more details on IFont methods.
968 static HRESULT WINAPI OLEFontImpl_SetHdc(
969 IFont* iface,
970 HDC hdc)
972 FIXME("():Stub\n");
973 return E_NOTIMPL;
976 /************************************************************************
977 * OLEFontImpl_IDispatch_QueryInterface (IUnknown)
979 * See Windows documentation for more details on IUnknown methods.
981 static HRESULT WINAPI OLEFontImpl_IDispatch_QueryInterface(
982 IDispatch* iface,
983 REFIID riid,
984 VOID** ppvoid)
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(
997 IDispatch* iface)
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(
1010 IDispatch* iface)
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(
1023 IDispatch* iface,
1024 unsigned int* pctinfo)
1026 FIXME("():Stub\n");
1028 return E_NOTIMPL;
1031 /************************************************************************
1032 * OLEFontImpl_GetTypeInfo (IDispatch)
1034 * See Windows documentation for more details on IDispatch methods.
1036 static HRESULT WINAPI OLEFontImpl_GetTypeInfo(
1037 IDispatch* iface,
1038 UINT iTInfo,
1039 LCID lcid,
1040 ITypeInfo** ppTInfo)
1042 FIXME("():Stub\n");
1044 return E_NOTIMPL;
1047 /************************************************************************
1048 * OLEFontImpl_GetIDsOfNames (IDispatch)
1050 * See Windows documentation for more details on IDispatch methods.
1052 static HRESULT WINAPI OLEFontImpl_GetIDsOfNames(
1053 IDispatch* iface,
1054 REFIID riid,
1055 LPOLESTR* rgszNames,
1056 UINT cNames,
1057 LCID lcid,
1058 DISPID* rgDispId)
1060 FIXME("():Stub\n");
1062 return E_NOTIMPL;
1065 /************************************************************************
1066 * OLEFontImpl_Invoke (IDispatch)
1068 * See Windows documentation for more details on IDispatch methods.
1070 static HRESULT WINAPI OLEFontImpl_Invoke(
1071 IDispatch* iface,
1072 DISPID dispIdMember,
1073 REFIID riid,
1074 LCID lcid,
1075 WORD wFlags,
1076 DISPPARAMS* pDispParams,
1077 VARIANT* pVarResult,
1078 EXCEPINFO* pExepInfo,
1079 UINT* puArgErr)
1081 FIXME("():Stub\n");
1083 return E_NOTIMPL;
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,
1093 REFIID riid,
1094 VOID** ppvoid)
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,
1134 CLSID* pClassID)
1136 if (pClassID==0)
1137 return E_POINTER;
1139 memcpy(pClassID, &CLSID_StdFont, sizeof(CLSID_StdFont));
1141 return S_OK;
1144 /************************************************************************
1145 * OLEFontImpl_IsDirty (IPersistStream)
1147 * See Windows documentation for more details on IPersistStream methods.
1149 static HRESULT WINAPI OLEFontImpl_IsDirty(
1150 IPersistStream* iface)
1152 return S_OK;
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
1161 * know
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:
1167 * 00000010 - Italic
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
1172 * structure/
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];
1181 ULONG cbRead;
1182 BYTE bVersion;
1183 BYTE bAttributes;
1184 BYTE bStringSize;
1186 _ICOM_THIS_From_IPersistStream(OLEFontImpl, iface);
1189 * Read the version byte
1191 IStream_Read(pLoadStream, &bVersion, 1, &cbRead);
1193 if ( (cbRead!=1) ||
1194 (bVersion!=0x01) )
1195 return E_FAIL;
1198 * Charset
1200 IStream_Read(pLoadStream, &this->description.sCharset, 2, &cbRead);
1202 if (cbRead!=2)
1203 return E_FAIL;
1206 * Attributes
1208 IStream_Read(pLoadStream, &bAttributes, 1, &cbRead);
1210 if (cbRead!=1)
1211 return E_FAIL;
1213 this->description.fItalic = (bAttributes & FONTPERSIST_ITALIC) != 0;
1214 this->description.fStrikethrough = (bAttributes & FONTPERSIST_STRIKETHROUGH) != 0;
1215 this->description.fUnderline = (bAttributes & FONTPERSIST_UNDERLINE) != 0;
1218 * Weight
1220 IStream_Read(pLoadStream, &this->description.sWeight, 2, &cbRead);
1222 if (cbRead!=2)
1223 return E_FAIL;
1226 * Size
1228 IStream_Read(pLoadStream, &this->description.cySize.s.Lo, 4, &cbRead);
1230 if (cbRead!=4)
1231 return E_FAIL;
1233 this->description.cySize.s.Hi = 0;
1236 * FontName
1238 IStream_Read(pLoadStream, &bStringSize, 1, &cbRead);
1240 if (cbRead!=1)
1241 return E_FAIL;
1243 memset(readBuffer, 0, 0x100);
1244 IStream_Read(pLoadStream, readBuffer, bStringSize, &cbRead);
1246 if (cbRead!=bStringSize)
1247 return E_FAIL;
1249 if (this->description.lpstrName!=0)
1250 HeapFree(GetProcessHeap(), 0, this->description.lpstrName);
1252 this->description.lpstrName = HEAP_strdupAtoW(GetProcessHeap(),
1253 HEAP_ZERO_MEMORY,
1254 readBuffer);
1256 return S_OK;
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,
1267 BOOL fClearDirty)
1269 char* writeBuffer = NULL;
1270 ULONG cbWritten;
1271 BYTE bVersion = 0x01;
1272 BYTE bAttributes;
1273 BYTE bStringSize;
1275 _ICOM_THIS_From_IPersistStream(OLEFontImpl, iface);
1278 * Read the version byte
1280 IStream_Write(pOutStream, &bVersion, 1, &cbWritten);
1282 if (cbWritten!=1)
1283 return E_FAIL;
1286 * Charset
1288 IStream_Write(pOutStream, &this->description.sCharset, 2, &cbWritten);
1290 if (cbWritten!=2)
1291 return E_FAIL;
1294 * Attributes
1296 bAttributes = 0;
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);
1309 if (cbWritten!=1)
1310 return E_FAIL;
1313 * Weight
1315 IStream_Write(pOutStream, &this->description.sWeight, 2, &cbWritten);
1317 if (cbWritten!=2)
1318 return E_FAIL;
1321 * Size
1323 IStream_Write(pOutStream, &this->description.cySize.s.Lo, 4, &cbWritten);
1325 if (cbWritten!=4)
1326 return E_FAIL;
1329 * FontName
1331 if (this->description.lpstrName!=0)
1332 bStringSize = lstrlenW(this->description.lpstrName);
1333 else
1334 bStringSize = 0;
1336 IStream_Write(pOutStream, &bStringSize, 1, &cbWritten);
1338 if (cbWritten!=1)
1339 return E_FAIL;
1341 if (bStringSize!=0)
1343 writeBuffer = HEAP_strdupWtoA(GetProcessHeap(),
1344 HEAP_ZERO_MEMORY,
1345 this->description.lpstrName);
1347 if (writeBuffer==0)
1348 return E_OUTOFMEMORY;
1350 IStream_Write(pOutStream, writeBuffer, bStringSize, &cbWritten);
1352 HeapFree(GetProcessHeap(), 0, writeBuffer);
1354 if (cbWritten!=bStringSize)
1355 return E_FAIL;
1358 return S_OK;
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);
1372 if (pcbSize==NULL)
1373 return E_POINTER;
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);
1388 return S_OK;