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_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 if (fontDesc
->description
.lpstrName
!=0)
458 HeapFree(GetProcessHeap(), 0, fontDesc
->description
.lpstrName
);
460 if (fontDesc
->gdiFont
!=0)
461 DeleteObject(fontDesc
->gdiFont
);
463 HeapFree(GetProcessHeap(), 0, fontDesc
);
466 /************************************************************************
467 * OLEFontImpl_QueryInterface (IUnknown)
469 * See Windows documentation for more details on IUnknown methods.
471 HRESULT WINAPI
OLEFontImpl_QueryInterface(
476 OLEFontImpl
*this = (OLEFontImpl
*)iface
;
477 TRACE("(%p)->(%s, %p)\n", this, debugstr_guid(riid
), ppvObject
);
480 * Perform a sanity check on the parameters.
482 if ( (this==0) || (ppvObject
==0) )
486 * Initialize the return parameter.
491 * Compare the riid with the interface IDs implemented by this object.
493 if (IsEqualGUID(&IID_IUnknown
, riid
))
494 *ppvObject
= (IFont
*)this;
495 if (IsEqualGUID(&IID_IFont
, riid
))
496 *ppvObject
= (IFont
*)this;
497 if (IsEqualGUID(&IID_IDispatch
, riid
))
498 *ppvObject
= (IDispatch
*)&(this->lpvtbl2
);
499 if (IsEqualGUID(&IID_IFontDisp
, riid
))
500 *ppvObject
= (IDispatch
*)&(this->lpvtbl2
);
501 if (IsEqualGUID(&IID_IPersistStream
, riid
))
502 *ppvObject
= (IPersistStream
*)&(this->lpvtbl3
);
503 if (IsEqualGUID(&IID_IConnectionPointContainer
, riid
))
504 *ppvObject
= (IConnectionPointContainer
*)&(this->lpvtbl4
);
505 if (IsEqualGUID(&IID_IPersistPropertyBag
, riid
))
506 *ppvObject
= (IPersistPropertyBag
*)&(this->lpvtbl5
);
507 if (IsEqualGUID(&IID_IPersistStreamInit
, riid
))
508 *ppvObject
= (IPersistStreamInit
*)&(this->lpvtbl6
);
511 * Check that we obtained an interface.
515 FIXME("() : asking for unsupported interface %s\n",debugstr_guid(riid
));
516 return E_NOINTERFACE
;
518 OLEFontImpl_AddRef((IFont
*)this);
522 /************************************************************************
523 * OLEFontImpl_AddRef (IUnknown)
525 * See Windows documentation for more details on IUnknown methods.
527 ULONG WINAPI
OLEFontImpl_AddRef(
530 OLEFontImpl
*this = (OLEFontImpl
*)iface
;
531 TRACE("(%p)->(ref=%ld)\n", this, this->ref
);
537 /************************************************************************
538 * OLEFontImpl_Release (IUnknown)
540 * See Windows documentation for more details on IUnknown methods.
542 ULONG WINAPI
OLEFontImpl_Release(
545 OLEFontImpl
*this = (OLEFontImpl
*)iface
;
546 TRACE("(%p)->(ref=%ld)\n", this, this->ref
);
549 * Decrease the reference count on this object.
554 * If the reference count goes down to 0, perform suicide.
558 OLEFontImpl_Destroy(this);
566 /************************************************************************
567 * OLEFontImpl_get_Name (IFont)
569 * See Windows documentation for more details on IFont methods.
571 static HRESULT WINAPI
OLEFontImpl_get_Name(
575 OLEFontImpl
*this = (OLEFontImpl
*)iface
;
576 TRACE("(%p)->(%p)\n", this, pname
);
583 if (this->description
.lpstrName
!=0)
584 *pname
= SysAllocString(this->description
.lpstrName
);
591 /************************************************************************
592 * OLEFontImpl_put_Name (IFont)
594 * See Windows documentation for more details on IFont methods.
596 static HRESULT WINAPI
OLEFontImpl_put_Name(
600 OLEFontImpl
*this = (OLEFontImpl
*)iface
;
601 TRACE("(%p)->(%p)\n", this, name
);
603 if (this->description
.lpstrName
==0)
605 this->description
.lpstrName
= HeapAlloc(GetProcessHeap(),
607 (lstrlenW(name
)+1) * sizeof(WCHAR
));
611 this->description
.lpstrName
= HeapReAlloc(GetProcessHeap(),
613 this->description
.lpstrName
,
614 (lstrlenW(name
)+1) * sizeof(WCHAR
));
617 if (this->description
.lpstrName
==0)
618 return E_OUTOFMEMORY
;
620 strcpyW(this->description
.lpstrName
, name
);
621 TRACE("new name %s\n", debugstr_w(this->description
.lpstrName
));
622 OLEFont_SendNotify(this, DISPID_FONT_NAME
);
626 /************************************************************************
627 * OLEFontImpl_get_Size (IFont)
629 * See Windows documentation for more details on IFont methods.
631 static HRESULT WINAPI
OLEFontImpl_get_Size(
635 OLEFontImpl
*this = (OLEFontImpl
*)iface
;
636 TRACE("(%p)->(%p)\n", this, psize
);
645 psize
->s
.Lo
= this->description
.cySize
.s
.Lo
;
650 /************************************************************************
651 * OLEFontImpl_put_Size (IFont)
653 * See Windows documentation for more details on IFont methods.
655 static HRESULT WINAPI
OLEFontImpl_put_Size(
659 OLEFontImpl
*this = (OLEFontImpl
*)iface
;
660 TRACE("(%p)->(%ld)\n", this, size
.s
.Lo
);
661 this->description
.cySize
.s
.Hi
= 0;
662 this->description
.cySize
.s
.Lo
= size
.s
.Lo
;
663 OLEFont_SendNotify(this, DISPID_FONT_SIZE
);
668 /************************************************************************
669 * OLEFontImpl_get_Bold (IFont)
671 * See Windows documentation for more details on IFont methods.
673 static HRESULT WINAPI
OLEFontImpl_get_Bold(
677 OLEFontImpl
*this = (OLEFontImpl
*)iface
;
678 TRACE("(%p)->(%p)\n", this, pbold
);
685 *pbold
= this->description
.sWeight
> 550;
690 /************************************************************************
691 * OLEFontImpl_put_Bold (IFont)
693 * See Windows documentation for more details on IFont methods.
695 static HRESULT WINAPI
OLEFontImpl_put_Bold(
699 OLEFontImpl
*this = (OLEFontImpl
*)iface
;
700 TRACE("(%p)->(%d)\n", this, bold
);
701 this->description
.sWeight
= bold
? FW_BOLD
: FW_NORMAL
;
702 OLEFont_SendNotify(this, DISPID_FONT_BOLD
);
707 /************************************************************************
708 * OLEFontImpl_get_Italic (IFont)
710 * See Windows documentation for more details on IFont methods.
712 static HRESULT WINAPI
OLEFontImpl_get_Italic(
716 OLEFontImpl
*this = (OLEFontImpl
*)iface
;
717 TRACE("(%p)->(%p)\n", this, pitalic
);
724 *pitalic
= this->description
.fItalic
;
729 /************************************************************************
730 * OLEFontImpl_put_Italic (IFont)
732 * See Windows documentation for more details on IFont methods.
734 static HRESULT WINAPI
OLEFontImpl_put_Italic(
738 OLEFontImpl
*this = (OLEFontImpl
*)iface
;
739 TRACE("(%p)->(%d)\n", this, italic
);
741 this->description
.fItalic
= italic
;
743 OLEFont_SendNotify(this, DISPID_FONT_ITALIC
);
747 /************************************************************************
748 * OLEFontImpl_get_Underline (IFont)
750 * See Windows documentation for more details on IFont methods.
752 static HRESULT WINAPI
OLEFontImpl_get_Underline(
756 OLEFontImpl
*this = (OLEFontImpl
*)iface
;
757 TRACE("(%p)->(%p)\n", this, punderline
);
765 *punderline
= this->description
.fUnderline
;
770 /************************************************************************
771 * OLEFontImpl_put_Underline (IFont)
773 * See Windows documentation for more details on IFont methods.
775 static HRESULT WINAPI
OLEFontImpl_put_Underline(
779 OLEFontImpl
*this = (OLEFontImpl
*)iface
;
780 TRACE("(%p)->(%d)\n", this, underline
);
782 this->description
.fUnderline
= underline
;
784 OLEFont_SendNotify(this, DISPID_FONT_UNDER
);
788 /************************************************************************
789 * OLEFontImpl_get_Strikethrough (IFont)
791 * See Windows documentation for more details on IFont methods.
793 static HRESULT WINAPI
OLEFontImpl_get_Strikethrough(
795 BOOL
* pstrikethrough
)
797 OLEFontImpl
*this = (OLEFontImpl
*)iface
;
798 TRACE("(%p)->(%p)\n", this, pstrikethrough
);
803 if (pstrikethrough
==0)
806 *pstrikethrough
= this->description
.fStrikethrough
;
811 /************************************************************************
812 * OLEFontImpl_put_Strikethrough (IFont)
814 * See Windows documentation for more details on IFont methods.
816 static HRESULT WINAPI
OLEFontImpl_put_Strikethrough(
820 OLEFontImpl
*this = (OLEFontImpl
*)iface
;
821 TRACE("(%p)->(%d)\n", this, strikethrough
);
823 this->description
.fStrikethrough
= strikethrough
;
824 OLEFont_SendNotify(this, DISPID_FONT_STRIKE
);
829 /************************************************************************
830 * OLEFontImpl_get_Weight (IFont)
832 * See Windows documentation for more details on IFont methods.
834 static HRESULT WINAPI
OLEFontImpl_get_Weight(
838 OLEFontImpl
*this = (OLEFontImpl
*)iface
;
839 TRACE("(%p)->(%p)\n", this, pweight
);
847 *pweight
= this->description
.sWeight
;
852 /************************************************************************
853 * OLEFontImpl_put_Weight (IFont)
855 * See Windows documentation for more details on IFont methods.
857 static HRESULT WINAPI
OLEFontImpl_put_Weight(
861 OLEFontImpl
*this = (OLEFontImpl
*)iface
;
862 TRACE("(%p)->(%d)\n", this, weight
);
864 this->description
.sWeight
= weight
;
866 OLEFont_SendNotify(this, DISPID_FONT_WEIGHT
);
870 /************************************************************************
871 * OLEFontImpl_get_Charset (IFont)
873 * See Windows documentation for more details on IFont methods.
875 static HRESULT WINAPI
OLEFontImpl_get_Charset(
879 OLEFontImpl
*this = (OLEFontImpl
*)iface
;
880 TRACE("(%p)->(%p)\n", this, pcharset
);
888 *pcharset
= this->description
.sCharset
;
893 /************************************************************************
894 * OLEFontImpl_put_Charset (IFont)
896 * See Windows documentation for more details on IFont methods.
898 static HRESULT WINAPI
OLEFontImpl_put_Charset(
902 OLEFontImpl
*this = (OLEFontImpl
*)iface
;
903 TRACE("(%p)->(%d)\n", this, charset
);
905 this->description
.sCharset
= charset
;
906 OLEFont_SendNotify(this, DISPID_FONT_CHARSET
);
911 /************************************************************************
912 * OLEFontImpl_get_hFont (IFont)
914 * See Windows documentation for more details on IFont methods.
916 static HRESULT WINAPI
OLEFontImpl_get_hFont(
920 OLEFontImpl
*this = (OLEFontImpl
*)iface
;
921 TRACE("(%p)->(%p)\n", this, phfont
);
926 * Realize the font if necessary
928 if (this->gdiFont
==0)
935 * The height of the font returned by the get_Size property is the
936 * height of the font in points multiplied by 10000... Using some
937 * simple conversions and the ratio given by the application, it can
938 * be converted to a height in pixels.
940 IFont_get_Size(iface
, &cySize
);
942 fontHeight
= MulDiv( cySize
.s
.Lo
, this->cyLogical
, this->cyHimetric
);
944 memset(&logFont
, 0, sizeof(LOGFONTW
));
946 logFont
.lfHeight
= ((fontHeight
%10000L)>5000L) ? (-fontHeight
/10000L)-1 :
947 (-fontHeight
/10000L);
948 logFont
.lfItalic
= this->description
.fItalic
;
949 logFont
.lfUnderline
= this->description
.fUnderline
;
950 logFont
.lfStrikeOut
= this->description
.fStrikethrough
;
951 logFont
.lfWeight
= this->description
.sWeight
;
952 logFont
.lfCharSet
= this->description
.sCharset
;
953 logFont
.lfOutPrecision
= OUT_CHARACTER_PRECIS
;
954 logFont
.lfClipPrecision
= CLIP_DEFAULT_PRECIS
;
955 logFont
.lfQuality
= DEFAULT_QUALITY
;
956 logFont
.lfPitchAndFamily
= DEFAULT_PITCH
;
957 strcpyW(logFont
.lfFaceName
,this->description
.lpstrName
);
959 this->gdiFont
= CreateFontIndirectW(&logFont
);
962 *phfont
= this->gdiFont
;
963 TRACE("Returning %p\n", *phfont
);
967 /************************************************************************
968 * OLEFontImpl_Clone (IFont)
970 * See Windows documentation for more details on IFont methods.
972 static HRESULT WINAPI
OLEFontImpl_Clone(
976 OLEFontImpl
* newObject
= 0;
980 OLEFontImpl
*this = (OLEFontImpl
*)iface
;
981 TRACE("(%p)->(%p)\n", this, ppfont
);
989 * Allocate space for the object.
991 newObject
= HeapAlloc(GetProcessHeap(), 0, sizeof(OLEFontImpl
));
994 return E_OUTOFMEMORY
;
998 /* We need to alloc new memory for the string, otherwise
999 * we free memory twice.
1001 newObject
->description
.lpstrName
= HeapAlloc(
1003 (1+strlenW(this->description
.lpstrName
))*2
1005 strcpyW(newObject
->description
.lpstrName
, this->description
.lpstrName
);
1006 /* We need to clone the HFONT too. This is just cut & paste from above */
1007 IFont_get_Size(iface
, &cySize
);
1009 fontHeight
= MulDiv(cySize
.s
.Lo
, this->cyLogical
,this->cyHimetric
);
1011 memset(&logFont
, 0, sizeof(LOGFONTW
));
1013 logFont
.lfHeight
= ((fontHeight
%10000L)>5000L) ? (-fontHeight
/10000L)-1 :
1014 (-fontHeight
/10000L);
1015 logFont
.lfItalic
= this->description
.fItalic
;
1016 logFont
.lfUnderline
= this->description
.fUnderline
;
1017 logFont
.lfStrikeOut
= this->description
.fStrikethrough
;
1018 logFont
.lfWeight
= this->description
.sWeight
;
1019 logFont
.lfCharSet
= this->description
.sCharset
;
1020 logFont
.lfOutPrecision
= OUT_CHARACTER_PRECIS
;
1021 logFont
.lfClipPrecision
= CLIP_DEFAULT_PRECIS
;
1022 logFont
.lfQuality
= DEFAULT_QUALITY
;
1023 logFont
.lfPitchAndFamily
= DEFAULT_PITCH
;
1024 strcpyW(logFont
.lfFaceName
,this->description
.lpstrName
);
1026 newObject
->gdiFont
= CreateFontIndirectW(&logFont
);
1029 /* The cloned object starts with a reference count of 1 */
1032 *ppfont
= (IFont
*)newObject
;
1037 /************************************************************************
1038 * OLEFontImpl_IsEqual (IFont)
1040 * See Windows documentation for more details on IFont methods.
1042 static HRESULT WINAPI
OLEFontImpl_IsEqual(
1046 FIXME("(%p, %p), stub!\n",iface
,pFontOther
);
1050 /************************************************************************
1051 * OLEFontImpl_SetRatio (IFont)
1053 * See Windows documentation for more details on IFont methods.
1055 static HRESULT WINAPI
OLEFontImpl_SetRatio(
1060 OLEFontImpl
*this = (OLEFontImpl
*)iface
;
1061 TRACE("(%p)->(%ld, %ld)\n", this, cyLogical
, cyHimetric
);
1063 this->cyLogical
= cyLogical
;
1064 this->cyHimetric
= cyHimetric
;
1069 /************************************************************************
1070 * OLEFontImpl_QueryTextMetrics (IFont)
1072 * See Windows documentation for more details on IFont methods.
1074 static HRESULT WINAPI
OLEFontImpl_QueryTextMetrics(
1078 FIXME("(%p, %p), stub!\n",iface
,ptm
);
1082 /************************************************************************
1083 * OLEFontImpl_AddRefHfont (IFont)
1085 * See Windows documentation for more details on IFont methods.
1087 static HRESULT WINAPI
OLEFontImpl_AddRefHfont(
1091 OLEFontImpl
*this = (OLEFontImpl
*)iface
;
1092 TRACE("(%p)->(%p) (lock=%ld)\n", this, hfont
, this->fontLock
);
1094 if ( (hfont
== 0) ||
1095 (hfont
!= this->gdiFont
) )
1096 return E_INVALIDARG
;
1103 /************************************************************************
1104 * OLEFontImpl_ReleaseHfont (IFont)
1106 * See Windows documentation for more details on IFont methods.
1108 static HRESULT WINAPI
OLEFontImpl_ReleaseHfont(
1112 OLEFontImpl
*this = (OLEFontImpl
*)iface
;
1113 TRACE("(%p)->(%p) (lock=%ld)\n", this, hfont
, this->fontLock
);
1115 if ( (hfont
== 0) ||
1116 (hfont
!= this->gdiFont
) )
1117 return E_INVALIDARG
;
1122 * If we just released our last font reference, destroy it.
1124 if (this->fontLock
==0)
1126 DeleteObject(this->gdiFont
);
1133 /************************************************************************
1134 * OLEFontImpl_SetHdc (IFont)
1136 * See Windows documentation for more details on IFont methods.
1138 static HRESULT WINAPI
OLEFontImpl_SetHdc(
1142 OLEFontImpl
*this = (OLEFontImpl
*)iface
;
1143 FIXME("(%p)->(%p): Stub\n", this, hdc
);
1147 /************************************************************************
1148 * OLEFontImpl_IDispatch_QueryInterface (IUnknown)
1150 * See Windows documentation for more details on IUnknown methods.
1152 static HRESULT WINAPI
OLEFontImpl_IDispatch_QueryInterface(
1157 _ICOM_THIS_From_IDispatch(IFont
, iface
);
1159 return IFont_QueryInterface(this, riid
, ppvoid
);
1162 /************************************************************************
1163 * OLEFontImpl_IDispatch_Release (IUnknown)
1165 * See Windows documentation for more details on IUnknown methods.
1167 static ULONG WINAPI
OLEFontImpl_IDispatch_Release(
1170 _ICOM_THIS_From_IDispatch(IFont
, iface
);
1172 return IFont_Release(this);
1175 /************************************************************************
1176 * OLEFontImpl_IDispatch_AddRef (IUnknown)
1178 * See Windows documentation for more details on IUnknown methods.
1180 static ULONG WINAPI
OLEFontImpl_IDispatch_AddRef(
1183 _ICOM_THIS_From_IDispatch(IFont
, iface
);
1185 return IFont_AddRef(this);
1188 /************************************************************************
1189 * OLEFontImpl_GetTypeInfoCount (IDispatch)
1191 * See Windows documentation for more details on IDispatch methods.
1193 static HRESULT WINAPI
OLEFontImpl_GetTypeInfoCount(
1195 unsigned int* pctinfo
)
1197 _ICOM_THIS_From_IDispatch(IFont
, iface
);
1198 FIXME("(%p)->(%p): Stub\n", this, pctinfo
);
1203 /************************************************************************
1204 * OLEFontImpl_GetTypeInfo (IDispatch)
1206 * See Windows documentation for more details on IDispatch methods.
1208 static HRESULT WINAPI
OLEFontImpl_GetTypeInfo(
1212 ITypeInfo
** ppTInfo
)
1214 static const WCHAR stdole32tlb
[] = {'s','t','d','o','l','e','3','2','.','t','l','b',0};
1218 _ICOM_THIS_From_IDispatch(OLEFontImpl
, iface
);
1219 TRACE("(%p, iTInfo=%d, lcid=%04x, %p), unimplemented stub!\n", this, iTInfo
, (int)lcid
, ppTInfo
);
1222 hres
= LoadTypeLib(stdole32tlb
, &tl
);
1224 FIXME("Could not load the stdole32.tlb?\n");
1227 hres
= ITypeLib_GetTypeInfoOfGuid(tl
, &IID_IDispatch
, ppTInfo
);
1229 FIXME("Did not IDispatch typeinfo from typelib, hres %lx\n",hres
);
1234 /************************************************************************
1235 * OLEFontImpl_GetIDsOfNames (IDispatch)
1237 * See Windows documentation for more details on IDispatch methods.
1239 static HRESULT WINAPI
OLEFontImpl_GetIDsOfNames(
1242 LPOLESTR
* rgszNames
,
1247 _ICOM_THIS_From_IDispatch(IFont
, iface
);
1248 FIXME("(%p,%s,%p,%d,%04x,%p), stub!\n", this, debugstr_guid(riid
), rgszNames
,
1249 cNames
, (int)lcid
, rgDispId
1254 /************************************************************************
1255 * OLEFontImpl_Invoke (IDispatch)
1257 * See Windows documentation for more details on IDispatch methods.
1259 * Note: Do not call _put_Xxx methods, since setting things here
1260 * should not call notify functions as I found out debugging the generic
1263 static HRESULT WINAPI
OLEFontImpl_Invoke(
1265 DISPID dispIdMember
,
1269 DISPPARAMS
* pDispParams
,
1270 VARIANT
* pVarResult
,
1271 EXCEPINFO
* pExepInfo
,
1274 _ICOM_THIS_From_IDispatch(IFont
, iface
);
1275 OLEFontImpl
*xthis
= (OLEFontImpl
*)this;
1277 switch (dispIdMember
) {
1278 case DISPID_FONT_NAME
:
1280 case DISPATCH_PROPERTYGET
:
1281 case DISPATCH_PROPERTYGET
|DISPATCH_METHOD
:
1282 V_VT(pVarResult
) = VT_BSTR
;
1283 return OLEFontImpl_get_Name(this, &V_BSTR(pVarResult
));
1284 case DISPATCH_PROPERTYPUT
: {
1285 BSTR name
= V_BSTR(&pDispParams
->rgvarg
[0]);
1286 if (V_VT(&pDispParams
->rgvarg
[0])!=VT_BSTR
) {
1287 FIXME("property put of Name, vt is not VT_BSTR but %d\n",V_VT(&pDispParams
->rgvarg
[0]));
1290 if (!xthis
->description
.lpstrName
)
1291 xthis
->description
.lpstrName
= HeapAlloc(GetProcessHeap(), 0, (lstrlenW(name
)+1) * sizeof(WCHAR
));
1293 xthis
->description
.lpstrName
= HeapReAlloc(GetProcessHeap(), 0, xthis
->description
.lpstrName
, (lstrlenW(name
)+1) * sizeof(WCHAR
));
1295 if (xthis
->description
.lpstrName
==0)
1296 return E_OUTOFMEMORY
;
1297 strcpyW(xthis
->description
.lpstrName
, name
);
1302 case DISPID_FONT_BOLD
:
1304 case DISPATCH_PROPERTYGET
:
1305 case DISPATCH_PROPERTYGET
|DISPATCH_METHOD
:
1306 V_VT(pVarResult
) = VT_BOOL
;
1307 return OLEFontImpl_get_Bold(this, (BOOL
*)&V_BOOL(pVarResult
));
1308 case DISPATCH_PROPERTYPUT
:
1309 if (V_VT(&pDispParams
->rgvarg
[0]) != VT_BOOL
) {
1310 FIXME("DISPID_FONT_BOLD/put, vt is %d, not VT_BOOL.\n",V_VT(&pDispParams
->rgvarg
[0]));
1313 xthis
->description
.sWeight
= V_BOOL(&pDispParams
->rgvarg
[0]) ? FW_BOLD
: FW_NORMAL
;
1318 case DISPID_FONT_ITALIC
:
1320 case DISPATCH_PROPERTYGET
:
1321 case DISPATCH_PROPERTYGET
|DISPATCH_METHOD
:
1322 V_VT(pVarResult
) = VT_BOOL
;
1323 return OLEFontImpl_get_Italic(this, (BOOL
*)&V_BOOL(pVarResult
));
1324 case DISPATCH_PROPERTYPUT
:
1325 if (V_VT(&pDispParams
->rgvarg
[0]) != VT_BOOL
) {
1326 FIXME("DISPID_FONT_ITALIC/put, vt is %d, not VT_BOOL.\n",V_VT(&pDispParams
->rgvarg
[0]));
1329 xthis
->description
.fItalic
= V_BOOL(&pDispParams
->rgvarg
[0]);
1334 case DISPID_FONT_UNDER
:
1336 case DISPATCH_PROPERTYGET
:
1337 case DISPATCH_PROPERTYGET
|DISPATCH_METHOD
:
1338 V_VT(pVarResult
) = VT_BOOL
;
1339 return OLEFontImpl_get_Underline(this, (BOOL
*)&V_BOOL(pVarResult
));
1340 case DISPATCH_PROPERTYPUT
:
1341 if (V_VT(&pDispParams
->rgvarg
[0]) != VT_BOOL
) {
1342 FIXME("DISPID_FONT_UNDER/put, vt is %d, not VT_BOOL.\n",V_VT(&pDispParams
->rgvarg
[0]));
1345 xthis
->description
.fUnderline
= V_BOOL(&pDispParams
->rgvarg
[0]);
1350 case DISPID_FONT_STRIKE
:
1352 case DISPATCH_PROPERTYGET
:
1353 case DISPATCH_PROPERTYGET
|DISPATCH_METHOD
:
1354 V_VT(pVarResult
) = VT_BOOL
;
1355 return OLEFontImpl_get_Strikethrough(this, (BOOL
*)&V_BOOL(pVarResult
));
1356 case DISPATCH_PROPERTYPUT
:
1357 if (V_VT(&pDispParams
->rgvarg
[0]) != VT_BOOL
) {
1358 FIXME("DISPID_FONT_STRIKE/put, vt is %d, not VT_BOOL.\n",V_VT(&pDispParams
->rgvarg
[0]));
1361 xthis
->description
.fStrikethrough
= V_BOOL(&pDispParams
->rgvarg
[0]);
1366 case DISPID_FONT_SIZE
:
1368 case DISPATCH_PROPERTYPUT
: {
1369 assert (pDispParams
->cArgs
== 1);
1370 xthis
->description
.cySize
.s
.Hi
= 0;
1371 if (V_VT(&pDispParams
->rgvarg
[0]) != VT_CY
) {
1372 if (V_VT(&pDispParams
->rgvarg
[0]) == VT_I2
) {
1373 xthis
->description
.cySize
.s
.Lo
= V_I2(&pDispParams
->rgvarg
[0]) * 10000;
1375 FIXME("property put for Size with vt %d unsupported!\n",V_VT(&pDispParams
->rgvarg
[0]));
1378 xthis
->description
.cySize
.s
.Lo
= V_CY(&pDispParams
->rgvarg
[0]).s
.Lo
;
1382 case DISPATCH_PROPERTYGET
:
1383 case DISPATCH_PROPERTYGET
|DISPATCH_METHOD
:
1384 V_VT(pVarResult
) = VT_CY
;
1385 return OLEFontImpl_get_Size(this, &V_CY(pVarResult
));
1388 case DISPID_FONT_CHARSET
:
1390 case DISPATCH_PROPERTYPUT
:
1391 assert (pDispParams
->cArgs
== 1);
1392 if (V_VT(&pDispParams
->rgvarg
[0]) != VT_I2
)
1393 FIXME("varg of first disparg is not VT_I2, but %d\n",V_VT(&pDispParams
->rgvarg
[0]));
1394 xthis
->description
.sCharset
= V_I2(&pDispParams
->rgvarg
[0]);
1396 case DISPATCH_PROPERTYGET
:
1397 case DISPATCH_PROPERTYGET
|DISPATCH_METHOD
:
1398 V_VT(pVarResult
) = VT_I2
;
1399 return OLEFontImpl_get_Charset(this, &V_I2(pVarResult
));
1403 FIXME("%p->(%ld,%s,%lx,%x,%p,%p,%p,%p), unhandled dispid/flag!\n",
1404 this,dispIdMember
,debugstr_guid(riid
),lcid
,
1405 wFlags
,pDispParams
,pVarResult
,pExepInfo
,puArgErr
1410 /************************************************************************
1411 * OLEFontImpl_IPersistStream_QueryInterface (IUnknown)
1413 * See Windows documentation for more details on IUnknown methods.
1415 static HRESULT WINAPI
OLEFontImpl_IPersistStream_QueryInterface(
1416 IPersistStream
* iface
,
1420 _ICOM_THIS_From_IPersistStream(IFont
, iface
);
1422 return IFont_QueryInterface(this, riid
, ppvoid
);
1425 /************************************************************************
1426 * OLEFontImpl_IPersistStream_Release (IUnknown)
1428 * See Windows documentation for more details on IUnknown methods.
1430 static ULONG WINAPI
OLEFontImpl_IPersistStream_Release(
1431 IPersistStream
* iface
)
1433 _ICOM_THIS_From_IPersistStream(IFont
, iface
);
1435 return IFont_Release(this);
1438 /************************************************************************
1439 * OLEFontImpl_IPersistStream_AddRef (IUnknown)
1441 * See Windows documentation for more details on IUnknown methods.
1443 static ULONG WINAPI
OLEFontImpl_IPersistStream_AddRef(
1444 IPersistStream
* iface
)
1446 _ICOM_THIS_From_IPersistStream(IFont
, iface
);
1448 return IFont_AddRef(this);
1451 /************************************************************************
1452 * OLEFontImpl_GetClassID (IPersistStream)
1454 * See Windows documentation for more details on IPersistStream methods.
1456 static HRESULT WINAPI
OLEFontImpl_GetClassID(
1457 IPersistStream
* iface
,
1460 TRACE("(%p,%p)\n",iface
,pClassID
);
1464 memcpy(pClassID
, &CLSID_StdFont
, sizeof(CLSID_StdFont
));
1469 /************************************************************************
1470 * OLEFontImpl_IsDirty (IPersistStream)
1472 * See Windows documentation for more details on IPersistStream methods.
1474 static HRESULT WINAPI
OLEFontImpl_IsDirty(
1475 IPersistStream
* iface
)
1477 TRACE("(%p)\n",iface
);
1481 /************************************************************************
1482 * OLEFontImpl_Load (IPersistStream)
1484 * See Windows documentation for more details on IPersistStream methods.
1486 * This is the format of the standard font serialization as far as I
1489 * Offset Type Value Comment
1490 * 0x0000 Byte Unknown Probably a version number, contains 0x01
1491 * 0x0001 Short Charset Charset value from the FONTDESC structure
1492 * 0x0003 Byte Attributes Flags defined as follows:
1494 * 00000100 - Underline
1495 * 00001000 - Strikethrough
1496 * 0x0004 Short Weight Weight value from FONTDESC structure
1497 * 0x0006 DWORD size "Low" portion of the cySize member of the FONTDESC
1499 * 0x000A Byte name length Length of the font name string (no null character)
1500 * 0x000B String name Name of the font (ASCII, no nul character)
1502 static HRESULT WINAPI
OLEFontImpl_Load(
1503 IPersistStream
* iface
,
1504 IStream
* pLoadStream
)
1506 char readBuffer
[0x100];
1513 _ICOM_THIS_From_IPersistStream(OLEFontImpl
, iface
);
1516 * Read the version byte
1518 IStream_Read(pLoadStream
, &bVersion
, 1, &cbRead
);
1527 IStream_Read(pLoadStream
, &this->description
.sCharset
, 2, &cbRead
);
1535 IStream_Read(pLoadStream
, &bAttributes
, 1, &cbRead
);
1540 this->description
.fItalic
= (bAttributes
& FONTPERSIST_ITALIC
) != 0;
1541 this->description
.fStrikethrough
= (bAttributes
& FONTPERSIST_STRIKETHROUGH
) != 0;
1542 this->description
.fUnderline
= (bAttributes
& FONTPERSIST_UNDERLINE
) != 0;
1547 IStream_Read(pLoadStream
, &this->description
.sWeight
, 2, &cbRead
);
1555 IStream_Read(pLoadStream
, &this->description
.cySize
.s
.Lo
, 4, &cbRead
);
1560 this->description
.cySize
.s
.Hi
= 0;
1565 IStream_Read(pLoadStream
, &bStringSize
, 1, &cbRead
);
1570 IStream_Read(pLoadStream
, readBuffer
, bStringSize
, &cbRead
);
1572 if (cbRead
!=bStringSize
)
1575 if (this->description
.lpstrName
!=0)
1576 HeapFree(GetProcessHeap(), 0, this->description
.lpstrName
);
1578 len
= MultiByteToWideChar( CP_ACP
, 0, readBuffer
, bStringSize
, NULL
, 0 );
1579 this->description
.lpstrName
= HeapAlloc( GetProcessHeap(), 0, (len
+1) * sizeof(WCHAR
) );
1580 MultiByteToWideChar( CP_ACP
, 0, readBuffer
, bStringSize
, this->description
.lpstrName
, len
);
1581 this->description
.lpstrName
[len
] = 0;
1583 /* Ensure use of this font causes a new one to be created @@@@ */
1584 DeleteObject(this->gdiFont
);
1590 /************************************************************************
1591 * OLEFontImpl_Save (IPersistStream)
1593 * See Windows documentation for more details on IPersistStream methods.
1595 static HRESULT WINAPI
OLEFontImpl_Save(
1596 IPersistStream
* iface
,
1597 IStream
* pOutStream
,
1600 char* writeBuffer
= NULL
;
1602 BYTE bVersion
= 0x01;
1606 _ICOM_THIS_From_IPersistStream(OLEFontImpl
, iface
);
1609 * Read the version byte
1611 IStream_Write(pOutStream
, &bVersion
, 1, &cbWritten
);
1619 IStream_Write(pOutStream
, &this->description
.sCharset
, 2, &cbWritten
);
1629 if (this->description
.fItalic
)
1630 bAttributes
|= FONTPERSIST_ITALIC
;
1632 if (this->description
.fStrikethrough
)
1633 bAttributes
|= FONTPERSIST_STRIKETHROUGH
;
1635 if (this->description
.fUnderline
)
1636 bAttributes
|= FONTPERSIST_UNDERLINE
;
1638 IStream_Write(pOutStream
, &bAttributes
, 1, &cbWritten
);
1646 IStream_Write(pOutStream
, &this->description
.sWeight
, 2, &cbWritten
);
1654 IStream_Write(pOutStream
, &this->description
.cySize
.s
.Lo
, 4, &cbWritten
);
1662 if (this->description
.lpstrName
!=0)
1663 bStringSize
= WideCharToMultiByte( CP_ACP
, 0, this->description
.lpstrName
,
1664 strlenW(this->description
.lpstrName
), NULL
, 0, NULL
, NULL
);
1668 IStream_Write(pOutStream
, &bStringSize
, 1, &cbWritten
);
1675 if (!(writeBuffer
= HeapAlloc( GetProcessHeap(), 0, bStringSize
))) return E_OUTOFMEMORY
;
1676 WideCharToMultiByte( CP_ACP
, 0, this->description
.lpstrName
,
1677 strlenW(this->description
.lpstrName
),
1678 writeBuffer
, bStringSize
, NULL
, NULL
);
1680 IStream_Write(pOutStream
, writeBuffer
, bStringSize
, &cbWritten
);
1681 HeapFree(GetProcessHeap(), 0, writeBuffer
);
1683 if (cbWritten
!=bStringSize
)
1690 /************************************************************************
1691 * OLEFontImpl_GetSizeMax (IPersistStream)
1693 * See Windows documentation for more details on IPersistStream methods.
1695 static HRESULT WINAPI
OLEFontImpl_GetSizeMax(
1696 IPersistStream
* iface
,
1697 ULARGE_INTEGER
* pcbSize
)
1699 _ICOM_THIS_From_IPersistStream(OLEFontImpl
, iface
);
1704 pcbSize
->u
.HighPart
= 0;
1705 pcbSize
->u
.LowPart
= 0;
1707 pcbSize
->u
.LowPart
+= sizeof(BYTE
); /* Version */
1708 pcbSize
->u
.LowPart
+= sizeof(WORD
); /* Lang code */
1709 pcbSize
->u
.LowPart
+= sizeof(BYTE
); /* Flags */
1710 pcbSize
->u
.LowPart
+= sizeof(WORD
); /* Weight */
1711 pcbSize
->u
.LowPart
+= sizeof(DWORD
); /* Size */
1712 pcbSize
->u
.LowPart
+= sizeof(BYTE
); /* StrLength */
1714 if (this->description
.lpstrName
!=0)
1715 pcbSize
->u
.LowPart
+= lstrlenW(this->description
.lpstrName
);
1720 /************************************************************************
1721 * OLEFontImpl_IConnectionPointContainer_QueryInterface (IUnknown)
1723 * See Windows documentation for more details on IUnknown methods.
1725 static HRESULT WINAPI
OLEFontImpl_IConnectionPointContainer_QueryInterface(
1726 IConnectionPointContainer
* iface
,
1730 _ICOM_THIS_From_IConnectionPointContainer(OLEFontImpl
, iface
);
1732 return IFont_QueryInterface((IFont
*)this, riid
, ppvoid
);
1735 /************************************************************************
1736 * OLEFontImpl_IConnectionPointContainer_Release (IUnknown)
1738 * See Windows documentation for more details on IUnknown methods.
1740 static ULONG WINAPI
OLEFontImpl_IConnectionPointContainer_Release(
1741 IConnectionPointContainer
* iface
)
1743 _ICOM_THIS_From_IConnectionPointContainer(OLEFontImpl
, iface
);
1745 return IFont_Release((IFont
*)this);
1748 /************************************************************************
1749 * OLEFontImpl_IConnectionPointContainer_AddRef (IUnknown)
1751 * See Windows documentation for more details on IUnknown methods.
1753 static ULONG WINAPI
OLEFontImpl_IConnectionPointContainer_AddRef(
1754 IConnectionPointContainer
* iface
)
1756 _ICOM_THIS_From_IConnectionPointContainer(OLEFontImpl
, iface
);
1758 return IFont_AddRef((IFont
*)this);
1761 /************************************************************************
1762 * OLEFontImpl_EnumConnectionPoints (IConnectionPointContainer)
1764 * See Windows documentation for more details on IConnectionPointContainer
1767 static HRESULT WINAPI
OLEFontImpl_EnumConnectionPoints(
1768 IConnectionPointContainer
* iface
,
1769 IEnumConnectionPoints
**ppEnum
)
1771 _ICOM_THIS_From_IConnectionPointContainer(OLEFontImpl
, iface
);
1773 FIXME("(%p)->(%p): stub\n", this, ppEnum
);
1777 /************************************************************************
1778 * OLEFontImpl_FindConnectionPoint (IConnectionPointContainer)
1780 * See Windows documentation for more details on IConnectionPointContainer
1783 static HRESULT WINAPI
OLEFontImpl_FindConnectionPoint(
1784 IConnectionPointContainer
* iface
,
1786 IConnectionPoint
**ppCp
)
1788 _ICOM_THIS_From_IConnectionPointContainer(OLEFontImpl
, iface
);
1789 TRACE("(%p)->(%s, %p): stub\n", this, debugstr_guid(riid
), ppCp
);
1791 if(memcmp(riid
, &IID_IPropertyNotifySink
, sizeof(IID_IPropertyNotifySink
)) == 0) {
1792 return IConnectionPoint_QueryInterface(this->pCP
, &IID_IConnectionPoint
,
1795 FIXME("Tried to find connection point on %s\n", debugstr_guid(riid
));
1796 return E_NOINTERFACE
;
1800 /************************************************************************
1801 * OLEFontImpl implementation of IPersistPropertyBag.
1803 static HRESULT WINAPI
OLEFontImpl_IPersistPropertyBag_QueryInterface(
1804 IPersistPropertyBag
*iface
, REFIID riid
, LPVOID
*ppvObj
1806 _ICOM_THIS_From_IPersistPropertyBag(IFont
, iface
);
1807 return IFont_QueryInterface(this,riid
,ppvObj
);
1810 static ULONG WINAPI
OLEFontImpl_IPersistPropertyBag_AddRef(
1811 IPersistPropertyBag
*iface
1813 _ICOM_THIS_From_IPersistPropertyBag(IFont
, iface
);
1814 return IFont_AddRef(this);
1817 static ULONG WINAPI
OLEFontImpl_IPersistPropertyBag_Release(
1818 IPersistPropertyBag
*iface
1820 _ICOM_THIS_From_IPersistPropertyBag(IFont
, iface
);
1821 return IFont_Release(this);
1824 static HRESULT WINAPI
OLEFontImpl_IPersistPropertyBag_GetClassID(
1825 IPersistPropertyBag
*iface
, CLSID
*classid
1827 FIXME("(%p,%p), stub!\n", iface
, classid
);
1831 static HRESULT WINAPI
OLEFontImpl_IPersistPropertyBag_InitNew(
1832 IPersistPropertyBag
*iface
1834 FIXME("(%p), stub!\n", iface
);
1838 static HRESULT WINAPI
OLEFontImpl_IPersistPropertyBag_Load(
1839 IPersistPropertyBag
*iface
, IPropertyBag
* pPropBag
, IErrorLog
* pErrorLog
1841 /* (from Visual Basic 6 property bag)
1842 Name = "MS Sans Serif"
1846 Underline = 0 'False
1848 Strikethrough = 0 'False
1850 static const WCHAR sAttrName
[] = {'N','a','m','e',0};
1851 static const WCHAR sAttrSize
[] = {'S','i','z','e',0};
1852 static const WCHAR sAttrCharset
[] = {'C','h','a','r','s','e','t',0};
1853 static const WCHAR sAttrWeight
[] = {'W','e','i','g','h','t',0};
1854 static const WCHAR sAttrUnderline
[] = {'U','n','d','e','r','l','i','n','e',0};
1855 static const WCHAR sAttrItalic
[] = {'I','t','a','l','i','c',0};
1856 static const WCHAR sAttrStrikethrough
[] = {'S','t','r','i','k','e','t','h','r','o','u','g','h',0};
1859 HRESULT iRes
= S_OK
;
1860 _ICOM_THIS_From_IPersistPropertyBag(IFont
, iface
);
1862 VariantInit(&rawAttr
);
1863 VariantInit(&valueAttr
);
1866 iRes
= IPropertyBag_Read(pPropBag
, sAttrName
, &rawAttr
, pErrorLog
);
1869 iRes
= VariantChangeType(&rawAttr
, &valueAttr
, 0, VT_BSTR
);
1871 iRes
= IFont_put_Name(this, V_BSTR(&valueAttr
));
1873 else if (iRes
== E_INVALIDARG
)
1875 VariantClear(&rawAttr
);
1876 VariantClear(&valueAttr
);
1880 iRes
= IPropertyBag_Read(pPropBag
, sAttrSize
, &rawAttr
, pErrorLog
);
1883 iRes
= VariantChangeType(&rawAttr
, &valueAttr
, 0, VT_CY
);
1885 iRes
= IFont_put_Size(this, V_CY(&valueAttr
));
1887 else if (iRes
== E_INVALIDARG
)
1889 VariantClear(&rawAttr
);
1890 VariantClear(&valueAttr
);
1894 iRes
= IPropertyBag_Read(pPropBag
, sAttrCharset
, &rawAttr
, pErrorLog
);
1897 iRes
= VariantChangeType(&rawAttr
, &valueAttr
, 0, VT_I2
);
1899 iRes
= IFont_put_Charset(this, V_I2(&valueAttr
));
1901 else if (iRes
== E_INVALIDARG
)
1903 VariantClear(&rawAttr
);
1904 VariantClear(&valueAttr
);
1908 iRes
= IPropertyBag_Read(pPropBag
, sAttrWeight
, &rawAttr
, pErrorLog
);
1911 iRes
= VariantChangeType(&rawAttr
, &valueAttr
, 0, VT_I2
);
1913 iRes
= IFont_put_Weight(this, V_I2(&valueAttr
));
1915 else if (iRes
== E_INVALIDARG
)
1917 VariantClear(&rawAttr
);
1918 VariantClear(&valueAttr
);
1923 iRes
= IPropertyBag_Read(pPropBag
, sAttrUnderline
, &rawAttr
, pErrorLog
);
1926 iRes
= VariantChangeType(&rawAttr
, &valueAttr
, 0, VT_BOOL
);
1928 iRes
= IFont_put_Underline(this, V_BOOL(&valueAttr
));
1930 else if (iRes
== E_INVALIDARG
)
1932 VariantClear(&rawAttr
);
1933 VariantClear(&valueAttr
);
1937 iRes
= IPropertyBag_Read(pPropBag
, sAttrItalic
, &rawAttr
, pErrorLog
);
1940 iRes
= VariantChangeType(&rawAttr
, &valueAttr
, 0, VT_BOOL
);
1942 iRes
= IFont_put_Italic(this, V_BOOL(&valueAttr
));
1944 else if (iRes
== E_INVALIDARG
)
1946 VariantClear(&rawAttr
);
1947 VariantClear(&valueAttr
);
1951 iRes
= IPropertyBag_Read(pPropBag
, sAttrStrikethrough
, &rawAttr
, pErrorLog
);
1954 iRes
= VariantChangeType(&rawAttr
, &valueAttr
, 0, VT_BOOL
);
1956 IFont_put_Strikethrough(this, V_BOOL(&valueAttr
));
1958 else if (iRes
== E_INVALIDARG
)
1960 VariantClear(&rawAttr
);
1961 VariantClear(&valueAttr
);
1965 WARN("-- 0x%08lx\n", iRes
);
1969 static HRESULT WINAPI
OLEFontImpl_IPersistPropertyBag_Save(
1970 IPersistPropertyBag
*iface
, IPropertyBag
* pPropBag
, BOOL fClearDirty
,
1971 BOOL fSaveAllProperties
1973 FIXME("(%p,%p,%d,%d), stub!\n", iface
, pPropBag
, fClearDirty
, fSaveAllProperties
);
1977 static IPersistPropertyBagVtbl OLEFontImpl_IPersistPropertyBag_VTable
=
1979 OLEFontImpl_IPersistPropertyBag_QueryInterface
,
1980 OLEFontImpl_IPersistPropertyBag_AddRef
,
1981 OLEFontImpl_IPersistPropertyBag_Release
,
1983 OLEFontImpl_IPersistPropertyBag_GetClassID
,
1984 OLEFontImpl_IPersistPropertyBag_InitNew
,
1985 OLEFontImpl_IPersistPropertyBag_Load
,
1986 OLEFontImpl_IPersistPropertyBag_Save
1989 /************************************************************************
1990 * OLEFontImpl implementation of IPersistStreamInit.
1992 static HRESULT WINAPI
OLEFontImpl_IPersistStreamInit_QueryInterface(
1993 IPersistStreamInit
*iface
, REFIID riid
, LPVOID
*ppvObj
1995 _ICOM_THIS_From_IPersistStreamInit(IFont
, iface
);
1996 return IFont_QueryInterface(this,riid
,ppvObj
);
1999 static ULONG WINAPI
OLEFontImpl_IPersistStreamInit_AddRef(
2000 IPersistStreamInit
*iface
2002 _ICOM_THIS_From_IPersistStreamInit(IFont
, iface
);
2003 return IFont_AddRef(this);
2006 static ULONG WINAPI
OLEFontImpl_IPersistStreamInit_Release(
2007 IPersistStreamInit
*iface
2009 _ICOM_THIS_From_IPersistStreamInit(IFont
, iface
);
2010 return IFont_Release(this);
2013 static HRESULT WINAPI
OLEFontImpl_IPersistStreamInit_GetClassID(
2014 IPersistStreamInit
*iface
, CLSID
*classid
2016 FIXME("(%p,%p), stub!\n", iface
, classid
);
2020 static HRESULT WINAPI
OLEFontImpl_IPersistStreamInit_IsDirty(
2021 IPersistStreamInit
*iface
2023 FIXME("(%p), stub!\n", iface
);
2027 static HRESULT WINAPI
OLEFontImpl_IPersistStreamInit_Load(
2028 IPersistStreamInit
*iface
, LPSTREAM pStm
2030 FIXME("(%p,%p), stub!\n", iface
, pStm
);
2034 static HRESULT WINAPI
OLEFontImpl_IPersistStreamInit_Save(
2035 IPersistStreamInit
*iface
, LPSTREAM pStm
, BOOL fClearDirty
2037 FIXME("(%p,%p,%d), stub!\n", iface
, pStm
, fClearDirty
);
2041 static HRESULT WINAPI
OLEFontImpl_IPersistStreamInit_GetSizeMax(
2042 IPersistStreamInit
*iface
, ULARGE_INTEGER
*pcbSize
2044 FIXME("(%p,%p), stub!\n", iface
, pcbSize
);
2048 static HRESULT WINAPI
OLEFontImpl_IPersistStreamInit_InitNew(
2049 IPersistStreamInit
*iface
2051 FIXME("(%p), stub!\n", iface
);
2055 static IPersistStreamInitVtbl OLEFontImpl_IPersistStreamInit_VTable
=
2057 OLEFontImpl_IPersistStreamInit_QueryInterface
,
2058 OLEFontImpl_IPersistStreamInit_AddRef
,
2059 OLEFontImpl_IPersistStreamInit_Release
,
2061 OLEFontImpl_IPersistStreamInit_GetClassID
,
2062 OLEFontImpl_IPersistStreamInit_IsDirty
,
2063 OLEFontImpl_IPersistStreamInit_Load
,
2064 OLEFontImpl_IPersistStreamInit_Save
,
2065 OLEFontImpl_IPersistStreamInit_GetSizeMax
,
2066 OLEFontImpl_IPersistStreamInit_InitNew
2069 /*******************************************************************************
2070 * StdFont ClassFactory
2074 /* IUnknown fields */
2075 IClassFactoryVtbl
*lpVtbl
;
2077 } IClassFactoryImpl
;
2079 static HRESULT WINAPI
2080 SFCF_QueryInterface(LPCLASSFACTORY iface
,REFIID riid
,LPVOID
*ppobj
) {
2081 IClassFactoryImpl
*This
= (IClassFactoryImpl
*)iface
;
2083 FIXME("(%p)->(%s,%p),stub!\n",This
,debugstr_guid(riid
),ppobj
);
2084 return E_NOINTERFACE
;
2088 SFCF_AddRef(LPCLASSFACTORY iface
) {
2089 IClassFactoryImpl
*This
= (IClassFactoryImpl
*)iface
;
2090 return ++(This
->ref
);
2093 static ULONG WINAPI
SFCF_Release(LPCLASSFACTORY iface
) {
2094 IClassFactoryImpl
*This
= (IClassFactoryImpl
*)iface
;
2095 /* static class, won't be freed */
2096 return --(This
->ref
);
2099 static HRESULT WINAPI
SFCF_CreateInstance(
2100 LPCLASSFACTORY iface
,LPUNKNOWN pOuter
,REFIID riid
,LPVOID
*ppobj
2102 return OleCreateFontIndirect(NULL
,riid
,ppobj
);
2106 static HRESULT WINAPI
SFCF_LockServer(LPCLASSFACTORY iface
,BOOL dolock
) {
2107 IClassFactoryImpl
*This
= (IClassFactoryImpl
*)iface
;
2108 FIXME("(%p)->(%d),stub!\n",This
,dolock
);
2112 static IClassFactoryVtbl SFCF_Vtbl
= {
2113 SFCF_QueryInterface
,
2116 SFCF_CreateInstance
,
2119 static IClassFactoryImpl STDFONT_CF
= {&SFCF_Vtbl
, 1 };
2121 void _get_STDFONT_CF(LPVOID
*ppv
) { *ppv
= (LPVOID
)&STDFONT_CF
; }