Test for static was reversed.
[wine.git] / ole / olefont.c
blob5640fa1f9dd1de181a76964323c96385bcf17efb
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"
13 #include "ocidl.h"
14 #include "olectl.h"
15 #include "debug.h"
16 #include "heap.h"
18 DEFAULT_DEBUG_CHANNEL(ole)
20 /***********************************************************************
21 * Declaration of constants used when serializing the font object.
23 #define FONTPERSIST_ITALIC 0x02
24 #define FONTPERSIST_UNDERLINE 0x04
25 #define FONTPERSIST_STRIKETHROUGH 0x08
27 /***********************************************************************
28 * Declaration of the implementation class for the IFont interface
30 typedef struct OLEFontImpl OLEFontImpl;
32 struct 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.
47 ULONG ref;
50 * This structure contains the description of the class.
52 FONTDESC description;
55 * Contain the font associated with this object.
57 HFONT gdiFont;
60 * Font lock count.
62 DWORD fontLock;
65 * Size ratio
67 long cyLogical;
68 long cyHimetric;
72 * Here, I define utility macros to help with the casting of the
73 * "this" parameter.
74 * There is a version to accomodate all of the VTables implemented
75 * by this object.
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
83 * interface
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
117 * interface
119 static HRESULT WINAPI OLEFontImpl_IDispatch_QueryInterface(IDispatch* iface,
120 REFIID riid,
121 VOID** ppvoid);
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,
127 UINT iTInfo,
128 LCID lcid,
129 ITypeInfo** ppTInfo);
130 static HRESULT WINAPI OLEFontImpl_GetIDsOfNames(IDispatch* iface,
131 REFIID riid,
132 LPOLESTR* rgszNames,
133 UINT cNames,
134 LCID lcid,
135 DISPID* rgDispId);
136 static HRESULT WINAPI OLEFontImpl_Invoke(IDispatch* iface,
137 DISPID dispIdMember,
138 REFIID riid,
139 LCID lcid,
140 WORD wFlags,
141 DISPPARAMS* pDispParams,
142 VARIANT* pVarResult,
143 EXCEPINFO* pExepInfo,
144 UINT* puArgErr);
146 /***********************************************************************
147 * Prototypes for the implementation functions for the IPersistStream
148 * interface
150 static HRESULT WINAPI OLEFontImpl_IPersistStream_QueryInterface(IPersistStream* iface,
151 REFIID riid,
152 VOID** ppvoid);
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,
156 CLSID* pClassID);
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,
161 IStream* pOutStream,
162 BOOL fClearDirty);
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,
172 OLEFontImpl_AddRef,
173 OLEFontImpl_Release,
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,
191 OLEFontImpl_Clone,
192 OLEFontImpl_IsEqual,
193 OLEFontImpl_SetRatio,
194 OLEFontImpl_QueryTextMetrics,
195 OLEFontImpl_AddRefHfont,
196 OLEFontImpl_ReleaseHfont,
197 OLEFontImpl_SetHdc
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,
208 OLEFontImpl_Invoke
211 static ICOM_VTABLE(IPersistStream) OLEFontImpl_IPersistStream_VTable =
213 OLEFontImpl_IPersistStream_QueryInterface,
214 OLEFontImpl_IPersistStream_AddRef,
215 OLEFontImpl_IPersistStream_Release,
216 OLEFontImpl_GetClassID,
217 OLEFontImpl_IsDirty,
218 OLEFontImpl_Load,
219 OLEFontImpl_Save,
220 OLEFontImpl_GetSizeMax
223 /******************************************************************************
224 * OleCreateFontIndirect [OLEAUT32.420]
226 WINOLECTLAPI OleCreateFontIndirect(
227 LPFONTDESC lpFontDesc,
228 REFIID riid,
229 VOID** ppvObj)
231 OLEFontImpl* newFont = 0;
232 HRESULT hr = S_OK;
235 * Sanity check
237 if (ppvObj==0)
238 return E_POINTER;
240 *ppvObj = 0;
243 * Try to construct a new instance of the class.
245 newFont = OLEFontImpl_Construct(lpFontDesc);
247 if (newFont == 0)
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);
261 return hr;
265 /***********************************************************************
266 * Implementation of the OLEFontImpl class.
269 /************************************************************************
270 * OLEFontImpl_Construct
272 * This method will construct a new instance of the OLEFontImpl
273 * class.
275 * The caller of this method must release the object when it's
276 * done with it.
278 static OLEFontImpl* OLEFontImpl_Construct(LPFONTDESC fontDesc)
280 OLEFontImpl* newObject = 0;
283 * Allocate space for the object.
285 newObject = HeapAlloc(GetProcessHeap(), 0, sizeof(OLEFontImpl));
287 if (newObject==0)
288 return newObject;
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.
301 newObject->ref = 1;
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;
328 return newObject;
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
336 * this object.
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(
355 IFont* iface,
356 REFIID riid,
357 void** ppvObject)
359 _ICOM_THIS(OLEFontImpl, iface);
362 * Perform a sanity check on the parameters.
364 if ( (this==0) || (ppvObject==0) )
365 return E_INVALIDARG;
368 * Initialize the return parameter.
370 *ppvObject = 0;
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.
399 if ((*ppvObject)==0)
401 char clsid[50];
403 WINE_StringFromCLSID((LPCLSID)riid,clsid);
405 WARN(ole,
406 "() : asking for un supported interface %s\n",
407 clsid);
409 return E_NOINTERFACE;
413 * Query Interface always increases the reference count by one when it is
414 * successful
416 OLEFontImpl_AddRef((IFont*)this);
418 return S_OK;;
421 /************************************************************************
422 * OLEFontImpl_AddRef (IUnknown)
424 * See Windows documentation for more details on IUnknown methods.
426 ULONG WINAPI OLEFontImpl_AddRef(
427 IFont* iface)
429 _ICOM_THIS(OLEFontImpl, iface);
431 this->ref++;
433 return this->ref;
436 /************************************************************************
437 * OLEFontImpl_Release (IUnknown)
439 * See Windows documentation for more details on IUnknown methods.
441 ULONG WINAPI OLEFontImpl_Release(
442 IFont* iface)
444 _ICOM_THIS(OLEFontImpl, iface);
447 * Decrease the reference count on this object.
449 this->ref--;
452 * If the reference count goes down to 0, perform suicide.
454 if (this->ref==0)
456 OLEFontImpl_Destroy(this);
458 return 0;
461 return this->ref;
464 /************************************************************************
465 * OLEFontImpl_get_Name (IFont)
467 * See Windows documentation for more details on IFont methods.
469 static HRESULT WINAPI OLEFontImpl_get_Name(
470 IFont* iface,
471 BSTR* pname)
473 _ICOM_THIS(OLEFontImpl, iface);
476 * Sanity check.
478 if (pname==0)
479 return E_POINTER;
481 if (this->description.lpstrName!=0)
482 *pname = SysAllocString(this->description.lpstrName);
483 else
484 *pname = 0;
486 return S_OK;
489 /************************************************************************
490 * OLEFontImpl_put_Name (IFont)
492 * See Windows documentation for more details on IFont methods.
494 static HRESULT WINAPI OLEFontImpl_put_Name(
495 IFont* iface,
496 BSTR name)
498 _ICOM_THIS(OLEFontImpl, iface);
500 if (this->description.lpstrName==0)
502 this->description.lpstrName = HeapAlloc(GetProcessHeap(),
504 (lstrlenW(name)+1) * sizeof(WCHAR));
506 else
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);
519 return S_OK;
522 /************************************************************************
523 * OLEFontImpl_get_Size (IFont)
525 * See Windows documentation for more details on IFont methods.
527 static HRESULT WINAPI OLEFontImpl_get_Size(
528 IFont* iface,
529 CY* psize)
531 _ICOM_THIS(OLEFontImpl, iface);
534 * Sanity check
536 if (psize==0)
537 return E_POINTER;
539 psize->u.Hi = 0;
540 psize->u.Lo = this->description.cySize.u.Lo;
542 return S_OK;
545 /************************************************************************
546 * OLEFontImpl_put_Size (IFont)
548 * See Windows documentation for more details on IFont methods.
550 static HRESULT WINAPI OLEFontImpl_put_Size(
551 IFont* iface,
552 CY size)
554 _ICOM_THIS(OLEFontImpl, iface);
556 this->description.cySize.u.Hi = 0;
557 this->description.cySize.u.Lo = this->description.cySize.u.Lo;
559 return S_OK;
562 /************************************************************************
563 * OLEFontImpl_get_Bold (IFont)
565 * See Windows documentation for more details on IFont methods.
567 static HRESULT WINAPI OLEFontImpl_get_Bold(
568 IFont* iface,
569 BOOL* pbold)
571 FIXME(ole,"():Stub\n");
572 return E_NOTIMPL;
575 /************************************************************************
576 * OLEFontImpl_put_Bold (IFont)
578 * See Windows documentation for more details on IFont methods.
580 static HRESULT WINAPI OLEFontImpl_put_Bold(
581 IFont* iface,
582 BOOL bold)
584 FIXME(ole,"():Stub\n");
585 return E_NOTIMPL;
588 /************************************************************************
589 * OLEFontImpl_get_Italic (IFont)
591 * See Windows documentation for more details on IFont methods.
593 static HRESULT WINAPI OLEFontImpl_get_Italic(
594 IFont* iface,
595 BOOL* pitalic)
597 _ICOM_THIS(OLEFontImpl, iface);
600 * Sanity check
602 if (pitalic==0)
603 return E_POINTER;
605 *pitalic = this->description.fItalic;
607 return S_OK;
610 /************************************************************************
611 * OLEFontImpl_put_Italic (IFont)
613 * See Windows documentation for more details on IFont methods.
615 static HRESULT WINAPI OLEFontImpl_put_Italic(
616 IFont* iface,
617 BOOL italic)
619 _ICOM_THIS(OLEFontImpl, iface);
621 this->description.fItalic = italic;
623 return S_OK;
626 /************************************************************************
627 * OLEFontImpl_get_Underline (IFont)
629 * See Windows documentation for more details on IFont methods.
631 static HRESULT WINAPI OLEFontImpl_get_Underline(
632 IFont* iface,
633 BOOL* punderline)
635 _ICOM_THIS(OLEFontImpl, iface);
638 * Sanity check
640 if (punderline==0)
641 return E_POINTER;
643 *punderline = this->description.fUnderline;
645 return S_OK;
648 /************************************************************************
649 * OLEFontImpl_put_Underline (IFont)
651 * See Windows documentation for more details on IFont methods.
653 static HRESULT WINAPI OLEFontImpl_put_Underline(
654 IFont* iface,
655 BOOL underline)
657 _ICOM_THIS(OLEFontImpl, iface);
659 this->description.fUnderline = underline;
661 return S_OK;
664 /************************************************************************
665 * OLEFontImpl_get_Strikethrough (IFont)
667 * See Windows documentation for more details on IFont methods.
669 static HRESULT WINAPI OLEFontImpl_get_Strikethrough(
670 IFont* iface,
671 BOOL* pstrikethrough)
673 _ICOM_THIS(OLEFontImpl, iface);
676 * Sanity check
678 if (pstrikethrough==0)
679 return E_POINTER;
681 *pstrikethrough = this->description.fStrikethrough;
683 return S_OK;
686 /************************************************************************
687 * OLEFontImpl_put_Strikethrough (IFont)
689 * See Windows documentation for more details on IFont methods.
691 static HRESULT WINAPI OLEFontImpl_put_Strikethrough(
692 IFont* iface,
693 BOOL strikethrough)
695 _ICOM_THIS(OLEFontImpl, iface);
697 this->description.fStrikethrough = strikethrough;
699 return S_OK;
702 /************************************************************************
703 * OLEFontImpl_get_Weight (IFont)
705 * See Windows documentation for more details on IFont methods.
707 static HRESULT WINAPI OLEFontImpl_get_Weight(
708 IFont* iface,
709 short* pweight)
711 _ICOM_THIS(OLEFontImpl, iface);
714 * Sanity check
716 if (pweight==0)
717 return E_POINTER;
719 *pweight = this->description.sWeight;
721 return S_OK;
724 /************************************************************************
725 * OLEFontImpl_put_Weight (IFont)
727 * See Windows documentation for more details on IFont methods.
729 static HRESULT WINAPI OLEFontImpl_put_Weight(
730 IFont* iface,
731 short weight)
733 _ICOM_THIS(OLEFontImpl, iface);
735 this->description.sWeight = weight;
737 return S_OK;
740 /************************************************************************
741 * OLEFontImpl_get_Charset (IFont)
743 * See Windows documentation for more details on IFont methods.
745 static HRESULT WINAPI OLEFontImpl_get_Charset(
746 IFont* iface,
747 short* pcharset)
749 _ICOM_THIS(OLEFontImpl, iface);
752 * Sanity check
754 if (pcharset==0)
755 return E_POINTER;
757 *pcharset = this->description.sCharset;
759 return S_OK;
762 /************************************************************************
763 * OLEFontImpl_put_Charset (IFont)
765 * See Windows documentation for more details on IFont methods.
767 static HRESULT WINAPI OLEFontImpl_put_Charset(
768 IFont* iface,
769 short charset)
771 _ICOM_THIS(OLEFontImpl, iface);
773 this->description.sCharset = charset;
775 return S_OK;
778 /************************************************************************
779 * OLEFontImpl_get_hFont (IFont)
781 * See Windows documentation for more details on IFont methods.
783 static HRESULT WINAPI OLEFontImpl_get_hFont(
784 IFont* iface,
785 HFONT* phfont)
787 _ICOM_THIS(OLEFontImpl, iface);
789 if (phfont==NULL)
790 return E_POINTER;
793 * Realize the font if necessary
795 if (this->gdiFont==0)
797 LOGFONTW logFont;
798 INT fontHeight;
799 CY cySize;
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;
832 return S_OK;
835 /************************************************************************
836 * OLEFontImpl_Clone (IFont)
838 * See Windows documentation for more details on IFont methods.
840 static HRESULT WINAPI OLEFontImpl_Clone(
841 IFont* iface,
842 IFont** ppfont)
844 OLEFontImpl* newObject = 0;
846 _ICOM_THIS(OLEFontImpl, iface);
848 if (ppfont == NULL)
849 return E_POINTER;
851 *ppfont = NULL;
854 * Allocate space for the object.
856 newObject = HeapAlloc(GetProcessHeap(), 0, sizeof(OLEFontImpl));
858 if (newObject==NULL)
859 return E_OUTOFMEMORY;
861 *newObject = *this;
864 * That new object starts with a reference count of 1
866 newObject->ref = 1;
868 *ppfont = (IFont*)newObject;
870 return S_OK;
873 /************************************************************************
874 * OLEFontImpl_IsEqual (IFont)
876 * See Windows documentation for more details on IFont methods.
878 static HRESULT WINAPI OLEFontImpl_IsEqual(
879 IFont* iface,
880 IFont* pFontOther)
882 FIXME(ole,"():Stub\n");
883 return E_NOTIMPL;
886 /************************************************************************
887 * OLEFontImpl_SetRatio (IFont)
889 * See Windows documentation for more details on IFont methods.
891 static HRESULT WINAPI OLEFontImpl_SetRatio(
892 IFont* iface,
893 long cyLogical,
894 long cyHimetric)
896 _ICOM_THIS(OLEFontImpl, iface);
898 this->cyLogical = cyLogical;
899 this->cyHimetric = cyHimetric;
901 return S_OK;
904 /************************************************************************
905 * OLEFontImpl_QueryTextMetrics (IFont)
907 * See Windows documentation for more details on IFont methods.
909 static HRESULT WINAPI OLEFontImpl_QueryTextMetrics(
910 IFont* iface,
911 TEXTMETRICOLE* ptm)
913 FIXME(ole,"():Stub\n");
914 return E_NOTIMPL;
917 /************************************************************************
918 * OLEFontImpl_AddRefHfont (IFont)
920 * See Windows documentation for more details on IFont methods.
922 static HRESULT WINAPI OLEFontImpl_AddRefHfont(
923 IFont* iface,
924 HFONT hfont)
926 _ICOM_THIS(OLEFontImpl, iface);
928 if ( (hfont == 0) ||
929 (hfont != this->gdiFont) )
930 return E_INVALIDARG;
932 this->fontLock++;
934 return S_OK;
937 /************************************************************************
938 * OLEFontImpl_ReleaseHfont (IFont)
940 * See Windows documentation for more details on IFont methods.
942 static HRESULT WINAPI OLEFontImpl_ReleaseHfont(
943 IFont* iface,
944 HFONT hfont)
946 _ICOM_THIS(OLEFontImpl, iface);
948 if ( (hfont == 0) ||
949 (hfont != this->gdiFont) )
950 return E_INVALIDARG;
952 this->fontLock--;
955 * If we just released our last font reference, destroy it.
957 if (this->fontLock==0)
959 DeleteObject(this->gdiFont);
960 this->gdiFont = 0;
963 return S_OK;
966 /************************************************************************
967 * OLEFontImpl_SetHdc (IFont)
969 * See Windows documentation for more details on IFont methods.
971 static HRESULT WINAPI OLEFontImpl_SetHdc(
972 IFont* iface,
973 HDC hdc)
975 FIXME(ole,"():Stub\n");
976 return E_NOTIMPL;
979 /************************************************************************
980 * OLEFontImpl_IDispatch_QueryInterface (IUnknown)
982 * See Windows documentation for more details on IUnknown methods.
984 static HRESULT WINAPI OLEFontImpl_IDispatch_QueryInterface(
985 IDispatch* iface,
986 REFIID riid,
987 VOID** ppvoid)
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(
1000 IDispatch* iface)
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(
1013 IDispatch* iface)
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(
1026 IDispatch* iface,
1027 unsigned int* pctinfo)
1029 FIXME(ole,"():Stub\n");
1031 return E_NOTIMPL;
1034 /************************************************************************
1035 * OLEFontImpl_GetTypeInfo (IDispatch)
1037 * See Windows documentation for more details on IDispatch methods.
1039 static HRESULT WINAPI OLEFontImpl_GetTypeInfo(
1040 IDispatch* iface,
1041 UINT iTInfo,
1042 LCID lcid,
1043 ITypeInfo** ppTInfo)
1045 FIXME(ole,"():Stub\n");
1047 return E_NOTIMPL;
1050 /************************************************************************
1051 * OLEFontImpl_GetIDsOfNames (IDispatch)
1053 * See Windows documentation for more details on IDispatch methods.
1055 static HRESULT WINAPI OLEFontImpl_GetIDsOfNames(
1056 IDispatch* iface,
1057 REFIID riid,
1058 LPOLESTR* rgszNames,
1059 UINT cNames,
1060 LCID lcid,
1061 DISPID* rgDispId)
1063 FIXME(ole,"():Stub\n");
1065 return E_NOTIMPL;
1068 /************************************************************************
1069 * OLEFontImpl_Invoke (IDispatch)
1071 * See Windows documentation for more details on IDispatch methods.
1073 static HRESULT WINAPI OLEFontImpl_Invoke(
1074 IDispatch* iface,
1075 DISPID dispIdMember,
1076 REFIID riid,
1077 LCID lcid,
1078 WORD wFlags,
1079 DISPPARAMS* pDispParams,
1080 VARIANT* pVarResult,
1081 EXCEPINFO* pExepInfo,
1082 UINT* puArgErr)
1084 FIXME(ole,"():Stub\n");
1086 return E_NOTIMPL;
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,
1096 REFIID riid,
1097 VOID** ppvoid)
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,
1137 CLSID* pClassID)
1139 if (pClassID==0)
1140 return E_POINTER;
1142 memcpy(pClassID, &CLSID_StdFont, sizeof(CLSID_StdFont));
1144 return S_OK;
1147 /************************************************************************
1148 * OLEFontImpl_IsDirty (IPersistStream)
1150 * See Windows documentation for more details on IPersistStream methods.
1152 static HRESULT WINAPI OLEFontImpl_IsDirty(
1153 IPersistStream* iface)
1155 return S_OK;
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
1164 * know
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:
1170 * 00000010 - Italic
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
1175 * structure/
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];
1184 ULONG cbRead;
1185 BYTE bVersion;
1186 BYTE bAttributes;
1187 BYTE bStringSize;
1189 _ICOM_THIS_From_IPersistStream(OLEFontImpl, iface);
1192 * Read the version byte
1194 IStream_Read(pLoadStream, &bVersion, 1, &cbRead);
1196 if ( (cbRead!=1) ||
1197 (bVersion!=0x01) )
1198 return E_FAIL;
1201 * Charset
1203 IStream_Read(pLoadStream, &this->description.sCharset, 2, &cbRead);
1205 if (cbRead!=2)
1206 return E_FAIL;
1209 * Attributes
1211 IStream_Read(pLoadStream, &bAttributes, 1, &cbRead);
1213 if (cbRead!=1)
1214 return E_FAIL;
1216 this->description.fItalic = (bAttributes & FONTPERSIST_ITALIC) != 0;
1217 this->description.fStrikethrough = (bAttributes & FONTPERSIST_STRIKETHROUGH) != 0;
1218 this->description.fUnderline = (bAttributes & FONTPERSIST_UNDERLINE) != 0;
1221 * Weight
1223 IStream_Read(pLoadStream, &this->description.sWeight, 2, &cbRead);
1225 if (cbRead!=2)
1226 return E_FAIL;
1229 * Size
1231 IStream_Read(pLoadStream, &this->description.cySize.u.Lo, 4, &cbRead);
1233 if (cbRead!=4)
1234 return E_FAIL;
1236 this->description.cySize.u.Hi = 0;
1239 * FontName
1241 IStream_Read(pLoadStream, &bStringSize, 1, &cbRead);
1243 if (cbRead!=1)
1244 return E_FAIL;
1246 memset(readBuffer, 0, 0x100);
1247 IStream_Read(pLoadStream, readBuffer, bStringSize, &cbRead);
1249 if (cbRead!=bStringSize)
1250 return E_FAIL;
1252 if (this->description.lpstrName!=0)
1253 HeapFree(GetProcessHeap(), 0, this->description.lpstrName);
1255 this->description.lpstrName = HEAP_strdupAtoW(GetProcessHeap(),
1256 HEAP_ZERO_MEMORY,
1257 readBuffer);
1259 return S_OK;
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,
1270 BOOL fClearDirty)
1272 char* writeBuffer = NULL;
1273 ULONG cbWritten;
1274 BYTE bVersion = 0x01;
1275 BYTE bAttributes;
1276 BYTE bStringSize;
1278 _ICOM_THIS_From_IPersistStream(OLEFontImpl, iface);
1281 * Read the version byte
1283 IStream_Write(pOutStream, &bVersion, 1, &cbWritten);
1285 if (cbWritten!=1)
1286 return E_FAIL;
1289 * Charset
1291 IStream_Write(pOutStream, &this->description.sCharset, 2, &cbWritten);
1293 if (cbWritten!=2)
1294 return E_FAIL;
1297 * Attributes
1299 bAttributes = 0;
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);
1312 if (cbWritten!=1)
1313 return E_FAIL;
1316 * Weight
1318 IStream_Write(pOutStream, &this->description.sWeight, 2, &cbWritten);
1320 if (cbWritten!=2)
1321 return E_FAIL;
1324 * Size
1326 IStream_Write(pOutStream, &this->description.cySize.u.Lo, 4, &cbWritten);
1328 if (cbWritten!=4)
1329 return E_FAIL;
1332 * FontName
1334 if (this->description.lpstrName!=0)
1335 bStringSize = lstrlenW(this->description.lpstrName);
1336 else
1337 bStringSize = 0;
1339 IStream_Write(pOutStream, &bStringSize, 1, &cbWritten);
1341 if (cbWritten!=1)
1342 return E_FAIL;
1344 if (bStringSize!=0)
1346 writeBuffer = HEAP_strdupWtoA(GetProcessHeap(),
1347 HEAP_ZERO_MEMORY,
1348 this->description.lpstrName);
1350 if (writeBuffer==0)
1351 return E_OUTOFMEMORY;
1353 IStream_Write(pOutStream, writeBuffer, bStringSize, &cbWritten);
1355 HeapFree(GetProcessHeap(), 0, writeBuffer);
1357 if (cbWritten!=bStringSize)
1358 return E_FAIL;
1361 return S_OK;
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);
1375 if (pcbSize==NULL)
1376 return E_POINTER;
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);
1391 return S_OK;