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
;
258 IPersistStreamInit IPersistStreamInit_iface
;
260 * Reference count for that instance of the class.
265 * This structure contains the description of the class.
267 FONTDESC description
;
270 * Contain the font associated with this object.
281 * Stash realized height (pixels) from TEXTMETRIC - used in get_Size()
285 IConnectionPoint
*pPropertyNotifyCP
;
286 IConnectionPoint
*pFontEventsCP
;
289 static inline OLEFontImpl
*impl_from_IFont(IFont
*iface
)
291 return CONTAINING_RECORD(iface
, OLEFontImpl
, IFont_iface
);
294 static inline OLEFontImpl
*impl_from_IDispatch( IDispatch
*iface
)
296 return CONTAINING_RECORD(iface
, OLEFontImpl
, IDispatch_iface
);
299 static inline OLEFontImpl
*impl_from_IPersistStream( IPersistStream
*iface
)
301 return CONTAINING_RECORD(iface
, OLEFontImpl
, IPersistStream_iface
);
304 static inline OLEFontImpl
*impl_from_IConnectionPointContainer( IConnectionPointContainer
*iface
)
306 return CONTAINING_RECORD(iface
, OLEFontImpl
, IConnectionPointContainer_iface
);
309 static inline OLEFontImpl
*impl_from_IPersistPropertyBag( IPersistPropertyBag
*iface
)
311 return CONTAINING_RECORD(iface
, OLEFontImpl
, IPersistPropertyBag_iface
);
314 static inline OLEFontImpl
*impl_from_IPersistStreamInit( IPersistStreamInit
*iface
)
316 return CONTAINING_RECORD(iface
, OLEFontImpl
, IPersistStreamInit_iface
);
320 /***********************************************************************
321 * Prototypes for the implementation functions for the IFont
324 static OLEFontImpl
* OLEFontImpl_Construct(const FONTDESC
*fontDesc
);
325 static void OLEFontImpl_Destroy(OLEFontImpl
* fontDesc
);
326 static ULONG WINAPI
OLEFontImpl_AddRef(IFont
* iface
);
328 /******************************************************************************
329 * OleCreateFontIndirect [OLEAUT32.420]
331 HRESULT WINAPI
OleCreateFontIndirect(
332 LPFONTDESC lpFontDesc
,
336 OLEFontImpl
* newFont
;
340 TRACE("(%p, %s, %p)\n", lpFontDesc
, debugstr_guid(riid
), ppvObj
);
342 if (!ppvObj
) return E_POINTER
;
347 static WCHAR fname
[] = { 'S','y','s','t','e','m',0 };
349 fd
.cbSizeofstruct
= sizeof(fd
);
350 fd
.lpstrName
= fname
;
351 fd
.cySize
.s
.Lo
= 80000;
356 fd
.fUnderline
= FALSE
;
357 fd
.fStrikethrough
= FALSE
;
361 newFont
= OLEFontImpl_Construct(lpFontDesc
);
362 if (!newFont
) return E_OUTOFMEMORY
;
364 hr
= IFont_QueryInterface(&newFont
->IFont_iface
, riid
, ppvObj
);
365 IFont_Release(&newFont
->IFont_iface
);
371 /***********************************************************************
372 * Implementation of the OLEFontImpl class.
375 /***********************************************************************
376 * OLEFont_SendNotify (internal)
378 * Sends notification messages of changed properties to any interested
381 static void OLEFont_SendNotify(OLEFontImpl
* this, DISPID dispID
)
383 static const WCHAR wszName
[] = {'N','a','m','e',0};
384 static const WCHAR wszSize
[] = {'S','i','z','e',0};
385 static const WCHAR wszBold
[] = {'B','o','l','d',0};
386 static const WCHAR wszItalic
[] = {'I','t','a','l','i','c',0};
387 static const WCHAR wszUnder
[] = {'U','n','d','e','r','l','i','n','e',0};
388 static const WCHAR wszStrike
[] = {'S','t','r','i','k','e','t','h','r','o','u','g','h',0};
389 static const WCHAR wszWeight
[] = {'W','e','i','g','h','t',0};
390 static const WCHAR wszCharset
[] = {'C','h','a','r','s','e','t',0};
391 static const LPCWSTR dispid_mapping
[] =
404 IEnumConnections
*pEnum
;
410 hres
= IConnectionPoint_EnumConnections(this->pPropertyNotifyCP
, &pEnum
);
413 while(IEnumConnections_Next(pEnum
, 1, &CD
, NULL
) == S_OK
) {
414 IPropertyNotifySink
*sink
;
416 IUnknown_QueryInterface(CD
.pUnk
, &IID_IPropertyNotifySink
, (void**)&sink
);
417 IPropertyNotifySink_OnChanged(sink
, dispID
);
418 IPropertyNotifySink_Release(sink
);
419 IUnknown_Release(CD
.pUnk
);
421 IEnumConnections_Release(pEnum
);
424 hres
= IConnectionPoint_EnumConnections(this->pFontEventsCP
, &pEnum
);
427 DISPPARAMS dispparams
;
430 VariantInit(&vararg
);
431 V_VT(&vararg
) = VT_BSTR
;
432 V_BSTR(&vararg
) = SysAllocString(dispid_mapping
[dispID
]);
434 dispparams
.cArgs
= 1;
435 dispparams
.cNamedArgs
= 0;
436 dispparams
.rgdispidNamedArgs
= NULL
;
437 dispparams
.rgvarg
= &vararg
;
439 while(IEnumConnections_Next(pEnum
, 1, &CD
, NULL
) == S_OK
) {
440 IFontEventsDisp
*disp
;
442 IUnknown_QueryInterface(CD
.pUnk
, &IID_IFontEventsDisp
, (void**)&disp
);
443 IFontEventsDisp_Invoke(disp
, DISPID_FONT_CHANGED
, &IID_NULL
,
444 LOCALE_NEUTRAL
, INVOKE_FUNC
, &dispparams
, NULL
,
447 IFontEventsDisp_Release(disp
);
448 IUnknown_Release(CD
.pUnk
);
450 VariantClear(&vararg
);
451 IEnumConnections_Release(pEnum
);
455 /************************************************************************
456 * OLEFontImpl_QueryInterface (IUnknown)
458 * See Windows documentation for more details on IUnknown methods.
460 static HRESULT WINAPI
OLEFontImpl_QueryInterface(
465 OLEFontImpl
*this = impl_from_IFont(iface
);
467 TRACE("(%p)->(%s, %p)\n", this, debugstr_guid(riid
), ppvObject
);
471 if (IsEqualGUID(&IID_IUnknown
, riid
) ||
472 IsEqualGUID(&IID_IFont
, riid
))
476 else if (IsEqualGUID(&IID_IDispatch
, riid
) ||
477 IsEqualGUID(&IID_IFontDisp
, riid
))
479 *ppvObject
= &this->IDispatch_iface
;
481 else if (IsEqualGUID(&IID_IPersist
, riid
) ||
482 IsEqualGUID(&IID_IPersistStream
, riid
))
484 *ppvObject
= &this->IPersistStream_iface
;
486 else if (IsEqualGUID(&IID_IConnectionPointContainer
, riid
))
488 *ppvObject
= &this->IConnectionPointContainer_iface
;
490 else if (IsEqualGUID(&IID_IPersistPropertyBag
, riid
))
492 *ppvObject
= &this->IPersistPropertyBag_iface
;
494 else if (IsEqualGUID(&IID_IPersistStreamInit
, riid
))
496 *ppvObject
= &this->IPersistStreamInit_iface
;
501 FIXME("() : asking for unsupported interface %s\n", debugstr_guid(riid
));
502 return E_NOINTERFACE
;
510 /************************************************************************
511 * OLEFontImpl_AddRef (IUnknown)
513 static ULONG WINAPI
OLEFontImpl_AddRef(
516 OLEFontImpl
*this = impl_from_IFont(iface
);
517 TRACE("(%p)->(ref=%d)\n", this, this->ref
);
518 return InterlockedIncrement(&this->ref
);
521 /************************************************************************
522 * OLEFontImpl_Release (IUnknown)
524 static ULONG WINAPI
OLEFontImpl_Release(IFont
* iface
)
526 OLEFontImpl
*this = impl_from_IFont(iface
);
529 TRACE("(%p)->(ref=%d)\n", this, this->ref
);
531 ref
= InterlockedDecrement(&this->ref
);
535 ULONG fontlist_refs
= InterlockedDecrement(&ifont_cnt
);
537 /* Final IFont object so destroy font cache */
538 if (fontlist_refs
== 0)
540 HFONTItem
*item
, *cursor2
;
542 EnterCriticalSection(&OLEFontImpl_csHFONTLIST
);
543 LIST_FOR_EACH_ENTRY_SAFE(item
, cursor2
, &OLEFontImpl_hFontList
, HFONTItem
, entry
)
544 HFONTItem_Delete(item
);
545 LeaveCriticalSection(&OLEFontImpl_csHFONTLIST
);
550 dec_int_ref(this->gdiFont
);
552 OLEFontImpl_Destroy(this);
564 static int CALLBACK
font_enum_proc(const LOGFONTW
*elf
, const TEXTMETRICW
*ntm
, DWORD type
, LPARAM lp
)
566 enum_data
*data
= (enum_data
*)lp
;
568 if(elf
->lfCharSet
== data
->orig_cs
)
570 data
->avail_cs
= data
->orig_cs
;
573 if(data
->avail_cs
== -1) data
->avail_cs
= elf
->lfCharSet
;
577 static void realize_font(OLEFontImpl
*This
)
581 WCHAR text_face
[LF_FACESIZE
];
586 if (!This
->dirty
) return;
592 old_font
= SelectObject(hdc
, This
->gdiFont
);
593 GetTextFaceW(hdc
, ARRAY_SIZE(text_face
), text_face
);
594 SelectObject(hdc
, old_font
);
595 dec_int_ref(This
->gdiFont
);
599 memset(&logFont
, 0, sizeof(LOGFONTW
));
601 lstrcpynW(logFont
.lfFaceName
, This
->description
.lpstrName
, LF_FACESIZE
);
602 logFont
.lfCharSet
= This
->description
.sCharset
;
604 /* If the font name has been changed then enumerate all charsets
605 and pick one that'll result in the font specified being selected */
606 if(text_face
[0] && lstrcmpiW(text_face
, This
->description
.lpstrName
))
609 data
.orig_cs
= This
->description
.sCharset
;
611 logFont
.lfCharSet
= DEFAULT_CHARSET
;
612 EnumFontFamiliesExW(get_dc(), &logFont
, font_enum_proc
, (LPARAM
)&data
, 0);
613 if(data
.avail_cs
!= -1) logFont
.lfCharSet
= data
.avail_cs
;
617 * The height of the font returned by the get_Size property is the
618 * height of the font in points multiplied by 10000... Using some
619 * simple conversions and the ratio given by the application, it can
620 * be converted to a height in pixels.
622 * Standard ratio is 72 / 2540, or 18 / 635 in lowest terms.
623 * Ratio is applied here relative to the standard.
626 fontHeight
= MulDiv( This
->description
.cySize
.s
.Lo
, This
->cyLogical
*635, This
->cyHimetric
*18 );
628 logFont
.lfHeight
= ((fontHeight
%10000L)>5000L) ? (-fontHeight
/10000L) - 1 :
629 (-fontHeight
/10000L);
630 logFont
.lfItalic
= This
->description
.fItalic
;
631 logFont
.lfUnderline
= This
->description
.fUnderline
;
632 logFont
.lfStrikeOut
= This
->description
.fStrikethrough
;
633 logFont
.lfWeight
= This
->description
.sWeight
;
634 logFont
.lfOutPrecision
= OUT_CHARACTER_PRECIS
;
635 logFont
.lfClipPrecision
= CLIP_DEFAULT_PRECIS
;
636 logFont
.lfQuality
= DEFAULT_QUALITY
;
637 logFont
.lfPitchAndFamily
= DEFAULT_PITCH
;
639 This
->gdiFont
= CreateFontIndirectW(&logFont
);
642 add_hfontitem(This
->gdiFont
);
644 /* Fixup the name and charset properties so that they match the
646 old_font
= SelectObject(get_dc(), This
->gdiFont
);
647 GetTextFaceW(hdc
, ARRAY_SIZE(text_face
), text_face
);
648 if(lstrcmpiW(text_face
, This
->description
.lpstrName
))
650 HeapFree(GetProcessHeap(), 0, This
->description
.lpstrName
);
651 This
->description
.lpstrName
= strdupW(text_face
);
653 GetTextMetricsW(hdc
, &tm
);
654 This
->description
.sCharset
= tm
.tmCharSet
;
655 /* While we have it handy, stash the realized font height for use by get_Size() */
656 This
->nRealHeight
= tm
.tmHeight
- tm
.tmInternalLeading
; /* corresponds to LOGFONT lfHeight */
657 SelectObject(hdc
, old_font
);
660 /************************************************************************
661 * OLEFontImpl_get_Name (IFont)
663 * See Windows documentation for more details on IFont methods.
665 static HRESULT WINAPI
OLEFontImpl_get_Name(
669 OLEFontImpl
*this = impl_from_IFont(iface
);
670 TRACE("(%p)->(%p)\n", this, pname
);
677 if (this->description
.lpstrName
!=0)
678 *pname
= SysAllocString(this->description
.lpstrName
);
685 /************************************************************************
686 * OLEFontImpl_put_Name (IFont)
688 static HRESULT WINAPI
OLEFontImpl_put_Name(
692 OLEFontImpl
*This
= impl_from_IFont(iface
);
693 TRACE("(%p)->(%p)\n", This
, name
);
696 return CTL_E_INVALIDPROPERTYVALUE
;
698 HeapFree(GetProcessHeap(), 0, This
->description
.lpstrName
);
699 This
->description
.lpstrName
= strdupW(name
);
700 if (!This
->description
.lpstrName
) return E_OUTOFMEMORY
;
702 TRACE("new name %s\n", debugstr_w(This
->description
.lpstrName
));
703 OLEFont_SendNotify(This
, DISPID_FONT_NAME
);
707 /************************************************************************
708 * OLEFontImpl_get_Size (IFont)
710 static HRESULT WINAPI
OLEFontImpl_get_Size(
714 OLEFontImpl
*this = impl_from_IFont(iface
);
715 TRACE("(%p)->(%p)\n", this, psize
);
717 if (!psize
) return E_POINTER
;
722 * Convert realized font height in pixels to points descaled by current
723 * scaling ratio then scaled up by 10000.
725 psize
->s
.Lo
= MulDiv(this->nRealHeight
,
726 this->cyHimetric
* 72 * 10000,
727 this->cyLogical
* 2540);
733 /************************************************************************
734 * OLEFontImpl_put_Size (IFont)
736 static HRESULT WINAPI
OLEFontImpl_put_Size(
740 OLEFontImpl
*this = impl_from_IFont(iface
);
741 TRACE("(%p)->(%d)\n", this, size
.s
.Lo
);
742 this->description
.cySize
.s
.Hi
= 0;
743 this->description
.cySize
.s
.Lo
= size
.s
.Lo
;
744 OLEFont_SendNotify(this, DISPID_FONT_SIZE
);
749 /************************************************************************
750 * OLEFontImpl_get_Bold (IFont)
752 * See Windows documentation for more details on IFont methods.
754 static HRESULT WINAPI
OLEFontImpl_get_Bold(
758 OLEFontImpl
*this = impl_from_IFont(iface
);
759 TRACE("(%p)->(%p)\n", this, pbold
);
761 if (!pbold
) return E_POINTER
;
765 *pbold
= this->description
.sWeight
> 550;
770 /************************************************************************
771 * OLEFontImpl_put_Bold (IFont)
773 static HRESULT WINAPI
OLEFontImpl_put_Bold(
777 OLEFontImpl
*this = impl_from_IFont(iface
);
778 TRACE("(%p)->(%d)\n", this, bold
);
779 this->description
.sWeight
= bold
? FW_BOLD
: FW_NORMAL
;
780 OLEFont_SendNotify(this, DISPID_FONT_BOLD
);
785 /************************************************************************
786 * OLEFontImpl_get_Italic (IFont)
788 static HRESULT WINAPI
OLEFontImpl_get_Italic(
792 OLEFontImpl
*this = impl_from_IFont(iface
);
793 TRACE("(%p)->(%p)\n", this, pitalic
);
800 *pitalic
= this->description
.fItalic
;
805 /************************************************************************
806 * OLEFontImpl_put_Italic (IFont)
808 static HRESULT WINAPI
OLEFontImpl_put_Italic(
812 OLEFontImpl
*this = impl_from_IFont(iface
);
813 TRACE("(%p)->(%d)\n", this, italic
);
815 this->description
.fItalic
= italic
;
817 OLEFont_SendNotify(this, DISPID_FONT_ITALIC
);
821 /************************************************************************
822 * OLEFontImpl_get_Underline (IFont)
824 static HRESULT WINAPI
OLEFontImpl_get_Underline(
828 OLEFontImpl
*this = impl_from_IFont(iface
);
829 TRACE("(%p)->(%p)\n", this, punderline
);
836 *punderline
= this->description
.fUnderline
;
841 /************************************************************************
842 * OLEFontImpl_put_Underline (IFont)
844 static HRESULT WINAPI
OLEFontImpl_put_Underline(
848 OLEFontImpl
*this = impl_from_IFont(iface
);
849 TRACE("(%p)->(%d)\n", this, underline
);
851 this->description
.fUnderline
= underline
;
853 OLEFont_SendNotify(this, DISPID_FONT_UNDER
);
857 /************************************************************************
858 * OLEFontImpl_get_Strikethrough (IFont)
860 static HRESULT WINAPI
OLEFontImpl_get_Strikethrough(
862 BOOL
* pstrikethrough
)
864 OLEFontImpl
*this = impl_from_IFont(iface
);
865 TRACE("(%p)->(%p)\n", this, pstrikethrough
);
867 if (pstrikethrough
==0)
872 *pstrikethrough
= this->description
.fStrikethrough
;
877 /************************************************************************
878 * OLEFontImpl_put_Strikethrough (IFont)
880 static HRESULT WINAPI
OLEFontImpl_put_Strikethrough(
884 OLEFontImpl
*this = impl_from_IFont(iface
);
885 TRACE("(%p)->(%d)\n", this, strikethrough
);
887 this->description
.fStrikethrough
= strikethrough
;
888 OLEFont_SendNotify(this, DISPID_FONT_STRIKE
);
893 /************************************************************************
894 * OLEFontImpl_get_Weight (IFont)
896 static HRESULT WINAPI
OLEFontImpl_get_Weight(
900 OLEFontImpl
*this = impl_from_IFont(iface
);
901 TRACE("(%p)->(%p)\n", this, pweight
);
908 *pweight
= this->description
.sWeight
;
913 /************************************************************************
914 * OLEFontImpl_put_Weight (IFont)
916 static HRESULT WINAPI
OLEFontImpl_put_Weight(
920 OLEFontImpl
*this = impl_from_IFont(iface
);
921 TRACE("(%p)->(%d)\n", this, weight
);
923 this->description
.sWeight
= weight
;
925 OLEFont_SendNotify(this, DISPID_FONT_WEIGHT
);
929 /************************************************************************
930 * OLEFontImpl_get_Charset (IFont)
932 static HRESULT WINAPI
OLEFontImpl_get_Charset(
936 OLEFontImpl
*this = impl_from_IFont(iface
);
937 TRACE("(%p)->(%p)\n", this, pcharset
);
944 *pcharset
= this->description
.sCharset
;
949 /************************************************************************
950 * OLEFontImpl_put_Charset (IFont)
952 static HRESULT WINAPI
OLEFontImpl_put_Charset(
956 OLEFontImpl
*this = impl_from_IFont(iface
);
957 TRACE("(%p)->(%d)\n", this, charset
);
959 this->description
.sCharset
= charset
;
960 OLEFont_SendNotify(this, DISPID_FONT_CHARSET
);
965 /************************************************************************
966 * OLEFontImpl_get_hFont (IFont)
968 static HRESULT WINAPI
OLEFontImpl_get_hFont(
972 OLEFontImpl
*this = impl_from_IFont(iface
);
973 TRACE("(%p)->(%p)\n", this, phfont
);
979 *phfont
= this->gdiFont
;
980 TRACE("Returning %p\n", *phfont
);
984 /************************************************************************
985 * OLEFontImpl_Clone (IFont)
987 static HRESULT WINAPI
OLEFontImpl_Clone(
991 OLEFontImpl
*this = impl_from_IFont(iface
);
992 OLEFontImpl
* newObject
;
994 TRACE("(%p)->(%p)\n", this, ppfont
);
1001 newObject
= HeapAlloc(GetProcessHeap(), 0, sizeof(OLEFontImpl
));
1002 if (newObject
==NULL
)
1003 return E_OUTOFMEMORY
;
1006 /* allocate separate buffer */
1007 newObject
->description
.lpstrName
= strdupW(this->description
.lpstrName
);
1009 /* Increment internal ref in hfont item list */
1010 if(newObject
->gdiFont
) inc_int_ref(newObject
->gdiFont
);
1012 InterlockedIncrement(&ifont_cnt
);
1014 newObject
->pPropertyNotifyCP
= NULL
;
1015 newObject
->pFontEventsCP
= NULL
;
1016 CreateConnectionPoint((IUnknown
*)&newObject
->IFont_iface
, &IID_IPropertyNotifySink
,
1017 &newObject
->pPropertyNotifyCP
);
1018 CreateConnectionPoint((IUnknown
*)&newObject
->IFont_iface
, &IID_IFontEventsDisp
,
1019 &newObject
->pFontEventsCP
);
1021 if (!newObject
->pPropertyNotifyCP
|| !newObject
->pFontEventsCP
)
1023 OLEFontImpl_Destroy(newObject
);
1024 return E_OUTOFMEMORY
;
1027 /* The cloned object starts with a reference count of 1 */
1030 *ppfont
= &newObject
->IFont_iface
;
1035 /************************************************************************
1036 * OLEFontImpl_IsEqual (IFont)
1038 static HRESULT WINAPI
OLEFontImpl_IsEqual(
1042 OLEFontImpl
*left
= impl_from_IFont(iface
);
1043 OLEFontImpl
*right
= impl_from_IFont(pFontOther
);
1045 INT left_len
,right_len
;
1047 if(pFontOther
== NULL
)
1049 else if (left
->description
.cySize
.s
.Lo
!= right
->description
.cySize
.s
.Lo
)
1051 else if (left
->description
.cySize
.s
.Hi
!= right
->description
.cySize
.s
.Hi
)
1053 else if (left
->description
.sWeight
!= right
->description
.sWeight
)
1055 else if (left
->description
.sCharset
!= right
->description
.sCharset
)
1057 else if (left
->description
.fItalic
!= right
->description
.fItalic
)
1059 else if (left
->description
.fUnderline
!= right
->description
.fUnderline
)
1061 else if (left
->description
.fStrikethrough
!= right
->description
.fStrikethrough
)
1064 /* Check from string */
1065 left_len
= lstrlenW(left
->description
.lpstrName
);
1066 right_len
= lstrlenW(right
->description
.lpstrName
);
1067 ret
= CompareStringW(0,0,left
->description
.lpstrName
, left_len
,
1068 right
->description
.lpstrName
, right_len
);
1069 if (ret
!= CSTR_EQUAL
)
1075 /************************************************************************
1076 * OLEFontImpl_SetRatio (IFont)
1078 static HRESULT WINAPI
OLEFontImpl_SetRatio(
1083 OLEFontImpl
*this = impl_from_IFont(iface
);
1084 TRACE("(%p)->(%d, %d)\n", this, cyLogical
, cyHimetric
);
1086 if(cyLogical
== 0 || cyHimetric
== 0)
1089 /* cyLogical and cyHimetric both set to 1 is a special case that
1090 does not change the scaling but also does not fail */
1091 if(cyLogical
== 1 && cyHimetric
== 1)
1094 this->cyLogical
= cyLogical
;
1095 this->cyHimetric
= cyHimetric
;
1101 /************************************************************************
1102 * OLEFontImpl_QueryTextMetrics (IFont)
1104 static HRESULT WINAPI
OLEFontImpl_QueryTextMetrics(
1109 HFONT hOldFont
, hNewFont
;
1112 IFont_get_hFont(iface
, &hNewFont
);
1113 hOldFont
= SelectObject(hdcRef
, hNewFont
);
1114 GetTextMetricsW(hdcRef
, ptm
);
1115 SelectObject(hdcRef
, hOldFont
);
1116 ReleaseDC(0, hdcRef
);
1120 /************************************************************************
1121 * OLEFontImpl_AddRefHfont (IFont)
1123 static HRESULT WINAPI
OLEFontImpl_AddRefHfont(
1127 OLEFontImpl
*this = impl_from_IFont(iface
);
1129 TRACE("(%p)->(%p)\n", this, hfont
);
1131 if (!hfont
) return E_INVALIDARG
;
1133 return inc_ext_ref(hfont
);
1136 /************************************************************************
1137 * OLEFontImpl_ReleaseHfont (IFont)
1139 static HRESULT WINAPI
OLEFontImpl_ReleaseHfont(
1143 OLEFontImpl
*this = impl_from_IFont(iface
);
1145 TRACE("(%p)->(%p)\n", this, hfont
);
1147 if (!hfont
) return E_INVALIDARG
;
1149 return dec_ext_ref(hfont
);
1152 /************************************************************************
1153 * OLEFontImpl_SetHdc (IFont)
1155 static HRESULT WINAPI
OLEFontImpl_SetHdc(
1159 OLEFontImpl
*this = impl_from_IFont(iface
);
1160 FIXME("(%p)->(%p): Stub\n", this, hdc
);
1164 static const IFontVtbl OLEFontImpl_VTable
=
1166 OLEFontImpl_QueryInterface
,
1168 OLEFontImpl_Release
,
1169 OLEFontImpl_get_Name
,
1170 OLEFontImpl_put_Name
,
1171 OLEFontImpl_get_Size
,
1172 OLEFontImpl_put_Size
,
1173 OLEFontImpl_get_Bold
,
1174 OLEFontImpl_put_Bold
,
1175 OLEFontImpl_get_Italic
,
1176 OLEFontImpl_put_Italic
,
1177 OLEFontImpl_get_Underline
,
1178 OLEFontImpl_put_Underline
,
1179 OLEFontImpl_get_Strikethrough
,
1180 OLEFontImpl_put_Strikethrough
,
1181 OLEFontImpl_get_Weight
,
1182 OLEFontImpl_put_Weight
,
1183 OLEFontImpl_get_Charset
,
1184 OLEFontImpl_put_Charset
,
1185 OLEFontImpl_get_hFont
,
1187 OLEFontImpl_IsEqual
,
1188 OLEFontImpl_SetRatio
,
1189 OLEFontImpl_QueryTextMetrics
,
1190 OLEFontImpl_AddRefHfont
,
1191 OLEFontImpl_ReleaseHfont
,
1195 /************************************************************************
1196 * OLEFontImpl_IDispatch_QueryInterface (IUnknown)
1198 static HRESULT WINAPI
OLEFontImpl_IDispatch_QueryInterface(
1203 OLEFontImpl
*this = impl_from_IDispatch(iface
);
1204 return IFont_QueryInterface(&this->IFont_iface
, riid
, ppvoid
);
1207 /************************************************************************
1208 * OLEFontImpl_IDispatch_Release (IUnknown)
1210 static ULONG WINAPI
OLEFontImpl_IDispatch_Release(
1213 OLEFontImpl
*this = impl_from_IDispatch(iface
);
1214 return IFont_Release(&this->IFont_iface
);
1217 /************************************************************************
1218 * OLEFontImpl_IDispatch_AddRef (IUnknown)
1220 static ULONG WINAPI
OLEFontImpl_IDispatch_AddRef(
1223 OLEFontImpl
*this = impl_from_IDispatch(iface
);
1224 return IFont_AddRef(&this->IFont_iface
);
1227 /************************************************************************
1228 * OLEFontImpl_GetTypeInfoCount (IDispatch)
1230 static HRESULT WINAPI
OLEFontImpl_GetTypeInfoCount(
1232 unsigned int* pctinfo
)
1234 OLEFontImpl
*this = impl_from_IDispatch(iface
);
1235 TRACE("(%p)->(%p)\n", this, pctinfo
);
1241 /************************************************************************
1242 * OLEFontImpl_GetTypeInfo (IDispatch)
1244 static HRESULT WINAPI
OLEFontImpl_GetTypeInfo(
1248 ITypeInfo
** ppTInfo
)
1250 static const WCHAR stdole2tlb
[] = {'s','t','d','o','l','e','2','.','t','l','b',0};
1254 OLEFontImpl
*this = impl_from_IDispatch(iface
);
1255 TRACE("(%p, iTInfo=%d, lcid=%04x, %p)\n", this, iTInfo
, (int)lcid
, ppTInfo
);
1258 hres
= LoadTypeLib(stdole2tlb
, &tl
);
1260 ERR("Could not load the stdole2.tlb?\n");
1263 hres
= ITypeLib_GetTypeInfoOfGuid(tl
, &IID_IFontDisp
, ppTInfo
);
1264 ITypeLib_Release(tl
);
1266 FIXME("Did not IDispatch typeinfo from typelib, hres %x\n",hres
);
1271 /************************************************************************
1272 * OLEFontImpl_GetIDsOfNames (IDispatch)
1274 static HRESULT WINAPI
OLEFontImpl_GetIDsOfNames(
1277 LPOLESTR
* rgszNames
,
1285 OLEFontImpl
*this = impl_from_IDispatch(iface
);
1287 TRACE("(%p,%s,%p,cNames=%d,lcid=%04x,%p)\n", this, debugstr_guid(riid
),
1288 rgszNames
, cNames
, (int)lcid
, rgDispId
);
1290 if (cNames
== 0) return E_INVALIDARG
;
1292 hres
= IDispatch_GetTypeInfo(iface
, 0, lcid
, &pTInfo
);
1295 ERR("GetTypeInfo failed.\n");
1299 /* convert names to DISPIDs */
1300 hres
= DispGetIDsOfNames (pTInfo
, rgszNames
, cNames
, rgDispId
);
1301 ITypeInfo_Release(pTInfo
);
1306 /************************************************************************
1307 * OLEFontImpl_Invoke (IDispatch)
1310 static HRESULT WINAPI
OLEFontImpl_Invoke(
1312 DISPID dispIdMember
,
1316 DISPPARAMS
* pDispParams
,
1317 VARIANT
* pVarResult
,
1318 EXCEPINFO
* pExepInfo
,
1321 OLEFontImpl
*this = impl_from_IDispatch(iface
);
1324 TRACE("%p->(%d,%s,0x%x,0x%x,%p,%p,%p,%p)\n", this, dispIdMember
,
1325 debugstr_guid(riid
), lcid
, wFlags
, pDispParams
, pVarResult
, pExepInfo
,
1328 /* validate parameters */
1330 if (!IsEqualIID(riid
, &IID_NULL
))
1332 ERR("riid was %s instead of IID_NULL\n", debugstr_guid(riid
));
1333 return DISP_E_UNKNOWNINTERFACE
;
1336 if (wFlags
& DISPATCH_PROPERTYGET
)
1340 ERR("null pVarResult not allowed when DISPATCH_PROPERTYGET specified\n");
1341 return DISP_E_PARAMNOTOPTIONAL
;
1344 else if (wFlags
& DISPATCH_PROPERTYPUT
)
1348 ERR("null pDispParams not allowed when DISPATCH_PROPERTYPUT specified\n");
1349 return DISP_E_PARAMNOTOPTIONAL
;
1351 if (pDispParams
->cArgs
!= 1)
1353 ERR("param count for DISPATCH_PROPERTYPUT was %d instead of 1\n", pDispParams
->cArgs
);
1354 return DISP_E_BADPARAMCOUNT
;
1359 ERR("one of DISPATCH_PROPERTYGET or DISPATCH_PROPERTYPUT must be specified\n");
1360 return DISP_E_MEMBERNOTFOUND
;
1363 switch (dispIdMember
) {
1364 case DISPID_FONT_NAME
:
1365 if (wFlags
& DISPATCH_PROPERTYGET
) {
1366 V_VT(pVarResult
) = VT_BSTR
;
1367 return IFont_get_Name(&this->IFont_iface
, &V_BSTR(pVarResult
));
1371 VariantInit(&vararg
);
1372 hr
= VariantChangeTypeEx(&vararg
, &pDispParams
->rgvarg
[0], lcid
, 0, VT_BSTR
);
1376 hr
= IFont_put_Name(&this->IFont_iface
, V_BSTR(&vararg
));
1378 VariantClear(&vararg
);
1382 case DISPID_FONT_BOLD
:
1383 if (wFlags
& DISPATCH_PROPERTYGET
) {
1385 hr
= IFont_get_Bold(&this->IFont_iface
, &value
);
1386 V_VT(pVarResult
) = VT_BOOL
;
1387 V_BOOL(pVarResult
) = value
? VARIANT_TRUE
: VARIANT_FALSE
;
1392 VariantInit(&vararg
);
1393 hr
= VariantChangeTypeEx(&vararg
, &pDispParams
->rgvarg
[0], lcid
, 0, VT_BOOL
);
1397 hr
= IFont_put_Bold(&this->IFont_iface
, V_BOOL(&vararg
));
1399 VariantClear(&vararg
);
1403 case DISPID_FONT_ITALIC
:
1404 if (wFlags
& DISPATCH_PROPERTYGET
) {
1406 hr
= IFont_get_Italic(&this->IFont_iface
, &value
);
1407 V_VT(pVarResult
) = VT_BOOL
;
1408 V_BOOL(pVarResult
) = value
? VARIANT_TRUE
: VARIANT_FALSE
;
1413 VariantInit(&vararg
);
1414 hr
= VariantChangeTypeEx(&vararg
, &pDispParams
->rgvarg
[0], lcid
, 0, VT_BOOL
);
1418 hr
= IFont_put_Italic(&this->IFont_iface
, V_BOOL(&vararg
));
1420 VariantClear(&vararg
);
1424 case DISPID_FONT_UNDER
:
1425 if (wFlags
& DISPATCH_PROPERTYGET
) {
1427 hr
= IFont_get_Underline(&this->IFont_iface
, &value
);
1428 V_VT(pVarResult
) = VT_BOOL
;
1429 V_BOOL(pVarResult
) = value
? VARIANT_TRUE
: VARIANT_FALSE
;
1434 VariantInit(&vararg
);
1435 hr
= VariantChangeTypeEx(&vararg
, &pDispParams
->rgvarg
[0], lcid
, 0, VT_BOOL
);
1439 hr
= IFont_put_Underline(&this->IFont_iface
, V_BOOL(&vararg
));
1441 VariantClear(&vararg
);
1445 case DISPID_FONT_STRIKE
:
1446 if (wFlags
& DISPATCH_PROPERTYGET
) {
1448 hr
= IFont_get_Strikethrough(&this->IFont_iface
, &value
);
1449 V_VT(pVarResult
) = VT_BOOL
;
1450 V_BOOL(pVarResult
) = value
? VARIANT_TRUE
: VARIANT_FALSE
;
1455 VariantInit(&vararg
);
1456 hr
= VariantChangeTypeEx(&vararg
, &pDispParams
->rgvarg
[0], lcid
, 0, VT_BOOL
);
1460 hr
= IFont_put_Strikethrough(&this->IFont_iface
, V_BOOL(&vararg
));
1462 VariantClear(&vararg
);
1466 case DISPID_FONT_SIZE
:
1467 if (wFlags
& DISPATCH_PROPERTYGET
) {
1468 V_VT(pVarResult
) = VT_CY
;
1469 return IFont_get_Size(&this->IFont_iface
, &V_CY(pVarResult
));
1473 VariantInit(&vararg
);
1474 hr
= VariantChangeTypeEx(&vararg
, &pDispParams
->rgvarg
[0], lcid
, 0, VT_CY
);
1478 hr
= IFont_put_Size(&this->IFont_iface
, V_CY(&vararg
));
1480 VariantClear(&vararg
);
1484 case DISPID_FONT_WEIGHT
:
1485 if (wFlags
& DISPATCH_PROPERTYGET
) {
1486 V_VT(pVarResult
) = VT_I2
;
1487 return IFont_get_Weight(&this->IFont_iface
, &V_I2(pVarResult
));
1491 VariantInit(&vararg
);
1492 hr
= VariantChangeTypeEx(&vararg
, &pDispParams
->rgvarg
[0], lcid
, 0, VT_I2
);
1496 hr
= IFont_put_Weight(&this->IFont_iface
, V_I2(&vararg
));
1498 VariantClear(&vararg
);
1502 case DISPID_FONT_CHARSET
:
1503 if (wFlags
& DISPATCH_PROPERTYGET
) {
1504 V_VT(pVarResult
) = VT_I2
;
1505 return OLEFontImpl_get_Charset(&this->IFont_iface
, &V_I2(pVarResult
));
1509 VariantInit(&vararg
);
1510 hr
= VariantChangeTypeEx(&vararg
, &pDispParams
->rgvarg
[0], lcid
, 0, VT_I2
);
1514 hr
= IFont_put_Charset(&this->IFont_iface
, V_I2(&vararg
));
1516 VariantClear(&vararg
);
1521 ERR("member not found for dispid 0x%x\n", dispIdMember
);
1522 return DISP_E_MEMBERNOTFOUND
;
1526 static const IDispatchVtbl OLEFontImpl_IDispatch_VTable
=
1528 OLEFontImpl_IDispatch_QueryInterface
,
1529 OLEFontImpl_IDispatch_AddRef
,
1530 OLEFontImpl_IDispatch_Release
,
1531 OLEFontImpl_GetTypeInfoCount
,
1532 OLEFontImpl_GetTypeInfo
,
1533 OLEFontImpl_GetIDsOfNames
,
1537 /************************************************************************
1538 * OLEFontImpl_IPersistStream_QueryInterface (IUnknown)
1540 static HRESULT WINAPI
OLEFontImpl_IPersistStream_QueryInterface(
1541 IPersistStream
* iface
,
1545 OLEFontImpl
*this = impl_from_IPersistStream(iface
);
1547 return IFont_QueryInterface(&this->IFont_iface
, riid
, ppvoid
);
1550 /************************************************************************
1551 * OLEFontImpl_IPersistStream_Release (IUnknown)
1553 static ULONG WINAPI
OLEFontImpl_IPersistStream_Release(
1554 IPersistStream
* iface
)
1556 OLEFontImpl
*this = impl_from_IPersistStream(iface
);
1558 return IFont_Release(&this->IFont_iface
);
1561 /************************************************************************
1562 * OLEFontImpl_IPersistStream_AddRef (IUnknown)
1564 static ULONG WINAPI
OLEFontImpl_IPersistStream_AddRef(
1565 IPersistStream
* iface
)
1567 OLEFontImpl
*this = impl_from_IPersistStream(iface
);
1569 return IFont_AddRef(&this->IFont_iface
);
1572 /************************************************************************
1573 * OLEFontImpl_GetClassID (IPersistStream)
1575 static HRESULT WINAPI
OLEFontImpl_GetClassID(
1576 IPersistStream
* iface
,
1579 TRACE("(%p,%p)\n",iface
,pClassID
);
1583 *pClassID
= CLSID_StdFont
;
1588 /************************************************************************
1589 * OLEFontImpl_IsDirty (IPersistStream)
1591 * See Windows documentation for more details on IPersistStream methods.
1593 static HRESULT WINAPI
OLEFontImpl_IsDirty(
1594 IPersistStream
* iface
)
1596 TRACE("(%p)\n",iface
);
1600 /************************************************************************
1601 * OLEFontImpl_Load (IPersistStream)
1603 * See Windows documentation for more details on IPersistStream methods.
1605 * This is the format of the standard font serialization as far as I
1608 * Offset Type Value Comment
1609 * 0x0000 Byte Unknown Probably a version number, contains 0x01
1610 * 0x0001 Short Charset Charset value from the FONTDESC structure
1611 * 0x0003 Byte Attributes Flags defined as follows:
1613 * 00000100 - Underline
1614 * 00001000 - Strikethrough
1615 * 0x0004 Short Weight Weight value from FONTDESC structure
1616 * 0x0006 DWORD size "Low" portion of the cySize member of the FONTDESC
1618 * 0x000A Byte name length Length of the font name string (no null character)
1619 * 0x000B String name Name of the font (ASCII, no nul character)
1621 static HRESULT WINAPI
OLEFontImpl_Load(
1622 IPersistStream
* iface
,
1623 IStream
* pLoadStream
)
1625 OLEFontImpl
*this = impl_from_IPersistStream(iface
);
1626 BYTE version
, attributes
, string_size
;
1627 char readBuffer
[0x100];
1632 IStream_Read(pLoadStream
, &version
, sizeof(BYTE
), &cbRead
);
1633 if ((cbRead
!= sizeof(BYTE
)) || (version
!= 0x01)) return E_FAIL
;
1636 IStream_Read(pLoadStream
, &this->description
.sCharset
, sizeof(WORD
), &cbRead
);
1637 if (cbRead
!= sizeof(WORD
)) return E_FAIL
;
1640 IStream_Read(pLoadStream
, &attributes
, sizeof(BYTE
), &cbRead
);
1641 if (cbRead
!= sizeof(BYTE
)) return E_FAIL
;
1643 this->description
.fItalic
= (attributes
& FONTPERSIST_ITALIC
) != 0;
1644 this->description
.fStrikethrough
= (attributes
& FONTPERSIST_STRIKETHROUGH
) != 0;
1645 this->description
.fUnderline
= (attributes
& FONTPERSIST_UNDERLINE
) != 0;
1648 IStream_Read(pLoadStream
, &this->description
.sWeight
, sizeof(WORD
), &cbRead
);
1649 if (cbRead
!= sizeof(WORD
)) return E_FAIL
;
1652 IStream_Read(pLoadStream
, &this->description
.cySize
.s
.Lo
, sizeof(DWORD
), &cbRead
);
1653 if (cbRead
!= sizeof(DWORD
)) return E_FAIL
;
1655 this->description
.cySize
.s
.Hi
= 0;
1658 IStream_Read(pLoadStream
, &string_size
, sizeof(BYTE
), &cbRead
);
1659 if (cbRead
!= sizeof(BYTE
)) return E_FAIL
;
1661 IStream_Read(pLoadStream
, readBuffer
, string_size
, &cbRead
);
1662 if (cbRead
!= string_size
) return E_FAIL
;
1664 HeapFree(GetProcessHeap(), 0, this->description
.lpstrName
);
1666 len
= MultiByteToWideChar( CP_ACP
, 0, readBuffer
, string_size
, NULL
, 0 );
1667 this->description
.lpstrName
= HeapAlloc( GetProcessHeap(), 0, (len
+1) * sizeof(WCHAR
) );
1668 MultiByteToWideChar( CP_ACP
, 0, readBuffer
, string_size
, this->description
.lpstrName
, len
);
1669 this->description
.lpstrName
[len
] = 0;
1671 /* Ensure use of this font causes a new one to be created */
1672 dec_int_ref(this->gdiFont
);
1679 /************************************************************************
1680 * OLEFontImpl_Save (IPersistStream)
1682 static HRESULT WINAPI
OLEFontImpl_Save(
1683 IPersistStream
* iface
,
1684 IStream
* pOutStream
,
1687 OLEFontImpl
*this = impl_from_IPersistStream(iface
);
1688 BYTE attributes
, string_size
;
1689 const BYTE version
= 0x01;
1690 char* writeBuffer
= NULL
;
1693 TRACE("(%p)->(%p %d)\n", this, pOutStream
, fClearDirty
);
1696 IStream_Write(pOutStream
, &version
, sizeof(BYTE
), &written
);
1697 if (written
!= sizeof(BYTE
)) return E_FAIL
;
1700 IStream_Write(pOutStream
, &this->description
.sCharset
, sizeof(WORD
), &written
);
1701 if (written
!= sizeof(WORD
)) return E_FAIL
;
1706 if (this->description
.fItalic
)
1707 attributes
|= FONTPERSIST_ITALIC
;
1709 if (this->description
.fStrikethrough
)
1710 attributes
|= FONTPERSIST_STRIKETHROUGH
;
1712 if (this->description
.fUnderline
)
1713 attributes
|= FONTPERSIST_UNDERLINE
;
1715 IStream_Write(pOutStream
, &attributes
, sizeof(BYTE
), &written
);
1716 if (written
!= sizeof(BYTE
)) return E_FAIL
;
1719 IStream_Write(pOutStream
, &this->description
.sWeight
, sizeof(WORD
), &written
);
1720 if (written
!= sizeof(WORD
)) return E_FAIL
;
1723 IStream_Write(pOutStream
, &this->description
.cySize
.s
.Lo
, sizeof(DWORD
), &written
);
1724 if (written
!= sizeof(DWORD
)) return E_FAIL
;
1727 if (this->description
.lpstrName
)
1728 string_size
= WideCharToMultiByte( CP_ACP
, 0, this->description
.lpstrName
,
1729 lstrlenW(this->description
.lpstrName
), NULL
, 0, NULL
, NULL
);
1733 IStream_Write(pOutStream
, &string_size
, sizeof(BYTE
), &written
);
1734 if (written
!= sizeof(BYTE
)) return E_FAIL
;
1738 if (!(writeBuffer
= HeapAlloc( GetProcessHeap(), 0, string_size
))) return E_OUTOFMEMORY
;
1739 WideCharToMultiByte( CP_ACP
, 0, this->description
.lpstrName
,
1740 lstrlenW(this->description
.lpstrName
),
1741 writeBuffer
, string_size
, NULL
, NULL
);
1743 IStream_Write(pOutStream
, writeBuffer
, string_size
, &written
);
1744 HeapFree(GetProcessHeap(), 0, writeBuffer
);
1746 if (written
!= string_size
) return E_FAIL
;
1752 /************************************************************************
1753 * OLEFontImpl_GetSizeMax (IPersistStream)
1755 static HRESULT WINAPI
OLEFontImpl_GetSizeMax(
1756 IPersistStream
* iface
,
1757 ULARGE_INTEGER
* pcbSize
)
1759 OLEFontImpl
*this = impl_from_IPersistStream(iface
);
1764 pcbSize
->u
.HighPart
= 0;
1765 pcbSize
->u
.LowPart
= 0;
1767 pcbSize
->u
.LowPart
+= sizeof(BYTE
); /* Version */
1768 pcbSize
->u
.LowPart
+= sizeof(WORD
); /* Lang code */
1769 pcbSize
->u
.LowPart
+= sizeof(BYTE
); /* Flags */
1770 pcbSize
->u
.LowPart
+= sizeof(WORD
); /* Weight */
1771 pcbSize
->u
.LowPart
+= sizeof(DWORD
); /* Size */
1772 pcbSize
->u
.LowPart
+= sizeof(BYTE
); /* StrLength */
1774 if (this->description
.lpstrName
!=0)
1775 pcbSize
->u
.LowPart
+= WideCharToMultiByte( CP_ACP
, 0, this->description
.lpstrName
,
1776 lstrlenW(this->description
.lpstrName
),
1777 NULL
, 0, NULL
, NULL
);
1782 static const IPersistStreamVtbl OLEFontImpl_IPersistStream_VTable
=
1784 OLEFontImpl_IPersistStream_QueryInterface
,
1785 OLEFontImpl_IPersistStream_AddRef
,
1786 OLEFontImpl_IPersistStream_Release
,
1787 OLEFontImpl_GetClassID
,
1788 OLEFontImpl_IsDirty
,
1791 OLEFontImpl_GetSizeMax
1794 /************************************************************************
1795 * OLEFontImpl_IConnectionPointContainer_QueryInterface (IUnknown)
1797 static HRESULT WINAPI
OLEFontImpl_IConnectionPointContainer_QueryInterface(
1798 IConnectionPointContainer
* iface
,
1802 OLEFontImpl
*this = impl_from_IConnectionPointContainer(iface
);
1804 return IFont_QueryInterface(&this->IFont_iface
, riid
, ppvoid
);
1807 /************************************************************************
1808 * OLEFontImpl_IConnectionPointContainer_Release (IUnknown)
1810 static ULONG WINAPI
OLEFontImpl_IConnectionPointContainer_Release(
1811 IConnectionPointContainer
* iface
)
1813 OLEFontImpl
*this = impl_from_IConnectionPointContainer(iface
);
1815 return IFont_Release(&this->IFont_iface
);
1818 /************************************************************************
1819 * OLEFontImpl_IConnectionPointContainer_AddRef (IUnknown)
1821 static ULONG WINAPI
OLEFontImpl_IConnectionPointContainer_AddRef(
1822 IConnectionPointContainer
* iface
)
1824 OLEFontImpl
*this = impl_from_IConnectionPointContainer(iface
);
1826 return IFont_AddRef(&this->IFont_iface
);
1829 /************************************************************************
1830 * OLEFontImpl_EnumConnectionPoints (IConnectionPointContainer)
1832 static HRESULT WINAPI
OLEFontImpl_EnumConnectionPoints(
1833 IConnectionPointContainer
* iface
,
1834 IEnumConnectionPoints
**ppEnum
)
1836 OLEFontImpl
*this = impl_from_IConnectionPointContainer(iface
);
1838 FIXME("(%p)->(%p): stub\n", this, ppEnum
);
1842 /************************************************************************
1843 * OLEFontImpl_FindConnectionPoint (IConnectionPointContainer)
1845 static HRESULT WINAPI
OLEFontImpl_FindConnectionPoint(
1846 IConnectionPointContainer
* iface
,
1848 IConnectionPoint
**ppCp
)
1850 OLEFontImpl
*this = impl_from_IConnectionPointContainer(iface
);
1851 TRACE("(%p)->(%s, %p)\n", this, debugstr_guid(riid
), ppCp
);
1853 if(IsEqualIID(riid
, &IID_IPropertyNotifySink
)) {
1854 return IConnectionPoint_QueryInterface(this->pPropertyNotifyCP
, &IID_IConnectionPoint
,
1856 } else if(IsEqualIID(riid
, &IID_IFontEventsDisp
)) {
1857 return IConnectionPoint_QueryInterface(this->pFontEventsCP
, &IID_IConnectionPoint
,
1860 FIXME("no connection point for %s\n", debugstr_guid(riid
));
1861 return CONNECT_E_NOCONNECTION
;
1865 static const IConnectionPointContainerVtbl
1866 OLEFontImpl_IConnectionPointContainer_VTable
=
1868 OLEFontImpl_IConnectionPointContainer_QueryInterface
,
1869 OLEFontImpl_IConnectionPointContainer_AddRef
,
1870 OLEFontImpl_IConnectionPointContainer_Release
,
1871 OLEFontImpl_EnumConnectionPoints
,
1872 OLEFontImpl_FindConnectionPoint
1875 /************************************************************************
1876 * OLEFontImpl implementation of IPersistPropertyBag.
1878 static HRESULT WINAPI
OLEFontImpl_IPersistPropertyBag_QueryInterface(
1879 IPersistPropertyBag
*iface
, REFIID riid
, LPVOID
*ppvObj
1881 OLEFontImpl
*this = impl_from_IPersistPropertyBag(iface
);
1882 return IFont_QueryInterface(&this->IFont_iface
,riid
,ppvObj
);
1885 static ULONG WINAPI
OLEFontImpl_IPersistPropertyBag_AddRef(
1886 IPersistPropertyBag
*iface
1888 OLEFontImpl
*this = impl_from_IPersistPropertyBag(iface
);
1889 return IFont_AddRef(&this->IFont_iface
);
1892 static ULONG WINAPI
OLEFontImpl_IPersistPropertyBag_Release(
1893 IPersistPropertyBag
*iface
1895 OLEFontImpl
*this = impl_from_IPersistPropertyBag(iface
);
1896 return IFont_Release(&this->IFont_iface
);
1899 static HRESULT WINAPI
OLEFontImpl_IPersistPropertyBag_GetClassID(
1900 IPersistPropertyBag
*iface
, CLSID
*classid
1902 FIXME("(%p,%p), stub!\n", iface
, classid
);
1906 static HRESULT WINAPI
OLEFontImpl_IPersistPropertyBag_InitNew(
1907 IPersistPropertyBag
*iface
1909 FIXME("(%p), stub!\n", iface
);
1913 static HRESULT WINAPI
OLEFontImpl_IPersistPropertyBag_Load(
1914 IPersistPropertyBag
*iface
, IPropertyBag
* pPropBag
, IErrorLog
* pErrorLog
1916 /* (from Visual Basic 6 property bag)
1917 Name = "MS Sans Serif"
1921 Underline = 0 'False
1923 Strikethrough = 0 'False
1925 static const WCHAR sAttrName
[] = {'N','a','m','e',0};
1926 static const WCHAR sAttrSize
[] = {'S','i','z','e',0};
1927 static const WCHAR sAttrCharset
[] = {'C','h','a','r','s','e','t',0};
1928 static const WCHAR sAttrWeight
[] = {'W','e','i','g','h','t',0};
1929 static const WCHAR sAttrUnderline
[] = {'U','n','d','e','r','l','i','n','e',0};
1930 static const WCHAR sAttrItalic
[] = {'I','t','a','l','i','c',0};
1931 static const WCHAR sAttrStrikethrough
[] = {'S','t','r','i','k','e','t','h','r','o','u','g','h',0};
1932 OLEFontImpl
*this = impl_from_IPersistPropertyBag(iface
);
1936 VariantInit(&value
);
1938 iRes
= IPropertyBag_Read(pPropBag
, sAttrName
, &value
, pErrorLog
);
1941 iRes
= VariantChangeType(&value
, &value
, 0, VT_BSTR
);
1943 iRes
= IFont_put_Name(&this->IFont_iface
, V_BSTR(&value
));
1945 else if (iRes
== E_INVALIDARG
)
1948 VariantClear(&value
);
1951 iRes
= IPropertyBag_Read(pPropBag
, sAttrSize
, &value
, pErrorLog
);
1954 iRes
= VariantChangeType(&value
, &value
, 0, VT_CY
);
1956 iRes
= IFont_put_Size(&this->IFont_iface
, V_CY(&value
));
1958 else if (iRes
== E_INVALIDARG
)
1961 VariantClear(&value
);
1965 iRes
= IPropertyBag_Read(pPropBag
, sAttrCharset
, &value
, pErrorLog
);
1968 iRes
= VariantChangeType(&value
, &value
, 0, VT_I2
);
1970 iRes
= IFont_put_Charset(&this->IFont_iface
, V_I2(&value
));
1972 else if (iRes
== E_INVALIDARG
)
1975 VariantClear(&value
);
1979 iRes
= IPropertyBag_Read(pPropBag
, sAttrWeight
, &value
, pErrorLog
);
1982 iRes
= VariantChangeType(&value
, &value
, 0, VT_I2
);
1984 iRes
= IFont_put_Weight(&this->IFont_iface
, V_I2(&value
));
1986 else if (iRes
== E_INVALIDARG
)
1989 VariantClear(&value
);
1993 iRes
= IPropertyBag_Read(pPropBag
, sAttrUnderline
, &value
, pErrorLog
);
1996 iRes
= VariantChangeType(&value
, &value
, 0, VT_BOOL
);
1998 iRes
= IFont_put_Underline(&this->IFont_iface
, V_BOOL(&value
));
2000 else if (iRes
== E_INVALIDARG
)
2003 VariantClear(&value
);
2007 iRes
= IPropertyBag_Read(pPropBag
, sAttrItalic
, &value
, pErrorLog
);
2010 iRes
= VariantChangeType(&value
, &value
, 0, VT_BOOL
);
2012 iRes
= IFont_put_Italic(&this->IFont_iface
, V_BOOL(&value
));
2014 else if (iRes
== E_INVALIDARG
)
2017 VariantClear(&value
);
2021 iRes
= IPropertyBag_Read(pPropBag
, sAttrStrikethrough
, &value
, pErrorLog
);
2024 iRes
= VariantChangeType(&value
, &value
, 0, VT_BOOL
);
2026 IFont_put_Strikethrough(&this->IFont_iface
, V_BOOL(&value
));
2028 else if (iRes
== E_INVALIDARG
)
2031 VariantClear(&value
);
2035 WARN("-- 0x%08x\n", iRes
);
2039 static HRESULT WINAPI
OLEFontImpl_IPersistPropertyBag_Save(
2040 IPersistPropertyBag
*iface
, IPropertyBag
* pPropBag
, BOOL fClearDirty
,
2041 BOOL fSaveAllProperties
2043 FIXME("(%p,%p,%d,%d), stub!\n", iface
, pPropBag
, fClearDirty
, fSaveAllProperties
);
2047 static const IPersistPropertyBagVtbl OLEFontImpl_IPersistPropertyBag_VTable
=
2049 OLEFontImpl_IPersistPropertyBag_QueryInterface
,
2050 OLEFontImpl_IPersistPropertyBag_AddRef
,
2051 OLEFontImpl_IPersistPropertyBag_Release
,
2053 OLEFontImpl_IPersistPropertyBag_GetClassID
,
2054 OLEFontImpl_IPersistPropertyBag_InitNew
,
2055 OLEFontImpl_IPersistPropertyBag_Load
,
2056 OLEFontImpl_IPersistPropertyBag_Save
2059 /************************************************************************
2060 * OLEFontImpl implementation of IPersistStreamInit.
2062 static HRESULT WINAPI
OLEFontImpl_IPersistStreamInit_QueryInterface(
2063 IPersistStreamInit
*iface
, REFIID riid
, LPVOID
*ppvObj
2065 OLEFontImpl
*this = impl_from_IPersistStreamInit(iface
);
2066 return IFont_QueryInterface(&this->IFont_iface
,riid
,ppvObj
);
2069 static ULONG WINAPI
OLEFontImpl_IPersistStreamInit_AddRef(
2070 IPersistStreamInit
*iface
2072 OLEFontImpl
*this = impl_from_IPersistStreamInit(iface
);
2073 return IFont_AddRef(&this->IFont_iface
);
2076 static ULONG WINAPI
OLEFontImpl_IPersistStreamInit_Release(
2077 IPersistStreamInit
*iface
2079 OLEFontImpl
*this = impl_from_IPersistStreamInit(iface
);
2080 return IFont_Release(&this->IFont_iface
);
2083 static HRESULT WINAPI
OLEFontImpl_IPersistStreamInit_GetClassID(
2084 IPersistStreamInit
*iface
, CLSID
*classid
2086 FIXME("(%p,%p), stub!\n", iface
, classid
);
2090 static HRESULT WINAPI
OLEFontImpl_IPersistStreamInit_IsDirty(
2091 IPersistStreamInit
*iface
2093 FIXME("(%p), stub!\n", iface
);
2097 static HRESULT WINAPI
OLEFontImpl_IPersistStreamInit_Load(
2098 IPersistStreamInit
*iface
, LPSTREAM pStm
2100 FIXME("(%p,%p), stub!\n", iface
, pStm
);
2104 static HRESULT WINAPI
OLEFontImpl_IPersistStreamInit_Save(
2105 IPersistStreamInit
*iface
, LPSTREAM pStm
, BOOL fClearDirty
2107 FIXME("(%p,%p,%d), stub!\n", iface
, pStm
, fClearDirty
);
2111 static HRESULT WINAPI
OLEFontImpl_IPersistStreamInit_GetSizeMax(
2112 IPersistStreamInit
*iface
, ULARGE_INTEGER
*pcbSize
2114 FIXME("(%p,%p), stub!\n", iface
, pcbSize
);
2118 static HRESULT WINAPI
OLEFontImpl_IPersistStreamInit_InitNew(
2119 IPersistStreamInit
*iface
2121 FIXME("(%p), stub!\n", iface
);
2125 static const IPersistStreamInitVtbl OLEFontImpl_IPersistStreamInit_VTable
=
2127 OLEFontImpl_IPersistStreamInit_QueryInterface
,
2128 OLEFontImpl_IPersistStreamInit_AddRef
,
2129 OLEFontImpl_IPersistStreamInit_Release
,
2131 OLEFontImpl_IPersistStreamInit_GetClassID
,
2132 OLEFontImpl_IPersistStreamInit_IsDirty
,
2133 OLEFontImpl_IPersistStreamInit_Load
,
2134 OLEFontImpl_IPersistStreamInit_Save
,
2135 OLEFontImpl_IPersistStreamInit_GetSizeMax
,
2136 OLEFontImpl_IPersistStreamInit_InitNew
2139 /************************************************************************
2140 * OLEFontImpl_Construct
2142 * This method will construct a new instance of the OLEFontImpl
2145 * The caller of this method must release the object when it's
2148 static OLEFontImpl
* OLEFontImpl_Construct(const FONTDESC
*fontDesc
)
2150 OLEFontImpl
* newObject
;
2152 newObject
= HeapAlloc(GetProcessHeap(), 0, sizeof(OLEFontImpl
));
2157 newObject
->IFont_iface
.lpVtbl
= &OLEFontImpl_VTable
;
2158 newObject
->IDispatch_iface
.lpVtbl
= &OLEFontImpl_IDispatch_VTable
;
2159 newObject
->IPersistStream_iface
.lpVtbl
= &OLEFontImpl_IPersistStream_VTable
;
2160 newObject
->IConnectionPointContainer_iface
.lpVtbl
= &OLEFontImpl_IConnectionPointContainer_VTable
;
2161 newObject
->IPersistPropertyBag_iface
.lpVtbl
= &OLEFontImpl_IPersistPropertyBag_VTable
;
2162 newObject
->IPersistStreamInit_iface
.lpVtbl
= &OLEFontImpl_IPersistStreamInit_VTable
;
2166 newObject
->description
.cbSizeofstruct
= sizeof(FONTDESC
);
2167 newObject
->description
.lpstrName
= strdupW(fontDesc
->lpstrName
);
2168 newObject
->description
.cySize
= fontDesc
->cySize
;
2169 newObject
->description
.sWeight
= fontDesc
->sWeight
;
2170 newObject
->description
.sCharset
= fontDesc
->sCharset
;
2171 newObject
->description
.fItalic
= fontDesc
->fItalic
;
2172 newObject
->description
.fUnderline
= fontDesc
->fUnderline
;
2173 newObject
->description
.fStrikethrough
= fontDesc
->fStrikethrough
;
2175 newObject
->gdiFont
= 0;
2176 newObject
->dirty
= TRUE
;
2177 newObject
->cyLogical
= GetDeviceCaps(get_dc(), LOGPIXELSY
);
2178 newObject
->cyHimetric
= 2540L;
2179 newObject
->pPropertyNotifyCP
= NULL
;
2180 newObject
->pFontEventsCP
= NULL
;
2182 CreateConnectionPoint((IUnknown
*)&newObject
->IFont_iface
, &IID_IPropertyNotifySink
, &newObject
->pPropertyNotifyCP
);
2183 CreateConnectionPoint((IUnknown
*)&newObject
->IFont_iface
, &IID_IFontEventsDisp
, &newObject
->pFontEventsCP
);
2185 if (!newObject
->pPropertyNotifyCP
|| !newObject
->pFontEventsCP
)
2187 OLEFontImpl_Destroy(newObject
);
2191 InterlockedIncrement(&ifont_cnt
);
2193 TRACE("returning %p\n", newObject
);
2197 /************************************************************************
2198 * OLEFontImpl_Destroy
2200 * This method is called by the Release method when the reference
2201 * count goes down to 0. It will free all resources used by
2204 static void OLEFontImpl_Destroy(OLEFontImpl
* fontDesc
)
2206 TRACE("(%p)\n", fontDesc
);
2208 HeapFree(GetProcessHeap(), 0, fontDesc
->description
.lpstrName
);
2210 if (fontDesc
->pPropertyNotifyCP
)
2211 IConnectionPoint_Release(fontDesc
->pPropertyNotifyCP
);
2212 if (fontDesc
->pFontEventsCP
)
2213 IConnectionPoint_Release(fontDesc
->pFontEventsCP
);
2215 HeapFree(GetProcessHeap(), 0, fontDesc
);
2218 /*******************************************************************************
2219 * StdFont ClassFactory
2223 /* IUnknown fields */
2224 IClassFactory IClassFactory_iface
;
2226 } IClassFactoryImpl
;
2228 static inline IClassFactoryImpl
*impl_from_IClassFactory(IClassFactory
*iface
)
2230 return CONTAINING_RECORD(iface
, IClassFactoryImpl
, IClassFactory_iface
);
2233 static HRESULT WINAPI
SFCF_QueryInterface(IClassFactory
*iface
, REFIID riid
, void **obj
)
2235 IClassFactoryImpl
*This
= impl_from_IClassFactory(iface
);
2237 TRACE("(%p)->(%s, %p)\n", This
, debugstr_guid(riid
), obj
);
2241 if (IsEqualIID(&IID_IClassFactory
, riid
) || IsEqualIID(&IID_IUnknown
, riid
))
2244 IClassFactory_AddRef(iface
);
2248 return E_NOINTERFACE
;
2252 SFCF_AddRef(LPCLASSFACTORY iface
) {
2253 IClassFactoryImpl
*This
= impl_from_IClassFactory(iface
);
2254 return InterlockedIncrement(&This
->ref
);
2257 static ULONG WINAPI
SFCF_Release(LPCLASSFACTORY iface
) {
2258 IClassFactoryImpl
*This
= impl_from_IClassFactory(iface
);
2259 /* static class, won't be freed */
2260 return InterlockedDecrement(&This
->ref
);
2263 static HRESULT WINAPI
SFCF_CreateInstance(
2264 LPCLASSFACTORY iface
,LPUNKNOWN pOuter
,REFIID riid
,LPVOID
*ppobj
2266 return OleCreateFontIndirect(NULL
,riid
,ppobj
);
2270 static HRESULT WINAPI
SFCF_LockServer(LPCLASSFACTORY iface
,BOOL dolock
) {
2271 IClassFactoryImpl
*This
= impl_from_IClassFactory(iface
);
2272 FIXME("(%p)->(%d),stub!\n",This
,dolock
);
2276 static const IClassFactoryVtbl SFCF_Vtbl
= {
2277 SFCF_QueryInterface
,
2280 SFCF_CreateInstance
,
2283 static IClassFactoryImpl STDFONT_CF
= {{&SFCF_Vtbl
}, 1 };
2285 void _get_STDFONT_CF(LPVOID
*ppv
) { *ppv
= &STDFONT_CF
; }