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.
66 const IFontVtbl* lpvtbl1;
67 const IDispatchVtbl* lpvtbl2;
68 const IPersistStreamVtbl* lpvtbl3;
69 const IConnectionPointContainerVtbl* lpvtbl4;
70 const IPersistPropertyBagVtbl* lpvtbl5;
71 const 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 const 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 const 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 const IPersistStreamVtbl OLEFontImpl_IPersistStream_VTable =
266 OLEFontImpl_IPersistStream_QueryInterface,
267 OLEFontImpl_IPersistStream_AddRef,
268 OLEFontImpl_IPersistStream_Release,
269 OLEFontImpl_GetClassID,
273 OLEFontImpl_GetSizeMax
276 static const 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 const IPersistPropertyBagVtbl OLEFontImpl_IPersistPropertyBag_VTable;
287 static const 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 HeapFree(GetProcessHeap(), 0, fontDesc->description.lpstrName);
460 if (fontDesc->gdiFont!=0)
461 DeleteObject(fontDesc->gdiFont);
463 HeapFree(GetProcessHeap(), 0, fontDesc);
466 /************************************************************************
467 * OLEFontImpl_QueryInterface (IUnknown)
469 * See Windows documentation for more details on IUnknown methods.
471 HRESULT WINAPI OLEFontImpl_QueryInterface(
476 OLEFontImpl *this = (OLEFontImpl *)iface;
477 TRACE("(%p)->(%s, %p)\n", this, debugstr_guid(riid), ppvObject);
480 * Perform a sanity check on the parameters.
482 if ( (this==0) || (ppvObject==0) )
486 * Initialize the return parameter.
491 * Compare the riid with the interface IDs implemented by this object.
493 if (IsEqualGUID(&IID_IUnknown, riid))
494 *ppvObject = (IFont*)this;
495 if (IsEqualGUID(&IID_IFont, riid))
496 *ppvObject = (IFont*)this;
497 if (IsEqualGUID(&IID_IDispatch, riid))
498 *ppvObject = (IDispatch*)&(this->lpvtbl2);
499 if (IsEqualGUID(&IID_IFontDisp, riid))
500 *ppvObject = (IDispatch*)&(this->lpvtbl2);
501 if (IsEqualGUID(&IID_IPersistStream, riid))
502 *ppvObject = (IPersistStream*)&(this->lpvtbl3);
503 if (IsEqualGUID(&IID_IConnectionPointContainer, riid))
504 *ppvObject = (IConnectionPointContainer*)&(this->lpvtbl4);
505 if (IsEqualGUID(&IID_IPersistPropertyBag, riid))
506 *ppvObject = (IPersistPropertyBag*)&(this->lpvtbl5);
507 if (IsEqualGUID(&IID_IPersistStreamInit, riid))
508 *ppvObject = (IPersistStreamInit*)&(this->lpvtbl6);
511 * Check that we obtained an interface.
515 FIXME("() : asking for unsupported interface %s\n",debugstr_guid(riid));
516 return E_NOINTERFACE;
518 OLEFontImpl_AddRef((IFont*)this);
522 /************************************************************************
523 * OLEFontImpl_AddRef (IUnknown)
525 * See Windows documentation for more details on IUnknown methods.
527 ULONG WINAPI OLEFontImpl_AddRef(
530 OLEFontImpl *this = (OLEFontImpl *)iface;
531 TRACE("(%p)->(ref=%ld)\n", this, this->ref);
532 return InterlockedIncrement(&this->ref);
535 /************************************************************************
536 * OLEFontImpl_Release (IUnknown)
538 * See Windows documentation for more details on IUnknown methods.
540 ULONG WINAPI OLEFontImpl_Release(
543 OLEFontImpl *this = (OLEFontImpl *)iface;
545 TRACE("(%p)->(ref=%ld)\n", this, this->ref);
548 * Decrease the reference count on this object.
550 ret = InterlockedDecrement(&this->ref);
553 * If the reference count goes down to 0, perform suicide.
555 if (ret==0) OLEFontImpl_Destroy(this);
560 /************************************************************************
561 * OLEFontImpl_get_Name (IFont)
563 * See Windows documentation for more details on IFont methods.
565 static HRESULT WINAPI OLEFontImpl_get_Name(
569 OLEFontImpl *this = (OLEFontImpl *)iface;
570 TRACE("(%p)->(%p)\n", this, pname);
577 if (this->description.lpstrName!=0)
578 *pname = SysAllocString(this->description.lpstrName);
585 /************************************************************************
586 * OLEFontImpl_put_Name (IFont)
588 * See Windows documentation for more details on IFont methods.
590 static HRESULT WINAPI OLEFontImpl_put_Name(
594 OLEFontImpl *this = (OLEFontImpl *)iface;
595 TRACE("(%p)->(%p)\n", this, name);
597 if (this->description.lpstrName==0)
599 this->description.lpstrName = HeapAlloc(GetProcessHeap(),
601 (lstrlenW(name)+1) * sizeof(WCHAR));
605 this->description.lpstrName = HeapReAlloc(GetProcessHeap(),
607 this->description.lpstrName,
608 (lstrlenW(name)+1) * sizeof(WCHAR));
611 if (this->description.lpstrName==0)
612 return E_OUTOFMEMORY;
614 strcpyW(this->description.lpstrName, name);
615 TRACE("new name %s\n", debugstr_w(this->description.lpstrName));
616 OLEFont_SendNotify(this, DISPID_FONT_NAME);
620 /************************************************************************
621 * OLEFontImpl_get_Size (IFont)
623 * See Windows documentation for more details on IFont methods.
625 static HRESULT WINAPI OLEFontImpl_get_Size(
629 OLEFontImpl *this = (OLEFontImpl *)iface;
630 TRACE("(%p)->(%p)\n", this, psize);
639 psize->s.Lo = this->description.cySize.s.Lo;
644 /************************************************************************
645 * OLEFontImpl_put_Size (IFont)
647 * See Windows documentation for more details on IFont methods.
649 static HRESULT WINAPI OLEFontImpl_put_Size(
653 OLEFontImpl *this = (OLEFontImpl *)iface;
654 TRACE("(%p)->(%ld)\n", this, size.s.Lo);
655 this->description.cySize.s.Hi = 0;
656 this->description.cySize.s.Lo = size.s.Lo;
657 OLEFont_SendNotify(this, DISPID_FONT_SIZE);
662 /************************************************************************
663 * OLEFontImpl_get_Bold (IFont)
665 * See Windows documentation for more details on IFont methods.
667 static HRESULT WINAPI OLEFontImpl_get_Bold(
671 OLEFontImpl *this = (OLEFontImpl *)iface;
672 TRACE("(%p)->(%p)\n", this, pbold);
679 *pbold = this->description.sWeight > 550;
684 /************************************************************************
685 * OLEFontImpl_put_Bold (IFont)
687 * See Windows documentation for more details on IFont methods.
689 static HRESULT WINAPI OLEFontImpl_put_Bold(
693 OLEFontImpl *this = (OLEFontImpl *)iface;
694 TRACE("(%p)->(%d)\n", this, bold);
695 this->description.sWeight = bold ? FW_BOLD : FW_NORMAL;
696 OLEFont_SendNotify(this, DISPID_FONT_BOLD);
701 /************************************************************************
702 * OLEFontImpl_get_Italic (IFont)
704 * See Windows documentation for more details on IFont methods.
706 static HRESULT WINAPI OLEFontImpl_get_Italic(
710 OLEFontImpl *this = (OLEFontImpl *)iface;
711 TRACE("(%p)->(%p)\n", this, pitalic);
718 *pitalic = this->description.fItalic;
723 /************************************************************************
724 * OLEFontImpl_put_Italic (IFont)
726 * See Windows documentation for more details on IFont methods.
728 static HRESULT WINAPI OLEFontImpl_put_Italic(
732 OLEFontImpl *this = (OLEFontImpl *)iface;
733 TRACE("(%p)->(%d)\n", this, italic);
735 this->description.fItalic = italic;
737 OLEFont_SendNotify(this, DISPID_FONT_ITALIC);
741 /************************************************************************
742 * OLEFontImpl_get_Underline (IFont)
744 * See Windows documentation for more details on IFont methods.
746 static HRESULT WINAPI OLEFontImpl_get_Underline(
750 OLEFontImpl *this = (OLEFontImpl *)iface;
751 TRACE("(%p)->(%p)\n", this, punderline);
759 *punderline = this->description.fUnderline;
764 /************************************************************************
765 * OLEFontImpl_put_Underline (IFont)
767 * See Windows documentation for more details on IFont methods.
769 static HRESULT WINAPI OLEFontImpl_put_Underline(
773 OLEFontImpl *this = (OLEFontImpl *)iface;
774 TRACE("(%p)->(%d)\n", this, underline);
776 this->description.fUnderline = underline;
778 OLEFont_SendNotify(this, DISPID_FONT_UNDER);
782 /************************************************************************
783 * OLEFontImpl_get_Strikethrough (IFont)
785 * See Windows documentation for more details on IFont methods.
787 static HRESULT WINAPI OLEFontImpl_get_Strikethrough(
789 BOOL* pstrikethrough)
791 OLEFontImpl *this = (OLEFontImpl *)iface;
792 TRACE("(%p)->(%p)\n", this, pstrikethrough);
797 if (pstrikethrough==0)
800 *pstrikethrough = this->description.fStrikethrough;
805 /************************************************************************
806 * OLEFontImpl_put_Strikethrough (IFont)
808 * See Windows documentation for more details on IFont methods.
810 static HRESULT WINAPI OLEFontImpl_put_Strikethrough(
814 OLEFontImpl *this = (OLEFontImpl *)iface;
815 TRACE("(%p)->(%d)\n", this, strikethrough);
817 this->description.fStrikethrough = strikethrough;
818 OLEFont_SendNotify(this, DISPID_FONT_STRIKE);
823 /************************************************************************
824 * OLEFontImpl_get_Weight (IFont)
826 * See Windows documentation for more details on IFont methods.
828 static HRESULT WINAPI OLEFontImpl_get_Weight(
832 OLEFontImpl *this = (OLEFontImpl *)iface;
833 TRACE("(%p)->(%p)\n", this, pweight);
841 *pweight = this->description.sWeight;
846 /************************************************************************
847 * OLEFontImpl_put_Weight (IFont)
849 * See Windows documentation for more details on IFont methods.
851 static HRESULT WINAPI OLEFontImpl_put_Weight(
855 OLEFontImpl *this = (OLEFontImpl *)iface;
856 TRACE("(%p)->(%d)\n", this, weight);
858 this->description.sWeight = weight;
860 OLEFont_SendNotify(this, DISPID_FONT_WEIGHT);
864 /************************************************************************
865 * OLEFontImpl_get_Charset (IFont)
867 * See Windows documentation for more details on IFont methods.
869 static HRESULT WINAPI OLEFontImpl_get_Charset(
873 OLEFontImpl *this = (OLEFontImpl *)iface;
874 TRACE("(%p)->(%p)\n", this, pcharset);
882 *pcharset = this->description.sCharset;
887 /************************************************************************
888 * OLEFontImpl_put_Charset (IFont)
890 * See Windows documentation for more details on IFont methods.
892 static HRESULT WINAPI OLEFontImpl_put_Charset(
896 OLEFontImpl *this = (OLEFontImpl *)iface;
897 TRACE("(%p)->(%d)\n", this, charset);
899 this->description.sCharset = charset;
900 OLEFont_SendNotify(this, DISPID_FONT_CHARSET);
905 /************************************************************************
906 * OLEFontImpl_get_hFont (IFont)
908 * See Windows documentation for more details on IFont methods.
910 static HRESULT WINAPI OLEFontImpl_get_hFont(
914 OLEFontImpl *this = (OLEFontImpl *)iface;
915 TRACE("(%p)->(%p)\n", this, phfont);
920 * Realize the font if necessary
922 if (this->gdiFont==0)
929 * The height of the font returned by the get_Size property is the
930 * height of the font in points multiplied by 10000... Using some
931 * simple conversions and the ratio given by the application, it can
932 * be converted to a height in pixels.
934 IFont_get_Size(iface, &cySize);
936 fontHeight = MulDiv( cySize.s.Lo, this->cyLogical, this->cyHimetric );
938 memset(&logFont, 0, sizeof(LOGFONTW));
940 logFont.lfHeight = ((fontHeight%10000L)>5000L) ? (-fontHeight/10000L)-1 :
941 (-fontHeight/10000L);
942 logFont.lfItalic = this->description.fItalic;
943 logFont.lfUnderline = this->description.fUnderline;
944 logFont.lfStrikeOut = this->description.fStrikethrough;
945 logFont.lfWeight = this->description.sWeight;
946 logFont.lfCharSet = this->description.sCharset;
947 logFont.lfOutPrecision = OUT_CHARACTER_PRECIS;
948 logFont.lfClipPrecision = CLIP_DEFAULT_PRECIS;
949 logFont.lfQuality = DEFAULT_QUALITY;
950 logFont.lfPitchAndFamily = DEFAULT_PITCH;
951 strcpyW(logFont.lfFaceName,this->description.lpstrName);
953 this->gdiFont = CreateFontIndirectW(&logFont);
956 *phfont = this->gdiFont;
957 TRACE("Returning %p\n", *phfont);
961 /************************************************************************
962 * OLEFontImpl_Clone (IFont)
964 * See Windows documentation for more details on IFont methods.
966 static HRESULT WINAPI OLEFontImpl_Clone(
970 OLEFontImpl* newObject = 0;
974 OLEFontImpl *this = (OLEFontImpl *)iface;
975 TRACE("(%p)->(%p)\n", this, ppfont);
983 * Allocate space for the object.
985 newObject = HeapAlloc(GetProcessHeap(), 0, sizeof(OLEFontImpl));
988 return E_OUTOFMEMORY;
992 /* We need to alloc new memory for the string, otherwise
993 * we free memory twice.
995 newObject->description.lpstrName = HeapAlloc(
997 (1+strlenW(this->description.lpstrName))*2
999 strcpyW(newObject->description.lpstrName, this->description.lpstrName);
1000 /* We need to clone the HFONT too. This is just cut & paste from above */
1001 IFont_get_Size(iface, &cySize);
1003 fontHeight = MulDiv(cySize.s.Lo, this->cyLogical,this->cyHimetric);
1005 memset(&logFont, 0, sizeof(LOGFONTW));
1007 logFont.lfHeight = ((fontHeight%10000L)>5000L) ? (-fontHeight/10000L)-1 :
1008 (-fontHeight/10000L);
1009 logFont.lfItalic = this->description.fItalic;
1010 logFont.lfUnderline = this->description.fUnderline;
1011 logFont.lfStrikeOut = this->description.fStrikethrough;
1012 logFont.lfWeight = this->description.sWeight;
1013 logFont.lfCharSet = this->description.sCharset;
1014 logFont.lfOutPrecision = OUT_CHARACTER_PRECIS;
1015 logFont.lfClipPrecision = CLIP_DEFAULT_PRECIS;
1016 logFont.lfQuality = DEFAULT_QUALITY;
1017 logFont.lfPitchAndFamily = DEFAULT_PITCH;
1018 strcpyW(logFont.lfFaceName,this->description.lpstrName);
1020 newObject->gdiFont = CreateFontIndirectW(&logFont);
1023 /* The cloned object starts with a reference count of 1 */
1026 *ppfont = (IFont*)newObject;
1031 /************************************************************************
1032 * OLEFontImpl_IsEqual (IFont)
1034 * See Windows documentation for more details on IFont methods.
1036 static HRESULT WINAPI OLEFontImpl_IsEqual(
1040 FIXME("(%p, %p), stub!\n",iface,pFontOther);
1044 /************************************************************************
1045 * OLEFontImpl_SetRatio (IFont)
1047 * See Windows documentation for more details on IFont methods.
1049 static HRESULT WINAPI OLEFontImpl_SetRatio(
1054 OLEFontImpl *this = (OLEFontImpl *)iface;
1055 TRACE("(%p)->(%ld, %ld)\n", this, cyLogical, cyHimetric);
1057 this->cyLogical = cyLogical;
1058 this->cyHimetric = cyHimetric;
1063 /************************************************************************
1064 * OLEFontImpl_QueryTextMetrics (IFont)
1066 * See Windows documentation for more details on IFont methods.
1068 static HRESULT WINAPI OLEFontImpl_QueryTextMetrics(
1073 HFONT hOldFont, hNewFont;
1076 OLEFontImpl_get_hFont(iface, &hNewFont);
1077 hOldFont = SelectObject(hdcRef, hNewFont);
1078 GetTextMetricsW(hdcRef, ptm);
1079 SelectObject(hdcRef, hOldFont);
1080 ReleaseDC(0, hdcRef);
1084 /************************************************************************
1085 * OLEFontImpl_AddRefHfont (IFont)
1087 * See Windows documentation for more details on IFont methods.
1089 static HRESULT WINAPI OLEFontImpl_AddRefHfont(
1093 OLEFontImpl *this = (OLEFontImpl *)iface;
1094 TRACE("(%p)->(%p) (lock=%ld)\n", this, hfont, this->fontLock);
1096 if ( (hfont == 0) ||
1097 (hfont != this->gdiFont) )
1098 return E_INVALIDARG;
1105 /************************************************************************
1106 * OLEFontImpl_ReleaseHfont (IFont)
1108 * See Windows documentation for more details on IFont methods.
1110 static HRESULT WINAPI OLEFontImpl_ReleaseHfont(
1114 OLEFontImpl *this = (OLEFontImpl *)iface;
1115 TRACE("(%p)->(%p) (lock=%ld)\n", this, hfont, this->fontLock);
1117 if ( (hfont == 0) ||
1118 (hfont != this->gdiFont) )
1119 return E_INVALIDARG;
1124 * If we just released our last font reference, destroy it.
1126 if (this->fontLock==0)
1128 DeleteObject(this->gdiFont);
1135 /************************************************************************
1136 * OLEFontImpl_SetHdc (IFont)
1138 * See Windows documentation for more details on IFont methods.
1140 static HRESULT WINAPI OLEFontImpl_SetHdc(
1144 OLEFontImpl *this = (OLEFontImpl *)iface;
1145 FIXME("(%p)->(%p): Stub\n", this, hdc);
1149 /************************************************************************
1150 * OLEFontImpl_IDispatch_QueryInterface (IUnknown)
1152 * See Windows documentation for more details on IUnknown methods.
1154 static HRESULT WINAPI OLEFontImpl_IDispatch_QueryInterface(
1159 _ICOM_THIS_From_IDispatch(IFont, iface);
1161 return IFont_QueryInterface(this, riid, ppvoid);
1164 /************************************************************************
1165 * OLEFontImpl_IDispatch_Release (IUnknown)
1167 * See Windows documentation for more details on IUnknown methods.
1169 static ULONG WINAPI OLEFontImpl_IDispatch_Release(
1172 _ICOM_THIS_From_IDispatch(IFont, iface);
1174 return IFont_Release(this);
1177 /************************************************************************
1178 * OLEFontImpl_IDispatch_AddRef (IUnknown)
1180 * See Windows documentation for more details on IUnknown methods.
1182 static ULONG WINAPI OLEFontImpl_IDispatch_AddRef(
1185 _ICOM_THIS_From_IDispatch(IFont, iface);
1187 return IFont_AddRef(this);
1190 /************************************************************************
1191 * OLEFontImpl_GetTypeInfoCount (IDispatch)
1193 * See Windows documentation for more details on IDispatch methods.
1195 static HRESULT WINAPI OLEFontImpl_GetTypeInfoCount(
1197 unsigned int* pctinfo)
1199 _ICOM_THIS_From_IDispatch(IFont, iface);
1200 FIXME("(%p)->(%p): Stub\n", this, pctinfo);
1205 /************************************************************************
1206 * OLEFontImpl_GetTypeInfo (IDispatch)
1208 * See Windows documentation for more details on IDispatch methods.
1210 static HRESULT WINAPI OLEFontImpl_GetTypeInfo(
1214 ITypeInfo** ppTInfo)
1216 static const WCHAR stdole32tlb[] = {'s','t','d','o','l','e','3','2','.','t','l','b',0};
1220 _ICOM_THIS_From_IDispatch(OLEFontImpl, iface);
1221 TRACE("(%p, iTInfo=%d, lcid=%04x, %p)\n", this, iTInfo, (int)lcid, ppTInfo);
1224 hres = LoadTypeLib(stdole32tlb, &tl);
1226 ERR("Could not load the stdole32.tlb?\n");
1229 hres = ITypeLib_GetTypeInfoOfGuid(tl, &IID_IDispatch, ppTInfo);
1231 FIXME("Did not IDispatch typeinfo from typelib, hres %lx\n",hres);
1236 /************************************************************************
1237 * OLEFontImpl_GetIDsOfNames (IDispatch)
1239 * See Windows documentation for more details on IDispatch methods.
1241 static HRESULT WINAPI OLEFontImpl_GetIDsOfNames(
1244 LPOLESTR* rgszNames,
1249 _ICOM_THIS_From_IDispatch(IFont, iface);
1250 FIXME("(%p,%s,%p,%d,%04x,%p), stub!\n", this, debugstr_guid(riid), rgszNames,
1251 cNames, (int)lcid, rgDispId
1256 /************************************************************************
1257 * OLEFontImpl_Invoke (IDispatch)
1259 * See Windows documentation for more details on IDispatch methods.
1261 * Note: Do not call _put_Xxx methods, since setting things here
1262 * should not call notify functions as I found out debugging the generic
1265 static HRESULT WINAPI OLEFontImpl_Invoke(
1267 DISPID dispIdMember,
1271 DISPPARAMS* pDispParams,
1272 VARIANT* pVarResult,
1273 EXCEPINFO* pExepInfo,
1276 _ICOM_THIS_From_IDispatch(IFont, iface);
1277 OLEFontImpl *xthis = (OLEFontImpl*)this;
1279 switch (dispIdMember) {
1280 case DISPID_FONT_NAME:
1282 case DISPATCH_PROPERTYGET:
1283 case DISPATCH_PROPERTYGET|DISPATCH_METHOD:
1284 V_VT(pVarResult) = VT_BSTR;
1285 return OLEFontImpl_get_Name(this, &V_BSTR(pVarResult));
1286 case DISPATCH_PROPERTYPUT: {
1290 if (V_VT(&pDispParams->rgvarg[0]) == VT_DISPATCH) {
1294 hr = IUnknown_QueryInterface(V_DISPATCH(&pDispParams->rgvarg[0]), &IID_IFont, (void **) &font);
1297 FIXME("dispatch value for name property is not an OleFont, returning hr=0x%lx\n", hr);
1301 hr = IFont_get_Name(font, &name); /* this allocates a new BSTR so free it later */
1302 if (FAILED(hr)) return hr;
1304 IUnknown_Release(font);
1307 } else if (V_VT(&pDispParams->rgvarg[0]) == VT_BSTR) {
1308 name = V_BSTR(&pDispParams->rgvarg[0]);
1311 FIXME("app is trying to set name property with a non BSTR, non dispatch value. returning E_FAIL\n");
1315 TRACE("name is %s\n", debugstr_w(name));
1317 if (!xthis->description.lpstrName)
1318 xthis->description.lpstrName = HeapAlloc(GetProcessHeap(), 0, (lstrlenW(name)+1) * sizeof(WCHAR));
1320 xthis->description.lpstrName = HeapReAlloc(GetProcessHeap(), 0, xthis->description.lpstrName, (lstrlenW(name)+1) * sizeof(WCHAR));
1322 if (xthis->description.lpstrName==0)
1323 return E_OUTOFMEMORY;
1324 strcpyW(xthis->description.lpstrName, name);
1326 if (freename) SysFreeString(name);
1332 case DISPID_FONT_BOLD:
1334 case DISPATCH_PROPERTYGET:
1335 case DISPATCH_PROPERTYGET|DISPATCH_METHOD:
1336 V_VT(pVarResult) = VT_BOOL;
1337 return OLEFontImpl_get_Bold(this, (BOOL*)&V_BOOL(pVarResult));
1338 case DISPATCH_PROPERTYPUT:
1339 if (V_VT(&pDispParams->rgvarg[0]) != VT_BOOL) {
1340 FIXME("DISPID_FONT_BOLD/put, vt is %d, not VT_BOOL.\n",V_VT(&pDispParams->rgvarg[0]));
1343 xthis->description.sWeight = V_BOOL(&pDispParams->rgvarg[0]) ? FW_BOLD : FW_NORMAL;
1348 case DISPID_FONT_ITALIC:
1350 case DISPATCH_PROPERTYGET:
1351 case DISPATCH_PROPERTYGET|DISPATCH_METHOD:
1352 V_VT(pVarResult) = VT_BOOL;
1353 return OLEFontImpl_get_Italic(this, (BOOL*)&V_BOOL(pVarResult));
1354 case DISPATCH_PROPERTYPUT:
1355 if (V_VT(&pDispParams->rgvarg[0]) != VT_BOOL) {
1356 FIXME("DISPID_FONT_ITALIC/put, vt is %d, not VT_BOOL.\n",V_VT(&pDispParams->rgvarg[0]));
1359 xthis->description.fItalic = V_BOOL(&pDispParams->rgvarg[0]);
1364 case DISPID_FONT_UNDER:
1366 case DISPATCH_PROPERTYGET:
1367 case DISPATCH_PROPERTYGET|DISPATCH_METHOD:
1368 V_VT(pVarResult) = VT_BOOL;
1369 return OLEFontImpl_get_Underline(this, (BOOL*)&V_BOOL(pVarResult));
1370 case DISPATCH_PROPERTYPUT:
1371 if (V_VT(&pDispParams->rgvarg[0]) != VT_BOOL) {
1372 FIXME("DISPID_FONT_UNDER/put, vt is %d, not VT_BOOL.\n",V_VT(&pDispParams->rgvarg[0]));
1375 xthis->description.fUnderline = V_BOOL(&pDispParams->rgvarg[0]);
1380 case DISPID_FONT_STRIKE:
1382 case DISPATCH_PROPERTYGET:
1383 case DISPATCH_PROPERTYGET|DISPATCH_METHOD:
1384 V_VT(pVarResult) = VT_BOOL;
1385 return OLEFontImpl_get_Strikethrough(this, (BOOL*)&V_BOOL(pVarResult));
1386 case DISPATCH_PROPERTYPUT:
1387 if (V_VT(&pDispParams->rgvarg[0]) != VT_BOOL) {
1388 FIXME("DISPID_FONT_STRIKE/put, vt is %d, not VT_BOOL.\n",V_VT(&pDispParams->rgvarg[0]));
1391 xthis->description.fStrikethrough = V_BOOL(&pDispParams->rgvarg[0]);
1396 case DISPID_FONT_SIZE:
1398 case DISPATCH_PROPERTYPUT: {
1399 assert (pDispParams->cArgs == 1);
1400 xthis->description.cySize.s.Hi = 0;
1401 if (V_VT(&pDispParams->rgvarg[0]) != VT_CY) {
1402 if (V_VT(&pDispParams->rgvarg[0]) == VT_I2) {
1403 xthis->description.cySize.s.Lo = V_I2(&pDispParams->rgvarg[0]) * 10000;
1405 FIXME("property put for Size with vt %d unsupported!\n",V_VT(&pDispParams->rgvarg[0]));
1408 xthis->description.cySize.s.Lo = V_CY(&pDispParams->rgvarg[0]).s.Lo;
1412 case DISPATCH_PROPERTYGET:
1413 case DISPATCH_PROPERTYGET|DISPATCH_METHOD:
1414 V_VT(pVarResult) = VT_CY;
1415 return OLEFontImpl_get_Size(this, &V_CY(pVarResult));
1418 case DISPID_FONT_CHARSET:
1420 case DISPATCH_PROPERTYPUT:
1421 assert (pDispParams->cArgs == 1);
1422 if (V_VT(&pDispParams->rgvarg[0]) != VT_I2)
1423 FIXME("varg of first disparg is not VT_I2, but %d\n",V_VT(&pDispParams->rgvarg[0]));
1424 xthis->description.sCharset = V_I2(&pDispParams->rgvarg[0]);
1426 case DISPATCH_PROPERTYGET:
1427 case DISPATCH_PROPERTYGET|DISPATCH_METHOD:
1428 V_VT(pVarResult) = VT_I2;
1429 return OLEFontImpl_get_Charset(this, &V_I2(pVarResult));
1433 FIXME("%p->(%ld,%s,%lx,%x,%p,%p,%p,%p), unhandled dispid/flag!\n",
1434 this,dispIdMember,debugstr_guid(riid),lcid,
1435 wFlags,pDispParams,pVarResult,pExepInfo,puArgErr
1440 /************************************************************************
1441 * OLEFontImpl_IPersistStream_QueryInterface (IUnknown)
1443 * See Windows documentation for more details on IUnknown methods.
1445 static HRESULT WINAPI OLEFontImpl_IPersistStream_QueryInterface(
1446 IPersistStream* iface,
1450 _ICOM_THIS_From_IPersistStream(IFont, iface);
1452 return IFont_QueryInterface(this, riid, ppvoid);
1455 /************************************************************************
1456 * OLEFontImpl_IPersistStream_Release (IUnknown)
1458 * See Windows documentation for more details on IUnknown methods.
1460 static ULONG WINAPI OLEFontImpl_IPersistStream_Release(
1461 IPersistStream* iface)
1463 _ICOM_THIS_From_IPersistStream(IFont, iface);
1465 return IFont_Release(this);
1468 /************************************************************************
1469 * OLEFontImpl_IPersistStream_AddRef (IUnknown)
1471 * See Windows documentation for more details on IUnknown methods.
1473 static ULONG WINAPI OLEFontImpl_IPersistStream_AddRef(
1474 IPersistStream* iface)
1476 _ICOM_THIS_From_IPersistStream(IFont, iface);
1478 return IFont_AddRef(this);
1481 /************************************************************************
1482 * OLEFontImpl_GetClassID (IPersistStream)
1484 * See Windows documentation for more details on IPersistStream methods.
1486 static HRESULT WINAPI OLEFontImpl_GetClassID(
1487 IPersistStream* iface,
1490 TRACE("(%p,%p)\n",iface,pClassID);
1494 memcpy(pClassID, &CLSID_StdFont, sizeof(CLSID_StdFont));
1499 /************************************************************************
1500 * OLEFontImpl_IsDirty (IPersistStream)
1502 * See Windows documentation for more details on IPersistStream methods.
1504 static HRESULT WINAPI OLEFontImpl_IsDirty(
1505 IPersistStream* iface)
1507 TRACE("(%p)\n",iface);
1511 /************************************************************************
1512 * OLEFontImpl_Load (IPersistStream)
1514 * See Windows documentation for more details on IPersistStream methods.
1516 * This is the format of the standard font serialization as far as I
1519 * Offset Type Value Comment
1520 * 0x0000 Byte Unknown Probably a version number, contains 0x01
1521 * 0x0001 Short Charset Charset value from the FONTDESC structure
1522 * 0x0003 Byte Attributes Flags defined as follows:
1524 * 00000100 - Underline
1525 * 00001000 - Strikethrough
1526 * 0x0004 Short Weight Weight value from FONTDESC structure
1527 * 0x0006 DWORD size "Low" portion of the cySize member of the FONTDESC
1529 * 0x000A Byte name length Length of the font name string (no null character)
1530 * 0x000B String name Name of the font (ASCII, no nul character)
1532 static HRESULT WINAPI OLEFontImpl_Load(
1533 IPersistStream* iface,
1534 IStream* pLoadStream)
1536 char readBuffer[0x100];
1543 _ICOM_THIS_From_IPersistStream(OLEFontImpl, iface);
1546 * Read the version byte
1548 IStream_Read(pLoadStream, &bVersion, 1, &cbRead);
1557 IStream_Read(pLoadStream, &this->description.sCharset, 2, &cbRead);
1565 IStream_Read(pLoadStream, &bAttributes, 1, &cbRead);
1570 this->description.fItalic = (bAttributes & FONTPERSIST_ITALIC) != 0;
1571 this->description.fStrikethrough = (bAttributes & FONTPERSIST_STRIKETHROUGH) != 0;
1572 this->description.fUnderline = (bAttributes & FONTPERSIST_UNDERLINE) != 0;
1577 IStream_Read(pLoadStream, &this->description.sWeight, 2, &cbRead);
1585 IStream_Read(pLoadStream, &this->description.cySize.s.Lo, 4, &cbRead);
1590 this->description.cySize.s.Hi = 0;
1595 IStream_Read(pLoadStream, &bStringSize, 1, &cbRead);
1600 IStream_Read(pLoadStream, readBuffer, bStringSize, &cbRead);
1602 if (cbRead!=bStringSize)
1605 HeapFree(GetProcessHeap(), 0, this->description.lpstrName);
1607 len = MultiByteToWideChar( CP_ACP, 0, readBuffer, bStringSize, NULL, 0 );
1608 this->description.lpstrName = HeapAlloc( GetProcessHeap(), 0, (len+1) * sizeof(WCHAR) );
1609 MultiByteToWideChar( CP_ACP, 0, readBuffer, bStringSize, this->description.lpstrName, len );
1610 this->description.lpstrName[len] = 0;
1612 /* Ensure use of this font causes a new one to be created @@@@ */
1613 DeleteObject(this->gdiFont);
1619 /************************************************************************
1620 * OLEFontImpl_Save (IPersistStream)
1622 * See Windows documentation for more details on IPersistStream methods.
1624 static HRESULT WINAPI OLEFontImpl_Save(
1625 IPersistStream* iface,
1626 IStream* pOutStream,
1629 char* writeBuffer = NULL;
1631 BYTE bVersion = 0x01;
1635 _ICOM_THIS_From_IPersistStream(OLEFontImpl, iface);
1638 * Read the version byte
1640 IStream_Write(pOutStream, &bVersion, 1, &cbWritten);
1648 IStream_Write(pOutStream, &this->description.sCharset, 2, &cbWritten);
1658 if (this->description.fItalic)
1659 bAttributes |= FONTPERSIST_ITALIC;
1661 if (this->description.fStrikethrough)
1662 bAttributes |= FONTPERSIST_STRIKETHROUGH;
1664 if (this->description.fUnderline)
1665 bAttributes |= FONTPERSIST_UNDERLINE;
1667 IStream_Write(pOutStream, &bAttributes, 1, &cbWritten);
1675 IStream_Write(pOutStream, &this->description.sWeight, 2, &cbWritten);
1683 IStream_Write(pOutStream, &this->description.cySize.s.Lo, 4, &cbWritten);
1691 if (this->description.lpstrName!=0)
1692 bStringSize = WideCharToMultiByte( CP_ACP, 0, this->description.lpstrName,
1693 strlenW(this->description.lpstrName), NULL, 0, NULL, NULL );
1697 IStream_Write(pOutStream, &bStringSize, 1, &cbWritten);
1704 if (!(writeBuffer = HeapAlloc( GetProcessHeap(), 0, bStringSize ))) return E_OUTOFMEMORY;
1705 WideCharToMultiByte( CP_ACP, 0, this->description.lpstrName,
1706 strlenW(this->description.lpstrName),
1707 writeBuffer, bStringSize, NULL, NULL );
1709 IStream_Write(pOutStream, writeBuffer, bStringSize, &cbWritten);
1710 HeapFree(GetProcessHeap(), 0, writeBuffer);
1712 if (cbWritten!=bStringSize)
1719 /************************************************************************
1720 * OLEFontImpl_GetSizeMax (IPersistStream)
1722 * See Windows documentation for more details on IPersistStream methods.
1724 static HRESULT WINAPI OLEFontImpl_GetSizeMax(
1725 IPersistStream* iface,
1726 ULARGE_INTEGER* pcbSize)
1728 _ICOM_THIS_From_IPersistStream(OLEFontImpl, iface);
1733 pcbSize->u.HighPart = 0;
1734 pcbSize->u.LowPart = 0;
1736 pcbSize->u.LowPart += sizeof(BYTE); /* Version */
1737 pcbSize->u.LowPart += sizeof(WORD); /* Lang code */
1738 pcbSize->u.LowPart += sizeof(BYTE); /* Flags */
1739 pcbSize->u.LowPart += sizeof(WORD); /* Weight */
1740 pcbSize->u.LowPart += sizeof(DWORD); /* Size */
1741 pcbSize->u.LowPart += sizeof(BYTE); /* StrLength */
1743 if (this->description.lpstrName!=0)
1744 pcbSize->u.LowPart += lstrlenW(this->description.lpstrName);
1749 /************************************************************************
1750 * OLEFontImpl_IConnectionPointContainer_QueryInterface (IUnknown)
1752 * See Windows documentation for more details on IUnknown methods.
1754 static HRESULT WINAPI OLEFontImpl_IConnectionPointContainer_QueryInterface(
1755 IConnectionPointContainer* iface,
1759 _ICOM_THIS_From_IConnectionPointContainer(OLEFontImpl, iface);
1761 return IFont_QueryInterface((IFont*)this, riid, ppvoid);
1764 /************************************************************************
1765 * OLEFontImpl_IConnectionPointContainer_Release (IUnknown)
1767 * See Windows documentation for more details on IUnknown methods.
1769 static ULONG WINAPI OLEFontImpl_IConnectionPointContainer_Release(
1770 IConnectionPointContainer* iface)
1772 _ICOM_THIS_From_IConnectionPointContainer(OLEFontImpl, iface);
1774 return IFont_Release((IFont*)this);
1777 /************************************************************************
1778 * OLEFontImpl_IConnectionPointContainer_AddRef (IUnknown)
1780 * See Windows documentation for more details on IUnknown methods.
1782 static ULONG WINAPI OLEFontImpl_IConnectionPointContainer_AddRef(
1783 IConnectionPointContainer* iface)
1785 _ICOM_THIS_From_IConnectionPointContainer(OLEFontImpl, iface);
1787 return IFont_AddRef((IFont*)this);
1790 /************************************************************************
1791 * OLEFontImpl_EnumConnectionPoints (IConnectionPointContainer)
1793 * See Windows documentation for more details on IConnectionPointContainer
1796 static HRESULT WINAPI OLEFontImpl_EnumConnectionPoints(
1797 IConnectionPointContainer* iface,
1798 IEnumConnectionPoints **ppEnum)
1800 _ICOM_THIS_From_IConnectionPointContainer(OLEFontImpl, iface);
1802 FIXME("(%p)->(%p): stub\n", this, ppEnum);
1806 /************************************************************************
1807 * OLEFontImpl_FindConnectionPoint (IConnectionPointContainer)
1809 * See Windows documentation for more details on IConnectionPointContainer
1812 static HRESULT WINAPI OLEFontImpl_FindConnectionPoint(
1813 IConnectionPointContainer* iface,
1815 IConnectionPoint **ppCp)
1817 _ICOM_THIS_From_IConnectionPointContainer(OLEFontImpl, iface);
1818 TRACE("(%p)->(%s, %p): stub\n", this, debugstr_guid(riid), ppCp);
1820 if(memcmp(riid, &IID_IPropertyNotifySink, sizeof(IID_IPropertyNotifySink)) == 0) {
1821 return IConnectionPoint_QueryInterface(this->pCP, &IID_IConnectionPoint,
1824 FIXME("Tried to find connection point on %s\n", debugstr_guid(riid));
1825 return E_NOINTERFACE;
1829 /************************************************************************
1830 * OLEFontImpl implementation of IPersistPropertyBag.
1832 static HRESULT WINAPI OLEFontImpl_IPersistPropertyBag_QueryInterface(
1833 IPersistPropertyBag *iface, REFIID riid, LPVOID *ppvObj
1835 _ICOM_THIS_From_IPersistPropertyBag(IFont, iface);
1836 return IFont_QueryInterface(this,riid,ppvObj);
1839 static ULONG WINAPI OLEFontImpl_IPersistPropertyBag_AddRef(
1840 IPersistPropertyBag *iface
1842 _ICOM_THIS_From_IPersistPropertyBag(IFont, iface);
1843 return IFont_AddRef(this);
1846 static ULONG WINAPI OLEFontImpl_IPersistPropertyBag_Release(
1847 IPersistPropertyBag *iface
1849 _ICOM_THIS_From_IPersistPropertyBag(IFont, iface);
1850 return IFont_Release(this);
1853 static HRESULT WINAPI OLEFontImpl_IPersistPropertyBag_GetClassID(
1854 IPersistPropertyBag *iface, CLSID *classid
1856 FIXME("(%p,%p), stub!\n", iface, classid);
1860 static HRESULT WINAPI OLEFontImpl_IPersistPropertyBag_InitNew(
1861 IPersistPropertyBag *iface
1863 FIXME("(%p), stub!\n", iface);
1867 static HRESULT WINAPI OLEFontImpl_IPersistPropertyBag_Load(
1868 IPersistPropertyBag *iface, IPropertyBag* pPropBag, IErrorLog* pErrorLog
1870 /* (from Visual Basic 6 property bag)
1871 Name = "MS Sans Serif"
1875 Underline = 0 'False
1877 Strikethrough = 0 'False
1879 static const WCHAR sAttrName[] = {'N','a','m','e',0};
1880 static const WCHAR sAttrSize[] = {'S','i','z','e',0};
1881 static const WCHAR sAttrCharset[] = {'C','h','a','r','s','e','t',0};
1882 static const WCHAR sAttrWeight[] = {'W','e','i','g','h','t',0};
1883 static const WCHAR sAttrUnderline[] = {'U','n','d','e','r','l','i','n','e',0};
1884 static const WCHAR sAttrItalic[] = {'I','t','a','l','i','c',0};
1885 static const WCHAR sAttrStrikethrough[] = {'S','t','r','i','k','e','t','h','r','o','u','g','h',0};
1888 HRESULT iRes = S_OK;
1889 _ICOM_THIS_From_IPersistPropertyBag(IFont, iface);
1891 VariantInit(&rawAttr);
1892 VariantInit(&valueAttr);
1895 iRes = IPropertyBag_Read(pPropBag, sAttrName, &rawAttr, pErrorLog);
1898 iRes = VariantChangeType(&rawAttr, &valueAttr, 0, VT_BSTR);
1900 iRes = IFont_put_Name(this, V_BSTR(&valueAttr));
1902 else if (iRes == E_INVALIDARG)
1904 VariantClear(&rawAttr);
1905 VariantClear(&valueAttr);
1909 iRes = IPropertyBag_Read(pPropBag, sAttrSize, &rawAttr, pErrorLog);
1912 iRes = VariantChangeType(&rawAttr, &valueAttr, 0, VT_CY);
1914 iRes = IFont_put_Size(this, V_CY(&valueAttr));
1916 else if (iRes == E_INVALIDARG)
1918 VariantClear(&rawAttr);
1919 VariantClear(&valueAttr);
1923 iRes = IPropertyBag_Read(pPropBag, sAttrCharset, &rawAttr, pErrorLog);
1926 iRes = VariantChangeType(&rawAttr, &valueAttr, 0, VT_I2);
1928 iRes = IFont_put_Charset(this, V_I2(&valueAttr));
1930 else if (iRes == E_INVALIDARG)
1932 VariantClear(&rawAttr);
1933 VariantClear(&valueAttr);
1937 iRes = IPropertyBag_Read(pPropBag, sAttrWeight, &rawAttr, pErrorLog);
1940 iRes = VariantChangeType(&rawAttr, &valueAttr, 0, VT_I2);
1942 iRes = IFont_put_Weight(this, V_I2(&valueAttr));
1944 else if (iRes == E_INVALIDARG)
1946 VariantClear(&rawAttr);
1947 VariantClear(&valueAttr);
1952 iRes = IPropertyBag_Read(pPropBag, sAttrUnderline, &rawAttr, pErrorLog);
1955 iRes = VariantChangeType(&rawAttr, &valueAttr, 0, VT_BOOL);
1957 iRes = IFont_put_Underline(this, V_BOOL(&valueAttr));
1959 else if (iRes == E_INVALIDARG)
1961 VariantClear(&rawAttr);
1962 VariantClear(&valueAttr);
1966 iRes = IPropertyBag_Read(pPropBag, sAttrItalic, &rawAttr, pErrorLog);
1969 iRes = VariantChangeType(&rawAttr, &valueAttr, 0, VT_BOOL);
1971 iRes = IFont_put_Italic(this, V_BOOL(&valueAttr));
1973 else if (iRes == E_INVALIDARG)
1975 VariantClear(&rawAttr);
1976 VariantClear(&valueAttr);
1980 iRes = IPropertyBag_Read(pPropBag, sAttrStrikethrough, &rawAttr, pErrorLog);
1983 iRes = VariantChangeType(&rawAttr, &valueAttr, 0, VT_BOOL);
1985 IFont_put_Strikethrough(this, V_BOOL(&valueAttr));
1987 else if (iRes == E_INVALIDARG)
1989 VariantClear(&rawAttr);
1990 VariantClear(&valueAttr);
1994 WARN("-- 0x%08lx\n", iRes);
1998 static HRESULT WINAPI OLEFontImpl_IPersistPropertyBag_Save(
1999 IPersistPropertyBag *iface, IPropertyBag* pPropBag, BOOL fClearDirty,
2000 BOOL fSaveAllProperties
2002 FIXME("(%p,%p,%d,%d), stub!\n", iface, pPropBag, fClearDirty, fSaveAllProperties);
2006 static const IPersistPropertyBagVtbl OLEFontImpl_IPersistPropertyBag_VTable =
2008 OLEFontImpl_IPersistPropertyBag_QueryInterface,
2009 OLEFontImpl_IPersistPropertyBag_AddRef,
2010 OLEFontImpl_IPersistPropertyBag_Release,
2012 OLEFontImpl_IPersistPropertyBag_GetClassID,
2013 OLEFontImpl_IPersistPropertyBag_InitNew,
2014 OLEFontImpl_IPersistPropertyBag_Load,
2015 OLEFontImpl_IPersistPropertyBag_Save
2018 /************************************************************************
2019 * OLEFontImpl implementation of IPersistStreamInit.
2021 static HRESULT WINAPI OLEFontImpl_IPersistStreamInit_QueryInterface(
2022 IPersistStreamInit *iface, REFIID riid, LPVOID *ppvObj
2024 _ICOM_THIS_From_IPersistStreamInit(IFont, iface);
2025 return IFont_QueryInterface(this,riid,ppvObj);
2028 static ULONG WINAPI OLEFontImpl_IPersistStreamInit_AddRef(
2029 IPersistStreamInit *iface
2031 _ICOM_THIS_From_IPersistStreamInit(IFont, iface);
2032 return IFont_AddRef(this);
2035 static ULONG WINAPI OLEFontImpl_IPersistStreamInit_Release(
2036 IPersistStreamInit *iface
2038 _ICOM_THIS_From_IPersistStreamInit(IFont, iface);
2039 return IFont_Release(this);
2042 static HRESULT WINAPI OLEFontImpl_IPersistStreamInit_GetClassID(
2043 IPersistStreamInit *iface, CLSID *classid
2045 FIXME("(%p,%p), stub!\n", iface, classid);
2049 static HRESULT WINAPI OLEFontImpl_IPersistStreamInit_IsDirty(
2050 IPersistStreamInit *iface
2052 FIXME("(%p), stub!\n", iface);
2056 static HRESULT WINAPI OLEFontImpl_IPersistStreamInit_Load(
2057 IPersistStreamInit *iface, LPSTREAM pStm
2059 FIXME("(%p,%p), stub!\n", iface, pStm);
2063 static HRESULT WINAPI OLEFontImpl_IPersistStreamInit_Save(
2064 IPersistStreamInit *iface, LPSTREAM pStm, BOOL fClearDirty
2066 FIXME("(%p,%p,%d), stub!\n", iface, pStm, fClearDirty);
2070 static HRESULT WINAPI OLEFontImpl_IPersistStreamInit_GetSizeMax(
2071 IPersistStreamInit *iface, ULARGE_INTEGER *pcbSize
2073 FIXME("(%p,%p), stub!\n", iface, pcbSize);
2077 static HRESULT WINAPI OLEFontImpl_IPersistStreamInit_InitNew(
2078 IPersistStreamInit *iface
2080 FIXME("(%p), stub!\n", iface);
2084 static const IPersistStreamInitVtbl OLEFontImpl_IPersistStreamInit_VTable =
2086 OLEFontImpl_IPersistStreamInit_QueryInterface,
2087 OLEFontImpl_IPersistStreamInit_AddRef,
2088 OLEFontImpl_IPersistStreamInit_Release,
2090 OLEFontImpl_IPersistStreamInit_GetClassID,
2091 OLEFontImpl_IPersistStreamInit_IsDirty,
2092 OLEFontImpl_IPersistStreamInit_Load,
2093 OLEFontImpl_IPersistStreamInit_Save,
2094 OLEFontImpl_IPersistStreamInit_GetSizeMax,
2095 OLEFontImpl_IPersistStreamInit_InitNew
2098 /*******************************************************************************
2099 * StdFont ClassFactory
2103 /* IUnknown fields */
2104 const IClassFactoryVtbl *lpVtbl;
2106 } IClassFactoryImpl;
2108 static HRESULT WINAPI
2109 SFCF_QueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj) {
2110 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
2112 FIXME("(%p)->(%s,%p),stub!\n",This,debugstr_guid(riid),ppobj);
2113 return E_NOINTERFACE;
2117 SFCF_AddRef(LPCLASSFACTORY iface) {
2118 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
2119 return InterlockedIncrement(&This->ref);
2122 static ULONG WINAPI SFCF_Release(LPCLASSFACTORY iface) {
2123 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
2124 /* static class, won't be freed */
2125 return InterlockedDecrement(&This->ref);
2128 static HRESULT WINAPI SFCF_CreateInstance(
2129 LPCLASSFACTORY iface,LPUNKNOWN pOuter,REFIID riid,LPVOID *ppobj
2131 return OleCreateFontIndirect(NULL,riid,ppobj);
2135 static HRESULT WINAPI SFCF_LockServer(LPCLASSFACTORY iface,BOOL dolock) {
2136 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
2137 FIXME("(%p)->(%d),stub!\n",This,dolock);
2141 static const IClassFactoryVtbl SFCF_Vtbl = {
2142 SFCF_QueryInterface,
2145 SFCF_CreateInstance,
2148 static IClassFactoryImpl STDFONT_CF = {&SFCF_Vtbl, 1 };
2150 void _get_STDFONT_CF(LPVOID *ppv) { *ppv = (LPVOID)&STDFONT_CF; }