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.
281 IConnectionPoint *pPropertyNotifyCP;
282 IConnectionPoint *pFontEventsCP;
286 * Here, I define utility macros to help with the casting of the
288 * There is a version to accommodate all of the VTables implemented
292 static inline OLEFontImpl *impl_from_IFont(IFont *iface)
294 return CONTAINING_RECORD(iface, OLEFontImpl, IFont_iface);
297 static inline OLEFontImpl *impl_from_IDispatch( IDispatch *iface )
299 return CONTAINING_RECORD(iface, OLEFontImpl, IDispatch_iface);
302 static inline OLEFontImpl *impl_from_IPersistStream( IPersistStream *iface )
304 return CONTAINING_RECORD(iface, OLEFontImpl, IPersistStream_iface);
307 static inline OLEFontImpl *impl_from_IConnectionPointContainer( IConnectionPointContainer *iface )
309 return CONTAINING_RECORD(iface, OLEFontImpl, IConnectionPointContainer_iface);
312 static inline OLEFontImpl *impl_from_IPersistPropertyBag( IPersistPropertyBag *iface )
314 return CONTAINING_RECORD(iface, OLEFontImpl, IPersistPropertyBag_iface);
317 static inline OLEFontImpl *impl_from_IPersistStreamInit( IPersistStreamInit *iface )
319 return CONTAINING_RECORD(iface, OLEFontImpl, IPersistStreamInit_iface);
323 /***********************************************************************
324 * Prototypes for the implementation functions for the IFont
327 static OLEFontImpl* OLEFontImpl_Construct(const FONTDESC *fontDesc);
328 static void OLEFontImpl_Destroy(OLEFontImpl* fontDesc);
329 static ULONG WINAPI OLEFontImpl_AddRef(IFont* iface);
331 /******************************************************************************
332 * OleCreateFontIndirect [OLEAUT32.420]
334 HRESULT WINAPI OleCreateFontIndirect(
335 LPFONTDESC lpFontDesc,
339 OLEFontImpl* newFont = 0;
342 TRACE("(%p, %s, %p)\n", lpFontDesc, debugstr_guid(riid), ppvObj);
354 static WCHAR fname[] = { 'S','y','s','t','e','m',0 };
356 fd.cbSizeofstruct = sizeof(fd);
357 fd.lpstrName = fname;
358 fd.cySize.s.Lo = 80000;
364 fd.fStrikethrough = 0;
369 * Try to construct a new instance of the class.
371 newFont = OLEFontImpl_Construct(lpFontDesc);
374 return E_OUTOFMEMORY;
377 * Make sure it supports the interface required by the caller.
379 hr = IFont_QueryInterface(&newFont->IFont_iface, riid, ppvObj);
382 * Release the reference obtained in the constructor. If
383 * the QueryInterface was unsuccessful, it will free the class.
385 IFont_Release(&newFont->IFont_iface);
391 /***********************************************************************
392 * Implementation of the OLEFontImpl class.
395 /***********************************************************************
396 * OLEFont_SendNotify (internal)
398 * Sends notification messages of changed properties to any interested
401 static void OLEFont_SendNotify(OLEFontImpl* this, DISPID dispID)
403 static const WCHAR wszName[] = {'N','a','m','e',0};
404 static const WCHAR wszSize[] = {'S','i','z','e',0};
405 static const WCHAR wszBold[] = {'B','o','l','d',0};
406 static const WCHAR wszItalic[] = {'I','t','a','l','i','c',0};
407 static const WCHAR wszUnder[] = {'U','n','d','e','r','l','i','n','e',0};
408 static const WCHAR wszStrike[] = {'S','t','r','i','k','e','t','h','r','o','u','g','h',0};
409 static const WCHAR wszWeight[] = {'W','e','i','g','h','t',0};
410 static const WCHAR wszCharset[] = {'C','h','a','r','s','s','e','t',0};
411 static const LPCWSTR dispid_mapping[] =
424 IEnumConnections *pEnum;
430 hres = IConnectionPoint_EnumConnections(this->pPropertyNotifyCP, &pEnum);
433 while(IEnumConnections_Next(pEnum, 1, &CD, NULL) == S_OK) {
434 IPropertyNotifySink *sink;
436 IUnknown_QueryInterface(CD.pUnk, &IID_IPropertyNotifySink, (LPVOID)&sink);
437 IPropertyNotifySink_OnChanged(sink, dispID);
438 IPropertyNotifySink_Release(sink);
439 IUnknown_Release(CD.pUnk);
441 IEnumConnections_Release(pEnum);
444 hres = IConnectionPoint_EnumConnections(this->pFontEventsCP, &pEnum);
447 DISPPARAMS dispparams;
450 VariantInit(&vararg);
451 V_VT(&vararg) = VT_BSTR;
452 V_BSTR(&vararg) = SysAllocString(dispid_mapping[dispID]);
454 dispparams.cArgs = 1;
455 dispparams.cNamedArgs = 0;
456 dispparams.rgdispidNamedArgs = NULL;
457 dispparams.rgvarg = &vararg;
459 while(IEnumConnections_Next(pEnum, 1, &CD, NULL) == S_OK) {
460 IFontEventsDisp *disp;
462 IUnknown_QueryInterface(CD.pUnk, &IID_IFontEventsDisp, (LPVOID)&disp);
463 IDispatch_Invoke(disp, DISPID_FONT_CHANGED, &IID_NULL,
464 LOCALE_NEUTRAL, INVOKE_FUNC, &dispparams, NULL,
467 IDispatch_Release(disp);
468 IUnknown_Release(CD.pUnk);
470 VariantClear(&vararg);
471 IEnumConnections_Release(pEnum);
475 /************************************************************************
476 * OLEFontImpl_QueryInterface (IUnknown)
478 * See Windows documentation for more details on IUnknown methods.
480 static HRESULT WINAPI OLEFontImpl_QueryInterface(
485 OLEFontImpl *this = impl_from_IFont(iface);
486 TRACE("(%p)->(%s, %p)\n", this, debugstr_guid(riid), ppvObject);
491 * Compare the riid with the interface IDs implemented by this object.
493 if (IsEqualGUID(&IID_IUnknown, riid))
495 if (IsEqualGUID(&IID_IFont, riid))
497 if (IsEqualGUID(&IID_IDispatch, riid))
498 *ppvObject = &this->IDispatch_iface;
499 if (IsEqualGUID(&IID_IFontDisp, riid))
500 *ppvObject = &this->IDispatch_iface;
501 if (IsEqualIID(&IID_IPersist, riid) || IsEqualGUID(&IID_IPersistStream, riid))
502 *ppvObject = &this->IPersistStream_iface;
503 if (IsEqualGUID(&IID_IConnectionPointContainer, riid))
504 *ppvObject = &this->IConnectionPointContainer_iface;
505 if (IsEqualGUID(&IID_IPersistPropertyBag, riid))
506 *ppvObject = &this->IPersistPropertyBag_iface;
507 if (IsEqualGUID(&IID_IPersistStreamInit, riid))
508 *ppvObject = &this->IPersistStreamInit_iface;
511 * Check that we obtained an interface.
515 FIXME("() : asking for unsupported interface %s\n",debugstr_guid(riid));
516 return E_NOINTERFACE;
518 OLEFontImpl_AddRef(&this->IFont_iface);
522 /************************************************************************
523 * OLEFontImpl_AddRef (IUnknown)
525 * See Windows documentation for more details on IUnknown methods.
527 static ULONG WINAPI OLEFontImpl_AddRef(
530 OLEFontImpl *this = impl_from_IFont(iface);
531 TRACE("(%p)->(ref=%d)\n", this, this->ref);
532 return InterlockedIncrement(&this->ref);
535 /************************************************************************
536 * OLEFontImpl_Release (IUnknown)
538 * See Windows documentation for more details on IUnknown methods.
540 static ULONG WINAPI OLEFontImpl_Release(
543 OLEFontImpl *this = impl_from_IFont(iface);
545 TRACE("(%p)->(ref=%d)\n", this, this->ref);
547 /* Decrease the reference count for current interface */
548 ret = InterlockedDecrement(&this->ref);
550 /* If the reference count goes down to 0, destroy. */
553 ULONG fontlist_refs = InterlockedDecrement(&ifont_cnt);
555 /* Final IFont object so destroy font cache */
556 if (fontlist_refs == 0)
558 HFONTItem *item, *cursor2;
560 EnterCriticalSection(&OLEFontImpl_csHFONTLIST);
561 LIST_FOR_EACH_ENTRY_SAFE(item, cursor2, &OLEFontImpl_hFontList, HFONTItem, entry)
562 HFONTItem_Delete(item);
563 LeaveCriticalSection(&OLEFontImpl_csHFONTLIST);
568 dec_int_ref(this->gdiFont);
570 OLEFontImpl_Destroy(this);
582 static int CALLBACK font_enum_proc(const LOGFONTW *elf, const TEXTMETRICW *ntm, DWORD type, LPARAM lp)
584 enum_data *data = (enum_data*)lp;
586 if(elf->lfCharSet == data->orig_cs)
588 data->avail_cs = data->orig_cs;
591 if(data->avail_cs == -1) data->avail_cs = elf->lfCharSet;
595 static void realize_font(OLEFontImpl *This)
601 WCHAR text_face[LF_FACESIZE];
610 old_font = SelectObject(hdc, This->gdiFont);
611 GetTextFaceW(hdc, sizeof(text_face) / sizeof(text_face[0]), text_face);
612 SelectObject(hdc, old_font);
613 dec_int_ref(This->gdiFont);
617 memset(&logFont, 0, sizeof(LOGFONTW));
619 lstrcpynW(logFont.lfFaceName, This->description.lpstrName, LF_FACESIZE);
620 logFont.lfCharSet = This->description.sCharset;
622 /* If the font name has been changed then enumerate all charsets
623 and pick one that'll result in the font specified being selected */
624 if(text_face[0] && lstrcmpiW(text_face, This->description.lpstrName))
627 data.orig_cs = This->description.sCharset;
629 logFont.lfCharSet = DEFAULT_CHARSET;
630 EnumFontFamiliesExW(get_dc(), &logFont, font_enum_proc, (LPARAM)&data, 0);
631 if(data.avail_cs != -1) logFont.lfCharSet = data.avail_cs;
636 * The height of the font returned by the get_Size property is the
637 * height of the font in points multiplied by 10000... Using some
638 * simple conversions and the ratio given by the application, it can
639 * be converted to a height in pixels.
641 * Standard ratio is 72 / 2540, or 18 / 635 in lowest terms.
642 * Ratio is applied here relative to the standard.
645 fontHeight = MulDiv( This->description.cySize.s.Lo, This->cyLogical*635, This->cyHimetric*18 );
648 logFont.lfHeight = ((fontHeight%10000L)>5000L) ? (-fontHeight/10000L) - 1 :
649 (-fontHeight/10000L);
650 logFont.lfItalic = This->description.fItalic;
651 logFont.lfUnderline = This->description.fUnderline;
652 logFont.lfStrikeOut = This->description.fStrikethrough;
653 logFont.lfWeight = This->description.sWeight;
654 logFont.lfOutPrecision = OUT_CHARACTER_PRECIS;
655 logFont.lfClipPrecision = CLIP_DEFAULT_PRECIS;
656 logFont.lfQuality = DEFAULT_QUALITY;
657 logFont.lfPitchAndFamily = DEFAULT_PITCH;
659 This->gdiFont = CreateFontIndirectW(&logFont);
662 add_hfontitem(This->gdiFont);
664 /* Fixup the name and charset properties so that they match the
666 old_font = SelectObject(get_dc(), This->gdiFont);
667 GetTextFaceW(hdc, sizeof(text_face) / sizeof(text_face[0]), text_face);
668 if(lstrcmpiW(text_face, This->description.lpstrName))
670 HeapFree(GetProcessHeap(), 0, This->description.lpstrName);
671 This->description.lpstrName = strdupW(text_face);
673 GetTextMetricsW(hdc, &tm);
674 This->description.sCharset = tm.tmCharSet;
675 SelectObject(hdc, old_font);
679 /************************************************************************
680 * OLEFontImpl_get_Name (IFont)
682 * See Windows documentation for more details on IFont methods.
684 static HRESULT WINAPI OLEFontImpl_get_Name(
688 OLEFontImpl *this = impl_from_IFont(iface);
689 TRACE("(%p)->(%p)\n", this, pname);
696 if(this->dirty) realize_font(this);
698 if (this->description.lpstrName!=0)
699 *pname = SysAllocString(this->description.lpstrName);
706 /************************************************************************
707 * OLEFontImpl_put_Name (IFont)
709 * See Windows documentation for more details on IFont methods.
711 static HRESULT WINAPI OLEFontImpl_put_Name(
715 OLEFontImpl *this = impl_from_IFont(iface);
716 TRACE("(%p)->(%p)\n", this, name);
719 return CTL_E_INVALIDPROPERTYVALUE;
721 if (this->description.lpstrName==0)
723 this->description.lpstrName = HeapAlloc(GetProcessHeap(),
725 (lstrlenW(name)+1) * sizeof(WCHAR));
729 this->description.lpstrName = HeapReAlloc(GetProcessHeap(),
731 this->description.lpstrName,
732 (lstrlenW(name)+1) * sizeof(WCHAR));
735 if (this->description.lpstrName==0)
736 return E_OUTOFMEMORY;
738 strcpyW(this->description.lpstrName, name);
739 TRACE("new name %s\n", debugstr_w(this->description.lpstrName));
740 OLEFont_SendNotify(this, DISPID_FONT_NAME);
744 /************************************************************************
745 * OLEFontImpl_get_Size (IFont)
747 * See Windows documentation for more details on IFont methods.
749 static HRESULT WINAPI OLEFontImpl_get_Size(
753 OLEFontImpl *this = impl_from_IFont(iface);
754 TRACE("(%p)->(%p)\n", this, psize);
762 if(this->dirty) realize_font(this);
765 psize->s.Lo = this->description.cySize.s.Lo;
770 /************************************************************************
771 * OLEFontImpl_put_Size (IFont)
773 * See Windows documentation for more details on IFont methods.
775 static HRESULT WINAPI OLEFontImpl_put_Size(
779 OLEFontImpl *this = impl_from_IFont(iface);
780 TRACE("(%p)->(%d)\n", this, size.s.Lo);
781 this->description.cySize.s.Hi = 0;
782 this->description.cySize.s.Lo = size.s.Lo;
783 OLEFont_SendNotify(this, DISPID_FONT_SIZE);
788 /************************************************************************
789 * OLEFontImpl_get_Bold (IFont)
791 * See Windows documentation for more details on IFont methods.
793 static HRESULT WINAPI OLEFontImpl_get_Bold(
797 OLEFontImpl *this = impl_from_IFont(iface);
798 TRACE("(%p)->(%p)\n", this, pbold);
805 if(this->dirty) realize_font(this);
807 *pbold = this->description.sWeight > 550;
812 /************************************************************************
813 * OLEFontImpl_put_Bold (IFont)
815 * See Windows documentation for more details on IFont methods.
817 static HRESULT WINAPI OLEFontImpl_put_Bold(
821 OLEFontImpl *this = impl_from_IFont(iface);
822 TRACE("(%p)->(%d)\n", this, bold);
823 this->description.sWeight = bold ? FW_BOLD : FW_NORMAL;
824 OLEFont_SendNotify(this, DISPID_FONT_BOLD);
829 /************************************************************************
830 * OLEFontImpl_get_Italic (IFont)
832 * See Windows documentation for more details on IFont methods.
834 static HRESULT WINAPI OLEFontImpl_get_Italic(
838 OLEFontImpl *this = impl_from_IFont(iface);
839 TRACE("(%p)->(%p)\n", this, pitalic);
846 if(this->dirty) realize_font(this);
848 *pitalic = this->description.fItalic;
853 /************************************************************************
854 * OLEFontImpl_put_Italic (IFont)
856 * See Windows documentation for more details on IFont methods.
858 static HRESULT WINAPI OLEFontImpl_put_Italic(
862 OLEFontImpl *this = impl_from_IFont(iface);
863 TRACE("(%p)->(%d)\n", this, italic);
865 this->description.fItalic = italic;
867 OLEFont_SendNotify(this, DISPID_FONT_ITALIC);
871 /************************************************************************
872 * OLEFontImpl_get_Underline (IFont)
874 * See Windows documentation for more details on IFont methods.
876 static HRESULT WINAPI OLEFontImpl_get_Underline(
880 OLEFontImpl *this = impl_from_IFont(iface);
881 TRACE("(%p)->(%p)\n", this, punderline);
889 if(this->dirty) realize_font(this);
891 *punderline = this->description.fUnderline;
896 /************************************************************************
897 * OLEFontImpl_put_Underline (IFont)
899 * See Windows documentation for more details on IFont methods.
901 static HRESULT WINAPI OLEFontImpl_put_Underline(
905 OLEFontImpl *this = impl_from_IFont(iface);
906 TRACE("(%p)->(%d)\n", this, underline);
908 this->description.fUnderline = underline;
910 OLEFont_SendNotify(this, DISPID_FONT_UNDER);
914 /************************************************************************
915 * OLEFontImpl_get_Strikethrough (IFont)
917 * See Windows documentation for more details on IFont methods.
919 static HRESULT WINAPI OLEFontImpl_get_Strikethrough(
921 BOOL* pstrikethrough)
923 OLEFontImpl *this = impl_from_IFont(iface);
924 TRACE("(%p)->(%p)\n", this, pstrikethrough);
929 if (pstrikethrough==0)
932 if(this->dirty) realize_font(this);
934 *pstrikethrough = this->description.fStrikethrough;
939 /************************************************************************
940 * OLEFontImpl_put_Strikethrough (IFont)
942 * See Windows documentation for more details on IFont methods.
944 static HRESULT WINAPI OLEFontImpl_put_Strikethrough(
948 OLEFontImpl *this = impl_from_IFont(iface);
949 TRACE("(%p)->(%d)\n", this, strikethrough);
951 this->description.fStrikethrough = strikethrough;
952 OLEFont_SendNotify(this, DISPID_FONT_STRIKE);
957 /************************************************************************
958 * OLEFontImpl_get_Weight (IFont)
960 * See Windows documentation for more details on IFont methods.
962 static HRESULT WINAPI OLEFontImpl_get_Weight(
966 OLEFontImpl *this = impl_from_IFont(iface);
967 TRACE("(%p)->(%p)\n", this, pweight);
975 if(this->dirty) realize_font(this);
977 *pweight = this->description.sWeight;
982 /************************************************************************
983 * OLEFontImpl_put_Weight (IFont)
985 * See Windows documentation for more details on IFont methods.
987 static HRESULT WINAPI OLEFontImpl_put_Weight(
991 OLEFontImpl *this = impl_from_IFont(iface);
992 TRACE("(%p)->(%d)\n", this, weight);
994 this->description.sWeight = weight;
996 OLEFont_SendNotify(this, DISPID_FONT_WEIGHT);
1000 /************************************************************************
1001 * OLEFontImpl_get_Charset (IFont)
1003 * See Windows documentation for more details on IFont methods.
1005 static HRESULT WINAPI OLEFontImpl_get_Charset(
1009 OLEFontImpl *this = impl_from_IFont(iface);
1010 TRACE("(%p)->(%p)\n", this, pcharset);
1018 if(this->dirty) realize_font(this);
1020 *pcharset = this->description.sCharset;
1025 /************************************************************************
1026 * OLEFontImpl_put_Charset (IFont)
1028 * See Windows documentation for more details on IFont methods.
1030 static HRESULT WINAPI OLEFontImpl_put_Charset(
1034 OLEFontImpl *this = impl_from_IFont(iface);
1035 TRACE("(%p)->(%d)\n", this, charset);
1037 this->description.sCharset = charset;
1038 OLEFont_SendNotify(this, DISPID_FONT_CHARSET);
1043 /************************************************************************
1044 * OLEFontImpl_get_hFont (IFont)
1046 * See Windows documentation for more details on IFont methods.
1048 static HRESULT WINAPI OLEFontImpl_get_hFont(
1052 OLEFontImpl *this = impl_from_IFont(iface);
1053 TRACE("(%p)->(%p)\n", this, phfont);
1057 if(this->dirty) realize_font(this);
1059 *phfont = this->gdiFont;
1060 TRACE("Returning %p\n", *phfont);
1064 /************************************************************************
1065 * OLEFontImpl_Clone (IFont)
1067 * See Windows documentation for more details on IFont methods.
1069 static HRESULT WINAPI OLEFontImpl_Clone(
1073 OLEFontImpl* newObject = 0;
1074 OLEFontImpl *this = impl_from_IFont(iface);
1076 TRACE("(%p)->(%p)\n", this, ppfont);
1084 * Allocate space for the object.
1086 newObject = HeapAlloc(GetProcessHeap(), 0, sizeof(OLEFontImpl));
1088 if (newObject==NULL)
1089 return E_OUTOFMEMORY;
1093 /* We need to alloc new memory for the string, otherwise
1094 * we free memory twice.
1096 newObject->description.lpstrName = HeapAlloc(
1098 (1+strlenW(this->description.lpstrName))*2
1100 strcpyW(newObject->description.lpstrName, this->description.lpstrName);
1103 /* Increment internal ref in hfont item list */
1104 if(newObject->gdiFont) inc_int_ref(newObject->gdiFont);
1106 InterlockedIncrement(&ifont_cnt);
1108 /* create new connection points */
1109 newObject->pPropertyNotifyCP = NULL;
1110 newObject->pFontEventsCP = NULL;
1111 CreateConnectionPoint((IUnknown*)newObject, &IID_IPropertyNotifySink, &newObject->pPropertyNotifyCP);
1112 CreateConnectionPoint((IUnknown*)newObject, &IID_IFontEventsDisp, &newObject->pFontEventsCP);
1114 if (!newObject->pPropertyNotifyCP || !newObject->pFontEventsCP)
1116 OLEFontImpl_Destroy(newObject);
1117 return E_OUTOFMEMORY;
1120 /* The cloned object starts with a reference count of 1 */
1123 *ppfont = &newObject->IFont_iface;
1128 /************************************************************************
1129 * OLEFontImpl_IsEqual (IFont)
1131 * See Windows documentation for more details on IFont methods.
1133 static HRESULT WINAPI OLEFontImpl_IsEqual(
1137 OLEFontImpl *left = impl_from_IFont(iface);
1138 OLEFontImpl *right = impl_from_IFont(pFontOther);
1140 INT left_len,right_len;
1142 if(pFontOther == NULL)
1144 else if (left->description.cySize.s.Lo != right->description.cySize.s.Lo)
1146 else if (left->description.cySize.s.Hi != right->description.cySize.s.Hi)
1148 else if (left->description.sWeight != right->description.sWeight)
1150 else if (left->description.sCharset != right->description.sCharset)
1152 else if (left->description.fItalic != right->description.fItalic)
1154 else if (left->description.fUnderline != right->description.fUnderline)
1156 else if (left->description.fStrikethrough != right->description.fStrikethrough)
1159 /* Check from string */
1160 left_len = strlenW(left->description.lpstrName);
1161 right_len = strlenW(right->description.lpstrName);
1162 ret = CompareStringW(0,0,left->description.lpstrName, left_len,
1163 right->description.lpstrName, right_len);
1164 if (ret != CSTR_EQUAL)
1170 /************************************************************************
1171 * OLEFontImpl_SetRatio (IFont)
1173 * See Windows documentation for more details on IFont methods.
1175 static HRESULT WINAPI OLEFontImpl_SetRatio(
1180 OLEFontImpl *this = impl_from_IFont(iface);
1181 TRACE("(%p)->(%d, %d)\n", this, cyLogical, cyHimetric);
1183 this->cyLogical = cyLogical;
1184 this->cyHimetric = cyHimetric;
1189 /************************************************************************
1190 * OLEFontImpl_QueryTextMetrics (IFont)
1192 * See Windows documentation for more details on IFont methods.
1194 static HRESULT WINAPI OLEFontImpl_QueryTextMetrics(
1199 HFONT hOldFont, hNewFont;
1202 OLEFontImpl_get_hFont(iface, &hNewFont);
1203 hOldFont = SelectObject(hdcRef, hNewFont);
1204 GetTextMetricsW(hdcRef, ptm);
1205 SelectObject(hdcRef, hOldFont);
1206 ReleaseDC(0, hdcRef);
1210 /************************************************************************
1211 * OLEFontImpl_AddRefHfont (IFont)
1213 * See Windows documentation for more details on IFont methods.
1215 static HRESULT WINAPI OLEFontImpl_AddRefHfont(
1219 OLEFontImpl *this = impl_from_IFont(iface);
1221 TRACE("(%p)->(%p)\n", this, hfont);
1223 if (!hfont) return E_INVALIDARG;
1225 return inc_ext_ref(hfont);
1228 /************************************************************************
1229 * OLEFontImpl_ReleaseHfont (IFont)
1231 * See Windows documentation for more details on IFont methods.
1233 static HRESULT WINAPI OLEFontImpl_ReleaseHfont(
1237 OLEFontImpl *this = impl_from_IFont(iface);
1239 TRACE("(%p)->(%p)\n", this, hfont);
1241 if (!hfont) return E_INVALIDARG;
1243 return dec_ext_ref(hfont);
1246 /************************************************************************
1247 * OLEFontImpl_SetHdc (IFont)
1249 * See Windows documentation for more details on IFont methods.
1251 static HRESULT WINAPI OLEFontImpl_SetHdc(
1255 OLEFontImpl *this = impl_from_IFont(iface);
1256 FIXME("(%p)->(%p): Stub\n", this, hdc);
1261 * Virtual function tables for the OLEFontImpl class.
1263 static const IFontVtbl OLEFontImpl_VTable =
1265 OLEFontImpl_QueryInterface,
1267 OLEFontImpl_Release,
1268 OLEFontImpl_get_Name,
1269 OLEFontImpl_put_Name,
1270 OLEFontImpl_get_Size,
1271 OLEFontImpl_put_Size,
1272 OLEFontImpl_get_Bold,
1273 OLEFontImpl_put_Bold,
1274 OLEFontImpl_get_Italic,
1275 OLEFontImpl_put_Italic,
1276 OLEFontImpl_get_Underline,
1277 OLEFontImpl_put_Underline,
1278 OLEFontImpl_get_Strikethrough,
1279 OLEFontImpl_put_Strikethrough,
1280 OLEFontImpl_get_Weight,
1281 OLEFontImpl_put_Weight,
1282 OLEFontImpl_get_Charset,
1283 OLEFontImpl_put_Charset,
1284 OLEFontImpl_get_hFont,
1286 OLEFontImpl_IsEqual,
1287 OLEFontImpl_SetRatio,
1288 OLEFontImpl_QueryTextMetrics,
1289 OLEFontImpl_AddRefHfont,
1290 OLEFontImpl_ReleaseHfont,
1294 /************************************************************************
1295 * OLEFontImpl_IDispatch_QueryInterface (IUnknown)
1297 * See Windows documentation for more details on IUnknown methods.
1299 static HRESULT WINAPI OLEFontImpl_IDispatch_QueryInterface(
1304 OLEFontImpl *this = impl_from_IDispatch(iface);
1306 return IFont_QueryInterface(&this->IFont_iface, riid, ppvoid);
1309 /************************************************************************
1310 * OLEFontImpl_IDispatch_Release (IUnknown)
1312 * See Windows documentation for more details on IUnknown methods.
1314 static ULONG WINAPI OLEFontImpl_IDispatch_Release(
1317 OLEFontImpl *this = impl_from_IDispatch(iface);
1319 return IFont_Release(&this->IFont_iface);
1322 /************************************************************************
1323 * OLEFontImpl_IDispatch_AddRef (IUnknown)
1325 * See Windows documentation for more details on IUnknown methods.
1327 static ULONG WINAPI OLEFontImpl_IDispatch_AddRef(
1330 OLEFontImpl *this = impl_from_IDispatch(iface);
1332 return IFont_AddRef(&this->IFont_iface);
1335 /************************************************************************
1336 * OLEFontImpl_GetTypeInfoCount (IDispatch)
1338 * See Windows documentation for more details on IDispatch methods.
1340 static HRESULT WINAPI OLEFontImpl_GetTypeInfoCount(
1342 unsigned int* pctinfo)
1344 OLEFontImpl *this = impl_from_IDispatch(iface);
1345 TRACE("(%p)->(%p)\n", this, pctinfo);
1351 /************************************************************************
1352 * OLEFontImpl_GetTypeInfo (IDispatch)
1354 * See Windows documentation for more details on IDispatch methods.
1356 static HRESULT WINAPI OLEFontImpl_GetTypeInfo(
1360 ITypeInfo** ppTInfo)
1362 static const WCHAR stdole2tlb[] = {'s','t','d','o','l','e','2','.','t','l','b',0};
1366 OLEFontImpl *this = impl_from_IDispatch(iface);
1367 TRACE("(%p, iTInfo=%d, lcid=%04x, %p)\n", this, iTInfo, (int)lcid, ppTInfo);
1370 hres = LoadTypeLib(stdole2tlb, &tl);
1372 ERR("Could not load the stdole2.tlb?\n");
1375 hres = ITypeLib_GetTypeInfoOfGuid(tl, &IID_IFontDisp, ppTInfo);
1376 ITypeLib_Release(tl);
1378 FIXME("Did not IDispatch typeinfo from typelib, hres %x\n",hres);
1383 /************************************************************************
1384 * OLEFontImpl_GetIDsOfNames (IDispatch)
1386 * See Windows documentation for more details on IDispatch methods.
1388 static HRESULT WINAPI OLEFontImpl_GetIDsOfNames(
1391 LPOLESTR* rgszNames,
1399 OLEFontImpl *this = impl_from_IDispatch(iface);
1401 TRACE("(%p,%s,%p,cNames=%d,lcid=%04x,%p)\n", this, debugstr_guid(riid),
1402 rgszNames, cNames, (int)lcid, rgDispId);
1406 return E_INVALIDARG;
1410 /* retrieve type information */
1411 hres = OLEFontImpl_GetTypeInfo(iface, 0, lcid, &pTInfo);
1415 ERR("GetTypeInfo failed.\n");
1419 /* convert names to DISPIDs */
1420 hres = DispGetIDsOfNames (pTInfo, rgszNames, cNames, rgDispId);
1421 ITypeInfo_Release(pTInfo);
1427 /************************************************************************
1428 * OLEFontImpl_Invoke (IDispatch)
1430 * See Windows documentation for more details on IDispatch methods.
1432 * Note: Do not call _put_Xxx methods, since setting things here
1433 * should not call notify functions as I found out debugging the generic
1436 static HRESULT WINAPI OLEFontImpl_Invoke(
1438 DISPID dispIdMember,
1442 DISPPARAMS* pDispParams,
1443 VARIANT* pVarResult,
1444 EXCEPINFO* pExepInfo,
1447 OLEFontImpl *this = impl_from_IDispatch(iface);
1450 TRACE("%p->(%d,%s,0x%x,0x%x,%p,%p,%p,%p)\n", this, dispIdMember,
1451 debugstr_guid(riid), lcid, wFlags, pDispParams, pVarResult, pExepInfo,
1454 /* validate parameters */
1456 if (!IsEqualIID(riid, &IID_NULL))
1458 ERR("riid was %s instead of IID_NULL\n", debugstr_guid(riid));
1459 return DISP_E_UNKNOWNINTERFACE;
1462 if (wFlags & DISPATCH_PROPERTYGET)
1466 ERR("null pVarResult not allowed when DISPATCH_PROPERTYGET specified\n");
1467 return DISP_E_PARAMNOTOPTIONAL;
1470 else if (wFlags & DISPATCH_PROPERTYPUT)
1474 ERR("null pDispParams not allowed when DISPATCH_PROPERTYPUT specified\n");
1475 return DISP_E_PARAMNOTOPTIONAL;
1477 if (pDispParams->cArgs != 1)
1479 ERR("param count for DISPATCH_PROPERTYPUT was %d instead of 1\n", pDispParams->cArgs);
1480 return DISP_E_BADPARAMCOUNT;
1485 ERR("one of DISPATCH_PROPERTYGET or DISPATCH_PROPERTYPUT must be specified\n");
1486 return DISP_E_MEMBERNOTFOUND;
1489 switch (dispIdMember) {
1490 case DISPID_FONT_NAME:
1491 if (wFlags & DISPATCH_PROPERTYGET) {
1492 V_VT(pVarResult) = VT_BSTR;
1493 return IFont_get_Name(&this->IFont_iface, &V_BSTR(pVarResult));
1497 VariantInit(&vararg);
1498 hr = VariantChangeTypeEx(&vararg, &pDispParams->rgvarg[0], lcid, 0, VT_BSTR);
1502 hr = IFont_put_Name(&this->IFont_iface, V_BSTR(&vararg));
1504 VariantClear(&vararg);
1508 case DISPID_FONT_BOLD:
1509 if (wFlags & DISPATCH_PROPERTYGET) {
1511 hr = IFont_get_Bold(&this->IFont_iface, &value);
1512 V_VT(pVarResult) = VT_BOOL;
1513 V_BOOL(pVarResult) = value ? VARIANT_TRUE : VARIANT_FALSE;
1518 VariantInit(&vararg);
1519 hr = VariantChangeTypeEx(&vararg, &pDispParams->rgvarg[0], lcid, 0, VT_BOOL);
1523 hr = IFont_put_Bold(&this->IFont_iface, V_BOOL(&vararg));
1525 VariantClear(&vararg);
1529 case DISPID_FONT_ITALIC:
1530 if (wFlags & DISPATCH_PROPERTYGET) {
1532 hr = IFont_get_Italic(&this->IFont_iface, &value);
1533 V_VT(pVarResult) = VT_BOOL;
1534 V_BOOL(pVarResult) = value ? VARIANT_TRUE : VARIANT_FALSE;
1539 VariantInit(&vararg);
1540 hr = VariantChangeTypeEx(&vararg, &pDispParams->rgvarg[0], lcid, 0, VT_BOOL);
1544 hr = IFont_put_Italic(&this->IFont_iface, V_BOOL(&vararg));
1546 VariantClear(&vararg);
1550 case DISPID_FONT_UNDER:
1551 if (wFlags & DISPATCH_PROPERTYGET) {
1553 hr = IFont_get_Underline(&this->IFont_iface, &value);
1554 V_VT(pVarResult) = VT_BOOL;
1555 V_BOOL(pVarResult) = value ? VARIANT_TRUE : VARIANT_FALSE;
1560 VariantInit(&vararg);
1561 hr = VariantChangeTypeEx(&vararg, &pDispParams->rgvarg[0], lcid, 0, VT_BOOL);
1565 hr = IFont_put_Underline(&this->IFont_iface, V_BOOL(&vararg));
1567 VariantClear(&vararg);
1571 case DISPID_FONT_STRIKE:
1572 if (wFlags & DISPATCH_PROPERTYGET) {
1574 hr = IFont_get_Strikethrough(&this->IFont_iface, &value);
1575 V_VT(pVarResult) = VT_BOOL;
1576 V_BOOL(pVarResult) = value ? VARIANT_TRUE : VARIANT_FALSE;
1581 VariantInit(&vararg);
1582 hr = VariantChangeTypeEx(&vararg, &pDispParams->rgvarg[0], lcid, 0, VT_BOOL);
1586 hr = IFont_put_Strikethrough(&this->IFont_iface, V_BOOL(&vararg));
1588 VariantClear(&vararg);
1592 case DISPID_FONT_SIZE:
1593 if (wFlags & DISPATCH_PROPERTYGET) {
1594 V_VT(pVarResult) = VT_CY;
1595 return OLEFontImpl_get_Size(&this->IFont_iface, &V_CY(pVarResult));
1599 VariantInit(&vararg);
1600 hr = VariantChangeTypeEx(&vararg, &pDispParams->rgvarg[0], lcid, 0, VT_CY);
1604 hr = IFont_put_Size(&this->IFont_iface, V_CY(&vararg));
1606 VariantClear(&vararg);
1610 case DISPID_FONT_WEIGHT:
1611 if (wFlags & DISPATCH_PROPERTYGET) {
1612 V_VT(pVarResult) = VT_I2;
1613 return OLEFontImpl_get_Weight(&this->IFont_iface, &V_I2(pVarResult));
1617 VariantInit(&vararg);
1618 hr = VariantChangeTypeEx(&vararg, &pDispParams->rgvarg[0], lcid, 0, VT_I2);
1622 hr = IFont_put_Weight(&this->IFont_iface, V_I2(&vararg));
1624 VariantClear(&vararg);
1628 case DISPID_FONT_CHARSET:
1629 if (wFlags & DISPATCH_PROPERTYGET) {
1630 V_VT(pVarResult) = VT_I2;
1631 return OLEFontImpl_get_Charset(&this->IFont_iface, &V_I2(pVarResult));
1635 VariantInit(&vararg);
1636 hr = VariantChangeTypeEx(&vararg, &pDispParams->rgvarg[0], lcid, 0, VT_I2);
1640 hr = IFont_put_Charset(&this->IFont_iface, V_I2(&vararg));
1642 VariantClear(&vararg);
1647 ERR("member not found for dispid 0x%x\n", dispIdMember);
1648 return DISP_E_MEMBERNOTFOUND;
1652 static const IDispatchVtbl OLEFontImpl_IDispatch_VTable =
1654 OLEFontImpl_IDispatch_QueryInterface,
1655 OLEFontImpl_IDispatch_AddRef,
1656 OLEFontImpl_IDispatch_Release,
1657 OLEFontImpl_GetTypeInfoCount,
1658 OLEFontImpl_GetTypeInfo,
1659 OLEFontImpl_GetIDsOfNames,
1663 /************************************************************************
1664 * OLEFontImpl_IPersistStream_QueryInterface (IUnknown)
1666 * See Windows documentation for more details on IUnknown methods.
1668 static HRESULT WINAPI OLEFontImpl_IPersistStream_QueryInterface(
1669 IPersistStream* iface,
1673 OLEFontImpl *this = impl_from_IPersistStream(iface);
1675 return IFont_QueryInterface(&this->IFont_iface, riid, ppvoid);
1678 /************************************************************************
1679 * OLEFontImpl_IPersistStream_Release (IUnknown)
1681 * See Windows documentation for more details on IUnknown methods.
1683 static ULONG WINAPI OLEFontImpl_IPersistStream_Release(
1684 IPersistStream* iface)
1686 OLEFontImpl *this = impl_from_IPersistStream(iface);
1688 return IFont_Release(&this->IFont_iface);
1691 /************************************************************************
1692 * OLEFontImpl_IPersistStream_AddRef (IUnknown)
1694 * See Windows documentation for more details on IUnknown methods.
1696 static ULONG WINAPI OLEFontImpl_IPersistStream_AddRef(
1697 IPersistStream* iface)
1699 OLEFontImpl *this = impl_from_IPersistStream(iface);
1701 return IFont_AddRef(&this->IFont_iface);
1704 /************************************************************************
1705 * OLEFontImpl_GetClassID (IPersistStream)
1707 * See Windows documentation for more details on IPersistStream methods.
1709 static HRESULT WINAPI OLEFontImpl_GetClassID(
1710 IPersistStream* iface,
1713 TRACE("(%p,%p)\n",iface,pClassID);
1717 *pClassID = CLSID_StdFont;
1722 /************************************************************************
1723 * OLEFontImpl_IsDirty (IPersistStream)
1725 * See Windows documentation for more details on IPersistStream methods.
1727 static HRESULT WINAPI OLEFontImpl_IsDirty(
1728 IPersistStream* iface)
1730 TRACE("(%p)\n",iface);
1734 /************************************************************************
1735 * OLEFontImpl_Load (IPersistStream)
1737 * See Windows documentation for more details on IPersistStream methods.
1739 * This is the format of the standard font serialization as far as I
1742 * Offset Type Value Comment
1743 * 0x0000 Byte Unknown Probably a version number, contains 0x01
1744 * 0x0001 Short Charset Charset value from the FONTDESC structure
1745 * 0x0003 Byte Attributes Flags defined as follows:
1747 * 00000100 - Underline
1748 * 00001000 - Strikethrough
1749 * 0x0004 Short Weight Weight value from FONTDESC structure
1750 * 0x0006 DWORD size "Low" portion of the cySize member of the FONTDESC
1752 * 0x000A Byte name length Length of the font name string (no null character)
1753 * 0x000B String name Name of the font (ASCII, no nul character)
1755 static HRESULT WINAPI OLEFontImpl_Load(
1756 IPersistStream* iface,
1757 IStream* pLoadStream)
1759 char readBuffer[0x100];
1766 OLEFontImpl *this = impl_from_IPersistStream(iface);
1769 * Read the version byte
1771 IStream_Read(pLoadStream, &bVersion, 1, &cbRead);
1780 IStream_Read(pLoadStream, &this->description.sCharset, 2, &cbRead);
1788 IStream_Read(pLoadStream, &bAttributes, 1, &cbRead);
1793 this->description.fItalic = (bAttributes & FONTPERSIST_ITALIC) != 0;
1794 this->description.fStrikethrough = (bAttributes & FONTPERSIST_STRIKETHROUGH) != 0;
1795 this->description.fUnderline = (bAttributes & FONTPERSIST_UNDERLINE) != 0;
1800 IStream_Read(pLoadStream, &this->description.sWeight, 2, &cbRead);
1808 IStream_Read(pLoadStream, &this->description.cySize.s.Lo, 4, &cbRead);
1813 this->description.cySize.s.Hi = 0;
1818 IStream_Read(pLoadStream, &bStringSize, 1, &cbRead);
1823 IStream_Read(pLoadStream, readBuffer, bStringSize, &cbRead);
1825 if (cbRead!=bStringSize)
1828 HeapFree(GetProcessHeap(), 0, this->description.lpstrName);
1830 len = MultiByteToWideChar( CP_ACP, 0, readBuffer, bStringSize, NULL, 0 );
1831 this->description.lpstrName = HeapAlloc( GetProcessHeap(), 0, (len+1) * sizeof(WCHAR) );
1832 MultiByteToWideChar( CP_ACP, 0, readBuffer, bStringSize, this->description.lpstrName, len );
1833 this->description.lpstrName[len] = 0;
1835 /* Ensure use of this font causes a new one to be created */
1836 dec_int_ref(this->gdiFont);
1843 /************************************************************************
1844 * OLEFontImpl_Save (IPersistStream)
1846 * See Windows documentation for more details on IPersistStream methods.
1848 static HRESULT WINAPI OLEFontImpl_Save(
1849 IPersistStream* iface,
1850 IStream* pOutStream,
1853 char* writeBuffer = NULL;
1855 BYTE bVersion = 0x01;
1859 OLEFontImpl *this = impl_from_IPersistStream(iface);
1862 * Read the version byte
1864 IStream_Write(pOutStream, &bVersion, 1, &cbWritten);
1872 IStream_Write(pOutStream, &this->description.sCharset, 2, &cbWritten);
1882 if (this->description.fItalic)
1883 bAttributes |= FONTPERSIST_ITALIC;
1885 if (this->description.fStrikethrough)
1886 bAttributes |= FONTPERSIST_STRIKETHROUGH;
1888 if (this->description.fUnderline)
1889 bAttributes |= FONTPERSIST_UNDERLINE;
1891 IStream_Write(pOutStream, &bAttributes, 1, &cbWritten);
1899 IStream_Write(pOutStream, &this->description.sWeight, 2, &cbWritten);
1907 IStream_Write(pOutStream, &this->description.cySize.s.Lo, 4, &cbWritten);
1915 if (this->description.lpstrName!=0)
1916 bStringSize = WideCharToMultiByte( CP_ACP, 0, this->description.lpstrName,
1917 strlenW(this->description.lpstrName), NULL, 0, NULL, NULL );
1921 IStream_Write(pOutStream, &bStringSize, 1, &cbWritten);
1928 if (!(writeBuffer = HeapAlloc( GetProcessHeap(), 0, bStringSize ))) return E_OUTOFMEMORY;
1929 WideCharToMultiByte( CP_ACP, 0, this->description.lpstrName,
1930 strlenW(this->description.lpstrName),
1931 writeBuffer, bStringSize, NULL, NULL );
1933 IStream_Write(pOutStream, writeBuffer, bStringSize, &cbWritten);
1934 HeapFree(GetProcessHeap(), 0, writeBuffer);
1936 if (cbWritten!=bStringSize)
1943 /************************************************************************
1944 * OLEFontImpl_GetSizeMax (IPersistStream)
1946 * See Windows documentation for more details on IPersistStream methods.
1948 static HRESULT WINAPI OLEFontImpl_GetSizeMax(
1949 IPersistStream* iface,
1950 ULARGE_INTEGER* pcbSize)
1952 OLEFontImpl *this = impl_from_IPersistStream(iface);
1957 pcbSize->u.HighPart = 0;
1958 pcbSize->u.LowPart = 0;
1960 pcbSize->u.LowPart += sizeof(BYTE); /* Version */
1961 pcbSize->u.LowPart += sizeof(WORD); /* Lang code */
1962 pcbSize->u.LowPart += sizeof(BYTE); /* Flags */
1963 pcbSize->u.LowPart += sizeof(WORD); /* Weight */
1964 pcbSize->u.LowPart += sizeof(DWORD); /* Size */
1965 pcbSize->u.LowPart += sizeof(BYTE); /* StrLength */
1967 if (this->description.lpstrName!=0)
1968 pcbSize->u.LowPart += WideCharToMultiByte( CP_ACP, 0, this->description.lpstrName,
1969 strlenW(this->description.lpstrName),
1970 NULL, 0, NULL, NULL );
1975 static const IPersistStreamVtbl OLEFontImpl_IPersistStream_VTable =
1977 OLEFontImpl_IPersistStream_QueryInterface,
1978 OLEFontImpl_IPersistStream_AddRef,
1979 OLEFontImpl_IPersistStream_Release,
1980 OLEFontImpl_GetClassID,
1981 OLEFontImpl_IsDirty,
1984 OLEFontImpl_GetSizeMax
1987 /************************************************************************
1988 * OLEFontImpl_IConnectionPointContainer_QueryInterface (IUnknown)
1990 * See Windows documentation for more details on IUnknown methods.
1992 static HRESULT WINAPI OLEFontImpl_IConnectionPointContainer_QueryInterface(
1993 IConnectionPointContainer* iface,
1997 OLEFontImpl *this = impl_from_IConnectionPointContainer(iface);
1999 return IFont_QueryInterface(&this->IFont_iface, riid, ppvoid);
2002 /************************************************************************
2003 * OLEFontImpl_IConnectionPointContainer_Release (IUnknown)
2005 * See Windows documentation for more details on IUnknown methods.
2007 static ULONG WINAPI OLEFontImpl_IConnectionPointContainer_Release(
2008 IConnectionPointContainer* iface)
2010 OLEFontImpl *this = impl_from_IConnectionPointContainer(iface);
2012 return IFont_Release(&this->IFont_iface);
2015 /************************************************************************
2016 * OLEFontImpl_IConnectionPointContainer_AddRef (IUnknown)
2018 * See Windows documentation for more details on IUnknown methods.
2020 static ULONG WINAPI OLEFontImpl_IConnectionPointContainer_AddRef(
2021 IConnectionPointContainer* iface)
2023 OLEFontImpl *this = impl_from_IConnectionPointContainer(iface);
2025 return IFont_AddRef(&this->IFont_iface);
2028 /************************************************************************
2029 * OLEFontImpl_EnumConnectionPoints (IConnectionPointContainer)
2031 * See Windows documentation for more details on IConnectionPointContainer
2034 static HRESULT WINAPI OLEFontImpl_EnumConnectionPoints(
2035 IConnectionPointContainer* iface,
2036 IEnumConnectionPoints **ppEnum)
2038 OLEFontImpl *this = impl_from_IConnectionPointContainer(iface);
2040 FIXME("(%p)->(%p): stub\n", this, ppEnum);
2044 /************************************************************************
2045 * OLEFontImpl_FindConnectionPoint (IConnectionPointContainer)
2047 * See Windows documentation for more details on IConnectionPointContainer
2050 static HRESULT WINAPI OLEFontImpl_FindConnectionPoint(
2051 IConnectionPointContainer* iface,
2053 IConnectionPoint **ppCp)
2055 OLEFontImpl *this = impl_from_IConnectionPointContainer(iface);
2056 TRACE("(%p)->(%s, %p)\n", this, debugstr_guid(riid), ppCp);
2058 if(IsEqualIID(riid, &IID_IPropertyNotifySink)) {
2059 return IConnectionPoint_QueryInterface(this->pPropertyNotifyCP,
2060 &IID_IConnectionPoint,
2062 } else if(IsEqualIID(riid, &IID_IFontEventsDisp)) {
2063 return IConnectionPoint_QueryInterface(this->pFontEventsCP,
2064 &IID_IConnectionPoint,
2067 FIXME("no connection point for %s\n", debugstr_guid(riid));
2068 return CONNECT_E_NOCONNECTION;
2072 static const IConnectionPointContainerVtbl
2073 OLEFontImpl_IConnectionPointContainer_VTable =
2075 OLEFontImpl_IConnectionPointContainer_QueryInterface,
2076 OLEFontImpl_IConnectionPointContainer_AddRef,
2077 OLEFontImpl_IConnectionPointContainer_Release,
2078 OLEFontImpl_EnumConnectionPoints,
2079 OLEFontImpl_FindConnectionPoint
2082 /************************************************************************
2083 * OLEFontImpl implementation of IPersistPropertyBag.
2085 static HRESULT WINAPI OLEFontImpl_IPersistPropertyBag_QueryInterface(
2086 IPersistPropertyBag *iface, REFIID riid, LPVOID *ppvObj
2088 OLEFontImpl *this = impl_from_IPersistPropertyBag(iface);
2089 return IFont_QueryInterface(&this->IFont_iface,riid,ppvObj);
2092 static ULONG WINAPI OLEFontImpl_IPersistPropertyBag_AddRef(
2093 IPersistPropertyBag *iface
2095 OLEFontImpl *this = impl_from_IPersistPropertyBag(iface);
2096 return IFont_AddRef(&this->IFont_iface);
2099 static ULONG WINAPI OLEFontImpl_IPersistPropertyBag_Release(
2100 IPersistPropertyBag *iface
2102 OLEFontImpl *this = impl_from_IPersistPropertyBag(iface);
2103 return IFont_Release(&this->IFont_iface);
2106 static HRESULT WINAPI OLEFontImpl_IPersistPropertyBag_GetClassID(
2107 IPersistPropertyBag *iface, CLSID *classid
2109 FIXME("(%p,%p), stub!\n", iface, classid);
2113 static HRESULT WINAPI OLEFontImpl_IPersistPropertyBag_InitNew(
2114 IPersistPropertyBag *iface
2116 FIXME("(%p), stub!\n", iface);
2120 static HRESULT WINAPI OLEFontImpl_IPersistPropertyBag_Load(
2121 IPersistPropertyBag *iface, IPropertyBag* pPropBag, IErrorLog* pErrorLog
2123 /* (from Visual Basic 6 property bag)
2124 Name = "MS Sans Serif"
2128 Underline = 0 'False
2130 Strikethrough = 0 'False
2132 static const WCHAR sAttrName[] = {'N','a','m','e',0};
2133 static const WCHAR sAttrSize[] = {'S','i','z','e',0};
2134 static const WCHAR sAttrCharset[] = {'C','h','a','r','s','e','t',0};
2135 static const WCHAR sAttrWeight[] = {'W','e','i','g','h','t',0};
2136 static const WCHAR sAttrUnderline[] = {'U','n','d','e','r','l','i','n','e',0};
2137 static const WCHAR sAttrItalic[] = {'I','t','a','l','i','c',0};
2138 static const WCHAR sAttrStrikethrough[] = {'S','t','r','i','k','e','t','h','r','o','u','g','h',0};
2139 OLEFontImpl *this = impl_from_IPersistPropertyBag(iface);
2143 VariantInit(&value);
2145 iRes = IPropertyBag_Read(pPropBag, sAttrName, &value, pErrorLog);
2148 iRes = VariantChangeType(&value, &value, 0, VT_BSTR);
2150 iRes = IFont_put_Name(&this->IFont_iface, V_BSTR(&value));
2152 else if (iRes == E_INVALIDARG)
2155 VariantClear(&value);
2158 iRes = IPropertyBag_Read(pPropBag, sAttrSize, &value, pErrorLog);
2161 iRes = VariantChangeType(&value, &value, 0, VT_CY);
2163 iRes = IFont_put_Size(&this->IFont_iface, V_CY(&value));
2165 else if (iRes == E_INVALIDARG)
2168 VariantClear(&value);
2172 iRes = IPropertyBag_Read(pPropBag, sAttrCharset, &value, pErrorLog);
2175 iRes = VariantChangeType(&value, &value, 0, VT_I2);
2177 iRes = IFont_put_Charset(&this->IFont_iface, V_I2(&value));
2179 else if (iRes == E_INVALIDARG)
2182 VariantClear(&value);
2186 iRes = IPropertyBag_Read(pPropBag, sAttrWeight, &value, pErrorLog);
2189 iRes = VariantChangeType(&value, &value, 0, VT_I2);
2191 iRes = IFont_put_Weight(&this->IFont_iface, V_I2(&value));
2193 else if (iRes == E_INVALIDARG)
2196 VariantClear(&value);
2200 iRes = IPropertyBag_Read(pPropBag, sAttrUnderline, &value, pErrorLog);
2203 iRes = VariantChangeType(&value, &value, 0, VT_BOOL);
2205 iRes = IFont_put_Underline(&this->IFont_iface, V_BOOL(&value));
2207 else if (iRes == E_INVALIDARG)
2210 VariantClear(&value);
2214 iRes = IPropertyBag_Read(pPropBag, sAttrItalic, &value, pErrorLog);
2217 iRes = VariantChangeType(&value, &value, 0, VT_BOOL);
2219 iRes = IFont_put_Italic(&this->IFont_iface, V_BOOL(&value));
2221 else if (iRes == E_INVALIDARG)
2224 VariantClear(&value);
2228 iRes = IPropertyBag_Read(pPropBag, sAttrStrikethrough, &value, pErrorLog);
2231 iRes = VariantChangeType(&value, &value, 0, VT_BOOL);
2233 IFont_put_Strikethrough(&this->IFont_iface, V_BOOL(&value));
2235 else if (iRes == E_INVALIDARG)
2238 VariantClear(&value);
2242 WARN("-- 0x%08x\n", iRes);
2246 static HRESULT WINAPI OLEFontImpl_IPersistPropertyBag_Save(
2247 IPersistPropertyBag *iface, IPropertyBag* pPropBag, BOOL fClearDirty,
2248 BOOL fSaveAllProperties
2250 FIXME("(%p,%p,%d,%d), stub!\n", iface, pPropBag, fClearDirty, fSaveAllProperties);
2254 static const IPersistPropertyBagVtbl OLEFontImpl_IPersistPropertyBag_VTable =
2256 OLEFontImpl_IPersistPropertyBag_QueryInterface,
2257 OLEFontImpl_IPersistPropertyBag_AddRef,
2258 OLEFontImpl_IPersistPropertyBag_Release,
2260 OLEFontImpl_IPersistPropertyBag_GetClassID,
2261 OLEFontImpl_IPersistPropertyBag_InitNew,
2262 OLEFontImpl_IPersistPropertyBag_Load,
2263 OLEFontImpl_IPersistPropertyBag_Save
2266 /************************************************************************
2267 * OLEFontImpl implementation of IPersistStreamInit.
2269 static HRESULT WINAPI OLEFontImpl_IPersistStreamInit_QueryInterface(
2270 IPersistStreamInit *iface, REFIID riid, LPVOID *ppvObj
2272 OLEFontImpl *this = impl_from_IPersistStreamInit(iface);
2273 return IFont_QueryInterface(&this->IFont_iface,riid,ppvObj);
2276 static ULONG WINAPI OLEFontImpl_IPersistStreamInit_AddRef(
2277 IPersistStreamInit *iface
2279 OLEFontImpl *this = impl_from_IPersistStreamInit(iface);
2280 return IFont_AddRef(&this->IFont_iface);
2283 static ULONG WINAPI OLEFontImpl_IPersistStreamInit_Release(
2284 IPersistStreamInit *iface
2286 OLEFontImpl *this = impl_from_IPersistStreamInit(iface);
2287 return IFont_Release(&this->IFont_iface);
2290 static HRESULT WINAPI OLEFontImpl_IPersistStreamInit_GetClassID(
2291 IPersistStreamInit *iface, CLSID *classid
2293 FIXME("(%p,%p), stub!\n", iface, classid);
2297 static HRESULT WINAPI OLEFontImpl_IPersistStreamInit_IsDirty(
2298 IPersistStreamInit *iface
2300 FIXME("(%p), stub!\n", iface);
2304 static HRESULT WINAPI OLEFontImpl_IPersistStreamInit_Load(
2305 IPersistStreamInit *iface, LPSTREAM pStm
2307 FIXME("(%p,%p), stub!\n", iface, pStm);
2311 static HRESULT WINAPI OLEFontImpl_IPersistStreamInit_Save(
2312 IPersistStreamInit *iface, LPSTREAM pStm, BOOL fClearDirty
2314 FIXME("(%p,%p,%d), stub!\n", iface, pStm, fClearDirty);
2318 static HRESULT WINAPI OLEFontImpl_IPersistStreamInit_GetSizeMax(
2319 IPersistStreamInit *iface, ULARGE_INTEGER *pcbSize
2321 FIXME("(%p,%p), stub!\n", iface, pcbSize);
2325 static HRESULT WINAPI OLEFontImpl_IPersistStreamInit_InitNew(
2326 IPersistStreamInit *iface
2328 FIXME("(%p), stub!\n", iface);
2332 static const IPersistStreamInitVtbl OLEFontImpl_IPersistStreamInit_VTable =
2334 OLEFontImpl_IPersistStreamInit_QueryInterface,
2335 OLEFontImpl_IPersistStreamInit_AddRef,
2336 OLEFontImpl_IPersistStreamInit_Release,
2338 OLEFontImpl_IPersistStreamInit_GetClassID,
2339 OLEFontImpl_IPersistStreamInit_IsDirty,
2340 OLEFontImpl_IPersistStreamInit_Load,
2341 OLEFontImpl_IPersistStreamInit_Save,
2342 OLEFontImpl_IPersistStreamInit_GetSizeMax,
2343 OLEFontImpl_IPersistStreamInit_InitNew
2346 /************************************************************************
2347 * OLEFontImpl_Construct
2349 * This method will construct a new instance of the OLEFontImpl
2352 * The caller of this method must release the object when it's
2355 static OLEFontImpl* OLEFontImpl_Construct(const FONTDESC *fontDesc)
2357 OLEFontImpl* newObject = 0;
2360 * Allocate space for the object.
2362 newObject = HeapAlloc(GetProcessHeap(), 0, sizeof(OLEFontImpl));
2368 * Initialize the virtual function table.
2370 newObject->IFont_iface.lpVtbl = &OLEFontImpl_VTable;
2371 newObject->IDispatch_iface.lpVtbl = &OLEFontImpl_IDispatch_VTable;
2372 newObject->IPersistStream_iface.lpVtbl = &OLEFontImpl_IPersistStream_VTable;
2373 newObject->IConnectionPointContainer_iface.lpVtbl = &OLEFontImpl_IConnectionPointContainer_VTable;
2374 newObject->IPersistPropertyBag_iface.lpVtbl = &OLEFontImpl_IPersistPropertyBag_VTable;
2375 newObject->IPersistStreamInit_iface.lpVtbl = &OLEFontImpl_IPersistStreamInit_VTable;
2378 * Start with one reference count. The caller of this function
2379 * must release the interface pointer when it is done.
2384 * Copy the description of the font in the object.
2386 assert(fontDesc->cbSizeofstruct >= sizeof(FONTDESC));
2388 newObject->description.cbSizeofstruct = sizeof(FONTDESC);
2389 newObject->description.lpstrName = HeapAlloc(GetProcessHeap(),
2391 (lstrlenW(fontDesc->lpstrName)+1) * sizeof(WCHAR));
2392 strcpyW(newObject->description.lpstrName, fontDesc->lpstrName);
2393 newObject->description.cySize = fontDesc->cySize;
2394 newObject->description.sWeight = fontDesc->sWeight;
2395 newObject->description.sCharset = fontDesc->sCharset;
2396 newObject->description.fItalic = fontDesc->fItalic;
2397 newObject->description.fUnderline = fontDesc->fUnderline;
2398 newObject->description.fStrikethrough = fontDesc->fStrikethrough;
2401 * Initializing all the other members.
2403 newObject->gdiFont = 0;
2404 newObject->dirty = TRUE;
2405 newObject->cyLogical = 72L;
2406 newObject->cyHimetric = 2540L;
2407 newObject->pPropertyNotifyCP = NULL;
2408 newObject->pFontEventsCP = NULL;
2410 CreateConnectionPoint((IUnknown*)newObject, &IID_IPropertyNotifySink, &newObject->pPropertyNotifyCP);
2411 CreateConnectionPoint((IUnknown*)newObject, &IID_IFontEventsDisp, &newObject->pFontEventsCP);
2413 if (!newObject->pPropertyNotifyCP || !newObject->pFontEventsCP)
2415 OLEFontImpl_Destroy(newObject);
2419 InterlockedIncrement(&ifont_cnt);
2421 TRACE("returning %p\n", newObject);
2425 /************************************************************************
2426 * OLEFontImpl_Destroy
2428 * This method is called by the Release method when the reference
2429 * count goes down to 0. It will free all resources used by
2432 static void OLEFontImpl_Destroy(OLEFontImpl* fontDesc)
2434 TRACE("(%p)\n", fontDesc);
2436 HeapFree(GetProcessHeap(), 0, fontDesc->description.lpstrName);
2438 if (fontDesc->pPropertyNotifyCP)
2439 IConnectionPoint_Release(fontDesc->pPropertyNotifyCP);
2440 if (fontDesc->pFontEventsCP)
2441 IConnectionPoint_Release(fontDesc->pFontEventsCP);
2443 HeapFree(GetProcessHeap(), 0, fontDesc);
2446 /*******************************************************************************
2447 * StdFont ClassFactory
2451 /* IUnknown fields */
2452 IClassFactory IClassFactory_iface;
2454 } IClassFactoryImpl;
2456 static inline IClassFactoryImpl *impl_from_IClassFactory(IClassFactory *iface)
2458 return CONTAINING_RECORD(iface, IClassFactoryImpl, IClassFactory_iface);
2461 static HRESULT WINAPI
2462 SFCF_QueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj) {
2463 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
2465 FIXME("(%p)->(%s,%p),stub!\n",This,debugstr_guid(riid),ppobj);
2466 return E_NOINTERFACE;
2470 SFCF_AddRef(LPCLASSFACTORY iface) {
2471 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
2472 return InterlockedIncrement(&This->ref);
2475 static ULONG WINAPI SFCF_Release(LPCLASSFACTORY iface) {
2476 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
2477 /* static class, won't be freed */
2478 return InterlockedDecrement(&This->ref);
2481 static HRESULT WINAPI SFCF_CreateInstance(
2482 LPCLASSFACTORY iface,LPUNKNOWN pOuter,REFIID riid,LPVOID *ppobj
2484 return OleCreateFontIndirect(NULL,riid,ppobj);
2488 static HRESULT WINAPI SFCF_LockServer(LPCLASSFACTORY iface,BOOL dolock) {
2489 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
2490 FIXME("(%p)->(%d),stub!\n",This,dolock);
2494 static const IClassFactoryVtbl SFCF_Vtbl = {
2495 SFCF_QueryInterface,
2498 SFCF_CreateInstance,
2501 static IClassFactoryImpl STDFONT_CF = {{&SFCF_Vtbl}, 1 };
2503 void _get_STDFONT_CF(LPVOID *ppv) { *ppv = &STDFONT_CF; }