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
29 #include "wine/unicode.h"
30 #include "oleauto.h" /* for SysAllocString(....) */
31 #include "wine/obj_base.h"
32 #include "wine/obj_olefont.h"
33 #include "wine/obj_storage.h"
36 #include "wine/debug.h"
37 #include "connpt.h" /* for CreateConnectionPoint */
39 WINE_DEFAULT_DEBUG_CHANNEL(ole);
41 /***********************************************************************
42 * Declaration of constants used when serializing the font object.
44 #define FONTPERSIST_ITALIC 0x02
45 #define FONTPERSIST_UNDERLINE 0x04
46 #define FONTPERSIST_STRIKETHROUGH 0x08
48 /***********************************************************************
49 * Declaration of the implementation class for the IFont interface
51 typedef struct OLEFontImpl OLEFontImpl;
56 * This class supports many interfaces. IUnknown, IFont,
57 * IDispatch, IDispFont IPersistStream and IConnectionPointContainer.
58 * The first two are supported by the first vtable, the next two are
59 * supported by the second table and the last two have their own.
61 ICOM_VTABLE(IFont)* lpvtbl1;
62 ICOM_VTABLE(IDispatch)* lpvtbl2;
63 ICOM_VTABLE(IPersistStream)* lpvtbl3;
64 ICOM_VTABLE(IConnectionPointContainer)* lpvtbl4;
66 * Reference count for that instance of the class.
71 * This structure contains the description of the class.
76 * Contain the font associated with this object.
91 IConnectionPoint *pCP;
95 * Here, I define utility macros to help with the casting of the
97 * There is a version to accomodate all of the VTables implemented
100 #define _ICOM_THIS(class,name) class* this = (class*)name;
101 #define _ICOM_THIS_From_IDispatch(class, name) class* this = (class*)(((char*)name)-sizeof(void*));
102 #define _ICOM_THIS_From_IPersistStream(class, name) class* this = (class*)(((char*)name)-2*sizeof(void*));
103 #define _ICOM_THIS_From_IConnectionPointContainer(class, name) class* this = (class*)(((char*)name)-3*sizeof(void*));
106 /***********************************************************************
107 * Prototypes for the implementation functions for the IFont
110 static OLEFontImpl* OLEFontImpl_Construct(LPFONTDESC fontDesc);
111 static void OLEFontImpl_Destroy(OLEFontImpl* fontDesc);
112 static HRESULT WINAPI OLEFontImpl_QueryInterface(IFont* iface, REFIID riid, VOID** ppvoid);
113 static ULONG WINAPI OLEFontImpl_AddRef(IFont* iface);
114 static ULONG WINAPI OLEFontImpl_Release(IFont* iface);
115 static HRESULT WINAPI OLEFontImpl_get_Name(IFont* iface, BSTR* pname);
116 static HRESULT WINAPI OLEFontImpl_put_Name(IFont* iface, BSTR name);
117 static HRESULT WINAPI OLEFontImpl_get_Size(IFont* iface, CY* psize);
118 static HRESULT WINAPI OLEFontImpl_put_Size(IFont* iface, CY size);
119 static HRESULT WINAPI OLEFontImpl_get_Bold(IFont* iface, BOOL* pbold);
120 static HRESULT WINAPI OLEFontImpl_put_Bold(IFont* iface, BOOL bold);
121 static HRESULT WINAPI OLEFontImpl_get_Italic(IFont* iface, BOOL* pitalic);
122 static HRESULT WINAPI OLEFontImpl_put_Italic(IFont* iface, BOOL italic);
123 static HRESULT WINAPI OLEFontImpl_get_Underline(IFont* iface, BOOL* punderline);
124 static HRESULT WINAPI OLEFontImpl_put_Underline(IFont* iface, BOOL underline);
125 static HRESULT WINAPI OLEFontImpl_get_Strikethrough(IFont* iface, BOOL* pstrikethrough);
126 static HRESULT WINAPI OLEFontImpl_put_Strikethrough(IFont* iface, BOOL strikethrough);
127 static HRESULT WINAPI OLEFontImpl_get_Weight(IFont* iface, short* pweight);
128 static HRESULT WINAPI OLEFontImpl_put_Weight(IFont* iface, short weight);
129 static HRESULT WINAPI OLEFontImpl_get_Charset(IFont* iface, short* pcharset);
130 static HRESULT WINAPI OLEFontImpl_put_Charset(IFont* iface, short charset);
131 static HRESULT WINAPI OLEFontImpl_get_hFont(IFont* iface, HFONT* phfont);
132 static HRESULT WINAPI OLEFontImpl_Clone(IFont* iface, IFont** ppfont);
133 static HRESULT WINAPI OLEFontImpl_IsEqual(IFont* iface, IFont* pFontOther);
134 static HRESULT WINAPI OLEFontImpl_SetRatio(IFont* iface, long cyLogical, long cyHimetric);
135 static HRESULT WINAPI OLEFontImpl_QueryTextMetrics(IFont* iface, TEXTMETRICOLE* ptm);
136 static HRESULT WINAPI OLEFontImpl_AddRefHfont(IFont* iface, HFONT hfont);
137 static HRESULT WINAPI OLEFontImpl_ReleaseHfont(IFont* iface, HFONT hfont);
138 static HRESULT WINAPI OLEFontImpl_SetHdc(IFont* iface, HDC hdc);
140 /***********************************************************************
141 * Prototypes for the implementation functions for the IDispatch
144 static HRESULT WINAPI OLEFontImpl_IDispatch_QueryInterface(IDispatch* iface,
147 static ULONG WINAPI OLEFontImpl_IDispatch_AddRef(IDispatch* iface);
148 static ULONG WINAPI OLEFontImpl_IDispatch_Release(IDispatch* iface);
149 static HRESULT WINAPI OLEFontImpl_GetTypeInfoCount(IDispatch* iface,
150 unsigned int* pctinfo);
151 static HRESULT WINAPI OLEFontImpl_GetTypeInfo(IDispatch* iface,
154 ITypeInfo** ppTInfo);
155 static HRESULT WINAPI OLEFontImpl_GetIDsOfNames(IDispatch* iface,
161 static HRESULT WINAPI OLEFontImpl_Invoke(IDispatch* iface,
166 DISPPARAMS* pDispParams,
168 EXCEPINFO* pExepInfo,
171 /***********************************************************************
172 * Prototypes for the implementation functions for the IPersistStream
175 static HRESULT WINAPI OLEFontImpl_IPersistStream_QueryInterface(IPersistStream* iface,
178 static ULONG WINAPI OLEFontImpl_IPersistStream_AddRef(IPersistStream* iface);
179 static ULONG WINAPI OLEFontImpl_IPersistStream_Release(IPersistStream* iface);
180 static HRESULT WINAPI OLEFontImpl_GetClassID(IPersistStream* iface,
182 static HRESULT WINAPI OLEFontImpl_IsDirty(IPersistStream* iface);
183 static HRESULT WINAPI OLEFontImpl_Load(IPersistStream* iface,
184 IStream* pLoadStream);
185 static HRESULT WINAPI OLEFontImpl_Save(IPersistStream* iface,
188 static HRESULT WINAPI OLEFontImpl_GetSizeMax(IPersistStream* iface,
189 ULARGE_INTEGER* pcbSize);
191 /***********************************************************************
192 * Prototypes for the implementation functions for the
193 * IConnectionPointContainer interface
195 static HRESULT WINAPI OLEFontImpl_IConnectionPointContainer_QueryInterface(
196 IConnectionPointContainer* iface,
199 static ULONG WINAPI OLEFontImpl_IConnectionPointContainer_AddRef(
200 IConnectionPointContainer* iface);
201 static ULONG WINAPI OLEFontImpl_IConnectionPointContainer_Release(
202 IConnectionPointContainer* iface);
203 static HRESULT WINAPI OLEFontImpl_EnumConnectionPoints(
204 IConnectionPointContainer* iface,
205 IEnumConnectionPoints **ppEnum);
206 static HRESULT WINAPI OLEFontImpl_FindConnectionPoint(
207 IConnectionPointContainer* iface,
209 IConnectionPoint **ppCp);
212 * Virtual function tables for the OLEFontImpl class.
214 static ICOM_VTABLE(IFont) OLEFontImpl_VTable =
216 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
217 OLEFontImpl_QueryInterface,
220 OLEFontImpl_get_Name,
221 OLEFontImpl_put_Name,
222 OLEFontImpl_get_Size,
223 OLEFontImpl_put_Size,
224 OLEFontImpl_get_Bold,
225 OLEFontImpl_put_Bold,
226 OLEFontImpl_get_Italic,
227 OLEFontImpl_put_Italic,
228 OLEFontImpl_get_Underline,
229 OLEFontImpl_put_Underline,
230 OLEFontImpl_get_Strikethrough,
231 OLEFontImpl_put_Strikethrough,
232 OLEFontImpl_get_Weight,
233 OLEFontImpl_put_Weight,
234 OLEFontImpl_get_Charset,
235 OLEFontImpl_put_Charset,
236 OLEFontImpl_get_hFont,
239 OLEFontImpl_SetRatio,
240 OLEFontImpl_QueryTextMetrics,
241 OLEFontImpl_AddRefHfont,
242 OLEFontImpl_ReleaseHfont,
246 static ICOM_VTABLE(IDispatch) OLEFontImpl_IDispatch_VTable =
248 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
249 OLEFontImpl_IDispatch_QueryInterface,
250 OLEFontImpl_IDispatch_AddRef,
251 OLEFontImpl_IDispatch_Release,
252 OLEFontImpl_GetTypeInfoCount,
253 OLEFontImpl_GetTypeInfo,
254 OLEFontImpl_GetIDsOfNames,
258 static ICOM_VTABLE(IPersistStream) OLEFontImpl_IPersistStream_VTable =
260 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
261 OLEFontImpl_IPersistStream_QueryInterface,
262 OLEFontImpl_IPersistStream_AddRef,
263 OLEFontImpl_IPersistStream_Release,
264 OLEFontImpl_GetClassID,
268 OLEFontImpl_GetSizeMax
271 static ICOM_VTABLE(IConnectionPointContainer)
272 OLEFontImpl_IConnectionPointContainer_VTable =
274 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
275 OLEFontImpl_IConnectionPointContainer_QueryInterface,
276 OLEFontImpl_IConnectionPointContainer_AddRef,
277 OLEFontImpl_IConnectionPointContainer_Release,
278 OLEFontImpl_EnumConnectionPoints,
279 OLEFontImpl_FindConnectionPoint
282 /******************************************************************************
283 * OleCreateFontIndirect [OLEAUT32.420]
285 HRESULT WINAPI OleCreateFontIndirect(
286 LPFONTDESC lpFontDesc,
290 OLEFontImpl* newFont = 0;
293 TRACE("(%p, %s, %p)\n", lpFontDesc, debugstr_guid(riid), ppvObj);
303 return NO_ERROR; /* MSDN Oct 2001 */
306 * Try to construct a new instance of the class.
308 newFont = OLEFontImpl_Construct(lpFontDesc);
311 return E_OUTOFMEMORY;
314 * Make sure it supports the interface required by the caller.
316 hr = IFont_QueryInterface((IFont*)newFont, riid, ppvObj);
319 * Release the reference obtained in the constructor. If
320 * the QueryInterface was unsuccessful, it will free the class.
322 IFont_Release((IFont*)newFont);
328 /***********************************************************************
329 * Implementation of the OLEFontImpl class.
332 /***********************************************************************
333 * OLEFont_SendNotify (internal)
335 * Sends notification messages of changed properties to any interested
338 static void OLEFont_SendNotify(OLEFontImpl* this, DISPID dispID)
340 IEnumConnections *pEnum;
343 IConnectionPoint_EnumConnections(this->pCP, &pEnum);
345 while(IEnumConnections_Next(pEnum, 1, &CD, NULL) == S_OK) {
346 IPropertyNotifySink *sink;
348 IUnknown_QueryInterface(CD.pUnk, &IID_IPropertyNotifySink, (LPVOID)&sink);
349 IPropertyNotifySink_OnChanged(sink, dispID);
350 IPropertyNotifySink_Release(sink);
351 IUnknown_Release(CD.pUnk);
353 IEnumConnections_Release(pEnum);
357 /************************************************************************
358 * OLEFontImpl_Construct
360 * This method will construct a new instance of the OLEFontImpl
363 * The caller of this method must release the object when it's
366 static OLEFontImpl* OLEFontImpl_Construct(LPFONTDESC fontDesc)
368 OLEFontImpl* newObject = 0;
371 * Allocate space for the object.
373 newObject = HeapAlloc(GetProcessHeap(), 0, sizeof(OLEFontImpl));
379 * Initialize the virtual function table.
381 newObject->lpvtbl1 = &OLEFontImpl_VTable;
382 newObject->lpvtbl2 = &OLEFontImpl_IDispatch_VTable;
383 newObject->lpvtbl3 = &OLEFontImpl_IPersistStream_VTable;
384 newObject->lpvtbl4 = &OLEFontImpl_IConnectionPointContainer_VTable;
387 * Start with one reference count. The caller of this function
388 * must release the interface pointer when it is done.
393 * Copy the description of the font in the object.
395 assert(fontDesc->cbSizeofstruct >= sizeof(FONTDESC));
397 newObject->description.cbSizeofstruct = sizeof(FONTDESC);
398 newObject->description.lpstrName = HeapAlloc(GetProcessHeap(),
400 (lstrlenW(fontDesc->lpstrName)+1) * sizeof(WCHAR));
401 strcpyW(newObject->description.lpstrName, fontDesc->lpstrName);
402 newObject->description.cySize = fontDesc->cySize;
403 newObject->description.sWeight = fontDesc->sWeight;
404 newObject->description.sCharset = fontDesc->sCharset;
405 newObject->description.fItalic = fontDesc->fItalic;
406 newObject->description.fUnderline = fontDesc->fUnderline;
407 newObject->description.fStrikethrough = fontDesc->fStrikethrough;
410 * Initializing all the other members.
412 newObject->gdiFont = 0;
413 newObject->fontLock = 0;
414 newObject->cyHimetric = 1;
415 newObject->cyLogical = 1;
417 CreateConnectionPoint((IUnknown*)newObject, &IID_IPropertyNotifySink, &newObject->pCP);
419 TRACE("returning %p\n", newObject);
423 /************************************************************************
424 * OLEFontImpl_Destroy
426 * This method is called by the Release method when the reference
427 * count goes down to 0. It will free all resources used by
430 static void OLEFontImpl_Destroy(OLEFontImpl* fontDesc)
432 TRACE("(%p)\n", fontDesc);
434 if (fontDesc->description.lpstrName!=0)
435 HeapFree(GetProcessHeap(), 0, fontDesc->description.lpstrName);
437 if (fontDesc->gdiFont!=0)
438 DeleteObject(fontDesc->gdiFont);
440 HeapFree(GetProcessHeap(), 0, fontDesc);
443 /************************************************************************
444 * OLEFontImpl_QueryInterface (IUnknown)
446 * See Windows documentation for more details on IUnknown methods.
448 HRESULT WINAPI OLEFontImpl_QueryInterface(
453 _ICOM_THIS(OLEFontImpl, iface);
454 TRACE("(%p)->(%s, %p)\n", this, debugstr_guid(riid), ppvObject);
457 * Perform a sanity check on the parameters.
459 if ( (this==0) || (ppvObject==0) )
463 * Initialize the return parameter.
468 * Compare the riid with the interface IDs implemented by this object.
470 if (memcmp(&IID_IUnknown, riid, sizeof(IID_IUnknown)) == 0)
472 *ppvObject = (IFont*)this;
474 else if (memcmp(&IID_IFont, riid, sizeof(IID_IFont)) == 0)
476 *ppvObject = (IFont*)this;
478 else if (memcmp(&IID_IDispatch, riid, sizeof(IID_IDispatch)) == 0)
480 *ppvObject = (IDispatch*)&(this->lpvtbl2);
482 else if (memcmp(&IID_IFontDisp, riid, sizeof(IID_IFontDisp)) == 0)
484 *ppvObject = (IDispatch*)&(this->lpvtbl2);
486 else if (memcmp(&IID_IPersistStream, riid, sizeof(IID_IPersistStream)) == 0)
488 *ppvObject = (IPersistStream*)&(this->lpvtbl3);
490 else if (memcmp(&IID_IConnectionPointContainer, riid,
491 sizeof(IID_IConnectionPointContainer)) == 0)
493 *ppvObject = (IPersistStream*)&(this->lpvtbl4);
497 * Check that we obtained an interface.
501 FIXME("() : asking for un supported interface %s\n",debugstr_guid(riid));
502 return E_NOINTERFACE;
506 * Query Interface always increases the reference count by one when it is
509 OLEFontImpl_AddRef((IFont*)this);
514 /************************************************************************
515 * OLEFontImpl_AddRef (IUnknown)
517 * See Windows documentation for more details on IUnknown methods.
519 ULONG WINAPI OLEFontImpl_AddRef(
522 _ICOM_THIS(OLEFontImpl, iface);
523 TRACE("(%p)->(ref=%ld)\n", this, this->ref);
529 /************************************************************************
530 * OLEFontImpl_Release (IUnknown)
532 * See Windows documentation for more details on IUnknown methods.
534 ULONG WINAPI OLEFontImpl_Release(
537 _ICOM_THIS(OLEFontImpl, iface);
538 TRACE("(%p)->(ref=%ld)\n", this, this->ref);
541 * Decrease the reference count on this object.
546 * If the reference count goes down to 0, perform suicide.
550 OLEFontImpl_Destroy(this);
558 /************************************************************************
559 * OLEFontImpl_get_Name (IFont)
561 * See Windows documentation for more details on IFont methods.
563 static HRESULT WINAPI OLEFontImpl_get_Name(
567 _ICOM_THIS(OLEFontImpl, iface);
568 TRACE("(%p)->(%p)\n", this, pname);
575 if (this->description.lpstrName!=0)
576 *pname = SysAllocString(this->description.lpstrName);
583 /************************************************************************
584 * OLEFontImpl_put_Name (IFont)
586 * See Windows documentation for more details on IFont methods.
588 static HRESULT WINAPI OLEFontImpl_put_Name(
592 _ICOM_THIS(OLEFontImpl, iface);
593 TRACE("(%p)->(%p)\n", this, name);
595 if (this->description.lpstrName==0)
597 this->description.lpstrName = HeapAlloc(GetProcessHeap(),
599 (lstrlenW(name)+1) * sizeof(WCHAR));
603 this->description.lpstrName = HeapReAlloc(GetProcessHeap(),
605 this->description.lpstrName,
606 (lstrlenW(name)+1) * sizeof(WCHAR));
609 if (this->description.lpstrName==0)
610 return E_OUTOFMEMORY;
612 strcpyW(this->description.lpstrName, name);
613 TRACE("new name %s\n", debugstr_w(this->description.lpstrName));
614 OLEFont_SendNotify(this, DISPID_FONT_NAME);
618 /************************************************************************
619 * OLEFontImpl_get_Size (IFont)
621 * See Windows documentation for more details on IFont methods.
623 static HRESULT WINAPI OLEFontImpl_get_Size(
627 _ICOM_THIS(OLEFontImpl, iface);
628 TRACE("(%p)->(%p)\n", this, psize);
637 psize->s.Lo = this->description.cySize.s.Lo;
642 /************************************************************************
643 * OLEFontImpl_put_Size (IFont)
645 * See Windows documentation for more details on IFont methods.
647 static HRESULT WINAPI OLEFontImpl_put_Size(
651 _ICOM_THIS(OLEFontImpl, iface);
652 TRACE("(%p)->(%ld)\n", this, size.s.Lo);
653 this->description.cySize.s.Hi = 0;
654 this->description.cySize.s.Lo = size.s.Lo;
655 OLEFont_SendNotify(this, DISPID_FONT_SIZE);
660 /************************************************************************
661 * OLEFontImpl_get_Bold (IFont)
663 * See Windows documentation for more details on IFont methods.
665 static HRESULT WINAPI OLEFontImpl_get_Bold(
669 _ICOM_THIS(OLEFontImpl, iface);
670 TRACE("(%p)->(%p)\n", this, pbold);
677 *pbold = this->description.sWeight > 550;
682 /************************************************************************
683 * OLEFontImpl_put_Bold (IFont)
685 * See Windows documentation for more details on IFont methods.
687 static HRESULT WINAPI OLEFontImpl_put_Bold(
691 _ICOM_THIS(OLEFontImpl, iface);
692 TRACE("(%p)->(%d)\n", this, bold);
693 this->description.sWeight = bold ? FW_BOLD : FW_NORMAL;
694 OLEFont_SendNotify(this, DISPID_FONT_BOLD);
699 /************************************************************************
700 * OLEFontImpl_get_Italic (IFont)
702 * See Windows documentation for more details on IFont methods.
704 static HRESULT WINAPI OLEFontImpl_get_Italic(
708 _ICOM_THIS(OLEFontImpl, iface);
709 TRACE("(%p)->(%p)\n", this, pitalic);
716 *pitalic = this->description.fItalic;
721 /************************************************************************
722 * OLEFontImpl_put_Italic (IFont)
724 * See Windows documentation for more details on IFont methods.
726 static HRESULT WINAPI OLEFontImpl_put_Italic(
730 _ICOM_THIS(OLEFontImpl, iface);
731 TRACE("(%p)->(%d)\n", this, italic);
733 this->description.fItalic = italic;
735 OLEFont_SendNotify(this, DISPID_FONT_ITALIC);
739 /************************************************************************
740 * OLEFontImpl_get_Underline (IFont)
742 * See Windows documentation for more details on IFont methods.
744 static HRESULT WINAPI OLEFontImpl_get_Underline(
748 _ICOM_THIS(OLEFontImpl, iface);
749 TRACE("(%p)->(%p)\n", this, punderline);
757 *punderline = this->description.fUnderline;
762 /************************************************************************
763 * OLEFontImpl_put_Underline (IFont)
765 * See Windows documentation for more details on IFont methods.
767 static HRESULT WINAPI OLEFontImpl_put_Underline(
771 _ICOM_THIS(OLEFontImpl, iface);
772 TRACE("(%p)->(%d)\n", this, underline);
774 this->description.fUnderline = underline;
776 OLEFont_SendNotify(this, DISPID_FONT_UNDER);
780 /************************************************************************
781 * OLEFontImpl_get_Strikethrough (IFont)
783 * See Windows documentation for more details on IFont methods.
785 static HRESULT WINAPI OLEFontImpl_get_Strikethrough(
787 BOOL* pstrikethrough)
789 _ICOM_THIS(OLEFontImpl, iface);
790 TRACE("(%p)->(%p)\n", this, pstrikethrough);
795 if (pstrikethrough==0)
798 *pstrikethrough = this->description.fStrikethrough;
803 /************************************************************************
804 * OLEFontImpl_put_Strikethrough (IFont)
806 * See Windows documentation for more details on IFont methods.
808 static HRESULT WINAPI OLEFontImpl_put_Strikethrough(
812 _ICOM_THIS(OLEFontImpl, iface);
813 TRACE("(%p)->(%d)\n", this, strikethrough);
815 this->description.fStrikethrough = strikethrough;
816 OLEFont_SendNotify(this, DISPID_FONT_STRIKE);
821 /************************************************************************
822 * OLEFontImpl_get_Weight (IFont)
824 * See Windows documentation for more details on IFont methods.
826 static HRESULT WINAPI OLEFontImpl_get_Weight(
830 _ICOM_THIS(OLEFontImpl, iface);
831 TRACE("(%p)->(%p)\n", this, pweight);
839 *pweight = this->description.sWeight;
844 /************************************************************************
845 * OLEFontImpl_put_Weight (IFont)
847 * See Windows documentation for more details on IFont methods.
849 static HRESULT WINAPI OLEFontImpl_put_Weight(
853 _ICOM_THIS(OLEFontImpl, iface);
854 TRACE("(%p)->(%d)\n", this, weight);
856 this->description.sWeight = weight;
858 OLEFont_SendNotify(this, DISPID_FONT_WEIGHT);
862 /************************************************************************
863 * OLEFontImpl_get_Charset (IFont)
865 * See Windows documentation for more details on IFont methods.
867 static HRESULT WINAPI OLEFontImpl_get_Charset(
871 _ICOM_THIS(OLEFontImpl, iface);
872 TRACE("(%p)->(%p)\n", this, pcharset);
880 *pcharset = this->description.sCharset;
885 /************************************************************************
886 * OLEFontImpl_put_Charset (IFont)
888 * See Windows documentation for more details on IFont methods.
890 static HRESULT WINAPI OLEFontImpl_put_Charset(
894 _ICOM_THIS(OLEFontImpl, iface);
895 TRACE("(%p)->(%d)\n", this, charset);
897 this->description.sCharset = charset;
898 OLEFont_SendNotify(this, DISPID_FONT_CHARSET);
903 /************************************************************************
904 * OLEFontImpl_get_hFont (IFont)
906 * See Windows documentation for more details on IFont methods.
908 static HRESULT WINAPI OLEFontImpl_get_hFont(
912 _ICOM_THIS(OLEFontImpl, iface);
913 TRACE("(%p)->(%p)\n", this, phfont);
918 * Realize the font if necessary
920 if (this->gdiFont==0)
927 * The height of the font returned by the get_Size property is the
928 * height of the font in points multiplied by 10000... Using some
929 * simple conversions and the ratio given by the application, it can
930 * be converted to a height in pixels.
932 IFont_get_Size(iface, &cySize);
934 fontHeight = MulDiv(cySize.s.Lo, 2540L, 72L);
935 fontHeight = MulDiv(fontHeight, this->cyLogical,this->cyHimetric);
937 memset(&logFont, 0, sizeof(LOGFONTW));
939 logFont.lfHeight = ((fontHeight%10000L)>5000L) ? (-fontHeight/10000L)-1 :
940 (-fontHeight/10000L);
941 logFont.lfItalic = this->description.fItalic;
942 logFont.lfUnderline = this->description.fUnderline;
943 logFont.lfStrikeOut = this->description.fStrikethrough;
944 logFont.lfWeight = this->description.sWeight;
945 logFont.lfCharSet = this->description.sCharset;
946 logFont.lfOutPrecision = OUT_CHARACTER_PRECIS;
947 logFont.lfClipPrecision = CLIP_DEFAULT_PRECIS;
948 logFont.lfQuality = DEFAULT_QUALITY;
949 logFont.lfPitchAndFamily = DEFAULT_PITCH;
950 strcpyW(logFont.lfFaceName,this->description.lpstrName);
952 this->gdiFont = CreateFontIndirectW(&logFont);
955 *phfont = this->gdiFont;
956 TRACE("Returning %08x\n", *phfont);
960 /************************************************************************
961 * OLEFontImpl_Clone (IFont)
963 * See Windows documentation for more details on IFont methods.
965 static HRESULT WINAPI OLEFontImpl_Clone(
969 OLEFontImpl* newObject = 0;
973 _ICOM_THIS(OLEFontImpl, iface);
974 TRACE("(%p)->(%p)\n", this, ppfont);
982 * Allocate space for the object.
984 newObject = HeapAlloc(GetProcessHeap(), 0, sizeof(OLEFontImpl));
987 return E_OUTOFMEMORY;
991 /* We need to alloc new memory for the string, otherwise
992 * we free memory twice.
994 newObject->description.lpstrName = HeapAlloc(
996 (1+strlenW(this->description.lpstrName))*2
998 strcpyW(newObject->description.lpstrName, this->description.lpstrName);
999 /* We need to clone the HFONT too. This is just cut & paste from above */
1000 IFont_get_Size(iface, &cySize);
1002 fontHeight = MulDiv(cySize.s.Lo, 2540L, 72L);
1003 fontHeight = MulDiv(fontHeight, this->cyLogical,this->cyHimetric);
1005 memset(&logFont, 0, sizeof(LOGFONTW));
1007 logFont.lfHeight = ((fontHeight%10000L)>5000L) ? (-fontHeight/10000L)-1 :
1008 (-fontHeight/10000L);
1009 logFont.lfItalic = this->description.fItalic;
1010 logFont.lfUnderline = this->description.fUnderline;
1011 logFont.lfStrikeOut = this->description.fStrikethrough;
1012 logFont.lfWeight = this->description.sWeight;
1013 logFont.lfCharSet = this->description.sCharset;
1014 logFont.lfOutPrecision = OUT_CHARACTER_PRECIS;
1015 logFont.lfClipPrecision = CLIP_DEFAULT_PRECIS;
1016 logFont.lfQuality = DEFAULT_QUALITY;
1017 logFont.lfPitchAndFamily = DEFAULT_PITCH;
1018 strcpyW(logFont.lfFaceName,this->description.lpstrName);
1020 newObject->gdiFont = CreateFontIndirectW(&logFont);
1023 /* The cloned object starts with a reference count of 1 */
1026 *ppfont = (IFont*)newObject;
1031 /************************************************************************
1032 * OLEFontImpl_IsEqual (IFont)
1034 * See Windows documentation for more details on IFont methods.
1036 static HRESULT WINAPI OLEFontImpl_IsEqual(
1044 /************************************************************************
1045 * OLEFontImpl_SetRatio (IFont)
1047 * See Windows documentation for more details on IFont methods.
1049 static HRESULT WINAPI OLEFontImpl_SetRatio(
1054 _ICOM_THIS(OLEFontImpl, iface);
1055 TRACE("(%p)->(%ld, %ld)\n", this, cyLogical, cyHimetric);
1057 this->cyLogical = cyLogical;
1058 this->cyHimetric = cyHimetric;
1063 /************************************************************************
1064 * OLEFontImpl_QueryTextMetrics (IFont)
1066 * See Windows documentation for more details on IFont methods.
1068 static HRESULT WINAPI OLEFontImpl_QueryTextMetrics(
1076 /************************************************************************
1077 * OLEFontImpl_AddRefHfont (IFont)
1079 * See Windows documentation for more details on IFont methods.
1081 static HRESULT WINAPI OLEFontImpl_AddRefHfont(
1085 _ICOM_THIS(OLEFontImpl, iface);
1086 TRACE("(%p)->(%08x) (lock=%ld)\n", this, hfont, this->fontLock);
1088 if ( (hfont == 0) ||
1089 (hfont != this->gdiFont) )
1090 return E_INVALIDARG;
1097 /************************************************************************
1098 * OLEFontImpl_ReleaseHfont (IFont)
1100 * See Windows documentation for more details on IFont methods.
1102 static HRESULT WINAPI OLEFontImpl_ReleaseHfont(
1106 _ICOM_THIS(OLEFontImpl, iface);
1107 TRACE("(%p)->(%08x) (lock=%ld)\n", this, hfont, this->fontLock);
1109 if ( (hfont == 0) ||
1110 (hfont != this->gdiFont) )
1111 return E_INVALIDARG;
1116 * If we just released our last font reference, destroy it.
1118 if (this->fontLock==0)
1120 DeleteObject(this->gdiFont);
1127 /************************************************************************
1128 * OLEFontImpl_SetHdc (IFont)
1130 * See Windows documentation for more details on IFont methods.
1132 static HRESULT WINAPI OLEFontImpl_SetHdc(
1136 _ICOM_THIS(OLEFontImpl, iface);
1137 FIXME("(%p)->(%08x): Stub\n", this, hdc);
1141 /************************************************************************
1142 * OLEFontImpl_IDispatch_QueryInterface (IUnknown)
1144 * See Windows documentation for more details on IUnknown methods.
1146 static HRESULT WINAPI OLEFontImpl_IDispatch_QueryInterface(
1151 _ICOM_THIS_From_IDispatch(IFont, iface);
1153 return IFont_QueryInterface(this, riid, ppvoid);
1156 /************************************************************************
1157 * OLEFontImpl_IDispatch_Release (IUnknown)
1159 * See Windows documentation for more details on IUnknown methods.
1161 static ULONG WINAPI OLEFontImpl_IDispatch_Release(
1164 _ICOM_THIS_From_IDispatch(IFont, iface);
1166 return IFont_Release(this);
1169 /************************************************************************
1170 * OLEFontImpl_IDispatch_AddRef (IUnknown)
1172 * See Windows documentation for more details on IUnknown methods.
1174 static ULONG WINAPI OLEFontImpl_IDispatch_AddRef(
1177 _ICOM_THIS_From_IDispatch(IFont, iface);
1179 return IFont_AddRef(this);
1182 /************************************************************************
1183 * OLEFontImpl_GetTypeInfoCount (IDispatch)
1185 * See Windows documentation for more details on IDispatch methods.
1187 static HRESULT WINAPI OLEFontImpl_GetTypeInfoCount(
1189 unsigned int* pctinfo)
1191 _ICOM_THIS_From_IDispatch(IFont, iface);
1192 FIXME("(%p)->(%p): Stub\n", this, pctinfo);
1197 /************************************************************************
1198 * OLEFontImpl_GetTypeInfo (IDispatch)
1200 * See Windows documentation for more details on IDispatch methods.
1202 static HRESULT WINAPI OLEFontImpl_GetTypeInfo(
1206 ITypeInfo** ppTInfo)
1208 _ICOM_THIS_From_IDispatch(IFont, iface);
1209 FIXME("(%p):Stub\n", this);
1214 /************************************************************************
1215 * OLEFontImpl_GetIDsOfNames (IDispatch)
1217 * See Windows documentation for more details on IDispatch methods.
1219 static HRESULT WINAPI OLEFontImpl_GetIDsOfNames(
1222 LPOLESTR* rgszNames,
1227 _ICOM_THIS_From_IDispatch(IFont, iface);
1228 FIXME("(%p):Stub\n", this);
1233 /************************************************************************
1234 * OLEFontImpl_Invoke (IDispatch)
1236 * See Windows documentation for more details on IDispatch methods.
1238 static HRESULT WINAPI OLEFontImpl_Invoke(
1240 DISPID dispIdMember,
1244 DISPPARAMS* pDispParams,
1245 VARIANT* pVarResult,
1246 EXCEPINFO* pExepInfo,
1249 _ICOM_THIS_From_IDispatch(IFont, iface);
1250 FIXME("%p->(%ld,%s,%lx,%x), stub!\n", this,dispIdMember,debugstr_guid(riid),lcid,
1256 /************************************************************************
1257 * OLEFontImpl_IPersistStream_QueryInterface (IUnknown)
1259 * See Windows documentation for more details on IUnknown methods.
1261 static HRESULT WINAPI OLEFontImpl_IPersistStream_QueryInterface(
1262 IPersistStream* iface,
1266 _ICOM_THIS_From_IPersistStream(IFont, iface);
1268 return IFont_QueryInterface(this, riid, ppvoid);
1271 /************************************************************************
1272 * OLEFontImpl_IPersistStream_Release (IUnknown)
1274 * See Windows documentation for more details on IUnknown methods.
1276 static ULONG WINAPI OLEFontImpl_IPersistStream_Release(
1277 IPersistStream* iface)
1279 _ICOM_THIS_From_IPersistStream(IFont, iface);
1281 return IFont_Release(this);
1284 /************************************************************************
1285 * OLEFontImpl_IPersistStream_AddRef (IUnknown)
1287 * See Windows documentation for more details on IUnknown methods.
1289 static ULONG WINAPI OLEFontImpl_IPersistStream_AddRef(
1290 IPersistStream* iface)
1292 _ICOM_THIS_From_IPersistStream(IFont, iface);
1294 return IFont_AddRef(this);
1297 /************************************************************************
1298 * OLEFontImpl_GetClassID (IPersistStream)
1300 * See Windows documentation for more details on IPersistStream methods.
1302 static HRESULT WINAPI OLEFontImpl_GetClassID(
1303 IPersistStream* iface,
1309 memcpy(pClassID, &CLSID_StdFont, sizeof(CLSID_StdFont));
1314 /************************************************************************
1315 * OLEFontImpl_IsDirty (IPersistStream)
1317 * See Windows documentation for more details on IPersistStream methods.
1319 static HRESULT WINAPI OLEFontImpl_IsDirty(
1320 IPersistStream* iface)
1325 /************************************************************************
1326 * OLEFontImpl_Load (IPersistStream)
1328 * See Windows documentation for more details on IPersistStream methods.
1330 * This is the format of the standard font serialization as far as I
1333 * Offset Type Value Comment
1334 * 0x0000 Byte Unknown Probably a version number, contains 0x01
1335 * 0x0001 Short Charset Charset value from the FONTDESC structure
1336 * 0x0003 Byte Attributes Flags defined as follows:
1338 * 00000100 - Underline
1339 * 00001000 - Strikethrough
1340 * 0x0004 Short Weight Weight value from FONTDESC structure
1341 * 0x0006 DWORD size "Low" portion of the cySize member of the FONTDESC
1343 * 0x000A Byte name length Length of the font name string (no null character)
1344 * 0x000B String name Name of the font (ASCII, no nul character)
1346 static HRESULT WINAPI OLEFontImpl_Load(
1347 IPersistStream* iface,
1348 IStream* pLoadStream)
1350 char readBuffer[0x100];
1357 _ICOM_THIS_From_IPersistStream(OLEFontImpl, iface);
1360 * Read the version byte
1362 IStream_Read(pLoadStream, &bVersion, 1, &cbRead);
1371 IStream_Read(pLoadStream, &this->description.sCharset, 2, &cbRead);
1379 IStream_Read(pLoadStream, &bAttributes, 1, &cbRead);
1384 this->description.fItalic = (bAttributes & FONTPERSIST_ITALIC) != 0;
1385 this->description.fStrikethrough = (bAttributes & FONTPERSIST_STRIKETHROUGH) != 0;
1386 this->description.fUnderline = (bAttributes & FONTPERSIST_UNDERLINE) != 0;
1391 IStream_Read(pLoadStream, &this->description.sWeight, 2, &cbRead);
1399 IStream_Read(pLoadStream, &this->description.cySize.s.Lo, 4, &cbRead);
1404 this->description.cySize.s.Hi = 0;
1409 IStream_Read(pLoadStream, &bStringSize, 1, &cbRead);
1414 IStream_Read(pLoadStream, readBuffer, bStringSize, &cbRead);
1416 if (cbRead!=bStringSize)
1419 if (this->description.lpstrName!=0)
1420 HeapFree(GetProcessHeap(), 0, this->description.lpstrName);
1422 len = MultiByteToWideChar( CP_ACP, 0, readBuffer, bStringSize, NULL, 0 );
1423 this->description.lpstrName = HeapAlloc( GetProcessHeap(), 0, (len+1) * sizeof(WCHAR) );
1424 MultiByteToWideChar( CP_ACP, 0, readBuffer, bStringSize, this->description.lpstrName, len );
1425 this->description.lpstrName[len] = 0;
1427 /* Ensure use of this font causes a new one to be created @@@@ */
1428 DeleteObject(this->gdiFont);
1434 /************************************************************************
1435 * OLEFontImpl_Save (IPersistStream)
1437 * See Windows documentation for more details on IPersistStream methods.
1439 static HRESULT WINAPI OLEFontImpl_Save(
1440 IPersistStream* iface,
1441 IStream* pOutStream,
1444 char* writeBuffer = NULL;
1446 BYTE bVersion = 0x01;
1450 _ICOM_THIS_From_IPersistStream(OLEFontImpl, iface);
1453 * Read the version byte
1455 IStream_Write(pOutStream, &bVersion, 1, &cbWritten);
1463 IStream_Write(pOutStream, &this->description.sCharset, 2, &cbWritten);
1473 if (this->description.fItalic)
1474 bAttributes |= FONTPERSIST_ITALIC;
1476 if (this->description.fStrikethrough)
1477 bAttributes |= FONTPERSIST_STRIKETHROUGH;
1479 if (this->description.fUnderline)
1480 bAttributes |= FONTPERSIST_UNDERLINE;
1482 IStream_Write(pOutStream, &bAttributes, 1, &cbWritten);
1490 IStream_Write(pOutStream, &this->description.sWeight, 2, &cbWritten);
1498 IStream_Write(pOutStream, &this->description.cySize.s.Lo, 4, &cbWritten);
1506 if (this->description.lpstrName!=0)
1507 bStringSize = WideCharToMultiByte( CP_ACP, 0, this->description.lpstrName,
1508 strlenW(this->description.lpstrName), NULL, 0, NULL, NULL );
1512 IStream_Write(pOutStream, &bStringSize, 1, &cbWritten);
1519 if (!(writeBuffer = HeapAlloc( GetProcessHeap(), 0, bStringSize ))) return E_OUTOFMEMORY;
1520 WideCharToMultiByte( CP_ACP, 0, this->description.lpstrName,
1521 strlenW(this->description.lpstrName),
1522 writeBuffer, bStringSize, NULL, NULL );
1524 IStream_Write(pOutStream, writeBuffer, bStringSize, &cbWritten);
1525 HeapFree(GetProcessHeap(), 0, writeBuffer);
1527 if (cbWritten!=bStringSize)
1534 /************************************************************************
1535 * OLEFontImpl_GetSizeMax (IPersistStream)
1537 * See Windows documentation for more details on IPersistStream methods.
1539 static HRESULT WINAPI OLEFontImpl_GetSizeMax(
1540 IPersistStream* iface,
1541 ULARGE_INTEGER* pcbSize)
1543 _ICOM_THIS_From_IPersistStream(OLEFontImpl, iface);
1548 pcbSize->s.HighPart = 0;
1549 pcbSize->s.LowPart = 0;
1551 pcbSize->s.LowPart += sizeof(BYTE); /* Version */
1552 pcbSize->s.LowPart += sizeof(WORD); /* Lang code */
1553 pcbSize->s.LowPart += sizeof(BYTE); /* Flags */
1554 pcbSize->s.LowPart += sizeof(WORD); /* Weight */
1555 pcbSize->s.LowPart += sizeof(DWORD); /* Size */
1556 pcbSize->s.LowPart += sizeof(BYTE); /* StrLength */
1558 if (this->description.lpstrName!=0)
1559 pcbSize->s.LowPart += lstrlenW(this->description.lpstrName);
1564 /************************************************************************
1565 * OLEFontImpl_IConnectionPointContainer_QueryInterface (IUnknown)
1567 * See Windows documentation for more details on IUnknown methods.
1569 static HRESULT WINAPI OLEFontImpl_IConnectionPointContainer_QueryInterface(
1570 IConnectionPointContainer* iface,
1574 _ICOM_THIS_From_IConnectionPointContainer(OLEFontImpl, iface);
1576 return IFont_QueryInterface((IFont*)this, riid, ppvoid);
1579 /************************************************************************
1580 * OLEFontImpl_IConnectionPointContainer_Release (IUnknown)
1582 * See Windows documentation for more details on IUnknown methods.
1584 static ULONG WINAPI OLEFontImpl_IConnectionPointContainer_Release(
1585 IConnectionPointContainer* iface)
1587 _ICOM_THIS_From_IConnectionPointContainer(OLEFontImpl, iface);
1589 return IFont_Release((IFont*)this);
1592 /************************************************************************
1593 * OLEFontImpl_IConnectionPointContainer_AddRef (IUnknown)
1595 * See Windows documentation for more details on IUnknown methods.
1597 static ULONG WINAPI OLEFontImpl_IConnectionPointContainer_AddRef(
1598 IConnectionPointContainer* iface)
1600 _ICOM_THIS_From_IConnectionPointContainer(OLEFontImpl, iface);
1602 return IFont_AddRef((IFont*)this);
1605 /************************************************************************
1606 * OLEFontImpl_EnumConnectionPoints (IConnectionPointContainer)
1608 * See Windows documentation for more details on IConnectionPointContainer
1611 static HRESULT WINAPI OLEFontImpl_EnumConnectionPoints(
1612 IConnectionPointContainer* iface,
1613 IEnumConnectionPoints **ppEnum)
1615 _ICOM_THIS_From_IConnectionPointContainer(OLEFontImpl, iface);
1617 FIXME("(%p)->(%p): stub\n", this, ppEnum);
1621 /************************************************************************
1622 * OLEFontImpl_FindConnectionPoint (IConnectionPointContainer)
1624 * See Windows documentation for more details on IConnectionPointContainer
1627 static HRESULT WINAPI OLEFontImpl_FindConnectionPoint(
1628 IConnectionPointContainer* iface,
1630 IConnectionPoint **ppCp)
1632 _ICOM_THIS_From_IConnectionPointContainer(OLEFontImpl, iface);
1633 TRACE("(%p)->(%s, %p): stub\n", this, debugstr_guid(riid), ppCp);
1635 if(memcmp(riid, &IID_IPropertyNotifySink, sizeof(IID_IPropertyNotifySink)) == 0) {
1636 return IConnectionPoint_QueryInterface(this->pCP, &IID_IConnectionPoint,
1639 FIXME("Tried to find connection point on %s\n", debugstr_guid(riid));
1640 return E_NOINTERFACE;
1644 /*******************************************************************************
1645 * StdFont ClassFactory
1649 /* IUnknown fields */
1650 ICOM_VFIELD(IClassFactory);
1652 } IClassFactoryImpl;
1654 static HRESULT WINAPI
1655 SFCF_QueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj) {
1656 ICOM_THIS(IClassFactoryImpl,iface);
1658 FIXME("(%p)->(%s,%p),stub!\n",This,debugstr_guid(riid),ppobj);
1659 return E_NOINTERFACE;
1663 SFCF_AddRef(LPCLASSFACTORY iface) {
1664 ICOM_THIS(IClassFactoryImpl,iface);
1665 return ++(This->ref);
1668 static ULONG WINAPI SFCF_Release(LPCLASSFACTORY iface) {
1669 ICOM_THIS(IClassFactoryImpl,iface);
1670 /* static class, won't be freed */
1671 return --(This->ref);
1674 static HRESULT WINAPI SFCF_CreateInstance(
1675 LPCLASSFACTORY iface,LPUNKNOWN pOuter,REFIID riid,LPVOID *ppobj
1679 WCHAR fname[] = { 'S','y','s','t','e','m',0 };
1681 fd.cbSizeofstruct = sizeof(fd);
1682 fd.lpstrName = fname;
1683 fd.cySize.s.Lo = 80000;
1689 fd.fStrikethrough = 0;
1690 return OleCreateFontIndirect(&fd,riid,ppobj);
1694 static HRESULT WINAPI SFCF_LockServer(LPCLASSFACTORY iface,BOOL dolock) {
1695 ICOM_THIS(IClassFactoryImpl,iface);
1696 FIXME("(%p)->(%d),stub!\n",This,dolock);
1700 static ICOM_VTABLE(IClassFactory) SFCF_Vtbl = {
1701 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
1702 SFCF_QueryInterface,
1705 SFCF_CreateInstance,
1708 static IClassFactoryImpl STDFONT_CF = {&SFCF_Vtbl, 1 };
1710 void _get_STDFONT_CF(LPVOID *ppv) { *ppv = (LPVOID)&STDFONT_CF; }