2 * OLE Font encapsulation implementation
4 * This file contains an implementation of the IFont
5 * interface and the OleCreateFontIndirect API call.
7 * Copyright 1999 Francis Beaudet
8 * Copyright 2006 (Google) Benjamin Arai
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
29 #define NONAMELESSUNION
30 #define NONAMELESSSTRUCT
37 #include "wine/list.h"
38 #include "wine/unicode.h"
40 #include "oleauto.h" /* for SysAllocString(....) */
43 #include "wine/debug.h"
44 #include "connpt.h" /* for CreateConnectionPoint */
47 WINE_DEFAULT_DEBUG_CHANNEL(ole);
49 /***********************************************************************
50 * Declaration of constants used when serializing the font object.
52 #define FONTPERSIST_ITALIC 0x02
53 #define FONTPERSIST_UNDERLINE 0x04
54 #define FONTPERSIST_STRIKETHROUGH 0x08
57 /***********************************************************************
58 * List of the HFONTs it has given out, with each one having a separate
61 typedef struct _HFONTItem
65 /* Reference count of any IFont objects that own this hfont */
68 /* Total reference count of any refs held by the application obtained by AddRefHfont plus any internal refs */
71 /* The font associated with this object. */
74 } HFONTItem, *PHFONTItem;
76 static struct list OLEFontImpl_hFontList = LIST_INIT(OLEFontImpl_hFontList);
78 /* Counts how many fonts contain at least one lock */
79 static LONG ifont_cnt = 0;
81 /***********************************************************************
82 * Critical section for OLEFontImpl_hFontList
84 static CRITICAL_SECTION OLEFontImpl_csHFONTLIST;
85 static CRITICAL_SECTION_DEBUG OLEFontImpl_csHFONTLIST_debug =
87 0, 0, &OLEFontImpl_csHFONTLIST,
88 { &OLEFontImpl_csHFONTLIST_debug.ProcessLocksList,
89 &OLEFontImpl_csHFONTLIST_debug.ProcessLocksList },
90 0, 0, { (DWORD_PTR)(__FILE__ ": OLEFontImpl_csHFONTLIST") }
92 static CRITICAL_SECTION OLEFontImpl_csHFONTLIST = { &OLEFontImpl_csHFONTLIST_debug, -1, 0, 0, 0, 0 };
94 static void HFONTItem_Delete(PHFONTItem item)
96 DeleteObject(item->gdiFont);
97 list_remove(&item->entry);
98 HeapFree(GetProcessHeap(), 0, item);
101 /* Find hfont item entry in the list. Should be called while holding the crit sect */
102 static HFONTItem *find_hfontitem(HFONT hfont)
106 LIST_FOR_EACH_ENTRY(item, &OLEFontImpl_hFontList, HFONTItem, entry)
108 if (item->gdiFont == hfont)
114 static HRESULT inc_int_ref(HFONT hfont)
117 HRESULT hr = S_FALSE;
119 EnterCriticalSection(&OLEFontImpl_csHFONTLIST);
120 item = find_hfontitem(hfont);
128 LeaveCriticalSection(&OLEFontImpl_csHFONTLIST);
133 /* decrements the internal ref of a hfont item. If both refs are zero it'll
134 remove the item from the list and delete the hfont */
135 static HRESULT dec_int_ref(HFONT hfont)
138 HRESULT hr = S_FALSE;
140 EnterCriticalSection(&OLEFontImpl_csHFONTLIST);
141 item = find_hfontitem(hfont);
147 if(item->int_refs == 0 && item->total_refs == 0)
148 HFONTItem_Delete(item);
151 LeaveCriticalSection(&OLEFontImpl_csHFONTLIST);
156 static HRESULT inc_ext_ref(HFONT hfont)
159 HRESULT hr = S_FALSE;
161 EnterCriticalSection(&OLEFontImpl_csHFONTLIST);
163 item = find_hfontitem(hfont);
169 LeaveCriticalSection(&OLEFontImpl_csHFONTLIST);
174 static HRESULT dec_ext_ref(HFONT hfont)
177 HRESULT hr = S_FALSE;
179 EnterCriticalSection(&OLEFontImpl_csHFONTLIST);
181 item = find_hfontitem(hfont);
184 if(--item->total_refs >= 0) hr = S_OK;
186 LeaveCriticalSection(&OLEFontImpl_csHFONTLIST);
191 /***********************************************************************
192 * Declaration of the implementation class for the IFont interface
194 typedef struct OLEFontImpl OLEFontImpl;
199 * This class supports many interfaces. IUnknown, IFont,
200 * IDispatch, IDispFont IPersistStream and IConnectionPointContainer.
201 * The first two are supported by the first vtable, the next two are
202 * supported by the second table and the last two have their own.
204 const IFontVtbl* lpVtbl;
205 const IDispatchVtbl* lpvtblIDispatch;
206 const IPersistStreamVtbl* lpvtblIPersistStream;
207 const IConnectionPointContainerVtbl* lpvtblIConnectionPointContainer;
208 const IPersistPropertyBagVtbl* lpvtblIPersistPropertyBag;
209 const IPersistStreamInitVtbl* lpvtblIPersistStreamInit;
211 * Reference count for that instance of the class.
216 * This structure contains the description of the class.
218 FONTDESC description;
221 * Contain the font associated with this object.
231 IConnectionPoint *pPropertyNotifyCP;
232 IConnectionPoint *pFontEventsCP;
236 * Here, I define utility macros to help with the casting of the
238 * There is a version to accommodate all of the VTables implemented
242 static inline OLEFontImpl *impl_from_IDispatch( IDispatch *iface )
244 return (OLEFontImpl *)((char*)iface - FIELD_OFFSET(OLEFontImpl, lpvtblIDispatch));
247 static inline OLEFontImpl *impl_from_IPersistStream( IPersistStream *iface )
249 return (OLEFontImpl *)((char*)iface - FIELD_OFFSET(OLEFontImpl, lpvtblIPersistStream));
252 static inline OLEFontImpl *impl_from_IConnectionPointContainer( IConnectionPointContainer *iface )
254 return (OLEFontImpl *)((char*)iface - FIELD_OFFSET(OLEFontImpl, lpvtblIConnectionPointContainer));
257 static inline OLEFontImpl *impl_from_IPersistPropertyBag( IPersistPropertyBag *iface )
259 return (OLEFontImpl *)((char*)iface - FIELD_OFFSET(OLEFontImpl, lpvtblIPersistPropertyBag));
262 static inline OLEFontImpl *impl_from_IPersistStreamInit( IPersistStreamInit *iface )
264 return (OLEFontImpl *)((char*)iface - FIELD_OFFSET(OLEFontImpl, lpvtblIPersistStreamInit));
268 /***********************************************************************
269 * Prototypes for the implementation functions for the IFont
272 static OLEFontImpl* OLEFontImpl_Construct(const FONTDESC *fontDesc);
273 static void OLEFontImpl_Destroy(OLEFontImpl* fontDesc);
274 static ULONG WINAPI OLEFontImpl_AddRef(IFont* iface);
276 /******************************************************************************
277 * OleCreateFontIndirect [OLEAUT32.420]
279 HRESULT WINAPI OleCreateFontIndirect(
280 LPFONTDESC lpFontDesc,
284 OLEFontImpl* newFont = 0;
287 TRACE("(%p, %s, %p)\n", lpFontDesc, debugstr_guid(riid), ppvObj);
299 static WCHAR fname[] = { 'S','y','s','t','e','m',0 };
301 fd.cbSizeofstruct = sizeof(fd);
302 fd.lpstrName = fname;
303 fd.cySize.s.Lo = 80000;
309 fd.fStrikethrough = 0;
314 * Try to construct a new instance of the class.
316 newFont = OLEFontImpl_Construct(lpFontDesc);
319 return E_OUTOFMEMORY;
322 * Make sure it supports the interface required by the caller.
324 hr = IFont_QueryInterface((IFont*)newFont, riid, ppvObj);
327 * Release the reference obtained in the constructor. If
328 * the QueryInterface was unsuccessful, it will free the class.
330 IFont_Release((IFont*)newFont);
336 /***********************************************************************
337 * Implementation of the OLEFontImpl class.
340 /***********************************************************************
341 * OLEFont_SendNotify (internal)
343 * Sends notification messages of changed properties to any interested
346 static void OLEFont_SendNotify(OLEFontImpl* this, DISPID dispID)
348 static const WCHAR wszName[] = {'N','a','m','e',0};
349 static const WCHAR wszSize[] = {'S','i','z','e',0};
350 static const WCHAR wszBold[] = {'B','o','l','d',0};
351 static const WCHAR wszItalic[] = {'I','t','a','l','i','c',0};
352 static const WCHAR wszUnder[] = {'U','n','d','e','r','l','i','n','e',0};
353 static const WCHAR wszStrike[] = {'S','t','r','i','k','e','t','h','r','o','u','g','h',0};
354 static const WCHAR wszWeight[] = {'W','e','i','g','h','t',0};
355 static const WCHAR wszCharset[] = {'C','h','a','r','s','s','e','t',0};
356 static const LPCWSTR dispid_mapping[] =
369 IEnumConnections *pEnum;
373 dec_int_ref(this->gdiFont);
375 hres = IConnectionPoint_EnumConnections(this->pPropertyNotifyCP, &pEnum);
378 while(IEnumConnections_Next(pEnum, 1, &CD, NULL) == S_OK) {
379 IPropertyNotifySink *sink;
381 IUnknown_QueryInterface(CD.pUnk, &IID_IPropertyNotifySink, (LPVOID)&sink);
382 IPropertyNotifySink_OnChanged(sink, dispID);
383 IPropertyNotifySink_Release(sink);
384 IUnknown_Release(CD.pUnk);
386 IEnumConnections_Release(pEnum);
389 hres = IConnectionPoint_EnumConnections(this->pFontEventsCP, &pEnum);
392 DISPPARAMS dispparams;
395 VariantInit(&vararg);
396 V_VT(&vararg) = VT_BSTR;
397 V_BSTR(&vararg) = SysAllocString(dispid_mapping[dispID]);
399 dispparams.cArgs = 1;
400 dispparams.cNamedArgs = 0;
401 dispparams.rgdispidNamedArgs = NULL;
402 dispparams.rgvarg = &vararg;
404 while(IEnumConnections_Next(pEnum, 1, &CD, NULL) == S_OK) {
405 IFontEventsDisp *disp;
407 IUnknown_QueryInterface(CD.pUnk, &IID_IFontEventsDisp, (LPVOID)&disp);
408 IDispatch_Invoke(disp, DISPID_FONT_CHANGED, &IID_NULL,
409 LOCALE_NEUTRAL, INVOKE_FUNC, &dispparams, NULL,
412 IDispatch_Release(disp);
413 IUnknown_Release(CD.pUnk);
415 VariantClear(&vararg);
416 IEnumConnections_Release(pEnum);
420 /************************************************************************
421 * OLEFontImpl_QueryInterface (IUnknown)
423 * See Windows documentation for more details on IUnknown methods.
425 static HRESULT WINAPI OLEFontImpl_QueryInterface(
430 OLEFontImpl *this = (OLEFontImpl *)iface;
431 TRACE("(%p)->(%s, %p)\n", this, debugstr_guid(riid), ppvObject);
434 * Perform a sanity check on the parameters.
436 if ( (this==0) || (ppvObject==0) )
440 * Initialize the return parameter.
445 * Compare the riid with the interface IDs implemented by this object.
447 if (IsEqualGUID(&IID_IUnknown, riid))
449 if (IsEqualGUID(&IID_IFont, riid))
451 if (IsEqualGUID(&IID_IDispatch, riid))
452 *ppvObject = &this->lpvtblIDispatch;
453 if (IsEqualGUID(&IID_IFontDisp, riid))
454 *ppvObject = &this->lpvtblIDispatch;
455 if (IsEqualIID(&IID_IPersist, riid) || IsEqualGUID(&IID_IPersistStream, riid))
456 *ppvObject = &this->lpvtblIPersistStream;
457 if (IsEqualGUID(&IID_IConnectionPointContainer, riid))
458 *ppvObject = &this->lpvtblIConnectionPointContainer;
459 if (IsEqualGUID(&IID_IPersistPropertyBag, riid))
460 *ppvObject = &this->lpvtblIPersistPropertyBag;
461 if (IsEqualGUID(&IID_IPersistStreamInit, riid))
462 *ppvObject = &this->lpvtblIPersistStreamInit;
465 * Check that we obtained an interface.
469 FIXME("() : asking for unsupported interface %s\n",debugstr_guid(riid));
470 return E_NOINTERFACE;
472 OLEFontImpl_AddRef((IFont*)this);
476 /************************************************************************
477 * OLEFontImpl_AddRef (IUnknown)
479 * See Windows documentation for more details on IUnknown methods.
481 static ULONG WINAPI OLEFontImpl_AddRef(
484 OLEFontImpl *this = (OLEFontImpl *)iface;
485 TRACE("(%p)->(ref=%d)\n", this, this->ref);
486 return InterlockedIncrement(&this->ref);
489 /************************************************************************
490 * OLEFontImpl_Release (IUnknown)
492 * See Windows documentation for more details on IUnknown methods.
494 static ULONG WINAPI OLEFontImpl_Release(
497 OLEFontImpl *this = (OLEFontImpl *)iface;
499 TRACE("(%p)->(ref=%d)\n", this, this->ref);
501 /* Decrease the reference count for current interface */
502 ret = InterlockedDecrement(&this->ref);
504 /* If the reference count goes down to 0, destroy. */
507 ULONG fontlist_refs = InterlockedDecrement(&ifont_cnt);
509 /* Final IFont object so destroy font cache */
510 if (fontlist_refs == 0)
512 HFONTItem *item, *cursor2;
514 EnterCriticalSection(&OLEFontImpl_csHFONTLIST);
515 LIST_FOR_EACH_ENTRY_SAFE(item, cursor2, &OLEFontImpl_hFontList, HFONTItem, entry)
516 HFONTItem_Delete(item);
517 LeaveCriticalSection(&OLEFontImpl_csHFONTLIST);
521 dec_int_ref(this->gdiFont);
523 OLEFontImpl_Destroy(this);
529 /************************************************************************
530 * OLEFontImpl_get_Name (IFont)
532 * See Windows documentation for more details on IFont methods.
534 static HRESULT WINAPI OLEFontImpl_get_Name(
538 OLEFontImpl *this = (OLEFontImpl *)iface;
539 TRACE("(%p)->(%p)\n", this, pname);
546 if (this->description.lpstrName!=0)
547 *pname = SysAllocString(this->description.lpstrName);
554 /************************************************************************
555 * OLEFontImpl_put_Name (IFont)
557 * See Windows documentation for more details on IFont methods.
559 static HRESULT WINAPI OLEFontImpl_put_Name(
563 OLEFontImpl *this = (OLEFontImpl *)iface;
564 TRACE("(%p)->(%p)\n", this, name);
567 return CTL_E_INVALIDPROPERTYVALUE;
569 if (this->description.lpstrName==0)
571 this->description.lpstrName = HeapAlloc(GetProcessHeap(),
573 (lstrlenW(name)+1) * sizeof(WCHAR));
577 this->description.lpstrName = HeapReAlloc(GetProcessHeap(),
579 this->description.lpstrName,
580 (lstrlenW(name)+1) * sizeof(WCHAR));
583 if (this->description.lpstrName==0)
584 return E_OUTOFMEMORY;
586 strcpyW(this->description.lpstrName, name);
587 TRACE("new name %s\n", debugstr_w(this->description.lpstrName));
588 OLEFont_SendNotify(this, DISPID_FONT_NAME);
592 /************************************************************************
593 * OLEFontImpl_get_Size (IFont)
595 * See Windows documentation for more details on IFont methods.
597 static HRESULT WINAPI OLEFontImpl_get_Size(
601 OLEFontImpl *this = (OLEFontImpl *)iface;
602 TRACE("(%p)->(%p)\n", this, psize);
611 psize->s.Lo = this->description.cySize.s.Lo;
616 /************************************************************************
617 * OLEFontImpl_put_Size (IFont)
619 * See Windows documentation for more details on IFont methods.
621 static HRESULT WINAPI OLEFontImpl_put_Size(
625 OLEFontImpl *this = (OLEFontImpl *)iface;
626 TRACE("(%p)->(%d)\n", this, size.s.Lo);
627 this->description.cySize.s.Hi = 0;
628 this->description.cySize.s.Lo = size.s.Lo;
629 OLEFont_SendNotify(this, DISPID_FONT_SIZE);
634 /************************************************************************
635 * OLEFontImpl_get_Bold (IFont)
637 * See Windows documentation for more details on IFont methods.
639 static HRESULT WINAPI OLEFontImpl_get_Bold(
643 OLEFontImpl *this = (OLEFontImpl *)iface;
644 TRACE("(%p)->(%p)\n", this, pbold);
651 *pbold = this->description.sWeight > 550;
656 /************************************************************************
657 * OLEFontImpl_put_Bold (IFont)
659 * See Windows documentation for more details on IFont methods.
661 static HRESULT WINAPI OLEFontImpl_put_Bold(
665 OLEFontImpl *this = (OLEFontImpl *)iface;
666 TRACE("(%p)->(%d)\n", this, bold);
667 this->description.sWeight = bold ? FW_BOLD : FW_NORMAL;
668 OLEFont_SendNotify(this, DISPID_FONT_BOLD);
673 /************************************************************************
674 * OLEFontImpl_get_Italic (IFont)
676 * See Windows documentation for more details on IFont methods.
678 static HRESULT WINAPI OLEFontImpl_get_Italic(
682 OLEFontImpl *this = (OLEFontImpl *)iface;
683 TRACE("(%p)->(%p)\n", this, pitalic);
690 *pitalic = this->description.fItalic;
695 /************************************************************************
696 * OLEFontImpl_put_Italic (IFont)
698 * See Windows documentation for more details on IFont methods.
700 static HRESULT WINAPI OLEFontImpl_put_Italic(
704 OLEFontImpl *this = (OLEFontImpl *)iface;
705 TRACE("(%p)->(%d)\n", this, italic);
707 this->description.fItalic = italic;
709 OLEFont_SendNotify(this, DISPID_FONT_ITALIC);
713 /************************************************************************
714 * OLEFontImpl_get_Underline (IFont)
716 * See Windows documentation for more details on IFont methods.
718 static HRESULT WINAPI OLEFontImpl_get_Underline(
722 OLEFontImpl *this = (OLEFontImpl *)iface;
723 TRACE("(%p)->(%p)\n", this, punderline);
731 *punderline = this->description.fUnderline;
736 /************************************************************************
737 * OLEFontImpl_put_Underline (IFont)
739 * See Windows documentation for more details on IFont methods.
741 static HRESULT WINAPI OLEFontImpl_put_Underline(
745 OLEFontImpl *this = (OLEFontImpl *)iface;
746 TRACE("(%p)->(%d)\n", this, underline);
748 this->description.fUnderline = underline;
750 OLEFont_SendNotify(this, DISPID_FONT_UNDER);
754 /************************************************************************
755 * OLEFontImpl_get_Strikethrough (IFont)
757 * See Windows documentation for more details on IFont methods.
759 static HRESULT WINAPI OLEFontImpl_get_Strikethrough(
761 BOOL* pstrikethrough)
763 OLEFontImpl *this = (OLEFontImpl *)iface;
764 TRACE("(%p)->(%p)\n", this, pstrikethrough);
769 if (pstrikethrough==0)
772 *pstrikethrough = this->description.fStrikethrough;
777 /************************************************************************
778 * OLEFontImpl_put_Strikethrough (IFont)
780 * See Windows documentation for more details on IFont methods.
782 static HRESULT WINAPI OLEFontImpl_put_Strikethrough(
786 OLEFontImpl *this = (OLEFontImpl *)iface;
787 TRACE("(%p)->(%d)\n", this, strikethrough);
789 this->description.fStrikethrough = strikethrough;
790 OLEFont_SendNotify(this, DISPID_FONT_STRIKE);
795 /************************************************************************
796 * OLEFontImpl_get_Weight (IFont)
798 * See Windows documentation for more details on IFont methods.
800 static HRESULT WINAPI OLEFontImpl_get_Weight(
804 OLEFontImpl *this = (OLEFontImpl *)iface;
805 TRACE("(%p)->(%p)\n", this, pweight);
813 *pweight = this->description.sWeight;
818 /************************************************************************
819 * OLEFontImpl_put_Weight (IFont)
821 * See Windows documentation for more details on IFont methods.
823 static HRESULT WINAPI OLEFontImpl_put_Weight(
827 OLEFontImpl *this = (OLEFontImpl *)iface;
828 TRACE("(%p)->(%d)\n", this, weight);
830 this->description.sWeight = weight;
832 OLEFont_SendNotify(this, DISPID_FONT_WEIGHT);
836 /************************************************************************
837 * OLEFontImpl_get_Charset (IFont)
839 * See Windows documentation for more details on IFont methods.
841 static HRESULT WINAPI OLEFontImpl_get_Charset(
845 OLEFontImpl *this = (OLEFontImpl *)iface;
846 TRACE("(%p)->(%p)\n", this, pcharset);
854 *pcharset = this->description.sCharset;
859 /************************************************************************
860 * OLEFontImpl_put_Charset (IFont)
862 * See Windows documentation for more details on IFont methods.
864 static HRESULT WINAPI OLEFontImpl_put_Charset(
868 OLEFontImpl *this = (OLEFontImpl *)iface;
869 TRACE("(%p)->(%d)\n", this, charset);
871 this->description.sCharset = charset;
872 OLEFont_SendNotify(this, DISPID_FONT_CHARSET);
877 /************************************************************************
878 * OLEFontImpl_get_hFont (IFont)
880 * See Windows documentation for more details on IFont methods.
882 static HRESULT WINAPI OLEFontImpl_get_hFont(
886 OLEFontImpl *this = (OLEFontImpl *)iface;
887 TRACE("(%p)->(%p)\n", this, phfont);
892 * Realize the font if necessary
894 if (this->gdiFont==0)
902 * The height of the font returned by the get_Size property is the
903 * height of the font in points multiplied by 10000... Using some
904 * simple conversions and the ratio given by the application, it can
905 * be converted to a height in pixels.
907 IFont_get_Size(iface, &cySize);
909 /* Standard ratio is 72 / 2540, or 18 / 635 in lowest terms. */
910 /* Ratio is applied here relative to the standard. */
911 fontHeight = MulDiv( cySize.s.Lo, this->cyLogical*635, this->cyHimetric*18 );
913 memset(&logFont, 0, sizeof(LOGFONTW));
915 logFont.lfHeight = ((fontHeight%10000L)>5000L) ? (-fontHeight/10000L)-1 :
916 (-fontHeight/10000L);
917 logFont.lfItalic = this->description.fItalic;
918 logFont.lfUnderline = this->description.fUnderline;
919 logFont.lfStrikeOut = this->description.fStrikethrough;
920 logFont.lfWeight = this->description.sWeight;
921 logFont.lfCharSet = this->description.sCharset;
922 logFont.lfOutPrecision = OUT_CHARACTER_PRECIS;
923 logFont.lfClipPrecision = CLIP_DEFAULT_PRECIS;
924 logFont.lfQuality = DEFAULT_QUALITY;
925 logFont.lfPitchAndFamily = DEFAULT_PITCH;
926 strcpyW(logFont.lfFaceName,this->description.lpstrName);
928 this->gdiFont = CreateFontIndirectW(&logFont);
930 /* Add font to the cache */
931 newEntry = HeapAlloc(GetProcessHeap(), 0, sizeof(HFONTItem));
932 newEntry->int_refs = 1;
933 newEntry->total_refs = 1;
934 newEntry->gdiFont = this->gdiFont;
935 EnterCriticalSection(&OLEFontImpl_csHFONTLIST);
936 list_add_tail(&OLEFontImpl_hFontList,&newEntry->entry);
937 LeaveCriticalSection(&OLEFontImpl_csHFONTLIST);
940 *phfont = this->gdiFont;
941 TRACE("Returning %p\n", *phfont);
945 /************************************************************************
946 * OLEFontImpl_Clone (IFont)
948 * See Windows documentation for more details on IFont methods.
950 static HRESULT WINAPI OLEFontImpl_Clone(
954 OLEFontImpl* newObject = 0;
955 OLEFontImpl *this = (OLEFontImpl *)iface;
957 TRACE("(%p)->(%p)\n", this, ppfont);
965 * Allocate space for the object.
967 newObject = HeapAlloc(GetProcessHeap(), 0, sizeof(OLEFontImpl));
970 return E_OUTOFMEMORY;
974 /* We need to alloc new memory for the string, otherwise
975 * we free memory twice.
977 newObject->description.lpstrName = HeapAlloc(
979 (1+strlenW(this->description.lpstrName))*2
981 strcpyW(newObject->description.lpstrName, this->description.lpstrName);
984 /* Increment internal ref in hfont item list */
985 if(newObject->gdiFont) inc_int_ref(newObject->gdiFont);
987 InterlockedIncrement(&ifont_cnt);
989 /* create new connection points */
990 newObject->pPropertyNotifyCP = NULL;
991 newObject->pFontEventsCP = NULL;
992 CreateConnectionPoint((IUnknown*)newObject, &IID_IPropertyNotifySink, &newObject->pPropertyNotifyCP);
993 CreateConnectionPoint((IUnknown*)newObject, &IID_IFontEventsDisp, &newObject->pFontEventsCP);
995 if (!newObject->pPropertyNotifyCP || !newObject->pFontEventsCP)
997 OLEFontImpl_Destroy(newObject);
998 return E_OUTOFMEMORY;
1001 /* The cloned object starts with a reference count of 1 */
1004 *ppfont = (IFont*)newObject;
1009 /************************************************************************
1010 * OLEFontImpl_IsEqual (IFont)
1012 * See Windows documentation for more details on IFont methods.
1014 static HRESULT WINAPI OLEFontImpl_IsEqual(
1018 OLEFontImpl *left = (OLEFontImpl *)iface;
1019 OLEFontImpl *right = (OLEFontImpl *)pFontOther;
1021 INT left_len,right_len;
1023 if((iface == NULL) || (pFontOther == NULL))
1025 else if (left->description.cySize.s.Lo != right->description.cySize.s.Lo)
1027 else if (left->description.cySize.s.Hi != right->description.cySize.s.Hi)
1029 else if (left->description.sWeight != right->description.sWeight)
1031 else if (left->description.sCharset != right->description.sCharset)
1033 else if (left->description.fItalic != right->description.fItalic)
1035 else if (left->description.fUnderline != right->description.fUnderline)
1037 else if (left->description.fStrikethrough != right->description.fStrikethrough)
1040 /* Check from string */
1041 left_len = strlenW(left->description.lpstrName);
1042 right_len = strlenW(right->description.lpstrName);
1043 ret = CompareStringW(0,0,left->description.lpstrName, left_len,
1044 right->description.lpstrName, right_len);
1045 if (ret != CSTR_EQUAL)
1051 /************************************************************************
1052 * OLEFontImpl_SetRatio (IFont)
1054 * See Windows documentation for more details on IFont methods.
1056 static HRESULT WINAPI OLEFontImpl_SetRatio(
1061 OLEFontImpl *this = (OLEFontImpl *)iface;
1062 TRACE("(%p)->(%d, %d)\n", this, cyLogical, cyHimetric);
1064 this->cyLogical = cyLogical;
1065 this->cyHimetric = cyHimetric;
1070 /************************************************************************
1071 * OLEFontImpl_QueryTextMetrics (IFont)
1073 * See Windows documentation for more details on IFont methods.
1075 static HRESULT WINAPI OLEFontImpl_QueryTextMetrics(
1080 HFONT hOldFont, hNewFont;
1083 OLEFontImpl_get_hFont(iface, &hNewFont);
1084 hOldFont = SelectObject(hdcRef, hNewFont);
1085 GetTextMetricsW(hdcRef, ptm);
1086 SelectObject(hdcRef, hOldFont);
1087 ReleaseDC(0, hdcRef);
1091 /************************************************************************
1092 * OLEFontImpl_AddRefHfont (IFont)
1094 * See Windows documentation for more details on IFont methods.
1096 static HRESULT WINAPI OLEFontImpl_AddRefHfont(
1100 OLEFontImpl *this = (OLEFontImpl *)iface;
1102 TRACE("(%p)->(%p)\n", this, hfont);
1104 if (!hfont) return E_INVALIDARG;
1106 return inc_ext_ref(hfont);
1109 /************************************************************************
1110 * OLEFontImpl_ReleaseHfont (IFont)
1112 * See Windows documentation for more details on IFont methods.
1114 static HRESULT WINAPI OLEFontImpl_ReleaseHfont(
1118 OLEFontImpl *this = (OLEFontImpl *)iface;
1120 TRACE("(%p)->(%p)\n", this, hfont);
1122 if (!hfont) return E_INVALIDARG;
1124 return dec_ext_ref(hfont);
1127 /************************************************************************
1128 * OLEFontImpl_SetHdc (IFont)
1130 * See Windows documentation for more details on IFont methods.
1132 static HRESULT WINAPI OLEFontImpl_SetHdc(
1136 OLEFontImpl *this = (OLEFontImpl *)iface;
1137 FIXME("(%p)->(%p): Stub\n", this, hdc);
1142 * Virtual function tables for the OLEFontImpl class.
1144 static const IFontVtbl OLEFontImpl_VTable =
1146 OLEFontImpl_QueryInterface,
1148 OLEFontImpl_Release,
1149 OLEFontImpl_get_Name,
1150 OLEFontImpl_put_Name,
1151 OLEFontImpl_get_Size,
1152 OLEFontImpl_put_Size,
1153 OLEFontImpl_get_Bold,
1154 OLEFontImpl_put_Bold,
1155 OLEFontImpl_get_Italic,
1156 OLEFontImpl_put_Italic,
1157 OLEFontImpl_get_Underline,
1158 OLEFontImpl_put_Underline,
1159 OLEFontImpl_get_Strikethrough,
1160 OLEFontImpl_put_Strikethrough,
1161 OLEFontImpl_get_Weight,
1162 OLEFontImpl_put_Weight,
1163 OLEFontImpl_get_Charset,
1164 OLEFontImpl_put_Charset,
1165 OLEFontImpl_get_hFont,
1167 OLEFontImpl_IsEqual,
1168 OLEFontImpl_SetRatio,
1169 OLEFontImpl_QueryTextMetrics,
1170 OLEFontImpl_AddRefHfont,
1171 OLEFontImpl_ReleaseHfont,
1175 /************************************************************************
1176 * OLEFontImpl_IDispatch_QueryInterface (IUnknown)
1178 * See Windows documentation for more details on IUnknown methods.
1180 static HRESULT WINAPI OLEFontImpl_IDispatch_QueryInterface(
1185 OLEFontImpl *this = impl_from_IDispatch(iface);
1187 return IFont_QueryInterface((IFont *)this, riid, ppvoid);
1190 /************************************************************************
1191 * OLEFontImpl_IDispatch_Release (IUnknown)
1193 * See Windows documentation for more details on IUnknown methods.
1195 static ULONG WINAPI OLEFontImpl_IDispatch_Release(
1198 OLEFontImpl *this = impl_from_IDispatch(iface);
1200 return IFont_Release((IFont *)this);
1203 /************************************************************************
1204 * OLEFontImpl_IDispatch_AddRef (IUnknown)
1206 * See Windows documentation for more details on IUnknown methods.
1208 static ULONG WINAPI OLEFontImpl_IDispatch_AddRef(
1211 OLEFontImpl *this = impl_from_IDispatch(iface);
1213 return IFont_AddRef((IFont *)this);
1216 /************************************************************************
1217 * OLEFontImpl_GetTypeInfoCount (IDispatch)
1219 * See Windows documentation for more details on IDispatch methods.
1221 static HRESULT WINAPI OLEFontImpl_GetTypeInfoCount(
1223 unsigned int* pctinfo)
1225 OLEFontImpl *this = impl_from_IDispatch(iface);
1226 TRACE("(%p)->(%p)\n", this, pctinfo);
1232 /************************************************************************
1233 * OLEFontImpl_GetTypeInfo (IDispatch)
1235 * See Windows documentation for more details on IDispatch methods.
1237 static HRESULT WINAPI OLEFontImpl_GetTypeInfo(
1241 ITypeInfo** ppTInfo)
1243 static const WCHAR stdole2tlb[] = {'s','t','d','o','l','e','2','.','t','l','b',0};
1247 OLEFontImpl *this = impl_from_IDispatch(iface);
1248 TRACE("(%p, iTInfo=%d, lcid=%04x, %p)\n", this, iTInfo, (int)lcid, ppTInfo);
1251 hres = LoadTypeLib(stdole2tlb, &tl);
1253 ERR("Could not load the stdole2.tlb?\n");
1256 hres = ITypeLib_GetTypeInfoOfGuid(tl, &IID_IFontDisp, ppTInfo);
1257 ITypeLib_Release(tl);
1259 FIXME("Did not IDispatch typeinfo from typelib, hres %x\n",hres);
1264 /************************************************************************
1265 * OLEFontImpl_GetIDsOfNames (IDispatch)
1267 * See Windows documentation for more details on IDispatch methods.
1269 static HRESULT WINAPI OLEFontImpl_GetIDsOfNames(
1272 LPOLESTR* rgszNames,
1280 OLEFontImpl *this = impl_from_IDispatch(iface);
1282 TRACE("(%p,%s,%p,cNames=%d,lcid=%04x,%p)\n", this, debugstr_guid(riid),
1283 rgszNames, cNames, (int)lcid, rgDispId);
1287 return E_INVALIDARG;
1291 /* retrieve type information */
1292 hres = OLEFontImpl_GetTypeInfo(iface, 0, lcid, &pTInfo);
1296 ERR("GetTypeInfo failed.\n");
1300 /* convert names to DISPIDs */
1301 hres = DispGetIDsOfNames (pTInfo, rgszNames, cNames, rgDispId);
1302 ITypeInfo_Release(pTInfo);
1308 /************************************************************************
1309 * OLEFontImpl_Invoke (IDispatch)
1311 * See Windows documentation for more details on IDispatch methods.
1313 * Note: Do not call _put_Xxx methods, since setting things here
1314 * should not call notify functions as I found out debugging the generic
1317 static HRESULT WINAPI OLEFontImpl_Invoke(
1319 DISPID dispIdMember,
1323 DISPPARAMS* pDispParams,
1324 VARIANT* pVarResult,
1325 EXCEPINFO* pExepInfo,
1328 OLEFontImpl *this = impl_from_IDispatch(iface);
1331 TRACE("%p->(%d,%s,0x%x,0x%x,%p,%p,%p,%p)\n", this, dispIdMember,
1332 debugstr_guid(riid), lcid, wFlags, pDispParams, pVarResult, pExepInfo,
1335 /* validate parameters */
1337 if (!IsEqualIID(riid, &IID_NULL))
1339 ERR("riid was %s instead of IID_NULL\n", debugstr_guid(riid));
1340 return DISP_E_UNKNOWNINTERFACE;
1343 if (wFlags & DISPATCH_PROPERTYGET)
1347 ERR("null pVarResult not allowed when DISPATCH_PROPERTYGET specified\n");
1348 return DISP_E_PARAMNOTOPTIONAL;
1351 else if (wFlags & DISPATCH_PROPERTYPUT)
1355 ERR("null pDispParams not allowed when DISPATCH_PROPERTYPUT specified\n");
1356 return DISP_E_PARAMNOTOPTIONAL;
1358 if (pDispParams->cArgs != 1)
1360 ERR("param count for DISPATCH_PROPERTYPUT was %d instead of 1\n", pDispParams->cArgs);
1361 return DISP_E_BADPARAMCOUNT;
1366 ERR("one of DISPATCH_PROPERTYGET or DISPATCH_PROPERTYPUT must be specified\n");
1367 return DISP_E_MEMBERNOTFOUND;
1370 switch (dispIdMember) {
1371 case DISPID_FONT_NAME:
1372 if (wFlags & DISPATCH_PROPERTYGET) {
1373 V_VT(pVarResult) = VT_BSTR;
1374 return IFont_get_Name((IFont *)this, &V_BSTR(pVarResult));
1378 VariantInit(&vararg);
1379 hr = VariantChangeTypeEx(&vararg, &pDispParams->rgvarg[0], lcid, 0, VT_BSTR);
1383 hr = IFont_put_Name((IFont *)this, V_BSTR(&vararg));
1385 VariantClear(&vararg);
1389 case DISPID_FONT_BOLD:
1390 if (wFlags & DISPATCH_PROPERTYGET) {
1392 hr = IFont_get_Bold((IFont *)this, &value);
1393 V_VT(pVarResult) = VT_BOOL;
1394 V_BOOL(pVarResult) = value ? VARIANT_TRUE : VARIANT_FALSE;
1399 VariantInit(&vararg);
1400 hr = VariantChangeTypeEx(&vararg, &pDispParams->rgvarg[0], lcid, 0, VT_BOOL);
1404 hr = IFont_put_Bold((IFont *)this, V_BOOL(&vararg));
1406 VariantClear(&vararg);
1410 case DISPID_FONT_ITALIC:
1411 if (wFlags & DISPATCH_PROPERTYGET) {
1413 hr = IFont_get_Italic((IFont *)this, &value);
1414 V_VT(pVarResult) = VT_BOOL;
1415 V_BOOL(pVarResult) = value ? VARIANT_TRUE : VARIANT_FALSE;
1420 VariantInit(&vararg);
1421 hr = VariantChangeTypeEx(&vararg, &pDispParams->rgvarg[0], lcid, 0, VT_BOOL);
1425 hr = IFont_put_Italic((IFont *)this, V_BOOL(&vararg));
1427 VariantClear(&vararg);
1431 case DISPID_FONT_UNDER:
1432 if (wFlags & DISPATCH_PROPERTYGET) {
1434 hr = IFont_get_Underline((IFont *)this, &value);
1435 V_VT(pVarResult) = VT_BOOL;
1436 V_BOOL(pVarResult) = value ? VARIANT_TRUE : VARIANT_FALSE;
1441 VariantInit(&vararg);
1442 hr = VariantChangeTypeEx(&vararg, &pDispParams->rgvarg[0], lcid, 0, VT_BOOL);
1446 hr = IFont_put_Underline((IFont *)this, V_BOOL(&vararg));
1448 VariantClear(&vararg);
1452 case DISPID_FONT_STRIKE:
1453 if (wFlags & DISPATCH_PROPERTYGET) {
1455 hr = IFont_get_Strikethrough((IFont *)this, &value);
1456 V_VT(pVarResult) = VT_BOOL;
1457 V_BOOL(pVarResult) = value ? VARIANT_TRUE : VARIANT_FALSE;
1462 VariantInit(&vararg);
1463 hr = VariantChangeTypeEx(&vararg, &pDispParams->rgvarg[0], lcid, 0, VT_BOOL);
1467 hr = IFont_put_Strikethrough((IFont *)this, V_BOOL(&vararg));
1469 VariantClear(&vararg);
1473 case DISPID_FONT_SIZE:
1474 if (wFlags & DISPATCH_PROPERTYGET) {
1475 V_VT(pVarResult) = VT_CY;
1476 return OLEFontImpl_get_Size((IFont *)this, &V_CY(pVarResult));
1480 VariantInit(&vararg);
1481 hr = VariantChangeTypeEx(&vararg, &pDispParams->rgvarg[0], lcid, 0, VT_CY);
1485 hr = IFont_put_Size((IFont *)this, V_CY(&vararg));
1487 VariantClear(&vararg);
1491 case DISPID_FONT_WEIGHT:
1492 if (wFlags & DISPATCH_PROPERTYGET) {
1493 V_VT(pVarResult) = VT_I2;
1494 return OLEFontImpl_get_Weight((IFont *)this, &V_I2(pVarResult));
1498 VariantInit(&vararg);
1499 hr = VariantChangeTypeEx(&vararg, &pDispParams->rgvarg[0], lcid, 0, VT_I2);
1503 hr = IFont_put_Weight((IFont *)this, V_I2(&vararg));
1505 VariantClear(&vararg);
1509 case DISPID_FONT_CHARSET:
1510 if (wFlags & DISPATCH_PROPERTYGET) {
1511 V_VT(pVarResult) = VT_I2;
1512 return OLEFontImpl_get_Charset((IFont *)this, &V_I2(pVarResult));
1516 VariantInit(&vararg);
1517 hr = VariantChangeTypeEx(&vararg, &pDispParams->rgvarg[0], lcid, 0, VT_I2);
1521 hr = IFont_put_Charset((IFont *)this, V_I2(&vararg));
1523 VariantClear(&vararg);
1528 ERR("member not found for dispid 0x%x\n", dispIdMember);
1529 return DISP_E_MEMBERNOTFOUND;
1533 static const IDispatchVtbl OLEFontImpl_IDispatch_VTable =
1535 OLEFontImpl_IDispatch_QueryInterface,
1536 OLEFontImpl_IDispatch_AddRef,
1537 OLEFontImpl_IDispatch_Release,
1538 OLEFontImpl_GetTypeInfoCount,
1539 OLEFontImpl_GetTypeInfo,
1540 OLEFontImpl_GetIDsOfNames,
1544 /************************************************************************
1545 * OLEFontImpl_IPersistStream_QueryInterface (IUnknown)
1547 * See Windows documentation for more details on IUnknown methods.
1549 static HRESULT WINAPI OLEFontImpl_IPersistStream_QueryInterface(
1550 IPersistStream* iface,
1554 OLEFontImpl *this = impl_from_IPersistStream(iface);
1556 return IFont_QueryInterface((IFont *)this, riid, ppvoid);
1559 /************************************************************************
1560 * OLEFontImpl_IPersistStream_Release (IUnknown)
1562 * See Windows documentation for more details on IUnknown methods.
1564 static ULONG WINAPI OLEFontImpl_IPersistStream_Release(
1565 IPersistStream* iface)
1567 OLEFontImpl *this = impl_from_IPersistStream(iface);
1569 return IFont_Release((IFont *)this);
1572 /************************************************************************
1573 * OLEFontImpl_IPersistStream_AddRef (IUnknown)
1575 * See Windows documentation for more details on IUnknown methods.
1577 static ULONG WINAPI OLEFontImpl_IPersistStream_AddRef(
1578 IPersistStream* iface)
1580 OLEFontImpl *this = impl_from_IPersistStream(iface);
1582 return IFont_AddRef((IFont *)this);
1585 /************************************************************************
1586 * OLEFontImpl_GetClassID (IPersistStream)
1588 * See Windows documentation for more details on IPersistStream methods.
1590 static HRESULT WINAPI OLEFontImpl_GetClassID(
1591 IPersistStream* iface,
1594 TRACE("(%p,%p)\n",iface,pClassID);
1598 *pClassID = CLSID_StdFont;
1603 /************************************************************************
1604 * OLEFontImpl_IsDirty (IPersistStream)
1606 * See Windows documentation for more details on IPersistStream methods.
1608 static HRESULT WINAPI OLEFontImpl_IsDirty(
1609 IPersistStream* iface)
1611 TRACE("(%p)\n",iface);
1615 /************************************************************************
1616 * OLEFontImpl_Load (IPersistStream)
1618 * See Windows documentation for more details on IPersistStream methods.
1620 * This is the format of the standard font serialization as far as I
1623 * Offset Type Value Comment
1624 * 0x0000 Byte Unknown Probably a version number, contains 0x01
1625 * 0x0001 Short Charset Charset value from the FONTDESC structure
1626 * 0x0003 Byte Attributes Flags defined as follows:
1628 * 00000100 - Underline
1629 * 00001000 - Strikethrough
1630 * 0x0004 Short Weight Weight value from FONTDESC structure
1631 * 0x0006 DWORD size "Low" portion of the cySize member of the FONTDESC
1633 * 0x000A Byte name length Length of the font name string (no null character)
1634 * 0x000B String name Name of the font (ASCII, no nul character)
1636 static HRESULT WINAPI OLEFontImpl_Load(
1637 IPersistStream* iface,
1638 IStream* pLoadStream)
1640 char readBuffer[0x100];
1647 OLEFontImpl *this = impl_from_IPersistStream(iface);
1650 * Read the version byte
1652 IStream_Read(pLoadStream, &bVersion, 1, &cbRead);
1661 IStream_Read(pLoadStream, &this->description.sCharset, 2, &cbRead);
1669 IStream_Read(pLoadStream, &bAttributes, 1, &cbRead);
1674 this->description.fItalic = (bAttributes & FONTPERSIST_ITALIC) != 0;
1675 this->description.fStrikethrough = (bAttributes & FONTPERSIST_STRIKETHROUGH) != 0;
1676 this->description.fUnderline = (bAttributes & FONTPERSIST_UNDERLINE) != 0;
1681 IStream_Read(pLoadStream, &this->description.sWeight, 2, &cbRead);
1689 IStream_Read(pLoadStream, &this->description.cySize.s.Lo, 4, &cbRead);
1694 this->description.cySize.s.Hi = 0;
1699 IStream_Read(pLoadStream, &bStringSize, 1, &cbRead);
1704 IStream_Read(pLoadStream, readBuffer, bStringSize, &cbRead);
1706 if (cbRead!=bStringSize)
1709 HeapFree(GetProcessHeap(), 0, this->description.lpstrName);
1711 len = MultiByteToWideChar( CP_ACP, 0, readBuffer, bStringSize, NULL, 0 );
1712 this->description.lpstrName = HeapAlloc( GetProcessHeap(), 0, (len+1) * sizeof(WCHAR) );
1713 MultiByteToWideChar( CP_ACP, 0, readBuffer, bStringSize, this->description.lpstrName, len );
1714 this->description.lpstrName[len] = 0;
1716 /* Ensure use of this font causes a new one to be created @@@@ */
1717 dec_int_ref(this->gdiFont);
1723 /************************************************************************
1724 * OLEFontImpl_Save (IPersistStream)
1726 * See Windows documentation for more details on IPersistStream methods.
1728 static HRESULT WINAPI OLEFontImpl_Save(
1729 IPersistStream* iface,
1730 IStream* pOutStream,
1733 char* writeBuffer = NULL;
1735 BYTE bVersion = 0x01;
1739 OLEFontImpl *this = impl_from_IPersistStream(iface);
1742 * Read the version byte
1744 IStream_Write(pOutStream, &bVersion, 1, &cbWritten);
1752 IStream_Write(pOutStream, &this->description.sCharset, 2, &cbWritten);
1762 if (this->description.fItalic)
1763 bAttributes |= FONTPERSIST_ITALIC;
1765 if (this->description.fStrikethrough)
1766 bAttributes |= FONTPERSIST_STRIKETHROUGH;
1768 if (this->description.fUnderline)
1769 bAttributes |= FONTPERSIST_UNDERLINE;
1771 IStream_Write(pOutStream, &bAttributes, 1, &cbWritten);
1779 IStream_Write(pOutStream, &this->description.sWeight, 2, &cbWritten);
1787 IStream_Write(pOutStream, &this->description.cySize.s.Lo, 4, &cbWritten);
1795 if (this->description.lpstrName!=0)
1796 bStringSize = WideCharToMultiByte( CP_ACP, 0, this->description.lpstrName,
1797 strlenW(this->description.lpstrName), NULL, 0, NULL, NULL );
1801 IStream_Write(pOutStream, &bStringSize, 1, &cbWritten);
1808 if (!(writeBuffer = HeapAlloc( GetProcessHeap(), 0, bStringSize ))) return E_OUTOFMEMORY;
1809 WideCharToMultiByte( CP_ACP, 0, this->description.lpstrName,
1810 strlenW(this->description.lpstrName),
1811 writeBuffer, bStringSize, NULL, NULL );
1813 IStream_Write(pOutStream, writeBuffer, bStringSize, &cbWritten);
1814 HeapFree(GetProcessHeap(), 0, writeBuffer);
1816 if (cbWritten!=bStringSize)
1823 /************************************************************************
1824 * OLEFontImpl_GetSizeMax (IPersistStream)
1826 * See Windows documentation for more details on IPersistStream methods.
1828 static HRESULT WINAPI OLEFontImpl_GetSizeMax(
1829 IPersistStream* iface,
1830 ULARGE_INTEGER* pcbSize)
1832 OLEFontImpl *this = impl_from_IPersistStream(iface);
1837 pcbSize->u.HighPart = 0;
1838 pcbSize->u.LowPart = 0;
1840 pcbSize->u.LowPart += sizeof(BYTE); /* Version */
1841 pcbSize->u.LowPart += sizeof(WORD); /* Lang code */
1842 pcbSize->u.LowPart += sizeof(BYTE); /* Flags */
1843 pcbSize->u.LowPart += sizeof(WORD); /* Weight */
1844 pcbSize->u.LowPart += sizeof(DWORD); /* Size */
1845 pcbSize->u.LowPart += sizeof(BYTE); /* StrLength */
1847 if (this->description.lpstrName!=0)
1848 pcbSize->u.LowPart += WideCharToMultiByte( CP_ACP, 0, this->description.lpstrName,
1849 strlenW(this->description.lpstrName),
1850 NULL, 0, NULL, NULL );
1855 static const IPersistStreamVtbl OLEFontImpl_IPersistStream_VTable =
1857 OLEFontImpl_IPersistStream_QueryInterface,
1858 OLEFontImpl_IPersistStream_AddRef,
1859 OLEFontImpl_IPersistStream_Release,
1860 OLEFontImpl_GetClassID,
1861 OLEFontImpl_IsDirty,
1864 OLEFontImpl_GetSizeMax
1867 /************************************************************************
1868 * OLEFontImpl_IConnectionPointContainer_QueryInterface (IUnknown)
1870 * See Windows documentation for more details on IUnknown methods.
1872 static HRESULT WINAPI OLEFontImpl_IConnectionPointContainer_QueryInterface(
1873 IConnectionPointContainer* iface,
1877 OLEFontImpl *this = impl_from_IConnectionPointContainer(iface);
1879 return IFont_QueryInterface((IFont*)this, riid, ppvoid);
1882 /************************************************************************
1883 * OLEFontImpl_IConnectionPointContainer_Release (IUnknown)
1885 * See Windows documentation for more details on IUnknown methods.
1887 static ULONG WINAPI OLEFontImpl_IConnectionPointContainer_Release(
1888 IConnectionPointContainer* iface)
1890 OLEFontImpl *this = impl_from_IConnectionPointContainer(iface);
1892 return IFont_Release((IFont*)this);
1895 /************************************************************************
1896 * OLEFontImpl_IConnectionPointContainer_AddRef (IUnknown)
1898 * See Windows documentation for more details on IUnknown methods.
1900 static ULONG WINAPI OLEFontImpl_IConnectionPointContainer_AddRef(
1901 IConnectionPointContainer* iface)
1903 OLEFontImpl *this = impl_from_IConnectionPointContainer(iface);
1905 return IFont_AddRef((IFont*)this);
1908 /************************************************************************
1909 * OLEFontImpl_EnumConnectionPoints (IConnectionPointContainer)
1911 * See Windows documentation for more details on IConnectionPointContainer
1914 static HRESULT WINAPI OLEFontImpl_EnumConnectionPoints(
1915 IConnectionPointContainer* iface,
1916 IEnumConnectionPoints **ppEnum)
1918 OLEFontImpl *this = impl_from_IConnectionPointContainer(iface);
1920 FIXME("(%p)->(%p): stub\n", this, ppEnum);
1924 /************************************************************************
1925 * OLEFontImpl_FindConnectionPoint (IConnectionPointContainer)
1927 * See Windows documentation for more details on IConnectionPointContainer
1930 static HRESULT WINAPI OLEFontImpl_FindConnectionPoint(
1931 IConnectionPointContainer* iface,
1933 IConnectionPoint **ppCp)
1935 OLEFontImpl *this = impl_from_IConnectionPointContainer(iface);
1936 TRACE("(%p)->(%s, %p)\n", this, debugstr_guid(riid), ppCp);
1938 if(IsEqualIID(riid, &IID_IPropertyNotifySink)) {
1939 return IConnectionPoint_QueryInterface(this->pPropertyNotifyCP,
1940 &IID_IConnectionPoint,
1942 } else if(IsEqualIID(riid, &IID_IFontEventsDisp)) {
1943 return IConnectionPoint_QueryInterface(this->pFontEventsCP,
1944 &IID_IConnectionPoint,
1947 FIXME("no connection point for %s\n", debugstr_guid(riid));
1948 return CONNECT_E_NOCONNECTION;
1952 static const IConnectionPointContainerVtbl
1953 OLEFontImpl_IConnectionPointContainer_VTable =
1955 OLEFontImpl_IConnectionPointContainer_QueryInterface,
1956 OLEFontImpl_IConnectionPointContainer_AddRef,
1957 OLEFontImpl_IConnectionPointContainer_Release,
1958 OLEFontImpl_EnumConnectionPoints,
1959 OLEFontImpl_FindConnectionPoint
1962 /************************************************************************
1963 * OLEFontImpl implementation of IPersistPropertyBag.
1965 static HRESULT WINAPI OLEFontImpl_IPersistPropertyBag_QueryInterface(
1966 IPersistPropertyBag *iface, REFIID riid, LPVOID *ppvObj
1968 OLEFontImpl *this = impl_from_IPersistPropertyBag(iface);
1969 return IFont_QueryInterface((IFont *)this,riid,ppvObj);
1972 static ULONG WINAPI OLEFontImpl_IPersistPropertyBag_AddRef(
1973 IPersistPropertyBag *iface
1975 OLEFontImpl *this = impl_from_IPersistPropertyBag(iface);
1976 return IFont_AddRef((IFont *)this);
1979 static ULONG WINAPI OLEFontImpl_IPersistPropertyBag_Release(
1980 IPersistPropertyBag *iface
1982 OLEFontImpl *this = impl_from_IPersistPropertyBag(iface);
1983 return IFont_Release((IFont *)this);
1986 static HRESULT WINAPI OLEFontImpl_IPersistPropertyBag_GetClassID(
1987 IPersistPropertyBag *iface, CLSID *classid
1989 FIXME("(%p,%p), stub!\n", iface, classid);
1993 static HRESULT WINAPI OLEFontImpl_IPersistPropertyBag_InitNew(
1994 IPersistPropertyBag *iface
1996 FIXME("(%p), stub!\n", iface);
2000 static HRESULT WINAPI OLEFontImpl_IPersistPropertyBag_Load(
2001 IPersistPropertyBag *iface, IPropertyBag* pPropBag, IErrorLog* pErrorLog
2003 /* (from Visual Basic 6 property bag)
2004 Name = "MS Sans Serif"
2008 Underline = 0 'False
2010 Strikethrough = 0 'False
2012 static const WCHAR sAttrName[] = {'N','a','m','e',0};
2013 static const WCHAR sAttrSize[] = {'S','i','z','e',0};
2014 static const WCHAR sAttrCharset[] = {'C','h','a','r','s','e','t',0};
2015 static const WCHAR sAttrWeight[] = {'W','e','i','g','h','t',0};
2016 static const WCHAR sAttrUnderline[] = {'U','n','d','e','r','l','i','n','e',0};
2017 static const WCHAR sAttrItalic[] = {'I','t','a','l','i','c',0};
2018 static const WCHAR sAttrStrikethrough[] = {'S','t','r','i','k','e','t','h','r','o','u','g','h',0};
2021 HRESULT iRes = S_OK;
2022 OLEFontImpl *this = impl_from_IPersistPropertyBag(iface);
2024 VariantInit(&rawAttr);
2025 VariantInit(&valueAttr);
2028 iRes = IPropertyBag_Read(pPropBag, sAttrName, &rawAttr, pErrorLog);
2031 iRes = VariantChangeType(&rawAttr, &valueAttr, 0, VT_BSTR);
2033 iRes = IFont_put_Name((IFont *)this, V_BSTR(&valueAttr));
2035 else if (iRes == E_INVALIDARG)
2037 VariantClear(&rawAttr);
2038 VariantClear(&valueAttr);
2042 iRes = IPropertyBag_Read(pPropBag, sAttrSize, &rawAttr, pErrorLog);
2045 iRes = VariantChangeType(&rawAttr, &valueAttr, 0, VT_CY);
2047 iRes = IFont_put_Size((IFont *)this, V_CY(&valueAttr));
2049 else if (iRes == E_INVALIDARG)
2051 VariantClear(&rawAttr);
2052 VariantClear(&valueAttr);
2056 iRes = IPropertyBag_Read(pPropBag, sAttrCharset, &rawAttr, pErrorLog);
2059 iRes = VariantChangeType(&rawAttr, &valueAttr, 0, VT_I2);
2061 iRes = IFont_put_Charset((IFont *)this, V_I2(&valueAttr));
2063 else if (iRes == E_INVALIDARG)
2065 VariantClear(&rawAttr);
2066 VariantClear(&valueAttr);
2070 iRes = IPropertyBag_Read(pPropBag, sAttrWeight, &rawAttr, pErrorLog);
2073 iRes = VariantChangeType(&rawAttr, &valueAttr, 0, VT_I2);
2075 iRes = IFont_put_Weight((IFont *)this, V_I2(&valueAttr));
2077 else if (iRes == E_INVALIDARG)
2079 VariantClear(&rawAttr);
2080 VariantClear(&valueAttr);
2085 iRes = IPropertyBag_Read(pPropBag, sAttrUnderline, &rawAttr, pErrorLog);
2088 iRes = VariantChangeType(&rawAttr, &valueAttr, 0, VT_BOOL);
2090 iRes = IFont_put_Underline((IFont *)this, V_BOOL(&valueAttr));
2092 else if (iRes == E_INVALIDARG)
2094 VariantClear(&rawAttr);
2095 VariantClear(&valueAttr);
2099 iRes = IPropertyBag_Read(pPropBag, sAttrItalic, &rawAttr, pErrorLog);
2102 iRes = VariantChangeType(&rawAttr, &valueAttr, 0, VT_BOOL);
2104 iRes = IFont_put_Italic((IFont *)this, V_BOOL(&valueAttr));
2106 else if (iRes == E_INVALIDARG)
2108 VariantClear(&rawAttr);
2109 VariantClear(&valueAttr);
2113 iRes = IPropertyBag_Read(pPropBag, sAttrStrikethrough, &rawAttr, pErrorLog);
2116 iRes = VariantChangeType(&rawAttr, &valueAttr, 0, VT_BOOL);
2118 IFont_put_Strikethrough((IFont *)this, V_BOOL(&valueAttr));
2120 else if (iRes == E_INVALIDARG)
2122 VariantClear(&rawAttr);
2123 VariantClear(&valueAttr);
2127 WARN("-- 0x%08x\n", iRes);
2131 static HRESULT WINAPI OLEFontImpl_IPersistPropertyBag_Save(
2132 IPersistPropertyBag *iface, IPropertyBag* pPropBag, BOOL fClearDirty,
2133 BOOL fSaveAllProperties
2135 FIXME("(%p,%p,%d,%d), stub!\n", iface, pPropBag, fClearDirty, fSaveAllProperties);
2139 static const IPersistPropertyBagVtbl OLEFontImpl_IPersistPropertyBag_VTable =
2141 OLEFontImpl_IPersistPropertyBag_QueryInterface,
2142 OLEFontImpl_IPersistPropertyBag_AddRef,
2143 OLEFontImpl_IPersistPropertyBag_Release,
2145 OLEFontImpl_IPersistPropertyBag_GetClassID,
2146 OLEFontImpl_IPersistPropertyBag_InitNew,
2147 OLEFontImpl_IPersistPropertyBag_Load,
2148 OLEFontImpl_IPersistPropertyBag_Save
2151 /************************************************************************
2152 * OLEFontImpl implementation of IPersistStreamInit.
2154 static HRESULT WINAPI OLEFontImpl_IPersistStreamInit_QueryInterface(
2155 IPersistStreamInit *iface, REFIID riid, LPVOID *ppvObj
2157 OLEFontImpl *this = impl_from_IPersistStreamInit(iface);
2158 return IFont_QueryInterface((IFont *)this,riid,ppvObj);
2161 static ULONG WINAPI OLEFontImpl_IPersistStreamInit_AddRef(
2162 IPersistStreamInit *iface
2164 OLEFontImpl *this = impl_from_IPersistStreamInit(iface);
2165 return IFont_AddRef((IFont *)this);
2168 static ULONG WINAPI OLEFontImpl_IPersistStreamInit_Release(
2169 IPersistStreamInit *iface
2171 OLEFontImpl *this = impl_from_IPersistStreamInit(iface);
2172 return IFont_Release((IFont *)this);
2175 static HRESULT WINAPI OLEFontImpl_IPersistStreamInit_GetClassID(
2176 IPersistStreamInit *iface, CLSID *classid
2178 FIXME("(%p,%p), stub!\n", iface, classid);
2182 static HRESULT WINAPI OLEFontImpl_IPersistStreamInit_IsDirty(
2183 IPersistStreamInit *iface
2185 FIXME("(%p), stub!\n", iface);
2189 static HRESULT WINAPI OLEFontImpl_IPersistStreamInit_Load(
2190 IPersistStreamInit *iface, LPSTREAM pStm
2192 FIXME("(%p,%p), stub!\n", iface, pStm);
2196 static HRESULT WINAPI OLEFontImpl_IPersistStreamInit_Save(
2197 IPersistStreamInit *iface, LPSTREAM pStm, BOOL fClearDirty
2199 FIXME("(%p,%p,%d), stub!\n", iface, pStm, fClearDirty);
2203 static HRESULT WINAPI OLEFontImpl_IPersistStreamInit_GetSizeMax(
2204 IPersistStreamInit *iface, ULARGE_INTEGER *pcbSize
2206 FIXME("(%p,%p), stub!\n", iface, pcbSize);
2210 static HRESULT WINAPI OLEFontImpl_IPersistStreamInit_InitNew(
2211 IPersistStreamInit *iface
2213 FIXME("(%p), stub!\n", iface);
2217 static const IPersistStreamInitVtbl OLEFontImpl_IPersistStreamInit_VTable =
2219 OLEFontImpl_IPersistStreamInit_QueryInterface,
2220 OLEFontImpl_IPersistStreamInit_AddRef,
2221 OLEFontImpl_IPersistStreamInit_Release,
2223 OLEFontImpl_IPersistStreamInit_GetClassID,
2224 OLEFontImpl_IPersistStreamInit_IsDirty,
2225 OLEFontImpl_IPersistStreamInit_Load,
2226 OLEFontImpl_IPersistStreamInit_Save,
2227 OLEFontImpl_IPersistStreamInit_GetSizeMax,
2228 OLEFontImpl_IPersistStreamInit_InitNew
2231 /************************************************************************
2232 * OLEFontImpl_Construct
2234 * This method will construct a new instance of the OLEFontImpl
2237 * The caller of this method must release the object when it's
2240 static OLEFontImpl* OLEFontImpl_Construct(const FONTDESC *fontDesc)
2242 OLEFontImpl* newObject = 0;
2245 * Allocate space for the object.
2247 newObject = HeapAlloc(GetProcessHeap(), 0, sizeof(OLEFontImpl));
2253 * Initialize the virtual function table.
2255 newObject->lpVtbl = &OLEFontImpl_VTable;
2256 newObject->lpvtblIDispatch = &OLEFontImpl_IDispatch_VTable;
2257 newObject->lpvtblIPersistStream = &OLEFontImpl_IPersistStream_VTable;
2258 newObject->lpvtblIConnectionPointContainer = &OLEFontImpl_IConnectionPointContainer_VTable;
2259 newObject->lpvtblIPersistPropertyBag = &OLEFontImpl_IPersistPropertyBag_VTable;
2260 newObject->lpvtblIPersistStreamInit = &OLEFontImpl_IPersistStreamInit_VTable;
2263 * Start with one reference count. The caller of this function
2264 * must release the interface pointer when it is done.
2269 * Copy the description of the font in the object.
2271 assert(fontDesc->cbSizeofstruct >= sizeof(FONTDESC));
2273 newObject->description.cbSizeofstruct = sizeof(FONTDESC);
2274 newObject->description.lpstrName = HeapAlloc(GetProcessHeap(),
2276 (lstrlenW(fontDesc->lpstrName)+1) * sizeof(WCHAR));
2277 strcpyW(newObject->description.lpstrName, fontDesc->lpstrName);
2278 newObject->description.cySize = fontDesc->cySize;
2279 newObject->description.sWeight = fontDesc->sWeight;
2280 newObject->description.sCharset = fontDesc->sCharset;
2281 newObject->description.fItalic = fontDesc->fItalic;
2282 newObject->description.fUnderline = fontDesc->fUnderline;
2283 newObject->description.fStrikethrough = fontDesc->fStrikethrough;
2286 * Initializing all the other members.
2288 newObject->gdiFont = 0;
2289 newObject->cyLogical = 72L;
2290 newObject->cyHimetric = 2540L;
2291 newObject->pPropertyNotifyCP = NULL;
2292 newObject->pFontEventsCP = NULL;
2294 CreateConnectionPoint((IUnknown*)newObject, &IID_IPropertyNotifySink, &newObject->pPropertyNotifyCP);
2295 CreateConnectionPoint((IUnknown*)newObject, &IID_IFontEventsDisp, &newObject->pFontEventsCP);
2297 if (!newObject->pPropertyNotifyCP || !newObject->pFontEventsCP)
2299 OLEFontImpl_Destroy(newObject);
2303 InterlockedIncrement(&ifont_cnt);
2305 TRACE("returning %p\n", newObject);
2309 /************************************************************************
2310 * OLEFontImpl_Destroy
2312 * This method is called by the Release method when the reference
2313 * count goes down to 0. It will free all resources used by
2316 static void OLEFontImpl_Destroy(OLEFontImpl* fontDesc)
2318 TRACE("(%p)\n", fontDesc);
2320 HeapFree(GetProcessHeap(), 0, fontDesc->description.lpstrName);
2322 if (fontDesc->pPropertyNotifyCP)
2323 IConnectionPoint_Release(fontDesc->pPropertyNotifyCP);
2324 if (fontDesc->pFontEventsCP)
2325 IConnectionPoint_Release(fontDesc->pFontEventsCP);
2327 HeapFree(GetProcessHeap(), 0, fontDesc);
2330 /*******************************************************************************
2331 * StdFont ClassFactory
2335 /* IUnknown fields */
2336 const IClassFactoryVtbl *lpVtbl;
2338 } IClassFactoryImpl;
2340 static HRESULT WINAPI
2341 SFCF_QueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj) {
2342 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
2344 FIXME("(%p)->(%s,%p),stub!\n",This,debugstr_guid(riid),ppobj);
2345 return E_NOINTERFACE;
2349 SFCF_AddRef(LPCLASSFACTORY iface) {
2350 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
2351 return InterlockedIncrement(&This->ref);
2354 static ULONG WINAPI SFCF_Release(LPCLASSFACTORY iface) {
2355 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
2356 /* static class, won't be freed */
2357 return InterlockedDecrement(&This->ref);
2360 static HRESULT WINAPI SFCF_CreateInstance(
2361 LPCLASSFACTORY iface,LPUNKNOWN pOuter,REFIID riid,LPVOID *ppobj
2363 return OleCreateFontIndirect(NULL,riid,ppobj);
2367 static HRESULT WINAPI SFCF_LockServer(LPCLASSFACTORY iface,BOOL dolock) {
2368 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
2369 FIXME("(%p)->(%d),stub!\n",This,dolock);
2373 static const IClassFactoryVtbl SFCF_Vtbl = {
2374 SFCF_QueryInterface,
2377 SFCF_CreateInstance,
2380 static IClassFactoryImpl STDFONT_CF = {&SFCF_Vtbl, 1 };
2382 void _get_STDFONT_CF(LPVOID *ppv) { *ppv = &STDFONT_CF; }