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
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 #define NONAMELESSUNION
29 #define NONAMELESSSTRUCT
36 #include "wine/unicode.h"
38 #include "oleauto.h" /* for SysAllocString(....) */
41 #include "wine/debug.h"
42 #include "connpt.h" /* for CreateConnectionPoint */
44 WINE_DEFAULT_DEBUG_CHANNEL(ole);
46 /***********************************************************************
47 * Declaration of constants used when serializing the font object.
49 #define FONTPERSIST_ITALIC 0x02
50 #define FONTPERSIST_UNDERLINE 0x04
51 #define FONTPERSIST_STRIKETHROUGH 0x08
53 /***********************************************************************
54 * Declaration of the implementation class for the IFont interface
56 typedef struct OLEFontImpl OLEFontImpl;
61 * This class supports many interfaces. IUnknown, IFont,
62 * IDispatch, IDispFont IPersistStream and IConnectionPointContainer.
63 * The first two are supported by the first vtable, the next two are
64 * supported by the second table and the last two have their own.
67 IDispatchVtbl* lpvtbl2;
68 IPersistStreamVtbl* lpvtbl3;
69 IConnectionPointContainerVtbl* lpvtbl4;
70 IPersistPropertyBagVtbl* lpvtbl5;
71 IPersistStreamInitVtbl* lpvtbl6;
73 * Reference count for that instance of the class.
78 * This structure contains the description of the class.
83 * Contain the font associated with this object.
98 IConnectionPoint *pCP;
102 * Here, I define utility macros to help with the casting of the
104 * There is a version to accomodate all of the VTables implemented
107 #define _ICOM_THIS(class,name) class* this = (class*)name
108 #define _ICOM_THIS_From_IDispatch(class, name) class* this = (class*)(((char*)name)-sizeof(void*))
109 #define _ICOM_THIS_From_IPersistStream(class, name) class* this = (class*)(((char*)name)-2*sizeof(void*))
110 #define _ICOM_THIS_From_IConnectionPointContainer(class, name) class* this = (class*)(((char*)name)-3*sizeof(void*))
111 #define _ICOM_THIS_From_IPersistPropertyBag(class, name) class* this = (class*)(((char*)name)-4*sizeof(void*))
112 #define _ICOM_THIS_From_IPersistStreamInit(class, name) class* this = (class*)(((char*)name)-5*sizeof(void*))
115 /***********************************************************************
116 * Prototypes for the implementation functions for the IFont
119 static OLEFontImpl* OLEFontImpl_Construct(LPFONTDESC fontDesc);
120 static void OLEFontImpl_Destroy(OLEFontImpl* fontDesc);
121 static HRESULT WINAPI OLEFontImpl_QueryInterface(IFont* iface, REFIID riid, VOID** ppvoid);
122 static ULONG WINAPI OLEFontImpl_AddRef(IFont* iface);
123 static ULONG WINAPI OLEFontImpl_Release(IFont* iface);
124 static HRESULT WINAPI OLEFontImpl_get_Name(IFont* iface, BSTR* pname);
125 static HRESULT WINAPI OLEFontImpl_put_Name(IFont* iface, BSTR name);
126 static HRESULT WINAPI OLEFontImpl_get_Size(IFont* iface, CY* psize);
127 static HRESULT WINAPI OLEFontImpl_put_Size(IFont* iface, CY size);
128 static HRESULT WINAPI OLEFontImpl_get_Bold(IFont* iface, BOOL* pbold);
129 static HRESULT WINAPI OLEFontImpl_put_Bold(IFont* iface, BOOL bold);
130 static HRESULT WINAPI OLEFontImpl_get_Italic(IFont* iface, BOOL* pitalic);
131 static HRESULT WINAPI OLEFontImpl_put_Italic(IFont* iface, BOOL italic);
132 static HRESULT WINAPI OLEFontImpl_get_Underline(IFont* iface, BOOL* punderline);
133 static HRESULT WINAPI OLEFontImpl_put_Underline(IFont* iface, BOOL underline);
134 static HRESULT WINAPI OLEFontImpl_get_Strikethrough(IFont* iface, BOOL* pstrikethrough);
135 static HRESULT WINAPI OLEFontImpl_put_Strikethrough(IFont* iface, BOOL strikethrough);
136 static HRESULT WINAPI OLEFontImpl_get_Weight(IFont* iface, short* pweight);
137 static HRESULT WINAPI OLEFontImpl_put_Weight(IFont* iface, short weight);
138 static HRESULT WINAPI OLEFontImpl_get_Charset(IFont* iface, short* pcharset);
139 static HRESULT WINAPI OLEFontImpl_put_Charset(IFont* iface, short charset);
140 static HRESULT WINAPI OLEFontImpl_get_hFont(IFont* iface, HFONT* phfont);
141 static HRESULT WINAPI OLEFontImpl_Clone(IFont* iface, IFont** ppfont);
142 static HRESULT WINAPI OLEFontImpl_IsEqual(IFont* iface, IFont* pFontOther);
143 static HRESULT WINAPI OLEFontImpl_SetRatio(IFont* iface, long cyLogical, long cyHimetric);
144 static HRESULT WINAPI OLEFontImpl_QueryTextMetrics(IFont* iface, TEXTMETRICOLE* ptm);
145 static HRESULT WINAPI OLEFontImpl_AddRefHfont(IFont* iface, HFONT hfont);
146 static HRESULT WINAPI OLEFontImpl_ReleaseHfont(IFont* iface, HFONT hfont);
147 static HRESULT WINAPI OLEFontImpl_SetHdc(IFont* iface, HDC hdc);
149 /***********************************************************************
150 * Prototypes for the implementation functions for the IDispatch
153 static HRESULT WINAPI OLEFontImpl_IDispatch_QueryInterface(IDispatch* iface,
156 static ULONG WINAPI OLEFontImpl_IDispatch_AddRef(IDispatch* iface);
157 static ULONG WINAPI OLEFontImpl_IDispatch_Release(IDispatch* iface);
158 static HRESULT WINAPI OLEFontImpl_GetTypeInfoCount(IDispatch* iface,
159 unsigned int* pctinfo);
160 static HRESULT WINAPI OLEFontImpl_GetTypeInfo(IDispatch* iface,
163 ITypeInfo** ppTInfo);
164 static HRESULT WINAPI OLEFontImpl_GetIDsOfNames(IDispatch* iface,
170 static HRESULT WINAPI OLEFontImpl_Invoke(IDispatch* iface,
175 DISPPARAMS* pDispParams,
177 EXCEPINFO* pExepInfo,
180 /***********************************************************************
181 * Prototypes for the implementation functions for the IPersistStream
184 static HRESULT WINAPI OLEFontImpl_IPersistStream_QueryInterface(IPersistStream* iface,
187 static ULONG WINAPI OLEFontImpl_IPersistStream_AddRef(IPersistStream* iface);
188 static ULONG WINAPI OLEFontImpl_IPersistStream_Release(IPersistStream* iface);
189 static HRESULT WINAPI OLEFontImpl_GetClassID(IPersistStream* iface,
191 static HRESULT WINAPI OLEFontImpl_IsDirty(IPersistStream* iface);
192 static HRESULT WINAPI OLEFontImpl_Load(IPersistStream* iface,
193 IStream* pLoadStream);
194 static HRESULT WINAPI OLEFontImpl_Save(IPersistStream* iface,
197 static HRESULT WINAPI OLEFontImpl_GetSizeMax(IPersistStream* iface,
198 ULARGE_INTEGER* pcbSize);
200 /***********************************************************************
201 * Prototypes for the implementation functions for the
202 * IConnectionPointContainer interface
204 static HRESULT WINAPI OLEFontImpl_IConnectionPointContainer_QueryInterface(
205 IConnectionPointContainer* iface,
208 static ULONG WINAPI OLEFontImpl_IConnectionPointContainer_AddRef(
209 IConnectionPointContainer* iface);
210 static ULONG WINAPI OLEFontImpl_IConnectionPointContainer_Release(
211 IConnectionPointContainer* iface);
212 static HRESULT WINAPI OLEFontImpl_EnumConnectionPoints(
213 IConnectionPointContainer* iface,
214 IEnumConnectionPoints **ppEnum);
215 static HRESULT WINAPI OLEFontImpl_FindConnectionPoint(
216 IConnectionPointContainer* iface,
218 IConnectionPoint **ppCp);
221 * Virtual function tables for the OLEFontImpl class.
223 static IFontVtbl OLEFontImpl_VTable =
225 OLEFontImpl_QueryInterface,
228 OLEFontImpl_get_Name,
229 OLEFontImpl_put_Name,
230 OLEFontImpl_get_Size,
231 OLEFontImpl_put_Size,
232 OLEFontImpl_get_Bold,
233 OLEFontImpl_put_Bold,
234 OLEFontImpl_get_Italic,
235 OLEFontImpl_put_Italic,
236 OLEFontImpl_get_Underline,
237 OLEFontImpl_put_Underline,
238 OLEFontImpl_get_Strikethrough,
239 OLEFontImpl_put_Strikethrough,
240 OLEFontImpl_get_Weight,
241 OLEFontImpl_put_Weight,
242 OLEFontImpl_get_Charset,
243 OLEFontImpl_put_Charset,
244 OLEFontImpl_get_hFont,
247 OLEFontImpl_SetRatio,
248 OLEFontImpl_QueryTextMetrics,
249 OLEFontImpl_AddRefHfont,
250 OLEFontImpl_ReleaseHfont,
254 static IDispatchVtbl OLEFontImpl_IDispatch_VTable =
256 OLEFontImpl_IDispatch_QueryInterface,
257 OLEFontImpl_IDispatch_AddRef,
258 OLEFontImpl_IDispatch_Release,
259 OLEFontImpl_GetTypeInfoCount,
260 OLEFontImpl_GetTypeInfo,
261 OLEFontImpl_GetIDsOfNames,
265 static IPersistStreamVtbl OLEFontImpl_IPersistStream_VTable =
267 OLEFontImpl_IPersistStream_QueryInterface,
268 OLEFontImpl_IPersistStream_AddRef,
269 OLEFontImpl_IPersistStream_Release,
270 OLEFontImpl_GetClassID,
274 OLEFontImpl_GetSizeMax
277 static IConnectionPointContainerVtbl
278 OLEFontImpl_IConnectionPointContainer_VTable =
280 OLEFontImpl_IConnectionPointContainer_QueryInterface,
281 OLEFontImpl_IConnectionPointContainer_AddRef,
282 OLEFontImpl_IConnectionPointContainer_Release,
283 OLEFontImpl_EnumConnectionPoints,
284 OLEFontImpl_FindConnectionPoint
287 static IPersistPropertyBagVtbl OLEFontImpl_IPersistPropertyBag_VTable;
288 static IPersistStreamInitVtbl OLEFontImpl_IPersistStreamInit_VTable;
289 /******************************************************************************
290 * OleCreateFontIndirect [OLEAUT32.420]
292 HRESULT WINAPI OleCreateFontIndirect(
293 LPFONTDESC lpFontDesc,
297 OLEFontImpl* newFont = 0;
300 TRACE("(%p, %s, %p)\n", lpFontDesc, debugstr_guid(riid), ppvObj);
312 static const WCHAR fname[] = { 'S','y','s','t','e','m',0 };
314 fd.cbSizeofstruct = sizeof(fd);
315 fd.lpstrName = (WCHAR*)fname;
316 fd.cySize.s.Lo = 80000;
322 fd.fStrikethrough = 0;
327 * Try to construct a new instance of the class.
329 newFont = OLEFontImpl_Construct(lpFontDesc);
332 return E_OUTOFMEMORY;
335 * Make sure it supports the interface required by the caller.
337 hr = IFont_QueryInterface((IFont*)newFont, riid, ppvObj);
340 * Release the reference obtained in the constructor. If
341 * the QueryInterface was unsuccessful, it will free the class.
343 IFont_Release((IFont*)newFont);
349 /***********************************************************************
350 * Implementation of the OLEFontImpl class.
353 /***********************************************************************
354 * OLEFont_SendNotify (internal)
356 * Sends notification messages of changed properties to any interested
359 static void OLEFont_SendNotify(OLEFontImpl* this, DISPID dispID)
361 IEnumConnections *pEnum;
365 hres = IConnectionPoint_EnumConnections(this->pCP, &pEnum);
366 if (FAILED(hres)) /* When we have 0 connections. */
369 while(IEnumConnections_Next(pEnum, 1, &CD, NULL) == S_OK) {
370 IPropertyNotifySink *sink;
372 IUnknown_QueryInterface(CD.pUnk, &IID_IPropertyNotifySink, (LPVOID)&sink);
373 IPropertyNotifySink_OnChanged(sink, dispID);
374 IPropertyNotifySink_Release(sink);
375 IUnknown_Release(CD.pUnk);
377 IEnumConnections_Release(pEnum);
381 /************************************************************************
382 * OLEFontImpl_Construct
384 * This method will construct a new instance of the OLEFontImpl
387 * The caller of this method must release the object when it's
390 static OLEFontImpl* OLEFontImpl_Construct(LPFONTDESC fontDesc)
392 OLEFontImpl* newObject = 0;
395 * Allocate space for the object.
397 newObject = HeapAlloc(GetProcessHeap(), 0, sizeof(OLEFontImpl));
403 * Initialize the virtual function table.
405 newObject->lpvtbl1 = &OLEFontImpl_VTable;
406 newObject->lpvtbl2 = &OLEFontImpl_IDispatch_VTable;
407 newObject->lpvtbl3 = &OLEFontImpl_IPersistStream_VTable;
408 newObject->lpvtbl4 = &OLEFontImpl_IConnectionPointContainer_VTable;
409 newObject->lpvtbl5 = &OLEFontImpl_IPersistPropertyBag_VTable;
410 newObject->lpvtbl6 = &OLEFontImpl_IPersistStreamInit_VTable;
413 * Start with one reference count. The caller of this function
414 * must release the interface pointer when it is done.
419 * Copy the description of the font in the object.
421 assert(fontDesc->cbSizeofstruct >= sizeof(FONTDESC));
423 newObject->description.cbSizeofstruct = sizeof(FONTDESC);
424 newObject->description.lpstrName = HeapAlloc(GetProcessHeap(),
426 (lstrlenW(fontDesc->lpstrName)+1) * sizeof(WCHAR));
427 strcpyW(newObject->description.lpstrName, fontDesc->lpstrName);
428 newObject->description.cySize = fontDesc->cySize;
429 newObject->description.sWeight = fontDesc->sWeight;
430 newObject->description.sCharset = fontDesc->sCharset;
431 newObject->description.fItalic = fontDesc->fItalic;
432 newObject->description.fUnderline = fontDesc->fUnderline;
433 newObject->description.fStrikethrough = fontDesc->fStrikethrough;
436 * Initializing all the other members.
438 newObject->gdiFont = 0;
439 newObject->fontLock = 0;
440 newObject->cyLogical = 72L;
441 newObject->cyHimetric = 2540L;
442 CreateConnectionPoint((IUnknown*)newObject, &IID_IPropertyNotifySink, &newObject->pCP);
443 TRACE("returning %p\n", newObject);
447 /************************************************************************
448 * OLEFontImpl_Destroy
450 * This method is called by the Release method when the reference
451 * count goes down to 0. It will free all resources used by
454 static void OLEFontImpl_Destroy(OLEFontImpl* fontDesc)
456 TRACE("(%p)\n", fontDesc);
458 if (fontDesc->description.lpstrName!=0)
459 HeapFree(GetProcessHeap(), 0, fontDesc->description.lpstrName);
461 if (fontDesc->gdiFont!=0)
462 DeleteObject(fontDesc->gdiFont);
464 HeapFree(GetProcessHeap(), 0, fontDesc);
467 /************************************************************************
468 * OLEFontImpl_QueryInterface (IUnknown)
470 * See Windows documentation for more details on IUnknown methods.
472 HRESULT WINAPI OLEFontImpl_QueryInterface(
477 _ICOM_THIS(OLEFontImpl, iface);
478 TRACE("(%p)->(%s, %p)\n", this, debugstr_guid(riid), ppvObject);
481 * Perform a sanity check on the parameters.
483 if ( (this==0) || (ppvObject==0) )
487 * Initialize the return parameter.
492 * Compare the riid with the interface IDs implemented by this object.
494 if (IsEqualGUID(&IID_IUnknown, riid))
495 *ppvObject = (IFont*)this;
496 if (IsEqualGUID(&IID_IFont, riid))
497 *ppvObject = (IFont*)this;
498 if (IsEqualGUID(&IID_IDispatch, riid))
499 *ppvObject = (IDispatch*)&(this->lpvtbl2);
500 if (IsEqualGUID(&IID_IFontDisp, riid))
501 *ppvObject = (IDispatch*)&(this->lpvtbl2);
502 if (IsEqualGUID(&IID_IPersistStream, riid))
503 *ppvObject = (IPersistStream*)&(this->lpvtbl3);
504 if (IsEqualGUID(&IID_IConnectionPointContainer, riid))
505 *ppvObject = (IConnectionPointContainer*)&(this->lpvtbl4);
506 if (IsEqualGUID(&IID_IPersistPropertyBag, riid))
507 *ppvObject = (IPersistPropertyBag*)&(this->lpvtbl5);
508 if (IsEqualGUID(&IID_IPersistStreamInit, riid))
509 *ppvObject = (IPersistStreamInit*)&(this->lpvtbl6);
512 * Check that we obtained an interface.
516 FIXME("() : asking for unsupported interface %s\n",debugstr_guid(riid));
517 return E_NOINTERFACE;
519 OLEFontImpl_AddRef((IFont*)this);
523 /************************************************************************
524 * OLEFontImpl_AddRef (IUnknown)
526 * See Windows documentation for more details on IUnknown methods.
528 ULONG WINAPI OLEFontImpl_AddRef(
531 _ICOM_THIS(OLEFontImpl, iface);
532 TRACE("(%p)->(ref=%ld)\n", this, this->ref);
538 /************************************************************************
539 * OLEFontImpl_Release (IUnknown)
541 * See Windows documentation for more details on IUnknown methods.
543 ULONG WINAPI OLEFontImpl_Release(
546 _ICOM_THIS(OLEFontImpl, iface);
547 TRACE("(%p)->(ref=%ld)\n", this, this->ref);
550 * Decrease the reference count on this object.
555 * If the reference count goes down to 0, perform suicide.
559 OLEFontImpl_Destroy(this);
567 /************************************************************************
568 * OLEFontImpl_get_Name (IFont)
570 * See Windows documentation for more details on IFont methods.
572 static HRESULT WINAPI OLEFontImpl_get_Name(
576 _ICOM_THIS(OLEFontImpl, iface);
577 TRACE("(%p)->(%p)\n", this, pname);
584 if (this->description.lpstrName!=0)
585 *pname = SysAllocString(this->description.lpstrName);
592 /************************************************************************
593 * OLEFontImpl_put_Name (IFont)
595 * See Windows documentation for more details on IFont methods.
597 static HRESULT WINAPI OLEFontImpl_put_Name(
601 _ICOM_THIS(OLEFontImpl, iface);
602 TRACE("(%p)->(%p)\n", this, name);
604 if (this->description.lpstrName==0)
606 this->description.lpstrName = HeapAlloc(GetProcessHeap(),
608 (lstrlenW(name)+1) * sizeof(WCHAR));
612 this->description.lpstrName = HeapReAlloc(GetProcessHeap(),
614 this->description.lpstrName,
615 (lstrlenW(name)+1) * sizeof(WCHAR));
618 if (this->description.lpstrName==0)
619 return E_OUTOFMEMORY;
621 strcpyW(this->description.lpstrName, name);
622 TRACE("new name %s\n", debugstr_w(this->description.lpstrName));
623 OLEFont_SendNotify(this, DISPID_FONT_NAME);
627 /************************************************************************
628 * OLEFontImpl_get_Size (IFont)
630 * See Windows documentation for more details on IFont methods.
632 static HRESULT WINAPI OLEFontImpl_get_Size(
636 _ICOM_THIS(OLEFontImpl, iface);
637 TRACE("(%p)->(%p)\n", this, psize);
646 psize->s.Lo = this->description.cySize.s.Lo;
651 /************************************************************************
652 * OLEFontImpl_put_Size (IFont)
654 * See Windows documentation for more details on IFont methods.
656 static HRESULT WINAPI OLEFontImpl_put_Size(
660 _ICOM_THIS(OLEFontImpl, iface);
661 TRACE("(%p)->(%ld)\n", this, size.s.Lo);
662 this->description.cySize.s.Hi = 0;
663 this->description.cySize.s.Lo = size.s.Lo;
664 OLEFont_SendNotify(this, DISPID_FONT_SIZE);
669 /************************************************************************
670 * OLEFontImpl_get_Bold (IFont)
672 * See Windows documentation for more details on IFont methods.
674 static HRESULT WINAPI OLEFontImpl_get_Bold(
678 _ICOM_THIS(OLEFontImpl, iface);
679 TRACE("(%p)->(%p)\n", this, pbold);
686 *pbold = this->description.sWeight > 550;
691 /************************************************************************
692 * OLEFontImpl_put_Bold (IFont)
694 * See Windows documentation for more details on IFont methods.
696 static HRESULT WINAPI OLEFontImpl_put_Bold(
700 _ICOM_THIS(OLEFontImpl, iface);
701 TRACE("(%p)->(%d)\n", this, bold);
702 this->description.sWeight = bold ? FW_BOLD : FW_NORMAL;
703 OLEFont_SendNotify(this, DISPID_FONT_BOLD);
708 /************************************************************************
709 * OLEFontImpl_get_Italic (IFont)
711 * See Windows documentation for more details on IFont methods.
713 static HRESULT WINAPI OLEFontImpl_get_Italic(
717 _ICOM_THIS(OLEFontImpl, iface);
718 TRACE("(%p)->(%p)\n", this, pitalic);
725 *pitalic = this->description.fItalic;
730 /************************************************************************
731 * OLEFontImpl_put_Italic (IFont)
733 * See Windows documentation for more details on IFont methods.
735 static HRESULT WINAPI OLEFontImpl_put_Italic(
739 _ICOM_THIS(OLEFontImpl, iface);
740 TRACE("(%p)->(%d)\n", this, italic);
742 this->description.fItalic = italic;
744 OLEFont_SendNotify(this, DISPID_FONT_ITALIC);
748 /************************************************************************
749 * OLEFontImpl_get_Underline (IFont)
751 * See Windows documentation for more details on IFont methods.
753 static HRESULT WINAPI OLEFontImpl_get_Underline(
757 _ICOM_THIS(OLEFontImpl, iface);
758 TRACE("(%p)->(%p)\n", this, punderline);
766 *punderline = this->description.fUnderline;
771 /************************************************************************
772 * OLEFontImpl_put_Underline (IFont)
774 * See Windows documentation for more details on IFont methods.
776 static HRESULT WINAPI OLEFontImpl_put_Underline(
780 _ICOM_THIS(OLEFontImpl, iface);
781 TRACE("(%p)->(%d)\n", this, underline);
783 this->description.fUnderline = underline;
785 OLEFont_SendNotify(this, DISPID_FONT_UNDER);
789 /************************************************************************
790 * OLEFontImpl_get_Strikethrough (IFont)
792 * See Windows documentation for more details on IFont methods.
794 static HRESULT WINAPI OLEFontImpl_get_Strikethrough(
796 BOOL* pstrikethrough)
798 _ICOM_THIS(OLEFontImpl, iface);
799 TRACE("(%p)->(%p)\n", this, pstrikethrough);
804 if (pstrikethrough==0)
807 *pstrikethrough = this->description.fStrikethrough;
812 /************************************************************************
813 * OLEFontImpl_put_Strikethrough (IFont)
815 * See Windows documentation for more details on IFont methods.
817 static HRESULT WINAPI OLEFontImpl_put_Strikethrough(
821 _ICOM_THIS(OLEFontImpl, iface);
822 TRACE("(%p)->(%d)\n", this, strikethrough);
824 this->description.fStrikethrough = strikethrough;
825 OLEFont_SendNotify(this, DISPID_FONT_STRIKE);
830 /************************************************************************
831 * OLEFontImpl_get_Weight (IFont)
833 * See Windows documentation for more details on IFont methods.
835 static HRESULT WINAPI OLEFontImpl_get_Weight(
839 _ICOM_THIS(OLEFontImpl, iface);
840 TRACE("(%p)->(%p)\n", this, pweight);
848 *pweight = this->description.sWeight;
853 /************************************************************************
854 * OLEFontImpl_put_Weight (IFont)
856 * See Windows documentation for more details on IFont methods.
858 static HRESULT WINAPI OLEFontImpl_put_Weight(
862 _ICOM_THIS(OLEFontImpl, iface);
863 TRACE("(%p)->(%d)\n", this, weight);
865 this->description.sWeight = weight;
867 OLEFont_SendNotify(this, DISPID_FONT_WEIGHT);
871 /************************************************************************
872 * OLEFontImpl_get_Charset (IFont)
874 * See Windows documentation for more details on IFont methods.
876 static HRESULT WINAPI OLEFontImpl_get_Charset(
880 _ICOM_THIS(OLEFontImpl, iface);
881 TRACE("(%p)->(%p)\n", this, pcharset);
889 *pcharset = this->description.sCharset;
894 /************************************************************************
895 * OLEFontImpl_put_Charset (IFont)
897 * See Windows documentation for more details on IFont methods.
899 static HRESULT WINAPI OLEFontImpl_put_Charset(
903 _ICOM_THIS(OLEFontImpl, iface);
904 TRACE("(%p)->(%d)\n", this, charset);
906 this->description.sCharset = charset;
907 OLEFont_SendNotify(this, DISPID_FONT_CHARSET);
912 /************************************************************************
913 * OLEFontImpl_get_hFont (IFont)
915 * See Windows documentation for more details on IFont methods.
917 static HRESULT WINAPI OLEFontImpl_get_hFont(
921 _ICOM_THIS(OLEFontImpl, iface);
922 TRACE("(%p)->(%p)\n", this, phfont);
927 * Realize the font if necessary
929 if (this->gdiFont==0)
936 * The height of the font returned by the get_Size property is the
937 * height of the font in points multiplied by 10000... Using some
938 * simple conversions and the ratio given by the application, it can
939 * be converted to a height in pixels.
941 IFont_get_Size(iface, &cySize);
943 fontHeight = MulDiv( cySize.s.Lo, this->cyLogical, this->cyHimetric );
945 memset(&logFont, 0, sizeof(LOGFONTW));
947 logFont.lfHeight = ((fontHeight%10000L)>5000L) ? (-fontHeight/10000L)-1 :
948 (-fontHeight/10000L);
949 logFont.lfItalic = this->description.fItalic;
950 logFont.lfUnderline = this->description.fUnderline;
951 logFont.lfStrikeOut = this->description.fStrikethrough;
952 logFont.lfWeight = this->description.sWeight;
953 logFont.lfCharSet = this->description.sCharset;
954 logFont.lfOutPrecision = OUT_CHARACTER_PRECIS;
955 logFont.lfClipPrecision = CLIP_DEFAULT_PRECIS;
956 logFont.lfQuality = DEFAULT_QUALITY;
957 logFont.lfPitchAndFamily = DEFAULT_PITCH;
958 strcpyW(logFont.lfFaceName,this->description.lpstrName);
960 this->gdiFont = CreateFontIndirectW(&logFont);
963 *phfont = this->gdiFont;
964 TRACE("Returning %p\n", *phfont);
968 /************************************************************************
969 * OLEFontImpl_Clone (IFont)
971 * See Windows documentation for more details on IFont methods.
973 static HRESULT WINAPI OLEFontImpl_Clone(
977 OLEFontImpl* newObject = 0;
981 _ICOM_THIS(OLEFontImpl, iface);
982 TRACE("(%p)->(%p)\n", this, ppfont);
990 * Allocate space for the object.
992 newObject = HeapAlloc(GetProcessHeap(), 0, sizeof(OLEFontImpl));
995 return E_OUTOFMEMORY;
999 /* We need to alloc new memory for the string, otherwise
1000 * we free memory twice.
1002 newObject->description.lpstrName = HeapAlloc(
1004 (1+strlenW(this->description.lpstrName))*2
1006 strcpyW(newObject->description.lpstrName, this->description.lpstrName);
1007 /* We need to clone the HFONT too. This is just cut & paste from above */
1008 IFont_get_Size(iface, &cySize);
1010 fontHeight = MulDiv(cySize.s.Lo, this->cyLogical,this->cyHimetric);
1012 memset(&logFont, 0, sizeof(LOGFONTW));
1014 logFont.lfHeight = ((fontHeight%10000L)>5000L) ? (-fontHeight/10000L)-1 :
1015 (-fontHeight/10000L);
1016 logFont.lfItalic = this->description.fItalic;
1017 logFont.lfUnderline = this->description.fUnderline;
1018 logFont.lfStrikeOut = this->description.fStrikethrough;
1019 logFont.lfWeight = this->description.sWeight;
1020 logFont.lfCharSet = this->description.sCharset;
1021 logFont.lfOutPrecision = OUT_CHARACTER_PRECIS;
1022 logFont.lfClipPrecision = CLIP_DEFAULT_PRECIS;
1023 logFont.lfQuality = DEFAULT_QUALITY;
1024 logFont.lfPitchAndFamily = DEFAULT_PITCH;
1025 strcpyW(logFont.lfFaceName,this->description.lpstrName);
1027 newObject->gdiFont = CreateFontIndirectW(&logFont);
1030 /* The cloned object starts with a reference count of 1 */
1033 *ppfont = (IFont*)newObject;
1038 /************************************************************************
1039 * OLEFontImpl_IsEqual (IFont)
1041 * See Windows documentation for more details on IFont methods.
1043 static HRESULT WINAPI OLEFontImpl_IsEqual(
1047 FIXME("(%p, %p), stub!\n",iface,pFontOther);
1051 /************************************************************************
1052 * OLEFontImpl_SetRatio (IFont)
1054 * See Windows documentation for more details on IFont methods.
1056 static HRESULT WINAPI OLEFontImpl_SetRatio(
1061 _ICOM_THIS(OLEFontImpl, iface);
1062 TRACE("(%p)->(%ld, %ld)\n", this, cyLogical, cyHimetric);
1064 this->cyLogical = cyLogical;
1065 this->cyHimetric = cyHimetric;
1070 /************************************************************************
1071 * OLEFontImpl_QueryTextMetrics (IFont)
1073 * See Windows documentation for more details on IFont methods.
1075 static HRESULT WINAPI OLEFontImpl_QueryTextMetrics(
1079 FIXME("(%p, %p), stub!\n",iface,ptm);
1083 /************************************************************************
1084 * OLEFontImpl_AddRefHfont (IFont)
1086 * See Windows documentation for more details on IFont methods.
1088 static HRESULT WINAPI OLEFontImpl_AddRefHfont(
1092 _ICOM_THIS(OLEFontImpl, iface);
1093 TRACE("(%p)->(%p) (lock=%ld)\n", this, hfont, this->fontLock);
1095 if ( (hfont == 0) ||
1096 (hfont != this->gdiFont) )
1097 return E_INVALIDARG;
1104 /************************************************************************
1105 * OLEFontImpl_ReleaseHfont (IFont)
1107 * See Windows documentation for more details on IFont methods.
1109 static HRESULT WINAPI OLEFontImpl_ReleaseHfont(
1113 _ICOM_THIS(OLEFontImpl, iface);
1114 TRACE("(%p)->(%p) (lock=%ld)\n", this, hfont, this->fontLock);
1116 if ( (hfont == 0) ||
1117 (hfont != this->gdiFont) )
1118 return E_INVALIDARG;
1123 * If we just released our last font reference, destroy it.
1125 if (this->fontLock==0)
1127 DeleteObject(this->gdiFont);
1134 /************************************************************************
1135 * OLEFontImpl_SetHdc (IFont)
1137 * See Windows documentation for more details on IFont methods.
1139 static HRESULT WINAPI OLEFontImpl_SetHdc(
1143 _ICOM_THIS(OLEFontImpl, iface);
1144 FIXME("(%p)->(%p): Stub\n", this, hdc);
1148 /************************************************************************
1149 * OLEFontImpl_IDispatch_QueryInterface (IUnknown)
1151 * See Windows documentation for more details on IUnknown methods.
1153 static HRESULT WINAPI OLEFontImpl_IDispatch_QueryInterface(
1158 _ICOM_THIS_From_IDispatch(IFont, iface);
1160 return IFont_QueryInterface(this, riid, ppvoid);
1163 /************************************************************************
1164 * OLEFontImpl_IDispatch_Release (IUnknown)
1166 * See Windows documentation for more details on IUnknown methods.
1168 static ULONG WINAPI OLEFontImpl_IDispatch_Release(
1171 _ICOM_THIS_From_IDispatch(IFont, iface);
1173 return IFont_Release(this);
1176 /************************************************************************
1177 * OLEFontImpl_IDispatch_AddRef (IUnknown)
1179 * See Windows documentation for more details on IUnknown methods.
1181 static ULONG WINAPI OLEFontImpl_IDispatch_AddRef(
1184 _ICOM_THIS_From_IDispatch(IFont, iface);
1186 return IFont_AddRef(this);
1189 /************************************************************************
1190 * OLEFontImpl_GetTypeInfoCount (IDispatch)
1192 * See Windows documentation for more details on IDispatch methods.
1194 static HRESULT WINAPI OLEFontImpl_GetTypeInfoCount(
1196 unsigned int* pctinfo)
1198 _ICOM_THIS_From_IDispatch(IFont, iface);
1199 FIXME("(%p)->(%p): Stub\n", this, pctinfo);
1204 /************************************************************************
1205 * OLEFontImpl_GetTypeInfo (IDispatch)
1207 * See Windows documentation for more details on IDispatch methods.
1209 static HRESULT WINAPI OLEFontImpl_GetTypeInfo(
1213 ITypeInfo** ppTInfo)
1215 static const WCHAR stdole32tlb[] = {'s','t','d','o','l','e','3','2','.','t','l','b',0};
1219 _ICOM_THIS_From_IDispatch(OLEFontImpl, iface);
1220 TRACE("(%p, iTInfo=%d, lcid=%04x, %p), unimplemented stub!\n", this, iTInfo, (int)lcid, ppTInfo);
1223 hres = LoadTypeLib(stdole32tlb, &tl);
1225 FIXME("Could not load the stdole32.tlb?\n");
1228 hres = ITypeLib_GetTypeInfoOfGuid(tl, &IID_IDispatch, ppTInfo);
1230 FIXME("Did not IDispatch typeinfo from typelib, hres %lx\n",hres);
1235 /************************************************************************
1236 * OLEFontImpl_GetIDsOfNames (IDispatch)
1238 * See Windows documentation for more details on IDispatch methods.
1240 static HRESULT WINAPI OLEFontImpl_GetIDsOfNames(
1243 LPOLESTR* rgszNames,
1248 _ICOM_THIS_From_IDispatch(IFont, iface);
1249 FIXME("(%p,%s,%p,%d,%04x,%p), stub!\n", this, debugstr_guid(riid), rgszNames,
1250 cNames, (int)lcid, rgDispId
1255 /************************************************************************
1256 * OLEFontImpl_Invoke (IDispatch)
1258 * See Windows documentation for more details on IDispatch methods.
1260 * Note: Do not call _put_Xxx methods, since setting things here
1261 * should not call notify functions as I found out debugging the generic
1264 static HRESULT WINAPI OLEFontImpl_Invoke(
1266 DISPID dispIdMember,
1270 DISPPARAMS* pDispParams,
1271 VARIANT* pVarResult,
1272 EXCEPINFO* pExepInfo,
1275 _ICOM_THIS_From_IDispatch(IFont, iface);
1276 OLEFontImpl *xthis = (OLEFontImpl*)this;
1278 switch (dispIdMember) {
1279 case DISPID_FONT_NAME:
1281 case DISPATCH_PROPERTYGET:
1282 case DISPATCH_PROPERTYGET|DISPATCH_METHOD:
1283 V_VT(pVarResult) = VT_BSTR;
1284 return OLEFontImpl_get_Name(this, &V_BSTR(pVarResult));
1285 case DISPATCH_PROPERTYPUT: {
1286 BSTR name = V_BSTR(&pDispParams->rgvarg[0]);
1287 if (V_VT(&pDispParams->rgvarg[0])!=VT_BSTR) {
1288 FIXME("property put of Name, vt is not VT_BSTR but %d\n",V_VT(&pDispParams->rgvarg[0]));
1291 if (!xthis->description.lpstrName)
1292 xthis->description.lpstrName = HeapAlloc(GetProcessHeap(), 0, (lstrlenW(name)+1) * sizeof(WCHAR));
1294 xthis->description.lpstrName = HeapReAlloc(GetProcessHeap(), 0, xthis->description.lpstrName, (lstrlenW(name)+1) * sizeof(WCHAR));
1296 if (xthis->description.lpstrName==0)
1297 return E_OUTOFMEMORY;
1298 strcpyW(xthis->description.lpstrName, name);
1303 case DISPID_FONT_BOLD:
1305 case DISPATCH_PROPERTYGET:
1306 case DISPATCH_PROPERTYGET|DISPATCH_METHOD:
1307 V_VT(pVarResult) = VT_BOOL;
1308 return OLEFontImpl_get_Bold(this, (BOOL*)&V_BOOL(pVarResult));
1309 case DISPATCH_PROPERTYPUT:
1310 if (V_VT(&pDispParams->rgvarg[0]) != VT_BOOL) {
1311 FIXME("DISPID_FONT_BOLD/put, vt is %d, not VT_BOOL.\n",V_VT(&pDispParams->rgvarg[0]));
1314 xthis->description.sWeight = V_BOOL(&pDispParams->rgvarg[0]) ? FW_BOLD : FW_NORMAL;
1319 case DISPID_FONT_ITALIC:
1321 case DISPATCH_PROPERTYGET:
1322 case DISPATCH_PROPERTYGET|DISPATCH_METHOD:
1323 V_VT(pVarResult) = VT_BOOL;
1324 return OLEFontImpl_get_Italic(this, (BOOL*)&V_BOOL(pVarResult));
1325 case DISPATCH_PROPERTYPUT:
1326 if (V_VT(&pDispParams->rgvarg[0]) != VT_BOOL) {
1327 FIXME("DISPID_FONT_ITALIC/put, vt is %d, not VT_BOOL.\n",V_VT(&pDispParams->rgvarg[0]));
1330 xthis->description.fItalic = V_BOOL(&pDispParams->rgvarg[0]);
1335 case DISPID_FONT_UNDER:
1337 case DISPATCH_PROPERTYGET:
1338 case DISPATCH_PROPERTYGET|DISPATCH_METHOD:
1339 V_VT(pVarResult) = VT_BOOL;
1340 return OLEFontImpl_get_Underline(this, (BOOL*)&V_BOOL(pVarResult));
1341 case DISPATCH_PROPERTYPUT:
1342 if (V_VT(&pDispParams->rgvarg[0]) != VT_BOOL) {
1343 FIXME("DISPID_FONT_UNDER/put, vt is %d, not VT_BOOL.\n",V_VT(&pDispParams->rgvarg[0]));
1346 xthis->description.fUnderline = V_BOOL(&pDispParams->rgvarg[0]);
1351 case DISPID_FONT_STRIKE:
1353 case DISPATCH_PROPERTYGET:
1354 case DISPATCH_PROPERTYGET|DISPATCH_METHOD:
1355 V_VT(pVarResult) = VT_BOOL;
1356 return OLEFontImpl_get_Strikethrough(this, (BOOL*)&V_BOOL(pVarResult));
1357 case DISPATCH_PROPERTYPUT:
1358 if (V_VT(&pDispParams->rgvarg[0]) != VT_BOOL) {
1359 FIXME("DISPID_FONT_STRIKE/put, vt is %d, not VT_BOOL.\n",V_VT(&pDispParams->rgvarg[0]));
1362 xthis->description.fStrikethrough = V_BOOL(&pDispParams->rgvarg[0]);
1367 case DISPID_FONT_SIZE:
1369 case DISPATCH_PROPERTYPUT: {
1370 assert (pDispParams->cArgs == 1);
1371 xthis->description.cySize.s.Hi = 0;
1372 if (V_VT(&pDispParams->rgvarg[0]) != VT_CY) {
1373 if (V_VT(&pDispParams->rgvarg[0]) == VT_I2) {
1374 xthis->description.cySize.s.Lo = V_I2(&pDispParams->rgvarg[0]) * 10000;
1376 FIXME("property put for Size with vt %d unsupported!\n",V_VT(&pDispParams->rgvarg[0]));
1379 xthis->description.cySize.s.Lo = V_CY(&pDispParams->rgvarg[0]).s.Lo;
1383 case DISPATCH_PROPERTYGET:
1384 case DISPATCH_PROPERTYGET|DISPATCH_METHOD:
1385 V_VT(pVarResult) = VT_CY;
1386 return OLEFontImpl_get_Size(this, &V_CY(pVarResult));
1389 case DISPID_FONT_CHARSET:
1391 case DISPATCH_PROPERTYPUT:
1392 assert (pDispParams->cArgs == 1);
1393 if (V_VT(&pDispParams->rgvarg[0]) != VT_I2)
1394 FIXME("varg of first disparg is not VT_I2, but %d\n",V_VT(&pDispParams->rgvarg[0]));
1395 xthis->description.sCharset = V_I2(&pDispParams->rgvarg[0]);
1397 case DISPATCH_PROPERTYGET:
1398 case DISPATCH_PROPERTYGET|DISPATCH_METHOD:
1399 V_VT(pVarResult) = VT_I2;
1400 return OLEFontImpl_get_Charset(this, &V_I2(pVarResult));
1404 FIXME("%p->(%ld,%s,%lx,%x,%p,%p,%p,%p), unhandled dispid/flag!\n",
1405 this,dispIdMember,debugstr_guid(riid),lcid,
1406 wFlags,pDispParams,pVarResult,pExepInfo,puArgErr
1411 /************************************************************************
1412 * OLEFontImpl_IPersistStream_QueryInterface (IUnknown)
1414 * See Windows documentation for more details on IUnknown methods.
1416 static HRESULT WINAPI OLEFontImpl_IPersistStream_QueryInterface(
1417 IPersistStream* iface,
1421 _ICOM_THIS_From_IPersistStream(IFont, iface);
1423 return IFont_QueryInterface(this, riid, ppvoid);
1426 /************************************************************************
1427 * OLEFontImpl_IPersistStream_Release (IUnknown)
1429 * See Windows documentation for more details on IUnknown methods.
1431 static ULONG WINAPI OLEFontImpl_IPersistStream_Release(
1432 IPersistStream* iface)
1434 _ICOM_THIS_From_IPersistStream(IFont, iface);
1436 return IFont_Release(this);
1439 /************************************************************************
1440 * OLEFontImpl_IPersistStream_AddRef (IUnknown)
1442 * See Windows documentation for more details on IUnknown methods.
1444 static ULONG WINAPI OLEFontImpl_IPersistStream_AddRef(
1445 IPersistStream* iface)
1447 _ICOM_THIS_From_IPersistStream(IFont, iface);
1449 return IFont_AddRef(this);
1452 /************************************************************************
1453 * OLEFontImpl_GetClassID (IPersistStream)
1455 * See Windows documentation for more details on IPersistStream methods.
1457 static HRESULT WINAPI OLEFontImpl_GetClassID(
1458 IPersistStream* iface,
1461 TRACE("(%p,%p)\n",iface,pClassID);
1465 memcpy(pClassID, &CLSID_StdFont, sizeof(CLSID_StdFont));
1470 /************************************************************************
1471 * OLEFontImpl_IsDirty (IPersistStream)
1473 * See Windows documentation for more details on IPersistStream methods.
1475 static HRESULT WINAPI OLEFontImpl_IsDirty(
1476 IPersistStream* iface)
1478 TRACE("(%p)\n",iface);
1482 /************************************************************************
1483 * OLEFontImpl_Load (IPersistStream)
1485 * See Windows documentation for more details on IPersistStream methods.
1487 * This is the format of the standard font serialization as far as I
1490 * Offset Type Value Comment
1491 * 0x0000 Byte Unknown Probably a version number, contains 0x01
1492 * 0x0001 Short Charset Charset value from the FONTDESC structure
1493 * 0x0003 Byte Attributes Flags defined as follows:
1495 * 00000100 - Underline
1496 * 00001000 - Strikethrough
1497 * 0x0004 Short Weight Weight value from FONTDESC structure
1498 * 0x0006 DWORD size "Low" portion of the cySize member of the FONTDESC
1500 * 0x000A Byte name length Length of the font name string (no null character)
1501 * 0x000B String name Name of the font (ASCII, no nul character)
1503 static HRESULT WINAPI OLEFontImpl_Load(
1504 IPersistStream* iface,
1505 IStream* pLoadStream)
1507 char readBuffer[0x100];
1514 _ICOM_THIS_From_IPersistStream(OLEFontImpl, iface);
1517 * Read the version byte
1519 IStream_Read(pLoadStream, &bVersion, 1, &cbRead);
1528 IStream_Read(pLoadStream, &this->description.sCharset, 2, &cbRead);
1536 IStream_Read(pLoadStream, &bAttributes, 1, &cbRead);
1541 this->description.fItalic = (bAttributes & FONTPERSIST_ITALIC) != 0;
1542 this->description.fStrikethrough = (bAttributes & FONTPERSIST_STRIKETHROUGH) != 0;
1543 this->description.fUnderline = (bAttributes & FONTPERSIST_UNDERLINE) != 0;
1548 IStream_Read(pLoadStream, &this->description.sWeight, 2, &cbRead);
1556 IStream_Read(pLoadStream, &this->description.cySize.s.Lo, 4, &cbRead);
1561 this->description.cySize.s.Hi = 0;
1566 IStream_Read(pLoadStream, &bStringSize, 1, &cbRead);
1571 IStream_Read(pLoadStream, readBuffer, bStringSize, &cbRead);
1573 if (cbRead!=bStringSize)
1576 if (this->description.lpstrName!=0)
1577 HeapFree(GetProcessHeap(), 0, this->description.lpstrName);
1579 len = MultiByteToWideChar( CP_ACP, 0, readBuffer, bStringSize, NULL, 0 );
1580 this->description.lpstrName = HeapAlloc( GetProcessHeap(), 0, (len+1) * sizeof(WCHAR) );
1581 MultiByteToWideChar( CP_ACP, 0, readBuffer, bStringSize, this->description.lpstrName, len );
1582 this->description.lpstrName[len] = 0;
1584 /* Ensure use of this font causes a new one to be created @@@@ */
1585 DeleteObject(this->gdiFont);
1591 /************************************************************************
1592 * OLEFontImpl_Save (IPersistStream)
1594 * See Windows documentation for more details on IPersistStream methods.
1596 static HRESULT WINAPI OLEFontImpl_Save(
1597 IPersistStream* iface,
1598 IStream* pOutStream,
1601 char* writeBuffer = NULL;
1603 BYTE bVersion = 0x01;
1607 _ICOM_THIS_From_IPersistStream(OLEFontImpl, iface);
1610 * Read the version byte
1612 IStream_Write(pOutStream, &bVersion, 1, &cbWritten);
1620 IStream_Write(pOutStream, &this->description.sCharset, 2, &cbWritten);
1630 if (this->description.fItalic)
1631 bAttributes |= FONTPERSIST_ITALIC;
1633 if (this->description.fStrikethrough)
1634 bAttributes |= FONTPERSIST_STRIKETHROUGH;
1636 if (this->description.fUnderline)
1637 bAttributes |= FONTPERSIST_UNDERLINE;
1639 IStream_Write(pOutStream, &bAttributes, 1, &cbWritten);
1647 IStream_Write(pOutStream, &this->description.sWeight, 2, &cbWritten);
1655 IStream_Write(pOutStream, &this->description.cySize.s.Lo, 4, &cbWritten);
1663 if (this->description.lpstrName!=0)
1664 bStringSize = WideCharToMultiByte( CP_ACP, 0, this->description.lpstrName,
1665 strlenW(this->description.lpstrName), NULL, 0, NULL, NULL );
1669 IStream_Write(pOutStream, &bStringSize, 1, &cbWritten);
1676 if (!(writeBuffer = HeapAlloc( GetProcessHeap(), 0, bStringSize ))) return E_OUTOFMEMORY;
1677 WideCharToMultiByte( CP_ACP, 0, this->description.lpstrName,
1678 strlenW(this->description.lpstrName),
1679 writeBuffer, bStringSize, NULL, NULL );
1681 IStream_Write(pOutStream, writeBuffer, bStringSize, &cbWritten);
1682 HeapFree(GetProcessHeap(), 0, writeBuffer);
1684 if (cbWritten!=bStringSize)
1691 /************************************************************************
1692 * OLEFontImpl_GetSizeMax (IPersistStream)
1694 * See Windows documentation for more details on IPersistStream methods.
1696 static HRESULT WINAPI OLEFontImpl_GetSizeMax(
1697 IPersistStream* iface,
1698 ULARGE_INTEGER* pcbSize)
1700 _ICOM_THIS_From_IPersistStream(OLEFontImpl, iface);
1705 pcbSize->u.HighPart = 0;
1706 pcbSize->u.LowPart = 0;
1708 pcbSize->u.LowPart += sizeof(BYTE); /* Version */
1709 pcbSize->u.LowPart += sizeof(WORD); /* Lang code */
1710 pcbSize->u.LowPart += sizeof(BYTE); /* Flags */
1711 pcbSize->u.LowPart += sizeof(WORD); /* Weight */
1712 pcbSize->u.LowPart += sizeof(DWORD); /* Size */
1713 pcbSize->u.LowPart += sizeof(BYTE); /* StrLength */
1715 if (this->description.lpstrName!=0)
1716 pcbSize->u.LowPart += lstrlenW(this->description.lpstrName);
1721 /************************************************************************
1722 * OLEFontImpl_IConnectionPointContainer_QueryInterface (IUnknown)
1724 * See Windows documentation for more details on IUnknown methods.
1726 static HRESULT WINAPI OLEFontImpl_IConnectionPointContainer_QueryInterface(
1727 IConnectionPointContainer* iface,
1731 _ICOM_THIS_From_IConnectionPointContainer(OLEFontImpl, iface);
1733 return IFont_QueryInterface((IFont*)this, riid, ppvoid);
1736 /************************************************************************
1737 * OLEFontImpl_IConnectionPointContainer_Release (IUnknown)
1739 * See Windows documentation for more details on IUnknown methods.
1741 static ULONG WINAPI OLEFontImpl_IConnectionPointContainer_Release(
1742 IConnectionPointContainer* iface)
1744 _ICOM_THIS_From_IConnectionPointContainer(OLEFontImpl, iface);
1746 return IFont_Release((IFont*)this);
1749 /************************************************************************
1750 * OLEFontImpl_IConnectionPointContainer_AddRef (IUnknown)
1752 * See Windows documentation for more details on IUnknown methods.
1754 static ULONG WINAPI OLEFontImpl_IConnectionPointContainer_AddRef(
1755 IConnectionPointContainer* iface)
1757 _ICOM_THIS_From_IConnectionPointContainer(OLEFontImpl, iface);
1759 return IFont_AddRef((IFont*)this);
1762 /************************************************************************
1763 * OLEFontImpl_EnumConnectionPoints (IConnectionPointContainer)
1765 * See Windows documentation for more details on IConnectionPointContainer
1768 static HRESULT WINAPI OLEFontImpl_EnumConnectionPoints(
1769 IConnectionPointContainer* iface,
1770 IEnumConnectionPoints **ppEnum)
1772 _ICOM_THIS_From_IConnectionPointContainer(OLEFontImpl, iface);
1774 FIXME("(%p)->(%p): stub\n", this, ppEnum);
1778 /************************************************************************
1779 * OLEFontImpl_FindConnectionPoint (IConnectionPointContainer)
1781 * See Windows documentation for more details on IConnectionPointContainer
1784 static HRESULT WINAPI OLEFontImpl_FindConnectionPoint(
1785 IConnectionPointContainer* iface,
1787 IConnectionPoint **ppCp)
1789 _ICOM_THIS_From_IConnectionPointContainer(OLEFontImpl, iface);
1790 TRACE("(%p)->(%s, %p): stub\n", this, debugstr_guid(riid), ppCp);
1792 if(memcmp(riid, &IID_IPropertyNotifySink, sizeof(IID_IPropertyNotifySink)) == 0) {
1793 return IConnectionPoint_QueryInterface(this->pCP, &IID_IConnectionPoint,
1796 FIXME("Tried to find connection point on %s\n", debugstr_guid(riid));
1797 return E_NOINTERFACE;
1801 /************************************************************************
1802 * OLEFontImpl implementation of IPersistPropertyBag.
1804 static HRESULT WINAPI OLEFontImpl_IPersistPropertyBag_QueryInterface(
1805 IPersistPropertyBag *iface, REFIID riid, LPVOID *ppvObj
1807 _ICOM_THIS_From_IPersistPropertyBag(IFont, iface);
1808 return IFont_QueryInterface(this,riid,ppvObj);
1811 static ULONG WINAPI OLEFontImpl_IPersistPropertyBag_AddRef(
1812 IPersistPropertyBag *iface
1814 _ICOM_THIS_From_IPersistPropertyBag(IFont, iface);
1815 return IFont_AddRef(this);
1818 static ULONG WINAPI OLEFontImpl_IPersistPropertyBag_Release(
1819 IPersistPropertyBag *iface
1821 _ICOM_THIS_From_IPersistPropertyBag(IFont, iface);
1822 return IFont_Release(this);
1825 static HRESULT WINAPI OLEFontImpl_IPersistPropertyBag_GetClassID(
1826 IPersistPropertyBag *iface, CLSID *classid
1828 FIXME("(%p,%p), stub!\n", iface, classid);
1832 static HRESULT WINAPI OLEFontImpl_IPersistPropertyBag_InitNew(
1833 IPersistPropertyBag *iface
1835 FIXME("(%p), stub!\n", iface);
1839 static HRESULT WINAPI OLEFontImpl_IPersistPropertyBag_Load(
1840 IPersistPropertyBag *iface, IPropertyBag* pPropBag, IErrorLog* pErrorLog
1842 /* (from Visual Basic 6 property bag)
1843 Name = "MS Sans Serif"
1847 Underline = 0 'False
1849 Strikethrough = 0 'False
1851 static const WCHAR sAttrName[] = {'N','a','m','e',0};
1852 static const WCHAR sAttrSize[] = {'S','i','z','e',0};
1853 static const WCHAR sAttrCharset[] = {'C','h','a','r','s','e','t',0};
1854 static const WCHAR sAttrWeight[] = {'W','e','i','g','h','t',0};
1855 static const WCHAR sAttrUnderline[] = {'U','n','d','e','r','l','i','n','e',0};
1856 static const WCHAR sAttrItalic[] = {'I','t','a','l','i','c',0};
1857 static const WCHAR sAttrStrikethrough[] = {'S','t','r','i','k','e','t','h','r','o','u','g','h',0};
1860 HRESULT iRes = S_OK;
1861 _ICOM_THIS_From_IPersistPropertyBag(IFont, iface);
1863 VariantInit(&rawAttr);
1864 VariantInit(&valueAttr);
1867 iRes = IPropertyBag_Read(pPropBag, sAttrName, &rawAttr, pErrorLog);
1870 iRes = VariantChangeType(&rawAttr, &valueAttr, 0, VT_BSTR);
1872 iRes = IFont_put_Name(this, V_BSTR(&valueAttr));
1874 else if (iRes == E_INVALIDARG)
1876 VariantClear(&rawAttr);
1877 VariantClear(&valueAttr);
1881 iRes = IPropertyBag_Read(pPropBag, sAttrSize, &rawAttr, pErrorLog);
1884 iRes = VariantChangeType(&rawAttr, &valueAttr, 0, VT_CY);
1886 iRes = IFont_put_Size(this, V_CY(&valueAttr));
1888 else if (iRes == E_INVALIDARG)
1890 VariantClear(&rawAttr);
1891 VariantClear(&valueAttr);
1895 iRes = IPropertyBag_Read(pPropBag, sAttrCharset, &rawAttr, pErrorLog);
1898 iRes = VariantChangeType(&rawAttr, &valueAttr, 0, VT_I2);
1900 iRes = IFont_put_Charset(this, V_I2(&valueAttr));
1902 else if (iRes == E_INVALIDARG)
1904 VariantClear(&rawAttr);
1905 VariantClear(&valueAttr);
1909 iRes = IPropertyBag_Read(pPropBag, sAttrWeight, &rawAttr, pErrorLog);
1912 iRes = VariantChangeType(&rawAttr, &valueAttr, 0, VT_I2);
1914 iRes = IFont_put_Weight(this, V_I2(&valueAttr));
1916 else if (iRes == E_INVALIDARG)
1918 VariantClear(&rawAttr);
1919 VariantClear(&valueAttr);
1924 iRes = IPropertyBag_Read(pPropBag, sAttrUnderline, &rawAttr, pErrorLog);
1927 iRes = VariantChangeType(&rawAttr, &valueAttr, 0, VT_BOOL);
1929 iRes = IFont_put_Underline(this, V_BOOL(&valueAttr));
1931 else if (iRes == E_INVALIDARG)
1933 VariantClear(&rawAttr);
1934 VariantClear(&valueAttr);
1938 iRes = IPropertyBag_Read(pPropBag, sAttrItalic, &rawAttr, pErrorLog);
1941 iRes = VariantChangeType(&rawAttr, &valueAttr, 0, VT_BOOL);
1943 iRes = IFont_put_Italic(this, V_BOOL(&valueAttr));
1945 else if (iRes == E_INVALIDARG)
1947 VariantClear(&rawAttr);
1948 VariantClear(&valueAttr);
1952 iRes = IPropertyBag_Read(pPropBag, sAttrStrikethrough, &rawAttr, pErrorLog);
1955 iRes = VariantChangeType(&rawAttr, &valueAttr, 0, VT_BOOL);
1957 IFont_put_Strikethrough(this, V_BOOL(&valueAttr));
1959 else if (iRes == E_INVALIDARG)
1961 VariantClear(&rawAttr);
1962 VariantClear(&valueAttr);
1966 WARN("-- 0x%08lx\n", iRes);
1970 static HRESULT WINAPI OLEFontImpl_IPersistPropertyBag_Save(
1971 IPersistPropertyBag *iface, IPropertyBag* pPropBag, BOOL fClearDirty,
1972 BOOL fSaveAllProperties
1974 FIXME("(%p,%p,%d,%d), stub!\n", iface, pPropBag, fClearDirty, fSaveAllProperties);
1978 static IPersistPropertyBagVtbl OLEFontImpl_IPersistPropertyBag_VTable =
1980 OLEFontImpl_IPersistPropertyBag_QueryInterface,
1981 OLEFontImpl_IPersistPropertyBag_AddRef,
1982 OLEFontImpl_IPersistPropertyBag_Release,
1984 OLEFontImpl_IPersistPropertyBag_GetClassID,
1985 OLEFontImpl_IPersistPropertyBag_InitNew,
1986 OLEFontImpl_IPersistPropertyBag_Load,
1987 OLEFontImpl_IPersistPropertyBag_Save
1990 /************************************************************************
1991 * OLEFontImpl implementation of IPersistStreamInit.
1993 static HRESULT WINAPI OLEFontImpl_IPersistStreamInit_QueryInterface(
1994 IPersistStreamInit *iface, REFIID riid, LPVOID *ppvObj
1996 _ICOM_THIS_From_IPersistStreamInit(IFont, iface);
1997 return IFont_QueryInterface(this,riid,ppvObj);
2000 static ULONG WINAPI OLEFontImpl_IPersistStreamInit_AddRef(
2001 IPersistStreamInit *iface
2003 _ICOM_THIS_From_IPersistStreamInit(IFont, iface);
2004 return IFont_AddRef(this);
2007 static ULONG WINAPI OLEFontImpl_IPersistStreamInit_Release(
2008 IPersistStreamInit *iface
2010 _ICOM_THIS_From_IPersistStreamInit(IFont, iface);
2011 return IFont_Release(this);
2014 static HRESULT WINAPI OLEFontImpl_IPersistStreamInit_GetClassID(
2015 IPersistStreamInit *iface, CLSID *classid
2017 FIXME("(%p,%p), stub!\n", iface, classid);
2021 static HRESULT WINAPI OLEFontImpl_IPersistStreamInit_IsDirty(
2022 IPersistStreamInit *iface
2024 FIXME("(%p), stub!\n", iface);
2028 static HRESULT WINAPI OLEFontImpl_IPersistStreamInit_Load(
2029 IPersistStreamInit *iface, LPSTREAM pStm
2031 FIXME("(%p,%p), stub!\n", iface, pStm);
2035 static HRESULT WINAPI OLEFontImpl_IPersistStreamInit_Save(
2036 IPersistStreamInit *iface, LPSTREAM pStm, BOOL fClearDirty
2038 FIXME("(%p,%p,%d), stub!\n", iface, pStm, fClearDirty);
2042 static HRESULT WINAPI OLEFontImpl_IPersistStreamInit_GetSizeMax(
2043 IPersistStreamInit *iface, ULARGE_INTEGER *pcbSize
2045 FIXME("(%p,%p), stub!\n", iface, pcbSize);
2049 static HRESULT WINAPI OLEFontImpl_IPersistStreamInit_InitNew(
2050 IPersistStreamInit *iface
2052 FIXME("(%p), stub!\n", iface);
2056 static IPersistStreamInitVtbl OLEFontImpl_IPersistStreamInit_VTable =
2058 OLEFontImpl_IPersistStreamInit_QueryInterface,
2059 OLEFontImpl_IPersistStreamInit_AddRef,
2060 OLEFontImpl_IPersistStreamInit_Release,
2062 OLEFontImpl_IPersistStreamInit_GetClassID,
2063 OLEFontImpl_IPersistStreamInit_IsDirty,
2064 OLEFontImpl_IPersistStreamInit_Load,
2065 OLEFontImpl_IPersistStreamInit_Save,
2066 OLEFontImpl_IPersistStreamInit_GetSizeMax,
2067 OLEFontImpl_IPersistStreamInit_InitNew
2070 /*******************************************************************************
2071 * StdFont ClassFactory
2075 /* IUnknown fields */
2076 IClassFactoryVtbl *lpVtbl;
2078 } IClassFactoryImpl;
2080 static HRESULT WINAPI
2081 SFCF_QueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj) {
2082 ICOM_THIS(IClassFactoryImpl,iface);
2084 FIXME("(%p)->(%s,%p),stub!\n",This,debugstr_guid(riid),ppobj);
2085 return E_NOINTERFACE;
2089 SFCF_AddRef(LPCLASSFACTORY iface) {
2090 ICOM_THIS(IClassFactoryImpl,iface);
2091 return ++(This->ref);
2094 static ULONG WINAPI SFCF_Release(LPCLASSFACTORY iface) {
2095 ICOM_THIS(IClassFactoryImpl,iface);
2096 /* static class, won't be freed */
2097 return --(This->ref);
2100 static HRESULT WINAPI SFCF_CreateInstance(
2101 LPCLASSFACTORY iface,LPUNKNOWN pOuter,REFIID riid,LPVOID *ppobj
2103 return OleCreateFontIndirect(NULL,riid,ppobj);
2107 static HRESULT WINAPI SFCF_LockServer(LPCLASSFACTORY iface,BOOL dolock) {
2108 ICOM_THIS(IClassFactoryImpl,iface);
2109 FIXME("(%p)->(%d),stub!\n",This,dolock);
2113 static IClassFactoryVtbl SFCF_Vtbl = {
2114 SFCF_QueryInterface,
2117 SFCF_CreateInstance,
2120 static IClassFactoryImpl STDFONT_CF = {&SFCF_Vtbl, 1 };
2122 void _get_STDFONT_CF(LPVOID *ppv) { *ppv = (LPVOID)&STDFONT_CF; }