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.
66 const IFontVtbl
* lpVtbl
;
67 const IDispatchVtbl
* lpvtblIDispatch
;
68 const IPersistStreamVtbl
* lpvtblIPersistStream
;
69 const IConnectionPointContainerVtbl
* lpvtblIConnectionPointContainer
;
70 const IPersistPropertyBagVtbl
* lpvtblIPersistPropertyBag
;
71 const IPersistStreamInitVtbl
* lpvtblIPersistStreamInit
;
73 * Reference count for that instance of the class.
78 * This structure contains the description of the class.
83 * Contain the font associated with this object.
98 IConnectionPoint
*pCP
;
102 * Here, I define utility macros to help with the casting of the
104 * There is a version to accommodate all of the VTables implemented
108 static inline OLEFontImpl
*impl_from_IDispatch( IDispatch
*iface
)
110 return (OLEFontImpl
*)((char*)iface
- FIELD_OFFSET(OLEFontImpl
, lpvtblIDispatch
));
113 static inline OLEFontImpl
*impl_from_IPersistStream( IPersistStream
*iface
)
115 return (OLEFontImpl
*)((char*)iface
- FIELD_OFFSET(OLEFontImpl
, lpvtblIPersistStream
));
118 static inline OLEFontImpl
*impl_from_IConnectionPointContainer( IConnectionPointContainer
*iface
)
120 return (OLEFontImpl
*)((char*)iface
- FIELD_OFFSET(OLEFontImpl
, lpvtblIConnectionPointContainer
));
123 static inline OLEFontImpl
*impl_from_IPersistPropertyBag( IPersistPropertyBag
*iface
)
125 return (OLEFontImpl
*)((char*)iface
- FIELD_OFFSET(OLEFontImpl
, lpvtblIPersistPropertyBag
));
128 static inline OLEFontImpl
*impl_from_IPersistStreamInit( IPersistStreamInit
*iface
)
130 return (OLEFontImpl
*)((char*)iface
- FIELD_OFFSET(OLEFontImpl
, lpvtblIPersistStreamInit
));
134 /***********************************************************************
135 * Prototypes for the implementation functions for the IFont
138 static OLEFontImpl
* OLEFontImpl_Construct(LPFONTDESC fontDesc
);
139 static void OLEFontImpl_Destroy(OLEFontImpl
* fontDesc
);
140 static HRESULT WINAPI
OLEFontImpl_QueryInterface(IFont
* iface
, REFIID riid
, VOID
** ppvoid
);
141 static ULONG WINAPI
OLEFontImpl_AddRef(IFont
* iface
);
142 static ULONG WINAPI
OLEFontImpl_Release(IFont
* iface
);
143 static HRESULT WINAPI
OLEFontImpl_get_Name(IFont
* iface
, BSTR
* pname
);
144 static HRESULT WINAPI
OLEFontImpl_put_Name(IFont
* iface
, BSTR name
);
145 static HRESULT WINAPI
OLEFontImpl_get_Size(IFont
* iface
, CY
* psize
);
146 static HRESULT WINAPI
OLEFontImpl_put_Size(IFont
* iface
, CY size
);
147 static HRESULT WINAPI
OLEFontImpl_get_Bold(IFont
* iface
, BOOL
* pbold
);
148 static HRESULT WINAPI
OLEFontImpl_put_Bold(IFont
* iface
, BOOL bold
);
149 static HRESULT WINAPI
OLEFontImpl_get_Italic(IFont
* iface
, BOOL
* pitalic
);
150 static HRESULT WINAPI
OLEFontImpl_put_Italic(IFont
* iface
, BOOL italic
);
151 static HRESULT WINAPI
OLEFontImpl_get_Underline(IFont
* iface
, BOOL
* punderline
);
152 static HRESULT WINAPI
OLEFontImpl_put_Underline(IFont
* iface
, BOOL underline
);
153 static HRESULT WINAPI
OLEFontImpl_get_Strikethrough(IFont
* iface
, BOOL
* pstrikethrough
);
154 static HRESULT WINAPI
OLEFontImpl_put_Strikethrough(IFont
* iface
, BOOL strikethrough
);
155 static HRESULT WINAPI
OLEFontImpl_get_Weight(IFont
* iface
, short* pweight
);
156 static HRESULT WINAPI
OLEFontImpl_put_Weight(IFont
* iface
, short weight
);
157 static HRESULT WINAPI
OLEFontImpl_get_Charset(IFont
* iface
, short* pcharset
);
158 static HRESULT WINAPI
OLEFontImpl_put_Charset(IFont
* iface
, short charset
);
159 static HRESULT WINAPI
OLEFontImpl_get_hFont(IFont
* iface
, HFONT
* phfont
);
160 static HRESULT WINAPI
OLEFontImpl_Clone(IFont
* iface
, IFont
** ppfont
);
161 static HRESULT WINAPI
OLEFontImpl_IsEqual(IFont
* iface
, IFont
* pFontOther
);
162 static HRESULT WINAPI
OLEFontImpl_SetRatio(IFont
* iface
, LONG cyLogical
, LONG cyHimetric
);
163 static HRESULT WINAPI
OLEFontImpl_QueryTextMetrics(IFont
* iface
, TEXTMETRICOLE
* ptm
);
164 static HRESULT WINAPI
OLEFontImpl_AddRefHfont(IFont
* iface
, HFONT hfont
);
165 static HRESULT WINAPI
OLEFontImpl_ReleaseHfont(IFont
* iface
, HFONT hfont
);
166 static HRESULT WINAPI
OLEFontImpl_SetHdc(IFont
* iface
, HDC hdc
);
168 /***********************************************************************
169 * Prototypes for the implementation functions for the IDispatch
172 static HRESULT WINAPI
OLEFontImpl_IDispatch_QueryInterface(IDispatch
* iface
,
175 static ULONG WINAPI
OLEFontImpl_IDispatch_AddRef(IDispatch
* iface
);
176 static ULONG WINAPI
OLEFontImpl_IDispatch_Release(IDispatch
* iface
);
177 static HRESULT WINAPI
OLEFontImpl_GetTypeInfoCount(IDispatch
* iface
,
178 unsigned int* pctinfo
);
179 static HRESULT WINAPI
OLEFontImpl_GetTypeInfo(IDispatch
* iface
,
182 ITypeInfo
** ppTInfo
);
183 static HRESULT WINAPI
OLEFontImpl_GetIDsOfNames(IDispatch
* iface
,
189 static HRESULT WINAPI
OLEFontImpl_Invoke(IDispatch
* iface
,
194 DISPPARAMS
* pDispParams
,
196 EXCEPINFO
* pExepInfo
,
199 /***********************************************************************
200 * Prototypes for the implementation functions for the IPersistStream
203 static HRESULT WINAPI
OLEFontImpl_IPersistStream_QueryInterface(IPersistStream
* iface
,
206 static ULONG WINAPI
OLEFontImpl_IPersistStream_AddRef(IPersistStream
* iface
);
207 static ULONG WINAPI
OLEFontImpl_IPersistStream_Release(IPersistStream
* iface
);
208 static HRESULT WINAPI
OLEFontImpl_GetClassID(IPersistStream
* iface
,
210 static HRESULT WINAPI
OLEFontImpl_IsDirty(IPersistStream
* iface
);
211 static HRESULT WINAPI
OLEFontImpl_Load(IPersistStream
* iface
,
212 IStream
* pLoadStream
);
213 static HRESULT WINAPI
OLEFontImpl_Save(IPersistStream
* iface
,
216 static HRESULT WINAPI
OLEFontImpl_GetSizeMax(IPersistStream
* iface
,
217 ULARGE_INTEGER
* pcbSize
);
219 /***********************************************************************
220 * Prototypes for the implementation functions for the
221 * IConnectionPointContainer interface
223 static HRESULT WINAPI
OLEFontImpl_IConnectionPointContainer_QueryInterface(
224 IConnectionPointContainer
* iface
,
227 static ULONG WINAPI
OLEFontImpl_IConnectionPointContainer_AddRef(
228 IConnectionPointContainer
* iface
);
229 static ULONG WINAPI
OLEFontImpl_IConnectionPointContainer_Release(
230 IConnectionPointContainer
* iface
);
231 static HRESULT WINAPI
OLEFontImpl_EnumConnectionPoints(
232 IConnectionPointContainer
* iface
,
233 IEnumConnectionPoints
**ppEnum
);
234 static HRESULT WINAPI
OLEFontImpl_FindConnectionPoint(
235 IConnectionPointContainer
* iface
,
237 IConnectionPoint
**ppCp
);
240 * Virtual function tables for the OLEFontImpl class.
242 static const IFontVtbl OLEFontImpl_VTable
=
244 OLEFontImpl_QueryInterface
,
247 OLEFontImpl_get_Name
,
248 OLEFontImpl_put_Name
,
249 OLEFontImpl_get_Size
,
250 OLEFontImpl_put_Size
,
251 OLEFontImpl_get_Bold
,
252 OLEFontImpl_put_Bold
,
253 OLEFontImpl_get_Italic
,
254 OLEFontImpl_put_Italic
,
255 OLEFontImpl_get_Underline
,
256 OLEFontImpl_put_Underline
,
257 OLEFontImpl_get_Strikethrough
,
258 OLEFontImpl_put_Strikethrough
,
259 OLEFontImpl_get_Weight
,
260 OLEFontImpl_put_Weight
,
261 OLEFontImpl_get_Charset
,
262 OLEFontImpl_put_Charset
,
263 OLEFontImpl_get_hFont
,
266 OLEFontImpl_SetRatio
,
267 OLEFontImpl_QueryTextMetrics
,
268 OLEFontImpl_AddRefHfont
,
269 OLEFontImpl_ReleaseHfont
,
273 static const IDispatchVtbl OLEFontImpl_IDispatch_VTable
=
275 OLEFontImpl_IDispatch_QueryInterface
,
276 OLEFontImpl_IDispatch_AddRef
,
277 OLEFontImpl_IDispatch_Release
,
278 OLEFontImpl_GetTypeInfoCount
,
279 OLEFontImpl_GetTypeInfo
,
280 OLEFontImpl_GetIDsOfNames
,
284 static const IPersistStreamVtbl OLEFontImpl_IPersistStream_VTable
=
286 OLEFontImpl_IPersistStream_QueryInterface
,
287 OLEFontImpl_IPersistStream_AddRef
,
288 OLEFontImpl_IPersistStream_Release
,
289 OLEFontImpl_GetClassID
,
293 OLEFontImpl_GetSizeMax
296 static const IConnectionPointContainerVtbl
297 OLEFontImpl_IConnectionPointContainer_VTable
=
299 OLEFontImpl_IConnectionPointContainer_QueryInterface
,
300 OLEFontImpl_IConnectionPointContainer_AddRef
,
301 OLEFontImpl_IConnectionPointContainer_Release
,
302 OLEFontImpl_EnumConnectionPoints
,
303 OLEFontImpl_FindConnectionPoint
306 static const IPersistPropertyBagVtbl OLEFontImpl_IPersistPropertyBag_VTable
;
307 static const IPersistStreamInitVtbl OLEFontImpl_IPersistStreamInit_VTable
;
309 /******************************************************************************
310 * OleCreateFontIndirect [OLEAUT32.420]
312 HRESULT WINAPI
OleCreateFontIndirect(
313 LPFONTDESC lpFontDesc
,
317 OLEFontImpl
* newFont
= 0;
320 TRACE("(%p, %s, %p)\n", lpFontDesc
, debugstr_guid(riid
), ppvObj
);
332 static const WCHAR fname
[] = { 'S','y','s','t','e','m',0 };
334 fd
.cbSizeofstruct
= sizeof(fd
);
335 fd
.lpstrName
= (WCHAR
*)fname
;
336 fd
.cySize
.s
.Lo
= 80000;
342 fd
.fStrikethrough
= 0;
347 * Try to construct a new instance of the class.
349 newFont
= OLEFontImpl_Construct(lpFontDesc
);
352 return E_OUTOFMEMORY
;
355 * Make sure it supports the interface required by the caller.
357 hr
= IFont_QueryInterface((IFont
*)newFont
, riid
, ppvObj
);
360 * Release the reference obtained in the constructor. If
361 * the QueryInterface was unsuccessful, it will free the class.
363 IFont_Release((IFont
*)newFont
);
369 /***********************************************************************
370 * Implementation of the OLEFontImpl class.
373 /***********************************************************************
374 * OLEFont_SendNotify (internal)
376 * Sends notification messages of changed properties to any interested
379 static void OLEFont_SendNotify(OLEFontImpl
* this, DISPID dispID
)
381 IEnumConnections
*pEnum
;
385 hres
= IConnectionPoint_EnumConnections(this->pCP
, &pEnum
);
386 if (FAILED(hres
)) /* When we have 0 connections. */
389 while(IEnumConnections_Next(pEnum
, 1, &CD
, NULL
) == S_OK
) {
390 IPropertyNotifySink
*sink
;
392 IUnknown_QueryInterface(CD
.pUnk
, &IID_IPropertyNotifySink
, (LPVOID
)&sink
);
393 IPropertyNotifySink_OnChanged(sink
, dispID
);
394 IPropertyNotifySink_Release(sink
);
395 IUnknown_Release(CD
.pUnk
);
397 IEnumConnections_Release(pEnum
);
401 /************************************************************************
402 * OLEFontImpl_Construct
404 * This method will construct a new instance of the OLEFontImpl
407 * The caller of this method must release the object when it's
410 static OLEFontImpl
* OLEFontImpl_Construct(LPFONTDESC fontDesc
)
412 OLEFontImpl
* newObject
= 0;
415 * Allocate space for the object.
417 newObject
= HeapAlloc(GetProcessHeap(), 0, sizeof(OLEFontImpl
));
423 * Initialize the virtual function table.
425 newObject
->lpVtbl
= &OLEFontImpl_VTable
;
426 newObject
->lpvtblIDispatch
= &OLEFontImpl_IDispatch_VTable
;
427 newObject
->lpvtblIPersistStream
= &OLEFontImpl_IPersistStream_VTable
;
428 newObject
->lpvtblIConnectionPointContainer
= &OLEFontImpl_IConnectionPointContainer_VTable
;
429 newObject
->lpvtblIPersistPropertyBag
= &OLEFontImpl_IPersistPropertyBag_VTable
;
430 newObject
->lpvtblIPersistStreamInit
= &OLEFontImpl_IPersistStreamInit_VTable
;
433 * Start with one reference count. The caller of this function
434 * must release the interface pointer when it is done.
439 * Copy the description of the font in the object.
441 assert(fontDesc
->cbSizeofstruct
>= sizeof(FONTDESC
));
443 newObject
->description
.cbSizeofstruct
= sizeof(FONTDESC
);
444 newObject
->description
.lpstrName
= HeapAlloc(GetProcessHeap(),
446 (lstrlenW(fontDesc
->lpstrName
)+1) * sizeof(WCHAR
));
447 strcpyW(newObject
->description
.lpstrName
, fontDesc
->lpstrName
);
448 newObject
->description
.cySize
= fontDesc
->cySize
;
449 newObject
->description
.sWeight
= fontDesc
->sWeight
;
450 newObject
->description
.sCharset
= fontDesc
->sCharset
;
451 newObject
->description
.fItalic
= fontDesc
->fItalic
;
452 newObject
->description
.fUnderline
= fontDesc
->fUnderline
;
453 newObject
->description
.fStrikethrough
= fontDesc
->fStrikethrough
;
456 * Initializing all the other members.
458 newObject
->gdiFont
= 0;
459 newObject
->fontLock
= 0;
460 newObject
->cyLogical
= 72L;
461 newObject
->cyHimetric
= 2540L;
462 CreateConnectionPoint((IUnknown
*)newObject
, &IID_IPropertyNotifySink
, &newObject
->pCP
);
463 TRACE("returning %p\n", newObject
);
467 /************************************************************************
468 * OLEFontImpl_Destroy
470 * This method is called by the Release method when the reference
471 * count goes down to 0. It will free all resources used by
474 static void OLEFontImpl_Destroy(OLEFontImpl
* fontDesc
)
476 TRACE("(%p)\n", fontDesc
);
478 HeapFree(GetProcessHeap(), 0, fontDesc
->description
.lpstrName
);
480 if (fontDesc
->gdiFont
!=0)
481 DeleteObject(fontDesc
->gdiFont
);
483 HeapFree(GetProcessHeap(), 0, fontDesc
);
486 /************************************************************************
487 * OLEFontImpl_QueryInterface (IUnknown)
489 * See Windows documentation for more details on IUnknown methods.
491 HRESULT WINAPI
OLEFontImpl_QueryInterface(
496 OLEFontImpl
*this = (OLEFontImpl
*)iface
;
497 TRACE("(%p)->(%s, %p)\n", this, debugstr_guid(riid
), ppvObject
);
500 * Perform a sanity check on the parameters.
502 if ( (this==0) || (ppvObject
==0) )
506 * Initialize the return parameter.
511 * Compare the riid with the interface IDs implemented by this object.
513 if (IsEqualGUID(&IID_IUnknown
, riid
))
514 *ppvObject
= (IFont
*)this;
515 if (IsEqualGUID(&IID_IFont
, riid
))
516 *ppvObject
= (IFont
*)this;
517 if (IsEqualGUID(&IID_IDispatch
, riid
))
518 *ppvObject
= (IDispatch
*)&(this->lpvtblIDispatch
);
519 if (IsEqualGUID(&IID_IFontDisp
, riid
))
520 *ppvObject
= (IDispatch
*)&(this->lpvtblIDispatch
);
521 if (IsEqualGUID(&IID_IPersistStream
, riid
))
522 *ppvObject
= (IPersistStream
*)&(this->lpvtblIPersistStream
);
523 if (IsEqualGUID(&IID_IConnectionPointContainer
, riid
))
524 *ppvObject
= (IConnectionPointContainer
*)&(this->lpvtblIConnectionPointContainer
);
525 if (IsEqualGUID(&IID_IPersistPropertyBag
, riid
))
526 *ppvObject
= (IPersistPropertyBag
*)&(this->lpvtblIPersistPropertyBag
);
527 if (IsEqualGUID(&IID_IPersistStreamInit
, riid
))
528 *ppvObject
= (IPersistStreamInit
*)&(this->lpvtblIPersistStreamInit
);
531 * Check that we obtained an interface.
535 FIXME("() : asking for unsupported interface %s\n",debugstr_guid(riid
));
536 return E_NOINTERFACE
;
538 OLEFontImpl_AddRef((IFont
*)this);
542 /************************************************************************
543 * OLEFontImpl_AddRef (IUnknown)
545 * See Windows documentation for more details on IUnknown methods.
547 ULONG WINAPI
OLEFontImpl_AddRef(
550 OLEFontImpl
*this = (OLEFontImpl
*)iface
;
551 TRACE("(%p)->(ref=%ld)\n", this, this->ref
);
552 return InterlockedIncrement(&this->ref
);
555 /************************************************************************
556 * OLEFontImpl_Release (IUnknown)
558 * See Windows documentation for more details on IUnknown methods.
560 ULONG WINAPI
OLEFontImpl_Release(
563 OLEFontImpl
*this = (OLEFontImpl
*)iface
;
565 TRACE("(%p)->(ref=%ld)\n", this, this->ref
);
568 * Decrease the reference count on this object.
570 ret
= InterlockedDecrement(&this->ref
);
573 * If the reference count goes down to 0, perform suicide.
575 if (ret
==0) OLEFontImpl_Destroy(this);
580 /************************************************************************
581 * OLEFontImpl_get_Name (IFont)
583 * See Windows documentation for more details on IFont methods.
585 static HRESULT WINAPI
OLEFontImpl_get_Name(
589 OLEFontImpl
*this = (OLEFontImpl
*)iface
;
590 TRACE("(%p)->(%p)\n", this, pname
);
597 if (this->description
.lpstrName
!=0)
598 *pname
= SysAllocString(this->description
.lpstrName
);
605 /************************************************************************
606 * OLEFontImpl_put_Name (IFont)
608 * See Windows documentation for more details on IFont methods.
610 static HRESULT WINAPI
OLEFontImpl_put_Name(
614 OLEFontImpl
*this = (OLEFontImpl
*)iface
;
615 TRACE("(%p)->(%p)\n", this, name
);
617 if (this->description
.lpstrName
==0)
619 this->description
.lpstrName
= HeapAlloc(GetProcessHeap(),
621 (lstrlenW(name
)+1) * sizeof(WCHAR
));
625 this->description
.lpstrName
= HeapReAlloc(GetProcessHeap(),
627 this->description
.lpstrName
,
628 (lstrlenW(name
)+1) * sizeof(WCHAR
));
631 if (this->description
.lpstrName
==0)
632 return E_OUTOFMEMORY
;
634 strcpyW(this->description
.lpstrName
, name
);
635 TRACE("new name %s\n", debugstr_w(this->description
.lpstrName
));
636 OLEFont_SendNotify(this, DISPID_FONT_NAME
);
640 /************************************************************************
641 * OLEFontImpl_get_Size (IFont)
643 * See Windows documentation for more details on IFont methods.
645 static HRESULT WINAPI
OLEFontImpl_get_Size(
649 OLEFontImpl
*this = (OLEFontImpl
*)iface
;
650 TRACE("(%p)->(%p)\n", this, psize
);
659 psize
->s
.Lo
= this->description
.cySize
.s
.Lo
;
664 /************************************************************************
665 * OLEFontImpl_put_Size (IFont)
667 * See Windows documentation for more details on IFont methods.
669 static HRESULT WINAPI
OLEFontImpl_put_Size(
673 OLEFontImpl
*this = (OLEFontImpl
*)iface
;
674 TRACE("(%p)->(%ld)\n", this, size
.s
.Lo
);
675 this->description
.cySize
.s
.Hi
= 0;
676 this->description
.cySize
.s
.Lo
= size
.s
.Lo
;
677 OLEFont_SendNotify(this, DISPID_FONT_SIZE
);
682 /************************************************************************
683 * OLEFontImpl_get_Bold (IFont)
685 * See Windows documentation for more details on IFont methods.
687 static HRESULT WINAPI
OLEFontImpl_get_Bold(
691 OLEFontImpl
*this = (OLEFontImpl
*)iface
;
692 TRACE("(%p)->(%p)\n", this, pbold
);
699 *pbold
= this->description
.sWeight
> 550;
704 /************************************************************************
705 * OLEFontImpl_put_Bold (IFont)
707 * See Windows documentation for more details on IFont methods.
709 static HRESULT WINAPI
OLEFontImpl_put_Bold(
713 OLEFontImpl
*this = (OLEFontImpl
*)iface
;
714 TRACE("(%p)->(%d)\n", this, bold
);
715 this->description
.sWeight
= bold
? FW_BOLD
: FW_NORMAL
;
716 OLEFont_SendNotify(this, DISPID_FONT_BOLD
);
721 /************************************************************************
722 * OLEFontImpl_get_Italic (IFont)
724 * See Windows documentation for more details on IFont methods.
726 static HRESULT WINAPI
OLEFontImpl_get_Italic(
730 OLEFontImpl
*this = (OLEFontImpl
*)iface
;
731 TRACE("(%p)->(%p)\n", this, pitalic
);
738 *pitalic
= this->description
.fItalic
;
743 /************************************************************************
744 * OLEFontImpl_put_Italic (IFont)
746 * See Windows documentation for more details on IFont methods.
748 static HRESULT WINAPI
OLEFontImpl_put_Italic(
752 OLEFontImpl
*this = (OLEFontImpl
*)iface
;
753 TRACE("(%p)->(%d)\n", this, italic
);
755 this->description
.fItalic
= italic
;
757 OLEFont_SendNotify(this, DISPID_FONT_ITALIC
);
761 /************************************************************************
762 * OLEFontImpl_get_Underline (IFont)
764 * See Windows documentation for more details on IFont methods.
766 static HRESULT WINAPI
OLEFontImpl_get_Underline(
770 OLEFontImpl
*this = (OLEFontImpl
*)iface
;
771 TRACE("(%p)->(%p)\n", this, punderline
);
779 *punderline
= this->description
.fUnderline
;
784 /************************************************************************
785 * OLEFontImpl_put_Underline (IFont)
787 * See Windows documentation for more details on IFont methods.
789 static HRESULT WINAPI
OLEFontImpl_put_Underline(
793 OLEFontImpl
*this = (OLEFontImpl
*)iface
;
794 TRACE("(%p)->(%d)\n", this, underline
);
796 this->description
.fUnderline
= underline
;
798 OLEFont_SendNotify(this, DISPID_FONT_UNDER
);
802 /************************************************************************
803 * OLEFontImpl_get_Strikethrough (IFont)
805 * See Windows documentation for more details on IFont methods.
807 static HRESULT WINAPI
OLEFontImpl_get_Strikethrough(
809 BOOL
* pstrikethrough
)
811 OLEFontImpl
*this = (OLEFontImpl
*)iface
;
812 TRACE("(%p)->(%p)\n", this, pstrikethrough
);
817 if (pstrikethrough
==0)
820 *pstrikethrough
= this->description
.fStrikethrough
;
825 /************************************************************************
826 * OLEFontImpl_put_Strikethrough (IFont)
828 * See Windows documentation for more details on IFont methods.
830 static HRESULT WINAPI
OLEFontImpl_put_Strikethrough(
834 OLEFontImpl
*this = (OLEFontImpl
*)iface
;
835 TRACE("(%p)->(%d)\n", this, strikethrough
);
837 this->description
.fStrikethrough
= strikethrough
;
838 OLEFont_SendNotify(this, DISPID_FONT_STRIKE
);
843 /************************************************************************
844 * OLEFontImpl_get_Weight (IFont)
846 * See Windows documentation for more details on IFont methods.
848 static HRESULT WINAPI
OLEFontImpl_get_Weight(
852 OLEFontImpl
*this = (OLEFontImpl
*)iface
;
853 TRACE("(%p)->(%p)\n", this, pweight
);
861 *pweight
= this->description
.sWeight
;
866 /************************************************************************
867 * OLEFontImpl_put_Weight (IFont)
869 * See Windows documentation for more details on IFont methods.
871 static HRESULT WINAPI
OLEFontImpl_put_Weight(
875 OLEFontImpl
*this = (OLEFontImpl
*)iface
;
876 TRACE("(%p)->(%d)\n", this, weight
);
878 this->description
.sWeight
= weight
;
880 OLEFont_SendNotify(this, DISPID_FONT_WEIGHT
);
884 /************************************************************************
885 * OLEFontImpl_get_Charset (IFont)
887 * See Windows documentation for more details on IFont methods.
889 static HRESULT WINAPI
OLEFontImpl_get_Charset(
893 OLEFontImpl
*this = (OLEFontImpl
*)iface
;
894 TRACE("(%p)->(%p)\n", this, pcharset
);
902 *pcharset
= this->description
.sCharset
;
907 /************************************************************************
908 * OLEFontImpl_put_Charset (IFont)
910 * See Windows documentation for more details on IFont methods.
912 static HRESULT WINAPI
OLEFontImpl_put_Charset(
916 OLEFontImpl
*this = (OLEFontImpl
*)iface
;
917 TRACE("(%p)->(%d)\n", this, charset
);
919 this->description
.sCharset
= charset
;
920 OLEFont_SendNotify(this, DISPID_FONT_CHARSET
);
925 /************************************************************************
926 * OLEFontImpl_get_hFont (IFont)
928 * See Windows documentation for more details on IFont methods.
930 static HRESULT WINAPI
OLEFontImpl_get_hFont(
934 OLEFontImpl
*this = (OLEFontImpl
*)iface
;
935 TRACE("(%p)->(%p)\n", this, phfont
);
940 * Realize the font if necessary
942 if (this->gdiFont
==0)
949 * The height of the font returned by the get_Size property is the
950 * height of the font in points multiplied by 10000... Using some
951 * simple conversions and the ratio given by the application, it can
952 * be converted to a height in pixels.
954 IFont_get_Size(iface
, &cySize
);
956 /* Standard ratio is 72 / 2540, or 18 / 635 in lowest terms. */
957 /* Ratio is applied here relative to the standard. */
958 fontHeight
= MulDiv( cySize
.s
.Lo
, this->cyLogical
*635, this->cyHimetric
*18 );
960 memset(&logFont
, 0, sizeof(LOGFONTW
));
962 logFont
.lfHeight
= ((fontHeight
%10000L)>5000L) ? (-fontHeight
/10000L)-1 :
963 (-fontHeight
/10000L);
964 logFont
.lfItalic
= this->description
.fItalic
;
965 logFont
.lfUnderline
= this->description
.fUnderline
;
966 logFont
.lfStrikeOut
= this->description
.fStrikethrough
;
967 logFont
.lfWeight
= this->description
.sWeight
;
968 logFont
.lfCharSet
= this->description
.sCharset
;
969 logFont
.lfOutPrecision
= OUT_CHARACTER_PRECIS
;
970 logFont
.lfClipPrecision
= CLIP_DEFAULT_PRECIS
;
971 logFont
.lfQuality
= DEFAULT_QUALITY
;
972 logFont
.lfPitchAndFamily
= DEFAULT_PITCH
;
973 strcpyW(logFont
.lfFaceName
,this->description
.lpstrName
);
975 this->gdiFont
= CreateFontIndirectW(&logFont
);
978 *phfont
= this->gdiFont
;
979 TRACE("Returning %p\n", *phfont
);
983 /************************************************************************
984 * OLEFontImpl_Clone (IFont)
986 * See Windows documentation for more details on IFont methods.
988 static HRESULT WINAPI
OLEFontImpl_Clone(
992 OLEFontImpl
* newObject
= 0;
996 OLEFontImpl
*this = (OLEFontImpl
*)iface
;
997 TRACE("(%p)->(%p)\n", this, ppfont
);
1005 * Allocate space for the object.
1007 newObject
= HeapAlloc(GetProcessHeap(), 0, sizeof(OLEFontImpl
));
1009 if (newObject
==NULL
)
1010 return E_OUTOFMEMORY
;
1014 /* We need to alloc new memory for the string, otherwise
1015 * we free memory twice.
1017 newObject
->description
.lpstrName
= HeapAlloc(
1019 (1+strlenW(this->description
.lpstrName
))*2
1021 strcpyW(newObject
->description
.lpstrName
, this->description
.lpstrName
);
1022 /* We need to clone the HFONT too. This is just cut & paste from above */
1023 IFont_get_Size(iface
, &cySize
);
1025 fontHeight
= MulDiv(cySize
.s
.Lo
, this->cyLogical
*635,this->cyHimetric
*18);
1027 memset(&logFont
, 0, sizeof(LOGFONTW
));
1029 logFont
.lfHeight
= ((fontHeight
%10000L)>5000L) ? (-fontHeight
/10000L)-1 :
1030 (-fontHeight
/10000L);
1031 logFont
.lfItalic
= this->description
.fItalic
;
1032 logFont
.lfUnderline
= this->description
.fUnderline
;
1033 logFont
.lfStrikeOut
= this->description
.fStrikethrough
;
1034 logFont
.lfWeight
= this->description
.sWeight
;
1035 logFont
.lfCharSet
= this->description
.sCharset
;
1036 logFont
.lfOutPrecision
= OUT_CHARACTER_PRECIS
;
1037 logFont
.lfClipPrecision
= CLIP_DEFAULT_PRECIS
;
1038 logFont
.lfQuality
= DEFAULT_QUALITY
;
1039 logFont
.lfPitchAndFamily
= DEFAULT_PITCH
;
1040 strcpyW(logFont
.lfFaceName
,this->description
.lpstrName
);
1042 newObject
->gdiFont
= CreateFontIndirectW(&logFont
);
1045 /* The cloned object starts with a reference count of 1 */
1048 *ppfont
= (IFont
*)newObject
;
1053 /************************************************************************
1054 * OLEFontImpl_IsEqual (IFont)
1056 * See Windows documentation for more details on IFont methods.
1058 static HRESULT WINAPI
OLEFontImpl_IsEqual(
1062 FIXME("(%p, %p), stub!\n",iface
,pFontOther
);
1066 /************************************************************************
1067 * OLEFontImpl_SetRatio (IFont)
1069 * See Windows documentation for more details on IFont methods.
1071 static HRESULT WINAPI
OLEFontImpl_SetRatio(
1076 OLEFontImpl
*this = (OLEFontImpl
*)iface
;
1077 TRACE("(%p)->(%ld, %ld)\n", this, cyLogical
, cyHimetric
);
1079 this->cyLogical
= cyLogical
;
1080 this->cyHimetric
= cyHimetric
;
1085 /************************************************************************
1086 * OLEFontImpl_QueryTextMetrics (IFont)
1088 * See Windows documentation for more details on IFont methods.
1090 static HRESULT WINAPI
OLEFontImpl_QueryTextMetrics(
1095 HFONT hOldFont
, hNewFont
;
1098 OLEFontImpl_get_hFont(iface
, &hNewFont
);
1099 hOldFont
= SelectObject(hdcRef
, hNewFont
);
1100 GetTextMetricsW(hdcRef
, ptm
);
1101 SelectObject(hdcRef
, hOldFont
);
1102 ReleaseDC(0, hdcRef
);
1106 /************************************************************************
1107 * OLEFontImpl_AddRefHfont (IFont)
1109 * See Windows documentation for more details on IFont methods.
1111 static HRESULT WINAPI
OLEFontImpl_AddRefHfont(
1115 OLEFontImpl
*this = (OLEFontImpl
*)iface
;
1116 TRACE("(%p)->(%p) (lock=%ld)\n", this, hfont
, this->fontLock
);
1118 if ( (hfont
== 0) ||
1119 (hfont
!= this->gdiFont
) )
1120 return E_INVALIDARG
;
1127 /************************************************************************
1128 * OLEFontImpl_ReleaseHfont (IFont)
1130 * See Windows documentation for more details on IFont methods.
1132 static HRESULT WINAPI
OLEFontImpl_ReleaseHfont(
1136 OLEFontImpl
*this = (OLEFontImpl
*)iface
;
1137 TRACE("(%p)->(%p) (lock=%ld)\n", this, hfont
, this->fontLock
);
1139 if ( (hfont
== 0) ||
1140 (hfont
!= this->gdiFont
) )
1141 return E_INVALIDARG
;
1146 * If we just released our last font reference, destroy it.
1148 if (this->fontLock
==0)
1150 DeleteObject(this->gdiFont
);
1157 /************************************************************************
1158 * OLEFontImpl_SetHdc (IFont)
1160 * See Windows documentation for more details on IFont methods.
1162 static HRESULT WINAPI
OLEFontImpl_SetHdc(
1166 OLEFontImpl
*this = (OLEFontImpl
*)iface
;
1167 FIXME("(%p)->(%p): Stub\n", this, hdc
);
1171 /************************************************************************
1172 * OLEFontImpl_IDispatch_QueryInterface (IUnknown)
1174 * See Windows documentation for more details on IUnknown methods.
1176 static HRESULT WINAPI
OLEFontImpl_IDispatch_QueryInterface(
1181 OLEFontImpl
*this = impl_from_IDispatch(iface
);
1183 return IFont_QueryInterface((IFont
*)this, riid
, ppvoid
);
1186 /************************************************************************
1187 * OLEFontImpl_IDispatch_Release (IUnknown)
1189 * See Windows documentation for more details on IUnknown methods.
1191 static ULONG WINAPI
OLEFontImpl_IDispatch_Release(
1194 OLEFontImpl
*this = impl_from_IDispatch(iface
);
1196 return IFont_Release((IFont
*)this);
1199 /************************************************************************
1200 * OLEFontImpl_IDispatch_AddRef (IUnknown)
1202 * See Windows documentation for more details on IUnknown methods.
1204 static ULONG WINAPI
OLEFontImpl_IDispatch_AddRef(
1207 OLEFontImpl
*this = impl_from_IDispatch(iface
);
1209 return IFont_AddRef((IFont
*)this);
1212 /************************************************************************
1213 * OLEFontImpl_GetTypeInfoCount (IDispatch)
1215 * See Windows documentation for more details on IDispatch methods.
1217 static HRESULT WINAPI
OLEFontImpl_GetTypeInfoCount(
1219 unsigned int* pctinfo
)
1221 OLEFontImpl
*this = impl_from_IDispatch(iface
);
1222 FIXME("(%p)->(%p): Stub\n", this, pctinfo
);
1227 /************************************************************************
1228 * OLEFontImpl_GetTypeInfo (IDispatch)
1230 * See Windows documentation for more details on IDispatch methods.
1232 static HRESULT WINAPI
OLEFontImpl_GetTypeInfo(
1236 ITypeInfo
** ppTInfo
)
1238 static const WCHAR stdole2tlb
[] = {'s','t','d','o','l','e','2','.','t','l','b',0};
1242 OLEFontImpl
*this = impl_from_IDispatch(iface
);
1243 TRACE("(%p, iTInfo=%d, lcid=%04x, %p)\n", this, iTInfo
, (int)lcid
, ppTInfo
);
1246 hres
= LoadTypeLib(stdole2tlb
, &tl
);
1248 ERR("Could not load the stdole2.tlb?\n");
1251 hres
= ITypeLib_GetTypeInfoOfGuid(tl
, &IID_IFontDisp
, ppTInfo
);
1253 FIXME("Did not IDispatch typeinfo from typelib, hres %lx\n",hres
);
1258 /************************************************************************
1259 * OLEFontImpl_GetIDsOfNames (IDispatch)
1261 * See Windows documentation for more details on IDispatch methods.
1263 static HRESULT WINAPI
OLEFontImpl_GetIDsOfNames(
1266 LPOLESTR
* rgszNames
,
1271 OLEFontImpl
*this = impl_from_IDispatch(iface
);
1272 FIXME("(%p,%s,%p,%d,%04x,%p), stub!\n", this, debugstr_guid(riid
), rgszNames
,
1273 cNames
, (int)lcid
, rgDispId
1278 /************************************************************************
1279 * OLEFontImpl_Invoke (IDispatch)
1281 * See Windows documentation for more details on IDispatch methods.
1283 * Note: Do not call _put_Xxx methods, since setting things here
1284 * should not call notify functions as I found out debugging the generic
1287 static HRESULT WINAPI
OLEFontImpl_Invoke(
1289 DISPID dispIdMember
,
1293 DISPPARAMS
* pDispParams
,
1294 VARIANT
* pVarResult
,
1295 EXCEPINFO
* pExepInfo
,
1298 OLEFontImpl
*this = impl_from_IDispatch(iface
);
1299 OLEFontImpl
*xthis
= (OLEFontImpl
*)this;
1301 switch (dispIdMember
) {
1302 case DISPID_FONT_NAME
:
1304 case DISPATCH_PROPERTYGET
:
1305 case DISPATCH_PROPERTYGET
|DISPATCH_METHOD
:
1306 V_VT(pVarResult
) = VT_BSTR
;
1307 return OLEFontImpl_get_Name((IFont
*)this, &V_BSTR(pVarResult
));
1308 case DISPATCH_PROPERTYPUT
: {
1312 if (V_VT(&pDispParams
->rgvarg
[0]) == VT_DISPATCH
) {
1316 hr
= IUnknown_QueryInterface(V_DISPATCH(&pDispParams
->rgvarg
[0]), &IID_IFont
, (void **) &font
);
1319 FIXME("dispatch value for name property is not an OleFont, returning hr=0x%lx\n", hr
);
1323 hr
= IFont_get_Name(font
, &name
); /* this allocates a new BSTR so free it later */
1324 if (FAILED(hr
)) return hr
;
1326 IUnknown_Release(font
);
1329 } else if (V_VT(&pDispParams
->rgvarg
[0]) == VT_BSTR
) {
1330 name
= V_BSTR(&pDispParams
->rgvarg
[0]);
1333 FIXME("app is trying to set name property with a non BSTR, non dispatch value. returning E_FAIL\n");
1337 TRACE("name is %s\n", debugstr_w(name
));
1339 if (!xthis
->description
.lpstrName
)
1340 xthis
->description
.lpstrName
= HeapAlloc(GetProcessHeap(), 0, (lstrlenW(name
)+1) * sizeof(WCHAR
));
1342 xthis
->description
.lpstrName
= HeapReAlloc(GetProcessHeap(), 0, xthis
->description
.lpstrName
, (lstrlenW(name
)+1) * sizeof(WCHAR
));
1344 if (xthis
->description
.lpstrName
==0)
1345 return E_OUTOFMEMORY
;
1346 strcpyW(xthis
->description
.lpstrName
, name
);
1348 if (freename
) SysFreeString(name
);
1354 case DISPID_FONT_BOLD
:
1356 case DISPATCH_PROPERTYGET
:
1357 case DISPATCH_PROPERTYGET
|DISPATCH_METHOD
:
1358 V_VT(pVarResult
) = VT_BOOL
;
1359 return OLEFontImpl_get_Bold((IFont
*)this, (BOOL
*)&V_BOOL(pVarResult
));
1360 case DISPATCH_PROPERTYPUT
:
1361 if (V_VT(&pDispParams
->rgvarg
[0]) != VT_BOOL
) {
1362 FIXME("DISPID_FONT_BOLD/put, vt is %d, not VT_BOOL.\n",V_VT(&pDispParams
->rgvarg
[0]));
1365 xthis
->description
.sWeight
= V_BOOL(&pDispParams
->rgvarg
[0]) ? FW_BOLD
: FW_NORMAL
;
1370 case DISPID_FONT_ITALIC
:
1372 case DISPATCH_PROPERTYGET
:
1373 case DISPATCH_PROPERTYGET
|DISPATCH_METHOD
:
1374 V_VT(pVarResult
) = VT_BOOL
;
1375 return OLEFontImpl_get_Italic((IFont
*)this, (BOOL
*)&V_BOOL(pVarResult
));
1376 case DISPATCH_PROPERTYPUT
:
1377 if (V_VT(&pDispParams
->rgvarg
[0]) != VT_BOOL
) {
1378 FIXME("DISPID_FONT_ITALIC/put, vt is %d, not VT_BOOL.\n",V_VT(&pDispParams
->rgvarg
[0]));
1381 xthis
->description
.fItalic
= V_BOOL(&pDispParams
->rgvarg
[0]);
1386 case DISPID_FONT_UNDER
:
1388 case DISPATCH_PROPERTYGET
:
1389 case DISPATCH_PROPERTYGET
|DISPATCH_METHOD
:
1390 V_VT(pVarResult
) = VT_BOOL
;
1391 return OLEFontImpl_get_Underline((IFont
*)this, (BOOL
*)&V_BOOL(pVarResult
));
1392 case DISPATCH_PROPERTYPUT
:
1393 if (V_VT(&pDispParams
->rgvarg
[0]) != VT_BOOL
) {
1394 FIXME("DISPID_FONT_UNDER/put, vt is %d, not VT_BOOL.\n",V_VT(&pDispParams
->rgvarg
[0]));
1397 xthis
->description
.fUnderline
= V_BOOL(&pDispParams
->rgvarg
[0]);
1402 case DISPID_FONT_STRIKE
:
1404 case DISPATCH_PROPERTYGET
:
1405 case DISPATCH_PROPERTYGET
|DISPATCH_METHOD
:
1406 V_VT(pVarResult
) = VT_BOOL
;
1407 return OLEFontImpl_get_Strikethrough((IFont
*)this, (BOOL
*)&V_BOOL(pVarResult
));
1408 case DISPATCH_PROPERTYPUT
:
1409 if (V_VT(&pDispParams
->rgvarg
[0]) != VT_BOOL
) {
1410 FIXME("DISPID_FONT_STRIKE/put, vt is %d, not VT_BOOL.\n",V_VT(&pDispParams
->rgvarg
[0]));
1413 xthis
->description
.fStrikethrough
= V_BOOL(&pDispParams
->rgvarg
[0]);
1418 case DISPID_FONT_SIZE
:
1420 case DISPATCH_PROPERTYPUT
: {
1421 assert (pDispParams
->cArgs
== 1);
1422 xthis
->description
.cySize
.s
.Hi
= 0;
1423 if (V_VT(&pDispParams
->rgvarg
[0]) != VT_CY
) {
1424 if (V_VT(&pDispParams
->rgvarg
[0]) == VT_I2
) {
1425 xthis
->description
.cySize
.s
.Lo
= V_I2(&pDispParams
->rgvarg
[0]) * 10000;
1427 FIXME("property put for Size with vt %d unsupported!\n",V_VT(&pDispParams
->rgvarg
[0]));
1430 xthis
->description
.cySize
.s
.Lo
= V_CY(&pDispParams
->rgvarg
[0]).s
.Lo
;
1434 case DISPATCH_PROPERTYGET
:
1435 case DISPATCH_PROPERTYGET
|DISPATCH_METHOD
:
1436 V_VT(pVarResult
) = VT_CY
;
1437 return OLEFontImpl_get_Size((IFont
*)this, &V_CY(pVarResult
));
1440 case DISPID_FONT_CHARSET
:
1442 case DISPATCH_PROPERTYPUT
:
1443 assert (pDispParams
->cArgs
== 1);
1444 if (V_VT(&pDispParams
->rgvarg
[0]) != VT_I2
)
1445 FIXME("varg of first disparg is not VT_I2, but %d\n",V_VT(&pDispParams
->rgvarg
[0]));
1446 xthis
->description
.sCharset
= V_I2(&pDispParams
->rgvarg
[0]);
1448 case DISPATCH_PROPERTYGET
:
1449 case DISPATCH_PROPERTYGET
|DISPATCH_METHOD
:
1450 V_VT(pVarResult
) = VT_I2
;
1451 return OLEFontImpl_get_Charset((IFont
*)this, &V_I2(pVarResult
));
1455 FIXME("%p->(%ld,%s,%lx,%x,%p,%p,%p,%p), unhandled dispid/flag!\n",
1456 this,dispIdMember
,debugstr_guid(riid
),lcid
,
1457 wFlags
,pDispParams
,pVarResult
,pExepInfo
,puArgErr
1462 /************************************************************************
1463 * OLEFontImpl_IPersistStream_QueryInterface (IUnknown)
1465 * See Windows documentation for more details on IUnknown methods.
1467 static HRESULT WINAPI
OLEFontImpl_IPersistStream_QueryInterface(
1468 IPersistStream
* iface
,
1472 OLEFontImpl
*this = impl_from_IPersistStream(iface
);
1474 return IFont_QueryInterface((IFont
*)this, riid
, ppvoid
);
1477 /************************************************************************
1478 * OLEFontImpl_IPersistStream_Release (IUnknown)
1480 * See Windows documentation for more details on IUnknown methods.
1482 static ULONG WINAPI
OLEFontImpl_IPersistStream_Release(
1483 IPersistStream
* iface
)
1485 OLEFontImpl
*this = impl_from_IPersistStream(iface
);
1487 return IFont_Release((IFont
*)this);
1490 /************************************************************************
1491 * OLEFontImpl_IPersistStream_AddRef (IUnknown)
1493 * See Windows documentation for more details on IUnknown methods.
1495 static ULONG WINAPI
OLEFontImpl_IPersistStream_AddRef(
1496 IPersistStream
* iface
)
1498 OLEFontImpl
*this = impl_from_IPersistStream(iface
);
1500 return IFont_AddRef((IFont
*)this);
1503 /************************************************************************
1504 * OLEFontImpl_GetClassID (IPersistStream)
1506 * See Windows documentation for more details on IPersistStream methods.
1508 static HRESULT WINAPI
OLEFontImpl_GetClassID(
1509 IPersistStream
* iface
,
1512 TRACE("(%p,%p)\n",iface
,pClassID
);
1516 memcpy(pClassID
, &CLSID_StdFont
, sizeof(CLSID_StdFont
));
1521 /************************************************************************
1522 * OLEFontImpl_IsDirty (IPersistStream)
1524 * See Windows documentation for more details on IPersistStream methods.
1526 static HRESULT WINAPI
OLEFontImpl_IsDirty(
1527 IPersistStream
* iface
)
1529 TRACE("(%p)\n",iface
);
1533 /************************************************************************
1534 * OLEFontImpl_Load (IPersistStream)
1536 * See Windows documentation for more details on IPersistStream methods.
1538 * This is the format of the standard font serialization as far as I
1541 * Offset Type Value Comment
1542 * 0x0000 Byte Unknown Probably a version number, contains 0x01
1543 * 0x0001 Short Charset Charset value from the FONTDESC structure
1544 * 0x0003 Byte Attributes Flags defined as follows:
1546 * 00000100 - Underline
1547 * 00001000 - Strikethrough
1548 * 0x0004 Short Weight Weight value from FONTDESC structure
1549 * 0x0006 DWORD size "Low" portion of the cySize member of the FONTDESC
1551 * 0x000A Byte name length Length of the font name string (no null character)
1552 * 0x000B String name Name of the font (ASCII, no nul character)
1554 static HRESULT WINAPI
OLEFontImpl_Load(
1555 IPersistStream
* iface
,
1556 IStream
* pLoadStream
)
1558 char readBuffer
[0x100];
1565 OLEFontImpl
*this = impl_from_IPersistStream(iface
);
1568 * Read the version byte
1570 IStream_Read(pLoadStream
, &bVersion
, 1, &cbRead
);
1579 IStream_Read(pLoadStream
, &this->description
.sCharset
, 2, &cbRead
);
1587 IStream_Read(pLoadStream
, &bAttributes
, 1, &cbRead
);
1592 this->description
.fItalic
= (bAttributes
& FONTPERSIST_ITALIC
) != 0;
1593 this->description
.fStrikethrough
= (bAttributes
& FONTPERSIST_STRIKETHROUGH
) != 0;
1594 this->description
.fUnderline
= (bAttributes
& FONTPERSIST_UNDERLINE
) != 0;
1599 IStream_Read(pLoadStream
, &this->description
.sWeight
, 2, &cbRead
);
1607 IStream_Read(pLoadStream
, &this->description
.cySize
.s
.Lo
, 4, &cbRead
);
1612 this->description
.cySize
.s
.Hi
= 0;
1617 IStream_Read(pLoadStream
, &bStringSize
, 1, &cbRead
);
1622 IStream_Read(pLoadStream
, readBuffer
, bStringSize
, &cbRead
);
1624 if (cbRead
!=bStringSize
)
1627 HeapFree(GetProcessHeap(), 0, this->description
.lpstrName
);
1629 len
= MultiByteToWideChar( CP_ACP
, 0, readBuffer
, bStringSize
, NULL
, 0 );
1630 this->description
.lpstrName
= HeapAlloc( GetProcessHeap(), 0, (len
+1) * sizeof(WCHAR
) );
1631 MultiByteToWideChar( CP_ACP
, 0, readBuffer
, bStringSize
, this->description
.lpstrName
, len
);
1632 this->description
.lpstrName
[len
] = 0;
1634 /* Ensure use of this font causes a new one to be created @@@@ */
1635 DeleteObject(this->gdiFont
);
1641 /************************************************************************
1642 * OLEFontImpl_Save (IPersistStream)
1644 * See Windows documentation for more details on IPersistStream methods.
1646 static HRESULT WINAPI
OLEFontImpl_Save(
1647 IPersistStream
* iface
,
1648 IStream
* pOutStream
,
1651 char* writeBuffer
= NULL
;
1653 BYTE bVersion
= 0x01;
1657 OLEFontImpl
*this = impl_from_IPersistStream(iface
);
1660 * Read the version byte
1662 IStream_Write(pOutStream
, &bVersion
, 1, &cbWritten
);
1670 IStream_Write(pOutStream
, &this->description
.sCharset
, 2, &cbWritten
);
1680 if (this->description
.fItalic
)
1681 bAttributes
|= FONTPERSIST_ITALIC
;
1683 if (this->description
.fStrikethrough
)
1684 bAttributes
|= FONTPERSIST_STRIKETHROUGH
;
1686 if (this->description
.fUnderline
)
1687 bAttributes
|= FONTPERSIST_UNDERLINE
;
1689 IStream_Write(pOutStream
, &bAttributes
, 1, &cbWritten
);
1697 IStream_Write(pOutStream
, &this->description
.sWeight
, 2, &cbWritten
);
1705 IStream_Write(pOutStream
, &this->description
.cySize
.s
.Lo
, 4, &cbWritten
);
1713 if (this->description
.lpstrName
!=0)
1714 bStringSize
= WideCharToMultiByte( CP_ACP
, 0, this->description
.lpstrName
,
1715 strlenW(this->description
.lpstrName
), NULL
, 0, NULL
, NULL
);
1719 IStream_Write(pOutStream
, &bStringSize
, 1, &cbWritten
);
1726 if (!(writeBuffer
= HeapAlloc( GetProcessHeap(), 0, bStringSize
))) return E_OUTOFMEMORY
;
1727 WideCharToMultiByte( CP_ACP
, 0, this->description
.lpstrName
,
1728 strlenW(this->description
.lpstrName
),
1729 writeBuffer
, bStringSize
, NULL
, NULL
);
1731 IStream_Write(pOutStream
, writeBuffer
, bStringSize
, &cbWritten
);
1732 HeapFree(GetProcessHeap(), 0, writeBuffer
);
1734 if (cbWritten
!=bStringSize
)
1741 /************************************************************************
1742 * OLEFontImpl_GetSizeMax (IPersistStream)
1744 * See Windows documentation for more details on IPersistStream methods.
1746 static HRESULT WINAPI
OLEFontImpl_GetSizeMax(
1747 IPersistStream
* iface
,
1748 ULARGE_INTEGER
* pcbSize
)
1750 OLEFontImpl
*this = impl_from_IPersistStream(iface
);
1755 pcbSize
->u
.HighPart
= 0;
1756 pcbSize
->u
.LowPart
= 0;
1758 pcbSize
->u
.LowPart
+= sizeof(BYTE
); /* Version */
1759 pcbSize
->u
.LowPart
+= sizeof(WORD
); /* Lang code */
1760 pcbSize
->u
.LowPart
+= sizeof(BYTE
); /* Flags */
1761 pcbSize
->u
.LowPart
+= sizeof(WORD
); /* Weight */
1762 pcbSize
->u
.LowPart
+= sizeof(DWORD
); /* Size */
1763 pcbSize
->u
.LowPart
+= sizeof(BYTE
); /* StrLength */
1765 if (this->description
.lpstrName
!=0)
1766 pcbSize
->u
.LowPart
+= lstrlenW(this->description
.lpstrName
);
1771 /************************************************************************
1772 * OLEFontImpl_IConnectionPointContainer_QueryInterface (IUnknown)
1774 * See Windows documentation for more details on IUnknown methods.
1776 static HRESULT WINAPI
OLEFontImpl_IConnectionPointContainer_QueryInterface(
1777 IConnectionPointContainer
* iface
,
1781 OLEFontImpl
*this = impl_from_IConnectionPointContainer(iface
);
1783 return IFont_QueryInterface((IFont
*)this, riid
, ppvoid
);
1786 /************************************************************************
1787 * OLEFontImpl_IConnectionPointContainer_Release (IUnknown)
1789 * See Windows documentation for more details on IUnknown methods.
1791 static ULONG WINAPI
OLEFontImpl_IConnectionPointContainer_Release(
1792 IConnectionPointContainer
* iface
)
1794 OLEFontImpl
*this = impl_from_IConnectionPointContainer(iface
);
1796 return IFont_Release((IFont
*)this);
1799 /************************************************************************
1800 * OLEFontImpl_IConnectionPointContainer_AddRef (IUnknown)
1802 * See Windows documentation for more details on IUnknown methods.
1804 static ULONG WINAPI
OLEFontImpl_IConnectionPointContainer_AddRef(
1805 IConnectionPointContainer
* iface
)
1807 OLEFontImpl
*this = impl_from_IConnectionPointContainer(iface
);
1809 return IFont_AddRef((IFont
*)this);
1812 /************************************************************************
1813 * OLEFontImpl_EnumConnectionPoints (IConnectionPointContainer)
1815 * See Windows documentation for more details on IConnectionPointContainer
1818 static HRESULT WINAPI
OLEFontImpl_EnumConnectionPoints(
1819 IConnectionPointContainer
* iface
,
1820 IEnumConnectionPoints
**ppEnum
)
1822 OLEFontImpl
*this = impl_from_IConnectionPointContainer(iface
);
1824 FIXME("(%p)->(%p): stub\n", this, ppEnum
);
1828 /************************************************************************
1829 * OLEFontImpl_FindConnectionPoint (IConnectionPointContainer)
1831 * See Windows documentation for more details on IConnectionPointContainer
1834 static HRESULT WINAPI
OLEFontImpl_FindConnectionPoint(
1835 IConnectionPointContainer
* iface
,
1837 IConnectionPoint
**ppCp
)
1839 OLEFontImpl
*this = impl_from_IConnectionPointContainer(iface
);
1840 TRACE("(%p)->(%s, %p): stub\n", this, debugstr_guid(riid
), ppCp
);
1842 if(memcmp(riid
, &IID_IPropertyNotifySink
, sizeof(IID_IPropertyNotifySink
)) == 0) {
1843 return IConnectionPoint_QueryInterface(this->pCP
, &IID_IConnectionPoint
,
1846 FIXME("Tried to find connection point on %s\n", debugstr_guid(riid
));
1847 return E_NOINTERFACE
;
1851 /************************************************************************
1852 * OLEFontImpl implementation of IPersistPropertyBag.
1854 static HRESULT WINAPI
OLEFontImpl_IPersistPropertyBag_QueryInterface(
1855 IPersistPropertyBag
*iface
, REFIID riid
, LPVOID
*ppvObj
1857 OLEFontImpl
*this = impl_from_IPersistPropertyBag(iface
);
1858 return IFont_QueryInterface((IFont
*)this,riid
,ppvObj
);
1861 static ULONG WINAPI
OLEFontImpl_IPersistPropertyBag_AddRef(
1862 IPersistPropertyBag
*iface
1864 OLEFontImpl
*this = impl_from_IPersistPropertyBag(iface
);
1865 return IFont_AddRef((IFont
*)this);
1868 static ULONG WINAPI
OLEFontImpl_IPersistPropertyBag_Release(
1869 IPersistPropertyBag
*iface
1871 OLEFontImpl
*this = impl_from_IPersistPropertyBag(iface
);
1872 return IFont_Release((IFont
*)this);
1875 static HRESULT WINAPI
OLEFontImpl_IPersistPropertyBag_GetClassID(
1876 IPersistPropertyBag
*iface
, CLSID
*classid
1878 FIXME("(%p,%p), stub!\n", iface
, classid
);
1882 static HRESULT WINAPI
OLEFontImpl_IPersistPropertyBag_InitNew(
1883 IPersistPropertyBag
*iface
1885 FIXME("(%p), stub!\n", iface
);
1889 static HRESULT WINAPI
OLEFontImpl_IPersistPropertyBag_Load(
1890 IPersistPropertyBag
*iface
, IPropertyBag
* pPropBag
, IErrorLog
* pErrorLog
1892 /* (from Visual Basic 6 property bag)
1893 Name = "MS Sans Serif"
1897 Underline = 0 'False
1899 Strikethrough = 0 'False
1901 static const WCHAR sAttrName
[] = {'N','a','m','e',0};
1902 static const WCHAR sAttrSize
[] = {'S','i','z','e',0};
1903 static const WCHAR sAttrCharset
[] = {'C','h','a','r','s','e','t',0};
1904 static const WCHAR sAttrWeight
[] = {'W','e','i','g','h','t',0};
1905 static const WCHAR sAttrUnderline
[] = {'U','n','d','e','r','l','i','n','e',0};
1906 static const WCHAR sAttrItalic
[] = {'I','t','a','l','i','c',0};
1907 static const WCHAR sAttrStrikethrough
[] = {'S','t','r','i','k','e','t','h','r','o','u','g','h',0};
1910 HRESULT iRes
= S_OK
;
1911 OLEFontImpl
*this = impl_from_IPersistPropertyBag(iface
);
1913 VariantInit(&rawAttr
);
1914 VariantInit(&valueAttr
);
1917 iRes
= IPropertyBag_Read(pPropBag
, sAttrName
, &rawAttr
, pErrorLog
);
1920 iRes
= VariantChangeType(&rawAttr
, &valueAttr
, 0, VT_BSTR
);
1922 iRes
= IFont_put_Name((IFont
*)this, V_BSTR(&valueAttr
));
1924 else if (iRes
== E_INVALIDARG
)
1926 VariantClear(&rawAttr
);
1927 VariantClear(&valueAttr
);
1931 iRes
= IPropertyBag_Read(pPropBag
, sAttrSize
, &rawAttr
, pErrorLog
);
1934 iRes
= VariantChangeType(&rawAttr
, &valueAttr
, 0, VT_CY
);
1936 iRes
= IFont_put_Size((IFont
*)this, V_CY(&valueAttr
));
1938 else if (iRes
== E_INVALIDARG
)
1940 VariantClear(&rawAttr
);
1941 VariantClear(&valueAttr
);
1945 iRes
= IPropertyBag_Read(pPropBag
, sAttrCharset
, &rawAttr
, pErrorLog
);
1948 iRes
= VariantChangeType(&rawAttr
, &valueAttr
, 0, VT_I2
);
1950 iRes
= IFont_put_Charset((IFont
*)this, V_I2(&valueAttr
));
1952 else if (iRes
== E_INVALIDARG
)
1954 VariantClear(&rawAttr
);
1955 VariantClear(&valueAttr
);
1959 iRes
= IPropertyBag_Read(pPropBag
, sAttrWeight
, &rawAttr
, pErrorLog
);
1962 iRes
= VariantChangeType(&rawAttr
, &valueAttr
, 0, VT_I2
);
1964 iRes
= IFont_put_Weight((IFont
*)this, V_I2(&valueAttr
));
1966 else if (iRes
== E_INVALIDARG
)
1968 VariantClear(&rawAttr
);
1969 VariantClear(&valueAttr
);
1974 iRes
= IPropertyBag_Read(pPropBag
, sAttrUnderline
, &rawAttr
, pErrorLog
);
1977 iRes
= VariantChangeType(&rawAttr
, &valueAttr
, 0, VT_BOOL
);
1979 iRes
= IFont_put_Underline((IFont
*)this, V_BOOL(&valueAttr
));
1981 else if (iRes
== E_INVALIDARG
)
1983 VariantClear(&rawAttr
);
1984 VariantClear(&valueAttr
);
1988 iRes
= IPropertyBag_Read(pPropBag
, sAttrItalic
, &rawAttr
, pErrorLog
);
1991 iRes
= VariantChangeType(&rawAttr
, &valueAttr
, 0, VT_BOOL
);
1993 iRes
= IFont_put_Italic((IFont
*)this, V_BOOL(&valueAttr
));
1995 else if (iRes
== E_INVALIDARG
)
1997 VariantClear(&rawAttr
);
1998 VariantClear(&valueAttr
);
2002 iRes
= IPropertyBag_Read(pPropBag
, sAttrStrikethrough
, &rawAttr
, pErrorLog
);
2005 iRes
= VariantChangeType(&rawAttr
, &valueAttr
, 0, VT_BOOL
);
2007 IFont_put_Strikethrough((IFont
*)this, V_BOOL(&valueAttr
));
2009 else if (iRes
== E_INVALIDARG
)
2011 VariantClear(&rawAttr
);
2012 VariantClear(&valueAttr
);
2016 WARN("-- 0x%08lx\n", iRes
);
2020 static HRESULT WINAPI
OLEFontImpl_IPersistPropertyBag_Save(
2021 IPersistPropertyBag
*iface
, IPropertyBag
* pPropBag
, BOOL fClearDirty
,
2022 BOOL fSaveAllProperties
2024 FIXME("(%p,%p,%d,%d), stub!\n", iface
, pPropBag
, fClearDirty
, fSaveAllProperties
);
2028 static const IPersistPropertyBagVtbl OLEFontImpl_IPersistPropertyBag_VTable
=
2030 OLEFontImpl_IPersistPropertyBag_QueryInterface
,
2031 OLEFontImpl_IPersistPropertyBag_AddRef
,
2032 OLEFontImpl_IPersistPropertyBag_Release
,
2034 OLEFontImpl_IPersistPropertyBag_GetClassID
,
2035 OLEFontImpl_IPersistPropertyBag_InitNew
,
2036 OLEFontImpl_IPersistPropertyBag_Load
,
2037 OLEFontImpl_IPersistPropertyBag_Save
2040 /************************************************************************
2041 * OLEFontImpl implementation of IPersistStreamInit.
2043 static HRESULT WINAPI
OLEFontImpl_IPersistStreamInit_QueryInterface(
2044 IPersistStreamInit
*iface
, REFIID riid
, LPVOID
*ppvObj
2046 OLEFontImpl
*this = impl_from_IPersistStreamInit(iface
);
2047 return IFont_QueryInterface((IFont
*)this,riid
,ppvObj
);
2050 static ULONG WINAPI
OLEFontImpl_IPersistStreamInit_AddRef(
2051 IPersistStreamInit
*iface
2053 OLEFontImpl
*this = impl_from_IPersistStreamInit(iface
);
2054 return IFont_AddRef((IFont
*)this);
2057 static ULONG WINAPI
OLEFontImpl_IPersistStreamInit_Release(
2058 IPersistStreamInit
*iface
2060 OLEFontImpl
*this = impl_from_IPersistStreamInit(iface
);
2061 return IFont_Release((IFont
*)this);
2064 static HRESULT WINAPI
OLEFontImpl_IPersistStreamInit_GetClassID(
2065 IPersistStreamInit
*iface
, CLSID
*classid
2067 FIXME("(%p,%p), stub!\n", iface
, classid
);
2071 static HRESULT WINAPI
OLEFontImpl_IPersistStreamInit_IsDirty(
2072 IPersistStreamInit
*iface
2074 FIXME("(%p), stub!\n", iface
);
2078 static HRESULT WINAPI
OLEFontImpl_IPersistStreamInit_Load(
2079 IPersistStreamInit
*iface
, LPSTREAM pStm
2081 FIXME("(%p,%p), stub!\n", iface
, pStm
);
2085 static HRESULT WINAPI
OLEFontImpl_IPersistStreamInit_Save(
2086 IPersistStreamInit
*iface
, LPSTREAM pStm
, BOOL fClearDirty
2088 FIXME("(%p,%p,%d), stub!\n", iface
, pStm
, fClearDirty
);
2092 static HRESULT WINAPI
OLEFontImpl_IPersistStreamInit_GetSizeMax(
2093 IPersistStreamInit
*iface
, ULARGE_INTEGER
*pcbSize
2095 FIXME("(%p,%p), stub!\n", iface
, pcbSize
);
2099 static HRESULT WINAPI
OLEFontImpl_IPersistStreamInit_InitNew(
2100 IPersistStreamInit
*iface
2102 FIXME("(%p), stub!\n", iface
);
2106 static const IPersistStreamInitVtbl OLEFontImpl_IPersistStreamInit_VTable
=
2108 OLEFontImpl_IPersistStreamInit_QueryInterface
,
2109 OLEFontImpl_IPersistStreamInit_AddRef
,
2110 OLEFontImpl_IPersistStreamInit_Release
,
2112 OLEFontImpl_IPersistStreamInit_GetClassID
,
2113 OLEFontImpl_IPersistStreamInit_IsDirty
,
2114 OLEFontImpl_IPersistStreamInit_Load
,
2115 OLEFontImpl_IPersistStreamInit_Save
,
2116 OLEFontImpl_IPersistStreamInit_GetSizeMax
,
2117 OLEFontImpl_IPersistStreamInit_InitNew
2120 /*******************************************************************************
2121 * StdFont ClassFactory
2125 /* IUnknown fields */
2126 const IClassFactoryVtbl
*lpVtbl
;
2128 } IClassFactoryImpl
;
2130 static HRESULT WINAPI
2131 SFCF_QueryInterface(LPCLASSFACTORY iface
,REFIID riid
,LPVOID
*ppobj
) {
2132 IClassFactoryImpl
*This
= (IClassFactoryImpl
*)iface
;
2134 FIXME("(%p)->(%s,%p),stub!\n",This
,debugstr_guid(riid
),ppobj
);
2135 return E_NOINTERFACE
;
2139 SFCF_AddRef(LPCLASSFACTORY iface
) {
2140 IClassFactoryImpl
*This
= (IClassFactoryImpl
*)iface
;
2141 return InterlockedIncrement(&This
->ref
);
2144 static ULONG WINAPI
SFCF_Release(LPCLASSFACTORY iface
) {
2145 IClassFactoryImpl
*This
= (IClassFactoryImpl
*)iface
;
2146 /* static class, won't be freed */
2147 return InterlockedDecrement(&This
->ref
);
2150 static HRESULT WINAPI
SFCF_CreateInstance(
2151 LPCLASSFACTORY iface
,LPUNKNOWN pOuter
,REFIID riid
,LPVOID
*ppobj
2153 return OleCreateFontIndirect(NULL
,riid
,ppobj
);
2157 static HRESULT WINAPI
SFCF_LockServer(LPCLASSFACTORY iface
,BOOL dolock
) {
2158 IClassFactoryImpl
*This
= (IClassFactoryImpl
*)iface
;
2159 FIXME("(%p)->(%d),stub!\n",This
,dolock
);
2163 static const IClassFactoryVtbl SFCF_Vtbl
= {
2164 SFCF_QueryInterface
,
2167 SFCF_CreateInstance
,
2170 static IClassFactoryImpl STDFONT_CF
= {&SFCF_Vtbl
, 1 };
2172 void _get_STDFONT_CF(LPVOID
*ppv
) { *ppv
= (LPVOID
)&STDFONT_CF
; }