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* lpVtbl;
67 const IDispatchVtbl* lpvtblIDispatch;
68 const IPersistStreamVtbl* lpvtblIPersistStream;
69 const IConnectionPointContainerVtbl* lpvtblIConnectionPointContainer;
70 const IPersistPropertyBagVtbl* lpvtblIPersistPropertyBag;
71 const IPersistStreamInitVtbl* lpvtblIPersistStreamInit;
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
108 static inline OLEFontImpl *impl_from_IDispatch( IDispatch *iface )
110 return (OLEFontImpl *)((char*)iface - FIELD_OFFSET(OLEFontImpl, lpvtblIDispatch));
113 static inline OLEFontImpl *impl_from_IPersistStream( IPersistStream *iface )
115 return (OLEFontImpl *)((char*)iface - FIELD_OFFSET(OLEFontImpl, lpvtblIPersistStream));
118 static inline OLEFontImpl *impl_from_IConnectionPointContainer( IConnectionPointContainer *iface )
120 return (OLEFontImpl *)((char*)iface - FIELD_OFFSET(OLEFontImpl, lpvtblIConnectionPointContainer));
123 static inline OLEFontImpl *impl_from_IPersistPropertyBag( IPersistPropertyBag *iface )
125 return (OLEFontImpl *)((char*)iface - FIELD_OFFSET(OLEFontImpl, lpvtblIPersistPropertyBag));
128 static inline OLEFontImpl *impl_from_IPersistStreamInit( IPersistStreamInit *iface )
130 return (OLEFontImpl *)((char*)iface - FIELD_OFFSET(OLEFontImpl, lpvtblIPersistStreamInit));
134 /***********************************************************************
135 * Prototypes for the implementation functions for the IFont
138 static OLEFontImpl* OLEFontImpl_Construct(LPFONTDESC fontDesc);
139 static void OLEFontImpl_Destroy(OLEFontImpl* fontDesc);
140 static HRESULT WINAPI OLEFontImpl_QueryInterface(IFont* iface, REFIID riid, VOID** ppvoid);
141 static ULONG WINAPI OLEFontImpl_AddRef(IFont* iface);
142 static ULONG WINAPI OLEFontImpl_Release(IFont* iface);
143 static HRESULT WINAPI OLEFontImpl_get_Name(IFont* iface, BSTR* pname);
144 static HRESULT WINAPI OLEFontImpl_put_Name(IFont* iface, BSTR name);
145 static HRESULT WINAPI OLEFontImpl_get_Size(IFont* iface, CY* psize);
146 static HRESULT WINAPI OLEFontImpl_put_Size(IFont* iface, CY size);
147 static HRESULT WINAPI OLEFontImpl_get_Bold(IFont* iface, BOOL* pbold);
148 static HRESULT WINAPI OLEFontImpl_put_Bold(IFont* iface, BOOL bold);
149 static HRESULT WINAPI OLEFontImpl_get_Italic(IFont* iface, BOOL* pitalic);
150 static HRESULT WINAPI OLEFontImpl_put_Italic(IFont* iface, BOOL italic);
151 static HRESULT WINAPI OLEFontImpl_get_Underline(IFont* iface, BOOL* punderline);
152 static HRESULT WINAPI OLEFontImpl_put_Underline(IFont* iface, BOOL underline);
153 static HRESULT WINAPI OLEFontImpl_get_Strikethrough(IFont* iface, BOOL* pstrikethrough);
154 static HRESULT WINAPI OLEFontImpl_put_Strikethrough(IFont* iface, BOOL strikethrough);
155 static HRESULT WINAPI OLEFontImpl_get_Weight(IFont* iface, short* pweight);
156 static HRESULT WINAPI OLEFontImpl_put_Weight(IFont* iface, short weight);
157 static HRESULT WINAPI OLEFontImpl_get_Charset(IFont* iface, short* pcharset);
158 static HRESULT WINAPI OLEFontImpl_put_Charset(IFont* iface, short charset);
159 static HRESULT WINAPI OLEFontImpl_get_hFont(IFont* iface, HFONT* phfont);
160 static HRESULT WINAPI OLEFontImpl_Clone(IFont* iface, IFont** ppfont);
161 static HRESULT WINAPI OLEFontImpl_IsEqual(IFont* iface, IFont* pFontOther);
162 static HRESULT WINAPI OLEFontImpl_SetRatio(IFont* iface, LONG cyLogical, LONG cyHimetric);
163 static HRESULT WINAPI OLEFontImpl_QueryTextMetrics(IFont* iface, TEXTMETRICOLE* ptm);
164 static HRESULT WINAPI OLEFontImpl_AddRefHfont(IFont* iface, HFONT hfont);
165 static HRESULT WINAPI OLEFontImpl_ReleaseHfont(IFont* iface, HFONT hfont);
166 static HRESULT WINAPI OLEFontImpl_SetHdc(IFont* iface, HDC hdc);
168 /***********************************************************************
169 * Prototypes for the implementation functions for the IDispatch
172 static HRESULT WINAPI OLEFontImpl_IDispatch_QueryInterface(IDispatch* iface,
175 static ULONG WINAPI OLEFontImpl_IDispatch_AddRef(IDispatch* iface);
176 static ULONG WINAPI OLEFontImpl_IDispatch_Release(IDispatch* iface);
177 static HRESULT WINAPI OLEFontImpl_GetTypeInfoCount(IDispatch* iface,
178 unsigned int* pctinfo);
179 static HRESULT WINAPI OLEFontImpl_GetTypeInfo(IDispatch* iface,
182 ITypeInfo** ppTInfo);
183 static HRESULT WINAPI OLEFontImpl_GetIDsOfNames(IDispatch* iface,
189 static HRESULT WINAPI OLEFontImpl_Invoke(IDispatch* iface,
194 DISPPARAMS* pDispParams,
196 EXCEPINFO* pExepInfo,
199 /***********************************************************************
200 * Prototypes for the implementation functions for the IPersistStream
203 static HRESULT WINAPI OLEFontImpl_IPersistStream_QueryInterface(IPersistStream* iface,
206 static ULONG WINAPI OLEFontImpl_IPersistStream_AddRef(IPersistStream* iface);
207 static ULONG WINAPI OLEFontImpl_IPersistStream_Release(IPersistStream* iface);
208 static HRESULT WINAPI OLEFontImpl_GetClassID(IPersistStream* iface,
210 static HRESULT WINAPI OLEFontImpl_IsDirty(IPersistStream* iface);
211 static HRESULT WINAPI OLEFontImpl_Load(IPersistStream* iface,
212 IStream* pLoadStream);
213 static HRESULT WINAPI OLEFontImpl_Save(IPersistStream* iface,
216 static HRESULT WINAPI OLEFontImpl_GetSizeMax(IPersistStream* iface,
217 ULARGE_INTEGER* pcbSize);
219 /***********************************************************************
220 * Prototypes for the implementation functions for the
221 * IConnectionPointContainer interface
223 static HRESULT WINAPI OLEFontImpl_IConnectionPointContainer_QueryInterface(
224 IConnectionPointContainer* iface,
227 static ULONG WINAPI OLEFontImpl_IConnectionPointContainer_AddRef(
228 IConnectionPointContainer* iface);
229 static ULONG WINAPI OLEFontImpl_IConnectionPointContainer_Release(
230 IConnectionPointContainer* iface);
231 static HRESULT WINAPI OLEFontImpl_EnumConnectionPoints(
232 IConnectionPointContainer* iface,
233 IEnumConnectionPoints **ppEnum);
234 static HRESULT WINAPI OLEFontImpl_FindConnectionPoint(
235 IConnectionPointContainer* iface,
237 IConnectionPoint **ppCp);
240 * Virtual function tables for the OLEFontImpl class.
242 static const IFontVtbl OLEFontImpl_VTable =
244 OLEFontImpl_QueryInterface,
247 OLEFontImpl_get_Name,
248 OLEFontImpl_put_Name,
249 OLEFontImpl_get_Size,
250 OLEFontImpl_put_Size,
251 OLEFontImpl_get_Bold,
252 OLEFontImpl_put_Bold,
253 OLEFontImpl_get_Italic,
254 OLEFontImpl_put_Italic,
255 OLEFontImpl_get_Underline,
256 OLEFontImpl_put_Underline,
257 OLEFontImpl_get_Strikethrough,
258 OLEFontImpl_put_Strikethrough,
259 OLEFontImpl_get_Weight,
260 OLEFontImpl_put_Weight,
261 OLEFontImpl_get_Charset,
262 OLEFontImpl_put_Charset,
263 OLEFontImpl_get_hFont,
266 OLEFontImpl_SetRatio,
267 OLEFontImpl_QueryTextMetrics,
268 OLEFontImpl_AddRefHfont,
269 OLEFontImpl_ReleaseHfont,
273 static const IDispatchVtbl OLEFontImpl_IDispatch_VTable =
275 OLEFontImpl_IDispatch_QueryInterface,
276 OLEFontImpl_IDispatch_AddRef,
277 OLEFontImpl_IDispatch_Release,
278 OLEFontImpl_GetTypeInfoCount,
279 OLEFontImpl_GetTypeInfo,
280 OLEFontImpl_GetIDsOfNames,
284 static const IPersistStreamVtbl OLEFontImpl_IPersistStream_VTable =
286 OLEFontImpl_IPersistStream_QueryInterface,
287 OLEFontImpl_IPersistStream_AddRef,
288 OLEFontImpl_IPersistStream_Release,
289 OLEFontImpl_GetClassID,
293 OLEFontImpl_GetSizeMax
296 static const IConnectionPointContainerVtbl
297 OLEFontImpl_IConnectionPointContainer_VTable =
299 OLEFontImpl_IConnectionPointContainer_QueryInterface,
300 OLEFontImpl_IConnectionPointContainer_AddRef,
301 OLEFontImpl_IConnectionPointContainer_Release,
302 OLEFontImpl_EnumConnectionPoints,
303 OLEFontImpl_FindConnectionPoint
306 static const IPersistPropertyBagVtbl OLEFontImpl_IPersistPropertyBag_VTable;
307 static const IPersistStreamInitVtbl OLEFontImpl_IPersistStreamInit_VTable;
309 /******************************************************************************
310 * OleCreateFontIndirect [OLEAUT32.420]
312 HRESULT WINAPI OleCreateFontIndirect(
313 LPFONTDESC lpFontDesc,
317 OLEFontImpl* newFont = 0;
320 TRACE("(%p, %s, %p)\n", lpFontDesc, debugstr_guid(riid), ppvObj);
332 static const WCHAR fname[] = { 'S','y','s','t','e','m',0 };
334 fd.cbSizeofstruct = sizeof(fd);
335 fd.lpstrName = (WCHAR*)fname;
336 fd.cySize.s.Lo = 80000;
342 fd.fStrikethrough = 0;
347 * Try to construct a new instance of the class.
349 newFont = OLEFontImpl_Construct(lpFontDesc);
352 return E_OUTOFMEMORY;
355 * Make sure it supports the interface required by the caller.
357 hr = IFont_QueryInterface((IFont*)newFont, riid, ppvObj);
360 * Release the reference obtained in the constructor. If
361 * the QueryInterface was unsuccessful, it will free the class.
363 IFont_Release((IFont*)newFont);
369 /***********************************************************************
370 * Implementation of the OLEFontImpl class.
373 /***********************************************************************
374 * OLEFont_SendNotify (internal)
376 * Sends notification messages of changed properties to any interested
379 static void OLEFont_SendNotify(OLEFontImpl* this, DISPID dispID)
381 IEnumConnections *pEnum;
385 hres = IConnectionPoint_EnumConnections(this->pCP, &pEnum);
386 if (FAILED(hres)) /* When we have 0 connections. */
389 while(IEnumConnections_Next(pEnum, 1, &CD, NULL) == S_OK) {
390 IPropertyNotifySink *sink;
392 IUnknown_QueryInterface(CD.pUnk, &IID_IPropertyNotifySink, (LPVOID)&sink);
393 IPropertyNotifySink_OnChanged(sink, dispID);
394 IPropertyNotifySink_Release(sink);
395 IUnknown_Release(CD.pUnk);
397 IEnumConnections_Release(pEnum);
401 /************************************************************************
402 * OLEFontImpl_Construct
404 * This method will construct a new instance of the OLEFontImpl
407 * The caller of this method must release the object when it's
410 static OLEFontImpl* OLEFontImpl_Construct(LPFONTDESC fontDesc)
412 OLEFontImpl* newObject = 0;
415 * Allocate space for the object.
417 newObject = HeapAlloc(GetProcessHeap(), 0, sizeof(OLEFontImpl));
423 * Initialize the virtual function table.
425 newObject->lpVtbl = &OLEFontImpl_VTable;
426 newObject->lpvtblIDispatch = &OLEFontImpl_IDispatch_VTable;
427 newObject->lpvtblIPersistStream = &OLEFontImpl_IPersistStream_VTable;
428 newObject->lpvtblIConnectionPointContainer = &OLEFontImpl_IConnectionPointContainer_VTable;
429 newObject->lpvtblIPersistPropertyBag = &OLEFontImpl_IPersistPropertyBag_VTable;
430 newObject->lpvtblIPersistStreamInit = &OLEFontImpl_IPersistStreamInit_VTable;
433 * Start with one reference count. The caller of this function
434 * must release the interface pointer when it is done.
439 * Copy the description of the font in the object.
441 assert(fontDesc->cbSizeofstruct >= sizeof(FONTDESC));
443 newObject->description.cbSizeofstruct = sizeof(FONTDESC);
444 newObject->description.lpstrName = HeapAlloc(GetProcessHeap(),
446 (lstrlenW(fontDesc->lpstrName)+1) * sizeof(WCHAR));
447 strcpyW(newObject->description.lpstrName, fontDesc->lpstrName);
448 newObject->description.cySize = fontDesc->cySize;
449 newObject->description.sWeight = fontDesc->sWeight;
450 newObject->description.sCharset = fontDesc->sCharset;
451 newObject->description.fItalic = fontDesc->fItalic;
452 newObject->description.fUnderline = fontDesc->fUnderline;
453 newObject->description.fStrikethrough = fontDesc->fStrikethrough;
456 * Initializing all the other members.
458 newObject->gdiFont = 0;
459 newObject->fontLock = 0;
460 newObject->cyLogical = 72L;
461 newObject->cyHimetric = 2540L;
462 CreateConnectionPoint((IUnknown*)newObject, &IID_IPropertyNotifySink, &newObject->pCP);
463 TRACE("returning %p\n", newObject);
467 /************************************************************************
468 * OLEFontImpl_Destroy
470 * This method is called by the Release method when the reference
471 * count goes down to 0. It will free all resources used by
474 static void OLEFontImpl_Destroy(OLEFontImpl* fontDesc)
476 TRACE("(%p)\n", fontDesc);
478 HeapFree(GetProcessHeap(), 0, fontDesc->description.lpstrName);
480 if (fontDesc->gdiFont!=0)
481 DeleteObject(fontDesc->gdiFont);
483 HeapFree(GetProcessHeap(), 0, fontDesc);
486 /************************************************************************
487 * OLEFontImpl_QueryInterface (IUnknown)
489 * See Windows documentation for more details on IUnknown methods.
491 HRESULT WINAPI OLEFontImpl_QueryInterface(
496 OLEFontImpl *this = (OLEFontImpl *)iface;
497 TRACE("(%p)->(%s, %p)\n", this, debugstr_guid(riid), ppvObject);
500 * Perform a sanity check on the parameters.
502 if ( (this==0) || (ppvObject==0) )
506 * Initialize the return parameter.
511 * Compare the riid with the interface IDs implemented by this object.
513 if (IsEqualGUID(&IID_IUnknown, riid))
514 *ppvObject = (IFont*)this;
515 if (IsEqualGUID(&IID_IFont, riid))
516 *ppvObject = (IFont*)this;
517 if (IsEqualGUID(&IID_IDispatch, riid))
518 *ppvObject = (IDispatch*)&(this->lpvtblIDispatch);
519 if (IsEqualGUID(&IID_IFontDisp, riid))
520 *ppvObject = (IDispatch*)&(this->lpvtblIDispatch);
521 if (IsEqualGUID(&IID_IPersistStream, riid))
522 *ppvObject = (IPersistStream*)&(this->lpvtblIPersistStream);
523 if (IsEqualGUID(&IID_IConnectionPointContainer, riid))
524 *ppvObject = (IConnectionPointContainer*)&(this->lpvtblIConnectionPointContainer);
525 if (IsEqualGUID(&IID_IPersistPropertyBag, riid))
526 *ppvObject = (IPersistPropertyBag*)&(this->lpvtblIPersistPropertyBag);
527 if (IsEqualGUID(&IID_IPersistStreamInit, riid))
528 *ppvObject = (IPersistStreamInit*)&(this->lpvtblIPersistStreamInit);
531 * Check that we obtained an interface.
535 FIXME("() : asking for unsupported interface %s\n",debugstr_guid(riid));
536 return E_NOINTERFACE;
538 OLEFontImpl_AddRef((IFont*)this);
542 /************************************************************************
543 * OLEFontImpl_AddRef (IUnknown)
545 * See Windows documentation for more details on IUnknown methods.
547 ULONG WINAPI OLEFontImpl_AddRef(
550 OLEFontImpl *this = (OLEFontImpl *)iface;
551 TRACE("(%p)->(ref=%ld)\n", this, this->ref);
552 return InterlockedIncrement(&this->ref);
555 /************************************************************************
556 * OLEFontImpl_Release (IUnknown)
558 * See Windows documentation for more details on IUnknown methods.
560 ULONG WINAPI OLEFontImpl_Release(
563 OLEFontImpl *this = (OLEFontImpl *)iface;
565 TRACE("(%p)->(ref=%ld)\n", this, this->ref);
568 * Decrease the reference count on this object.
570 ret = InterlockedDecrement(&this->ref);
573 * If the reference count goes down to 0, perform suicide.
575 if (ret==0) OLEFontImpl_Destroy(this);
580 /************************************************************************
581 * OLEFontImpl_get_Name (IFont)
583 * See Windows documentation for more details on IFont methods.
585 static HRESULT WINAPI OLEFontImpl_get_Name(
589 OLEFontImpl *this = (OLEFontImpl *)iface;
590 TRACE("(%p)->(%p)\n", this, pname);
597 if (this->description.lpstrName!=0)
598 *pname = SysAllocString(this->description.lpstrName);
605 /************************************************************************
606 * OLEFontImpl_put_Name (IFont)
608 * See Windows documentation for more details on IFont methods.
610 static HRESULT WINAPI OLEFontImpl_put_Name(
614 OLEFontImpl *this = (OLEFontImpl *)iface;
615 TRACE("(%p)->(%p)\n", this, name);
617 if (this->description.lpstrName==0)
619 this->description.lpstrName = HeapAlloc(GetProcessHeap(),
621 (lstrlenW(name)+1) * sizeof(WCHAR));
625 this->description.lpstrName = HeapReAlloc(GetProcessHeap(),
627 this->description.lpstrName,
628 (lstrlenW(name)+1) * sizeof(WCHAR));
631 if (this->description.lpstrName==0)
632 return E_OUTOFMEMORY;
634 strcpyW(this->description.lpstrName, name);
635 TRACE("new name %s\n", debugstr_w(this->description.lpstrName));
636 OLEFont_SendNotify(this, DISPID_FONT_NAME);
640 /************************************************************************
641 * OLEFontImpl_get_Size (IFont)
643 * See Windows documentation for more details on IFont methods.
645 static HRESULT WINAPI OLEFontImpl_get_Size(
649 OLEFontImpl *this = (OLEFontImpl *)iface;
650 TRACE("(%p)->(%p)\n", this, psize);
659 psize->s.Lo = this->description.cySize.s.Lo;
664 /************************************************************************
665 * OLEFontImpl_put_Size (IFont)
667 * See Windows documentation for more details on IFont methods.
669 static HRESULT WINAPI OLEFontImpl_put_Size(
673 OLEFontImpl *this = (OLEFontImpl *)iface;
674 TRACE("(%p)->(%ld)\n", this, size.s.Lo);
675 this->description.cySize.s.Hi = 0;
676 this->description.cySize.s.Lo = size.s.Lo;
677 OLEFont_SendNotify(this, DISPID_FONT_SIZE);
682 /************************************************************************
683 * OLEFontImpl_get_Bold (IFont)
685 * See Windows documentation for more details on IFont methods.
687 static HRESULT WINAPI OLEFontImpl_get_Bold(
691 OLEFontImpl *this = (OLEFontImpl *)iface;
692 TRACE("(%p)->(%p)\n", this, pbold);
699 *pbold = this->description.sWeight > 550;
704 /************************************************************************
705 * OLEFontImpl_put_Bold (IFont)
707 * See Windows documentation for more details on IFont methods.
709 static HRESULT WINAPI OLEFontImpl_put_Bold(
713 OLEFontImpl *this = (OLEFontImpl *)iface;
714 TRACE("(%p)->(%d)\n", this, bold);
715 this->description.sWeight = bold ? FW_BOLD : FW_NORMAL;
716 OLEFont_SendNotify(this, DISPID_FONT_BOLD);
721 /************************************************************************
722 * OLEFontImpl_get_Italic (IFont)
724 * See Windows documentation for more details on IFont methods.
726 static HRESULT WINAPI OLEFontImpl_get_Italic(
730 OLEFontImpl *this = (OLEFontImpl *)iface;
731 TRACE("(%p)->(%p)\n", this, pitalic);
738 *pitalic = this->description.fItalic;
743 /************************************************************************
744 * OLEFontImpl_put_Italic (IFont)
746 * See Windows documentation for more details on IFont methods.
748 static HRESULT WINAPI OLEFontImpl_put_Italic(
752 OLEFontImpl *this = (OLEFontImpl *)iface;
753 TRACE("(%p)->(%d)\n", this, italic);
755 this->description.fItalic = italic;
757 OLEFont_SendNotify(this, DISPID_FONT_ITALIC);
761 /************************************************************************
762 * OLEFontImpl_get_Underline (IFont)
764 * See Windows documentation for more details on IFont methods.
766 static HRESULT WINAPI OLEFontImpl_get_Underline(
770 OLEFontImpl *this = (OLEFontImpl *)iface;
771 TRACE("(%p)->(%p)\n", this, punderline);
779 *punderline = this->description.fUnderline;
784 /************************************************************************
785 * OLEFontImpl_put_Underline (IFont)
787 * See Windows documentation for more details on IFont methods.
789 static HRESULT WINAPI OLEFontImpl_put_Underline(
793 OLEFontImpl *this = (OLEFontImpl *)iface;
794 TRACE("(%p)->(%d)\n", this, underline);
796 this->description.fUnderline = underline;
798 OLEFont_SendNotify(this, DISPID_FONT_UNDER);
802 /************************************************************************
803 * OLEFontImpl_get_Strikethrough (IFont)
805 * See Windows documentation for more details on IFont methods.
807 static HRESULT WINAPI OLEFontImpl_get_Strikethrough(
809 BOOL* pstrikethrough)
811 OLEFontImpl *this = (OLEFontImpl *)iface;
812 TRACE("(%p)->(%p)\n", this, pstrikethrough);
817 if (pstrikethrough==0)
820 *pstrikethrough = this->description.fStrikethrough;
825 /************************************************************************
826 * OLEFontImpl_put_Strikethrough (IFont)
828 * See Windows documentation for more details on IFont methods.
830 static HRESULT WINAPI OLEFontImpl_put_Strikethrough(
834 OLEFontImpl *this = (OLEFontImpl *)iface;
835 TRACE("(%p)->(%d)\n", this, strikethrough);
837 this->description.fStrikethrough = strikethrough;
838 OLEFont_SendNotify(this, DISPID_FONT_STRIKE);
843 /************************************************************************
844 * OLEFontImpl_get_Weight (IFont)
846 * See Windows documentation for more details on IFont methods.
848 static HRESULT WINAPI OLEFontImpl_get_Weight(
852 OLEFontImpl *this = (OLEFontImpl *)iface;
853 TRACE("(%p)->(%p)\n", this, pweight);
861 *pweight = this->description.sWeight;
866 /************************************************************************
867 * OLEFontImpl_put_Weight (IFont)
869 * See Windows documentation for more details on IFont methods.
871 static HRESULT WINAPI OLEFontImpl_put_Weight(
875 OLEFontImpl *this = (OLEFontImpl *)iface;
876 TRACE("(%p)->(%d)\n", this, weight);
878 this->description.sWeight = weight;
880 OLEFont_SendNotify(this, DISPID_FONT_WEIGHT);
884 /************************************************************************
885 * OLEFontImpl_get_Charset (IFont)
887 * See Windows documentation for more details on IFont methods.
889 static HRESULT WINAPI OLEFontImpl_get_Charset(
893 OLEFontImpl *this = (OLEFontImpl *)iface;
894 TRACE("(%p)->(%p)\n", this, pcharset);
902 *pcharset = this->description.sCharset;
907 /************************************************************************
908 * OLEFontImpl_put_Charset (IFont)
910 * See Windows documentation for more details on IFont methods.
912 static HRESULT WINAPI OLEFontImpl_put_Charset(
916 OLEFontImpl *this = (OLEFontImpl *)iface;
917 TRACE("(%p)->(%d)\n", this, charset);
919 this->description.sCharset = charset;
920 OLEFont_SendNotify(this, DISPID_FONT_CHARSET);
925 /************************************************************************
926 * OLEFontImpl_get_hFont (IFont)
928 * See Windows documentation for more details on IFont methods.
930 static HRESULT WINAPI OLEFontImpl_get_hFont(
934 OLEFontImpl *this = (OLEFontImpl *)iface;
935 TRACE("(%p)->(%p)\n", this, phfont);
940 * Realize the font if necessary
942 if (this->gdiFont==0)
949 * The height of the font returned by the get_Size property is the
950 * height of the font in points multiplied by 10000... Using some
951 * simple conversions and the ratio given by the application, it can
952 * be converted to a height in pixels.
954 IFont_get_Size(iface, &cySize);
956 fontHeight = MulDiv( cySize.s.Lo, this->cyLogical, this->cyHimetric );
958 memset(&logFont, 0, sizeof(LOGFONTW));
960 logFont.lfHeight = ((fontHeight%10000L)>5000L) ? (-fontHeight/10000L)-1 :
961 (-fontHeight/10000L);
962 logFont.lfItalic = this->description.fItalic;
963 logFont.lfUnderline = this->description.fUnderline;
964 logFont.lfStrikeOut = this->description.fStrikethrough;
965 logFont.lfWeight = this->description.sWeight;
966 logFont.lfCharSet = this->description.sCharset;
967 logFont.lfOutPrecision = OUT_CHARACTER_PRECIS;
968 logFont.lfClipPrecision = CLIP_DEFAULT_PRECIS;
969 logFont.lfQuality = DEFAULT_QUALITY;
970 logFont.lfPitchAndFamily = DEFAULT_PITCH;
971 strcpyW(logFont.lfFaceName,this->description.lpstrName);
973 this->gdiFont = CreateFontIndirectW(&logFont);
976 *phfont = this->gdiFont;
977 TRACE("Returning %p\n", *phfont);
981 /************************************************************************
982 * OLEFontImpl_Clone (IFont)
984 * See Windows documentation for more details on IFont methods.
986 static HRESULT WINAPI OLEFontImpl_Clone(
990 OLEFontImpl* newObject = 0;
994 OLEFontImpl *this = (OLEFontImpl *)iface;
995 TRACE("(%p)->(%p)\n", this, ppfont);
1003 * Allocate space for the object.
1005 newObject = HeapAlloc(GetProcessHeap(), 0, sizeof(OLEFontImpl));
1007 if (newObject==NULL)
1008 return E_OUTOFMEMORY;
1012 /* We need to alloc new memory for the string, otherwise
1013 * we free memory twice.
1015 newObject->description.lpstrName = HeapAlloc(
1017 (1+strlenW(this->description.lpstrName))*2
1019 strcpyW(newObject->description.lpstrName, this->description.lpstrName);
1020 /* We need to clone the HFONT too. This is just cut & paste from above */
1021 IFont_get_Size(iface, &cySize);
1023 fontHeight = MulDiv(cySize.s.Lo, this->cyLogical,this->cyHimetric);
1025 memset(&logFont, 0, sizeof(LOGFONTW));
1027 logFont.lfHeight = ((fontHeight%10000L)>5000L) ? (-fontHeight/10000L)-1 :
1028 (-fontHeight/10000L);
1029 logFont.lfItalic = this->description.fItalic;
1030 logFont.lfUnderline = this->description.fUnderline;
1031 logFont.lfStrikeOut = this->description.fStrikethrough;
1032 logFont.lfWeight = this->description.sWeight;
1033 logFont.lfCharSet = this->description.sCharset;
1034 logFont.lfOutPrecision = OUT_CHARACTER_PRECIS;
1035 logFont.lfClipPrecision = CLIP_DEFAULT_PRECIS;
1036 logFont.lfQuality = DEFAULT_QUALITY;
1037 logFont.lfPitchAndFamily = DEFAULT_PITCH;
1038 strcpyW(logFont.lfFaceName,this->description.lpstrName);
1040 newObject->gdiFont = CreateFontIndirectW(&logFont);
1043 /* The cloned object starts with a reference count of 1 */
1046 *ppfont = (IFont*)newObject;
1051 /************************************************************************
1052 * OLEFontImpl_IsEqual (IFont)
1054 * See Windows documentation for more details on IFont methods.
1056 static HRESULT WINAPI OLEFontImpl_IsEqual(
1060 FIXME("(%p, %p), stub!\n",iface,pFontOther);
1064 /************************************************************************
1065 * OLEFontImpl_SetRatio (IFont)
1067 * See Windows documentation for more details on IFont methods.
1069 static HRESULT WINAPI OLEFontImpl_SetRatio(
1074 OLEFontImpl *this = (OLEFontImpl *)iface;
1075 TRACE("(%p)->(%ld, %ld)\n", this, cyLogical, cyHimetric);
1077 this->cyLogical = cyLogical;
1078 this->cyHimetric = cyHimetric;
1083 /************************************************************************
1084 * OLEFontImpl_QueryTextMetrics (IFont)
1086 * See Windows documentation for more details on IFont methods.
1088 static HRESULT WINAPI OLEFontImpl_QueryTextMetrics(
1093 HFONT hOldFont, hNewFont;
1096 OLEFontImpl_get_hFont(iface, &hNewFont);
1097 hOldFont = SelectObject(hdcRef, hNewFont);
1098 GetTextMetricsW(hdcRef, ptm);
1099 SelectObject(hdcRef, hOldFont);
1100 ReleaseDC(0, hdcRef);
1104 /************************************************************************
1105 * OLEFontImpl_AddRefHfont (IFont)
1107 * See Windows documentation for more details on IFont methods.
1109 static HRESULT WINAPI OLEFontImpl_AddRefHfont(
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;
1125 /************************************************************************
1126 * OLEFontImpl_ReleaseHfont (IFont)
1128 * See Windows documentation for more details on IFont methods.
1130 static HRESULT WINAPI OLEFontImpl_ReleaseHfont(
1134 OLEFontImpl *this = (OLEFontImpl *)iface;
1135 TRACE("(%p)->(%p) (lock=%ld)\n", this, hfont, this->fontLock);
1137 if ( (hfont == 0) ||
1138 (hfont != this->gdiFont) )
1139 return E_INVALIDARG;
1144 * If we just released our last font reference, destroy it.
1146 if (this->fontLock==0)
1148 DeleteObject(this->gdiFont);
1155 /************************************************************************
1156 * OLEFontImpl_SetHdc (IFont)
1158 * See Windows documentation for more details on IFont methods.
1160 static HRESULT WINAPI OLEFontImpl_SetHdc(
1164 OLEFontImpl *this = (OLEFontImpl *)iface;
1165 FIXME("(%p)->(%p): Stub\n", this, hdc);
1169 /************************************************************************
1170 * OLEFontImpl_IDispatch_QueryInterface (IUnknown)
1172 * See Windows documentation for more details on IUnknown methods.
1174 static HRESULT WINAPI OLEFontImpl_IDispatch_QueryInterface(
1179 OLEFontImpl *this = impl_from_IDispatch(iface);
1181 return IFont_QueryInterface((IFont *)this, riid, ppvoid);
1184 /************************************************************************
1185 * OLEFontImpl_IDispatch_Release (IUnknown)
1187 * See Windows documentation for more details on IUnknown methods.
1189 static ULONG WINAPI OLEFontImpl_IDispatch_Release(
1192 OLEFontImpl *this = impl_from_IDispatch(iface);
1194 return IFont_Release((IFont *)this);
1197 /************************************************************************
1198 * OLEFontImpl_IDispatch_AddRef (IUnknown)
1200 * See Windows documentation for more details on IUnknown methods.
1202 static ULONG WINAPI OLEFontImpl_IDispatch_AddRef(
1205 OLEFontImpl *this = impl_from_IDispatch(iface);
1207 return IFont_AddRef((IFont *)this);
1210 /************************************************************************
1211 * OLEFontImpl_GetTypeInfoCount (IDispatch)
1213 * See Windows documentation for more details on IDispatch methods.
1215 static HRESULT WINAPI OLEFontImpl_GetTypeInfoCount(
1217 unsigned int* pctinfo)
1219 OLEFontImpl *this = impl_from_IDispatch(iface);
1220 FIXME("(%p)->(%p): Stub\n", this, pctinfo);
1225 /************************************************************************
1226 * OLEFontImpl_GetTypeInfo (IDispatch)
1228 * See Windows documentation for more details on IDispatch methods.
1230 static HRESULT WINAPI OLEFontImpl_GetTypeInfo(
1234 ITypeInfo** ppTInfo)
1236 static const WCHAR stdole32tlb[] = {'s','t','d','o','l','e','3','2','.','t','l','b',0};
1240 OLEFontImpl *this = impl_from_IDispatch(iface);
1241 TRACE("(%p, iTInfo=%d, lcid=%04x, %p)\n", this, iTInfo, (int)lcid, ppTInfo);
1244 hres = LoadTypeLib(stdole32tlb, &tl);
1246 ERR("Could not load the stdole32.tlb?\n");
1249 hres = ITypeLib_GetTypeInfoOfGuid(tl, &IID_IDispatch, ppTInfo);
1251 FIXME("Did not IDispatch typeinfo from typelib, hres %lx\n",hres);
1256 /************************************************************************
1257 * OLEFontImpl_GetIDsOfNames (IDispatch)
1259 * See Windows documentation for more details on IDispatch methods.
1261 static HRESULT WINAPI OLEFontImpl_GetIDsOfNames(
1264 LPOLESTR* rgszNames,
1269 OLEFontImpl *this = impl_from_IDispatch(iface);
1270 FIXME("(%p,%s,%p,%d,%04x,%p), stub!\n", this, debugstr_guid(riid), rgszNames,
1271 cNames, (int)lcid, rgDispId
1276 /************************************************************************
1277 * OLEFontImpl_Invoke (IDispatch)
1279 * See Windows documentation for more details on IDispatch methods.
1281 * Note: Do not call _put_Xxx methods, since setting things here
1282 * should not call notify functions as I found out debugging the generic
1285 static HRESULT WINAPI OLEFontImpl_Invoke(
1287 DISPID dispIdMember,
1291 DISPPARAMS* pDispParams,
1292 VARIANT* pVarResult,
1293 EXCEPINFO* pExepInfo,
1296 OLEFontImpl *this = impl_from_IDispatch(iface);
1297 OLEFontImpl *xthis = (OLEFontImpl*)this;
1299 switch (dispIdMember) {
1300 case DISPID_FONT_NAME:
1302 case DISPATCH_PROPERTYGET:
1303 case DISPATCH_PROPERTYGET|DISPATCH_METHOD:
1304 V_VT(pVarResult) = VT_BSTR;
1305 return OLEFontImpl_get_Name((IFont *)this, &V_BSTR(pVarResult));
1306 case DISPATCH_PROPERTYPUT: {
1310 if (V_VT(&pDispParams->rgvarg[0]) == VT_DISPATCH) {
1314 hr = IUnknown_QueryInterface(V_DISPATCH(&pDispParams->rgvarg[0]), &IID_IFont, (void **) &font);
1317 FIXME("dispatch value for name property is not an OleFont, returning hr=0x%lx\n", hr);
1321 hr = IFont_get_Name(font, &name); /* this allocates a new BSTR so free it later */
1322 if (FAILED(hr)) return hr;
1324 IUnknown_Release(font);
1327 } else if (V_VT(&pDispParams->rgvarg[0]) == VT_BSTR) {
1328 name = V_BSTR(&pDispParams->rgvarg[0]);
1331 FIXME("app is trying to set name property with a non BSTR, non dispatch value. returning E_FAIL\n");
1335 TRACE("name is %s\n", debugstr_w(name));
1337 if (!xthis->description.lpstrName)
1338 xthis->description.lpstrName = HeapAlloc(GetProcessHeap(), 0, (lstrlenW(name)+1) * sizeof(WCHAR));
1340 xthis->description.lpstrName = HeapReAlloc(GetProcessHeap(), 0, xthis->description.lpstrName, (lstrlenW(name)+1) * sizeof(WCHAR));
1342 if (xthis->description.lpstrName==0)
1343 return E_OUTOFMEMORY;
1344 strcpyW(xthis->description.lpstrName, name);
1346 if (freename) SysFreeString(name);
1352 case DISPID_FONT_BOLD:
1354 case DISPATCH_PROPERTYGET:
1355 case DISPATCH_PROPERTYGET|DISPATCH_METHOD:
1356 V_VT(pVarResult) = VT_BOOL;
1357 return OLEFontImpl_get_Bold((IFont *)this, (BOOL*)&V_BOOL(pVarResult));
1358 case DISPATCH_PROPERTYPUT:
1359 if (V_VT(&pDispParams->rgvarg[0]) != VT_BOOL) {
1360 FIXME("DISPID_FONT_BOLD/put, vt is %d, not VT_BOOL.\n",V_VT(&pDispParams->rgvarg[0]));
1363 xthis->description.sWeight = V_BOOL(&pDispParams->rgvarg[0]) ? FW_BOLD : FW_NORMAL;
1368 case DISPID_FONT_ITALIC:
1370 case DISPATCH_PROPERTYGET:
1371 case DISPATCH_PROPERTYGET|DISPATCH_METHOD:
1372 V_VT(pVarResult) = VT_BOOL;
1373 return OLEFontImpl_get_Italic((IFont *)this, (BOOL*)&V_BOOL(pVarResult));
1374 case DISPATCH_PROPERTYPUT:
1375 if (V_VT(&pDispParams->rgvarg[0]) != VT_BOOL) {
1376 FIXME("DISPID_FONT_ITALIC/put, vt is %d, not VT_BOOL.\n",V_VT(&pDispParams->rgvarg[0]));
1379 xthis->description.fItalic = V_BOOL(&pDispParams->rgvarg[0]);
1384 case DISPID_FONT_UNDER:
1386 case DISPATCH_PROPERTYGET:
1387 case DISPATCH_PROPERTYGET|DISPATCH_METHOD:
1388 V_VT(pVarResult) = VT_BOOL;
1389 return OLEFontImpl_get_Underline((IFont *)this, (BOOL*)&V_BOOL(pVarResult));
1390 case DISPATCH_PROPERTYPUT:
1391 if (V_VT(&pDispParams->rgvarg[0]) != VT_BOOL) {
1392 FIXME("DISPID_FONT_UNDER/put, vt is %d, not VT_BOOL.\n",V_VT(&pDispParams->rgvarg[0]));
1395 xthis->description.fUnderline = V_BOOL(&pDispParams->rgvarg[0]);
1400 case DISPID_FONT_STRIKE:
1402 case DISPATCH_PROPERTYGET:
1403 case DISPATCH_PROPERTYGET|DISPATCH_METHOD:
1404 V_VT(pVarResult) = VT_BOOL;
1405 return OLEFontImpl_get_Strikethrough((IFont *)this, (BOOL*)&V_BOOL(pVarResult));
1406 case DISPATCH_PROPERTYPUT:
1407 if (V_VT(&pDispParams->rgvarg[0]) != VT_BOOL) {
1408 FIXME("DISPID_FONT_STRIKE/put, vt is %d, not VT_BOOL.\n",V_VT(&pDispParams->rgvarg[0]));
1411 xthis->description.fStrikethrough = V_BOOL(&pDispParams->rgvarg[0]);
1416 case DISPID_FONT_SIZE:
1418 case DISPATCH_PROPERTYPUT: {
1419 assert (pDispParams->cArgs == 1);
1420 xthis->description.cySize.s.Hi = 0;
1421 if (V_VT(&pDispParams->rgvarg[0]) != VT_CY) {
1422 if (V_VT(&pDispParams->rgvarg[0]) == VT_I2) {
1423 xthis->description.cySize.s.Lo = V_I2(&pDispParams->rgvarg[0]) * 10000;
1425 FIXME("property put for Size with vt %d unsupported!\n",V_VT(&pDispParams->rgvarg[0]));
1428 xthis->description.cySize.s.Lo = V_CY(&pDispParams->rgvarg[0]).s.Lo;
1432 case DISPATCH_PROPERTYGET:
1433 case DISPATCH_PROPERTYGET|DISPATCH_METHOD:
1434 V_VT(pVarResult) = VT_CY;
1435 return OLEFontImpl_get_Size((IFont *)this, &V_CY(pVarResult));
1438 case DISPID_FONT_CHARSET:
1440 case DISPATCH_PROPERTYPUT:
1441 assert (pDispParams->cArgs == 1);
1442 if (V_VT(&pDispParams->rgvarg[0]) != VT_I2)
1443 FIXME("varg of first disparg is not VT_I2, but %d\n",V_VT(&pDispParams->rgvarg[0]));
1444 xthis->description.sCharset = V_I2(&pDispParams->rgvarg[0]);
1446 case DISPATCH_PROPERTYGET:
1447 case DISPATCH_PROPERTYGET|DISPATCH_METHOD:
1448 V_VT(pVarResult) = VT_I2;
1449 return OLEFontImpl_get_Charset((IFont *)this, &V_I2(pVarResult));
1453 FIXME("%p->(%ld,%s,%lx,%x,%p,%p,%p,%p), unhandled dispid/flag!\n",
1454 this,dispIdMember,debugstr_guid(riid),lcid,
1455 wFlags,pDispParams,pVarResult,pExepInfo,puArgErr
1460 /************************************************************************
1461 * OLEFontImpl_IPersistStream_QueryInterface (IUnknown)
1463 * See Windows documentation for more details on IUnknown methods.
1465 static HRESULT WINAPI OLEFontImpl_IPersistStream_QueryInterface(
1466 IPersistStream* iface,
1470 OLEFontImpl *this = impl_from_IPersistStream(iface);
1472 return IFont_QueryInterface((IFont *)this, riid, ppvoid);
1475 /************************************************************************
1476 * OLEFontImpl_IPersistStream_Release (IUnknown)
1478 * See Windows documentation for more details on IUnknown methods.
1480 static ULONG WINAPI OLEFontImpl_IPersistStream_Release(
1481 IPersistStream* iface)
1483 OLEFontImpl *this = impl_from_IPersistStream(iface);
1485 return IFont_Release((IFont *)this);
1488 /************************************************************************
1489 * OLEFontImpl_IPersistStream_AddRef (IUnknown)
1491 * See Windows documentation for more details on IUnknown methods.
1493 static ULONG WINAPI OLEFontImpl_IPersistStream_AddRef(
1494 IPersistStream* iface)
1496 OLEFontImpl *this = impl_from_IPersistStream(iface);
1498 return IFont_AddRef((IFont *)this);
1501 /************************************************************************
1502 * OLEFontImpl_GetClassID (IPersistStream)
1504 * See Windows documentation for more details on IPersistStream methods.
1506 static HRESULT WINAPI OLEFontImpl_GetClassID(
1507 IPersistStream* iface,
1510 TRACE("(%p,%p)\n",iface,pClassID);
1514 memcpy(pClassID, &CLSID_StdFont, sizeof(CLSID_StdFont));
1519 /************************************************************************
1520 * OLEFontImpl_IsDirty (IPersistStream)
1522 * See Windows documentation for more details on IPersistStream methods.
1524 static HRESULT WINAPI OLEFontImpl_IsDirty(
1525 IPersistStream* iface)
1527 TRACE("(%p)\n",iface);
1531 /************************************************************************
1532 * OLEFontImpl_Load (IPersistStream)
1534 * See Windows documentation for more details on IPersistStream methods.
1536 * This is the format of the standard font serialization as far as I
1539 * Offset Type Value Comment
1540 * 0x0000 Byte Unknown Probably a version number, contains 0x01
1541 * 0x0001 Short Charset Charset value from the FONTDESC structure
1542 * 0x0003 Byte Attributes Flags defined as follows:
1544 * 00000100 - Underline
1545 * 00001000 - Strikethrough
1546 * 0x0004 Short Weight Weight value from FONTDESC structure
1547 * 0x0006 DWORD size "Low" portion of the cySize member of the FONTDESC
1549 * 0x000A Byte name length Length of the font name string (no null character)
1550 * 0x000B String name Name of the font (ASCII, no nul character)
1552 static HRESULT WINAPI OLEFontImpl_Load(
1553 IPersistStream* iface,
1554 IStream* pLoadStream)
1556 char readBuffer[0x100];
1563 OLEFontImpl *this = impl_from_IPersistStream(iface);
1566 * Read the version byte
1568 IStream_Read(pLoadStream, &bVersion, 1, &cbRead);
1577 IStream_Read(pLoadStream, &this->description.sCharset, 2, &cbRead);
1585 IStream_Read(pLoadStream, &bAttributes, 1, &cbRead);
1590 this->description.fItalic = (bAttributes & FONTPERSIST_ITALIC) != 0;
1591 this->description.fStrikethrough = (bAttributes & FONTPERSIST_STRIKETHROUGH) != 0;
1592 this->description.fUnderline = (bAttributes & FONTPERSIST_UNDERLINE) != 0;
1597 IStream_Read(pLoadStream, &this->description.sWeight, 2, &cbRead);
1605 IStream_Read(pLoadStream, &this->description.cySize.s.Lo, 4, &cbRead);
1610 this->description.cySize.s.Hi = 0;
1615 IStream_Read(pLoadStream, &bStringSize, 1, &cbRead);
1620 IStream_Read(pLoadStream, readBuffer, bStringSize, &cbRead);
1622 if (cbRead!=bStringSize)
1625 HeapFree(GetProcessHeap(), 0, this->description.lpstrName);
1627 len = MultiByteToWideChar( CP_ACP, 0, readBuffer, bStringSize, NULL, 0 );
1628 this->description.lpstrName = HeapAlloc( GetProcessHeap(), 0, (len+1) * sizeof(WCHAR) );
1629 MultiByteToWideChar( CP_ACP, 0, readBuffer, bStringSize, this->description.lpstrName, len );
1630 this->description.lpstrName[len] = 0;
1632 /* Ensure use of this font causes a new one to be created @@@@ */
1633 DeleteObject(this->gdiFont);
1639 /************************************************************************
1640 * OLEFontImpl_Save (IPersistStream)
1642 * See Windows documentation for more details on IPersistStream methods.
1644 static HRESULT WINAPI OLEFontImpl_Save(
1645 IPersistStream* iface,
1646 IStream* pOutStream,
1649 char* writeBuffer = NULL;
1651 BYTE bVersion = 0x01;
1655 OLEFontImpl *this = impl_from_IPersistStream(iface);
1658 * Read the version byte
1660 IStream_Write(pOutStream, &bVersion, 1, &cbWritten);
1668 IStream_Write(pOutStream, &this->description.sCharset, 2, &cbWritten);
1678 if (this->description.fItalic)
1679 bAttributes |= FONTPERSIST_ITALIC;
1681 if (this->description.fStrikethrough)
1682 bAttributes |= FONTPERSIST_STRIKETHROUGH;
1684 if (this->description.fUnderline)
1685 bAttributes |= FONTPERSIST_UNDERLINE;
1687 IStream_Write(pOutStream, &bAttributes, 1, &cbWritten);
1695 IStream_Write(pOutStream, &this->description.sWeight, 2, &cbWritten);
1703 IStream_Write(pOutStream, &this->description.cySize.s.Lo, 4, &cbWritten);
1711 if (this->description.lpstrName!=0)
1712 bStringSize = WideCharToMultiByte( CP_ACP, 0, this->description.lpstrName,
1713 strlenW(this->description.lpstrName), NULL, 0, NULL, NULL );
1717 IStream_Write(pOutStream, &bStringSize, 1, &cbWritten);
1724 if (!(writeBuffer = HeapAlloc( GetProcessHeap(), 0, bStringSize ))) return E_OUTOFMEMORY;
1725 WideCharToMultiByte( CP_ACP, 0, this->description.lpstrName,
1726 strlenW(this->description.lpstrName),
1727 writeBuffer, bStringSize, NULL, NULL );
1729 IStream_Write(pOutStream, writeBuffer, bStringSize, &cbWritten);
1730 HeapFree(GetProcessHeap(), 0, writeBuffer);
1732 if (cbWritten!=bStringSize)
1739 /************************************************************************
1740 * OLEFontImpl_GetSizeMax (IPersistStream)
1742 * See Windows documentation for more details on IPersistStream methods.
1744 static HRESULT WINAPI OLEFontImpl_GetSizeMax(
1745 IPersistStream* iface,
1746 ULARGE_INTEGER* pcbSize)
1748 OLEFontImpl *this = impl_from_IPersistStream(iface);
1753 pcbSize->u.HighPart = 0;
1754 pcbSize->u.LowPart = 0;
1756 pcbSize->u.LowPart += sizeof(BYTE); /* Version */
1757 pcbSize->u.LowPart += sizeof(WORD); /* Lang code */
1758 pcbSize->u.LowPart += sizeof(BYTE); /* Flags */
1759 pcbSize->u.LowPart += sizeof(WORD); /* Weight */
1760 pcbSize->u.LowPart += sizeof(DWORD); /* Size */
1761 pcbSize->u.LowPart += sizeof(BYTE); /* StrLength */
1763 if (this->description.lpstrName!=0)
1764 pcbSize->u.LowPart += lstrlenW(this->description.lpstrName);
1769 /************************************************************************
1770 * OLEFontImpl_IConnectionPointContainer_QueryInterface (IUnknown)
1772 * See Windows documentation for more details on IUnknown methods.
1774 static HRESULT WINAPI OLEFontImpl_IConnectionPointContainer_QueryInterface(
1775 IConnectionPointContainer* iface,
1779 OLEFontImpl *this = impl_from_IConnectionPointContainer(iface);
1781 return IFont_QueryInterface((IFont*)this, riid, ppvoid);
1784 /************************************************************************
1785 * OLEFontImpl_IConnectionPointContainer_Release (IUnknown)
1787 * See Windows documentation for more details on IUnknown methods.
1789 static ULONG WINAPI OLEFontImpl_IConnectionPointContainer_Release(
1790 IConnectionPointContainer* iface)
1792 OLEFontImpl *this = impl_from_IConnectionPointContainer(iface);
1794 return IFont_Release((IFont*)this);
1797 /************************************************************************
1798 * OLEFontImpl_IConnectionPointContainer_AddRef (IUnknown)
1800 * See Windows documentation for more details on IUnknown methods.
1802 static ULONG WINAPI OLEFontImpl_IConnectionPointContainer_AddRef(
1803 IConnectionPointContainer* iface)
1805 OLEFontImpl *this = impl_from_IConnectionPointContainer(iface);
1807 return IFont_AddRef((IFont*)this);
1810 /************************************************************************
1811 * OLEFontImpl_EnumConnectionPoints (IConnectionPointContainer)
1813 * See Windows documentation for more details on IConnectionPointContainer
1816 static HRESULT WINAPI OLEFontImpl_EnumConnectionPoints(
1817 IConnectionPointContainer* iface,
1818 IEnumConnectionPoints **ppEnum)
1820 OLEFontImpl *this = impl_from_IConnectionPointContainer(iface);
1822 FIXME("(%p)->(%p): stub\n", this, ppEnum);
1826 /************************************************************************
1827 * OLEFontImpl_FindConnectionPoint (IConnectionPointContainer)
1829 * See Windows documentation for more details on IConnectionPointContainer
1832 static HRESULT WINAPI OLEFontImpl_FindConnectionPoint(
1833 IConnectionPointContainer* iface,
1835 IConnectionPoint **ppCp)
1837 OLEFontImpl *this = impl_from_IConnectionPointContainer(iface);
1838 TRACE("(%p)->(%s, %p): stub\n", this, debugstr_guid(riid), ppCp);
1840 if(memcmp(riid, &IID_IPropertyNotifySink, sizeof(IID_IPropertyNotifySink)) == 0) {
1841 return IConnectionPoint_QueryInterface(this->pCP, &IID_IConnectionPoint,
1844 FIXME("Tried to find connection point on %s\n", debugstr_guid(riid));
1845 return E_NOINTERFACE;
1849 /************************************************************************
1850 * OLEFontImpl implementation of IPersistPropertyBag.
1852 static HRESULT WINAPI OLEFontImpl_IPersistPropertyBag_QueryInterface(
1853 IPersistPropertyBag *iface, REFIID riid, LPVOID *ppvObj
1855 OLEFontImpl *this = impl_from_IPersistPropertyBag(iface);
1856 return IFont_QueryInterface((IFont *)this,riid,ppvObj);
1859 static ULONG WINAPI OLEFontImpl_IPersistPropertyBag_AddRef(
1860 IPersistPropertyBag *iface
1862 OLEFontImpl *this = impl_from_IPersistPropertyBag(iface);
1863 return IFont_AddRef((IFont *)this);
1866 static ULONG WINAPI OLEFontImpl_IPersistPropertyBag_Release(
1867 IPersistPropertyBag *iface
1869 OLEFontImpl *this = impl_from_IPersistPropertyBag(iface);
1870 return IFont_Release((IFont *)this);
1873 static HRESULT WINAPI OLEFontImpl_IPersistPropertyBag_GetClassID(
1874 IPersistPropertyBag *iface, CLSID *classid
1876 FIXME("(%p,%p), stub!\n", iface, classid);
1880 static HRESULT WINAPI OLEFontImpl_IPersistPropertyBag_InitNew(
1881 IPersistPropertyBag *iface
1883 FIXME("(%p), stub!\n", iface);
1887 static HRESULT WINAPI OLEFontImpl_IPersistPropertyBag_Load(
1888 IPersistPropertyBag *iface, IPropertyBag* pPropBag, IErrorLog* pErrorLog
1890 /* (from Visual Basic 6 property bag)
1891 Name = "MS Sans Serif"
1895 Underline = 0 'False
1897 Strikethrough = 0 'False
1899 static const WCHAR sAttrName[] = {'N','a','m','e',0};
1900 static const WCHAR sAttrSize[] = {'S','i','z','e',0};
1901 static const WCHAR sAttrCharset[] = {'C','h','a','r','s','e','t',0};
1902 static const WCHAR sAttrWeight[] = {'W','e','i','g','h','t',0};
1903 static const WCHAR sAttrUnderline[] = {'U','n','d','e','r','l','i','n','e',0};
1904 static const WCHAR sAttrItalic[] = {'I','t','a','l','i','c',0};
1905 static const WCHAR sAttrStrikethrough[] = {'S','t','r','i','k','e','t','h','r','o','u','g','h',0};
1908 HRESULT iRes = S_OK;
1909 OLEFontImpl *this = impl_from_IPersistPropertyBag(iface);
1911 VariantInit(&rawAttr);
1912 VariantInit(&valueAttr);
1915 iRes = IPropertyBag_Read(pPropBag, sAttrName, &rawAttr, pErrorLog);
1918 iRes = VariantChangeType(&rawAttr, &valueAttr, 0, VT_BSTR);
1920 iRes = IFont_put_Name((IFont *)this, V_BSTR(&valueAttr));
1922 else if (iRes == E_INVALIDARG)
1924 VariantClear(&rawAttr);
1925 VariantClear(&valueAttr);
1929 iRes = IPropertyBag_Read(pPropBag, sAttrSize, &rawAttr, pErrorLog);
1932 iRes = VariantChangeType(&rawAttr, &valueAttr, 0, VT_CY);
1934 iRes = IFont_put_Size((IFont *)this, V_CY(&valueAttr));
1936 else if (iRes == E_INVALIDARG)
1938 VariantClear(&rawAttr);
1939 VariantClear(&valueAttr);
1943 iRes = IPropertyBag_Read(pPropBag, sAttrCharset, &rawAttr, pErrorLog);
1946 iRes = VariantChangeType(&rawAttr, &valueAttr, 0, VT_I2);
1948 iRes = IFont_put_Charset((IFont *)this, V_I2(&valueAttr));
1950 else if (iRes == E_INVALIDARG)
1952 VariantClear(&rawAttr);
1953 VariantClear(&valueAttr);
1957 iRes = IPropertyBag_Read(pPropBag, sAttrWeight, &rawAttr, pErrorLog);
1960 iRes = VariantChangeType(&rawAttr, &valueAttr, 0, VT_I2);
1962 iRes = IFont_put_Weight((IFont *)this, V_I2(&valueAttr));
1964 else if (iRes == E_INVALIDARG)
1966 VariantClear(&rawAttr);
1967 VariantClear(&valueAttr);
1972 iRes = IPropertyBag_Read(pPropBag, sAttrUnderline, &rawAttr, pErrorLog);
1975 iRes = VariantChangeType(&rawAttr, &valueAttr, 0, VT_BOOL);
1977 iRes = IFont_put_Underline((IFont *)this, V_BOOL(&valueAttr));
1979 else if (iRes == E_INVALIDARG)
1981 VariantClear(&rawAttr);
1982 VariantClear(&valueAttr);
1986 iRes = IPropertyBag_Read(pPropBag, sAttrItalic, &rawAttr, pErrorLog);
1989 iRes = VariantChangeType(&rawAttr, &valueAttr, 0, VT_BOOL);
1991 iRes = IFont_put_Italic((IFont *)this, V_BOOL(&valueAttr));
1993 else if (iRes == E_INVALIDARG)
1995 VariantClear(&rawAttr);
1996 VariantClear(&valueAttr);
2000 iRes = IPropertyBag_Read(pPropBag, sAttrStrikethrough, &rawAttr, pErrorLog);
2003 iRes = VariantChangeType(&rawAttr, &valueAttr, 0, VT_BOOL);
2005 IFont_put_Strikethrough((IFont *)this, V_BOOL(&valueAttr));
2007 else if (iRes == E_INVALIDARG)
2009 VariantClear(&rawAttr);
2010 VariantClear(&valueAttr);
2014 WARN("-- 0x%08lx\n", iRes);
2018 static HRESULT WINAPI OLEFontImpl_IPersistPropertyBag_Save(
2019 IPersistPropertyBag *iface, IPropertyBag* pPropBag, BOOL fClearDirty,
2020 BOOL fSaveAllProperties
2022 FIXME("(%p,%p,%d,%d), stub!\n", iface, pPropBag, fClearDirty, fSaveAllProperties);
2026 static const IPersistPropertyBagVtbl OLEFontImpl_IPersistPropertyBag_VTable =
2028 OLEFontImpl_IPersistPropertyBag_QueryInterface,
2029 OLEFontImpl_IPersistPropertyBag_AddRef,
2030 OLEFontImpl_IPersistPropertyBag_Release,
2032 OLEFontImpl_IPersistPropertyBag_GetClassID,
2033 OLEFontImpl_IPersistPropertyBag_InitNew,
2034 OLEFontImpl_IPersistPropertyBag_Load,
2035 OLEFontImpl_IPersistPropertyBag_Save
2038 /************************************************************************
2039 * OLEFontImpl implementation of IPersistStreamInit.
2041 static HRESULT WINAPI OLEFontImpl_IPersistStreamInit_QueryInterface(
2042 IPersistStreamInit *iface, REFIID riid, LPVOID *ppvObj
2044 OLEFontImpl *this = impl_from_IPersistStreamInit(iface);
2045 return IFont_QueryInterface((IFont *)this,riid,ppvObj);
2048 static ULONG WINAPI OLEFontImpl_IPersistStreamInit_AddRef(
2049 IPersistStreamInit *iface
2051 OLEFontImpl *this = impl_from_IPersistStreamInit(iface);
2052 return IFont_AddRef((IFont *)this);
2055 static ULONG WINAPI OLEFontImpl_IPersistStreamInit_Release(
2056 IPersistStreamInit *iface
2058 OLEFontImpl *this = impl_from_IPersistStreamInit(iface);
2059 return IFont_Release((IFont *)this);
2062 static HRESULT WINAPI OLEFontImpl_IPersistStreamInit_GetClassID(
2063 IPersistStreamInit *iface, CLSID *classid
2065 FIXME("(%p,%p), stub!\n", iface, classid);
2069 static HRESULT WINAPI OLEFontImpl_IPersistStreamInit_IsDirty(
2070 IPersistStreamInit *iface
2072 FIXME("(%p), stub!\n", iface);
2076 static HRESULT WINAPI OLEFontImpl_IPersistStreamInit_Load(
2077 IPersistStreamInit *iface, LPSTREAM pStm
2079 FIXME("(%p,%p), stub!\n", iface, pStm);
2083 static HRESULT WINAPI OLEFontImpl_IPersistStreamInit_Save(
2084 IPersistStreamInit *iface, LPSTREAM pStm, BOOL fClearDirty
2086 FIXME("(%p,%p,%d), stub!\n", iface, pStm, fClearDirty);
2090 static HRESULT WINAPI OLEFontImpl_IPersistStreamInit_GetSizeMax(
2091 IPersistStreamInit *iface, ULARGE_INTEGER *pcbSize
2093 FIXME("(%p,%p), stub!\n", iface, pcbSize);
2097 static HRESULT WINAPI OLEFontImpl_IPersistStreamInit_InitNew(
2098 IPersistStreamInit *iface
2100 FIXME("(%p), stub!\n", iface);
2104 static const IPersistStreamInitVtbl OLEFontImpl_IPersistStreamInit_VTable =
2106 OLEFontImpl_IPersistStreamInit_QueryInterface,
2107 OLEFontImpl_IPersistStreamInit_AddRef,
2108 OLEFontImpl_IPersistStreamInit_Release,
2110 OLEFontImpl_IPersistStreamInit_GetClassID,
2111 OLEFontImpl_IPersistStreamInit_IsDirty,
2112 OLEFontImpl_IPersistStreamInit_Load,
2113 OLEFontImpl_IPersistStreamInit_Save,
2114 OLEFontImpl_IPersistStreamInit_GetSizeMax,
2115 OLEFontImpl_IPersistStreamInit_InitNew
2118 /*******************************************************************************
2119 * StdFont ClassFactory
2123 /* IUnknown fields */
2124 const IClassFactoryVtbl *lpVtbl;
2126 } IClassFactoryImpl;
2128 static HRESULT WINAPI
2129 SFCF_QueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj) {
2130 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
2132 FIXME("(%p)->(%s,%p),stub!\n",This,debugstr_guid(riid),ppobj);
2133 return E_NOINTERFACE;
2137 SFCF_AddRef(LPCLASSFACTORY iface) {
2138 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
2139 return InterlockedIncrement(&This->ref);
2142 static ULONG WINAPI SFCF_Release(LPCLASSFACTORY iface) {
2143 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
2144 /* static class, won't be freed */
2145 return InterlockedDecrement(&This->ref);
2148 static HRESULT WINAPI SFCF_CreateInstance(
2149 LPCLASSFACTORY iface,LPUNKNOWN pOuter,REFIID riid,LPVOID *ppobj
2151 return OleCreateFontIndirect(NULL,riid,ppobj);
2155 static HRESULT WINAPI SFCF_LockServer(LPCLASSFACTORY iface,BOOL dolock) {
2156 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
2157 FIXME("(%p)->(%d),stub!\n",This,dolock);
2161 static const IClassFactoryVtbl SFCF_Vtbl = {
2162 SFCF_QueryInterface,
2165 SFCF_CreateInstance,
2168 static IClassFactoryImpl STDFONT_CF = {&SFCF_Vtbl, 1 };
2170 void _get_STDFONT_CF(LPVOID *ppv) { *ppv = (LPVOID)&STDFONT_CF; }