oleaut32: Clean QueryInterface() method, turn impl. calls to interface calls.
[wine/multimedia.git] / dlls / oleaut32 / olefont.c
blobc986f0e8f348e612a496eb9c38220e9870e12b49
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
56 static HDC olefont_hdc;
58 /***********************************************************************
59 * List of the HFONTs it has given out, with each one having a separate
60 * ref count.
62 typedef struct _HFONTItem
64 struct list entry;
66 /* Reference count of any IFont objects that own this hfont */
67 LONG int_refs;
69 /* Total reference count of any refs held by the application obtained by AddRefHfont plus any internal refs */
70 LONG total_refs;
72 /* The font associated with this object. */
73 HFONT gdiFont;
75 } HFONTItem, *PHFONTItem;
77 static struct list OLEFontImpl_hFontList = LIST_INIT(OLEFontImpl_hFontList);
79 /* Counts how many fonts contain at least one lock */
80 static LONG ifont_cnt = 0;
82 /***********************************************************************
83 * Critical section for OLEFontImpl_hFontList
85 static CRITICAL_SECTION OLEFontImpl_csHFONTLIST;
86 static CRITICAL_SECTION_DEBUG OLEFontImpl_csHFONTLIST_debug =
88 0, 0, &OLEFontImpl_csHFONTLIST,
89 { &OLEFontImpl_csHFONTLIST_debug.ProcessLocksList,
90 &OLEFontImpl_csHFONTLIST_debug.ProcessLocksList },
91 0, 0, { (DWORD_PTR)(__FILE__ ": OLEFontImpl_csHFONTLIST") }
93 static CRITICAL_SECTION OLEFontImpl_csHFONTLIST = { &OLEFontImpl_csHFONTLIST_debug, -1, 0, 0, 0, 0 };
95 static HDC get_dc(void)
97 HDC hdc;
98 EnterCriticalSection(&OLEFontImpl_csHFONTLIST);
99 if(!olefont_hdc)
100 olefont_hdc = CreateCompatibleDC(NULL);
101 hdc = olefont_hdc;
102 LeaveCriticalSection(&OLEFontImpl_csHFONTLIST);
103 return hdc;
106 static void delete_dc(void)
108 EnterCriticalSection(&OLEFontImpl_csHFONTLIST);
109 if(olefont_hdc)
111 DeleteDC(olefont_hdc);
112 olefont_hdc = NULL;
114 LeaveCriticalSection(&OLEFontImpl_csHFONTLIST);
117 static void HFONTItem_Delete(PHFONTItem item)
119 DeleteObject(item->gdiFont);
120 list_remove(&item->entry);
121 HeapFree(GetProcessHeap(), 0, item);
124 /* Find hfont item entry in the list. Should be called while holding the crit sect */
125 static HFONTItem *find_hfontitem(HFONT hfont)
127 HFONTItem *item;
129 LIST_FOR_EACH_ENTRY(item, &OLEFontImpl_hFontList, HFONTItem, entry)
131 if (item->gdiFont == hfont)
132 return item;
134 return NULL;
137 /* Add an item to the list with one internal reference */
138 static HRESULT add_hfontitem(HFONT hfont)
140 HFONTItem *new_item = HeapAlloc(GetProcessHeap(), 0, sizeof(*new_item));
142 if(!new_item) return E_OUTOFMEMORY;
144 new_item->int_refs = 1;
145 new_item->total_refs = 1;
146 new_item->gdiFont = hfont;
147 EnterCriticalSection(&OLEFontImpl_csHFONTLIST);
148 list_add_tail(&OLEFontImpl_hFontList,&new_item->entry);
149 LeaveCriticalSection(&OLEFontImpl_csHFONTLIST);
150 return S_OK;
153 static HRESULT inc_int_ref(HFONT hfont)
155 HFONTItem *item;
156 HRESULT hr = S_FALSE;
158 EnterCriticalSection(&OLEFontImpl_csHFONTLIST);
159 item = find_hfontitem(hfont);
161 if(item)
163 item->int_refs++;
164 item->total_refs++;
165 hr = S_OK;
167 LeaveCriticalSection(&OLEFontImpl_csHFONTLIST);
169 return hr;
172 /* decrements the internal ref of a hfont item. If both refs are zero it'll
173 remove the item from the list and delete the hfont */
174 static HRESULT dec_int_ref(HFONT hfont)
176 HFONTItem *item;
177 HRESULT hr = S_FALSE;
179 EnterCriticalSection(&OLEFontImpl_csHFONTLIST);
180 item = find_hfontitem(hfont);
182 if(item)
184 item->int_refs--;
185 item->total_refs--;
186 if(item->int_refs == 0 && item->total_refs == 0)
187 HFONTItem_Delete(item);
188 hr = S_OK;
190 LeaveCriticalSection(&OLEFontImpl_csHFONTLIST);
192 return hr;
195 static HRESULT inc_ext_ref(HFONT hfont)
197 HFONTItem *item;
198 HRESULT hr = S_FALSE;
200 EnterCriticalSection(&OLEFontImpl_csHFONTLIST);
202 item = find_hfontitem(hfont);
203 if(item)
205 item->total_refs++;
206 hr = S_OK;
208 LeaveCriticalSection(&OLEFontImpl_csHFONTLIST);
210 return hr;
213 static HRESULT dec_ext_ref(HFONT hfont)
215 HFONTItem *item;
216 HRESULT hr = S_FALSE;
218 EnterCriticalSection(&OLEFontImpl_csHFONTLIST);
220 item = find_hfontitem(hfont);
221 if(item)
223 if(--item->total_refs >= 0) hr = S_OK;
225 LeaveCriticalSection(&OLEFontImpl_csHFONTLIST);
227 return hr;
230 static WCHAR *strdupW(const WCHAR* str)
232 WCHAR *ret;
233 DWORD size = (strlenW(str) + 1) * sizeof(WCHAR);
235 ret = HeapAlloc(GetProcessHeap(), 0, size);
236 if(ret)
237 memcpy(ret, str, size);
238 return ret;
241 /***********************************************************************
242 * Declaration of the implementation class for the IFont interface
244 typedef struct OLEFontImpl OLEFontImpl;
246 struct OLEFontImpl
249 * This class supports many interfaces. IUnknown, IFont,
250 * IDispatch, IDispFont IPersistStream and IConnectionPointContainer.
251 * The first two are supported by the first vtable, the next two are
252 * supported by the second table and the last two have their own.
254 IFont IFont_iface;
255 IDispatch IDispatch_iface;
256 IPersistStream IPersistStream_iface;
257 IConnectionPointContainer IConnectionPointContainer_iface;
258 IPersistPropertyBag IPersistPropertyBag_iface;
259 IPersistStreamInit IPersistStreamInit_iface;
261 * Reference count for that instance of the class.
263 LONG ref;
266 * This structure contains the description of the class.
268 FONTDESC description;
271 * Contain the font associated with this object.
273 HFONT gdiFont;
274 BOOL dirty;
276 * Size ratio
278 LONG cyLogical;
279 LONG cyHimetric;
282 * Stash realized height (pixels) from TEXTMETRIC - used in get_Size()
284 LONG nRealHeight;
286 IConnectionPoint *pPropertyNotifyCP;
287 IConnectionPoint *pFontEventsCP;
291 * Here, I define utility macros to help with the casting of the
292 * "this" parameter.
293 * There is a version to accommodate all of the VTables implemented
294 * by this object.
297 static inline OLEFontImpl *impl_from_IFont(IFont *iface)
299 return CONTAINING_RECORD(iface, OLEFontImpl, IFont_iface);
302 static inline OLEFontImpl *impl_from_IDispatch( IDispatch *iface )
304 return CONTAINING_RECORD(iface, OLEFontImpl, IDispatch_iface);
307 static inline OLEFontImpl *impl_from_IPersistStream( IPersistStream *iface )
309 return CONTAINING_RECORD(iface, OLEFontImpl, IPersistStream_iface);
312 static inline OLEFontImpl *impl_from_IConnectionPointContainer( IConnectionPointContainer *iface )
314 return CONTAINING_RECORD(iface, OLEFontImpl, IConnectionPointContainer_iface);
317 static inline OLEFontImpl *impl_from_IPersistPropertyBag( IPersistPropertyBag *iface )
319 return CONTAINING_RECORD(iface, OLEFontImpl, IPersistPropertyBag_iface);
322 static inline OLEFontImpl *impl_from_IPersistStreamInit( IPersistStreamInit *iface )
324 return CONTAINING_RECORD(iface, OLEFontImpl, IPersistStreamInit_iface);
328 /***********************************************************************
329 * Prototypes for the implementation functions for the IFont
330 * interface
332 static OLEFontImpl* OLEFontImpl_Construct(const FONTDESC *fontDesc);
333 static void OLEFontImpl_Destroy(OLEFontImpl* fontDesc);
334 static ULONG WINAPI OLEFontImpl_AddRef(IFont* iface);
336 /******************************************************************************
337 * OleCreateFontIndirect [OLEAUT32.420]
339 HRESULT WINAPI OleCreateFontIndirect(
340 LPFONTDESC lpFontDesc,
341 REFIID riid,
342 LPVOID* ppvObj)
344 OLEFontImpl* newFont;
345 HRESULT hr;
346 FONTDESC fd;
348 TRACE("(%p, %s, %p)\n", lpFontDesc, debugstr_guid(riid), ppvObj);
350 if (!ppvObj) return E_POINTER;
352 *ppvObj = 0;
354 if (!lpFontDesc) {
355 static WCHAR fname[] = { 'S','y','s','t','e','m',0 };
357 fd.cbSizeofstruct = sizeof(fd);
358 fd.lpstrName = fname;
359 fd.cySize.s.Lo = 80000;
360 fd.cySize.s.Hi = 0;
361 fd.sWeight = 0;
362 fd.sCharset = 0;
363 fd.fItalic = 0;
364 fd.fUnderline = 0;
365 fd.fStrikethrough = 0;
366 lpFontDesc = &fd;
369 newFont = OLEFontImpl_Construct(lpFontDesc);
370 if (!newFont) return E_OUTOFMEMORY;
372 hr = IFont_QueryInterface(&newFont->IFont_iface, riid, ppvObj);
373 IFont_Release(&newFont->IFont_iface);
375 return hr;
379 /***********************************************************************
380 * Implementation of the OLEFontImpl class.
383 /***********************************************************************
384 * OLEFont_SendNotify (internal)
386 * Sends notification messages of changed properties to any interested
387 * connections.
389 static void OLEFont_SendNotify(OLEFontImpl* this, DISPID dispID)
391 static const WCHAR wszName[] = {'N','a','m','e',0};
392 static const WCHAR wszSize[] = {'S','i','z','e',0};
393 static const WCHAR wszBold[] = {'B','o','l','d',0};
394 static const WCHAR wszItalic[] = {'I','t','a','l','i','c',0};
395 static const WCHAR wszUnder[] = {'U','n','d','e','r','l','i','n','e',0};
396 static const WCHAR wszStrike[] = {'S','t','r','i','k','e','t','h','r','o','u','g','h',0};
397 static const WCHAR wszWeight[] = {'W','e','i','g','h','t',0};
398 static const WCHAR wszCharset[] = {'C','h','a','r','s','s','e','t',0};
399 static const LPCWSTR dispid_mapping[] =
401 wszName,
402 NULL,
403 wszSize,
404 wszBold,
405 wszItalic,
406 wszUnder,
407 wszStrike,
408 wszWeight,
409 wszCharset
412 IEnumConnections *pEnum;
413 CONNECTDATA CD;
414 HRESULT hres;
416 this->dirty = TRUE;
418 hres = IConnectionPoint_EnumConnections(this->pPropertyNotifyCP, &pEnum);
419 if (SUCCEEDED(hres))
421 while(IEnumConnections_Next(pEnum, 1, &CD, NULL) == S_OK) {
422 IPropertyNotifySink *sink;
424 IUnknown_QueryInterface(CD.pUnk, &IID_IPropertyNotifySink, (LPVOID)&sink);
425 IPropertyNotifySink_OnChanged(sink, dispID);
426 IPropertyNotifySink_Release(sink);
427 IUnknown_Release(CD.pUnk);
429 IEnumConnections_Release(pEnum);
432 hres = IConnectionPoint_EnumConnections(this->pFontEventsCP, &pEnum);
433 if (SUCCEEDED(hres))
435 DISPPARAMS dispparams;
436 VARIANTARG vararg;
438 VariantInit(&vararg);
439 V_VT(&vararg) = VT_BSTR;
440 V_BSTR(&vararg) = SysAllocString(dispid_mapping[dispID]);
442 dispparams.cArgs = 1;
443 dispparams.cNamedArgs = 0;
444 dispparams.rgdispidNamedArgs = NULL;
445 dispparams.rgvarg = &vararg;
447 while(IEnumConnections_Next(pEnum, 1, &CD, NULL) == S_OK) {
448 IFontEventsDisp *disp;
450 IUnknown_QueryInterface(CD.pUnk, &IID_IFontEventsDisp, (LPVOID)&disp);
451 IDispatch_Invoke(disp, DISPID_FONT_CHANGED, &IID_NULL,
452 LOCALE_NEUTRAL, INVOKE_FUNC, &dispparams, NULL,
453 NULL, NULL);
455 IDispatch_Release(disp);
456 IUnknown_Release(CD.pUnk);
458 VariantClear(&vararg);
459 IEnumConnections_Release(pEnum);
463 /************************************************************************
464 * OLEFontImpl_QueryInterface (IUnknown)
466 * See Windows documentation for more details on IUnknown methods.
468 static HRESULT WINAPI OLEFontImpl_QueryInterface(
469 IFont* iface,
470 REFIID riid,
471 void** ppvObject)
473 OLEFontImpl *this = impl_from_IFont(iface);
475 TRACE("(%p)->(%s, %p)\n", this, debugstr_guid(riid), ppvObject);
477 *ppvObject = 0;
479 if (IsEqualGUID(&IID_IUnknown, riid) ||
480 IsEqualGUID(&IID_IFont, riid))
482 *ppvObject = this;
484 else if (IsEqualGUID(&IID_IDispatch, riid) ||
485 IsEqualGUID(&IID_IFontDisp, riid))
487 *ppvObject = &this->IDispatch_iface;
489 else if (IsEqualGUID(&IID_IPersist, riid) ||
490 IsEqualGUID(&IID_IPersistStream, riid))
492 *ppvObject = &this->IPersistStream_iface;
494 else if (IsEqualGUID(&IID_IConnectionPointContainer, riid))
496 *ppvObject = &this->IConnectionPointContainer_iface;
498 else if (IsEqualGUID(&IID_IPersistPropertyBag, riid))
500 *ppvObject = &this->IPersistPropertyBag_iface;
502 else if (IsEqualGUID(&IID_IPersistStreamInit, riid))
504 *ppvObject = &this->IPersistStreamInit_iface;
507 if (!*ppvObject)
509 FIXME("() : asking for unsupported interface %s\n", debugstr_guid(riid));
510 return E_NOINTERFACE;
513 IFont_AddRef(iface);
515 return S_OK;
518 /************************************************************************
519 * OLEFontImpl_AddRef (IUnknown)
521 static ULONG WINAPI OLEFontImpl_AddRef(
522 IFont* iface)
524 OLEFontImpl *this = impl_from_IFont(iface);
525 TRACE("(%p)->(ref=%d)\n", this, this->ref);
526 return InterlockedIncrement(&this->ref);
529 /************************************************************************
530 * OLEFontImpl_Release (IUnknown)
532 static ULONG WINAPI OLEFontImpl_Release(IFont* iface)
534 OLEFontImpl *this = impl_from_IFont(iface);
535 ULONG ref;
537 TRACE("(%p)->(ref=%d)\n", this, this->ref);
539 ref = InterlockedDecrement(&this->ref);
541 if (ref == 0)
543 ULONG fontlist_refs = InterlockedDecrement(&ifont_cnt);
545 /* Final IFont object so destroy font cache */
546 if (fontlist_refs == 0)
548 HFONTItem *item, *cursor2;
550 EnterCriticalSection(&OLEFontImpl_csHFONTLIST);
551 LIST_FOR_EACH_ENTRY_SAFE(item, cursor2, &OLEFontImpl_hFontList, HFONTItem, entry)
552 HFONTItem_Delete(item);
553 LeaveCriticalSection(&OLEFontImpl_csHFONTLIST);
554 delete_dc();
556 else
558 dec_int_ref(this->gdiFont);
560 OLEFontImpl_Destroy(this);
563 return ref;
566 typedef struct
568 short orig_cs;
569 short avail_cs;
570 } enum_data;
572 static int CALLBACK font_enum_proc(const LOGFONTW *elf, const TEXTMETRICW *ntm, DWORD type, LPARAM lp)
574 enum_data *data = (enum_data*)lp;
576 if(elf->lfCharSet == data->orig_cs)
578 data->avail_cs = data->orig_cs;
579 return 0;
581 if(data->avail_cs == -1) data->avail_cs = elf->lfCharSet;
582 return 1;
585 static void realize_font(OLEFontImpl *This)
587 if (This->dirty)
589 LOGFONTW logFont;
590 INT fontHeight;
591 WCHAR text_face[LF_FACESIZE];
592 HDC hdc = get_dc();
593 HFONT old_font;
594 TEXTMETRICW tm;
596 text_face[0] = 0;
598 if(This->gdiFont)
600 old_font = SelectObject(hdc, This->gdiFont);
601 GetTextFaceW(hdc, sizeof(text_face) / sizeof(text_face[0]), text_face);
602 SelectObject(hdc, old_font);
603 dec_int_ref(This->gdiFont);
604 This->gdiFont = 0;
607 memset(&logFont, 0, sizeof(LOGFONTW));
609 lstrcpynW(logFont.lfFaceName, This->description.lpstrName, LF_FACESIZE);
610 logFont.lfCharSet = This->description.sCharset;
612 /* If the font name has been changed then enumerate all charsets
613 and pick one that'll result in the font specified being selected */
614 if(text_face[0] && lstrcmpiW(text_face, This->description.lpstrName))
616 enum_data data;
617 data.orig_cs = This->description.sCharset;
618 data.avail_cs = -1;
619 logFont.lfCharSet = DEFAULT_CHARSET;
620 EnumFontFamiliesExW(get_dc(), &logFont, font_enum_proc, (LPARAM)&data, 0);
621 if(data.avail_cs != -1) logFont.lfCharSet = data.avail_cs;
626 * The height of the font returned by the get_Size property is the
627 * height of the font in points multiplied by 10000... Using some
628 * simple conversions and the ratio given by the application, it can
629 * be converted to a height in pixels.
631 * Standard ratio is 72 / 2540, or 18 / 635 in lowest terms.
632 * Ratio is applied here relative to the standard.
635 fontHeight = MulDiv( This->description.cySize.s.Lo, This->cyLogical*635, This->cyHimetric*18 );
638 logFont.lfHeight = ((fontHeight%10000L)>5000L) ? (-fontHeight/10000L) - 1 :
639 (-fontHeight/10000L);
640 logFont.lfItalic = This->description.fItalic;
641 logFont.lfUnderline = This->description.fUnderline;
642 logFont.lfStrikeOut = This->description.fStrikethrough;
643 logFont.lfWeight = This->description.sWeight;
644 logFont.lfOutPrecision = OUT_CHARACTER_PRECIS;
645 logFont.lfClipPrecision = CLIP_DEFAULT_PRECIS;
646 logFont.lfQuality = DEFAULT_QUALITY;
647 logFont.lfPitchAndFamily = DEFAULT_PITCH;
649 This->gdiFont = CreateFontIndirectW(&logFont);
650 This->dirty = FALSE;
652 add_hfontitem(This->gdiFont);
654 /* Fixup the name and charset properties so that they match the
655 selected font */
656 old_font = SelectObject(get_dc(), This->gdiFont);
657 GetTextFaceW(hdc, sizeof(text_face) / sizeof(text_face[0]), text_face);
658 if(lstrcmpiW(text_face, This->description.lpstrName))
660 HeapFree(GetProcessHeap(), 0, This->description.lpstrName);
661 This->description.lpstrName = strdupW(text_face);
663 GetTextMetricsW(hdc, &tm);
664 This->description.sCharset = tm.tmCharSet;
665 /* While we have it handy, stash the realized font height for use by get_Size() */
666 This->nRealHeight = tm.tmHeight - tm.tmInternalLeading; /* corresponds to LOGFONT lfHeight */
667 SelectObject(hdc, old_font);
671 /************************************************************************
672 * OLEFontImpl_get_Name (IFont)
674 * See Windows documentation for more details on IFont methods.
676 static HRESULT WINAPI OLEFontImpl_get_Name(
677 IFont* iface,
678 BSTR* pname)
680 OLEFontImpl *this = impl_from_IFont(iface);
681 TRACE("(%p)->(%p)\n", this, pname);
683 if (pname==0)
684 return E_POINTER;
686 if(this->dirty) realize_font(this);
688 if (this->description.lpstrName!=0)
689 *pname = SysAllocString(this->description.lpstrName);
690 else
691 *pname = 0;
693 return S_OK;
696 /************************************************************************
697 * OLEFontImpl_put_Name (IFont)
699 static HRESULT WINAPI OLEFontImpl_put_Name(
700 IFont* iface,
701 BSTR name)
703 OLEFontImpl *this = impl_from_IFont(iface);
704 TRACE("(%p)->(%p)\n", this, name);
706 if (!name)
707 return CTL_E_INVALIDPROPERTYVALUE;
709 if (this->description.lpstrName==0)
711 this->description.lpstrName = HeapAlloc(GetProcessHeap(),
713 (lstrlenW(name)+1) * sizeof(WCHAR));
715 else
717 this->description.lpstrName = HeapReAlloc(GetProcessHeap(),
719 this->description.lpstrName,
720 (lstrlenW(name)+1) * sizeof(WCHAR));
723 if (this->description.lpstrName==0)
724 return E_OUTOFMEMORY;
726 strcpyW(this->description.lpstrName, name);
727 TRACE("new name %s\n", debugstr_w(this->description.lpstrName));
728 OLEFont_SendNotify(this, DISPID_FONT_NAME);
729 return S_OK;
732 /************************************************************************
733 * OLEFontImpl_get_Size (IFont)
735 static HRESULT WINAPI OLEFontImpl_get_Size(
736 IFont* iface,
737 CY* psize)
739 OLEFontImpl *this = impl_from_IFont(iface);
740 TRACE("(%p)->(%p)\n", this, psize);
742 if (!psize) return E_POINTER;
744 if(this->dirty) realize_font(this);
747 * Convert realized font height in pixels to points descaled by current
748 * scaling ratio then scaled up by 10000.
750 psize->s.Lo = MulDiv(this->nRealHeight,
751 this->cyHimetric * 72 * 10000,
752 this->cyLogical * 2540);
753 psize->s.Hi = 0;
755 return S_OK;
758 /************************************************************************
759 * OLEFontImpl_put_Size (IFont)
761 static HRESULT WINAPI OLEFontImpl_put_Size(
762 IFont* iface,
763 CY size)
765 OLEFontImpl *this = impl_from_IFont(iface);
766 TRACE("(%p)->(%d)\n", this, size.s.Lo);
767 this->description.cySize.s.Hi = 0;
768 this->description.cySize.s.Lo = size.s.Lo;
769 OLEFont_SendNotify(this, DISPID_FONT_SIZE);
771 return S_OK;
774 /************************************************************************
775 * OLEFontImpl_get_Bold (IFont)
777 * See Windows documentation for more details on IFont methods.
779 static HRESULT WINAPI OLEFontImpl_get_Bold(
780 IFont* iface,
781 BOOL* pbold)
783 OLEFontImpl *this = impl_from_IFont(iface);
784 TRACE("(%p)->(%p)\n", this, pbold);
786 if (!pbold) return E_POINTER;
788 if(this->dirty) realize_font(this);
790 *pbold = this->description.sWeight > 550;
792 return S_OK;
795 /************************************************************************
796 * OLEFontImpl_put_Bold (IFont)
798 static HRESULT WINAPI OLEFontImpl_put_Bold(
799 IFont* iface,
800 BOOL bold)
802 OLEFontImpl *this = impl_from_IFont(iface);
803 TRACE("(%p)->(%d)\n", this, bold);
804 this->description.sWeight = bold ? FW_BOLD : FW_NORMAL;
805 OLEFont_SendNotify(this, DISPID_FONT_BOLD);
807 return S_OK;
810 /************************************************************************
811 * OLEFontImpl_get_Italic (IFont)
813 static HRESULT WINAPI OLEFontImpl_get_Italic(
814 IFont* iface,
815 BOOL* pitalic)
817 OLEFontImpl *this = impl_from_IFont(iface);
818 TRACE("(%p)->(%p)\n", this, pitalic);
820 if (pitalic==0)
821 return E_POINTER;
823 if(this->dirty) realize_font(this);
825 *pitalic = this->description.fItalic;
827 return S_OK;
830 /************************************************************************
831 * OLEFontImpl_put_Italic (IFont)
833 static HRESULT WINAPI OLEFontImpl_put_Italic(
834 IFont* iface,
835 BOOL italic)
837 OLEFontImpl *this = impl_from_IFont(iface);
838 TRACE("(%p)->(%d)\n", this, italic);
840 this->description.fItalic = italic;
842 OLEFont_SendNotify(this, DISPID_FONT_ITALIC);
843 return S_OK;
846 /************************************************************************
847 * OLEFontImpl_get_Underline (IFont)
849 static HRESULT WINAPI OLEFontImpl_get_Underline(
850 IFont* iface,
851 BOOL* punderline)
853 OLEFontImpl *this = impl_from_IFont(iface);
854 TRACE("(%p)->(%p)\n", this, punderline);
856 if (punderline==0)
857 return E_POINTER;
859 if(this->dirty) realize_font(this);
861 *punderline = this->description.fUnderline;
863 return S_OK;
866 /************************************************************************
867 * OLEFontImpl_put_Underline (IFont)
869 static HRESULT WINAPI OLEFontImpl_put_Underline(
870 IFont* iface,
871 BOOL underline)
873 OLEFontImpl *this = impl_from_IFont(iface);
874 TRACE("(%p)->(%d)\n", this, underline);
876 this->description.fUnderline = underline;
878 OLEFont_SendNotify(this, DISPID_FONT_UNDER);
879 return S_OK;
882 /************************************************************************
883 * OLEFontImpl_get_Strikethrough (IFont)
885 static HRESULT WINAPI OLEFontImpl_get_Strikethrough(
886 IFont* iface,
887 BOOL* pstrikethrough)
889 OLEFontImpl *this = impl_from_IFont(iface);
890 TRACE("(%p)->(%p)\n", this, pstrikethrough);
892 if (pstrikethrough==0)
893 return E_POINTER;
895 if(this->dirty) realize_font(this);
897 *pstrikethrough = this->description.fStrikethrough;
899 return S_OK;
902 /************************************************************************
903 * OLEFontImpl_put_Strikethrough (IFont)
905 static HRESULT WINAPI OLEFontImpl_put_Strikethrough(
906 IFont* iface,
907 BOOL strikethrough)
909 OLEFontImpl *this = impl_from_IFont(iface);
910 TRACE("(%p)->(%d)\n", this, strikethrough);
912 this->description.fStrikethrough = strikethrough;
913 OLEFont_SendNotify(this, DISPID_FONT_STRIKE);
915 return S_OK;
918 /************************************************************************
919 * OLEFontImpl_get_Weight (IFont)
921 static HRESULT WINAPI OLEFontImpl_get_Weight(
922 IFont* iface,
923 short* pweight)
925 OLEFontImpl *this = impl_from_IFont(iface);
926 TRACE("(%p)->(%p)\n", this, pweight);
928 if (pweight==0)
929 return E_POINTER;
931 if(this->dirty) realize_font(this);
933 *pweight = this->description.sWeight;
935 return S_OK;
938 /************************************************************************
939 * OLEFontImpl_put_Weight (IFont)
941 static HRESULT WINAPI OLEFontImpl_put_Weight(
942 IFont* iface,
943 short weight)
945 OLEFontImpl *this = impl_from_IFont(iface);
946 TRACE("(%p)->(%d)\n", this, weight);
948 this->description.sWeight = weight;
950 OLEFont_SendNotify(this, DISPID_FONT_WEIGHT);
951 return S_OK;
954 /************************************************************************
955 * OLEFontImpl_get_Charset (IFont)
957 static HRESULT WINAPI OLEFontImpl_get_Charset(
958 IFont* iface,
959 short* pcharset)
961 OLEFontImpl *this = impl_from_IFont(iface);
962 TRACE("(%p)->(%p)\n", this, pcharset);
964 if (pcharset==0)
965 return E_POINTER;
967 if(this->dirty) realize_font(this);
969 *pcharset = this->description.sCharset;
971 return S_OK;
974 /************************************************************************
975 * OLEFontImpl_put_Charset (IFont)
977 static HRESULT WINAPI OLEFontImpl_put_Charset(
978 IFont* iface,
979 short charset)
981 OLEFontImpl *this = impl_from_IFont(iface);
982 TRACE("(%p)->(%d)\n", this, charset);
984 this->description.sCharset = charset;
985 OLEFont_SendNotify(this, DISPID_FONT_CHARSET);
987 return S_OK;
990 /************************************************************************
991 * OLEFontImpl_get_hFont (IFont)
993 static HRESULT WINAPI OLEFontImpl_get_hFont(
994 IFont* iface,
995 HFONT* phfont)
997 OLEFontImpl *this = impl_from_IFont(iface);
998 TRACE("(%p)->(%p)\n", this, phfont);
999 if (phfont==NULL)
1000 return E_POINTER;
1002 if(this->dirty) realize_font(this);
1004 *phfont = this->gdiFont;
1005 TRACE("Returning %p\n", *phfont);
1006 return S_OK;
1009 /************************************************************************
1010 * OLEFontImpl_Clone (IFont)
1012 static HRESULT WINAPI OLEFontImpl_Clone(
1013 IFont* iface,
1014 IFont** ppfont)
1016 OLEFontImpl *this = impl_from_IFont(iface);
1017 OLEFontImpl* newObject;
1019 TRACE("(%p)->(%p)\n", this, ppfont);
1021 if (ppfont == NULL)
1022 return E_POINTER;
1024 *ppfont = NULL;
1026 newObject = HeapAlloc(GetProcessHeap(), 0, sizeof(OLEFontImpl));
1027 if (newObject==NULL)
1028 return E_OUTOFMEMORY;
1030 *newObject = *this;
1032 /* We need to alloc new memory for the string, otherwise
1033 * we free memory twice.
1035 newObject->description.lpstrName = HeapAlloc(
1036 GetProcessHeap(),0,
1037 (1+strlenW(this->description.lpstrName))*2
1039 strcpyW(newObject->description.lpstrName, this->description.lpstrName);
1041 /* Increment internal ref in hfont item list */
1042 if(newObject->gdiFont) inc_int_ref(newObject->gdiFont);
1044 InterlockedIncrement(&ifont_cnt);
1046 newObject->pPropertyNotifyCP = NULL;
1047 newObject->pFontEventsCP = NULL;
1048 CreateConnectionPoint((IUnknown*)newObject, &IID_IPropertyNotifySink, &newObject->pPropertyNotifyCP);
1049 CreateConnectionPoint((IUnknown*)newObject, &IID_IFontEventsDisp, &newObject->pFontEventsCP);
1051 if (!newObject->pPropertyNotifyCP || !newObject->pFontEventsCP)
1053 OLEFontImpl_Destroy(newObject);
1054 return E_OUTOFMEMORY;
1057 /* The cloned object starts with a reference count of 1 */
1058 newObject->ref = 1;
1060 *ppfont = &newObject->IFont_iface;
1062 return S_OK;
1065 /************************************************************************
1066 * OLEFontImpl_IsEqual (IFont)
1068 static HRESULT WINAPI OLEFontImpl_IsEqual(
1069 IFont* iface,
1070 IFont* pFontOther)
1072 OLEFontImpl *left = impl_from_IFont(iface);
1073 OLEFontImpl *right = impl_from_IFont(pFontOther);
1074 INT ret;
1075 INT left_len,right_len;
1077 if(pFontOther == NULL)
1078 return E_POINTER;
1079 else if (left->description.cySize.s.Lo != right->description.cySize.s.Lo)
1080 return S_FALSE;
1081 else if (left->description.cySize.s.Hi != right->description.cySize.s.Hi)
1082 return S_FALSE;
1083 else if (left->description.sWeight != right->description.sWeight)
1084 return S_FALSE;
1085 else if (left->description.sCharset != right->description.sCharset)
1086 return S_FALSE;
1087 else if (left->description.fItalic != right->description.fItalic)
1088 return S_FALSE;
1089 else if (left->description.fUnderline != right->description.fUnderline)
1090 return S_FALSE;
1091 else if (left->description.fStrikethrough != right->description.fStrikethrough)
1092 return S_FALSE;
1094 /* Check from string */
1095 left_len = strlenW(left->description.lpstrName);
1096 right_len = strlenW(right->description.lpstrName);
1097 ret = CompareStringW(0,0,left->description.lpstrName, left_len,
1098 right->description.lpstrName, right_len);
1099 if (ret != CSTR_EQUAL)
1100 return S_FALSE;
1102 return S_OK;
1105 /************************************************************************
1106 * OLEFontImpl_SetRatio (IFont)
1108 static HRESULT WINAPI OLEFontImpl_SetRatio(
1109 IFont* iface,
1110 LONG cyLogical,
1111 LONG cyHimetric)
1113 OLEFontImpl *this = impl_from_IFont(iface);
1114 TRACE("(%p)->(%d, %d)\n", this, cyLogical, cyHimetric);
1116 if(cyLogical == 0 || cyHimetric == 0)
1117 return E_INVALIDARG;
1119 this->cyLogical = cyLogical;
1120 this->cyHimetric = cyHimetric;
1121 this->dirty = TRUE;
1123 return S_OK;
1126 /************************************************************************
1127 * OLEFontImpl_QueryTextMetrics (IFont)
1129 static HRESULT WINAPI OLEFontImpl_QueryTextMetrics(
1130 IFont* iface,
1131 TEXTMETRICOLE* ptm)
1133 HDC hdcRef;
1134 HFONT hOldFont, hNewFont;
1136 hdcRef = GetDC(0);
1137 IFont_get_hFont(iface, &hNewFont);
1138 hOldFont = SelectObject(hdcRef, hNewFont);
1139 GetTextMetricsW(hdcRef, ptm);
1140 SelectObject(hdcRef, hOldFont);
1141 ReleaseDC(0, hdcRef);
1142 return S_OK;
1145 /************************************************************************
1146 * OLEFontImpl_AddRefHfont (IFont)
1148 static HRESULT WINAPI OLEFontImpl_AddRefHfont(
1149 IFont* iface,
1150 HFONT hfont)
1152 OLEFontImpl *this = impl_from_IFont(iface);
1154 TRACE("(%p)->(%p)\n", this, hfont);
1156 if (!hfont) return E_INVALIDARG;
1158 return inc_ext_ref(hfont);
1161 /************************************************************************
1162 * OLEFontImpl_ReleaseHfont (IFont)
1164 static HRESULT WINAPI OLEFontImpl_ReleaseHfont(
1165 IFont* iface,
1166 HFONT hfont)
1168 OLEFontImpl *this = impl_from_IFont(iface);
1170 TRACE("(%p)->(%p)\n", this, hfont);
1172 if (!hfont) return E_INVALIDARG;
1174 return dec_ext_ref(hfont);
1177 /************************************************************************
1178 * OLEFontImpl_SetHdc (IFont)
1180 static HRESULT WINAPI OLEFontImpl_SetHdc(
1181 IFont* iface,
1182 HDC hdc)
1184 OLEFontImpl *this = impl_from_IFont(iface);
1185 FIXME("(%p)->(%p): Stub\n", this, hdc);
1186 return E_NOTIMPL;
1189 static const IFontVtbl OLEFontImpl_VTable =
1191 OLEFontImpl_QueryInterface,
1192 OLEFontImpl_AddRef,
1193 OLEFontImpl_Release,
1194 OLEFontImpl_get_Name,
1195 OLEFontImpl_put_Name,
1196 OLEFontImpl_get_Size,
1197 OLEFontImpl_put_Size,
1198 OLEFontImpl_get_Bold,
1199 OLEFontImpl_put_Bold,
1200 OLEFontImpl_get_Italic,
1201 OLEFontImpl_put_Italic,
1202 OLEFontImpl_get_Underline,
1203 OLEFontImpl_put_Underline,
1204 OLEFontImpl_get_Strikethrough,
1205 OLEFontImpl_put_Strikethrough,
1206 OLEFontImpl_get_Weight,
1207 OLEFontImpl_put_Weight,
1208 OLEFontImpl_get_Charset,
1209 OLEFontImpl_put_Charset,
1210 OLEFontImpl_get_hFont,
1211 OLEFontImpl_Clone,
1212 OLEFontImpl_IsEqual,
1213 OLEFontImpl_SetRatio,
1214 OLEFontImpl_QueryTextMetrics,
1215 OLEFontImpl_AddRefHfont,
1216 OLEFontImpl_ReleaseHfont,
1217 OLEFontImpl_SetHdc
1220 /************************************************************************
1221 * OLEFontImpl_IDispatch_QueryInterface (IUnknown)
1223 static HRESULT WINAPI OLEFontImpl_IDispatch_QueryInterface(
1224 IDispatch* iface,
1225 REFIID riid,
1226 VOID** ppvoid)
1228 OLEFontImpl *this = impl_from_IDispatch(iface);
1229 return IFont_QueryInterface(&this->IFont_iface, riid, ppvoid);
1232 /************************************************************************
1233 * OLEFontImpl_IDispatch_Release (IUnknown)
1235 static ULONG WINAPI OLEFontImpl_IDispatch_Release(
1236 IDispatch* iface)
1238 OLEFontImpl *this = impl_from_IDispatch(iface);
1239 return IFont_Release(&this->IFont_iface);
1242 /************************************************************************
1243 * OLEFontImpl_IDispatch_AddRef (IUnknown)
1245 static ULONG WINAPI OLEFontImpl_IDispatch_AddRef(
1246 IDispatch* iface)
1248 OLEFontImpl *this = impl_from_IDispatch(iface);
1249 return IFont_AddRef(&this->IFont_iface);
1252 /************************************************************************
1253 * OLEFontImpl_GetTypeInfoCount (IDispatch)
1255 static HRESULT WINAPI OLEFontImpl_GetTypeInfoCount(
1256 IDispatch* iface,
1257 unsigned int* pctinfo)
1259 OLEFontImpl *this = impl_from_IDispatch(iface);
1260 TRACE("(%p)->(%p)\n", this, pctinfo);
1261 *pctinfo = 1;
1263 return S_OK;
1266 /************************************************************************
1267 * OLEFontImpl_GetTypeInfo (IDispatch)
1269 static HRESULT WINAPI OLEFontImpl_GetTypeInfo(
1270 IDispatch* iface,
1271 UINT iTInfo,
1272 LCID lcid,
1273 ITypeInfo** ppTInfo)
1275 static const WCHAR stdole2tlb[] = {'s','t','d','o','l','e','2','.','t','l','b',0};
1276 ITypeLib *tl;
1277 HRESULT hres;
1279 OLEFontImpl *this = impl_from_IDispatch(iface);
1280 TRACE("(%p, iTInfo=%d, lcid=%04x, %p)\n", this, iTInfo, (int)lcid, ppTInfo);
1281 if (iTInfo != 0)
1282 return E_FAIL;
1283 hres = LoadTypeLib(stdole2tlb, &tl);
1284 if (FAILED(hres)) {
1285 ERR("Could not load the stdole2.tlb?\n");
1286 return hres;
1288 hres = ITypeLib_GetTypeInfoOfGuid(tl, &IID_IFontDisp, ppTInfo);
1289 ITypeLib_Release(tl);
1290 if (FAILED(hres)) {
1291 FIXME("Did not IDispatch typeinfo from typelib, hres %x\n",hres);
1293 return hres;
1296 /************************************************************************
1297 * OLEFontImpl_GetIDsOfNames (IDispatch)
1299 static HRESULT WINAPI OLEFontImpl_GetIDsOfNames(
1300 IDispatch* iface,
1301 REFIID riid,
1302 LPOLESTR* rgszNames,
1303 UINT cNames,
1304 LCID lcid,
1305 DISPID* rgDispId)
1307 ITypeInfo * pTInfo;
1308 HRESULT hres;
1310 OLEFontImpl *this = impl_from_IDispatch(iface);
1312 TRACE("(%p,%s,%p,cNames=%d,lcid=%04x,%p)\n", this, debugstr_guid(riid),
1313 rgszNames, cNames, (int)lcid, rgDispId);
1315 if (cNames == 0) return E_INVALIDARG;
1317 hres = IDispatch_GetTypeInfo(iface, 0, lcid, &pTInfo);
1318 if (FAILED(hres))
1320 ERR("GetTypeInfo failed.\n");
1321 return hres;
1324 /* convert names to DISPIDs */
1325 hres = DispGetIDsOfNames (pTInfo, rgszNames, cNames, rgDispId);
1326 ITypeInfo_Release(pTInfo);
1328 return hres;
1331 /************************************************************************
1332 * OLEFontImpl_Invoke (IDispatch)
1334 * Note: Do not call _put_Xxx methods, since setting things here
1335 * should not call notify functions as I found out debugging the generic
1336 * MS VB5 installer.
1338 static HRESULT WINAPI OLEFontImpl_Invoke(
1339 IDispatch* iface,
1340 DISPID dispIdMember,
1341 REFIID riid,
1342 LCID lcid,
1343 WORD wFlags,
1344 DISPPARAMS* pDispParams,
1345 VARIANT* pVarResult,
1346 EXCEPINFO* pExepInfo,
1347 UINT* puArgErr)
1349 OLEFontImpl *this = impl_from_IDispatch(iface);
1350 HRESULT hr;
1352 TRACE("%p->(%d,%s,0x%x,0x%x,%p,%p,%p,%p)\n", this, dispIdMember,
1353 debugstr_guid(riid), lcid, wFlags, pDispParams, pVarResult, pExepInfo,
1354 puArgErr);
1356 /* validate parameters */
1358 if (!IsEqualIID(riid, &IID_NULL))
1360 ERR("riid was %s instead of IID_NULL\n", debugstr_guid(riid));
1361 return DISP_E_UNKNOWNINTERFACE;
1364 if (wFlags & DISPATCH_PROPERTYGET)
1366 if (!pVarResult)
1368 ERR("null pVarResult not allowed when DISPATCH_PROPERTYGET specified\n");
1369 return DISP_E_PARAMNOTOPTIONAL;
1372 else if (wFlags & DISPATCH_PROPERTYPUT)
1374 if (!pDispParams)
1376 ERR("null pDispParams not allowed when DISPATCH_PROPERTYPUT specified\n");
1377 return DISP_E_PARAMNOTOPTIONAL;
1379 if (pDispParams->cArgs != 1)
1381 ERR("param count for DISPATCH_PROPERTYPUT was %d instead of 1\n", pDispParams->cArgs);
1382 return DISP_E_BADPARAMCOUNT;
1385 else
1387 ERR("one of DISPATCH_PROPERTYGET or DISPATCH_PROPERTYPUT must be specified\n");
1388 return DISP_E_MEMBERNOTFOUND;
1391 switch (dispIdMember) {
1392 case DISPID_FONT_NAME:
1393 if (wFlags & DISPATCH_PROPERTYGET) {
1394 V_VT(pVarResult) = VT_BSTR;
1395 return IFont_get_Name(&this->IFont_iface, &V_BSTR(pVarResult));
1396 } else {
1397 VARIANTARG vararg;
1399 VariantInit(&vararg);
1400 hr = VariantChangeTypeEx(&vararg, &pDispParams->rgvarg[0], lcid, 0, VT_BSTR);
1401 if (FAILED(hr))
1402 return hr;
1404 hr = IFont_put_Name(&this->IFont_iface, V_BSTR(&vararg));
1406 VariantClear(&vararg);
1407 return hr;
1409 break;
1410 case DISPID_FONT_BOLD:
1411 if (wFlags & DISPATCH_PROPERTYGET) {
1412 BOOL value;
1413 hr = IFont_get_Bold(&this->IFont_iface, &value);
1414 V_VT(pVarResult) = VT_BOOL;
1415 V_BOOL(pVarResult) = value ? VARIANT_TRUE : VARIANT_FALSE;
1416 return hr;
1417 } else {
1418 VARIANTARG vararg;
1420 VariantInit(&vararg);
1421 hr = VariantChangeTypeEx(&vararg, &pDispParams->rgvarg[0], lcid, 0, VT_BOOL);
1422 if (FAILED(hr))
1423 return hr;
1425 hr = IFont_put_Bold(&this->IFont_iface, V_BOOL(&vararg));
1427 VariantClear(&vararg);
1428 return hr;
1430 break;
1431 case DISPID_FONT_ITALIC:
1432 if (wFlags & DISPATCH_PROPERTYGET) {
1433 BOOL value;
1434 hr = IFont_get_Italic(&this->IFont_iface, &value);
1435 V_VT(pVarResult) = VT_BOOL;
1436 V_BOOL(pVarResult) = value ? VARIANT_TRUE : VARIANT_FALSE;
1437 return hr;
1438 } else {
1439 VARIANTARG vararg;
1441 VariantInit(&vararg);
1442 hr = VariantChangeTypeEx(&vararg, &pDispParams->rgvarg[0], lcid, 0, VT_BOOL);
1443 if (FAILED(hr))
1444 return hr;
1446 hr = IFont_put_Italic(&this->IFont_iface, V_BOOL(&vararg));
1448 VariantClear(&vararg);
1449 return hr;
1451 break;
1452 case DISPID_FONT_UNDER:
1453 if (wFlags & DISPATCH_PROPERTYGET) {
1454 BOOL value;
1455 hr = IFont_get_Underline(&this->IFont_iface, &value);
1456 V_VT(pVarResult) = VT_BOOL;
1457 V_BOOL(pVarResult) = value ? VARIANT_TRUE : VARIANT_FALSE;
1458 return hr;
1459 } else {
1460 VARIANTARG vararg;
1462 VariantInit(&vararg);
1463 hr = VariantChangeTypeEx(&vararg, &pDispParams->rgvarg[0], lcid, 0, VT_BOOL);
1464 if (FAILED(hr))
1465 return hr;
1467 hr = IFont_put_Underline(&this->IFont_iface, V_BOOL(&vararg));
1469 VariantClear(&vararg);
1470 return hr;
1472 break;
1473 case DISPID_FONT_STRIKE:
1474 if (wFlags & DISPATCH_PROPERTYGET) {
1475 BOOL value;
1476 hr = IFont_get_Strikethrough(&this->IFont_iface, &value);
1477 V_VT(pVarResult) = VT_BOOL;
1478 V_BOOL(pVarResult) = value ? VARIANT_TRUE : VARIANT_FALSE;
1479 return hr;
1480 } else {
1481 VARIANTARG vararg;
1483 VariantInit(&vararg);
1484 hr = VariantChangeTypeEx(&vararg, &pDispParams->rgvarg[0], lcid, 0, VT_BOOL);
1485 if (FAILED(hr))
1486 return hr;
1488 hr = IFont_put_Strikethrough(&this->IFont_iface, V_BOOL(&vararg));
1490 VariantClear(&vararg);
1491 return hr;
1493 break;
1494 case DISPID_FONT_SIZE:
1495 if (wFlags & DISPATCH_PROPERTYGET) {
1496 V_VT(pVarResult) = VT_CY;
1497 return IFont_get_Size(&this->IFont_iface, &V_CY(pVarResult));
1498 } else {
1499 VARIANTARG vararg;
1501 VariantInit(&vararg);
1502 hr = VariantChangeTypeEx(&vararg, &pDispParams->rgvarg[0], lcid, 0, VT_CY);
1503 if (FAILED(hr))
1504 return hr;
1506 hr = IFont_put_Size(&this->IFont_iface, V_CY(&vararg));
1508 VariantClear(&vararg);
1509 return hr;
1511 break;
1512 case DISPID_FONT_WEIGHT:
1513 if (wFlags & DISPATCH_PROPERTYGET) {
1514 V_VT(pVarResult) = VT_I2;
1515 return IFont_get_Weight(&this->IFont_iface, &V_I2(pVarResult));
1516 } else {
1517 VARIANTARG vararg;
1519 VariantInit(&vararg);
1520 hr = VariantChangeTypeEx(&vararg, &pDispParams->rgvarg[0], lcid, 0, VT_I2);
1521 if (FAILED(hr))
1522 return hr;
1524 hr = IFont_put_Weight(&this->IFont_iface, V_I2(&vararg));
1526 VariantClear(&vararg);
1527 return hr;
1529 break;
1530 case DISPID_FONT_CHARSET:
1531 if (wFlags & DISPATCH_PROPERTYGET) {
1532 V_VT(pVarResult) = VT_I2;
1533 return OLEFontImpl_get_Charset(&this->IFont_iface, &V_I2(pVarResult));
1534 } else {
1535 VARIANTARG vararg;
1537 VariantInit(&vararg);
1538 hr = VariantChangeTypeEx(&vararg, &pDispParams->rgvarg[0], lcid, 0, VT_I2);
1539 if (FAILED(hr))
1540 return hr;
1542 hr = IFont_put_Charset(&this->IFont_iface, V_I2(&vararg));
1544 VariantClear(&vararg);
1545 return hr;
1547 break;
1548 default:
1549 ERR("member not found for dispid 0x%x\n", dispIdMember);
1550 return DISP_E_MEMBERNOTFOUND;
1554 static const IDispatchVtbl OLEFontImpl_IDispatch_VTable =
1556 OLEFontImpl_IDispatch_QueryInterface,
1557 OLEFontImpl_IDispatch_AddRef,
1558 OLEFontImpl_IDispatch_Release,
1559 OLEFontImpl_GetTypeInfoCount,
1560 OLEFontImpl_GetTypeInfo,
1561 OLEFontImpl_GetIDsOfNames,
1562 OLEFontImpl_Invoke
1565 /************************************************************************
1566 * OLEFontImpl_IPersistStream_QueryInterface (IUnknown)
1568 static HRESULT WINAPI OLEFontImpl_IPersistStream_QueryInterface(
1569 IPersistStream* iface,
1570 REFIID riid,
1571 VOID** ppvoid)
1573 OLEFontImpl *this = impl_from_IPersistStream(iface);
1575 return IFont_QueryInterface(&this->IFont_iface, riid, ppvoid);
1578 /************************************************************************
1579 * OLEFontImpl_IPersistStream_Release (IUnknown)
1581 static ULONG WINAPI OLEFontImpl_IPersistStream_Release(
1582 IPersistStream* iface)
1584 OLEFontImpl *this = impl_from_IPersistStream(iface);
1586 return IFont_Release(&this->IFont_iface);
1589 /************************************************************************
1590 * OLEFontImpl_IPersistStream_AddRef (IUnknown)
1592 static ULONG WINAPI OLEFontImpl_IPersistStream_AddRef(
1593 IPersistStream* iface)
1595 OLEFontImpl *this = impl_from_IPersistStream(iface);
1597 return IFont_AddRef(&this->IFont_iface);
1600 /************************************************************************
1601 * OLEFontImpl_GetClassID (IPersistStream)
1603 static HRESULT WINAPI OLEFontImpl_GetClassID(
1604 IPersistStream* iface,
1605 CLSID* pClassID)
1607 TRACE("(%p,%p)\n",iface,pClassID);
1608 if (pClassID==0)
1609 return E_POINTER;
1611 *pClassID = CLSID_StdFont;
1613 return S_OK;
1616 /************************************************************************
1617 * OLEFontImpl_IsDirty (IPersistStream)
1619 * See Windows documentation for more details on IPersistStream methods.
1621 static HRESULT WINAPI OLEFontImpl_IsDirty(
1622 IPersistStream* iface)
1624 TRACE("(%p)\n",iface);
1625 return S_OK;
1628 /************************************************************************
1629 * OLEFontImpl_Load (IPersistStream)
1631 * See Windows documentation for more details on IPersistStream methods.
1633 * This is the format of the standard font serialization as far as I
1634 * know
1636 * Offset Type Value Comment
1637 * 0x0000 Byte Unknown Probably a version number, contains 0x01
1638 * 0x0001 Short Charset Charset value from the FONTDESC structure
1639 * 0x0003 Byte Attributes Flags defined as follows:
1640 * 00000010 - Italic
1641 * 00000100 - Underline
1642 * 00001000 - Strikethrough
1643 * 0x0004 Short Weight Weight value from FONTDESC structure
1644 * 0x0006 DWORD size "Low" portion of the cySize member of the FONTDESC
1645 * structure/
1646 * 0x000A Byte name length Length of the font name string (no null character)
1647 * 0x000B String name Name of the font (ASCII, no nul character)
1649 static HRESULT WINAPI OLEFontImpl_Load(
1650 IPersistStream* iface,
1651 IStream* pLoadStream)
1653 char readBuffer[0x100];
1654 ULONG cbRead;
1655 BYTE bVersion;
1656 BYTE bAttributes;
1657 BYTE bStringSize;
1658 INT len;
1660 OLEFontImpl *this = impl_from_IPersistStream(iface);
1663 * Read the version byte
1665 IStream_Read(pLoadStream, &bVersion, 1, &cbRead);
1667 if ( (cbRead!=1) ||
1668 (bVersion!=0x01) )
1669 return E_FAIL;
1672 * Charset
1674 IStream_Read(pLoadStream, &this->description.sCharset, 2, &cbRead);
1676 if (cbRead!=2)
1677 return E_FAIL;
1680 * Attributes
1682 IStream_Read(pLoadStream, &bAttributes, 1, &cbRead);
1684 if (cbRead!=1)
1685 return E_FAIL;
1687 this->description.fItalic = (bAttributes & FONTPERSIST_ITALIC) != 0;
1688 this->description.fStrikethrough = (bAttributes & FONTPERSIST_STRIKETHROUGH) != 0;
1689 this->description.fUnderline = (bAttributes & FONTPERSIST_UNDERLINE) != 0;
1692 * Weight
1694 IStream_Read(pLoadStream, &this->description.sWeight, 2, &cbRead);
1696 if (cbRead!=2)
1697 return E_FAIL;
1700 * Size
1702 IStream_Read(pLoadStream, &this->description.cySize.s.Lo, 4, &cbRead);
1704 if (cbRead!=4)
1705 return E_FAIL;
1707 this->description.cySize.s.Hi = 0;
1710 * FontName
1712 IStream_Read(pLoadStream, &bStringSize, 1, &cbRead);
1714 if (cbRead!=1)
1715 return E_FAIL;
1717 IStream_Read(pLoadStream, readBuffer, bStringSize, &cbRead);
1719 if (cbRead!=bStringSize)
1720 return E_FAIL;
1722 HeapFree(GetProcessHeap(), 0, this->description.lpstrName);
1724 len = MultiByteToWideChar( CP_ACP, 0, readBuffer, bStringSize, NULL, 0 );
1725 this->description.lpstrName = HeapAlloc( GetProcessHeap(), 0, (len+1) * sizeof(WCHAR) );
1726 MultiByteToWideChar( CP_ACP, 0, readBuffer, bStringSize, this->description.lpstrName, len );
1727 this->description.lpstrName[len] = 0;
1729 /* Ensure use of this font causes a new one to be created */
1730 dec_int_ref(this->gdiFont);
1731 this->gdiFont = 0;
1732 this->dirty = TRUE;
1734 return S_OK;
1737 /************************************************************************
1738 * OLEFontImpl_Save (IPersistStream)
1740 static HRESULT WINAPI OLEFontImpl_Save(
1741 IPersistStream* iface,
1742 IStream* pOutStream,
1743 BOOL fClearDirty)
1745 char* writeBuffer = NULL;
1746 ULONG cbWritten;
1747 BYTE bVersion = 0x01;
1748 BYTE bAttributes;
1749 BYTE bStringSize;
1751 OLEFontImpl *this = impl_from_IPersistStream(iface);
1754 * Read the version byte
1756 IStream_Write(pOutStream, &bVersion, 1, &cbWritten);
1758 if (cbWritten!=1)
1759 return E_FAIL;
1762 * Charset
1764 IStream_Write(pOutStream, &this->description.sCharset, 2, &cbWritten);
1766 if (cbWritten!=2)
1767 return E_FAIL;
1770 * Attributes
1772 bAttributes = 0;
1774 if (this->description.fItalic)
1775 bAttributes |= FONTPERSIST_ITALIC;
1777 if (this->description.fStrikethrough)
1778 bAttributes |= FONTPERSIST_STRIKETHROUGH;
1780 if (this->description.fUnderline)
1781 bAttributes |= FONTPERSIST_UNDERLINE;
1783 IStream_Write(pOutStream, &bAttributes, 1, &cbWritten);
1785 if (cbWritten!=1)
1786 return E_FAIL;
1789 * Weight
1791 IStream_Write(pOutStream, &this->description.sWeight, 2, &cbWritten);
1793 if (cbWritten!=2)
1794 return E_FAIL;
1797 * Size
1799 IStream_Write(pOutStream, &this->description.cySize.s.Lo, 4, &cbWritten);
1801 if (cbWritten!=4)
1802 return E_FAIL;
1805 * FontName
1807 if (this->description.lpstrName!=0)
1808 bStringSize = WideCharToMultiByte( CP_ACP, 0, this->description.lpstrName,
1809 strlenW(this->description.lpstrName), NULL, 0, NULL, NULL );
1810 else
1811 bStringSize = 0;
1813 IStream_Write(pOutStream, &bStringSize, 1, &cbWritten);
1815 if (cbWritten!=1)
1816 return E_FAIL;
1818 if (bStringSize!=0)
1820 if (!(writeBuffer = HeapAlloc( GetProcessHeap(), 0, bStringSize ))) return E_OUTOFMEMORY;
1821 WideCharToMultiByte( CP_ACP, 0, this->description.lpstrName,
1822 strlenW(this->description.lpstrName),
1823 writeBuffer, bStringSize, NULL, NULL );
1825 IStream_Write(pOutStream, writeBuffer, bStringSize, &cbWritten);
1826 HeapFree(GetProcessHeap(), 0, writeBuffer);
1828 if (cbWritten!=bStringSize)
1829 return E_FAIL;
1832 return S_OK;
1835 /************************************************************************
1836 * OLEFontImpl_GetSizeMax (IPersistStream)
1838 static HRESULT WINAPI OLEFontImpl_GetSizeMax(
1839 IPersistStream* iface,
1840 ULARGE_INTEGER* pcbSize)
1842 OLEFontImpl *this = impl_from_IPersistStream(iface);
1844 if (pcbSize==NULL)
1845 return E_POINTER;
1847 pcbSize->u.HighPart = 0;
1848 pcbSize->u.LowPart = 0;
1850 pcbSize->u.LowPart += sizeof(BYTE); /* Version */
1851 pcbSize->u.LowPart += sizeof(WORD); /* Lang code */
1852 pcbSize->u.LowPart += sizeof(BYTE); /* Flags */
1853 pcbSize->u.LowPart += sizeof(WORD); /* Weight */
1854 pcbSize->u.LowPart += sizeof(DWORD); /* Size */
1855 pcbSize->u.LowPart += sizeof(BYTE); /* StrLength */
1857 if (this->description.lpstrName!=0)
1858 pcbSize->u.LowPart += WideCharToMultiByte( CP_ACP, 0, this->description.lpstrName,
1859 strlenW(this->description.lpstrName),
1860 NULL, 0, NULL, NULL );
1862 return S_OK;
1865 static const IPersistStreamVtbl OLEFontImpl_IPersistStream_VTable =
1867 OLEFontImpl_IPersistStream_QueryInterface,
1868 OLEFontImpl_IPersistStream_AddRef,
1869 OLEFontImpl_IPersistStream_Release,
1870 OLEFontImpl_GetClassID,
1871 OLEFontImpl_IsDirty,
1872 OLEFontImpl_Load,
1873 OLEFontImpl_Save,
1874 OLEFontImpl_GetSizeMax
1877 /************************************************************************
1878 * OLEFontImpl_IConnectionPointContainer_QueryInterface (IUnknown)
1880 static HRESULT WINAPI OLEFontImpl_IConnectionPointContainer_QueryInterface(
1881 IConnectionPointContainer* iface,
1882 REFIID riid,
1883 VOID** ppvoid)
1885 OLEFontImpl *this = impl_from_IConnectionPointContainer(iface);
1887 return IFont_QueryInterface(&this->IFont_iface, riid, ppvoid);
1890 /************************************************************************
1891 * OLEFontImpl_IConnectionPointContainer_Release (IUnknown)
1893 static ULONG WINAPI OLEFontImpl_IConnectionPointContainer_Release(
1894 IConnectionPointContainer* iface)
1896 OLEFontImpl *this = impl_from_IConnectionPointContainer(iface);
1898 return IFont_Release(&this->IFont_iface);
1901 /************************************************************************
1902 * OLEFontImpl_IConnectionPointContainer_AddRef (IUnknown)
1904 static ULONG WINAPI OLEFontImpl_IConnectionPointContainer_AddRef(
1905 IConnectionPointContainer* iface)
1907 OLEFontImpl *this = impl_from_IConnectionPointContainer(iface);
1909 return IFont_AddRef(&this->IFont_iface);
1912 /************************************************************************
1913 * OLEFontImpl_EnumConnectionPoints (IConnectionPointContainer)
1915 static HRESULT WINAPI OLEFontImpl_EnumConnectionPoints(
1916 IConnectionPointContainer* iface,
1917 IEnumConnectionPoints **ppEnum)
1919 OLEFontImpl *this = impl_from_IConnectionPointContainer(iface);
1921 FIXME("(%p)->(%p): stub\n", this, ppEnum);
1922 return E_NOTIMPL;
1925 /************************************************************************
1926 * OLEFontImpl_FindConnectionPoint (IConnectionPointContainer)
1928 static HRESULT WINAPI OLEFontImpl_FindConnectionPoint(
1929 IConnectionPointContainer* iface,
1930 REFIID riid,
1931 IConnectionPoint **ppCp)
1933 OLEFontImpl *this = impl_from_IConnectionPointContainer(iface);
1934 TRACE("(%p)->(%s, %p)\n", this, debugstr_guid(riid), ppCp);
1936 if(IsEqualIID(riid, &IID_IPropertyNotifySink)) {
1937 return IConnectionPoint_QueryInterface(this->pPropertyNotifyCP,
1938 &IID_IConnectionPoint,
1939 (LPVOID)ppCp);
1940 } else if(IsEqualIID(riid, &IID_IFontEventsDisp)) {
1941 return IConnectionPoint_QueryInterface(this->pFontEventsCP,
1942 &IID_IConnectionPoint,
1943 (LPVOID)ppCp);
1944 } else {
1945 FIXME("no connection point for %s\n", debugstr_guid(riid));
1946 return CONNECT_E_NOCONNECTION;
1950 static const IConnectionPointContainerVtbl
1951 OLEFontImpl_IConnectionPointContainer_VTable =
1953 OLEFontImpl_IConnectionPointContainer_QueryInterface,
1954 OLEFontImpl_IConnectionPointContainer_AddRef,
1955 OLEFontImpl_IConnectionPointContainer_Release,
1956 OLEFontImpl_EnumConnectionPoints,
1957 OLEFontImpl_FindConnectionPoint
1960 /************************************************************************
1961 * OLEFontImpl implementation of IPersistPropertyBag.
1963 static HRESULT WINAPI OLEFontImpl_IPersistPropertyBag_QueryInterface(
1964 IPersistPropertyBag *iface, REFIID riid, LPVOID *ppvObj
1966 OLEFontImpl *this = impl_from_IPersistPropertyBag(iface);
1967 return IFont_QueryInterface(&this->IFont_iface,riid,ppvObj);
1970 static ULONG WINAPI OLEFontImpl_IPersistPropertyBag_AddRef(
1971 IPersistPropertyBag *iface
1973 OLEFontImpl *this = impl_from_IPersistPropertyBag(iface);
1974 return IFont_AddRef(&this->IFont_iface);
1977 static ULONG WINAPI OLEFontImpl_IPersistPropertyBag_Release(
1978 IPersistPropertyBag *iface
1980 OLEFontImpl *this = impl_from_IPersistPropertyBag(iface);
1981 return IFont_Release(&this->IFont_iface);
1984 static HRESULT WINAPI OLEFontImpl_IPersistPropertyBag_GetClassID(
1985 IPersistPropertyBag *iface, CLSID *classid
1987 FIXME("(%p,%p), stub!\n", iface, classid);
1988 return E_FAIL;
1991 static HRESULT WINAPI OLEFontImpl_IPersistPropertyBag_InitNew(
1992 IPersistPropertyBag *iface
1994 FIXME("(%p), stub!\n", iface);
1995 return S_OK;
1998 static HRESULT WINAPI OLEFontImpl_IPersistPropertyBag_Load(
1999 IPersistPropertyBag *iface, IPropertyBag* pPropBag, IErrorLog* pErrorLog
2001 /* (from Visual Basic 6 property bag)
2002 Name = "MS Sans Serif"
2003 Size = 13.8
2004 Charset = 0
2005 Weight = 400
2006 Underline = 0 'False
2007 Italic = 0 'False
2008 Strikethrough = 0 'False
2010 static const WCHAR sAttrName[] = {'N','a','m','e',0};
2011 static const WCHAR sAttrSize[] = {'S','i','z','e',0};
2012 static const WCHAR sAttrCharset[] = {'C','h','a','r','s','e','t',0};
2013 static const WCHAR sAttrWeight[] = {'W','e','i','g','h','t',0};
2014 static const WCHAR sAttrUnderline[] = {'U','n','d','e','r','l','i','n','e',0};
2015 static const WCHAR sAttrItalic[] = {'I','t','a','l','i','c',0};
2016 static const WCHAR sAttrStrikethrough[] = {'S','t','r','i','k','e','t','h','r','o','u','g','h',0};
2017 OLEFontImpl *this = impl_from_IPersistPropertyBag(iface);
2018 VARIANT value;
2019 HRESULT iRes;
2021 VariantInit(&value);
2023 iRes = IPropertyBag_Read(pPropBag, sAttrName, &value, pErrorLog);
2024 if (iRes == S_OK)
2026 iRes = VariantChangeType(&value, &value, 0, VT_BSTR);
2027 if (iRes == S_OK)
2028 iRes = IFont_put_Name(&this->IFont_iface, V_BSTR(&value));
2030 else if (iRes == E_INVALIDARG)
2031 iRes = S_OK;
2033 VariantClear(&value);
2035 if (iRes == S_OK) {
2036 iRes = IPropertyBag_Read(pPropBag, sAttrSize, &value, pErrorLog);
2037 if (iRes == S_OK)
2039 iRes = VariantChangeType(&value, &value, 0, VT_CY);
2040 if (iRes == S_OK)
2041 iRes = IFont_put_Size(&this->IFont_iface, V_CY(&value));
2043 else if (iRes == E_INVALIDARG)
2044 iRes = S_OK;
2046 VariantClear(&value);
2049 if (iRes == S_OK) {
2050 iRes = IPropertyBag_Read(pPropBag, sAttrCharset, &value, pErrorLog);
2051 if (iRes == S_OK)
2053 iRes = VariantChangeType(&value, &value, 0, VT_I2);
2054 if (iRes == S_OK)
2055 iRes = IFont_put_Charset(&this->IFont_iface, V_I2(&value));
2057 else if (iRes == E_INVALIDARG)
2058 iRes = S_OK;
2060 VariantClear(&value);
2063 if (iRes == S_OK) {
2064 iRes = IPropertyBag_Read(pPropBag, sAttrWeight, &value, pErrorLog);
2065 if (iRes == S_OK)
2067 iRes = VariantChangeType(&value, &value, 0, VT_I2);
2068 if (iRes == S_OK)
2069 iRes = IFont_put_Weight(&this->IFont_iface, V_I2(&value));
2071 else if (iRes == E_INVALIDARG)
2072 iRes = S_OK;
2074 VariantClear(&value);
2077 if (iRes == S_OK) {
2078 iRes = IPropertyBag_Read(pPropBag, sAttrUnderline, &value, pErrorLog);
2079 if (iRes == S_OK)
2081 iRes = VariantChangeType(&value, &value, 0, VT_BOOL);
2082 if (iRes == S_OK)
2083 iRes = IFont_put_Underline(&this->IFont_iface, V_BOOL(&value));
2085 else if (iRes == E_INVALIDARG)
2086 iRes = S_OK;
2088 VariantClear(&value);
2091 if (iRes == S_OK) {
2092 iRes = IPropertyBag_Read(pPropBag, sAttrItalic, &value, pErrorLog);
2093 if (iRes == S_OK)
2095 iRes = VariantChangeType(&value, &value, 0, VT_BOOL);
2096 if (iRes == S_OK)
2097 iRes = IFont_put_Italic(&this->IFont_iface, V_BOOL(&value));
2099 else if (iRes == E_INVALIDARG)
2100 iRes = S_OK;
2102 VariantClear(&value);
2105 if (iRes == S_OK) {
2106 iRes = IPropertyBag_Read(pPropBag, sAttrStrikethrough, &value, pErrorLog);
2107 if (iRes == S_OK)
2109 iRes = VariantChangeType(&value, &value, 0, VT_BOOL);
2110 if (iRes == S_OK)
2111 IFont_put_Strikethrough(&this->IFont_iface, V_BOOL(&value));
2113 else if (iRes == E_INVALIDARG)
2114 iRes = S_OK;
2116 VariantClear(&value);
2119 if (FAILED(iRes))
2120 WARN("-- 0x%08x\n", iRes);
2121 return iRes;
2124 static HRESULT WINAPI OLEFontImpl_IPersistPropertyBag_Save(
2125 IPersistPropertyBag *iface, IPropertyBag* pPropBag, BOOL fClearDirty,
2126 BOOL fSaveAllProperties
2128 FIXME("(%p,%p,%d,%d), stub!\n", iface, pPropBag, fClearDirty, fSaveAllProperties);
2129 return E_FAIL;
2132 static const IPersistPropertyBagVtbl OLEFontImpl_IPersistPropertyBag_VTable =
2134 OLEFontImpl_IPersistPropertyBag_QueryInterface,
2135 OLEFontImpl_IPersistPropertyBag_AddRef,
2136 OLEFontImpl_IPersistPropertyBag_Release,
2138 OLEFontImpl_IPersistPropertyBag_GetClassID,
2139 OLEFontImpl_IPersistPropertyBag_InitNew,
2140 OLEFontImpl_IPersistPropertyBag_Load,
2141 OLEFontImpl_IPersistPropertyBag_Save
2144 /************************************************************************
2145 * OLEFontImpl implementation of IPersistStreamInit.
2147 static HRESULT WINAPI OLEFontImpl_IPersistStreamInit_QueryInterface(
2148 IPersistStreamInit *iface, REFIID riid, LPVOID *ppvObj
2150 OLEFontImpl *this = impl_from_IPersistStreamInit(iface);
2151 return IFont_QueryInterface(&this->IFont_iface,riid,ppvObj);
2154 static ULONG WINAPI OLEFontImpl_IPersistStreamInit_AddRef(
2155 IPersistStreamInit *iface
2157 OLEFontImpl *this = impl_from_IPersistStreamInit(iface);
2158 return IFont_AddRef(&this->IFont_iface);
2161 static ULONG WINAPI OLEFontImpl_IPersistStreamInit_Release(
2162 IPersistStreamInit *iface
2164 OLEFontImpl *this = impl_from_IPersistStreamInit(iface);
2165 return IFont_Release(&this->IFont_iface);
2168 static HRESULT WINAPI OLEFontImpl_IPersistStreamInit_GetClassID(
2169 IPersistStreamInit *iface, CLSID *classid
2171 FIXME("(%p,%p), stub!\n", iface, classid);
2172 return E_FAIL;
2175 static HRESULT WINAPI OLEFontImpl_IPersistStreamInit_IsDirty(
2176 IPersistStreamInit *iface
2178 FIXME("(%p), stub!\n", iface);
2179 return E_FAIL;
2182 static HRESULT WINAPI OLEFontImpl_IPersistStreamInit_Load(
2183 IPersistStreamInit *iface, LPSTREAM pStm
2185 FIXME("(%p,%p), stub!\n", iface, pStm);
2186 return E_FAIL;
2189 static HRESULT WINAPI OLEFontImpl_IPersistStreamInit_Save(
2190 IPersistStreamInit *iface, LPSTREAM pStm, BOOL fClearDirty
2192 FIXME("(%p,%p,%d), stub!\n", iface, pStm, fClearDirty);
2193 return E_FAIL;
2196 static HRESULT WINAPI OLEFontImpl_IPersistStreamInit_GetSizeMax(
2197 IPersistStreamInit *iface, ULARGE_INTEGER *pcbSize
2199 FIXME("(%p,%p), stub!\n", iface, pcbSize);
2200 return E_FAIL;
2203 static HRESULT WINAPI OLEFontImpl_IPersistStreamInit_InitNew(
2204 IPersistStreamInit *iface
2206 FIXME("(%p), stub!\n", iface);
2207 return S_OK;
2210 static const IPersistStreamInitVtbl OLEFontImpl_IPersistStreamInit_VTable =
2212 OLEFontImpl_IPersistStreamInit_QueryInterface,
2213 OLEFontImpl_IPersistStreamInit_AddRef,
2214 OLEFontImpl_IPersistStreamInit_Release,
2216 OLEFontImpl_IPersistStreamInit_GetClassID,
2217 OLEFontImpl_IPersistStreamInit_IsDirty,
2218 OLEFontImpl_IPersistStreamInit_Load,
2219 OLEFontImpl_IPersistStreamInit_Save,
2220 OLEFontImpl_IPersistStreamInit_GetSizeMax,
2221 OLEFontImpl_IPersistStreamInit_InitNew
2224 /************************************************************************
2225 * OLEFontImpl_Construct
2227 * This method will construct a new instance of the OLEFontImpl
2228 * class.
2230 * The caller of this method must release the object when it's
2231 * done with it.
2233 static OLEFontImpl* OLEFontImpl_Construct(const FONTDESC *fontDesc)
2235 OLEFontImpl* newObject;
2237 newObject = HeapAlloc(GetProcessHeap(), 0, sizeof(OLEFontImpl));
2239 if (newObject==0)
2240 return newObject;
2242 newObject->IFont_iface.lpVtbl = &OLEFontImpl_VTable;
2243 newObject->IDispatch_iface.lpVtbl = &OLEFontImpl_IDispatch_VTable;
2244 newObject->IPersistStream_iface.lpVtbl = &OLEFontImpl_IPersistStream_VTable;
2245 newObject->IConnectionPointContainer_iface.lpVtbl = &OLEFontImpl_IConnectionPointContainer_VTable;
2246 newObject->IPersistPropertyBag_iface.lpVtbl = &OLEFontImpl_IPersistPropertyBag_VTable;
2247 newObject->IPersistStreamInit_iface.lpVtbl = &OLEFontImpl_IPersistStreamInit_VTable;
2249 newObject->ref = 1;
2252 * Copy the description of the font in the object.
2254 assert(fontDesc->cbSizeofstruct >= sizeof(FONTDESC));
2256 newObject->description.cbSizeofstruct = sizeof(FONTDESC);
2257 newObject->description.lpstrName = HeapAlloc(GetProcessHeap(),
2259 (lstrlenW(fontDesc->lpstrName)+1) * sizeof(WCHAR));
2260 strcpyW(newObject->description.lpstrName, fontDesc->lpstrName);
2261 newObject->description.cySize = fontDesc->cySize;
2262 newObject->description.sWeight = fontDesc->sWeight;
2263 newObject->description.sCharset = fontDesc->sCharset;
2264 newObject->description.fItalic = fontDesc->fItalic;
2265 newObject->description.fUnderline = fontDesc->fUnderline;
2266 newObject->description.fStrikethrough = fontDesc->fStrikethrough;
2268 newObject->gdiFont = 0;
2269 newObject->dirty = TRUE;
2270 newObject->cyLogical = GetDeviceCaps(get_dc(), LOGPIXELSY);
2271 newObject->cyHimetric = 2540L;
2272 newObject->pPropertyNotifyCP = NULL;
2273 newObject->pFontEventsCP = NULL;
2275 CreateConnectionPoint((IUnknown*)newObject, &IID_IPropertyNotifySink, &newObject->pPropertyNotifyCP);
2276 CreateConnectionPoint((IUnknown*)newObject, &IID_IFontEventsDisp, &newObject->pFontEventsCP);
2278 if (!newObject->pPropertyNotifyCP || !newObject->pFontEventsCP)
2280 OLEFontImpl_Destroy(newObject);
2281 return NULL;
2284 InterlockedIncrement(&ifont_cnt);
2286 TRACE("returning %p\n", newObject);
2287 return newObject;
2290 /************************************************************************
2291 * OLEFontImpl_Destroy
2293 * This method is called by the Release method when the reference
2294 * count goes down to 0. It will free all resources used by
2295 * this object.
2297 static void OLEFontImpl_Destroy(OLEFontImpl* fontDesc)
2299 TRACE("(%p)\n", fontDesc);
2301 HeapFree(GetProcessHeap(), 0, fontDesc->description.lpstrName);
2303 if (fontDesc->pPropertyNotifyCP)
2304 IConnectionPoint_Release(fontDesc->pPropertyNotifyCP);
2305 if (fontDesc->pFontEventsCP)
2306 IConnectionPoint_Release(fontDesc->pFontEventsCP);
2308 HeapFree(GetProcessHeap(), 0, fontDesc);
2311 /*******************************************************************************
2312 * StdFont ClassFactory
2314 typedef struct
2316 /* IUnknown fields */
2317 IClassFactory IClassFactory_iface;
2318 LONG ref;
2319 } IClassFactoryImpl;
2321 static inline IClassFactoryImpl *impl_from_IClassFactory(IClassFactory *iface)
2323 return CONTAINING_RECORD(iface, IClassFactoryImpl, IClassFactory_iface);
2326 static HRESULT WINAPI
2327 SFCF_QueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj) {
2328 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
2330 FIXME("(%p)->(%s,%p),stub!\n",This,debugstr_guid(riid),ppobj);
2331 return E_NOINTERFACE;
2334 static ULONG WINAPI
2335 SFCF_AddRef(LPCLASSFACTORY iface) {
2336 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
2337 return InterlockedIncrement(&This->ref);
2340 static ULONG WINAPI SFCF_Release(LPCLASSFACTORY iface) {
2341 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
2342 /* static class, won't be freed */
2343 return InterlockedDecrement(&This->ref);
2346 static HRESULT WINAPI SFCF_CreateInstance(
2347 LPCLASSFACTORY iface,LPUNKNOWN pOuter,REFIID riid,LPVOID *ppobj
2349 return OleCreateFontIndirect(NULL,riid,ppobj);
2353 static HRESULT WINAPI SFCF_LockServer(LPCLASSFACTORY iface,BOOL dolock) {
2354 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
2355 FIXME("(%p)->(%d),stub!\n",This,dolock);
2356 return S_OK;
2359 static const IClassFactoryVtbl SFCF_Vtbl = {
2360 SFCF_QueryInterface,
2361 SFCF_AddRef,
2362 SFCF_Release,
2363 SFCF_CreateInstance,
2364 SFCF_LockServer
2366 static IClassFactoryImpl STDFONT_CF = {{&SFCF_Vtbl}, 1 };
2368 void _get_STDFONT_CF(LPVOID *ppv) { *ppv = &STDFONT_CF; }