Compile the oleaut32 dll with -DSTRICT.
[wine/multimedia.git] / dlls / oleaut32 / olefont.c
blobcb9180ba110a901ae1229fbb83086f372c826f20
1 /*
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
23 #include <assert.h>
24 #include <string.h>
25 #include "winerror.h"
26 #include "winbase.h"
27 #include "wingdi.h"
28 #include "winuser.h"
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"
34 #include "ole2.h"
35 #include "olectl.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;
53 struct 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.
68 ULONG ref;
71 * This structure contains the description of the class.
73 FONTDESC description;
76 * Contain the font associated with this object.
78 HFONT gdiFont;
81 * Font lock count.
83 DWORD fontLock;
86 * Size ratio
88 long cyLogical;
89 long cyHimetric;
91 IConnectionPoint *pCP;
95 * Here, I define utility macros to help with the casting of the
96 * "this" parameter.
97 * There is a version to accomodate all of the VTables implemented
98 * by this object.
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
108 * interface
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
142 * interface
144 static HRESULT WINAPI OLEFontImpl_IDispatch_QueryInterface(IDispatch* iface,
145 REFIID riid,
146 VOID** ppvoid);
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,
152 UINT iTInfo,
153 LCID lcid,
154 ITypeInfo** ppTInfo);
155 static HRESULT WINAPI OLEFontImpl_GetIDsOfNames(IDispatch* iface,
156 REFIID riid,
157 LPOLESTR* rgszNames,
158 UINT cNames,
159 LCID lcid,
160 DISPID* rgDispId);
161 static HRESULT WINAPI OLEFontImpl_Invoke(IDispatch* iface,
162 DISPID dispIdMember,
163 REFIID riid,
164 LCID lcid,
165 WORD wFlags,
166 DISPPARAMS* pDispParams,
167 VARIANT* pVarResult,
168 EXCEPINFO* pExepInfo,
169 UINT* puArgErr);
171 /***********************************************************************
172 * Prototypes for the implementation functions for the IPersistStream
173 * interface
175 static HRESULT WINAPI OLEFontImpl_IPersistStream_QueryInterface(IPersistStream* iface,
176 REFIID riid,
177 VOID** ppvoid);
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,
181 CLSID* pClassID);
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,
186 IStream* pOutStream,
187 BOOL fClearDirty);
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,
197 REFIID riid,
198 VOID** ppvoid);
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,
208 REFIID riid,
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,
218 OLEFontImpl_AddRef,
219 OLEFontImpl_Release,
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,
237 OLEFontImpl_Clone,
238 OLEFontImpl_IsEqual,
239 OLEFontImpl_SetRatio,
240 OLEFontImpl_QueryTextMetrics,
241 OLEFontImpl_AddRefHfont,
242 OLEFontImpl_ReleaseHfont,
243 OLEFontImpl_SetHdc
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,
255 OLEFontImpl_Invoke
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,
265 OLEFontImpl_IsDirty,
266 OLEFontImpl_Load,
267 OLEFontImpl_Save,
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,
287 REFIID riid,
288 LPVOID* ppvObj)
290 OLEFontImpl* newFont = 0;
291 HRESULT hr = S_OK;
293 TRACE("(%p, %s, %p)\n", lpFontDesc, debugstr_guid(riid), ppvObj);
295 * Sanity check
297 if (ppvObj==0)
298 return E_POINTER;
300 *ppvObj = 0;
302 if (lpFontDesc == 0)
303 return NO_ERROR; /* MSDN Oct 2001 */
306 * Try to construct a new instance of the class.
308 newFont = OLEFontImpl_Construct(lpFontDesc);
310 if (newFont == 0)
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);
324 return hr;
328 /***********************************************************************
329 * Implementation of the OLEFontImpl class.
332 /***********************************************************************
333 * OLEFont_SendNotify (internal)
335 * Sends notification messages of changed properties to any interested
336 * connections.
338 static void OLEFont_SendNotify(OLEFontImpl* this, DISPID dispID)
340 IEnumConnections *pEnum;
341 CONNECTDATA CD;
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);
354 return;
357 /************************************************************************
358 * OLEFontImpl_Construct
360 * This method will construct a new instance of the OLEFontImpl
361 * class.
363 * The caller of this method must release the object when it's
364 * done with it.
366 static OLEFontImpl* OLEFontImpl_Construct(LPFONTDESC fontDesc)
368 OLEFontImpl* newObject = 0;
371 * Allocate space for the object.
373 newObject = HeapAlloc(GetProcessHeap(), 0, sizeof(OLEFontImpl));
375 if (newObject==0)
376 return newObject;
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.
390 newObject->ref = 1;
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);
420 return 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
428 * this object.
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(
449 IFont* iface,
450 REFIID riid,
451 void** ppvObject)
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) )
460 return E_INVALIDARG;
463 * Initialize the return parameter.
465 *ppvObject = 0;
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.
499 if ((*ppvObject)==0)
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
507 * successful
509 OLEFontImpl_AddRef((IFont*)this);
511 return S_OK;
514 /************************************************************************
515 * OLEFontImpl_AddRef (IUnknown)
517 * See Windows documentation for more details on IUnknown methods.
519 ULONG WINAPI OLEFontImpl_AddRef(
520 IFont* iface)
522 _ICOM_THIS(OLEFontImpl, iface);
523 TRACE("(%p)->(ref=%ld)\n", this, this->ref);
524 this->ref++;
526 return this->ref;
529 /************************************************************************
530 * OLEFontImpl_Release (IUnknown)
532 * See Windows documentation for more details on IUnknown methods.
534 ULONG WINAPI OLEFontImpl_Release(
535 IFont* iface)
537 _ICOM_THIS(OLEFontImpl, iface);
538 TRACE("(%p)->(ref=%ld)\n", this, this->ref);
541 * Decrease the reference count on this object.
543 this->ref--;
546 * If the reference count goes down to 0, perform suicide.
548 if (this->ref==0)
550 OLEFontImpl_Destroy(this);
552 return 0;
555 return this->ref;
558 /************************************************************************
559 * OLEFontImpl_get_Name (IFont)
561 * See Windows documentation for more details on IFont methods.
563 static HRESULT WINAPI OLEFontImpl_get_Name(
564 IFont* iface,
565 BSTR* pname)
567 _ICOM_THIS(OLEFontImpl, iface);
568 TRACE("(%p)->(%p)\n", this, pname);
570 * Sanity check.
572 if (pname==0)
573 return E_POINTER;
575 if (this->description.lpstrName!=0)
576 *pname = SysAllocString(this->description.lpstrName);
577 else
578 *pname = 0;
580 return S_OK;
583 /************************************************************************
584 * OLEFontImpl_put_Name (IFont)
586 * See Windows documentation for more details on IFont methods.
588 static HRESULT WINAPI OLEFontImpl_put_Name(
589 IFont* iface,
590 BSTR 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));
601 else
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);
615 return S_OK;
618 /************************************************************************
619 * OLEFontImpl_get_Size (IFont)
621 * See Windows documentation for more details on IFont methods.
623 static HRESULT WINAPI OLEFontImpl_get_Size(
624 IFont* iface,
625 CY* psize)
627 _ICOM_THIS(OLEFontImpl, iface);
628 TRACE("(%p)->(%p)\n", this, psize);
631 * Sanity check
633 if (psize==0)
634 return E_POINTER;
636 psize->s.Hi = 0;
637 psize->s.Lo = this->description.cySize.s.Lo;
639 return S_OK;
642 /************************************************************************
643 * OLEFontImpl_put_Size (IFont)
645 * See Windows documentation for more details on IFont methods.
647 static HRESULT WINAPI OLEFontImpl_put_Size(
648 IFont* iface,
649 CY 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);
657 return S_OK;
660 /************************************************************************
661 * OLEFontImpl_get_Bold (IFont)
663 * See Windows documentation for more details on IFont methods.
665 static HRESULT WINAPI OLEFontImpl_get_Bold(
666 IFont* iface,
667 BOOL* pbold)
669 _ICOM_THIS(OLEFontImpl, iface);
670 TRACE("(%p)->(%p)\n", this, pbold);
672 * Sanity check
674 if (pbold==0)
675 return E_POINTER;
677 *pbold = this->description.sWeight > 550;
679 return S_OK;
682 /************************************************************************
683 * OLEFontImpl_put_Bold (IFont)
685 * See Windows documentation for more details on IFont methods.
687 static HRESULT WINAPI OLEFontImpl_put_Bold(
688 IFont* iface,
689 BOOL 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);
696 return S_OK;
699 /************************************************************************
700 * OLEFontImpl_get_Italic (IFont)
702 * See Windows documentation for more details on IFont methods.
704 static HRESULT WINAPI OLEFontImpl_get_Italic(
705 IFont* iface,
706 BOOL* pitalic)
708 _ICOM_THIS(OLEFontImpl, iface);
709 TRACE("(%p)->(%p)\n", this, pitalic);
711 * Sanity check
713 if (pitalic==0)
714 return E_POINTER;
716 *pitalic = this->description.fItalic;
718 return S_OK;
721 /************************************************************************
722 * OLEFontImpl_put_Italic (IFont)
724 * See Windows documentation for more details on IFont methods.
726 static HRESULT WINAPI OLEFontImpl_put_Italic(
727 IFont* iface,
728 BOOL 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);
736 return S_OK;
739 /************************************************************************
740 * OLEFontImpl_get_Underline (IFont)
742 * See Windows documentation for more details on IFont methods.
744 static HRESULT WINAPI OLEFontImpl_get_Underline(
745 IFont* iface,
746 BOOL* punderline)
748 _ICOM_THIS(OLEFontImpl, iface);
749 TRACE("(%p)->(%p)\n", this, punderline);
752 * Sanity check
754 if (punderline==0)
755 return E_POINTER;
757 *punderline = this->description.fUnderline;
759 return S_OK;
762 /************************************************************************
763 * OLEFontImpl_put_Underline (IFont)
765 * See Windows documentation for more details on IFont methods.
767 static HRESULT WINAPI OLEFontImpl_put_Underline(
768 IFont* iface,
769 BOOL 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);
777 return S_OK;
780 /************************************************************************
781 * OLEFontImpl_get_Strikethrough (IFont)
783 * See Windows documentation for more details on IFont methods.
785 static HRESULT WINAPI OLEFontImpl_get_Strikethrough(
786 IFont* iface,
787 BOOL* pstrikethrough)
789 _ICOM_THIS(OLEFontImpl, iface);
790 TRACE("(%p)->(%p)\n", this, pstrikethrough);
793 * Sanity check
795 if (pstrikethrough==0)
796 return E_POINTER;
798 *pstrikethrough = this->description.fStrikethrough;
800 return S_OK;
803 /************************************************************************
804 * OLEFontImpl_put_Strikethrough (IFont)
806 * See Windows documentation for more details on IFont methods.
808 static HRESULT WINAPI OLEFontImpl_put_Strikethrough(
809 IFont* iface,
810 BOOL 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);
818 return S_OK;
821 /************************************************************************
822 * OLEFontImpl_get_Weight (IFont)
824 * See Windows documentation for more details on IFont methods.
826 static HRESULT WINAPI OLEFontImpl_get_Weight(
827 IFont* iface,
828 short* pweight)
830 _ICOM_THIS(OLEFontImpl, iface);
831 TRACE("(%p)->(%p)\n", this, pweight);
834 * Sanity check
836 if (pweight==0)
837 return E_POINTER;
839 *pweight = this->description.sWeight;
841 return S_OK;
844 /************************************************************************
845 * OLEFontImpl_put_Weight (IFont)
847 * See Windows documentation for more details on IFont methods.
849 static HRESULT WINAPI OLEFontImpl_put_Weight(
850 IFont* iface,
851 short 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);
859 return S_OK;
862 /************************************************************************
863 * OLEFontImpl_get_Charset (IFont)
865 * See Windows documentation for more details on IFont methods.
867 static HRESULT WINAPI OLEFontImpl_get_Charset(
868 IFont* iface,
869 short* pcharset)
871 _ICOM_THIS(OLEFontImpl, iface);
872 TRACE("(%p)->(%p)\n", this, pcharset);
875 * Sanity check
877 if (pcharset==0)
878 return E_POINTER;
880 *pcharset = this->description.sCharset;
882 return S_OK;
885 /************************************************************************
886 * OLEFontImpl_put_Charset (IFont)
888 * See Windows documentation for more details on IFont methods.
890 static HRESULT WINAPI OLEFontImpl_put_Charset(
891 IFont* iface,
892 short 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);
900 return S_OK;
903 /************************************************************************
904 * OLEFontImpl_get_hFont (IFont)
906 * See Windows documentation for more details on IFont methods.
908 static HRESULT WINAPI OLEFontImpl_get_hFont(
909 IFont* iface,
910 HFONT* phfont)
912 _ICOM_THIS(OLEFontImpl, iface);
913 TRACE("(%p)->(%p)\n", this, phfont);
914 if (phfont==NULL)
915 return E_POINTER;
918 * Realize the font if necessary
920 if (this->gdiFont==0)
922 LOGFONTW logFont;
923 INT fontHeight;
924 CY cySize;
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 %p\n", *phfont);
957 return S_OK;
960 /************************************************************************
961 * OLEFontImpl_Clone (IFont)
963 * See Windows documentation for more details on IFont methods.
965 static HRESULT WINAPI OLEFontImpl_Clone(
966 IFont* iface,
967 IFont** ppfont)
969 OLEFontImpl* newObject = 0;
970 LOGFONTW logFont;
971 INT fontHeight;
972 CY cySize;
973 _ICOM_THIS(OLEFontImpl, iface);
974 TRACE("(%p)->(%p)\n", this, ppfont);
976 if (ppfont == NULL)
977 return E_POINTER;
979 *ppfont = NULL;
982 * Allocate space for the object.
984 newObject = HeapAlloc(GetProcessHeap(), 0, sizeof(OLEFontImpl));
986 if (newObject==NULL)
987 return E_OUTOFMEMORY;
989 *newObject = *this;
991 /* We need to alloc new memory for the string, otherwise
992 * we free memory twice.
994 newObject->description.lpstrName = HeapAlloc(
995 GetProcessHeap(),0,
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 */
1024 newObject->ref = 1;
1026 *ppfont = (IFont*)newObject;
1028 return S_OK;
1031 /************************************************************************
1032 * OLEFontImpl_IsEqual (IFont)
1034 * See Windows documentation for more details on IFont methods.
1036 static HRESULT WINAPI OLEFontImpl_IsEqual(
1037 IFont* iface,
1038 IFont* pFontOther)
1040 FIXME("():Stub\n");
1041 return E_NOTIMPL;
1044 /************************************************************************
1045 * OLEFontImpl_SetRatio (IFont)
1047 * See Windows documentation for more details on IFont methods.
1049 static HRESULT WINAPI OLEFontImpl_SetRatio(
1050 IFont* iface,
1051 long cyLogical,
1052 long cyHimetric)
1054 _ICOM_THIS(OLEFontImpl, iface);
1055 TRACE("(%p)->(%ld, %ld)\n", this, cyLogical, cyHimetric);
1057 this->cyLogical = cyLogical;
1058 this->cyHimetric = cyHimetric;
1060 return S_OK;
1063 /************************************************************************
1064 * OLEFontImpl_QueryTextMetrics (IFont)
1066 * See Windows documentation for more details on IFont methods.
1068 static HRESULT WINAPI OLEFontImpl_QueryTextMetrics(
1069 IFont* iface,
1070 TEXTMETRICOLE* ptm)
1072 FIXME("():Stub\n");
1073 return E_NOTIMPL;
1076 /************************************************************************
1077 * OLEFontImpl_AddRefHfont (IFont)
1079 * See Windows documentation for more details on IFont methods.
1081 static HRESULT WINAPI OLEFontImpl_AddRefHfont(
1082 IFont* iface,
1083 HFONT hfont)
1085 _ICOM_THIS(OLEFontImpl, iface);
1086 TRACE("(%p)->(%p) (lock=%ld)\n", this, hfont, this->fontLock);
1088 if ( (hfont == 0) ||
1089 (hfont != this->gdiFont) )
1090 return E_INVALIDARG;
1092 this->fontLock++;
1094 return S_OK;
1097 /************************************************************************
1098 * OLEFontImpl_ReleaseHfont (IFont)
1100 * See Windows documentation for more details on IFont methods.
1102 static HRESULT WINAPI OLEFontImpl_ReleaseHfont(
1103 IFont* iface,
1104 HFONT hfont)
1106 _ICOM_THIS(OLEFontImpl, iface);
1107 TRACE("(%p)->(%p) (lock=%ld)\n", this, hfont, this->fontLock);
1109 if ( (hfont == 0) ||
1110 (hfont != this->gdiFont) )
1111 return E_INVALIDARG;
1113 this->fontLock--;
1116 * If we just released our last font reference, destroy it.
1118 if (this->fontLock==0)
1120 DeleteObject(this->gdiFont);
1121 this->gdiFont = 0;
1124 return S_OK;
1127 /************************************************************************
1128 * OLEFontImpl_SetHdc (IFont)
1130 * See Windows documentation for more details on IFont methods.
1132 static HRESULT WINAPI OLEFontImpl_SetHdc(
1133 IFont* iface,
1134 HDC hdc)
1136 _ICOM_THIS(OLEFontImpl, iface);
1137 FIXME("(%p)->(%p): Stub\n", this, hdc);
1138 return E_NOTIMPL;
1141 /************************************************************************
1142 * OLEFontImpl_IDispatch_QueryInterface (IUnknown)
1144 * See Windows documentation for more details on IUnknown methods.
1146 static HRESULT WINAPI OLEFontImpl_IDispatch_QueryInterface(
1147 IDispatch* iface,
1148 REFIID riid,
1149 VOID** ppvoid)
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(
1162 IDispatch* iface)
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(
1175 IDispatch* iface)
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(
1188 IDispatch* iface,
1189 unsigned int* pctinfo)
1191 _ICOM_THIS_From_IDispatch(IFont, iface);
1192 FIXME("(%p)->(%p): Stub\n", this, pctinfo);
1194 return E_NOTIMPL;
1197 /************************************************************************
1198 * OLEFontImpl_GetTypeInfo (IDispatch)
1200 * See Windows documentation for more details on IDispatch methods.
1202 static HRESULT WINAPI OLEFontImpl_GetTypeInfo(
1203 IDispatch* iface,
1204 UINT iTInfo,
1205 LCID lcid,
1206 ITypeInfo** ppTInfo)
1208 _ICOM_THIS_From_IDispatch(IFont, iface);
1209 FIXME("(%p):Stub\n", this);
1211 return E_NOTIMPL;
1214 /************************************************************************
1215 * OLEFontImpl_GetIDsOfNames (IDispatch)
1217 * See Windows documentation for more details on IDispatch methods.
1219 static HRESULT WINAPI OLEFontImpl_GetIDsOfNames(
1220 IDispatch* iface,
1221 REFIID riid,
1222 LPOLESTR* rgszNames,
1223 UINT cNames,
1224 LCID lcid,
1225 DISPID* rgDispId)
1227 _ICOM_THIS_From_IDispatch(IFont, iface);
1228 FIXME("(%p):Stub\n", this);
1230 return E_NOTIMPL;
1233 /************************************************************************
1234 * OLEFontImpl_Invoke (IDispatch)
1236 * See Windows documentation for more details on IDispatch methods.
1238 static HRESULT WINAPI OLEFontImpl_Invoke(
1239 IDispatch* iface,
1240 DISPID dispIdMember,
1241 REFIID riid,
1242 LCID lcid,
1243 WORD wFlags,
1244 DISPPARAMS* pDispParams,
1245 VARIANT* pVarResult,
1246 EXCEPINFO* pExepInfo,
1247 UINT* puArgErr)
1249 _ICOM_THIS_From_IDispatch(IFont, iface);
1250 FIXME("%p->(%ld,%s,%lx,%x), stub!\n", this,dispIdMember,debugstr_guid(riid),lcid,
1251 wFlags
1253 return S_OK;
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,
1263 REFIID riid,
1264 VOID** ppvoid)
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,
1304 CLSID* pClassID)
1306 if (pClassID==0)
1307 return E_POINTER;
1309 memcpy(pClassID, &CLSID_StdFont, sizeof(CLSID_StdFont));
1311 return S_OK;
1314 /************************************************************************
1315 * OLEFontImpl_IsDirty (IPersistStream)
1317 * See Windows documentation for more details on IPersistStream methods.
1319 static HRESULT WINAPI OLEFontImpl_IsDirty(
1320 IPersistStream* iface)
1322 return S_OK;
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
1331 * know
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:
1337 * 00000010 - Italic
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
1342 * structure/
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];
1351 ULONG cbRead;
1352 BYTE bVersion;
1353 BYTE bAttributes;
1354 BYTE bStringSize;
1355 INT len;
1357 _ICOM_THIS_From_IPersistStream(OLEFontImpl, iface);
1360 * Read the version byte
1362 IStream_Read(pLoadStream, &bVersion, 1, &cbRead);
1364 if ( (cbRead!=1) ||
1365 (bVersion!=0x01) )
1366 return E_FAIL;
1369 * Charset
1371 IStream_Read(pLoadStream, &this->description.sCharset, 2, &cbRead);
1373 if (cbRead!=2)
1374 return E_FAIL;
1377 * Attributes
1379 IStream_Read(pLoadStream, &bAttributes, 1, &cbRead);
1381 if (cbRead!=1)
1382 return E_FAIL;
1384 this->description.fItalic = (bAttributes & FONTPERSIST_ITALIC) != 0;
1385 this->description.fStrikethrough = (bAttributes & FONTPERSIST_STRIKETHROUGH) != 0;
1386 this->description.fUnderline = (bAttributes & FONTPERSIST_UNDERLINE) != 0;
1389 * Weight
1391 IStream_Read(pLoadStream, &this->description.sWeight, 2, &cbRead);
1393 if (cbRead!=2)
1394 return E_FAIL;
1397 * Size
1399 IStream_Read(pLoadStream, &this->description.cySize.s.Lo, 4, &cbRead);
1401 if (cbRead!=4)
1402 return E_FAIL;
1404 this->description.cySize.s.Hi = 0;
1407 * FontName
1409 IStream_Read(pLoadStream, &bStringSize, 1, &cbRead);
1411 if (cbRead!=1)
1412 return E_FAIL;
1414 IStream_Read(pLoadStream, readBuffer, bStringSize, &cbRead);
1416 if (cbRead!=bStringSize)
1417 return E_FAIL;
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);
1429 this->gdiFont = 0;
1431 return S_OK;
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,
1442 BOOL fClearDirty)
1444 char* writeBuffer = NULL;
1445 ULONG cbWritten;
1446 BYTE bVersion = 0x01;
1447 BYTE bAttributes;
1448 BYTE bStringSize;
1450 _ICOM_THIS_From_IPersistStream(OLEFontImpl, iface);
1453 * Read the version byte
1455 IStream_Write(pOutStream, &bVersion, 1, &cbWritten);
1457 if (cbWritten!=1)
1458 return E_FAIL;
1461 * Charset
1463 IStream_Write(pOutStream, &this->description.sCharset, 2, &cbWritten);
1465 if (cbWritten!=2)
1466 return E_FAIL;
1469 * Attributes
1471 bAttributes = 0;
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);
1484 if (cbWritten!=1)
1485 return E_FAIL;
1488 * Weight
1490 IStream_Write(pOutStream, &this->description.sWeight, 2, &cbWritten);
1492 if (cbWritten!=2)
1493 return E_FAIL;
1496 * Size
1498 IStream_Write(pOutStream, &this->description.cySize.s.Lo, 4, &cbWritten);
1500 if (cbWritten!=4)
1501 return E_FAIL;
1504 * FontName
1506 if (this->description.lpstrName!=0)
1507 bStringSize = WideCharToMultiByte( CP_ACP, 0, this->description.lpstrName,
1508 strlenW(this->description.lpstrName), NULL, 0, NULL, NULL );
1509 else
1510 bStringSize = 0;
1512 IStream_Write(pOutStream, &bStringSize, 1, &cbWritten);
1514 if (cbWritten!=1)
1515 return E_FAIL;
1517 if (bStringSize!=0)
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)
1528 return E_FAIL;
1531 return S_OK;
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);
1545 if (pcbSize==NULL)
1546 return E_POINTER;
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);
1561 return S_OK;
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,
1571 REFIID riid,
1572 VOID** ppvoid)
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
1609 * methods.
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);
1618 return E_NOTIMPL;
1621 /************************************************************************
1622 * OLEFontImpl_FindConnectionPoint (IConnectionPointContainer)
1624 * See Windows documentation for more details on IConnectionPointContainer
1625 * methods.
1627 static HRESULT WINAPI OLEFontImpl_FindConnectionPoint(
1628 IConnectionPointContainer* iface,
1629 REFIID riid,
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,
1637 (LPVOID)ppCp);
1638 } else {
1639 FIXME("Tried to find connection point on %s\n", debugstr_guid(riid));
1640 return E_NOINTERFACE;
1644 /*******************************************************************************
1645 * StdFont ClassFactory
1647 typedef struct
1649 /* IUnknown fields */
1650 ICOM_VFIELD(IClassFactory);
1651 DWORD ref;
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;
1662 static ULONG WINAPI
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
1677 FONTDESC fd;
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;
1684 fd.cySize.s.Hi = 0;
1685 fd.sWeight = 0;
1686 fd.sCharset = 0;
1687 fd.fItalic = 0;
1688 fd.fUnderline = 0;
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);
1697 return S_OK;
1700 static ICOM_VTABLE(IClassFactory) SFCF_Vtbl = {
1701 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
1702 SFCF_QueryInterface,
1703 SFCF_AddRef,
1704 SFCF_Release,
1705 SFCF_CreateInstance,
1706 SFCF_LockServer
1708 static IClassFactoryImpl STDFONT_CF = {&SFCF_Vtbl, 1 };
1710 void _get_STDFONT_CF(LPVOID *ppv) { *ppv = (LPVOID)&STDFONT_CF; }