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 accommodate all of the VTables implemented
107 #define _ICOM_THIS_From_IDispatch(class, name) class* this = (class*)(((char*)name)-sizeof(void*))
108 #define _ICOM_THIS_From_IPersistStream(class, name) class* this = (class*)(((char*)name)-2*sizeof(void*))
109 #define _ICOM_THIS_From_IConnectionPointContainer(class, name) class* this = (class*)(((char*)name)-3*sizeof(void*))
110 #define _ICOM_THIS_From_IPersistPropertyBag(class, name) class* this = (class*)(((char*)name)-4*sizeof(void*))
111 #define _ICOM_THIS_From_IPersistStreamInit(class, name) class* this = (class*)(((char*)name)-5*sizeof(void*))
114 /***********************************************************************
115 * Prototypes for the implementation functions for the IFont
118 static OLEFontImpl* OLEFontImpl_Construct(LPFONTDESC fontDesc);
119 static void OLEFontImpl_Destroy(OLEFontImpl* fontDesc);
120 static HRESULT WINAPI OLEFontImpl_QueryInterface(IFont* iface, REFIID riid, VOID** ppvoid);
121 static ULONG WINAPI OLEFontImpl_AddRef(IFont* iface);
122 static ULONG WINAPI OLEFontImpl_Release(IFont* iface);
123 static HRESULT WINAPI OLEFontImpl_get_Name(IFont* iface, BSTR* pname);
124 static HRESULT WINAPI OLEFontImpl_put_Name(IFont* iface, BSTR name);
125 static HRESULT WINAPI OLEFontImpl_get_Size(IFont* iface, CY* psize);
126 static HRESULT WINAPI OLEFontImpl_put_Size(IFont* iface, CY size);
127 static HRESULT WINAPI OLEFontImpl_get_Bold(IFont* iface, BOOL* pbold);
128 static HRESULT WINAPI OLEFontImpl_put_Bold(IFont* iface, BOOL bold);
129 static HRESULT WINAPI OLEFontImpl_get_Italic(IFont* iface, BOOL* pitalic);
130 static HRESULT WINAPI OLEFontImpl_put_Italic(IFont* iface, BOOL italic);
131 static HRESULT WINAPI OLEFontImpl_get_Underline(IFont* iface, BOOL* punderline);
132 static HRESULT WINAPI OLEFontImpl_put_Underline(IFont* iface, BOOL underline);
133 static HRESULT WINAPI OLEFontImpl_get_Strikethrough(IFont* iface, BOOL* pstrikethrough);
134 static HRESULT WINAPI OLEFontImpl_put_Strikethrough(IFont* iface, BOOL strikethrough);
135 static HRESULT WINAPI OLEFontImpl_get_Weight(IFont* iface, short* pweight);
136 static HRESULT WINAPI OLEFontImpl_put_Weight(IFont* iface, short weight);
137 static HRESULT WINAPI OLEFontImpl_get_Charset(IFont* iface, short* pcharset);
138 static HRESULT WINAPI OLEFontImpl_put_Charset(IFont* iface, short charset);
139 static HRESULT WINAPI OLEFontImpl_get_hFont(IFont* iface, HFONT* phfont);
140 static HRESULT WINAPI OLEFontImpl_Clone(IFont* iface, IFont** ppfont);
141 static HRESULT WINAPI OLEFontImpl_IsEqual(IFont* iface, IFont* pFontOther);
142 static HRESULT WINAPI OLEFontImpl_SetRatio(IFont* iface, LONG cyLogical, LONG cyHimetric);
143 static HRESULT WINAPI OLEFontImpl_QueryTextMetrics(IFont* iface, TEXTMETRICOLE* ptm);
144 static HRESULT WINAPI OLEFontImpl_AddRefHfont(IFont* iface, HFONT hfont);
145 static HRESULT WINAPI OLEFontImpl_ReleaseHfont(IFont* iface, HFONT hfont);
146 static HRESULT WINAPI OLEFontImpl_SetHdc(IFont* iface, HDC hdc);
148 /***********************************************************************
149 * Prototypes for the implementation functions for the IDispatch
152 static HRESULT WINAPI OLEFontImpl_IDispatch_QueryInterface(IDispatch* iface,
155 static ULONG WINAPI OLEFontImpl_IDispatch_AddRef(IDispatch* iface);
156 static ULONG WINAPI OLEFontImpl_IDispatch_Release(IDispatch* iface);
157 static HRESULT WINAPI OLEFontImpl_GetTypeInfoCount(IDispatch* iface,
158 unsigned int* pctinfo);
159 static HRESULT WINAPI OLEFontImpl_GetTypeInfo(IDispatch* iface,
162 ITypeInfo** ppTInfo);
163 static HRESULT WINAPI OLEFontImpl_GetIDsOfNames(IDispatch* iface,
169 static HRESULT WINAPI OLEFontImpl_Invoke(IDispatch* iface,
174 DISPPARAMS* pDispParams,
176 EXCEPINFO* pExepInfo,
179 /***********************************************************************
180 * Prototypes for the implementation functions for the IPersistStream
183 static HRESULT WINAPI OLEFontImpl_IPersistStream_QueryInterface(IPersistStream* iface,
186 static ULONG WINAPI OLEFontImpl_IPersistStream_AddRef(IPersistStream* iface);
187 static ULONG WINAPI OLEFontImpl_IPersistStream_Release(IPersistStream* iface);
188 static HRESULT WINAPI OLEFontImpl_GetClassID(IPersistStream* iface,
190 static HRESULT WINAPI OLEFontImpl_IsDirty(IPersistStream* iface);
191 static HRESULT WINAPI OLEFontImpl_Load(IPersistStream* iface,
192 IStream* pLoadStream);
193 static HRESULT WINAPI OLEFontImpl_Save(IPersistStream* iface,
196 static HRESULT WINAPI OLEFontImpl_GetSizeMax(IPersistStream* iface,
197 ULARGE_INTEGER* pcbSize);
199 /***********************************************************************
200 * Prototypes for the implementation functions for the
201 * IConnectionPointContainer interface
203 static HRESULT WINAPI OLEFontImpl_IConnectionPointContainer_QueryInterface(
204 IConnectionPointContainer* iface,
207 static ULONG WINAPI OLEFontImpl_IConnectionPointContainer_AddRef(
208 IConnectionPointContainer* iface);
209 static ULONG WINAPI OLEFontImpl_IConnectionPointContainer_Release(
210 IConnectionPointContainer* iface);
211 static HRESULT WINAPI OLEFontImpl_EnumConnectionPoints(
212 IConnectionPointContainer* iface,
213 IEnumConnectionPoints **ppEnum);
214 static HRESULT WINAPI OLEFontImpl_FindConnectionPoint(
215 IConnectionPointContainer* iface,
217 IConnectionPoint **ppCp);
220 * Virtual function tables for the OLEFontImpl class.
222 static IFontVtbl OLEFontImpl_VTable =
224 OLEFontImpl_QueryInterface,
227 OLEFontImpl_get_Name,
228 OLEFontImpl_put_Name,
229 OLEFontImpl_get_Size,
230 OLEFontImpl_put_Size,
231 OLEFontImpl_get_Bold,
232 OLEFontImpl_put_Bold,
233 OLEFontImpl_get_Italic,
234 OLEFontImpl_put_Italic,
235 OLEFontImpl_get_Underline,
236 OLEFontImpl_put_Underline,
237 OLEFontImpl_get_Strikethrough,
238 OLEFontImpl_put_Strikethrough,
239 OLEFontImpl_get_Weight,
240 OLEFontImpl_put_Weight,
241 OLEFontImpl_get_Charset,
242 OLEFontImpl_put_Charset,
243 OLEFontImpl_get_hFont,
246 OLEFontImpl_SetRatio,
247 OLEFontImpl_QueryTextMetrics,
248 OLEFontImpl_AddRefHfont,
249 OLEFontImpl_ReleaseHfont,
253 static IDispatchVtbl OLEFontImpl_IDispatch_VTable =
255 OLEFontImpl_IDispatch_QueryInterface,
256 OLEFontImpl_IDispatch_AddRef,
257 OLEFontImpl_IDispatch_Release,
258 OLEFontImpl_GetTypeInfoCount,
259 OLEFontImpl_GetTypeInfo,
260 OLEFontImpl_GetIDsOfNames,
264 static IPersistStreamVtbl OLEFontImpl_IPersistStream_VTable =
266 OLEFontImpl_IPersistStream_QueryInterface,
267 OLEFontImpl_IPersistStream_AddRef,
268 OLEFontImpl_IPersistStream_Release,
269 OLEFontImpl_GetClassID,
273 OLEFontImpl_GetSizeMax
276 static IConnectionPointContainerVtbl
277 OLEFontImpl_IConnectionPointContainer_VTable =
279 OLEFontImpl_IConnectionPointContainer_QueryInterface,
280 OLEFontImpl_IConnectionPointContainer_AddRef,
281 OLEFontImpl_IConnectionPointContainer_Release,
282 OLEFontImpl_EnumConnectionPoints,
283 OLEFontImpl_FindConnectionPoint
286 static IPersistPropertyBagVtbl OLEFontImpl_IPersistPropertyBag_VTable;
287 static IPersistStreamInitVtbl OLEFontImpl_IPersistStreamInit_VTable;
288 /******************************************************************************
289 * OleCreateFontIndirect [OLEAUT32.420]
291 HRESULT WINAPI OleCreateFontIndirect(
292 LPFONTDESC lpFontDesc,
296 OLEFontImpl* newFont = 0;
299 TRACE("(%p, %s, %p)\n", lpFontDesc, debugstr_guid(riid), ppvObj);
311 static const WCHAR fname[] = { 'S','y','s','t','e','m',0 };
313 fd.cbSizeofstruct = sizeof(fd);
314 fd.lpstrName = (WCHAR*)fname;
315 fd.cySize.s.Lo = 80000;
321 fd.fStrikethrough = 0;
326 * Try to construct a new instance of the class.
328 newFont = OLEFontImpl_Construct(lpFontDesc);
331 return E_OUTOFMEMORY;
334 * Make sure it supports the interface required by the caller.
336 hr = IFont_QueryInterface((IFont*)newFont, riid, ppvObj);
339 * Release the reference obtained in the constructor. If
340 * the QueryInterface was unsuccessful, it will free the class.
342 IFont_Release((IFont*)newFont);
348 /***********************************************************************
349 * Implementation of the OLEFontImpl class.
352 /***********************************************************************
353 * OLEFont_SendNotify (internal)
355 * Sends notification messages of changed properties to any interested
358 static void OLEFont_SendNotify(OLEFontImpl* this, DISPID dispID)
360 IEnumConnections *pEnum;
364 hres = IConnectionPoint_EnumConnections(this->pCP, &pEnum);
365 if (FAILED(hres)) /* When we have 0 connections. */
368 while(IEnumConnections_Next(pEnum, 1, &CD, NULL) == S_OK) {
369 IPropertyNotifySink *sink;
371 IUnknown_QueryInterface(CD.pUnk, &IID_IPropertyNotifySink, (LPVOID)&sink);
372 IPropertyNotifySink_OnChanged(sink, dispID);
373 IPropertyNotifySink_Release(sink);
374 IUnknown_Release(CD.pUnk);
376 IEnumConnections_Release(pEnum);
380 /************************************************************************
381 * OLEFontImpl_Construct
383 * This method will construct a new instance of the OLEFontImpl
386 * The caller of this method must release the object when it's
389 static OLEFontImpl* OLEFontImpl_Construct(LPFONTDESC fontDesc)
391 OLEFontImpl* newObject = 0;
394 * Allocate space for the object.
396 newObject = HeapAlloc(GetProcessHeap(), 0, sizeof(OLEFontImpl));
402 * Initialize the virtual function table.
404 newObject->lpvtbl1 = &OLEFontImpl_VTable;
405 newObject->lpvtbl2 = &OLEFontImpl_IDispatch_VTable;
406 newObject->lpvtbl3 = &OLEFontImpl_IPersistStream_VTable;
407 newObject->lpvtbl4 = &OLEFontImpl_IConnectionPointContainer_VTable;
408 newObject->lpvtbl5 = &OLEFontImpl_IPersistPropertyBag_VTable;
409 newObject->lpvtbl6 = &OLEFontImpl_IPersistStreamInit_VTable;
412 * Start with one reference count. The caller of this function
413 * must release the interface pointer when it is done.
418 * Copy the description of the font in the object.
420 assert(fontDesc->cbSizeofstruct >= sizeof(FONTDESC));
422 newObject->description.cbSizeofstruct = sizeof(FONTDESC);
423 newObject->description.lpstrName = HeapAlloc(GetProcessHeap(),
425 (lstrlenW(fontDesc->lpstrName)+1) * sizeof(WCHAR));
426 strcpyW(newObject->description.lpstrName, fontDesc->lpstrName);
427 newObject->description.cySize = fontDesc->cySize;
428 newObject->description.sWeight = fontDesc->sWeight;
429 newObject->description.sCharset = fontDesc->sCharset;
430 newObject->description.fItalic = fontDesc->fItalic;
431 newObject->description.fUnderline = fontDesc->fUnderline;
432 newObject->description.fStrikethrough = fontDesc->fStrikethrough;
435 * Initializing all the other members.
437 newObject->gdiFont = 0;
438 newObject->fontLock = 0;
439 newObject->cyLogical = 72L;
440 newObject->cyHimetric = 2540L;
441 CreateConnectionPoint((IUnknown*)newObject, &IID_IPropertyNotifySink, &newObject->pCP);
442 TRACE("returning %p\n", newObject);
446 /************************************************************************
447 * OLEFontImpl_Destroy
449 * This method is called by the Release method when the reference
450 * count goes down to 0. It will free all resources used by
453 static void OLEFontImpl_Destroy(OLEFontImpl* fontDesc)
455 TRACE("(%p)\n", fontDesc);
457 HeapFree(GetProcessHeap(), 0, fontDesc->description.lpstrName);
459 if (fontDesc->gdiFont!=0)
460 DeleteObject(fontDesc->gdiFont);
462 HeapFree(GetProcessHeap(), 0, fontDesc);
465 /************************************************************************
466 * OLEFontImpl_QueryInterface (IUnknown)
468 * See Windows documentation for more details on IUnknown methods.
470 HRESULT WINAPI OLEFontImpl_QueryInterface(
475 OLEFontImpl *this = (OLEFontImpl *)iface;
476 TRACE("(%p)->(%s, %p)\n", this, debugstr_guid(riid), ppvObject);
479 * Perform a sanity check on the parameters.
481 if ( (this==0) || (ppvObject==0) )
485 * Initialize the return parameter.
490 * Compare the riid with the interface IDs implemented by this object.
492 if (IsEqualGUID(&IID_IUnknown, riid))
493 *ppvObject = (IFont*)this;
494 if (IsEqualGUID(&IID_IFont, riid))
495 *ppvObject = (IFont*)this;
496 if (IsEqualGUID(&IID_IDispatch, riid))
497 *ppvObject = (IDispatch*)&(this->lpvtbl2);
498 if (IsEqualGUID(&IID_IFontDisp, riid))
499 *ppvObject = (IDispatch*)&(this->lpvtbl2);
500 if (IsEqualGUID(&IID_IPersistStream, riid))
501 *ppvObject = (IPersistStream*)&(this->lpvtbl3);
502 if (IsEqualGUID(&IID_IConnectionPointContainer, riid))
503 *ppvObject = (IConnectionPointContainer*)&(this->lpvtbl4);
504 if (IsEqualGUID(&IID_IPersistPropertyBag, riid))
505 *ppvObject = (IPersistPropertyBag*)&(this->lpvtbl5);
506 if (IsEqualGUID(&IID_IPersistStreamInit, riid))
507 *ppvObject = (IPersistStreamInit*)&(this->lpvtbl6);
510 * Check that we obtained an interface.
514 FIXME("() : asking for unsupported interface %s\n",debugstr_guid(riid));
515 return E_NOINTERFACE;
517 OLEFontImpl_AddRef((IFont*)this);
521 /************************************************************************
522 * OLEFontImpl_AddRef (IUnknown)
524 * See Windows documentation for more details on IUnknown methods.
526 ULONG WINAPI OLEFontImpl_AddRef(
529 OLEFontImpl *this = (OLEFontImpl *)iface;
530 TRACE("(%p)->(ref=%ld)\n", this, this->ref);
531 return InterlockedIncrement(&this->ref);
534 /************************************************************************
535 * OLEFontImpl_Release (IUnknown)
537 * See Windows documentation for more details on IUnknown methods.
539 ULONG WINAPI OLEFontImpl_Release(
542 OLEFontImpl *this = (OLEFontImpl *)iface;
544 TRACE("(%p)->(ref=%ld)\n", this, this->ref);
547 * Decrease the reference count on this object.
549 ret = InterlockedDecrement(&this->ref);
552 * If the reference count goes down to 0, perform suicide.
554 if (ret==0) OLEFontImpl_Destroy(this);
559 /************************************************************************
560 * OLEFontImpl_get_Name (IFont)
562 * See Windows documentation for more details on IFont methods.
564 static HRESULT WINAPI OLEFontImpl_get_Name(
568 OLEFontImpl *this = (OLEFontImpl *)iface;
569 TRACE("(%p)->(%p)\n", this, pname);
576 if (this->description.lpstrName!=0)
577 *pname = SysAllocString(this->description.lpstrName);
584 /************************************************************************
585 * OLEFontImpl_put_Name (IFont)
587 * See Windows documentation for more details on IFont methods.
589 static HRESULT WINAPI OLEFontImpl_put_Name(
593 OLEFontImpl *this = (OLEFontImpl *)iface;
594 TRACE("(%p)->(%p)\n", this, name);
596 if (this->description.lpstrName==0)
598 this->description.lpstrName = HeapAlloc(GetProcessHeap(),
600 (lstrlenW(name)+1) * sizeof(WCHAR));
604 this->description.lpstrName = HeapReAlloc(GetProcessHeap(),
606 this->description.lpstrName,
607 (lstrlenW(name)+1) * sizeof(WCHAR));
610 if (this->description.lpstrName==0)
611 return E_OUTOFMEMORY;
613 strcpyW(this->description.lpstrName, name);
614 TRACE("new name %s\n", debugstr_w(this->description.lpstrName));
615 OLEFont_SendNotify(this, DISPID_FONT_NAME);
619 /************************************************************************
620 * OLEFontImpl_get_Size (IFont)
622 * See Windows documentation for more details on IFont methods.
624 static HRESULT WINAPI OLEFontImpl_get_Size(
628 OLEFontImpl *this = (OLEFontImpl *)iface;
629 TRACE("(%p)->(%p)\n", this, psize);
638 psize->s.Lo = this->description.cySize.s.Lo;
643 /************************************************************************
644 * OLEFontImpl_put_Size (IFont)
646 * See Windows documentation for more details on IFont methods.
648 static HRESULT WINAPI OLEFontImpl_put_Size(
652 OLEFontImpl *this = (OLEFontImpl *)iface;
653 TRACE("(%p)->(%ld)\n", this, size.s.Lo);
654 this->description.cySize.s.Hi = 0;
655 this->description.cySize.s.Lo = size.s.Lo;
656 OLEFont_SendNotify(this, DISPID_FONT_SIZE);
661 /************************************************************************
662 * OLEFontImpl_get_Bold (IFont)
664 * See Windows documentation for more details on IFont methods.
666 static HRESULT WINAPI OLEFontImpl_get_Bold(
670 OLEFontImpl *this = (OLEFontImpl *)iface;
671 TRACE("(%p)->(%p)\n", this, pbold);
678 *pbold = this->description.sWeight > 550;
683 /************************************************************************
684 * OLEFontImpl_put_Bold (IFont)
686 * See Windows documentation for more details on IFont methods.
688 static HRESULT WINAPI OLEFontImpl_put_Bold(
692 OLEFontImpl *this = (OLEFontImpl *)iface;
693 TRACE("(%p)->(%d)\n", this, bold);
694 this->description.sWeight = bold ? FW_BOLD : FW_NORMAL;
695 OLEFont_SendNotify(this, DISPID_FONT_BOLD);
700 /************************************************************************
701 * OLEFontImpl_get_Italic (IFont)
703 * See Windows documentation for more details on IFont methods.
705 static HRESULT WINAPI OLEFontImpl_get_Italic(
709 OLEFontImpl *this = (OLEFontImpl *)iface;
710 TRACE("(%p)->(%p)\n", this, pitalic);
717 *pitalic = this->description.fItalic;
722 /************************************************************************
723 * OLEFontImpl_put_Italic (IFont)
725 * See Windows documentation for more details on IFont methods.
727 static HRESULT WINAPI OLEFontImpl_put_Italic(
731 OLEFontImpl *this = (OLEFontImpl *)iface;
732 TRACE("(%p)->(%d)\n", this, italic);
734 this->description.fItalic = italic;
736 OLEFont_SendNotify(this, DISPID_FONT_ITALIC);
740 /************************************************************************
741 * OLEFontImpl_get_Underline (IFont)
743 * See Windows documentation for more details on IFont methods.
745 static HRESULT WINAPI OLEFontImpl_get_Underline(
749 OLEFontImpl *this = (OLEFontImpl *)iface;
750 TRACE("(%p)->(%p)\n", this, punderline);
758 *punderline = this->description.fUnderline;
763 /************************************************************************
764 * OLEFontImpl_put_Underline (IFont)
766 * See Windows documentation for more details on IFont methods.
768 static HRESULT WINAPI OLEFontImpl_put_Underline(
772 OLEFontImpl *this = (OLEFontImpl *)iface;
773 TRACE("(%p)->(%d)\n", this, underline);
775 this->description.fUnderline = underline;
777 OLEFont_SendNotify(this, DISPID_FONT_UNDER);
781 /************************************************************************
782 * OLEFontImpl_get_Strikethrough (IFont)
784 * See Windows documentation for more details on IFont methods.
786 static HRESULT WINAPI OLEFontImpl_get_Strikethrough(
788 BOOL* pstrikethrough)
790 OLEFontImpl *this = (OLEFontImpl *)iface;
791 TRACE("(%p)->(%p)\n", this, pstrikethrough);
796 if (pstrikethrough==0)
799 *pstrikethrough = this->description.fStrikethrough;
804 /************************************************************************
805 * OLEFontImpl_put_Strikethrough (IFont)
807 * See Windows documentation for more details on IFont methods.
809 static HRESULT WINAPI OLEFontImpl_put_Strikethrough(
813 OLEFontImpl *this = (OLEFontImpl *)iface;
814 TRACE("(%p)->(%d)\n", this, strikethrough);
816 this->description.fStrikethrough = strikethrough;
817 OLEFont_SendNotify(this, DISPID_FONT_STRIKE);
822 /************************************************************************
823 * OLEFontImpl_get_Weight (IFont)
825 * See Windows documentation for more details on IFont methods.
827 static HRESULT WINAPI OLEFontImpl_get_Weight(
831 OLEFontImpl *this = (OLEFontImpl *)iface;
832 TRACE("(%p)->(%p)\n", this, pweight);
840 *pweight = this->description.sWeight;
845 /************************************************************************
846 * OLEFontImpl_put_Weight (IFont)
848 * See Windows documentation for more details on IFont methods.
850 static HRESULT WINAPI OLEFontImpl_put_Weight(
854 OLEFontImpl *this = (OLEFontImpl *)iface;
855 TRACE("(%p)->(%d)\n", this, weight);
857 this->description.sWeight = weight;
859 OLEFont_SendNotify(this, DISPID_FONT_WEIGHT);
863 /************************************************************************
864 * OLEFontImpl_get_Charset (IFont)
866 * See Windows documentation for more details on IFont methods.
868 static HRESULT WINAPI OLEFontImpl_get_Charset(
872 OLEFontImpl *this = (OLEFontImpl *)iface;
873 TRACE("(%p)->(%p)\n", this, pcharset);
881 *pcharset = this->description.sCharset;
886 /************************************************************************
887 * OLEFontImpl_put_Charset (IFont)
889 * See Windows documentation for more details on IFont methods.
891 static HRESULT WINAPI OLEFontImpl_put_Charset(
895 OLEFontImpl *this = (OLEFontImpl *)iface;
896 TRACE("(%p)->(%d)\n", this, charset);
898 this->description.sCharset = charset;
899 OLEFont_SendNotify(this, DISPID_FONT_CHARSET);
904 /************************************************************************
905 * OLEFontImpl_get_hFont (IFont)
907 * See Windows documentation for more details on IFont methods.
909 static HRESULT WINAPI OLEFontImpl_get_hFont(
913 OLEFontImpl *this = (OLEFontImpl *)iface;
914 TRACE("(%p)->(%p)\n", this, phfont);
919 * Realize the font if necessary
921 if (this->gdiFont==0)
928 * The height of the font returned by the get_Size property is the
929 * height of the font in points multiplied by 10000... Using some
930 * simple conversions and the ratio given by the application, it can
931 * be converted to a height in pixels.
933 IFont_get_Size(iface, &cySize);
935 fontHeight = MulDiv( cySize.s.Lo, this->cyLogical, this->cyHimetric );
937 memset(&logFont, 0, sizeof(LOGFONTW));
939 logFont.lfHeight = ((fontHeight%10000L)>5000L) ? (-fontHeight/10000L)-1 :
940 (-fontHeight/10000L);
941 logFont.lfItalic = this->description.fItalic;
942 logFont.lfUnderline = this->description.fUnderline;
943 logFont.lfStrikeOut = this->description.fStrikethrough;
944 logFont.lfWeight = this->description.sWeight;
945 logFont.lfCharSet = this->description.sCharset;
946 logFont.lfOutPrecision = OUT_CHARACTER_PRECIS;
947 logFont.lfClipPrecision = CLIP_DEFAULT_PRECIS;
948 logFont.lfQuality = DEFAULT_QUALITY;
949 logFont.lfPitchAndFamily = DEFAULT_PITCH;
950 strcpyW(logFont.lfFaceName,this->description.lpstrName);
952 this->gdiFont = CreateFontIndirectW(&logFont);
955 *phfont = this->gdiFont;
956 TRACE("Returning %p\n", *phfont);
960 /************************************************************************
961 * OLEFontImpl_Clone (IFont)
963 * See Windows documentation for more details on IFont methods.
965 static HRESULT WINAPI OLEFontImpl_Clone(
969 OLEFontImpl* newObject = 0;
973 OLEFontImpl *this = (OLEFontImpl *)iface;
974 TRACE("(%p)->(%p)\n", this, ppfont);
982 * Allocate space for the object.
984 newObject = HeapAlloc(GetProcessHeap(), 0, sizeof(OLEFontImpl));
987 return E_OUTOFMEMORY;
991 /* We need to alloc new memory for the string, otherwise
992 * we free memory twice.
994 newObject->description.lpstrName = HeapAlloc(
996 (1+strlenW(this->description.lpstrName))*2
998 strcpyW(newObject->description.lpstrName, this->description.lpstrName);
999 /* We need to clone the HFONT too. This is just cut & paste from above */
1000 IFont_get_Size(iface, &cySize);
1002 fontHeight = MulDiv(cySize.s.Lo, this->cyLogical,this->cyHimetric);
1004 memset(&logFont, 0, sizeof(LOGFONTW));
1006 logFont.lfHeight = ((fontHeight%10000L)>5000L) ? (-fontHeight/10000L)-1 :
1007 (-fontHeight/10000L);
1008 logFont.lfItalic = this->description.fItalic;
1009 logFont.lfUnderline = this->description.fUnderline;
1010 logFont.lfStrikeOut = this->description.fStrikethrough;
1011 logFont.lfWeight = this->description.sWeight;
1012 logFont.lfCharSet = this->description.sCharset;
1013 logFont.lfOutPrecision = OUT_CHARACTER_PRECIS;
1014 logFont.lfClipPrecision = CLIP_DEFAULT_PRECIS;
1015 logFont.lfQuality = DEFAULT_QUALITY;
1016 logFont.lfPitchAndFamily = DEFAULT_PITCH;
1017 strcpyW(logFont.lfFaceName,this->description.lpstrName);
1019 newObject->gdiFont = CreateFontIndirectW(&logFont);
1022 /* The cloned object starts with a reference count of 1 */
1025 *ppfont = (IFont*)newObject;
1030 /************************************************************************
1031 * OLEFontImpl_IsEqual (IFont)
1033 * See Windows documentation for more details on IFont methods.
1035 static HRESULT WINAPI OLEFontImpl_IsEqual(
1039 FIXME("(%p, %p), stub!\n",iface,pFontOther);
1043 /************************************************************************
1044 * OLEFontImpl_SetRatio (IFont)
1046 * See Windows documentation for more details on IFont methods.
1048 static HRESULT WINAPI OLEFontImpl_SetRatio(
1053 OLEFontImpl *this = (OLEFontImpl *)iface;
1054 TRACE("(%p)->(%ld, %ld)\n", this, cyLogical, cyHimetric);
1056 this->cyLogical = cyLogical;
1057 this->cyHimetric = cyHimetric;
1062 /************************************************************************
1063 * OLEFontImpl_QueryTextMetrics (IFont)
1065 * See Windows documentation for more details on IFont methods.
1067 static HRESULT WINAPI OLEFontImpl_QueryTextMetrics(
1072 HFONT hOldFont, hNewFont;
1075 OLEFontImpl_get_hFont(iface, &hNewFont);
1076 hOldFont = SelectObject(hdcRef, hNewFont);
1077 GetTextMetricsW(hdcRef, ptm);
1078 SelectObject(hdcRef, hOldFont);
1079 ReleaseDC(0, hdcRef);
1083 /************************************************************************
1084 * OLEFontImpl_AddRefHfont (IFont)
1086 * See Windows documentation for more details on IFont methods.
1088 static HRESULT WINAPI OLEFontImpl_AddRefHfont(
1092 OLEFontImpl *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 OLEFontImpl *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 OLEFontImpl *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)\n", this, iTInfo, (int)lcid, ppTInfo);
1223 hres = LoadTypeLib(stdole32tlb, &tl);
1225 ERR("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: {
1289 if (V_VT(&pDispParams->rgvarg[0]) == VT_DISPATCH) {
1293 hr = IUnknown_QueryInterface(V_DISPATCH(&pDispParams->rgvarg[0]), &IID_IFont, (void **) &font);
1296 FIXME("dispatch value for name property is not an OleFont, returning hr=0x%lx\n", hr);
1300 hr = IFont_get_Name(font, &name); /* this allocates a new BSTR so free it later */
1301 if (FAILED(hr)) return hr;
1303 IUnknown_Release(font);
1306 } else if (V_VT(&pDispParams->rgvarg[0]) == VT_BSTR) {
1307 name = V_BSTR(&pDispParams->rgvarg[0]);
1310 FIXME("app is trying to set name property with a non BSTR, non dispatch value. returning E_FAIL\n");
1314 TRACE("name is %s\n", debugstr_w(name));
1316 if (!xthis->description.lpstrName)
1317 xthis->description.lpstrName = HeapAlloc(GetProcessHeap(), 0, (lstrlenW(name)+1) * sizeof(WCHAR));
1319 xthis->description.lpstrName = HeapReAlloc(GetProcessHeap(), 0, xthis->description.lpstrName, (lstrlenW(name)+1) * sizeof(WCHAR));
1321 if (xthis->description.lpstrName==0)
1322 return E_OUTOFMEMORY;
1323 strcpyW(xthis->description.lpstrName, name);
1325 if (freename) SysFreeString(name);
1331 case DISPID_FONT_BOLD:
1333 case DISPATCH_PROPERTYGET:
1334 case DISPATCH_PROPERTYGET|DISPATCH_METHOD:
1335 V_VT(pVarResult) = VT_BOOL;
1336 return OLEFontImpl_get_Bold(this, (BOOL*)&V_BOOL(pVarResult));
1337 case DISPATCH_PROPERTYPUT:
1338 if (V_VT(&pDispParams->rgvarg[0]) != VT_BOOL) {
1339 FIXME("DISPID_FONT_BOLD/put, vt is %d, not VT_BOOL.\n",V_VT(&pDispParams->rgvarg[0]));
1342 xthis->description.sWeight = V_BOOL(&pDispParams->rgvarg[0]) ? FW_BOLD : FW_NORMAL;
1347 case DISPID_FONT_ITALIC:
1349 case DISPATCH_PROPERTYGET:
1350 case DISPATCH_PROPERTYGET|DISPATCH_METHOD:
1351 V_VT(pVarResult) = VT_BOOL;
1352 return OLEFontImpl_get_Italic(this, (BOOL*)&V_BOOL(pVarResult));
1353 case DISPATCH_PROPERTYPUT:
1354 if (V_VT(&pDispParams->rgvarg[0]) != VT_BOOL) {
1355 FIXME("DISPID_FONT_ITALIC/put, vt is %d, not VT_BOOL.\n",V_VT(&pDispParams->rgvarg[0]));
1358 xthis->description.fItalic = V_BOOL(&pDispParams->rgvarg[0]);
1363 case DISPID_FONT_UNDER:
1365 case DISPATCH_PROPERTYGET:
1366 case DISPATCH_PROPERTYGET|DISPATCH_METHOD:
1367 V_VT(pVarResult) = VT_BOOL;
1368 return OLEFontImpl_get_Underline(this, (BOOL*)&V_BOOL(pVarResult));
1369 case DISPATCH_PROPERTYPUT:
1370 if (V_VT(&pDispParams->rgvarg[0]) != VT_BOOL) {
1371 FIXME("DISPID_FONT_UNDER/put, vt is %d, not VT_BOOL.\n",V_VT(&pDispParams->rgvarg[0]));
1374 xthis->description.fUnderline = V_BOOL(&pDispParams->rgvarg[0]);
1379 case DISPID_FONT_STRIKE:
1381 case DISPATCH_PROPERTYGET:
1382 case DISPATCH_PROPERTYGET|DISPATCH_METHOD:
1383 V_VT(pVarResult) = VT_BOOL;
1384 return OLEFontImpl_get_Strikethrough(this, (BOOL*)&V_BOOL(pVarResult));
1385 case DISPATCH_PROPERTYPUT:
1386 if (V_VT(&pDispParams->rgvarg[0]) != VT_BOOL) {
1387 FIXME("DISPID_FONT_STRIKE/put, vt is %d, not VT_BOOL.\n",V_VT(&pDispParams->rgvarg[0]));
1390 xthis->description.fStrikethrough = V_BOOL(&pDispParams->rgvarg[0]);
1395 case DISPID_FONT_SIZE:
1397 case DISPATCH_PROPERTYPUT: {
1398 assert (pDispParams->cArgs == 1);
1399 xthis->description.cySize.s.Hi = 0;
1400 if (V_VT(&pDispParams->rgvarg[0]) != VT_CY) {
1401 if (V_VT(&pDispParams->rgvarg[0]) == VT_I2) {
1402 xthis->description.cySize.s.Lo = V_I2(&pDispParams->rgvarg[0]) * 10000;
1404 FIXME("property put for Size with vt %d unsupported!\n",V_VT(&pDispParams->rgvarg[0]));
1407 xthis->description.cySize.s.Lo = V_CY(&pDispParams->rgvarg[0]).s.Lo;
1411 case DISPATCH_PROPERTYGET:
1412 case DISPATCH_PROPERTYGET|DISPATCH_METHOD:
1413 V_VT(pVarResult) = VT_CY;
1414 return OLEFontImpl_get_Size(this, &V_CY(pVarResult));
1417 case DISPID_FONT_CHARSET:
1419 case DISPATCH_PROPERTYPUT:
1420 assert (pDispParams->cArgs == 1);
1421 if (V_VT(&pDispParams->rgvarg[0]) != VT_I2)
1422 FIXME("varg of first disparg is not VT_I2, but %d\n",V_VT(&pDispParams->rgvarg[0]));
1423 xthis->description.sCharset = V_I2(&pDispParams->rgvarg[0]);
1425 case DISPATCH_PROPERTYGET:
1426 case DISPATCH_PROPERTYGET|DISPATCH_METHOD:
1427 V_VT(pVarResult) = VT_I2;
1428 return OLEFontImpl_get_Charset(this, &V_I2(pVarResult));
1432 FIXME("%p->(%ld,%s,%lx,%x,%p,%p,%p,%p), unhandled dispid/flag!\n",
1433 this,dispIdMember,debugstr_guid(riid),lcid,
1434 wFlags,pDispParams,pVarResult,pExepInfo,puArgErr
1439 /************************************************************************
1440 * OLEFontImpl_IPersistStream_QueryInterface (IUnknown)
1442 * See Windows documentation for more details on IUnknown methods.
1444 static HRESULT WINAPI OLEFontImpl_IPersistStream_QueryInterface(
1445 IPersistStream* iface,
1449 _ICOM_THIS_From_IPersistStream(IFont, iface);
1451 return IFont_QueryInterface(this, riid, ppvoid);
1454 /************************************************************************
1455 * OLEFontImpl_IPersistStream_Release (IUnknown)
1457 * See Windows documentation for more details on IUnknown methods.
1459 static ULONG WINAPI OLEFontImpl_IPersistStream_Release(
1460 IPersistStream* iface)
1462 _ICOM_THIS_From_IPersistStream(IFont, iface);
1464 return IFont_Release(this);
1467 /************************************************************************
1468 * OLEFontImpl_IPersistStream_AddRef (IUnknown)
1470 * See Windows documentation for more details on IUnknown methods.
1472 static ULONG WINAPI OLEFontImpl_IPersistStream_AddRef(
1473 IPersistStream* iface)
1475 _ICOM_THIS_From_IPersistStream(IFont, iface);
1477 return IFont_AddRef(this);
1480 /************************************************************************
1481 * OLEFontImpl_GetClassID (IPersistStream)
1483 * See Windows documentation for more details on IPersistStream methods.
1485 static HRESULT WINAPI OLEFontImpl_GetClassID(
1486 IPersistStream* iface,
1489 TRACE("(%p,%p)\n",iface,pClassID);
1493 memcpy(pClassID, &CLSID_StdFont, sizeof(CLSID_StdFont));
1498 /************************************************************************
1499 * OLEFontImpl_IsDirty (IPersistStream)
1501 * See Windows documentation for more details on IPersistStream methods.
1503 static HRESULT WINAPI OLEFontImpl_IsDirty(
1504 IPersistStream* iface)
1506 TRACE("(%p)\n",iface);
1510 /************************************************************************
1511 * OLEFontImpl_Load (IPersistStream)
1513 * See Windows documentation for more details on IPersistStream methods.
1515 * This is the format of the standard font serialization as far as I
1518 * Offset Type Value Comment
1519 * 0x0000 Byte Unknown Probably a version number, contains 0x01
1520 * 0x0001 Short Charset Charset value from the FONTDESC structure
1521 * 0x0003 Byte Attributes Flags defined as follows:
1523 * 00000100 - Underline
1524 * 00001000 - Strikethrough
1525 * 0x0004 Short Weight Weight value from FONTDESC structure
1526 * 0x0006 DWORD size "Low" portion of the cySize member of the FONTDESC
1528 * 0x000A Byte name length Length of the font name string (no null character)
1529 * 0x000B String name Name of the font (ASCII, no nul character)
1531 static HRESULT WINAPI OLEFontImpl_Load(
1532 IPersistStream* iface,
1533 IStream* pLoadStream)
1535 char readBuffer[0x100];
1542 _ICOM_THIS_From_IPersistStream(OLEFontImpl, iface);
1545 * Read the version byte
1547 IStream_Read(pLoadStream, &bVersion, 1, &cbRead);
1556 IStream_Read(pLoadStream, &this->description.sCharset, 2, &cbRead);
1564 IStream_Read(pLoadStream, &bAttributes, 1, &cbRead);
1569 this->description.fItalic = (bAttributes & FONTPERSIST_ITALIC) != 0;
1570 this->description.fStrikethrough = (bAttributes & FONTPERSIST_STRIKETHROUGH) != 0;
1571 this->description.fUnderline = (bAttributes & FONTPERSIST_UNDERLINE) != 0;
1576 IStream_Read(pLoadStream, &this->description.sWeight, 2, &cbRead);
1584 IStream_Read(pLoadStream, &this->description.cySize.s.Lo, 4, &cbRead);
1589 this->description.cySize.s.Hi = 0;
1594 IStream_Read(pLoadStream, &bStringSize, 1, &cbRead);
1599 IStream_Read(pLoadStream, readBuffer, bStringSize, &cbRead);
1601 if (cbRead!=bStringSize)
1604 HeapFree(GetProcessHeap(), 0, this->description.lpstrName);
1606 len = MultiByteToWideChar( CP_ACP, 0, readBuffer, bStringSize, NULL, 0 );
1607 this->description.lpstrName = HeapAlloc( GetProcessHeap(), 0, (len+1) * sizeof(WCHAR) );
1608 MultiByteToWideChar( CP_ACP, 0, readBuffer, bStringSize, this->description.lpstrName, len );
1609 this->description.lpstrName[len] = 0;
1611 /* Ensure use of this font causes a new one to be created @@@@ */
1612 DeleteObject(this->gdiFont);
1618 /************************************************************************
1619 * OLEFontImpl_Save (IPersistStream)
1621 * See Windows documentation for more details on IPersistStream methods.
1623 static HRESULT WINAPI OLEFontImpl_Save(
1624 IPersistStream* iface,
1625 IStream* pOutStream,
1628 char* writeBuffer = NULL;
1630 BYTE bVersion = 0x01;
1634 _ICOM_THIS_From_IPersistStream(OLEFontImpl, iface);
1637 * Read the version byte
1639 IStream_Write(pOutStream, &bVersion, 1, &cbWritten);
1647 IStream_Write(pOutStream, &this->description.sCharset, 2, &cbWritten);
1657 if (this->description.fItalic)
1658 bAttributes |= FONTPERSIST_ITALIC;
1660 if (this->description.fStrikethrough)
1661 bAttributes |= FONTPERSIST_STRIKETHROUGH;
1663 if (this->description.fUnderline)
1664 bAttributes |= FONTPERSIST_UNDERLINE;
1666 IStream_Write(pOutStream, &bAttributes, 1, &cbWritten);
1674 IStream_Write(pOutStream, &this->description.sWeight, 2, &cbWritten);
1682 IStream_Write(pOutStream, &this->description.cySize.s.Lo, 4, &cbWritten);
1690 if (this->description.lpstrName!=0)
1691 bStringSize = WideCharToMultiByte( CP_ACP, 0, this->description.lpstrName,
1692 strlenW(this->description.lpstrName), NULL, 0, NULL, NULL );
1696 IStream_Write(pOutStream, &bStringSize, 1, &cbWritten);
1703 if (!(writeBuffer = HeapAlloc( GetProcessHeap(), 0, bStringSize ))) return E_OUTOFMEMORY;
1704 WideCharToMultiByte( CP_ACP, 0, this->description.lpstrName,
1705 strlenW(this->description.lpstrName),
1706 writeBuffer, bStringSize, NULL, NULL );
1708 IStream_Write(pOutStream, writeBuffer, bStringSize, &cbWritten);
1709 HeapFree(GetProcessHeap(), 0, writeBuffer);
1711 if (cbWritten!=bStringSize)
1718 /************************************************************************
1719 * OLEFontImpl_GetSizeMax (IPersistStream)
1721 * See Windows documentation for more details on IPersistStream methods.
1723 static HRESULT WINAPI OLEFontImpl_GetSizeMax(
1724 IPersistStream* iface,
1725 ULARGE_INTEGER* pcbSize)
1727 _ICOM_THIS_From_IPersistStream(OLEFontImpl, iface);
1732 pcbSize->u.HighPart = 0;
1733 pcbSize->u.LowPart = 0;
1735 pcbSize->u.LowPart += sizeof(BYTE); /* Version */
1736 pcbSize->u.LowPart += sizeof(WORD); /* Lang code */
1737 pcbSize->u.LowPart += sizeof(BYTE); /* Flags */
1738 pcbSize->u.LowPart += sizeof(WORD); /* Weight */
1739 pcbSize->u.LowPart += sizeof(DWORD); /* Size */
1740 pcbSize->u.LowPart += sizeof(BYTE); /* StrLength */
1742 if (this->description.lpstrName!=0)
1743 pcbSize->u.LowPart += lstrlenW(this->description.lpstrName);
1748 /************************************************************************
1749 * OLEFontImpl_IConnectionPointContainer_QueryInterface (IUnknown)
1751 * See Windows documentation for more details on IUnknown methods.
1753 static HRESULT WINAPI OLEFontImpl_IConnectionPointContainer_QueryInterface(
1754 IConnectionPointContainer* iface,
1758 _ICOM_THIS_From_IConnectionPointContainer(OLEFontImpl, iface);
1760 return IFont_QueryInterface((IFont*)this, riid, ppvoid);
1763 /************************************************************************
1764 * OLEFontImpl_IConnectionPointContainer_Release (IUnknown)
1766 * See Windows documentation for more details on IUnknown methods.
1768 static ULONG WINAPI OLEFontImpl_IConnectionPointContainer_Release(
1769 IConnectionPointContainer* iface)
1771 _ICOM_THIS_From_IConnectionPointContainer(OLEFontImpl, iface);
1773 return IFont_Release((IFont*)this);
1776 /************************************************************************
1777 * OLEFontImpl_IConnectionPointContainer_AddRef (IUnknown)
1779 * See Windows documentation for more details on IUnknown methods.
1781 static ULONG WINAPI OLEFontImpl_IConnectionPointContainer_AddRef(
1782 IConnectionPointContainer* iface)
1784 _ICOM_THIS_From_IConnectionPointContainer(OLEFontImpl, iface);
1786 return IFont_AddRef((IFont*)this);
1789 /************************************************************************
1790 * OLEFontImpl_EnumConnectionPoints (IConnectionPointContainer)
1792 * See Windows documentation for more details on IConnectionPointContainer
1795 static HRESULT WINAPI OLEFontImpl_EnumConnectionPoints(
1796 IConnectionPointContainer* iface,
1797 IEnumConnectionPoints **ppEnum)
1799 _ICOM_THIS_From_IConnectionPointContainer(OLEFontImpl, iface);
1801 FIXME("(%p)->(%p): stub\n", this, ppEnum);
1805 /************************************************************************
1806 * OLEFontImpl_FindConnectionPoint (IConnectionPointContainer)
1808 * See Windows documentation for more details on IConnectionPointContainer
1811 static HRESULT WINAPI OLEFontImpl_FindConnectionPoint(
1812 IConnectionPointContainer* iface,
1814 IConnectionPoint **ppCp)
1816 _ICOM_THIS_From_IConnectionPointContainer(OLEFontImpl, iface);
1817 TRACE("(%p)->(%s, %p): stub\n", this, debugstr_guid(riid), ppCp);
1819 if(memcmp(riid, &IID_IPropertyNotifySink, sizeof(IID_IPropertyNotifySink)) == 0) {
1820 return IConnectionPoint_QueryInterface(this->pCP, &IID_IConnectionPoint,
1823 FIXME("Tried to find connection point on %s\n", debugstr_guid(riid));
1824 return E_NOINTERFACE;
1828 /************************************************************************
1829 * OLEFontImpl implementation of IPersistPropertyBag.
1831 static HRESULT WINAPI OLEFontImpl_IPersistPropertyBag_QueryInterface(
1832 IPersistPropertyBag *iface, REFIID riid, LPVOID *ppvObj
1834 _ICOM_THIS_From_IPersistPropertyBag(IFont, iface);
1835 return IFont_QueryInterface(this,riid,ppvObj);
1838 static ULONG WINAPI OLEFontImpl_IPersistPropertyBag_AddRef(
1839 IPersistPropertyBag *iface
1841 _ICOM_THIS_From_IPersistPropertyBag(IFont, iface);
1842 return IFont_AddRef(this);
1845 static ULONG WINAPI OLEFontImpl_IPersistPropertyBag_Release(
1846 IPersistPropertyBag *iface
1848 _ICOM_THIS_From_IPersistPropertyBag(IFont, iface);
1849 return IFont_Release(this);
1852 static HRESULT WINAPI OLEFontImpl_IPersistPropertyBag_GetClassID(
1853 IPersistPropertyBag *iface, CLSID *classid
1855 FIXME("(%p,%p), stub!\n", iface, classid);
1859 static HRESULT WINAPI OLEFontImpl_IPersistPropertyBag_InitNew(
1860 IPersistPropertyBag *iface
1862 FIXME("(%p), stub!\n", iface);
1866 static HRESULT WINAPI OLEFontImpl_IPersistPropertyBag_Load(
1867 IPersistPropertyBag *iface, IPropertyBag* pPropBag, IErrorLog* pErrorLog
1869 /* (from Visual Basic 6 property bag)
1870 Name = "MS Sans Serif"
1874 Underline = 0 'False
1876 Strikethrough = 0 'False
1878 static const WCHAR sAttrName[] = {'N','a','m','e',0};
1879 static const WCHAR sAttrSize[] = {'S','i','z','e',0};
1880 static const WCHAR sAttrCharset[] = {'C','h','a','r','s','e','t',0};
1881 static const WCHAR sAttrWeight[] = {'W','e','i','g','h','t',0};
1882 static const WCHAR sAttrUnderline[] = {'U','n','d','e','r','l','i','n','e',0};
1883 static const WCHAR sAttrItalic[] = {'I','t','a','l','i','c',0};
1884 static const WCHAR sAttrStrikethrough[] = {'S','t','r','i','k','e','t','h','r','o','u','g','h',0};
1887 HRESULT iRes = S_OK;
1888 _ICOM_THIS_From_IPersistPropertyBag(IFont, iface);
1890 VariantInit(&rawAttr);
1891 VariantInit(&valueAttr);
1894 iRes = IPropertyBag_Read(pPropBag, sAttrName, &rawAttr, pErrorLog);
1897 iRes = VariantChangeType(&rawAttr, &valueAttr, 0, VT_BSTR);
1899 iRes = IFont_put_Name(this, V_BSTR(&valueAttr));
1901 else if (iRes == E_INVALIDARG)
1903 VariantClear(&rawAttr);
1904 VariantClear(&valueAttr);
1908 iRes = IPropertyBag_Read(pPropBag, sAttrSize, &rawAttr, pErrorLog);
1911 iRes = VariantChangeType(&rawAttr, &valueAttr, 0, VT_CY);
1913 iRes = IFont_put_Size(this, V_CY(&valueAttr));
1915 else if (iRes == E_INVALIDARG)
1917 VariantClear(&rawAttr);
1918 VariantClear(&valueAttr);
1922 iRes = IPropertyBag_Read(pPropBag, sAttrCharset, &rawAttr, pErrorLog);
1925 iRes = VariantChangeType(&rawAttr, &valueAttr, 0, VT_I2);
1927 iRes = IFont_put_Charset(this, V_I2(&valueAttr));
1929 else if (iRes == E_INVALIDARG)
1931 VariantClear(&rawAttr);
1932 VariantClear(&valueAttr);
1936 iRes = IPropertyBag_Read(pPropBag, sAttrWeight, &rawAttr, pErrorLog);
1939 iRes = VariantChangeType(&rawAttr, &valueAttr, 0, VT_I2);
1941 iRes = IFont_put_Weight(this, V_I2(&valueAttr));
1943 else if (iRes == E_INVALIDARG)
1945 VariantClear(&rawAttr);
1946 VariantClear(&valueAttr);
1951 iRes = IPropertyBag_Read(pPropBag, sAttrUnderline, &rawAttr, pErrorLog);
1954 iRes = VariantChangeType(&rawAttr, &valueAttr, 0, VT_BOOL);
1956 iRes = IFont_put_Underline(this, V_BOOL(&valueAttr));
1958 else if (iRes == E_INVALIDARG)
1960 VariantClear(&rawAttr);
1961 VariantClear(&valueAttr);
1965 iRes = IPropertyBag_Read(pPropBag, sAttrItalic, &rawAttr, pErrorLog);
1968 iRes = VariantChangeType(&rawAttr, &valueAttr, 0, VT_BOOL);
1970 iRes = IFont_put_Italic(this, V_BOOL(&valueAttr));
1972 else if (iRes == E_INVALIDARG)
1974 VariantClear(&rawAttr);
1975 VariantClear(&valueAttr);
1979 iRes = IPropertyBag_Read(pPropBag, sAttrStrikethrough, &rawAttr, pErrorLog);
1982 iRes = VariantChangeType(&rawAttr, &valueAttr, 0, VT_BOOL);
1984 IFont_put_Strikethrough(this, V_BOOL(&valueAttr));
1986 else if (iRes == E_INVALIDARG)
1988 VariantClear(&rawAttr);
1989 VariantClear(&valueAttr);
1993 WARN("-- 0x%08lx\n", iRes);
1997 static HRESULT WINAPI OLEFontImpl_IPersistPropertyBag_Save(
1998 IPersistPropertyBag *iface, IPropertyBag* pPropBag, BOOL fClearDirty,
1999 BOOL fSaveAllProperties
2001 FIXME("(%p,%p,%d,%d), stub!\n", iface, pPropBag, fClearDirty, fSaveAllProperties);
2005 static IPersistPropertyBagVtbl OLEFontImpl_IPersistPropertyBag_VTable =
2007 OLEFontImpl_IPersistPropertyBag_QueryInterface,
2008 OLEFontImpl_IPersistPropertyBag_AddRef,
2009 OLEFontImpl_IPersistPropertyBag_Release,
2011 OLEFontImpl_IPersistPropertyBag_GetClassID,
2012 OLEFontImpl_IPersistPropertyBag_InitNew,
2013 OLEFontImpl_IPersistPropertyBag_Load,
2014 OLEFontImpl_IPersistPropertyBag_Save
2017 /************************************************************************
2018 * OLEFontImpl implementation of IPersistStreamInit.
2020 static HRESULT WINAPI OLEFontImpl_IPersistStreamInit_QueryInterface(
2021 IPersistStreamInit *iface, REFIID riid, LPVOID *ppvObj
2023 _ICOM_THIS_From_IPersistStreamInit(IFont, iface);
2024 return IFont_QueryInterface(this,riid,ppvObj);
2027 static ULONG WINAPI OLEFontImpl_IPersistStreamInit_AddRef(
2028 IPersistStreamInit *iface
2030 _ICOM_THIS_From_IPersistStreamInit(IFont, iface);
2031 return IFont_AddRef(this);
2034 static ULONG WINAPI OLEFontImpl_IPersistStreamInit_Release(
2035 IPersistStreamInit *iface
2037 _ICOM_THIS_From_IPersistStreamInit(IFont, iface);
2038 return IFont_Release(this);
2041 static HRESULT WINAPI OLEFontImpl_IPersistStreamInit_GetClassID(
2042 IPersistStreamInit *iface, CLSID *classid
2044 FIXME("(%p,%p), stub!\n", iface, classid);
2048 static HRESULT WINAPI OLEFontImpl_IPersistStreamInit_IsDirty(
2049 IPersistStreamInit *iface
2051 FIXME("(%p), stub!\n", iface);
2055 static HRESULT WINAPI OLEFontImpl_IPersistStreamInit_Load(
2056 IPersistStreamInit *iface, LPSTREAM pStm
2058 FIXME("(%p,%p), stub!\n", iface, pStm);
2062 static HRESULT WINAPI OLEFontImpl_IPersistStreamInit_Save(
2063 IPersistStreamInit *iface, LPSTREAM pStm, BOOL fClearDirty
2065 FIXME("(%p,%p,%d), stub!\n", iface, pStm, fClearDirty);
2069 static HRESULT WINAPI OLEFontImpl_IPersistStreamInit_GetSizeMax(
2070 IPersistStreamInit *iface, ULARGE_INTEGER *pcbSize
2072 FIXME("(%p,%p), stub!\n", iface, pcbSize);
2076 static HRESULT WINAPI OLEFontImpl_IPersistStreamInit_InitNew(
2077 IPersistStreamInit *iface
2079 FIXME("(%p), stub!\n", iface);
2083 static IPersistStreamInitVtbl OLEFontImpl_IPersistStreamInit_VTable =
2085 OLEFontImpl_IPersistStreamInit_QueryInterface,
2086 OLEFontImpl_IPersistStreamInit_AddRef,
2087 OLEFontImpl_IPersistStreamInit_Release,
2089 OLEFontImpl_IPersistStreamInit_GetClassID,
2090 OLEFontImpl_IPersistStreamInit_IsDirty,
2091 OLEFontImpl_IPersistStreamInit_Load,
2092 OLEFontImpl_IPersistStreamInit_Save,
2093 OLEFontImpl_IPersistStreamInit_GetSizeMax,
2094 OLEFontImpl_IPersistStreamInit_InitNew
2097 /*******************************************************************************
2098 * StdFont ClassFactory
2102 /* IUnknown fields */
2103 IClassFactoryVtbl *lpVtbl;
2105 } IClassFactoryImpl;
2107 static HRESULT WINAPI
2108 SFCF_QueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj) {
2109 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
2111 FIXME("(%p)->(%s,%p),stub!\n",This,debugstr_guid(riid),ppobj);
2112 return E_NOINTERFACE;
2116 SFCF_AddRef(LPCLASSFACTORY iface) {
2117 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
2118 return InterlockedIncrement(&This->ref);
2121 static ULONG WINAPI SFCF_Release(LPCLASSFACTORY iface) {
2122 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
2123 /* static class, won't be freed */
2124 return InterlockedDecrement(&This->ref);
2127 static HRESULT WINAPI SFCF_CreateInstance(
2128 LPCLASSFACTORY iface,LPUNKNOWN pOuter,REFIID riid,LPVOID *ppobj
2130 return OleCreateFontIndirect(NULL,riid,ppobj);
2134 static HRESULT WINAPI SFCF_LockServer(LPCLASSFACTORY iface,BOOL dolock) {
2135 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
2136 FIXME("(%p)->(%d),stub!\n",This,dolock);
2140 static IClassFactoryVtbl SFCF_Vtbl = {
2141 SFCF_QueryInterface,
2144 SFCF_CreateInstance,
2147 static IClassFactoryImpl STDFONT_CF = {&SFCF_Vtbl, 1 };
2149 void _get_STDFONT_CF(LPVOID *ppv) { *ppv = (LPVOID)&STDFONT_CF; }