d3drm: Implement partially IDirect3DRMMeshBuilderImpl_Load.
[wine/multimedia.git] / dlls / oleaut32 / olefont.c
blob2fc842cf9d18d230a5748a7cce68fe49ffa8df86
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
8 * Copyright 2006 (Google) Benjamin Arai
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #include <assert.h>
25 #include <stdarg.h>
26 #include <string.h>
28 #define COBJMACROS
29 #define NONAMELESSUNION
30 #define NONAMELESSSTRUCT
32 #include "winerror.h"
33 #include "windef.h"
34 #include "winbase.h"
35 #include "wingdi.h"
36 #include "winuser.h"
37 #include "wine/list.h"
38 #include "wine/unicode.h"
39 #include "objbase.h"
40 #include "oleauto.h" /* for SysAllocString(....) */
41 #include "ole2.h"
42 #include "olectl.h"
43 #include "wine/debug.h"
44 #include "connpt.h" /* for CreateConnectionPoint */
45 #include "oaidl.h"
47 WINE_DEFAULT_DEBUG_CHANNEL(ole);
49 /***********************************************************************
50 * Declaration of constants used when serializing the font object.
52 #define FONTPERSIST_ITALIC 0x02
53 #define FONTPERSIST_UNDERLINE 0x04
54 #define FONTPERSIST_STRIKETHROUGH 0x08
57 /***********************************************************************
58 * List of the HFONTs it has given out, with each one having a separate
59 * ref count.
61 typedef struct _HFONTItem
63 struct list entry;
65 /* Reference count for that instance of the class. */
66 LONG ref;
68 /* Contain the font associated with this object. */
69 HFONT gdiFont;
71 } HFONTItem, *PHFONTItem;
73 static struct list OLEFontImpl_hFontList = LIST_INIT(OLEFontImpl_hFontList);
75 /* Counts how many fonts contain at least one lock */
76 static LONG ifont_cnt = 0;
78 /***********************************************************************
79 * Critical section for OLEFontImpl_hFontList
81 static CRITICAL_SECTION OLEFontImpl_csHFONTLIST;
82 static CRITICAL_SECTION_DEBUG OLEFontImpl_csHFONTLIST_debug =
84 0, 0, &OLEFontImpl_csHFONTLIST,
85 { &OLEFontImpl_csHFONTLIST_debug.ProcessLocksList,
86 &OLEFontImpl_csHFONTLIST_debug.ProcessLocksList },
87 0, 0, { (DWORD_PTR)(__FILE__ ": OLEFontImpl_csHFONTLIST") }
89 static CRITICAL_SECTION OLEFontImpl_csHFONTLIST = { &OLEFontImpl_csHFONTLIST_debug, -1, 0, 0, 0, 0 };
91 static void HFONTItem_Delete(PHFONTItem item)
93 DeleteObject(item->gdiFont);
94 list_remove(&item->entry);
95 HeapFree(GetProcessHeap(), 0, item);
98 /***********************************************************************
99 * Declaration of the implementation class for the IFont interface
101 typedef struct OLEFontImpl OLEFontImpl;
103 struct OLEFontImpl
106 * This class supports many interfaces. IUnknown, IFont,
107 * IDispatch, IDispFont IPersistStream and IConnectionPointContainer.
108 * The first two are supported by the first vtable, the next two are
109 * supported by the second table and the last two have their own.
111 const IFontVtbl* lpVtbl;
112 const IDispatchVtbl* lpvtblIDispatch;
113 const IPersistStreamVtbl* lpvtblIPersistStream;
114 const IConnectionPointContainerVtbl* lpvtblIConnectionPointContainer;
115 const IPersistPropertyBagVtbl* lpvtblIPersistPropertyBag;
116 const IPersistStreamInitVtbl* lpvtblIPersistStreamInit;
118 * Reference count for that instance of the class.
120 LONG ref;
123 * This structure contains the description of the class.
125 FONTDESC description;
128 * Contain the font associated with this object.
130 HFONT gdiFont;
133 * Size ratio
135 LONG cyLogical;
136 LONG cyHimetric;
138 IConnectionPoint *pPropertyNotifyCP;
139 IConnectionPoint *pFontEventsCP;
143 * Here, I define utility macros to help with the casting of the
144 * "this" parameter.
145 * There is a version to accommodate all of the VTables implemented
146 * by this object.
149 static inline OLEFontImpl *impl_from_IDispatch( IDispatch *iface )
151 return (OLEFontImpl *)((char*)iface - FIELD_OFFSET(OLEFontImpl, lpvtblIDispatch));
154 static inline OLEFontImpl *impl_from_IPersistStream( IPersistStream *iface )
156 return (OLEFontImpl *)((char*)iface - FIELD_OFFSET(OLEFontImpl, lpvtblIPersistStream));
159 static inline OLEFontImpl *impl_from_IConnectionPointContainer( IConnectionPointContainer *iface )
161 return (OLEFontImpl *)((char*)iface - FIELD_OFFSET(OLEFontImpl, lpvtblIConnectionPointContainer));
164 static inline OLEFontImpl *impl_from_IPersistPropertyBag( IPersistPropertyBag *iface )
166 return (OLEFontImpl *)((char*)iface - FIELD_OFFSET(OLEFontImpl, lpvtblIPersistPropertyBag));
169 static inline OLEFontImpl *impl_from_IPersistStreamInit( IPersistStreamInit *iface )
171 return (OLEFontImpl *)((char*)iface - FIELD_OFFSET(OLEFontImpl, lpvtblIPersistStreamInit));
175 /***********************************************************************
176 * Prototypes for the implementation functions for the IFont
177 * interface
179 static OLEFontImpl* OLEFontImpl_Construct(const FONTDESC *fontDesc);
180 static void OLEFontImpl_Destroy(OLEFontImpl* fontDesc);
181 static ULONG WINAPI OLEFontImpl_AddRef(IFont* iface);
183 /******************************************************************************
184 * OleCreateFontIndirect [OLEAUT32.420]
186 HRESULT WINAPI OleCreateFontIndirect(
187 LPFONTDESC lpFontDesc,
188 REFIID riid,
189 LPVOID* ppvObj)
191 OLEFontImpl* newFont = 0;
192 HRESULT hr = S_OK;
194 TRACE("(%p, %s, %p)\n", lpFontDesc, debugstr_guid(riid), ppvObj);
196 * Sanity check
198 if (ppvObj==0)
199 return E_POINTER;
201 *ppvObj = 0;
203 if (!lpFontDesc) {
204 FONTDESC fd;
206 static WCHAR fname[] = { 'S','y','s','t','e','m',0 };
208 fd.cbSizeofstruct = sizeof(fd);
209 fd.lpstrName = fname;
210 fd.cySize.s.Lo = 80000;
211 fd.cySize.s.Hi = 0;
212 fd.sWeight = 0;
213 fd.sCharset = 0;
214 fd.fItalic = 0;
215 fd.fUnderline = 0;
216 fd.fStrikethrough = 0;
217 lpFontDesc = &fd;
221 * Try to construct a new instance of the class.
223 newFont = OLEFontImpl_Construct(lpFontDesc);
225 if (newFont == 0)
226 return E_OUTOFMEMORY;
229 * Make sure it supports the interface required by the caller.
231 hr = IFont_QueryInterface((IFont*)newFont, riid, ppvObj);
234 * Release the reference obtained in the constructor. If
235 * the QueryInterface was unsuccessful, it will free the class.
237 IFont_Release((IFont*)newFont);
239 return hr;
243 /***********************************************************************
244 * Implementation of the OLEFontImpl class.
247 /***********************************************************************
248 * OLEFont_SendNotify (internal)
250 * Sends notification messages of changed properties to any interested
251 * connections.
253 static void OLEFont_SendNotify(OLEFontImpl* this, DISPID dispID)
255 static const WCHAR wszName[] = {'N','a','m','e',0};
256 static const WCHAR wszSize[] = {'S','i','z','e',0};
257 static const WCHAR wszBold[] = {'B','o','l','d',0};
258 static const WCHAR wszItalic[] = {'I','t','a','l','i','c',0};
259 static const WCHAR wszUnder[] = {'U','n','d','e','r','l','i','n','e',0};
260 static const WCHAR wszStrike[] = {'S','t','r','i','k','e','t','h','r','o','u','g','h',0};
261 static const WCHAR wszWeight[] = {'W','e','i','g','h','t',0};
262 static const WCHAR wszCharset[] = {'C','h','a','r','s','s','e','t',0};
263 static const LPCWSTR dispid_mapping[] =
265 wszName,
266 NULL,
267 wszSize,
268 wszBold,
269 wszItalic,
270 wszUnder,
271 wszStrike,
272 wszWeight,
273 wszCharset
276 IEnumConnections *pEnum;
277 CONNECTDATA CD;
278 HRESULT hres;
280 this->gdiFont = 0;
281 hres = IConnectionPoint_EnumConnections(this->pPropertyNotifyCP, &pEnum);
282 if (SUCCEEDED(hres))
284 while(IEnumConnections_Next(pEnum, 1, &CD, NULL) == S_OK) {
285 IPropertyNotifySink *sink;
287 IUnknown_QueryInterface(CD.pUnk, &IID_IPropertyNotifySink, (LPVOID)&sink);
288 IPropertyNotifySink_OnChanged(sink, dispID);
289 IPropertyNotifySink_Release(sink);
290 IUnknown_Release(CD.pUnk);
292 IEnumConnections_Release(pEnum);
295 hres = IConnectionPoint_EnumConnections(this->pFontEventsCP, &pEnum);
296 if (SUCCEEDED(hres))
298 DISPPARAMS dispparams;
299 VARIANTARG vararg;
301 VariantInit(&vararg);
302 V_VT(&vararg) = VT_BSTR;
303 V_BSTR(&vararg) = SysAllocString(dispid_mapping[dispID]);
305 dispparams.cArgs = 1;
306 dispparams.cNamedArgs = 0;
307 dispparams.rgdispidNamedArgs = NULL;
308 dispparams.rgvarg = &vararg;
310 while(IEnumConnections_Next(pEnum, 1, &CD, NULL) == S_OK) {
311 IFontEventsDisp *disp;
313 IUnknown_QueryInterface(CD.pUnk, &IID_IFontEventsDisp, (LPVOID)&disp);
314 IDispatch_Invoke(disp, DISPID_FONT_CHANGED, &IID_NULL,
315 LOCALE_NEUTRAL, INVOKE_FUNC, &dispparams, NULL,
316 NULL, NULL);
318 IDispatch_Release(disp);
319 IUnknown_Release(CD.pUnk);
321 VariantClear(&vararg);
322 IEnumConnections_Release(pEnum);
326 /************************************************************************
327 * OLEFontImpl_QueryInterface (IUnknown)
329 * See Windows documentation for more details on IUnknown methods.
331 static HRESULT WINAPI OLEFontImpl_QueryInterface(
332 IFont* iface,
333 REFIID riid,
334 void** ppvObject)
336 OLEFontImpl *this = (OLEFontImpl *)iface;
337 TRACE("(%p)->(%s, %p)\n", this, debugstr_guid(riid), ppvObject);
340 * Perform a sanity check on the parameters.
342 if ( (this==0) || (ppvObject==0) )
343 return E_INVALIDARG;
346 * Initialize the return parameter.
348 *ppvObject = 0;
351 * Compare the riid with the interface IDs implemented by this object.
353 if (IsEqualGUID(&IID_IUnknown, riid))
354 *ppvObject = this;
355 if (IsEqualGUID(&IID_IFont, riid))
356 *ppvObject = this;
357 if (IsEqualGUID(&IID_IDispatch, riid))
358 *ppvObject = &this->lpvtblIDispatch;
359 if (IsEqualGUID(&IID_IFontDisp, riid))
360 *ppvObject = &this->lpvtblIDispatch;
361 if (IsEqualIID(&IID_IPersist, riid) || IsEqualGUID(&IID_IPersistStream, riid))
362 *ppvObject = &this->lpvtblIPersistStream;
363 if (IsEqualGUID(&IID_IConnectionPointContainer, riid))
364 *ppvObject = &this->lpvtblIConnectionPointContainer;
365 if (IsEqualGUID(&IID_IPersistPropertyBag, riid))
366 *ppvObject = &this->lpvtblIPersistPropertyBag;
367 if (IsEqualGUID(&IID_IPersistStreamInit, riid))
368 *ppvObject = &this->lpvtblIPersistStreamInit;
371 * Check that we obtained an interface.
373 if ((*ppvObject)==0)
375 FIXME("() : asking for unsupported interface %s\n",debugstr_guid(riid));
376 return E_NOINTERFACE;
378 OLEFontImpl_AddRef((IFont*)this);
379 return S_OK;
382 /************************************************************************
383 * OLEFontImpl_AddRef (IUnknown)
385 * See Windows documentation for more details on IUnknown methods.
387 static ULONG WINAPI OLEFontImpl_AddRef(
388 IFont* iface)
390 OLEFontImpl *this = (OLEFontImpl *)iface;
391 TRACE("(%p)->(ref=%d)\n", this, this->ref);
392 return InterlockedIncrement(&this->ref);
395 /************************************************************************
396 * OLEFontImpl_Release (IUnknown)
398 * See Windows documentation for more details on IUnknown methods.
400 static ULONG WINAPI OLEFontImpl_Release(
401 IFont* iface)
403 OLEFontImpl *this = (OLEFontImpl *)iface;
404 ULONG ret;
405 PHFONTItem ptr, next;
406 TRACE("(%p)->(ref=%d)\n", this, this->ref);
408 /* Decrease the reference count for current interface */
409 ret = InterlockedDecrement(&this->ref);
411 /* If the reference count goes down to 0, destroy. */
412 if (ret == 0)
414 ULONG fontlist_refs = InterlockedDecrement(&ifont_cnt);
415 /* Check if all HFONT list refs are zero */
416 if (fontlist_refs == 0)
418 EnterCriticalSection(&OLEFontImpl_csHFONTLIST);
419 LIST_FOR_EACH_ENTRY_SAFE(ptr, next, &OLEFontImpl_hFontList, HFONTItem, entry)
420 HFONTItem_Delete(ptr);
421 LeaveCriticalSection(&OLEFontImpl_csHFONTLIST);
423 OLEFontImpl_Destroy(this);
426 return ret;
429 /************************************************************************
430 * OLEFontImpl_get_Name (IFont)
432 * See Windows documentation for more details on IFont methods.
434 static HRESULT WINAPI OLEFontImpl_get_Name(
435 IFont* iface,
436 BSTR* pname)
438 OLEFontImpl *this = (OLEFontImpl *)iface;
439 TRACE("(%p)->(%p)\n", this, pname);
441 * Sanity check.
443 if (pname==0)
444 return E_POINTER;
446 if (this->description.lpstrName!=0)
447 *pname = SysAllocString(this->description.lpstrName);
448 else
449 *pname = 0;
451 return S_OK;
454 /************************************************************************
455 * OLEFontImpl_put_Name (IFont)
457 * See Windows documentation for more details on IFont methods.
459 static HRESULT WINAPI OLEFontImpl_put_Name(
460 IFont* iface,
461 BSTR name)
463 OLEFontImpl *this = (OLEFontImpl *)iface;
464 TRACE("(%p)->(%p)\n", this, name);
466 if (!name)
467 return CTL_E_INVALIDPROPERTYVALUE;
469 if (this->description.lpstrName==0)
471 this->description.lpstrName = HeapAlloc(GetProcessHeap(),
473 (lstrlenW(name)+1) * sizeof(WCHAR));
475 else
477 this->description.lpstrName = HeapReAlloc(GetProcessHeap(),
479 this->description.lpstrName,
480 (lstrlenW(name)+1) * sizeof(WCHAR));
483 if (this->description.lpstrName==0)
484 return E_OUTOFMEMORY;
486 strcpyW(this->description.lpstrName, name);
487 TRACE("new name %s\n", debugstr_w(this->description.lpstrName));
488 OLEFont_SendNotify(this, DISPID_FONT_NAME);
489 return S_OK;
492 /************************************************************************
493 * OLEFontImpl_get_Size (IFont)
495 * See Windows documentation for more details on IFont methods.
497 static HRESULT WINAPI OLEFontImpl_get_Size(
498 IFont* iface,
499 CY* psize)
501 OLEFontImpl *this = (OLEFontImpl *)iface;
502 TRACE("(%p)->(%p)\n", this, psize);
505 * Sanity check
507 if (psize==0)
508 return E_POINTER;
510 psize->s.Hi = 0;
511 psize->s.Lo = this->description.cySize.s.Lo;
513 return S_OK;
516 /************************************************************************
517 * OLEFontImpl_put_Size (IFont)
519 * See Windows documentation for more details on IFont methods.
521 static HRESULT WINAPI OLEFontImpl_put_Size(
522 IFont* iface,
523 CY size)
525 OLEFontImpl *this = (OLEFontImpl *)iface;
526 TRACE("(%p)->(%d)\n", this, size.s.Lo);
527 this->description.cySize.s.Hi = 0;
528 this->description.cySize.s.Lo = size.s.Lo;
529 OLEFont_SendNotify(this, DISPID_FONT_SIZE);
531 return S_OK;
534 /************************************************************************
535 * OLEFontImpl_get_Bold (IFont)
537 * See Windows documentation for more details on IFont methods.
539 static HRESULT WINAPI OLEFontImpl_get_Bold(
540 IFont* iface,
541 BOOL* pbold)
543 OLEFontImpl *this = (OLEFontImpl *)iface;
544 TRACE("(%p)->(%p)\n", this, pbold);
546 * Sanity check
548 if (pbold==0)
549 return E_POINTER;
551 *pbold = this->description.sWeight > 550;
553 return S_OK;
556 /************************************************************************
557 * OLEFontImpl_put_Bold (IFont)
559 * See Windows documentation for more details on IFont methods.
561 static HRESULT WINAPI OLEFontImpl_put_Bold(
562 IFont* iface,
563 BOOL bold)
565 OLEFontImpl *this = (OLEFontImpl *)iface;
566 TRACE("(%p)->(%d)\n", this, bold);
567 this->description.sWeight = bold ? FW_BOLD : FW_NORMAL;
568 OLEFont_SendNotify(this, DISPID_FONT_BOLD);
570 return S_OK;
573 /************************************************************************
574 * OLEFontImpl_get_Italic (IFont)
576 * See Windows documentation for more details on IFont methods.
578 static HRESULT WINAPI OLEFontImpl_get_Italic(
579 IFont* iface,
580 BOOL* pitalic)
582 OLEFontImpl *this = (OLEFontImpl *)iface;
583 TRACE("(%p)->(%p)\n", this, pitalic);
585 * Sanity check
587 if (pitalic==0)
588 return E_POINTER;
590 *pitalic = this->description.fItalic;
592 return S_OK;
595 /************************************************************************
596 * OLEFontImpl_put_Italic (IFont)
598 * See Windows documentation for more details on IFont methods.
600 static HRESULT WINAPI OLEFontImpl_put_Italic(
601 IFont* iface,
602 BOOL italic)
604 OLEFontImpl *this = (OLEFontImpl *)iface;
605 TRACE("(%p)->(%d)\n", this, italic);
607 this->description.fItalic = italic;
609 OLEFont_SendNotify(this, DISPID_FONT_ITALIC);
610 return S_OK;
613 /************************************************************************
614 * OLEFontImpl_get_Underline (IFont)
616 * See Windows documentation for more details on IFont methods.
618 static HRESULT WINAPI OLEFontImpl_get_Underline(
619 IFont* iface,
620 BOOL* punderline)
622 OLEFontImpl *this = (OLEFontImpl *)iface;
623 TRACE("(%p)->(%p)\n", this, punderline);
626 * Sanity check
628 if (punderline==0)
629 return E_POINTER;
631 *punderline = this->description.fUnderline;
633 return S_OK;
636 /************************************************************************
637 * OLEFontImpl_put_Underline (IFont)
639 * See Windows documentation for more details on IFont methods.
641 static HRESULT WINAPI OLEFontImpl_put_Underline(
642 IFont* iface,
643 BOOL underline)
645 OLEFontImpl *this = (OLEFontImpl *)iface;
646 TRACE("(%p)->(%d)\n", this, underline);
648 this->description.fUnderline = underline;
650 OLEFont_SendNotify(this, DISPID_FONT_UNDER);
651 return S_OK;
654 /************************************************************************
655 * OLEFontImpl_get_Strikethrough (IFont)
657 * See Windows documentation for more details on IFont methods.
659 static HRESULT WINAPI OLEFontImpl_get_Strikethrough(
660 IFont* iface,
661 BOOL* pstrikethrough)
663 OLEFontImpl *this = (OLEFontImpl *)iface;
664 TRACE("(%p)->(%p)\n", this, pstrikethrough);
667 * Sanity check
669 if (pstrikethrough==0)
670 return E_POINTER;
672 *pstrikethrough = this->description.fStrikethrough;
674 return S_OK;
677 /************************************************************************
678 * OLEFontImpl_put_Strikethrough (IFont)
680 * See Windows documentation for more details on IFont methods.
682 static HRESULT WINAPI OLEFontImpl_put_Strikethrough(
683 IFont* iface,
684 BOOL strikethrough)
686 OLEFontImpl *this = (OLEFontImpl *)iface;
687 TRACE("(%p)->(%d)\n", this, strikethrough);
689 this->description.fStrikethrough = strikethrough;
690 OLEFont_SendNotify(this, DISPID_FONT_STRIKE);
692 return S_OK;
695 /************************************************************************
696 * OLEFontImpl_get_Weight (IFont)
698 * See Windows documentation for more details on IFont methods.
700 static HRESULT WINAPI OLEFontImpl_get_Weight(
701 IFont* iface,
702 short* pweight)
704 OLEFontImpl *this = (OLEFontImpl *)iface;
705 TRACE("(%p)->(%p)\n", this, pweight);
708 * Sanity check
710 if (pweight==0)
711 return E_POINTER;
713 *pweight = this->description.sWeight;
715 return S_OK;
718 /************************************************************************
719 * OLEFontImpl_put_Weight (IFont)
721 * See Windows documentation for more details on IFont methods.
723 static HRESULT WINAPI OLEFontImpl_put_Weight(
724 IFont* iface,
725 short weight)
727 OLEFontImpl *this = (OLEFontImpl *)iface;
728 TRACE("(%p)->(%d)\n", this, weight);
730 this->description.sWeight = weight;
732 OLEFont_SendNotify(this, DISPID_FONT_WEIGHT);
733 return S_OK;
736 /************************************************************************
737 * OLEFontImpl_get_Charset (IFont)
739 * See Windows documentation for more details on IFont methods.
741 static HRESULT WINAPI OLEFontImpl_get_Charset(
742 IFont* iface,
743 short* pcharset)
745 OLEFontImpl *this = (OLEFontImpl *)iface;
746 TRACE("(%p)->(%p)\n", this, pcharset);
749 * Sanity check
751 if (pcharset==0)
752 return E_POINTER;
754 *pcharset = this->description.sCharset;
756 return S_OK;
759 /************************************************************************
760 * OLEFontImpl_put_Charset (IFont)
762 * See Windows documentation for more details on IFont methods.
764 static HRESULT WINAPI OLEFontImpl_put_Charset(
765 IFont* iface,
766 short charset)
768 OLEFontImpl *this = (OLEFontImpl *)iface;
769 TRACE("(%p)->(%d)\n", this, charset);
771 this->description.sCharset = charset;
772 OLEFont_SendNotify(this, DISPID_FONT_CHARSET);
774 return S_OK;
777 /************************************************************************
778 * OLEFontImpl_get_hFont (IFont)
780 * See Windows documentation for more details on IFont methods.
782 static HRESULT WINAPI OLEFontImpl_get_hFont(
783 IFont* iface,
784 HFONT* phfont)
786 OLEFontImpl *this = (OLEFontImpl *)iface;
787 TRACE("(%p)->(%p)\n", this, phfont);
788 if (phfont==NULL)
789 return E_POINTER;
792 * Realize the font if necessary
794 if (this->gdiFont==0)
796 LOGFONTW logFont;
797 INT fontHeight;
798 CY cySize;
799 PHFONTItem newEntry;
802 * The height of the font returned by the get_Size property is the
803 * height of the font in points multiplied by 10000... Using some
804 * simple conversions and the ratio given by the application, it can
805 * be converted to a height in pixels.
807 IFont_get_Size(iface, &cySize);
809 /* Standard ratio is 72 / 2540, or 18 / 635 in lowest terms. */
810 /* Ratio is applied here relative to the standard. */
811 fontHeight = MulDiv( cySize.s.Lo, this->cyLogical*635, this->cyHimetric*18 );
813 memset(&logFont, 0, sizeof(LOGFONTW));
815 logFont.lfHeight = ((fontHeight%10000L)>5000L) ? (-fontHeight/10000L)-1 :
816 (-fontHeight/10000L);
817 logFont.lfItalic = this->description.fItalic;
818 logFont.lfUnderline = this->description.fUnderline;
819 logFont.lfStrikeOut = this->description.fStrikethrough;
820 logFont.lfWeight = this->description.sWeight;
821 logFont.lfCharSet = this->description.sCharset;
822 logFont.lfOutPrecision = OUT_CHARACTER_PRECIS;
823 logFont.lfClipPrecision = CLIP_DEFAULT_PRECIS;
824 logFont.lfQuality = DEFAULT_QUALITY;
825 logFont.lfPitchAndFamily = DEFAULT_PITCH;
826 strcpyW(logFont.lfFaceName,this->description.lpstrName);
828 this->gdiFont = CreateFontIndirectW(&logFont);
830 /* Add font to the cache */
831 newEntry = HeapAlloc(GetProcessHeap(), 0, sizeof(HFONTItem));
832 newEntry->ref = 1;
833 newEntry->gdiFont = this->gdiFont;
834 EnterCriticalSection(&OLEFontImpl_csHFONTLIST);
835 list_add_tail(&OLEFontImpl_hFontList,&newEntry->entry);
836 LeaveCriticalSection(&OLEFontImpl_csHFONTLIST);
839 *phfont = this->gdiFont;
840 TRACE("Returning %p\n", *phfont);
841 return S_OK;
844 /************************************************************************
845 * OLEFontImpl_Clone (IFont)
847 * See Windows documentation for more details on IFont methods.
849 static HRESULT WINAPI OLEFontImpl_Clone(
850 IFont* iface,
851 IFont** ppfont)
853 OLEFontImpl* newObject = 0;
854 LOGFONTW logFont;
855 INT fontHeight;
856 CY cySize;
857 PHFONTItem newEntry;
859 OLEFontImpl *this = (OLEFontImpl *)iface;
860 TRACE("(%p)->(%p)\n", this, ppfont);
862 if (ppfont == NULL)
863 return E_POINTER;
865 *ppfont = NULL;
868 * Allocate space for the object.
870 newObject = HeapAlloc(GetProcessHeap(), 0, sizeof(OLEFontImpl));
872 if (newObject==NULL)
873 return E_OUTOFMEMORY;
875 *newObject = *this;
877 /* We need to alloc new memory for the string, otherwise
878 * we free memory twice.
880 newObject->description.lpstrName = HeapAlloc(
881 GetProcessHeap(),0,
882 (1+strlenW(this->description.lpstrName))*2
884 strcpyW(newObject->description.lpstrName, this->description.lpstrName);
885 /* We need to clone the HFONT too. This is just cut & paste from above */
886 IFont_get_Size(iface, &cySize);
888 fontHeight = MulDiv(cySize.s.Lo, this->cyLogical*635,this->cyHimetric*18);
890 memset(&logFont, 0, sizeof(LOGFONTW));
892 logFont.lfHeight = ((fontHeight%10000L)>5000L) ? (-fontHeight/10000L)-1 :
893 (-fontHeight/10000L);
894 logFont.lfItalic = this->description.fItalic;
895 logFont.lfUnderline = this->description.fUnderline;
896 logFont.lfStrikeOut = this->description.fStrikethrough;
897 logFont.lfWeight = this->description.sWeight;
898 logFont.lfCharSet = this->description.sCharset;
899 logFont.lfOutPrecision = OUT_CHARACTER_PRECIS;
900 logFont.lfClipPrecision = CLIP_DEFAULT_PRECIS;
901 logFont.lfQuality = DEFAULT_QUALITY;
902 logFont.lfPitchAndFamily = DEFAULT_PITCH;
903 strcpyW(logFont.lfFaceName,this->description.lpstrName);
905 newObject->gdiFont = CreateFontIndirectW(&logFont);
907 /* Add font to the cache */
908 InterlockedIncrement(&ifont_cnt);
909 newEntry = HeapAlloc(GetProcessHeap(), 0, sizeof(HFONTItem));
910 newEntry->ref = 1;
911 newEntry->gdiFont = newObject->gdiFont;
912 EnterCriticalSection(&OLEFontImpl_csHFONTLIST);
913 list_add_tail(&OLEFontImpl_hFontList,&newEntry->entry);
914 LeaveCriticalSection(&OLEFontImpl_csHFONTLIST);
916 /* create new connection points */
917 newObject->pPropertyNotifyCP = NULL;
918 newObject->pFontEventsCP = NULL;
919 CreateConnectionPoint((IUnknown*)newObject, &IID_IPropertyNotifySink, &newObject->pPropertyNotifyCP);
920 CreateConnectionPoint((IUnknown*)newObject, &IID_IFontEventsDisp, &newObject->pFontEventsCP);
922 if (!newObject->pPropertyNotifyCP || !newObject->pFontEventsCP)
924 OLEFontImpl_Destroy(newObject);
925 return E_OUTOFMEMORY;
928 /* The cloned object starts with a reference count of 1 */
929 newObject->ref = 1;
931 *ppfont = (IFont*)newObject;
933 return S_OK;
936 /************************************************************************
937 * OLEFontImpl_IsEqual (IFont)
939 * See Windows documentation for more details on IFont methods.
941 static HRESULT WINAPI OLEFontImpl_IsEqual(
942 IFont* iface,
943 IFont* pFontOther)
945 OLEFontImpl *left = (OLEFontImpl *)iface;
946 OLEFontImpl *right = (OLEFontImpl *)pFontOther;
947 INT ret;
948 INT left_len,right_len;
950 if((iface == NULL) || (pFontOther == NULL))
951 return E_POINTER;
952 else if (left->description.cySize.s.Lo != right->description.cySize.s.Lo)
953 return S_FALSE;
954 else if (left->description.cySize.s.Hi != right->description.cySize.s.Hi)
955 return S_FALSE;
956 else if (left->description.sWeight != right->description.sWeight)
957 return S_FALSE;
958 else if (left->description.sCharset != right->description.sCharset)
959 return S_FALSE;
960 else if (left->description.fItalic != right->description.fItalic)
961 return S_FALSE;
962 else if (left->description.fUnderline != right->description.fUnderline)
963 return S_FALSE;
964 else if (left->description.fStrikethrough != right->description.fStrikethrough)
965 return S_FALSE;
967 /* Check from string */
968 left_len = strlenW(left->description.lpstrName);
969 right_len = strlenW(right->description.lpstrName);
970 ret = CompareStringW(0,0,left->description.lpstrName, left_len,
971 right->description.lpstrName, right_len);
972 if (ret != CSTR_EQUAL)
973 return S_FALSE;
975 return S_OK;
978 /************************************************************************
979 * OLEFontImpl_SetRatio (IFont)
981 * See Windows documentation for more details on IFont methods.
983 static HRESULT WINAPI OLEFontImpl_SetRatio(
984 IFont* iface,
985 LONG cyLogical,
986 LONG cyHimetric)
988 OLEFontImpl *this = (OLEFontImpl *)iface;
989 TRACE("(%p)->(%d, %d)\n", this, cyLogical, cyHimetric);
991 this->cyLogical = cyLogical;
992 this->cyHimetric = cyHimetric;
994 return S_OK;
997 /************************************************************************
998 * OLEFontImpl_QueryTextMetrics (IFont)
1000 * See Windows documentation for more details on IFont methods.
1002 static HRESULT WINAPI OLEFontImpl_QueryTextMetrics(
1003 IFont* iface,
1004 TEXTMETRICOLE* ptm)
1006 HDC hdcRef;
1007 HFONT hOldFont, hNewFont;
1009 hdcRef = GetDC(0);
1010 OLEFontImpl_get_hFont(iface, &hNewFont);
1011 hOldFont = SelectObject(hdcRef, hNewFont);
1012 GetTextMetricsW(hdcRef, ptm);
1013 SelectObject(hdcRef, hOldFont);
1014 ReleaseDC(0, hdcRef);
1015 return S_OK;
1018 /************************************************************************
1019 * OLEFontImpl_AddRefHfont (IFont)
1021 * See Windows documentation for more details on IFont methods.
1023 static HRESULT WINAPI OLEFontImpl_AddRefHfont(
1024 IFont* iface,
1025 HFONT hfont)
1027 OLEFontImpl *this = (OLEFontImpl *)iface;
1028 PHFONTItem ptr, next;
1029 HRESULT hres = S_FALSE; /* assume not present */
1031 TRACE("(%p)->(%p)\n", this, hfont);
1033 if (!hfont)
1034 return E_INVALIDARG;
1036 /* Check of the hFont is already in the list */
1037 EnterCriticalSection(&OLEFontImpl_csHFONTLIST);
1038 LIST_FOR_EACH_ENTRY_SAFE(ptr, next, &OLEFontImpl_hFontList, HFONTItem, entry)
1040 if (ptr->gdiFont == hfont)
1042 ptr->ref++;
1043 hres = S_OK;
1044 break;
1047 LeaveCriticalSection(&OLEFontImpl_csHFONTLIST);
1049 return hres;
1052 /************************************************************************
1053 * OLEFontImpl_ReleaseHfont (IFont)
1055 * See Windows documentation for more details on IFont methods.
1057 static HRESULT WINAPI OLEFontImpl_ReleaseHfont(
1058 IFont* iface,
1059 HFONT hfont)
1061 OLEFontImpl *this = (OLEFontImpl *)iface;
1062 PHFONTItem ptr, next;
1063 HRESULT hres = S_FALSE; /* assume not present */
1065 TRACE("(%p)->(%p)\n", this, hfont);
1067 if (!hfont)
1068 return E_INVALIDARG;
1070 /* Check of the hFont is already in the list */
1071 EnterCriticalSection(&OLEFontImpl_csHFONTLIST);
1072 LIST_FOR_EACH_ENTRY_SAFE(ptr, next, &OLEFontImpl_hFontList, HFONTItem, entry)
1074 if ((ptr->gdiFont == hfont) && ptr->ref)
1076 /* Remove from cache and delete object if not referenced */
1077 if (!--ptr->ref)
1079 if (ptr->gdiFont == this->gdiFont)
1080 this->gdiFont = NULL;
1082 hres = S_OK;
1083 break;
1086 LeaveCriticalSection(&OLEFontImpl_csHFONTLIST);
1088 return hres;
1091 /************************************************************************
1092 * OLEFontImpl_SetHdc (IFont)
1094 * See Windows documentation for more details on IFont methods.
1096 static HRESULT WINAPI OLEFontImpl_SetHdc(
1097 IFont* iface,
1098 HDC hdc)
1100 OLEFontImpl *this = (OLEFontImpl *)iface;
1101 FIXME("(%p)->(%p): Stub\n", this, hdc);
1102 return E_NOTIMPL;
1106 * Virtual function tables for the OLEFontImpl class.
1108 static const IFontVtbl OLEFontImpl_VTable =
1110 OLEFontImpl_QueryInterface,
1111 OLEFontImpl_AddRef,
1112 OLEFontImpl_Release,
1113 OLEFontImpl_get_Name,
1114 OLEFontImpl_put_Name,
1115 OLEFontImpl_get_Size,
1116 OLEFontImpl_put_Size,
1117 OLEFontImpl_get_Bold,
1118 OLEFontImpl_put_Bold,
1119 OLEFontImpl_get_Italic,
1120 OLEFontImpl_put_Italic,
1121 OLEFontImpl_get_Underline,
1122 OLEFontImpl_put_Underline,
1123 OLEFontImpl_get_Strikethrough,
1124 OLEFontImpl_put_Strikethrough,
1125 OLEFontImpl_get_Weight,
1126 OLEFontImpl_put_Weight,
1127 OLEFontImpl_get_Charset,
1128 OLEFontImpl_put_Charset,
1129 OLEFontImpl_get_hFont,
1130 OLEFontImpl_Clone,
1131 OLEFontImpl_IsEqual,
1132 OLEFontImpl_SetRatio,
1133 OLEFontImpl_QueryTextMetrics,
1134 OLEFontImpl_AddRefHfont,
1135 OLEFontImpl_ReleaseHfont,
1136 OLEFontImpl_SetHdc
1139 /************************************************************************
1140 * OLEFontImpl_IDispatch_QueryInterface (IUnknown)
1142 * See Windows documentation for more details on IUnknown methods.
1144 static HRESULT WINAPI OLEFontImpl_IDispatch_QueryInterface(
1145 IDispatch* iface,
1146 REFIID riid,
1147 VOID** ppvoid)
1149 OLEFontImpl *this = impl_from_IDispatch(iface);
1151 return IFont_QueryInterface((IFont *)this, riid, ppvoid);
1154 /************************************************************************
1155 * OLEFontImpl_IDispatch_Release (IUnknown)
1157 * See Windows documentation for more details on IUnknown methods.
1159 static ULONG WINAPI OLEFontImpl_IDispatch_Release(
1160 IDispatch* iface)
1162 OLEFontImpl *this = impl_from_IDispatch(iface);
1164 return IFont_Release((IFont *)this);
1167 /************************************************************************
1168 * OLEFontImpl_IDispatch_AddRef (IUnknown)
1170 * See Windows documentation for more details on IUnknown methods.
1172 static ULONG WINAPI OLEFontImpl_IDispatch_AddRef(
1173 IDispatch* iface)
1175 OLEFontImpl *this = impl_from_IDispatch(iface);
1177 return IFont_AddRef((IFont *)this);
1180 /************************************************************************
1181 * OLEFontImpl_GetTypeInfoCount (IDispatch)
1183 * See Windows documentation for more details on IDispatch methods.
1185 static HRESULT WINAPI OLEFontImpl_GetTypeInfoCount(
1186 IDispatch* iface,
1187 unsigned int* pctinfo)
1189 OLEFontImpl *this = impl_from_IDispatch(iface);
1190 TRACE("(%p)->(%p)\n", this, pctinfo);
1191 *pctinfo = 1;
1193 return S_OK;
1196 /************************************************************************
1197 * OLEFontImpl_GetTypeInfo (IDispatch)
1199 * See Windows documentation for more details on IDispatch methods.
1201 static HRESULT WINAPI OLEFontImpl_GetTypeInfo(
1202 IDispatch* iface,
1203 UINT iTInfo,
1204 LCID lcid,
1205 ITypeInfo** ppTInfo)
1207 static const WCHAR stdole2tlb[] = {'s','t','d','o','l','e','2','.','t','l','b',0};
1208 ITypeLib *tl;
1209 HRESULT hres;
1211 OLEFontImpl *this = impl_from_IDispatch(iface);
1212 TRACE("(%p, iTInfo=%d, lcid=%04x, %p)\n", this, iTInfo, (int)lcid, ppTInfo);
1213 if (iTInfo != 0)
1214 return E_FAIL;
1215 hres = LoadTypeLib(stdole2tlb, &tl);
1216 if (FAILED(hres)) {
1217 ERR("Could not load the stdole2.tlb?\n");
1218 return hres;
1220 hres = ITypeLib_GetTypeInfoOfGuid(tl, &IID_IFontDisp, ppTInfo);
1221 ITypeLib_Release(tl);
1222 if (FAILED(hres)) {
1223 FIXME("Did not IDispatch typeinfo from typelib, hres %x\n",hres);
1225 return hres;
1228 /************************************************************************
1229 * OLEFontImpl_GetIDsOfNames (IDispatch)
1231 * See Windows documentation for more details on IDispatch methods.
1233 static HRESULT WINAPI OLEFontImpl_GetIDsOfNames(
1234 IDispatch* iface,
1235 REFIID riid,
1236 LPOLESTR* rgszNames,
1237 UINT cNames,
1238 LCID lcid,
1239 DISPID* rgDispId)
1241 ITypeInfo * pTInfo;
1242 HRESULT hres;
1244 OLEFontImpl *this = impl_from_IDispatch(iface);
1246 TRACE("(%p,%s,%p,cNames=%d,lcid=%04x,%p)\n", this, debugstr_guid(riid),
1247 rgszNames, cNames, (int)lcid, rgDispId);
1249 if (cNames == 0)
1251 return E_INVALIDARG;
1253 else
1255 /* retrieve type information */
1256 hres = OLEFontImpl_GetTypeInfo(iface, 0, lcid, &pTInfo);
1258 if (FAILED(hres))
1260 ERR("GetTypeInfo failed.\n");
1261 return hres;
1264 /* convert names to DISPIDs */
1265 hres = DispGetIDsOfNames (pTInfo, rgszNames, cNames, rgDispId);
1266 ITypeInfo_Release(pTInfo);
1268 return hres;
1272 /************************************************************************
1273 * OLEFontImpl_Invoke (IDispatch)
1275 * See Windows documentation for more details on IDispatch methods.
1277 * Note: Do not call _put_Xxx methods, since setting things here
1278 * should not call notify functions as I found out debugging the generic
1279 * MS VB5 installer.
1281 static HRESULT WINAPI OLEFontImpl_Invoke(
1282 IDispatch* iface,
1283 DISPID dispIdMember,
1284 REFIID riid,
1285 LCID lcid,
1286 WORD wFlags,
1287 DISPPARAMS* pDispParams,
1288 VARIANT* pVarResult,
1289 EXCEPINFO* pExepInfo,
1290 UINT* puArgErr)
1292 OLEFontImpl *this = impl_from_IDispatch(iface);
1293 HRESULT hr;
1295 TRACE("%p->(%d,%s,0x%x,0x%x,%p,%p,%p,%p)\n", this, dispIdMember,
1296 debugstr_guid(riid), lcid, wFlags, pDispParams, pVarResult, pExepInfo,
1297 puArgErr);
1299 /* validate parameters */
1301 if (!IsEqualIID(riid, &IID_NULL))
1303 ERR("riid was %s instead of IID_NULL\n", debugstr_guid(riid));
1304 return DISP_E_UNKNOWNINTERFACE;
1307 if (wFlags & DISPATCH_PROPERTYGET)
1309 if (!pVarResult)
1311 ERR("null pVarResult not allowed when DISPATCH_PROPERTYGET specified\n");
1312 return DISP_E_PARAMNOTOPTIONAL;
1315 else if (wFlags & DISPATCH_PROPERTYPUT)
1317 if (!pDispParams)
1319 ERR("null pDispParams not allowed when DISPATCH_PROPERTYPUT specified\n");
1320 return DISP_E_PARAMNOTOPTIONAL;
1322 if (pDispParams->cArgs != 1)
1324 ERR("param count for DISPATCH_PROPERTYPUT was %d instead of 1\n", pDispParams->cArgs);
1325 return DISP_E_BADPARAMCOUNT;
1328 else
1330 ERR("one of DISPATCH_PROPERTYGET or DISPATCH_PROPERTYPUT must be specified\n");
1331 return DISP_E_MEMBERNOTFOUND;
1334 switch (dispIdMember) {
1335 case DISPID_FONT_NAME:
1336 if (wFlags & DISPATCH_PROPERTYGET) {
1337 V_VT(pVarResult) = VT_BSTR;
1338 return IFont_get_Name((IFont *)this, &V_BSTR(pVarResult));
1339 } else {
1340 VARIANTARG vararg;
1342 VariantInit(&vararg);
1343 hr = VariantChangeTypeEx(&vararg, &pDispParams->rgvarg[0], lcid, 0, VT_BSTR);
1344 if (FAILED(hr))
1345 return hr;
1347 hr = IFont_put_Name((IFont *)this, V_BSTR(&vararg));
1349 VariantClear(&vararg);
1350 return hr;
1352 break;
1353 case DISPID_FONT_BOLD:
1354 if (wFlags & DISPATCH_PROPERTYGET) {
1355 BOOL value;
1356 hr = IFont_get_Bold((IFont *)this, &value);
1357 V_VT(pVarResult) = VT_BOOL;
1358 V_BOOL(pVarResult) = value ? VARIANT_TRUE : VARIANT_FALSE;
1359 return hr;
1360 } else {
1361 VARIANTARG vararg;
1363 VariantInit(&vararg);
1364 hr = VariantChangeTypeEx(&vararg, &pDispParams->rgvarg[0], lcid, 0, VT_BOOL);
1365 if (FAILED(hr))
1366 return hr;
1368 hr = IFont_put_Bold((IFont *)this, V_BOOL(&vararg));
1370 VariantClear(&vararg);
1371 return hr;
1373 break;
1374 case DISPID_FONT_ITALIC:
1375 if (wFlags & DISPATCH_PROPERTYGET) {
1376 BOOL value;
1377 hr = IFont_get_Italic((IFont *)this, &value);
1378 V_VT(pVarResult) = VT_BOOL;
1379 V_BOOL(pVarResult) = value ? VARIANT_TRUE : VARIANT_FALSE;
1380 return hr;
1381 } else {
1382 VARIANTARG vararg;
1384 VariantInit(&vararg);
1385 hr = VariantChangeTypeEx(&vararg, &pDispParams->rgvarg[0], lcid, 0, VT_BOOL);
1386 if (FAILED(hr))
1387 return hr;
1389 hr = IFont_put_Italic((IFont *)this, V_BOOL(&vararg));
1391 VariantClear(&vararg);
1392 return hr;
1394 break;
1395 case DISPID_FONT_UNDER:
1396 if (wFlags & DISPATCH_PROPERTYGET) {
1397 BOOL value;
1398 hr = IFont_get_Underline((IFont *)this, &value);
1399 V_VT(pVarResult) = VT_BOOL;
1400 V_BOOL(pVarResult) = value ? VARIANT_TRUE : VARIANT_FALSE;
1401 return hr;
1402 } else {
1403 VARIANTARG vararg;
1405 VariantInit(&vararg);
1406 hr = VariantChangeTypeEx(&vararg, &pDispParams->rgvarg[0], lcid, 0, VT_BOOL);
1407 if (FAILED(hr))
1408 return hr;
1410 hr = IFont_put_Underline((IFont *)this, V_BOOL(&vararg));
1412 VariantClear(&vararg);
1413 return hr;
1415 break;
1416 case DISPID_FONT_STRIKE:
1417 if (wFlags & DISPATCH_PROPERTYGET) {
1418 BOOL value;
1419 hr = IFont_get_Strikethrough((IFont *)this, &value);
1420 V_VT(pVarResult) = VT_BOOL;
1421 V_BOOL(pVarResult) = value ? VARIANT_TRUE : VARIANT_FALSE;
1422 return hr;
1423 } else {
1424 VARIANTARG vararg;
1426 VariantInit(&vararg);
1427 hr = VariantChangeTypeEx(&vararg, &pDispParams->rgvarg[0], lcid, 0, VT_BOOL);
1428 if (FAILED(hr))
1429 return hr;
1431 hr = IFont_put_Strikethrough((IFont *)this, V_BOOL(&vararg));
1433 VariantClear(&vararg);
1434 return hr;
1436 break;
1437 case DISPID_FONT_SIZE:
1438 if (wFlags & DISPATCH_PROPERTYGET) {
1439 V_VT(pVarResult) = VT_CY;
1440 return OLEFontImpl_get_Size((IFont *)this, &V_CY(pVarResult));
1441 } else {
1442 VARIANTARG vararg;
1444 VariantInit(&vararg);
1445 hr = VariantChangeTypeEx(&vararg, &pDispParams->rgvarg[0], lcid, 0, VT_CY);
1446 if (FAILED(hr))
1447 return hr;
1449 hr = IFont_put_Size((IFont *)this, V_CY(&vararg));
1451 VariantClear(&vararg);
1452 return hr;
1454 break;
1455 case DISPID_FONT_WEIGHT:
1456 if (wFlags & DISPATCH_PROPERTYGET) {
1457 V_VT(pVarResult) = VT_I2;
1458 return OLEFontImpl_get_Weight((IFont *)this, &V_I2(pVarResult));
1459 } else {
1460 VARIANTARG vararg;
1462 VariantInit(&vararg);
1463 hr = VariantChangeTypeEx(&vararg, &pDispParams->rgvarg[0], lcid, 0, VT_I2);
1464 if (FAILED(hr))
1465 return hr;
1467 hr = IFont_put_Weight((IFont *)this, V_I2(&vararg));
1469 VariantClear(&vararg);
1470 return hr;
1472 break;
1473 case DISPID_FONT_CHARSET:
1474 if (wFlags & DISPATCH_PROPERTYGET) {
1475 V_VT(pVarResult) = VT_I2;
1476 return OLEFontImpl_get_Charset((IFont *)this, &V_I2(pVarResult));
1477 } else {
1478 VARIANTARG vararg;
1480 VariantInit(&vararg);
1481 hr = VariantChangeTypeEx(&vararg, &pDispParams->rgvarg[0], lcid, 0, VT_I2);
1482 if (FAILED(hr))
1483 return hr;
1485 hr = IFont_put_Charset((IFont *)this, V_I2(&vararg));
1487 VariantClear(&vararg);
1488 return hr;
1490 break;
1491 default:
1492 ERR("member not found for dispid 0x%x\n", dispIdMember);
1493 return DISP_E_MEMBERNOTFOUND;
1497 static const IDispatchVtbl OLEFontImpl_IDispatch_VTable =
1499 OLEFontImpl_IDispatch_QueryInterface,
1500 OLEFontImpl_IDispatch_AddRef,
1501 OLEFontImpl_IDispatch_Release,
1502 OLEFontImpl_GetTypeInfoCount,
1503 OLEFontImpl_GetTypeInfo,
1504 OLEFontImpl_GetIDsOfNames,
1505 OLEFontImpl_Invoke
1508 /************************************************************************
1509 * OLEFontImpl_IPersistStream_QueryInterface (IUnknown)
1511 * See Windows documentation for more details on IUnknown methods.
1513 static HRESULT WINAPI OLEFontImpl_IPersistStream_QueryInterface(
1514 IPersistStream* iface,
1515 REFIID riid,
1516 VOID** ppvoid)
1518 OLEFontImpl *this = impl_from_IPersistStream(iface);
1520 return IFont_QueryInterface((IFont *)this, riid, ppvoid);
1523 /************************************************************************
1524 * OLEFontImpl_IPersistStream_Release (IUnknown)
1526 * See Windows documentation for more details on IUnknown methods.
1528 static ULONG WINAPI OLEFontImpl_IPersistStream_Release(
1529 IPersistStream* iface)
1531 OLEFontImpl *this = impl_from_IPersistStream(iface);
1533 return IFont_Release((IFont *)this);
1536 /************************************************************************
1537 * OLEFontImpl_IPersistStream_AddRef (IUnknown)
1539 * See Windows documentation for more details on IUnknown methods.
1541 static ULONG WINAPI OLEFontImpl_IPersistStream_AddRef(
1542 IPersistStream* iface)
1544 OLEFontImpl *this = impl_from_IPersistStream(iface);
1546 return IFont_AddRef((IFont *)this);
1549 /************************************************************************
1550 * OLEFontImpl_GetClassID (IPersistStream)
1552 * See Windows documentation for more details on IPersistStream methods.
1554 static HRESULT WINAPI OLEFontImpl_GetClassID(
1555 IPersistStream* iface,
1556 CLSID* pClassID)
1558 TRACE("(%p,%p)\n",iface,pClassID);
1559 if (pClassID==0)
1560 return E_POINTER;
1562 *pClassID = CLSID_StdFont;
1564 return S_OK;
1567 /************************************************************************
1568 * OLEFontImpl_IsDirty (IPersistStream)
1570 * See Windows documentation for more details on IPersistStream methods.
1572 static HRESULT WINAPI OLEFontImpl_IsDirty(
1573 IPersistStream* iface)
1575 TRACE("(%p)\n",iface);
1576 return S_OK;
1579 /************************************************************************
1580 * OLEFontImpl_Load (IPersistStream)
1582 * See Windows documentation for more details on IPersistStream methods.
1584 * This is the format of the standard font serialization as far as I
1585 * know
1587 * Offset Type Value Comment
1588 * 0x0000 Byte Unknown Probably a version number, contains 0x01
1589 * 0x0001 Short Charset Charset value from the FONTDESC structure
1590 * 0x0003 Byte Attributes Flags defined as follows:
1591 * 00000010 - Italic
1592 * 00000100 - Underline
1593 * 00001000 - Strikethrough
1594 * 0x0004 Short Weight Weight value from FONTDESC structure
1595 * 0x0006 DWORD size "Low" portion of the cySize member of the FONTDESC
1596 * structure/
1597 * 0x000A Byte name length Length of the font name string (no null character)
1598 * 0x000B String name Name of the font (ASCII, no nul character)
1600 static HRESULT WINAPI OLEFontImpl_Load(
1601 IPersistStream* iface,
1602 IStream* pLoadStream)
1604 char readBuffer[0x100];
1605 ULONG cbRead;
1606 BYTE bVersion;
1607 BYTE bAttributes;
1608 BYTE bStringSize;
1609 INT len;
1611 OLEFontImpl *this = impl_from_IPersistStream(iface);
1614 * Read the version byte
1616 IStream_Read(pLoadStream, &bVersion, 1, &cbRead);
1618 if ( (cbRead!=1) ||
1619 (bVersion!=0x01) )
1620 return E_FAIL;
1623 * Charset
1625 IStream_Read(pLoadStream, &this->description.sCharset, 2, &cbRead);
1627 if (cbRead!=2)
1628 return E_FAIL;
1631 * Attributes
1633 IStream_Read(pLoadStream, &bAttributes, 1, &cbRead);
1635 if (cbRead!=1)
1636 return E_FAIL;
1638 this->description.fItalic = (bAttributes & FONTPERSIST_ITALIC) != 0;
1639 this->description.fStrikethrough = (bAttributes & FONTPERSIST_STRIKETHROUGH) != 0;
1640 this->description.fUnderline = (bAttributes & FONTPERSIST_UNDERLINE) != 0;
1643 * Weight
1645 IStream_Read(pLoadStream, &this->description.sWeight, 2, &cbRead);
1647 if (cbRead!=2)
1648 return E_FAIL;
1651 * Size
1653 IStream_Read(pLoadStream, &this->description.cySize.s.Lo, 4, &cbRead);
1655 if (cbRead!=4)
1656 return E_FAIL;
1658 this->description.cySize.s.Hi = 0;
1661 * FontName
1663 IStream_Read(pLoadStream, &bStringSize, 1, &cbRead);
1665 if (cbRead!=1)
1666 return E_FAIL;
1668 IStream_Read(pLoadStream, readBuffer, bStringSize, &cbRead);
1670 if (cbRead!=bStringSize)
1671 return E_FAIL;
1673 HeapFree(GetProcessHeap(), 0, this->description.lpstrName);
1675 len = MultiByteToWideChar( CP_ACP, 0, readBuffer, bStringSize, NULL, 0 );
1676 this->description.lpstrName = HeapAlloc( GetProcessHeap(), 0, (len+1) * sizeof(WCHAR) );
1677 MultiByteToWideChar( CP_ACP, 0, readBuffer, bStringSize, this->description.lpstrName, len );
1678 this->description.lpstrName[len] = 0;
1680 /* Ensure use of this font causes a new one to be created @@@@ */
1681 DeleteObject(this->gdiFont);
1682 this->gdiFont = 0;
1684 return S_OK;
1687 /************************************************************************
1688 * OLEFontImpl_Save (IPersistStream)
1690 * See Windows documentation for more details on IPersistStream methods.
1692 static HRESULT WINAPI OLEFontImpl_Save(
1693 IPersistStream* iface,
1694 IStream* pOutStream,
1695 BOOL fClearDirty)
1697 char* writeBuffer = NULL;
1698 ULONG cbWritten;
1699 BYTE bVersion = 0x01;
1700 BYTE bAttributes;
1701 BYTE bStringSize;
1703 OLEFontImpl *this = impl_from_IPersistStream(iface);
1706 * Read the version byte
1708 IStream_Write(pOutStream, &bVersion, 1, &cbWritten);
1710 if (cbWritten!=1)
1711 return E_FAIL;
1714 * Charset
1716 IStream_Write(pOutStream, &this->description.sCharset, 2, &cbWritten);
1718 if (cbWritten!=2)
1719 return E_FAIL;
1722 * Attributes
1724 bAttributes = 0;
1726 if (this->description.fItalic)
1727 bAttributes |= FONTPERSIST_ITALIC;
1729 if (this->description.fStrikethrough)
1730 bAttributes |= FONTPERSIST_STRIKETHROUGH;
1732 if (this->description.fUnderline)
1733 bAttributes |= FONTPERSIST_UNDERLINE;
1735 IStream_Write(pOutStream, &bAttributes, 1, &cbWritten);
1737 if (cbWritten!=1)
1738 return E_FAIL;
1741 * Weight
1743 IStream_Write(pOutStream, &this->description.sWeight, 2, &cbWritten);
1745 if (cbWritten!=2)
1746 return E_FAIL;
1749 * Size
1751 IStream_Write(pOutStream, &this->description.cySize.s.Lo, 4, &cbWritten);
1753 if (cbWritten!=4)
1754 return E_FAIL;
1757 * FontName
1759 if (this->description.lpstrName!=0)
1760 bStringSize = WideCharToMultiByte( CP_ACP, 0, this->description.lpstrName,
1761 strlenW(this->description.lpstrName), NULL, 0, NULL, NULL );
1762 else
1763 bStringSize = 0;
1765 IStream_Write(pOutStream, &bStringSize, 1, &cbWritten);
1767 if (cbWritten!=1)
1768 return E_FAIL;
1770 if (bStringSize!=0)
1772 if (!(writeBuffer = HeapAlloc( GetProcessHeap(), 0, bStringSize ))) return E_OUTOFMEMORY;
1773 WideCharToMultiByte( CP_ACP, 0, this->description.lpstrName,
1774 strlenW(this->description.lpstrName),
1775 writeBuffer, bStringSize, NULL, NULL );
1777 IStream_Write(pOutStream, writeBuffer, bStringSize, &cbWritten);
1778 HeapFree(GetProcessHeap(), 0, writeBuffer);
1780 if (cbWritten!=bStringSize)
1781 return E_FAIL;
1784 return S_OK;
1787 /************************************************************************
1788 * OLEFontImpl_GetSizeMax (IPersistStream)
1790 * See Windows documentation for more details on IPersistStream methods.
1792 static HRESULT WINAPI OLEFontImpl_GetSizeMax(
1793 IPersistStream* iface,
1794 ULARGE_INTEGER* pcbSize)
1796 OLEFontImpl *this = impl_from_IPersistStream(iface);
1798 if (pcbSize==NULL)
1799 return E_POINTER;
1801 pcbSize->u.HighPart = 0;
1802 pcbSize->u.LowPart = 0;
1804 pcbSize->u.LowPart += sizeof(BYTE); /* Version */
1805 pcbSize->u.LowPart += sizeof(WORD); /* Lang code */
1806 pcbSize->u.LowPart += sizeof(BYTE); /* Flags */
1807 pcbSize->u.LowPart += sizeof(WORD); /* Weight */
1808 pcbSize->u.LowPart += sizeof(DWORD); /* Size */
1809 pcbSize->u.LowPart += sizeof(BYTE); /* StrLength */
1811 if (this->description.lpstrName!=0)
1812 pcbSize->u.LowPart += WideCharToMultiByte( CP_ACP, 0, this->description.lpstrName,
1813 strlenW(this->description.lpstrName),
1814 NULL, 0, NULL, NULL );
1816 return S_OK;
1819 static const IPersistStreamVtbl OLEFontImpl_IPersistStream_VTable =
1821 OLEFontImpl_IPersistStream_QueryInterface,
1822 OLEFontImpl_IPersistStream_AddRef,
1823 OLEFontImpl_IPersistStream_Release,
1824 OLEFontImpl_GetClassID,
1825 OLEFontImpl_IsDirty,
1826 OLEFontImpl_Load,
1827 OLEFontImpl_Save,
1828 OLEFontImpl_GetSizeMax
1831 /************************************************************************
1832 * OLEFontImpl_IConnectionPointContainer_QueryInterface (IUnknown)
1834 * See Windows documentation for more details on IUnknown methods.
1836 static HRESULT WINAPI OLEFontImpl_IConnectionPointContainer_QueryInterface(
1837 IConnectionPointContainer* iface,
1838 REFIID riid,
1839 VOID** ppvoid)
1841 OLEFontImpl *this = impl_from_IConnectionPointContainer(iface);
1843 return IFont_QueryInterface((IFont*)this, riid, ppvoid);
1846 /************************************************************************
1847 * OLEFontImpl_IConnectionPointContainer_Release (IUnknown)
1849 * See Windows documentation for more details on IUnknown methods.
1851 static ULONG WINAPI OLEFontImpl_IConnectionPointContainer_Release(
1852 IConnectionPointContainer* iface)
1854 OLEFontImpl *this = impl_from_IConnectionPointContainer(iface);
1856 return IFont_Release((IFont*)this);
1859 /************************************************************************
1860 * OLEFontImpl_IConnectionPointContainer_AddRef (IUnknown)
1862 * See Windows documentation for more details on IUnknown methods.
1864 static ULONG WINAPI OLEFontImpl_IConnectionPointContainer_AddRef(
1865 IConnectionPointContainer* iface)
1867 OLEFontImpl *this = impl_from_IConnectionPointContainer(iface);
1869 return IFont_AddRef((IFont*)this);
1872 /************************************************************************
1873 * OLEFontImpl_EnumConnectionPoints (IConnectionPointContainer)
1875 * See Windows documentation for more details on IConnectionPointContainer
1876 * methods.
1878 static HRESULT WINAPI OLEFontImpl_EnumConnectionPoints(
1879 IConnectionPointContainer* iface,
1880 IEnumConnectionPoints **ppEnum)
1882 OLEFontImpl *this = impl_from_IConnectionPointContainer(iface);
1884 FIXME("(%p)->(%p): stub\n", this, ppEnum);
1885 return E_NOTIMPL;
1888 /************************************************************************
1889 * OLEFontImpl_FindConnectionPoint (IConnectionPointContainer)
1891 * See Windows documentation for more details on IConnectionPointContainer
1892 * methods.
1894 static HRESULT WINAPI OLEFontImpl_FindConnectionPoint(
1895 IConnectionPointContainer* iface,
1896 REFIID riid,
1897 IConnectionPoint **ppCp)
1899 OLEFontImpl *this = impl_from_IConnectionPointContainer(iface);
1900 TRACE("(%p)->(%s, %p)\n", this, debugstr_guid(riid), ppCp);
1902 if(IsEqualIID(riid, &IID_IPropertyNotifySink)) {
1903 return IConnectionPoint_QueryInterface(this->pPropertyNotifyCP,
1904 &IID_IConnectionPoint,
1905 (LPVOID)ppCp);
1906 } else if(IsEqualIID(riid, &IID_IFontEventsDisp)) {
1907 return IConnectionPoint_QueryInterface(this->pFontEventsCP,
1908 &IID_IConnectionPoint,
1909 (LPVOID)ppCp);
1910 } else {
1911 FIXME("no connection point for %s\n", debugstr_guid(riid));
1912 return CONNECT_E_NOCONNECTION;
1916 static const IConnectionPointContainerVtbl
1917 OLEFontImpl_IConnectionPointContainer_VTable =
1919 OLEFontImpl_IConnectionPointContainer_QueryInterface,
1920 OLEFontImpl_IConnectionPointContainer_AddRef,
1921 OLEFontImpl_IConnectionPointContainer_Release,
1922 OLEFontImpl_EnumConnectionPoints,
1923 OLEFontImpl_FindConnectionPoint
1926 /************************************************************************
1927 * OLEFontImpl implementation of IPersistPropertyBag.
1929 static HRESULT WINAPI OLEFontImpl_IPersistPropertyBag_QueryInterface(
1930 IPersistPropertyBag *iface, REFIID riid, LPVOID *ppvObj
1932 OLEFontImpl *this = impl_from_IPersistPropertyBag(iface);
1933 return IFont_QueryInterface((IFont *)this,riid,ppvObj);
1936 static ULONG WINAPI OLEFontImpl_IPersistPropertyBag_AddRef(
1937 IPersistPropertyBag *iface
1939 OLEFontImpl *this = impl_from_IPersistPropertyBag(iface);
1940 return IFont_AddRef((IFont *)this);
1943 static ULONG WINAPI OLEFontImpl_IPersistPropertyBag_Release(
1944 IPersistPropertyBag *iface
1946 OLEFontImpl *this = impl_from_IPersistPropertyBag(iface);
1947 return IFont_Release((IFont *)this);
1950 static HRESULT WINAPI OLEFontImpl_IPersistPropertyBag_GetClassID(
1951 IPersistPropertyBag *iface, CLSID *classid
1953 FIXME("(%p,%p), stub!\n", iface, classid);
1954 return E_FAIL;
1957 static HRESULT WINAPI OLEFontImpl_IPersistPropertyBag_InitNew(
1958 IPersistPropertyBag *iface
1960 FIXME("(%p), stub!\n", iface);
1961 return S_OK;
1964 static HRESULT WINAPI OLEFontImpl_IPersistPropertyBag_Load(
1965 IPersistPropertyBag *iface, IPropertyBag* pPropBag, IErrorLog* pErrorLog
1967 /* (from Visual Basic 6 property bag)
1968 Name = "MS Sans Serif"
1969 Size = 13.8
1970 Charset = 0
1971 Weight = 400
1972 Underline = 0 'False
1973 Italic = 0 'False
1974 Strikethrough = 0 'False
1976 static const WCHAR sAttrName[] = {'N','a','m','e',0};
1977 static const WCHAR sAttrSize[] = {'S','i','z','e',0};
1978 static const WCHAR sAttrCharset[] = {'C','h','a','r','s','e','t',0};
1979 static const WCHAR sAttrWeight[] = {'W','e','i','g','h','t',0};
1980 static const WCHAR sAttrUnderline[] = {'U','n','d','e','r','l','i','n','e',0};
1981 static const WCHAR sAttrItalic[] = {'I','t','a','l','i','c',0};
1982 static const WCHAR sAttrStrikethrough[] = {'S','t','r','i','k','e','t','h','r','o','u','g','h',0};
1983 VARIANT rawAttr;
1984 VARIANT valueAttr;
1985 HRESULT iRes = S_OK;
1986 OLEFontImpl *this = impl_from_IPersistPropertyBag(iface);
1988 VariantInit(&rawAttr);
1989 VariantInit(&valueAttr);
1991 if (iRes == S_OK) {
1992 iRes = IPropertyBag_Read(pPropBag, sAttrName, &rawAttr, pErrorLog);
1993 if (iRes == S_OK)
1995 iRes = VariantChangeType(&rawAttr, &valueAttr, 0, VT_BSTR);
1996 if (iRes == S_OK)
1997 iRes = IFont_put_Name((IFont *)this, V_BSTR(&valueAttr));
1999 else if (iRes == E_INVALIDARG)
2000 iRes = S_OK;
2001 VariantClear(&rawAttr);
2002 VariantClear(&valueAttr);
2005 if (iRes == S_OK) {
2006 iRes = IPropertyBag_Read(pPropBag, sAttrSize, &rawAttr, pErrorLog);
2007 if (iRes == S_OK)
2009 iRes = VariantChangeType(&rawAttr, &valueAttr, 0, VT_CY);
2010 if (iRes == S_OK)
2011 iRes = IFont_put_Size((IFont *)this, V_CY(&valueAttr));
2013 else if (iRes == E_INVALIDARG)
2014 iRes = S_OK;
2015 VariantClear(&rawAttr);
2016 VariantClear(&valueAttr);
2019 if (iRes == S_OK) {
2020 iRes = IPropertyBag_Read(pPropBag, sAttrCharset, &rawAttr, pErrorLog);
2021 if (iRes == S_OK)
2023 iRes = VariantChangeType(&rawAttr, &valueAttr, 0, VT_I2);
2024 if (iRes == S_OK)
2025 iRes = IFont_put_Charset((IFont *)this, V_I2(&valueAttr));
2027 else if (iRes == E_INVALIDARG)
2028 iRes = S_OK;
2029 VariantClear(&rawAttr);
2030 VariantClear(&valueAttr);
2033 if (iRes == S_OK) {
2034 iRes = IPropertyBag_Read(pPropBag, sAttrWeight, &rawAttr, pErrorLog);
2035 if (iRes == S_OK)
2037 iRes = VariantChangeType(&rawAttr, &valueAttr, 0, VT_I2);
2038 if (iRes == S_OK)
2039 iRes = IFont_put_Weight((IFont *)this, V_I2(&valueAttr));
2041 else if (iRes == E_INVALIDARG)
2042 iRes = S_OK;
2043 VariantClear(&rawAttr);
2044 VariantClear(&valueAttr);
2048 if (iRes == S_OK) {
2049 iRes = IPropertyBag_Read(pPropBag, sAttrUnderline, &rawAttr, pErrorLog);
2050 if (iRes == S_OK)
2052 iRes = VariantChangeType(&rawAttr, &valueAttr, 0, VT_BOOL);
2053 if (iRes == S_OK)
2054 iRes = IFont_put_Underline((IFont *)this, V_BOOL(&valueAttr));
2056 else if (iRes == E_INVALIDARG)
2057 iRes = S_OK;
2058 VariantClear(&rawAttr);
2059 VariantClear(&valueAttr);
2062 if (iRes == S_OK) {
2063 iRes = IPropertyBag_Read(pPropBag, sAttrItalic, &rawAttr, pErrorLog);
2064 if (iRes == S_OK)
2066 iRes = VariantChangeType(&rawAttr, &valueAttr, 0, VT_BOOL);
2067 if (iRes == S_OK)
2068 iRes = IFont_put_Italic((IFont *)this, V_BOOL(&valueAttr));
2070 else if (iRes == E_INVALIDARG)
2071 iRes = S_OK;
2072 VariantClear(&rawAttr);
2073 VariantClear(&valueAttr);
2076 if (iRes == S_OK) {
2077 iRes = IPropertyBag_Read(pPropBag, sAttrStrikethrough, &rawAttr, pErrorLog);
2078 if (iRes == S_OK)
2080 iRes = VariantChangeType(&rawAttr, &valueAttr, 0, VT_BOOL);
2081 if (iRes == S_OK)
2082 IFont_put_Strikethrough((IFont *)this, V_BOOL(&valueAttr));
2084 else if (iRes == E_INVALIDARG)
2085 iRes = S_OK;
2086 VariantClear(&rawAttr);
2087 VariantClear(&valueAttr);
2090 if (FAILED(iRes))
2091 WARN("-- 0x%08x\n", iRes);
2092 return iRes;
2095 static HRESULT WINAPI OLEFontImpl_IPersistPropertyBag_Save(
2096 IPersistPropertyBag *iface, IPropertyBag* pPropBag, BOOL fClearDirty,
2097 BOOL fSaveAllProperties
2099 FIXME("(%p,%p,%d,%d), stub!\n", iface, pPropBag, fClearDirty, fSaveAllProperties);
2100 return E_FAIL;
2103 static const IPersistPropertyBagVtbl OLEFontImpl_IPersistPropertyBag_VTable =
2105 OLEFontImpl_IPersistPropertyBag_QueryInterface,
2106 OLEFontImpl_IPersistPropertyBag_AddRef,
2107 OLEFontImpl_IPersistPropertyBag_Release,
2109 OLEFontImpl_IPersistPropertyBag_GetClassID,
2110 OLEFontImpl_IPersistPropertyBag_InitNew,
2111 OLEFontImpl_IPersistPropertyBag_Load,
2112 OLEFontImpl_IPersistPropertyBag_Save
2115 /************************************************************************
2116 * OLEFontImpl implementation of IPersistStreamInit.
2118 static HRESULT WINAPI OLEFontImpl_IPersistStreamInit_QueryInterface(
2119 IPersistStreamInit *iface, REFIID riid, LPVOID *ppvObj
2121 OLEFontImpl *this = impl_from_IPersistStreamInit(iface);
2122 return IFont_QueryInterface((IFont *)this,riid,ppvObj);
2125 static ULONG WINAPI OLEFontImpl_IPersistStreamInit_AddRef(
2126 IPersistStreamInit *iface
2128 OLEFontImpl *this = impl_from_IPersistStreamInit(iface);
2129 return IFont_AddRef((IFont *)this);
2132 static ULONG WINAPI OLEFontImpl_IPersistStreamInit_Release(
2133 IPersistStreamInit *iface
2135 OLEFontImpl *this = impl_from_IPersistStreamInit(iface);
2136 return IFont_Release((IFont *)this);
2139 static HRESULT WINAPI OLEFontImpl_IPersistStreamInit_GetClassID(
2140 IPersistStreamInit *iface, CLSID *classid
2142 FIXME("(%p,%p), stub!\n", iface, classid);
2143 return E_FAIL;
2146 static HRESULT WINAPI OLEFontImpl_IPersistStreamInit_IsDirty(
2147 IPersistStreamInit *iface
2149 FIXME("(%p), stub!\n", iface);
2150 return E_FAIL;
2153 static HRESULT WINAPI OLEFontImpl_IPersistStreamInit_Load(
2154 IPersistStreamInit *iface, LPSTREAM pStm
2156 FIXME("(%p,%p), stub!\n", iface, pStm);
2157 return E_FAIL;
2160 static HRESULT WINAPI OLEFontImpl_IPersistStreamInit_Save(
2161 IPersistStreamInit *iface, LPSTREAM pStm, BOOL fClearDirty
2163 FIXME("(%p,%p,%d), stub!\n", iface, pStm, fClearDirty);
2164 return E_FAIL;
2167 static HRESULT WINAPI OLEFontImpl_IPersistStreamInit_GetSizeMax(
2168 IPersistStreamInit *iface, ULARGE_INTEGER *pcbSize
2170 FIXME("(%p,%p), stub!\n", iface, pcbSize);
2171 return E_FAIL;
2174 static HRESULT WINAPI OLEFontImpl_IPersistStreamInit_InitNew(
2175 IPersistStreamInit *iface
2177 FIXME("(%p), stub!\n", iface);
2178 return S_OK;
2181 static const IPersistStreamInitVtbl OLEFontImpl_IPersistStreamInit_VTable =
2183 OLEFontImpl_IPersistStreamInit_QueryInterface,
2184 OLEFontImpl_IPersistStreamInit_AddRef,
2185 OLEFontImpl_IPersistStreamInit_Release,
2187 OLEFontImpl_IPersistStreamInit_GetClassID,
2188 OLEFontImpl_IPersistStreamInit_IsDirty,
2189 OLEFontImpl_IPersistStreamInit_Load,
2190 OLEFontImpl_IPersistStreamInit_Save,
2191 OLEFontImpl_IPersistStreamInit_GetSizeMax,
2192 OLEFontImpl_IPersistStreamInit_InitNew
2195 /************************************************************************
2196 * OLEFontImpl_Construct
2198 * This method will construct a new instance of the OLEFontImpl
2199 * class.
2201 * The caller of this method must release the object when it's
2202 * done with it.
2204 static OLEFontImpl* OLEFontImpl_Construct(const FONTDESC *fontDesc)
2206 OLEFontImpl* newObject = 0;
2209 * Allocate space for the object.
2211 newObject = HeapAlloc(GetProcessHeap(), 0, sizeof(OLEFontImpl));
2213 if (newObject==0)
2214 return newObject;
2217 * Initialize the virtual function table.
2219 newObject->lpVtbl = &OLEFontImpl_VTable;
2220 newObject->lpvtblIDispatch = &OLEFontImpl_IDispatch_VTable;
2221 newObject->lpvtblIPersistStream = &OLEFontImpl_IPersistStream_VTable;
2222 newObject->lpvtblIConnectionPointContainer = &OLEFontImpl_IConnectionPointContainer_VTable;
2223 newObject->lpvtblIPersistPropertyBag = &OLEFontImpl_IPersistPropertyBag_VTable;
2224 newObject->lpvtblIPersistStreamInit = &OLEFontImpl_IPersistStreamInit_VTable;
2227 * Start with one reference count. The caller of this function
2228 * must release the interface pointer when it is done.
2230 newObject->ref = 1;
2233 * Copy the description of the font in the object.
2235 assert(fontDesc->cbSizeofstruct >= sizeof(FONTDESC));
2237 newObject->description.cbSizeofstruct = sizeof(FONTDESC);
2238 newObject->description.lpstrName = HeapAlloc(GetProcessHeap(),
2240 (lstrlenW(fontDesc->lpstrName)+1) * sizeof(WCHAR));
2241 strcpyW(newObject->description.lpstrName, fontDesc->lpstrName);
2242 newObject->description.cySize = fontDesc->cySize;
2243 newObject->description.sWeight = fontDesc->sWeight;
2244 newObject->description.sCharset = fontDesc->sCharset;
2245 newObject->description.fItalic = fontDesc->fItalic;
2246 newObject->description.fUnderline = fontDesc->fUnderline;
2247 newObject->description.fStrikethrough = fontDesc->fStrikethrough;
2250 * Initializing all the other members.
2252 newObject->gdiFont = 0;
2253 newObject->cyLogical = 72L;
2254 newObject->cyHimetric = 2540L;
2255 newObject->pPropertyNotifyCP = NULL;
2256 newObject->pFontEventsCP = NULL;
2258 CreateConnectionPoint((IUnknown*)newObject, &IID_IPropertyNotifySink, &newObject->pPropertyNotifyCP);
2259 CreateConnectionPoint((IUnknown*)newObject, &IID_IFontEventsDisp, &newObject->pFontEventsCP);
2261 if (!newObject->pPropertyNotifyCP || !newObject->pFontEventsCP)
2263 OLEFontImpl_Destroy(newObject);
2264 return NULL;
2267 InterlockedIncrement(&ifont_cnt);
2269 TRACE("returning %p\n", newObject);
2270 return newObject;
2273 /************************************************************************
2274 * OLEFontImpl_Destroy
2276 * This method is called by the Release method when the reference
2277 * count goes down to 0. It will free all resources used by
2278 * this object.
2280 static void OLEFontImpl_Destroy(OLEFontImpl* fontDesc)
2282 TRACE("(%p)\n", fontDesc);
2284 HeapFree(GetProcessHeap(), 0, fontDesc->description.lpstrName);
2286 if (fontDesc->gdiFont!=0)
2287 DeleteObject(fontDesc->gdiFont);
2289 if (fontDesc->pPropertyNotifyCP)
2290 IConnectionPoint_Release(fontDesc->pPropertyNotifyCP);
2291 if (fontDesc->pFontEventsCP)
2292 IConnectionPoint_Release(fontDesc->pFontEventsCP);
2294 HeapFree(GetProcessHeap(), 0, fontDesc);
2297 /*******************************************************************************
2298 * StdFont ClassFactory
2300 typedef struct
2302 /* IUnknown fields */
2303 const IClassFactoryVtbl *lpVtbl;
2304 LONG ref;
2305 } IClassFactoryImpl;
2307 static HRESULT WINAPI
2308 SFCF_QueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj) {
2309 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
2311 FIXME("(%p)->(%s,%p),stub!\n",This,debugstr_guid(riid),ppobj);
2312 return E_NOINTERFACE;
2315 static ULONG WINAPI
2316 SFCF_AddRef(LPCLASSFACTORY iface) {
2317 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
2318 return InterlockedIncrement(&This->ref);
2321 static ULONG WINAPI SFCF_Release(LPCLASSFACTORY iface) {
2322 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
2323 /* static class, won't be freed */
2324 return InterlockedDecrement(&This->ref);
2327 static HRESULT WINAPI SFCF_CreateInstance(
2328 LPCLASSFACTORY iface,LPUNKNOWN pOuter,REFIID riid,LPVOID *ppobj
2330 return OleCreateFontIndirect(NULL,riid,ppobj);
2334 static HRESULT WINAPI SFCF_LockServer(LPCLASSFACTORY iface,BOOL dolock) {
2335 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
2336 FIXME("(%p)->(%d),stub!\n",This,dolock);
2337 return S_OK;
2340 static const IClassFactoryVtbl SFCF_Vtbl = {
2341 SFCF_QueryInterface,
2342 SFCF_AddRef,
2343 SFCF_Release,
2344 SFCF_CreateInstance,
2345 SFCF_LockServer
2347 static IClassFactoryImpl STDFONT_CF = {&SFCF_Vtbl, 1 };
2349 void _get_STDFONT_CF(LPVOID *ppv) { *ppv = &STDFONT_CF; }