2 * OLE Font encapsulation implementation
4 * This file contains an implementation of the IFont
5 * interface and the OleCreateFontIndirect API call.
7 * Copyright 1999 Francis Beaudet
8 * Copyright 2006 (Google) Benjamin Arai
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
29 #define NONAMELESSUNION
30 #define NONAMELESSSTRUCT
37 #include "wine/list.h"
38 #include "wine/unicode.h"
40 #include "oleauto.h" /* for SysAllocString(....) */
43 #include "wine/debug.h"
44 #include "connpt.h" /* for CreateConnectionPoint */
47 WINE_DEFAULT_DEBUG_CHANNEL(ole
);
49 /***********************************************************************
50 * Declaration of constants used when serializing the font object.
52 #define FONTPERSIST_ITALIC 0x02
53 #define FONTPERSIST_UNDERLINE 0x04
54 #define FONTPERSIST_STRIKETHROUGH 0x08
56 static HDC olefont_hdc
;
58 /***********************************************************************
59 * List of the HFONTs it has given out, with each one having a separate
62 typedef struct _HFONTItem
66 /* Reference count of any IFont objects that own this hfont */
69 /* Total reference count of any refs held by the application obtained by AddRefHfont plus any internal refs */
72 /* The font associated with this object. */
75 } HFONTItem
, *PHFONTItem
;
77 static struct list OLEFontImpl_hFontList
= LIST_INIT(OLEFontImpl_hFontList
);
79 /* Counts how many fonts contain at least one lock */
80 static LONG ifont_cnt
= 0;
82 /***********************************************************************
83 * Critical section for OLEFontImpl_hFontList
85 static CRITICAL_SECTION OLEFontImpl_csHFONTLIST
;
86 static CRITICAL_SECTION_DEBUG OLEFontImpl_csHFONTLIST_debug
=
88 0, 0, &OLEFontImpl_csHFONTLIST
,
89 { &OLEFontImpl_csHFONTLIST_debug
.ProcessLocksList
,
90 &OLEFontImpl_csHFONTLIST_debug
.ProcessLocksList
},
91 0, 0, { (DWORD_PTR
)(__FILE__
": OLEFontImpl_csHFONTLIST") }
93 static CRITICAL_SECTION OLEFontImpl_csHFONTLIST
= { &OLEFontImpl_csHFONTLIST_debug
, -1, 0, 0, 0, 0 };
95 static HDC
get_dc(void)
98 EnterCriticalSection(&OLEFontImpl_csHFONTLIST
);
100 olefont_hdc
= CreateCompatibleDC(NULL
);
102 LeaveCriticalSection(&OLEFontImpl_csHFONTLIST
);
106 static void delete_dc(void)
108 EnterCriticalSection(&OLEFontImpl_csHFONTLIST
);
111 DeleteDC(olefont_hdc
);
114 LeaveCriticalSection(&OLEFontImpl_csHFONTLIST
);
117 static void HFONTItem_Delete(PHFONTItem item
)
119 DeleteObject(item
->gdiFont
);
120 list_remove(&item
->entry
);
121 HeapFree(GetProcessHeap(), 0, item
);
124 /* Find hfont item entry in the list. Should be called while holding the crit sect */
125 static HFONTItem
*find_hfontitem(HFONT hfont
)
129 LIST_FOR_EACH_ENTRY(item
, &OLEFontImpl_hFontList
, HFONTItem
, entry
)
131 if (item
->gdiFont
== hfont
)
137 /* Add an item to the list with one internal reference */
138 static HRESULT
add_hfontitem(HFONT hfont
)
140 HFONTItem
*new_item
= HeapAlloc(GetProcessHeap(), 0, sizeof(*new_item
));
142 if(!new_item
) return E_OUTOFMEMORY
;
144 new_item
->int_refs
= 1;
145 new_item
->total_refs
= 1;
146 new_item
->gdiFont
= hfont
;
147 EnterCriticalSection(&OLEFontImpl_csHFONTLIST
);
148 list_add_tail(&OLEFontImpl_hFontList
,&new_item
->entry
);
149 LeaveCriticalSection(&OLEFontImpl_csHFONTLIST
);
153 static HRESULT
inc_int_ref(HFONT hfont
)
156 HRESULT hr
= S_FALSE
;
158 EnterCriticalSection(&OLEFontImpl_csHFONTLIST
);
159 item
= find_hfontitem(hfont
);
167 LeaveCriticalSection(&OLEFontImpl_csHFONTLIST
);
172 /* decrements the internal ref of a hfont item. If both refs are zero it'll
173 remove the item from the list and delete the hfont */
174 static HRESULT
dec_int_ref(HFONT hfont
)
177 HRESULT hr
= S_FALSE
;
179 EnterCriticalSection(&OLEFontImpl_csHFONTLIST
);
180 item
= find_hfontitem(hfont
);
186 if(item
->int_refs
== 0 && item
->total_refs
== 0)
187 HFONTItem_Delete(item
);
190 LeaveCriticalSection(&OLEFontImpl_csHFONTLIST
);
195 static HRESULT
inc_ext_ref(HFONT hfont
)
198 HRESULT hr
= S_FALSE
;
200 EnterCriticalSection(&OLEFontImpl_csHFONTLIST
);
202 item
= find_hfontitem(hfont
);
208 LeaveCriticalSection(&OLEFontImpl_csHFONTLIST
);
213 static HRESULT
dec_ext_ref(HFONT hfont
)
216 HRESULT hr
= S_FALSE
;
218 EnterCriticalSection(&OLEFontImpl_csHFONTLIST
);
220 item
= find_hfontitem(hfont
);
223 if(--item
->total_refs
>= 0) hr
= S_OK
;
225 LeaveCriticalSection(&OLEFontImpl_csHFONTLIST
);
230 static WCHAR
*strdupW(const WCHAR
* str
)
233 DWORD size
= (strlenW(str
) + 1) * sizeof(WCHAR
);
235 ret
= HeapAlloc(GetProcessHeap(), 0, size
);
237 memcpy(ret
, str
, size
);
241 /***********************************************************************
242 * Declaration of the implementation class for the IFont interface
244 typedef struct OLEFontImpl OLEFontImpl
;
249 * This class supports many interfaces. IUnknown, IFont,
250 * IDispatch, IDispFont IPersistStream and IConnectionPointContainer.
251 * The first two are supported by the first vtable, the next two are
252 * supported by the second table and the last two have their own.
255 IDispatch IDispatch_iface
;
256 IPersistStream IPersistStream_iface
;
257 IConnectionPointContainer IConnectionPointContainer_iface
;
258 IPersistPropertyBag IPersistPropertyBag_iface
;
259 IPersistStreamInit IPersistStreamInit_iface
;
261 * Reference count for that instance of the class.
266 * This structure contains the description of the class.
268 FONTDESC description
;
271 * Contain the font associated with this object.
282 * Stash realized height (pixels) from TEXTMETRIC - used in get_Size()
286 IConnectionPoint
*pPropertyNotifyCP
;
287 IConnectionPoint
*pFontEventsCP
;
291 * Here, I define utility macros to help with the casting of the
293 * There is a version to accommodate all of the VTables implemented
297 static inline OLEFontImpl
*impl_from_IFont(IFont
*iface
)
299 return CONTAINING_RECORD(iface
, OLEFontImpl
, IFont_iface
);
302 static inline OLEFontImpl
*impl_from_IDispatch( IDispatch
*iface
)
304 return CONTAINING_RECORD(iface
, OLEFontImpl
, IDispatch_iface
);
307 static inline OLEFontImpl
*impl_from_IPersistStream( IPersistStream
*iface
)
309 return CONTAINING_RECORD(iface
, OLEFontImpl
, IPersistStream_iface
);
312 static inline OLEFontImpl
*impl_from_IConnectionPointContainer( IConnectionPointContainer
*iface
)
314 return CONTAINING_RECORD(iface
, OLEFontImpl
, IConnectionPointContainer_iface
);
317 static inline OLEFontImpl
*impl_from_IPersistPropertyBag( IPersistPropertyBag
*iface
)
319 return CONTAINING_RECORD(iface
, OLEFontImpl
, IPersistPropertyBag_iface
);
322 static inline OLEFontImpl
*impl_from_IPersistStreamInit( IPersistStreamInit
*iface
)
324 return CONTAINING_RECORD(iface
, OLEFontImpl
, IPersistStreamInit_iface
);
328 /***********************************************************************
329 * Prototypes for the implementation functions for the IFont
332 static OLEFontImpl
* OLEFontImpl_Construct(const FONTDESC
*fontDesc
);
333 static void OLEFontImpl_Destroy(OLEFontImpl
* fontDesc
);
334 static ULONG WINAPI
OLEFontImpl_AddRef(IFont
* iface
);
336 /******************************************************************************
337 * OleCreateFontIndirect [OLEAUT32.420]
339 HRESULT WINAPI
OleCreateFontIndirect(
340 LPFONTDESC lpFontDesc
,
344 OLEFontImpl
* newFont
;
348 TRACE("(%p, %s, %p)\n", lpFontDesc
, debugstr_guid(riid
), ppvObj
);
350 if (!ppvObj
) return E_POINTER
;
355 static WCHAR fname
[] = { 'S','y','s','t','e','m',0 };
357 fd
.cbSizeofstruct
= sizeof(fd
);
358 fd
.lpstrName
= fname
;
359 fd
.cySize
.s
.Lo
= 80000;
365 fd
.fStrikethrough
= 0;
369 newFont
= OLEFontImpl_Construct(lpFontDesc
);
370 if (!newFont
) return E_OUTOFMEMORY
;
372 hr
= IFont_QueryInterface(&newFont
->IFont_iface
, riid
, ppvObj
);
373 IFont_Release(&newFont
->IFont_iface
);
379 /***********************************************************************
380 * Implementation of the OLEFontImpl class.
383 /***********************************************************************
384 * OLEFont_SendNotify (internal)
386 * Sends notification messages of changed properties to any interested
389 static void OLEFont_SendNotify(OLEFontImpl
* this, DISPID dispID
)
391 static const WCHAR wszName
[] = {'N','a','m','e',0};
392 static const WCHAR wszSize
[] = {'S','i','z','e',0};
393 static const WCHAR wszBold
[] = {'B','o','l','d',0};
394 static const WCHAR wszItalic
[] = {'I','t','a','l','i','c',0};
395 static const WCHAR wszUnder
[] = {'U','n','d','e','r','l','i','n','e',0};
396 static const WCHAR wszStrike
[] = {'S','t','r','i','k','e','t','h','r','o','u','g','h',0};
397 static const WCHAR wszWeight
[] = {'W','e','i','g','h','t',0};
398 static const WCHAR wszCharset
[] = {'C','h','a','r','s','s','e','t',0};
399 static const LPCWSTR dispid_mapping
[] =
412 IEnumConnections
*pEnum
;
418 hres
= IConnectionPoint_EnumConnections(this->pPropertyNotifyCP
, &pEnum
);
421 while(IEnumConnections_Next(pEnum
, 1, &CD
, NULL
) == S_OK
) {
422 IPropertyNotifySink
*sink
;
424 IUnknown_QueryInterface(CD
.pUnk
, &IID_IPropertyNotifySink
, (LPVOID
)&sink
);
425 IPropertyNotifySink_OnChanged(sink
, dispID
);
426 IPropertyNotifySink_Release(sink
);
427 IUnknown_Release(CD
.pUnk
);
429 IEnumConnections_Release(pEnum
);
432 hres
= IConnectionPoint_EnumConnections(this->pFontEventsCP
, &pEnum
);
435 DISPPARAMS dispparams
;
438 VariantInit(&vararg
);
439 V_VT(&vararg
) = VT_BSTR
;
440 V_BSTR(&vararg
) = SysAllocString(dispid_mapping
[dispID
]);
442 dispparams
.cArgs
= 1;
443 dispparams
.cNamedArgs
= 0;
444 dispparams
.rgdispidNamedArgs
= NULL
;
445 dispparams
.rgvarg
= &vararg
;
447 while(IEnumConnections_Next(pEnum
, 1, &CD
, NULL
) == S_OK
) {
448 IFontEventsDisp
*disp
;
450 IUnknown_QueryInterface(CD
.pUnk
, &IID_IFontEventsDisp
, (LPVOID
)&disp
);
451 IDispatch_Invoke(disp
, DISPID_FONT_CHANGED
, &IID_NULL
,
452 LOCALE_NEUTRAL
, INVOKE_FUNC
, &dispparams
, NULL
,
455 IDispatch_Release(disp
);
456 IUnknown_Release(CD
.pUnk
);
458 VariantClear(&vararg
);
459 IEnumConnections_Release(pEnum
);
463 /************************************************************************
464 * OLEFontImpl_QueryInterface (IUnknown)
466 * See Windows documentation for more details on IUnknown methods.
468 static HRESULT WINAPI
OLEFontImpl_QueryInterface(
473 OLEFontImpl
*this = impl_from_IFont(iface
);
475 TRACE("(%p)->(%s, %p)\n", this, debugstr_guid(riid
), ppvObject
);
479 if (IsEqualGUID(&IID_IUnknown
, riid
) ||
480 IsEqualGUID(&IID_IFont
, riid
))
484 else if (IsEqualGUID(&IID_IDispatch
, riid
) ||
485 IsEqualGUID(&IID_IFontDisp
, riid
))
487 *ppvObject
= &this->IDispatch_iface
;
489 else if (IsEqualGUID(&IID_IPersist
, riid
) ||
490 IsEqualGUID(&IID_IPersistStream
, riid
))
492 *ppvObject
= &this->IPersistStream_iface
;
494 else if (IsEqualGUID(&IID_IConnectionPointContainer
, riid
))
496 *ppvObject
= &this->IConnectionPointContainer_iface
;
498 else if (IsEqualGUID(&IID_IPersistPropertyBag
, riid
))
500 *ppvObject
= &this->IPersistPropertyBag_iface
;
502 else if (IsEqualGUID(&IID_IPersistStreamInit
, riid
))
504 *ppvObject
= &this->IPersistStreamInit_iface
;
509 FIXME("() : asking for unsupported interface %s\n", debugstr_guid(riid
));
510 return E_NOINTERFACE
;
518 /************************************************************************
519 * OLEFontImpl_AddRef (IUnknown)
521 static ULONG WINAPI
OLEFontImpl_AddRef(
524 OLEFontImpl
*this = impl_from_IFont(iface
);
525 TRACE("(%p)->(ref=%d)\n", this, this->ref
);
526 return InterlockedIncrement(&this->ref
);
529 /************************************************************************
530 * OLEFontImpl_Release (IUnknown)
532 static ULONG WINAPI
OLEFontImpl_Release(IFont
* iface
)
534 OLEFontImpl
*this = impl_from_IFont(iface
);
537 TRACE("(%p)->(ref=%d)\n", this, this->ref
);
539 ref
= InterlockedDecrement(&this->ref
);
543 ULONG fontlist_refs
= InterlockedDecrement(&ifont_cnt
);
545 /* Final IFont object so destroy font cache */
546 if (fontlist_refs
== 0)
548 HFONTItem
*item
, *cursor2
;
550 EnterCriticalSection(&OLEFontImpl_csHFONTLIST
);
551 LIST_FOR_EACH_ENTRY_SAFE(item
, cursor2
, &OLEFontImpl_hFontList
, HFONTItem
, entry
)
552 HFONTItem_Delete(item
);
553 LeaveCriticalSection(&OLEFontImpl_csHFONTLIST
);
558 dec_int_ref(this->gdiFont
);
560 OLEFontImpl_Destroy(this);
572 static int CALLBACK
font_enum_proc(const LOGFONTW
*elf
, const TEXTMETRICW
*ntm
, DWORD type
, LPARAM lp
)
574 enum_data
*data
= (enum_data
*)lp
;
576 if(elf
->lfCharSet
== data
->orig_cs
)
578 data
->avail_cs
= data
->orig_cs
;
581 if(data
->avail_cs
== -1) data
->avail_cs
= elf
->lfCharSet
;
585 static void realize_font(OLEFontImpl
*This
)
589 WCHAR text_face
[LF_FACESIZE
];
594 if (!This
->dirty
) return;
600 old_font
= SelectObject(hdc
, This
->gdiFont
);
601 GetTextFaceW(hdc
, sizeof(text_face
) / sizeof(text_face
[0]), text_face
);
602 SelectObject(hdc
, old_font
);
603 dec_int_ref(This
->gdiFont
);
607 memset(&logFont
, 0, sizeof(LOGFONTW
));
609 lstrcpynW(logFont
.lfFaceName
, This
->description
.lpstrName
, LF_FACESIZE
);
610 logFont
.lfCharSet
= This
->description
.sCharset
;
612 /* If the font name has been changed then enumerate all charsets
613 and pick one that'll result in the font specified being selected */
614 if(text_face
[0] && lstrcmpiW(text_face
, This
->description
.lpstrName
))
617 data
.orig_cs
= This
->description
.sCharset
;
619 logFont
.lfCharSet
= DEFAULT_CHARSET
;
620 EnumFontFamiliesExW(get_dc(), &logFont
, font_enum_proc
, (LPARAM
)&data
, 0);
621 if(data
.avail_cs
!= -1) logFont
.lfCharSet
= data
.avail_cs
;
625 * The height of the font returned by the get_Size property is the
626 * height of the font in points multiplied by 10000... Using some
627 * simple conversions and the ratio given by the application, it can
628 * be converted to a height in pixels.
630 * Standard ratio is 72 / 2540, or 18 / 635 in lowest terms.
631 * Ratio is applied here relative to the standard.
634 fontHeight
= MulDiv( This
->description
.cySize
.s
.Lo
, This
->cyLogical
*635, This
->cyHimetric
*18 );
636 logFont
.lfHeight
= ((fontHeight
%10000L)>5000L) ? (-fontHeight
/10000L) - 1 :
637 (-fontHeight
/10000L);
638 logFont
.lfItalic
= This
->description
.fItalic
;
639 logFont
.lfUnderline
= This
->description
.fUnderline
;
640 logFont
.lfStrikeOut
= This
->description
.fStrikethrough
;
641 logFont
.lfWeight
= This
->description
.sWeight
;
642 logFont
.lfOutPrecision
= OUT_CHARACTER_PRECIS
;
643 logFont
.lfClipPrecision
= CLIP_DEFAULT_PRECIS
;
644 logFont
.lfQuality
= DEFAULT_QUALITY
;
645 logFont
.lfPitchAndFamily
= DEFAULT_PITCH
;
647 This
->gdiFont
= CreateFontIndirectW(&logFont
);
650 add_hfontitem(This
->gdiFont
);
652 /* Fixup the name and charset properties so that they match the
654 old_font
= SelectObject(get_dc(), This
->gdiFont
);
655 GetTextFaceW(hdc
, sizeof(text_face
) / sizeof(text_face
[0]), text_face
);
656 if(lstrcmpiW(text_face
, This
->description
.lpstrName
))
658 HeapFree(GetProcessHeap(), 0, This
->description
.lpstrName
);
659 This
->description
.lpstrName
= strdupW(text_face
);
661 GetTextMetricsW(hdc
, &tm
);
662 This
->description
.sCharset
= tm
.tmCharSet
;
663 /* While we have it handy, stash the realized font height for use by get_Size() */
664 This
->nRealHeight
= tm
.tmHeight
- tm
.tmInternalLeading
; /* corresponds to LOGFONT lfHeight */
665 SelectObject(hdc
, old_font
);
668 /************************************************************************
669 * OLEFontImpl_get_Name (IFont)
671 * See Windows documentation for more details on IFont methods.
673 static HRESULT WINAPI
OLEFontImpl_get_Name(
677 OLEFontImpl
*this = impl_from_IFont(iface
);
678 TRACE("(%p)->(%p)\n", this, pname
);
685 if (this->description
.lpstrName
!=0)
686 *pname
= SysAllocString(this->description
.lpstrName
);
693 /************************************************************************
694 * OLEFontImpl_put_Name (IFont)
696 static HRESULT WINAPI
OLEFontImpl_put_Name(
700 OLEFontImpl
*this = impl_from_IFont(iface
);
701 TRACE("(%p)->(%p)\n", this, name
);
704 return CTL_E_INVALIDPROPERTYVALUE
;
706 if (this->description
.lpstrName
==0)
708 this->description
.lpstrName
= HeapAlloc(GetProcessHeap(),
710 (lstrlenW(name
)+1) * sizeof(WCHAR
));
714 this->description
.lpstrName
= HeapReAlloc(GetProcessHeap(),
716 this->description
.lpstrName
,
717 (lstrlenW(name
)+1) * sizeof(WCHAR
));
720 if (this->description
.lpstrName
==0)
721 return E_OUTOFMEMORY
;
723 strcpyW(this->description
.lpstrName
, name
);
724 TRACE("new name %s\n", debugstr_w(this->description
.lpstrName
));
725 OLEFont_SendNotify(this, DISPID_FONT_NAME
);
729 /************************************************************************
730 * OLEFontImpl_get_Size (IFont)
732 static HRESULT WINAPI
OLEFontImpl_get_Size(
736 OLEFontImpl
*this = impl_from_IFont(iface
);
737 TRACE("(%p)->(%p)\n", this, psize
);
739 if (!psize
) return E_POINTER
;
744 * Convert realized font height in pixels to points descaled by current
745 * scaling ratio then scaled up by 10000.
747 psize
->s
.Lo
= MulDiv(this->nRealHeight
,
748 this->cyHimetric
* 72 * 10000,
749 this->cyLogical
* 2540);
755 /************************************************************************
756 * OLEFontImpl_put_Size (IFont)
758 static HRESULT WINAPI
OLEFontImpl_put_Size(
762 OLEFontImpl
*this = impl_from_IFont(iface
);
763 TRACE("(%p)->(%d)\n", this, size
.s
.Lo
);
764 this->description
.cySize
.s
.Hi
= 0;
765 this->description
.cySize
.s
.Lo
= size
.s
.Lo
;
766 OLEFont_SendNotify(this, DISPID_FONT_SIZE
);
771 /************************************************************************
772 * OLEFontImpl_get_Bold (IFont)
774 * See Windows documentation for more details on IFont methods.
776 static HRESULT WINAPI
OLEFontImpl_get_Bold(
780 OLEFontImpl
*this = impl_from_IFont(iface
);
781 TRACE("(%p)->(%p)\n", this, pbold
);
783 if (!pbold
) return E_POINTER
;
787 *pbold
= this->description
.sWeight
> 550;
792 /************************************************************************
793 * OLEFontImpl_put_Bold (IFont)
795 static HRESULT WINAPI
OLEFontImpl_put_Bold(
799 OLEFontImpl
*this = impl_from_IFont(iface
);
800 TRACE("(%p)->(%d)\n", this, bold
);
801 this->description
.sWeight
= bold
? FW_BOLD
: FW_NORMAL
;
802 OLEFont_SendNotify(this, DISPID_FONT_BOLD
);
807 /************************************************************************
808 * OLEFontImpl_get_Italic (IFont)
810 static HRESULT WINAPI
OLEFontImpl_get_Italic(
814 OLEFontImpl
*this = impl_from_IFont(iface
);
815 TRACE("(%p)->(%p)\n", this, pitalic
);
822 *pitalic
= this->description
.fItalic
;
827 /************************************************************************
828 * OLEFontImpl_put_Italic (IFont)
830 static HRESULT WINAPI
OLEFontImpl_put_Italic(
834 OLEFontImpl
*this = impl_from_IFont(iface
);
835 TRACE("(%p)->(%d)\n", this, italic
);
837 this->description
.fItalic
= italic
;
839 OLEFont_SendNotify(this, DISPID_FONT_ITALIC
);
843 /************************************************************************
844 * OLEFontImpl_get_Underline (IFont)
846 static HRESULT WINAPI
OLEFontImpl_get_Underline(
850 OLEFontImpl
*this = impl_from_IFont(iface
);
851 TRACE("(%p)->(%p)\n", this, punderline
);
858 *punderline
= this->description
.fUnderline
;
863 /************************************************************************
864 * OLEFontImpl_put_Underline (IFont)
866 static HRESULT WINAPI
OLEFontImpl_put_Underline(
870 OLEFontImpl
*this = impl_from_IFont(iface
);
871 TRACE("(%p)->(%d)\n", this, underline
);
873 this->description
.fUnderline
= underline
;
875 OLEFont_SendNotify(this, DISPID_FONT_UNDER
);
879 /************************************************************************
880 * OLEFontImpl_get_Strikethrough (IFont)
882 static HRESULT WINAPI
OLEFontImpl_get_Strikethrough(
884 BOOL
* pstrikethrough
)
886 OLEFontImpl
*this = impl_from_IFont(iface
);
887 TRACE("(%p)->(%p)\n", this, pstrikethrough
);
889 if (pstrikethrough
==0)
894 *pstrikethrough
= this->description
.fStrikethrough
;
899 /************************************************************************
900 * OLEFontImpl_put_Strikethrough (IFont)
902 static HRESULT WINAPI
OLEFontImpl_put_Strikethrough(
906 OLEFontImpl
*this = impl_from_IFont(iface
);
907 TRACE("(%p)->(%d)\n", this, strikethrough
);
909 this->description
.fStrikethrough
= strikethrough
;
910 OLEFont_SendNotify(this, DISPID_FONT_STRIKE
);
915 /************************************************************************
916 * OLEFontImpl_get_Weight (IFont)
918 static HRESULT WINAPI
OLEFontImpl_get_Weight(
922 OLEFontImpl
*this = impl_from_IFont(iface
);
923 TRACE("(%p)->(%p)\n", this, pweight
);
930 *pweight
= this->description
.sWeight
;
935 /************************************************************************
936 * OLEFontImpl_put_Weight (IFont)
938 static HRESULT WINAPI
OLEFontImpl_put_Weight(
942 OLEFontImpl
*this = impl_from_IFont(iface
);
943 TRACE("(%p)->(%d)\n", this, weight
);
945 this->description
.sWeight
= weight
;
947 OLEFont_SendNotify(this, DISPID_FONT_WEIGHT
);
951 /************************************************************************
952 * OLEFontImpl_get_Charset (IFont)
954 static HRESULT WINAPI
OLEFontImpl_get_Charset(
958 OLEFontImpl
*this = impl_from_IFont(iface
);
959 TRACE("(%p)->(%p)\n", this, pcharset
);
966 *pcharset
= this->description
.sCharset
;
971 /************************************************************************
972 * OLEFontImpl_put_Charset (IFont)
974 static HRESULT WINAPI
OLEFontImpl_put_Charset(
978 OLEFontImpl
*this = impl_from_IFont(iface
);
979 TRACE("(%p)->(%d)\n", this, charset
);
981 this->description
.sCharset
= charset
;
982 OLEFont_SendNotify(this, DISPID_FONT_CHARSET
);
987 /************************************************************************
988 * OLEFontImpl_get_hFont (IFont)
990 static HRESULT WINAPI
OLEFontImpl_get_hFont(
994 OLEFontImpl
*this = impl_from_IFont(iface
);
995 TRACE("(%p)->(%p)\n", this, phfont
);
1001 *phfont
= this->gdiFont
;
1002 TRACE("Returning %p\n", *phfont
);
1006 /************************************************************************
1007 * OLEFontImpl_Clone (IFont)
1009 static HRESULT WINAPI
OLEFontImpl_Clone(
1013 OLEFontImpl
*this = impl_from_IFont(iface
);
1014 OLEFontImpl
* newObject
;
1016 TRACE("(%p)->(%p)\n", this, ppfont
);
1023 newObject
= HeapAlloc(GetProcessHeap(), 0, sizeof(OLEFontImpl
));
1024 if (newObject
==NULL
)
1025 return E_OUTOFMEMORY
;
1029 /* We need to alloc new memory for the string, otherwise
1030 * we free memory twice.
1032 newObject
->description
.lpstrName
= HeapAlloc(
1034 (1+strlenW(this->description
.lpstrName
))*2
1036 strcpyW(newObject
->description
.lpstrName
, this->description
.lpstrName
);
1038 /* Increment internal ref in hfont item list */
1039 if(newObject
->gdiFont
) inc_int_ref(newObject
->gdiFont
);
1041 InterlockedIncrement(&ifont_cnt
);
1043 newObject
->pPropertyNotifyCP
= NULL
;
1044 newObject
->pFontEventsCP
= NULL
;
1045 CreateConnectionPoint((IUnknown
*)newObject
, &IID_IPropertyNotifySink
, &newObject
->pPropertyNotifyCP
);
1046 CreateConnectionPoint((IUnknown
*)newObject
, &IID_IFontEventsDisp
, &newObject
->pFontEventsCP
);
1048 if (!newObject
->pPropertyNotifyCP
|| !newObject
->pFontEventsCP
)
1050 OLEFontImpl_Destroy(newObject
);
1051 return E_OUTOFMEMORY
;
1054 /* The cloned object starts with a reference count of 1 */
1057 *ppfont
= &newObject
->IFont_iface
;
1062 /************************************************************************
1063 * OLEFontImpl_IsEqual (IFont)
1065 static HRESULT WINAPI
OLEFontImpl_IsEqual(
1069 OLEFontImpl
*left
= impl_from_IFont(iface
);
1070 OLEFontImpl
*right
= impl_from_IFont(pFontOther
);
1072 INT left_len
,right_len
;
1074 if(pFontOther
== NULL
)
1076 else if (left
->description
.cySize
.s
.Lo
!= right
->description
.cySize
.s
.Lo
)
1078 else if (left
->description
.cySize
.s
.Hi
!= right
->description
.cySize
.s
.Hi
)
1080 else if (left
->description
.sWeight
!= right
->description
.sWeight
)
1082 else if (left
->description
.sCharset
!= right
->description
.sCharset
)
1084 else if (left
->description
.fItalic
!= right
->description
.fItalic
)
1086 else if (left
->description
.fUnderline
!= right
->description
.fUnderline
)
1088 else if (left
->description
.fStrikethrough
!= right
->description
.fStrikethrough
)
1091 /* Check from string */
1092 left_len
= strlenW(left
->description
.lpstrName
);
1093 right_len
= strlenW(right
->description
.lpstrName
);
1094 ret
= CompareStringW(0,0,left
->description
.lpstrName
, left_len
,
1095 right
->description
.lpstrName
, right_len
);
1096 if (ret
!= CSTR_EQUAL
)
1102 /************************************************************************
1103 * OLEFontImpl_SetRatio (IFont)
1105 static HRESULT WINAPI
OLEFontImpl_SetRatio(
1110 OLEFontImpl
*this = impl_from_IFont(iface
);
1111 TRACE("(%p)->(%d, %d)\n", this, cyLogical
, cyHimetric
);
1113 if(cyLogical
== 0 || cyHimetric
== 0)
1114 return E_INVALIDARG
;
1116 this->cyLogical
= cyLogical
;
1117 this->cyHimetric
= cyHimetric
;
1123 /************************************************************************
1124 * OLEFontImpl_QueryTextMetrics (IFont)
1126 static HRESULT WINAPI
OLEFontImpl_QueryTextMetrics(
1131 HFONT hOldFont
, hNewFont
;
1134 IFont_get_hFont(iface
, &hNewFont
);
1135 hOldFont
= SelectObject(hdcRef
, hNewFont
);
1136 GetTextMetricsW(hdcRef
, ptm
);
1137 SelectObject(hdcRef
, hOldFont
);
1138 ReleaseDC(0, hdcRef
);
1142 /************************************************************************
1143 * OLEFontImpl_AddRefHfont (IFont)
1145 static HRESULT WINAPI
OLEFontImpl_AddRefHfont(
1149 OLEFontImpl
*this = impl_from_IFont(iface
);
1151 TRACE("(%p)->(%p)\n", this, hfont
);
1153 if (!hfont
) return E_INVALIDARG
;
1155 return inc_ext_ref(hfont
);
1158 /************************************************************************
1159 * OLEFontImpl_ReleaseHfont (IFont)
1161 static HRESULT WINAPI
OLEFontImpl_ReleaseHfont(
1165 OLEFontImpl
*this = impl_from_IFont(iface
);
1167 TRACE("(%p)->(%p)\n", this, hfont
);
1169 if (!hfont
) return E_INVALIDARG
;
1171 return dec_ext_ref(hfont
);
1174 /************************************************************************
1175 * OLEFontImpl_SetHdc (IFont)
1177 static HRESULT WINAPI
OLEFontImpl_SetHdc(
1181 OLEFontImpl
*this = impl_from_IFont(iface
);
1182 FIXME("(%p)->(%p): Stub\n", this, hdc
);
1186 static const IFontVtbl OLEFontImpl_VTable
=
1188 OLEFontImpl_QueryInterface
,
1190 OLEFontImpl_Release
,
1191 OLEFontImpl_get_Name
,
1192 OLEFontImpl_put_Name
,
1193 OLEFontImpl_get_Size
,
1194 OLEFontImpl_put_Size
,
1195 OLEFontImpl_get_Bold
,
1196 OLEFontImpl_put_Bold
,
1197 OLEFontImpl_get_Italic
,
1198 OLEFontImpl_put_Italic
,
1199 OLEFontImpl_get_Underline
,
1200 OLEFontImpl_put_Underline
,
1201 OLEFontImpl_get_Strikethrough
,
1202 OLEFontImpl_put_Strikethrough
,
1203 OLEFontImpl_get_Weight
,
1204 OLEFontImpl_put_Weight
,
1205 OLEFontImpl_get_Charset
,
1206 OLEFontImpl_put_Charset
,
1207 OLEFontImpl_get_hFont
,
1209 OLEFontImpl_IsEqual
,
1210 OLEFontImpl_SetRatio
,
1211 OLEFontImpl_QueryTextMetrics
,
1212 OLEFontImpl_AddRefHfont
,
1213 OLEFontImpl_ReleaseHfont
,
1217 /************************************************************************
1218 * OLEFontImpl_IDispatch_QueryInterface (IUnknown)
1220 static HRESULT WINAPI
OLEFontImpl_IDispatch_QueryInterface(
1225 OLEFontImpl
*this = impl_from_IDispatch(iface
);
1226 return IFont_QueryInterface(&this->IFont_iface
, riid
, ppvoid
);
1229 /************************************************************************
1230 * OLEFontImpl_IDispatch_Release (IUnknown)
1232 static ULONG WINAPI
OLEFontImpl_IDispatch_Release(
1235 OLEFontImpl
*this = impl_from_IDispatch(iface
);
1236 return IFont_Release(&this->IFont_iface
);
1239 /************************************************************************
1240 * OLEFontImpl_IDispatch_AddRef (IUnknown)
1242 static ULONG WINAPI
OLEFontImpl_IDispatch_AddRef(
1245 OLEFontImpl
*this = impl_from_IDispatch(iface
);
1246 return IFont_AddRef(&this->IFont_iface
);
1249 /************************************************************************
1250 * OLEFontImpl_GetTypeInfoCount (IDispatch)
1252 static HRESULT WINAPI
OLEFontImpl_GetTypeInfoCount(
1254 unsigned int* pctinfo
)
1256 OLEFontImpl
*this = impl_from_IDispatch(iface
);
1257 TRACE("(%p)->(%p)\n", this, pctinfo
);
1263 /************************************************************************
1264 * OLEFontImpl_GetTypeInfo (IDispatch)
1266 static HRESULT WINAPI
OLEFontImpl_GetTypeInfo(
1270 ITypeInfo
** ppTInfo
)
1272 static const WCHAR stdole2tlb
[] = {'s','t','d','o','l','e','2','.','t','l','b',0};
1276 OLEFontImpl
*this = impl_from_IDispatch(iface
);
1277 TRACE("(%p, iTInfo=%d, lcid=%04x, %p)\n", this, iTInfo
, (int)lcid
, ppTInfo
);
1280 hres
= LoadTypeLib(stdole2tlb
, &tl
);
1282 ERR("Could not load the stdole2.tlb?\n");
1285 hres
= ITypeLib_GetTypeInfoOfGuid(tl
, &IID_IFontDisp
, ppTInfo
);
1286 ITypeLib_Release(tl
);
1288 FIXME("Did not IDispatch typeinfo from typelib, hres %x\n",hres
);
1293 /************************************************************************
1294 * OLEFontImpl_GetIDsOfNames (IDispatch)
1296 static HRESULT WINAPI
OLEFontImpl_GetIDsOfNames(
1299 LPOLESTR
* rgszNames
,
1307 OLEFontImpl
*this = impl_from_IDispatch(iface
);
1309 TRACE("(%p,%s,%p,cNames=%d,lcid=%04x,%p)\n", this, debugstr_guid(riid
),
1310 rgszNames
, cNames
, (int)lcid
, rgDispId
);
1312 if (cNames
== 0) return E_INVALIDARG
;
1314 hres
= IDispatch_GetTypeInfo(iface
, 0, lcid
, &pTInfo
);
1317 ERR("GetTypeInfo failed.\n");
1321 /* convert names to DISPIDs */
1322 hres
= DispGetIDsOfNames (pTInfo
, rgszNames
, cNames
, rgDispId
);
1323 ITypeInfo_Release(pTInfo
);
1328 /************************************************************************
1329 * OLEFontImpl_Invoke (IDispatch)
1331 * Note: Do not call _put_Xxx methods, since setting things here
1332 * should not call notify functions as I found out debugging the generic
1335 static HRESULT WINAPI
OLEFontImpl_Invoke(
1337 DISPID dispIdMember
,
1341 DISPPARAMS
* pDispParams
,
1342 VARIANT
* pVarResult
,
1343 EXCEPINFO
* pExepInfo
,
1346 OLEFontImpl
*this = impl_from_IDispatch(iface
);
1349 TRACE("%p->(%d,%s,0x%x,0x%x,%p,%p,%p,%p)\n", this, dispIdMember
,
1350 debugstr_guid(riid
), lcid
, wFlags
, pDispParams
, pVarResult
, pExepInfo
,
1353 /* validate parameters */
1355 if (!IsEqualIID(riid
, &IID_NULL
))
1357 ERR("riid was %s instead of IID_NULL\n", debugstr_guid(riid
));
1358 return DISP_E_UNKNOWNINTERFACE
;
1361 if (wFlags
& DISPATCH_PROPERTYGET
)
1365 ERR("null pVarResult not allowed when DISPATCH_PROPERTYGET specified\n");
1366 return DISP_E_PARAMNOTOPTIONAL
;
1369 else if (wFlags
& DISPATCH_PROPERTYPUT
)
1373 ERR("null pDispParams not allowed when DISPATCH_PROPERTYPUT specified\n");
1374 return DISP_E_PARAMNOTOPTIONAL
;
1376 if (pDispParams
->cArgs
!= 1)
1378 ERR("param count for DISPATCH_PROPERTYPUT was %d instead of 1\n", pDispParams
->cArgs
);
1379 return DISP_E_BADPARAMCOUNT
;
1384 ERR("one of DISPATCH_PROPERTYGET or DISPATCH_PROPERTYPUT must be specified\n");
1385 return DISP_E_MEMBERNOTFOUND
;
1388 switch (dispIdMember
) {
1389 case DISPID_FONT_NAME
:
1390 if (wFlags
& DISPATCH_PROPERTYGET
) {
1391 V_VT(pVarResult
) = VT_BSTR
;
1392 return IFont_get_Name(&this->IFont_iface
, &V_BSTR(pVarResult
));
1396 VariantInit(&vararg
);
1397 hr
= VariantChangeTypeEx(&vararg
, &pDispParams
->rgvarg
[0], lcid
, 0, VT_BSTR
);
1401 hr
= IFont_put_Name(&this->IFont_iface
, V_BSTR(&vararg
));
1403 VariantClear(&vararg
);
1407 case DISPID_FONT_BOLD
:
1408 if (wFlags
& DISPATCH_PROPERTYGET
) {
1410 hr
= IFont_get_Bold(&this->IFont_iface
, &value
);
1411 V_VT(pVarResult
) = VT_BOOL
;
1412 V_BOOL(pVarResult
) = value
? VARIANT_TRUE
: VARIANT_FALSE
;
1417 VariantInit(&vararg
);
1418 hr
= VariantChangeTypeEx(&vararg
, &pDispParams
->rgvarg
[0], lcid
, 0, VT_BOOL
);
1422 hr
= IFont_put_Bold(&this->IFont_iface
, V_BOOL(&vararg
));
1424 VariantClear(&vararg
);
1428 case DISPID_FONT_ITALIC
:
1429 if (wFlags
& DISPATCH_PROPERTYGET
) {
1431 hr
= IFont_get_Italic(&this->IFont_iface
, &value
);
1432 V_VT(pVarResult
) = VT_BOOL
;
1433 V_BOOL(pVarResult
) = value
? VARIANT_TRUE
: VARIANT_FALSE
;
1438 VariantInit(&vararg
);
1439 hr
= VariantChangeTypeEx(&vararg
, &pDispParams
->rgvarg
[0], lcid
, 0, VT_BOOL
);
1443 hr
= IFont_put_Italic(&this->IFont_iface
, V_BOOL(&vararg
));
1445 VariantClear(&vararg
);
1449 case DISPID_FONT_UNDER
:
1450 if (wFlags
& DISPATCH_PROPERTYGET
) {
1452 hr
= IFont_get_Underline(&this->IFont_iface
, &value
);
1453 V_VT(pVarResult
) = VT_BOOL
;
1454 V_BOOL(pVarResult
) = value
? VARIANT_TRUE
: VARIANT_FALSE
;
1459 VariantInit(&vararg
);
1460 hr
= VariantChangeTypeEx(&vararg
, &pDispParams
->rgvarg
[0], lcid
, 0, VT_BOOL
);
1464 hr
= IFont_put_Underline(&this->IFont_iface
, V_BOOL(&vararg
));
1466 VariantClear(&vararg
);
1470 case DISPID_FONT_STRIKE
:
1471 if (wFlags
& DISPATCH_PROPERTYGET
) {
1473 hr
= IFont_get_Strikethrough(&this->IFont_iface
, &value
);
1474 V_VT(pVarResult
) = VT_BOOL
;
1475 V_BOOL(pVarResult
) = value
? VARIANT_TRUE
: VARIANT_FALSE
;
1480 VariantInit(&vararg
);
1481 hr
= VariantChangeTypeEx(&vararg
, &pDispParams
->rgvarg
[0], lcid
, 0, VT_BOOL
);
1485 hr
= IFont_put_Strikethrough(&this->IFont_iface
, V_BOOL(&vararg
));
1487 VariantClear(&vararg
);
1491 case DISPID_FONT_SIZE
:
1492 if (wFlags
& DISPATCH_PROPERTYGET
) {
1493 V_VT(pVarResult
) = VT_CY
;
1494 return IFont_get_Size(&this->IFont_iface
, &V_CY(pVarResult
));
1498 VariantInit(&vararg
);
1499 hr
= VariantChangeTypeEx(&vararg
, &pDispParams
->rgvarg
[0], lcid
, 0, VT_CY
);
1503 hr
= IFont_put_Size(&this->IFont_iface
, V_CY(&vararg
));
1505 VariantClear(&vararg
);
1509 case DISPID_FONT_WEIGHT
:
1510 if (wFlags
& DISPATCH_PROPERTYGET
) {
1511 V_VT(pVarResult
) = VT_I2
;
1512 return IFont_get_Weight(&this->IFont_iface
, &V_I2(pVarResult
));
1516 VariantInit(&vararg
);
1517 hr
= VariantChangeTypeEx(&vararg
, &pDispParams
->rgvarg
[0], lcid
, 0, VT_I2
);
1521 hr
= IFont_put_Weight(&this->IFont_iface
, V_I2(&vararg
));
1523 VariantClear(&vararg
);
1527 case DISPID_FONT_CHARSET
:
1528 if (wFlags
& DISPATCH_PROPERTYGET
) {
1529 V_VT(pVarResult
) = VT_I2
;
1530 return OLEFontImpl_get_Charset(&this->IFont_iface
, &V_I2(pVarResult
));
1534 VariantInit(&vararg
);
1535 hr
= VariantChangeTypeEx(&vararg
, &pDispParams
->rgvarg
[0], lcid
, 0, VT_I2
);
1539 hr
= IFont_put_Charset(&this->IFont_iface
, V_I2(&vararg
));
1541 VariantClear(&vararg
);
1546 ERR("member not found for dispid 0x%x\n", dispIdMember
);
1547 return DISP_E_MEMBERNOTFOUND
;
1551 static const IDispatchVtbl OLEFontImpl_IDispatch_VTable
=
1553 OLEFontImpl_IDispatch_QueryInterface
,
1554 OLEFontImpl_IDispatch_AddRef
,
1555 OLEFontImpl_IDispatch_Release
,
1556 OLEFontImpl_GetTypeInfoCount
,
1557 OLEFontImpl_GetTypeInfo
,
1558 OLEFontImpl_GetIDsOfNames
,
1562 /************************************************************************
1563 * OLEFontImpl_IPersistStream_QueryInterface (IUnknown)
1565 static HRESULT WINAPI
OLEFontImpl_IPersistStream_QueryInterface(
1566 IPersistStream
* iface
,
1570 OLEFontImpl
*this = impl_from_IPersistStream(iface
);
1572 return IFont_QueryInterface(&this->IFont_iface
, riid
, ppvoid
);
1575 /************************************************************************
1576 * OLEFontImpl_IPersistStream_Release (IUnknown)
1578 static ULONG WINAPI
OLEFontImpl_IPersistStream_Release(
1579 IPersistStream
* iface
)
1581 OLEFontImpl
*this = impl_from_IPersistStream(iface
);
1583 return IFont_Release(&this->IFont_iface
);
1586 /************************************************************************
1587 * OLEFontImpl_IPersistStream_AddRef (IUnknown)
1589 static ULONG WINAPI
OLEFontImpl_IPersistStream_AddRef(
1590 IPersistStream
* iface
)
1592 OLEFontImpl
*this = impl_from_IPersistStream(iface
);
1594 return IFont_AddRef(&this->IFont_iface
);
1597 /************************************************************************
1598 * OLEFontImpl_GetClassID (IPersistStream)
1600 static HRESULT WINAPI
OLEFontImpl_GetClassID(
1601 IPersistStream
* iface
,
1604 TRACE("(%p,%p)\n",iface
,pClassID
);
1608 *pClassID
= CLSID_StdFont
;
1613 /************************************************************************
1614 * OLEFontImpl_IsDirty (IPersistStream)
1616 * See Windows documentation for more details on IPersistStream methods.
1618 static HRESULT WINAPI
OLEFontImpl_IsDirty(
1619 IPersistStream
* iface
)
1621 TRACE("(%p)\n",iface
);
1625 /************************************************************************
1626 * OLEFontImpl_Load (IPersistStream)
1628 * See Windows documentation for more details on IPersistStream methods.
1630 * This is the format of the standard font serialization as far as I
1633 * Offset Type Value Comment
1634 * 0x0000 Byte Unknown Probably a version number, contains 0x01
1635 * 0x0001 Short Charset Charset value from the FONTDESC structure
1636 * 0x0003 Byte Attributes Flags defined as follows:
1638 * 00000100 - Underline
1639 * 00001000 - Strikethrough
1640 * 0x0004 Short Weight Weight value from FONTDESC structure
1641 * 0x0006 DWORD size "Low" portion of the cySize member of the FONTDESC
1643 * 0x000A Byte name length Length of the font name string (no null character)
1644 * 0x000B String name Name of the font (ASCII, no nul character)
1646 static HRESULT WINAPI
OLEFontImpl_Load(
1647 IPersistStream
* iface
,
1648 IStream
* pLoadStream
)
1650 char readBuffer
[0x100];
1657 OLEFontImpl
*this = impl_from_IPersistStream(iface
);
1660 * Read the version byte
1662 IStream_Read(pLoadStream
, &bVersion
, 1, &cbRead
);
1671 IStream_Read(pLoadStream
, &this->description
.sCharset
, 2, &cbRead
);
1679 IStream_Read(pLoadStream
, &bAttributes
, 1, &cbRead
);
1684 this->description
.fItalic
= (bAttributes
& FONTPERSIST_ITALIC
) != 0;
1685 this->description
.fStrikethrough
= (bAttributes
& FONTPERSIST_STRIKETHROUGH
) != 0;
1686 this->description
.fUnderline
= (bAttributes
& FONTPERSIST_UNDERLINE
) != 0;
1691 IStream_Read(pLoadStream
, &this->description
.sWeight
, 2, &cbRead
);
1699 IStream_Read(pLoadStream
, &this->description
.cySize
.s
.Lo
, 4, &cbRead
);
1704 this->description
.cySize
.s
.Hi
= 0;
1709 IStream_Read(pLoadStream
, &bStringSize
, 1, &cbRead
);
1714 IStream_Read(pLoadStream
, readBuffer
, bStringSize
, &cbRead
);
1716 if (cbRead
!=bStringSize
)
1719 HeapFree(GetProcessHeap(), 0, this->description
.lpstrName
);
1721 len
= MultiByteToWideChar( CP_ACP
, 0, readBuffer
, bStringSize
, NULL
, 0 );
1722 this->description
.lpstrName
= HeapAlloc( GetProcessHeap(), 0, (len
+1) * sizeof(WCHAR
) );
1723 MultiByteToWideChar( CP_ACP
, 0, readBuffer
, bStringSize
, this->description
.lpstrName
, len
);
1724 this->description
.lpstrName
[len
] = 0;
1726 /* Ensure use of this font causes a new one to be created */
1727 dec_int_ref(this->gdiFont
);
1734 /************************************************************************
1735 * OLEFontImpl_Save (IPersistStream)
1737 static HRESULT WINAPI
OLEFontImpl_Save(
1738 IPersistStream
* iface
,
1739 IStream
* pOutStream
,
1742 char* writeBuffer
= NULL
;
1744 BYTE bVersion
= 0x01;
1748 OLEFontImpl
*this = impl_from_IPersistStream(iface
);
1751 * Read the version byte
1753 IStream_Write(pOutStream
, &bVersion
, 1, &cbWritten
);
1761 IStream_Write(pOutStream
, &this->description
.sCharset
, 2, &cbWritten
);
1771 if (this->description
.fItalic
)
1772 bAttributes
|= FONTPERSIST_ITALIC
;
1774 if (this->description
.fStrikethrough
)
1775 bAttributes
|= FONTPERSIST_STRIKETHROUGH
;
1777 if (this->description
.fUnderline
)
1778 bAttributes
|= FONTPERSIST_UNDERLINE
;
1780 IStream_Write(pOutStream
, &bAttributes
, 1, &cbWritten
);
1788 IStream_Write(pOutStream
, &this->description
.sWeight
, 2, &cbWritten
);
1796 IStream_Write(pOutStream
, &this->description
.cySize
.s
.Lo
, 4, &cbWritten
);
1804 if (this->description
.lpstrName
!=0)
1805 bStringSize
= WideCharToMultiByte( CP_ACP
, 0, this->description
.lpstrName
,
1806 strlenW(this->description
.lpstrName
), NULL
, 0, NULL
, NULL
);
1810 IStream_Write(pOutStream
, &bStringSize
, 1, &cbWritten
);
1817 if (!(writeBuffer
= HeapAlloc( GetProcessHeap(), 0, bStringSize
))) return E_OUTOFMEMORY
;
1818 WideCharToMultiByte( CP_ACP
, 0, this->description
.lpstrName
,
1819 strlenW(this->description
.lpstrName
),
1820 writeBuffer
, bStringSize
, NULL
, NULL
);
1822 IStream_Write(pOutStream
, writeBuffer
, bStringSize
, &cbWritten
);
1823 HeapFree(GetProcessHeap(), 0, writeBuffer
);
1825 if (cbWritten
!=bStringSize
)
1832 /************************************************************************
1833 * OLEFontImpl_GetSizeMax (IPersistStream)
1835 static HRESULT WINAPI
OLEFontImpl_GetSizeMax(
1836 IPersistStream
* iface
,
1837 ULARGE_INTEGER
* pcbSize
)
1839 OLEFontImpl
*this = impl_from_IPersistStream(iface
);
1844 pcbSize
->u
.HighPart
= 0;
1845 pcbSize
->u
.LowPart
= 0;
1847 pcbSize
->u
.LowPart
+= sizeof(BYTE
); /* Version */
1848 pcbSize
->u
.LowPart
+= sizeof(WORD
); /* Lang code */
1849 pcbSize
->u
.LowPart
+= sizeof(BYTE
); /* Flags */
1850 pcbSize
->u
.LowPart
+= sizeof(WORD
); /* Weight */
1851 pcbSize
->u
.LowPart
+= sizeof(DWORD
); /* Size */
1852 pcbSize
->u
.LowPart
+= sizeof(BYTE
); /* StrLength */
1854 if (this->description
.lpstrName
!=0)
1855 pcbSize
->u
.LowPart
+= WideCharToMultiByte( CP_ACP
, 0, this->description
.lpstrName
,
1856 strlenW(this->description
.lpstrName
),
1857 NULL
, 0, NULL
, NULL
);
1862 static const IPersistStreamVtbl OLEFontImpl_IPersistStream_VTable
=
1864 OLEFontImpl_IPersistStream_QueryInterface
,
1865 OLEFontImpl_IPersistStream_AddRef
,
1866 OLEFontImpl_IPersistStream_Release
,
1867 OLEFontImpl_GetClassID
,
1868 OLEFontImpl_IsDirty
,
1871 OLEFontImpl_GetSizeMax
1874 /************************************************************************
1875 * OLEFontImpl_IConnectionPointContainer_QueryInterface (IUnknown)
1877 static HRESULT WINAPI
OLEFontImpl_IConnectionPointContainer_QueryInterface(
1878 IConnectionPointContainer
* iface
,
1882 OLEFontImpl
*this = impl_from_IConnectionPointContainer(iface
);
1884 return IFont_QueryInterface(&this->IFont_iface
, riid
, ppvoid
);
1887 /************************************************************************
1888 * OLEFontImpl_IConnectionPointContainer_Release (IUnknown)
1890 static ULONG WINAPI
OLEFontImpl_IConnectionPointContainer_Release(
1891 IConnectionPointContainer
* iface
)
1893 OLEFontImpl
*this = impl_from_IConnectionPointContainer(iface
);
1895 return IFont_Release(&this->IFont_iface
);
1898 /************************************************************************
1899 * OLEFontImpl_IConnectionPointContainer_AddRef (IUnknown)
1901 static ULONG WINAPI
OLEFontImpl_IConnectionPointContainer_AddRef(
1902 IConnectionPointContainer
* iface
)
1904 OLEFontImpl
*this = impl_from_IConnectionPointContainer(iface
);
1906 return IFont_AddRef(&this->IFont_iface
);
1909 /************************************************************************
1910 * OLEFontImpl_EnumConnectionPoints (IConnectionPointContainer)
1912 static HRESULT WINAPI
OLEFontImpl_EnumConnectionPoints(
1913 IConnectionPointContainer
* iface
,
1914 IEnumConnectionPoints
**ppEnum
)
1916 OLEFontImpl
*this = impl_from_IConnectionPointContainer(iface
);
1918 FIXME("(%p)->(%p): stub\n", this, ppEnum
);
1922 /************************************************************************
1923 * OLEFontImpl_FindConnectionPoint (IConnectionPointContainer)
1925 static HRESULT WINAPI
OLEFontImpl_FindConnectionPoint(
1926 IConnectionPointContainer
* iface
,
1928 IConnectionPoint
**ppCp
)
1930 OLEFontImpl
*this = impl_from_IConnectionPointContainer(iface
);
1931 TRACE("(%p)->(%s, %p)\n", this, debugstr_guid(riid
), ppCp
);
1933 if(IsEqualIID(riid
, &IID_IPropertyNotifySink
)) {
1934 return IConnectionPoint_QueryInterface(this->pPropertyNotifyCP
,
1935 &IID_IConnectionPoint
,
1937 } else if(IsEqualIID(riid
, &IID_IFontEventsDisp
)) {
1938 return IConnectionPoint_QueryInterface(this->pFontEventsCP
,
1939 &IID_IConnectionPoint
,
1942 FIXME("no connection point for %s\n", debugstr_guid(riid
));
1943 return CONNECT_E_NOCONNECTION
;
1947 static const IConnectionPointContainerVtbl
1948 OLEFontImpl_IConnectionPointContainer_VTable
=
1950 OLEFontImpl_IConnectionPointContainer_QueryInterface
,
1951 OLEFontImpl_IConnectionPointContainer_AddRef
,
1952 OLEFontImpl_IConnectionPointContainer_Release
,
1953 OLEFontImpl_EnumConnectionPoints
,
1954 OLEFontImpl_FindConnectionPoint
1957 /************************************************************************
1958 * OLEFontImpl implementation of IPersistPropertyBag.
1960 static HRESULT WINAPI
OLEFontImpl_IPersistPropertyBag_QueryInterface(
1961 IPersistPropertyBag
*iface
, REFIID riid
, LPVOID
*ppvObj
1963 OLEFontImpl
*this = impl_from_IPersistPropertyBag(iface
);
1964 return IFont_QueryInterface(&this->IFont_iface
,riid
,ppvObj
);
1967 static ULONG WINAPI
OLEFontImpl_IPersistPropertyBag_AddRef(
1968 IPersistPropertyBag
*iface
1970 OLEFontImpl
*this = impl_from_IPersistPropertyBag(iface
);
1971 return IFont_AddRef(&this->IFont_iface
);
1974 static ULONG WINAPI
OLEFontImpl_IPersistPropertyBag_Release(
1975 IPersistPropertyBag
*iface
1977 OLEFontImpl
*this = impl_from_IPersistPropertyBag(iface
);
1978 return IFont_Release(&this->IFont_iface
);
1981 static HRESULT WINAPI
OLEFontImpl_IPersistPropertyBag_GetClassID(
1982 IPersistPropertyBag
*iface
, CLSID
*classid
1984 FIXME("(%p,%p), stub!\n", iface
, classid
);
1988 static HRESULT WINAPI
OLEFontImpl_IPersistPropertyBag_InitNew(
1989 IPersistPropertyBag
*iface
1991 FIXME("(%p), stub!\n", iface
);
1995 static HRESULT WINAPI
OLEFontImpl_IPersistPropertyBag_Load(
1996 IPersistPropertyBag
*iface
, IPropertyBag
* pPropBag
, IErrorLog
* pErrorLog
1998 /* (from Visual Basic 6 property bag)
1999 Name = "MS Sans Serif"
2003 Underline = 0 'False
2005 Strikethrough = 0 'False
2007 static const WCHAR sAttrName
[] = {'N','a','m','e',0};
2008 static const WCHAR sAttrSize
[] = {'S','i','z','e',0};
2009 static const WCHAR sAttrCharset
[] = {'C','h','a','r','s','e','t',0};
2010 static const WCHAR sAttrWeight
[] = {'W','e','i','g','h','t',0};
2011 static const WCHAR sAttrUnderline
[] = {'U','n','d','e','r','l','i','n','e',0};
2012 static const WCHAR sAttrItalic
[] = {'I','t','a','l','i','c',0};
2013 static const WCHAR sAttrStrikethrough
[] = {'S','t','r','i','k','e','t','h','r','o','u','g','h',0};
2014 OLEFontImpl
*this = impl_from_IPersistPropertyBag(iface
);
2018 VariantInit(&value
);
2020 iRes
= IPropertyBag_Read(pPropBag
, sAttrName
, &value
, pErrorLog
);
2023 iRes
= VariantChangeType(&value
, &value
, 0, VT_BSTR
);
2025 iRes
= IFont_put_Name(&this->IFont_iface
, V_BSTR(&value
));
2027 else if (iRes
== E_INVALIDARG
)
2030 VariantClear(&value
);
2033 iRes
= IPropertyBag_Read(pPropBag
, sAttrSize
, &value
, pErrorLog
);
2036 iRes
= VariantChangeType(&value
, &value
, 0, VT_CY
);
2038 iRes
= IFont_put_Size(&this->IFont_iface
, V_CY(&value
));
2040 else if (iRes
== E_INVALIDARG
)
2043 VariantClear(&value
);
2047 iRes
= IPropertyBag_Read(pPropBag
, sAttrCharset
, &value
, pErrorLog
);
2050 iRes
= VariantChangeType(&value
, &value
, 0, VT_I2
);
2052 iRes
= IFont_put_Charset(&this->IFont_iface
, V_I2(&value
));
2054 else if (iRes
== E_INVALIDARG
)
2057 VariantClear(&value
);
2061 iRes
= IPropertyBag_Read(pPropBag
, sAttrWeight
, &value
, pErrorLog
);
2064 iRes
= VariantChangeType(&value
, &value
, 0, VT_I2
);
2066 iRes
= IFont_put_Weight(&this->IFont_iface
, V_I2(&value
));
2068 else if (iRes
== E_INVALIDARG
)
2071 VariantClear(&value
);
2075 iRes
= IPropertyBag_Read(pPropBag
, sAttrUnderline
, &value
, pErrorLog
);
2078 iRes
= VariantChangeType(&value
, &value
, 0, VT_BOOL
);
2080 iRes
= IFont_put_Underline(&this->IFont_iface
, V_BOOL(&value
));
2082 else if (iRes
== E_INVALIDARG
)
2085 VariantClear(&value
);
2089 iRes
= IPropertyBag_Read(pPropBag
, sAttrItalic
, &value
, pErrorLog
);
2092 iRes
= VariantChangeType(&value
, &value
, 0, VT_BOOL
);
2094 iRes
= IFont_put_Italic(&this->IFont_iface
, V_BOOL(&value
));
2096 else if (iRes
== E_INVALIDARG
)
2099 VariantClear(&value
);
2103 iRes
= IPropertyBag_Read(pPropBag
, sAttrStrikethrough
, &value
, pErrorLog
);
2106 iRes
= VariantChangeType(&value
, &value
, 0, VT_BOOL
);
2108 IFont_put_Strikethrough(&this->IFont_iface
, V_BOOL(&value
));
2110 else if (iRes
== E_INVALIDARG
)
2113 VariantClear(&value
);
2117 WARN("-- 0x%08x\n", iRes
);
2121 static HRESULT WINAPI
OLEFontImpl_IPersistPropertyBag_Save(
2122 IPersistPropertyBag
*iface
, IPropertyBag
* pPropBag
, BOOL fClearDirty
,
2123 BOOL fSaveAllProperties
2125 FIXME("(%p,%p,%d,%d), stub!\n", iface
, pPropBag
, fClearDirty
, fSaveAllProperties
);
2129 static const IPersistPropertyBagVtbl OLEFontImpl_IPersistPropertyBag_VTable
=
2131 OLEFontImpl_IPersistPropertyBag_QueryInterface
,
2132 OLEFontImpl_IPersistPropertyBag_AddRef
,
2133 OLEFontImpl_IPersistPropertyBag_Release
,
2135 OLEFontImpl_IPersistPropertyBag_GetClassID
,
2136 OLEFontImpl_IPersistPropertyBag_InitNew
,
2137 OLEFontImpl_IPersistPropertyBag_Load
,
2138 OLEFontImpl_IPersistPropertyBag_Save
2141 /************************************************************************
2142 * OLEFontImpl implementation of IPersistStreamInit.
2144 static HRESULT WINAPI
OLEFontImpl_IPersistStreamInit_QueryInterface(
2145 IPersistStreamInit
*iface
, REFIID riid
, LPVOID
*ppvObj
2147 OLEFontImpl
*this = impl_from_IPersistStreamInit(iface
);
2148 return IFont_QueryInterface(&this->IFont_iface
,riid
,ppvObj
);
2151 static ULONG WINAPI
OLEFontImpl_IPersistStreamInit_AddRef(
2152 IPersistStreamInit
*iface
2154 OLEFontImpl
*this = impl_from_IPersistStreamInit(iface
);
2155 return IFont_AddRef(&this->IFont_iface
);
2158 static ULONG WINAPI
OLEFontImpl_IPersistStreamInit_Release(
2159 IPersistStreamInit
*iface
2161 OLEFontImpl
*this = impl_from_IPersistStreamInit(iface
);
2162 return IFont_Release(&this->IFont_iface
);
2165 static HRESULT WINAPI
OLEFontImpl_IPersistStreamInit_GetClassID(
2166 IPersistStreamInit
*iface
, CLSID
*classid
2168 FIXME("(%p,%p), stub!\n", iface
, classid
);
2172 static HRESULT WINAPI
OLEFontImpl_IPersistStreamInit_IsDirty(
2173 IPersistStreamInit
*iface
2175 FIXME("(%p), stub!\n", iface
);
2179 static HRESULT WINAPI
OLEFontImpl_IPersistStreamInit_Load(
2180 IPersistStreamInit
*iface
, LPSTREAM pStm
2182 FIXME("(%p,%p), stub!\n", iface
, pStm
);
2186 static HRESULT WINAPI
OLEFontImpl_IPersistStreamInit_Save(
2187 IPersistStreamInit
*iface
, LPSTREAM pStm
, BOOL fClearDirty
2189 FIXME("(%p,%p,%d), stub!\n", iface
, pStm
, fClearDirty
);
2193 static HRESULT WINAPI
OLEFontImpl_IPersistStreamInit_GetSizeMax(
2194 IPersistStreamInit
*iface
, ULARGE_INTEGER
*pcbSize
2196 FIXME("(%p,%p), stub!\n", iface
, pcbSize
);
2200 static HRESULT WINAPI
OLEFontImpl_IPersistStreamInit_InitNew(
2201 IPersistStreamInit
*iface
2203 FIXME("(%p), stub!\n", iface
);
2207 static const IPersistStreamInitVtbl OLEFontImpl_IPersistStreamInit_VTable
=
2209 OLEFontImpl_IPersistStreamInit_QueryInterface
,
2210 OLEFontImpl_IPersistStreamInit_AddRef
,
2211 OLEFontImpl_IPersistStreamInit_Release
,
2213 OLEFontImpl_IPersistStreamInit_GetClassID
,
2214 OLEFontImpl_IPersistStreamInit_IsDirty
,
2215 OLEFontImpl_IPersistStreamInit_Load
,
2216 OLEFontImpl_IPersistStreamInit_Save
,
2217 OLEFontImpl_IPersistStreamInit_GetSizeMax
,
2218 OLEFontImpl_IPersistStreamInit_InitNew
2221 /************************************************************************
2222 * OLEFontImpl_Construct
2224 * This method will construct a new instance of the OLEFontImpl
2227 * The caller of this method must release the object when it's
2230 static OLEFontImpl
* OLEFontImpl_Construct(const FONTDESC
*fontDesc
)
2232 OLEFontImpl
* newObject
;
2234 newObject
= HeapAlloc(GetProcessHeap(), 0, sizeof(OLEFontImpl
));
2239 newObject
->IFont_iface
.lpVtbl
= &OLEFontImpl_VTable
;
2240 newObject
->IDispatch_iface
.lpVtbl
= &OLEFontImpl_IDispatch_VTable
;
2241 newObject
->IPersistStream_iface
.lpVtbl
= &OLEFontImpl_IPersistStream_VTable
;
2242 newObject
->IConnectionPointContainer_iface
.lpVtbl
= &OLEFontImpl_IConnectionPointContainer_VTable
;
2243 newObject
->IPersistPropertyBag_iface
.lpVtbl
= &OLEFontImpl_IPersistPropertyBag_VTable
;
2244 newObject
->IPersistStreamInit_iface
.lpVtbl
= &OLEFontImpl_IPersistStreamInit_VTable
;
2248 newObject
->description
.cbSizeofstruct
= sizeof(FONTDESC
);
2249 newObject
->description
.lpstrName
= HeapAlloc(GetProcessHeap(),
2251 (lstrlenW(fontDesc
->lpstrName
)+1) * sizeof(WCHAR
));
2252 strcpyW(newObject
->description
.lpstrName
, fontDesc
->lpstrName
);
2253 newObject
->description
.cySize
= fontDesc
->cySize
;
2254 newObject
->description
.sWeight
= fontDesc
->sWeight
;
2255 newObject
->description
.sCharset
= fontDesc
->sCharset
;
2256 newObject
->description
.fItalic
= fontDesc
->fItalic
;
2257 newObject
->description
.fUnderline
= fontDesc
->fUnderline
;
2258 newObject
->description
.fStrikethrough
= fontDesc
->fStrikethrough
;
2260 newObject
->gdiFont
= 0;
2261 newObject
->dirty
= TRUE
;
2262 newObject
->cyLogical
= GetDeviceCaps(get_dc(), LOGPIXELSY
);
2263 newObject
->cyHimetric
= 2540L;
2264 newObject
->pPropertyNotifyCP
= NULL
;
2265 newObject
->pFontEventsCP
= NULL
;
2267 CreateConnectionPoint((IUnknown
*)newObject
, &IID_IPropertyNotifySink
, &newObject
->pPropertyNotifyCP
);
2268 CreateConnectionPoint((IUnknown
*)newObject
, &IID_IFontEventsDisp
, &newObject
->pFontEventsCP
);
2270 if (!newObject
->pPropertyNotifyCP
|| !newObject
->pFontEventsCP
)
2272 OLEFontImpl_Destroy(newObject
);
2276 InterlockedIncrement(&ifont_cnt
);
2278 TRACE("returning %p\n", newObject
);
2282 /************************************************************************
2283 * OLEFontImpl_Destroy
2285 * This method is called by the Release method when the reference
2286 * count goes down to 0. It will free all resources used by
2289 static void OLEFontImpl_Destroy(OLEFontImpl
* fontDesc
)
2291 TRACE("(%p)\n", fontDesc
);
2293 HeapFree(GetProcessHeap(), 0, fontDesc
->description
.lpstrName
);
2295 if (fontDesc
->pPropertyNotifyCP
)
2296 IConnectionPoint_Release(fontDesc
->pPropertyNotifyCP
);
2297 if (fontDesc
->pFontEventsCP
)
2298 IConnectionPoint_Release(fontDesc
->pFontEventsCP
);
2300 HeapFree(GetProcessHeap(), 0, fontDesc
);
2303 /*******************************************************************************
2304 * StdFont ClassFactory
2308 /* IUnknown fields */
2309 IClassFactory IClassFactory_iface
;
2311 } IClassFactoryImpl
;
2313 static inline IClassFactoryImpl
*impl_from_IClassFactory(IClassFactory
*iface
)
2315 return CONTAINING_RECORD(iface
, IClassFactoryImpl
, IClassFactory_iface
);
2318 static HRESULT WINAPI
2319 SFCF_QueryInterface(LPCLASSFACTORY iface
,REFIID riid
,LPVOID
*ppobj
) {
2320 IClassFactoryImpl
*This
= impl_from_IClassFactory(iface
);
2322 FIXME("(%p)->(%s,%p),stub!\n",This
,debugstr_guid(riid
),ppobj
);
2323 return E_NOINTERFACE
;
2327 SFCF_AddRef(LPCLASSFACTORY iface
) {
2328 IClassFactoryImpl
*This
= impl_from_IClassFactory(iface
);
2329 return InterlockedIncrement(&This
->ref
);
2332 static ULONG WINAPI
SFCF_Release(LPCLASSFACTORY iface
) {
2333 IClassFactoryImpl
*This
= impl_from_IClassFactory(iface
);
2334 /* static class, won't be freed */
2335 return InterlockedDecrement(&This
->ref
);
2338 static HRESULT WINAPI
SFCF_CreateInstance(
2339 LPCLASSFACTORY iface
,LPUNKNOWN pOuter
,REFIID riid
,LPVOID
*ppobj
2341 return OleCreateFontIndirect(NULL
,riid
,ppobj
);
2345 static HRESULT WINAPI
SFCF_LockServer(LPCLASSFACTORY iface
,BOOL dolock
) {
2346 IClassFactoryImpl
*This
= impl_from_IClassFactory(iface
);
2347 FIXME("(%p)->(%d),stub!\n",This
,dolock
);
2351 static const IClassFactoryVtbl SFCF_Vtbl
= {
2352 SFCF_QueryInterface
,
2355 SFCF_CreateInstance
,
2358 static IClassFactoryImpl STDFONT_CF
= {{&SFCF_Vtbl
}, 1 };
2360 void _get_STDFONT_CF(LPVOID
*ppv
) { *ppv
= &STDFONT_CF
; }