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"
39 #include "oleauto.h" /* for SysAllocString(....) */
42 #include "wine/debug.h"
43 #include "connpt.h" /* for CreateConnectionPoint */
46 WINE_DEFAULT_DEBUG_CHANNEL(ole
);
48 /***********************************************************************
49 * Declaration of constants used when serializing the font object.
51 #define FONTPERSIST_ITALIC 0x02
52 #define FONTPERSIST_UNDERLINE 0x04
53 #define FONTPERSIST_STRIKETHROUGH 0x08
55 static HDC olefont_hdc
;
57 /***********************************************************************
58 * List of the HFONTs it has given out, with each one having a separate
61 typedef struct _HFONTItem
65 /* Reference count of any IFont objects that own this hfont */
68 /* Total reference count of any refs held by the application obtained by AddRefHfont plus any internal refs */
71 /* The font associated with this object. */
74 } HFONTItem
, *PHFONTItem
;
76 static struct list OLEFontImpl_hFontList
= LIST_INIT(OLEFontImpl_hFontList
);
78 /* Counts how many fonts contain at least one lock */
79 static LONG ifont_cnt
= 0;
81 /***********************************************************************
82 * Critical section for OLEFontImpl_hFontList
84 static CRITICAL_SECTION OLEFontImpl_csHFONTLIST
;
85 static CRITICAL_SECTION_DEBUG OLEFontImpl_csHFONTLIST_debug
=
87 0, 0, &OLEFontImpl_csHFONTLIST
,
88 { &OLEFontImpl_csHFONTLIST_debug
.ProcessLocksList
,
89 &OLEFontImpl_csHFONTLIST_debug
.ProcessLocksList
},
90 0, 0, { (DWORD_PTR
)(__FILE__
": OLEFontImpl_csHFONTLIST") }
92 static CRITICAL_SECTION OLEFontImpl_csHFONTLIST
= { &OLEFontImpl_csHFONTLIST_debug
, -1, 0, 0, 0, 0 };
94 static HDC
get_dc(void)
97 EnterCriticalSection(&OLEFontImpl_csHFONTLIST
);
99 olefont_hdc
= CreateCompatibleDC(NULL
);
101 LeaveCriticalSection(&OLEFontImpl_csHFONTLIST
);
105 static void delete_dc(void)
107 EnterCriticalSection(&OLEFontImpl_csHFONTLIST
);
110 DeleteDC(olefont_hdc
);
113 LeaveCriticalSection(&OLEFontImpl_csHFONTLIST
);
116 static void HFONTItem_Delete(PHFONTItem item
)
118 DeleteObject(item
->gdiFont
);
119 list_remove(&item
->entry
);
120 HeapFree(GetProcessHeap(), 0, item
);
123 /* Find hfont item entry in the list. Should be called while holding the crit sect */
124 static HFONTItem
*find_hfontitem(HFONT hfont
)
128 LIST_FOR_EACH_ENTRY(item
, &OLEFontImpl_hFontList
, HFONTItem
, entry
)
130 if (item
->gdiFont
== hfont
)
136 /* Add an item to the list with one internal reference */
137 static HRESULT
add_hfontitem(HFONT hfont
)
139 HFONTItem
*new_item
= HeapAlloc(GetProcessHeap(), 0, sizeof(*new_item
));
141 if(!new_item
) return E_OUTOFMEMORY
;
143 new_item
->int_refs
= 1;
144 new_item
->total_refs
= 1;
145 new_item
->gdiFont
= hfont
;
146 EnterCriticalSection(&OLEFontImpl_csHFONTLIST
);
147 list_add_tail(&OLEFontImpl_hFontList
,&new_item
->entry
);
148 LeaveCriticalSection(&OLEFontImpl_csHFONTLIST
);
152 static HRESULT
inc_int_ref(HFONT hfont
)
155 HRESULT hr
= S_FALSE
;
157 EnterCriticalSection(&OLEFontImpl_csHFONTLIST
);
158 item
= find_hfontitem(hfont
);
166 LeaveCriticalSection(&OLEFontImpl_csHFONTLIST
);
171 /* decrements the internal ref of a hfont item. If both refs are zero it'll
172 remove the item from the list and delete the hfont */
173 static HRESULT
dec_int_ref(HFONT hfont
)
176 HRESULT hr
= S_FALSE
;
178 EnterCriticalSection(&OLEFontImpl_csHFONTLIST
);
179 item
= find_hfontitem(hfont
);
185 if(item
->int_refs
== 0 && item
->total_refs
== 0)
186 HFONTItem_Delete(item
);
189 LeaveCriticalSection(&OLEFontImpl_csHFONTLIST
);
194 static HRESULT
inc_ext_ref(HFONT hfont
)
197 HRESULT hr
= S_FALSE
;
199 EnterCriticalSection(&OLEFontImpl_csHFONTLIST
);
201 item
= find_hfontitem(hfont
);
207 LeaveCriticalSection(&OLEFontImpl_csHFONTLIST
);
212 static HRESULT
dec_ext_ref(HFONT hfont
)
215 HRESULT hr
= S_FALSE
;
217 EnterCriticalSection(&OLEFontImpl_csHFONTLIST
);
219 item
= find_hfontitem(hfont
);
222 if(--item
->total_refs
>= 0) hr
= S_OK
;
224 LeaveCriticalSection(&OLEFontImpl_csHFONTLIST
);
229 static WCHAR
*strdupW(const WCHAR
* str
)
232 DWORD size
= (lstrlenW(str
) + 1) * sizeof(WCHAR
);
234 ret
= HeapAlloc(GetProcessHeap(), 0, size
);
236 memcpy(ret
, str
, size
);
240 /***********************************************************************
241 * Declaration of the implementation class for the IFont interface
243 typedef struct OLEFontImpl OLEFontImpl
;
248 * This class supports many interfaces. IUnknown, IFont,
249 * IDispatch, IDispFont IPersistStream and IConnectionPointContainer.
250 * The first two are supported by the first vtable, the next two are
251 * supported by the second table and the last two have their own.
254 IDispatch IDispatch_iface
;
255 IPersistStream IPersistStream_iface
;
256 IConnectionPointContainer IConnectionPointContainer_iface
;
257 IPersistPropertyBag IPersistPropertyBag_iface
;
259 * Reference count for that instance of the class.
264 * This structure contains the description of the class.
266 FONTDESC description
;
269 * Contain the font associated with this object.
280 * Stash realized height (pixels) from TEXTMETRIC - used in get_Size()
284 IConnectionPoint
*pPropertyNotifyCP
;
285 IConnectionPoint
*pFontEventsCP
;
288 static inline OLEFontImpl
*impl_from_IFont(IFont
*iface
)
290 return CONTAINING_RECORD(iface
, OLEFontImpl
, IFont_iface
);
293 static inline OLEFontImpl
*impl_from_IDispatch( IDispatch
*iface
)
295 return CONTAINING_RECORD(iface
, OLEFontImpl
, IDispatch_iface
);
298 static inline OLEFontImpl
*impl_from_IPersistStream( IPersistStream
*iface
)
300 return CONTAINING_RECORD(iface
, OLEFontImpl
, IPersistStream_iface
);
303 static inline OLEFontImpl
*impl_from_IConnectionPointContainer( IConnectionPointContainer
*iface
)
305 return CONTAINING_RECORD(iface
, OLEFontImpl
, IConnectionPointContainer_iface
);
308 static inline OLEFontImpl
*impl_from_IPersistPropertyBag( IPersistPropertyBag
*iface
)
310 return CONTAINING_RECORD(iface
, OLEFontImpl
, IPersistPropertyBag_iface
);
314 /***********************************************************************
315 * Prototypes for the implementation functions for the IFont
318 static OLEFontImpl
* OLEFontImpl_Construct(const FONTDESC
*fontDesc
);
319 static void OLEFontImpl_Destroy(OLEFontImpl
* fontDesc
);
320 static ULONG WINAPI
OLEFontImpl_AddRef(IFont
* iface
);
322 /******************************************************************************
323 * OleCreateFontIndirect [OLEAUT32.420]
325 HRESULT WINAPI
OleCreateFontIndirect(
326 LPFONTDESC lpFontDesc
,
330 OLEFontImpl
* newFont
;
334 TRACE("(%p, %s, %p)\n", lpFontDesc
, debugstr_guid(riid
), ppvObj
);
336 if (!ppvObj
) return E_POINTER
;
341 static WCHAR fname
[] = L
"System";
343 fd
.cbSizeofstruct
= sizeof(fd
);
344 fd
.lpstrName
= fname
;
345 fd
.cySize
.s
.Lo
= 80000;
350 fd
.fUnderline
= FALSE
;
351 fd
.fStrikethrough
= FALSE
;
355 newFont
= OLEFontImpl_Construct(lpFontDesc
);
356 if (!newFont
) return E_OUTOFMEMORY
;
358 hr
= IFont_QueryInterface(&newFont
->IFont_iface
, riid
, ppvObj
);
359 IFont_Release(&newFont
->IFont_iface
);
365 /***********************************************************************
366 * Implementation of the OLEFontImpl class.
369 /***********************************************************************
370 * OLEFont_SendNotify (internal)
372 * Sends notification messages of changed properties to any interested
375 static void OLEFont_SendNotify(OLEFontImpl
* this, DISPID dispID
)
377 static const LPCWSTR dispid_mapping
[] =
390 IEnumConnections
*pEnum
;
396 hres
= IConnectionPoint_EnumConnections(this->pPropertyNotifyCP
, &pEnum
);
399 while(IEnumConnections_Next(pEnum
, 1, &CD
, NULL
) == S_OK
) {
400 IPropertyNotifySink
*sink
;
402 IUnknown_QueryInterface(CD
.pUnk
, &IID_IPropertyNotifySink
, (void**)&sink
);
403 IPropertyNotifySink_OnChanged(sink
, dispID
);
404 IPropertyNotifySink_Release(sink
);
405 IUnknown_Release(CD
.pUnk
);
407 IEnumConnections_Release(pEnum
);
410 hres
= IConnectionPoint_EnumConnections(this->pFontEventsCP
, &pEnum
);
413 DISPPARAMS dispparams
;
416 VariantInit(&vararg
);
417 V_VT(&vararg
) = VT_BSTR
;
418 V_BSTR(&vararg
) = SysAllocString(dispid_mapping
[dispID
]);
420 dispparams
.cArgs
= 1;
421 dispparams
.cNamedArgs
= 0;
422 dispparams
.rgdispidNamedArgs
= NULL
;
423 dispparams
.rgvarg
= &vararg
;
425 while(IEnumConnections_Next(pEnum
, 1, &CD
, NULL
) == S_OK
) {
426 IFontEventsDisp
*disp
;
428 IUnknown_QueryInterface(CD
.pUnk
, &IID_IFontEventsDisp
, (void**)&disp
);
429 IFontEventsDisp_Invoke(disp
, DISPID_FONT_CHANGED
, &IID_NULL
,
430 LOCALE_NEUTRAL
, INVOKE_FUNC
, &dispparams
, NULL
,
433 IFontEventsDisp_Release(disp
);
434 IUnknown_Release(CD
.pUnk
);
436 VariantClear(&vararg
);
437 IEnumConnections_Release(pEnum
);
441 /************************************************************************
442 * OLEFontImpl_QueryInterface (IUnknown)
444 * See Windows documentation for more details on IUnknown methods.
446 static HRESULT WINAPI
OLEFontImpl_QueryInterface(
451 OLEFontImpl
*this = impl_from_IFont(iface
);
453 TRACE("(%p)->(%s, %p)\n", this, debugstr_guid(riid
), ppvObject
);
457 if (IsEqualGUID(&IID_IUnknown
, riid
) ||
458 IsEqualGUID(&IID_IFont
, riid
))
462 else if (IsEqualGUID(&IID_IDispatch
, riid
) ||
463 IsEqualGUID(&IID_IFontDisp
, riid
))
465 *ppvObject
= &this->IDispatch_iface
;
467 else if (IsEqualGUID(&IID_IPersist
, riid
) ||
468 IsEqualGUID(&IID_IPersistStream
, riid
))
470 *ppvObject
= &this->IPersistStream_iface
;
472 else if (IsEqualGUID(&IID_IConnectionPointContainer
, riid
))
474 *ppvObject
= &this->IConnectionPointContainer_iface
;
476 else if (IsEqualGUID(&IID_IPersistPropertyBag
, riid
))
478 *ppvObject
= &this->IPersistPropertyBag_iface
;
483 FIXME("() : asking for unsupported interface %s\n", debugstr_guid(riid
));
484 return E_NOINTERFACE
;
492 /************************************************************************
493 * OLEFontImpl_AddRef (IUnknown)
495 static ULONG WINAPI
OLEFontImpl_AddRef(
498 OLEFontImpl
*this = impl_from_IFont(iface
);
499 TRACE("(%p)->(ref=%d)\n", this, this->ref
);
500 return InterlockedIncrement(&this->ref
);
503 /************************************************************************
504 * OLEFontImpl_Release (IUnknown)
506 static ULONG WINAPI
OLEFontImpl_Release(IFont
* iface
)
508 OLEFontImpl
*this = impl_from_IFont(iface
);
511 TRACE("(%p)->(ref=%d)\n", this, this->ref
);
513 ref
= InterlockedDecrement(&this->ref
);
517 ULONG fontlist_refs
= InterlockedDecrement(&ifont_cnt
);
519 /* Final IFont object so destroy font cache */
520 if (fontlist_refs
== 0)
522 HFONTItem
*item
, *cursor2
;
524 EnterCriticalSection(&OLEFontImpl_csHFONTLIST
);
525 LIST_FOR_EACH_ENTRY_SAFE(item
, cursor2
, &OLEFontImpl_hFontList
, HFONTItem
, entry
)
526 HFONTItem_Delete(item
);
527 LeaveCriticalSection(&OLEFontImpl_csHFONTLIST
);
532 dec_int_ref(this->gdiFont
);
534 OLEFontImpl_Destroy(this);
546 static int CALLBACK
font_enum_proc(const LOGFONTW
*elf
, const TEXTMETRICW
*ntm
, DWORD type
, LPARAM lp
)
548 enum_data
*data
= (enum_data
*)lp
;
550 if(elf
->lfCharSet
== data
->orig_cs
)
552 data
->avail_cs
= data
->orig_cs
;
555 if(data
->avail_cs
== -1) data
->avail_cs
= elf
->lfCharSet
;
559 static void realize_font(OLEFontImpl
*This
)
563 WCHAR text_face
[LF_FACESIZE
];
568 if (!This
->dirty
) return;
574 old_font
= SelectObject(hdc
, This
->gdiFont
);
575 GetTextFaceW(hdc
, ARRAY_SIZE(text_face
), text_face
);
576 SelectObject(hdc
, old_font
);
577 dec_int_ref(This
->gdiFont
);
581 memset(&logFont
, 0, sizeof(LOGFONTW
));
583 lstrcpynW(logFont
.lfFaceName
, This
->description
.lpstrName
, LF_FACESIZE
);
584 logFont
.lfCharSet
= This
->description
.sCharset
;
586 /* If the font name has been changed then enumerate all charsets
587 and pick one that'll result in the font specified being selected */
588 if(text_face
[0] && lstrcmpiW(text_face
, This
->description
.lpstrName
))
591 data
.orig_cs
= This
->description
.sCharset
;
593 logFont
.lfCharSet
= DEFAULT_CHARSET
;
594 EnumFontFamiliesExW(get_dc(), &logFont
, font_enum_proc
, (LPARAM
)&data
, 0);
595 if(data
.avail_cs
!= -1) logFont
.lfCharSet
= data
.avail_cs
;
599 * The height of the font returned by the get_Size property is the
600 * height of the font in points multiplied by 10000... Using some
601 * simple conversions and the ratio given by the application, it can
602 * be converted to a height in pixels.
604 * Standard ratio is 72 / 2540, or 18 / 635 in lowest terms.
605 * Ratio is applied here relative to the standard.
608 fontHeight
= MulDiv( This
->description
.cySize
.s
.Lo
, This
->cyLogical
*635, This
->cyHimetric
*18 );
610 logFont
.lfHeight
= ((fontHeight
%10000L)>5000L) ? (-fontHeight
/10000L) - 1 :
611 (-fontHeight
/10000L);
612 logFont
.lfItalic
= This
->description
.fItalic
;
613 logFont
.lfUnderline
= This
->description
.fUnderline
;
614 logFont
.lfStrikeOut
= This
->description
.fStrikethrough
;
615 logFont
.lfWeight
= This
->description
.sWeight
;
616 logFont
.lfOutPrecision
= OUT_CHARACTER_PRECIS
;
617 logFont
.lfClipPrecision
= CLIP_DEFAULT_PRECIS
;
618 logFont
.lfQuality
= DEFAULT_QUALITY
;
619 logFont
.lfPitchAndFamily
= DEFAULT_PITCH
;
621 This
->gdiFont
= CreateFontIndirectW(&logFont
);
624 add_hfontitem(This
->gdiFont
);
626 /* Fixup the name and charset properties so that they match the
628 old_font
= SelectObject(get_dc(), This
->gdiFont
);
629 GetTextFaceW(hdc
, ARRAY_SIZE(text_face
), text_face
);
630 if(lstrcmpiW(text_face
, This
->description
.lpstrName
))
632 HeapFree(GetProcessHeap(), 0, This
->description
.lpstrName
);
633 This
->description
.lpstrName
= strdupW(text_face
);
635 GetTextMetricsW(hdc
, &tm
);
636 This
->description
.sCharset
= tm
.tmCharSet
;
637 /* While we have it handy, stash the realized font height for use by get_Size() */
638 This
->nRealHeight
= tm
.tmHeight
- tm
.tmInternalLeading
; /* corresponds to LOGFONT lfHeight */
639 SelectObject(hdc
, old_font
);
642 /************************************************************************
643 * OLEFontImpl_get_Name (IFont)
645 * See Windows documentation for more details on IFont methods.
647 static HRESULT WINAPI
OLEFontImpl_get_Name(
651 OLEFontImpl
*this = impl_from_IFont(iface
);
652 TRACE("(%p)->(%p)\n", this, pname
);
659 if (this->description
.lpstrName
!=0)
660 *pname
= SysAllocString(this->description
.lpstrName
);
667 /************************************************************************
668 * OLEFontImpl_put_Name (IFont)
670 static HRESULT WINAPI
OLEFontImpl_put_Name(
674 OLEFontImpl
*This
= impl_from_IFont(iface
);
675 TRACE("(%p)->(%p)\n", This
, name
);
678 return CTL_E_INVALIDPROPERTYVALUE
;
680 HeapFree(GetProcessHeap(), 0, This
->description
.lpstrName
);
681 This
->description
.lpstrName
= strdupW(name
);
682 if (!This
->description
.lpstrName
) return E_OUTOFMEMORY
;
684 TRACE("new name %s\n", debugstr_w(This
->description
.lpstrName
));
685 OLEFont_SendNotify(This
, DISPID_FONT_NAME
);
689 /************************************************************************
690 * OLEFontImpl_get_Size (IFont)
692 static HRESULT WINAPI
OLEFontImpl_get_Size(
696 OLEFontImpl
*this = impl_from_IFont(iface
);
697 TRACE("(%p)->(%p)\n", this, psize
);
699 if (!psize
) return E_POINTER
;
704 * Convert realized font height in pixels to points descaled by current
705 * scaling ratio then scaled up by 10000.
707 psize
->s
.Lo
= MulDiv(this->nRealHeight
,
708 this->cyHimetric
* 72 * 10000,
709 this->cyLogical
* 2540);
715 /************************************************************************
716 * OLEFontImpl_put_Size (IFont)
718 static HRESULT WINAPI
OLEFontImpl_put_Size(
722 OLEFontImpl
*this = impl_from_IFont(iface
);
723 TRACE("(%p)->(%d)\n", this, size
.s
.Lo
);
724 this->description
.cySize
.s
.Hi
= 0;
725 this->description
.cySize
.s
.Lo
= size
.s
.Lo
;
726 OLEFont_SendNotify(this, DISPID_FONT_SIZE
);
731 /************************************************************************
732 * OLEFontImpl_get_Bold (IFont)
734 * See Windows documentation for more details on IFont methods.
736 static HRESULT WINAPI
OLEFontImpl_get_Bold(
740 OLEFontImpl
*this = impl_from_IFont(iface
);
741 TRACE("(%p)->(%p)\n", this, pbold
);
743 if (!pbold
) return E_POINTER
;
747 *pbold
= this->description
.sWeight
> 550;
752 /************************************************************************
753 * OLEFontImpl_put_Bold (IFont)
755 static HRESULT WINAPI
OLEFontImpl_put_Bold(
759 OLEFontImpl
*this = impl_from_IFont(iface
);
760 TRACE("(%p)->(%d)\n", this, bold
);
761 this->description
.sWeight
= bold
? FW_BOLD
: FW_NORMAL
;
762 OLEFont_SendNotify(this, DISPID_FONT_BOLD
);
767 /************************************************************************
768 * OLEFontImpl_get_Italic (IFont)
770 static HRESULT WINAPI
OLEFontImpl_get_Italic(
774 OLEFontImpl
*this = impl_from_IFont(iface
);
775 TRACE("(%p)->(%p)\n", this, pitalic
);
782 *pitalic
= this->description
.fItalic
;
787 /************************************************************************
788 * OLEFontImpl_put_Italic (IFont)
790 static HRESULT WINAPI
OLEFontImpl_put_Italic(
794 OLEFontImpl
*this = impl_from_IFont(iface
);
795 TRACE("(%p)->(%d)\n", this, italic
);
797 this->description
.fItalic
= italic
;
799 OLEFont_SendNotify(this, DISPID_FONT_ITALIC
);
803 /************************************************************************
804 * OLEFontImpl_get_Underline (IFont)
806 static HRESULT WINAPI
OLEFontImpl_get_Underline(
810 OLEFontImpl
*this = impl_from_IFont(iface
);
811 TRACE("(%p)->(%p)\n", this, punderline
);
818 *punderline
= this->description
.fUnderline
;
823 /************************************************************************
824 * OLEFontImpl_put_Underline (IFont)
826 static HRESULT WINAPI
OLEFontImpl_put_Underline(
830 OLEFontImpl
*this = impl_from_IFont(iface
);
831 TRACE("(%p)->(%d)\n", this, underline
);
833 this->description
.fUnderline
= underline
;
835 OLEFont_SendNotify(this, DISPID_FONT_UNDER
);
839 /************************************************************************
840 * OLEFontImpl_get_Strikethrough (IFont)
842 static HRESULT WINAPI
OLEFontImpl_get_Strikethrough(
844 BOOL
* pstrikethrough
)
846 OLEFontImpl
*this = impl_from_IFont(iface
);
847 TRACE("(%p)->(%p)\n", this, pstrikethrough
);
849 if (pstrikethrough
==0)
854 *pstrikethrough
= this->description
.fStrikethrough
;
859 /************************************************************************
860 * OLEFontImpl_put_Strikethrough (IFont)
862 static HRESULT WINAPI
OLEFontImpl_put_Strikethrough(
866 OLEFontImpl
*this = impl_from_IFont(iface
);
867 TRACE("(%p)->(%d)\n", this, strikethrough
);
869 this->description
.fStrikethrough
= strikethrough
;
870 OLEFont_SendNotify(this, DISPID_FONT_STRIKE
);
875 /************************************************************************
876 * OLEFontImpl_get_Weight (IFont)
878 static HRESULT WINAPI
OLEFontImpl_get_Weight(
882 OLEFontImpl
*this = impl_from_IFont(iface
);
883 TRACE("(%p)->(%p)\n", this, pweight
);
890 *pweight
= this->description
.sWeight
;
895 /************************************************************************
896 * OLEFontImpl_put_Weight (IFont)
898 static HRESULT WINAPI
OLEFontImpl_put_Weight(
902 OLEFontImpl
*this = impl_from_IFont(iface
);
903 TRACE("(%p)->(%d)\n", this, weight
);
905 this->description
.sWeight
= weight
;
907 OLEFont_SendNotify(this, DISPID_FONT_WEIGHT
);
911 /************************************************************************
912 * OLEFontImpl_get_Charset (IFont)
914 static HRESULT WINAPI
OLEFontImpl_get_Charset(
918 OLEFontImpl
*this = impl_from_IFont(iface
);
919 TRACE("(%p)->(%p)\n", this, pcharset
);
926 *pcharset
= this->description
.sCharset
;
931 /************************************************************************
932 * OLEFontImpl_put_Charset (IFont)
934 static HRESULT WINAPI
OLEFontImpl_put_Charset(
938 OLEFontImpl
*this = impl_from_IFont(iface
);
939 TRACE("(%p)->(%d)\n", this, charset
);
941 this->description
.sCharset
= charset
;
942 OLEFont_SendNotify(this, DISPID_FONT_CHARSET
);
947 /************************************************************************
948 * OLEFontImpl_get_hFont (IFont)
950 static HRESULT WINAPI
OLEFontImpl_get_hFont(
954 OLEFontImpl
*this = impl_from_IFont(iface
);
955 TRACE("(%p)->(%p)\n", this, phfont
);
961 *phfont
= this->gdiFont
;
962 TRACE("Returning %p\n", *phfont
);
966 /************************************************************************
967 * OLEFontImpl_Clone (IFont)
969 static HRESULT WINAPI
OLEFontImpl_Clone(
973 OLEFontImpl
*this = impl_from_IFont(iface
);
974 OLEFontImpl
* newObject
;
976 TRACE("(%p)->(%p)\n", this, ppfont
);
983 newObject
= HeapAlloc(GetProcessHeap(), 0, sizeof(OLEFontImpl
));
985 return E_OUTOFMEMORY
;
988 /* allocate separate buffer */
989 newObject
->description
.lpstrName
= strdupW(this->description
.lpstrName
);
991 /* Increment internal ref in hfont item list */
992 if(newObject
->gdiFont
) inc_int_ref(newObject
->gdiFont
);
994 InterlockedIncrement(&ifont_cnt
);
996 newObject
->pPropertyNotifyCP
= NULL
;
997 newObject
->pFontEventsCP
= NULL
;
998 CreateConnectionPoint((IUnknown
*)&newObject
->IFont_iface
, &IID_IPropertyNotifySink
,
999 &newObject
->pPropertyNotifyCP
);
1000 CreateConnectionPoint((IUnknown
*)&newObject
->IFont_iface
, &IID_IFontEventsDisp
,
1001 &newObject
->pFontEventsCP
);
1003 if (!newObject
->pPropertyNotifyCP
|| !newObject
->pFontEventsCP
)
1005 OLEFontImpl_Destroy(newObject
);
1006 return E_OUTOFMEMORY
;
1009 /* The cloned object starts with a reference count of 1 */
1012 *ppfont
= &newObject
->IFont_iface
;
1017 /************************************************************************
1018 * OLEFontImpl_IsEqual (IFont)
1020 static HRESULT WINAPI
OLEFontImpl_IsEqual(
1024 OLEFontImpl
*left
= impl_from_IFont(iface
);
1025 OLEFontImpl
*right
= impl_from_IFont(pFontOther
);
1027 INT left_len
,right_len
;
1029 if(pFontOther
== NULL
)
1031 else if (left
->description
.cySize
.s
.Lo
!= right
->description
.cySize
.s
.Lo
)
1033 else if (left
->description
.cySize
.s
.Hi
!= right
->description
.cySize
.s
.Hi
)
1035 else if (left
->description
.sWeight
!= right
->description
.sWeight
)
1037 else if (left
->description
.sCharset
!= right
->description
.sCharset
)
1039 else if (left
->description
.fItalic
!= right
->description
.fItalic
)
1041 else if (left
->description
.fUnderline
!= right
->description
.fUnderline
)
1043 else if (left
->description
.fStrikethrough
!= right
->description
.fStrikethrough
)
1046 /* Check from string */
1047 left_len
= lstrlenW(left
->description
.lpstrName
);
1048 right_len
= lstrlenW(right
->description
.lpstrName
);
1049 ret
= CompareStringW(0,0,left
->description
.lpstrName
, left_len
,
1050 right
->description
.lpstrName
, right_len
);
1051 if (ret
!= CSTR_EQUAL
)
1057 /************************************************************************
1058 * OLEFontImpl_SetRatio (IFont)
1060 static HRESULT WINAPI
OLEFontImpl_SetRatio(
1065 OLEFontImpl
*this = impl_from_IFont(iface
);
1066 TRACE("(%p)->(%d, %d)\n", this, cyLogical
, cyHimetric
);
1068 if(cyLogical
== 0 || cyHimetric
== 0)
1071 /* cyLogical and cyHimetric both set to 1 is a special case that
1072 does not change the scaling but also does not fail */
1073 if(cyLogical
== 1 && cyHimetric
== 1)
1076 this->cyLogical
= cyLogical
;
1077 this->cyHimetric
= cyHimetric
;
1083 /************************************************************************
1084 * OLEFontImpl_QueryTextMetrics (IFont)
1086 static HRESULT WINAPI
OLEFontImpl_QueryTextMetrics(
1091 HFONT hOldFont
, hNewFont
;
1094 IFont_get_hFont(iface
, &hNewFont
);
1095 hOldFont
= SelectObject(hdcRef
, hNewFont
);
1096 GetTextMetricsW(hdcRef
, ptm
);
1097 SelectObject(hdcRef
, hOldFont
);
1098 ReleaseDC(0, hdcRef
);
1102 /************************************************************************
1103 * OLEFontImpl_AddRefHfont (IFont)
1105 static HRESULT WINAPI
OLEFontImpl_AddRefHfont(
1109 OLEFontImpl
*this = impl_from_IFont(iface
);
1111 TRACE("(%p)->(%p)\n", this, hfont
);
1113 if (!hfont
) return E_INVALIDARG
;
1115 return inc_ext_ref(hfont
);
1118 /************************************************************************
1119 * OLEFontImpl_ReleaseHfont (IFont)
1121 static HRESULT WINAPI
OLEFontImpl_ReleaseHfont(
1125 OLEFontImpl
*this = impl_from_IFont(iface
);
1127 TRACE("(%p)->(%p)\n", this, hfont
);
1129 if (!hfont
) return E_INVALIDARG
;
1131 return dec_ext_ref(hfont
);
1134 /************************************************************************
1135 * OLEFontImpl_SetHdc (IFont)
1137 static HRESULT WINAPI
OLEFontImpl_SetHdc(
1141 OLEFontImpl
*this = impl_from_IFont(iface
);
1142 FIXME("(%p)->(%p): Stub\n", this, hdc
);
1146 static const IFontVtbl OLEFontImpl_VTable
=
1148 OLEFontImpl_QueryInterface
,
1150 OLEFontImpl_Release
,
1151 OLEFontImpl_get_Name
,
1152 OLEFontImpl_put_Name
,
1153 OLEFontImpl_get_Size
,
1154 OLEFontImpl_put_Size
,
1155 OLEFontImpl_get_Bold
,
1156 OLEFontImpl_put_Bold
,
1157 OLEFontImpl_get_Italic
,
1158 OLEFontImpl_put_Italic
,
1159 OLEFontImpl_get_Underline
,
1160 OLEFontImpl_put_Underline
,
1161 OLEFontImpl_get_Strikethrough
,
1162 OLEFontImpl_put_Strikethrough
,
1163 OLEFontImpl_get_Weight
,
1164 OLEFontImpl_put_Weight
,
1165 OLEFontImpl_get_Charset
,
1166 OLEFontImpl_put_Charset
,
1167 OLEFontImpl_get_hFont
,
1169 OLEFontImpl_IsEqual
,
1170 OLEFontImpl_SetRatio
,
1171 OLEFontImpl_QueryTextMetrics
,
1172 OLEFontImpl_AddRefHfont
,
1173 OLEFontImpl_ReleaseHfont
,
1177 /************************************************************************
1178 * OLEFontImpl_IDispatch_QueryInterface (IUnknown)
1180 static HRESULT WINAPI
OLEFontImpl_IDispatch_QueryInterface(
1185 OLEFontImpl
*this = impl_from_IDispatch(iface
);
1186 return IFont_QueryInterface(&this->IFont_iface
, riid
, ppvoid
);
1189 /************************************************************************
1190 * OLEFontImpl_IDispatch_Release (IUnknown)
1192 static ULONG WINAPI
OLEFontImpl_IDispatch_Release(
1195 OLEFontImpl
*this = impl_from_IDispatch(iface
);
1196 return IFont_Release(&this->IFont_iface
);
1199 /************************************************************************
1200 * OLEFontImpl_IDispatch_AddRef (IUnknown)
1202 static ULONG WINAPI
OLEFontImpl_IDispatch_AddRef(
1205 OLEFontImpl
*this = impl_from_IDispatch(iface
);
1206 return IFont_AddRef(&this->IFont_iface
);
1209 /************************************************************************
1210 * OLEFontImpl_GetTypeInfoCount (IDispatch)
1212 static HRESULT WINAPI
OLEFontImpl_GetTypeInfoCount(
1214 unsigned int* pctinfo
)
1216 OLEFontImpl
*this = impl_from_IDispatch(iface
);
1217 TRACE("(%p)->(%p)\n", this, pctinfo
);
1223 /************************************************************************
1224 * OLEFontImpl_GetTypeInfo (IDispatch)
1226 static HRESULT WINAPI
OLEFontImpl_GetTypeInfo(
1230 ITypeInfo
** ppTInfo
)
1235 OLEFontImpl
*this = impl_from_IDispatch(iface
);
1236 TRACE("(%p, iTInfo=%d, lcid=%04x, %p)\n", this, iTInfo
, (int)lcid
, ppTInfo
);
1239 hres
= LoadTypeLib(L
"stdole2.tlb", &tl
);
1241 ERR("Could not load the stdole2.tlb?\n");
1244 hres
= ITypeLib_GetTypeInfoOfGuid(tl
, &IID_IFontDisp
, ppTInfo
);
1245 ITypeLib_Release(tl
);
1247 FIXME("Did not IDispatch typeinfo from typelib, hres %x\n",hres
);
1252 /************************************************************************
1253 * OLEFontImpl_GetIDsOfNames (IDispatch)
1255 static HRESULT WINAPI
OLEFontImpl_GetIDsOfNames(
1258 LPOLESTR
* rgszNames
,
1266 OLEFontImpl
*this = impl_from_IDispatch(iface
);
1268 TRACE("(%p,%s,%p,cNames=%d,lcid=%04x,%p)\n", this, debugstr_guid(riid
),
1269 rgszNames
, cNames
, (int)lcid
, rgDispId
);
1271 if (cNames
== 0) return E_INVALIDARG
;
1273 hres
= IDispatch_GetTypeInfo(iface
, 0, lcid
, &pTInfo
);
1276 ERR("GetTypeInfo failed.\n");
1280 /* convert names to DISPIDs */
1281 hres
= DispGetIDsOfNames (pTInfo
, rgszNames
, cNames
, rgDispId
);
1282 ITypeInfo_Release(pTInfo
);
1287 /************************************************************************
1288 * OLEFontImpl_Invoke (IDispatch)
1291 static HRESULT WINAPI
OLEFontImpl_Invoke(
1293 DISPID dispIdMember
,
1297 DISPPARAMS
* pDispParams
,
1298 VARIANT
* pVarResult
,
1299 EXCEPINFO
* pExepInfo
,
1302 OLEFontImpl
*this = impl_from_IDispatch(iface
);
1305 TRACE("%p->(%d,%s,0x%x,0x%x,%p,%p,%p,%p)\n", this, dispIdMember
,
1306 debugstr_guid(riid
), lcid
, wFlags
, pDispParams
, pVarResult
, pExepInfo
,
1309 /* validate parameters */
1311 if (!IsEqualIID(riid
, &IID_NULL
))
1313 ERR("riid was %s instead of IID_NULL\n", debugstr_guid(riid
));
1314 return DISP_E_UNKNOWNINTERFACE
;
1317 if (wFlags
& DISPATCH_PROPERTYGET
)
1321 ERR("null pVarResult not allowed when DISPATCH_PROPERTYGET specified\n");
1322 return DISP_E_PARAMNOTOPTIONAL
;
1325 else if (wFlags
& DISPATCH_PROPERTYPUT
)
1329 ERR("null pDispParams not allowed when DISPATCH_PROPERTYPUT specified\n");
1330 return DISP_E_PARAMNOTOPTIONAL
;
1332 if (pDispParams
->cArgs
!= 1)
1334 ERR("param count for DISPATCH_PROPERTYPUT was %d instead of 1\n", pDispParams
->cArgs
);
1335 return DISP_E_BADPARAMCOUNT
;
1340 ERR("one of DISPATCH_PROPERTYGET or DISPATCH_PROPERTYPUT must be specified\n");
1341 return DISP_E_MEMBERNOTFOUND
;
1344 switch (dispIdMember
) {
1345 case DISPID_FONT_NAME
:
1346 if (wFlags
& DISPATCH_PROPERTYGET
) {
1347 V_VT(pVarResult
) = VT_BSTR
;
1348 return IFont_get_Name(&this->IFont_iface
, &V_BSTR(pVarResult
));
1352 VariantInit(&vararg
);
1353 hr
= VariantChangeTypeEx(&vararg
, &pDispParams
->rgvarg
[0], lcid
, 0, VT_BSTR
);
1357 hr
= IFont_put_Name(&this->IFont_iface
, V_BSTR(&vararg
));
1359 VariantClear(&vararg
);
1363 case DISPID_FONT_BOLD
:
1364 if (wFlags
& DISPATCH_PROPERTYGET
) {
1366 hr
= IFont_get_Bold(&this->IFont_iface
, &value
);
1367 V_VT(pVarResult
) = VT_BOOL
;
1368 V_BOOL(pVarResult
) = value
? VARIANT_TRUE
: VARIANT_FALSE
;
1373 VariantInit(&vararg
);
1374 hr
= VariantChangeTypeEx(&vararg
, &pDispParams
->rgvarg
[0], lcid
, 0, VT_BOOL
);
1378 hr
= IFont_put_Bold(&this->IFont_iface
, V_BOOL(&vararg
));
1380 VariantClear(&vararg
);
1384 case DISPID_FONT_ITALIC
:
1385 if (wFlags
& DISPATCH_PROPERTYGET
) {
1387 hr
= IFont_get_Italic(&this->IFont_iface
, &value
);
1388 V_VT(pVarResult
) = VT_BOOL
;
1389 V_BOOL(pVarResult
) = value
? VARIANT_TRUE
: VARIANT_FALSE
;
1394 VariantInit(&vararg
);
1395 hr
= VariantChangeTypeEx(&vararg
, &pDispParams
->rgvarg
[0], lcid
, 0, VT_BOOL
);
1399 hr
= IFont_put_Italic(&this->IFont_iface
, V_BOOL(&vararg
));
1401 VariantClear(&vararg
);
1405 case DISPID_FONT_UNDER
:
1406 if (wFlags
& DISPATCH_PROPERTYGET
) {
1408 hr
= IFont_get_Underline(&this->IFont_iface
, &value
);
1409 V_VT(pVarResult
) = VT_BOOL
;
1410 V_BOOL(pVarResult
) = value
? VARIANT_TRUE
: VARIANT_FALSE
;
1415 VariantInit(&vararg
);
1416 hr
= VariantChangeTypeEx(&vararg
, &pDispParams
->rgvarg
[0], lcid
, 0, VT_BOOL
);
1420 hr
= IFont_put_Underline(&this->IFont_iface
, V_BOOL(&vararg
));
1422 VariantClear(&vararg
);
1426 case DISPID_FONT_STRIKE
:
1427 if (wFlags
& DISPATCH_PROPERTYGET
) {
1429 hr
= IFont_get_Strikethrough(&this->IFont_iface
, &value
);
1430 V_VT(pVarResult
) = VT_BOOL
;
1431 V_BOOL(pVarResult
) = value
? VARIANT_TRUE
: VARIANT_FALSE
;
1436 VariantInit(&vararg
);
1437 hr
= VariantChangeTypeEx(&vararg
, &pDispParams
->rgvarg
[0], lcid
, 0, VT_BOOL
);
1441 hr
= IFont_put_Strikethrough(&this->IFont_iface
, V_BOOL(&vararg
));
1443 VariantClear(&vararg
);
1447 case DISPID_FONT_SIZE
:
1448 if (wFlags
& DISPATCH_PROPERTYGET
) {
1449 V_VT(pVarResult
) = VT_CY
;
1450 return IFont_get_Size(&this->IFont_iface
, &V_CY(pVarResult
));
1454 VariantInit(&vararg
);
1455 hr
= VariantChangeTypeEx(&vararg
, &pDispParams
->rgvarg
[0], lcid
, 0, VT_CY
);
1459 hr
= IFont_put_Size(&this->IFont_iface
, V_CY(&vararg
));
1461 VariantClear(&vararg
);
1465 case DISPID_FONT_WEIGHT
:
1466 if (wFlags
& DISPATCH_PROPERTYGET
) {
1467 V_VT(pVarResult
) = VT_I2
;
1468 return IFont_get_Weight(&this->IFont_iface
, &V_I2(pVarResult
));
1472 VariantInit(&vararg
);
1473 hr
= VariantChangeTypeEx(&vararg
, &pDispParams
->rgvarg
[0], lcid
, 0, VT_I2
);
1477 hr
= IFont_put_Weight(&this->IFont_iface
, V_I2(&vararg
));
1479 VariantClear(&vararg
);
1483 case DISPID_FONT_CHARSET
:
1484 if (wFlags
& DISPATCH_PROPERTYGET
) {
1485 V_VT(pVarResult
) = VT_I2
;
1486 return OLEFontImpl_get_Charset(&this->IFont_iface
, &V_I2(pVarResult
));
1490 VariantInit(&vararg
);
1491 hr
= VariantChangeTypeEx(&vararg
, &pDispParams
->rgvarg
[0], lcid
, 0, VT_I2
);
1495 hr
= IFont_put_Charset(&this->IFont_iface
, V_I2(&vararg
));
1497 VariantClear(&vararg
);
1502 ERR("member not found for dispid 0x%x\n", dispIdMember
);
1503 return DISP_E_MEMBERNOTFOUND
;
1507 static const IDispatchVtbl OLEFontImpl_IDispatch_VTable
=
1509 OLEFontImpl_IDispatch_QueryInterface
,
1510 OLEFontImpl_IDispatch_AddRef
,
1511 OLEFontImpl_IDispatch_Release
,
1512 OLEFontImpl_GetTypeInfoCount
,
1513 OLEFontImpl_GetTypeInfo
,
1514 OLEFontImpl_GetIDsOfNames
,
1518 /************************************************************************
1519 * OLEFontImpl_IPersistStream_QueryInterface (IUnknown)
1521 static HRESULT WINAPI
OLEFontImpl_IPersistStream_QueryInterface(
1522 IPersistStream
* iface
,
1526 OLEFontImpl
*this = impl_from_IPersistStream(iface
);
1528 return IFont_QueryInterface(&this->IFont_iface
, riid
, ppvoid
);
1531 /************************************************************************
1532 * OLEFontImpl_IPersistStream_Release (IUnknown)
1534 static ULONG WINAPI
OLEFontImpl_IPersistStream_Release(
1535 IPersistStream
* iface
)
1537 OLEFontImpl
*this = impl_from_IPersistStream(iface
);
1539 return IFont_Release(&this->IFont_iface
);
1542 /************************************************************************
1543 * OLEFontImpl_IPersistStream_AddRef (IUnknown)
1545 static ULONG WINAPI
OLEFontImpl_IPersistStream_AddRef(
1546 IPersistStream
* iface
)
1548 OLEFontImpl
*this = impl_from_IPersistStream(iface
);
1550 return IFont_AddRef(&this->IFont_iface
);
1553 /************************************************************************
1554 * OLEFontImpl_GetClassID (IPersistStream)
1556 static HRESULT WINAPI
OLEFontImpl_GetClassID(
1557 IPersistStream
* iface
,
1560 TRACE("(%p,%p)\n",iface
,pClassID
);
1564 *pClassID
= CLSID_StdFont
;
1569 /************************************************************************
1570 * OLEFontImpl_IsDirty (IPersistStream)
1572 * See Windows documentation for more details on IPersistStream methods.
1574 static HRESULT WINAPI
OLEFontImpl_IsDirty(
1575 IPersistStream
* iface
)
1577 TRACE("(%p)\n",iface
);
1581 /************************************************************************
1582 * OLEFontImpl_Load (IPersistStream)
1584 * See Windows documentation for more details on IPersistStream methods.
1586 * This is the format of the standard font serialization as far as I
1589 * Offset Type Value Comment
1590 * 0x0000 Byte Unknown Probably a version number, contains 0x01
1591 * 0x0001 Short Charset Charset value from the FONTDESC structure
1592 * 0x0003 Byte Attributes Flags defined as follows:
1594 * 00000100 - Underline
1595 * 00001000 - Strikethrough
1596 * 0x0004 Short Weight Weight value from FONTDESC structure
1597 * 0x0006 DWORD size "Low" portion of the cySize member of the FONTDESC
1599 * 0x000A Byte name length Length of the font name string (no null character)
1600 * 0x000B String name Name of the font (ASCII, no nul character)
1602 static HRESULT WINAPI
OLEFontImpl_Load(
1603 IPersistStream
* iface
,
1604 IStream
* pLoadStream
)
1606 OLEFontImpl
*this = impl_from_IPersistStream(iface
);
1607 BYTE version
, attributes
, string_size
;
1608 char readBuffer
[0x100];
1613 IStream_Read(pLoadStream
, &version
, sizeof(BYTE
), &cbRead
);
1614 if ((cbRead
!= sizeof(BYTE
)) || (version
!= 0x01)) return E_FAIL
;
1617 IStream_Read(pLoadStream
, &this->description
.sCharset
, sizeof(WORD
), &cbRead
);
1618 if (cbRead
!= sizeof(WORD
)) return E_FAIL
;
1621 IStream_Read(pLoadStream
, &attributes
, sizeof(BYTE
), &cbRead
);
1622 if (cbRead
!= sizeof(BYTE
)) return E_FAIL
;
1624 this->description
.fItalic
= (attributes
& FONTPERSIST_ITALIC
) != 0;
1625 this->description
.fStrikethrough
= (attributes
& FONTPERSIST_STRIKETHROUGH
) != 0;
1626 this->description
.fUnderline
= (attributes
& FONTPERSIST_UNDERLINE
) != 0;
1629 IStream_Read(pLoadStream
, &this->description
.sWeight
, sizeof(WORD
), &cbRead
);
1630 if (cbRead
!= sizeof(WORD
)) return E_FAIL
;
1633 IStream_Read(pLoadStream
, &this->description
.cySize
.s
.Lo
, sizeof(DWORD
), &cbRead
);
1634 if (cbRead
!= sizeof(DWORD
)) return E_FAIL
;
1636 this->description
.cySize
.s
.Hi
= 0;
1639 IStream_Read(pLoadStream
, &string_size
, sizeof(BYTE
), &cbRead
);
1640 if (cbRead
!= sizeof(BYTE
)) return E_FAIL
;
1642 IStream_Read(pLoadStream
, readBuffer
, string_size
, &cbRead
);
1643 if (cbRead
!= string_size
) return E_FAIL
;
1645 HeapFree(GetProcessHeap(), 0, this->description
.lpstrName
);
1647 len
= MultiByteToWideChar( CP_ACP
, 0, readBuffer
, string_size
, NULL
, 0 );
1648 this->description
.lpstrName
= HeapAlloc( GetProcessHeap(), 0, (len
+1) * sizeof(WCHAR
) );
1649 MultiByteToWideChar( CP_ACP
, 0, readBuffer
, string_size
, this->description
.lpstrName
, len
);
1650 this->description
.lpstrName
[len
] = 0;
1652 /* Ensure use of this font causes a new one to be created */
1653 dec_int_ref(this->gdiFont
);
1660 /************************************************************************
1661 * OLEFontImpl_Save (IPersistStream)
1663 static HRESULT WINAPI
OLEFontImpl_Save(
1664 IPersistStream
* iface
,
1665 IStream
* pOutStream
,
1668 OLEFontImpl
*this = impl_from_IPersistStream(iface
);
1669 BYTE attributes
, string_size
;
1670 const BYTE version
= 0x01;
1671 char* writeBuffer
= NULL
;
1674 TRACE("(%p)->(%p %d)\n", this, pOutStream
, fClearDirty
);
1677 IStream_Write(pOutStream
, &version
, sizeof(BYTE
), &written
);
1678 if (written
!= sizeof(BYTE
)) return E_FAIL
;
1681 IStream_Write(pOutStream
, &this->description
.sCharset
, sizeof(WORD
), &written
);
1682 if (written
!= sizeof(WORD
)) return E_FAIL
;
1687 if (this->description
.fItalic
)
1688 attributes
|= FONTPERSIST_ITALIC
;
1690 if (this->description
.fStrikethrough
)
1691 attributes
|= FONTPERSIST_STRIKETHROUGH
;
1693 if (this->description
.fUnderline
)
1694 attributes
|= FONTPERSIST_UNDERLINE
;
1696 IStream_Write(pOutStream
, &attributes
, sizeof(BYTE
), &written
);
1697 if (written
!= sizeof(BYTE
)) return E_FAIL
;
1700 IStream_Write(pOutStream
, &this->description
.sWeight
, sizeof(WORD
), &written
);
1701 if (written
!= sizeof(WORD
)) return E_FAIL
;
1704 IStream_Write(pOutStream
, &this->description
.cySize
.s
.Lo
, sizeof(DWORD
), &written
);
1705 if (written
!= sizeof(DWORD
)) return E_FAIL
;
1708 if (this->description
.lpstrName
)
1709 string_size
= WideCharToMultiByte( CP_ACP
, 0, this->description
.lpstrName
,
1710 lstrlenW(this->description
.lpstrName
), NULL
, 0, NULL
, NULL
);
1714 IStream_Write(pOutStream
, &string_size
, sizeof(BYTE
), &written
);
1715 if (written
!= sizeof(BYTE
)) return E_FAIL
;
1719 if (!(writeBuffer
= HeapAlloc( GetProcessHeap(), 0, string_size
))) return E_OUTOFMEMORY
;
1720 WideCharToMultiByte( CP_ACP
, 0, this->description
.lpstrName
,
1721 lstrlenW(this->description
.lpstrName
),
1722 writeBuffer
, string_size
, NULL
, NULL
);
1724 IStream_Write(pOutStream
, writeBuffer
, string_size
, &written
);
1725 HeapFree(GetProcessHeap(), 0, writeBuffer
);
1727 if (written
!= string_size
) return E_FAIL
;
1733 /************************************************************************
1734 * OLEFontImpl_GetSizeMax (IPersistStream)
1736 static HRESULT WINAPI
OLEFontImpl_GetSizeMax(
1737 IPersistStream
* iface
,
1738 ULARGE_INTEGER
* pcbSize
)
1740 OLEFontImpl
*this = impl_from_IPersistStream(iface
);
1745 pcbSize
->u
.HighPart
= 0;
1746 pcbSize
->u
.LowPart
= 0;
1748 pcbSize
->u
.LowPart
+= sizeof(BYTE
); /* Version */
1749 pcbSize
->u
.LowPart
+= sizeof(WORD
); /* Lang code */
1750 pcbSize
->u
.LowPart
+= sizeof(BYTE
); /* Flags */
1751 pcbSize
->u
.LowPart
+= sizeof(WORD
); /* Weight */
1752 pcbSize
->u
.LowPart
+= sizeof(DWORD
); /* Size */
1753 pcbSize
->u
.LowPart
+= sizeof(BYTE
); /* StrLength */
1755 if (this->description
.lpstrName
!=0)
1756 pcbSize
->u
.LowPart
+= WideCharToMultiByte( CP_ACP
, 0, this->description
.lpstrName
,
1757 lstrlenW(this->description
.lpstrName
),
1758 NULL
, 0, NULL
, NULL
);
1763 static const IPersistStreamVtbl OLEFontImpl_IPersistStream_VTable
=
1765 OLEFontImpl_IPersistStream_QueryInterface
,
1766 OLEFontImpl_IPersistStream_AddRef
,
1767 OLEFontImpl_IPersistStream_Release
,
1768 OLEFontImpl_GetClassID
,
1769 OLEFontImpl_IsDirty
,
1772 OLEFontImpl_GetSizeMax
1775 /************************************************************************
1776 * OLEFontImpl_IConnectionPointContainer_QueryInterface (IUnknown)
1778 static HRESULT WINAPI
OLEFontImpl_IConnectionPointContainer_QueryInterface(
1779 IConnectionPointContainer
* iface
,
1783 OLEFontImpl
*this = impl_from_IConnectionPointContainer(iface
);
1785 return IFont_QueryInterface(&this->IFont_iface
, riid
, ppvoid
);
1788 /************************************************************************
1789 * OLEFontImpl_IConnectionPointContainer_Release (IUnknown)
1791 static ULONG WINAPI
OLEFontImpl_IConnectionPointContainer_Release(
1792 IConnectionPointContainer
* iface
)
1794 OLEFontImpl
*this = impl_from_IConnectionPointContainer(iface
);
1796 return IFont_Release(&this->IFont_iface
);
1799 /************************************************************************
1800 * OLEFontImpl_IConnectionPointContainer_AddRef (IUnknown)
1802 static ULONG WINAPI
OLEFontImpl_IConnectionPointContainer_AddRef(
1803 IConnectionPointContainer
* iface
)
1805 OLEFontImpl
*this = impl_from_IConnectionPointContainer(iface
);
1807 return IFont_AddRef(&this->IFont_iface
);
1810 /************************************************************************
1811 * OLEFontImpl_EnumConnectionPoints (IConnectionPointContainer)
1813 static HRESULT WINAPI
OLEFontImpl_EnumConnectionPoints(
1814 IConnectionPointContainer
* iface
,
1815 IEnumConnectionPoints
**ppEnum
)
1817 OLEFontImpl
*this = impl_from_IConnectionPointContainer(iface
);
1819 FIXME("(%p)->(%p): stub\n", this, ppEnum
);
1823 /************************************************************************
1824 * OLEFontImpl_FindConnectionPoint (IConnectionPointContainer)
1826 static HRESULT WINAPI
OLEFontImpl_FindConnectionPoint(
1827 IConnectionPointContainer
* iface
,
1829 IConnectionPoint
**ppCp
)
1831 OLEFontImpl
*this = impl_from_IConnectionPointContainer(iface
);
1832 TRACE("(%p)->(%s, %p)\n", this, debugstr_guid(riid
), ppCp
);
1834 if(IsEqualIID(riid
, &IID_IPropertyNotifySink
)) {
1835 return IConnectionPoint_QueryInterface(this->pPropertyNotifyCP
, &IID_IConnectionPoint
,
1837 } else if(IsEqualIID(riid
, &IID_IFontEventsDisp
)) {
1838 return IConnectionPoint_QueryInterface(this->pFontEventsCP
, &IID_IConnectionPoint
,
1841 FIXME("no connection point for %s\n", debugstr_guid(riid
));
1842 return CONNECT_E_NOCONNECTION
;
1846 static const IConnectionPointContainerVtbl
1847 OLEFontImpl_IConnectionPointContainer_VTable
=
1849 OLEFontImpl_IConnectionPointContainer_QueryInterface
,
1850 OLEFontImpl_IConnectionPointContainer_AddRef
,
1851 OLEFontImpl_IConnectionPointContainer_Release
,
1852 OLEFontImpl_EnumConnectionPoints
,
1853 OLEFontImpl_FindConnectionPoint
1856 /************************************************************************
1857 * OLEFontImpl implementation of IPersistPropertyBag.
1859 static HRESULT WINAPI
OLEFontImpl_IPersistPropertyBag_QueryInterface(
1860 IPersistPropertyBag
*iface
, REFIID riid
, LPVOID
*ppvObj
1862 OLEFontImpl
*this = impl_from_IPersistPropertyBag(iface
);
1863 return IFont_QueryInterface(&this->IFont_iface
,riid
,ppvObj
);
1866 static ULONG WINAPI
OLEFontImpl_IPersistPropertyBag_AddRef(
1867 IPersistPropertyBag
*iface
1869 OLEFontImpl
*this = impl_from_IPersistPropertyBag(iface
);
1870 return IFont_AddRef(&this->IFont_iface
);
1873 static ULONG WINAPI
OLEFontImpl_IPersistPropertyBag_Release(
1874 IPersistPropertyBag
*iface
1876 OLEFontImpl
*this = impl_from_IPersistPropertyBag(iface
);
1877 return IFont_Release(&this->IFont_iface
);
1880 static HRESULT WINAPI
OLEFontImpl_IPersistPropertyBag_GetClassID(
1881 IPersistPropertyBag
*iface
, CLSID
*classid
1883 FIXME("(%p,%p), stub!\n", iface
, classid
);
1887 static HRESULT WINAPI
OLEFontImpl_IPersistPropertyBag_InitNew(
1888 IPersistPropertyBag
*iface
1890 FIXME("(%p), stub!\n", iface
);
1894 static HRESULT WINAPI
OLEFontImpl_IPersistPropertyBag_Load(
1895 IPersistPropertyBag
*iface
, IPropertyBag
* pPropBag
, IErrorLog
* pErrorLog
1897 /* (from Visual Basic 6 property bag)
1898 Name = "MS Sans Serif"
1902 Underline = 0 'False
1904 Strikethrough = 0 'False
1906 OLEFontImpl
*this = impl_from_IPersistPropertyBag(iface
);
1910 VariantInit(&value
);
1912 iRes
= IPropertyBag_Read(pPropBag
, L
"Name", &value
, pErrorLog
);
1915 iRes
= VariantChangeType(&value
, &value
, 0, VT_BSTR
);
1917 iRes
= IFont_put_Name(&this->IFont_iface
, V_BSTR(&value
));
1919 else if (iRes
== E_INVALIDARG
)
1922 VariantClear(&value
);
1925 iRes
= IPropertyBag_Read(pPropBag
, L
"Size", &value
, pErrorLog
);
1928 iRes
= VariantChangeType(&value
, &value
, 0, VT_CY
);
1930 iRes
= IFont_put_Size(&this->IFont_iface
, V_CY(&value
));
1932 else if (iRes
== E_INVALIDARG
)
1935 VariantClear(&value
);
1939 iRes
= IPropertyBag_Read(pPropBag
, L
"Charset", &value
, pErrorLog
);
1942 iRes
= VariantChangeType(&value
, &value
, 0, VT_I2
);
1944 iRes
= IFont_put_Charset(&this->IFont_iface
, V_I2(&value
));
1946 else if (iRes
== E_INVALIDARG
)
1949 VariantClear(&value
);
1953 iRes
= IPropertyBag_Read(pPropBag
, L
"Weight", &value
, pErrorLog
);
1956 iRes
= VariantChangeType(&value
, &value
, 0, VT_I2
);
1958 iRes
= IFont_put_Weight(&this->IFont_iface
, V_I2(&value
));
1960 else if (iRes
== E_INVALIDARG
)
1963 VariantClear(&value
);
1967 iRes
= IPropertyBag_Read(pPropBag
, L
"Underline", &value
, pErrorLog
);
1970 iRes
= VariantChangeType(&value
, &value
, 0, VT_BOOL
);
1972 iRes
= IFont_put_Underline(&this->IFont_iface
, V_BOOL(&value
));
1974 else if (iRes
== E_INVALIDARG
)
1977 VariantClear(&value
);
1981 iRes
= IPropertyBag_Read(pPropBag
, L
"Italic", &value
, pErrorLog
);
1984 iRes
= VariantChangeType(&value
, &value
, 0, VT_BOOL
);
1986 iRes
= IFont_put_Italic(&this->IFont_iface
, V_BOOL(&value
));
1988 else if (iRes
== E_INVALIDARG
)
1991 VariantClear(&value
);
1995 iRes
= IPropertyBag_Read(pPropBag
, L
"Strikethrough", &value
, pErrorLog
);
1998 iRes
= VariantChangeType(&value
, &value
, 0, VT_BOOL
);
2000 IFont_put_Strikethrough(&this->IFont_iface
, V_BOOL(&value
));
2002 else if (iRes
== E_INVALIDARG
)
2005 VariantClear(&value
);
2009 WARN("-- 0x%08x\n", iRes
);
2013 static HRESULT WINAPI
OLEFontImpl_IPersistPropertyBag_Save(
2014 IPersistPropertyBag
*iface
, IPropertyBag
* pPropBag
, BOOL fClearDirty
,
2015 BOOL fSaveAllProperties
2017 FIXME("(%p,%p,%d,%d), stub!\n", iface
, pPropBag
, fClearDirty
, fSaveAllProperties
);
2021 static const IPersistPropertyBagVtbl OLEFontImpl_IPersistPropertyBag_VTable
=
2023 OLEFontImpl_IPersistPropertyBag_QueryInterface
,
2024 OLEFontImpl_IPersistPropertyBag_AddRef
,
2025 OLEFontImpl_IPersistPropertyBag_Release
,
2027 OLEFontImpl_IPersistPropertyBag_GetClassID
,
2028 OLEFontImpl_IPersistPropertyBag_InitNew
,
2029 OLEFontImpl_IPersistPropertyBag_Load
,
2030 OLEFontImpl_IPersistPropertyBag_Save
2033 /************************************************************************
2034 * OLEFontImpl_Construct
2036 * This method will construct a new instance of the OLEFontImpl
2039 * The caller of this method must release the object when it's
2042 static OLEFontImpl
* OLEFontImpl_Construct(const FONTDESC
*fontDesc
)
2044 OLEFontImpl
* newObject
;
2046 newObject
= HeapAlloc(GetProcessHeap(), 0, sizeof(OLEFontImpl
));
2051 newObject
->IFont_iface
.lpVtbl
= &OLEFontImpl_VTable
;
2052 newObject
->IDispatch_iface
.lpVtbl
= &OLEFontImpl_IDispatch_VTable
;
2053 newObject
->IPersistStream_iface
.lpVtbl
= &OLEFontImpl_IPersistStream_VTable
;
2054 newObject
->IConnectionPointContainer_iface
.lpVtbl
= &OLEFontImpl_IConnectionPointContainer_VTable
;
2055 newObject
->IPersistPropertyBag_iface
.lpVtbl
= &OLEFontImpl_IPersistPropertyBag_VTable
;
2059 newObject
->description
.cbSizeofstruct
= sizeof(FONTDESC
);
2060 newObject
->description
.lpstrName
= strdupW(fontDesc
->lpstrName
);
2061 newObject
->description
.cySize
= fontDesc
->cySize
;
2062 newObject
->description
.sWeight
= fontDesc
->sWeight
;
2063 newObject
->description
.sCharset
= fontDesc
->sCharset
;
2064 newObject
->description
.fItalic
= fontDesc
->fItalic
;
2065 newObject
->description
.fUnderline
= fontDesc
->fUnderline
;
2066 newObject
->description
.fStrikethrough
= fontDesc
->fStrikethrough
;
2068 newObject
->gdiFont
= 0;
2069 newObject
->dirty
= TRUE
;
2070 newObject
->cyLogical
= GetDeviceCaps(get_dc(), LOGPIXELSY
);
2071 newObject
->cyHimetric
= 2540L;
2072 newObject
->pPropertyNotifyCP
= NULL
;
2073 newObject
->pFontEventsCP
= NULL
;
2075 CreateConnectionPoint((IUnknown
*)&newObject
->IFont_iface
, &IID_IPropertyNotifySink
, &newObject
->pPropertyNotifyCP
);
2076 CreateConnectionPoint((IUnknown
*)&newObject
->IFont_iface
, &IID_IFontEventsDisp
, &newObject
->pFontEventsCP
);
2078 if (!newObject
->pPropertyNotifyCP
|| !newObject
->pFontEventsCP
)
2080 OLEFontImpl_Destroy(newObject
);
2084 InterlockedIncrement(&ifont_cnt
);
2086 TRACE("returning %p\n", newObject
);
2090 /************************************************************************
2091 * OLEFontImpl_Destroy
2093 * This method is called by the Release method when the reference
2094 * count goes down to 0. It will free all resources used by
2097 static void OLEFontImpl_Destroy(OLEFontImpl
* fontDesc
)
2099 TRACE("(%p)\n", fontDesc
);
2101 HeapFree(GetProcessHeap(), 0, fontDesc
->description
.lpstrName
);
2103 if (fontDesc
->pPropertyNotifyCP
)
2104 IConnectionPoint_Release(fontDesc
->pPropertyNotifyCP
);
2105 if (fontDesc
->pFontEventsCP
)
2106 IConnectionPoint_Release(fontDesc
->pFontEventsCP
);
2108 HeapFree(GetProcessHeap(), 0, fontDesc
);
2111 /*******************************************************************************
2112 * StdFont ClassFactory
2116 /* IUnknown fields */
2117 IClassFactory IClassFactory_iface
;
2119 } IClassFactoryImpl
;
2121 static inline IClassFactoryImpl
*impl_from_IClassFactory(IClassFactory
*iface
)
2123 return CONTAINING_RECORD(iface
, IClassFactoryImpl
, IClassFactory_iface
);
2126 static HRESULT WINAPI
SFCF_QueryInterface(IClassFactory
*iface
, REFIID riid
, void **obj
)
2128 IClassFactoryImpl
*This
= impl_from_IClassFactory(iface
);
2130 TRACE("(%p)->(%s, %p)\n", This
, debugstr_guid(riid
), obj
);
2134 if (IsEqualIID(&IID_IClassFactory
, riid
) || IsEqualIID(&IID_IUnknown
, riid
))
2137 IClassFactory_AddRef(iface
);
2141 return E_NOINTERFACE
;
2145 SFCF_AddRef(LPCLASSFACTORY iface
) {
2146 IClassFactoryImpl
*This
= impl_from_IClassFactory(iface
);
2147 return InterlockedIncrement(&This
->ref
);
2150 static ULONG WINAPI
SFCF_Release(LPCLASSFACTORY iface
) {
2151 IClassFactoryImpl
*This
= impl_from_IClassFactory(iface
);
2152 /* static class, won't be freed */
2153 return InterlockedDecrement(&This
->ref
);
2156 static HRESULT WINAPI
SFCF_CreateInstance(
2157 LPCLASSFACTORY iface
,LPUNKNOWN pOuter
,REFIID riid
,LPVOID
*ppobj
2159 return OleCreateFontIndirect(NULL
,riid
,ppobj
);
2163 static HRESULT WINAPI
SFCF_LockServer(LPCLASSFACTORY iface
,BOOL dolock
) {
2164 IClassFactoryImpl
*This
= impl_from_IClassFactory(iface
);
2165 FIXME("(%p)->(%d),stub!\n",This
,dolock
);
2169 static const IClassFactoryVtbl SFCF_Vtbl
= {
2170 SFCF_QueryInterface
,
2173 SFCF_CreateInstance
,
2176 static IClassFactoryImpl STDFONT_CF
= {{&SFCF_Vtbl
}, 1 };
2178 void _get_STDFONT_CF(LPVOID
*ppv
) { *ppv
= &STDFONT_CF
; }