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
56 static HDC olefont_hdc;
58 /***********************************************************************
59 * List of the HFONTs it has given out, with each one having a separate
62 typedef struct _HFONTItem
66 /* Reference count of any IFont objects that own this hfont */
69 /* Total reference count of any refs held by the application obtained by AddRefHfont plus any internal refs */
72 /* The font associated with this object. */
75 } HFONTItem, *PHFONTItem;
77 static struct list OLEFontImpl_hFontList = LIST_INIT(OLEFontImpl_hFontList);
79 /* Counts how many fonts contain at least one lock */
80 static LONG ifont_cnt = 0;
82 /***********************************************************************
83 * Critical section for OLEFontImpl_hFontList
85 static CRITICAL_SECTION OLEFontImpl_csHFONTLIST;
86 static CRITICAL_SECTION_DEBUG OLEFontImpl_csHFONTLIST_debug =
88 0, 0, &OLEFontImpl_csHFONTLIST,
89 { &OLEFontImpl_csHFONTLIST_debug.ProcessLocksList,
90 &OLEFontImpl_csHFONTLIST_debug.ProcessLocksList },
91 0, 0, { (DWORD_PTR)(__FILE__ ": OLEFontImpl_csHFONTLIST") }
93 static CRITICAL_SECTION OLEFontImpl_csHFONTLIST = { &OLEFontImpl_csHFONTLIST_debug, -1, 0, 0, 0, 0 };
95 static HDC get_dc(void)
98 EnterCriticalSection(&OLEFontImpl_csHFONTLIST);
100 olefont_hdc = CreateCompatibleDC(NULL);
102 LeaveCriticalSection(&OLEFontImpl_csHFONTLIST);
106 static void delete_dc(void)
108 EnterCriticalSection(&OLEFontImpl_csHFONTLIST);
111 DeleteDC(olefont_hdc);
114 LeaveCriticalSection(&OLEFontImpl_csHFONTLIST);
117 static void HFONTItem_Delete(PHFONTItem item)
119 DeleteObject(item->gdiFont);
120 list_remove(&item->entry);
121 HeapFree(GetProcessHeap(), 0, item);
124 /* Find hfont item entry in the list. Should be called while holding the crit sect */
125 static HFONTItem *find_hfontitem(HFONT hfont)
129 LIST_FOR_EACH_ENTRY(item, &OLEFontImpl_hFontList, HFONTItem, entry)
131 if (item->gdiFont == hfont)
137 /* Add an item to the list with one internal reference */
138 static HRESULT add_hfontitem(HFONT hfont)
140 HFONTItem *new_item = HeapAlloc(GetProcessHeap(), 0, sizeof(*new_item));
142 if(!new_item) return E_OUTOFMEMORY;
144 new_item->int_refs = 1;
145 new_item->total_refs = 1;
146 new_item->gdiFont = hfont;
147 EnterCriticalSection(&OLEFontImpl_csHFONTLIST);
148 list_add_tail(&OLEFontImpl_hFontList,&new_item->entry);
149 LeaveCriticalSection(&OLEFontImpl_csHFONTLIST);
153 static HRESULT inc_int_ref(HFONT hfont)
156 HRESULT hr = S_FALSE;
158 EnterCriticalSection(&OLEFontImpl_csHFONTLIST);
159 item = find_hfontitem(hfont);
167 LeaveCriticalSection(&OLEFontImpl_csHFONTLIST);
172 /* decrements the internal ref of a hfont item. If both refs are zero it'll
173 remove the item from the list and delete the hfont */
174 static HRESULT dec_int_ref(HFONT hfont)
177 HRESULT hr = S_FALSE;
179 EnterCriticalSection(&OLEFontImpl_csHFONTLIST);
180 item = find_hfontitem(hfont);
186 if(item->int_refs == 0 && item->total_refs == 0)
187 HFONTItem_Delete(item);
190 LeaveCriticalSection(&OLEFontImpl_csHFONTLIST);
195 static HRESULT inc_ext_ref(HFONT hfont)
198 HRESULT hr = S_FALSE;
200 EnterCriticalSection(&OLEFontImpl_csHFONTLIST);
202 item = find_hfontitem(hfont);
208 LeaveCriticalSection(&OLEFontImpl_csHFONTLIST);
213 static HRESULT dec_ext_ref(HFONT hfont)
216 HRESULT hr = S_FALSE;
218 EnterCriticalSection(&OLEFontImpl_csHFONTLIST);
220 item = find_hfontitem(hfont);
223 if(--item->total_refs >= 0) hr = S_OK;
225 LeaveCriticalSection(&OLEFontImpl_csHFONTLIST);
230 static WCHAR *strdupW(const WCHAR* str)
233 DWORD size = (strlenW(str) + 1) * sizeof(WCHAR);
235 ret = HeapAlloc(GetProcessHeap(), 0, size);
237 memcpy(ret, str, size);
241 /***********************************************************************
242 * Declaration of the implementation class for the IFont interface
244 typedef struct OLEFontImpl OLEFontImpl;
249 * This class supports many interfaces. IUnknown, IFont,
250 * IDispatch, IDispFont IPersistStream and IConnectionPointContainer.
251 * The first two are supported by the first vtable, the next two are
252 * supported by the second table and the last two have their own.
255 IDispatch IDispatch_iface;
256 IPersistStream IPersistStream_iface;
257 IConnectionPointContainer IConnectionPointContainer_iface;
258 IPersistPropertyBag IPersistPropertyBag_iface;
259 IPersistStreamInit IPersistStreamInit_iface;
261 * Reference count for that instance of the class.
266 * This structure contains the description of the class.
268 FONTDESC description;
271 * Contain the font associated with this object.
282 * Stash realized height (pixels) from TEXTMETRIC - used in get_Size()
286 IConnectionPoint *pPropertyNotifyCP;
287 IConnectionPoint *pFontEventsCP;
291 * Here, I define utility macros to help with the casting of the
293 * There is a version to accommodate all of the VTables implemented
297 static inline OLEFontImpl *impl_from_IFont(IFont *iface)
299 return CONTAINING_RECORD(iface, OLEFontImpl, IFont_iface);
302 static inline OLEFontImpl *impl_from_IDispatch( IDispatch *iface )
304 return CONTAINING_RECORD(iface, OLEFontImpl, IDispatch_iface);
307 static inline OLEFontImpl *impl_from_IPersistStream( IPersistStream *iface )
309 return CONTAINING_RECORD(iface, OLEFontImpl, IPersistStream_iface);
312 static inline OLEFontImpl *impl_from_IConnectionPointContainer( IConnectionPointContainer *iface )
314 return CONTAINING_RECORD(iface, OLEFontImpl, IConnectionPointContainer_iface);
317 static inline OLEFontImpl *impl_from_IPersistPropertyBag( IPersistPropertyBag *iface )
319 return CONTAINING_RECORD(iface, OLEFontImpl, IPersistPropertyBag_iface);
322 static inline OLEFontImpl *impl_from_IPersistStreamInit( IPersistStreamInit *iface )
324 return CONTAINING_RECORD(iface, OLEFontImpl, IPersistStreamInit_iface);
328 /***********************************************************************
329 * Prototypes for the implementation functions for the IFont
332 static OLEFontImpl* OLEFontImpl_Construct(const FONTDESC *fontDesc);
333 static void OLEFontImpl_Destroy(OLEFontImpl* fontDesc);
334 static ULONG WINAPI OLEFontImpl_AddRef(IFont* iface);
336 /******************************************************************************
337 * OleCreateFontIndirect [OLEAUT32.420]
339 HRESULT WINAPI OleCreateFontIndirect(
340 LPFONTDESC lpFontDesc,
344 OLEFontImpl* newFont;
348 TRACE("(%p, %s, %p)\n", lpFontDesc, debugstr_guid(riid), ppvObj);
350 if (!ppvObj) return E_POINTER;
355 static WCHAR fname[] = { 'S','y','s','t','e','m',0 };
357 fd.cbSizeofstruct = sizeof(fd);
358 fd.lpstrName = fname;
359 fd.cySize.s.Lo = 80000;
365 fd.fStrikethrough = 0;
369 newFont = OLEFontImpl_Construct(lpFontDesc);
370 if (!newFont) return E_OUTOFMEMORY;
372 hr = IFont_QueryInterface(&newFont->IFont_iface, riid, ppvObj);
373 IFont_Release(&newFont->IFont_iface);
379 /***********************************************************************
380 * Implementation of the OLEFontImpl class.
383 /***********************************************************************
384 * OLEFont_SendNotify (internal)
386 * Sends notification messages of changed properties to any interested
389 static void OLEFont_SendNotify(OLEFontImpl* this, DISPID dispID)
391 static const WCHAR wszName[] = {'N','a','m','e',0};
392 static const WCHAR wszSize[] = {'S','i','z','e',0};
393 static const WCHAR wszBold[] = {'B','o','l','d',0};
394 static const WCHAR wszItalic[] = {'I','t','a','l','i','c',0};
395 static const WCHAR wszUnder[] = {'U','n','d','e','r','l','i','n','e',0};
396 static const WCHAR wszStrike[] = {'S','t','r','i','k','e','t','h','r','o','u','g','h',0};
397 static const WCHAR wszWeight[] = {'W','e','i','g','h','t',0};
398 static const WCHAR wszCharset[] = {'C','h','a','r','s','s','e','t',0};
399 static const LPCWSTR dispid_mapping[] =
412 IEnumConnections *pEnum;
418 hres = IConnectionPoint_EnumConnections(this->pPropertyNotifyCP, &pEnum);
421 while(IEnumConnections_Next(pEnum, 1, &CD, NULL) == S_OK) {
422 IPropertyNotifySink *sink;
424 IUnknown_QueryInterface(CD.pUnk, &IID_IPropertyNotifySink, (LPVOID)&sink);
425 IPropertyNotifySink_OnChanged(sink, dispID);
426 IPropertyNotifySink_Release(sink);
427 IUnknown_Release(CD.pUnk);
429 IEnumConnections_Release(pEnum);
432 hres = IConnectionPoint_EnumConnections(this->pFontEventsCP, &pEnum);
435 DISPPARAMS dispparams;
438 VariantInit(&vararg);
439 V_VT(&vararg) = VT_BSTR;
440 V_BSTR(&vararg) = SysAllocString(dispid_mapping[dispID]);
442 dispparams.cArgs = 1;
443 dispparams.cNamedArgs = 0;
444 dispparams.rgdispidNamedArgs = NULL;
445 dispparams.rgvarg = &vararg;
447 while(IEnumConnections_Next(pEnum, 1, &CD, NULL) == S_OK) {
448 IFontEventsDisp *disp;
450 IUnknown_QueryInterface(CD.pUnk, &IID_IFontEventsDisp, (LPVOID)&disp);
451 IDispatch_Invoke(disp, DISPID_FONT_CHANGED, &IID_NULL,
452 LOCALE_NEUTRAL, INVOKE_FUNC, &dispparams, NULL,
455 IDispatch_Release(disp);
456 IUnknown_Release(CD.pUnk);
458 VariantClear(&vararg);
459 IEnumConnections_Release(pEnum);
463 /************************************************************************
464 * OLEFontImpl_QueryInterface (IUnknown)
466 * See Windows documentation for more details on IUnknown methods.
468 static HRESULT WINAPI OLEFontImpl_QueryInterface(
473 OLEFontImpl *this = impl_from_IFont(iface);
475 TRACE("(%p)->(%s, %p)\n", this, debugstr_guid(riid), ppvObject);
479 if (IsEqualGUID(&IID_IUnknown, riid) ||
480 IsEqualGUID(&IID_IFont, riid))
484 else if (IsEqualGUID(&IID_IDispatch, riid) ||
485 IsEqualGUID(&IID_IFontDisp, riid))
487 *ppvObject = &this->IDispatch_iface;
489 else if (IsEqualGUID(&IID_IPersist, riid) ||
490 IsEqualGUID(&IID_IPersistStream, riid))
492 *ppvObject = &this->IPersistStream_iface;
494 else if (IsEqualGUID(&IID_IConnectionPointContainer, riid))
496 *ppvObject = &this->IConnectionPointContainer_iface;
498 else if (IsEqualGUID(&IID_IPersistPropertyBag, riid))
500 *ppvObject = &this->IPersistPropertyBag_iface;
502 else if (IsEqualGUID(&IID_IPersistStreamInit, riid))
504 *ppvObject = &this->IPersistStreamInit_iface;
509 FIXME("() : asking for unsupported interface %s\n", debugstr_guid(riid));
510 return E_NOINTERFACE;
518 /************************************************************************
519 * OLEFontImpl_AddRef (IUnknown)
521 static ULONG WINAPI OLEFontImpl_AddRef(
524 OLEFontImpl *this = impl_from_IFont(iface);
525 TRACE("(%p)->(ref=%d)\n", this, this->ref);
526 return InterlockedIncrement(&this->ref);
529 /************************************************************************
530 * OLEFontImpl_Release (IUnknown)
532 static ULONG WINAPI OLEFontImpl_Release(IFont* iface)
534 OLEFontImpl *this = impl_from_IFont(iface);
537 TRACE("(%p)->(ref=%d)\n", this, this->ref);
539 ref = InterlockedDecrement(&this->ref);
543 ULONG fontlist_refs = InterlockedDecrement(&ifont_cnt);
545 /* Final IFont object so destroy font cache */
546 if (fontlist_refs == 0)
548 HFONTItem *item, *cursor2;
550 EnterCriticalSection(&OLEFontImpl_csHFONTLIST);
551 LIST_FOR_EACH_ENTRY_SAFE(item, cursor2, &OLEFontImpl_hFontList, HFONTItem, entry)
552 HFONTItem_Delete(item);
553 LeaveCriticalSection(&OLEFontImpl_csHFONTLIST);
558 dec_int_ref(this->gdiFont);
560 OLEFontImpl_Destroy(this);
572 static int CALLBACK font_enum_proc(const LOGFONTW *elf, const TEXTMETRICW *ntm, DWORD type, LPARAM lp)
574 enum_data *data = (enum_data*)lp;
576 if(elf->lfCharSet == data->orig_cs)
578 data->avail_cs = data->orig_cs;
581 if(data->avail_cs == -1) data->avail_cs = elf->lfCharSet;
585 static void realize_font(OLEFontImpl *This)
591 WCHAR text_face[LF_FACESIZE];
600 old_font = SelectObject(hdc, This->gdiFont);
601 GetTextFaceW(hdc, sizeof(text_face) / sizeof(text_face[0]), text_face);
602 SelectObject(hdc, old_font);
603 dec_int_ref(This->gdiFont);
607 memset(&logFont, 0, sizeof(LOGFONTW));
609 lstrcpynW(logFont.lfFaceName, This->description.lpstrName, LF_FACESIZE);
610 logFont.lfCharSet = This->description.sCharset;
612 /* If the font name has been changed then enumerate all charsets
613 and pick one that'll result in the font specified being selected */
614 if(text_face[0] && lstrcmpiW(text_face, This->description.lpstrName))
617 data.orig_cs = This->description.sCharset;
619 logFont.lfCharSet = DEFAULT_CHARSET;
620 EnumFontFamiliesExW(get_dc(), &logFont, font_enum_proc, (LPARAM)&data, 0);
621 if(data.avail_cs != -1) logFont.lfCharSet = data.avail_cs;
626 * The height of the font returned by the get_Size property is the
627 * height of the font in points multiplied by 10000... Using some
628 * simple conversions and the ratio given by the application, it can
629 * be converted to a height in pixels.
631 * Standard ratio is 72 / 2540, or 18 / 635 in lowest terms.
632 * Ratio is applied here relative to the standard.
635 fontHeight = MulDiv( This->description.cySize.s.Lo, This->cyLogical*635, This->cyHimetric*18 );
638 logFont.lfHeight = ((fontHeight%10000L)>5000L) ? (-fontHeight/10000L) - 1 :
639 (-fontHeight/10000L);
640 logFont.lfItalic = This->description.fItalic;
641 logFont.lfUnderline = This->description.fUnderline;
642 logFont.lfStrikeOut = This->description.fStrikethrough;
643 logFont.lfWeight = This->description.sWeight;
644 logFont.lfOutPrecision = OUT_CHARACTER_PRECIS;
645 logFont.lfClipPrecision = CLIP_DEFAULT_PRECIS;
646 logFont.lfQuality = DEFAULT_QUALITY;
647 logFont.lfPitchAndFamily = DEFAULT_PITCH;
649 This->gdiFont = CreateFontIndirectW(&logFont);
652 add_hfontitem(This->gdiFont);
654 /* Fixup the name and charset properties so that they match the
656 old_font = SelectObject(get_dc(), This->gdiFont);
657 GetTextFaceW(hdc, sizeof(text_face) / sizeof(text_face[0]), text_face);
658 if(lstrcmpiW(text_face, This->description.lpstrName))
660 HeapFree(GetProcessHeap(), 0, This->description.lpstrName);
661 This->description.lpstrName = strdupW(text_face);
663 GetTextMetricsW(hdc, &tm);
664 This->description.sCharset = tm.tmCharSet;
665 /* While we have it handy, stash the realized font height for use by get_Size() */
666 This->nRealHeight = tm.tmHeight - tm.tmInternalLeading; /* corresponds to LOGFONT lfHeight */
667 SelectObject(hdc, old_font);
671 /************************************************************************
672 * OLEFontImpl_get_Name (IFont)
674 * See Windows documentation for more details on IFont methods.
676 static HRESULT WINAPI OLEFontImpl_get_Name(
680 OLEFontImpl *this = impl_from_IFont(iface);
681 TRACE("(%p)->(%p)\n", this, pname);
686 if(this->dirty) realize_font(this);
688 if (this->description.lpstrName!=0)
689 *pname = SysAllocString(this->description.lpstrName);
696 /************************************************************************
697 * OLEFontImpl_put_Name (IFont)
699 static HRESULT WINAPI OLEFontImpl_put_Name(
703 OLEFontImpl *this = impl_from_IFont(iface);
704 TRACE("(%p)->(%p)\n", this, name);
707 return CTL_E_INVALIDPROPERTYVALUE;
709 if (this->description.lpstrName==0)
711 this->description.lpstrName = HeapAlloc(GetProcessHeap(),
713 (lstrlenW(name)+1) * sizeof(WCHAR));
717 this->description.lpstrName = HeapReAlloc(GetProcessHeap(),
719 this->description.lpstrName,
720 (lstrlenW(name)+1) * sizeof(WCHAR));
723 if (this->description.lpstrName==0)
724 return E_OUTOFMEMORY;
726 strcpyW(this->description.lpstrName, name);
727 TRACE("new name %s\n", debugstr_w(this->description.lpstrName));
728 OLEFont_SendNotify(this, DISPID_FONT_NAME);
732 /************************************************************************
733 * OLEFontImpl_get_Size (IFont)
735 static HRESULT WINAPI OLEFontImpl_get_Size(
739 OLEFontImpl *this = impl_from_IFont(iface);
740 TRACE("(%p)->(%p)\n", this, psize);
742 if (!psize) return E_POINTER;
744 if(this->dirty) realize_font(this);
747 * Convert realized font height in pixels to points descaled by current
748 * scaling ratio then scaled up by 10000.
750 psize->s.Lo = MulDiv(this->nRealHeight,
751 this->cyHimetric * 72 * 10000,
752 this->cyLogical * 2540);
758 /************************************************************************
759 * OLEFontImpl_put_Size (IFont)
761 static HRESULT WINAPI OLEFontImpl_put_Size(
765 OLEFontImpl *this = impl_from_IFont(iface);
766 TRACE("(%p)->(%d)\n", this, size.s.Lo);
767 this->description.cySize.s.Hi = 0;
768 this->description.cySize.s.Lo = size.s.Lo;
769 OLEFont_SendNotify(this, DISPID_FONT_SIZE);
774 /************************************************************************
775 * OLEFontImpl_get_Bold (IFont)
777 * See Windows documentation for more details on IFont methods.
779 static HRESULT WINAPI OLEFontImpl_get_Bold(
783 OLEFontImpl *this = impl_from_IFont(iface);
784 TRACE("(%p)->(%p)\n", this, pbold);
786 if (!pbold) return E_POINTER;
788 if(this->dirty) realize_font(this);
790 *pbold = this->description.sWeight > 550;
795 /************************************************************************
796 * OLEFontImpl_put_Bold (IFont)
798 static HRESULT WINAPI OLEFontImpl_put_Bold(
802 OLEFontImpl *this = impl_from_IFont(iface);
803 TRACE("(%p)->(%d)\n", this, bold);
804 this->description.sWeight = bold ? FW_BOLD : FW_NORMAL;
805 OLEFont_SendNotify(this, DISPID_FONT_BOLD);
810 /************************************************************************
811 * OLEFontImpl_get_Italic (IFont)
813 static HRESULT WINAPI OLEFontImpl_get_Italic(
817 OLEFontImpl *this = impl_from_IFont(iface);
818 TRACE("(%p)->(%p)\n", this, pitalic);
823 if(this->dirty) realize_font(this);
825 *pitalic = this->description.fItalic;
830 /************************************************************************
831 * OLEFontImpl_put_Italic (IFont)
833 static HRESULT WINAPI OLEFontImpl_put_Italic(
837 OLEFontImpl *this = impl_from_IFont(iface);
838 TRACE("(%p)->(%d)\n", this, italic);
840 this->description.fItalic = italic;
842 OLEFont_SendNotify(this, DISPID_FONT_ITALIC);
846 /************************************************************************
847 * OLEFontImpl_get_Underline (IFont)
849 static HRESULT WINAPI OLEFontImpl_get_Underline(
853 OLEFontImpl *this = impl_from_IFont(iface);
854 TRACE("(%p)->(%p)\n", this, punderline);
859 if(this->dirty) realize_font(this);
861 *punderline = this->description.fUnderline;
866 /************************************************************************
867 * OLEFontImpl_put_Underline (IFont)
869 static HRESULT WINAPI OLEFontImpl_put_Underline(
873 OLEFontImpl *this = impl_from_IFont(iface);
874 TRACE("(%p)->(%d)\n", this, underline);
876 this->description.fUnderline = underline;
878 OLEFont_SendNotify(this, DISPID_FONT_UNDER);
882 /************************************************************************
883 * OLEFontImpl_get_Strikethrough (IFont)
885 static HRESULT WINAPI OLEFontImpl_get_Strikethrough(
887 BOOL* pstrikethrough)
889 OLEFontImpl *this = impl_from_IFont(iface);
890 TRACE("(%p)->(%p)\n", this, pstrikethrough);
892 if (pstrikethrough==0)
895 if(this->dirty) realize_font(this);
897 *pstrikethrough = this->description.fStrikethrough;
902 /************************************************************************
903 * OLEFontImpl_put_Strikethrough (IFont)
905 static HRESULT WINAPI OLEFontImpl_put_Strikethrough(
909 OLEFontImpl *this = impl_from_IFont(iface);
910 TRACE("(%p)->(%d)\n", this, strikethrough);
912 this->description.fStrikethrough = strikethrough;
913 OLEFont_SendNotify(this, DISPID_FONT_STRIKE);
918 /************************************************************************
919 * OLEFontImpl_get_Weight (IFont)
921 static HRESULT WINAPI OLEFontImpl_get_Weight(
925 OLEFontImpl *this = impl_from_IFont(iface);
926 TRACE("(%p)->(%p)\n", this, pweight);
931 if(this->dirty) realize_font(this);
933 *pweight = this->description.sWeight;
938 /************************************************************************
939 * OLEFontImpl_put_Weight (IFont)
941 static HRESULT WINAPI OLEFontImpl_put_Weight(
945 OLEFontImpl *this = impl_from_IFont(iface);
946 TRACE("(%p)->(%d)\n", this, weight);
948 this->description.sWeight = weight;
950 OLEFont_SendNotify(this, DISPID_FONT_WEIGHT);
954 /************************************************************************
955 * OLEFontImpl_get_Charset (IFont)
957 static HRESULT WINAPI OLEFontImpl_get_Charset(
961 OLEFontImpl *this = impl_from_IFont(iface);
962 TRACE("(%p)->(%p)\n", this, pcharset);
967 if(this->dirty) realize_font(this);
969 *pcharset = this->description.sCharset;
974 /************************************************************************
975 * OLEFontImpl_put_Charset (IFont)
977 static HRESULT WINAPI OLEFontImpl_put_Charset(
981 OLEFontImpl *this = impl_from_IFont(iface);
982 TRACE("(%p)->(%d)\n", this, charset);
984 this->description.sCharset = charset;
985 OLEFont_SendNotify(this, DISPID_FONT_CHARSET);
990 /************************************************************************
991 * OLEFontImpl_get_hFont (IFont)
993 static HRESULT WINAPI OLEFontImpl_get_hFont(
997 OLEFontImpl *this = impl_from_IFont(iface);
998 TRACE("(%p)->(%p)\n", this, phfont);
1002 if(this->dirty) realize_font(this);
1004 *phfont = this->gdiFont;
1005 TRACE("Returning %p\n", *phfont);
1009 /************************************************************************
1010 * OLEFontImpl_Clone (IFont)
1012 static HRESULT WINAPI OLEFontImpl_Clone(
1016 OLEFontImpl *this = impl_from_IFont(iface);
1017 OLEFontImpl* newObject;
1019 TRACE("(%p)->(%p)\n", this, ppfont);
1026 newObject = HeapAlloc(GetProcessHeap(), 0, sizeof(OLEFontImpl));
1027 if (newObject==NULL)
1028 return E_OUTOFMEMORY;
1032 /* We need to alloc new memory for the string, otherwise
1033 * we free memory twice.
1035 newObject->description.lpstrName = HeapAlloc(
1037 (1+strlenW(this->description.lpstrName))*2
1039 strcpyW(newObject->description.lpstrName, this->description.lpstrName);
1041 /* Increment internal ref in hfont item list */
1042 if(newObject->gdiFont) inc_int_ref(newObject->gdiFont);
1044 InterlockedIncrement(&ifont_cnt);
1046 newObject->pPropertyNotifyCP = NULL;
1047 newObject->pFontEventsCP = NULL;
1048 CreateConnectionPoint((IUnknown*)newObject, &IID_IPropertyNotifySink, &newObject->pPropertyNotifyCP);
1049 CreateConnectionPoint((IUnknown*)newObject, &IID_IFontEventsDisp, &newObject->pFontEventsCP);
1051 if (!newObject->pPropertyNotifyCP || !newObject->pFontEventsCP)
1053 OLEFontImpl_Destroy(newObject);
1054 return E_OUTOFMEMORY;
1057 /* The cloned object starts with a reference count of 1 */
1060 *ppfont = &newObject->IFont_iface;
1065 /************************************************************************
1066 * OLEFontImpl_IsEqual (IFont)
1068 static HRESULT WINAPI OLEFontImpl_IsEqual(
1072 OLEFontImpl *left = impl_from_IFont(iface);
1073 OLEFontImpl *right = impl_from_IFont(pFontOther);
1075 INT left_len,right_len;
1077 if(pFontOther == NULL)
1079 else if (left->description.cySize.s.Lo != right->description.cySize.s.Lo)
1081 else if (left->description.cySize.s.Hi != right->description.cySize.s.Hi)
1083 else if (left->description.sWeight != right->description.sWeight)
1085 else if (left->description.sCharset != right->description.sCharset)
1087 else if (left->description.fItalic != right->description.fItalic)
1089 else if (left->description.fUnderline != right->description.fUnderline)
1091 else if (left->description.fStrikethrough != right->description.fStrikethrough)
1094 /* Check from string */
1095 left_len = strlenW(left->description.lpstrName);
1096 right_len = strlenW(right->description.lpstrName);
1097 ret = CompareStringW(0,0,left->description.lpstrName, left_len,
1098 right->description.lpstrName, right_len);
1099 if (ret != CSTR_EQUAL)
1105 /************************************************************************
1106 * OLEFontImpl_SetRatio (IFont)
1108 static HRESULT WINAPI OLEFontImpl_SetRatio(
1113 OLEFontImpl *this = impl_from_IFont(iface);
1114 TRACE("(%p)->(%d, %d)\n", this, cyLogical, cyHimetric);
1116 if(cyLogical == 0 || cyHimetric == 0)
1117 return E_INVALIDARG;
1119 this->cyLogical = cyLogical;
1120 this->cyHimetric = cyHimetric;
1126 /************************************************************************
1127 * OLEFontImpl_QueryTextMetrics (IFont)
1129 static HRESULT WINAPI OLEFontImpl_QueryTextMetrics(
1134 HFONT hOldFont, hNewFont;
1137 IFont_get_hFont(iface, &hNewFont);
1138 hOldFont = SelectObject(hdcRef, hNewFont);
1139 GetTextMetricsW(hdcRef, ptm);
1140 SelectObject(hdcRef, hOldFont);
1141 ReleaseDC(0, hdcRef);
1145 /************************************************************************
1146 * OLEFontImpl_AddRefHfont (IFont)
1148 static HRESULT WINAPI OLEFontImpl_AddRefHfont(
1152 OLEFontImpl *this = impl_from_IFont(iface);
1154 TRACE("(%p)->(%p)\n", this, hfont);
1156 if (!hfont) return E_INVALIDARG;
1158 return inc_ext_ref(hfont);
1161 /************************************************************************
1162 * OLEFontImpl_ReleaseHfont (IFont)
1164 static HRESULT WINAPI OLEFontImpl_ReleaseHfont(
1168 OLEFontImpl *this = impl_from_IFont(iface);
1170 TRACE("(%p)->(%p)\n", this, hfont);
1172 if (!hfont) return E_INVALIDARG;
1174 return dec_ext_ref(hfont);
1177 /************************************************************************
1178 * OLEFontImpl_SetHdc (IFont)
1180 static HRESULT WINAPI OLEFontImpl_SetHdc(
1184 OLEFontImpl *this = impl_from_IFont(iface);
1185 FIXME("(%p)->(%p): Stub\n", this, hdc);
1189 static const IFontVtbl OLEFontImpl_VTable =
1191 OLEFontImpl_QueryInterface,
1193 OLEFontImpl_Release,
1194 OLEFontImpl_get_Name,
1195 OLEFontImpl_put_Name,
1196 OLEFontImpl_get_Size,
1197 OLEFontImpl_put_Size,
1198 OLEFontImpl_get_Bold,
1199 OLEFontImpl_put_Bold,
1200 OLEFontImpl_get_Italic,
1201 OLEFontImpl_put_Italic,
1202 OLEFontImpl_get_Underline,
1203 OLEFontImpl_put_Underline,
1204 OLEFontImpl_get_Strikethrough,
1205 OLEFontImpl_put_Strikethrough,
1206 OLEFontImpl_get_Weight,
1207 OLEFontImpl_put_Weight,
1208 OLEFontImpl_get_Charset,
1209 OLEFontImpl_put_Charset,
1210 OLEFontImpl_get_hFont,
1212 OLEFontImpl_IsEqual,
1213 OLEFontImpl_SetRatio,
1214 OLEFontImpl_QueryTextMetrics,
1215 OLEFontImpl_AddRefHfont,
1216 OLEFontImpl_ReleaseHfont,
1220 /************************************************************************
1221 * OLEFontImpl_IDispatch_QueryInterface (IUnknown)
1223 static HRESULT WINAPI OLEFontImpl_IDispatch_QueryInterface(
1228 OLEFontImpl *this = impl_from_IDispatch(iface);
1229 return IFont_QueryInterface(&this->IFont_iface, riid, ppvoid);
1232 /************************************************************************
1233 * OLEFontImpl_IDispatch_Release (IUnknown)
1235 static ULONG WINAPI OLEFontImpl_IDispatch_Release(
1238 OLEFontImpl *this = impl_from_IDispatch(iface);
1239 return IFont_Release(&this->IFont_iface);
1242 /************************************************************************
1243 * OLEFontImpl_IDispatch_AddRef (IUnknown)
1245 static ULONG WINAPI OLEFontImpl_IDispatch_AddRef(
1248 OLEFontImpl *this = impl_from_IDispatch(iface);
1249 return IFont_AddRef(&this->IFont_iface);
1252 /************************************************************************
1253 * OLEFontImpl_GetTypeInfoCount (IDispatch)
1255 static HRESULT WINAPI OLEFontImpl_GetTypeInfoCount(
1257 unsigned int* pctinfo)
1259 OLEFontImpl *this = impl_from_IDispatch(iface);
1260 TRACE("(%p)->(%p)\n", this, pctinfo);
1266 /************************************************************************
1267 * OLEFontImpl_GetTypeInfo (IDispatch)
1269 static HRESULT WINAPI OLEFontImpl_GetTypeInfo(
1273 ITypeInfo** ppTInfo)
1275 static const WCHAR stdole2tlb[] = {'s','t','d','o','l','e','2','.','t','l','b',0};
1279 OLEFontImpl *this = impl_from_IDispatch(iface);
1280 TRACE("(%p, iTInfo=%d, lcid=%04x, %p)\n", this, iTInfo, (int)lcid, ppTInfo);
1283 hres = LoadTypeLib(stdole2tlb, &tl);
1285 ERR("Could not load the stdole2.tlb?\n");
1288 hres = ITypeLib_GetTypeInfoOfGuid(tl, &IID_IFontDisp, ppTInfo);
1289 ITypeLib_Release(tl);
1291 FIXME("Did not IDispatch typeinfo from typelib, hres %x\n",hres);
1296 /************************************************************************
1297 * OLEFontImpl_GetIDsOfNames (IDispatch)
1299 static HRESULT WINAPI OLEFontImpl_GetIDsOfNames(
1302 LPOLESTR* rgszNames,
1310 OLEFontImpl *this = impl_from_IDispatch(iface);
1312 TRACE("(%p,%s,%p,cNames=%d,lcid=%04x,%p)\n", this, debugstr_guid(riid),
1313 rgszNames, cNames, (int)lcid, rgDispId);
1315 if (cNames == 0) return E_INVALIDARG;
1317 hres = IDispatch_GetTypeInfo(iface, 0, lcid, &pTInfo);
1320 ERR("GetTypeInfo failed.\n");
1324 /* convert names to DISPIDs */
1325 hres = DispGetIDsOfNames (pTInfo, rgszNames, cNames, rgDispId);
1326 ITypeInfo_Release(pTInfo);
1331 /************************************************************************
1332 * OLEFontImpl_Invoke (IDispatch)
1334 * Note: Do not call _put_Xxx methods, since setting things here
1335 * should not call notify functions as I found out debugging the generic
1338 static HRESULT WINAPI OLEFontImpl_Invoke(
1340 DISPID dispIdMember,
1344 DISPPARAMS* pDispParams,
1345 VARIANT* pVarResult,
1346 EXCEPINFO* pExepInfo,
1349 OLEFontImpl *this = impl_from_IDispatch(iface);
1352 TRACE("%p->(%d,%s,0x%x,0x%x,%p,%p,%p,%p)\n", this, dispIdMember,
1353 debugstr_guid(riid), lcid, wFlags, pDispParams, pVarResult, pExepInfo,
1356 /* validate parameters */
1358 if (!IsEqualIID(riid, &IID_NULL))
1360 ERR("riid was %s instead of IID_NULL\n", debugstr_guid(riid));
1361 return DISP_E_UNKNOWNINTERFACE;
1364 if (wFlags & DISPATCH_PROPERTYGET)
1368 ERR("null pVarResult not allowed when DISPATCH_PROPERTYGET specified\n");
1369 return DISP_E_PARAMNOTOPTIONAL;
1372 else if (wFlags & DISPATCH_PROPERTYPUT)
1376 ERR("null pDispParams not allowed when DISPATCH_PROPERTYPUT specified\n");
1377 return DISP_E_PARAMNOTOPTIONAL;
1379 if (pDispParams->cArgs != 1)
1381 ERR("param count for DISPATCH_PROPERTYPUT was %d instead of 1\n", pDispParams->cArgs);
1382 return DISP_E_BADPARAMCOUNT;
1387 ERR("one of DISPATCH_PROPERTYGET or DISPATCH_PROPERTYPUT must be specified\n");
1388 return DISP_E_MEMBERNOTFOUND;
1391 switch (dispIdMember) {
1392 case DISPID_FONT_NAME:
1393 if (wFlags & DISPATCH_PROPERTYGET) {
1394 V_VT(pVarResult) = VT_BSTR;
1395 return IFont_get_Name(&this->IFont_iface, &V_BSTR(pVarResult));
1399 VariantInit(&vararg);
1400 hr = VariantChangeTypeEx(&vararg, &pDispParams->rgvarg[0], lcid, 0, VT_BSTR);
1404 hr = IFont_put_Name(&this->IFont_iface, V_BSTR(&vararg));
1406 VariantClear(&vararg);
1410 case DISPID_FONT_BOLD:
1411 if (wFlags & DISPATCH_PROPERTYGET) {
1413 hr = IFont_get_Bold(&this->IFont_iface, &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_Bold(&this->IFont_iface, V_BOOL(&vararg));
1427 VariantClear(&vararg);
1431 case DISPID_FONT_ITALIC:
1432 if (wFlags & DISPATCH_PROPERTYGET) {
1434 hr = IFont_get_Italic(&this->IFont_iface, &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_Italic(&this->IFont_iface, V_BOOL(&vararg));
1448 VariantClear(&vararg);
1452 case DISPID_FONT_UNDER:
1453 if (wFlags & DISPATCH_PROPERTYGET) {
1455 hr = IFont_get_Underline(&this->IFont_iface, &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_Underline(&this->IFont_iface, V_BOOL(&vararg));
1469 VariantClear(&vararg);
1473 case DISPID_FONT_STRIKE:
1474 if (wFlags & DISPATCH_PROPERTYGET) {
1476 hr = IFont_get_Strikethrough(&this->IFont_iface, &value);
1477 V_VT(pVarResult) = VT_BOOL;
1478 V_BOOL(pVarResult) = value ? VARIANT_TRUE : VARIANT_FALSE;
1483 VariantInit(&vararg);
1484 hr = VariantChangeTypeEx(&vararg, &pDispParams->rgvarg[0], lcid, 0, VT_BOOL);
1488 hr = IFont_put_Strikethrough(&this->IFont_iface, V_BOOL(&vararg));
1490 VariantClear(&vararg);
1494 case DISPID_FONT_SIZE:
1495 if (wFlags & DISPATCH_PROPERTYGET) {
1496 V_VT(pVarResult) = VT_CY;
1497 return IFont_get_Size(&this->IFont_iface, &V_CY(pVarResult));
1501 VariantInit(&vararg);
1502 hr = VariantChangeTypeEx(&vararg, &pDispParams->rgvarg[0], lcid, 0, VT_CY);
1506 hr = IFont_put_Size(&this->IFont_iface, V_CY(&vararg));
1508 VariantClear(&vararg);
1512 case DISPID_FONT_WEIGHT:
1513 if (wFlags & DISPATCH_PROPERTYGET) {
1514 V_VT(pVarResult) = VT_I2;
1515 return IFont_get_Weight(&this->IFont_iface, &V_I2(pVarResult));
1519 VariantInit(&vararg);
1520 hr = VariantChangeTypeEx(&vararg, &pDispParams->rgvarg[0], lcid, 0, VT_I2);
1524 hr = IFont_put_Weight(&this->IFont_iface, V_I2(&vararg));
1526 VariantClear(&vararg);
1530 case DISPID_FONT_CHARSET:
1531 if (wFlags & DISPATCH_PROPERTYGET) {
1532 V_VT(pVarResult) = VT_I2;
1533 return OLEFontImpl_get_Charset(&this->IFont_iface, &V_I2(pVarResult));
1537 VariantInit(&vararg);
1538 hr = VariantChangeTypeEx(&vararg, &pDispParams->rgvarg[0], lcid, 0, VT_I2);
1542 hr = IFont_put_Charset(&this->IFont_iface, V_I2(&vararg));
1544 VariantClear(&vararg);
1549 ERR("member not found for dispid 0x%x\n", dispIdMember);
1550 return DISP_E_MEMBERNOTFOUND;
1554 static const IDispatchVtbl OLEFontImpl_IDispatch_VTable =
1556 OLEFontImpl_IDispatch_QueryInterface,
1557 OLEFontImpl_IDispatch_AddRef,
1558 OLEFontImpl_IDispatch_Release,
1559 OLEFontImpl_GetTypeInfoCount,
1560 OLEFontImpl_GetTypeInfo,
1561 OLEFontImpl_GetIDsOfNames,
1565 /************************************************************************
1566 * OLEFontImpl_IPersistStream_QueryInterface (IUnknown)
1568 static HRESULT WINAPI OLEFontImpl_IPersistStream_QueryInterface(
1569 IPersistStream* iface,
1573 OLEFontImpl *this = impl_from_IPersistStream(iface);
1575 return IFont_QueryInterface(&this->IFont_iface, riid, ppvoid);
1578 /************************************************************************
1579 * OLEFontImpl_IPersistStream_Release (IUnknown)
1581 static ULONG WINAPI OLEFontImpl_IPersistStream_Release(
1582 IPersistStream* iface)
1584 OLEFontImpl *this = impl_from_IPersistStream(iface);
1586 return IFont_Release(&this->IFont_iface);
1589 /************************************************************************
1590 * OLEFontImpl_IPersistStream_AddRef (IUnknown)
1592 static ULONG WINAPI OLEFontImpl_IPersistStream_AddRef(
1593 IPersistStream* iface)
1595 OLEFontImpl *this = impl_from_IPersistStream(iface);
1597 return IFont_AddRef(&this->IFont_iface);
1600 /************************************************************************
1601 * OLEFontImpl_GetClassID (IPersistStream)
1603 static HRESULT WINAPI OLEFontImpl_GetClassID(
1604 IPersistStream* iface,
1607 TRACE("(%p,%p)\n",iface,pClassID);
1611 *pClassID = CLSID_StdFont;
1616 /************************************************************************
1617 * OLEFontImpl_IsDirty (IPersistStream)
1619 * See Windows documentation for more details on IPersistStream methods.
1621 static HRESULT WINAPI OLEFontImpl_IsDirty(
1622 IPersistStream* iface)
1624 TRACE("(%p)\n",iface);
1628 /************************************************************************
1629 * OLEFontImpl_Load (IPersistStream)
1631 * See Windows documentation for more details on IPersistStream methods.
1633 * This is the format of the standard font serialization as far as I
1636 * Offset Type Value Comment
1637 * 0x0000 Byte Unknown Probably a version number, contains 0x01
1638 * 0x0001 Short Charset Charset value from the FONTDESC structure
1639 * 0x0003 Byte Attributes Flags defined as follows:
1641 * 00000100 - Underline
1642 * 00001000 - Strikethrough
1643 * 0x0004 Short Weight Weight value from FONTDESC structure
1644 * 0x0006 DWORD size "Low" portion of the cySize member of the FONTDESC
1646 * 0x000A Byte name length Length of the font name string (no null character)
1647 * 0x000B String name Name of the font (ASCII, no nul character)
1649 static HRESULT WINAPI OLEFontImpl_Load(
1650 IPersistStream* iface,
1651 IStream* pLoadStream)
1653 char readBuffer[0x100];
1660 OLEFontImpl *this = impl_from_IPersistStream(iface);
1663 * Read the version byte
1665 IStream_Read(pLoadStream, &bVersion, 1, &cbRead);
1674 IStream_Read(pLoadStream, &this->description.sCharset, 2, &cbRead);
1682 IStream_Read(pLoadStream, &bAttributes, 1, &cbRead);
1687 this->description.fItalic = (bAttributes & FONTPERSIST_ITALIC) != 0;
1688 this->description.fStrikethrough = (bAttributes & FONTPERSIST_STRIKETHROUGH) != 0;
1689 this->description.fUnderline = (bAttributes & FONTPERSIST_UNDERLINE) != 0;
1694 IStream_Read(pLoadStream, &this->description.sWeight, 2, &cbRead);
1702 IStream_Read(pLoadStream, &this->description.cySize.s.Lo, 4, &cbRead);
1707 this->description.cySize.s.Hi = 0;
1712 IStream_Read(pLoadStream, &bStringSize, 1, &cbRead);
1717 IStream_Read(pLoadStream, readBuffer, bStringSize, &cbRead);
1719 if (cbRead!=bStringSize)
1722 HeapFree(GetProcessHeap(), 0, this->description.lpstrName);
1724 len = MultiByteToWideChar( CP_ACP, 0, readBuffer, bStringSize, NULL, 0 );
1725 this->description.lpstrName = HeapAlloc( GetProcessHeap(), 0, (len+1) * sizeof(WCHAR) );
1726 MultiByteToWideChar( CP_ACP, 0, readBuffer, bStringSize, this->description.lpstrName, len );
1727 this->description.lpstrName[len] = 0;
1729 /* Ensure use of this font causes a new one to be created */
1730 dec_int_ref(this->gdiFont);
1737 /************************************************************************
1738 * OLEFontImpl_Save (IPersistStream)
1740 static HRESULT WINAPI OLEFontImpl_Save(
1741 IPersistStream* iface,
1742 IStream* pOutStream,
1745 char* writeBuffer = NULL;
1747 BYTE bVersion = 0x01;
1751 OLEFontImpl *this = impl_from_IPersistStream(iface);
1754 * Read the version byte
1756 IStream_Write(pOutStream, &bVersion, 1, &cbWritten);
1764 IStream_Write(pOutStream, &this->description.sCharset, 2, &cbWritten);
1774 if (this->description.fItalic)
1775 bAttributes |= FONTPERSIST_ITALIC;
1777 if (this->description.fStrikethrough)
1778 bAttributes |= FONTPERSIST_STRIKETHROUGH;
1780 if (this->description.fUnderline)
1781 bAttributes |= FONTPERSIST_UNDERLINE;
1783 IStream_Write(pOutStream, &bAttributes, 1, &cbWritten);
1791 IStream_Write(pOutStream, &this->description.sWeight, 2, &cbWritten);
1799 IStream_Write(pOutStream, &this->description.cySize.s.Lo, 4, &cbWritten);
1807 if (this->description.lpstrName!=0)
1808 bStringSize = WideCharToMultiByte( CP_ACP, 0, this->description.lpstrName,
1809 strlenW(this->description.lpstrName), NULL, 0, NULL, NULL );
1813 IStream_Write(pOutStream, &bStringSize, 1, &cbWritten);
1820 if (!(writeBuffer = HeapAlloc( GetProcessHeap(), 0, bStringSize ))) return E_OUTOFMEMORY;
1821 WideCharToMultiByte( CP_ACP, 0, this->description.lpstrName,
1822 strlenW(this->description.lpstrName),
1823 writeBuffer, bStringSize, NULL, NULL );
1825 IStream_Write(pOutStream, writeBuffer, bStringSize, &cbWritten);
1826 HeapFree(GetProcessHeap(), 0, writeBuffer);
1828 if (cbWritten!=bStringSize)
1835 /************************************************************************
1836 * OLEFontImpl_GetSizeMax (IPersistStream)
1838 static HRESULT WINAPI OLEFontImpl_GetSizeMax(
1839 IPersistStream* iface,
1840 ULARGE_INTEGER* pcbSize)
1842 OLEFontImpl *this = impl_from_IPersistStream(iface);
1847 pcbSize->u.HighPart = 0;
1848 pcbSize->u.LowPart = 0;
1850 pcbSize->u.LowPart += sizeof(BYTE); /* Version */
1851 pcbSize->u.LowPart += sizeof(WORD); /* Lang code */
1852 pcbSize->u.LowPart += sizeof(BYTE); /* Flags */
1853 pcbSize->u.LowPart += sizeof(WORD); /* Weight */
1854 pcbSize->u.LowPart += sizeof(DWORD); /* Size */
1855 pcbSize->u.LowPart += sizeof(BYTE); /* StrLength */
1857 if (this->description.lpstrName!=0)
1858 pcbSize->u.LowPart += WideCharToMultiByte( CP_ACP, 0, this->description.lpstrName,
1859 strlenW(this->description.lpstrName),
1860 NULL, 0, NULL, NULL );
1865 static const IPersistStreamVtbl OLEFontImpl_IPersistStream_VTable =
1867 OLEFontImpl_IPersistStream_QueryInterface,
1868 OLEFontImpl_IPersistStream_AddRef,
1869 OLEFontImpl_IPersistStream_Release,
1870 OLEFontImpl_GetClassID,
1871 OLEFontImpl_IsDirty,
1874 OLEFontImpl_GetSizeMax
1877 /************************************************************************
1878 * OLEFontImpl_IConnectionPointContainer_QueryInterface (IUnknown)
1880 static HRESULT WINAPI OLEFontImpl_IConnectionPointContainer_QueryInterface(
1881 IConnectionPointContainer* iface,
1885 OLEFontImpl *this = impl_from_IConnectionPointContainer(iface);
1887 return IFont_QueryInterface(&this->IFont_iface, riid, ppvoid);
1890 /************************************************************************
1891 * OLEFontImpl_IConnectionPointContainer_Release (IUnknown)
1893 static ULONG WINAPI OLEFontImpl_IConnectionPointContainer_Release(
1894 IConnectionPointContainer* iface)
1896 OLEFontImpl *this = impl_from_IConnectionPointContainer(iface);
1898 return IFont_Release(&this->IFont_iface);
1901 /************************************************************************
1902 * OLEFontImpl_IConnectionPointContainer_AddRef (IUnknown)
1904 static ULONG WINAPI OLEFontImpl_IConnectionPointContainer_AddRef(
1905 IConnectionPointContainer* iface)
1907 OLEFontImpl *this = impl_from_IConnectionPointContainer(iface);
1909 return IFont_AddRef(&this->IFont_iface);
1912 /************************************************************************
1913 * OLEFontImpl_EnumConnectionPoints (IConnectionPointContainer)
1915 static HRESULT WINAPI OLEFontImpl_EnumConnectionPoints(
1916 IConnectionPointContainer* iface,
1917 IEnumConnectionPoints **ppEnum)
1919 OLEFontImpl *this = impl_from_IConnectionPointContainer(iface);
1921 FIXME("(%p)->(%p): stub\n", this, ppEnum);
1925 /************************************************************************
1926 * OLEFontImpl_FindConnectionPoint (IConnectionPointContainer)
1928 static HRESULT WINAPI OLEFontImpl_FindConnectionPoint(
1929 IConnectionPointContainer* iface,
1931 IConnectionPoint **ppCp)
1933 OLEFontImpl *this = impl_from_IConnectionPointContainer(iface);
1934 TRACE("(%p)->(%s, %p)\n", this, debugstr_guid(riid), ppCp);
1936 if(IsEqualIID(riid, &IID_IPropertyNotifySink)) {
1937 return IConnectionPoint_QueryInterface(this->pPropertyNotifyCP,
1938 &IID_IConnectionPoint,
1940 } else if(IsEqualIID(riid, &IID_IFontEventsDisp)) {
1941 return IConnectionPoint_QueryInterface(this->pFontEventsCP,
1942 &IID_IConnectionPoint,
1945 FIXME("no connection point for %s\n", debugstr_guid(riid));
1946 return CONNECT_E_NOCONNECTION;
1950 static const IConnectionPointContainerVtbl
1951 OLEFontImpl_IConnectionPointContainer_VTable =
1953 OLEFontImpl_IConnectionPointContainer_QueryInterface,
1954 OLEFontImpl_IConnectionPointContainer_AddRef,
1955 OLEFontImpl_IConnectionPointContainer_Release,
1956 OLEFontImpl_EnumConnectionPoints,
1957 OLEFontImpl_FindConnectionPoint
1960 /************************************************************************
1961 * OLEFontImpl implementation of IPersistPropertyBag.
1963 static HRESULT WINAPI OLEFontImpl_IPersistPropertyBag_QueryInterface(
1964 IPersistPropertyBag *iface, REFIID riid, LPVOID *ppvObj
1966 OLEFontImpl *this = impl_from_IPersistPropertyBag(iface);
1967 return IFont_QueryInterface(&this->IFont_iface,riid,ppvObj);
1970 static ULONG WINAPI OLEFontImpl_IPersistPropertyBag_AddRef(
1971 IPersistPropertyBag *iface
1973 OLEFontImpl *this = impl_from_IPersistPropertyBag(iface);
1974 return IFont_AddRef(&this->IFont_iface);
1977 static ULONG WINAPI OLEFontImpl_IPersistPropertyBag_Release(
1978 IPersistPropertyBag *iface
1980 OLEFontImpl *this = impl_from_IPersistPropertyBag(iface);
1981 return IFont_Release(&this->IFont_iface);
1984 static HRESULT WINAPI OLEFontImpl_IPersistPropertyBag_GetClassID(
1985 IPersistPropertyBag *iface, CLSID *classid
1987 FIXME("(%p,%p), stub!\n", iface, classid);
1991 static HRESULT WINAPI OLEFontImpl_IPersistPropertyBag_InitNew(
1992 IPersistPropertyBag *iface
1994 FIXME("(%p), stub!\n", iface);
1998 static HRESULT WINAPI OLEFontImpl_IPersistPropertyBag_Load(
1999 IPersistPropertyBag *iface, IPropertyBag* pPropBag, IErrorLog* pErrorLog
2001 /* (from Visual Basic 6 property bag)
2002 Name = "MS Sans Serif"
2006 Underline = 0 'False
2008 Strikethrough = 0 'False
2010 static const WCHAR sAttrName[] = {'N','a','m','e',0};
2011 static const WCHAR sAttrSize[] = {'S','i','z','e',0};
2012 static const WCHAR sAttrCharset[] = {'C','h','a','r','s','e','t',0};
2013 static const WCHAR sAttrWeight[] = {'W','e','i','g','h','t',0};
2014 static const WCHAR sAttrUnderline[] = {'U','n','d','e','r','l','i','n','e',0};
2015 static const WCHAR sAttrItalic[] = {'I','t','a','l','i','c',0};
2016 static const WCHAR sAttrStrikethrough[] = {'S','t','r','i','k','e','t','h','r','o','u','g','h',0};
2017 OLEFontImpl *this = impl_from_IPersistPropertyBag(iface);
2021 VariantInit(&value);
2023 iRes = IPropertyBag_Read(pPropBag, sAttrName, &value, pErrorLog);
2026 iRes = VariantChangeType(&value, &value, 0, VT_BSTR);
2028 iRes = IFont_put_Name(&this->IFont_iface, V_BSTR(&value));
2030 else if (iRes == E_INVALIDARG)
2033 VariantClear(&value);
2036 iRes = IPropertyBag_Read(pPropBag, sAttrSize, &value, pErrorLog);
2039 iRes = VariantChangeType(&value, &value, 0, VT_CY);
2041 iRes = IFont_put_Size(&this->IFont_iface, V_CY(&value));
2043 else if (iRes == E_INVALIDARG)
2046 VariantClear(&value);
2050 iRes = IPropertyBag_Read(pPropBag, sAttrCharset, &value, pErrorLog);
2053 iRes = VariantChangeType(&value, &value, 0, VT_I2);
2055 iRes = IFont_put_Charset(&this->IFont_iface, V_I2(&value));
2057 else if (iRes == E_INVALIDARG)
2060 VariantClear(&value);
2064 iRes = IPropertyBag_Read(pPropBag, sAttrWeight, &value, pErrorLog);
2067 iRes = VariantChangeType(&value, &value, 0, VT_I2);
2069 iRes = IFont_put_Weight(&this->IFont_iface, V_I2(&value));
2071 else if (iRes == E_INVALIDARG)
2074 VariantClear(&value);
2078 iRes = IPropertyBag_Read(pPropBag, sAttrUnderline, &value, pErrorLog);
2081 iRes = VariantChangeType(&value, &value, 0, VT_BOOL);
2083 iRes = IFont_put_Underline(&this->IFont_iface, V_BOOL(&value));
2085 else if (iRes == E_INVALIDARG)
2088 VariantClear(&value);
2092 iRes = IPropertyBag_Read(pPropBag, sAttrItalic, &value, pErrorLog);
2095 iRes = VariantChangeType(&value, &value, 0, VT_BOOL);
2097 iRes = IFont_put_Italic(&this->IFont_iface, V_BOOL(&value));
2099 else if (iRes == E_INVALIDARG)
2102 VariantClear(&value);
2106 iRes = IPropertyBag_Read(pPropBag, sAttrStrikethrough, &value, pErrorLog);
2109 iRes = VariantChangeType(&value, &value, 0, VT_BOOL);
2111 IFont_put_Strikethrough(&this->IFont_iface, V_BOOL(&value));
2113 else if (iRes == E_INVALIDARG)
2116 VariantClear(&value);
2120 WARN("-- 0x%08x\n", iRes);
2124 static HRESULT WINAPI OLEFontImpl_IPersistPropertyBag_Save(
2125 IPersistPropertyBag *iface, IPropertyBag* pPropBag, BOOL fClearDirty,
2126 BOOL fSaveAllProperties
2128 FIXME("(%p,%p,%d,%d), stub!\n", iface, pPropBag, fClearDirty, fSaveAllProperties);
2132 static const IPersistPropertyBagVtbl OLEFontImpl_IPersistPropertyBag_VTable =
2134 OLEFontImpl_IPersistPropertyBag_QueryInterface,
2135 OLEFontImpl_IPersistPropertyBag_AddRef,
2136 OLEFontImpl_IPersistPropertyBag_Release,
2138 OLEFontImpl_IPersistPropertyBag_GetClassID,
2139 OLEFontImpl_IPersistPropertyBag_InitNew,
2140 OLEFontImpl_IPersistPropertyBag_Load,
2141 OLEFontImpl_IPersistPropertyBag_Save
2144 /************************************************************************
2145 * OLEFontImpl implementation of IPersistStreamInit.
2147 static HRESULT WINAPI OLEFontImpl_IPersistStreamInit_QueryInterface(
2148 IPersistStreamInit *iface, REFIID riid, LPVOID *ppvObj
2150 OLEFontImpl *this = impl_from_IPersistStreamInit(iface);
2151 return IFont_QueryInterface(&this->IFont_iface,riid,ppvObj);
2154 static ULONG WINAPI OLEFontImpl_IPersistStreamInit_AddRef(
2155 IPersistStreamInit *iface
2157 OLEFontImpl *this = impl_from_IPersistStreamInit(iface);
2158 return IFont_AddRef(&this->IFont_iface);
2161 static ULONG WINAPI OLEFontImpl_IPersistStreamInit_Release(
2162 IPersistStreamInit *iface
2164 OLEFontImpl *this = impl_from_IPersistStreamInit(iface);
2165 return IFont_Release(&this->IFont_iface);
2168 static HRESULT WINAPI OLEFontImpl_IPersistStreamInit_GetClassID(
2169 IPersistStreamInit *iface, CLSID *classid
2171 FIXME("(%p,%p), stub!\n", iface, classid);
2175 static HRESULT WINAPI OLEFontImpl_IPersistStreamInit_IsDirty(
2176 IPersistStreamInit *iface
2178 FIXME("(%p), stub!\n", iface);
2182 static HRESULT WINAPI OLEFontImpl_IPersistStreamInit_Load(
2183 IPersistStreamInit *iface, LPSTREAM pStm
2185 FIXME("(%p,%p), stub!\n", iface, pStm);
2189 static HRESULT WINAPI OLEFontImpl_IPersistStreamInit_Save(
2190 IPersistStreamInit *iface, LPSTREAM pStm, BOOL fClearDirty
2192 FIXME("(%p,%p,%d), stub!\n", iface, pStm, fClearDirty);
2196 static HRESULT WINAPI OLEFontImpl_IPersistStreamInit_GetSizeMax(
2197 IPersistStreamInit *iface, ULARGE_INTEGER *pcbSize
2199 FIXME("(%p,%p), stub!\n", iface, pcbSize);
2203 static HRESULT WINAPI OLEFontImpl_IPersistStreamInit_InitNew(
2204 IPersistStreamInit *iface
2206 FIXME("(%p), stub!\n", iface);
2210 static const IPersistStreamInitVtbl OLEFontImpl_IPersistStreamInit_VTable =
2212 OLEFontImpl_IPersistStreamInit_QueryInterface,
2213 OLEFontImpl_IPersistStreamInit_AddRef,
2214 OLEFontImpl_IPersistStreamInit_Release,
2216 OLEFontImpl_IPersistStreamInit_GetClassID,
2217 OLEFontImpl_IPersistStreamInit_IsDirty,
2218 OLEFontImpl_IPersistStreamInit_Load,
2219 OLEFontImpl_IPersistStreamInit_Save,
2220 OLEFontImpl_IPersistStreamInit_GetSizeMax,
2221 OLEFontImpl_IPersistStreamInit_InitNew
2224 /************************************************************************
2225 * OLEFontImpl_Construct
2227 * This method will construct a new instance of the OLEFontImpl
2230 * The caller of this method must release the object when it's
2233 static OLEFontImpl* OLEFontImpl_Construct(const FONTDESC *fontDesc)
2235 OLEFontImpl* newObject;
2237 newObject = HeapAlloc(GetProcessHeap(), 0, sizeof(OLEFontImpl));
2242 newObject->IFont_iface.lpVtbl = &OLEFontImpl_VTable;
2243 newObject->IDispatch_iface.lpVtbl = &OLEFontImpl_IDispatch_VTable;
2244 newObject->IPersistStream_iface.lpVtbl = &OLEFontImpl_IPersistStream_VTable;
2245 newObject->IConnectionPointContainer_iface.lpVtbl = &OLEFontImpl_IConnectionPointContainer_VTable;
2246 newObject->IPersistPropertyBag_iface.lpVtbl = &OLEFontImpl_IPersistPropertyBag_VTable;
2247 newObject->IPersistStreamInit_iface.lpVtbl = &OLEFontImpl_IPersistStreamInit_VTable;
2252 * Copy the description of the font in the object.
2254 assert(fontDesc->cbSizeofstruct >= sizeof(FONTDESC));
2256 newObject->description.cbSizeofstruct = sizeof(FONTDESC);
2257 newObject->description.lpstrName = HeapAlloc(GetProcessHeap(),
2259 (lstrlenW(fontDesc->lpstrName)+1) * sizeof(WCHAR));
2260 strcpyW(newObject->description.lpstrName, fontDesc->lpstrName);
2261 newObject->description.cySize = fontDesc->cySize;
2262 newObject->description.sWeight = fontDesc->sWeight;
2263 newObject->description.sCharset = fontDesc->sCharset;
2264 newObject->description.fItalic = fontDesc->fItalic;
2265 newObject->description.fUnderline = fontDesc->fUnderline;
2266 newObject->description.fStrikethrough = fontDesc->fStrikethrough;
2268 newObject->gdiFont = 0;
2269 newObject->dirty = TRUE;
2270 newObject->cyLogical = GetDeviceCaps(get_dc(), LOGPIXELSY);
2271 newObject->cyHimetric = 2540L;
2272 newObject->pPropertyNotifyCP = NULL;
2273 newObject->pFontEventsCP = NULL;
2275 CreateConnectionPoint((IUnknown*)newObject, &IID_IPropertyNotifySink, &newObject->pPropertyNotifyCP);
2276 CreateConnectionPoint((IUnknown*)newObject, &IID_IFontEventsDisp, &newObject->pFontEventsCP);
2278 if (!newObject->pPropertyNotifyCP || !newObject->pFontEventsCP)
2280 OLEFontImpl_Destroy(newObject);
2284 InterlockedIncrement(&ifont_cnt);
2286 TRACE("returning %p\n", newObject);
2290 /************************************************************************
2291 * OLEFontImpl_Destroy
2293 * This method is called by the Release method when the reference
2294 * count goes down to 0. It will free all resources used by
2297 static void OLEFontImpl_Destroy(OLEFontImpl* fontDesc)
2299 TRACE("(%p)\n", fontDesc);
2301 HeapFree(GetProcessHeap(), 0, fontDesc->description.lpstrName);
2303 if (fontDesc->pPropertyNotifyCP)
2304 IConnectionPoint_Release(fontDesc->pPropertyNotifyCP);
2305 if (fontDesc->pFontEventsCP)
2306 IConnectionPoint_Release(fontDesc->pFontEventsCP);
2308 HeapFree(GetProcessHeap(), 0, fontDesc);
2311 /*******************************************************************************
2312 * StdFont ClassFactory
2316 /* IUnknown fields */
2317 IClassFactory IClassFactory_iface;
2319 } IClassFactoryImpl;
2321 static inline IClassFactoryImpl *impl_from_IClassFactory(IClassFactory *iface)
2323 return CONTAINING_RECORD(iface, IClassFactoryImpl, IClassFactory_iface);
2326 static HRESULT WINAPI
2327 SFCF_QueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj) {
2328 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
2330 FIXME("(%p)->(%s,%p),stub!\n",This,debugstr_guid(riid),ppobj);
2331 return E_NOINTERFACE;
2335 SFCF_AddRef(LPCLASSFACTORY iface) {
2336 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
2337 return InterlockedIncrement(&This->ref);
2340 static ULONG WINAPI SFCF_Release(LPCLASSFACTORY iface) {
2341 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
2342 /* static class, won't be freed */
2343 return InterlockedDecrement(&This->ref);
2346 static HRESULT WINAPI SFCF_CreateInstance(
2347 LPCLASSFACTORY iface,LPUNKNOWN pOuter,REFIID riid,LPVOID *ppobj
2349 return OleCreateFontIndirect(NULL,riid,ppobj);
2353 static HRESULT WINAPI SFCF_LockServer(LPCLASSFACTORY iface,BOOL dolock) {
2354 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
2355 FIXME("(%p)->(%d),stub!\n",This,dolock);
2359 static const IClassFactoryVtbl SFCF_Vtbl = {
2360 SFCF_QueryInterface,
2363 SFCF_CreateInstance,
2366 static IClassFactoryImpl STDFONT_CF = {{&SFCF_Vtbl}, 1 };
2368 void _get_STDFONT_CF(LPVOID *ppv) { *ppv = &STDFONT_CF; }