2 * OLE Font encapsulation implementation
4 * This file contains an implementation of the IFont
5 * interface and the OleCreateFontIndirect API call.
7 * Copyright 1999 Francis Beaudet
8 * Copyright 2006 (Google) Benjamin Arai
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
29 #define NONAMELESSUNION
30 #define NONAMELESSSTRUCT
37 #include "wine/unicode.h"
39 #include "oleauto.h" /* for SysAllocString(....) */
42 #include "wine/debug.h"
43 #include "connpt.h" /* for CreateConnectionPoint */
46 WINE_DEFAULT_DEBUG_CHANNEL(ole);
48 /***********************************************************************
49 * Declaration of constants used when serializing the font object.
51 #define FONTPERSIST_ITALIC 0x02
52 #define FONTPERSIST_UNDERLINE 0x04
53 #define FONTPERSIST_STRIKETHROUGH 0x08
55 /***********************************************************************
56 * Declaration of the implementation class for the IFont interface
58 typedef struct OLEFontImpl OLEFontImpl;
63 * This class supports many interfaces. IUnknown, IFont,
64 * IDispatch, IDispFont IPersistStream and IConnectionPointContainer.
65 * The first two are supported by the first vtable, the next two are
66 * supported by the second table and the last two have their own.
68 const IFontVtbl* lpVtbl;
69 const IDispatchVtbl* lpvtblIDispatch;
70 const IPersistStreamVtbl* lpvtblIPersistStream;
71 const IConnectionPointContainerVtbl* lpvtblIConnectionPointContainer;
72 const IPersistPropertyBagVtbl* lpvtblIPersistPropertyBag;
73 const IPersistStreamInitVtbl* lpvtblIPersistStreamInit;
75 * Reference count for that instance of the class.
80 * This structure contains the description of the class.
85 * Contain the font associated with this object.
100 IConnectionPoint *pPropertyNotifyCP;
101 IConnectionPoint *pFontEventsCP;
105 * Here, I define utility macros to help with the casting of the
107 * There is a version to accommodate all of the VTables implemented
111 static inline OLEFontImpl *impl_from_IDispatch( IDispatch *iface )
113 return (OLEFontImpl *)((char*)iface - FIELD_OFFSET(OLEFontImpl, lpvtblIDispatch));
116 static inline OLEFontImpl *impl_from_IPersistStream( IPersistStream *iface )
118 return (OLEFontImpl *)((char*)iface - FIELD_OFFSET(OLEFontImpl, lpvtblIPersistStream));
121 static inline OLEFontImpl *impl_from_IConnectionPointContainer( IConnectionPointContainer *iface )
123 return (OLEFontImpl *)((char*)iface - FIELD_OFFSET(OLEFontImpl, lpvtblIConnectionPointContainer));
126 static inline OLEFontImpl *impl_from_IPersistPropertyBag( IPersistPropertyBag *iface )
128 return (OLEFontImpl *)((char*)iface - FIELD_OFFSET(OLEFontImpl, lpvtblIPersistPropertyBag));
131 static inline OLEFontImpl *impl_from_IPersistStreamInit( IPersistStreamInit *iface )
133 return (OLEFontImpl *)((char*)iface - FIELD_OFFSET(OLEFontImpl, lpvtblIPersistStreamInit));
137 /***********************************************************************
138 * Prototypes for the implementation functions for the IFont
141 static OLEFontImpl* OLEFontImpl_Construct(LPFONTDESC fontDesc);
142 static void OLEFontImpl_Destroy(OLEFontImpl* fontDesc);
143 static HRESULT WINAPI OLEFontImpl_QueryInterface(IFont* iface, REFIID riid, VOID** ppvoid);
144 static ULONG WINAPI OLEFontImpl_AddRef(IFont* iface);
145 static ULONG WINAPI OLEFontImpl_Release(IFont* iface);
146 static HRESULT WINAPI OLEFontImpl_get_Name(IFont* iface, BSTR* pname);
147 static HRESULT WINAPI OLEFontImpl_put_Name(IFont* iface, BSTR name);
148 static HRESULT WINAPI OLEFontImpl_get_Size(IFont* iface, CY* psize);
149 static HRESULT WINAPI OLEFontImpl_put_Size(IFont* iface, CY size);
150 static HRESULT WINAPI OLEFontImpl_get_Bold(IFont* iface, BOOL* pbold);
151 static HRESULT WINAPI OLEFontImpl_put_Bold(IFont* iface, BOOL bold);
152 static HRESULT WINAPI OLEFontImpl_get_Italic(IFont* iface, BOOL* pitalic);
153 static HRESULT WINAPI OLEFontImpl_put_Italic(IFont* iface, BOOL italic);
154 static HRESULT WINAPI OLEFontImpl_get_Underline(IFont* iface, BOOL* punderline);
155 static HRESULT WINAPI OLEFontImpl_put_Underline(IFont* iface, BOOL underline);
156 static HRESULT WINAPI OLEFontImpl_get_Strikethrough(IFont* iface, BOOL* pstrikethrough);
157 static HRESULT WINAPI OLEFontImpl_put_Strikethrough(IFont* iface, BOOL strikethrough);
158 static HRESULT WINAPI OLEFontImpl_get_Weight(IFont* iface, short* pweight);
159 static HRESULT WINAPI OLEFontImpl_put_Weight(IFont* iface, short weight);
160 static HRESULT WINAPI OLEFontImpl_get_Charset(IFont* iface, short* pcharset);
161 static HRESULT WINAPI OLEFontImpl_put_Charset(IFont* iface, short charset);
162 static HRESULT WINAPI OLEFontImpl_get_hFont(IFont* iface, HFONT* phfont);
163 static HRESULT WINAPI OLEFontImpl_Clone(IFont* iface, IFont** ppfont);
164 static HRESULT WINAPI OLEFontImpl_IsEqual(IFont* iface, IFont* pFontOther);
165 static HRESULT WINAPI OLEFontImpl_SetRatio(IFont* iface, LONG cyLogical, LONG cyHimetric);
166 static HRESULT WINAPI OLEFontImpl_QueryTextMetrics(IFont* iface, TEXTMETRICOLE* ptm);
167 static HRESULT WINAPI OLEFontImpl_AddRefHfont(IFont* iface, HFONT hfont);
168 static HRESULT WINAPI OLEFontImpl_ReleaseHfont(IFont* iface, HFONT hfont);
169 static HRESULT WINAPI OLEFontImpl_SetHdc(IFont* iface, HDC hdc);
171 /***********************************************************************
172 * Prototypes for the implementation functions for the IDispatch
175 static HRESULT WINAPI OLEFontImpl_IDispatch_QueryInterface(IDispatch* iface,
178 static ULONG WINAPI OLEFontImpl_IDispatch_AddRef(IDispatch* iface);
179 static ULONG WINAPI OLEFontImpl_IDispatch_Release(IDispatch* iface);
180 static HRESULT WINAPI OLEFontImpl_GetTypeInfoCount(IDispatch* iface,
181 unsigned int* pctinfo);
182 static HRESULT WINAPI OLEFontImpl_GetTypeInfo(IDispatch* iface,
185 ITypeInfo** ppTInfo);
186 static HRESULT WINAPI OLEFontImpl_GetIDsOfNames(IDispatch* iface,
192 static HRESULT WINAPI OLEFontImpl_Invoke(IDispatch* iface,
197 DISPPARAMS* pDispParams,
199 EXCEPINFO* pExepInfo,
202 /***********************************************************************
203 * Prototypes for the implementation functions for the IPersistStream
206 static HRESULT WINAPI OLEFontImpl_IPersistStream_QueryInterface(IPersistStream* iface,
209 static ULONG WINAPI OLEFontImpl_IPersistStream_AddRef(IPersistStream* iface);
210 static ULONG WINAPI OLEFontImpl_IPersistStream_Release(IPersistStream* iface);
211 static HRESULT WINAPI OLEFontImpl_GetClassID(IPersistStream* iface,
213 static HRESULT WINAPI OLEFontImpl_IsDirty(IPersistStream* iface);
214 static HRESULT WINAPI OLEFontImpl_Load(IPersistStream* iface,
215 IStream* pLoadStream);
216 static HRESULT WINAPI OLEFontImpl_Save(IPersistStream* iface,
219 static HRESULT WINAPI OLEFontImpl_GetSizeMax(IPersistStream* iface,
220 ULARGE_INTEGER* pcbSize);
222 /***********************************************************************
223 * Prototypes for the implementation functions for the
224 * IConnectionPointContainer interface
226 static HRESULT WINAPI OLEFontImpl_IConnectionPointContainer_QueryInterface(
227 IConnectionPointContainer* iface,
230 static ULONG WINAPI OLEFontImpl_IConnectionPointContainer_AddRef(
231 IConnectionPointContainer* iface);
232 static ULONG WINAPI OLEFontImpl_IConnectionPointContainer_Release(
233 IConnectionPointContainer* iface);
234 static HRESULT WINAPI OLEFontImpl_EnumConnectionPoints(
235 IConnectionPointContainer* iface,
236 IEnumConnectionPoints **ppEnum);
237 static HRESULT WINAPI OLEFontImpl_FindConnectionPoint(
238 IConnectionPointContainer* iface,
240 IConnectionPoint **ppCp);
243 * Virtual function tables for the OLEFontImpl class.
245 static const IFontVtbl OLEFontImpl_VTable =
247 OLEFontImpl_QueryInterface,
250 OLEFontImpl_get_Name,
251 OLEFontImpl_put_Name,
252 OLEFontImpl_get_Size,
253 OLEFontImpl_put_Size,
254 OLEFontImpl_get_Bold,
255 OLEFontImpl_put_Bold,
256 OLEFontImpl_get_Italic,
257 OLEFontImpl_put_Italic,
258 OLEFontImpl_get_Underline,
259 OLEFontImpl_put_Underline,
260 OLEFontImpl_get_Strikethrough,
261 OLEFontImpl_put_Strikethrough,
262 OLEFontImpl_get_Weight,
263 OLEFontImpl_put_Weight,
264 OLEFontImpl_get_Charset,
265 OLEFontImpl_put_Charset,
266 OLEFontImpl_get_hFont,
269 OLEFontImpl_SetRatio,
270 OLEFontImpl_QueryTextMetrics,
271 OLEFontImpl_AddRefHfont,
272 OLEFontImpl_ReleaseHfont,
276 static const IDispatchVtbl OLEFontImpl_IDispatch_VTable =
278 OLEFontImpl_IDispatch_QueryInterface,
279 OLEFontImpl_IDispatch_AddRef,
280 OLEFontImpl_IDispatch_Release,
281 OLEFontImpl_GetTypeInfoCount,
282 OLEFontImpl_GetTypeInfo,
283 OLEFontImpl_GetIDsOfNames,
287 static const IPersistStreamVtbl OLEFontImpl_IPersistStream_VTable =
289 OLEFontImpl_IPersistStream_QueryInterface,
290 OLEFontImpl_IPersistStream_AddRef,
291 OLEFontImpl_IPersistStream_Release,
292 OLEFontImpl_GetClassID,
296 OLEFontImpl_GetSizeMax
299 static const IConnectionPointContainerVtbl
300 OLEFontImpl_IConnectionPointContainer_VTable =
302 OLEFontImpl_IConnectionPointContainer_QueryInterface,
303 OLEFontImpl_IConnectionPointContainer_AddRef,
304 OLEFontImpl_IConnectionPointContainer_Release,
305 OLEFontImpl_EnumConnectionPoints,
306 OLEFontImpl_FindConnectionPoint
309 static const IPersistPropertyBagVtbl OLEFontImpl_IPersistPropertyBag_VTable;
310 static const IPersistStreamInitVtbl OLEFontImpl_IPersistStreamInit_VTable;
312 /******************************************************************************
313 * OleCreateFontIndirect [OLEAUT32.420]
315 HRESULT WINAPI OleCreateFontIndirect(
316 LPFONTDESC lpFontDesc,
320 OLEFontImpl* newFont = 0;
323 TRACE("(%p, %s, %p)\n", lpFontDesc, debugstr_guid(riid), ppvObj);
335 static const WCHAR fname[] = { 'S','y','s','t','e','m',0 };
337 fd.cbSizeofstruct = sizeof(fd);
338 fd.lpstrName = (WCHAR*)fname;
339 fd.cySize.s.Lo = 80000;
345 fd.fStrikethrough = 0;
350 * Try to construct a new instance of the class.
352 newFont = OLEFontImpl_Construct(lpFontDesc);
355 return E_OUTOFMEMORY;
358 * Make sure it supports the interface required by the caller.
360 hr = IFont_QueryInterface((IFont*)newFont, riid, ppvObj);
363 * Release the reference obtained in the constructor. If
364 * the QueryInterface was unsuccessful, it will free the class.
366 IFont_Release((IFont*)newFont);
372 /***********************************************************************
373 * Implementation of the OLEFontImpl class.
376 /***********************************************************************
377 * OLEFont_SendNotify (internal)
379 * Sends notification messages of changed properties to any interested
382 static void OLEFont_SendNotify(OLEFontImpl* this, DISPID dispID)
384 static const WCHAR wszName[] = {'N','a','m','e',0};
385 static const WCHAR wszSize[] = {'S','i','z','e',0};
386 static const WCHAR wszBold[] = {'B','o','l','d',0};
387 static const WCHAR wszItalic[] = {'I','t','a','l','i','c',0};
388 static const WCHAR wszUnder[] = {'U','n','d','e','r','l','i','n','e',0};
389 static const WCHAR wszStrike[] = {'S','t','r','i','k','e','t','h','r','o','u','g','h',0};
390 static const WCHAR wszWeight[] = {'W','e','i','g','h','t',0};
391 static const WCHAR wszCharset[] = {'C','h','a','r','s','s','e','t',0};
392 static const LPCWSTR dispid_mapping[] =
405 IEnumConnections *pEnum;
409 hres = IConnectionPoint_EnumConnections(this->pPropertyNotifyCP, &pEnum);
412 while(IEnumConnections_Next(pEnum, 1, &CD, NULL) == S_OK) {
413 IPropertyNotifySink *sink;
415 IUnknown_QueryInterface(CD.pUnk, &IID_IPropertyNotifySink, (LPVOID)&sink);
416 IPropertyNotifySink_OnChanged(sink, dispID);
417 IPropertyNotifySink_Release(sink);
418 IUnknown_Release(CD.pUnk);
420 IEnumConnections_Release(pEnum);
423 hres = IConnectionPoint_EnumConnections(this->pFontEventsCP, &pEnum);
426 DISPPARAMS dispparams;
429 VariantInit(&vararg);
430 V_VT(&vararg) = VT_BSTR;
431 V_BSTR(&vararg) = SysAllocString(dispid_mapping[dispID]);
433 dispparams.cArgs = 1;
434 dispparams.cNamedArgs = 0;
435 dispparams.rgdispidNamedArgs = NULL;
436 dispparams.rgvarg = &vararg;
438 while(IEnumConnections_Next(pEnum, 1, &CD, NULL) == S_OK) {
439 IFontEventsDisp *disp;
441 IUnknown_QueryInterface(CD.pUnk, &IID_IFontEventsDisp, (LPVOID)&disp);
442 IDispatch_Invoke(disp, DISPID_FONT_CHANGED, &IID_NULL,
443 LOCALE_NEUTRAL, INVOKE_FUNC, &dispparams, NULL,
446 IDispatch_Release(disp);
447 IUnknown_Release(CD.pUnk);
449 VariantClear(&vararg);
450 IEnumConnections_Release(pEnum);
454 /************************************************************************
455 * OLEFontImpl_Construct
457 * This method will construct a new instance of the OLEFontImpl
460 * The caller of this method must release the object when it's
463 static OLEFontImpl* OLEFontImpl_Construct(LPFONTDESC fontDesc)
465 OLEFontImpl* newObject = 0;
468 * Allocate space for the object.
470 newObject = HeapAlloc(GetProcessHeap(), 0, sizeof(OLEFontImpl));
476 * Initialize the virtual function table.
478 newObject->lpVtbl = &OLEFontImpl_VTable;
479 newObject->lpvtblIDispatch = &OLEFontImpl_IDispatch_VTable;
480 newObject->lpvtblIPersistStream = &OLEFontImpl_IPersistStream_VTable;
481 newObject->lpvtblIConnectionPointContainer = &OLEFontImpl_IConnectionPointContainer_VTable;
482 newObject->lpvtblIPersistPropertyBag = &OLEFontImpl_IPersistPropertyBag_VTable;
483 newObject->lpvtblIPersistStreamInit = &OLEFontImpl_IPersistStreamInit_VTable;
486 * Start with one reference count. The caller of this function
487 * must release the interface pointer when it is done.
492 * Copy the description of the font in the object.
494 assert(fontDesc->cbSizeofstruct >= sizeof(FONTDESC));
496 newObject->description.cbSizeofstruct = sizeof(FONTDESC);
497 newObject->description.lpstrName = HeapAlloc(GetProcessHeap(),
499 (lstrlenW(fontDesc->lpstrName)+1) * sizeof(WCHAR));
500 strcpyW(newObject->description.lpstrName, fontDesc->lpstrName);
501 newObject->description.cySize = fontDesc->cySize;
502 newObject->description.sWeight = fontDesc->sWeight;
503 newObject->description.sCharset = fontDesc->sCharset;
504 newObject->description.fItalic = fontDesc->fItalic;
505 newObject->description.fUnderline = fontDesc->fUnderline;
506 newObject->description.fStrikethrough = fontDesc->fStrikethrough;
509 * Initializing all the other members.
511 newObject->gdiFont = 0;
512 newObject->fontLock = 0;
513 newObject->cyLogical = 72L;
514 newObject->cyHimetric = 2540L;
515 newObject->pPropertyNotifyCP = NULL;
516 newObject->pFontEventsCP = NULL;
518 CreateConnectionPoint((IUnknown*)newObject, &IID_IPropertyNotifySink, &newObject->pPropertyNotifyCP);
519 CreateConnectionPoint((IUnknown*)newObject, &IID_IFontEventsDisp, &newObject->pFontEventsCP);
521 if (!newObject->pPropertyNotifyCP || !newObject->pFontEventsCP)
523 OLEFontImpl_Destroy(newObject);
527 TRACE("returning %p\n", newObject);
531 /************************************************************************
532 * OLEFontImpl_Destroy
534 * This method is called by the Release method when the reference
535 * count goes down to 0. It will free all resources used by
538 static void OLEFontImpl_Destroy(OLEFontImpl* fontDesc)
540 TRACE("(%p)\n", fontDesc);
542 HeapFree(GetProcessHeap(), 0, fontDesc->description.lpstrName);
544 if (fontDesc->gdiFont!=0)
545 DeleteObject(fontDesc->gdiFont);
547 if (fontDesc->pPropertyNotifyCP)
548 IConnectionPoint_Release(fontDesc->pPropertyNotifyCP);
549 if (fontDesc->pFontEventsCP)
550 IConnectionPoint_Release(fontDesc->pFontEventsCP);
552 HeapFree(GetProcessHeap(), 0, fontDesc);
555 /************************************************************************
556 * OLEFontImpl_QueryInterface (IUnknown)
558 * See Windows documentation for more details on IUnknown methods.
560 HRESULT WINAPI OLEFontImpl_QueryInterface(
565 OLEFontImpl *this = (OLEFontImpl *)iface;
566 TRACE("(%p)->(%s, %p)\n", this, debugstr_guid(riid), ppvObject);
569 * Perform a sanity check on the parameters.
571 if ( (this==0) || (ppvObject==0) )
575 * Initialize the return parameter.
580 * Compare the riid with the interface IDs implemented by this object.
582 if (IsEqualGUID(&IID_IUnknown, riid))
583 *ppvObject = (IFont*)this;
584 if (IsEqualGUID(&IID_IFont, riid))
585 *ppvObject = (IFont*)this;
586 if (IsEqualGUID(&IID_IDispatch, riid))
587 *ppvObject = (IDispatch*)&(this->lpvtblIDispatch);
588 if (IsEqualGUID(&IID_IFontDisp, riid))
589 *ppvObject = (IDispatch*)&(this->lpvtblIDispatch);
590 if (IsEqualIID(&IID_IPersist, riid) || IsEqualGUID(&IID_IPersistStream, riid))
591 *ppvObject = (IPersistStream*)&(this->lpvtblIPersistStream);
592 if (IsEqualGUID(&IID_IConnectionPointContainer, riid))
593 *ppvObject = (IConnectionPointContainer*)&(this->lpvtblIConnectionPointContainer);
594 if (IsEqualGUID(&IID_IPersistPropertyBag, riid))
595 *ppvObject = (IPersistPropertyBag*)&(this->lpvtblIPersistPropertyBag);
596 if (IsEqualGUID(&IID_IPersistStreamInit, riid))
597 *ppvObject = (IPersistStreamInit*)&(this->lpvtblIPersistStreamInit);
600 * Check that we obtained an interface.
604 FIXME("() : asking for unsupported interface %s\n",debugstr_guid(riid));
605 return E_NOINTERFACE;
607 OLEFontImpl_AddRef((IFont*)this);
611 /************************************************************************
612 * OLEFontImpl_AddRef (IUnknown)
614 * See Windows documentation for more details on IUnknown methods.
616 ULONG WINAPI OLEFontImpl_AddRef(
619 OLEFontImpl *this = (OLEFontImpl *)iface;
620 TRACE("(%p)->(ref=%ld)\n", this, this->ref);
621 return InterlockedIncrement(&this->ref);
624 /************************************************************************
625 * OLEFontImpl_Release (IUnknown)
627 * See Windows documentation for more details on IUnknown methods.
629 ULONG WINAPI OLEFontImpl_Release(
632 OLEFontImpl *this = (OLEFontImpl *)iface;
634 TRACE("(%p)->(ref=%ld)\n", this, this->ref);
637 * Decrease the reference count on this object.
639 ret = InterlockedDecrement(&this->ref);
642 * If the reference count goes down to 0, perform suicide.
644 if (ret==0) OLEFontImpl_Destroy(this);
649 /************************************************************************
650 * OLEFontImpl_get_Name (IFont)
652 * See Windows documentation for more details on IFont methods.
654 static HRESULT WINAPI OLEFontImpl_get_Name(
658 OLEFontImpl *this = (OLEFontImpl *)iface;
659 TRACE("(%p)->(%p)\n", this, pname);
666 if (this->description.lpstrName!=0)
667 *pname = SysAllocString(this->description.lpstrName);
674 /************************************************************************
675 * OLEFontImpl_put_Name (IFont)
677 * See Windows documentation for more details on IFont methods.
679 static HRESULT WINAPI OLEFontImpl_put_Name(
683 OLEFontImpl *this = (OLEFontImpl *)iface;
684 TRACE("(%p)->(%p)\n", this, name);
686 if (this->description.lpstrName==0)
688 this->description.lpstrName = HeapAlloc(GetProcessHeap(),
690 (lstrlenW(name)+1) * sizeof(WCHAR));
694 this->description.lpstrName = HeapReAlloc(GetProcessHeap(),
696 this->description.lpstrName,
697 (lstrlenW(name)+1) * sizeof(WCHAR));
700 if (this->description.lpstrName==0)
701 return E_OUTOFMEMORY;
703 strcpyW(this->description.lpstrName, name);
704 TRACE("new name %s\n", debugstr_w(this->description.lpstrName));
705 OLEFont_SendNotify(this, DISPID_FONT_NAME);
709 /************************************************************************
710 * OLEFontImpl_get_Size (IFont)
712 * See Windows documentation for more details on IFont methods.
714 static HRESULT WINAPI OLEFontImpl_get_Size(
718 OLEFontImpl *this = (OLEFontImpl *)iface;
719 TRACE("(%p)->(%p)\n", this, psize);
728 psize->s.Lo = this->description.cySize.s.Lo;
733 /************************************************************************
734 * OLEFontImpl_put_Size (IFont)
736 * See Windows documentation for more details on IFont methods.
738 static HRESULT WINAPI OLEFontImpl_put_Size(
742 OLEFontImpl *this = (OLEFontImpl *)iface;
743 TRACE("(%p)->(%ld)\n", this, size.s.Lo);
744 this->description.cySize.s.Hi = 0;
745 this->description.cySize.s.Lo = size.s.Lo;
746 OLEFont_SendNotify(this, DISPID_FONT_SIZE);
751 /************************************************************************
752 * OLEFontImpl_get_Bold (IFont)
754 * See Windows documentation for more details on IFont methods.
756 static HRESULT WINAPI OLEFontImpl_get_Bold(
760 OLEFontImpl *this = (OLEFontImpl *)iface;
761 TRACE("(%p)->(%p)\n", this, pbold);
768 *pbold = this->description.sWeight > 550;
773 /************************************************************************
774 * OLEFontImpl_put_Bold (IFont)
776 * See Windows documentation for more details on IFont methods.
778 static HRESULT WINAPI OLEFontImpl_put_Bold(
782 OLEFontImpl *this = (OLEFontImpl *)iface;
783 TRACE("(%p)->(%d)\n", this, bold);
784 this->description.sWeight = bold ? FW_BOLD : FW_NORMAL;
785 OLEFont_SendNotify(this, DISPID_FONT_BOLD);
790 /************************************************************************
791 * OLEFontImpl_get_Italic (IFont)
793 * See Windows documentation for more details on IFont methods.
795 static HRESULT WINAPI OLEFontImpl_get_Italic(
799 OLEFontImpl *this = (OLEFontImpl *)iface;
800 TRACE("(%p)->(%p)\n", this, pitalic);
807 *pitalic = this->description.fItalic;
812 /************************************************************************
813 * OLEFontImpl_put_Italic (IFont)
815 * See Windows documentation for more details on IFont methods.
817 static HRESULT WINAPI OLEFontImpl_put_Italic(
821 OLEFontImpl *this = (OLEFontImpl *)iface;
822 TRACE("(%p)->(%d)\n", this, italic);
824 this->description.fItalic = italic;
826 OLEFont_SendNotify(this, DISPID_FONT_ITALIC);
830 /************************************************************************
831 * OLEFontImpl_get_Underline (IFont)
833 * See Windows documentation for more details on IFont methods.
835 static HRESULT WINAPI OLEFontImpl_get_Underline(
839 OLEFontImpl *this = (OLEFontImpl *)iface;
840 TRACE("(%p)->(%p)\n", this, punderline);
848 *punderline = this->description.fUnderline;
853 /************************************************************************
854 * OLEFontImpl_put_Underline (IFont)
856 * See Windows documentation for more details on IFont methods.
858 static HRESULT WINAPI OLEFontImpl_put_Underline(
862 OLEFontImpl *this = (OLEFontImpl *)iface;
863 TRACE("(%p)->(%d)\n", this, underline);
865 this->description.fUnderline = underline;
867 OLEFont_SendNotify(this, DISPID_FONT_UNDER);
871 /************************************************************************
872 * OLEFontImpl_get_Strikethrough (IFont)
874 * See Windows documentation for more details on IFont methods.
876 static HRESULT WINAPI OLEFontImpl_get_Strikethrough(
878 BOOL* pstrikethrough)
880 OLEFontImpl *this = (OLEFontImpl *)iface;
881 TRACE("(%p)->(%p)\n", this, pstrikethrough);
886 if (pstrikethrough==0)
889 *pstrikethrough = this->description.fStrikethrough;
894 /************************************************************************
895 * OLEFontImpl_put_Strikethrough (IFont)
897 * See Windows documentation for more details on IFont methods.
899 static HRESULT WINAPI OLEFontImpl_put_Strikethrough(
903 OLEFontImpl *this = (OLEFontImpl *)iface;
904 TRACE("(%p)->(%d)\n", this, strikethrough);
906 this->description.fStrikethrough = strikethrough;
907 OLEFont_SendNotify(this, DISPID_FONT_STRIKE);
912 /************************************************************************
913 * OLEFontImpl_get_Weight (IFont)
915 * See Windows documentation for more details on IFont methods.
917 static HRESULT WINAPI OLEFontImpl_get_Weight(
921 OLEFontImpl *this = (OLEFontImpl *)iface;
922 TRACE("(%p)->(%p)\n", this, pweight);
930 *pweight = this->description.sWeight;
935 /************************************************************************
936 * OLEFontImpl_put_Weight (IFont)
938 * See Windows documentation for more details on IFont methods.
940 static HRESULT WINAPI OLEFontImpl_put_Weight(
944 OLEFontImpl *this = (OLEFontImpl *)iface;
945 TRACE("(%p)->(%d)\n", this, weight);
947 this->description.sWeight = weight;
949 OLEFont_SendNotify(this, DISPID_FONT_WEIGHT);
953 /************************************************************************
954 * OLEFontImpl_get_Charset (IFont)
956 * See Windows documentation for more details on IFont methods.
958 static HRESULT WINAPI OLEFontImpl_get_Charset(
962 OLEFontImpl *this = (OLEFontImpl *)iface;
963 TRACE("(%p)->(%p)\n", this, pcharset);
971 *pcharset = this->description.sCharset;
976 /************************************************************************
977 * OLEFontImpl_put_Charset (IFont)
979 * See Windows documentation for more details on IFont methods.
981 static HRESULT WINAPI OLEFontImpl_put_Charset(
985 OLEFontImpl *this = (OLEFontImpl *)iface;
986 TRACE("(%p)->(%d)\n", this, charset);
988 this->description.sCharset = charset;
989 OLEFont_SendNotify(this, DISPID_FONT_CHARSET);
994 /************************************************************************
995 * OLEFontImpl_get_hFont (IFont)
997 * See Windows documentation for more details on IFont methods.
999 static HRESULT WINAPI OLEFontImpl_get_hFont(
1003 OLEFontImpl *this = (OLEFontImpl *)iface;
1004 TRACE("(%p)->(%p)\n", this, phfont);
1009 * Realize the font if necessary
1011 if (this->gdiFont==0)
1018 * The height of the font returned by the get_Size property is the
1019 * height of the font in points multiplied by 10000... Using some
1020 * simple conversions and the ratio given by the application, it can
1021 * be converted to a height in pixels.
1023 IFont_get_Size(iface, &cySize);
1025 /* Standard ratio is 72 / 2540, or 18 / 635 in lowest terms. */
1026 /* Ratio is applied here relative to the standard. */
1027 fontHeight = MulDiv( cySize.s.Lo, this->cyLogical*635, this->cyHimetric*18 );
1029 memset(&logFont, 0, sizeof(LOGFONTW));
1031 logFont.lfHeight = ((fontHeight%10000L)>5000L) ? (-fontHeight/10000L)-1 :
1032 (-fontHeight/10000L);
1033 logFont.lfItalic = this->description.fItalic;
1034 logFont.lfUnderline = this->description.fUnderline;
1035 logFont.lfStrikeOut = this->description.fStrikethrough;
1036 logFont.lfWeight = this->description.sWeight;
1037 logFont.lfCharSet = this->description.sCharset;
1038 logFont.lfOutPrecision = OUT_CHARACTER_PRECIS;
1039 logFont.lfClipPrecision = CLIP_DEFAULT_PRECIS;
1040 logFont.lfQuality = DEFAULT_QUALITY;
1041 logFont.lfPitchAndFamily = DEFAULT_PITCH;
1042 strcpyW(logFont.lfFaceName,this->description.lpstrName);
1044 this->gdiFont = CreateFontIndirectW(&logFont);
1047 *phfont = this->gdiFont;
1048 TRACE("Returning %p\n", *phfont);
1052 /************************************************************************
1053 * OLEFontImpl_Clone (IFont)
1055 * See Windows documentation for more details on IFont methods.
1057 static HRESULT WINAPI OLEFontImpl_Clone(
1061 OLEFontImpl* newObject = 0;
1065 OLEFontImpl *this = (OLEFontImpl *)iface;
1066 TRACE("(%p)->(%p)\n", this, ppfont);
1074 * Allocate space for the object.
1076 newObject = HeapAlloc(GetProcessHeap(), 0, sizeof(OLEFontImpl));
1078 if (newObject==NULL)
1079 return E_OUTOFMEMORY;
1083 /* We need to alloc new memory for the string, otherwise
1084 * we free memory twice.
1086 newObject->description.lpstrName = HeapAlloc(
1088 (1+strlenW(this->description.lpstrName))*2
1090 strcpyW(newObject->description.lpstrName, this->description.lpstrName);
1091 /* We need to clone the HFONT too. This is just cut & paste from above */
1092 IFont_get_Size(iface, &cySize);
1094 fontHeight = MulDiv(cySize.s.Lo, this->cyLogical*635,this->cyHimetric*18);
1096 memset(&logFont, 0, sizeof(LOGFONTW));
1098 logFont.lfHeight = ((fontHeight%10000L)>5000L) ? (-fontHeight/10000L)-1 :
1099 (-fontHeight/10000L);
1100 logFont.lfItalic = this->description.fItalic;
1101 logFont.lfUnderline = this->description.fUnderline;
1102 logFont.lfStrikeOut = this->description.fStrikethrough;
1103 logFont.lfWeight = this->description.sWeight;
1104 logFont.lfCharSet = this->description.sCharset;
1105 logFont.lfOutPrecision = OUT_CHARACTER_PRECIS;
1106 logFont.lfClipPrecision = CLIP_DEFAULT_PRECIS;
1107 logFont.lfQuality = DEFAULT_QUALITY;
1108 logFont.lfPitchAndFamily = DEFAULT_PITCH;
1109 strcpyW(logFont.lfFaceName,this->description.lpstrName);
1111 newObject->gdiFont = CreateFontIndirectW(&logFont);
1113 /* create new connection points */
1114 newObject->pPropertyNotifyCP = NULL;
1115 newObject->pFontEventsCP = NULL;
1116 CreateConnectionPoint((IUnknown*)newObject, &IID_IPropertyNotifySink, &newObject->pPropertyNotifyCP);
1117 CreateConnectionPoint((IUnknown*)newObject, &IID_IFontEventsDisp, &newObject->pFontEventsCP);
1119 if (!newObject->pPropertyNotifyCP || !newObject->pFontEventsCP)
1121 OLEFontImpl_Destroy(newObject);
1122 return E_OUTOFMEMORY;
1125 /* The cloned object starts with a reference count of 1 */
1128 *ppfont = (IFont*)newObject;
1133 /************************************************************************
1134 * OLEFontImpl_IsEqual (IFont)
1136 * See Windows documentation for more details on IFont methods.
1138 static HRESULT WINAPI OLEFontImpl_IsEqual(
1142 FIXME("(%p, %p), stub!\n",iface,pFontOther);
1146 /************************************************************************
1147 * OLEFontImpl_SetRatio (IFont)
1149 * See Windows documentation for more details on IFont methods.
1151 static HRESULT WINAPI OLEFontImpl_SetRatio(
1156 OLEFontImpl *this = (OLEFontImpl *)iface;
1157 TRACE("(%p)->(%ld, %ld)\n", this, cyLogical, cyHimetric);
1159 this->cyLogical = cyLogical;
1160 this->cyHimetric = cyHimetric;
1165 /************************************************************************
1166 * OLEFontImpl_QueryTextMetrics (IFont)
1168 * See Windows documentation for more details on IFont methods.
1170 static HRESULT WINAPI OLEFontImpl_QueryTextMetrics(
1175 HFONT hOldFont, hNewFont;
1178 OLEFontImpl_get_hFont(iface, &hNewFont);
1179 hOldFont = SelectObject(hdcRef, hNewFont);
1180 GetTextMetricsW(hdcRef, ptm);
1181 SelectObject(hdcRef, hOldFont);
1182 ReleaseDC(0, hdcRef);
1186 /************************************************************************
1187 * OLEFontImpl_AddRefHfont (IFont)
1189 * See Windows documentation for more details on IFont methods.
1191 static HRESULT WINAPI OLEFontImpl_AddRefHfont(
1195 OLEFontImpl *this = (OLEFontImpl *)iface;
1196 TRACE("(%p)->(%p) (lock=%ld)\n", this, hfont, this->fontLock);
1198 if ( (hfont == 0) ||
1199 (hfont != this->gdiFont) )
1200 return E_INVALIDARG;
1207 /************************************************************************
1208 * OLEFontImpl_ReleaseHfont (IFont)
1210 * See Windows documentation for more details on IFont methods.
1212 static HRESULT WINAPI OLEFontImpl_ReleaseHfont(
1216 OLEFontImpl *this = (OLEFontImpl *)iface;
1217 TRACE("(%p)->(%p) (lock=%ld)\n", this, hfont, this->fontLock);
1219 if ( (hfont == 0) ||
1220 (hfont != this->gdiFont) )
1221 return E_INVALIDARG;
1226 * If we just released our last font reference, destroy it.
1228 if (this->fontLock==0)
1230 DeleteObject(this->gdiFont);
1237 /************************************************************************
1238 * OLEFontImpl_SetHdc (IFont)
1240 * See Windows documentation for more details on IFont methods.
1242 static HRESULT WINAPI OLEFontImpl_SetHdc(
1246 OLEFontImpl *this = (OLEFontImpl *)iface;
1247 FIXME("(%p)->(%p): Stub\n", this, hdc);
1251 /************************************************************************
1252 * OLEFontImpl_IDispatch_QueryInterface (IUnknown)
1254 * See Windows documentation for more details on IUnknown methods.
1256 static HRESULT WINAPI OLEFontImpl_IDispatch_QueryInterface(
1261 OLEFontImpl *this = impl_from_IDispatch(iface);
1263 return IFont_QueryInterface((IFont *)this, riid, ppvoid);
1266 /************************************************************************
1267 * OLEFontImpl_IDispatch_Release (IUnknown)
1269 * See Windows documentation for more details on IUnknown methods.
1271 static ULONG WINAPI OLEFontImpl_IDispatch_Release(
1274 OLEFontImpl *this = impl_from_IDispatch(iface);
1276 return IFont_Release((IFont *)this);
1279 /************************************************************************
1280 * OLEFontImpl_IDispatch_AddRef (IUnknown)
1282 * See Windows documentation for more details on IUnknown methods.
1284 static ULONG WINAPI OLEFontImpl_IDispatch_AddRef(
1287 OLEFontImpl *this = impl_from_IDispatch(iface);
1289 return IFont_AddRef((IFont *)this);
1292 /************************************************************************
1293 * OLEFontImpl_GetTypeInfoCount (IDispatch)
1295 * See Windows documentation for more details on IDispatch methods.
1297 static HRESULT WINAPI OLEFontImpl_GetTypeInfoCount(
1299 unsigned int* pctinfo)
1301 OLEFontImpl *this = impl_from_IDispatch(iface);
1302 FIXME("(%p)->(%p): Stub\n", this, pctinfo);
1307 /************************************************************************
1308 * OLEFontImpl_GetTypeInfo (IDispatch)
1310 * See Windows documentation for more details on IDispatch methods.
1312 static HRESULT WINAPI OLEFontImpl_GetTypeInfo(
1316 ITypeInfo** ppTInfo)
1318 static const WCHAR stdole2tlb[] = {'s','t','d','o','l','e','2','.','t','l','b',0};
1322 OLEFontImpl *this = impl_from_IDispatch(iface);
1323 TRACE("(%p, iTInfo=%d, lcid=%04x, %p)\n", this, iTInfo, (int)lcid, ppTInfo);
1326 hres = LoadTypeLib(stdole2tlb, &tl);
1328 ERR("Could not load the stdole2.tlb?\n");
1331 hres = ITypeLib_GetTypeInfoOfGuid(tl, &IID_IFontDisp, ppTInfo);
1333 FIXME("Did not IDispatch typeinfo from typelib, hres %lx\n",hres);
1338 /************************************************************************
1339 * OLEFontImpl_GetIDsOfNames (IDispatch)
1341 * See Windows documentation for more details on IDispatch methods.
1343 static HRESULT WINAPI OLEFontImpl_GetIDsOfNames(
1346 LPOLESTR* rgszNames,
1354 OLEFontImpl *this = impl_from_IDispatch(iface);
1356 TRACE("(%p,%s,%p,cNames=%d,lcid=%04x,%p)\n", this, debugstr_guid(riid),
1357 rgszNames, cNames, (int)lcid, rgDispId);
1361 return E_INVALIDARG;
1365 /* retrieve type information */
1366 hres = OLEFontImpl_GetTypeInfo(iface, 0, lcid, &pTInfo);
1370 ERR("GetTypeInfo failed.\n");
1374 /* convert names to DISPIDs */
1375 hres = DispGetIDsOfNames (pTInfo, rgszNames, cNames, rgDispId);
1376 ITypeInfo_Release(pTInfo);
1382 /************************************************************************
1383 * OLEFontImpl_Invoke (IDispatch)
1385 * See Windows documentation for more details on IDispatch methods.
1387 * Note: Do not call _put_Xxx methods, since setting things here
1388 * should not call notify functions as I found out debugging the generic
1391 static HRESULT WINAPI OLEFontImpl_Invoke(
1393 DISPID dispIdMember,
1397 DISPPARAMS* pDispParams,
1398 VARIANT* pVarResult,
1399 EXCEPINFO* pExepInfo,
1402 OLEFontImpl *this = impl_from_IDispatch(iface);
1405 /* validate parameters */
1407 if (!IsEqualIID(riid, &IID_NULL))
1409 ERR("riid was %s instead of IID_NULL\n", debugstr_guid(riid));
1410 return DISP_E_UNKNOWNINTERFACE;
1413 if (wFlags & DISPATCH_PROPERTYGET)
1417 ERR("null pVarResult not allowed when DISPATCH_PROPERTYGET specified\n");
1418 return DISP_E_PARAMNOTOPTIONAL;
1421 else if (wFlags & DISPATCH_PROPERTYPUT)
1425 ERR("null pDispParams not allowed when DISPATCH_PROPERTYPUT specified\n");
1426 return DISP_E_PARAMNOTOPTIONAL;
1428 if (pDispParams->cArgs != 1)
1430 ERR("param count for DISPATCH_PROPERTYPUT was %d instead of 1\n", pDispParams->cArgs);
1431 return DISP_E_BADPARAMCOUNT;
1436 ERR("one of DISPATCH_PROPERTYGET or DISPATCH_PROPERTYPUT must be specified\n");
1437 return DISP_E_MEMBERNOTFOUND;
1440 switch (dispIdMember) {
1441 case DISPID_FONT_NAME:
1442 if (wFlags & DISPATCH_PROPERTYGET) {
1443 V_VT(pVarResult) = VT_BSTR;
1444 return IFont_get_Name((IFont *)this, &V_BSTR(pVarResult));
1448 VariantInit(&vararg);
1449 hr = VariantChangeTypeEx(&vararg, &pDispParams->rgvarg[0], lcid, 0, VT_BSTR);
1453 hr = IFont_put_Name((IFont *)this, V_BSTR(&vararg));
1455 VariantClear(&vararg);
1459 case DISPID_FONT_BOLD:
1460 if (wFlags & DISPATCH_PROPERTYGET) {
1462 hr = IFont_get_Bold((IFont *)this, &value);
1463 V_VT(pVarResult) = VT_BOOL;
1464 V_BOOL(pVarResult) = value ? VARIANT_TRUE : VARIANT_FALSE;
1469 VariantInit(&vararg);
1470 hr = VariantChangeTypeEx(&vararg, &pDispParams->rgvarg[0], lcid, 0, VT_BOOL);
1474 hr = IFont_put_Bold((IFont *)this, V_BOOL(&vararg));
1476 VariantClear(&vararg);
1480 case DISPID_FONT_ITALIC:
1481 if (wFlags & DISPATCH_PROPERTYGET) {
1483 hr = IFont_get_Italic((IFont *)this, &value);
1484 V_VT(pVarResult) = VT_BOOL;
1485 V_BOOL(pVarResult) = value ? VARIANT_TRUE : VARIANT_FALSE;
1491 VariantInit(&vararg);
1492 hr = VariantChangeTypeEx(&vararg, &pDispParams->rgvarg[0], lcid, 0, VT_BOOL);
1496 hr = IFont_put_Italic((IFont *)this, V_BOOL(&vararg));
1498 VariantClear(&vararg);
1502 case DISPID_FONT_UNDER:
1503 if (wFlags & DISPATCH_PROPERTYGET) {
1505 hr = IFont_get_Underline((IFont *)this, &value);
1506 V_VT(pVarResult) = VT_BOOL;
1507 V_BOOL(pVarResult) = value ? VARIANT_TRUE : VARIANT_FALSE;
1513 VariantInit(&vararg);
1514 hr = VariantChangeTypeEx(&vararg, &pDispParams->rgvarg[0], lcid, 0, VT_BOOL);
1518 hr = IFont_put_Underline((IFont *)this, V_BOOL(&vararg));
1520 VariantClear(&vararg);
1524 case DISPID_FONT_STRIKE:
1525 if (wFlags & DISPATCH_PROPERTYGET) {
1527 hr = IFont_get_Strikethrough((IFont *)this, &value);
1528 V_VT(pVarResult) = VT_BOOL;
1529 V_BOOL(pVarResult) = value ? VARIANT_TRUE : VARIANT_FALSE;
1535 VariantInit(&vararg);
1536 hr = VariantChangeTypeEx(&vararg, &pDispParams->rgvarg[0], lcid, 0, VT_BOOL);
1540 hr = IFont_put_Strikethrough((IFont *)this, V_BOOL(&vararg));
1542 VariantClear(&vararg);
1546 case DISPID_FONT_SIZE:
1547 if (wFlags & DISPATCH_PROPERTYGET) {
1548 V_VT(pVarResult) = VT_CY;
1549 return OLEFontImpl_get_Size((IFont *)this, &V_CY(pVarResult));
1554 VariantInit(&vararg);
1555 hr = VariantChangeTypeEx(&vararg, &pDispParams->rgvarg[0], lcid, 0, VT_CY);
1559 hr = IFont_put_Size((IFont *)this, V_CY(&vararg));
1561 VariantClear(&vararg);
1565 case DISPID_FONT_CHARSET:
1566 if (wFlags & DISPATCH_PROPERTYGET) {
1567 V_VT(pVarResult) = VT_I2;
1568 return OLEFontImpl_get_Charset((IFont *)this, &V_I2(pVarResult));
1573 VariantInit(&vararg);
1574 hr = VariantChangeTypeEx(&vararg, &pDispParams->rgvarg[0], lcid, 0, VT_I2);
1578 hr = IFont_put_Charset((IFont *)this, V_I2(&vararg));
1580 VariantClear(&vararg);
1585 FIXME("%p->(%ld,%s,%lx,%x,%p,%p,%p,%p), unhandled dispid/flag!\n",
1586 this,dispIdMember,debugstr_guid(riid),lcid,
1587 wFlags,pDispParams,pVarResult,pExepInfo,puArgErr
1592 /************************************************************************
1593 * OLEFontImpl_IPersistStream_QueryInterface (IUnknown)
1595 * See Windows documentation for more details on IUnknown methods.
1597 static HRESULT WINAPI OLEFontImpl_IPersistStream_QueryInterface(
1598 IPersistStream* iface,
1602 OLEFontImpl *this = impl_from_IPersistStream(iface);
1604 return IFont_QueryInterface((IFont *)this, riid, ppvoid);
1607 /************************************************************************
1608 * OLEFontImpl_IPersistStream_Release (IUnknown)
1610 * See Windows documentation for more details on IUnknown methods.
1612 static ULONG WINAPI OLEFontImpl_IPersistStream_Release(
1613 IPersistStream* iface)
1615 OLEFontImpl *this = impl_from_IPersistStream(iface);
1617 return IFont_Release((IFont *)this);
1620 /************************************************************************
1621 * OLEFontImpl_IPersistStream_AddRef (IUnknown)
1623 * See Windows documentation for more details on IUnknown methods.
1625 static ULONG WINAPI OLEFontImpl_IPersistStream_AddRef(
1626 IPersistStream* iface)
1628 OLEFontImpl *this = impl_from_IPersistStream(iface);
1630 return IFont_AddRef((IFont *)this);
1633 /************************************************************************
1634 * OLEFontImpl_GetClassID (IPersistStream)
1636 * See Windows documentation for more details on IPersistStream methods.
1638 static HRESULT WINAPI OLEFontImpl_GetClassID(
1639 IPersistStream* iface,
1642 TRACE("(%p,%p)\n",iface,pClassID);
1646 memcpy(pClassID, &CLSID_StdFont, sizeof(CLSID_StdFont));
1651 /************************************************************************
1652 * OLEFontImpl_IsDirty (IPersistStream)
1654 * See Windows documentation for more details on IPersistStream methods.
1656 static HRESULT WINAPI OLEFontImpl_IsDirty(
1657 IPersistStream* iface)
1659 TRACE("(%p)\n",iface);
1663 /************************************************************************
1664 * OLEFontImpl_Load (IPersistStream)
1666 * See Windows documentation for more details on IPersistStream methods.
1668 * This is the format of the standard font serialization as far as I
1671 * Offset Type Value Comment
1672 * 0x0000 Byte Unknown Probably a version number, contains 0x01
1673 * 0x0001 Short Charset Charset value from the FONTDESC structure
1674 * 0x0003 Byte Attributes Flags defined as follows:
1676 * 00000100 - Underline
1677 * 00001000 - Strikethrough
1678 * 0x0004 Short Weight Weight value from FONTDESC structure
1679 * 0x0006 DWORD size "Low" portion of the cySize member of the FONTDESC
1681 * 0x000A Byte name length Length of the font name string (no null character)
1682 * 0x000B String name Name of the font (ASCII, no nul character)
1684 static HRESULT WINAPI OLEFontImpl_Load(
1685 IPersistStream* iface,
1686 IStream* pLoadStream)
1688 char readBuffer[0x100];
1695 OLEFontImpl *this = impl_from_IPersistStream(iface);
1698 * Read the version byte
1700 IStream_Read(pLoadStream, &bVersion, 1, &cbRead);
1709 IStream_Read(pLoadStream, &this->description.sCharset, 2, &cbRead);
1717 IStream_Read(pLoadStream, &bAttributes, 1, &cbRead);
1722 this->description.fItalic = (bAttributes & FONTPERSIST_ITALIC) != 0;
1723 this->description.fStrikethrough = (bAttributes & FONTPERSIST_STRIKETHROUGH) != 0;
1724 this->description.fUnderline = (bAttributes & FONTPERSIST_UNDERLINE) != 0;
1729 IStream_Read(pLoadStream, &this->description.sWeight, 2, &cbRead);
1737 IStream_Read(pLoadStream, &this->description.cySize.s.Lo, 4, &cbRead);
1742 this->description.cySize.s.Hi = 0;
1747 IStream_Read(pLoadStream, &bStringSize, 1, &cbRead);
1752 IStream_Read(pLoadStream, readBuffer, bStringSize, &cbRead);
1754 if (cbRead!=bStringSize)
1757 HeapFree(GetProcessHeap(), 0, this->description.lpstrName);
1759 len = MultiByteToWideChar( CP_ACP, 0, readBuffer, bStringSize, NULL, 0 );
1760 this->description.lpstrName = HeapAlloc( GetProcessHeap(), 0, (len+1) * sizeof(WCHAR) );
1761 MultiByteToWideChar( CP_ACP, 0, readBuffer, bStringSize, this->description.lpstrName, len );
1762 this->description.lpstrName[len] = 0;
1764 /* Ensure use of this font causes a new one to be created @@@@ */
1765 DeleteObject(this->gdiFont);
1771 /************************************************************************
1772 * OLEFontImpl_Save (IPersistStream)
1774 * See Windows documentation for more details on IPersistStream methods.
1776 static HRESULT WINAPI OLEFontImpl_Save(
1777 IPersistStream* iface,
1778 IStream* pOutStream,
1781 char* writeBuffer = NULL;
1783 BYTE bVersion = 0x01;
1787 OLEFontImpl *this = impl_from_IPersistStream(iface);
1790 * Read the version byte
1792 IStream_Write(pOutStream, &bVersion, 1, &cbWritten);
1800 IStream_Write(pOutStream, &this->description.sCharset, 2, &cbWritten);
1810 if (this->description.fItalic)
1811 bAttributes |= FONTPERSIST_ITALIC;
1813 if (this->description.fStrikethrough)
1814 bAttributes |= FONTPERSIST_STRIKETHROUGH;
1816 if (this->description.fUnderline)
1817 bAttributes |= FONTPERSIST_UNDERLINE;
1819 IStream_Write(pOutStream, &bAttributes, 1, &cbWritten);
1827 IStream_Write(pOutStream, &this->description.sWeight, 2, &cbWritten);
1835 IStream_Write(pOutStream, &this->description.cySize.s.Lo, 4, &cbWritten);
1843 if (this->description.lpstrName!=0)
1844 bStringSize = WideCharToMultiByte( CP_ACP, 0, this->description.lpstrName,
1845 strlenW(this->description.lpstrName), NULL, 0, NULL, NULL );
1849 IStream_Write(pOutStream, &bStringSize, 1, &cbWritten);
1856 if (!(writeBuffer = HeapAlloc( GetProcessHeap(), 0, bStringSize ))) return E_OUTOFMEMORY;
1857 WideCharToMultiByte( CP_ACP, 0, this->description.lpstrName,
1858 strlenW(this->description.lpstrName),
1859 writeBuffer, bStringSize, NULL, NULL );
1861 IStream_Write(pOutStream, writeBuffer, bStringSize, &cbWritten);
1862 HeapFree(GetProcessHeap(), 0, writeBuffer);
1864 if (cbWritten!=bStringSize)
1871 /************************************************************************
1872 * OLEFontImpl_GetSizeMax (IPersistStream)
1874 * See Windows documentation for more details on IPersistStream methods.
1876 static HRESULT WINAPI OLEFontImpl_GetSizeMax(
1877 IPersistStream* iface,
1878 ULARGE_INTEGER* pcbSize)
1880 OLEFontImpl *this = impl_from_IPersistStream(iface);
1885 pcbSize->u.HighPart = 0;
1886 pcbSize->u.LowPart = 0;
1888 pcbSize->u.LowPart += sizeof(BYTE); /* Version */
1889 pcbSize->u.LowPart += sizeof(WORD); /* Lang code */
1890 pcbSize->u.LowPart += sizeof(BYTE); /* Flags */
1891 pcbSize->u.LowPart += sizeof(WORD); /* Weight */
1892 pcbSize->u.LowPart += sizeof(DWORD); /* Size */
1893 pcbSize->u.LowPart += sizeof(BYTE); /* StrLength */
1895 if (this->description.lpstrName!=0)
1896 pcbSize->u.LowPart += lstrlenW(this->description.lpstrName);
1901 /************************************************************************
1902 * OLEFontImpl_IConnectionPointContainer_QueryInterface (IUnknown)
1904 * See Windows documentation for more details on IUnknown methods.
1906 static HRESULT WINAPI OLEFontImpl_IConnectionPointContainer_QueryInterface(
1907 IConnectionPointContainer* iface,
1911 OLEFontImpl *this = impl_from_IConnectionPointContainer(iface);
1913 return IFont_QueryInterface((IFont*)this, riid, ppvoid);
1916 /************************************************************************
1917 * OLEFontImpl_IConnectionPointContainer_Release (IUnknown)
1919 * See Windows documentation for more details on IUnknown methods.
1921 static ULONG WINAPI OLEFontImpl_IConnectionPointContainer_Release(
1922 IConnectionPointContainer* iface)
1924 OLEFontImpl *this = impl_from_IConnectionPointContainer(iface);
1926 return IFont_Release((IFont*)this);
1929 /************************************************************************
1930 * OLEFontImpl_IConnectionPointContainer_AddRef (IUnknown)
1932 * See Windows documentation for more details on IUnknown methods.
1934 static ULONG WINAPI OLEFontImpl_IConnectionPointContainer_AddRef(
1935 IConnectionPointContainer* iface)
1937 OLEFontImpl *this = impl_from_IConnectionPointContainer(iface);
1939 return IFont_AddRef((IFont*)this);
1942 /************************************************************************
1943 * OLEFontImpl_EnumConnectionPoints (IConnectionPointContainer)
1945 * See Windows documentation for more details on IConnectionPointContainer
1948 static HRESULT WINAPI OLEFontImpl_EnumConnectionPoints(
1949 IConnectionPointContainer* iface,
1950 IEnumConnectionPoints **ppEnum)
1952 OLEFontImpl *this = impl_from_IConnectionPointContainer(iface);
1954 FIXME("(%p)->(%p): stub\n", this, ppEnum);
1958 /************************************************************************
1959 * OLEFontImpl_FindConnectionPoint (IConnectionPointContainer)
1961 * See Windows documentation for more details on IConnectionPointContainer
1964 static HRESULT WINAPI OLEFontImpl_FindConnectionPoint(
1965 IConnectionPointContainer* iface,
1967 IConnectionPoint **ppCp)
1969 OLEFontImpl *this = impl_from_IConnectionPointContainer(iface);
1970 TRACE("(%p)->(%s, %p): stub\n", this, debugstr_guid(riid), ppCp);
1972 if(IsEqualIID(riid, &IID_IPropertyNotifySink)) {
1973 return IConnectionPoint_QueryInterface(this->pPropertyNotifyCP,
1974 &IID_IConnectionPoint,
1976 } else if(IsEqualIID(riid, &IID_IFontEventsDisp)) {
1977 return IConnectionPoint_QueryInterface(this->pFontEventsCP,
1978 &IID_IConnectionPoint,
1981 FIXME("no connection point for %s\n", debugstr_guid(riid));
1982 return CONNECT_E_NOCONNECTION;
1986 /************************************************************************
1987 * OLEFontImpl implementation of IPersistPropertyBag.
1989 static HRESULT WINAPI OLEFontImpl_IPersistPropertyBag_QueryInterface(
1990 IPersistPropertyBag *iface, REFIID riid, LPVOID *ppvObj
1992 OLEFontImpl *this = impl_from_IPersistPropertyBag(iface);
1993 return IFont_QueryInterface((IFont *)this,riid,ppvObj);
1996 static ULONG WINAPI OLEFontImpl_IPersistPropertyBag_AddRef(
1997 IPersistPropertyBag *iface
1999 OLEFontImpl *this = impl_from_IPersistPropertyBag(iface);
2000 return IFont_AddRef((IFont *)this);
2003 static ULONG WINAPI OLEFontImpl_IPersistPropertyBag_Release(
2004 IPersistPropertyBag *iface
2006 OLEFontImpl *this = impl_from_IPersistPropertyBag(iface);
2007 return IFont_Release((IFont *)this);
2010 static HRESULT WINAPI OLEFontImpl_IPersistPropertyBag_GetClassID(
2011 IPersistPropertyBag *iface, CLSID *classid
2013 FIXME("(%p,%p), stub!\n", iface, classid);
2017 static HRESULT WINAPI OLEFontImpl_IPersistPropertyBag_InitNew(
2018 IPersistPropertyBag *iface
2020 FIXME("(%p), stub!\n", iface);
2024 static HRESULT WINAPI OLEFontImpl_IPersistPropertyBag_Load(
2025 IPersistPropertyBag *iface, IPropertyBag* pPropBag, IErrorLog* pErrorLog
2027 /* (from Visual Basic 6 property bag)
2028 Name = "MS Sans Serif"
2032 Underline = 0 'False
2034 Strikethrough = 0 'False
2036 static const WCHAR sAttrName[] = {'N','a','m','e',0};
2037 static const WCHAR sAttrSize[] = {'S','i','z','e',0};
2038 static const WCHAR sAttrCharset[] = {'C','h','a','r','s','e','t',0};
2039 static const WCHAR sAttrWeight[] = {'W','e','i','g','h','t',0};
2040 static const WCHAR sAttrUnderline[] = {'U','n','d','e','r','l','i','n','e',0};
2041 static const WCHAR sAttrItalic[] = {'I','t','a','l','i','c',0};
2042 static const WCHAR sAttrStrikethrough[] = {'S','t','r','i','k','e','t','h','r','o','u','g','h',0};
2045 HRESULT iRes = S_OK;
2046 OLEFontImpl *this = impl_from_IPersistPropertyBag(iface);
2048 VariantInit(&rawAttr);
2049 VariantInit(&valueAttr);
2052 iRes = IPropertyBag_Read(pPropBag, sAttrName, &rawAttr, pErrorLog);
2055 iRes = VariantChangeType(&rawAttr, &valueAttr, 0, VT_BSTR);
2057 iRes = IFont_put_Name((IFont *)this, V_BSTR(&valueAttr));
2059 else if (iRes == E_INVALIDARG)
2061 VariantClear(&rawAttr);
2062 VariantClear(&valueAttr);
2066 iRes = IPropertyBag_Read(pPropBag, sAttrSize, &rawAttr, pErrorLog);
2069 iRes = VariantChangeType(&rawAttr, &valueAttr, 0, VT_CY);
2071 iRes = IFont_put_Size((IFont *)this, V_CY(&valueAttr));
2073 else if (iRes == E_INVALIDARG)
2075 VariantClear(&rawAttr);
2076 VariantClear(&valueAttr);
2080 iRes = IPropertyBag_Read(pPropBag, sAttrCharset, &rawAttr, pErrorLog);
2083 iRes = VariantChangeType(&rawAttr, &valueAttr, 0, VT_I2);
2085 iRes = IFont_put_Charset((IFont *)this, V_I2(&valueAttr));
2087 else if (iRes == E_INVALIDARG)
2089 VariantClear(&rawAttr);
2090 VariantClear(&valueAttr);
2094 iRes = IPropertyBag_Read(pPropBag, sAttrWeight, &rawAttr, pErrorLog);
2097 iRes = VariantChangeType(&rawAttr, &valueAttr, 0, VT_I2);
2099 iRes = IFont_put_Weight((IFont *)this, V_I2(&valueAttr));
2101 else if (iRes == E_INVALIDARG)
2103 VariantClear(&rawAttr);
2104 VariantClear(&valueAttr);
2109 iRes = IPropertyBag_Read(pPropBag, sAttrUnderline, &rawAttr, pErrorLog);
2112 iRes = VariantChangeType(&rawAttr, &valueAttr, 0, VT_BOOL);
2114 iRes = IFont_put_Underline((IFont *)this, V_BOOL(&valueAttr));
2116 else if (iRes == E_INVALIDARG)
2118 VariantClear(&rawAttr);
2119 VariantClear(&valueAttr);
2123 iRes = IPropertyBag_Read(pPropBag, sAttrItalic, &rawAttr, pErrorLog);
2126 iRes = VariantChangeType(&rawAttr, &valueAttr, 0, VT_BOOL);
2128 iRes = IFont_put_Italic((IFont *)this, V_BOOL(&valueAttr));
2130 else if (iRes == E_INVALIDARG)
2132 VariantClear(&rawAttr);
2133 VariantClear(&valueAttr);
2137 iRes = IPropertyBag_Read(pPropBag, sAttrStrikethrough, &rawAttr, pErrorLog);
2140 iRes = VariantChangeType(&rawAttr, &valueAttr, 0, VT_BOOL);
2142 IFont_put_Strikethrough((IFont *)this, V_BOOL(&valueAttr));
2144 else if (iRes == E_INVALIDARG)
2146 VariantClear(&rawAttr);
2147 VariantClear(&valueAttr);
2151 WARN("-- 0x%08lx\n", iRes);
2155 static HRESULT WINAPI OLEFontImpl_IPersistPropertyBag_Save(
2156 IPersistPropertyBag *iface, IPropertyBag* pPropBag, BOOL fClearDirty,
2157 BOOL fSaveAllProperties
2159 FIXME("(%p,%p,%d,%d), stub!\n", iface, pPropBag, fClearDirty, fSaveAllProperties);
2163 static const IPersistPropertyBagVtbl OLEFontImpl_IPersistPropertyBag_VTable =
2165 OLEFontImpl_IPersistPropertyBag_QueryInterface,
2166 OLEFontImpl_IPersistPropertyBag_AddRef,
2167 OLEFontImpl_IPersistPropertyBag_Release,
2169 OLEFontImpl_IPersistPropertyBag_GetClassID,
2170 OLEFontImpl_IPersistPropertyBag_InitNew,
2171 OLEFontImpl_IPersistPropertyBag_Load,
2172 OLEFontImpl_IPersistPropertyBag_Save
2175 /************************************************************************
2176 * OLEFontImpl implementation of IPersistStreamInit.
2178 static HRESULT WINAPI OLEFontImpl_IPersistStreamInit_QueryInterface(
2179 IPersistStreamInit *iface, REFIID riid, LPVOID *ppvObj
2181 OLEFontImpl *this = impl_from_IPersistStreamInit(iface);
2182 return IFont_QueryInterface((IFont *)this,riid,ppvObj);
2185 static ULONG WINAPI OLEFontImpl_IPersistStreamInit_AddRef(
2186 IPersistStreamInit *iface
2188 OLEFontImpl *this = impl_from_IPersistStreamInit(iface);
2189 return IFont_AddRef((IFont *)this);
2192 static ULONG WINAPI OLEFontImpl_IPersistStreamInit_Release(
2193 IPersistStreamInit *iface
2195 OLEFontImpl *this = impl_from_IPersistStreamInit(iface);
2196 return IFont_Release((IFont *)this);
2199 static HRESULT WINAPI OLEFontImpl_IPersistStreamInit_GetClassID(
2200 IPersistStreamInit *iface, CLSID *classid
2202 FIXME("(%p,%p), stub!\n", iface, classid);
2206 static HRESULT WINAPI OLEFontImpl_IPersistStreamInit_IsDirty(
2207 IPersistStreamInit *iface
2209 FIXME("(%p), stub!\n", iface);
2213 static HRESULT WINAPI OLEFontImpl_IPersistStreamInit_Load(
2214 IPersistStreamInit *iface, LPSTREAM pStm
2216 FIXME("(%p,%p), stub!\n", iface, pStm);
2220 static HRESULT WINAPI OLEFontImpl_IPersistStreamInit_Save(
2221 IPersistStreamInit *iface, LPSTREAM pStm, BOOL fClearDirty
2223 FIXME("(%p,%p,%d), stub!\n", iface, pStm, fClearDirty);
2227 static HRESULT WINAPI OLEFontImpl_IPersistStreamInit_GetSizeMax(
2228 IPersistStreamInit *iface, ULARGE_INTEGER *pcbSize
2230 FIXME("(%p,%p), stub!\n", iface, pcbSize);
2234 static HRESULT WINAPI OLEFontImpl_IPersistStreamInit_InitNew(
2235 IPersistStreamInit *iface
2237 FIXME("(%p), stub!\n", iface);
2241 static const IPersistStreamInitVtbl OLEFontImpl_IPersistStreamInit_VTable =
2243 OLEFontImpl_IPersistStreamInit_QueryInterface,
2244 OLEFontImpl_IPersistStreamInit_AddRef,
2245 OLEFontImpl_IPersistStreamInit_Release,
2247 OLEFontImpl_IPersistStreamInit_GetClassID,
2248 OLEFontImpl_IPersistStreamInit_IsDirty,
2249 OLEFontImpl_IPersistStreamInit_Load,
2250 OLEFontImpl_IPersistStreamInit_Save,
2251 OLEFontImpl_IPersistStreamInit_GetSizeMax,
2252 OLEFontImpl_IPersistStreamInit_InitNew
2255 /*******************************************************************************
2256 * StdFont ClassFactory
2260 /* IUnknown fields */
2261 const IClassFactoryVtbl *lpVtbl;
2263 } IClassFactoryImpl;
2265 static HRESULT WINAPI
2266 SFCF_QueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj) {
2267 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
2269 FIXME("(%p)->(%s,%p),stub!\n",This,debugstr_guid(riid),ppobj);
2270 return E_NOINTERFACE;
2274 SFCF_AddRef(LPCLASSFACTORY iface) {
2275 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
2276 return InterlockedIncrement(&This->ref);
2279 static ULONG WINAPI SFCF_Release(LPCLASSFACTORY iface) {
2280 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
2281 /* static class, won't be freed */
2282 return InterlockedDecrement(&This->ref);
2285 static HRESULT WINAPI SFCF_CreateInstance(
2286 LPCLASSFACTORY iface,LPUNKNOWN pOuter,REFIID riid,LPVOID *ppobj
2288 return OleCreateFontIndirect(NULL,riid,ppobj);
2292 static HRESULT WINAPI SFCF_LockServer(LPCLASSFACTORY iface,BOOL dolock) {
2293 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
2294 FIXME("(%p)->(%d),stub!\n",This,dolock);
2298 static const IClassFactoryVtbl SFCF_Vtbl = {
2299 SFCF_QueryInterface,
2302 SFCF_CreateInstance,
2305 static IClassFactoryImpl STDFONT_CF = {&SFCF_Vtbl, 1 };
2307 void _get_STDFONT_CF(LPVOID *ppv) { *ppv = (LPVOID)&STDFONT_CF; }