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
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 #define NONAMELESSUNION
29 #define NONAMELESSSTRUCT
36 #include "wine/unicode.h"
38 #include "oleauto.h" /* for SysAllocString(....) */
41 #include "wine/debug.h"
42 #include "connpt.h" /* for CreateConnectionPoint */
44 WINE_DEFAULT_DEBUG_CHANNEL(ole
);
46 /***********************************************************************
47 * Declaration of constants used when serializing the font object.
49 #define FONTPERSIST_ITALIC 0x02
50 #define FONTPERSIST_UNDERLINE 0x04
51 #define FONTPERSIST_STRIKETHROUGH 0x08
53 /***********************************************************************
54 * Declaration of the implementation class for the IFont interface
56 typedef struct OLEFontImpl OLEFontImpl
;
61 * This class supports many interfaces. IUnknown, IFont,
62 * IDispatch, IDispFont IPersistStream and IConnectionPointContainer.
63 * The first two are supported by the first vtable, the next two are
64 * supported by the second table and the last two have their own.
67 IDispatchVtbl
* lpvtbl2
;
68 IPersistStreamVtbl
* lpvtbl3
;
69 IConnectionPointContainerVtbl
* lpvtbl4
;
70 IPersistPropertyBagVtbl
* lpvtbl5
;
71 IPersistStreamInitVtbl
* lpvtbl6
;
73 * Reference count for that instance of the class.
78 * This structure contains the description of the class.
83 * Contain the font associated with this object.
98 IConnectionPoint
*pCP
;
102 * Here, I define utility macros to help with the casting of the
104 * There is a version to accommodate all of the VTables implemented
107 #define _ICOM_THIS_From_IDispatch(class, name) class* this = (class*)(((char*)name)-sizeof(void*))
108 #define _ICOM_THIS_From_IPersistStream(class, name) class* this = (class*)(((char*)name)-2*sizeof(void*))
109 #define _ICOM_THIS_From_IConnectionPointContainer(class, name) class* this = (class*)(((char*)name)-3*sizeof(void*))
110 #define _ICOM_THIS_From_IPersistPropertyBag(class, name) class* this = (class*)(((char*)name)-4*sizeof(void*))
111 #define _ICOM_THIS_From_IPersistStreamInit(class, name) class* this = (class*)(((char*)name)-5*sizeof(void*))
114 /***********************************************************************
115 * Prototypes for the implementation functions for the IFont
118 static OLEFontImpl
* OLEFontImpl_Construct(LPFONTDESC fontDesc
);
119 static void OLEFontImpl_Destroy(OLEFontImpl
* fontDesc
);
120 static HRESULT WINAPI
OLEFontImpl_QueryInterface(IFont
* iface
, REFIID riid
, VOID
** ppvoid
);
121 static ULONG WINAPI
OLEFontImpl_AddRef(IFont
* iface
);
122 static ULONG WINAPI
OLEFontImpl_Release(IFont
* iface
);
123 static HRESULT WINAPI
OLEFontImpl_get_Name(IFont
* iface
, BSTR
* pname
);
124 static HRESULT WINAPI
OLEFontImpl_put_Name(IFont
* iface
, BSTR name
);
125 static HRESULT WINAPI
OLEFontImpl_get_Size(IFont
* iface
, CY
* psize
);
126 static HRESULT WINAPI
OLEFontImpl_put_Size(IFont
* iface
, CY size
);
127 static HRESULT WINAPI
OLEFontImpl_get_Bold(IFont
* iface
, BOOL
* pbold
);
128 static HRESULT WINAPI
OLEFontImpl_put_Bold(IFont
* iface
, BOOL bold
);
129 static HRESULT WINAPI
OLEFontImpl_get_Italic(IFont
* iface
, BOOL
* pitalic
);
130 static HRESULT WINAPI
OLEFontImpl_put_Italic(IFont
* iface
, BOOL italic
);
131 static HRESULT WINAPI
OLEFontImpl_get_Underline(IFont
* iface
, BOOL
* punderline
);
132 static HRESULT WINAPI
OLEFontImpl_put_Underline(IFont
* iface
, BOOL underline
);
133 static HRESULT WINAPI
OLEFontImpl_get_Strikethrough(IFont
* iface
, BOOL
* pstrikethrough
);
134 static HRESULT WINAPI
OLEFontImpl_put_Strikethrough(IFont
* iface
, BOOL strikethrough
);
135 static HRESULT WINAPI
OLEFontImpl_get_Weight(IFont
* iface
, short* pweight
);
136 static HRESULT WINAPI
OLEFontImpl_put_Weight(IFont
* iface
, short weight
);
137 static HRESULT WINAPI
OLEFontImpl_get_Charset(IFont
* iface
, short* pcharset
);
138 static HRESULT WINAPI
OLEFontImpl_put_Charset(IFont
* iface
, short charset
);
139 static HRESULT WINAPI
OLEFontImpl_get_hFont(IFont
* iface
, HFONT
* phfont
);
140 static HRESULT WINAPI
OLEFontImpl_Clone(IFont
* iface
, IFont
** ppfont
);
141 static HRESULT WINAPI
OLEFontImpl_IsEqual(IFont
* iface
, IFont
* pFontOther
);
142 static HRESULT WINAPI
OLEFontImpl_SetRatio(IFont
* iface
, LONG cyLogical
, LONG cyHimetric
);
143 static HRESULT WINAPI
OLEFontImpl_QueryTextMetrics(IFont
* iface
, TEXTMETRICOLE
* ptm
);
144 static HRESULT WINAPI
OLEFontImpl_AddRefHfont(IFont
* iface
, HFONT hfont
);
145 static HRESULT WINAPI
OLEFontImpl_ReleaseHfont(IFont
* iface
, HFONT hfont
);
146 static HRESULT WINAPI
OLEFontImpl_SetHdc(IFont
* iface
, HDC hdc
);
148 /***********************************************************************
149 * Prototypes for the implementation functions for the IDispatch
152 static HRESULT WINAPI
OLEFontImpl_IDispatch_QueryInterface(IDispatch
* iface
,
155 static ULONG WINAPI
OLEFontImpl_IDispatch_AddRef(IDispatch
* iface
);
156 static ULONG WINAPI
OLEFontImpl_IDispatch_Release(IDispatch
* iface
);
157 static HRESULT WINAPI
OLEFontImpl_GetTypeInfoCount(IDispatch
* iface
,
158 unsigned int* pctinfo
);
159 static HRESULT WINAPI
OLEFontImpl_GetTypeInfo(IDispatch
* iface
,
162 ITypeInfo
** ppTInfo
);
163 static HRESULT WINAPI
OLEFontImpl_GetIDsOfNames(IDispatch
* iface
,
169 static HRESULT WINAPI
OLEFontImpl_Invoke(IDispatch
* iface
,
174 DISPPARAMS
* pDispParams
,
176 EXCEPINFO
* pExepInfo
,
179 /***********************************************************************
180 * Prototypes for the implementation functions for the IPersistStream
183 static HRESULT WINAPI
OLEFontImpl_IPersistStream_QueryInterface(IPersistStream
* iface
,
186 static ULONG WINAPI
OLEFontImpl_IPersistStream_AddRef(IPersistStream
* iface
);
187 static ULONG WINAPI
OLEFontImpl_IPersistStream_Release(IPersistStream
* iface
);
188 static HRESULT WINAPI
OLEFontImpl_GetClassID(IPersistStream
* iface
,
190 static HRESULT WINAPI
OLEFontImpl_IsDirty(IPersistStream
* iface
);
191 static HRESULT WINAPI
OLEFontImpl_Load(IPersistStream
* iface
,
192 IStream
* pLoadStream
);
193 static HRESULT WINAPI
OLEFontImpl_Save(IPersistStream
* iface
,
196 static HRESULT WINAPI
OLEFontImpl_GetSizeMax(IPersistStream
* iface
,
197 ULARGE_INTEGER
* pcbSize
);
199 /***********************************************************************
200 * Prototypes for the implementation functions for the
201 * IConnectionPointContainer interface
203 static HRESULT WINAPI
OLEFontImpl_IConnectionPointContainer_QueryInterface(
204 IConnectionPointContainer
* iface
,
207 static ULONG WINAPI
OLEFontImpl_IConnectionPointContainer_AddRef(
208 IConnectionPointContainer
* iface
);
209 static ULONG WINAPI
OLEFontImpl_IConnectionPointContainer_Release(
210 IConnectionPointContainer
* iface
);
211 static HRESULT WINAPI
OLEFontImpl_EnumConnectionPoints(
212 IConnectionPointContainer
* iface
,
213 IEnumConnectionPoints
**ppEnum
);
214 static HRESULT WINAPI
OLEFontImpl_FindConnectionPoint(
215 IConnectionPointContainer
* iface
,
217 IConnectionPoint
**ppCp
);
220 * Virtual function tables for the OLEFontImpl class.
222 static IFontVtbl OLEFontImpl_VTable
=
224 OLEFontImpl_QueryInterface
,
227 OLEFontImpl_get_Name
,
228 OLEFontImpl_put_Name
,
229 OLEFontImpl_get_Size
,
230 OLEFontImpl_put_Size
,
231 OLEFontImpl_get_Bold
,
232 OLEFontImpl_put_Bold
,
233 OLEFontImpl_get_Italic
,
234 OLEFontImpl_put_Italic
,
235 OLEFontImpl_get_Underline
,
236 OLEFontImpl_put_Underline
,
237 OLEFontImpl_get_Strikethrough
,
238 OLEFontImpl_put_Strikethrough
,
239 OLEFontImpl_get_Weight
,
240 OLEFontImpl_put_Weight
,
241 OLEFontImpl_get_Charset
,
242 OLEFontImpl_put_Charset
,
243 OLEFontImpl_get_hFont
,
246 OLEFontImpl_SetRatio
,
247 OLEFontImpl_QueryTextMetrics
,
248 OLEFontImpl_AddRefHfont
,
249 OLEFontImpl_ReleaseHfont
,
253 static IDispatchVtbl OLEFontImpl_IDispatch_VTable
=
255 OLEFontImpl_IDispatch_QueryInterface
,
256 OLEFontImpl_IDispatch_AddRef
,
257 OLEFontImpl_IDispatch_Release
,
258 OLEFontImpl_GetTypeInfoCount
,
259 OLEFontImpl_GetTypeInfo
,
260 OLEFontImpl_GetIDsOfNames
,
264 static IPersistStreamVtbl OLEFontImpl_IPersistStream_VTable
=
266 OLEFontImpl_IPersistStream_QueryInterface
,
267 OLEFontImpl_IPersistStream_AddRef
,
268 OLEFontImpl_IPersistStream_Release
,
269 OLEFontImpl_GetClassID
,
273 OLEFontImpl_GetSizeMax
276 static IConnectionPointContainerVtbl
277 OLEFontImpl_IConnectionPointContainer_VTable
=
279 OLEFontImpl_IConnectionPointContainer_QueryInterface
,
280 OLEFontImpl_IConnectionPointContainer_AddRef
,
281 OLEFontImpl_IConnectionPointContainer_Release
,
282 OLEFontImpl_EnumConnectionPoints
,
283 OLEFontImpl_FindConnectionPoint
286 static IPersistPropertyBagVtbl OLEFontImpl_IPersistPropertyBag_VTable
;
287 static IPersistStreamInitVtbl OLEFontImpl_IPersistStreamInit_VTable
;
288 /******************************************************************************
289 * OleCreateFontIndirect [OLEAUT32.420]
291 HRESULT WINAPI
OleCreateFontIndirect(
292 LPFONTDESC lpFontDesc
,
296 OLEFontImpl
* newFont
= 0;
299 TRACE("(%p, %s, %p)\n", lpFontDesc
, debugstr_guid(riid
), ppvObj
);
311 static const WCHAR fname
[] = { 'S','y','s','t','e','m',0 };
313 fd
.cbSizeofstruct
= sizeof(fd
);
314 fd
.lpstrName
= (WCHAR
*)fname
;
315 fd
.cySize
.s
.Lo
= 80000;
321 fd
.fStrikethrough
= 0;
326 * Try to construct a new instance of the class.
328 newFont
= OLEFontImpl_Construct(lpFontDesc
);
331 return E_OUTOFMEMORY
;
334 * Make sure it supports the interface required by the caller.
336 hr
= IFont_QueryInterface((IFont
*)newFont
, riid
, ppvObj
);
339 * Release the reference obtained in the constructor. If
340 * the QueryInterface was unsuccessful, it will free the class.
342 IFont_Release((IFont
*)newFont
);
348 /***********************************************************************
349 * Implementation of the OLEFontImpl class.
352 /***********************************************************************
353 * OLEFont_SendNotify (internal)
355 * Sends notification messages of changed properties to any interested
358 static void OLEFont_SendNotify(OLEFontImpl
* this, DISPID dispID
)
360 IEnumConnections
*pEnum
;
364 hres
= IConnectionPoint_EnumConnections(this->pCP
, &pEnum
);
365 if (FAILED(hres
)) /* When we have 0 connections. */
368 while(IEnumConnections_Next(pEnum
, 1, &CD
, NULL
) == S_OK
) {
369 IPropertyNotifySink
*sink
;
371 IUnknown_QueryInterface(CD
.pUnk
, &IID_IPropertyNotifySink
, (LPVOID
)&sink
);
372 IPropertyNotifySink_OnChanged(sink
, dispID
);
373 IPropertyNotifySink_Release(sink
);
374 IUnknown_Release(CD
.pUnk
);
376 IEnumConnections_Release(pEnum
);
380 /************************************************************************
381 * OLEFontImpl_Construct
383 * This method will construct a new instance of the OLEFontImpl
386 * The caller of this method must release the object when it's
389 static OLEFontImpl
* OLEFontImpl_Construct(LPFONTDESC fontDesc
)
391 OLEFontImpl
* newObject
= 0;
394 * Allocate space for the object.
396 newObject
= HeapAlloc(GetProcessHeap(), 0, sizeof(OLEFontImpl
));
402 * Initialize the virtual function table.
404 newObject
->lpvtbl1
= &OLEFontImpl_VTable
;
405 newObject
->lpvtbl2
= &OLEFontImpl_IDispatch_VTable
;
406 newObject
->lpvtbl3
= &OLEFontImpl_IPersistStream_VTable
;
407 newObject
->lpvtbl4
= &OLEFontImpl_IConnectionPointContainer_VTable
;
408 newObject
->lpvtbl5
= &OLEFontImpl_IPersistPropertyBag_VTable
;
409 newObject
->lpvtbl6
= &OLEFontImpl_IPersistStreamInit_VTable
;
412 * Start with one reference count. The caller of this function
413 * must release the interface pointer when it is done.
418 * Copy the description of the font in the object.
420 assert(fontDesc
->cbSizeofstruct
>= sizeof(FONTDESC
));
422 newObject
->description
.cbSizeofstruct
= sizeof(FONTDESC
);
423 newObject
->description
.lpstrName
= HeapAlloc(GetProcessHeap(),
425 (lstrlenW(fontDesc
->lpstrName
)+1) * sizeof(WCHAR
));
426 strcpyW(newObject
->description
.lpstrName
, fontDesc
->lpstrName
);
427 newObject
->description
.cySize
= fontDesc
->cySize
;
428 newObject
->description
.sWeight
= fontDesc
->sWeight
;
429 newObject
->description
.sCharset
= fontDesc
->sCharset
;
430 newObject
->description
.fItalic
= fontDesc
->fItalic
;
431 newObject
->description
.fUnderline
= fontDesc
->fUnderline
;
432 newObject
->description
.fStrikethrough
= fontDesc
->fStrikethrough
;
435 * Initializing all the other members.
437 newObject
->gdiFont
= 0;
438 newObject
->fontLock
= 0;
439 newObject
->cyLogical
= 72L;
440 newObject
->cyHimetric
= 2540L;
441 CreateConnectionPoint((IUnknown
*)newObject
, &IID_IPropertyNotifySink
, &newObject
->pCP
);
442 TRACE("returning %p\n", newObject
);
446 /************************************************************************
447 * OLEFontImpl_Destroy
449 * This method is called by the Release method when the reference
450 * count goes down to 0. It will free all resources used by
453 static void OLEFontImpl_Destroy(OLEFontImpl
* fontDesc
)
455 TRACE("(%p)\n", fontDesc
);
457 HeapFree(GetProcessHeap(), 0, fontDesc
->description
.lpstrName
);
459 if (fontDesc
->gdiFont
!=0)
460 DeleteObject(fontDesc
->gdiFont
);
462 HeapFree(GetProcessHeap(), 0, fontDesc
);
465 /************************************************************************
466 * OLEFontImpl_QueryInterface (IUnknown)
468 * See Windows documentation for more details on IUnknown methods.
470 HRESULT WINAPI
OLEFontImpl_QueryInterface(
475 OLEFontImpl
*this = (OLEFontImpl
*)iface
;
476 TRACE("(%p)->(%s, %p)\n", this, debugstr_guid(riid
), ppvObject
);
479 * Perform a sanity check on the parameters.
481 if ( (this==0) || (ppvObject
==0) )
485 * Initialize the return parameter.
490 * Compare the riid with the interface IDs implemented by this object.
492 if (IsEqualGUID(&IID_IUnknown
, riid
))
493 *ppvObject
= (IFont
*)this;
494 if (IsEqualGUID(&IID_IFont
, riid
))
495 *ppvObject
= (IFont
*)this;
496 if (IsEqualGUID(&IID_IDispatch
, riid
))
497 *ppvObject
= (IDispatch
*)&(this->lpvtbl2
);
498 if (IsEqualGUID(&IID_IFontDisp
, riid
))
499 *ppvObject
= (IDispatch
*)&(this->lpvtbl2
);
500 if (IsEqualGUID(&IID_IPersistStream
, riid
))
501 *ppvObject
= (IPersistStream
*)&(this->lpvtbl3
);
502 if (IsEqualGUID(&IID_IConnectionPointContainer
, riid
))
503 *ppvObject
= (IConnectionPointContainer
*)&(this->lpvtbl4
);
504 if (IsEqualGUID(&IID_IPersistPropertyBag
, riid
))
505 *ppvObject
= (IPersistPropertyBag
*)&(this->lpvtbl5
);
506 if (IsEqualGUID(&IID_IPersistStreamInit
, riid
))
507 *ppvObject
= (IPersistStreamInit
*)&(this->lpvtbl6
);
510 * Check that we obtained an interface.
514 FIXME("() : asking for unsupported interface %s\n",debugstr_guid(riid
));
515 return E_NOINTERFACE
;
517 OLEFontImpl_AddRef((IFont
*)this);
521 /************************************************************************
522 * OLEFontImpl_AddRef (IUnknown)
524 * See Windows documentation for more details on IUnknown methods.
526 ULONG WINAPI
OLEFontImpl_AddRef(
529 OLEFontImpl
*this = (OLEFontImpl
*)iface
;
530 TRACE("(%p)->(ref=%ld)\n", this, this->ref
);
531 return InterlockedIncrement(&this->ref
);
534 /************************************************************************
535 * OLEFontImpl_Release (IUnknown)
537 * See Windows documentation for more details on IUnknown methods.
539 ULONG WINAPI
OLEFontImpl_Release(
542 OLEFontImpl
*this = (OLEFontImpl
*)iface
;
544 TRACE("(%p)->(ref=%ld)\n", this, this->ref
);
547 * Decrease the reference count on this object.
549 ret
= InterlockedDecrement(&this->ref
);
552 * If the reference count goes down to 0, perform suicide.
554 if (ret
==0) OLEFontImpl_Destroy(this);
559 /************************************************************************
560 * OLEFontImpl_get_Name (IFont)
562 * See Windows documentation for more details on IFont methods.
564 static HRESULT WINAPI
OLEFontImpl_get_Name(
568 OLEFontImpl
*this = (OLEFontImpl
*)iface
;
569 TRACE("(%p)->(%p)\n", this, pname
);
576 if (this->description
.lpstrName
!=0)
577 *pname
= SysAllocString(this->description
.lpstrName
);
584 /************************************************************************
585 * OLEFontImpl_put_Name (IFont)
587 * See Windows documentation for more details on IFont methods.
589 static HRESULT WINAPI
OLEFontImpl_put_Name(
593 OLEFontImpl
*this = (OLEFontImpl
*)iface
;
594 TRACE("(%p)->(%p)\n", this, name
);
596 if (this->description
.lpstrName
==0)
598 this->description
.lpstrName
= HeapAlloc(GetProcessHeap(),
600 (lstrlenW(name
)+1) * sizeof(WCHAR
));
604 this->description
.lpstrName
= HeapReAlloc(GetProcessHeap(),
606 this->description
.lpstrName
,
607 (lstrlenW(name
)+1) * sizeof(WCHAR
));
610 if (this->description
.lpstrName
==0)
611 return E_OUTOFMEMORY
;
613 strcpyW(this->description
.lpstrName
, name
);
614 TRACE("new name %s\n", debugstr_w(this->description
.lpstrName
));
615 OLEFont_SendNotify(this, DISPID_FONT_NAME
);
619 /************************************************************************
620 * OLEFontImpl_get_Size (IFont)
622 * See Windows documentation for more details on IFont methods.
624 static HRESULT WINAPI
OLEFontImpl_get_Size(
628 OLEFontImpl
*this = (OLEFontImpl
*)iface
;
629 TRACE("(%p)->(%p)\n", this, psize
);
638 psize
->s
.Lo
= this->description
.cySize
.s
.Lo
;
643 /************************************************************************
644 * OLEFontImpl_put_Size (IFont)
646 * See Windows documentation for more details on IFont methods.
648 static HRESULT WINAPI
OLEFontImpl_put_Size(
652 OLEFontImpl
*this = (OLEFontImpl
*)iface
;
653 TRACE("(%p)->(%ld)\n", this, size
.s
.Lo
);
654 this->description
.cySize
.s
.Hi
= 0;
655 this->description
.cySize
.s
.Lo
= size
.s
.Lo
;
656 OLEFont_SendNotify(this, DISPID_FONT_SIZE
);
661 /************************************************************************
662 * OLEFontImpl_get_Bold (IFont)
664 * See Windows documentation for more details on IFont methods.
666 static HRESULT WINAPI
OLEFontImpl_get_Bold(
670 OLEFontImpl
*this = (OLEFontImpl
*)iface
;
671 TRACE("(%p)->(%p)\n", this, pbold
);
678 *pbold
= this->description
.sWeight
> 550;
683 /************************************************************************
684 * OLEFontImpl_put_Bold (IFont)
686 * See Windows documentation for more details on IFont methods.
688 static HRESULT WINAPI
OLEFontImpl_put_Bold(
692 OLEFontImpl
*this = (OLEFontImpl
*)iface
;
693 TRACE("(%p)->(%d)\n", this, bold
);
694 this->description
.sWeight
= bold
? FW_BOLD
: FW_NORMAL
;
695 OLEFont_SendNotify(this, DISPID_FONT_BOLD
);
700 /************************************************************************
701 * OLEFontImpl_get_Italic (IFont)
703 * See Windows documentation for more details on IFont methods.
705 static HRESULT WINAPI
OLEFontImpl_get_Italic(
709 OLEFontImpl
*this = (OLEFontImpl
*)iface
;
710 TRACE("(%p)->(%p)\n", this, pitalic
);
717 *pitalic
= this->description
.fItalic
;
722 /************************************************************************
723 * OLEFontImpl_put_Italic (IFont)
725 * See Windows documentation for more details on IFont methods.
727 static HRESULT WINAPI
OLEFontImpl_put_Italic(
731 OLEFontImpl
*this = (OLEFontImpl
*)iface
;
732 TRACE("(%p)->(%d)\n", this, italic
);
734 this->description
.fItalic
= italic
;
736 OLEFont_SendNotify(this, DISPID_FONT_ITALIC
);
740 /************************************************************************
741 * OLEFontImpl_get_Underline (IFont)
743 * See Windows documentation for more details on IFont methods.
745 static HRESULT WINAPI
OLEFontImpl_get_Underline(
749 OLEFontImpl
*this = (OLEFontImpl
*)iface
;
750 TRACE("(%p)->(%p)\n", this, punderline
);
758 *punderline
= this->description
.fUnderline
;
763 /************************************************************************
764 * OLEFontImpl_put_Underline (IFont)
766 * See Windows documentation for more details on IFont methods.
768 static HRESULT WINAPI
OLEFontImpl_put_Underline(
772 OLEFontImpl
*this = (OLEFontImpl
*)iface
;
773 TRACE("(%p)->(%d)\n", this, underline
);
775 this->description
.fUnderline
= underline
;
777 OLEFont_SendNotify(this, DISPID_FONT_UNDER
);
781 /************************************************************************
782 * OLEFontImpl_get_Strikethrough (IFont)
784 * See Windows documentation for more details on IFont methods.
786 static HRESULT WINAPI
OLEFontImpl_get_Strikethrough(
788 BOOL
* pstrikethrough
)
790 OLEFontImpl
*this = (OLEFontImpl
*)iface
;
791 TRACE("(%p)->(%p)\n", this, pstrikethrough
);
796 if (pstrikethrough
==0)
799 *pstrikethrough
= this->description
.fStrikethrough
;
804 /************************************************************************
805 * OLEFontImpl_put_Strikethrough (IFont)
807 * See Windows documentation for more details on IFont methods.
809 static HRESULT WINAPI
OLEFontImpl_put_Strikethrough(
813 OLEFontImpl
*this = (OLEFontImpl
*)iface
;
814 TRACE("(%p)->(%d)\n", this, strikethrough
);
816 this->description
.fStrikethrough
= strikethrough
;
817 OLEFont_SendNotify(this, DISPID_FONT_STRIKE
);
822 /************************************************************************
823 * OLEFontImpl_get_Weight (IFont)
825 * See Windows documentation for more details on IFont methods.
827 static HRESULT WINAPI
OLEFontImpl_get_Weight(
831 OLEFontImpl
*this = (OLEFontImpl
*)iface
;
832 TRACE("(%p)->(%p)\n", this, pweight
);
840 *pweight
= this->description
.sWeight
;
845 /************************************************************************
846 * OLEFontImpl_put_Weight (IFont)
848 * See Windows documentation for more details on IFont methods.
850 static HRESULT WINAPI
OLEFontImpl_put_Weight(
854 OLEFontImpl
*this = (OLEFontImpl
*)iface
;
855 TRACE("(%p)->(%d)\n", this, weight
);
857 this->description
.sWeight
= weight
;
859 OLEFont_SendNotify(this, DISPID_FONT_WEIGHT
);
863 /************************************************************************
864 * OLEFontImpl_get_Charset (IFont)
866 * See Windows documentation for more details on IFont methods.
868 static HRESULT WINAPI
OLEFontImpl_get_Charset(
872 OLEFontImpl
*this = (OLEFontImpl
*)iface
;
873 TRACE("(%p)->(%p)\n", this, pcharset
);
881 *pcharset
= this->description
.sCharset
;
886 /************************************************************************
887 * OLEFontImpl_put_Charset (IFont)
889 * See Windows documentation for more details on IFont methods.
891 static HRESULT WINAPI
OLEFontImpl_put_Charset(
895 OLEFontImpl
*this = (OLEFontImpl
*)iface
;
896 TRACE("(%p)->(%d)\n", this, charset
);
898 this->description
.sCharset
= charset
;
899 OLEFont_SendNotify(this, DISPID_FONT_CHARSET
);
904 /************************************************************************
905 * OLEFontImpl_get_hFont (IFont)
907 * See Windows documentation for more details on IFont methods.
909 static HRESULT WINAPI
OLEFontImpl_get_hFont(
913 OLEFontImpl
*this = (OLEFontImpl
*)iface
;
914 TRACE("(%p)->(%p)\n", this, phfont
);
919 * Realize the font if necessary
921 if (this->gdiFont
==0)
928 * The height of the font returned by the get_Size property is the
929 * height of the font in points multiplied by 10000... Using some
930 * simple conversions and the ratio given by the application, it can
931 * be converted to a height in pixels.
933 IFont_get_Size(iface
, &cySize
);
935 fontHeight
= MulDiv( cySize
.s
.Lo
, this->cyLogical
, this->cyHimetric
);
937 memset(&logFont
, 0, sizeof(LOGFONTW
));
939 logFont
.lfHeight
= ((fontHeight
%10000L)>5000L) ? (-fontHeight
/10000L)-1 :
940 (-fontHeight
/10000L);
941 logFont
.lfItalic
= this->description
.fItalic
;
942 logFont
.lfUnderline
= this->description
.fUnderline
;
943 logFont
.lfStrikeOut
= this->description
.fStrikethrough
;
944 logFont
.lfWeight
= this->description
.sWeight
;
945 logFont
.lfCharSet
= this->description
.sCharset
;
946 logFont
.lfOutPrecision
= OUT_CHARACTER_PRECIS
;
947 logFont
.lfClipPrecision
= CLIP_DEFAULT_PRECIS
;
948 logFont
.lfQuality
= DEFAULT_QUALITY
;
949 logFont
.lfPitchAndFamily
= DEFAULT_PITCH
;
950 strcpyW(logFont
.lfFaceName
,this->description
.lpstrName
);
952 this->gdiFont
= CreateFontIndirectW(&logFont
);
955 *phfont
= this->gdiFont
;
956 TRACE("Returning %p\n", *phfont
);
960 /************************************************************************
961 * OLEFontImpl_Clone (IFont)
963 * See Windows documentation for more details on IFont methods.
965 static HRESULT WINAPI
OLEFontImpl_Clone(
969 OLEFontImpl
* newObject
= 0;
973 OLEFontImpl
*this = (OLEFontImpl
*)iface
;
974 TRACE("(%p)->(%p)\n", this, ppfont
);
982 * Allocate space for the object.
984 newObject
= HeapAlloc(GetProcessHeap(), 0, sizeof(OLEFontImpl
));
987 return E_OUTOFMEMORY
;
991 /* We need to alloc new memory for the string, otherwise
992 * we free memory twice.
994 newObject
->description
.lpstrName
= HeapAlloc(
996 (1+strlenW(this->description
.lpstrName
))*2
998 strcpyW(newObject
->description
.lpstrName
, this->description
.lpstrName
);
999 /* We need to clone the HFONT too. This is just cut & paste from above */
1000 IFont_get_Size(iface
, &cySize
);
1002 fontHeight
= MulDiv(cySize
.s
.Lo
, this->cyLogical
,this->cyHimetric
);
1004 memset(&logFont
, 0, sizeof(LOGFONTW
));
1006 logFont
.lfHeight
= ((fontHeight
%10000L)>5000L) ? (-fontHeight
/10000L)-1 :
1007 (-fontHeight
/10000L);
1008 logFont
.lfItalic
= this->description
.fItalic
;
1009 logFont
.lfUnderline
= this->description
.fUnderline
;
1010 logFont
.lfStrikeOut
= this->description
.fStrikethrough
;
1011 logFont
.lfWeight
= this->description
.sWeight
;
1012 logFont
.lfCharSet
= this->description
.sCharset
;
1013 logFont
.lfOutPrecision
= OUT_CHARACTER_PRECIS
;
1014 logFont
.lfClipPrecision
= CLIP_DEFAULT_PRECIS
;
1015 logFont
.lfQuality
= DEFAULT_QUALITY
;
1016 logFont
.lfPitchAndFamily
= DEFAULT_PITCH
;
1017 strcpyW(logFont
.lfFaceName
,this->description
.lpstrName
);
1019 newObject
->gdiFont
= CreateFontIndirectW(&logFont
);
1022 /* The cloned object starts with a reference count of 1 */
1025 *ppfont
= (IFont
*)newObject
;
1030 /************************************************************************
1031 * OLEFontImpl_IsEqual (IFont)
1033 * See Windows documentation for more details on IFont methods.
1035 static HRESULT WINAPI
OLEFontImpl_IsEqual(
1039 FIXME("(%p, %p), stub!\n",iface
,pFontOther
);
1043 /************************************************************************
1044 * OLEFontImpl_SetRatio (IFont)
1046 * See Windows documentation for more details on IFont methods.
1048 static HRESULT WINAPI
OLEFontImpl_SetRatio(
1053 OLEFontImpl
*this = (OLEFontImpl
*)iface
;
1054 TRACE("(%p)->(%ld, %ld)\n", this, cyLogical
, cyHimetric
);
1056 this->cyLogical
= cyLogical
;
1057 this->cyHimetric
= cyHimetric
;
1062 /************************************************************************
1063 * OLEFontImpl_QueryTextMetrics (IFont)
1065 * See Windows documentation for more details on IFont methods.
1067 static HRESULT WINAPI
OLEFontImpl_QueryTextMetrics(
1071 FIXME("(%p, %p), stub!\n",iface
,ptm
);
1075 /************************************************************************
1076 * OLEFontImpl_AddRefHfont (IFont)
1078 * See Windows documentation for more details on IFont methods.
1080 static HRESULT WINAPI
OLEFontImpl_AddRefHfont(
1084 OLEFontImpl
*this = (OLEFontImpl
*)iface
;
1085 TRACE("(%p)->(%p) (lock=%ld)\n", this, hfont
, this->fontLock
);
1087 if ( (hfont
== 0) ||
1088 (hfont
!= this->gdiFont
) )
1089 return E_INVALIDARG
;
1096 /************************************************************************
1097 * OLEFontImpl_ReleaseHfont (IFont)
1099 * See Windows documentation for more details on IFont methods.
1101 static HRESULT WINAPI
OLEFontImpl_ReleaseHfont(
1105 OLEFontImpl
*this = (OLEFontImpl
*)iface
;
1106 TRACE("(%p)->(%p) (lock=%ld)\n", this, hfont
, this->fontLock
);
1108 if ( (hfont
== 0) ||
1109 (hfont
!= this->gdiFont
) )
1110 return E_INVALIDARG
;
1115 * If we just released our last font reference, destroy it.
1117 if (this->fontLock
==0)
1119 DeleteObject(this->gdiFont
);
1126 /************************************************************************
1127 * OLEFontImpl_SetHdc (IFont)
1129 * See Windows documentation for more details on IFont methods.
1131 static HRESULT WINAPI
OLEFontImpl_SetHdc(
1135 OLEFontImpl
*this = (OLEFontImpl
*)iface
;
1136 FIXME("(%p)->(%p): Stub\n", this, hdc
);
1140 /************************************************************************
1141 * OLEFontImpl_IDispatch_QueryInterface (IUnknown)
1143 * See Windows documentation for more details on IUnknown methods.
1145 static HRESULT WINAPI
OLEFontImpl_IDispatch_QueryInterface(
1150 _ICOM_THIS_From_IDispatch(IFont
, iface
);
1152 return IFont_QueryInterface(this, riid
, ppvoid
);
1155 /************************************************************************
1156 * OLEFontImpl_IDispatch_Release (IUnknown)
1158 * See Windows documentation for more details on IUnknown methods.
1160 static ULONG WINAPI
OLEFontImpl_IDispatch_Release(
1163 _ICOM_THIS_From_IDispatch(IFont
, iface
);
1165 return IFont_Release(this);
1168 /************************************************************************
1169 * OLEFontImpl_IDispatch_AddRef (IUnknown)
1171 * See Windows documentation for more details on IUnknown methods.
1173 static ULONG WINAPI
OLEFontImpl_IDispatch_AddRef(
1176 _ICOM_THIS_From_IDispatch(IFont
, iface
);
1178 return IFont_AddRef(this);
1181 /************************************************************************
1182 * OLEFontImpl_GetTypeInfoCount (IDispatch)
1184 * See Windows documentation for more details on IDispatch methods.
1186 static HRESULT WINAPI
OLEFontImpl_GetTypeInfoCount(
1188 unsigned int* pctinfo
)
1190 _ICOM_THIS_From_IDispatch(IFont
, iface
);
1191 FIXME("(%p)->(%p): Stub\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 stdole32tlb
[] = {'s','t','d','o','l','e','3','2','.','t','l','b',0};
1211 _ICOM_THIS_From_IDispatch(OLEFontImpl
, iface
);
1212 TRACE("(%p, iTInfo=%d, lcid=%04x, %p)\n", this, iTInfo
, (int)lcid
, ppTInfo
);
1215 hres
= LoadTypeLib(stdole32tlb
, &tl
);
1217 FIXME("Could not load the stdole32.tlb?\n");
1220 hres
= ITypeLib_GetTypeInfoOfGuid(tl
, &IID_IDispatch
, ppTInfo
);
1222 FIXME("Did not IDispatch typeinfo from typelib, hres %lx\n",hres
);
1227 /************************************************************************
1228 * OLEFontImpl_GetIDsOfNames (IDispatch)
1230 * See Windows documentation for more details on IDispatch methods.
1232 static HRESULT WINAPI
OLEFontImpl_GetIDsOfNames(
1235 LPOLESTR
* rgszNames
,
1240 _ICOM_THIS_From_IDispatch(IFont
, iface
);
1241 FIXME("(%p,%s,%p,%d,%04x,%p), stub!\n", this, debugstr_guid(riid
), rgszNames
,
1242 cNames
, (int)lcid
, rgDispId
1247 /************************************************************************
1248 * OLEFontImpl_Invoke (IDispatch)
1250 * See Windows documentation for more details on IDispatch methods.
1252 * Note: Do not call _put_Xxx methods, since setting things here
1253 * should not call notify functions as I found out debugging the generic
1256 static HRESULT WINAPI
OLEFontImpl_Invoke(
1258 DISPID dispIdMember
,
1262 DISPPARAMS
* pDispParams
,
1263 VARIANT
* pVarResult
,
1264 EXCEPINFO
* pExepInfo
,
1267 _ICOM_THIS_From_IDispatch(IFont
, iface
);
1268 OLEFontImpl
*xthis
= (OLEFontImpl
*)this;
1270 switch (dispIdMember
) {
1271 case DISPID_FONT_NAME
:
1273 case DISPATCH_PROPERTYGET
:
1274 case DISPATCH_PROPERTYGET
|DISPATCH_METHOD
:
1275 V_VT(pVarResult
) = VT_BSTR
;
1276 return OLEFontImpl_get_Name(this, &V_BSTR(pVarResult
));
1277 case DISPATCH_PROPERTYPUT
: {
1281 if (V_VT(&pDispParams
->rgvarg
[0]) == VT_DISPATCH
) {
1285 hr
= IUnknown_QueryInterface(V_DISPATCH(&pDispParams
->rgvarg
[0]), &IID_IFont
, (void **) &font
);
1288 FIXME("dispatch value for name property is not an OleFont, returning hr=0x%lx\n", hr
);
1292 hr
= IFont_get_Name(font
, &name
); /* this allocates a new BSTR so free it later */
1293 if (FAILED(hr
)) return hr
;
1295 IUnknown_Release(font
);
1298 } else if (V_VT(&pDispParams
->rgvarg
[0]) == VT_BSTR
) {
1299 name
= V_BSTR(&pDispParams
->rgvarg
[0]);
1302 FIXME("app is trying to set name property with a non BSTR, non dispatch value. returning E_FAIL\n");
1306 TRACE("name is %s\n", debugstr_w(name
));
1308 if (!xthis
->description
.lpstrName
)
1309 xthis
->description
.lpstrName
= HeapAlloc(GetProcessHeap(), 0, (lstrlenW(name
)+1) * sizeof(WCHAR
));
1311 xthis
->description
.lpstrName
= HeapReAlloc(GetProcessHeap(), 0, xthis
->description
.lpstrName
, (lstrlenW(name
)+1) * sizeof(WCHAR
));
1313 if (xthis
->description
.lpstrName
==0)
1314 return E_OUTOFMEMORY
;
1315 strcpyW(xthis
->description
.lpstrName
, name
);
1317 if (freename
) SysFreeString(name
);
1323 case DISPID_FONT_BOLD
:
1325 case DISPATCH_PROPERTYGET
:
1326 case DISPATCH_PROPERTYGET
|DISPATCH_METHOD
:
1327 V_VT(pVarResult
) = VT_BOOL
;
1328 return OLEFontImpl_get_Bold(this, (BOOL
*)&V_BOOL(pVarResult
));
1329 case DISPATCH_PROPERTYPUT
:
1330 if (V_VT(&pDispParams
->rgvarg
[0]) != VT_BOOL
) {
1331 FIXME("DISPID_FONT_BOLD/put, vt is %d, not VT_BOOL.\n",V_VT(&pDispParams
->rgvarg
[0]));
1334 xthis
->description
.sWeight
= V_BOOL(&pDispParams
->rgvarg
[0]) ? FW_BOLD
: FW_NORMAL
;
1339 case DISPID_FONT_ITALIC
:
1341 case DISPATCH_PROPERTYGET
:
1342 case DISPATCH_PROPERTYGET
|DISPATCH_METHOD
:
1343 V_VT(pVarResult
) = VT_BOOL
;
1344 return OLEFontImpl_get_Italic(this, (BOOL
*)&V_BOOL(pVarResult
));
1345 case DISPATCH_PROPERTYPUT
:
1346 if (V_VT(&pDispParams
->rgvarg
[0]) != VT_BOOL
) {
1347 FIXME("DISPID_FONT_ITALIC/put, vt is %d, not VT_BOOL.\n",V_VT(&pDispParams
->rgvarg
[0]));
1350 xthis
->description
.fItalic
= V_BOOL(&pDispParams
->rgvarg
[0]);
1355 case DISPID_FONT_UNDER
:
1357 case DISPATCH_PROPERTYGET
:
1358 case DISPATCH_PROPERTYGET
|DISPATCH_METHOD
:
1359 V_VT(pVarResult
) = VT_BOOL
;
1360 return OLEFontImpl_get_Underline(this, (BOOL
*)&V_BOOL(pVarResult
));
1361 case DISPATCH_PROPERTYPUT
:
1362 if (V_VT(&pDispParams
->rgvarg
[0]) != VT_BOOL
) {
1363 FIXME("DISPID_FONT_UNDER/put, vt is %d, not VT_BOOL.\n",V_VT(&pDispParams
->rgvarg
[0]));
1366 xthis
->description
.fUnderline
= V_BOOL(&pDispParams
->rgvarg
[0]);
1371 case DISPID_FONT_STRIKE
:
1373 case DISPATCH_PROPERTYGET
:
1374 case DISPATCH_PROPERTYGET
|DISPATCH_METHOD
:
1375 V_VT(pVarResult
) = VT_BOOL
;
1376 return OLEFontImpl_get_Strikethrough(this, (BOOL
*)&V_BOOL(pVarResult
));
1377 case DISPATCH_PROPERTYPUT
:
1378 if (V_VT(&pDispParams
->rgvarg
[0]) != VT_BOOL
) {
1379 FIXME("DISPID_FONT_STRIKE/put, vt is %d, not VT_BOOL.\n",V_VT(&pDispParams
->rgvarg
[0]));
1382 xthis
->description
.fStrikethrough
= V_BOOL(&pDispParams
->rgvarg
[0]);
1387 case DISPID_FONT_SIZE
:
1389 case DISPATCH_PROPERTYPUT
: {
1390 assert (pDispParams
->cArgs
== 1);
1391 xthis
->description
.cySize
.s
.Hi
= 0;
1392 if (V_VT(&pDispParams
->rgvarg
[0]) != VT_CY
) {
1393 if (V_VT(&pDispParams
->rgvarg
[0]) == VT_I2
) {
1394 xthis
->description
.cySize
.s
.Lo
= V_I2(&pDispParams
->rgvarg
[0]) * 10000;
1396 FIXME("property put for Size with vt %d unsupported!\n",V_VT(&pDispParams
->rgvarg
[0]));
1399 xthis
->description
.cySize
.s
.Lo
= V_CY(&pDispParams
->rgvarg
[0]).s
.Lo
;
1403 case DISPATCH_PROPERTYGET
:
1404 case DISPATCH_PROPERTYGET
|DISPATCH_METHOD
:
1405 V_VT(pVarResult
) = VT_CY
;
1406 return OLEFontImpl_get_Size(this, &V_CY(pVarResult
));
1409 case DISPID_FONT_CHARSET
:
1411 case DISPATCH_PROPERTYPUT
:
1412 assert (pDispParams
->cArgs
== 1);
1413 if (V_VT(&pDispParams
->rgvarg
[0]) != VT_I2
)
1414 FIXME("varg of first disparg is not VT_I2, but %d\n",V_VT(&pDispParams
->rgvarg
[0]));
1415 xthis
->description
.sCharset
= V_I2(&pDispParams
->rgvarg
[0]);
1417 case DISPATCH_PROPERTYGET
:
1418 case DISPATCH_PROPERTYGET
|DISPATCH_METHOD
:
1419 V_VT(pVarResult
) = VT_I2
;
1420 return OLEFontImpl_get_Charset(this, &V_I2(pVarResult
));
1424 FIXME("%p->(%ld,%s,%lx,%x,%p,%p,%p,%p), unhandled dispid/flag!\n",
1425 this,dispIdMember
,debugstr_guid(riid
),lcid
,
1426 wFlags
,pDispParams
,pVarResult
,pExepInfo
,puArgErr
1431 /************************************************************************
1432 * OLEFontImpl_IPersistStream_QueryInterface (IUnknown)
1434 * See Windows documentation for more details on IUnknown methods.
1436 static HRESULT WINAPI
OLEFontImpl_IPersistStream_QueryInterface(
1437 IPersistStream
* iface
,
1441 _ICOM_THIS_From_IPersistStream(IFont
, iface
);
1443 return IFont_QueryInterface(this, riid
, ppvoid
);
1446 /************************************************************************
1447 * OLEFontImpl_IPersistStream_Release (IUnknown)
1449 * See Windows documentation for more details on IUnknown methods.
1451 static ULONG WINAPI
OLEFontImpl_IPersistStream_Release(
1452 IPersistStream
* iface
)
1454 _ICOM_THIS_From_IPersistStream(IFont
, iface
);
1456 return IFont_Release(this);
1459 /************************************************************************
1460 * OLEFontImpl_IPersistStream_AddRef (IUnknown)
1462 * See Windows documentation for more details on IUnknown methods.
1464 static ULONG WINAPI
OLEFontImpl_IPersistStream_AddRef(
1465 IPersistStream
* iface
)
1467 _ICOM_THIS_From_IPersistStream(IFont
, iface
);
1469 return IFont_AddRef(this);
1472 /************************************************************************
1473 * OLEFontImpl_GetClassID (IPersistStream)
1475 * See Windows documentation for more details on IPersistStream methods.
1477 static HRESULT WINAPI
OLEFontImpl_GetClassID(
1478 IPersistStream
* iface
,
1481 TRACE("(%p,%p)\n",iface
,pClassID
);
1485 memcpy(pClassID
, &CLSID_StdFont
, sizeof(CLSID_StdFont
));
1490 /************************************************************************
1491 * OLEFontImpl_IsDirty (IPersistStream)
1493 * See Windows documentation for more details on IPersistStream methods.
1495 static HRESULT WINAPI
OLEFontImpl_IsDirty(
1496 IPersistStream
* iface
)
1498 TRACE("(%p)\n",iface
);
1502 /************************************************************************
1503 * OLEFontImpl_Load (IPersistStream)
1505 * See Windows documentation for more details on IPersistStream methods.
1507 * This is the format of the standard font serialization as far as I
1510 * Offset Type Value Comment
1511 * 0x0000 Byte Unknown Probably a version number, contains 0x01
1512 * 0x0001 Short Charset Charset value from the FONTDESC structure
1513 * 0x0003 Byte Attributes Flags defined as follows:
1515 * 00000100 - Underline
1516 * 00001000 - Strikethrough
1517 * 0x0004 Short Weight Weight value from FONTDESC structure
1518 * 0x0006 DWORD size "Low" portion of the cySize member of the FONTDESC
1520 * 0x000A Byte name length Length of the font name string (no null character)
1521 * 0x000B String name Name of the font (ASCII, no nul character)
1523 static HRESULT WINAPI
OLEFontImpl_Load(
1524 IPersistStream
* iface
,
1525 IStream
* pLoadStream
)
1527 char readBuffer
[0x100];
1534 _ICOM_THIS_From_IPersistStream(OLEFontImpl
, iface
);
1537 * Read the version byte
1539 IStream_Read(pLoadStream
, &bVersion
, 1, &cbRead
);
1548 IStream_Read(pLoadStream
, &this->description
.sCharset
, 2, &cbRead
);
1556 IStream_Read(pLoadStream
, &bAttributes
, 1, &cbRead
);
1561 this->description
.fItalic
= (bAttributes
& FONTPERSIST_ITALIC
) != 0;
1562 this->description
.fStrikethrough
= (bAttributes
& FONTPERSIST_STRIKETHROUGH
) != 0;
1563 this->description
.fUnderline
= (bAttributes
& FONTPERSIST_UNDERLINE
) != 0;
1568 IStream_Read(pLoadStream
, &this->description
.sWeight
, 2, &cbRead
);
1576 IStream_Read(pLoadStream
, &this->description
.cySize
.s
.Lo
, 4, &cbRead
);
1581 this->description
.cySize
.s
.Hi
= 0;
1586 IStream_Read(pLoadStream
, &bStringSize
, 1, &cbRead
);
1591 IStream_Read(pLoadStream
, readBuffer
, bStringSize
, &cbRead
);
1593 if (cbRead
!=bStringSize
)
1596 HeapFree(GetProcessHeap(), 0, this->description
.lpstrName
);
1598 len
= MultiByteToWideChar( CP_ACP
, 0, readBuffer
, bStringSize
, NULL
, 0 );
1599 this->description
.lpstrName
= HeapAlloc( GetProcessHeap(), 0, (len
+1) * sizeof(WCHAR
) );
1600 MultiByteToWideChar( CP_ACP
, 0, readBuffer
, bStringSize
, this->description
.lpstrName
, len
);
1601 this->description
.lpstrName
[len
] = 0;
1603 /* Ensure use of this font causes a new one to be created @@@@ */
1604 DeleteObject(this->gdiFont
);
1610 /************************************************************************
1611 * OLEFontImpl_Save (IPersistStream)
1613 * See Windows documentation for more details on IPersistStream methods.
1615 static HRESULT WINAPI
OLEFontImpl_Save(
1616 IPersistStream
* iface
,
1617 IStream
* pOutStream
,
1620 char* writeBuffer
= NULL
;
1622 BYTE bVersion
= 0x01;
1626 _ICOM_THIS_From_IPersistStream(OLEFontImpl
, iface
);
1629 * Read the version byte
1631 IStream_Write(pOutStream
, &bVersion
, 1, &cbWritten
);
1639 IStream_Write(pOutStream
, &this->description
.sCharset
, 2, &cbWritten
);
1649 if (this->description
.fItalic
)
1650 bAttributes
|= FONTPERSIST_ITALIC
;
1652 if (this->description
.fStrikethrough
)
1653 bAttributes
|= FONTPERSIST_STRIKETHROUGH
;
1655 if (this->description
.fUnderline
)
1656 bAttributes
|= FONTPERSIST_UNDERLINE
;
1658 IStream_Write(pOutStream
, &bAttributes
, 1, &cbWritten
);
1666 IStream_Write(pOutStream
, &this->description
.sWeight
, 2, &cbWritten
);
1674 IStream_Write(pOutStream
, &this->description
.cySize
.s
.Lo
, 4, &cbWritten
);
1682 if (this->description
.lpstrName
!=0)
1683 bStringSize
= WideCharToMultiByte( CP_ACP
, 0, this->description
.lpstrName
,
1684 strlenW(this->description
.lpstrName
), NULL
, 0, NULL
, NULL
);
1688 IStream_Write(pOutStream
, &bStringSize
, 1, &cbWritten
);
1695 if (!(writeBuffer
= HeapAlloc( GetProcessHeap(), 0, bStringSize
))) return E_OUTOFMEMORY
;
1696 WideCharToMultiByte( CP_ACP
, 0, this->description
.lpstrName
,
1697 strlenW(this->description
.lpstrName
),
1698 writeBuffer
, bStringSize
, NULL
, NULL
);
1700 IStream_Write(pOutStream
, writeBuffer
, bStringSize
, &cbWritten
);
1701 HeapFree(GetProcessHeap(), 0, writeBuffer
);
1703 if (cbWritten
!=bStringSize
)
1710 /************************************************************************
1711 * OLEFontImpl_GetSizeMax (IPersistStream)
1713 * See Windows documentation for more details on IPersistStream methods.
1715 static HRESULT WINAPI
OLEFontImpl_GetSizeMax(
1716 IPersistStream
* iface
,
1717 ULARGE_INTEGER
* pcbSize
)
1719 _ICOM_THIS_From_IPersistStream(OLEFontImpl
, iface
);
1724 pcbSize
->u
.HighPart
= 0;
1725 pcbSize
->u
.LowPart
= 0;
1727 pcbSize
->u
.LowPart
+= sizeof(BYTE
); /* Version */
1728 pcbSize
->u
.LowPart
+= sizeof(WORD
); /* Lang code */
1729 pcbSize
->u
.LowPart
+= sizeof(BYTE
); /* Flags */
1730 pcbSize
->u
.LowPart
+= sizeof(WORD
); /* Weight */
1731 pcbSize
->u
.LowPart
+= sizeof(DWORD
); /* Size */
1732 pcbSize
->u
.LowPart
+= sizeof(BYTE
); /* StrLength */
1734 if (this->description
.lpstrName
!=0)
1735 pcbSize
->u
.LowPart
+= lstrlenW(this->description
.lpstrName
);
1740 /************************************************************************
1741 * OLEFontImpl_IConnectionPointContainer_QueryInterface (IUnknown)
1743 * See Windows documentation for more details on IUnknown methods.
1745 static HRESULT WINAPI
OLEFontImpl_IConnectionPointContainer_QueryInterface(
1746 IConnectionPointContainer
* iface
,
1750 _ICOM_THIS_From_IConnectionPointContainer(OLEFontImpl
, iface
);
1752 return IFont_QueryInterface((IFont
*)this, riid
, ppvoid
);
1755 /************************************************************************
1756 * OLEFontImpl_IConnectionPointContainer_Release (IUnknown)
1758 * See Windows documentation for more details on IUnknown methods.
1760 static ULONG WINAPI
OLEFontImpl_IConnectionPointContainer_Release(
1761 IConnectionPointContainer
* iface
)
1763 _ICOM_THIS_From_IConnectionPointContainer(OLEFontImpl
, iface
);
1765 return IFont_Release((IFont
*)this);
1768 /************************************************************************
1769 * OLEFontImpl_IConnectionPointContainer_AddRef (IUnknown)
1771 * See Windows documentation for more details on IUnknown methods.
1773 static ULONG WINAPI
OLEFontImpl_IConnectionPointContainer_AddRef(
1774 IConnectionPointContainer
* iface
)
1776 _ICOM_THIS_From_IConnectionPointContainer(OLEFontImpl
, iface
);
1778 return IFont_AddRef((IFont
*)this);
1781 /************************************************************************
1782 * OLEFontImpl_EnumConnectionPoints (IConnectionPointContainer)
1784 * See Windows documentation for more details on IConnectionPointContainer
1787 static HRESULT WINAPI
OLEFontImpl_EnumConnectionPoints(
1788 IConnectionPointContainer
* iface
,
1789 IEnumConnectionPoints
**ppEnum
)
1791 _ICOM_THIS_From_IConnectionPointContainer(OLEFontImpl
, iface
);
1793 FIXME("(%p)->(%p): stub\n", this, ppEnum
);
1797 /************************************************************************
1798 * OLEFontImpl_FindConnectionPoint (IConnectionPointContainer)
1800 * See Windows documentation for more details on IConnectionPointContainer
1803 static HRESULT WINAPI
OLEFontImpl_FindConnectionPoint(
1804 IConnectionPointContainer
* iface
,
1806 IConnectionPoint
**ppCp
)
1808 _ICOM_THIS_From_IConnectionPointContainer(OLEFontImpl
, iface
);
1809 TRACE("(%p)->(%s, %p): stub\n", this, debugstr_guid(riid
), ppCp
);
1811 if(memcmp(riid
, &IID_IPropertyNotifySink
, sizeof(IID_IPropertyNotifySink
)) == 0) {
1812 return IConnectionPoint_QueryInterface(this->pCP
, &IID_IConnectionPoint
,
1815 FIXME("Tried to find connection point on %s\n", debugstr_guid(riid
));
1816 return E_NOINTERFACE
;
1820 /************************************************************************
1821 * OLEFontImpl implementation of IPersistPropertyBag.
1823 static HRESULT WINAPI
OLEFontImpl_IPersistPropertyBag_QueryInterface(
1824 IPersistPropertyBag
*iface
, REFIID riid
, LPVOID
*ppvObj
1826 _ICOM_THIS_From_IPersistPropertyBag(IFont
, iface
);
1827 return IFont_QueryInterface(this,riid
,ppvObj
);
1830 static ULONG WINAPI
OLEFontImpl_IPersistPropertyBag_AddRef(
1831 IPersistPropertyBag
*iface
1833 _ICOM_THIS_From_IPersistPropertyBag(IFont
, iface
);
1834 return IFont_AddRef(this);
1837 static ULONG WINAPI
OLEFontImpl_IPersistPropertyBag_Release(
1838 IPersistPropertyBag
*iface
1840 _ICOM_THIS_From_IPersistPropertyBag(IFont
, iface
);
1841 return IFont_Release(this);
1844 static HRESULT WINAPI
OLEFontImpl_IPersistPropertyBag_GetClassID(
1845 IPersistPropertyBag
*iface
, CLSID
*classid
1847 FIXME("(%p,%p), stub!\n", iface
, classid
);
1851 static HRESULT WINAPI
OLEFontImpl_IPersistPropertyBag_InitNew(
1852 IPersistPropertyBag
*iface
1854 FIXME("(%p), stub!\n", iface
);
1858 static HRESULT WINAPI
OLEFontImpl_IPersistPropertyBag_Load(
1859 IPersistPropertyBag
*iface
, IPropertyBag
* pPropBag
, IErrorLog
* pErrorLog
1861 /* (from Visual Basic 6 property bag)
1862 Name = "MS Sans Serif"
1866 Underline = 0 'False
1868 Strikethrough = 0 'False
1870 static const WCHAR sAttrName
[] = {'N','a','m','e',0};
1871 static const WCHAR sAttrSize
[] = {'S','i','z','e',0};
1872 static const WCHAR sAttrCharset
[] = {'C','h','a','r','s','e','t',0};
1873 static const WCHAR sAttrWeight
[] = {'W','e','i','g','h','t',0};
1874 static const WCHAR sAttrUnderline
[] = {'U','n','d','e','r','l','i','n','e',0};
1875 static const WCHAR sAttrItalic
[] = {'I','t','a','l','i','c',0};
1876 static const WCHAR sAttrStrikethrough
[] = {'S','t','r','i','k','e','t','h','r','o','u','g','h',0};
1879 HRESULT iRes
= S_OK
;
1880 _ICOM_THIS_From_IPersistPropertyBag(IFont
, iface
);
1882 VariantInit(&rawAttr
);
1883 VariantInit(&valueAttr
);
1886 iRes
= IPropertyBag_Read(pPropBag
, sAttrName
, &rawAttr
, pErrorLog
);
1889 iRes
= VariantChangeType(&rawAttr
, &valueAttr
, 0, VT_BSTR
);
1891 iRes
= IFont_put_Name(this, V_BSTR(&valueAttr
));
1893 else if (iRes
== E_INVALIDARG
)
1895 VariantClear(&rawAttr
);
1896 VariantClear(&valueAttr
);
1900 iRes
= IPropertyBag_Read(pPropBag
, sAttrSize
, &rawAttr
, pErrorLog
);
1903 iRes
= VariantChangeType(&rawAttr
, &valueAttr
, 0, VT_CY
);
1905 iRes
= IFont_put_Size(this, V_CY(&valueAttr
));
1907 else if (iRes
== E_INVALIDARG
)
1909 VariantClear(&rawAttr
);
1910 VariantClear(&valueAttr
);
1914 iRes
= IPropertyBag_Read(pPropBag
, sAttrCharset
, &rawAttr
, pErrorLog
);
1917 iRes
= VariantChangeType(&rawAttr
, &valueAttr
, 0, VT_I2
);
1919 iRes
= IFont_put_Charset(this, V_I2(&valueAttr
));
1921 else if (iRes
== E_INVALIDARG
)
1923 VariantClear(&rawAttr
);
1924 VariantClear(&valueAttr
);
1928 iRes
= IPropertyBag_Read(pPropBag
, sAttrWeight
, &rawAttr
, pErrorLog
);
1931 iRes
= VariantChangeType(&rawAttr
, &valueAttr
, 0, VT_I2
);
1933 iRes
= IFont_put_Weight(this, V_I2(&valueAttr
));
1935 else if (iRes
== E_INVALIDARG
)
1937 VariantClear(&rawAttr
);
1938 VariantClear(&valueAttr
);
1943 iRes
= IPropertyBag_Read(pPropBag
, sAttrUnderline
, &rawAttr
, pErrorLog
);
1946 iRes
= VariantChangeType(&rawAttr
, &valueAttr
, 0, VT_BOOL
);
1948 iRes
= IFont_put_Underline(this, V_BOOL(&valueAttr
));
1950 else if (iRes
== E_INVALIDARG
)
1952 VariantClear(&rawAttr
);
1953 VariantClear(&valueAttr
);
1957 iRes
= IPropertyBag_Read(pPropBag
, sAttrItalic
, &rawAttr
, pErrorLog
);
1960 iRes
= VariantChangeType(&rawAttr
, &valueAttr
, 0, VT_BOOL
);
1962 iRes
= IFont_put_Italic(this, V_BOOL(&valueAttr
));
1964 else if (iRes
== E_INVALIDARG
)
1966 VariantClear(&rawAttr
);
1967 VariantClear(&valueAttr
);
1971 iRes
= IPropertyBag_Read(pPropBag
, sAttrStrikethrough
, &rawAttr
, pErrorLog
);
1974 iRes
= VariantChangeType(&rawAttr
, &valueAttr
, 0, VT_BOOL
);
1976 IFont_put_Strikethrough(this, V_BOOL(&valueAttr
));
1978 else if (iRes
== E_INVALIDARG
)
1980 VariantClear(&rawAttr
);
1981 VariantClear(&valueAttr
);
1985 WARN("-- 0x%08lx\n", iRes
);
1989 static HRESULT WINAPI
OLEFontImpl_IPersistPropertyBag_Save(
1990 IPersistPropertyBag
*iface
, IPropertyBag
* pPropBag
, BOOL fClearDirty
,
1991 BOOL fSaveAllProperties
1993 FIXME("(%p,%p,%d,%d), stub!\n", iface
, pPropBag
, fClearDirty
, fSaveAllProperties
);
1997 static IPersistPropertyBagVtbl OLEFontImpl_IPersistPropertyBag_VTable
=
1999 OLEFontImpl_IPersistPropertyBag_QueryInterface
,
2000 OLEFontImpl_IPersistPropertyBag_AddRef
,
2001 OLEFontImpl_IPersistPropertyBag_Release
,
2003 OLEFontImpl_IPersistPropertyBag_GetClassID
,
2004 OLEFontImpl_IPersistPropertyBag_InitNew
,
2005 OLEFontImpl_IPersistPropertyBag_Load
,
2006 OLEFontImpl_IPersistPropertyBag_Save
2009 /************************************************************************
2010 * OLEFontImpl implementation of IPersistStreamInit.
2012 static HRESULT WINAPI
OLEFontImpl_IPersistStreamInit_QueryInterface(
2013 IPersistStreamInit
*iface
, REFIID riid
, LPVOID
*ppvObj
2015 _ICOM_THIS_From_IPersistStreamInit(IFont
, iface
);
2016 return IFont_QueryInterface(this,riid
,ppvObj
);
2019 static ULONG WINAPI
OLEFontImpl_IPersistStreamInit_AddRef(
2020 IPersistStreamInit
*iface
2022 _ICOM_THIS_From_IPersistStreamInit(IFont
, iface
);
2023 return IFont_AddRef(this);
2026 static ULONG WINAPI
OLEFontImpl_IPersistStreamInit_Release(
2027 IPersistStreamInit
*iface
2029 _ICOM_THIS_From_IPersistStreamInit(IFont
, iface
);
2030 return IFont_Release(this);
2033 static HRESULT WINAPI
OLEFontImpl_IPersistStreamInit_GetClassID(
2034 IPersistStreamInit
*iface
, CLSID
*classid
2036 FIXME("(%p,%p), stub!\n", iface
, classid
);
2040 static HRESULT WINAPI
OLEFontImpl_IPersistStreamInit_IsDirty(
2041 IPersistStreamInit
*iface
2043 FIXME("(%p), stub!\n", iface
);
2047 static HRESULT WINAPI
OLEFontImpl_IPersistStreamInit_Load(
2048 IPersistStreamInit
*iface
, LPSTREAM pStm
2050 FIXME("(%p,%p), stub!\n", iface
, pStm
);
2054 static HRESULT WINAPI
OLEFontImpl_IPersistStreamInit_Save(
2055 IPersistStreamInit
*iface
, LPSTREAM pStm
, BOOL fClearDirty
2057 FIXME("(%p,%p,%d), stub!\n", iface
, pStm
, fClearDirty
);
2061 static HRESULT WINAPI
OLEFontImpl_IPersistStreamInit_GetSizeMax(
2062 IPersistStreamInit
*iface
, ULARGE_INTEGER
*pcbSize
2064 FIXME("(%p,%p), stub!\n", iface
, pcbSize
);
2068 static HRESULT WINAPI
OLEFontImpl_IPersistStreamInit_InitNew(
2069 IPersistStreamInit
*iface
2071 FIXME("(%p), stub!\n", iface
);
2075 static IPersistStreamInitVtbl OLEFontImpl_IPersistStreamInit_VTable
=
2077 OLEFontImpl_IPersistStreamInit_QueryInterface
,
2078 OLEFontImpl_IPersistStreamInit_AddRef
,
2079 OLEFontImpl_IPersistStreamInit_Release
,
2081 OLEFontImpl_IPersistStreamInit_GetClassID
,
2082 OLEFontImpl_IPersistStreamInit_IsDirty
,
2083 OLEFontImpl_IPersistStreamInit_Load
,
2084 OLEFontImpl_IPersistStreamInit_Save
,
2085 OLEFontImpl_IPersistStreamInit_GetSizeMax
,
2086 OLEFontImpl_IPersistStreamInit_InitNew
2089 /*******************************************************************************
2090 * StdFont ClassFactory
2094 /* IUnknown fields */
2095 IClassFactoryVtbl
*lpVtbl
;
2097 } IClassFactoryImpl
;
2099 static HRESULT WINAPI
2100 SFCF_QueryInterface(LPCLASSFACTORY iface
,REFIID riid
,LPVOID
*ppobj
) {
2101 IClassFactoryImpl
*This
= (IClassFactoryImpl
*)iface
;
2103 FIXME("(%p)->(%s,%p),stub!\n",This
,debugstr_guid(riid
),ppobj
);
2104 return E_NOINTERFACE
;
2108 SFCF_AddRef(LPCLASSFACTORY iface
) {
2109 IClassFactoryImpl
*This
= (IClassFactoryImpl
*)iface
;
2110 return InterlockedIncrement(&This
->ref
);
2113 static ULONG WINAPI
SFCF_Release(LPCLASSFACTORY iface
) {
2114 IClassFactoryImpl
*This
= (IClassFactoryImpl
*)iface
;
2115 /* static class, won't be freed */
2116 return InterlockedDecrement(&This
->ref
);
2119 static HRESULT WINAPI
SFCF_CreateInstance(
2120 LPCLASSFACTORY iface
,LPUNKNOWN pOuter
,REFIID riid
,LPVOID
*ppobj
2122 return OleCreateFontIndirect(NULL
,riid
,ppobj
);
2126 static HRESULT WINAPI
SFCF_LockServer(LPCLASSFACTORY iface
,BOOL dolock
) {
2127 IClassFactoryImpl
*This
= (IClassFactoryImpl
*)iface
;
2128 FIXME("(%p)->(%d),stub!\n",This
,dolock
);
2132 static IClassFactoryVtbl SFCF_Vtbl
= {
2133 SFCF_QueryInterface
,
2136 SFCF_CreateInstance
,
2139 static IClassFactoryImpl STDFONT_CF
= {&SFCF_Vtbl
, 1 };
2141 void _get_STDFONT_CF(LPVOID
*ppv
) { *ppv
= (LPVOID
)&STDFONT_CF
; }