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 */
45 WINE_DEFAULT_DEBUG_CHANNEL(ole);
47 /***********************************************************************
48 * Declaration of constants used when serializing the font object.
50 #define FONTPERSIST_ITALIC 0x02
51 #define FONTPERSIST_UNDERLINE 0x04
52 #define FONTPERSIST_STRIKETHROUGH 0x08
54 /***********************************************************************
55 * Declaration of the implementation class for the IFont interface
57 typedef struct OLEFontImpl OLEFontImpl;
62 * This class supports many interfaces. IUnknown, IFont,
63 * IDispatch, IDispFont IPersistStream and IConnectionPointContainer.
64 * The first two are supported by the first vtable, the next two are
65 * supported by the second table and the last two have their own.
67 const IFontVtbl* lpVtbl;
68 const IDispatchVtbl* lpvtblIDispatch;
69 const IPersistStreamVtbl* lpvtblIPersistStream;
70 const IConnectionPointContainerVtbl* lpvtblIConnectionPointContainer;
71 const IPersistPropertyBagVtbl* lpvtblIPersistPropertyBag;
72 const IPersistStreamInitVtbl* lpvtblIPersistStreamInit;
74 * Reference count for that instance of the class.
79 * This structure contains the description of the class.
84 * Contain the font associated with this object.
99 IConnectionPoint *pPropertyNotifyCP;
100 IConnectionPoint *pFontEventsCP;
104 * Here, I define utility macros to help with the casting of the
106 * There is a version to accommodate all of the VTables implemented
110 static inline OLEFontImpl *impl_from_IDispatch( IDispatch *iface )
112 return (OLEFontImpl *)((char*)iface - FIELD_OFFSET(OLEFontImpl, lpvtblIDispatch));
115 static inline OLEFontImpl *impl_from_IPersistStream( IPersistStream *iface )
117 return (OLEFontImpl *)((char*)iface - FIELD_OFFSET(OLEFontImpl, lpvtblIPersistStream));
120 static inline OLEFontImpl *impl_from_IConnectionPointContainer( IConnectionPointContainer *iface )
122 return (OLEFontImpl *)((char*)iface - FIELD_OFFSET(OLEFontImpl, lpvtblIConnectionPointContainer));
125 static inline OLEFontImpl *impl_from_IPersistPropertyBag( IPersistPropertyBag *iface )
127 return (OLEFontImpl *)((char*)iface - FIELD_OFFSET(OLEFontImpl, lpvtblIPersistPropertyBag));
130 static inline OLEFontImpl *impl_from_IPersistStreamInit( IPersistStreamInit *iface )
132 return (OLEFontImpl *)((char*)iface - FIELD_OFFSET(OLEFontImpl, lpvtblIPersistStreamInit));
136 /***********************************************************************
137 * Prototypes for the implementation functions for the IFont
140 static OLEFontImpl* OLEFontImpl_Construct(LPFONTDESC fontDesc);
141 static void OLEFontImpl_Destroy(OLEFontImpl* fontDesc);
142 static HRESULT WINAPI OLEFontImpl_QueryInterface(IFont* iface, REFIID riid, VOID** ppvoid);
143 static ULONG WINAPI OLEFontImpl_AddRef(IFont* iface);
144 static ULONG WINAPI OLEFontImpl_Release(IFont* iface);
145 static HRESULT WINAPI OLEFontImpl_get_Name(IFont* iface, BSTR* pname);
146 static HRESULT WINAPI OLEFontImpl_put_Name(IFont* iface, BSTR name);
147 static HRESULT WINAPI OLEFontImpl_get_Size(IFont* iface, CY* psize);
148 static HRESULT WINAPI OLEFontImpl_put_Size(IFont* iface, CY size);
149 static HRESULT WINAPI OLEFontImpl_get_Bold(IFont* iface, BOOL* pbold);
150 static HRESULT WINAPI OLEFontImpl_put_Bold(IFont* iface, BOOL bold);
151 static HRESULT WINAPI OLEFontImpl_get_Italic(IFont* iface, BOOL* pitalic);
152 static HRESULT WINAPI OLEFontImpl_put_Italic(IFont* iface, BOOL italic);
153 static HRESULT WINAPI OLEFontImpl_get_Underline(IFont* iface, BOOL* punderline);
154 static HRESULT WINAPI OLEFontImpl_put_Underline(IFont* iface, BOOL underline);
155 static HRESULT WINAPI OLEFontImpl_get_Strikethrough(IFont* iface, BOOL* pstrikethrough);
156 static HRESULT WINAPI OLEFontImpl_put_Strikethrough(IFont* iface, BOOL strikethrough);
157 static HRESULT WINAPI OLEFontImpl_get_Weight(IFont* iface, short* pweight);
158 static HRESULT WINAPI OLEFontImpl_put_Weight(IFont* iface, short weight);
159 static HRESULT WINAPI OLEFontImpl_get_Charset(IFont* iface, short* pcharset);
160 static HRESULT WINAPI OLEFontImpl_put_Charset(IFont* iface, short charset);
161 static HRESULT WINAPI OLEFontImpl_get_hFont(IFont* iface, HFONT* phfont);
162 static HRESULT WINAPI OLEFontImpl_Clone(IFont* iface, IFont** ppfont);
163 static HRESULT WINAPI OLEFontImpl_IsEqual(IFont* iface, IFont* pFontOther);
164 static HRESULT WINAPI OLEFontImpl_SetRatio(IFont* iface, LONG cyLogical, LONG cyHimetric);
165 static HRESULT WINAPI OLEFontImpl_QueryTextMetrics(IFont* iface, TEXTMETRICOLE* ptm);
166 static HRESULT WINAPI OLEFontImpl_AddRefHfont(IFont* iface, HFONT hfont);
167 static HRESULT WINAPI OLEFontImpl_ReleaseHfont(IFont* iface, HFONT hfont);
168 static HRESULT WINAPI OLEFontImpl_SetHdc(IFont* iface, HDC hdc);
170 /***********************************************************************
171 * Prototypes for the implementation functions for the IDispatch
174 static HRESULT WINAPI OLEFontImpl_IDispatch_QueryInterface(IDispatch* iface,
177 static ULONG WINAPI OLEFontImpl_IDispatch_AddRef(IDispatch* iface);
178 static ULONG WINAPI OLEFontImpl_IDispatch_Release(IDispatch* iface);
179 static HRESULT WINAPI OLEFontImpl_GetTypeInfoCount(IDispatch* iface,
180 unsigned int* pctinfo);
181 static HRESULT WINAPI OLEFontImpl_GetTypeInfo(IDispatch* iface,
184 ITypeInfo** ppTInfo);
185 static HRESULT WINAPI OLEFontImpl_GetIDsOfNames(IDispatch* iface,
191 static HRESULT WINAPI OLEFontImpl_Invoke(IDispatch* iface,
196 DISPPARAMS* pDispParams,
198 EXCEPINFO* pExepInfo,
201 /***********************************************************************
202 * Prototypes for the implementation functions for the IPersistStream
205 static HRESULT WINAPI OLEFontImpl_IPersistStream_QueryInterface(IPersistStream* iface,
208 static ULONG WINAPI OLEFontImpl_IPersistStream_AddRef(IPersistStream* iface);
209 static ULONG WINAPI OLEFontImpl_IPersistStream_Release(IPersistStream* iface);
210 static HRESULT WINAPI OLEFontImpl_GetClassID(IPersistStream* iface,
212 static HRESULT WINAPI OLEFontImpl_IsDirty(IPersistStream* iface);
213 static HRESULT WINAPI OLEFontImpl_Load(IPersistStream* iface,
214 IStream* pLoadStream);
215 static HRESULT WINAPI OLEFontImpl_Save(IPersistStream* iface,
218 static HRESULT WINAPI OLEFontImpl_GetSizeMax(IPersistStream* iface,
219 ULARGE_INTEGER* pcbSize);
221 /***********************************************************************
222 * Prototypes for the implementation functions for the
223 * IConnectionPointContainer interface
225 static HRESULT WINAPI OLEFontImpl_IConnectionPointContainer_QueryInterface(
226 IConnectionPointContainer* iface,
229 static ULONG WINAPI OLEFontImpl_IConnectionPointContainer_AddRef(
230 IConnectionPointContainer* iface);
231 static ULONG WINAPI OLEFontImpl_IConnectionPointContainer_Release(
232 IConnectionPointContainer* iface);
233 static HRESULT WINAPI OLEFontImpl_EnumConnectionPoints(
234 IConnectionPointContainer* iface,
235 IEnumConnectionPoints **ppEnum);
236 static HRESULT WINAPI OLEFontImpl_FindConnectionPoint(
237 IConnectionPointContainer* iface,
239 IConnectionPoint **ppCp);
242 * Virtual function tables for the OLEFontImpl class.
244 static const IFontVtbl OLEFontImpl_VTable =
246 OLEFontImpl_QueryInterface,
249 OLEFontImpl_get_Name,
250 OLEFontImpl_put_Name,
251 OLEFontImpl_get_Size,
252 OLEFontImpl_put_Size,
253 OLEFontImpl_get_Bold,
254 OLEFontImpl_put_Bold,
255 OLEFontImpl_get_Italic,
256 OLEFontImpl_put_Italic,
257 OLEFontImpl_get_Underline,
258 OLEFontImpl_put_Underline,
259 OLEFontImpl_get_Strikethrough,
260 OLEFontImpl_put_Strikethrough,
261 OLEFontImpl_get_Weight,
262 OLEFontImpl_put_Weight,
263 OLEFontImpl_get_Charset,
264 OLEFontImpl_put_Charset,
265 OLEFontImpl_get_hFont,
268 OLEFontImpl_SetRatio,
269 OLEFontImpl_QueryTextMetrics,
270 OLEFontImpl_AddRefHfont,
271 OLEFontImpl_ReleaseHfont,
275 static const IDispatchVtbl OLEFontImpl_IDispatch_VTable =
277 OLEFontImpl_IDispatch_QueryInterface,
278 OLEFontImpl_IDispatch_AddRef,
279 OLEFontImpl_IDispatch_Release,
280 OLEFontImpl_GetTypeInfoCount,
281 OLEFontImpl_GetTypeInfo,
282 OLEFontImpl_GetIDsOfNames,
286 static const IPersistStreamVtbl OLEFontImpl_IPersistStream_VTable =
288 OLEFontImpl_IPersistStream_QueryInterface,
289 OLEFontImpl_IPersistStream_AddRef,
290 OLEFontImpl_IPersistStream_Release,
291 OLEFontImpl_GetClassID,
295 OLEFontImpl_GetSizeMax
298 static const IConnectionPointContainerVtbl
299 OLEFontImpl_IConnectionPointContainer_VTable =
301 OLEFontImpl_IConnectionPointContainer_QueryInterface,
302 OLEFontImpl_IConnectionPointContainer_AddRef,
303 OLEFontImpl_IConnectionPointContainer_Release,
304 OLEFontImpl_EnumConnectionPoints,
305 OLEFontImpl_FindConnectionPoint
308 static const IPersistPropertyBagVtbl OLEFontImpl_IPersistPropertyBag_VTable;
309 static const IPersistStreamInitVtbl OLEFontImpl_IPersistStreamInit_VTable;
311 /******************************************************************************
312 * OleCreateFontIndirect [OLEAUT32.420]
314 HRESULT WINAPI OleCreateFontIndirect(
315 LPFONTDESC lpFontDesc,
319 OLEFontImpl* newFont = 0;
322 TRACE("(%p, %s, %p)\n", lpFontDesc, debugstr_guid(riid), ppvObj);
334 static const WCHAR fname[] = { 'S','y','s','t','e','m',0 };
336 fd.cbSizeofstruct = sizeof(fd);
337 fd.lpstrName = (WCHAR*)fname;
338 fd.cySize.s.Lo = 80000;
344 fd.fStrikethrough = 0;
349 * Try to construct a new instance of the class.
351 newFont = OLEFontImpl_Construct(lpFontDesc);
354 return E_OUTOFMEMORY;
357 * Make sure it supports the interface required by the caller.
359 hr = IFont_QueryInterface((IFont*)newFont, riid, ppvObj);
362 * Release the reference obtained in the constructor. If
363 * the QueryInterface was unsuccessful, it will free the class.
365 IFont_Release((IFont*)newFont);
371 /***********************************************************************
372 * Implementation of the OLEFontImpl class.
375 /***********************************************************************
376 * OLEFont_SendNotify (internal)
378 * Sends notification messages of changed properties to any interested
381 static void OLEFont_SendNotify(OLEFontImpl* this, DISPID dispID)
383 static const WCHAR wszName[] = {'N','a','m','e',0};
384 static const WCHAR wszSize[] = {'S','i','z','e',0};
385 static const WCHAR wszBold[] = {'B','o','l','d',0};
386 static const WCHAR wszItalic[] = {'I','t','a','l','i','c',0};
387 static const WCHAR wszUnder[] = {'U','n','d','e','r','l','i','n','e',0};
388 static const WCHAR wszStrike[] = {'S','t','r','i','k','e','t','h','r','o','u','g','h',0};
389 static const WCHAR wszWeight[] = {'W','e','i','g','h','t',0};
390 static const WCHAR wszCharset[] = {'C','h','a','r','s','s','e','t',0};
391 static const LPCWSTR dispid_mapping[] =
404 IEnumConnections *pEnum;
408 hres = IConnectionPoint_EnumConnections(this->pPropertyNotifyCP, &pEnum);
411 while(IEnumConnections_Next(pEnum, 1, &CD, NULL) == S_OK) {
412 IPropertyNotifySink *sink;
414 IUnknown_QueryInterface(CD.pUnk, &IID_IPropertyNotifySink, (LPVOID)&sink);
415 IPropertyNotifySink_OnChanged(sink, dispID);
416 IPropertyNotifySink_Release(sink);
417 IUnknown_Release(CD.pUnk);
419 IEnumConnections_Release(pEnum);
422 hres = IConnectionPoint_EnumConnections(this->pFontEventsCP, &pEnum);
425 DISPPARAMS dispparams;
428 VariantInit(&vararg);
429 V_VT(&vararg) = VT_BSTR;
430 V_BSTR(&vararg) = SysAllocString(dispid_mapping[dispID]);
432 dispparams.cArgs = 1;
433 dispparams.cNamedArgs = 0;
434 dispparams.rgdispidNamedArgs = NULL;
435 dispparams.rgvarg = &vararg;
437 while(IEnumConnections_Next(pEnum, 1, &CD, NULL) == S_OK) {
438 IFontEventsDisp *disp;
440 IUnknown_QueryInterface(CD.pUnk, &IID_IFontEventsDisp, (LPVOID)&disp);
441 IDispatch_Invoke(disp, DISPID_FONT_CHANGED, &IID_NULL,
442 LOCALE_NEUTRAL, INVOKE_FUNC, &dispparams, NULL,
445 IDispatch_Release(disp);
446 IUnknown_Release(CD.pUnk);
448 VariantClear(&vararg);
449 IEnumConnections_Release(pEnum);
453 /************************************************************************
454 * OLEFontImpl_Construct
456 * This method will construct a new instance of the OLEFontImpl
459 * The caller of this method must release the object when it's
462 static OLEFontImpl* OLEFontImpl_Construct(LPFONTDESC fontDesc)
464 OLEFontImpl* newObject = 0;
467 * Allocate space for the object.
469 newObject = HeapAlloc(GetProcessHeap(), 0, sizeof(OLEFontImpl));
475 * Initialize the virtual function table.
477 newObject->lpVtbl = &OLEFontImpl_VTable;
478 newObject->lpvtblIDispatch = &OLEFontImpl_IDispatch_VTable;
479 newObject->lpvtblIPersistStream = &OLEFontImpl_IPersistStream_VTable;
480 newObject->lpvtblIConnectionPointContainer = &OLEFontImpl_IConnectionPointContainer_VTable;
481 newObject->lpvtblIPersistPropertyBag = &OLEFontImpl_IPersistPropertyBag_VTable;
482 newObject->lpvtblIPersistStreamInit = &OLEFontImpl_IPersistStreamInit_VTable;
485 * Start with one reference count. The caller of this function
486 * must release the interface pointer when it is done.
491 * Copy the description of the font in the object.
493 assert(fontDesc->cbSizeofstruct >= sizeof(FONTDESC));
495 newObject->description.cbSizeofstruct = sizeof(FONTDESC);
496 newObject->description.lpstrName = HeapAlloc(GetProcessHeap(),
498 (lstrlenW(fontDesc->lpstrName)+1) * sizeof(WCHAR));
499 strcpyW(newObject->description.lpstrName, fontDesc->lpstrName);
500 newObject->description.cySize = fontDesc->cySize;
501 newObject->description.sWeight = fontDesc->sWeight;
502 newObject->description.sCharset = fontDesc->sCharset;
503 newObject->description.fItalic = fontDesc->fItalic;
504 newObject->description.fUnderline = fontDesc->fUnderline;
505 newObject->description.fStrikethrough = fontDesc->fStrikethrough;
508 * Initializing all the other members.
510 newObject->gdiFont = 0;
511 newObject->fontLock = 0;
512 newObject->cyLogical = 72L;
513 newObject->cyHimetric = 2540L;
514 newObject->pPropertyNotifyCP = NULL;
515 newObject->pFontEventsCP = NULL;
517 CreateConnectionPoint((IUnknown*)newObject, &IID_IPropertyNotifySink, &newObject->pPropertyNotifyCP);
518 CreateConnectionPoint((IUnknown*)newObject, &IID_IFontEventsDisp, &newObject->pFontEventsCP);
520 if (!newObject->pPropertyNotifyCP || !newObject->pFontEventsCP)
522 OLEFontImpl_Destroy(newObject);
526 TRACE("returning %p\n", newObject);
530 /************************************************************************
531 * OLEFontImpl_Destroy
533 * This method is called by the Release method when the reference
534 * count goes down to 0. It will free all resources used by
537 static void OLEFontImpl_Destroy(OLEFontImpl* fontDesc)
539 TRACE("(%p)\n", fontDesc);
541 HeapFree(GetProcessHeap(), 0, fontDesc->description.lpstrName);
543 if (fontDesc->gdiFont!=0)
544 DeleteObject(fontDesc->gdiFont);
546 if (fontDesc->pPropertyNotifyCP)
547 IConnectionPoint_Release(fontDesc->pPropertyNotifyCP);
548 if (fontDesc->pFontEventsCP)
549 IConnectionPoint_Release(fontDesc->pFontEventsCP);
551 HeapFree(GetProcessHeap(), 0, fontDesc);
554 /************************************************************************
555 * OLEFontImpl_QueryInterface (IUnknown)
557 * See Windows documentation for more details on IUnknown methods.
559 HRESULT WINAPI OLEFontImpl_QueryInterface(
564 OLEFontImpl *this = (OLEFontImpl *)iface;
565 TRACE("(%p)->(%s, %p)\n", this, debugstr_guid(riid), ppvObject);
568 * Perform a sanity check on the parameters.
570 if ( (this==0) || (ppvObject==0) )
574 * Initialize the return parameter.
579 * Compare the riid with the interface IDs implemented by this object.
581 if (IsEqualGUID(&IID_IUnknown, riid))
582 *ppvObject = (IFont*)this;
583 if (IsEqualGUID(&IID_IFont, riid))
584 *ppvObject = (IFont*)this;
585 if (IsEqualGUID(&IID_IDispatch, riid))
586 *ppvObject = (IDispatch*)&(this->lpvtblIDispatch);
587 if (IsEqualGUID(&IID_IFontDisp, riid))
588 *ppvObject = (IDispatch*)&(this->lpvtblIDispatch);
589 if (IsEqualIID(&IID_IPersist, riid) || IsEqualGUID(&IID_IPersistStream, riid))
590 *ppvObject = (IPersistStream*)&(this->lpvtblIPersistStream);
591 if (IsEqualGUID(&IID_IConnectionPointContainer, riid))
592 *ppvObject = (IConnectionPointContainer*)&(this->lpvtblIConnectionPointContainer);
593 if (IsEqualGUID(&IID_IPersistPropertyBag, riid))
594 *ppvObject = (IPersistPropertyBag*)&(this->lpvtblIPersistPropertyBag);
595 if (IsEqualGUID(&IID_IPersistStreamInit, riid))
596 *ppvObject = (IPersistStreamInit*)&(this->lpvtblIPersistStreamInit);
599 * Check that we obtained an interface.
603 FIXME("() : asking for unsupported interface %s\n",debugstr_guid(riid));
604 return E_NOINTERFACE;
606 OLEFontImpl_AddRef((IFont*)this);
610 /************************************************************************
611 * OLEFontImpl_AddRef (IUnknown)
613 * See Windows documentation for more details on IUnknown methods.
615 ULONG WINAPI OLEFontImpl_AddRef(
618 OLEFontImpl *this = (OLEFontImpl *)iface;
619 TRACE("(%p)->(ref=%ld)\n", this, this->ref);
620 return InterlockedIncrement(&this->ref);
623 /************************************************************************
624 * OLEFontImpl_Release (IUnknown)
626 * See Windows documentation for more details on IUnknown methods.
628 ULONG WINAPI OLEFontImpl_Release(
631 OLEFontImpl *this = (OLEFontImpl *)iface;
633 TRACE("(%p)->(ref=%ld)\n", this, this->ref);
636 * Decrease the reference count on this object.
638 ret = InterlockedDecrement(&this->ref);
641 * If the reference count goes down to 0, perform suicide.
643 if (ret==0) OLEFontImpl_Destroy(this);
648 /************************************************************************
649 * OLEFontImpl_get_Name (IFont)
651 * See Windows documentation for more details on IFont methods.
653 static HRESULT WINAPI OLEFontImpl_get_Name(
657 OLEFontImpl *this = (OLEFontImpl *)iface;
658 TRACE("(%p)->(%p)\n", this, pname);
665 if (this->description.lpstrName!=0)
666 *pname = SysAllocString(this->description.lpstrName);
673 /************************************************************************
674 * OLEFontImpl_put_Name (IFont)
676 * See Windows documentation for more details on IFont methods.
678 static HRESULT WINAPI OLEFontImpl_put_Name(
682 OLEFontImpl *this = (OLEFontImpl *)iface;
683 TRACE("(%p)->(%p)\n", this, name);
685 if (this->description.lpstrName==0)
687 this->description.lpstrName = HeapAlloc(GetProcessHeap(),
689 (lstrlenW(name)+1) * sizeof(WCHAR));
693 this->description.lpstrName = HeapReAlloc(GetProcessHeap(),
695 this->description.lpstrName,
696 (lstrlenW(name)+1) * sizeof(WCHAR));
699 if (this->description.lpstrName==0)
700 return E_OUTOFMEMORY;
702 strcpyW(this->description.lpstrName, name);
703 TRACE("new name %s\n", debugstr_w(this->description.lpstrName));
704 OLEFont_SendNotify(this, DISPID_FONT_NAME);
708 /************************************************************************
709 * OLEFontImpl_get_Size (IFont)
711 * See Windows documentation for more details on IFont methods.
713 static HRESULT WINAPI OLEFontImpl_get_Size(
717 OLEFontImpl *this = (OLEFontImpl *)iface;
718 TRACE("(%p)->(%p)\n", this, psize);
727 psize->s.Lo = this->description.cySize.s.Lo;
732 /************************************************************************
733 * OLEFontImpl_put_Size (IFont)
735 * See Windows documentation for more details on IFont methods.
737 static HRESULT WINAPI OLEFontImpl_put_Size(
741 OLEFontImpl *this = (OLEFontImpl *)iface;
742 TRACE("(%p)->(%ld)\n", this, size.s.Lo);
743 this->description.cySize.s.Hi = 0;
744 this->description.cySize.s.Lo = size.s.Lo;
745 OLEFont_SendNotify(this, DISPID_FONT_SIZE);
750 /************************************************************************
751 * OLEFontImpl_get_Bold (IFont)
753 * See Windows documentation for more details on IFont methods.
755 static HRESULT WINAPI OLEFontImpl_get_Bold(
759 OLEFontImpl *this = (OLEFontImpl *)iface;
760 TRACE("(%p)->(%p)\n", this, pbold);
767 *pbold = this->description.sWeight > 550;
772 /************************************************************************
773 * OLEFontImpl_put_Bold (IFont)
775 * See Windows documentation for more details on IFont methods.
777 static HRESULT WINAPI OLEFontImpl_put_Bold(
781 OLEFontImpl *this = (OLEFontImpl *)iface;
782 TRACE("(%p)->(%d)\n", this, bold);
783 this->description.sWeight = bold ? FW_BOLD : FW_NORMAL;
784 OLEFont_SendNotify(this, DISPID_FONT_BOLD);
789 /************************************************************************
790 * OLEFontImpl_get_Italic (IFont)
792 * See Windows documentation for more details on IFont methods.
794 static HRESULT WINAPI OLEFontImpl_get_Italic(
798 OLEFontImpl *this = (OLEFontImpl *)iface;
799 TRACE("(%p)->(%p)\n", this, pitalic);
806 *pitalic = this->description.fItalic;
811 /************************************************************************
812 * OLEFontImpl_put_Italic (IFont)
814 * See Windows documentation for more details on IFont methods.
816 static HRESULT WINAPI OLEFontImpl_put_Italic(
820 OLEFontImpl *this = (OLEFontImpl *)iface;
821 TRACE("(%p)->(%d)\n", this, italic);
823 this->description.fItalic = italic;
825 OLEFont_SendNotify(this, DISPID_FONT_ITALIC);
829 /************************************************************************
830 * OLEFontImpl_get_Underline (IFont)
832 * See Windows documentation for more details on IFont methods.
834 static HRESULT WINAPI OLEFontImpl_get_Underline(
838 OLEFontImpl *this = (OLEFontImpl *)iface;
839 TRACE("(%p)->(%p)\n", this, punderline);
847 *punderline = this->description.fUnderline;
852 /************************************************************************
853 * OLEFontImpl_put_Underline (IFont)
855 * See Windows documentation for more details on IFont methods.
857 static HRESULT WINAPI OLEFontImpl_put_Underline(
861 OLEFontImpl *this = (OLEFontImpl *)iface;
862 TRACE("(%p)->(%d)\n", this, underline);
864 this->description.fUnderline = underline;
866 OLEFont_SendNotify(this, DISPID_FONT_UNDER);
870 /************************************************************************
871 * OLEFontImpl_get_Strikethrough (IFont)
873 * See Windows documentation for more details on IFont methods.
875 static HRESULT WINAPI OLEFontImpl_get_Strikethrough(
877 BOOL* pstrikethrough)
879 OLEFontImpl *this = (OLEFontImpl *)iface;
880 TRACE("(%p)->(%p)\n", this, pstrikethrough);
885 if (pstrikethrough==0)
888 *pstrikethrough = this->description.fStrikethrough;
893 /************************************************************************
894 * OLEFontImpl_put_Strikethrough (IFont)
896 * See Windows documentation for more details on IFont methods.
898 static HRESULT WINAPI OLEFontImpl_put_Strikethrough(
902 OLEFontImpl *this = (OLEFontImpl *)iface;
903 TRACE("(%p)->(%d)\n", this, strikethrough);
905 this->description.fStrikethrough = strikethrough;
906 OLEFont_SendNotify(this, DISPID_FONT_STRIKE);
911 /************************************************************************
912 * OLEFontImpl_get_Weight (IFont)
914 * See Windows documentation for more details on IFont methods.
916 static HRESULT WINAPI OLEFontImpl_get_Weight(
920 OLEFontImpl *this = (OLEFontImpl *)iface;
921 TRACE("(%p)->(%p)\n", this, pweight);
929 *pweight = this->description.sWeight;
934 /************************************************************************
935 * OLEFontImpl_put_Weight (IFont)
937 * See Windows documentation for more details on IFont methods.
939 static HRESULT WINAPI OLEFontImpl_put_Weight(
943 OLEFontImpl *this = (OLEFontImpl *)iface;
944 TRACE("(%p)->(%d)\n", this, weight);
946 this->description.sWeight = weight;
948 OLEFont_SendNotify(this, DISPID_FONT_WEIGHT);
952 /************************************************************************
953 * OLEFontImpl_get_Charset (IFont)
955 * See Windows documentation for more details on IFont methods.
957 static HRESULT WINAPI OLEFontImpl_get_Charset(
961 OLEFontImpl *this = (OLEFontImpl *)iface;
962 TRACE("(%p)->(%p)\n", this, pcharset);
970 *pcharset = this->description.sCharset;
975 /************************************************************************
976 * OLEFontImpl_put_Charset (IFont)
978 * See Windows documentation for more details on IFont methods.
980 static HRESULT WINAPI OLEFontImpl_put_Charset(
984 OLEFontImpl *this = (OLEFontImpl *)iface;
985 TRACE("(%p)->(%d)\n", this, charset);
987 this->description.sCharset = charset;
988 OLEFont_SendNotify(this, DISPID_FONT_CHARSET);
993 /************************************************************************
994 * OLEFontImpl_get_hFont (IFont)
996 * See Windows documentation for more details on IFont methods.
998 static HRESULT WINAPI OLEFontImpl_get_hFont(
1002 OLEFontImpl *this = (OLEFontImpl *)iface;
1003 TRACE("(%p)->(%p)\n", this, phfont);
1008 * Realize the font if necessary
1010 if (this->gdiFont==0)
1017 * The height of the font returned by the get_Size property is the
1018 * height of the font in points multiplied by 10000... Using some
1019 * simple conversions and the ratio given by the application, it can
1020 * be converted to a height in pixels.
1022 IFont_get_Size(iface, &cySize);
1024 /* Standard ratio is 72 / 2540, or 18 / 635 in lowest terms. */
1025 /* Ratio is applied here relative to the standard. */
1026 fontHeight = MulDiv( cySize.s.Lo, this->cyLogical*635, this->cyHimetric*18 );
1028 memset(&logFont, 0, sizeof(LOGFONTW));
1030 logFont.lfHeight = ((fontHeight%10000L)>5000L) ? (-fontHeight/10000L)-1 :
1031 (-fontHeight/10000L);
1032 logFont.lfItalic = this->description.fItalic;
1033 logFont.lfUnderline = this->description.fUnderline;
1034 logFont.lfStrikeOut = this->description.fStrikethrough;
1035 logFont.lfWeight = this->description.sWeight;
1036 logFont.lfCharSet = this->description.sCharset;
1037 logFont.lfOutPrecision = OUT_CHARACTER_PRECIS;
1038 logFont.lfClipPrecision = CLIP_DEFAULT_PRECIS;
1039 logFont.lfQuality = DEFAULT_QUALITY;
1040 logFont.lfPitchAndFamily = DEFAULT_PITCH;
1041 strcpyW(logFont.lfFaceName,this->description.lpstrName);
1043 this->gdiFont = CreateFontIndirectW(&logFont);
1046 *phfont = this->gdiFont;
1047 TRACE("Returning %p\n", *phfont);
1051 /************************************************************************
1052 * OLEFontImpl_Clone (IFont)
1054 * See Windows documentation for more details on IFont methods.
1056 static HRESULT WINAPI OLEFontImpl_Clone(
1060 OLEFontImpl* newObject = 0;
1064 OLEFontImpl *this = (OLEFontImpl *)iface;
1065 TRACE("(%p)->(%p)\n", this, ppfont);
1073 * Allocate space for the object.
1075 newObject = HeapAlloc(GetProcessHeap(), 0, sizeof(OLEFontImpl));
1077 if (newObject==NULL)
1078 return E_OUTOFMEMORY;
1082 /* We need to alloc new memory for the string, otherwise
1083 * we free memory twice.
1085 newObject->description.lpstrName = HeapAlloc(
1087 (1+strlenW(this->description.lpstrName))*2
1089 strcpyW(newObject->description.lpstrName, this->description.lpstrName);
1090 /* We need to clone the HFONT too. This is just cut & paste from above */
1091 IFont_get_Size(iface, &cySize);
1093 fontHeight = MulDiv(cySize.s.Lo, this->cyLogical*635,this->cyHimetric*18);
1095 memset(&logFont, 0, sizeof(LOGFONTW));
1097 logFont.lfHeight = ((fontHeight%10000L)>5000L) ? (-fontHeight/10000L)-1 :
1098 (-fontHeight/10000L);
1099 logFont.lfItalic = this->description.fItalic;
1100 logFont.lfUnderline = this->description.fUnderline;
1101 logFont.lfStrikeOut = this->description.fStrikethrough;
1102 logFont.lfWeight = this->description.sWeight;
1103 logFont.lfCharSet = this->description.sCharset;
1104 logFont.lfOutPrecision = OUT_CHARACTER_PRECIS;
1105 logFont.lfClipPrecision = CLIP_DEFAULT_PRECIS;
1106 logFont.lfQuality = DEFAULT_QUALITY;
1107 logFont.lfPitchAndFamily = DEFAULT_PITCH;
1108 strcpyW(logFont.lfFaceName,this->description.lpstrName);
1110 newObject->gdiFont = CreateFontIndirectW(&logFont);
1112 /* create new connection points */
1113 newObject->pPropertyNotifyCP = NULL;
1114 newObject->pFontEventsCP = NULL;
1115 CreateConnectionPoint((IUnknown*)newObject, &IID_IPropertyNotifySink, &newObject->pPropertyNotifyCP);
1116 CreateConnectionPoint((IUnknown*)newObject, &IID_IFontEventsDisp, &newObject->pFontEventsCP);
1118 if (!newObject->pPropertyNotifyCP || !newObject->pFontEventsCP)
1120 OLEFontImpl_Destroy(newObject);
1121 return E_OUTOFMEMORY;
1124 /* The cloned object starts with a reference count of 1 */
1127 *ppfont = (IFont*)newObject;
1132 /************************************************************************
1133 * OLEFontImpl_IsEqual (IFont)
1135 * See Windows documentation for more details on IFont methods.
1137 static HRESULT WINAPI OLEFontImpl_IsEqual(
1141 FIXME("(%p, %p), stub!\n",iface,pFontOther);
1145 /************************************************************************
1146 * OLEFontImpl_SetRatio (IFont)
1148 * See Windows documentation for more details on IFont methods.
1150 static HRESULT WINAPI OLEFontImpl_SetRatio(
1155 OLEFontImpl *this = (OLEFontImpl *)iface;
1156 TRACE("(%p)->(%ld, %ld)\n", this, cyLogical, cyHimetric);
1158 this->cyLogical = cyLogical;
1159 this->cyHimetric = cyHimetric;
1164 /************************************************************************
1165 * OLEFontImpl_QueryTextMetrics (IFont)
1167 * See Windows documentation for more details on IFont methods.
1169 static HRESULT WINAPI OLEFontImpl_QueryTextMetrics(
1174 HFONT hOldFont, hNewFont;
1177 OLEFontImpl_get_hFont(iface, &hNewFont);
1178 hOldFont = SelectObject(hdcRef, hNewFont);
1179 GetTextMetricsW(hdcRef, ptm);
1180 SelectObject(hdcRef, hOldFont);
1181 ReleaseDC(0, hdcRef);
1185 /************************************************************************
1186 * OLEFontImpl_AddRefHfont (IFont)
1188 * See Windows documentation for more details on IFont methods.
1190 static HRESULT WINAPI OLEFontImpl_AddRefHfont(
1194 OLEFontImpl *this = (OLEFontImpl *)iface;
1195 TRACE("(%p)->(%p) (lock=%ld)\n", this, hfont, this->fontLock);
1197 if ( (hfont == 0) ||
1198 (hfont != this->gdiFont) )
1199 return E_INVALIDARG;
1206 /************************************************************************
1207 * OLEFontImpl_ReleaseHfont (IFont)
1209 * See Windows documentation for more details on IFont methods.
1211 static HRESULT WINAPI OLEFontImpl_ReleaseHfont(
1215 OLEFontImpl *this = (OLEFontImpl *)iface;
1216 TRACE("(%p)->(%p) (lock=%ld)\n", this, hfont, this->fontLock);
1218 if ( (hfont == 0) ||
1219 (hfont != this->gdiFont) )
1220 return E_INVALIDARG;
1225 * If we just released our last font reference, destroy it.
1227 if (this->fontLock==0)
1229 DeleteObject(this->gdiFont);
1236 /************************************************************************
1237 * OLEFontImpl_SetHdc (IFont)
1239 * See Windows documentation for more details on IFont methods.
1241 static HRESULT WINAPI OLEFontImpl_SetHdc(
1245 OLEFontImpl *this = (OLEFontImpl *)iface;
1246 FIXME("(%p)->(%p): Stub\n", this, hdc);
1250 /************************************************************************
1251 * OLEFontImpl_IDispatch_QueryInterface (IUnknown)
1253 * See Windows documentation for more details on IUnknown methods.
1255 static HRESULT WINAPI OLEFontImpl_IDispatch_QueryInterface(
1260 OLEFontImpl *this = impl_from_IDispatch(iface);
1262 return IFont_QueryInterface((IFont *)this, riid, ppvoid);
1265 /************************************************************************
1266 * OLEFontImpl_IDispatch_Release (IUnknown)
1268 * See Windows documentation for more details on IUnknown methods.
1270 static ULONG WINAPI OLEFontImpl_IDispatch_Release(
1273 OLEFontImpl *this = impl_from_IDispatch(iface);
1275 return IFont_Release((IFont *)this);
1278 /************************************************************************
1279 * OLEFontImpl_IDispatch_AddRef (IUnknown)
1281 * See Windows documentation for more details on IUnknown methods.
1283 static ULONG WINAPI OLEFontImpl_IDispatch_AddRef(
1286 OLEFontImpl *this = impl_from_IDispatch(iface);
1288 return IFont_AddRef((IFont *)this);
1291 /************************************************************************
1292 * OLEFontImpl_GetTypeInfoCount (IDispatch)
1294 * See Windows documentation for more details on IDispatch methods.
1296 static HRESULT WINAPI OLEFontImpl_GetTypeInfoCount(
1298 unsigned int* pctinfo)
1300 OLEFontImpl *this = impl_from_IDispatch(iface);
1301 FIXME("(%p)->(%p): Stub\n", this, pctinfo);
1306 /************************************************************************
1307 * OLEFontImpl_GetTypeInfo (IDispatch)
1309 * See Windows documentation for more details on IDispatch methods.
1311 static HRESULT WINAPI OLEFontImpl_GetTypeInfo(
1315 ITypeInfo** ppTInfo)
1317 static const WCHAR stdole2tlb[] = {'s','t','d','o','l','e','2','.','t','l','b',0};
1321 OLEFontImpl *this = impl_from_IDispatch(iface);
1322 TRACE("(%p, iTInfo=%d, lcid=%04x, %p)\n", this, iTInfo, (int)lcid, ppTInfo);
1325 hres = LoadTypeLib(stdole2tlb, &tl);
1327 ERR("Could not load the stdole2.tlb?\n");
1330 hres = ITypeLib_GetTypeInfoOfGuid(tl, &IID_IFontDisp, ppTInfo);
1332 FIXME("Did not IDispatch typeinfo from typelib, hres %lx\n",hres);
1337 /************************************************************************
1338 * OLEFontImpl_GetIDsOfNames (IDispatch)
1340 * See Windows documentation for more details on IDispatch methods.
1342 static HRESULT WINAPI OLEFontImpl_GetIDsOfNames(
1345 LPOLESTR* rgszNames,
1350 OLEFontImpl *this = impl_from_IDispatch(iface);
1351 FIXME("(%p,%s,%p,%d,%04x,%p), stub!\n", this, debugstr_guid(riid), rgszNames,
1352 cNames, (int)lcid, rgDispId
1357 /************************************************************************
1358 * OLEFontImpl_Invoke (IDispatch)
1360 * See Windows documentation for more details on IDispatch methods.
1362 * Note: Do not call _put_Xxx methods, since setting things here
1363 * should not call notify functions as I found out debugging the generic
1366 static HRESULT WINAPI OLEFontImpl_Invoke(
1368 DISPID dispIdMember,
1372 DISPPARAMS* pDispParams,
1373 VARIANT* pVarResult,
1374 EXCEPINFO* pExepInfo,
1377 OLEFontImpl *this = impl_from_IDispatch(iface);
1378 OLEFontImpl *xthis = (OLEFontImpl*)this;
1380 switch (dispIdMember) {
1381 case DISPID_FONT_NAME:
1383 case DISPATCH_PROPERTYGET:
1384 case DISPATCH_PROPERTYGET|DISPATCH_METHOD:
1385 V_VT(pVarResult) = VT_BSTR;
1386 return OLEFontImpl_get_Name((IFont *)this, &V_BSTR(pVarResult));
1387 case DISPATCH_PROPERTYPUT: {
1391 if (V_VT(&pDispParams->rgvarg[0]) == VT_DISPATCH) {
1395 hr = IUnknown_QueryInterface(V_DISPATCH(&pDispParams->rgvarg[0]), &IID_IFont, (void **) &font);
1398 FIXME("dispatch value for name property is not an OleFont, returning hr=0x%lx\n", hr);
1402 hr = IFont_get_Name(font, &name); /* this allocates a new BSTR so free it later */
1403 if (FAILED(hr)) return hr;
1405 IUnknown_Release(font);
1408 } else if (V_VT(&pDispParams->rgvarg[0]) == VT_BSTR) {
1409 name = V_BSTR(&pDispParams->rgvarg[0]);
1412 FIXME("app is trying to set name property with a non BSTR, non dispatch value. returning E_FAIL\n");
1416 TRACE("name is %s\n", debugstr_w(name));
1418 if (!xthis->description.lpstrName)
1419 xthis->description.lpstrName = HeapAlloc(GetProcessHeap(), 0, (lstrlenW(name)+1) * sizeof(WCHAR));
1421 xthis->description.lpstrName = HeapReAlloc(GetProcessHeap(), 0, xthis->description.lpstrName, (lstrlenW(name)+1) * sizeof(WCHAR));
1423 if (xthis->description.lpstrName==0)
1424 return E_OUTOFMEMORY;
1425 strcpyW(xthis->description.lpstrName, name);
1427 if (freename) SysFreeString(name);
1433 case DISPID_FONT_BOLD:
1435 case DISPATCH_PROPERTYGET:
1436 case DISPATCH_PROPERTYGET|DISPATCH_METHOD:
1437 V_VT(pVarResult) = VT_BOOL;
1438 return OLEFontImpl_get_Bold((IFont *)this, (BOOL*)&V_BOOL(pVarResult));
1439 case DISPATCH_PROPERTYPUT:
1440 if (V_VT(&pDispParams->rgvarg[0]) != VT_BOOL) {
1441 FIXME("DISPID_FONT_BOLD/put, vt is %d, not VT_BOOL.\n",V_VT(&pDispParams->rgvarg[0]));
1444 xthis->description.sWeight = V_BOOL(&pDispParams->rgvarg[0]) ? FW_BOLD : FW_NORMAL;
1449 case DISPID_FONT_ITALIC:
1451 case DISPATCH_PROPERTYGET:
1452 case DISPATCH_PROPERTYGET|DISPATCH_METHOD:
1453 V_VT(pVarResult) = VT_BOOL;
1454 return OLEFontImpl_get_Italic((IFont *)this, (BOOL*)&V_BOOL(pVarResult));
1455 case DISPATCH_PROPERTYPUT:
1456 if (V_VT(&pDispParams->rgvarg[0]) != VT_BOOL) {
1457 FIXME("DISPID_FONT_ITALIC/put, vt is %d, not VT_BOOL.\n",V_VT(&pDispParams->rgvarg[0]));
1460 xthis->description.fItalic = V_BOOL(&pDispParams->rgvarg[0]);
1465 case DISPID_FONT_UNDER:
1467 case DISPATCH_PROPERTYGET:
1468 case DISPATCH_PROPERTYGET|DISPATCH_METHOD:
1469 V_VT(pVarResult) = VT_BOOL;
1470 return OLEFontImpl_get_Underline((IFont *)this, (BOOL*)&V_BOOL(pVarResult));
1471 case DISPATCH_PROPERTYPUT:
1472 if (V_VT(&pDispParams->rgvarg[0]) != VT_BOOL) {
1473 FIXME("DISPID_FONT_UNDER/put, vt is %d, not VT_BOOL.\n",V_VT(&pDispParams->rgvarg[0]));
1476 xthis->description.fUnderline = V_BOOL(&pDispParams->rgvarg[0]);
1481 case DISPID_FONT_STRIKE:
1483 case DISPATCH_PROPERTYGET:
1484 case DISPATCH_PROPERTYGET|DISPATCH_METHOD:
1485 V_VT(pVarResult) = VT_BOOL;
1486 return OLEFontImpl_get_Strikethrough((IFont *)this, (BOOL*)&V_BOOL(pVarResult));
1487 case DISPATCH_PROPERTYPUT:
1488 if (V_VT(&pDispParams->rgvarg[0]) != VT_BOOL) {
1489 FIXME("DISPID_FONT_STRIKE/put, vt is %d, not VT_BOOL.\n",V_VT(&pDispParams->rgvarg[0]));
1492 xthis->description.fStrikethrough = V_BOOL(&pDispParams->rgvarg[0]);
1497 case DISPID_FONT_SIZE:
1499 case DISPATCH_PROPERTYPUT: {
1500 assert (pDispParams->cArgs == 1);
1501 xthis->description.cySize.s.Hi = 0;
1502 if (V_VT(&pDispParams->rgvarg[0]) != VT_CY) {
1503 if (V_VT(&pDispParams->rgvarg[0]) == VT_I2) {
1504 xthis->description.cySize.s.Lo = V_I2(&pDispParams->rgvarg[0]) * 10000;
1506 FIXME("property put for Size with vt %d unsupported!\n",V_VT(&pDispParams->rgvarg[0]));
1509 xthis->description.cySize.s.Lo = V_CY(&pDispParams->rgvarg[0]).s.Lo;
1513 case DISPATCH_PROPERTYGET:
1514 case DISPATCH_PROPERTYGET|DISPATCH_METHOD:
1515 V_VT(pVarResult) = VT_CY;
1516 return OLEFontImpl_get_Size((IFont *)this, &V_CY(pVarResult));
1519 case DISPID_FONT_CHARSET:
1521 case DISPATCH_PROPERTYPUT:
1522 assert (pDispParams->cArgs == 1);
1523 if (V_VT(&pDispParams->rgvarg[0]) != VT_I2)
1524 FIXME("varg of first disparg is not VT_I2, but %d\n",V_VT(&pDispParams->rgvarg[0]));
1525 xthis->description.sCharset = V_I2(&pDispParams->rgvarg[0]);
1527 case DISPATCH_PROPERTYGET:
1528 case DISPATCH_PROPERTYGET|DISPATCH_METHOD:
1529 V_VT(pVarResult) = VT_I2;
1530 return OLEFontImpl_get_Charset((IFont *)this, &V_I2(pVarResult));
1534 FIXME("%p->(%ld,%s,%lx,%x,%p,%p,%p,%p), unhandled dispid/flag!\n",
1535 this,dispIdMember,debugstr_guid(riid),lcid,
1536 wFlags,pDispParams,pVarResult,pExepInfo,puArgErr
1541 /************************************************************************
1542 * OLEFontImpl_IPersistStream_QueryInterface (IUnknown)
1544 * See Windows documentation for more details on IUnknown methods.
1546 static HRESULT WINAPI OLEFontImpl_IPersistStream_QueryInterface(
1547 IPersistStream* iface,
1551 OLEFontImpl *this = impl_from_IPersistStream(iface);
1553 return IFont_QueryInterface((IFont *)this, riid, ppvoid);
1556 /************************************************************************
1557 * OLEFontImpl_IPersistStream_Release (IUnknown)
1559 * See Windows documentation for more details on IUnknown methods.
1561 static ULONG WINAPI OLEFontImpl_IPersistStream_Release(
1562 IPersistStream* iface)
1564 OLEFontImpl *this = impl_from_IPersistStream(iface);
1566 return IFont_Release((IFont *)this);
1569 /************************************************************************
1570 * OLEFontImpl_IPersistStream_AddRef (IUnknown)
1572 * See Windows documentation for more details on IUnknown methods.
1574 static ULONG WINAPI OLEFontImpl_IPersistStream_AddRef(
1575 IPersistStream* iface)
1577 OLEFontImpl *this = impl_from_IPersistStream(iface);
1579 return IFont_AddRef((IFont *)this);
1582 /************************************************************************
1583 * OLEFontImpl_GetClassID (IPersistStream)
1585 * See Windows documentation for more details on IPersistStream methods.
1587 static HRESULT WINAPI OLEFontImpl_GetClassID(
1588 IPersistStream* iface,
1591 TRACE("(%p,%p)\n",iface,pClassID);
1595 memcpy(pClassID, &CLSID_StdFont, sizeof(CLSID_StdFont));
1600 /************************************************************************
1601 * OLEFontImpl_IsDirty (IPersistStream)
1603 * See Windows documentation for more details on IPersistStream methods.
1605 static HRESULT WINAPI OLEFontImpl_IsDirty(
1606 IPersistStream* iface)
1608 TRACE("(%p)\n",iface);
1612 /************************************************************************
1613 * OLEFontImpl_Load (IPersistStream)
1615 * See Windows documentation for more details on IPersistStream methods.
1617 * This is the format of the standard font serialization as far as I
1620 * Offset Type Value Comment
1621 * 0x0000 Byte Unknown Probably a version number, contains 0x01
1622 * 0x0001 Short Charset Charset value from the FONTDESC structure
1623 * 0x0003 Byte Attributes Flags defined as follows:
1625 * 00000100 - Underline
1626 * 00001000 - Strikethrough
1627 * 0x0004 Short Weight Weight value from FONTDESC structure
1628 * 0x0006 DWORD size "Low" portion of the cySize member of the FONTDESC
1630 * 0x000A Byte name length Length of the font name string (no null character)
1631 * 0x000B String name Name of the font (ASCII, no nul character)
1633 static HRESULT WINAPI OLEFontImpl_Load(
1634 IPersistStream* iface,
1635 IStream* pLoadStream)
1637 char readBuffer[0x100];
1644 OLEFontImpl *this = impl_from_IPersistStream(iface);
1647 * Read the version byte
1649 IStream_Read(pLoadStream, &bVersion, 1, &cbRead);
1658 IStream_Read(pLoadStream, &this->description.sCharset, 2, &cbRead);
1666 IStream_Read(pLoadStream, &bAttributes, 1, &cbRead);
1671 this->description.fItalic = (bAttributes & FONTPERSIST_ITALIC) != 0;
1672 this->description.fStrikethrough = (bAttributes & FONTPERSIST_STRIKETHROUGH) != 0;
1673 this->description.fUnderline = (bAttributes & FONTPERSIST_UNDERLINE) != 0;
1678 IStream_Read(pLoadStream, &this->description.sWeight, 2, &cbRead);
1686 IStream_Read(pLoadStream, &this->description.cySize.s.Lo, 4, &cbRead);
1691 this->description.cySize.s.Hi = 0;
1696 IStream_Read(pLoadStream, &bStringSize, 1, &cbRead);
1701 IStream_Read(pLoadStream, readBuffer, bStringSize, &cbRead);
1703 if (cbRead!=bStringSize)
1706 HeapFree(GetProcessHeap(), 0, this->description.lpstrName);
1708 len = MultiByteToWideChar( CP_ACP, 0, readBuffer, bStringSize, NULL, 0 );
1709 this->description.lpstrName = HeapAlloc( GetProcessHeap(), 0, (len+1) * sizeof(WCHAR) );
1710 MultiByteToWideChar( CP_ACP, 0, readBuffer, bStringSize, this->description.lpstrName, len );
1711 this->description.lpstrName[len] = 0;
1713 /* Ensure use of this font causes a new one to be created @@@@ */
1714 DeleteObject(this->gdiFont);
1720 /************************************************************************
1721 * OLEFontImpl_Save (IPersistStream)
1723 * See Windows documentation for more details on IPersistStream methods.
1725 static HRESULT WINAPI OLEFontImpl_Save(
1726 IPersistStream* iface,
1727 IStream* pOutStream,
1730 char* writeBuffer = NULL;
1732 BYTE bVersion = 0x01;
1736 OLEFontImpl *this = impl_from_IPersistStream(iface);
1739 * Read the version byte
1741 IStream_Write(pOutStream, &bVersion, 1, &cbWritten);
1749 IStream_Write(pOutStream, &this->description.sCharset, 2, &cbWritten);
1759 if (this->description.fItalic)
1760 bAttributes |= FONTPERSIST_ITALIC;
1762 if (this->description.fStrikethrough)
1763 bAttributes |= FONTPERSIST_STRIKETHROUGH;
1765 if (this->description.fUnderline)
1766 bAttributes |= FONTPERSIST_UNDERLINE;
1768 IStream_Write(pOutStream, &bAttributes, 1, &cbWritten);
1776 IStream_Write(pOutStream, &this->description.sWeight, 2, &cbWritten);
1784 IStream_Write(pOutStream, &this->description.cySize.s.Lo, 4, &cbWritten);
1792 if (this->description.lpstrName!=0)
1793 bStringSize = WideCharToMultiByte( CP_ACP, 0, this->description.lpstrName,
1794 strlenW(this->description.lpstrName), NULL, 0, NULL, NULL );
1798 IStream_Write(pOutStream, &bStringSize, 1, &cbWritten);
1805 if (!(writeBuffer = HeapAlloc( GetProcessHeap(), 0, bStringSize ))) return E_OUTOFMEMORY;
1806 WideCharToMultiByte( CP_ACP, 0, this->description.lpstrName,
1807 strlenW(this->description.lpstrName),
1808 writeBuffer, bStringSize, NULL, NULL );
1810 IStream_Write(pOutStream, writeBuffer, bStringSize, &cbWritten);
1811 HeapFree(GetProcessHeap(), 0, writeBuffer);
1813 if (cbWritten!=bStringSize)
1820 /************************************************************************
1821 * OLEFontImpl_GetSizeMax (IPersistStream)
1823 * See Windows documentation for more details on IPersistStream methods.
1825 static HRESULT WINAPI OLEFontImpl_GetSizeMax(
1826 IPersistStream* iface,
1827 ULARGE_INTEGER* pcbSize)
1829 OLEFontImpl *this = impl_from_IPersistStream(iface);
1834 pcbSize->u.HighPart = 0;
1835 pcbSize->u.LowPart = 0;
1837 pcbSize->u.LowPart += sizeof(BYTE); /* Version */
1838 pcbSize->u.LowPart += sizeof(WORD); /* Lang code */
1839 pcbSize->u.LowPart += sizeof(BYTE); /* Flags */
1840 pcbSize->u.LowPart += sizeof(WORD); /* Weight */
1841 pcbSize->u.LowPart += sizeof(DWORD); /* Size */
1842 pcbSize->u.LowPart += sizeof(BYTE); /* StrLength */
1844 if (this->description.lpstrName!=0)
1845 pcbSize->u.LowPart += lstrlenW(this->description.lpstrName);
1850 /************************************************************************
1851 * OLEFontImpl_IConnectionPointContainer_QueryInterface (IUnknown)
1853 * See Windows documentation for more details on IUnknown methods.
1855 static HRESULT WINAPI OLEFontImpl_IConnectionPointContainer_QueryInterface(
1856 IConnectionPointContainer* iface,
1860 OLEFontImpl *this = impl_from_IConnectionPointContainer(iface);
1862 return IFont_QueryInterface((IFont*)this, riid, ppvoid);
1865 /************************************************************************
1866 * OLEFontImpl_IConnectionPointContainer_Release (IUnknown)
1868 * See Windows documentation for more details on IUnknown methods.
1870 static ULONG WINAPI OLEFontImpl_IConnectionPointContainer_Release(
1871 IConnectionPointContainer* iface)
1873 OLEFontImpl *this = impl_from_IConnectionPointContainer(iface);
1875 return IFont_Release((IFont*)this);
1878 /************************************************************************
1879 * OLEFontImpl_IConnectionPointContainer_AddRef (IUnknown)
1881 * See Windows documentation for more details on IUnknown methods.
1883 static ULONG WINAPI OLEFontImpl_IConnectionPointContainer_AddRef(
1884 IConnectionPointContainer* iface)
1886 OLEFontImpl *this = impl_from_IConnectionPointContainer(iface);
1888 return IFont_AddRef((IFont*)this);
1891 /************************************************************************
1892 * OLEFontImpl_EnumConnectionPoints (IConnectionPointContainer)
1894 * See Windows documentation for more details on IConnectionPointContainer
1897 static HRESULT WINAPI OLEFontImpl_EnumConnectionPoints(
1898 IConnectionPointContainer* iface,
1899 IEnumConnectionPoints **ppEnum)
1901 OLEFontImpl *this = impl_from_IConnectionPointContainer(iface);
1903 FIXME("(%p)->(%p): stub\n", this, ppEnum);
1907 /************************************************************************
1908 * OLEFontImpl_FindConnectionPoint (IConnectionPointContainer)
1910 * See Windows documentation for more details on IConnectionPointContainer
1913 static HRESULT WINAPI OLEFontImpl_FindConnectionPoint(
1914 IConnectionPointContainer* iface,
1916 IConnectionPoint **ppCp)
1918 OLEFontImpl *this = impl_from_IConnectionPointContainer(iface);
1919 TRACE("(%p)->(%s, %p): stub\n", this, debugstr_guid(riid), ppCp);
1921 if(IsEqualIID(riid, &IID_IPropertyNotifySink)) {
1922 return IConnectionPoint_QueryInterface(this->pPropertyNotifyCP,
1923 &IID_IConnectionPoint,
1925 } else if(IsEqualIID(riid, &IID_IFontEventsDisp)) {
1926 return IConnectionPoint_QueryInterface(this->pFontEventsCP,
1927 &IID_IConnectionPoint,
1930 FIXME("no connection point for %s\n", debugstr_guid(riid));
1931 return CONNECT_E_NOCONNECTION;
1935 /************************************************************************
1936 * OLEFontImpl implementation of IPersistPropertyBag.
1938 static HRESULT WINAPI OLEFontImpl_IPersistPropertyBag_QueryInterface(
1939 IPersistPropertyBag *iface, REFIID riid, LPVOID *ppvObj
1941 OLEFontImpl *this = impl_from_IPersistPropertyBag(iface);
1942 return IFont_QueryInterface((IFont *)this,riid,ppvObj);
1945 static ULONG WINAPI OLEFontImpl_IPersistPropertyBag_AddRef(
1946 IPersistPropertyBag *iface
1948 OLEFontImpl *this = impl_from_IPersistPropertyBag(iface);
1949 return IFont_AddRef((IFont *)this);
1952 static ULONG WINAPI OLEFontImpl_IPersistPropertyBag_Release(
1953 IPersistPropertyBag *iface
1955 OLEFontImpl *this = impl_from_IPersistPropertyBag(iface);
1956 return IFont_Release((IFont *)this);
1959 static HRESULT WINAPI OLEFontImpl_IPersistPropertyBag_GetClassID(
1960 IPersistPropertyBag *iface, CLSID *classid
1962 FIXME("(%p,%p), stub!\n", iface, classid);
1966 static HRESULT WINAPI OLEFontImpl_IPersistPropertyBag_InitNew(
1967 IPersistPropertyBag *iface
1969 FIXME("(%p), stub!\n", iface);
1973 static HRESULT WINAPI OLEFontImpl_IPersistPropertyBag_Load(
1974 IPersistPropertyBag *iface, IPropertyBag* pPropBag, IErrorLog* pErrorLog
1976 /* (from Visual Basic 6 property bag)
1977 Name = "MS Sans Serif"
1981 Underline = 0 'False
1983 Strikethrough = 0 'False
1985 static const WCHAR sAttrName[] = {'N','a','m','e',0};
1986 static const WCHAR sAttrSize[] = {'S','i','z','e',0};
1987 static const WCHAR sAttrCharset[] = {'C','h','a','r','s','e','t',0};
1988 static const WCHAR sAttrWeight[] = {'W','e','i','g','h','t',0};
1989 static const WCHAR sAttrUnderline[] = {'U','n','d','e','r','l','i','n','e',0};
1990 static const WCHAR sAttrItalic[] = {'I','t','a','l','i','c',0};
1991 static const WCHAR sAttrStrikethrough[] = {'S','t','r','i','k','e','t','h','r','o','u','g','h',0};
1994 HRESULT iRes = S_OK;
1995 OLEFontImpl *this = impl_from_IPersistPropertyBag(iface);
1997 VariantInit(&rawAttr);
1998 VariantInit(&valueAttr);
2001 iRes = IPropertyBag_Read(pPropBag, sAttrName, &rawAttr, pErrorLog);
2004 iRes = VariantChangeType(&rawAttr, &valueAttr, 0, VT_BSTR);
2006 iRes = IFont_put_Name((IFont *)this, V_BSTR(&valueAttr));
2008 else if (iRes == E_INVALIDARG)
2010 VariantClear(&rawAttr);
2011 VariantClear(&valueAttr);
2015 iRes = IPropertyBag_Read(pPropBag, sAttrSize, &rawAttr, pErrorLog);
2018 iRes = VariantChangeType(&rawAttr, &valueAttr, 0, VT_CY);
2020 iRes = IFont_put_Size((IFont *)this, V_CY(&valueAttr));
2022 else if (iRes == E_INVALIDARG)
2024 VariantClear(&rawAttr);
2025 VariantClear(&valueAttr);
2029 iRes = IPropertyBag_Read(pPropBag, sAttrCharset, &rawAttr, pErrorLog);
2032 iRes = VariantChangeType(&rawAttr, &valueAttr, 0, VT_I2);
2034 iRes = IFont_put_Charset((IFont *)this, V_I2(&valueAttr));
2036 else if (iRes == E_INVALIDARG)
2038 VariantClear(&rawAttr);
2039 VariantClear(&valueAttr);
2043 iRes = IPropertyBag_Read(pPropBag, sAttrWeight, &rawAttr, pErrorLog);
2046 iRes = VariantChangeType(&rawAttr, &valueAttr, 0, VT_I2);
2048 iRes = IFont_put_Weight((IFont *)this, V_I2(&valueAttr));
2050 else if (iRes == E_INVALIDARG)
2052 VariantClear(&rawAttr);
2053 VariantClear(&valueAttr);
2058 iRes = IPropertyBag_Read(pPropBag, sAttrUnderline, &rawAttr, pErrorLog);
2061 iRes = VariantChangeType(&rawAttr, &valueAttr, 0, VT_BOOL);
2063 iRes = IFont_put_Underline((IFont *)this, V_BOOL(&valueAttr));
2065 else if (iRes == E_INVALIDARG)
2067 VariantClear(&rawAttr);
2068 VariantClear(&valueAttr);
2072 iRes = IPropertyBag_Read(pPropBag, sAttrItalic, &rawAttr, pErrorLog);
2075 iRes = VariantChangeType(&rawAttr, &valueAttr, 0, VT_BOOL);
2077 iRes = IFont_put_Italic((IFont *)this, V_BOOL(&valueAttr));
2079 else if (iRes == E_INVALIDARG)
2081 VariantClear(&rawAttr);
2082 VariantClear(&valueAttr);
2086 iRes = IPropertyBag_Read(pPropBag, sAttrStrikethrough, &rawAttr, pErrorLog);
2089 iRes = VariantChangeType(&rawAttr, &valueAttr, 0, VT_BOOL);
2091 IFont_put_Strikethrough((IFont *)this, V_BOOL(&valueAttr));
2093 else if (iRes == E_INVALIDARG)
2095 VariantClear(&rawAttr);
2096 VariantClear(&valueAttr);
2100 WARN("-- 0x%08lx\n", iRes);
2104 static HRESULT WINAPI OLEFontImpl_IPersistPropertyBag_Save(
2105 IPersistPropertyBag *iface, IPropertyBag* pPropBag, BOOL fClearDirty,
2106 BOOL fSaveAllProperties
2108 FIXME("(%p,%p,%d,%d), stub!\n", iface, pPropBag, fClearDirty, fSaveAllProperties);
2112 static const IPersistPropertyBagVtbl OLEFontImpl_IPersistPropertyBag_VTable =
2114 OLEFontImpl_IPersistPropertyBag_QueryInterface,
2115 OLEFontImpl_IPersistPropertyBag_AddRef,
2116 OLEFontImpl_IPersistPropertyBag_Release,
2118 OLEFontImpl_IPersistPropertyBag_GetClassID,
2119 OLEFontImpl_IPersistPropertyBag_InitNew,
2120 OLEFontImpl_IPersistPropertyBag_Load,
2121 OLEFontImpl_IPersistPropertyBag_Save
2124 /************************************************************************
2125 * OLEFontImpl implementation of IPersistStreamInit.
2127 static HRESULT WINAPI OLEFontImpl_IPersistStreamInit_QueryInterface(
2128 IPersistStreamInit *iface, REFIID riid, LPVOID *ppvObj
2130 OLEFontImpl *this = impl_from_IPersistStreamInit(iface);
2131 return IFont_QueryInterface((IFont *)this,riid,ppvObj);
2134 static ULONG WINAPI OLEFontImpl_IPersistStreamInit_AddRef(
2135 IPersistStreamInit *iface
2137 OLEFontImpl *this = impl_from_IPersistStreamInit(iface);
2138 return IFont_AddRef((IFont *)this);
2141 static ULONG WINAPI OLEFontImpl_IPersistStreamInit_Release(
2142 IPersistStreamInit *iface
2144 OLEFontImpl *this = impl_from_IPersistStreamInit(iface);
2145 return IFont_Release((IFont *)this);
2148 static HRESULT WINAPI OLEFontImpl_IPersistStreamInit_GetClassID(
2149 IPersistStreamInit *iface, CLSID *classid
2151 FIXME("(%p,%p), stub!\n", iface, classid);
2155 static HRESULT WINAPI OLEFontImpl_IPersistStreamInit_IsDirty(
2156 IPersistStreamInit *iface
2158 FIXME("(%p), stub!\n", iface);
2162 static HRESULT WINAPI OLEFontImpl_IPersistStreamInit_Load(
2163 IPersistStreamInit *iface, LPSTREAM pStm
2165 FIXME("(%p,%p), stub!\n", iface, pStm);
2169 static HRESULT WINAPI OLEFontImpl_IPersistStreamInit_Save(
2170 IPersistStreamInit *iface, LPSTREAM pStm, BOOL fClearDirty
2172 FIXME("(%p,%p,%d), stub!\n", iface, pStm, fClearDirty);
2176 static HRESULT WINAPI OLEFontImpl_IPersistStreamInit_GetSizeMax(
2177 IPersistStreamInit *iface, ULARGE_INTEGER *pcbSize
2179 FIXME("(%p,%p), stub!\n", iface, pcbSize);
2183 static HRESULT WINAPI OLEFontImpl_IPersistStreamInit_InitNew(
2184 IPersistStreamInit *iface
2186 FIXME("(%p), stub!\n", iface);
2190 static const IPersistStreamInitVtbl OLEFontImpl_IPersistStreamInit_VTable =
2192 OLEFontImpl_IPersistStreamInit_QueryInterface,
2193 OLEFontImpl_IPersistStreamInit_AddRef,
2194 OLEFontImpl_IPersistStreamInit_Release,
2196 OLEFontImpl_IPersistStreamInit_GetClassID,
2197 OLEFontImpl_IPersistStreamInit_IsDirty,
2198 OLEFontImpl_IPersistStreamInit_Load,
2199 OLEFontImpl_IPersistStreamInit_Save,
2200 OLEFontImpl_IPersistStreamInit_GetSizeMax,
2201 OLEFontImpl_IPersistStreamInit_InitNew
2204 /*******************************************************************************
2205 * StdFont ClassFactory
2209 /* IUnknown fields */
2210 const IClassFactoryVtbl *lpVtbl;
2212 } IClassFactoryImpl;
2214 static HRESULT WINAPI
2215 SFCF_QueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj) {
2216 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
2218 FIXME("(%p)->(%s,%p),stub!\n",This,debugstr_guid(riid),ppobj);
2219 return E_NOINTERFACE;
2223 SFCF_AddRef(LPCLASSFACTORY iface) {
2224 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
2225 return InterlockedIncrement(&This->ref);
2228 static ULONG WINAPI SFCF_Release(LPCLASSFACTORY iface) {
2229 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
2230 /* static class, won't be freed */
2231 return InterlockedDecrement(&This->ref);
2234 static HRESULT WINAPI SFCF_CreateInstance(
2235 LPCLASSFACTORY iface,LPUNKNOWN pOuter,REFIID riid,LPVOID *ppobj
2237 return OleCreateFontIndirect(NULL,riid,ppobj);
2241 static HRESULT WINAPI SFCF_LockServer(LPCLASSFACTORY iface,BOOL dolock) {
2242 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
2243 FIXME("(%p)->(%d),stub!\n",This,dolock);
2247 static const IClassFactoryVtbl SFCF_Vtbl = {
2248 SFCF_QueryInterface,
2251 SFCF_CreateInstance,
2254 static IClassFactoryImpl STDFONT_CF = {&SFCF_Vtbl, 1 };
2256 void _get_STDFONT_CF(LPVOID *ppv) { *ppv = (LPVOID)&STDFONT_CF; }