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
34 #include "wine/list.h"
36 #include "oleauto.h" /* for SysAllocString(....) */
39 #include "wine/debug.h"
40 #include "connpt.h" /* for CreateConnectionPoint */
43 WINE_DEFAULT_DEBUG_CHANNEL(ole
);
45 /***********************************************************************
46 * Declaration of constants used when serializing the font object.
48 #define FONTPERSIST_ITALIC 0x02
49 #define FONTPERSIST_UNDERLINE 0x04
50 #define FONTPERSIST_STRIKETHROUGH 0x08
52 static HDC olefont_hdc
;
54 /***********************************************************************
55 * List of the HFONTs it has given out, with each one having a separate
58 typedef struct _HFONTItem
62 /* Reference count of any IFont objects that own this hfont */
65 /* Total reference count of any refs held by the application obtained by AddRefHfont plus any internal refs */
68 /* The font associated with this object. */
71 } HFONTItem
, *PHFONTItem
;
73 static struct list OLEFontImpl_hFontList
= LIST_INIT(OLEFontImpl_hFontList
);
75 /* Counts how many fonts contain at least one lock */
76 static LONG ifont_cnt
= 0;
78 /***********************************************************************
79 * Critical section for OLEFontImpl_hFontList
81 static CRITICAL_SECTION OLEFontImpl_csHFONTLIST
;
82 static CRITICAL_SECTION_DEBUG OLEFontImpl_csHFONTLIST_debug
=
84 0, 0, &OLEFontImpl_csHFONTLIST
,
85 { &OLEFontImpl_csHFONTLIST_debug
.ProcessLocksList
,
86 &OLEFontImpl_csHFONTLIST_debug
.ProcessLocksList
},
87 0, 0, { (DWORD_PTR
)(__FILE__
": OLEFontImpl_csHFONTLIST") }
89 static CRITICAL_SECTION OLEFontImpl_csHFONTLIST
= { &OLEFontImpl_csHFONTLIST_debug
, -1, 0, 0, 0, 0 };
91 static HDC
get_dc(void)
94 EnterCriticalSection(&OLEFontImpl_csHFONTLIST
);
96 olefont_hdc
= CreateCompatibleDC(NULL
);
98 LeaveCriticalSection(&OLEFontImpl_csHFONTLIST
);
102 static void delete_dc(void)
104 EnterCriticalSection(&OLEFontImpl_csHFONTLIST
);
107 DeleteDC(olefont_hdc
);
110 LeaveCriticalSection(&OLEFontImpl_csHFONTLIST
);
113 static void HFONTItem_Delete(PHFONTItem item
)
115 DeleteObject(item
->gdiFont
);
116 list_remove(&item
->entry
);
120 /* Find hfont item entry in the list. Should be called while holding the crit sect */
121 static HFONTItem
*find_hfontitem(HFONT hfont
)
125 LIST_FOR_EACH_ENTRY(item
, &OLEFontImpl_hFontList
, HFONTItem
, entry
)
127 if (item
->gdiFont
== hfont
)
133 /* Add an item to the list with one internal reference */
134 static HRESULT
add_hfontitem(HFONT hfont
)
136 HFONTItem
*new_item
= malloc(sizeof(*new_item
));
138 if(!new_item
) return E_OUTOFMEMORY
;
140 new_item
->int_refs
= 1;
141 new_item
->total_refs
= 1;
142 new_item
->gdiFont
= hfont
;
143 EnterCriticalSection(&OLEFontImpl_csHFONTLIST
);
144 list_add_tail(&OLEFontImpl_hFontList
,&new_item
->entry
);
145 LeaveCriticalSection(&OLEFontImpl_csHFONTLIST
);
149 static HRESULT
inc_int_ref(HFONT hfont
)
152 HRESULT hr
= S_FALSE
;
154 EnterCriticalSection(&OLEFontImpl_csHFONTLIST
);
155 item
= find_hfontitem(hfont
);
163 LeaveCriticalSection(&OLEFontImpl_csHFONTLIST
);
168 /* decrements the internal ref of a hfont item. If both refs are zero it'll
169 remove the item from the list and delete the hfont */
170 static HRESULT
dec_int_ref(HFONT hfont
)
173 HRESULT hr
= S_FALSE
;
175 EnterCriticalSection(&OLEFontImpl_csHFONTLIST
);
176 item
= find_hfontitem(hfont
);
182 if(item
->int_refs
== 0 && item
->total_refs
== 0)
183 HFONTItem_Delete(item
);
186 LeaveCriticalSection(&OLEFontImpl_csHFONTLIST
);
191 static HRESULT
inc_ext_ref(HFONT hfont
)
194 HRESULT hr
= S_FALSE
;
196 EnterCriticalSection(&OLEFontImpl_csHFONTLIST
);
198 item
= find_hfontitem(hfont
);
204 LeaveCriticalSection(&OLEFontImpl_csHFONTLIST
);
209 static HRESULT
dec_ext_ref(HFONT hfont
)
212 HRESULT hr
= S_FALSE
;
214 EnterCriticalSection(&OLEFontImpl_csHFONTLIST
);
216 item
= find_hfontitem(hfont
);
219 if(--item
->total_refs
>= 0) hr
= S_OK
;
221 LeaveCriticalSection(&OLEFontImpl_csHFONTLIST
);
226 /***********************************************************************
227 * Declaration of the implementation class for the IFont interface
229 typedef struct OLEFontImpl OLEFontImpl
;
234 * This class supports many interfaces. IUnknown, IFont,
235 * IDispatch, IDispFont IPersistStream and IConnectionPointContainer.
236 * The first two are supported by the first vtable, the next two are
237 * supported by the second table and the last two have their own.
240 IDispatch IDispatch_iface
;
241 IPersistStream IPersistStream_iface
;
242 IConnectionPointContainer IConnectionPointContainer_iface
;
243 IPersistPropertyBag IPersistPropertyBag_iface
;
245 * Reference count for that instance of the class.
250 * This structure contains the description of the class.
252 FONTDESC description
;
255 * Contain the font associated with this object.
266 * Stash realized height (pixels) from TEXTMETRIC - used in get_Size()
270 IConnectionPoint
*pPropertyNotifyCP
;
271 IConnectionPoint
*pFontEventsCP
;
274 static inline OLEFontImpl
*impl_from_IFont(IFont
*iface
)
276 return CONTAINING_RECORD(iface
, OLEFontImpl
, IFont_iface
);
279 static inline OLEFontImpl
*impl_from_IDispatch( IDispatch
*iface
)
281 return CONTAINING_RECORD(iface
, OLEFontImpl
, IDispatch_iface
);
284 static inline OLEFontImpl
*impl_from_IPersistStream( IPersistStream
*iface
)
286 return CONTAINING_RECORD(iface
, OLEFontImpl
, IPersistStream_iface
);
289 static inline OLEFontImpl
*impl_from_IConnectionPointContainer( IConnectionPointContainer
*iface
)
291 return CONTAINING_RECORD(iface
, OLEFontImpl
, IConnectionPointContainer_iface
);
294 static inline OLEFontImpl
*impl_from_IPersistPropertyBag( IPersistPropertyBag
*iface
)
296 return CONTAINING_RECORD(iface
, OLEFontImpl
, IPersistPropertyBag_iface
);
300 /***********************************************************************
301 * Prototypes for the implementation functions for the IFont
304 static OLEFontImpl
* OLEFontImpl_Construct(const FONTDESC
*fontDesc
);
305 static void OLEFontImpl_Destroy(OLEFontImpl
* fontDesc
);
306 static ULONG WINAPI
OLEFontImpl_AddRef(IFont
* iface
);
308 /******************************************************************************
309 * OleCreateFontIndirect [OLEAUT32.420]
311 HRESULT WINAPI
OleCreateFontIndirect(
312 LPFONTDESC lpFontDesc
,
316 OLEFontImpl
* newFont
;
320 TRACE("(%p, %s, %p)\n", lpFontDesc
, debugstr_guid(riid
), ppvObj
);
322 if (!ppvObj
) return E_POINTER
;
327 static WCHAR fname
[] = L
"System";
329 fd
.cbSizeofstruct
= sizeof(fd
);
330 fd
.lpstrName
= fname
;
331 fd
.cySize
.Lo
= 80000;
336 fd
.fUnderline
= FALSE
;
337 fd
.fStrikethrough
= FALSE
;
341 newFont
= OLEFontImpl_Construct(lpFontDesc
);
342 if (!newFont
) return E_OUTOFMEMORY
;
344 hr
= IFont_QueryInterface(&newFont
->IFont_iface
, riid
, ppvObj
);
345 IFont_Release(&newFont
->IFont_iface
);
351 /***********************************************************************
352 * Implementation of the OLEFontImpl class.
355 /***********************************************************************
356 * OLEFont_SendNotify (internal)
358 * Sends notification messages of changed properties to any interested
361 static void OLEFont_SendNotify(OLEFontImpl
* this, DISPID dispID
)
363 static const LPCWSTR dispid_mapping
[] =
376 IEnumConnections
*pEnum
;
382 hres
= IConnectionPoint_EnumConnections(this->pPropertyNotifyCP
, &pEnum
);
385 while(IEnumConnections_Next(pEnum
, 1, &CD
, NULL
) == S_OK
) {
386 IPropertyNotifySink
*sink
;
388 IUnknown_QueryInterface(CD
.pUnk
, &IID_IPropertyNotifySink
, (void**)&sink
);
389 IPropertyNotifySink_OnChanged(sink
, dispID
);
390 IPropertyNotifySink_Release(sink
);
391 IUnknown_Release(CD
.pUnk
);
393 IEnumConnections_Release(pEnum
);
396 hres
= IConnectionPoint_EnumConnections(this->pFontEventsCP
, &pEnum
);
399 DISPPARAMS dispparams
;
402 VariantInit(&vararg
);
403 V_VT(&vararg
) = VT_BSTR
;
404 V_BSTR(&vararg
) = SysAllocString(dispid_mapping
[dispID
]);
406 dispparams
.cArgs
= 1;
407 dispparams
.cNamedArgs
= 0;
408 dispparams
.rgdispidNamedArgs
= NULL
;
409 dispparams
.rgvarg
= &vararg
;
411 while(IEnumConnections_Next(pEnum
, 1, &CD
, NULL
) == S_OK
) {
412 IFontEventsDisp
*disp
;
414 IUnknown_QueryInterface(CD
.pUnk
, &IID_IFontEventsDisp
, (void**)&disp
);
415 IFontEventsDisp_Invoke(disp
, DISPID_FONT_CHANGED
, &IID_NULL
,
416 LOCALE_NEUTRAL
, INVOKE_FUNC
, &dispparams
, NULL
,
419 IFontEventsDisp_Release(disp
);
420 IUnknown_Release(CD
.pUnk
);
422 VariantClear(&vararg
);
423 IEnumConnections_Release(pEnum
);
427 /************************************************************************
428 * OLEFontImpl_QueryInterface (IUnknown)
430 * See Windows documentation for more details on IUnknown methods.
432 static HRESULT WINAPI
OLEFontImpl_QueryInterface(
437 OLEFontImpl
*this = impl_from_IFont(iface
);
439 TRACE("(%p)->(%s, %p)\n", this, debugstr_guid(riid
), ppvObject
);
443 if (IsEqualGUID(&IID_IUnknown
, riid
) ||
444 IsEqualGUID(&IID_IFont
, riid
))
448 else if (IsEqualGUID(&IID_IDispatch
, riid
) ||
449 IsEqualGUID(&IID_IFontDisp
, riid
))
451 *ppvObject
= &this->IDispatch_iface
;
453 else if (IsEqualGUID(&IID_IPersist
, riid
) ||
454 IsEqualGUID(&IID_IPersistStream
, riid
))
456 *ppvObject
= &this->IPersistStream_iface
;
458 else if (IsEqualGUID(&IID_IConnectionPointContainer
, riid
))
460 *ppvObject
= &this->IConnectionPointContainer_iface
;
462 else if (IsEqualGUID(&IID_IPersistPropertyBag
, riid
))
464 *ppvObject
= &this->IPersistPropertyBag_iface
;
469 FIXME("() : asking for unsupported interface %s\n", debugstr_guid(riid
));
470 return E_NOINTERFACE
;
478 static ULONG WINAPI
OLEFontImpl_AddRef(IFont
* iface
)
480 OLEFontImpl
*this = impl_from_IFont(iface
);
481 ULONG ref
= InterlockedIncrement(&this->ref
);
482 TRACE("%p, refcount %lu.\n", iface
, ref
);
486 static ULONG WINAPI
OLEFontImpl_Release(IFont
* iface
)
488 OLEFontImpl
*this = impl_from_IFont(iface
);
489 ULONG ref
= InterlockedDecrement(&this->ref
);
491 TRACE("%p, refcount %lu.\n", iface
, ref
);
495 ULONG fontlist_refs
= InterlockedDecrement(&ifont_cnt
);
497 /* Final IFont object so destroy font cache */
498 if (fontlist_refs
== 0)
500 HFONTItem
*item
, *cursor2
;
502 EnterCriticalSection(&OLEFontImpl_csHFONTLIST
);
503 LIST_FOR_EACH_ENTRY_SAFE(item
, cursor2
, &OLEFontImpl_hFontList
, HFONTItem
, entry
)
504 HFONTItem_Delete(item
);
505 LeaveCriticalSection(&OLEFontImpl_csHFONTLIST
);
510 dec_int_ref(this->gdiFont
);
512 OLEFontImpl_Destroy(this);
524 static int CALLBACK
font_enum_proc(const LOGFONTW
*elf
, const TEXTMETRICW
*ntm
, DWORD type
, LPARAM lp
)
526 enum_data
*data
= (enum_data
*)lp
;
528 if(elf
->lfCharSet
== data
->orig_cs
)
530 data
->avail_cs
= data
->orig_cs
;
533 if(data
->avail_cs
== -1) data
->avail_cs
= elf
->lfCharSet
;
537 static void realize_font(OLEFontImpl
*This
)
541 WCHAR text_face
[LF_FACESIZE
];
546 if (!This
->dirty
) return;
552 old_font
= SelectObject(hdc
, This
->gdiFont
);
553 GetTextFaceW(hdc
, ARRAY_SIZE(text_face
), text_face
);
554 SelectObject(hdc
, old_font
);
555 dec_int_ref(This
->gdiFont
);
559 memset(&logFont
, 0, sizeof(LOGFONTW
));
561 lstrcpynW(logFont
.lfFaceName
, This
->description
.lpstrName
, LF_FACESIZE
);
562 logFont
.lfCharSet
= This
->description
.sCharset
;
564 /* If the font name has been changed then enumerate all charsets
565 and pick one that'll result in the font specified being selected */
566 if(text_face
[0] && lstrcmpiW(text_face
, This
->description
.lpstrName
))
569 data
.orig_cs
= This
->description
.sCharset
;
571 logFont
.lfCharSet
= DEFAULT_CHARSET
;
572 EnumFontFamiliesExW(get_dc(), &logFont
, font_enum_proc
, (LPARAM
)&data
, 0);
573 if(data
.avail_cs
!= -1) logFont
.lfCharSet
= data
.avail_cs
;
577 * The height of the font returned by the get_Size property is the
578 * height of the font in points multiplied by 10000... Using some
579 * simple conversions and the ratio given by the application, it can
580 * be converted to a height in pixels.
582 * Standard ratio is 72 / 2540, or 18 / 635 in lowest terms.
583 * Ratio is applied here relative to the standard.
586 fontHeight
= MulDiv( This
->description
.cySize
.Lo
, This
->cyLogical
*635, This
->cyHimetric
*18 );
588 logFont
.lfHeight
= ((fontHeight
%10000L)>5000L) ? (-fontHeight
/10000L) - 1 :
589 (-fontHeight
/10000L);
590 logFont
.lfItalic
= This
->description
.fItalic
;
591 logFont
.lfUnderline
= This
->description
.fUnderline
;
592 logFont
.lfStrikeOut
= This
->description
.fStrikethrough
;
593 logFont
.lfWeight
= This
->description
.sWeight
;
594 logFont
.lfOutPrecision
= OUT_CHARACTER_PRECIS
;
595 logFont
.lfClipPrecision
= CLIP_DEFAULT_PRECIS
;
596 logFont
.lfQuality
= DEFAULT_QUALITY
;
597 logFont
.lfPitchAndFamily
= DEFAULT_PITCH
;
599 This
->gdiFont
= CreateFontIndirectW(&logFont
);
602 add_hfontitem(This
->gdiFont
);
604 /* Fixup the name and charset properties so that they match the
606 old_font
= SelectObject(get_dc(), This
->gdiFont
);
607 GetTextFaceW(hdc
, ARRAY_SIZE(text_face
), text_face
);
608 if(lstrcmpiW(text_face
, This
->description
.lpstrName
))
610 free(This
->description
.lpstrName
);
611 This
->description
.lpstrName
= wcsdup(text_face
);
613 GetTextMetricsW(hdc
, &tm
);
614 This
->description
.sCharset
= tm
.tmCharSet
;
615 /* While we have it handy, stash the realized font height for use by get_Size() */
616 This
->nRealHeight
= tm
.tmHeight
- tm
.tmInternalLeading
; /* corresponds to LOGFONT lfHeight */
617 SelectObject(hdc
, old_font
);
620 /************************************************************************
621 * OLEFontImpl_get_Name (IFont)
623 * See Windows documentation for more details on IFont methods.
625 static HRESULT WINAPI
OLEFontImpl_get_Name(
629 OLEFontImpl
*this = impl_from_IFont(iface
);
630 TRACE("(%p)->(%p)\n", this, pname
);
637 if (this->description
.lpstrName
!=0)
638 *pname
= SysAllocString(this->description
.lpstrName
);
645 /************************************************************************
646 * OLEFontImpl_put_Name (IFont)
648 static HRESULT WINAPI
OLEFontImpl_put_Name(
652 OLEFontImpl
*This
= impl_from_IFont(iface
);
653 TRACE("(%p)->(%p)\n", This
, name
);
656 return CTL_E_INVALIDPROPERTYVALUE
;
658 free(This
->description
.lpstrName
);
659 This
->description
.lpstrName
= wcsdup(name
);
660 if (!This
->description
.lpstrName
) return E_OUTOFMEMORY
;
662 TRACE("new name %s\n", debugstr_w(This
->description
.lpstrName
));
663 OLEFont_SendNotify(This
, DISPID_FONT_NAME
);
667 /************************************************************************
668 * OLEFontImpl_get_Size (IFont)
670 static HRESULT WINAPI
OLEFontImpl_get_Size(
674 OLEFontImpl
*this = impl_from_IFont(iface
);
675 TRACE("(%p)->(%p)\n", this, psize
);
677 if (!psize
) return E_POINTER
;
682 * Convert realized font height in pixels to points descaled by current
683 * scaling ratio then scaled up by 10000.
685 psize
->Lo
= MulDiv(this->nRealHeight
, this->cyHimetric
* 72 * 10000, this->cyLogical
* 2540);
691 static HRESULT WINAPI
OLEFontImpl_put_Size(IFont
*iface
, CY size
)
693 OLEFontImpl
*this = impl_from_IFont(iface
);
694 TRACE("%p, %ld.\n", iface
, size
.Lo
);
695 this->description
.cySize
.Hi
= 0;
696 this->description
.cySize
.Lo
= size
.Lo
;
697 OLEFont_SendNotify(this, DISPID_FONT_SIZE
);
702 static HRESULT WINAPI
OLEFontImpl_get_Bold(IFont
*iface
, BOOL
*pbold
)
704 OLEFontImpl
*this = impl_from_IFont(iface
);
705 TRACE("(%p)->(%p)\n", this, pbold
);
707 if (!pbold
) return E_POINTER
;
711 *pbold
= this->description
.sWeight
> 550;
716 /************************************************************************
717 * OLEFontImpl_put_Bold (IFont)
719 static HRESULT WINAPI
OLEFontImpl_put_Bold(
723 OLEFontImpl
*this = impl_from_IFont(iface
);
724 TRACE("(%p)->(%d)\n", this, bold
);
725 this->description
.sWeight
= bold
? FW_BOLD
: FW_NORMAL
;
726 OLEFont_SendNotify(this, DISPID_FONT_BOLD
);
731 /************************************************************************
732 * OLEFontImpl_get_Italic (IFont)
734 static HRESULT WINAPI
OLEFontImpl_get_Italic(
738 OLEFontImpl
*this = impl_from_IFont(iface
);
739 TRACE("(%p)->(%p)\n", this, pitalic
);
746 *pitalic
= this->description
.fItalic
;
751 /************************************************************************
752 * OLEFontImpl_put_Italic (IFont)
754 static HRESULT WINAPI
OLEFontImpl_put_Italic(
758 OLEFontImpl
*this = impl_from_IFont(iface
);
759 TRACE("(%p)->(%d)\n", this, italic
);
761 this->description
.fItalic
= italic
;
763 OLEFont_SendNotify(this, DISPID_FONT_ITALIC
);
767 /************************************************************************
768 * OLEFontImpl_get_Underline (IFont)
770 static HRESULT WINAPI
OLEFontImpl_get_Underline(
774 OLEFontImpl
*this = impl_from_IFont(iface
);
775 TRACE("(%p)->(%p)\n", this, punderline
);
782 *punderline
= this->description
.fUnderline
;
787 /************************************************************************
788 * OLEFontImpl_put_Underline (IFont)
790 static HRESULT WINAPI
OLEFontImpl_put_Underline(
794 OLEFontImpl
*this = impl_from_IFont(iface
);
795 TRACE("(%p)->(%d)\n", this, underline
);
797 this->description
.fUnderline
= underline
;
799 OLEFont_SendNotify(this, DISPID_FONT_UNDER
);
803 /************************************************************************
804 * OLEFontImpl_get_Strikethrough (IFont)
806 static HRESULT WINAPI
OLEFontImpl_get_Strikethrough(
808 BOOL
* pstrikethrough
)
810 OLEFontImpl
*this = impl_from_IFont(iface
);
811 TRACE("(%p)->(%p)\n", this, pstrikethrough
);
813 if (pstrikethrough
==0)
818 *pstrikethrough
= this->description
.fStrikethrough
;
823 /************************************************************************
824 * OLEFontImpl_put_Strikethrough (IFont)
826 static HRESULT WINAPI
OLEFontImpl_put_Strikethrough(
830 OLEFontImpl
*this = impl_from_IFont(iface
);
831 TRACE("(%p)->(%d)\n", this, strikethrough
);
833 this->description
.fStrikethrough
= strikethrough
;
834 OLEFont_SendNotify(this, DISPID_FONT_STRIKE
);
839 /************************************************************************
840 * OLEFontImpl_get_Weight (IFont)
842 static HRESULT WINAPI
OLEFontImpl_get_Weight(
846 OLEFontImpl
*this = impl_from_IFont(iface
);
847 TRACE("(%p)->(%p)\n", this, pweight
);
854 *pweight
= this->description
.sWeight
;
859 /************************************************************************
860 * OLEFontImpl_put_Weight (IFont)
862 static HRESULT WINAPI
OLEFontImpl_put_Weight(
866 OLEFontImpl
*this = impl_from_IFont(iface
);
867 TRACE("(%p)->(%d)\n", this, weight
);
869 this->description
.sWeight
= weight
;
871 OLEFont_SendNotify(this, DISPID_FONT_WEIGHT
);
875 /************************************************************************
876 * OLEFontImpl_get_Charset (IFont)
878 static HRESULT WINAPI
OLEFontImpl_get_Charset(
882 OLEFontImpl
*this = impl_from_IFont(iface
);
883 TRACE("(%p)->(%p)\n", this, pcharset
);
890 *pcharset
= this->description
.sCharset
;
895 /************************************************************************
896 * OLEFontImpl_put_Charset (IFont)
898 static HRESULT WINAPI
OLEFontImpl_put_Charset(
902 OLEFontImpl
*this = impl_from_IFont(iface
);
903 TRACE("(%p)->(%d)\n", this, charset
);
905 this->description
.sCharset
= charset
;
906 OLEFont_SendNotify(this, DISPID_FONT_CHARSET
);
911 /************************************************************************
912 * OLEFontImpl_get_hFont (IFont)
914 static HRESULT WINAPI
OLEFontImpl_get_hFont(
918 OLEFontImpl
*this = impl_from_IFont(iface
);
919 TRACE("(%p)->(%p)\n", this, phfont
);
925 *phfont
= this->gdiFont
;
926 TRACE("Returning %p\n", *phfont
);
930 /************************************************************************
931 * OLEFontImpl_Clone (IFont)
933 static HRESULT WINAPI
OLEFontImpl_Clone(
937 OLEFontImpl
*this = impl_from_IFont(iface
);
938 OLEFontImpl
* newObject
;
940 TRACE("(%p)->(%p)\n", this, ppfont
);
947 newObject
= malloc(sizeof(OLEFontImpl
));
949 return E_OUTOFMEMORY
;
952 /* allocate separate buffer */
953 newObject
->description
.lpstrName
= wcsdup(this->description
.lpstrName
);
955 /* Increment internal ref in hfont item list */
956 if(newObject
->gdiFont
) inc_int_ref(newObject
->gdiFont
);
958 InterlockedIncrement(&ifont_cnt
);
960 newObject
->pPropertyNotifyCP
= NULL
;
961 newObject
->pFontEventsCP
= NULL
;
962 CreateConnectionPoint((IUnknown
*)&newObject
->IFont_iface
, &IID_IPropertyNotifySink
,
963 &newObject
->pPropertyNotifyCP
);
964 CreateConnectionPoint((IUnknown
*)&newObject
->IFont_iface
, &IID_IFontEventsDisp
,
965 &newObject
->pFontEventsCP
);
967 if (!newObject
->pPropertyNotifyCP
|| !newObject
->pFontEventsCP
)
969 OLEFontImpl_Destroy(newObject
);
970 return E_OUTOFMEMORY
;
973 /* The cloned object starts with a reference count of 1 */
976 *ppfont
= &newObject
->IFont_iface
;
981 /************************************************************************
982 * OLEFontImpl_IsEqual (IFont)
984 static HRESULT WINAPI
OLEFontImpl_IsEqual(
988 OLEFontImpl
*left
= impl_from_IFont(iface
);
989 OLEFontImpl
*right
= impl_from_IFont(pFontOther
);
991 INT left_len
,right_len
;
993 if(pFontOther
== NULL
)
995 else if (left
->description
.cySize
.Lo
!= right
->description
.cySize
.Lo
)
997 else if (left
->description
.cySize
.Hi
!= right
->description
.cySize
.Hi
)
999 else if (left
->description
.sWeight
!= right
->description
.sWeight
)
1001 else if (left
->description
.sCharset
!= right
->description
.sCharset
)
1003 else if (left
->description
.fItalic
!= right
->description
.fItalic
)
1005 else if (left
->description
.fUnderline
!= right
->description
.fUnderline
)
1007 else if (left
->description
.fStrikethrough
!= right
->description
.fStrikethrough
)
1010 /* Check from string */
1011 left_len
= lstrlenW(left
->description
.lpstrName
);
1012 right_len
= lstrlenW(right
->description
.lpstrName
);
1013 ret
= CompareStringW(0,0,left
->description
.lpstrName
, left_len
,
1014 right
->description
.lpstrName
, right_len
);
1015 if (ret
!= CSTR_EQUAL
)
1021 /************************************************************************
1022 * OLEFontImpl_SetRatio (IFont)
1024 static HRESULT WINAPI
OLEFontImpl_SetRatio(
1029 OLEFontImpl
*this = impl_from_IFont(iface
);
1031 TRACE("%p, %ld, %ld.\n", iface
, cyLogical
, cyHimetric
);
1033 if(cyLogical
== 0 || cyHimetric
== 0)
1036 /* cyLogical and cyHimetric both set to 1 is a special case that
1037 does not change the scaling but also does not fail */
1038 if(cyLogical
== 1 && cyHimetric
== 1)
1041 this->cyLogical
= cyLogical
;
1042 this->cyHimetric
= cyHimetric
;
1048 /************************************************************************
1049 * OLEFontImpl_QueryTextMetrics (IFont)
1051 static HRESULT WINAPI
OLEFontImpl_QueryTextMetrics(
1056 HFONT hOldFont
, hNewFont
;
1059 IFont_get_hFont(iface
, &hNewFont
);
1060 hOldFont
= SelectObject(hdcRef
, hNewFont
);
1061 GetTextMetricsW(hdcRef
, ptm
);
1062 SelectObject(hdcRef
, hOldFont
);
1063 ReleaseDC(0, hdcRef
);
1067 /************************************************************************
1068 * OLEFontImpl_AddRefHfont (IFont)
1070 static HRESULT WINAPI
OLEFontImpl_AddRefHfont(
1074 OLEFontImpl
*this = impl_from_IFont(iface
);
1076 TRACE("(%p)->(%p)\n", this, hfont
);
1078 if (!hfont
) return E_INVALIDARG
;
1080 return inc_ext_ref(hfont
);
1083 /************************************************************************
1084 * OLEFontImpl_ReleaseHfont (IFont)
1086 static HRESULT WINAPI
OLEFontImpl_ReleaseHfont(
1090 OLEFontImpl
*this = impl_from_IFont(iface
);
1092 TRACE("(%p)->(%p)\n", this, hfont
);
1094 if (!hfont
) return E_INVALIDARG
;
1096 return dec_ext_ref(hfont
);
1099 /************************************************************************
1100 * OLEFontImpl_SetHdc (IFont)
1102 static HRESULT WINAPI
OLEFontImpl_SetHdc(
1106 OLEFontImpl
*this = impl_from_IFont(iface
);
1107 FIXME("(%p)->(%p): Stub\n", this, hdc
);
1111 static const IFontVtbl OLEFontImpl_VTable
=
1113 OLEFontImpl_QueryInterface
,
1115 OLEFontImpl_Release
,
1116 OLEFontImpl_get_Name
,
1117 OLEFontImpl_put_Name
,
1118 OLEFontImpl_get_Size
,
1119 OLEFontImpl_put_Size
,
1120 OLEFontImpl_get_Bold
,
1121 OLEFontImpl_put_Bold
,
1122 OLEFontImpl_get_Italic
,
1123 OLEFontImpl_put_Italic
,
1124 OLEFontImpl_get_Underline
,
1125 OLEFontImpl_put_Underline
,
1126 OLEFontImpl_get_Strikethrough
,
1127 OLEFontImpl_put_Strikethrough
,
1128 OLEFontImpl_get_Weight
,
1129 OLEFontImpl_put_Weight
,
1130 OLEFontImpl_get_Charset
,
1131 OLEFontImpl_put_Charset
,
1132 OLEFontImpl_get_hFont
,
1134 OLEFontImpl_IsEqual
,
1135 OLEFontImpl_SetRatio
,
1136 OLEFontImpl_QueryTextMetrics
,
1137 OLEFontImpl_AddRefHfont
,
1138 OLEFontImpl_ReleaseHfont
,
1142 /************************************************************************
1143 * OLEFontImpl_IDispatch_QueryInterface (IUnknown)
1145 static HRESULT WINAPI
OLEFontImpl_IDispatch_QueryInterface(
1150 OLEFontImpl
*this = impl_from_IDispatch(iface
);
1151 return IFont_QueryInterface(&this->IFont_iface
, riid
, ppvoid
);
1154 /************************************************************************
1155 * OLEFontImpl_IDispatch_Release (IUnknown)
1157 static ULONG WINAPI
OLEFontImpl_IDispatch_Release(
1160 OLEFontImpl
*this = impl_from_IDispatch(iface
);
1161 return IFont_Release(&this->IFont_iface
);
1164 /************************************************************************
1165 * OLEFontImpl_IDispatch_AddRef (IUnknown)
1167 static ULONG WINAPI
OLEFontImpl_IDispatch_AddRef(
1170 OLEFontImpl
*this = impl_from_IDispatch(iface
);
1171 return IFont_AddRef(&this->IFont_iface
);
1174 /************************************************************************
1175 * OLEFontImpl_GetTypeInfoCount (IDispatch)
1177 static HRESULT WINAPI
OLEFontImpl_GetTypeInfoCount(
1179 unsigned int* pctinfo
)
1181 OLEFontImpl
*this = impl_from_IDispatch(iface
);
1182 TRACE("(%p)->(%p)\n", this, pctinfo
);
1188 /************************************************************************
1189 * OLEFontImpl_GetTypeInfo (IDispatch)
1191 static HRESULT WINAPI
OLEFontImpl_GetTypeInfo(
1195 ITypeInfo
** ppTInfo
)
1200 OLEFontImpl
*this = impl_from_IDispatch(iface
);
1201 TRACE("(%p, iTInfo=%d, lcid=%04x, %p)\n", this, iTInfo
, (int)lcid
, ppTInfo
);
1204 hres
= LoadTypeLib(L
"stdole2.tlb", &tl
);
1206 ERR("Could not load the stdole2.tlb?\n");
1209 hres
= ITypeLib_GetTypeInfoOfGuid(tl
, &IID_IFontDisp
, ppTInfo
);
1210 ITypeLib_Release(tl
);
1212 FIXME("Did not IDispatch typeinfo from typelib, hres %#lx.\n", hres
);
1217 /************************************************************************
1218 * OLEFontImpl_GetIDsOfNames (IDispatch)
1220 static HRESULT WINAPI
OLEFontImpl_GetIDsOfNames(
1223 LPOLESTR
* rgszNames
,
1231 OLEFontImpl
*this = impl_from_IDispatch(iface
);
1233 TRACE("(%p,%s,%p,cNames=%d,lcid=%04x,%p)\n", this, debugstr_guid(riid
),
1234 rgszNames
, cNames
, (int)lcid
, rgDispId
);
1236 if (cNames
== 0) return E_INVALIDARG
;
1238 hres
= IDispatch_GetTypeInfo(iface
, 0, lcid
, &pTInfo
);
1241 ERR("GetTypeInfo failed.\n");
1245 /* convert names to DISPIDs */
1246 hres
= DispGetIDsOfNames (pTInfo
, rgszNames
, cNames
, rgDispId
);
1247 ITypeInfo_Release(pTInfo
);
1252 /************************************************************************
1253 * OLEFontImpl_Invoke (IDispatch)
1256 static HRESULT WINAPI
OLEFontImpl_Invoke(
1258 DISPID dispIdMember
,
1262 DISPPARAMS
* pDispParams
,
1263 VARIANT
* pVarResult
,
1264 EXCEPINFO
* pExepInfo
,
1267 OLEFontImpl
*this = impl_from_IDispatch(iface
);
1270 TRACE("%p, %ld, %s, %#lx, %#x, %p, %p, %p, %p.\n", iface
, dispIdMember
,
1271 debugstr_guid(riid
), lcid
, wFlags
, pDispParams
, pVarResult
, pExepInfo
,
1274 /* validate parameters */
1276 if (!IsEqualIID(riid
, &IID_NULL
))
1278 ERR("riid was %s instead of IID_NULL\n", debugstr_guid(riid
));
1279 return DISP_E_UNKNOWNINTERFACE
;
1282 if (wFlags
& DISPATCH_PROPERTYGET
)
1286 ERR("null pVarResult not allowed when DISPATCH_PROPERTYGET specified\n");
1287 return DISP_E_PARAMNOTOPTIONAL
;
1290 else if (wFlags
& DISPATCH_PROPERTYPUT
)
1294 ERR("null pDispParams not allowed when DISPATCH_PROPERTYPUT specified\n");
1295 return DISP_E_PARAMNOTOPTIONAL
;
1297 if (pDispParams
->cArgs
!= 1)
1299 ERR("param count for DISPATCH_PROPERTYPUT was %d instead of 1\n", pDispParams
->cArgs
);
1300 return DISP_E_BADPARAMCOUNT
;
1305 ERR("one of DISPATCH_PROPERTYGET or DISPATCH_PROPERTYPUT must be specified\n");
1306 return DISP_E_MEMBERNOTFOUND
;
1309 switch (dispIdMember
) {
1310 case DISPID_FONT_NAME
:
1311 if (wFlags
& DISPATCH_PROPERTYGET
) {
1312 V_VT(pVarResult
) = VT_BSTR
;
1313 return IFont_get_Name(&this->IFont_iface
, &V_BSTR(pVarResult
));
1317 VariantInit(&vararg
);
1318 hr
= VariantChangeTypeEx(&vararg
, &pDispParams
->rgvarg
[0], lcid
, 0, VT_BSTR
);
1322 hr
= IFont_put_Name(&this->IFont_iface
, V_BSTR(&vararg
));
1324 VariantClear(&vararg
);
1328 case DISPID_FONT_BOLD
:
1329 if (wFlags
& DISPATCH_PROPERTYGET
) {
1331 hr
= IFont_get_Bold(&this->IFont_iface
, &value
);
1332 V_VT(pVarResult
) = VT_BOOL
;
1333 V_BOOL(pVarResult
) = value
? VARIANT_TRUE
: VARIANT_FALSE
;
1338 VariantInit(&vararg
);
1339 hr
= VariantChangeTypeEx(&vararg
, &pDispParams
->rgvarg
[0], lcid
, 0, VT_BOOL
);
1343 hr
= IFont_put_Bold(&this->IFont_iface
, V_BOOL(&vararg
));
1345 VariantClear(&vararg
);
1349 case DISPID_FONT_ITALIC
:
1350 if (wFlags
& DISPATCH_PROPERTYGET
) {
1352 hr
= IFont_get_Italic(&this->IFont_iface
, &value
);
1353 V_VT(pVarResult
) = VT_BOOL
;
1354 V_BOOL(pVarResult
) = value
? VARIANT_TRUE
: VARIANT_FALSE
;
1359 VariantInit(&vararg
);
1360 hr
= VariantChangeTypeEx(&vararg
, &pDispParams
->rgvarg
[0], lcid
, 0, VT_BOOL
);
1364 hr
= IFont_put_Italic(&this->IFont_iface
, V_BOOL(&vararg
));
1366 VariantClear(&vararg
);
1370 case DISPID_FONT_UNDER
:
1371 if (wFlags
& DISPATCH_PROPERTYGET
) {
1373 hr
= IFont_get_Underline(&this->IFont_iface
, &value
);
1374 V_VT(pVarResult
) = VT_BOOL
;
1375 V_BOOL(pVarResult
) = value
? VARIANT_TRUE
: VARIANT_FALSE
;
1380 VariantInit(&vararg
);
1381 hr
= VariantChangeTypeEx(&vararg
, &pDispParams
->rgvarg
[0], lcid
, 0, VT_BOOL
);
1385 hr
= IFont_put_Underline(&this->IFont_iface
, V_BOOL(&vararg
));
1387 VariantClear(&vararg
);
1391 case DISPID_FONT_STRIKE
:
1392 if (wFlags
& DISPATCH_PROPERTYGET
) {
1394 hr
= IFont_get_Strikethrough(&this->IFont_iface
, &value
);
1395 V_VT(pVarResult
) = VT_BOOL
;
1396 V_BOOL(pVarResult
) = value
? VARIANT_TRUE
: VARIANT_FALSE
;
1401 VariantInit(&vararg
);
1402 hr
= VariantChangeTypeEx(&vararg
, &pDispParams
->rgvarg
[0], lcid
, 0, VT_BOOL
);
1406 hr
= IFont_put_Strikethrough(&this->IFont_iface
, V_BOOL(&vararg
));
1408 VariantClear(&vararg
);
1412 case DISPID_FONT_SIZE
:
1413 if (wFlags
& DISPATCH_PROPERTYGET
) {
1414 V_VT(pVarResult
) = VT_CY
;
1415 return IFont_get_Size(&this->IFont_iface
, &V_CY(pVarResult
));
1419 VariantInit(&vararg
);
1420 hr
= VariantChangeTypeEx(&vararg
, &pDispParams
->rgvarg
[0], lcid
, 0, VT_CY
);
1424 hr
= IFont_put_Size(&this->IFont_iface
, V_CY(&vararg
));
1426 VariantClear(&vararg
);
1430 case DISPID_FONT_WEIGHT
:
1431 if (wFlags
& DISPATCH_PROPERTYGET
) {
1432 V_VT(pVarResult
) = VT_I2
;
1433 return IFont_get_Weight(&this->IFont_iface
, &V_I2(pVarResult
));
1437 VariantInit(&vararg
);
1438 hr
= VariantChangeTypeEx(&vararg
, &pDispParams
->rgvarg
[0], lcid
, 0, VT_I2
);
1442 hr
= IFont_put_Weight(&this->IFont_iface
, V_I2(&vararg
));
1444 VariantClear(&vararg
);
1448 case DISPID_FONT_CHARSET
:
1449 if (wFlags
& DISPATCH_PROPERTYGET
) {
1450 V_VT(pVarResult
) = VT_I2
;
1451 return OLEFontImpl_get_Charset(&this->IFont_iface
, &V_I2(pVarResult
));
1455 VariantInit(&vararg
);
1456 hr
= VariantChangeTypeEx(&vararg
, &pDispParams
->rgvarg
[0], lcid
, 0, VT_I2
);
1460 hr
= IFont_put_Charset(&this->IFont_iface
, V_I2(&vararg
));
1462 VariantClear(&vararg
);
1467 ERR("member not found for dispid %#lx.\n", dispIdMember
);
1468 return DISP_E_MEMBERNOTFOUND
;
1472 static const IDispatchVtbl OLEFontImpl_IDispatch_VTable
=
1474 OLEFontImpl_IDispatch_QueryInterface
,
1475 OLEFontImpl_IDispatch_AddRef
,
1476 OLEFontImpl_IDispatch_Release
,
1477 OLEFontImpl_GetTypeInfoCount
,
1478 OLEFontImpl_GetTypeInfo
,
1479 OLEFontImpl_GetIDsOfNames
,
1483 /************************************************************************
1484 * OLEFontImpl_IPersistStream_QueryInterface (IUnknown)
1486 static HRESULT WINAPI
OLEFontImpl_IPersistStream_QueryInterface(
1487 IPersistStream
* iface
,
1491 OLEFontImpl
*this = impl_from_IPersistStream(iface
);
1493 return IFont_QueryInterface(&this->IFont_iface
, riid
, ppvoid
);
1496 /************************************************************************
1497 * OLEFontImpl_IPersistStream_Release (IUnknown)
1499 static ULONG WINAPI
OLEFontImpl_IPersistStream_Release(
1500 IPersistStream
* iface
)
1502 OLEFontImpl
*this = impl_from_IPersistStream(iface
);
1504 return IFont_Release(&this->IFont_iface
);
1507 /************************************************************************
1508 * OLEFontImpl_IPersistStream_AddRef (IUnknown)
1510 static ULONG WINAPI
OLEFontImpl_IPersistStream_AddRef(
1511 IPersistStream
* iface
)
1513 OLEFontImpl
*this = impl_from_IPersistStream(iface
);
1515 return IFont_AddRef(&this->IFont_iface
);
1518 /************************************************************************
1519 * OLEFontImpl_GetClassID (IPersistStream)
1521 static HRESULT WINAPI
OLEFontImpl_GetClassID(
1522 IPersistStream
* iface
,
1525 TRACE("(%p,%p)\n",iface
,pClassID
);
1529 *pClassID
= CLSID_StdFont
;
1534 /************************************************************************
1535 * OLEFontImpl_IsDirty (IPersistStream)
1537 * See Windows documentation for more details on IPersistStream methods.
1539 static HRESULT WINAPI
OLEFontImpl_IsDirty(
1540 IPersistStream
* iface
)
1542 TRACE("(%p)\n",iface
);
1546 /************************************************************************
1547 * OLEFontImpl_Load (IPersistStream)
1549 * See Windows documentation for more details on IPersistStream methods.
1551 * This is the format of the standard font serialization as far as I
1554 * Offset Type Value Comment
1555 * 0x0000 Byte Unknown Probably a version number, contains 0x01
1556 * 0x0001 Short Charset Charset value from the FONTDESC structure
1557 * 0x0003 Byte Attributes Flags defined as follows:
1559 * 00000100 - Underline
1560 * 00001000 - Strikethrough
1561 * 0x0004 Short Weight Weight value from FONTDESC structure
1562 * 0x0006 DWORD size "Low" portion of the cySize member of the FONTDESC
1564 * 0x000A Byte name length Length of the font name string (no null character)
1565 * 0x000B String name Name of the font (ASCII, no nul character)
1567 static HRESULT WINAPI
OLEFontImpl_Load(
1568 IPersistStream
* iface
,
1569 IStream
* pLoadStream
)
1571 OLEFontImpl
*this = impl_from_IPersistStream(iface
);
1572 BYTE version
, attributes
, string_size
;
1573 char readBuffer
[0x100];
1578 IStream_Read(pLoadStream
, &version
, sizeof(BYTE
), &cbRead
);
1579 if ((cbRead
!= sizeof(BYTE
)) || (version
!= 0x01)) return E_FAIL
;
1582 IStream_Read(pLoadStream
, &this->description
.sCharset
, sizeof(WORD
), &cbRead
);
1583 if (cbRead
!= sizeof(WORD
)) return E_FAIL
;
1586 IStream_Read(pLoadStream
, &attributes
, sizeof(BYTE
), &cbRead
);
1587 if (cbRead
!= sizeof(BYTE
)) return E_FAIL
;
1589 this->description
.fItalic
= (attributes
& FONTPERSIST_ITALIC
) != 0;
1590 this->description
.fStrikethrough
= (attributes
& FONTPERSIST_STRIKETHROUGH
) != 0;
1591 this->description
.fUnderline
= (attributes
& FONTPERSIST_UNDERLINE
) != 0;
1594 IStream_Read(pLoadStream
, &this->description
.sWeight
, sizeof(WORD
), &cbRead
);
1595 if (cbRead
!= sizeof(WORD
)) return E_FAIL
;
1598 IStream_Read(pLoadStream
, &this->description
.cySize
.Lo
, sizeof(DWORD
), &cbRead
);
1599 if (cbRead
!= sizeof(DWORD
)) return E_FAIL
;
1601 this->description
.cySize
.Hi
= 0;
1604 IStream_Read(pLoadStream
, &string_size
, sizeof(BYTE
), &cbRead
);
1605 if (cbRead
!= sizeof(BYTE
)) return E_FAIL
;
1607 IStream_Read(pLoadStream
, readBuffer
, string_size
, &cbRead
);
1608 if (cbRead
!= string_size
) return E_FAIL
;
1610 free(this->description
.lpstrName
);
1612 len
= MultiByteToWideChar( CP_ACP
, 0, readBuffer
, string_size
, NULL
, 0 );
1613 this->description
.lpstrName
= malloc((len
+ 1) * sizeof(WCHAR
));
1614 MultiByteToWideChar( CP_ACP
, 0, readBuffer
, string_size
, this->description
.lpstrName
, len
);
1615 this->description
.lpstrName
[len
] = 0;
1617 /* Ensure use of this font causes a new one to be created */
1618 dec_int_ref(this->gdiFont
);
1625 /************************************************************************
1626 * OLEFontImpl_Save (IPersistStream)
1628 static HRESULT WINAPI
OLEFontImpl_Save(
1629 IPersistStream
* iface
,
1630 IStream
* pOutStream
,
1633 OLEFontImpl
*this = impl_from_IPersistStream(iface
);
1634 BYTE attributes
, string_size
;
1635 const BYTE version
= 0x01;
1636 char* writeBuffer
= NULL
;
1639 TRACE("(%p)->(%p %d)\n", this, pOutStream
, fClearDirty
);
1642 IStream_Write(pOutStream
, &version
, sizeof(BYTE
), &written
);
1643 if (written
!= sizeof(BYTE
)) return E_FAIL
;
1646 IStream_Write(pOutStream
, &this->description
.sCharset
, sizeof(WORD
), &written
);
1647 if (written
!= sizeof(WORD
)) return E_FAIL
;
1652 if (this->description
.fItalic
)
1653 attributes
|= FONTPERSIST_ITALIC
;
1655 if (this->description
.fStrikethrough
)
1656 attributes
|= FONTPERSIST_STRIKETHROUGH
;
1658 if (this->description
.fUnderline
)
1659 attributes
|= FONTPERSIST_UNDERLINE
;
1661 IStream_Write(pOutStream
, &attributes
, sizeof(BYTE
), &written
);
1662 if (written
!= sizeof(BYTE
)) return E_FAIL
;
1665 IStream_Write(pOutStream
, &this->description
.sWeight
, sizeof(WORD
), &written
);
1666 if (written
!= sizeof(WORD
)) return E_FAIL
;
1669 IStream_Write(pOutStream
, &this->description
.cySize
.Lo
, sizeof(DWORD
), &written
);
1670 if (written
!= sizeof(DWORD
)) return E_FAIL
;
1673 if (this->description
.lpstrName
)
1674 string_size
= WideCharToMultiByte( CP_ACP
, 0, this->description
.lpstrName
,
1675 lstrlenW(this->description
.lpstrName
), NULL
, 0, NULL
, NULL
);
1679 IStream_Write(pOutStream
, &string_size
, sizeof(BYTE
), &written
);
1680 if (written
!= sizeof(BYTE
)) return E_FAIL
;
1684 if (!(writeBuffer
= malloc(string_size
))) return E_OUTOFMEMORY
;
1685 WideCharToMultiByte( CP_ACP
, 0, this->description
.lpstrName
,
1686 lstrlenW(this->description
.lpstrName
),
1687 writeBuffer
, string_size
, NULL
, NULL
);
1689 IStream_Write(pOutStream
, writeBuffer
, string_size
, &written
);
1692 if (written
!= string_size
) return E_FAIL
;
1698 /************************************************************************
1699 * OLEFontImpl_GetSizeMax (IPersistStream)
1701 static HRESULT WINAPI
OLEFontImpl_GetSizeMax(
1702 IPersistStream
* iface
,
1703 ULARGE_INTEGER
* pcbSize
)
1705 OLEFontImpl
*this = impl_from_IPersistStream(iface
);
1710 pcbSize
->u
.HighPart
= 0;
1711 pcbSize
->u
.LowPart
= 0;
1713 pcbSize
->u
.LowPart
+= sizeof(BYTE
); /* Version */
1714 pcbSize
->u
.LowPart
+= sizeof(WORD
); /* Lang code */
1715 pcbSize
->u
.LowPart
+= sizeof(BYTE
); /* Flags */
1716 pcbSize
->u
.LowPart
+= sizeof(WORD
); /* Weight */
1717 pcbSize
->u
.LowPart
+= sizeof(DWORD
); /* Size */
1718 pcbSize
->u
.LowPart
+= sizeof(BYTE
); /* StrLength */
1720 if (this->description
.lpstrName
!=0)
1721 pcbSize
->u
.LowPart
+= WideCharToMultiByte( CP_ACP
, 0, this->description
.lpstrName
,
1722 lstrlenW(this->description
.lpstrName
),
1723 NULL
, 0, NULL
, NULL
);
1728 static const IPersistStreamVtbl OLEFontImpl_IPersistStream_VTable
=
1730 OLEFontImpl_IPersistStream_QueryInterface
,
1731 OLEFontImpl_IPersistStream_AddRef
,
1732 OLEFontImpl_IPersistStream_Release
,
1733 OLEFontImpl_GetClassID
,
1734 OLEFontImpl_IsDirty
,
1737 OLEFontImpl_GetSizeMax
1740 /************************************************************************
1741 * OLEFontImpl_IConnectionPointContainer_QueryInterface (IUnknown)
1743 static HRESULT WINAPI
OLEFontImpl_IConnectionPointContainer_QueryInterface(
1744 IConnectionPointContainer
* iface
,
1748 OLEFontImpl
*this = impl_from_IConnectionPointContainer(iface
);
1750 return IFont_QueryInterface(&this->IFont_iface
, riid
, ppvoid
);
1753 /************************************************************************
1754 * OLEFontImpl_IConnectionPointContainer_Release (IUnknown)
1756 static ULONG WINAPI
OLEFontImpl_IConnectionPointContainer_Release(
1757 IConnectionPointContainer
* iface
)
1759 OLEFontImpl
*this = impl_from_IConnectionPointContainer(iface
);
1761 return IFont_Release(&this->IFont_iface
);
1764 /************************************************************************
1765 * OLEFontImpl_IConnectionPointContainer_AddRef (IUnknown)
1767 static ULONG WINAPI
OLEFontImpl_IConnectionPointContainer_AddRef(
1768 IConnectionPointContainer
* iface
)
1770 OLEFontImpl
*this = impl_from_IConnectionPointContainer(iface
);
1772 return IFont_AddRef(&this->IFont_iface
);
1775 /************************************************************************
1776 * OLEFontImpl_EnumConnectionPoints (IConnectionPointContainer)
1778 static HRESULT WINAPI
OLEFontImpl_EnumConnectionPoints(
1779 IConnectionPointContainer
* iface
,
1780 IEnumConnectionPoints
**ppEnum
)
1782 OLEFontImpl
*this = impl_from_IConnectionPointContainer(iface
);
1784 FIXME("(%p)->(%p): stub\n", this, ppEnum
);
1788 /************************************************************************
1789 * OLEFontImpl_FindConnectionPoint (IConnectionPointContainer)
1791 static HRESULT WINAPI
OLEFontImpl_FindConnectionPoint(
1792 IConnectionPointContainer
* iface
,
1794 IConnectionPoint
**ppCp
)
1796 OLEFontImpl
*this = impl_from_IConnectionPointContainer(iface
);
1797 TRACE("(%p)->(%s, %p)\n", this, debugstr_guid(riid
), ppCp
);
1799 if(IsEqualIID(riid
, &IID_IPropertyNotifySink
)) {
1800 return IConnectionPoint_QueryInterface(this->pPropertyNotifyCP
, &IID_IConnectionPoint
,
1802 } else if(IsEqualIID(riid
, &IID_IFontEventsDisp
)) {
1803 return IConnectionPoint_QueryInterface(this->pFontEventsCP
, &IID_IConnectionPoint
,
1806 FIXME("no connection point for %s\n", debugstr_guid(riid
));
1807 return CONNECT_E_NOCONNECTION
;
1811 static const IConnectionPointContainerVtbl
1812 OLEFontImpl_IConnectionPointContainer_VTable
=
1814 OLEFontImpl_IConnectionPointContainer_QueryInterface
,
1815 OLEFontImpl_IConnectionPointContainer_AddRef
,
1816 OLEFontImpl_IConnectionPointContainer_Release
,
1817 OLEFontImpl_EnumConnectionPoints
,
1818 OLEFontImpl_FindConnectionPoint
1821 /************************************************************************
1822 * OLEFontImpl implementation of IPersistPropertyBag.
1824 static HRESULT WINAPI
OLEFontImpl_IPersistPropertyBag_QueryInterface(
1825 IPersistPropertyBag
*iface
, REFIID riid
, LPVOID
*ppvObj
1827 OLEFontImpl
*this = impl_from_IPersistPropertyBag(iface
);
1828 return IFont_QueryInterface(&this->IFont_iface
,riid
,ppvObj
);
1831 static ULONG WINAPI
OLEFontImpl_IPersistPropertyBag_AddRef(
1832 IPersistPropertyBag
*iface
1834 OLEFontImpl
*this = impl_from_IPersistPropertyBag(iface
);
1835 return IFont_AddRef(&this->IFont_iface
);
1838 static ULONG WINAPI
OLEFontImpl_IPersistPropertyBag_Release(
1839 IPersistPropertyBag
*iface
1841 OLEFontImpl
*this = impl_from_IPersistPropertyBag(iface
);
1842 return IFont_Release(&this->IFont_iface
);
1845 static HRESULT WINAPI
OLEFontImpl_IPersistPropertyBag_GetClassID(
1846 IPersistPropertyBag
*iface
, CLSID
*classid
1848 FIXME("(%p,%p), stub!\n", iface
, classid
);
1852 static HRESULT WINAPI
OLEFontImpl_IPersistPropertyBag_InitNew(
1853 IPersistPropertyBag
*iface
1855 FIXME("(%p), stub!\n", iface
);
1859 static HRESULT WINAPI
OLEFontImpl_IPersistPropertyBag_Load(
1860 IPersistPropertyBag
*iface
, IPropertyBag
* pPropBag
, IErrorLog
* pErrorLog
1862 /* (from Visual Basic 6 property bag)
1863 Name = "MS Sans Serif"
1867 Underline = 0 'False
1869 Strikethrough = 0 'False
1871 OLEFontImpl
*this = impl_from_IPersistPropertyBag(iface
);
1875 VariantInit(&value
);
1877 iRes
= IPropertyBag_Read(pPropBag
, L
"Name", &value
, pErrorLog
);
1880 iRes
= VariantChangeType(&value
, &value
, 0, VT_BSTR
);
1882 iRes
= IFont_put_Name(&this->IFont_iface
, V_BSTR(&value
));
1884 else if (iRes
== E_INVALIDARG
)
1887 VariantClear(&value
);
1890 iRes
= IPropertyBag_Read(pPropBag
, L
"Size", &value
, pErrorLog
);
1893 iRes
= VariantChangeType(&value
, &value
, 0, VT_CY
);
1895 iRes
= IFont_put_Size(&this->IFont_iface
, V_CY(&value
));
1897 else if (iRes
== E_INVALIDARG
)
1900 VariantClear(&value
);
1904 iRes
= IPropertyBag_Read(pPropBag
, L
"Charset", &value
, pErrorLog
);
1907 iRes
= VariantChangeType(&value
, &value
, 0, VT_I2
);
1909 iRes
= IFont_put_Charset(&this->IFont_iface
, V_I2(&value
));
1911 else if (iRes
== E_INVALIDARG
)
1914 VariantClear(&value
);
1918 iRes
= IPropertyBag_Read(pPropBag
, L
"Weight", &value
, pErrorLog
);
1921 iRes
= VariantChangeType(&value
, &value
, 0, VT_I2
);
1923 iRes
= IFont_put_Weight(&this->IFont_iface
, V_I2(&value
));
1925 else if (iRes
== E_INVALIDARG
)
1928 VariantClear(&value
);
1932 iRes
= IPropertyBag_Read(pPropBag
, L
"Underline", &value
, pErrorLog
);
1935 iRes
= VariantChangeType(&value
, &value
, 0, VT_BOOL
);
1937 iRes
= IFont_put_Underline(&this->IFont_iface
, V_BOOL(&value
));
1939 else if (iRes
== E_INVALIDARG
)
1942 VariantClear(&value
);
1946 iRes
= IPropertyBag_Read(pPropBag
, L
"Italic", &value
, pErrorLog
);
1949 iRes
= VariantChangeType(&value
, &value
, 0, VT_BOOL
);
1951 iRes
= IFont_put_Italic(&this->IFont_iface
, V_BOOL(&value
));
1953 else if (iRes
== E_INVALIDARG
)
1956 VariantClear(&value
);
1960 iRes
= IPropertyBag_Read(pPropBag
, L
"Strikethrough", &value
, pErrorLog
);
1963 iRes
= VariantChangeType(&value
, &value
, 0, VT_BOOL
);
1965 IFont_put_Strikethrough(&this->IFont_iface
, V_BOOL(&value
));
1967 else if (iRes
== E_INVALIDARG
)
1970 VariantClear(&value
);
1974 WARN("-- %#lx.\n", iRes
);
1978 static HRESULT WINAPI
OLEFontImpl_IPersistPropertyBag_Save(
1979 IPersistPropertyBag
*iface
, IPropertyBag
* pPropBag
, BOOL fClearDirty
,
1980 BOOL fSaveAllProperties
1982 FIXME("(%p,%p,%d,%d), stub!\n", iface
, pPropBag
, fClearDirty
, fSaveAllProperties
);
1986 static const IPersistPropertyBagVtbl OLEFontImpl_IPersistPropertyBag_VTable
=
1988 OLEFontImpl_IPersistPropertyBag_QueryInterface
,
1989 OLEFontImpl_IPersistPropertyBag_AddRef
,
1990 OLEFontImpl_IPersistPropertyBag_Release
,
1992 OLEFontImpl_IPersistPropertyBag_GetClassID
,
1993 OLEFontImpl_IPersistPropertyBag_InitNew
,
1994 OLEFontImpl_IPersistPropertyBag_Load
,
1995 OLEFontImpl_IPersistPropertyBag_Save
1998 /************************************************************************
1999 * OLEFontImpl_Construct
2001 * This method will construct a new instance of the OLEFontImpl
2004 * The caller of this method must release the object when it's
2007 static OLEFontImpl
* OLEFontImpl_Construct(const FONTDESC
*fontDesc
)
2009 OLEFontImpl
* newObject
;
2011 newObject
= malloc(sizeof(OLEFontImpl
));
2016 newObject
->IFont_iface
.lpVtbl
= &OLEFontImpl_VTable
;
2017 newObject
->IDispatch_iface
.lpVtbl
= &OLEFontImpl_IDispatch_VTable
;
2018 newObject
->IPersistStream_iface
.lpVtbl
= &OLEFontImpl_IPersistStream_VTable
;
2019 newObject
->IConnectionPointContainer_iface
.lpVtbl
= &OLEFontImpl_IConnectionPointContainer_VTable
;
2020 newObject
->IPersistPropertyBag_iface
.lpVtbl
= &OLEFontImpl_IPersistPropertyBag_VTable
;
2024 newObject
->description
.cbSizeofstruct
= sizeof(FONTDESC
);
2025 newObject
->description
.lpstrName
= wcsdup(fontDesc
->lpstrName
);
2026 newObject
->description
.cySize
= fontDesc
->cySize
;
2027 newObject
->description
.sWeight
= fontDesc
->sWeight
;
2028 newObject
->description
.sCharset
= fontDesc
->sCharset
;
2029 newObject
->description
.fItalic
= fontDesc
->fItalic
;
2030 newObject
->description
.fUnderline
= fontDesc
->fUnderline
;
2031 newObject
->description
.fStrikethrough
= fontDesc
->fStrikethrough
;
2033 newObject
->gdiFont
= 0;
2034 newObject
->dirty
= TRUE
;
2035 newObject
->cyLogical
= GetDeviceCaps(get_dc(), LOGPIXELSY
);
2036 newObject
->cyHimetric
= 2540L;
2037 newObject
->pPropertyNotifyCP
= NULL
;
2038 newObject
->pFontEventsCP
= NULL
;
2040 CreateConnectionPoint((IUnknown
*)&newObject
->IFont_iface
, &IID_IPropertyNotifySink
, &newObject
->pPropertyNotifyCP
);
2041 CreateConnectionPoint((IUnknown
*)&newObject
->IFont_iface
, &IID_IFontEventsDisp
, &newObject
->pFontEventsCP
);
2043 if (!newObject
->pPropertyNotifyCP
|| !newObject
->pFontEventsCP
)
2045 OLEFontImpl_Destroy(newObject
);
2049 InterlockedIncrement(&ifont_cnt
);
2051 TRACE("returning %p\n", newObject
);
2055 /************************************************************************
2056 * OLEFontImpl_Destroy
2058 * This method is called by the Release method when the reference
2059 * count goes down to 0. It will free all resources used by
2062 static void OLEFontImpl_Destroy(OLEFontImpl
* fontDesc
)
2064 TRACE("(%p)\n", fontDesc
);
2066 free(fontDesc
->description
.lpstrName
);
2068 if (fontDesc
->pPropertyNotifyCP
)
2069 IConnectionPoint_Release(fontDesc
->pPropertyNotifyCP
);
2070 if (fontDesc
->pFontEventsCP
)
2071 IConnectionPoint_Release(fontDesc
->pFontEventsCP
);
2076 /*******************************************************************************
2077 * StdFont ClassFactory
2081 /* IUnknown fields */
2082 IClassFactory IClassFactory_iface
;
2084 } IClassFactoryImpl
;
2086 static inline IClassFactoryImpl
*impl_from_IClassFactory(IClassFactory
*iface
)
2088 return CONTAINING_RECORD(iface
, IClassFactoryImpl
, IClassFactory_iface
);
2091 static HRESULT WINAPI
SFCF_QueryInterface(IClassFactory
*iface
, REFIID riid
, void **obj
)
2093 IClassFactoryImpl
*This
= impl_from_IClassFactory(iface
);
2095 TRACE("(%p)->(%s, %p)\n", This
, debugstr_guid(riid
), obj
);
2099 if (IsEqualIID(&IID_IClassFactory
, riid
) || IsEqualIID(&IID_IUnknown
, riid
))
2102 IClassFactory_AddRef(iface
);
2106 return E_NOINTERFACE
;
2110 SFCF_AddRef(LPCLASSFACTORY iface
) {
2111 IClassFactoryImpl
*This
= impl_from_IClassFactory(iface
);
2112 return InterlockedIncrement(&This
->ref
);
2115 static ULONG WINAPI
SFCF_Release(LPCLASSFACTORY iface
) {
2116 IClassFactoryImpl
*This
= impl_from_IClassFactory(iface
);
2117 /* static class, won't be freed */
2118 return InterlockedDecrement(&This
->ref
);
2121 static HRESULT WINAPI
SFCF_CreateInstance(
2122 LPCLASSFACTORY iface
,LPUNKNOWN pOuter
,REFIID riid
,LPVOID
*ppobj
2124 return OleCreateFontIndirect(NULL
,riid
,ppobj
);
2128 static HRESULT WINAPI
SFCF_LockServer(LPCLASSFACTORY iface
,BOOL dolock
) {
2129 IClassFactoryImpl
*This
= impl_from_IClassFactory(iface
);
2130 FIXME("(%p)->(%d),stub!\n",This
,dolock
);
2134 static const IClassFactoryVtbl SFCF_Vtbl
= {
2135 SFCF_QueryInterface
,
2138 SFCF_CreateInstance
,
2141 static IClassFactoryImpl STDFONT_CF
= {{&SFCF_Vtbl
}, 1 };
2143 void _get_STDFONT_CF(LPVOID
*ppv
) { *ppv
= &STDFONT_CF
; }