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
57 /***********************************************************************
58 * List of the HFONTs it has given out, with each one having a separate
61 typedef struct _HFONTItem
65 /* Reference count for that instance of the class. */
68 /* Contain 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 void HFONTItem_Delete(PHFONTItem item
)
93 DeleteObject(item
->gdiFont
);
94 list_remove(&item
->entry
);
95 HeapFree(GetProcessHeap(), 0, item
);
98 /***********************************************************************
99 * Declaration of the implementation class for the IFont interface
101 typedef struct OLEFontImpl OLEFontImpl
;
106 * This class supports many interfaces. IUnknown, IFont,
107 * IDispatch, IDispFont IPersistStream and IConnectionPointContainer.
108 * The first two are supported by the first vtable, the next two are
109 * supported by the second table and the last two have their own.
111 const IFontVtbl
* lpVtbl
;
112 const IDispatchVtbl
* lpvtblIDispatch
;
113 const IPersistStreamVtbl
* lpvtblIPersistStream
;
114 const IConnectionPointContainerVtbl
* lpvtblIConnectionPointContainer
;
115 const IPersistPropertyBagVtbl
* lpvtblIPersistPropertyBag
;
116 const IPersistStreamInitVtbl
* lpvtblIPersistStreamInit
;
118 * Reference count for that instance of the class.
123 * This structure contains the description of the class.
125 FONTDESC description
;
128 * Contain the font associated with this object.
138 IConnectionPoint
*pPropertyNotifyCP
;
139 IConnectionPoint
*pFontEventsCP
;
143 * Here, I define utility macros to help with the casting of the
145 * There is a version to accommodate all of the VTables implemented
149 static inline OLEFontImpl
*impl_from_IDispatch( IDispatch
*iface
)
151 return (OLEFontImpl
*)((char*)iface
- FIELD_OFFSET(OLEFontImpl
, lpvtblIDispatch
));
154 static inline OLEFontImpl
*impl_from_IPersistStream( IPersistStream
*iface
)
156 return (OLEFontImpl
*)((char*)iface
- FIELD_OFFSET(OLEFontImpl
, lpvtblIPersistStream
));
159 static inline OLEFontImpl
*impl_from_IConnectionPointContainer( IConnectionPointContainer
*iface
)
161 return (OLEFontImpl
*)((char*)iface
- FIELD_OFFSET(OLEFontImpl
, lpvtblIConnectionPointContainer
));
164 static inline OLEFontImpl
*impl_from_IPersistPropertyBag( IPersistPropertyBag
*iface
)
166 return (OLEFontImpl
*)((char*)iface
- FIELD_OFFSET(OLEFontImpl
, lpvtblIPersistPropertyBag
));
169 static inline OLEFontImpl
*impl_from_IPersistStreamInit( IPersistStreamInit
*iface
)
171 return (OLEFontImpl
*)((char*)iface
- FIELD_OFFSET(OLEFontImpl
, lpvtblIPersistStreamInit
));
175 /***********************************************************************
176 * Prototypes for the implementation functions for the IFont
179 static OLEFontImpl
* OLEFontImpl_Construct(const FONTDESC
*fontDesc
);
180 static void OLEFontImpl_Destroy(OLEFontImpl
* fontDesc
);
181 static ULONG WINAPI
OLEFontImpl_AddRef(IFont
* iface
);
183 /******************************************************************************
184 * OleCreateFontIndirect [OLEAUT32.420]
186 HRESULT WINAPI
OleCreateFontIndirect(
187 LPFONTDESC lpFontDesc
,
191 OLEFontImpl
* newFont
= 0;
194 TRACE("(%p, %s, %p)\n", lpFontDesc
, debugstr_guid(riid
), ppvObj
);
206 static WCHAR fname
[] = { 'S','y','s','t','e','m',0 };
208 fd
.cbSizeofstruct
= sizeof(fd
);
209 fd
.lpstrName
= fname
;
210 fd
.cySize
.s
.Lo
= 80000;
216 fd
.fStrikethrough
= 0;
221 * Try to construct a new instance of the class.
223 newFont
= OLEFontImpl_Construct(lpFontDesc
);
226 return E_OUTOFMEMORY
;
229 * Make sure it supports the interface required by the caller.
231 hr
= IFont_QueryInterface((IFont
*)newFont
, riid
, ppvObj
);
234 * Release the reference obtained in the constructor. If
235 * the QueryInterface was unsuccessful, it will free the class.
237 IFont_Release((IFont
*)newFont
);
243 /***********************************************************************
244 * Implementation of the OLEFontImpl class.
247 /***********************************************************************
248 * OLEFont_SendNotify (internal)
250 * Sends notification messages of changed properties to any interested
253 static void OLEFont_SendNotify(OLEFontImpl
* this, DISPID dispID
)
255 static const WCHAR wszName
[] = {'N','a','m','e',0};
256 static const WCHAR wszSize
[] = {'S','i','z','e',0};
257 static const WCHAR wszBold
[] = {'B','o','l','d',0};
258 static const WCHAR wszItalic
[] = {'I','t','a','l','i','c',0};
259 static const WCHAR wszUnder
[] = {'U','n','d','e','r','l','i','n','e',0};
260 static const WCHAR wszStrike
[] = {'S','t','r','i','k','e','t','h','r','o','u','g','h',0};
261 static const WCHAR wszWeight
[] = {'W','e','i','g','h','t',0};
262 static const WCHAR wszCharset
[] = {'C','h','a','r','s','s','e','t',0};
263 static const LPCWSTR dispid_mapping
[] =
276 IEnumConnections
*pEnum
;
281 hres
= IConnectionPoint_EnumConnections(this->pPropertyNotifyCP
, &pEnum
);
284 while(IEnumConnections_Next(pEnum
, 1, &CD
, NULL
) == S_OK
) {
285 IPropertyNotifySink
*sink
;
287 IUnknown_QueryInterface(CD
.pUnk
, &IID_IPropertyNotifySink
, (LPVOID
)&sink
);
288 IPropertyNotifySink_OnChanged(sink
, dispID
);
289 IPropertyNotifySink_Release(sink
);
290 IUnknown_Release(CD
.pUnk
);
292 IEnumConnections_Release(pEnum
);
295 hres
= IConnectionPoint_EnumConnections(this->pFontEventsCP
, &pEnum
);
298 DISPPARAMS dispparams
;
301 VariantInit(&vararg
);
302 V_VT(&vararg
) = VT_BSTR
;
303 V_BSTR(&vararg
) = SysAllocString(dispid_mapping
[dispID
]);
305 dispparams
.cArgs
= 1;
306 dispparams
.cNamedArgs
= 0;
307 dispparams
.rgdispidNamedArgs
= NULL
;
308 dispparams
.rgvarg
= &vararg
;
310 while(IEnumConnections_Next(pEnum
, 1, &CD
, NULL
) == S_OK
) {
311 IFontEventsDisp
*disp
;
313 IUnknown_QueryInterface(CD
.pUnk
, &IID_IFontEventsDisp
, (LPVOID
)&disp
);
314 IDispatch_Invoke(disp
, DISPID_FONT_CHANGED
, &IID_NULL
,
315 LOCALE_NEUTRAL
, INVOKE_FUNC
, &dispparams
, NULL
,
318 IDispatch_Release(disp
);
319 IUnknown_Release(CD
.pUnk
);
321 VariantClear(&vararg
);
322 IEnumConnections_Release(pEnum
);
326 /************************************************************************
327 * OLEFontImpl_QueryInterface (IUnknown)
329 * See Windows documentation for more details on IUnknown methods.
331 static HRESULT WINAPI
OLEFontImpl_QueryInterface(
336 OLEFontImpl
*this = (OLEFontImpl
*)iface
;
337 TRACE("(%p)->(%s, %p)\n", this, debugstr_guid(riid
), ppvObject
);
340 * Perform a sanity check on the parameters.
342 if ( (this==0) || (ppvObject
==0) )
346 * Initialize the return parameter.
351 * Compare the riid with the interface IDs implemented by this object.
353 if (IsEqualGUID(&IID_IUnknown
, riid
))
355 if (IsEqualGUID(&IID_IFont
, riid
))
357 if (IsEqualGUID(&IID_IDispatch
, riid
))
358 *ppvObject
= &this->lpvtblIDispatch
;
359 if (IsEqualGUID(&IID_IFontDisp
, riid
))
360 *ppvObject
= &this->lpvtblIDispatch
;
361 if (IsEqualIID(&IID_IPersist
, riid
) || IsEqualGUID(&IID_IPersistStream
, riid
))
362 *ppvObject
= &this->lpvtblIPersistStream
;
363 if (IsEqualGUID(&IID_IConnectionPointContainer
, riid
))
364 *ppvObject
= &this->lpvtblIConnectionPointContainer
;
365 if (IsEqualGUID(&IID_IPersistPropertyBag
, riid
))
366 *ppvObject
= &this->lpvtblIPersistPropertyBag
;
367 if (IsEqualGUID(&IID_IPersistStreamInit
, riid
))
368 *ppvObject
= &this->lpvtblIPersistStreamInit
;
371 * Check that we obtained an interface.
375 FIXME("() : asking for unsupported interface %s\n",debugstr_guid(riid
));
376 return E_NOINTERFACE
;
378 OLEFontImpl_AddRef((IFont
*)this);
382 /************************************************************************
383 * OLEFontImpl_AddRef (IUnknown)
385 * See Windows documentation for more details on IUnknown methods.
387 static ULONG WINAPI
OLEFontImpl_AddRef(
390 OLEFontImpl
*this = (OLEFontImpl
*)iface
;
391 TRACE("(%p)->(ref=%d)\n", this, this->ref
);
392 return InterlockedIncrement(&this->ref
);
395 /************************************************************************
396 * OLEFontImpl_Release (IUnknown)
398 * See Windows documentation for more details on IUnknown methods.
400 static ULONG WINAPI
OLEFontImpl_Release(
403 OLEFontImpl
*this = (OLEFontImpl
*)iface
;
405 PHFONTItem ptr
, next
;
406 TRACE("(%p)->(ref=%d)\n", this, this->ref
);
408 /* Decrease the reference count for current interface */
409 ret
= InterlockedDecrement(&this->ref
);
411 /* If the reference count goes down to 0, destroy. */
414 ULONG fontlist_refs
= InterlockedDecrement(&ifont_cnt
);
415 /* Check if all HFONT list refs are zero */
416 if (fontlist_refs
== 0)
418 EnterCriticalSection(&OLEFontImpl_csHFONTLIST
);
419 LIST_FOR_EACH_ENTRY_SAFE(ptr
, next
, &OLEFontImpl_hFontList
, HFONTItem
, entry
)
420 HFONTItem_Delete(ptr
);
421 LeaveCriticalSection(&OLEFontImpl_csHFONTLIST
);
423 OLEFontImpl_Destroy(this);
429 /************************************************************************
430 * OLEFontImpl_get_Name (IFont)
432 * See Windows documentation for more details on IFont methods.
434 static HRESULT WINAPI
OLEFontImpl_get_Name(
438 OLEFontImpl
*this = (OLEFontImpl
*)iface
;
439 TRACE("(%p)->(%p)\n", this, pname
);
446 if (this->description
.lpstrName
!=0)
447 *pname
= SysAllocString(this->description
.lpstrName
);
454 /************************************************************************
455 * OLEFontImpl_put_Name (IFont)
457 * See Windows documentation for more details on IFont methods.
459 static HRESULT WINAPI
OLEFontImpl_put_Name(
463 OLEFontImpl
*this = (OLEFontImpl
*)iface
;
464 TRACE("(%p)->(%p)\n", this, name
);
467 return CTL_E_INVALIDPROPERTYVALUE
;
469 if (this->description
.lpstrName
==0)
471 this->description
.lpstrName
= HeapAlloc(GetProcessHeap(),
473 (lstrlenW(name
)+1) * sizeof(WCHAR
));
477 this->description
.lpstrName
= HeapReAlloc(GetProcessHeap(),
479 this->description
.lpstrName
,
480 (lstrlenW(name
)+1) * sizeof(WCHAR
));
483 if (this->description
.lpstrName
==0)
484 return E_OUTOFMEMORY
;
486 strcpyW(this->description
.lpstrName
, name
);
487 TRACE("new name %s\n", debugstr_w(this->description
.lpstrName
));
488 OLEFont_SendNotify(this, DISPID_FONT_NAME
);
492 /************************************************************************
493 * OLEFontImpl_get_Size (IFont)
495 * See Windows documentation for more details on IFont methods.
497 static HRESULT WINAPI
OLEFontImpl_get_Size(
501 OLEFontImpl
*this = (OLEFontImpl
*)iface
;
502 TRACE("(%p)->(%p)\n", this, psize
);
511 psize
->s
.Lo
= this->description
.cySize
.s
.Lo
;
516 /************************************************************************
517 * OLEFontImpl_put_Size (IFont)
519 * See Windows documentation for more details on IFont methods.
521 static HRESULT WINAPI
OLEFontImpl_put_Size(
525 OLEFontImpl
*this = (OLEFontImpl
*)iface
;
526 TRACE("(%p)->(%d)\n", this, size
.s
.Lo
);
527 this->description
.cySize
.s
.Hi
= 0;
528 this->description
.cySize
.s
.Lo
= size
.s
.Lo
;
529 OLEFont_SendNotify(this, DISPID_FONT_SIZE
);
534 /************************************************************************
535 * OLEFontImpl_get_Bold (IFont)
537 * See Windows documentation for more details on IFont methods.
539 static HRESULT WINAPI
OLEFontImpl_get_Bold(
543 OLEFontImpl
*this = (OLEFontImpl
*)iface
;
544 TRACE("(%p)->(%p)\n", this, pbold
);
551 *pbold
= this->description
.sWeight
> 550;
556 /************************************************************************
557 * OLEFontImpl_put_Bold (IFont)
559 * See Windows documentation for more details on IFont methods.
561 static HRESULT WINAPI
OLEFontImpl_put_Bold(
565 OLEFontImpl
*this = (OLEFontImpl
*)iface
;
566 TRACE("(%p)->(%d)\n", this, bold
);
567 this->description
.sWeight
= bold
? FW_BOLD
: FW_NORMAL
;
568 OLEFont_SendNotify(this, DISPID_FONT_BOLD
);
573 /************************************************************************
574 * OLEFontImpl_get_Italic (IFont)
576 * See Windows documentation for more details on IFont methods.
578 static HRESULT WINAPI
OLEFontImpl_get_Italic(
582 OLEFontImpl
*this = (OLEFontImpl
*)iface
;
583 TRACE("(%p)->(%p)\n", this, pitalic
);
590 *pitalic
= this->description
.fItalic
;
595 /************************************************************************
596 * OLEFontImpl_put_Italic (IFont)
598 * See Windows documentation for more details on IFont methods.
600 static HRESULT WINAPI
OLEFontImpl_put_Italic(
604 OLEFontImpl
*this = (OLEFontImpl
*)iface
;
605 TRACE("(%p)->(%d)\n", this, italic
);
607 this->description
.fItalic
= italic
;
609 OLEFont_SendNotify(this, DISPID_FONT_ITALIC
);
613 /************************************************************************
614 * OLEFontImpl_get_Underline (IFont)
616 * See Windows documentation for more details on IFont methods.
618 static HRESULT WINAPI
OLEFontImpl_get_Underline(
622 OLEFontImpl
*this = (OLEFontImpl
*)iface
;
623 TRACE("(%p)->(%p)\n", this, punderline
);
631 *punderline
= this->description
.fUnderline
;
636 /************************************************************************
637 * OLEFontImpl_put_Underline (IFont)
639 * See Windows documentation for more details on IFont methods.
641 static HRESULT WINAPI
OLEFontImpl_put_Underline(
645 OLEFontImpl
*this = (OLEFontImpl
*)iface
;
646 TRACE("(%p)->(%d)\n", this, underline
);
648 this->description
.fUnderline
= underline
;
650 OLEFont_SendNotify(this, DISPID_FONT_UNDER
);
654 /************************************************************************
655 * OLEFontImpl_get_Strikethrough (IFont)
657 * See Windows documentation for more details on IFont methods.
659 static HRESULT WINAPI
OLEFontImpl_get_Strikethrough(
661 BOOL
* pstrikethrough
)
663 OLEFontImpl
*this = (OLEFontImpl
*)iface
;
664 TRACE("(%p)->(%p)\n", this, pstrikethrough
);
669 if (pstrikethrough
==0)
672 *pstrikethrough
= this->description
.fStrikethrough
;
677 /************************************************************************
678 * OLEFontImpl_put_Strikethrough (IFont)
680 * See Windows documentation for more details on IFont methods.
682 static HRESULT WINAPI
OLEFontImpl_put_Strikethrough(
686 OLEFontImpl
*this = (OLEFontImpl
*)iface
;
687 TRACE("(%p)->(%d)\n", this, strikethrough
);
689 this->description
.fStrikethrough
= strikethrough
;
690 OLEFont_SendNotify(this, DISPID_FONT_STRIKE
);
695 /************************************************************************
696 * OLEFontImpl_get_Weight (IFont)
698 * See Windows documentation for more details on IFont methods.
700 static HRESULT WINAPI
OLEFontImpl_get_Weight(
704 OLEFontImpl
*this = (OLEFontImpl
*)iface
;
705 TRACE("(%p)->(%p)\n", this, pweight
);
713 *pweight
= this->description
.sWeight
;
718 /************************************************************************
719 * OLEFontImpl_put_Weight (IFont)
721 * See Windows documentation for more details on IFont methods.
723 static HRESULT WINAPI
OLEFontImpl_put_Weight(
727 OLEFontImpl
*this = (OLEFontImpl
*)iface
;
728 TRACE("(%p)->(%d)\n", this, weight
);
730 this->description
.sWeight
= weight
;
732 OLEFont_SendNotify(this, DISPID_FONT_WEIGHT
);
736 /************************************************************************
737 * OLEFontImpl_get_Charset (IFont)
739 * See Windows documentation for more details on IFont methods.
741 static HRESULT WINAPI
OLEFontImpl_get_Charset(
745 OLEFontImpl
*this = (OLEFontImpl
*)iface
;
746 TRACE("(%p)->(%p)\n", this, pcharset
);
754 *pcharset
= this->description
.sCharset
;
759 /************************************************************************
760 * OLEFontImpl_put_Charset (IFont)
762 * See Windows documentation for more details on IFont methods.
764 static HRESULT WINAPI
OLEFontImpl_put_Charset(
768 OLEFontImpl
*this = (OLEFontImpl
*)iface
;
769 TRACE("(%p)->(%d)\n", this, charset
);
771 this->description
.sCharset
= charset
;
772 OLEFont_SendNotify(this, DISPID_FONT_CHARSET
);
777 /************************************************************************
778 * OLEFontImpl_get_hFont (IFont)
780 * See Windows documentation for more details on IFont methods.
782 static HRESULT WINAPI
OLEFontImpl_get_hFont(
786 OLEFontImpl
*this = (OLEFontImpl
*)iface
;
787 TRACE("(%p)->(%p)\n", this, phfont
);
792 * Realize the font if necessary
794 if (this->gdiFont
==0)
802 * The height of the font returned by the get_Size property is the
803 * height of the font in points multiplied by 10000... Using some
804 * simple conversions and the ratio given by the application, it can
805 * be converted to a height in pixels.
807 IFont_get_Size(iface
, &cySize
);
809 /* Standard ratio is 72 / 2540, or 18 / 635 in lowest terms. */
810 /* Ratio is applied here relative to the standard. */
811 fontHeight
= MulDiv( cySize
.s
.Lo
, this->cyLogical
*635, this->cyHimetric
*18 );
813 memset(&logFont
, 0, sizeof(LOGFONTW
));
815 logFont
.lfHeight
= ((fontHeight
%10000L)>5000L) ? (-fontHeight
/10000L)-1 :
816 (-fontHeight
/10000L);
817 logFont
.lfItalic
= this->description
.fItalic
;
818 logFont
.lfUnderline
= this->description
.fUnderline
;
819 logFont
.lfStrikeOut
= this->description
.fStrikethrough
;
820 logFont
.lfWeight
= this->description
.sWeight
;
821 logFont
.lfCharSet
= this->description
.sCharset
;
822 logFont
.lfOutPrecision
= OUT_CHARACTER_PRECIS
;
823 logFont
.lfClipPrecision
= CLIP_DEFAULT_PRECIS
;
824 logFont
.lfQuality
= DEFAULT_QUALITY
;
825 logFont
.lfPitchAndFamily
= DEFAULT_PITCH
;
826 strcpyW(logFont
.lfFaceName
,this->description
.lpstrName
);
828 this->gdiFont
= CreateFontIndirectW(&logFont
);
830 /* Add font to the cache */
831 newEntry
= HeapAlloc(GetProcessHeap(), 0, sizeof(HFONTItem
));
833 newEntry
->gdiFont
= this->gdiFont
;
834 EnterCriticalSection(&OLEFontImpl_csHFONTLIST
);
835 list_add_tail(&OLEFontImpl_hFontList
,&newEntry
->entry
);
836 LeaveCriticalSection(&OLEFontImpl_csHFONTLIST
);
839 *phfont
= this->gdiFont
;
840 TRACE("Returning %p\n", *phfont
);
844 /************************************************************************
845 * OLEFontImpl_Clone (IFont)
847 * See Windows documentation for more details on IFont methods.
849 static HRESULT WINAPI
OLEFontImpl_Clone(
853 OLEFontImpl
* newObject
= 0;
859 OLEFontImpl
*this = (OLEFontImpl
*)iface
;
860 TRACE("(%p)->(%p)\n", this, ppfont
);
868 * Allocate space for the object.
870 newObject
= HeapAlloc(GetProcessHeap(), 0, sizeof(OLEFontImpl
));
873 return E_OUTOFMEMORY
;
877 /* We need to alloc new memory for the string, otherwise
878 * we free memory twice.
880 newObject
->description
.lpstrName
= HeapAlloc(
882 (1+strlenW(this->description
.lpstrName
))*2
884 strcpyW(newObject
->description
.lpstrName
, this->description
.lpstrName
);
885 /* We need to clone the HFONT too. This is just cut & paste from above */
886 IFont_get_Size(iface
, &cySize
);
888 fontHeight
= MulDiv(cySize
.s
.Lo
, this->cyLogical
*635,this->cyHimetric
*18);
890 memset(&logFont
, 0, sizeof(LOGFONTW
));
892 logFont
.lfHeight
= ((fontHeight
%10000L)>5000L) ? (-fontHeight
/10000L)-1 :
893 (-fontHeight
/10000L);
894 logFont
.lfItalic
= this->description
.fItalic
;
895 logFont
.lfUnderline
= this->description
.fUnderline
;
896 logFont
.lfStrikeOut
= this->description
.fStrikethrough
;
897 logFont
.lfWeight
= this->description
.sWeight
;
898 logFont
.lfCharSet
= this->description
.sCharset
;
899 logFont
.lfOutPrecision
= OUT_CHARACTER_PRECIS
;
900 logFont
.lfClipPrecision
= CLIP_DEFAULT_PRECIS
;
901 logFont
.lfQuality
= DEFAULT_QUALITY
;
902 logFont
.lfPitchAndFamily
= DEFAULT_PITCH
;
903 strcpyW(logFont
.lfFaceName
,this->description
.lpstrName
);
905 newObject
->gdiFont
= CreateFontIndirectW(&logFont
);
907 /* Add font to the cache */
908 InterlockedIncrement(&ifont_cnt
);
909 newEntry
= HeapAlloc(GetProcessHeap(), 0, sizeof(HFONTItem
));
911 newEntry
->gdiFont
= newObject
->gdiFont
;
912 EnterCriticalSection(&OLEFontImpl_csHFONTLIST
);
913 list_add_tail(&OLEFontImpl_hFontList
,&newEntry
->entry
);
914 LeaveCriticalSection(&OLEFontImpl_csHFONTLIST
);
916 /* create new connection points */
917 newObject
->pPropertyNotifyCP
= NULL
;
918 newObject
->pFontEventsCP
= NULL
;
919 CreateConnectionPoint((IUnknown
*)newObject
, &IID_IPropertyNotifySink
, &newObject
->pPropertyNotifyCP
);
920 CreateConnectionPoint((IUnknown
*)newObject
, &IID_IFontEventsDisp
, &newObject
->pFontEventsCP
);
922 if (!newObject
->pPropertyNotifyCP
|| !newObject
->pFontEventsCP
)
924 OLEFontImpl_Destroy(newObject
);
925 return E_OUTOFMEMORY
;
928 /* The cloned object starts with a reference count of 1 */
931 *ppfont
= (IFont
*)newObject
;
936 /************************************************************************
937 * OLEFontImpl_IsEqual (IFont)
939 * See Windows documentation for more details on IFont methods.
941 static HRESULT WINAPI
OLEFontImpl_IsEqual(
945 OLEFontImpl
*left
= (OLEFontImpl
*)iface
;
946 OLEFontImpl
*right
= (OLEFontImpl
*)pFontOther
;
948 INT left_len
,right_len
;
950 if((iface
== NULL
) || (pFontOther
== NULL
))
952 else if (left
->description
.cySize
.s
.Lo
!= right
->description
.cySize
.s
.Lo
)
954 else if (left
->description
.cySize
.s
.Hi
!= right
->description
.cySize
.s
.Hi
)
956 else if (left
->description
.sWeight
!= right
->description
.sWeight
)
958 else if (left
->description
.sCharset
!= right
->description
.sCharset
)
960 else if (left
->description
.fItalic
!= right
->description
.fItalic
)
962 else if (left
->description
.fUnderline
!= right
->description
.fUnderline
)
964 else if (left
->description
.fStrikethrough
!= right
->description
.fStrikethrough
)
967 /* Check from string */
968 left_len
= strlenW(left
->description
.lpstrName
);
969 right_len
= strlenW(right
->description
.lpstrName
);
970 ret
= CompareStringW(0,0,left
->description
.lpstrName
, left_len
,
971 right
->description
.lpstrName
, right_len
);
972 if (ret
!= CSTR_EQUAL
)
978 /************************************************************************
979 * OLEFontImpl_SetRatio (IFont)
981 * See Windows documentation for more details on IFont methods.
983 static HRESULT WINAPI
OLEFontImpl_SetRatio(
988 OLEFontImpl
*this = (OLEFontImpl
*)iface
;
989 TRACE("(%p)->(%d, %d)\n", this, cyLogical
, cyHimetric
);
991 this->cyLogical
= cyLogical
;
992 this->cyHimetric
= cyHimetric
;
997 /************************************************************************
998 * OLEFontImpl_QueryTextMetrics (IFont)
1000 * See Windows documentation for more details on IFont methods.
1002 static HRESULT WINAPI
OLEFontImpl_QueryTextMetrics(
1007 HFONT hOldFont
, hNewFont
;
1010 OLEFontImpl_get_hFont(iface
, &hNewFont
);
1011 hOldFont
= SelectObject(hdcRef
, hNewFont
);
1012 GetTextMetricsW(hdcRef
, ptm
);
1013 SelectObject(hdcRef
, hOldFont
);
1014 ReleaseDC(0, hdcRef
);
1018 /************************************************************************
1019 * OLEFontImpl_AddRefHfont (IFont)
1021 * See Windows documentation for more details on IFont methods.
1023 static HRESULT WINAPI
OLEFontImpl_AddRefHfont(
1027 OLEFontImpl
*this = (OLEFontImpl
*)iface
;
1028 PHFONTItem ptr
, next
;
1029 HRESULT hres
= S_FALSE
; /* assume not present */
1031 TRACE("(%p)->(%p)\n", this, hfont
);
1034 return E_INVALIDARG
;
1036 /* Check of the hFont is already in the list */
1037 EnterCriticalSection(&OLEFontImpl_csHFONTLIST
);
1038 LIST_FOR_EACH_ENTRY_SAFE(ptr
, next
, &OLEFontImpl_hFontList
, HFONTItem
, entry
)
1040 if (ptr
->gdiFont
== hfont
)
1047 LeaveCriticalSection(&OLEFontImpl_csHFONTLIST
);
1052 /************************************************************************
1053 * OLEFontImpl_ReleaseHfont (IFont)
1055 * See Windows documentation for more details on IFont methods.
1057 static HRESULT WINAPI
OLEFontImpl_ReleaseHfont(
1061 OLEFontImpl
*this = (OLEFontImpl
*)iface
;
1062 PHFONTItem ptr
, next
;
1063 HRESULT hres
= S_FALSE
; /* assume not present */
1065 TRACE("(%p)->(%p)\n", this, hfont
);
1068 return E_INVALIDARG
;
1070 /* Check of the hFont is already in the list */
1071 EnterCriticalSection(&OLEFontImpl_csHFONTLIST
);
1072 LIST_FOR_EACH_ENTRY_SAFE(ptr
, next
, &OLEFontImpl_hFontList
, HFONTItem
, entry
)
1074 if ((ptr
->gdiFont
== hfont
) && ptr
->ref
)
1076 /* Remove from cache and delete object if not referenced */
1079 if (ptr
->gdiFont
== this->gdiFont
)
1080 this->gdiFont
= NULL
;
1086 LeaveCriticalSection(&OLEFontImpl_csHFONTLIST
);
1091 /************************************************************************
1092 * OLEFontImpl_SetHdc (IFont)
1094 * See Windows documentation for more details on IFont methods.
1096 static HRESULT WINAPI
OLEFontImpl_SetHdc(
1100 OLEFontImpl
*this = (OLEFontImpl
*)iface
;
1101 FIXME("(%p)->(%p): Stub\n", this, hdc
);
1106 * Virtual function tables for the OLEFontImpl class.
1108 static const IFontVtbl OLEFontImpl_VTable
=
1110 OLEFontImpl_QueryInterface
,
1112 OLEFontImpl_Release
,
1113 OLEFontImpl_get_Name
,
1114 OLEFontImpl_put_Name
,
1115 OLEFontImpl_get_Size
,
1116 OLEFontImpl_put_Size
,
1117 OLEFontImpl_get_Bold
,
1118 OLEFontImpl_put_Bold
,
1119 OLEFontImpl_get_Italic
,
1120 OLEFontImpl_put_Italic
,
1121 OLEFontImpl_get_Underline
,
1122 OLEFontImpl_put_Underline
,
1123 OLEFontImpl_get_Strikethrough
,
1124 OLEFontImpl_put_Strikethrough
,
1125 OLEFontImpl_get_Weight
,
1126 OLEFontImpl_put_Weight
,
1127 OLEFontImpl_get_Charset
,
1128 OLEFontImpl_put_Charset
,
1129 OLEFontImpl_get_hFont
,
1131 OLEFontImpl_IsEqual
,
1132 OLEFontImpl_SetRatio
,
1133 OLEFontImpl_QueryTextMetrics
,
1134 OLEFontImpl_AddRefHfont
,
1135 OLEFontImpl_ReleaseHfont
,
1139 /************************************************************************
1140 * OLEFontImpl_IDispatch_QueryInterface (IUnknown)
1142 * See Windows documentation for more details on IUnknown methods.
1144 static HRESULT WINAPI
OLEFontImpl_IDispatch_QueryInterface(
1149 OLEFontImpl
*this = impl_from_IDispatch(iface
);
1151 return IFont_QueryInterface((IFont
*)this, riid
, ppvoid
);
1154 /************************************************************************
1155 * OLEFontImpl_IDispatch_Release (IUnknown)
1157 * See Windows documentation for more details on IUnknown methods.
1159 static ULONG WINAPI
OLEFontImpl_IDispatch_Release(
1162 OLEFontImpl
*this = impl_from_IDispatch(iface
);
1164 return IFont_Release((IFont
*)this);
1167 /************************************************************************
1168 * OLEFontImpl_IDispatch_AddRef (IUnknown)
1170 * See Windows documentation for more details on IUnknown methods.
1172 static ULONG WINAPI
OLEFontImpl_IDispatch_AddRef(
1175 OLEFontImpl
*this = impl_from_IDispatch(iface
);
1177 return IFont_AddRef((IFont
*)this);
1180 /************************************************************************
1181 * OLEFontImpl_GetTypeInfoCount (IDispatch)
1183 * See Windows documentation for more details on IDispatch methods.
1185 static HRESULT WINAPI
OLEFontImpl_GetTypeInfoCount(
1187 unsigned int* pctinfo
)
1189 OLEFontImpl
*this = impl_from_IDispatch(iface
);
1190 TRACE("(%p)->(%p)\n", this, pctinfo
);
1196 /************************************************************************
1197 * OLEFontImpl_GetTypeInfo (IDispatch)
1199 * See Windows documentation for more details on IDispatch methods.
1201 static HRESULT WINAPI
OLEFontImpl_GetTypeInfo(
1205 ITypeInfo
** ppTInfo
)
1207 static const WCHAR stdole2tlb
[] = {'s','t','d','o','l','e','2','.','t','l','b',0};
1211 OLEFontImpl
*this = impl_from_IDispatch(iface
);
1212 TRACE("(%p, iTInfo=%d, lcid=%04x, %p)\n", this, iTInfo
, (int)lcid
, ppTInfo
);
1215 hres
= LoadTypeLib(stdole2tlb
, &tl
);
1217 ERR("Could not load the stdole2.tlb?\n");
1220 hres
= ITypeLib_GetTypeInfoOfGuid(tl
, &IID_IFontDisp
, ppTInfo
);
1221 ITypeLib_Release(tl
);
1223 FIXME("Did not IDispatch typeinfo from typelib, hres %x\n",hres
);
1228 /************************************************************************
1229 * OLEFontImpl_GetIDsOfNames (IDispatch)
1231 * See Windows documentation for more details on IDispatch methods.
1233 static HRESULT WINAPI
OLEFontImpl_GetIDsOfNames(
1236 LPOLESTR
* rgszNames
,
1244 OLEFontImpl
*this = impl_from_IDispatch(iface
);
1246 TRACE("(%p,%s,%p,cNames=%d,lcid=%04x,%p)\n", this, debugstr_guid(riid
),
1247 rgszNames
, cNames
, (int)lcid
, rgDispId
);
1251 return E_INVALIDARG
;
1255 /* retrieve type information */
1256 hres
= OLEFontImpl_GetTypeInfo(iface
, 0, lcid
, &pTInfo
);
1260 ERR("GetTypeInfo failed.\n");
1264 /* convert names to DISPIDs */
1265 hres
= DispGetIDsOfNames (pTInfo
, rgszNames
, cNames
, rgDispId
);
1266 ITypeInfo_Release(pTInfo
);
1272 /************************************************************************
1273 * OLEFontImpl_Invoke (IDispatch)
1275 * See Windows documentation for more details on IDispatch methods.
1277 * Note: Do not call _put_Xxx methods, since setting things here
1278 * should not call notify functions as I found out debugging the generic
1281 static HRESULT WINAPI
OLEFontImpl_Invoke(
1283 DISPID dispIdMember
,
1287 DISPPARAMS
* pDispParams
,
1288 VARIANT
* pVarResult
,
1289 EXCEPINFO
* pExepInfo
,
1292 OLEFontImpl
*this = impl_from_IDispatch(iface
);
1295 TRACE("%p->(%d,%s,0x%x,0x%x,%p,%p,%p,%p)\n", this, dispIdMember
,
1296 debugstr_guid(riid
), lcid
, wFlags
, pDispParams
, pVarResult
, pExepInfo
,
1299 /* validate parameters */
1301 if (!IsEqualIID(riid
, &IID_NULL
))
1303 ERR("riid was %s instead of IID_NULL\n", debugstr_guid(riid
));
1304 return DISP_E_UNKNOWNINTERFACE
;
1307 if (wFlags
& DISPATCH_PROPERTYGET
)
1311 ERR("null pVarResult not allowed when DISPATCH_PROPERTYGET specified\n");
1312 return DISP_E_PARAMNOTOPTIONAL
;
1315 else if (wFlags
& DISPATCH_PROPERTYPUT
)
1319 ERR("null pDispParams not allowed when DISPATCH_PROPERTYPUT specified\n");
1320 return DISP_E_PARAMNOTOPTIONAL
;
1322 if (pDispParams
->cArgs
!= 1)
1324 ERR("param count for DISPATCH_PROPERTYPUT was %d instead of 1\n", pDispParams
->cArgs
);
1325 return DISP_E_BADPARAMCOUNT
;
1330 ERR("one of DISPATCH_PROPERTYGET or DISPATCH_PROPERTYPUT must be specified\n");
1331 return DISP_E_MEMBERNOTFOUND
;
1334 switch (dispIdMember
) {
1335 case DISPID_FONT_NAME
:
1336 if (wFlags
& DISPATCH_PROPERTYGET
) {
1337 V_VT(pVarResult
) = VT_BSTR
;
1338 return IFont_get_Name((IFont
*)this, &V_BSTR(pVarResult
));
1342 VariantInit(&vararg
);
1343 hr
= VariantChangeTypeEx(&vararg
, &pDispParams
->rgvarg
[0], lcid
, 0, VT_BSTR
);
1347 hr
= IFont_put_Name((IFont
*)this, V_BSTR(&vararg
));
1349 VariantClear(&vararg
);
1353 case DISPID_FONT_BOLD
:
1354 if (wFlags
& DISPATCH_PROPERTYGET
) {
1356 hr
= IFont_get_Bold((IFont
*)this, &value
);
1357 V_VT(pVarResult
) = VT_BOOL
;
1358 V_BOOL(pVarResult
) = value
? VARIANT_TRUE
: VARIANT_FALSE
;
1363 VariantInit(&vararg
);
1364 hr
= VariantChangeTypeEx(&vararg
, &pDispParams
->rgvarg
[0], lcid
, 0, VT_BOOL
);
1368 hr
= IFont_put_Bold((IFont
*)this, V_BOOL(&vararg
));
1370 VariantClear(&vararg
);
1374 case DISPID_FONT_ITALIC
:
1375 if (wFlags
& DISPATCH_PROPERTYGET
) {
1377 hr
= IFont_get_Italic((IFont
*)this, &value
);
1378 V_VT(pVarResult
) = VT_BOOL
;
1379 V_BOOL(pVarResult
) = value
? VARIANT_TRUE
: VARIANT_FALSE
;
1384 VariantInit(&vararg
);
1385 hr
= VariantChangeTypeEx(&vararg
, &pDispParams
->rgvarg
[0], lcid
, 0, VT_BOOL
);
1389 hr
= IFont_put_Italic((IFont
*)this, V_BOOL(&vararg
));
1391 VariantClear(&vararg
);
1395 case DISPID_FONT_UNDER
:
1396 if (wFlags
& DISPATCH_PROPERTYGET
) {
1398 hr
= IFont_get_Underline((IFont
*)this, &value
);
1399 V_VT(pVarResult
) = VT_BOOL
;
1400 V_BOOL(pVarResult
) = value
? VARIANT_TRUE
: VARIANT_FALSE
;
1405 VariantInit(&vararg
);
1406 hr
= VariantChangeTypeEx(&vararg
, &pDispParams
->rgvarg
[0], lcid
, 0, VT_BOOL
);
1410 hr
= IFont_put_Underline((IFont
*)this, V_BOOL(&vararg
));
1412 VariantClear(&vararg
);
1416 case DISPID_FONT_STRIKE
:
1417 if (wFlags
& DISPATCH_PROPERTYGET
) {
1419 hr
= IFont_get_Strikethrough((IFont
*)this, &value
);
1420 V_VT(pVarResult
) = VT_BOOL
;
1421 V_BOOL(pVarResult
) = value
? VARIANT_TRUE
: VARIANT_FALSE
;
1426 VariantInit(&vararg
);
1427 hr
= VariantChangeTypeEx(&vararg
, &pDispParams
->rgvarg
[0], lcid
, 0, VT_BOOL
);
1431 hr
= IFont_put_Strikethrough((IFont
*)this, V_BOOL(&vararg
));
1433 VariantClear(&vararg
);
1437 case DISPID_FONT_SIZE
:
1438 if (wFlags
& DISPATCH_PROPERTYGET
) {
1439 V_VT(pVarResult
) = VT_CY
;
1440 return OLEFontImpl_get_Size((IFont
*)this, &V_CY(pVarResult
));
1444 VariantInit(&vararg
);
1445 hr
= VariantChangeTypeEx(&vararg
, &pDispParams
->rgvarg
[0], lcid
, 0, VT_CY
);
1449 hr
= IFont_put_Size((IFont
*)this, V_CY(&vararg
));
1451 VariantClear(&vararg
);
1455 case DISPID_FONT_WEIGHT
:
1456 if (wFlags
& DISPATCH_PROPERTYGET
) {
1457 V_VT(pVarResult
) = VT_I2
;
1458 return OLEFontImpl_get_Weight((IFont
*)this, &V_I2(pVarResult
));
1462 VariantInit(&vararg
);
1463 hr
= VariantChangeTypeEx(&vararg
, &pDispParams
->rgvarg
[0], lcid
, 0, VT_I2
);
1467 hr
= IFont_put_Weight((IFont
*)this, V_I2(&vararg
));
1469 VariantClear(&vararg
);
1473 case DISPID_FONT_CHARSET
:
1474 if (wFlags
& DISPATCH_PROPERTYGET
) {
1475 V_VT(pVarResult
) = VT_I2
;
1476 return OLEFontImpl_get_Charset((IFont
*)this, &V_I2(pVarResult
));
1480 VariantInit(&vararg
);
1481 hr
= VariantChangeTypeEx(&vararg
, &pDispParams
->rgvarg
[0], lcid
, 0, VT_I2
);
1485 hr
= IFont_put_Charset((IFont
*)this, V_I2(&vararg
));
1487 VariantClear(&vararg
);
1492 ERR("member not found for dispid 0x%x\n", dispIdMember
);
1493 return DISP_E_MEMBERNOTFOUND
;
1497 static const IDispatchVtbl OLEFontImpl_IDispatch_VTable
=
1499 OLEFontImpl_IDispatch_QueryInterface
,
1500 OLEFontImpl_IDispatch_AddRef
,
1501 OLEFontImpl_IDispatch_Release
,
1502 OLEFontImpl_GetTypeInfoCount
,
1503 OLEFontImpl_GetTypeInfo
,
1504 OLEFontImpl_GetIDsOfNames
,
1508 /************************************************************************
1509 * OLEFontImpl_IPersistStream_QueryInterface (IUnknown)
1511 * See Windows documentation for more details on IUnknown methods.
1513 static HRESULT WINAPI
OLEFontImpl_IPersistStream_QueryInterface(
1514 IPersistStream
* iface
,
1518 OLEFontImpl
*this = impl_from_IPersistStream(iface
);
1520 return IFont_QueryInterface((IFont
*)this, riid
, ppvoid
);
1523 /************************************************************************
1524 * OLEFontImpl_IPersistStream_Release (IUnknown)
1526 * See Windows documentation for more details on IUnknown methods.
1528 static ULONG WINAPI
OLEFontImpl_IPersistStream_Release(
1529 IPersistStream
* iface
)
1531 OLEFontImpl
*this = impl_from_IPersistStream(iface
);
1533 return IFont_Release((IFont
*)this);
1536 /************************************************************************
1537 * OLEFontImpl_IPersistStream_AddRef (IUnknown)
1539 * See Windows documentation for more details on IUnknown methods.
1541 static ULONG WINAPI
OLEFontImpl_IPersistStream_AddRef(
1542 IPersistStream
* iface
)
1544 OLEFontImpl
*this = impl_from_IPersistStream(iface
);
1546 return IFont_AddRef((IFont
*)this);
1549 /************************************************************************
1550 * OLEFontImpl_GetClassID (IPersistStream)
1552 * See Windows documentation for more details on IPersistStream methods.
1554 static HRESULT WINAPI
OLEFontImpl_GetClassID(
1555 IPersistStream
* iface
,
1558 TRACE("(%p,%p)\n",iface
,pClassID
);
1562 *pClassID
= CLSID_StdFont
;
1567 /************************************************************************
1568 * OLEFontImpl_IsDirty (IPersistStream)
1570 * See Windows documentation for more details on IPersistStream methods.
1572 static HRESULT WINAPI
OLEFontImpl_IsDirty(
1573 IPersistStream
* iface
)
1575 TRACE("(%p)\n",iface
);
1579 /************************************************************************
1580 * OLEFontImpl_Load (IPersistStream)
1582 * See Windows documentation for more details on IPersistStream methods.
1584 * This is the format of the standard font serialization as far as I
1587 * Offset Type Value Comment
1588 * 0x0000 Byte Unknown Probably a version number, contains 0x01
1589 * 0x0001 Short Charset Charset value from the FONTDESC structure
1590 * 0x0003 Byte Attributes Flags defined as follows:
1592 * 00000100 - Underline
1593 * 00001000 - Strikethrough
1594 * 0x0004 Short Weight Weight value from FONTDESC structure
1595 * 0x0006 DWORD size "Low" portion of the cySize member of the FONTDESC
1597 * 0x000A Byte name length Length of the font name string (no null character)
1598 * 0x000B String name Name of the font (ASCII, no nul character)
1600 static HRESULT WINAPI
OLEFontImpl_Load(
1601 IPersistStream
* iface
,
1602 IStream
* pLoadStream
)
1604 char readBuffer
[0x100];
1611 OLEFontImpl
*this = impl_from_IPersistStream(iface
);
1614 * Read the version byte
1616 IStream_Read(pLoadStream
, &bVersion
, 1, &cbRead
);
1625 IStream_Read(pLoadStream
, &this->description
.sCharset
, 2, &cbRead
);
1633 IStream_Read(pLoadStream
, &bAttributes
, 1, &cbRead
);
1638 this->description
.fItalic
= (bAttributes
& FONTPERSIST_ITALIC
) != 0;
1639 this->description
.fStrikethrough
= (bAttributes
& FONTPERSIST_STRIKETHROUGH
) != 0;
1640 this->description
.fUnderline
= (bAttributes
& FONTPERSIST_UNDERLINE
) != 0;
1645 IStream_Read(pLoadStream
, &this->description
.sWeight
, 2, &cbRead
);
1653 IStream_Read(pLoadStream
, &this->description
.cySize
.s
.Lo
, 4, &cbRead
);
1658 this->description
.cySize
.s
.Hi
= 0;
1663 IStream_Read(pLoadStream
, &bStringSize
, 1, &cbRead
);
1668 IStream_Read(pLoadStream
, readBuffer
, bStringSize
, &cbRead
);
1670 if (cbRead
!=bStringSize
)
1673 HeapFree(GetProcessHeap(), 0, this->description
.lpstrName
);
1675 len
= MultiByteToWideChar( CP_ACP
, 0, readBuffer
, bStringSize
, NULL
, 0 );
1676 this->description
.lpstrName
= HeapAlloc( GetProcessHeap(), 0, (len
+1) * sizeof(WCHAR
) );
1677 MultiByteToWideChar( CP_ACP
, 0, readBuffer
, bStringSize
, this->description
.lpstrName
, len
);
1678 this->description
.lpstrName
[len
] = 0;
1680 /* Ensure use of this font causes a new one to be created @@@@ */
1681 DeleteObject(this->gdiFont
);
1687 /************************************************************************
1688 * OLEFontImpl_Save (IPersistStream)
1690 * See Windows documentation for more details on IPersistStream methods.
1692 static HRESULT WINAPI
OLEFontImpl_Save(
1693 IPersistStream
* iface
,
1694 IStream
* pOutStream
,
1697 char* writeBuffer
= NULL
;
1699 BYTE bVersion
= 0x01;
1703 OLEFontImpl
*this = impl_from_IPersistStream(iface
);
1706 * Read the version byte
1708 IStream_Write(pOutStream
, &bVersion
, 1, &cbWritten
);
1716 IStream_Write(pOutStream
, &this->description
.sCharset
, 2, &cbWritten
);
1726 if (this->description
.fItalic
)
1727 bAttributes
|= FONTPERSIST_ITALIC
;
1729 if (this->description
.fStrikethrough
)
1730 bAttributes
|= FONTPERSIST_STRIKETHROUGH
;
1732 if (this->description
.fUnderline
)
1733 bAttributes
|= FONTPERSIST_UNDERLINE
;
1735 IStream_Write(pOutStream
, &bAttributes
, 1, &cbWritten
);
1743 IStream_Write(pOutStream
, &this->description
.sWeight
, 2, &cbWritten
);
1751 IStream_Write(pOutStream
, &this->description
.cySize
.s
.Lo
, 4, &cbWritten
);
1759 if (this->description
.lpstrName
!=0)
1760 bStringSize
= WideCharToMultiByte( CP_ACP
, 0, this->description
.lpstrName
,
1761 strlenW(this->description
.lpstrName
), NULL
, 0, NULL
, NULL
);
1765 IStream_Write(pOutStream
, &bStringSize
, 1, &cbWritten
);
1772 if (!(writeBuffer
= HeapAlloc( GetProcessHeap(), 0, bStringSize
))) return E_OUTOFMEMORY
;
1773 WideCharToMultiByte( CP_ACP
, 0, this->description
.lpstrName
,
1774 strlenW(this->description
.lpstrName
),
1775 writeBuffer
, bStringSize
, NULL
, NULL
);
1777 IStream_Write(pOutStream
, writeBuffer
, bStringSize
, &cbWritten
);
1778 HeapFree(GetProcessHeap(), 0, writeBuffer
);
1780 if (cbWritten
!=bStringSize
)
1787 /************************************************************************
1788 * OLEFontImpl_GetSizeMax (IPersistStream)
1790 * See Windows documentation for more details on IPersistStream methods.
1792 static HRESULT WINAPI
OLEFontImpl_GetSizeMax(
1793 IPersistStream
* iface
,
1794 ULARGE_INTEGER
* pcbSize
)
1796 OLEFontImpl
*this = impl_from_IPersistStream(iface
);
1801 pcbSize
->u
.HighPart
= 0;
1802 pcbSize
->u
.LowPart
= 0;
1804 pcbSize
->u
.LowPart
+= sizeof(BYTE
); /* Version */
1805 pcbSize
->u
.LowPart
+= sizeof(WORD
); /* Lang code */
1806 pcbSize
->u
.LowPart
+= sizeof(BYTE
); /* Flags */
1807 pcbSize
->u
.LowPart
+= sizeof(WORD
); /* Weight */
1808 pcbSize
->u
.LowPart
+= sizeof(DWORD
); /* Size */
1809 pcbSize
->u
.LowPart
+= sizeof(BYTE
); /* StrLength */
1811 if (this->description
.lpstrName
!=0)
1812 pcbSize
->u
.LowPart
+= WideCharToMultiByte( CP_ACP
, 0, this->description
.lpstrName
,
1813 strlenW(this->description
.lpstrName
),
1814 NULL
, 0, NULL
, NULL
);
1819 static const IPersistStreamVtbl OLEFontImpl_IPersistStream_VTable
=
1821 OLEFontImpl_IPersistStream_QueryInterface
,
1822 OLEFontImpl_IPersistStream_AddRef
,
1823 OLEFontImpl_IPersistStream_Release
,
1824 OLEFontImpl_GetClassID
,
1825 OLEFontImpl_IsDirty
,
1828 OLEFontImpl_GetSizeMax
1831 /************************************************************************
1832 * OLEFontImpl_IConnectionPointContainer_QueryInterface (IUnknown)
1834 * See Windows documentation for more details on IUnknown methods.
1836 static HRESULT WINAPI
OLEFontImpl_IConnectionPointContainer_QueryInterface(
1837 IConnectionPointContainer
* iface
,
1841 OLEFontImpl
*this = impl_from_IConnectionPointContainer(iface
);
1843 return IFont_QueryInterface((IFont
*)this, riid
, ppvoid
);
1846 /************************************************************************
1847 * OLEFontImpl_IConnectionPointContainer_Release (IUnknown)
1849 * See Windows documentation for more details on IUnknown methods.
1851 static ULONG WINAPI
OLEFontImpl_IConnectionPointContainer_Release(
1852 IConnectionPointContainer
* iface
)
1854 OLEFontImpl
*this = impl_from_IConnectionPointContainer(iface
);
1856 return IFont_Release((IFont
*)this);
1859 /************************************************************************
1860 * OLEFontImpl_IConnectionPointContainer_AddRef (IUnknown)
1862 * See Windows documentation for more details on IUnknown methods.
1864 static ULONG WINAPI
OLEFontImpl_IConnectionPointContainer_AddRef(
1865 IConnectionPointContainer
* iface
)
1867 OLEFontImpl
*this = impl_from_IConnectionPointContainer(iface
);
1869 return IFont_AddRef((IFont
*)this);
1872 /************************************************************************
1873 * OLEFontImpl_EnumConnectionPoints (IConnectionPointContainer)
1875 * See Windows documentation for more details on IConnectionPointContainer
1878 static HRESULT WINAPI
OLEFontImpl_EnumConnectionPoints(
1879 IConnectionPointContainer
* iface
,
1880 IEnumConnectionPoints
**ppEnum
)
1882 OLEFontImpl
*this = impl_from_IConnectionPointContainer(iface
);
1884 FIXME("(%p)->(%p): stub\n", this, ppEnum
);
1888 /************************************************************************
1889 * OLEFontImpl_FindConnectionPoint (IConnectionPointContainer)
1891 * See Windows documentation for more details on IConnectionPointContainer
1894 static HRESULT WINAPI
OLEFontImpl_FindConnectionPoint(
1895 IConnectionPointContainer
* iface
,
1897 IConnectionPoint
**ppCp
)
1899 OLEFontImpl
*this = impl_from_IConnectionPointContainer(iface
);
1900 TRACE("(%p)->(%s, %p)\n", this, debugstr_guid(riid
), ppCp
);
1902 if(IsEqualIID(riid
, &IID_IPropertyNotifySink
)) {
1903 return IConnectionPoint_QueryInterface(this->pPropertyNotifyCP
,
1904 &IID_IConnectionPoint
,
1906 } else if(IsEqualIID(riid
, &IID_IFontEventsDisp
)) {
1907 return IConnectionPoint_QueryInterface(this->pFontEventsCP
,
1908 &IID_IConnectionPoint
,
1911 FIXME("no connection point for %s\n", debugstr_guid(riid
));
1912 return CONNECT_E_NOCONNECTION
;
1916 static const IConnectionPointContainerVtbl
1917 OLEFontImpl_IConnectionPointContainer_VTable
=
1919 OLEFontImpl_IConnectionPointContainer_QueryInterface
,
1920 OLEFontImpl_IConnectionPointContainer_AddRef
,
1921 OLEFontImpl_IConnectionPointContainer_Release
,
1922 OLEFontImpl_EnumConnectionPoints
,
1923 OLEFontImpl_FindConnectionPoint
1926 /************************************************************************
1927 * OLEFontImpl implementation of IPersistPropertyBag.
1929 static HRESULT WINAPI
OLEFontImpl_IPersistPropertyBag_QueryInterface(
1930 IPersistPropertyBag
*iface
, REFIID riid
, LPVOID
*ppvObj
1932 OLEFontImpl
*this = impl_from_IPersistPropertyBag(iface
);
1933 return IFont_QueryInterface((IFont
*)this,riid
,ppvObj
);
1936 static ULONG WINAPI
OLEFontImpl_IPersistPropertyBag_AddRef(
1937 IPersistPropertyBag
*iface
1939 OLEFontImpl
*this = impl_from_IPersistPropertyBag(iface
);
1940 return IFont_AddRef((IFont
*)this);
1943 static ULONG WINAPI
OLEFontImpl_IPersistPropertyBag_Release(
1944 IPersistPropertyBag
*iface
1946 OLEFontImpl
*this = impl_from_IPersistPropertyBag(iface
);
1947 return IFont_Release((IFont
*)this);
1950 static HRESULT WINAPI
OLEFontImpl_IPersistPropertyBag_GetClassID(
1951 IPersistPropertyBag
*iface
, CLSID
*classid
1953 FIXME("(%p,%p), stub!\n", iface
, classid
);
1957 static HRESULT WINAPI
OLEFontImpl_IPersistPropertyBag_InitNew(
1958 IPersistPropertyBag
*iface
1960 FIXME("(%p), stub!\n", iface
);
1964 static HRESULT WINAPI
OLEFontImpl_IPersistPropertyBag_Load(
1965 IPersistPropertyBag
*iface
, IPropertyBag
* pPropBag
, IErrorLog
* pErrorLog
1967 /* (from Visual Basic 6 property bag)
1968 Name = "MS Sans Serif"
1972 Underline = 0 'False
1974 Strikethrough = 0 'False
1976 static const WCHAR sAttrName
[] = {'N','a','m','e',0};
1977 static const WCHAR sAttrSize
[] = {'S','i','z','e',0};
1978 static const WCHAR sAttrCharset
[] = {'C','h','a','r','s','e','t',0};
1979 static const WCHAR sAttrWeight
[] = {'W','e','i','g','h','t',0};
1980 static const WCHAR sAttrUnderline
[] = {'U','n','d','e','r','l','i','n','e',0};
1981 static const WCHAR sAttrItalic
[] = {'I','t','a','l','i','c',0};
1982 static const WCHAR sAttrStrikethrough
[] = {'S','t','r','i','k','e','t','h','r','o','u','g','h',0};
1985 HRESULT iRes
= S_OK
;
1986 OLEFontImpl
*this = impl_from_IPersistPropertyBag(iface
);
1988 VariantInit(&rawAttr
);
1989 VariantInit(&valueAttr
);
1992 iRes
= IPropertyBag_Read(pPropBag
, sAttrName
, &rawAttr
, pErrorLog
);
1995 iRes
= VariantChangeType(&rawAttr
, &valueAttr
, 0, VT_BSTR
);
1997 iRes
= IFont_put_Name((IFont
*)this, V_BSTR(&valueAttr
));
1999 else if (iRes
== E_INVALIDARG
)
2001 VariantClear(&rawAttr
);
2002 VariantClear(&valueAttr
);
2006 iRes
= IPropertyBag_Read(pPropBag
, sAttrSize
, &rawAttr
, pErrorLog
);
2009 iRes
= VariantChangeType(&rawAttr
, &valueAttr
, 0, VT_CY
);
2011 iRes
= IFont_put_Size((IFont
*)this, V_CY(&valueAttr
));
2013 else if (iRes
== E_INVALIDARG
)
2015 VariantClear(&rawAttr
);
2016 VariantClear(&valueAttr
);
2020 iRes
= IPropertyBag_Read(pPropBag
, sAttrCharset
, &rawAttr
, pErrorLog
);
2023 iRes
= VariantChangeType(&rawAttr
, &valueAttr
, 0, VT_I2
);
2025 iRes
= IFont_put_Charset((IFont
*)this, V_I2(&valueAttr
));
2027 else if (iRes
== E_INVALIDARG
)
2029 VariantClear(&rawAttr
);
2030 VariantClear(&valueAttr
);
2034 iRes
= IPropertyBag_Read(pPropBag
, sAttrWeight
, &rawAttr
, pErrorLog
);
2037 iRes
= VariantChangeType(&rawAttr
, &valueAttr
, 0, VT_I2
);
2039 iRes
= IFont_put_Weight((IFont
*)this, V_I2(&valueAttr
));
2041 else if (iRes
== E_INVALIDARG
)
2043 VariantClear(&rawAttr
);
2044 VariantClear(&valueAttr
);
2049 iRes
= IPropertyBag_Read(pPropBag
, sAttrUnderline
, &rawAttr
, pErrorLog
);
2052 iRes
= VariantChangeType(&rawAttr
, &valueAttr
, 0, VT_BOOL
);
2054 iRes
= IFont_put_Underline((IFont
*)this, V_BOOL(&valueAttr
));
2056 else if (iRes
== E_INVALIDARG
)
2058 VariantClear(&rawAttr
);
2059 VariantClear(&valueAttr
);
2063 iRes
= IPropertyBag_Read(pPropBag
, sAttrItalic
, &rawAttr
, pErrorLog
);
2066 iRes
= VariantChangeType(&rawAttr
, &valueAttr
, 0, VT_BOOL
);
2068 iRes
= IFont_put_Italic((IFont
*)this, V_BOOL(&valueAttr
));
2070 else if (iRes
== E_INVALIDARG
)
2072 VariantClear(&rawAttr
);
2073 VariantClear(&valueAttr
);
2077 iRes
= IPropertyBag_Read(pPropBag
, sAttrStrikethrough
, &rawAttr
, pErrorLog
);
2080 iRes
= VariantChangeType(&rawAttr
, &valueAttr
, 0, VT_BOOL
);
2082 IFont_put_Strikethrough((IFont
*)this, V_BOOL(&valueAttr
));
2084 else if (iRes
== E_INVALIDARG
)
2086 VariantClear(&rawAttr
);
2087 VariantClear(&valueAttr
);
2091 WARN("-- 0x%08x\n", iRes
);
2095 static HRESULT WINAPI
OLEFontImpl_IPersistPropertyBag_Save(
2096 IPersistPropertyBag
*iface
, IPropertyBag
* pPropBag
, BOOL fClearDirty
,
2097 BOOL fSaveAllProperties
2099 FIXME("(%p,%p,%d,%d), stub!\n", iface
, pPropBag
, fClearDirty
, fSaveAllProperties
);
2103 static const IPersistPropertyBagVtbl OLEFontImpl_IPersistPropertyBag_VTable
=
2105 OLEFontImpl_IPersistPropertyBag_QueryInterface
,
2106 OLEFontImpl_IPersistPropertyBag_AddRef
,
2107 OLEFontImpl_IPersistPropertyBag_Release
,
2109 OLEFontImpl_IPersistPropertyBag_GetClassID
,
2110 OLEFontImpl_IPersistPropertyBag_InitNew
,
2111 OLEFontImpl_IPersistPropertyBag_Load
,
2112 OLEFontImpl_IPersistPropertyBag_Save
2115 /************************************************************************
2116 * OLEFontImpl implementation of IPersistStreamInit.
2118 static HRESULT WINAPI
OLEFontImpl_IPersistStreamInit_QueryInterface(
2119 IPersistStreamInit
*iface
, REFIID riid
, LPVOID
*ppvObj
2121 OLEFontImpl
*this = impl_from_IPersistStreamInit(iface
);
2122 return IFont_QueryInterface((IFont
*)this,riid
,ppvObj
);
2125 static ULONG WINAPI
OLEFontImpl_IPersistStreamInit_AddRef(
2126 IPersistStreamInit
*iface
2128 OLEFontImpl
*this = impl_from_IPersistStreamInit(iface
);
2129 return IFont_AddRef((IFont
*)this);
2132 static ULONG WINAPI
OLEFontImpl_IPersistStreamInit_Release(
2133 IPersistStreamInit
*iface
2135 OLEFontImpl
*this = impl_from_IPersistStreamInit(iface
);
2136 return IFont_Release((IFont
*)this);
2139 static HRESULT WINAPI
OLEFontImpl_IPersistStreamInit_GetClassID(
2140 IPersistStreamInit
*iface
, CLSID
*classid
2142 FIXME("(%p,%p), stub!\n", iface
, classid
);
2146 static HRESULT WINAPI
OLEFontImpl_IPersistStreamInit_IsDirty(
2147 IPersistStreamInit
*iface
2149 FIXME("(%p), stub!\n", iface
);
2153 static HRESULT WINAPI
OLEFontImpl_IPersistStreamInit_Load(
2154 IPersistStreamInit
*iface
, LPSTREAM pStm
2156 FIXME("(%p,%p), stub!\n", iface
, pStm
);
2160 static HRESULT WINAPI
OLEFontImpl_IPersistStreamInit_Save(
2161 IPersistStreamInit
*iface
, LPSTREAM pStm
, BOOL fClearDirty
2163 FIXME("(%p,%p,%d), stub!\n", iface
, pStm
, fClearDirty
);
2167 static HRESULT WINAPI
OLEFontImpl_IPersistStreamInit_GetSizeMax(
2168 IPersistStreamInit
*iface
, ULARGE_INTEGER
*pcbSize
2170 FIXME("(%p,%p), stub!\n", iface
, pcbSize
);
2174 static HRESULT WINAPI
OLEFontImpl_IPersistStreamInit_InitNew(
2175 IPersistStreamInit
*iface
2177 FIXME("(%p), stub!\n", iface
);
2181 static const IPersistStreamInitVtbl OLEFontImpl_IPersistStreamInit_VTable
=
2183 OLEFontImpl_IPersistStreamInit_QueryInterface
,
2184 OLEFontImpl_IPersistStreamInit_AddRef
,
2185 OLEFontImpl_IPersistStreamInit_Release
,
2187 OLEFontImpl_IPersistStreamInit_GetClassID
,
2188 OLEFontImpl_IPersistStreamInit_IsDirty
,
2189 OLEFontImpl_IPersistStreamInit_Load
,
2190 OLEFontImpl_IPersistStreamInit_Save
,
2191 OLEFontImpl_IPersistStreamInit_GetSizeMax
,
2192 OLEFontImpl_IPersistStreamInit_InitNew
2195 /************************************************************************
2196 * OLEFontImpl_Construct
2198 * This method will construct a new instance of the OLEFontImpl
2201 * The caller of this method must release the object when it's
2204 static OLEFontImpl
* OLEFontImpl_Construct(const FONTDESC
*fontDesc
)
2206 OLEFontImpl
* newObject
= 0;
2209 * Allocate space for the object.
2211 newObject
= HeapAlloc(GetProcessHeap(), 0, sizeof(OLEFontImpl
));
2217 * Initialize the virtual function table.
2219 newObject
->lpVtbl
= &OLEFontImpl_VTable
;
2220 newObject
->lpvtblIDispatch
= &OLEFontImpl_IDispatch_VTable
;
2221 newObject
->lpvtblIPersistStream
= &OLEFontImpl_IPersistStream_VTable
;
2222 newObject
->lpvtblIConnectionPointContainer
= &OLEFontImpl_IConnectionPointContainer_VTable
;
2223 newObject
->lpvtblIPersistPropertyBag
= &OLEFontImpl_IPersistPropertyBag_VTable
;
2224 newObject
->lpvtblIPersistStreamInit
= &OLEFontImpl_IPersistStreamInit_VTable
;
2227 * Start with one reference count. The caller of this function
2228 * must release the interface pointer when it is done.
2233 * Copy the description of the font in the object.
2235 assert(fontDesc
->cbSizeofstruct
>= sizeof(FONTDESC
));
2237 newObject
->description
.cbSizeofstruct
= sizeof(FONTDESC
);
2238 newObject
->description
.lpstrName
= HeapAlloc(GetProcessHeap(),
2240 (lstrlenW(fontDesc
->lpstrName
)+1) * sizeof(WCHAR
));
2241 strcpyW(newObject
->description
.lpstrName
, fontDesc
->lpstrName
);
2242 newObject
->description
.cySize
= fontDesc
->cySize
;
2243 newObject
->description
.sWeight
= fontDesc
->sWeight
;
2244 newObject
->description
.sCharset
= fontDesc
->sCharset
;
2245 newObject
->description
.fItalic
= fontDesc
->fItalic
;
2246 newObject
->description
.fUnderline
= fontDesc
->fUnderline
;
2247 newObject
->description
.fStrikethrough
= fontDesc
->fStrikethrough
;
2250 * Initializing all the other members.
2252 newObject
->gdiFont
= 0;
2253 newObject
->cyLogical
= 72L;
2254 newObject
->cyHimetric
= 2540L;
2255 newObject
->pPropertyNotifyCP
= NULL
;
2256 newObject
->pFontEventsCP
= NULL
;
2258 CreateConnectionPoint((IUnknown
*)newObject
, &IID_IPropertyNotifySink
, &newObject
->pPropertyNotifyCP
);
2259 CreateConnectionPoint((IUnknown
*)newObject
, &IID_IFontEventsDisp
, &newObject
->pFontEventsCP
);
2261 if (!newObject
->pPropertyNotifyCP
|| !newObject
->pFontEventsCP
)
2263 OLEFontImpl_Destroy(newObject
);
2267 InterlockedIncrement(&ifont_cnt
);
2269 TRACE("returning %p\n", newObject
);
2273 /************************************************************************
2274 * OLEFontImpl_Destroy
2276 * This method is called by the Release method when the reference
2277 * count goes down to 0. It will free all resources used by
2280 static void OLEFontImpl_Destroy(OLEFontImpl
* fontDesc
)
2282 TRACE("(%p)\n", fontDesc
);
2284 HeapFree(GetProcessHeap(), 0, fontDesc
->description
.lpstrName
);
2286 if (fontDesc
->gdiFont
!=0)
2287 DeleteObject(fontDesc
->gdiFont
);
2289 if (fontDesc
->pPropertyNotifyCP
)
2290 IConnectionPoint_Release(fontDesc
->pPropertyNotifyCP
);
2291 if (fontDesc
->pFontEventsCP
)
2292 IConnectionPoint_Release(fontDesc
->pFontEventsCP
);
2294 HeapFree(GetProcessHeap(), 0, fontDesc
);
2297 /*******************************************************************************
2298 * StdFont ClassFactory
2302 /* IUnknown fields */
2303 const IClassFactoryVtbl
*lpVtbl
;
2305 } IClassFactoryImpl
;
2307 static HRESULT WINAPI
2308 SFCF_QueryInterface(LPCLASSFACTORY iface
,REFIID riid
,LPVOID
*ppobj
) {
2309 IClassFactoryImpl
*This
= (IClassFactoryImpl
*)iface
;
2311 FIXME("(%p)->(%s,%p),stub!\n",This
,debugstr_guid(riid
),ppobj
);
2312 return E_NOINTERFACE
;
2316 SFCF_AddRef(LPCLASSFACTORY iface
) {
2317 IClassFactoryImpl
*This
= (IClassFactoryImpl
*)iface
;
2318 return InterlockedIncrement(&This
->ref
);
2321 static ULONG WINAPI
SFCF_Release(LPCLASSFACTORY iface
) {
2322 IClassFactoryImpl
*This
= (IClassFactoryImpl
*)iface
;
2323 /* static class, won't be freed */
2324 return InterlockedDecrement(&This
->ref
);
2327 static HRESULT WINAPI
SFCF_CreateInstance(
2328 LPCLASSFACTORY iface
,LPUNKNOWN pOuter
,REFIID riid
,LPVOID
*ppobj
2330 return OleCreateFontIndirect(NULL
,riid
,ppobj
);
2334 static HRESULT WINAPI
SFCF_LockServer(LPCLASSFACTORY iface
,BOOL dolock
) {
2335 IClassFactoryImpl
*This
= (IClassFactoryImpl
*)iface
;
2336 FIXME("(%p)->(%d),stub!\n",This
,dolock
);
2340 static const IClassFactoryVtbl SFCF_Vtbl
= {
2341 SFCF_QueryInterface
,
2344 SFCF_CreateInstance
,
2347 static IClassFactoryImpl STDFONT_CF
= {&SFCF_Vtbl
, 1 };
2349 void _get_STDFONT_CF(LPVOID
*ppv
) { *ppv
= &STDFONT_CF
; }