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
);
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
= malloc(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 /***********************************************************************
230 * Declaration of the implementation class for the IFont interface
232 typedef struct OLEFontImpl OLEFontImpl
;
237 * This class supports many interfaces. IUnknown, IFont,
238 * IDispatch, IDispFont IPersistStream and IConnectionPointContainer.
239 * The first two are supported by the first vtable, the next two are
240 * supported by the second table and the last two have their own.
243 IDispatch IDispatch_iface
;
244 IPersistStream IPersistStream_iface
;
245 IConnectionPointContainer IConnectionPointContainer_iface
;
246 IPersistPropertyBag IPersistPropertyBag_iface
;
248 * Reference count for that instance of the class.
253 * This structure contains the description of the class.
255 FONTDESC description
;
258 * Contain the font associated with this object.
269 * Stash realized height (pixels) from TEXTMETRIC - used in get_Size()
273 IConnectionPoint
*pPropertyNotifyCP
;
274 IConnectionPoint
*pFontEventsCP
;
277 static inline OLEFontImpl
*impl_from_IFont(IFont
*iface
)
279 return CONTAINING_RECORD(iface
, OLEFontImpl
, IFont_iface
);
282 static inline OLEFontImpl
*impl_from_IDispatch( IDispatch
*iface
)
284 return CONTAINING_RECORD(iface
, OLEFontImpl
, IDispatch_iface
);
287 static inline OLEFontImpl
*impl_from_IPersistStream( IPersistStream
*iface
)
289 return CONTAINING_RECORD(iface
, OLEFontImpl
, IPersistStream_iface
);
292 static inline OLEFontImpl
*impl_from_IConnectionPointContainer( IConnectionPointContainer
*iface
)
294 return CONTAINING_RECORD(iface
, OLEFontImpl
, IConnectionPointContainer_iface
);
297 static inline OLEFontImpl
*impl_from_IPersistPropertyBag( IPersistPropertyBag
*iface
)
299 return CONTAINING_RECORD(iface
, OLEFontImpl
, IPersistPropertyBag_iface
);
303 /***********************************************************************
304 * Prototypes for the implementation functions for the IFont
307 static OLEFontImpl
* OLEFontImpl_Construct(const FONTDESC
*fontDesc
);
308 static void OLEFontImpl_Destroy(OLEFontImpl
* fontDesc
);
309 static ULONG WINAPI
OLEFontImpl_AddRef(IFont
* iface
);
311 /******************************************************************************
312 * OleCreateFontIndirect [OLEAUT32.420]
314 HRESULT WINAPI
OleCreateFontIndirect(
315 LPFONTDESC lpFontDesc
,
319 OLEFontImpl
* newFont
;
323 TRACE("(%p, %s, %p)\n", lpFontDesc
, debugstr_guid(riid
), ppvObj
);
325 if (!ppvObj
) return E_POINTER
;
330 static WCHAR fname
[] = L
"System";
332 fd
.cbSizeofstruct
= sizeof(fd
);
333 fd
.lpstrName
= fname
;
334 fd
.cySize
.s
.Lo
= 80000;
339 fd
.fUnderline
= FALSE
;
340 fd
.fStrikethrough
= FALSE
;
344 newFont
= OLEFontImpl_Construct(lpFontDesc
);
345 if (!newFont
) return E_OUTOFMEMORY
;
347 hr
= IFont_QueryInterface(&newFont
->IFont_iface
, riid
, ppvObj
);
348 IFont_Release(&newFont
->IFont_iface
);
354 /***********************************************************************
355 * Implementation of the OLEFontImpl class.
358 /***********************************************************************
359 * OLEFont_SendNotify (internal)
361 * Sends notification messages of changed properties to any interested
364 static void OLEFont_SendNotify(OLEFontImpl
* this, DISPID dispID
)
366 static const LPCWSTR dispid_mapping
[] =
379 IEnumConnections
*pEnum
;
385 hres
= IConnectionPoint_EnumConnections(this->pPropertyNotifyCP
, &pEnum
);
388 while(IEnumConnections_Next(pEnum
, 1, &CD
, NULL
) == S_OK
) {
389 IPropertyNotifySink
*sink
;
391 IUnknown_QueryInterface(CD
.pUnk
, &IID_IPropertyNotifySink
, (void**)&sink
);
392 IPropertyNotifySink_OnChanged(sink
, dispID
);
393 IPropertyNotifySink_Release(sink
);
394 IUnknown_Release(CD
.pUnk
);
396 IEnumConnections_Release(pEnum
);
399 hres
= IConnectionPoint_EnumConnections(this->pFontEventsCP
, &pEnum
);
402 DISPPARAMS dispparams
;
405 VariantInit(&vararg
);
406 V_VT(&vararg
) = VT_BSTR
;
407 V_BSTR(&vararg
) = SysAllocString(dispid_mapping
[dispID
]);
409 dispparams
.cArgs
= 1;
410 dispparams
.cNamedArgs
= 0;
411 dispparams
.rgdispidNamedArgs
= NULL
;
412 dispparams
.rgvarg
= &vararg
;
414 while(IEnumConnections_Next(pEnum
, 1, &CD
, NULL
) == S_OK
) {
415 IFontEventsDisp
*disp
;
417 IUnknown_QueryInterface(CD
.pUnk
, &IID_IFontEventsDisp
, (void**)&disp
);
418 IFontEventsDisp_Invoke(disp
, DISPID_FONT_CHANGED
, &IID_NULL
,
419 LOCALE_NEUTRAL
, INVOKE_FUNC
, &dispparams
, NULL
,
422 IFontEventsDisp_Release(disp
);
423 IUnknown_Release(CD
.pUnk
);
425 VariantClear(&vararg
);
426 IEnumConnections_Release(pEnum
);
430 /************************************************************************
431 * OLEFontImpl_QueryInterface (IUnknown)
433 * See Windows documentation for more details on IUnknown methods.
435 static HRESULT WINAPI
OLEFontImpl_QueryInterface(
440 OLEFontImpl
*this = impl_from_IFont(iface
);
442 TRACE("(%p)->(%s, %p)\n", this, debugstr_guid(riid
), ppvObject
);
446 if (IsEqualGUID(&IID_IUnknown
, riid
) ||
447 IsEqualGUID(&IID_IFont
, riid
))
451 else if (IsEqualGUID(&IID_IDispatch
, riid
) ||
452 IsEqualGUID(&IID_IFontDisp
, riid
))
454 *ppvObject
= &this->IDispatch_iface
;
456 else if (IsEqualGUID(&IID_IPersist
, riid
) ||
457 IsEqualGUID(&IID_IPersistStream
, riid
))
459 *ppvObject
= &this->IPersistStream_iface
;
461 else if (IsEqualGUID(&IID_IConnectionPointContainer
, riid
))
463 *ppvObject
= &this->IConnectionPointContainer_iface
;
465 else if (IsEqualGUID(&IID_IPersistPropertyBag
, riid
))
467 *ppvObject
= &this->IPersistPropertyBag_iface
;
472 FIXME("() : asking for unsupported interface %s\n", debugstr_guid(riid
));
473 return E_NOINTERFACE
;
481 static ULONG WINAPI
OLEFontImpl_AddRef(IFont
* iface
)
483 OLEFontImpl
*this = impl_from_IFont(iface
);
484 ULONG ref
= InterlockedIncrement(&this->ref
);
485 TRACE("%p, refcount %lu.\n", iface
, ref
);
489 static ULONG WINAPI
OLEFontImpl_Release(IFont
* iface
)
491 OLEFontImpl
*this = impl_from_IFont(iface
);
492 ULONG ref
= InterlockedDecrement(&this->ref
);
494 TRACE("%p, refcount %lu.\n", iface
, ref
);
498 ULONG fontlist_refs
= InterlockedDecrement(&ifont_cnt
);
500 /* Final IFont object so destroy font cache */
501 if (fontlist_refs
== 0)
503 HFONTItem
*item
, *cursor2
;
505 EnterCriticalSection(&OLEFontImpl_csHFONTLIST
);
506 LIST_FOR_EACH_ENTRY_SAFE(item
, cursor2
, &OLEFontImpl_hFontList
, HFONTItem
, entry
)
507 HFONTItem_Delete(item
);
508 LeaveCriticalSection(&OLEFontImpl_csHFONTLIST
);
513 dec_int_ref(this->gdiFont
);
515 OLEFontImpl_Destroy(this);
527 static int CALLBACK
font_enum_proc(const LOGFONTW
*elf
, const TEXTMETRICW
*ntm
, DWORD type
, LPARAM lp
)
529 enum_data
*data
= (enum_data
*)lp
;
531 if(elf
->lfCharSet
== data
->orig_cs
)
533 data
->avail_cs
= data
->orig_cs
;
536 if(data
->avail_cs
== -1) data
->avail_cs
= elf
->lfCharSet
;
540 static void realize_font(OLEFontImpl
*This
)
544 WCHAR text_face
[LF_FACESIZE
];
549 if (!This
->dirty
) return;
555 old_font
= SelectObject(hdc
, This
->gdiFont
);
556 GetTextFaceW(hdc
, ARRAY_SIZE(text_face
), text_face
);
557 SelectObject(hdc
, old_font
);
558 dec_int_ref(This
->gdiFont
);
562 memset(&logFont
, 0, sizeof(LOGFONTW
));
564 lstrcpynW(logFont
.lfFaceName
, This
->description
.lpstrName
, LF_FACESIZE
);
565 logFont
.lfCharSet
= This
->description
.sCharset
;
567 /* If the font name has been changed then enumerate all charsets
568 and pick one that'll result in the font specified being selected */
569 if(text_face
[0] && lstrcmpiW(text_face
, This
->description
.lpstrName
))
572 data
.orig_cs
= This
->description
.sCharset
;
574 logFont
.lfCharSet
= DEFAULT_CHARSET
;
575 EnumFontFamiliesExW(get_dc(), &logFont
, font_enum_proc
, (LPARAM
)&data
, 0);
576 if(data
.avail_cs
!= -1) logFont
.lfCharSet
= data
.avail_cs
;
580 * The height of the font returned by the get_Size property is the
581 * height of the font in points multiplied by 10000... Using some
582 * simple conversions and the ratio given by the application, it can
583 * be converted to a height in pixels.
585 * Standard ratio is 72 / 2540, or 18 / 635 in lowest terms.
586 * Ratio is applied here relative to the standard.
589 fontHeight
= MulDiv( This
->description
.cySize
.s
.Lo
, This
->cyLogical
*635, This
->cyHimetric
*18 );
591 logFont
.lfHeight
= ((fontHeight
%10000L)>5000L) ? (-fontHeight
/10000L) - 1 :
592 (-fontHeight
/10000L);
593 logFont
.lfItalic
= This
->description
.fItalic
;
594 logFont
.lfUnderline
= This
->description
.fUnderline
;
595 logFont
.lfStrikeOut
= This
->description
.fStrikethrough
;
596 logFont
.lfWeight
= This
->description
.sWeight
;
597 logFont
.lfOutPrecision
= OUT_CHARACTER_PRECIS
;
598 logFont
.lfClipPrecision
= CLIP_DEFAULT_PRECIS
;
599 logFont
.lfQuality
= DEFAULT_QUALITY
;
600 logFont
.lfPitchAndFamily
= DEFAULT_PITCH
;
602 This
->gdiFont
= CreateFontIndirectW(&logFont
);
605 add_hfontitem(This
->gdiFont
);
607 /* Fixup the name and charset properties so that they match the
609 old_font
= SelectObject(get_dc(), This
->gdiFont
);
610 GetTextFaceW(hdc
, ARRAY_SIZE(text_face
), text_face
);
611 if(lstrcmpiW(text_face
, This
->description
.lpstrName
))
613 free(This
->description
.lpstrName
);
614 This
->description
.lpstrName
= wcsdup(text_face
);
616 GetTextMetricsW(hdc
, &tm
);
617 This
->description
.sCharset
= tm
.tmCharSet
;
618 /* While we have it handy, stash the realized font height for use by get_Size() */
619 This
->nRealHeight
= tm
.tmHeight
- tm
.tmInternalLeading
; /* corresponds to LOGFONT lfHeight */
620 SelectObject(hdc
, old_font
);
623 /************************************************************************
624 * OLEFontImpl_get_Name (IFont)
626 * See Windows documentation for more details on IFont methods.
628 static HRESULT WINAPI
OLEFontImpl_get_Name(
632 OLEFontImpl
*this = impl_from_IFont(iface
);
633 TRACE("(%p)->(%p)\n", this, pname
);
640 if (this->description
.lpstrName
!=0)
641 *pname
= SysAllocString(this->description
.lpstrName
);
648 /************************************************************************
649 * OLEFontImpl_put_Name (IFont)
651 static HRESULT WINAPI
OLEFontImpl_put_Name(
655 OLEFontImpl
*This
= impl_from_IFont(iface
);
656 TRACE("(%p)->(%p)\n", This
, name
);
659 return CTL_E_INVALIDPROPERTYVALUE
;
661 free(This
->description
.lpstrName
);
662 This
->description
.lpstrName
= wcsdup(name
);
663 if (!This
->description
.lpstrName
) return E_OUTOFMEMORY
;
665 TRACE("new name %s\n", debugstr_w(This
->description
.lpstrName
));
666 OLEFont_SendNotify(This
, DISPID_FONT_NAME
);
670 /************************************************************************
671 * OLEFontImpl_get_Size (IFont)
673 static HRESULT WINAPI
OLEFontImpl_get_Size(
677 OLEFontImpl
*this = impl_from_IFont(iface
);
678 TRACE("(%p)->(%p)\n", this, psize
);
680 if (!psize
) return E_POINTER
;
685 * Convert realized font height in pixels to points descaled by current
686 * scaling ratio then scaled up by 10000.
688 psize
->s
.Lo
= MulDiv(this->nRealHeight
,
689 this->cyHimetric
* 72 * 10000,
690 this->cyLogical
* 2540);
696 static HRESULT WINAPI
OLEFontImpl_put_Size(IFont
*iface
, CY size
)
698 OLEFontImpl
*this = impl_from_IFont(iface
);
699 TRACE("%p, %ld.\n", iface
, size
.s
.Lo
);
700 this->description
.cySize
.s
.Hi
= 0;
701 this->description
.cySize
.s
.Lo
= size
.s
.Lo
;
702 OLEFont_SendNotify(this, DISPID_FONT_SIZE
);
707 static HRESULT WINAPI
OLEFontImpl_get_Bold(IFont
*iface
, BOOL
*pbold
)
709 OLEFontImpl
*this = impl_from_IFont(iface
);
710 TRACE("(%p)->(%p)\n", this, pbold
);
712 if (!pbold
) return E_POINTER
;
716 *pbold
= this->description
.sWeight
> 550;
721 /************************************************************************
722 * OLEFontImpl_put_Bold (IFont)
724 static HRESULT WINAPI
OLEFontImpl_put_Bold(
728 OLEFontImpl
*this = impl_from_IFont(iface
);
729 TRACE("(%p)->(%d)\n", this, bold
);
730 this->description
.sWeight
= bold
? FW_BOLD
: FW_NORMAL
;
731 OLEFont_SendNotify(this, DISPID_FONT_BOLD
);
736 /************************************************************************
737 * OLEFontImpl_get_Italic (IFont)
739 static HRESULT WINAPI
OLEFontImpl_get_Italic(
743 OLEFontImpl
*this = impl_from_IFont(iface
);
744 TRACE("(%p)->(%p)\n", this, pitalic
);
751 *pitalic
= this->description
.fItalic
;
756 /************************************************************************
757 * OLEFontImpl_put_Italic (IFont)
759 static HRESULT WINAPI
OLEFontImpl_put_Italic(
763 OLEFontImpl
*this = impl_from_IFont(iface
);
764 TRACE("(%p)->(%d)\n", this, italic
);
766 this->description
.fItalic
= italic
;
768 OLEFont_SendNotify(this, DISPID_FONT_ITALIC
);
772 /************************************************************************
773 * OLEFontImpl_get_Underline (IFont)
775 static HRESULT WINAPI
OLEFontImpl_get_Underline(
779 OLEFontImpl
*this = impl_from_IFont(iface
);
780 TRACE("(%p)->(%p)\n", this, punderline
);
787 *punderline
= this->description
.fUnderline
;
792 /************************************************************************
793 * OLEFontImpl_put_Underline (IFont)
795 static HRESULT WINAPI
OLEFontImpl_put_Underline(
799 OLEFontImpl
*this = impl_from_IFont(iface
);
800 TRACE("(%p)->(%d)\n", this, underline
);
802 this->description
.fUnderline
= underline
;
804 OLEFont_SendNotify(this, DISPID_FONT_UNDER
);
808 /************************************************************************
809 * OLEFontImpl_get_Strikethrough (IFont)
811 static HRESULT WINAPI
OLEFontImpl_get_Strikethrough(
813 BOOL
* pstrikethrough
)
815 OLEFontImpl
*this = impl_from_IFont(iface
);
816 TRACE("(%p)->(%p)\n", this, pstrikethrough
);
818 if (pstrikethrough
==0)
823 *pstrikethrough
= this->description
.fStrikethrough
;
828 /************************************************************************
829 * OLEFontImpl_put_Strikethrough (IFont)
831 static HRESULT WINAPI
OLEFontImpl_put_Strikethrough(
835 OLEFontImpl
*this = impl_from_IFont(iface
);
836 TRACE("(%p)->(%d)\n", this, strikethrough
);
838 this->description
.fStrikethrough
= strikethrough
;
839 OLEFont_SendNotify(this, DISPID_FONT_STRIKE
);
844 /************************************************************************
845 * OLEFontImpl_get_Weight (IFont)
847 static HRESULT WINAPI
OLEFontImpl_get_Weight(
851 OLEFontImpl
*this = impl_from_IFont(iface
);
852 TRACE("(%p)->(%p)\n", this, pweight
);
859 *pweight
= this->description
.sWeight
;
864 /************************************************************************
865 * OLEFontImpl_put_Weight (IFont)
867 static HRESULT WINAPI
OLEFontImpl_put_Weight(
871 OLEFontImpl
*this = impl_from_IFont(iface
);
872 TRACE("(%p)->(%d)\n", this, weight
);
874 this->description
.sWeight
= weight
;
876 OLEFont_SendNotify(this, DISPID_FONT_WEIGHT
);
880 /************************************************************************
881 * OLEFontImpl_get_Charset (IFont)
883 static HRESULT WINAPI
OLEFontImpl_get_Charset(
887 OLEFontImpl
*this = impl_from_IFont(iface
);
888 TRACE("(%p)->(%p)\n", this, pcharset
);
895 *pcharset
= this->description
.sCharset
;
900 /************************************************************************
901 * OLEFontImpl_put_Charset (IFont)
903 static HRESULT WINAPI
OLEFontImpl_put_Charset(
907 OLEFontImpl
*this = impl_from_IFont(iface
);
908 TRACE("(%p)->(%d)\n", this, charset
);
910 this->description
.sCharset
= charset
;
911 OLEFont_SendNotify(this, DISPID_FONT_CHARSET
);
916 /************************************************************************
917 * OLEFontImpl_get_hFont (IFont)
919 static HRESULT WINAPI
OLEFontImpl_get_hFont(
923 OLEFontImpl
*this = impl_from_IFont(iface
);
924 TRACE("(%p)->(%p)\n", this, phfont
);
930 *phfont
= this->gdiFont
;
931 TRACE("Returning %p\n", *phfont
);
935 /************************************************************************
936 * OLEFontImpl_Clone (IFont)
938 static HRESULT WINAPI
OLEFontImpl_Clone(
942 OLEFontImpl
*this = impl_from_IFont(iface
);
943 OLEFontImpl
* newObject
;
945 TRACE("(%p)->(%p)\n", this, ppfont
);
952 newObject
= malloc(sizeof(OLEFontImpl
));
954 return E_OUTOFMEMORY
;
957 /* allocate separate buffer */
958 newObject
->description
.lpstrName
= wcsdup(this->description
.lpstrName
);
960 /* Increment internal ref in hfont item list */
961 if(newObject
->gdiFont
) inc_int_ref(newObject
->gdiFont
);
963 InterlockedIncrement(&ifont_cnt
);
965 newObject
->pPropertyNotifyCP
= NULL
;
966 newObject
->pFontEventsCP
= NULL
;
967 CreateConnectionPoint((IUnknown
*)&newObject
->IFont_iface
, &IID_IPropertyNotifySink
,
968 &newObject
->pPropertyNotifyCP
);
969 CreateConnectionPoint((IUnknown
*)&newObject
->IFont_iface
, &IID_IFontEventsDisp
,
970 &newObject
->pFontEventsCP
);
972 if (!newObject
->pPropertyNotifyCP
|| !newObject
->pFontEventsCP
)
974 OLEFontImpl_Destroy(newObject
);
975 return E_OUTOFMEMORY
;
978 /* The cloned object starts with a reference count of 1 */
981 *ppfont
= &newObject
->IFont_iface
;
986 /************************************************************************
987 * OLEFontImpl_IsEqual (IFont)
989 static HRESULT WINAPI
OLEFontImpl_IsEqual(
993 OLEFontImpl
*left
= impl_from_IFont(iface
);
994 OLEFontImpl
*right
= impl_from_IFont(pFontOther
);
996 INT left_len
,right_len
;
998 if(pFontOther
== NULL
)
1000 else if (left
->description
.cySize
.s
.Lo
!= right
->description
.cySize
.s
.Lo
)
1002 else if (left
->description
.cySize
.s
.Hi
!= right
->description
.cySize
.s
.Hi
)
1004 else if (left
->description
.sWeight
!= right
->description
.sWeight
)
1006 else if (left
->description
.sCharset
!= right
->description
.sCharset
)
1008 else if (left
->description
.fItalic
!= right
->description
.fItalic
)
1010 else if (left
->description
.fUnderline
!= right
->description
.fUnderline
)
1012 else if (left
->description
.fStrikethrough
!= right
->description
.fStrikethrough
)
1015 /* Check from string */
1016 left_len
= lstrlenW(left
->description
.lpstrName
);
1017 right_len
= lstrlenW(right
->description
.lpstrName
);
1018 ret
= CompareStringW(0,0,left
->description
.lpstrName
, left_len
,
1019 right
->description
.lpstrName
, right_len
);
1020 if (ret
!= CSTR_EQUAL
)
1026 /************************************************************************
1027 * OLEFontImpl_SetRatio (IFont)
1029 static HRESULT WINAPI
OLEFontImpl_SetRatio(
1034 OLEFontImpl
*this = impl_from_IFont(iface
);
1036 TRACE("%p, %ld, %ld.\n", iface
, cyLogical
, cyHimetric
);
1038 if(cyLogical
== 0 || cyHimetric
== 0)
1041 /* cyLogical and cyHimetric both set to 1 is a special case that
1042 does not change the scaling but also does not fail */
1043 if(cyLogical
== 1 && cyHimetric
== 1)
1046 this->cyLogical
= cyLogical
;
1047 this->cyHimetric
= cyHimetric
;
1053 /************************************************************************
1054 * OLEFontImpl_QueryTextMetrics (IFont)
1056 static HRESULT WINAPI
OLEFontImpl_QueryTextMetrics(
1061 HFONT hOldFont
, hNewFont
;
1064 IFont_get_hFont(iface
, &hNewFont
);
1065 hOldFont
= SelectObject(hdcRef
, hNewFont
);
1066 GetTextMetricsW(hdcRef
, ptm
);
1067 SelectObject(hdcRef
, hOldFont
);
1068 ReleaseDC(0, hdcRef
);
1072 /************************************************************************
1073 * OLEFontImpl_AddRefHfont (IFont)
1075 static HRESULT WINAPI
OLEFontImpl_AddRefHfont(
1079 OLEFontImpl
*this = impl_from_IFont(iface
);
1081 TRACE("(%p)->(%p)\n", this, hfont
);
1083 if (!hfont
) return E_INVALIDARG
;
1085 return inc_ext_ref(hfont
);
1088 /************************************************************************
1089 * OLEFontImpl_ReleaseHfont (IFont)
1091 static HRESULT WINAPI
OLEFontImpl_ReleaseHfont(
1095 OLEFontImpl
*this = impl_from_IFont(iface
);
1097 TRACE("(%p)->(%p)\n", this, hfont
);
1099 if (!hfont
) return E_INVALIDARG
;
1101 return dec_ext_ref(hfont
);
1104 /************************************************************************
1105 * OLEFontImpl_SetHdc (IFont)
1107 static HRESULT WINAPI
OLEFontImpl_SetHdc(
1111 OLEFontImpl
*this = impl_from_IFont(iface
);
1112 FIXME("(%p)->(%p): Stub\n", this, hdc
);
1116 static const IFontVtbl OLEFontImpl_VTable
=
1118 OLEFontImpl_QueryInterface
,
1120 OLEFontImpl_Release
,
1121 OLEFontImpl_get_Name
,
1122 OLEFontImpl_put_Name
,
1123 OLEFontImpl_get_Size
,
1124 OLEFontImpl_put_Size
,
1125 OLEFontImpl_get_Bold
,
1126 OLEFontImpl_put_Bold
,
1127 OLEFontImpl_get_Italic
,
1128 OLEFontImpl_put_Italic
,
1129 OLEFontImpl_get_Underline
,
1130 OLEFontImpl_put_Underline
,
1131 OLEFontImpl_get_Strikethrough
,
1132 OLEFontImpl_put_Strikethrough
,
1133 OLEFontImpl_get_Weight
,
1134 OLEFontImpl_put_Weight
,
1135 OLEFontImpl_get_Charset
,
1136 OLEFontImpl_put_Charset
,
1137 OLEFontImpl_get_hFont
,
1139 OLEFontImpl_IsEqual
,
1140 OLEFontImpl_SetRatio
,
1141 OLEFontImpl_QueryTextMetrics
,
1142 OLEFontImpl_AddRefHfont
,
1143 OLEFontImpl_ReleaseHfont
,
1147 /************************************************************************
1148 * OLEFontImpl_IDispatch_QueryInterface (IUnknown)
1150 static HRESULT WINAPI
OLEFontImpl_IDispatch_QueryInterface(
1155 OLEFontImpl
*this = impl_from_IDispatch(iface
);
1156 return IFont_QueryInterface(&this->IFont_iface
, riid
, ppvoid
);
1159 /************************************************************************
1160 * OLEFontImpl_IDispatch_Release (IUnknown)
1162 static ULONG WINAPI
OLEFontImpl_IDispatch_Release(
1165 OLEFontImpl
*this = impl_from_IDispatch(iface
);
1166 return IFont_Release(&this->IFont_iface
);
1169 /************************************************************************
1170 * OLEFontImpl_IDispatch_AddRef (IUnknown)
1172 static ULONG WINAPI
OLEFontImpl_IDispatch_AddRef(
1175 OLEFontImpl
*this = impl_from_IDispatch(iface
);
1176 return IFont_AddRef(&this->IFont_iface
);
1179 /************************************************************************
1180 * OLEFontImpl_GetTypeInfoCount (IDispatch)
1182 static HRESULT WINAPI
OLEFontImpl_GetTypeInfoCount(
1184 unsigned int* pctinfo
)
1186 OLEFontImpl
*this = impl_from_IDispatch(iface
);
1187 TRACE("(%p)->(%p)\n", this, pctinfo
);
1193 /************************************************************************
1194 * OLEFontImpl_GetTypeInfo (IDispatch)
1196 static HRESULT WINAPI
OLEFontImpl_GetTypeInfo(
1200 ITypeInfo
** ppTInfo
)
1205 OLEFontImpl
*this = impl_from_IDispatch(iface
);
1206 TRACE("(%p, iTInfo=%d, lcid=%04x, %p)\n", this, iTInfo
, (int)lcid
, ppTInfo
);
1209 hres
= LoadTypeLib(L
"stdole2.tlb", &tl
);
1211 ERR("Could not load the stdole2.tlb?\n");
1214 hres
= ITypeLib_GetTypeInfoOfGuid(tl
, &IID_IFontDisp
, ppTInfo
);
1215 ITypeLib_Release(tl
);
1217 FIXME("Did not IDispatch typeinfo from typelib, hres %#lx.\n", hres
);
1222 /************************************************************************
1223 * OLEFontImpl_GetIDsOfNames (IDispatch)
1225 static HRESULT WINAPI
OLEFontImpl_GetIDsOfNames(
1228 LPOLESTR
* rgszNames
,
1236 OLEFontImpl
*this = impl_from_IDispatch(iface
);
1238 TRACE("(%p,%s,%p,cNames=%d,lcid=%04x,%p)\n", this, debugstr_guid(riid
),
1239 rgszNames
, cNames
, (int)lcid
, rgDispId
);
1241 if (cNames
== 0) return E_INVALIDARG
;
1243 hres
= IDispatch_GetTypeInfo(iface
, 0, lcid
, &pTInfo
);
1246 ERR("GetTypeInfo failed.\n");
1250 /* convert names to DISPIDs */
1251 hres
= DispGetIDsOfNames (pTInfo
, rgszNames
, cNames
, rgDispId
);
1252 ITypeInfo_Release(pTInfo
);
1257 /************************************************************************
1258 * OLEFontImpl_Invoke (IDispatch)
1261 static HRESULT WINAPI
OLEFontImpl_Invoke(
1263 DISPID dispIdMember
,
1267 DISPPARAMS
* pDispParams
,
1268 VARIANT
* pVarResult
,
1269 EXCEPINFO
* pExepInfo
,
1272 OLEFontImpl
*this = impl_from_IDispatch(iface
);
1275 TRACE("%p, %ld, %s, %#lx, %#x, %p, %p, %p, %p.\n", iface
, dispIdMember
,
1276 debugstr_guid(riid
), lcid
, wFlags
, pDispParams
, pVarResult
, pExepInfo
,
1279 /* validate parameters */
1281 if (!IsEqualIID(riid
, &IID_NULL
))
1283 ERR("riid was %s instead of IID_NULL\n", debugstr_guid(riid
));
1284 return DISP_E_UNKNOWNINTERFACE
;
1287 if (wFlags
& DISPATCH_PROPERTYGET
)
1291 ERR("null pVarResult not allowed when DISPATCH_PROPERTYGET specified\n");
1292 return DISP_E_PARAMNOTOPTIONAL
;
1295 else if (wFlags
& DISPATCH_PROPERTYPUT
)
1299 ERR("null pDispParams not allowed when DISPATCH_PROPERTYPUT specified\n");
1300 return DISP_E_PARAMNOTOPTIONAL
;
1302 if (pDispParams
->cArgs
!= 1)
1304 ERR("param count for DISPATCH_PROPERTYPUT was %d instead of 1\n", pDispParams
->cArgs
);
1305 return DISP_E_BADPARAMCOUNT
;
1310 ERR("one of DISPATCH_PROPERTYGET or DISPATCH_PROPERTYPUT must be specified\n");
1311 return DISP_E_MEMBERNOTFOUND
;
1314 switch (dispIdMember
) {
1315 case DISPID_FONT_NAME
:
1316 if (wFlags
& DISPATCH_PROPERTYGET
) {
1317 V_VT(pVarResult
) = VT_BSTR
;
1318 return IFont_get_Name(&this->IFont_iface
, &V_BSTR(pVarResult
));
1322 VariantInit(&vararg
);
1323 hr
= VariantChangeTypeEx(&vararg
, &pDispParams
->rgvarg
[0], lcid
, 0, VT_BSTR
);
1327 hr
= IFont_put_Name(&this->IFont_iface
, V_BSTR(&vararg
));
1329 VariantClear(&vararg
);
1333 case DISPID_FONT_BOLD
:
1334 if (wFlags
& DISPATCH_PROPERTYGET
) {
1336 hr
= IFont_get_Bold(&this->IFont_iface
, &value
);
1337 V_VT(pVarResult
) = VT_BOOL
;
1338 V_BOOL(pVarResult
) = value
? VARIANT_TRUE
: VARIANT_FALSE
;
1343 VariantInit(&vararg
);
1344 hr
= VariantChangeTypeEx(&vararg
, &pDispParams
->rgvarg
[0], lcid
, 0, VT_BOOL
);
1348 hr
= IFont_put_Bold(&this->IFont_iface
, V_BOOL(&vararg
));
1350 VariantClear(&vararg
);
1354 case DISPID_FONT_ITALIC
:
1355 if (wFlags
& DISPATCH_PROPERTYGET
) {
1357 hr
= IFont_get_Italic(&this->IFont_iface
, &value
);
1358 V_VT(pVarResult
) = VT_BOOL
;
1359 V_BOOL(pVarResult
) = value
? VARIANT_TRUE
: VARIANT_FALSE
;
1364 VariantInit(&vararg
);
1365 hr
= VariantChangeTypeEx(&vararg
, &pDispParams
->rgvarg
[0], lcid
, 0, VT_BOOL
);
1369 hr
= IFont_put_Italic(&this->IFont_iface
, V_BOOL(&vararg
));
1371 VariantClear(&vararg
);
1375 case DISPID_FONT_UNDER
:
1376 if (wFlags
& DISPATCH_PROPERTYGET
) {
1378 hr
= IFont_get_Underline(&this->IFont_iface
, &value
);
1379 V_VT(pVarResult
) = VT_BOOL
;
1380 V_BOOL(pVarResult
) = value
? VARIANT_TRUE
: VARIANT_FALSE
;
1385 VariantInit(&vararg
);
1386 hr
= VariantChangeTypeEx(&vararg
, &pDispParams
->rgvarg
[0], lcid
, 0, VT_BOOL
);
1390 hr
= IFont_put_Underline(&this->IFont_iface
, V_BOOL(&vararg
));
1392 VariantClear(&vararg
);
1396 case DISPID_FONT_STRIKE
:
1397 if (wFlags
& DISPATCH_PROPERTYGET
) {
1399 hr
= IFont_get_Strikethrough(&this->IFont_iface
, &value
);
1400 V_VT(pVarResult
) = VT_BOOL
;
1401 V_BOOL(pVarResult
) = value
? VARIANT_TRUE
: VARIANT_FALSE
;
1406 VariantInit(&vararg
);
1407 hr
= VariantChangeTypeEx(&vararg
, &pDispParams
->rgvarg
[0], lcid
, 0, VT_BOOL
);
1411 hr
= IFont_put_Strikethrough(&this->IFont_iface
, V_BOOL(&vararg
));
1413 VariantClear(&vararg
);
1417 case DISPID_FONT_SIZE
:
1418 if (wFlags
& DISPATCH_PROPERTYGET
) {
1419 V_VT(pVarResult
) = VT_CY
;
1420 return IFont_get_Size(&this->IFont_iface
, &V_CY(pVarResult
));
1424 VariantInit(&vararg
);
1425 hr
= VariantChangeTypeEx(&vararg
, &pDispParams
->rgvarg
[0], lcid
, 0, VT_CY
);
1429 hr
= IFont_put_Size(&this->IFont_iface
, V_CY(&vararg
));
1431 VariantClear(&vararg
);
1435 case DISPID_FONT_WEIGHT
:
1436 if (wFlags
& DISPATCH_PROPERTYGET
) {
1437 V_VT(pVarResult
) = VT_I2
;
1438 return IFont_get_Weight(&this->IFont_iface
, &V_I2(pVarResult
));
1442 VariantInit(&vararg
);
1443 hr
= VariantChangeTypeEx(&vararg
, &pDispParams
->rgvarg
[0], lcid
, 0, VT_I2
);
1447 hr
= IFont_put_Weight(&this->IFont_iface
, V_I2(&vararg
));
1449 VariantClear(&vararg
);
1453 case DISPID_FONT_CHARSET
:
1454 if (wFlags
& DISPATCH_PROPERTYGET
) {
1455 V_VT(pVarResult
) = VT_I2
;
1456 return OLEFontImpl_get_Charset(&this->IFont_iface
, &V_I2(pVarResult
));
1460 VariantInit(&vararg
);
1461 hr
= VariantChangeTypeEx(&vararg
, &pDispParams
->rgvarg
[0], lcid
, 0, VT_I2
);
1465 hr
= IFont_put_Charset(&this->IFont_iface
, V_I2(&vararg
));
1467 VariantClear(&vararg
);
1472 ERR("member not found for dispid %#lx.\n", dispIdMember
);
1473 return DISP_E_MEMBERNOTFOUND
;
1477 static const IDispatchVtbl OLEFontImpl_IDispatch_VTable
=
1479 OLEFontImpl_IDispatch_QueryInterface
,
1480 OLEFontImpl_IDispatch_AddRef
,
1481 OLEFontImpl_IDispatch_Release
,
1482 OLEFontImpl_GetTypeInfoCount
,
1483 OLEFontImpl_GetTypeInfo
,
1484 OLEFontImpl_GetIDsOfNames
,
1488 /************************************************************************
1489 * OLEFontImpl_IPersistStream_QueryInterface (IUnknown)
1491 static HRESULT WINAPI
OLEFontImpl_IPersistStream_QueryInterface(
1492 IPersistStream
* iface
,
1496 OLEFontImpl
*this = impl_from_IPersistStream(iface
);
1498 return IFont_QueryInterface(&this->IFont_iface
, riid
, ppvoid
);
1501 /************************************************************************
1502 * OLEFontImpl_IPersistStream_Release (IUnknown)
1504 static ULONG WINAPI
OLEFontImpl_IPersistStream_Release(
1505 IPersistStream
* iface
)
1507 OLEFontImpl
*this = impl_from_IPersistStream(iface
);
1509 return IFont_Release(&this->IFont_iface
);
1512 /************************************************************************
1513 * OLEFontImpl_IPersistStream_AddRef (IUnknown)
1515 static ULONG WINAPI
OLEFontImpl_IPersistStream_AddRef(
1516 IPersistStream
* iface
)
1518 OLEFontImpl
*this = impl_from_IPersistStream(iface
);
1520 return IFont_AddRef(&this->IFont_iface
);
1523 /************************************************************************
1524 * OLEFontImpl_GetClassID (IPersistStream)
1526 static HRESULT WINAPI
OLEFontImpl_GetClassID(
1527 IPersistStream
* iface
,
1530 TRACE("(%p,%p)\n",iface
,pClassID
);
1534 *pClassID
= CLSID_StdFont
;
1539 /************************************************************************
1540 * OLEFontImpl_IsDirty (IPersistStream)
1542 * See Windows documentation for more details on IPersistStream methods.
1544 static HRESULT WINAPI
OLEFontImpl_IsDirty(
1545 IPersistStream
* iface
)
1547 TRACE("(%p)\n",iface
);
1551 /************************************************************************
1552 * OLEFontImpl_Load (IPersistStream)
1554 * See Windows documentation for more details on IPersistStream methods.
1556 * This is the format of the standard font serialization as far as I
1559 * Offset Type Value Comment
1560 * 0x0000 Byte Unknown Probably a version number, contains 0x01
1561 * 0x0001 Short Charset Charset value from the FONTDESC structure
1562 * 0x0003 Byte Attributes Flags defined as follows:
1564 * 00000100 - Underline
1565 * 00001000 - Strikethrough
1566 * 0x0004 Short Weight Weight value from FONTDESC structure
1567 * 0x0006 DWORD size "Low" portion of the cySize member of the FONTDESC
1569 * 0x000A Byte name length Length of the font name string (no null character)
1570 * 0x000B String name Name of the font (ASCII, no nul character)
1572 static HRESULT WINAPI
OLEFontImpl_Load(
1573 IPersistStream
* iface
,
1574 IStream
* pLoadStream
)
1576 OLEFontImpl
*this = impl_from_IPersistStream(iface
);
1577 BYTE version
, attributes
, string_size
;
1578 char readBuffer
[0x100];
1583 IStream_Read(pLoadStream
, &version
, sizeof(BYTE
), &cbRead
);
1584 if ((cbRead
!= sizeof(BYTE
)) || (version
!= 0x01)) return E_FAIL
;
1587 IStream_Read(pLoadStream
, &this->description
.sCharset
, sizeof(WORD
), &cbRead
);
1588 if (cbRead
!= sizeof(WORD
)) return E_FAIL
;
1591 IStream_Read(pLoadStream
, &attributes
, sizeof(BYTE
), &cbRead
);
1592 if (cbRead
!= sizeof(BYTE
)) return E_FAIL
;
1594 this->description
.fItalic
= (attributes
& FONTPERSIST_ITALIC
) != 0;
1595 this->description
.fStrikethrough
= (attributes
& FONTPERSIST_STRIKETHROUGH
) != 0;
1596 this->description
.fUnderline
= (attributes
& FONTPERSIST_UNDERLINE
) != 0;
1599 IStream_Read(pLoadStream
, &this->description
.sWeight
, sizeof(WORD
), &cbRead
);
1600 if (cbRead
!= sizeof(WORD
)) return E_FAIL
;
1603 IStream_Read(pLoadStream
, &this->description
.cySize
.s
.Lo
, sizeof(DWORD
), &cbRead
);
1604 if (cbRead
!= sizeof(DWORD
)) return E_FAIL
;
1606 this->description
.cySize
.s
.Hi
= 0;
1609 IStream_Read(pLoadStream
, &string_size
, sizeof(BYTE
), &cbRead
);
1610 if (cbRead
!= sizeof(BYTE
)) return E_FAIL
;
1612 IStream_Read(pLoadStream
, readBuffer
, string_size
, &cbRead
);
1613 if (cbRead
!= string_size
) return E_FAIL
;
1615 free(this->description
.lpstrName
);
1617 len
= MultiByteToWideChar( CP_ACP
, 0, readBuffer
, string_size
, NULL
, 0 );
1618 this->description
.lpstrName
= malloc((len
+ 1) * sizeof(WCHAR
));
1619 MultiByteToWideChar( CP_ACP
, 0, readBuffer
, string_size
, this->description
.lpstrName
, len
);
1620 this->description
.lpstrName
[len
] = 0;
1622 /* Ensure use of this font causes a new one to be created */
1623 dec_int_ref(this->gdiFont
);
1630 /************************************************************************
1631 * OLEFontImpl_Save (IPersistStream)
1633 static HRESULT WINAPI
OLEFontImpl_Save(
1634 IPersistStream
* iface
,
1635 IStream
* pOutStream
,
1638 OLEFontImpl
*this = impl_from_IPersistStream(iface
);
1639 BYTE attributes
, string_size
;
1640 const BYTE version
= 0x01;
1641 char* writeBuffer
= NULL
;
1644 TRACE("(%p)->(%p %d)\n", this, pOutStream
, fClearDirty
);
1647 IStream_Write(pOutStream
, &version
, sizeof(BYTE
), &written
);
1648 if (written
!= sizeof(BYTE
)) return E_FAIL
;
1651 IStream_Write(pOutStream
, &this->description
.sCharset
, sizeof(WORD
), &written
);
1652 if (written
!= sizeof(WORD
)) return E_FAIL
;
1657 if (this->description
.fItalic
)
1658 attributes
|= FONTPERSIST_ITALIC
;
1660 if (this->description
.fStrikethrough
)
1661 attributes
|= FONTPERSIST_STRIKETHROUGH
;
1663 if (this->description
.fUnderline
)
1664 attributes
|= FONTPERSIST_UNDERLINE
;
1666 IStream_Write(pOutStream
, &attributes
, sizeof(BYTE
), &written
);
1667 if (written
!= sizeof(BYTE
)) return E_FAIL
;
1670 IStream_Write(pOutStream
, &this->description
.sWeight
, sizeof(WORD
), &written
);
1671 if (written
!= sizeof(WORD
)) return E_FAIL
;
1674 IStream_Write(pOutStream
, &this->description
.cySize
.s
.Lo
, sizeof(DWORD
), &written
);
1675 if (written
!= sizeof(DWORD
)) return E_FAIL
;
1678 if (this->description
.lpstrName
)
1679 string_size
= WideCharToMultiByte( CP_ACP
, 0, this->description
.lpstrName
,
1680 lstrlenW(this->description
.lpstrName
), NULL
, 0, NULL
, NULL
);
1684 IStream_Write(pOutStream
, &string_size
, sizeof(BYTE
), &written
);
1685 if (written
!= sizeof(BYTE
)) return E_FAIL
;
1689 if (!(writeBuffer
= malloc(string_size
))) return E_OUTOFMEMORY
;
1690 WideCharToMultiByte( CP_ACP
, 0, this->description
.lpstrName
,
1691 lstrlenW(this->description
.lpstrName
),
1692 writeBuffer
, string_size
, NULL
, NULL
);
1694 IStream_Write(pOutStream
, writeBuffer
, string_size
, &written
);
1697 if (written
!= string_size
) return E_FAIL
;
1703 /************************************************************************
1704 * OLEFontImpl_GetSizeMax (IPersistStream)
1706 static HRESULT WINAPI
OLEFontImpl_GetSizeMax(
1707 IPersistStream
* iface
,
1708 ULARGE_INTEGER
* pcbSize
)
1710 OLEFontImpl
*this = impl_from_IPersistStream(iface
);
1715 pcbSize
->u
.HighPart
= 0;
1716 pcbSize
->u
.LowPart
= 0;
1718 pcbSize
->u
.LowPart
+= sizeof(BYTE
); /* Version */
1719 pcbSize
->u
.LowPart
+= sizeof(WORD
); /* Lang code */
1720 pcbSize
->u
.LowPart
+= sizeof(BYTE
); /* Flags */
1721 pcbSize
->u
.LowPart
+= sizeof(WORD
); /* Weight */
1722 pcbSize
->u
.LowPart
+= sizeof(DWORD
); /* Size */
1723 pcbSize
->u
.LowPart
+= sizeof(BYTE
); /* StrLength */
1725 if (this->description
.lpstrName
!=0)
1726 pcbSize
->u
.LowPart
+= WideCharToMultiByte( CP_ACP
, 0, this->description
.lpstrName
,
1727 lstrlenW(this->description
.lpstrName
),
1728 NULL
, 0, NULL
, NULL
);
1733 static const IPersistStreamVtbl OLEFontImpl_IPersistStream_VTable
=
1735 OLEFontImpl_IPersistStream_QueryInterface
,
1736 OLEFontImpl_IPersistStream_AddRef
,
1737 OLEFontImpl_IPersistStream_Release
,
1738 OLEFontImpl_GetClassID
,
1739 OLEFontImpl_IsDirty
,
1742 OLEFontImpl_GetSizeMax
1745 /************************************************************************
1746 * OLEFontImpl_IConnectionPointContainer_QueryInterface (IUnknown)
1748 static HRESULT WINAPI
OLEFontImpl_IConnectionPointContainer_QueryInterface(
1749 IConnectionPointContainer
* iface
,
1753 OLEFontImpl
*this = impl_from_IConnectionPointContainer(iface
);
1755 return IFont_QueryInterface(&this->IFont_iface
, riid
, ppvoid
);
1758 /************************************************************************
1759 * OLEFontImpl_IConnectionPointContainer_Release (IUnknown)
1761 static ULONG WINAPI
OLEFontImpl_IConnectionPointContainer_Release(
1762 IConnectionPointContainer
* iface
)
1764 OLEFontImpl
*this = impl_from_IConnectionPointContainer(iface
);
1766 return IFont_Release(&this->IFont_iface
);
1769 /************************************************************************
1770 * OLEFontImpl_IConnectionPointContainer_AddRef (IUnknown)
1772 static ULONG WINAPI
OLEFontImpl_IConnectionPointContainer_AddRef(
1773 IConnectionPointContainer
* iface
)
1775 OLEFontImpl
*this = impl_from_IConnectionPointContainer(iface
);
1777 return IFont_AddRef(&this->IFont_iface
);
1780 /************************************************************************
1781 * OLEFontImpl_EnumConnectionPoints (IConnectionPointContainer)
1783 static HRESULT WINAPI
OLEFontImpl_EnumConnectionPoints(
1784 IConnectionPointContainer
* iface
,
1785 IEnumConnectionPoints
**ppEnum
)
1787 OLEFontImpl
*this = impl_from_IConnectionPointContainer(iface
);
1789 FIXME("(%p)->(%p): stub\n", this, ppEnum
);
1793 /************************************************************************
1794 * OLEFontImpl_FindConnectionPoint (IConnectionPointContainer)
1796 static HRESULT WINAPI
OLEFontImpl_FindConnectionPoint(
1797 IConnectionPointContainer
* iface
,
1799 IConnectionPoint
**ppCp
)
1801 OLEFontImpl
*this = impl_from_IConnectionPointContainer(iface
);
1802 TRACE("(%p)->(%s, %p)\n", this, debugstr_guid(riid
), ppCp
);
1804 if(IsEqualIID(riid
, &IID_IPropertyNotifySink
)) {
1805 return IConnectionPoint_QueryInterface(this->pPropertyNotifyCP
, &IID_IConnectionPoint
,
1807 } else if(IsEqualIID(riid
, &IID_IFontEventsDisp
)) {
1808 return IConnectionPoint_QueryInterface(this->pFontEventsCP
, &IID_IConnectionPoint
,
1811 FIXME("no connection point for %s\n", debugstr_guid(riid
));
1812 return CONNECT_E_NOCONNECTION
;
1816 static const IConnectionPointContainerVtbl
1817 OLEFontImpl_IConnectionPointContainer_VTable
=
1819 OLEFontImpl_IConnectionPointContainer_QueryInterface
,
1820 OLEFontImpl_IConnectionPointContainer_AddRef
,
1821 OLEFontImpl_IConnectionPointContainer_Release
,
1822 OLEFontImpl_EnumConnectionPoints
,
1823 OLEFontImpl_FindConnectionPoint
1826 /************************************************************************
1827 * OLEFontImpl implementation of IPersistPropertyBag.
1829 static HRESULT WINAPI
OLEFontImpl_IPersistPropertyBag_QueryInterface(
1830 IPersistPropertyBag
*iface
, REFIID riid
, LPVOID
*ppvObj
1832 OLEFontImpl
*this = impl_from_IPersistPropertyBag(iface
);
1833 return IFont_QueryInterface(&this->IFont_iface
,riid
,ppvObj
);
1836 static ULONG WINAPI
OLEFontImpl_IPersistPropertyBag_AddRef(
1837 IPersistPropertyBag
*iface
1839 OLEFontImpl
*this = impl_from_IPersistPropertyBag(iface
);
1840 return IFont_AddRef(&this->IFont_iface
);
1843 static ULONG WINAPI
OLEFontImpl_IPersistPropertyBag_Release(
1844 IPersistPropertyBag
*iface
1846 OLEFontImpl
*this = impl_from_IPersistPropertyBag(iface
);
1847 return IFont_Release(&this->IFont_iface
);
1850 static HRESULT WINAPI
OLEFontImpl_IPersistPropertyBag_GetClassID(
1851 IPersistPropertyBag
*iface
, CLSID
*classid
1853 FIXME("(%p,%p), stub!\n", iface
, classid
);
1857 static HRESULT WINAPI
OLEFontImpl_IPersistPropertyBag_InitNew(
1858 IPersistPropertyBag
*iface
1860 FIXME("(%p), stub!\n", iface
);
1864 static HRESULT WINAPI
OLEFontImpl_IPersistPropertyBag_Load(
1865 IPersistPropertyBag
*iface
, IPropertyBag
* pPropBag
, IErrorLog
* pErrorLog
1867 /* (from Visual Basic 6 property bag)
1868 Name = "MS Sans Serif"
1872 Underline = 0 'False
1874 Strikethrough = 0 'False
1876 OLEFontImpl
*this = impl_from_IPersistPropertyBag(iface
);
1880 VariantInit(&value
);
1882 iRes
= IPropertyBag_Read(pPropBag
, L
"Name", &value
, pErrorLog
);
1885 iRes
= VariantChangeType(&value
, &value
, 0, VT_BSTR
);
1887 iRes
= IFont_put_Name(&this->IFont_iface
, V_BSTR(&value
));
1889 else if (iRes
== E_INVALIDARG
)
1892 VariantClear(&value
);
1895 iRes
= IPropertyBag_Read(pPropBag
, L
"Size", &value
, pErrorLog
);
1898 iRes
= VariantChangeType(&value
, &value
, 0, VT_CY
);
1900 iRes
= IFont_put_Size(&this->IFont_iface
, V_CY(&value
));
1902 else if (iRes
== E_INVALIDARG
)
1905 VariantClear(&value
);
1909 iRes
= IPropertyBag_Read(pPropBag
, L
"Charset", &value
, pErrorLog
);
1912 iRes
= VariantChangeType(&value
, &value
, 0, VT_I2
);
1914 iRes
= IFont_put_Charset(&this->IFont_iface
, V_I2(&value
));
1916 else if (iRes
== E_INVALIDARG
)
1919 VariantClear(&value
);
1923 iRes
= IPropertyBag_Read(pPropBag
, L
"Weight", &value
, pErrorLog
);
1926 iRes
= VariantChangeType(&value
, &value
, 0, VT_I2
);
1928 iRes
= IFont_put_Weight(&this->IFont_iface
, V_I2(&value
));
1930 else if (iRes
== E_INVALIDARG
)
1933 VariantClear(&value
);
1937 iRes
= IPropertyBag_Read(pPropBag
, L
"Underline", &value
, pErrorLog
);
1940 iRes
= VariantChangeType(&value
, &value
, 0, VT_BOOL
);
1942 iRes
= IFont_put_Underline(&this->IFont_iface
, V_BOOL(&value
));
1944 else if (iRes
== E_INVALIDARG
)
1947 VariantClear(&value
);
1951 iRes
= IPropertyBag_Read(pPropBag
, L
"Italic", &value
, pErrorLog
);
1954 iRes
= VariantChangeType(&value
, &value
, 0, VT_BOOL
);
1956 iRes
= IFont_put_Italic(&this->IFont_iface
, V_BOOL(&value
));
1958 else if (iRes
== E_INVALIDARG
)
1961 VariantClear(&value
);
1965 iRes
= IPropertyBag_Read(pPropBag
, L
"Strikethrough", &value
, pErrorLog
);
1968 iRes
= VariantChangeType(&value
, &value
, 0, VT_BOOL
);
1970 IFont_put_Strikethrough(&this->IFont_iface
, V_BOOL(&value
));
1972 else if (iRes
== E_INVALIDARG
)
1975 VariantClear(&value
);
1979 WARN("-- %#lx.\n", iRes
);
1983 static HRESULT WINAPI
OLEFontImpl_IPersistPropertyBag_Save(
1984 IPersistPropertyBag
*iface
, IPropertyBag
* pPropBag
, BOOL fClearDirty
,
1985 BOOL fSaveAllProperties
1987 FIXME("(%p,%p,%d,%d), stub!\n", iface
, pPropBag
, fClearDirty
, fSaveAllProperties
);
1991 static const IPersistPropertyBagVtbl OLEFontImpl_IPersistPropertyBag_VTable
=
1993 OLEFontImpl_IPersistPropertyBag_QueryInterface
,
1994 OLEFontImpl_IPersistPropertyBag_AddRef
,
1995 OLEFontImpl_IPersistPropertyBag_Release
,
1997 OLEFontImpl_IPersistPropertyBag_GetClassID
,
1998 OLEFontImpl_IPersistPropertyBag_InitNew
,
1999 OLEFontImpl_IPersistPropertyBag_Load
,
2000 OLEFontImpl_IPersistPropertyBag_Save
2003 /************************************************************************
2004 * OLEFontImpl_Construct
2006 * This method will construct a new instance of the OLEFontImpl
2009 * The caller of this method must release the object when it's
2012 static OLEFontImpl
* OLEFontImpl_Construct(const FONTDESC
*fontDesc
)
2014 OLEFontImpl
* newObject
;
2016 newObject
= malloc(sizeof(OLEFontImpl
));
2021 newObject
->IFont_iface
.lpVtbl
= &OLEFontImpl_VTable
;
2022 newObject
->IDispatch_iface
.lpVtbl
= &OLEFontImpl_IDispatch_VTable
;
2023 newObject
->IPersistStream_iface
.lpVtbl
= &OLEFontImpl_IPersistStream_VTable
;
2024 newObject
->IConnectionPointContainer_iface
.lpVtbl
= &OLEFontImpl_IConnectionPointContainer_VTable
;
2025 newObject
->IPersistPropertyBag_iface
.lpVtbl
= &OLEFontImpl_IPersistPropertyBag_VTable
;
2029 newObject
->description
.cbSizeofstruct
= sizeof(FONTDESC
);
2030 newObject
->description
.lpstrName
= wcsdup(fontDesc
->lpstrName
);
2031 newObject
->description
.cySize
= fontDesc
->cySize
;
2032 newObject
->description
.sWeight
= fontDesc
->sWeight
;
2033 newObject
->description
.sCharset
= fontDesc
->sCharset
;
2034 newObject
->description
.fItalic
= fontDesc
->fItalic
;
2035 newObject
->description
.fUnderline
= fontDesc
->fUnderline
;
2036 newObject
->description
.fStrikethrough
= fontDesc
->fStrikethrough
;
2038 newObject
->gdiFont
= 0;
2039 newObject
->dirty
= TRUE
;
2040 newObject
->cyLogical
= GetDeviceCaps(get_dc(), LOGPIXELSY
);
2041 newObject
->cyHimetric
= 2540L;
2042 newObject
->pPropertyNotifyCP
= NULL
;
2043 newObject
->pFontEventsCP
= NULL
;
2045 CreateConnectionPoint((IUnknown
*)&newObject
->IFont_iface
, &IID_IPropertyNotifySink
, &newObject
->pPropertyNotifyCP
);
2046 CreateConnectionPoint((IUnknown
*)&newObject
->IFont_iface
, &IID_IFontEventsDisp
, &newObject
->pFontEventsCP
);
2048 if (!newObject
->pPropertyNotifyCP
|| !newObject
->pFontEventsCP
)
2050 OLEFontImpl_Destroy(newObject
);
2054 InterlockedIncrement(&ifont_cnt
);
2056 TRACE("returning %p\n", newObject
);
2060 /************************************************************************
2061 * OLEFontImpl_Destroy
2063 * This method is called by the Release method when the reference
2064 * count goes down to 0. It will free all resources used by
2067 static void OLEFontImpl_Destroy(OLEFontImpl
* fontDesc
)
2069 TRACE("(%p)\n", fontDesc
);
2071 free(fontDesc
->description
.lpstrName
);
2073 if (fontDesc
->pPropertyNotifyCP
)
2074 IConnectionPoint_Release(fontDesc
->pPropertyNotifyCP
);
2075 if (fontDesc
->pFontEventsCP
)
2076 IConnectionPoint_Release(fontDesc
->pFontEventsCP
);
2081 /*******************************************************************************
2082 * StdFont ClassFactory
2086 /* IUnknown fields */
2087 IClassFactory IClassFactory_iface
;
2089 } IClassFactoryImpl
;
2091 static inline IClassFactoryImpl
*impl_from_IClassFactory(IClassFactory
*iface
)
2093 return CONTAINING_RECORD(iface
, IClassFactoryImpl
, IClassFactory_iface
);
2096 static HRESULT WINAPI
SFCF_QueryInterface(IClassFactory
*iface
, REFIID riid
, void **obj
)
2098 IClassFactoryImpl
*This
= impl_from_IClassFactory(iface
);
2100 TRACE("(%p)->(%s, %p)\n", This
, debugstr_guid(riid
), obj
);
2104 if (IsEqualIID(&IID_IClassFactory
, riid
) || IsEqualIID(&IID_IUnknown
, riid
))
2107 IClassFactory_AddRef(iface
);
2111 return E_NOINTERFACE
;
2115 SFCF_AddRef(LPCLASSFACTORY iface
) {
2116 IClassFactoryImpl
*This
= impl_from_IClassFactory(iface
);
2117 return InterlockedIncrement(&This
->ref
);
2120 static ULONG WINAPI
SFCF_Release(LPCLASSFACTORY iface
) {
2121 IClassFactoryImpl
*This
= impl_from_IClassFactory(iface
);
2122 /* static class, won't be freed */
2123 return InterlockedDecrement(&This
->ref
);
2126 static HRESULT WINAPI
SFCF_CreateInstance(
2127 LPCLASSFACTORY iface
,LPUNKNOWN pOuter
,REFIID riid
,LPVOID
*ppobj
2129 return OleCreateFontIndirect(NULL
,riid
,ppobj
);
2133 static HRESULT WINAPI
SFCF_LockServer(LPCLASSFACTORY iface
,BOOL dolock
) {
2134 IClassFactoryImpl
*This
= impl_from_IClassFactory(iface
);
2135 FIXME("(%p)->(%d),stub!\n",This
,dolock
);
2139 static const IClassFactoryVtbl SFCF_Vtbl
= {
2140 SFCF_QueryInterface
,
2143 SFCF_CreateInstance
,
2146 static IClassFactoryImpl STDFONT_CF
= {{&SFCF_Vtbl
}, 1 };
2148 void _get_STDFONT_CF(LPVOID
*ppv
) { *ppv
= &STDFONT_CF
; }