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 accomodate all of the VTables implemented
107 #define _ICOM_THIS(class,name) class* this = (class*)name
108 #define _ICOM_THIS_From_IDispatch(class, name) class* this = (class*)(((char*)name)-sizeof(void*))
109 #define _ICOM_THIS_From_IPersistStream(class, name) class* this = (class*)(((char*)name)-2*sizeof(void*))
110 #define _ICOM_THIS_From_IConnectionPointContainer(class, name) class* this = (class*)(((char*)name)-3*sizeof(void*))
111 #define _ICOM_THIS_From_IPersistPropertyBag(class, name) class* this = (class*)(((char*)name)-4*sizeof(void*))
112 #define _ICOM_THIS_From_IPersistStreamInit(class, name) class* this = (class*)(((char*)name)-5*sizeof(void*))
115 /***********************************************************************
116 * Prototypes for the implementation functions for the IFont
119 static OLEFontImpl
* OLEFontImpl_Construct(LPFONTDESC fontDesc
);
120 static void OLEFontImpl_Destroy(OLEFontImpl
* fontDesc
);
121 static HRESULT WINAPI
OLEFontImpl_QueryInterface(IFont
* iface
, REFIID riid
, VOID
** ppvoid
);
122 static ULONG WINAPI
OLEFontImpl_AddRef(IFont
* iface
);
123 static ULONG WINAPI
OLEFontImpl_Release(IFont
* iface
);
124 static HRESULT WINAPI
OLEFontImpl_get_Name(IFont
* iface
, BSTR
* pname
);
125 static HRESULT WINAPI
OLEFontImpl_put_Name(IFont
* iface
, BSTR name
);
126 static HRESULT WINAPI
OLEFontImpl_get_Size(IFont
* iface
, CY
* psize
);
127 static HRESULT WINAPI
OLEFontImpl_put_Size(IFont
* iface
, CY size
);
128 static HRESULT WINAPI
OLEFontImpl_get_Bold(IFont
* iface
, BOOL
* pbold
);
129 static HRESULT WINAPI
OLEFontImpl_put_Bold(IFont
* iface
, BOOL bold
);
130 static HRESULT WINAPI
OLEFontImpl_get_Italic(IFont
* iface
, BOOL
* pitalic
);
131 static HRESULT WINAPI
OLEFontImpl_put_Italic(IFont
* iface
, BOOL italic
);
132 static HRESULT WINAPI
OLEFontImpl_get_Underline(IFont
* iface
, BOOL
* punderline
);
133 static HRESULT WINAPI
OLEFontImpl_put_Underline(IFont
* iface
, BOOL underline
);
134 static HRESULT WINAPI
OLEFontImpl_get_Strikethrough(IFont
* iface
, BOOL
* pstrikethrough
);
135 static HRESULT WINAPI
OLEFontImpl_put_Strikethrough(IFont
* iface
, BOOL strikethrough
);
136 static HRESULT WINAPI
OLEFontImpl_get_Weight(IFont
* iface
, short* pweight
);
137 static HRESULT WINAPI
OLEFontImpl_put_Weight(IFont
* iface
, short weight
);
138 static HRESULT WINAPI
OLEFontImpl_get_Charset(IFont
* iface
, short* pcharset
);
139 static HRESULT WINAPI
OLEFontImpl_put_Charset(IFont
* iface
, short charset
);
140 static HRESULT WINAPI
OLEFontImpl_get_hFont(IFont
* iface
, HFONT
* phfont
);
141 static HRESULT WINAPI
OLEFontImpl_Clone(IFont
* iface
, IFont
** ppfont
);
142 static HRESULT WINAPI
OLEFontImpl_IsEqual(IFont
* iface
, IFont
* pFontOther
);
143 static HRESULT WINAPI
OLEFontImpl_SetRatio(IFont
* iface
, long cyLogical
, long cyHimetric
);
144 static HRESULT WINAPI
OLEFontImpl_QueryTextMetrics(IFont
* iface
, TEXTMETRICOLE
* ptm
);
145 static HRESULT WINAPI
OLEFontImpl_AddRefHfont(IFont
* iface
, HFONT hfont
);
146 static HRESULT WINAPI
OLEFontImpl_ReleaseHfont(IFont
* iface
, HFONT hfont
);
147 static HRESULT WINAPI
OLEFontImpl_SetHdc(IFont
* iface
, HDC hdc
);
149 /***********************************************************************
150 * Prototypes for the implementation functions for the IDispatch
153 static HRESULT WINAPI
OLEFontImpl_IDispatch_QueryInterface(IDispatch
* iface
,
156 static ULONG WINAPI
OLEFontImpl_IDispatch_AddRef(IDispatch
* iface
);
157 static ULONG WINAPI
OLEFontImpl_IDispatch_Release(IDispatch
* iface
);
158 static HRESULT WINAPI
OLEFontImpl_GetTypeInfoCount(IDispatch
* iface
,
159 unsigned int* pctinfo
);
160 static HRESULT WINAPI
OLEFontImpl_GetTypeInfo(IDispatch
* iface
,
163 ITypeInfo
** ppTInfo
);
164 static HRESULT WINAPI
OLEFontImpl_GetIDsOfNames(IDispatch
* iface
,
170 static HRESULT WINAPI
OLEFontImpl_Invoke(IDispatch
* iface
,
175 DISPPARAMS
* pDispParams
,
177 EXCEPINFO
* pExepInfo
,
180 /***********************************************************************
181 * Prototypes for the implementation functions for the IPersistStream
184 static HRESULT WINAPI
OLEFontImpl_IPersistStream_QueryInterface(IPersistStream
* iface
,
187 static ULONG WINAPI
OLEFontImpl_IPersistStream_AddRef(IPersistStream
* iface
);
188 static ULONG WINAPI
OLEFontImpl_IPersistStream_Release(IPersistStream
* iface
);
189 static HRESULT WINAPI
OLEFontImpl_GetClassID(IPersistStream
* iface
,
191 static HRESULT WINAPI
OLEFontImpl_IsDirty(IPersistStream
* iface
);
192 static HRESULT WINAPI
OLEFontImpl_Load(IPersistStream
* iface
,
193 IStream
* pLoadStream
);
194 static HRESULT WINAPI
OLEFontImpl_Save(IPersistStream
* iface
,
197 static HRESULT WINAPI
OLEFontImpl_GetSizeMax(IPersistStream
* iface
,
198 ULARGE_INTEGER
* pcbSize
);
200 /***********************************************************************
201 * Prototypes for the implementation functions for the
202 * IConnectionPointContainer interface
204 static HRESULT WINAPI
OLEFontImpl_IConnectionPointContainer_QueryInterface(
205 IConnectionPointContainer
* iface
,
208 static ULONG WINAPI
OLEFontImpl_IConnectionPointContainer_AddRef(
209 IConnectionPointContainer
* iface
);
210 static ULONG WINAPI
OLEFontImpl_IConnectionPointContainer_Release(
211 IConnectionPointContainer
* iface
);
212 static HRESULT WINAPI
OLEFontImpl_EnumConnectionPoints(
213 IConnectionPointContainer
* iface
,
214 IEnumConnectionPoints
**ppEnum
);
215 static HRESULT WINAPI
OLEFontImpl_FindConnectionPoint(
216 IConnectionPointContainer
* iface
,
218 IConnectionPoint
**ppCp
);
221 * Virtual function tables for the OLEFontImpl class.
223 static IFontVtbl OLEFontImpl_VTable
=
225 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
226 OLEFontImpl_QueryInterface
,
229 OLEFontImpl_get_Name
,
230 OLEFontImpl_put_Name
,
231 OLEFontImpl_get_Size
,
232 OLEFontImpl_put_Size
,
233 OLEFontImpl_get_Bold
,
234 OLEFontImpl_put_Bold
,
235 OLEFontImpl_get_Italic
,
236 OLEFontImpl_put_Italic
,
237 OLEFontImpl_get_Underline
,
238 OLEFontImpl_put_Underline
,
239 OLEFontImpl_get_Strikethrough
,
240 OLEFontImpl_put_Strikethrough
,
241 OLEFontImpl_get_Weight
,
242 OLEFontImpl_put_Weight
,
243 OLEFontImpl_get_Charset
,
244 OLEFontImpl_put_Charset
,
245 OLEFontImpl_get_hFont
,
248 OLEFontImpl_SetRatio
,
249 OLEFontImpl_QueryTextMetrics
,
250 OLEFontImpl_AddRefHfont
,
251 OLEFontImpl_ReleaseHfont
,
255 static IDispatchVtbl OLEFontImpl_IDispatch_VTable
=
257 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
258 OLEFontImpl_IDispatch_QueryInterface
,
259 OLEFontImpl_IDispatch_AddRef
,
260 OLEFontImpl_IDispatch_Release
,
261 OLEFontImpl_GetTypeInfoCount
,
262 OLEFontImpl_GetTypeInfo
,
263 OLEFontImpl_GetIDsOfNames
,
267 static IPersistStreamVtbl OLEFontImpl_IPersistStream_VTable
=
269 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
270 OLEFontImpl_IPersistStream_QueryInterface
,
271 OLEFontImpl_IPersistStream_AddRef
,
272 OLEFontImpl_IPersistStream_Release
,
273 OLEFontImpl_GetClassID
,
277 OLEFontImpl_GetSizeMax
280 static IConnectionPointContainerVtbl
281 OLEFontImpl_IConnectionPointContainer_VTable
=
283 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
284 OLEFontImpl_IConnectionPointContainer_QueryInterface
,
285 OLEFontImpl_IConnectionPointContainer_AddRef
,
286 OLEFontImpl_IConnectionPointContainer_Release
,
287 OLEFontImpl_EnumConnectionPoints
,
288 OLEFontImpl_FindConnectionPoint
291 static IPersistPropertyBagVtbl OLEFontImpl_IPersistPropertyBag_VTable
;
292 static IPersistStreamInitVtbl OLEFontImpl_IPersistStreamInit_VTable
;
293 /******************************************************************************
294 * OleCreateFontIndirect [OLEAUT32.420]
296 HRESULT WINAPI
OleCreateFontIndirect(
297 LPFONTDESC lpFontDesc
,
301 OLEFontImpl
* newFont
= 0;
304 TRACE("(%p, %s, %p)\n", lpFontDesc
, debugstr_guid(riid
), ppvObj
);
316 static const WCHAR fname
[] = { 'S','y','s','t','e','m',0 };
318 fd
.cbSizeofstruct
= sizeof(fd
);
319 fd
.lpstrName
= (WCHAR
*)fname
;
320 fd
.cySize
.s
.Lo
= 80000;
326 fd
.fStrikethrough
= 0;
331 * Try to construct a new instance of the class.
333 newFont
= OLEFontImpl_Construct(lpFontDesc
);
336 return E_OUTOFMEMORY
;
339 * Make sure it supports the interface required by the caller.
341 hr
= IFont_QueryInterface((IFont
*)newFont
, riid
, ppvObj
);
344 * Release the reference obtained in the constructor. If
345 * the QueryInterface was unsuccessful, it will free the class.
347 IFont_Release((IFont
*)newFont
);
353 /***********************************************************************
354 * Implementation of the OLEFontImpl class.
357 /***********************************************************************
358 * OLEFont_SendNotify (internal)
360 * Sends notification messages of changed properties to any interested
363 static void OLEFont_SendNotify(OLEFontImpl
* this, DISPID dispID
)
365 IEnumConnections
*pEnum
;
369 hres
= IConnectionPoint_EnumConnections(this->pCP
, &pEnum
);
370 if (FAILED(hres
)) /* When we have 0 connections. */
373 while(IEnumConnections_Next(pEnum
, 1, &CD
, NULL
) == S_OK
) {
374 IPropertyNotifySink
*sink
;
376 IUnknown_QueryInterface(CD
.pUnk
, &IID_IPropertyNotifySink
, (LPVOID
)&sink
);
377 IPropertyNotifySink_OnChanged(sink
, dispID
);
378 IPropertyNotifySink_Release(sink
);
379 IUnknown_Release(CD
.pUnk
);
381 IEnumConnections_Release(pEnum
);
385 /************************************************************************
386 * OLEFontImpl_Construct
388 * This method will construct a new instance of the OLEFontImpl
391 * The caller of this method must release the object when it's
394 static OLEFontImpl
* OLEFontImpl_Construct(LPFONTDESC fontDesc
)
396 OLEFontImpl
* newObject
= 0;
399 * Allocate space for the object.
401 newObject
= HeapAlloc(GetProcessHeap(), 0, sizeof(OLEFontImpl
));
407 * Initialize the virtual function table.
409 newObject
->lpvtbl1
= &OLEFontImpl_VTable
;
410 newObject
->lpvtbl2
= &OLEFontImpl_IDispatch_VTable
;
411 newObject
->lpvtbl3
= &OLEFontImpl_IPersistStream_VTable
;
412 newObject
->lpvtbl4
= &OLEFontImpl_IConnectionPointContainer_VTable
;
413 newObject
->lpvtbl5
= &OLEFontImpl_IPersistPropertyBag_VTable
;
414 newObject
->lpvtbl6
= &OLEFontImpl_IPersistStreamInit_VTable
;
417 * Start with one reference count. The caller of this function
418 * must release the interface pointer when it is done.
423 * Copy the description of the font in the object.
425 assert(fontDesc
->cbSizeofstruct
>= sizeof(FONTDESC
));
427 newObject
->description
.cbSizeofstruct
= sizeof(FONTDESC
);
428 newObject
->description
.lpstrName
= HeapAlloc(GetProcessHeap(),
430 (lstrlenW(fontDesc
->lpstrName
)+1) * sizeof(WCHAR
));
431 strcpyW(newObject
->description
.lpstrName
, fontDesc
->lpstrName
);
432 newObject
->description
.cySize
= fontDesc
->cySize
;
433 newObject
->description
.sWeight
= fontDesc
->sWeight
;
434 newObject
->description
.sCharset
= fontDesc
->sCharset
;
435 newObject
->description
.fItalic
= fontDesc
->fItalic
;
436 newObject
->description
.fUnderline
= fontDesc
->fUnderline
;
437 newObject
->description
.fStrikethrough
= fontDesc
->fStrikethrough
;
440 * Initializing all the other members.
442 newObject
->gdiFont
= 0;
443 newObject
->fontLock
= 0;
444 newObject
->cyLogical
= 72L;
445 newObject
->cyHimetric
= 2540L;
446 CreateConnectionPoint((IUnknown
*)newObject
, &IID_IPropertyNotifySink
, &newObject
->pCP
);
447 TRACE("returning %p\n", newObject
);
451 /************************************************************************
452 * OLEFontImpl_Destroy
454 * This method is called by the Release method when the reference
455 * count goes down to 0. It will free all resources used by
458 static void OLEFontImpl_Destroy(OLEFontImpl
* fontDesc
)
460 TRACE("(%p)\n", fontDesc
);
462 if (fontDesc
->description
.lpstrName
!=0)
463 HeapFree(GetProcessHeap(), 0, fontDesc
->description
.lpstrName
);
465 if (fontDesc
->gdiFont
!=0)
466 DeleteObject(fontDesc
->gdiFont
);
468 HeapFree(GetProcessHeap(), 0, fontDesc
);
471 /************************************************************************
472 * OLEFontImpl_QueryInterface (IUnknown)
474 * See Windows documentation for more details on IUnknown methods.
476 HRESULT WINAPI
OLEFontImpl_QueryInterface(
481 _ICOM_THIS(OLEFontImpl
, iface
);
482 TRACE("(%p)->(%s, %p)\n", this, debugstr_guid(riid
), ppvObject
);
485 * Perform a sanity check on the parameters.
487 if ( (this==0) || (ppvObject
==0) )
491 * Initialize the return parameter.
496 * Compare the riid with the interface IDs implemented by this object.
498 if (IsEqualGUID(&IID_IUnknown
, riid
))
499 *ppvObject
= (IFont
*)this;
500 if (IsEqualGUID(&IID_IFont
, riid
))
501 *ppvObject
= (IFont
*)this;
502 if (IsEqualGUID(&IID_IDispatch
, riid
))
503 *ppvObject
= (IDispatch
*)&(this->lpvtbl2
);
504 if (IsEqualGUID(&IID_IFontDisp
, riid
))
505 *ppvObject
= (IDispatch
*)&(this->lpvtbl2
);
506 if (IsEqualGUID(&IID_IPersistStream
, riid
))
507 *ppvObject
= (IPersistStream
*)&(this->lpvtbl3
);
508 if (IsEqualGUID(&IID_IConnectionPointContainer
, riid
))
509 *ppvObject
= (IConnectionPointContainer
*)&(this->lpvtbl4
);
510 if (IsEqualGUID(&IID_IPersistPropertyBag
, riid
))
511 *ppvObject
= (IPersistPropertyBag
*)&(this->lpvtbl5
);
512 if (IsEqualGUID(&IID_IPersistStreamInit
, riid
))
513 *ppvObject
= (IPersistStreamInit
*)&(this->lpvtbl6
);
516 * Check that we obtained an interface.
520 FIXME("() : asking for unsupported interface %s\n",debugstr_guid(riid
));
521 return E_NOINTERFACE
;
523 OLEFontImpl_AddRef((IFont
*)this);
527 /************************************************************************
528 * OLEFontImpl_AddRef (IUnknown)
530 * See Windows documentation for more details on IUnknown methods.
532 ULONG WINAPI
OLEFontImpl_AddRef(
535 _ICOM_THIS(OLEFontImpl
, iface
);
536 TRACE("(%p)->(ref=%ld)\n", this, this->ref
);
542 /************************************************************************
543 * OLEFontImpl_Release (IUnknown)
545 * See Windows documentation for more details on IUnknown methods.
547 ULONG WINAPI
OLEFontImpl_Release(
550 _ICOM_THIS(OLEFontImpl
, iface
);
551 TRACE("(%p)->(ref=%ld)\n", this, this->ref
);
554 * Decrease the reference count on this object.
559 * If the reference count goes down to 0, perform suicide.
563 OLEFontImpl_Destroy(this);
571 /************************************************************************
572 * OLEFontImpl_get_Name (IFont)
574 * See Windows documentation for more details on IFont methods.
576 static HRESULT WINAPI
OLEFontImpl_get_Name(
580 _ICOM_THIS(OLEFontImpl
, iface
);
581 TRACE("(%p)->(%p)\n", this, pname
);
588 if (this->description
.lpstrName
!=0)
589 *pname
= SysAllocString(this->description
.lpstrName
);
596 /************************************************************************
597 * OLEFontImpl_put_Name (IFont)
599 * See Windows documentation for more details on IFont methods.
601 static HRESULT WINAPI
OLEFontImpl_put_Name(
605 _ICOM_THIS(OLEFontImpl
, iface
);
606 TRACE("(%p)->(%p)\n", this, name
);
608 if (this->description
.lpstrName
==0)
610 this->description
.lpstrName
= HeapAlloc(GetProcessHeap(),
612 (lstrlenW(name
)+1) * sizeof(WCHAR
));
616 this->description
.lpstrName
= HeapReAlloc(GetProcessHeap(),
618 this->description
.lpstrName
,
619 (lstrlenW(name
)+1) * sizeof(WCHAR
));
622 if (this->description
.lpstrName
==0)
623 return E_OUTOFMEMORY
;
625 strcpyW(this->description
.lpstrName
, name
);
626 TRACE("new name %s\n", debugstr_w(this->description
.lpstrName
));
627 OLEFont_SendNotify(this, DISPID_FONT_NAME
);
631 /************************************************************************
632 * OLEFontImpl_get_Size (IFont)
634 * See Windows documentation for more details on IFont methods.
636 static HRESULT WINAPI
OLEFontImpl_get_Size(
640 _ICOM_THIS(OLEFontImpl
, iface
);
641 TRACE("(%p)->(%p)\n", this, psize
);
650 psize
->s
.Lo
= this->description
.cySize
.s
.Lo
;
655 /************************************************************************
656 * OLEFontImpl_put_Size (IFont)
658 * See Windows documentation for more details on IFont methods.
660 static HRESULT WINAPI
OLEFontImpl_put_Size(
664 _ICOM_THIS(OLEFontImpl
, iface
);
665 TRACE("(%p)->(%ld)\n", this, size
.s
.Lo
);
666 this->description
.cySize
.s
.Hi
= 0;
667 this->description
.cySize
.s
.Lo
= size
.s
.Lo
;
668 OLEFont_SendNotify(this, DISPID_FONT_SIZE
);
673 /************************************************************************
674 * OLEFontImpl_get_Bold (IFont)
676 * See Windows documentation for more details on IFont methods.
678 static HRESULT WINAPI
OLEFontImpl_get_Bold(
682 _ICOM_THIS(OLEFontImpl
, iface
);
683 TRACE("(%p)->(%p)\n", this, pbold
);
690 *pbold
= this->description
.sWeight
> 550;
695 /************************************************************************
696 * OLEFontImpl_put_Bold (IFont)
698 * See Windows documentation for more details on IFont methods.
700 static HRESULT WINAPI
OLEFontImpl_put_Bold(
704 _ICOM_THIS(OLEFontImpl
, iface
);
705 TRACE("(%p)->(%d)\n", this, bold
);
706 this->description
.sWeight
= bold
? FW_BOLD
: FW_NORMAL
;
707 OLEFont_SendNotify(this, DISPID_FONT_BOLD
);
712 /************************************************************************
713 * OLEFontImpl_get_Italic (IFont)
715 * See Windows documentation for more details on IFont methods.
717 static HRESULT WINAPI
OLEFontImpl_get_Italic(
721 _ICOM_THIS(OLEFontImpl
, iface
);
722 TRACE("(%p)->(%p)\n", this, pitalic
);
729 *pitalic
= this->description
.fItalic
;
734 /************************************************************************
735 * OLEFontImpl_put_Italic (IFont)
737 * See Windows documentation for more details on IFont methods.
739 static HRESULT WINAPI
OLEFontImpl_put_Italic(
743 _ICOM_THIS(OLEFontImpl
, iface
);
744 TRACE("(%p)->(%d)\n", this, italic
);
746 this->description
.fItalic
= italic
;
748 OLEFont_SendNotify(this, DISPID_FONT_ITALIC
);
752 /************************************************************************
753 * OLEFontImpl_get_Underline (IFont)
755 * See Windows documentation for more details on IFont methods.
757 static HRESULT WINAPI
OLEFontImpl_get_Underline(
761 _ICOM_THIS(OLEFontImpl
, iface
);
762 TRACE("(%p)->(%p)\n", this, punderline
);
770 *punderline
= this->description
.fUnderline
;
775 /************************************************************************
776 * OLEFontImpl_put_Underline (IFont)
778 * See Windows documentation for more details on IFont methods.
780 static HRESULT WINAPI
OLEFontImpl_put_Underline(
784 _ICOM_THIS(OLEFontImpl
, iface
);
785 TRACE("(%p)->(%d)\n", this, underline
);
787 this->description
.fUnderline
= underline
;
789 OLEFont_SendNotify(this, DISPID_FONT_UNDER
);
793 /************************************************************************
794 * OLEFontImpl_get_Strikethrough (IFont)
796 * See Windows documentation for more details on IFont methods.
798 static HRESULT WINAPI
OLEFontImpl_get_Strikethrough(
800 BOOL
* pstrikethrough
)
802 _ICOM_THIS(OLEFontImpl
, iface
);
803 TRACE("(%p)->(%p)\n", this, pstrikethrough
);
808 if (pstrikethrough
==0)
811 *pstrikethrough
= this->description
.fStrikethrough
;
816 /************************************************************************
817 * OLEFontImpl_put_Strikethrough (IFont)
819 * See Windows documentation for more details on IFont methods.
821 static HRESULT WINAPI
OLEFontImpl_put_Strikethrough(
825 _ICOM_THIS(OLEFontImpl
, iface
);
826 TRACE("(%p)->(%d)\n", this, strikethrough
);
828 this->description
.fStrikethrough
= strikethrough
;
829 OLEFont_SendNotify(this, DISPID_FONT_STRIKE
);
834 /************************************************************************
835 * OLEFontImpl_get_Weight (IFont)
837 * See Windows documentation for more details on IFont methods.
839 static HRESULT WINAPI
OLEFontImpl_get_Weight(
843 _ICOM_THIS(OLEFontImpl
, iface
);
844 TRACE("(%p)->(%p)\n", this, pweight
);
852 *pweight
= this->description
.sWeight
;
857 /************************************************************************
858 * OLEFontImpl_put_Weight (IFont)
860 * See Windows documentation for more details on IFont methods.
862 static HRESULT WINAPI
OLEFontImpl_put_Weight(
866 _ICOM_THIS(OLEFontImpl
, iface
);
867 TRACE("(%p)->(%d)\n", this, weight
);
869 this->description
.sWeight
= weight
;
871 OLEFont_SendNotify(this, DISPID_FONT_WEIGHT
);
875 /************************************************************************
876 * OLEFontImpl_get_Charset (IFont)
878 * See Windows documentation for more details on IFont methods.
880 static HRESULT WINAPI
OLEFontImpl_get_Charset(
884 _ICOM_THIS(OLEFontImpl
, iface
);
885 TRACE("(%p)->(%p)\n", this, pcharset
);
893 *pcharset
= this->description
.sCharset
;
898 /************************************************************************
899 * OLEFontImpl_put_Charset (IFont)
901 * See Windows documentation for more details on IFont methods.
903 static HRESULT WINAPI
OLEFontImpl_put_Charset(
907 _ICOM_THIS(OLEFontImpl
, iface
);
908 TRACE("(%p)->(%d)\n", this, charset
);
910 this->description
.sCharset
= charset
;
911 OLEFont_SendNotify(this, DISPID_FONT_CHARSET
);
916 /************************************************************************
917 * OLEFontImpl_get_hFont (IFont)
919 * See Windows documentation for more details on IFont methods.
921 static HRESULT WINAPI
OLEFontImpl_get_hFont(
925 _ICOM_THIS(OLEFontImpl
, iface
);
926 TRACE("(%p)->(%p)\n", this, phfont
);
931 * Realize the font if necessary
933 if (this->gdiFont
==0)
940 * The height of the font returned by the get_Size property is the
941 * height of the font in points multiplied by 10000... Using some
942 * simple conversions and the ratio given by the application, it can
943 * be converted to a height in pixels.
945 IFont_get_Size(iface
, &cySize
);
947 fontHeight
= MulDiv( cySize
.s
.Lo
, this->cyLogical
, this->cyHimetric
);
949 memset(&logFont
, 0, sizeof(LOGFONTW
));
951 logFont
.lfHeight
= ((fontHeight
%10000L)>5000L) ? (-fontHeight
/10000L)-1 :
952 (-fontHeight
/10000L);
953 logFont
.lfItalic
= this->description
.fItalic
;
954 logFont
.lfUnderline
= this->description
.fUnderline
;
955 logFont
.lfStrikeOut
= this->description
.fStrikethrough
;
956 logFont
.lfWeight
= this->description
.sWeight
;
957 logFont
.lfCharSet
= this->description
.sCharset
;
958 logFont
.lfOutPrecision
= OUT_CHARACTER_PRECIS
;
959 logFont
.lfClipPrecision
= CLIP_DEFAULT_PRECIS
;
960 logFont
.lfQuality
= DEFAULT_QUALITY
;
961 logFont
.lfPitchAndFamily
= DEFAULT_PITCH
;
962 strcpyW(logFont
.lfFaceName
,this->description
.lpstrName
);
964 this->gdiFont
= CreateFontIndirectW(&logFont
);
967 *phfont
= this->gdiFont
;
968 TRACE("Returning %p\n", *phfont
);
972 /************************************************************************
973 * OLEFontImpl_Clone (IFont)
975 * See Windows documentation for more details on IFont methods.
977 static HRESULT WINAPI
OLEFontImpl_Clone(
981 OLEFontImpl
* newObject
= 0;
985 _ICOM_THIS(OLEFontImpl
, iface
);
986 TRACE("(%p)->(%p)\n", this, ppfont
);
994 * Allocate space for the object.
996 newObject
= HeapAlloc(GetProcessHeap(), 0, sizeof(OLEFontImpl
));
999 return E_OUTOFMEMORY
;
1003 /* We need to alloc new memory for the string, otherwise
1004 * we free memory twice.
1006 newObject
->description
.lpstrName
= HeapAlloc(
1008 (1+strlenW(this->description
.lpstrName
))*2
1010 strcpyW(newObject
->description
.lpstrName
, this->description
.lpstrName
);
1011 /* We need to clone the HFONT too. This is just cut & paste from above */
1012 IFont_get_Size(iface
, &cySize
);
1014 fontHeight
= MulDiv(cySize
.s
.Lo
, this->cyLogical
,this->cyHimetric
);
1016 memset(&logFont
, 0, sizeof(LOGFONTW
));
1018 logFont
.lfHeight
= ((fontHeight
%10000L)>5000L) ? (-fontHeight
/10000L)-1 :
1019 (-fontHeight
/10000L);
1020 logFont
.lfItalic
= this->description
.fItalic
;
1021 logFont
.lfUnderline
= this->description
.fUnderline
;
1022 logFont
.lfStrikeOut
= this->description
.fStrikethrough
;
1023 logFont
.lfWeight
= this->description
.sWeight
;
1024 logFont
.lfCharSet
= this->description
.sCharset
;
1025 logFont
.lfOutPrecision
= OUT_CHARACTER_PRECIS
;
1026 logFont
.lfClipPrecision
= CLIP_DEFAULT_PRECIS
;
1027 logFont
.lfQuality
= DEFAULT_QUALITY
;
1028 logFont
.lfPitchAndFamily
= DEFAULT_PITCH
;
1029 strcpyW(logFont
.lfFaceName
,this->description
.lpstrName
);
1031 newObject
->gdiFont
= CreateFontIndirectW(&logFont
);
1034 /* The cloned object starts with a reference count of 1 */
1037 *ppfont
= (IFont
*)newObject
;
1042 /************************************************************************
1043 * OLEFontImpl_IsEqual (IFont)
1045 * See Windows documentation for more details on IFont methods.
1047 static HRESULT WINAPI
OLEFontImpl_IsEqual(
1051 FIXME("(%p, %p), stub!\n",iface
,pFontOther
);
1055 /************************************************************************
1056 * OLEFontImpl_SetRatio (IFont)
1058 * See Windows documentation for more details on IFont methods.
1060 static HRESULT WINAPI
OLEFontImpl_SetRatio(
1065 _ICOM_THIS(OLEFontImpl
, iface
);
1066 TRACE("(%p)->(%ld, %ld)\n", this, cyLogical
, cyHimetric
);
1068 this->cyLogical
= cyLogical
;
1069 this->cyHimetric
= cyHimetric
;
1074 /************************************************************************
1075 * OLEFontImpl_QueryTextMetrics (IFont)
1077 * See Windows documentation for more details on IFont methods.
1079 static HRESULT WINAPI
OLEFontImpl_QueryTextMetrics(
1083 FIXME("(%p, %p), stub!\n",iface
,ptm
);
1087 /************************************************************************
1088 * OLEFontImpl_AddRefHfont (IFont)
1090 * See Windows documentation for more details on IFont methods.
1092 static HRESULT WINAPI
OLEFontImpl_AddRefHfont(
1096 _ICOM_THIS(OLEFontImpl
, iface
);
1097 TRACE("(%p)->(%p) (lock=%ld)\n", this, hfont
, this->fontLock
);
1099 if ( (hfont
== 0) ||
1100 (hfont
!= this->gdiFont
) )
1101 return E_INVALIDARG
;
1108 /************************************************************************
1109 * OLEFontImpl_ReleaseHfont (IFont)
1111 * See Windows documentation for more details on IFont methods.
1113 static HRESULT WINAPI
OLEFontImpl_ReleaseHfont(
1117 _ICOM_THIS(OLEFontImpl
, iface
);
1118 TRACE("(%p)->(%p) (lock=%ld)\n", this, hfont
, this->fontLock
);
1120 if ( (hfont
== 0) ||
1121 (hfont
!= this->gdiFont
) )
1122 return E_INVALIDARG
;
1127 * If we just released our last font reference, destroy it.
1129 if (this->fontLock
==0)
1131 DeleteObject(this->gdiFont
);
1138 /************************************************************************
1139 * OLEFontImpl_SetHdc (IFont)
1141 * See Windows documentation for more details on IFont methods.
1143 static HRESULT WINAPI
OLEFontImpl_SetHdc(
1147 _ICOM_THIS(OLEFontImpl
, iface
);
1148 FIXME("(%p)->(%p): Stub\n", this, hdc
);
1152 /************************************************************************
1153 * OLEFontImpl_IDispatch_QueryInterface (IUnknown)
1155 * See Windows documentation for more details on IUnknown methods.
1157 static HRESULT WINAPI
OLEFontImpl_IDispatch_QueryInterface(
1162 _ICOM_THIS_From_IDispatch(IFont
, iface
);
1164 return IFont_QueryInterface(this, riid
, ppvoid
);
1167 /************************************************************************
1168 * OLEFontImpl_IDispatch_Release (IUnknown)
1170 * See Windows documentation for more details on IUnknown methods.
1172 static ULONG WINAPI
OLEFontImpl_IDispatch_Release(
1175 _ICOM_THIS_From_IDispatch(IFont
, iface
);
1177 return IFont_Release(this);
1180 /************************************************************************
1181 * OLEFontImpl_IDispatch_AddRef (IUnknown)
1183 * See Windows documentation for more details on IUnknown methods.
1185 static ULONG WINAPI
OLEFontImpl_IDispatch_AddRef(
1188 _ICOM_THIS_From_IDispatch(IFont
, iface
);
1190 return IFont_AddRef(this);
1193 /************************************************************************
1194 * OLEFontImpl_GetTypeInfoCount (IDispatch)
1196 * See Windows documentation for more details on IDispatch methods.
1198 static HRESULT WINAPI
OLEFontImpl_GetTypeInfoCount(
1200 unsigned int* pctinfo
)
1202 _ICOM_THIS_From_IDispatch(IFont
, iface
);
1203 FIXME("(%p)->(%p): Stub\n", this, pctinfo
);
1208 /************************************************************************
1209 * OLEFontImpl_GetTypeInfo (IDispatch)
1211 * See Windows documentation for more details on IDispatch methods.
1213 static HRESULT WINAPI
OLEFontImpl_GetTypeInfo(
1217 ITypeInfo
** ppTInfo
)
1219 static const WCHAR stdole32tlb
[] = {'s','t','d','o','l','e','3','2','.','t','l','b',0};
1223 _ICOM_THIS_From_IDispatch(OLEFontImpl
, iface
);
1224 TRACE("(%p, iTInfo=%d, lcid=%04x, %p), unimplemented stub!\n", this, iTInfo
, (int)lcid
, ppTInfo
);
1227 hres
= LoadTypeLib(stdole32tlb
, &tl
);
1229 FIXME("Could not load the stdole32.tlb?\n");
1232 hres
= ITypeLib_GetTypeInfoOfGuid(tl
, &IID_IDispatch
, ppTInfo
);
1234 FIXME("Did not IDispatch typeinfo from typelib, hres %lx\n",hres
);
1239 /************************************************************************
1240 * OLEFontImpl_GetIDsOfNames (IDispatch)
1242 * See Windows documentation for more details on IDispatch methods.
1244 static HRESULT WINAPI
OLEFontImpl_GetIDsOfNames(
1247 LPOLESTR
* rgszNames
,
1252 _ICOM_THIS_From_IDispatch(IFont
, iface
);
1253 FIXME("(%p,%s,%p,%d,%04x,%p), stub!\n", this, debugstr_guid(riid
), rgszNames
,
1254 cNames
, (int)lcid
, rgDispId
1259 /************************************************************************
1260 * OLEFontImpl_Invoke (IDispatch)
1262 * See Windows documentation for more details on IDispatch methods.
1264 * Note: Do not call _put_Xxx methods, since setting things here
1265 * should not call notify functions as I found out debugging the generic
1268 static HRESULT WINAPI
OLEFontImpl_Invoke(
1270 DISPID dispIdMember
,
1274 DISPPARAMS
* pDispParams
,
1275 VARIANT
* pVarResult
,
1276 EXCEPINFO
* pExepInfo
,
1279 _ICOM_THIS_From_IDispatch(IFont
, iface
);
1280 OLEFontImpl
*xthis
= (OLEFontImpl
*)this;
1282 switch (dispIdMember
) {
1283 case DISPID_FONT_NAME
:
1285 case DISPATCH_PROPERTYGET
:
1286 case DISPATCH_PROPERTYGET
|DISPATCH_METHOD
:
1287 V_VT(pVarResult
) = VT_BSTR
;
1288 return OLEFontImpl_get_Name(this, &V_BSTR(pVarResult
));
1289 case DISPATCH_PROPERTYPUT
: {
1290 BSTR name
= V_BSTR(&pDispParams
->rgvarg
[0]);
1291 if (V_VT(&pDispParams
->rgvarg
[0])!=VT_BSTR
) {
1292 FIXME("property put of Name, vt is not VT_BSTR but %d\n",V_VT(&pDispParams
->rgvarg
[0]));
1295 if (!xthis
->description
.lpstrName
)
1296 xthis
->description
.lpstrName
= HeapAlloc(GetProcessHeap(), 0, (lstrlenW(name
)+1) * sizeof(WCHAR
));
1298 xthis
->description
.lpstrName
= HeapReAlloc(GetProcessHeap(), 0, xthis
->description
.lpstrName
, (lstrlenW(name
)+1) * sizeof(WCHAR
));
1300 if (xthis
->description
.lpstrName
==0)
1301 return E_OUTOFMEMORY
;
1302 strcpyW(xthis
->description
.lpstrName
, name
);
1307 case DISPID_FONT_BOLD
:
1309 case DISPATCH_PROPERTYGET
:
1310 case DISPATCH_PROPERTYGET
|DISPATCH_METHOD
:
1311 V_VT(pVarResult
) = VT_BOOL
;
1312 return OLEFontImpl_get_Bold(this, (BOOL
*)&V_BOOL(pVarResult
));
1313 case DISPATCH_PROPERTYPUT
:
1314 if (V_VT(&pDispParams
->rgvarg
[0]) != VT_BOOL
) {
1315 FIXME("DISPID_FONT_BOLD/put, vt is %d, not VT_BOOL.\n",V_VT(&pDispParams
->rgvarg
[0]));
1318 xthis
->description
.sWeight
= V_BOOL(&pDispParams
->rgvarg
[0]) ? FW_BOLD
: FW_NORMAL
;
1323 case DISPID_FONT_ITALIC
:
1325 case DISPATCH_PROPERTYGET
:
1326 case DISPATCH_PROPERTYGET
|DISPATCH_METHOD
:
1327 V_VT(pVarResult
) = VT_BOOL
;
1328 return OLEFontImpl_get_Italic(this, (BOOL
*)&V_BOOL(pVarResult
));
1329 case DISPATCH_PROPERTYPUT
:
1330 if (V_VT(&pDispParams
->rgvarg
[0]) != VT_BOOL
) {
1331 FIXME("DISPID_FONT_ITALIC/put, vt is %d, not VT_BOOL.\n",V_VT(&pDispParams
->rgvarg
[0]));
1334 xthis
->description
.fItalic
= V_BOOL(&pDispParams
->rgvarg
[0]);
1339 case DISPID_FONT_UNDER
:
1341 case DISPATCH_PROPERTYGET
:
1342 case DISPATCH_PROPERTYGET
|DISPATCH_METHOD
:
1343 V_VT(pVarResult
) = VT_BOOL
;
1344 return OLEFontImpl_get_Underline(this, (BOOL
*)&V_BOOL(pVarResult
));
1345 case DISPATCH_PROPERTYPUT
:
1346 if (V_VT(&pDispParams
->rgvarg
[0]) != VT_BOOL
) {
1347 FIXME("DISPID_FONT_UNDER/put, vt is %d, not VT_BOOL.\n",V_VT(&pDispParams
->rgvarg
[0]));
1350 xthis
->description
.fUnderline
= V_BOOL(&pDispParams
->rgvarg
[0]);
1355 case DISPID_FONT_STRIKE
:
1357 case DISPATCH_PROPERTYGET
:
1358 case DISPATCH_PROPERTYGET
|DISPATCH_METHOD
:
1359 V_VT(pVarResult
) = VT_BOOL
;
1360 return OLEFontImpl_get_Strikethrough(this, (BOOL
*)&V_BOOL(pVarResult
));
1361 case DISPATCH_PROPERTYPUT
:
1362 if (V_VT(&pDispParams
->rgvarg
[0]) != VT_BOOL
) {
1363 FIXME("DISPID_FONT_STRIKE/put, vt is %d, not VT_BOOL.\n",V_VT(&pDispParams
->rgvarg
[0]));
1366 xthis
->description
.fStrikethrough
= V_BOOL(&pDispParams
->rgvarg
[0]);
1371 case DISPID_FONT_SIZE
:
1373 case DISPATCH_PROPERTYPUT
: {
1374 assert (pDispParams
->cArgs
== 1);
1375 xthis
->description
.cySize
.s
.Hi
= 0;
1376 if (V_VT(&pDispParams
->rgvarg
[0]) != VT_CY
) {
1377 if (V_VT(&pDispParams
->rgvarg
[0]) == VT_I2
) {
1378 xthis
->description
.cySize
.s
.Lo
= V_I2(&pDispParams
->rgvarg
[0]) * 10000;
1380 FIXME("property put for Size with vt %d unsupported!\n",V_VT(&pDispParams
->rgvarg
[0]));
1383 xthis
->description
.cySize
.s
.Lo
= V_CY(&pDispParams
->rgvarg
[0]).s
.Lo
;
1387 case DISPATCH_PROPERTYGET
:
1388 case DISPATCH_PROPERTYGET
|DISPATCH_METHOD
:
1389 V_VT(pVarResult
) = VT_CY
;
1390 return OLEFontImpl_get_Size(this, &V_CY(pVarResult
));
1393 case DISPID_FONT_CHARSET
:
1395 case DISPATCH_PROPERTYPUT
:
1396 assert (pDispParams
->cArgs
== 1);
1397 if (V_VT(&pDispParams
->rgvarg
[0]) != VT_I2
)
1398 FIXME("varg of first disparg is not VT_I2, but %d\n",V_VT(&pDispParams
->rgvarg
[0]));
1399 xthis
->description
.sCharset
= V_I2(&pDispParams
->rgvarg
[0]);
1401 case DISPATCH_PROPERTYGET
:
1402 case DISPATCH_PROPERTYGET
|DISPATCH_METHOD
:
1403 V_VT(pVarResult
) = VT_I2
;
1404 return OLEFontImpl_get_Charset(this, &V_I2(pVarResult
));
1408 FIXME("%p->(%ld,%s,%lx,%x,%p,%p,%p,%p), unhandled dispid/flag!\n",
1409 this,dispIdMember
,debugstr_guid(riid
),lcid
,
1410 wFlags
,pDispParams
,pVarResult
,pExepInfo
,puArgErr
1415 /************************************************************************
1416 * OLEFontImpl_IPersistStream_QueryInterface (IUnknown)
1418 * See Windows documentation for more details on IUnknown methods.
1420 static HRESULT WINAPI
OLEFontImpl_IPersistStream_QueryInterface(
1421 IPersistStream
* iface
,
1425 _ICOM_THIS_From_IPersistStream(IFont
, iface
);
1427 return IFont_QueryInterface(this, riid
, ppvoid
);
1430 /************************************************************************
1431 * OLEFontImpl_IPersistStream_Release (IUnknown)
1433 * See Windows documentation for more details on IUnknown methods.
1435 static ULONG WINAPI
OLEFontImpl_IPersistStream_Release(
1436 IPersistStream
* iface
)
1438 _ICOM_THIS_From_IPersistStream(IFont
, iface
);
1440 return IFont_Release(this);
1443 /************************************************************************
1444 * OLEFontImpl_IPersistStream_AddRef (IUnknown)
1446 * See Windows documentation for more details on IUnknown methods.
1448 static ULONG WINAPI
OLEFontImpl_IPersistStream_AddRef(
1449 IPersistStream
* iface
)
1451 _ICOM_THIS_From_IPersistStream(IFont
, iface
);
1453 return IFont_AddRef(this);
1456 /************************************************************************
1457 * OLEFontImpl_GetClassID (IPersistStream)
1459 * See Windows documentation for more details on IPersistStream methods.
1461 static HRESULT WINAPI
OLEFontImpl_GetClassID(
1462 IPersistStream
* iface
,
1465 TRACE("(%p,%p)\n",iface
,pClassID
);
1469 memcpy(pClassID
, &CLSID_StdFont
, sizeof(CLSID_StdFont
));
1474 /************************************************************************
1475 * OLEFontImpl_IsDirty (IPersistStream)
1477 * See Windows documentation for more details on IPersistStream methods.
1479 static HRESULT WINAPI
OLEFontImpl_IsDirty(
1480 IPersistStream
* iface
)
1482 TRACE("(%p)\n",iface
);
1486 /************************************************************************
1487 * OLEFontImpl_Load (IPersistStream)
1489 * See Windows documentation for more details on IPersistStream methods.
1491 * This is the format of the standard font serialization as far as I
1494 * Offset Type Value Comment
1495 * 0x0000 Byte Unknown Probably a version number, contains 0x01
1496 * 0x0001 Short Charset Charset value from the FONTDESC structure
1497 * 0x0003 Byte Attributes Flags defined as follows:
1499 * 00000100 - Underline
1500 * 00001000 - Strikethrough
1501 * 0x0004 Short Weight Weight value from FONTDESC structure
1502 * 0x0006 DWORD size "Low" portion of the cySize member of the FONTDESC
1504 * 0x000A Byte name length Length of the font name string (no null character)
1505 * 0x000B String name Name of the font (ASCII, no nul character)
1507 static HRESULT WINAPI
OLEFontImpl_Load(
1508 IPersistStream
* iface
,
1509 IStream
* pLoadStream
)
1511 char readBuffer
[0x100];
1518 _ICOM_THIS_From_IPersistStream(OLEFontImpl
, iface
);
1521 * Read the version byte
1523 IStream_Read(pLoadStream
, &bVersion
, 1, &cbRead
);
1532 IStream_Read(pLoadStream
, &this->description
.sCharset
, 2, &cbRead
);
1540 IStream_Read(pLoadStream
, &bAttributes
, 1, &cbRead
);
1545 this->description
.fItalic
= (bAttributes
& FONTPERSIST_ITALIC
) != 0;
1546 this->description
.fStrikethrough
= (bAttributes
& FONTPERSIST_STRIKETHROUGH
) != 0;
1547 this->description
.fUnderline
= (bAttributes
& FONTPERSIST_UNDERLINE
) != 0;
1552 IStream_Read(pLoadStream
, &this->description
.sWeight
, 2, &cbRead
);
1560 IStream_Read(pLoadStream
, &this->description
.cySize
.s
.Lo
, 4, &cbRead
);
1565 this->description
.cySize
.s
.Hi
= 0;
1570 IStream_Read(pLoadStream
, &bStringSize
, 1, &cbRead
);
1575 IStream_Read(pLoadStream
, readBuffer
, bStringSize
, &cbRead
);
1577 if (cbRead
!=bStringSize
)
1580 if (this->description
.lpstrName
!=0)
1581 HeapFree(GetProcessHeap(), 0, this->description
.lpstrName
);
1583 len
= MultiByteToWideChar( CP_ACP
, 0, readBuffer
, bStringSize
, NULL
, 0 );
1584 this->description
.lpstrName
= HeapAlloc( GetProcessHeap(), 0, (len
+1) * sizeof(WCHAR
) );
1585 MultiByteToWideChar( CP_ACP
, 0, readBuffer
, bStringSize
, this->description
.lpstrName
, len
);
1586 this->description
.lpstrName
[len
] = 0;
1588 /* Ensure use of this font causes a new one to be created @@@@ */
1589 DeleteObject(this->gdiFont
);
1595 /************************************************************************
1596 * OLEFontImpl_Save (IPersistStream)
1598 * See Windows documentation for more details on IPersistStream methods.
1600 static HRESULT WINAPI
OLEFontImpl_Save(
1601 IPersistStream
* iface
,
1602 IStream
* pOutStream
,
1605 char* writeBuffer
= NULL
;
1607 BYTE bVersion
= 0x01;
1611 _ICOM_THIS_From_IPersistStream(OLEFontImpl
, iface
);
1614 * Read the version byte
1616 IStream_Write(pOutStream
, &bVersion
, 1, &cbWritten
);
1624 IStream_Write(pOutStream
, &this->description
.sCharset
, 2, &cbWritten
);
1634 if (this->description
.fItalic
)
1635 bAttributes
|= FONTPERSIST_ITALIC
;
1637 if (this->description
.fStrikethrough
)
1638 bAttributes
|= FONTPERSIST_STRIKETHROUGH
;
1640 if (this->description
.fUnderline
)
1641 bAttributes
|= FONTPERSIST_UNDERLINE
;
1643 IStream_Write(pOutStream
, &bAttributes
, 1, &cbWritten
);
1651 IStream_Write(pOutStream
, &this->description
.sWeight
, 2, &cbWritten
);
1659 IStream_Write(pOutStream
, &this->description
.cySize
.s
.Lo
, 4, &cbWritten
);
1667 if (this->description
.lpstrName
!=0)
1668 bStringSize
= WideCharToMultiByte( CP_ACP
, 0, this->description
.lpstrName
,
1669 strlenW(this->description
.lpstrName
), NULL
, 0, NULL
, NULL
);
1673 IStream_Write(pOutStream
, &bStringSize
, 1, &cbWritten
);
1680 if (!(writeBuffer
= HeapAlloc( GetProcessHeap(), 0, bStringSize
))) return E_OUTOFMEMORY
;
1681 WideCharToMultiByte( CP_ACP
, 0, this->description
.lpstrName
,
1682 strlenW(this->description
.lpstrName
),
1683 writeBuffer
, bStringSize
, NULL
, NULL
);
1685 IStream_Write(pOutStream
, writeBuffer
, bStringSize
, &cbWritten
);
1686 HeapFree(GetProcessHeap(), 0, writeBuffer
);
1688 if (cbWritten
!=bStringSize
)
1695 /************************************************************************
1696 * OLEFontImpl_GetSizeMax (IPersistStream)
1698 * See Windows documentation for more details on IPersistStream methods.
1700 static HRESULT WINAPI
OLEFontImpl_GetSizeMax(
1701 IPersistStream
* iface
,
1702 ULARGE_INTEGER
* pcbSize
)
1704 _ICOM_THIS_From_IPersistStream(OLEFontImpl
, iface
);
1709 pcbSize
->u
.HighPart
= 0;
1710 pcbSize
->u
.LowPart
= 0;
1712 pcbSize
->u
.LowPart
+= sizeof(BYTE
); /* Version */
1713 pcbSize
->u
.LowPart
+= sizeof(WORD
); /* Lang code */
1714 pcbSize
->u
.LowPart
+= sizeof(BYTE
); /* Flags */
1715 pcbSize
->u
.LowPart
+= sizeof(WORD
); /* Weight */
1716 pcbSize
->u
.LowPart
+= sizeof(DWORD
); /* Size */
1717 pcbSize
->u
.LowPart
+= sizeof(BYTE
); /* StrLength */
1719 if (this->description
.lpstrName
!=0)
1720 pcbSize
->u
.LowPart
+= lstrlenW(this->description
.lpstrName
);
1725 /************************************************************************
1726 * OLEFontImpl_IConnectionPointContainer_QueryInterface (IUnknown)
1728 * See Windows documentation for more details on IUnknown methods.
1730 static HRESULT WINAPI
OLEFontImpl_IConnectionPointContainer_QueryInterface(
1731 IConnectionPointContainer
* iface
,
1735 _ICOM_THIS_From_IConnectionPointContainer(OLEFontImpl
, iface
);
1737 return IFont_QueryInterface((IFont
*)this, riid
, ppvoid
);
1740 /************************************************************************
1741 * OLEFontImpl_IConnectionPointContainer_Release (IUnknown)
1743 * See Windows documentation for more details on IUnknown methods.
1745 static ULONG WINAPI
OLEFontImpl_IConnectionPointContainer_Release(
1746 IConnectionPointContainer
* iface
)
1748 _ICOM_THIS_From_IConnectionPointContainer(OLEFontImpl
, iface
);
1750 return IFont_Release((IFont
*)this);
1753 /************************************************************************
1754 * OLEFontImpl_IConnectionPointContainer_AddRef (IUnknown)
1756 * See Windows documentation for more details on IUnknown methods.
1758 static ULONG WINAPI
OLEFontImpl_IConnectionPointContainer_AddRef(
1759 IConnectionPointContainer
* iface
)
1761 _ICOM_THIS_From_IConnectionPointContainer(OLEFontImpl
, iface
);
1763 return IFont_AddRef((IFont
*)this);
1766 /************************************************************************
1767 * OLEFontImpl_EnumConnectionPoints (IConnectionPointContainer)
1769 * See Windows documentation for more details on IConnectionPointContainer
1772 static HRESULT WINAPI
OLEFontImpl_EnumConnectionPoints(
1773 IConnectionPointContainer
* iface
,
1774 IEnumConnectionPoints
**ppEnum
)
1776 _ICOM_THIS_From_IConnectionPointContainer(OLEFontImpl
, iface
);
1778 FIXME("(%p)->(%p): stub\n", this, ppEnum
);
1782 /************************************************************************
1783 * OLEFontImpl_FindConnectionPoint (IConnectionPointContainer)
1785 * See Windows documentation for more details on IConnectionPointContainer
1788 static HRESULT WINAPI
OLEFontImpl_FindConnectionPoint(
1789 IConnectionPointContainer
* iface
,
1791 IConnectionPoint
**ppCp
)
1793 _ICOM_THIS_From_IConnectionPointContainer(OLEFontImpl
, iface
);
1794 TRACE("(%p)->(%s, %p): stub\n", this, debugstr_guid(riid
), ppCp
);
1796 if(memcmp(riid
, &IID_IPropertyNotifySink
, sizeof(IID_IPropertyNotifySink
)) == 0) {
1797 return IConnectionPoint_QueryInterface(this->pCP
, &IID_IConnectionPoint
,
1800 FIXME("Tried to find connection point on %s\n", debugstr_guid(riid
));
1801 return E_NOINTERFACE
;
1805 /************************************************************************
1806 * OLEFontImpl implementation of IPersistPropertyBag.
1808 static HRESULT WINAPI
OLEFontImpl_IPersistPropertyBag_QueryInterface(
1809 IPersistPropertyBag
*iface
, REFIID riid
, LPVOID
*ppvObj
1811 _ICOM_THIS_From_IPersistPropertyBag(IFont
, iface
);
1812 return IFont_QueryInterface(this,riid
,ppvObj
);
1815 static ULONG WINAPI
OLEFontImpl_IPersistPropertyBag_AddRef(
1816 IPersistPropertyBag
*iface
1818 _ICOM_THIS_From_IPersistPropertyBag(IFont
, iface
);
1819 return IFont_AddRef(this);
1822 static ULONG WINAPI
OLEFontImpl_IPersistPropertyBag_Release(
1823 IPersistPropertyBag
*iface
1825 _ICOM_THIS_From_IPersistPropertyBag(IFont
, iface
);
1826 return IFont_Release(this);
1829 static HRESULT WINAPI
OLEFontImpl_IPersistPropertyBag_GetClassID(
1830 IPersistPropertyBag
*iface
, CLSID
*classid
1832 FIXME("(%p,%p), stub!\n", iface
, classid
);
1836 static HRESULT WINAPI
OLEFontImpl_IPersistPropertyBag_InitNew(
1837 IPersistPropertyBag
*iface
1839 FIXME("(%p), stub!\n", iface
);
1843 static HRESULT WINAPI
OLEFontImpl_IPersistPropertyBag_Load(
1844 IPersistPropertyBag
*iface
, IPropertyBag
* pPropBag
, IErrorLog
* pErrorLog
1846 /* (from Visual Basic 6 property bag)
1847 Name = "MS Sans Serif"
1851 Underline = 0 'False
1853 Strikethrough = 0 'False
1855 static const WCHAR sAttrName
[] = {'N','a','m','e',0};
1856 static const WCHAR sAttrSize
[] = {'S','i','z','e',0};
1857 static const WCHAR sAttrCharset
[] = {'C','h','a','r','s','e','t',0};
1858 static const WCHAR sAttrWeight
[] = {'W','e','i','g','h','t',0};
1859 static const WCHAR sAttrUnderline
[] = {'U','n','d','e','r','l','i','n','e',0};
1860 static const WCHAR sAttrItalic
[] = {'I','t','a','l','i','c',0};
1861 static const WCHAR sAttrStrikethrough
[] = {'S','t','r','i','k','e','t','h','r','o','u','g','h',0};
1864 HRESULT iRes
= S_OK
;
1865 _ICOM_THIS_From_IPersistPropertyBag(IFont
, iface
);
1867 VariantInit(&rawAttr
);
1868 VariantInit(&valueAttr
);
1871 iRes
= IPropertyBag_Read(pPropBag
, sAttrName
, &rawAttr
, pErrorLog
);
1874 iRes
= VariantChangeType(&rawAttr
, &valueAttr
, 0, VT_BSTR
);
1876 iRes
= IFont_put_Name(this, V_BSTR(&valueAttr
));
1878 else if (iRes
== E_INVALIDARG
)
1880 VariantClear(&rawAttr
);
1881 VariantClear(&valueAttr
);
1885 iRes
= IPropertyBag_Read(pPropBag
, sAttrSize
, &rawAttr
, pErrorLog
);
1888 iRes
= VariantChangeType(&rawAttr
, &valueAttr
, 0, VT_CY
);
1890 iRes
= IFont_put_Size(this, V_CY(&valueAttr
));
1892 else if (iRes
== E_INVALIDARG
)
1894 VariantClear(&rawAttr
);
1895 VariantClear(&valueAttr
);
1899 iRes
= IPropertyBag_Read(pPropBag
, sAttrCharset
, &rawAttr
, pErrorLog
);
1902 iRes
= VariantChangeType(&rawAttr
, &valueAttr
, 0, VT_I2
);
1904 iRes
= IFont_put_Charset(this, V_I2(&valueAttr
));
1906 else if (iRes
== E_INVALIDARG
)
1908 VariantClear(&rawAttr
);
1909 VariantClear(&valueAttr
);
1913 iRes
= IPropertyBag_Read(pPropBag
, sAttrWeight
, &rawAttr
, pErrorLog
);
1916 iRes
= VariantChangeType(&rawAttr
, &valueAttr
, 0, VT_I2
);
1918 iRes
= IFont_put_Weight(this, V_I2(&valueAttr
));
1920 else if (iRes
== E_INVALIDARG
)
1922 VariantClear(&rawAttr
);
1923 VariantClear(&valueAttr
);
1928 iRes
= IPropertyBag_Read(pPropBag
, sAttrUnderline
, &rawAttr
, pErrorLog
);
1931 iRes
= VariantChangeType(&rawAttr
, &valueAttr
, 0, VT_BOOL
);
1933 iRes
= IFont_put_Underline(this, V_BOOL(&valueAttr
));
1935 else if (iRes
== E_INVALIDARG
)
1937 VariantClear(&rawAttr
);
1938 VariantClear(&valueAttr
);
1942 iRes
= IPropertyBag_Read(pPropBag
, sAttrItalic
, &rawAttr
, pErrorLog
);
1945 iRes
= VariantChangeType(&rawAttr
, &valueAttr
, 0, VT_BOOL
);
1947 iRes
= IFont_put_Italic(this, V_BOOL(&valueAttr
));
1949 else if (iRes
== E_INVALIDARG
)
1951 VariantClear(&rawAttr
);
1952 VariantClear(&valueAttr
);
1956 iRes
= IPropertyBag_Read(pPropBag
, sAttrStrikethrough
, &rawAttr
, pErrorLog
);
1959 iRes
= VariantChangeType(&rawAttr
, &valueAttr
, 0, VT_BOOL
);
1961 IFont_put_Strikethrough(this, V_BOOL(&valueAttr
));
1963 else if (iRes
== E_INVALIDARG
)
1965 VariantClear(&rawAttr
);
1966 VariantClear(&valueAttr
);
1970 WARN("-- 0x%08lx\n", iRes
);
1974 static HRESULT WINAPI
OLEFontImpl_IPersistPropertyBag_Save(
1975 IPersistPropertyBag
*iface
, IPropertyBag
* pPropBag
, BOOL fClearDirty
,
1976 BOOL fSaveAllProperties
1978 FIXME("(%p,%p,%d,%d), stub!\n", iface
, pPropBag
, fClearDirty
, fSaveAllProperties
);
1982 static IPersistPropertyBagVtbl OLEFontImpl_IPersistPropertyBag_VTable
=
1984 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
1985 OLEFontImpl_IPersistPropertyBag_QueryInterface
,
1986 OLEFontImpl_IPersistPropertyBag_AddRef
,
1987 OLEFontImpl_IPersistPropertyBag_Release
,
1989 OLEFontImpl_IPersistPropertyBag_GetClassID
,
1990 OLEFontImpl_IPersistPropertyBag_InitNew
,
1991 OLEFontImpl_IPersistPropertyBag_Load
,
1992 OLEFontImpl_IPersistPropertyBag_Save
1995 /************************************************************************
1996 * OLEFontImpl implementation of IPersistStreamInit.
1998 static HRESULT WINAPI
OLEFontImpl_IPersistStreamInit_QueryInterface(
1999 IPersistStreamInit
*iface
, REFIID riid
, LPVOID
*ppvObj
2001 _ICOM_THIS_From_IPersistStreamInit(IFont
, iface
);
2002 return IFont_QueryInterface(this,riid
,ppvObj
);
2005 static ULONG WINAPI
OLEFontImpl_IPersistStreamInit_AddRef(
2006 IPersistStreamInit
*iface
2008 _ICOM_THIS_From_IPersistStreamInit(IFont
, iface
);
2009 return IFont_AddRef(this);
2012 static ULONG WINAPI
OLEFontImpl_IPersistStreamInit_Release(
2013 IPersistStreamInit
*iface
2015 _ICOM_THIS_From_IPersistStreamInit(IFont
, iface
);
2016 return IFont_Release(this);
2019 static HRESULT WINAPI
OLEFontImpl_IPersistStreamInit_GetClassID(
2020 IPersistStreamInit
*iface
, CLSID
*classid
2022 FIXME("(%p,%p), stub!\n", iface
, classid
);
2026 static HRESULT WINAPI
OLEFontImpl_IPersistStreamInit_IsDirty(
2027 IPersistStreamInit
*iface
2029 FIXME("(%p), stub!\n", iface
);
2033 static HRESULT WINAPI
OLEFontImpl_IPersistStreamInit_Load(
2034 IPersistStreamInit
*iface
, LPSTREAM pStm
2036 FIXME("(%p,%p), stub!\n", iface
, pStm
);
2040 static HRESULT WINAPI
OLEFontImpl_IPersistStreamInit_Save(
2041 IPersistStreamInit
*iface
, LPSTREAM pStm
, BOOL fClearDirty
2043 FIXME("(%p,%p,%d), stub!\n", iface
, pStm
, fClearDirty
);
2047 static HRESULT WINAPI
OLEFontImpl_IPersistStreamInit_GetSizeMax(
2048 IPersistStreamInit
*iface
, ULARGE_INTEGER
*pcbSize
2050 FIXME("(%p,%p), stub!\n", iface
, pcbSize
);
2054 static HRESULT WINAPI
OLEFontImpl_IPersistStreamInit_InitNew(
2055 IPersistStreamInit
*iface
2057 FIXME("(%p), stub!\n", iface
);
2061 static IPersistStreamInitVtbl OLEFontImpl_IPersistStreamInit_VTable
=
2063 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
2064 OLEFontImpl_IPersistStreamInit_QueryInterface
,
2065 OLEFontImpl_IPersistStreamInit_AddRef
,
2066 OLEFontImpl_IPersistStreamInit_Release
,
2068 OLEFontImpl_IPersistStreamInit_GetClassID
,
2069 OLEFontImpl_IPersistStreamInit_IsDirty
,
2070 OLEFontImpl_IPersistStreamInit_Load
,
2071 OLEFontImpl_IPersistStreamInit_Save
,
2072 OLEFontImpl_IPersistStreamInit_GetSizeMax
,
2073 OLEFontImpl_IPersistStreamInit_InitNew
2076 /*******************************************************************************
2077 * StdFont ClassFactory
2081 /* IUnknown fields */
2082 IClassFactoryVtbl
*lpVtbl
;
2084 } IClassFactoryImpl
;
2086 static HRESULT WINAPI
2087 SFCF_QueryInterface(LPCLASSFACTORY iface
,REFIID riid
,LPVOID
*ppobj
) {
2088 ICOM_THIS(IClassFactoryImpl
,iface
);
2090 FIXME("(%p)->(%s,%p),stub!\n",This
,debugstr_guid(riid
),ppobj
);
2091 return E_NOINTERFACE
;
2095 SFCF_AddRef(LPCLASSFACTORY iface
) {
2096 ICOM_THIS(IClassFactoryImpl
,iface
);
2097 return ++(This
->ref
);
2100 static ULONG WINAPI
SFCF_Release(LPCLASSFACTORY iface
) {
2101 ICOM_THIS(IClassFactoryImpl
,iface
);
2102 /* static class, won't be freed */
2103 return --(This
->ref
);
2106 static HRESULT WINAPI
SFCF_CreateInstance(
2107 LPCLASSFACTORY iface
,LPUNKNOWN pOuter
,REFIID riid
,LPVOID
*ppobj
2109 return OleCreateFontIndirect(NULL
,riid
,ppobj
);
2113 static HRESULT WINAPI
SFCF_LockServer(LPCLASSFACTORY iface
,BOOL dolock
) {
2114 ICOM_THIS(IClassFactoryImpl
,iface
);
2115 FIXME("(%p)->(%d),stub!\n",This
,dolock
);
2119 static IClassFactoryVtbl SFCF_Vtbl
= {
2120 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
2121 SFCF_QueryInterface
,
2124 SFCF_CreateInstance
,
2127 static IClassFactoryImpl STDFONT_CF
= {&SFCF_Vtbl
, 1 };
2129 void _get_STDFONT_CF(LPVOID
*ppv
) { *ppv
= (LPVOID
)&STDFONT_CF
; }