oleaut32: Handle OLEFontImpl_SetRatio case where cyLogical and cyHimetric are both 1.
[wine/wine-gecko.git] / dlls / oleaut32 / olefont.c
blob3155fc32188597917f2261b92313a375aa55e586
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;
290 static inline OLEFontImpl *impl_from_IFont(IFont *iface)
292 return CONTAINING_RECORD(iface, OLEFontImpl, IFont_iface);
295 static inline OLEFontImpl *impl_from_IDispatch( IDispatch *iface )
297 return CONTAINING_RECORD(iface, OLEFontImpl, IDispatch_iface);
300 static inline OLEFontImpl *impl_from_IPersistStream( IPersistStream *iface )
302 return CONTAINING_RECORD(iface, OLEFontImpl, IPersistStream_iface);
305 static inline OLEFontImpl *impl_from_IConnectionPointContainer( IConnectionPointContainer *iface )
307 return CONTAINING_RECORD(iface, OLEFontImpl, IConnectionPointContainer_iface);
310 static inline OLEFontImpl *impl_from_IPersistPropertyBag( IPersistPropertyBag *iface )
312 return CONTAINING_RECORD(iface, OLEFontImpl, IPersistPropertyBag_iface);
315 static inline OLEFontImpl *impl_from_IPersistStreamInit( IPersistStreamInit *iface )
317 return CONTAINING_RECORD(iface, OLEFontImpl, IPersistStreamInit_iface);
321 /***********************************************************************
322 * Prototypes for the implementation functions for the IFont
323 * interface
325 static OLEFontImpl* OLEFontImpl_Construct(const FONTDESC *fontDesc);
326 static void OLEFontImpl_Destroy(OLEFontImpl* fontDesc);
327 static ULONG WINAPI OLEFontImpl_AddRef(IFont* iface);
329 /******************************************************************************
330 * OleCreateFontIndirect [OLEAUT32.420]
332 HRESULT WINAPI OleCreateFontIndirect(
333 LPFONTDESC lpFontDesc,
334 REFIID riid,
335 LPVOID* ppvObj)
337 OLEFontImpl* newFont;
338 HRESULT hr;
339 FONTDESC fd;
341 TRACE("(%p, %s, %p)\n", lpFontDesc, debugstr_guid(riid), ppvObj);
343 if (!ppvObj) return E_POINTER;
345 *ppvObj = 0;
347 if (!lpFontDesc) {
348 static WCHAR fname[] = { 'S','y','s','t','e','m',0 };
350 fd.cbSizeofstruct = sizeof(fd);
351 fd.lpstrName = fname;
352 fd.cySize.s.Lo = 80000;
353 fd.cySize.s.Hi = 0;
354 fd.sWeight = 0;
355 fd.sCharset = 0;
356 fd.fItalic = FALSE;
357 fd.fUnderline = FALSE;
358 fd.fStrikethrough = FALSE;
359 lpFontDesc = &fd;
362 newFont = OLEFontImpl_Construct(lpFontDesc);
363 if (!newFont) return E_OUTOFMEMORY;
365 hr = IFont_QueryInterface(&newFont->IFont_iface, riid, ppvObj);
366 IFont_Release(&newFont->IFont_iface);
368 return hr;
372 /***********************************************************************
373 * Implementation of the OLEFontImpl class.
376 /***********************************************************************
377 * OLEFont_SendNotify (internal)
379 * Sends notification messages of changed properties to any interested
380 * connections.
382 static void OLEFont_SendNotify(OLEFontImpl* this, DISPID dispID)
384 static const WCHAR wszName[] = {'N','a','m','e',0};
385 static const WCHAR wszSize[] = {'S','i','z','e',0};
386 static const WCHAR wszBold[] = {'B','o','l','d',0};
387 static const WCHAR wszItalic[] = {'I','t','a','l','i','c',0};
388 static const WCHAR wszUnder[] = {'U','n','d','e','r','l','i','n','e',0};
389 static const WCHAR wszStrike[] = {'S','t','r','i','k','e','t','h','r','o','u','g','h',0};
390 static const WCHAR wszWeight[] = {'W','e','i','g','h','t',0};
391 static const WCHAR wszCharset[] = {'C','h','a','r','s','s','e','t',0};
392 static const LPCWSTR dispid_mapping[] =
394 wszName,
395 NULL,
396 wszSize,
397 wszBold,
398 wszItalic,
399 wszUnder,
400 wszStrike,
401 wszWeight,
402 wszCharset
405 IEnumConnections *pEnum;
406 CONNECTDATA CD;
407 HRESULT hres;
409 this->dirty = TRUE;
411 hres = IConnectionPoint_EnumConnections(this->pPropertyNotifyCP, &pEnum);
412 if (SUCCEEDED(hres))
414 while(IEnumConnections_Next(pEnum, 1, &CD, NULL) == S_OK) {
415 IPropertyNotifySink *sink;
417 IUnknown_QueryInterface(CD.pUnk, &IID_IPropertyNotifySink, (void**)&sink);
418 IPropertyNotifySink_OnChanged(sink, dispID);
419 IPropertyNotifySink_Release(sink);
420 IUnknown_Release(CD.pUnk);
422 IEnumConnections_Release(pEnum);
425 hres = IConnectionPoint_EnumConnections(this->pFontEventsCP, &pEnum);
426 if (SUCCEEDED(hres))
428 DISPPARAMS dispparams;
429 VARIANTARG vararg;
431 VariantInit(&vararg);
432 V_VT(&vararg) = VT_BSTR;
433 V_BSTR(&vararg) = SysAllocString(dispid_mapping[dispID]);
435 dispparams.cArgs = 1;
436 dispparams.cNamedArgs = 0;
437 dispparams.rgdispidNamedArgs = NULL;
438 dispparams.rgvarg = &vararg;
440 while(IEnumConnections_Next(pEnum, 1, &CD, NULL) == S_OK) {
441 IFontEventsDisp *disp;
443 IUnknown_QueryInterface(CD.pUnk, &IID_IFontEventsDisp, (void**)&disp);
444 IFontEventsDisp_Invoke(disp, DISPID_FONT_CHANGED, &IID_NULL,
445 LOCALE_NEUTRAL, INVOKE_FUNC, &dispparams, NULL,
446 NULL, NULL);
448 IFontEventsDisp_Release(disp);
449 IUnknown_Release(CD.pUnk);
451 VariantClear(&vararg);
452 IEnumConnections_Release(pEnum);
456 /************************************************************************
457 * OLEFontImpl_QueryInterface (IUnknown)
459 * See Windows documentation for more details on IUnknown methods.
461 static HRESULT WINAPI OLEFontImpl_QueryInterface(
462 IFont* iface,
463 REFIID riid,
464 void** ppvObject)
466 OLEFontImpl *this = impl_from_IFont(iface);
468 TRACE("(%p)->(%s, %p)\n", this, debugstr_guid(riid), ppvObject);
470 *ppvObject = 0;
472 if (IsEqualGUID(&IID_IUnknown, riid) ||
473 IsEqualGUID(&IID_IFont, riid))
475 *ppvObject = this;
477 else if (IsEqualGUID(&IID_IDispatch, riid) ||
478 IsEqualGUID(&IID_IFontDisp, riid))
480 *ppvObject = &this->IDispatch_iface;
482 else if (IsEqualGUID(&IID_IPersist, riid) ||
483 IsEqualGUID(&IID_IPersistStream, riid))
485 *ppvObject = &this->IPersistStream_iface;
487 else if (IsEqualGUID(&IID_IConnectionPointContainer, riid))
489 *ppvObject = &this->IConnectionPointContainer_iface;
491 else if (IsEqualGUID(&IID_IPersistPropertyBag, riid))
493 *ppvObject = &this->IPersistPropertyBag_iface;
495 else if (IsEqualGUID(&IID_IPersistStreamInit, riid))
497 *ppvObject = &this->IPersistStreamInit_iface;
500 if (!*ppvObject)
502 FIXME("() : asking for unsupported interface %s\n", debugstr_guid(riid));
503 return E_NOINTERFACE;
506 IFont_AddRef(iface);
508 return S_OK;
511 /************************************************************************
512 * OLEFontImpl_AddRef (IUnknown)
514 static ULONG WINAPI OLEFontImpl_AddRef(
515 IFont* iface)
517 OLEFontImpl *this = impl_from_IFont(iface);
518 TRACE("(%p)->(ref=%d)\n", this, this->ref);
519 return InterlockedIncrement(&this->ref);
522 /************************************************************************
523 * OLEFontImpl_Release (IUnknown)
525 static ULONG WINAPI OLEFontImpl_Release(IFont* iface)
527 OLEFontImpl *this = impl_from_IFont(iface);
528 ULONG ref;
530 TRACE("(%p)->(ref=%d)\n", this, this->ref);
532 ref = InterlockedDecrement(&this->ref);
534 if (ref == 0)
536 ULONG fontlist_refs = InterlockedDecrement(&ifont_cnt);
538 /* Final IFont object so destroy font cache */
539 if (fontlist_refs == 0)
541 HFONTItem *item, *cursor2;
543 EnterCriticalSection(&OLEFontImpl_csHFONTLIST);
544 LIST_FOR_EACH_ENTRY_SAFE(item, cursor2, &OLEFontImpl_hFontList, HFONTItem, entry)
545 HFONTItem_Delete(item);
546 LeaveCriticalSection(&OLEFontImpl_csHFONTLIST);
547 delete_dc();
549 else
551 dec_int_ref(this->gdiFont);
553 OLEFontImpl_Destroy(this);
556 return ref;
559 typedef struct
561 short orig_cs;
562 short avail_cs;
563 } enum_data;
565 static int CALLBACK font_enum_proc(const LOGFONTW *elf, const TEXTMETRICW *ntm, DWORD type, LPARAM lp)
567 enum_data *data = (enum_data*)lp;
569 if(elf->lfCharSet == data->orig_cs)
571 data->avail_cs = data->orig_cs;
572 return 0;
574 if(data->avail_cs == -1) data->avail_cs = elf->lfCharSet;
575 return 1;
578 static void realize_font(OLEFontImpl *This)
580 LOGFONTW logFont;
581 INT fontHeight;
582 WCHAR text_face[LF_FACESIZE];
583 HDC hdc = get_dc();
584 HFONT old_font;
585 TEXTMETRICW tm;
587 if (!This->dirty) return;
589 text_face[0] = 0;
591 if(This->gdiFont)
593 old_font = SelectObject(hdc, This->gdiFont);
594 GetTextFaceW(hdc, sizeof(text_face) / sizeof(text_face[0]), text_face);
595 SelectObject(hdc, old_font);
596 dec_int_ref(This->gdiFont);
597 This->gdiFont = 0;
600 memset(&logFont, 0, sizeof(LOGFONTW));
602 lstrcpynW(logFont.lfFaceName, This->description.lpstrName, LF_FACESIZE);
603 logFont.lfCharSet = This->description.sCharset;
605 /* If the font name has been changed then enumerate all charsets
606 and pick one that'll result in the font specified being selected */
607 if(text_face[0] && lstrcmpiW(text_face, This->description.lpstrName))
609 enum_data data;
610 data.orig_cs = This->description.sCharset;
611 data.avail_cs = -1;
612 logFont.lfCharSet = DEFAULT_CHARSET;
613 EnumFontFamiliesExW(get_dc(), &logFont, font_enum_proc, (LPARAM)&data, 0);
614 if(data.avail_cs != -1) logFont.lfCharSet = data.avail_cs;
618 * The height of the font returned by the get_Size property is the
619 * height of the font in points multiplied by 10000... Using some
620 * simple conversions and the ratio given by the application, it can
621 * be converted to a height in pixels.
623 * Standard ratio is 72 / 2540, or 18 / 635 in lowest terms.
624 * Ratio is applied here relative to the standard.
627 fontHeight = MulDiv( This->description.cySize.s.Lo, This->cyLogical*635, This->cyHimetric*18 );
629 logFont.lfHeight = ((fontHeight%10000L)>5000L) ? (-fontHeight/10000L) - 1 :
630 (-fontHeight/10000L);
631 logFont.lfItalic = This->description.fItalic;
632 logFont.lfUnderline = This->description.fUnderline;
633 logFont.lfStrikeOut = This->description.fStrikethrough;
634 logFont.lfWeight = This->description.sWeight;
635 logFont.lfOutPrecision = OUT_CHARACTER_PRECIS;
636 logFont.lfClipPrecision = CLIP_DEFAULT_PRECIS;
637 logFont.lfQuality = DEFAULT_QUALITY;
638 logFont.lfPitchAndFamily = DEFAULT_PITCH;
640 This->gdiFont = CreateFontIndirectW(&logFont);
641 This->dirty = FALSE;
643 add_hfontitem(This->gdiFont);
645 /* Fixup the name and charset properties so that they match the
646 selected font */
647 old_font = SelectObject(get_dc(), This->gdiFont);
648 GetTextFaceW(hdc, sizeof(text_face) / sizeof(text_face[0]), text_face);
649 if(lstrcmpiW(text_face, This->description.lpstrName))
651 HeapFree(GetProcessHeap(), 0, This->description.lpstrName);
652 This->description.lpstrName = strdupW(text_face);
654 GetTextMetricsW(hdc, &tm);
655 This->description.sCharset = tm.tmCharSet;
656 /* While we have it handy, stash the realized font height for use by get_Size() */
657 This->nRealHeight = tm.tmHeight - tm.tmInternalLeading; /* corresponds to LOGFONT lfHeight */
658 SelectObject(hdc, old_font);
661 /************************************************************************
662 * OLEFontImpl_get_Name (IFont)
664 * See Windows documentation for more details on IFont methods.
666 static HRESULT WINAPI OLEFontImpl_get_Name(
667 IFont* iface,
668 BSTR* pname)
670 OLEFontImpl *this = impl_from_IFont(iface);
671 TRACE("(%p)->(%p)\n", this, pname);
673 if (pname==0)
674 return E_POINTER;
676 realize_font(this);
678 if (this->description.lpstrName!=0)
679 *pname = SysAllocString(this->description.lpstrName);
680 else
681 *pname = 0;
683 return S_OK;
686 /************************************************************************
687 * OLEFontImpl_put_Name (IFont)
689 static HRESULT WINAPI OLEFontImpl_put_Name(
690 IFont* iface,
691 BSTR name)
693 OLEFontImpl *This = impl_from_IFont(iface);
694 TRACE("(%p)->(%p)\n", This, name);
696 if (!name)
697 return CTL_E_INVALIDPROPERTYVALUE;
699 HeapFree(GetProcessHeap(), 0, This->description.lpstrName);
700 This->description.lpstrName = strdupW(name);
701 if (!This->description.lpstrName) return E_OUTOFMEMORY;
703 TRACE("new name %s\n", debugstr_w(This->description.lpstrName));
704 OLEFont_SendNotify(This, DISPID_FONT_NAME);
705 return S_OK;
708 /************************************************************************
709 * OLEFontImpl_get_Size (IFont)
711 static HRESULT WINAPI OLEFontImpl_get_Size(
712 IFont* iface,
713 CY* psize)
715 OLEFontImpl *this = impl_from_IFont(iface);
716 TRACE("(%p)->(%p)\n", this, psize);
718 if (!psize) return E_POINTER;
720 realize_font(this);
723 * Convert realized font height in pixels to points descaled by current
724 * scaling ratio then scaled up by 10000.
726 psize->s.Lo = MulDiv(this->nRealHeight,
727 this->cyHimetric * 72 * 10000,
728 this->cyLogical * 2540);
729 psize->s.Hi = 0;
731 return S_OK;
734 /************************************************************************
735 * OLEFontImpl_put_Size (IFont)
737 static HRESULT WINAPI OLEFontImpl_put_Size(
738 IFont* iface,
739 CY size)
741 OLEFontImpl *this = impl_from_IFont(iface);
742 TRACE("(%p)->(%d)\n", this, size.s.Lo);
743 this->description.cySize.s.Hi = 0;
744 this->description.cySize.s.Lo = size.s.Lo;
745 OLEFont_SendNotify(this, DISPID_FONT_SIZE);
747 return S_OK;
750 /************************************************************************
751 * OLEFontImpl_get_Bold (IFont)
753 * See Windows documentation for more details on IFont methods.
755 static HRESULT WINAPI OLEFontImpl_get_Bold(
756 IFont* iface,
757 BOOL* pbold)
759 OLEFontImpl *this = impl_from_IFont(iface);
760 TRACE("(%p)->(%p)\n", this, pbold);
762 if (!pbold) return E_POINTER;
764 realize_font(this);
766 *pbold = this->description.sWeight > 550;
768 return S_OK;
771 /************************************************************************
772 * OLEFontImpl_put_Bold (IFont)
774 static HRESULT WINAPI OLEFontImpl_put_Bold(
775 IFont* iface,
776 BOOL bold)
778 OLEFontImpl *this = impl_from_IFont(iface);
779 TRACE("(%p)->(%d)\n", this, bold);
780 this->description.sWeight = bold ? FW_BOLD : FW_NORMAL;
781 OLEFont_SendNotify(this, DISPID_FONT_BOLD);
783 return S_OK;
786 /************************************************************************
787 * OLEFontImpl_get_Italic (IFont)
789 static HRESULT WINAPI OLEFontImpl_get_Italic(
790 IFont* iface,
791 BOOL* pitalic)
793 OLEFontImpl *this = impl_from_IFont(iface);
794 TRACE("(%p)->(%p)\n", this, pitalic);
796 if (pitalic==0)
797 return E_POINTER;
799 realize_font(this);
801 *pitalic = this->description.fItalic;
803 return S_OK;
806 /************************************************************************
807 * OLEFontImpl_put_Italic (IFont)
809 static HRESULT WINAPI OLEFontImpl_put_Italic(
810 IFont* iface,
811 BOOL italic)
813 OLEFontImpl *this = impl_from_IFont(iface);
814 TRACE("(%p)->(%d)\n", this, italic);
816 this->description.fItalic = italic;
818 OLEFont_SendNotify(this, DISPID_FONT_ITALIC);
819 return S_OK;
822 /************************************************************************
823 * OLEFontImpl_get_Underline (IFont)
825 static HRESULT WINAPI OLEFontImpl_get_Underline(
826 IFont* iface,
827 BOOL* punderline)
829 OLEFontImpl *this = impl_from_IFont(iface);
830 TRACE("(%p)->(%p)\n", this, punderline);
832 if (punderline==0)
833 return E_POINTER;
835 realize_font(this);
837 *punderline = this->description.fUnderline;
839 return S_OK;
842 /************************************************************************
843 * OLEFontImpl_put_Underline (IFont)
845 static HRESULT WINAPI OLEFontImpl_put_Underline(
846 IFont* iface,
847 BOOL underline)
849 OLEFontImpl *this = impl_from_IFont(iface);
850 TRACE("(%p)->(%d)\n", this, underline);
852 this->description.fUnderline = underline;
854 OLEFont_SendNotify(this, DISPID_FONT_UNDER);
855 return S_OK;
858 /************************************************************************
859 * OLEFontImpl_get_Strikethrough (IFont)
861 static HRESULT WINAPI OLEFontImpl_get_Strikethrough(
862 IFont* iface,
863 BOOL* pstrikethrough)
865 OLEFontImpl *this = impl_from_IFont(iface);
866 TRACE("(%p)->(%p)\n", this, pstrikethrough);
868 if (pstrikethrough==0)
869 return E_POINTER;
871 realize_font(this);
873 *pstrikethrough = this->description.fStrikethrough;
875 return S_OK;
878 /************************************************************************
879 * OLEFontImpl_put_Strikethrough (IFont)
881 static HRESULT WINAPI OLEFontImpl_put_Strikethrough(
882 IFont* iface,
883 BOOL strikethrough)
885 OLEFontImpl *this = impl_from_IFont(iface);
886 TRACE("(%p)->(%d)\n", this, strikethrough);
888 this->description.fStrikethrough = strikethrough;
889 OLEFont_SendNotify(this, DISPID_FONT_STRIKE);
891 return S_OK;
894 /************************************************************************
895 * OLEFontImpl_get_Weight (IFont)
897 static HRESULT WINAPI OLEFontImpl_get_Weight(
898 IFont* iface,
899 short* pweight)
901 OLEFontImpl *this = impl_from_IFont(iface);
902 TRACE("(%p)->(%p)\n", this, pweight);
904 if (pweight==0)
905 return E_POINTER;
907 realize_font(this);
909 *pweight = this->description.sWeight;
911 return S_OK;
914 /************************************************************************
915 * OLEFontImpl_put_Weight (IFont)
917 static HRESULT WINAPI OLEFontImpl_put_Weight(
918 IFont* iface,
919 short weight)
921 OLEFontImpl *this = impl_from_IFont(iface);
922 TRACE("(%p)->(%d)\n", this, weight);
924 this->description.sWeight = weight;
926 OLEFont_SendNotify(this, DISPID_FONT_WEIGHT);
927 return S_OK;
930 /************************************************************************
931 * OLEFontImpl_get_Charset (IFont)
933 static HRESULT WINAPI OLEFontImpl_get_Charset(
934 IFont* iface,
935 short* pcharset)
937 OLEFontImpl *this = impl_from_IFont(iface);
938 TRACE("(%p)->(%p)\n", this, pcharset);
940 if (pcharset==0)
941 return E_POINTER;
943 realize_font(this);
945 *pcharset = this->description.sCharset;
947 return S_OK;
950 /************************************************************************
951 * OLEFontImpl_put_Charset (IFont)
953 static HRESULT WINAPI OLEFontImpl_put_Charset(
954 IFont* iface,
955 short charset)
957 OLEFontImpl *this = impl_from_IFont(iface);
958 TRACE("(%p)->(%d)\n", this, charset);
960 this->description.sCharset = charset;
961 OLEFont_SendNotify(this, DISPID_FONT_CHARSET);
963 return S_OK;
966 /************************************************************************
967 * OLEFontImpl_get_hFont (IFont)
969 static HRESULT WINAPI OLEFontImpl_get_hFont(
970 IFont* iface,
971 HFONT* phfont)
973 OLEFontImpl *this = impl_from_IFont(iface);
974 TRACE("(%p)->(%p)\n", this, phfont);
975 if (phfont==NULL)
976 return E_POINTER;
978 realize_font(this);
980 *phfont = this->gdiFont;
981 TRACE("Returning %p\n", *phfont);
982 return S_OK;
985 /************************************************************************
986 * OLEFontImpl_Clone (IFont)
988 static HRESULT WINAPI OLEFontImpl_Clone(
989 IFont* iface,
990 IFont** ppfont)
992 OLEFontImpl *this = impl_from_IFont(iface);
993 OLEFontImpl* newObject;
995 TRACE("(%p)->(%p)\n", this, ppfont);
997 if (ppfont == NULL)
998 return E_POINTER;
1000 *ppfont = NULL;
1002 newObject = HeapAlloc(GetProcessHeap(), 0, sizeof(OLEFontImpl));
1003 if (newObject==NULL)
1004 return E_OUTOFMEMORY;
1006 *newObject = *this;
1007 /* allocate separate buffer */
1008 newObject->description.lpstrName = strdupW(this->description.lpstrName);
1010 /* Increment internal ref in hfont item list */
1011 if(newObject->gdiFont) inc_int_ref(newObject->gdiFont);
1013 InterlockedIncrement(&ifont_cnt);
1015 newObject->pPropertyNotifyCP = NULL;
1016 newObject->pFontEventsCP = NULL;
1017 CreateConnectionPoint((IUnknown*)newObject, &IID_IPropertyNotifySink, &newObject->pPropertyNotifyCP);
1018 CreateConnectionPoint((IUnknown*)newObject, &IID_IFontEventsDisp, &newObject->pFontEventsCP);
1020 if (!newObject->pPropertyNotifyCP || !newObject->pFontEventsCP)
1022 OLEFontImpl_Destroy(newObject);
1023 return E_OUTOFMEMORY;
1026 /* The cloned object starts with a reference count of 1 */
1027 newObject->ref = 1;
1029 *ppfont = &newObject->IFont_iface;
1031 return S_OK;
1034 /************************************************************************
1035 * OLEFontImpl_IsEqual (IFont)
1037 static HRESULT WINAPI OLEFontImpl_IsEqual(
1038 IFont* iface,
1039 IFont* pFontOther)
1041 OLEFontImpl *left = impl_from_IFont(iface);
1042 OLEFontImpl *right = impl_from_IFont(pFontOther);
1043 INT ret;
1044 INT left_len,right_len;
1046 if(pFontOther == NULL)
1047 return E_POINTER;
1048 else if (left->description.cySize.s.Lo != right->description.cySize.s.Lo)
1049 return S_FALSE;
1050 else if (left->description.cySize.s.Hi != right->description.cySize.s.Hi)
1051 return S_FALSE;
1052 else if (left->description.sWeight != right->description.sWeight)
1053 return S_FALSE;
1054 else if (left->description.sCharset != right->description.sCharset)
1055 return S_FALSE;
1056 else if (left->description.fItalic != right->description.fItalic)
1057 return S_FALSE;
1058 else if (left->description.fUnderline != right->description.fUnderline)
1059 return S_FALSE;
1060 else if (left->description.fStrikethrough != right->description.fStrikethrough)
1061 return S_FALSE;
1063 /* Check from string */
1064 left_len = strlenW(left->description.lpstrName);
1065 right_len = strlenW(right->description.lpstrName);
1066 ret = CompareStringW(0,0,left->description.lpstrName, left_len,
1067 right->description.lpstrName, right_len);
1068 if (ret != CSTR_EQUAL)
1069 return S_FALSE;
1071 return S_OK;
1074 /************************************************************************
1075 * OLEFontImpl_SetRatio (IFont)
1077 static HRESULT WINAPI OLEFontImpl_SetRatio(
1078 IFont* iface,
1079 LONG cyLogical,
1080 LONG cyHimetric)
1082 OLEFontImpl *this = impl_from_IFont(iface);
1083 TRACE("(%p)->(%d, %d)\n", this, cyLogical, cyHimetric);
1085 if(cyLogical == 0 || cyHimetric == 0)
1086 return E_INVALIDARG;
1088 /* cyLogical and cyHimetric both set to 1 is a special case that
1089 does not change the scaling but also does not fail */
1090 if(cyLogical == 1 && cyHimetric == 1)
1091 return S_OK;
1093 this->cyLogical = cyLogical;
1094 this->cyHimetric = cyHimetric;
1095 this->dirty = TRUE;
1097 return S_OK;
1100 /************************************************************************
1101 * OLEFontImpl_QueryTextMetrics (IFont)
1103 static HRESULT WINAPI OLEFontImpl_QueryTextMetrics(
1104 IFont* iface,
1105 TEXTMETRICOLE* ptm)
1107 HDC hdcRef;
1108 HFONT hOldFont, hNewFont;
1110 hdcRef = GetDC(0);
1111 IFont_get_hFont(iface, &hNewFont);
1112 hOldFont = SelectObject(hdcRef, hNewFont);
1113 GetTextMetricsW(hdcRef, ptm);
1114 SelectObject(hdcRef, hOldFont);
1115 ReleaseDC(0, hdcRef);
1116 return S_OK;
1119 /************************************************************************
1120 * OLEFontImpl_AddRefHfont (IFont)
1122 static HRESULT WINAPI OLEFontImpl_AddRefHfont(
1123 IFont* iface,
1124 HFONT hfont)
1126 OLEFontImpl *this = impl_from_IFont(iface);
1128 TRACE("(%p)->(%p)\n", this, hfont);
1130 if (!hfont) return E_INVALIDARG;
1132 return inc_ext_ref(hfont);
1135 /************************************************************************
1136 * OLEFontImpl_ReleaseHfont (IFont)
1138 static HRESULT WINAPI OLEFontImpl_ReleaseHfont(
1139 IFont* iface,
1140 HFONT hfont)
1142 OLEFontImpl *this = impl_from_IFont(iface);
1144 TRACE("(%p)->(%p)\n", this, hfont);
1146 if (!hfont) return E_INVALIDARG;
1148 return dec_ext_ref(hfont);
1151 /************************************************************************
1152 * OLEFontImpl_SetHdc (IFont)
1154 static HRESULT WINAPI OLEFontImpl_SetHdc(
1155 IFont* iface,
1156 HDC hdc)
1158 OLEFontImpl *this = impl_from_IFont(iface);
1159 FIXME("(%p)->(%p): Stub\n", this, hdc);
1160 return E_NOTIMPL;
1163 static const IFontVtbl OLEFontImpl_VTable =
1165 OLEFontImpl_QueryInterface,
1166 OLEFontImpl_AddRef,
1167 OLEFontImpl_Release,
1168 OLEFontImpl_get_Name,
1169 OLEFontImpl_put_Name,
1170 OLEFontImpl_get_Size,
1171 OLEFontImpl_put_Size,
1172 OLEFontImpl_get_Bold,
1173 OLEFontImpl_put_Bold,
1174 OLEFontImpl_get_Italic,
1175 OLEFontImpl_put_Italic,
1176 OLEFontImpl_get_Underline,
1177 OLEFontImpl_put_Underline,
1178 OLEFontImpl_get_Strikethrough,
1179 OLEFontImpl_put_Strikethrough,
1180 OLEFontImpl_get_Weight,
1181 OLEFontImpl_put_Weight,
1182 OLEFontImpl_get_Charset,
1183 OLEFontImpl_put_Charset,
1184 OLEFontImpl_get_hFont,
1185 OLEFontImpl_Clone,
1186 OLEFontImpl_IsEqual,
1187 OLEFontImpl_SetRatio,
1188 OLEFontImpl_QueryTextMetrics,
1189 OLEFontImpl_AddRefHfont,
1190 OLEFontImpl_ReleaseHfont,
1191 OLEFontImpl_SetHdc
1194 /************************************************************************
1195 * OLEFontImpl_IDispatch_QueryInterface (IUnknown)
1197 static HRESULT WINAPI OLEFontImpl_IDispatch_QueryInterface(
1198 IDispatch* iface,
1199 REFIID riid,
1200 VOID** ppvoid)
1202 OLEFontImpl *this = impl_from_IDispatch(iface);
1203 return IFont_QueryInterface(&this->IFont_iface, riid, ppvoid);
1206 /************************************************************************
1207 * OLEFontImpl_IDispatch_Release (IUnknown)
1209 static ULONG WINAPI OLEFontImpl_IDispatch_Release(
1210 IDispatch* iface)
1212 OLEFontImpl *this = impl_from_IDispatch(iface);
1213 return IFont_Release(&this->IFont_iface);
1216 /************************************************************************
1217 * OLEFontImpl_IDispatch_AddRef (IUnknown)
1219 static ULONG WINAPI OLEFontImpl_IDispatch_AddRef(
1220 IDispatch* iface)
1222 OLEFontImpl *this = impl_from_IDispatch(iface);
1223 return IFont_AddRef(&this->IFont_iface);
1226 /************************************************************************
1227 * OLEFontImpl_GetTypeInfoCount (IDispatch)
1229 static HRESULT WINAPI OLEFontImpl_GetTypeInfoCount(
1230 IDispatch* iface,
1231 unsigned int* pctinfo)
1233 OLEFontImpl *this = impl_from_IDispatch(iface);
1234 TRACE("(%p)->(%p)\n", this, pctinfo);
1235 *pctinfo = 1;
1237 return S_OK;
1240 /************************************************************************
1241 * OLEFontImpl_GetTypeInfo (IDispatch)
1243 static HRESULT WINAPI OLEFontImpl_GetTypeInfo(
1244 IDispatch* iface,
1245 UINT iTInfo,
1246 LCID lcid,
1247 ITypeInfo** ppTInfo)
1249 static const WCHAR stdole2tlb[] = {'s','t','d','o','l','e','2','.','t','l','b',0};
1250 ITypeLib *tl;
1251 HRESULT hres;
1253 OLEFontImpl *this = impl_from_IDispatch(iface);
1254 TRACE("(%p, iTInfo=%d, lcid=%04x, %p)\n", this, iTInfo, (int)lcid, ppTInfo);
1255 if (iTInfo != 0)
1256 return E_FAIL;
1257 hres = LoadTypeLib(stdole2tlb, &tl);
1258 if (FAILED(hres)) {
1259 ERR("Could not load the stdole2.tlb?\n");
1260 return hres;
1262 hres = ITypeLib_GetTypeInfoOfGuid(tl, &IID_IFontDisp, ppTInfo);
1263 ITypeLib_Release(tl);
1264 if (FAILED(hres)) {
1265 FIXME("Did not IDispatch typeinfo from typelib, hres %x\n",hres);
1267 return hres;
1270 /************************************************************************
1271 * OLEFontImpl_GetIDsOfNames (IDispatch)
1273 static HRESULT WINAPI OLEFontImpl_GetIDsOfNames(
1274 IDispatch* iface,
1275 REFIID riid,
1276 LPOLESTR* rgszNames,
1277 UINT cNames,
1278 LCID lcid,
1279 DISPID* rgDispId)
1281 ITypeInfo * pTInfo;
1282 HRESULT hres;
1284 OLEFontImpl *this = impl_from_IDispatch(iface);
1286 TRACE("(%p,%s,%p,cNames=%d,lcid=%04x,%p)\n", this, debugstr_guid(riid),
1287 rgszNames, cNames, (int)lcid, rgDispId);
1289 if (cNames == 0) return E_INVALIDARG;
1291 hres = IDispatch_GetTypeInfo(iface, 0, lcid, &pTInfo);
1292 if (FAILED(hres))
1294 ERR("GetTypeInfo failed.\n");
1295 return hres;
1298 /* convert names to DISPIDs */
1299 hres = DispGetIDsOfNames (pTInfo, rgszNames, cNames, rgDispId);
1300 ITypeInfo_Release(pTInfo);
1302 return hres;
1305 /************************************************************************
1306 * OLEFontImpl_Invoke (IDispatch)
1308 * Note: Do not call _put_Xxx methods, since setting things here
1309 * should not call notify functions as I found out debugging the generic
1310 * MS VB5 installer.
1312 static HRESULT WINAPI OLEFontImpl_Invoke(
1313 IDispatch* iface,
1314 DISPID dispIdMember,
1315 REFIID riid,
1316 LCID lcid,
1317 WORD wFlags,
1318 DISPPARAMS* pDispParams,
1319 VARIANT* pVarResult,
1320 EXCEPINFO* pExepInfo,
1321 UINT* puArgErr)
1323 OLEFontImpl *this = impl_from_IDispatch(iface);
1324 HRESULT hr;
1326 TRACE("%p->(%d,%s,0x%x,0x%x,%p,%p,%p,%p)\n", this, dispIdMember,
1327 debugstr_guid(riid), lcid, wFlags, pDispParams, pVarResult, pExepInfo,
1328 puArgErr);
1330 /* validate parameters */
1332 if (!IsEqualIID(riid, &IID_NULL))
1334 ERR("riid was %s instead of IID_NULL\n", debugstr_guid(riid));
1335 return DISP_E_UNKNOWNINTERFACE;
1338 if (wFlags & DISPATCH_PROPERTYGET)
1340 if (!pVarResult)
1342 ERR("null pVarResult not allowed when DISPATCH_PROPERTYGET specified\n");
1343 return DISP_E_PARAMNOTOPTIONAL;
1346 else if (wFlags & DISPATCH_PROPERTYPUT)
1348 if (!pDispParams)
1350 ERR("null pDispParams not allowed when DISPATCH_PROPERTYPUT specified\n");
1351 return DISP_E_PARAMNOTOPTIONAL;
1353 if (pDispParams->cArgs != 1)
1355 ERR("param count for DISPATCH_PROPERTYPUT was %d instead of 1\n", pDispParams->cArgs);
1356 return DISP_E_BADPARAMCOUNT;
1359 else
1361 ERR("one of DISPATCH_PROPERTYGET or DISPATCH_PROPERTYPUT must be specified\n");
1362 return DISP_E_MEMBERNOTFOUND;
1365 switch (dispIdMember) {
1366 case DISPID_FONT_NAME:
1367 if (wFlags & DISPATCH_PROPERTYGET) {
1368 V_VT(pVarResult) = VT_BSTR;
1369 return IFont_get_Name(&this->IFont_iface, &V_BSTR(pVarResult));
1370 } else {
1371 VARIANTARG vararg;
1373 VariantInit(&vararg);
1374 hr = VariantChangeTypeEx(&vararg, &pDispParams->rgvarg[0], lcid, 0, VT_BSTR);
1375 if (FAILED(hr))
1376 return hr;
1378 hr = IFont_put_Name(&this->IFont_iface, V_BSTR(&vararg));
1380 VariantClear(&vararg);
1381 return hr;
1383 break;
1384 case DISPID_FONT_BOLD:
1385 if (wFlags & DISPATCH_PROPERTYGET) {
1386 BOOL value;
1387 hr = IFont_get_Bold(&this->IFont_iface, &value);
1388 V_VT(pVarResult) = VT_BOOL;
1389 V_BOOL(pVarResult) = value ? VARIANT_TRUE : VARIANT_FALSE;
1390 return hr;
1391 } else {
1392 VARIANTARG vararg;
1394 VariantInit(&vararg);
1395 hr = VariantChangeTypeEx(&vararg, &pDispParams->rgvarg[0], lcid, 0, VT_BOOL);
1396 if (FAILED(hr))
1397 return hr;
1399 hr = IFont_put_Bold(&this->IFont_iface, V_BOOL(&vararg));
1401 VariantClear(&vararg);
1402 return hr;
1404 break;
1405 case DISPID_FONT_ITALIC:
1406 if (wFlags & DISPATCH_PROPERTYGET) {
1407 BOOL value;
1408 hr = IFont_get_Italic(&this->IFont_iface, &value);
1409 V_VT(pVarResult) = VT_BOOL;
1410 V_BOOL(pVarResult) = value ? VARIANT_TRUE : VARIANT_FALSE;
1411 return hr;
1412 } else {
1413 VARIANTARG vararg;
1415 VariantInit(&vararg);
1416 hr = VariantChangeTypeEx(&vararg, &pDispParams->rgvarg[0], lcid, 0, VT_BOOL);
1417 if (FAILED(hr))
1418 return hr;
1420 hr = IFont_put_Italic(&this->IFont_iface, V_BOOL(&vararg));
1422 VariantClear(&vararg);
1423 return hr;
1425 break;
1426 case DISPID_FONT_UNDER:
1427 if (wFlags & DISPATCH_PROPERTYGET) {
1428 BOOL value;
1429 hr = IFont_get_Underline(&this->IFont_iface, &value);
1430 V_VT(pVarResult) = VT_BOOL;
1431 V_BOOL(pVarResult) = value ? VARIANT_TRUE : VARIANT_FALSE;
1432 return hr;
1433 } else {
1434 VARIANTARG vararg;
1436 VariantInit(&vararg);
1437 hr = VariantChangeTypeEx(&vararg, &pDispParams->rgvarg[0], lcid, 0, VT_BOOL);
1438 if (FAILED(hr))
1439 return hr;
1441 hr = IFont_put_Underline(&this->IFont_iface, V_BOOL(&vararg));
1443 VariantClear(&vararg);
1444 return hr;
1446 break;
1447 case DISPID_FONT_STRIKE:
1448 if (wFlags & DISPATCH_PROPERTYGET) {
1449 BOOL value;
1450 hr = IFont_get_Strikethrough(&this->IFont_iface, &value);
1451 V_VT(pVarResult) = VT_BOOL;
1452 V_BOOL(pVarResult) = value ? VARIANT_TRUE : VARIANT_FALSE;
1453 return hr;
1454 } else {
1455 VARIANTARG vararg;
1457 VariantInit(&vararg);
1458 hr = VariantChangeTypeEx(&vararg, &pDispParams->rgvarg[0], lcid, 0, VT_BOOL);
1459 if (FAILED(hr))
1460 return hr;
1462 hr = IFont_put_Strikethrough(&this->IFont_iface, V_BOOL(&vararg));
1464 VariantClear(&vararg);
1465 return hr;
1467 break;
1468 case DISPID_FONT_SIZE:
1469 if (wFlags & DISPATCH_PROPERTYGET) {
1470 V_VT(pVarResult) = VT_CY;
1471 return IFont_get_Size(&this->IFont_iface, &V_CY(pVarResult));
1472 } else {
1473 VARIANTARG vararg;
1475 VariantInit(&vararg);
1476 hr = VariantChangeTypeEx(&vararg, &pDispParams->rgvarg[0], lcid, 0, VT_CY);
1477 if (FAILED(hr))
1478 return hr;
1480 hr = IFont_put_Size(&this->IFont_iface, V_CY(&vararg));
1482 VariantClear(&vararg);
1483 return hr;
1485 break;
1486 case DISPID_FONT_WEIGHT:
1487 if (wFlags & DISPATCH_PROPERTYGET) {
1488 V_VT(pVarResult) = VT_I2;
1489 return IFont_get_Weight(&this->IFont_iface, &V_I2(pVarResult));
1490 } else {
1491 VARIANTARG vararg;
1493 VariantInit(&vararg);
1494 hr = VariantChangeTypeEx(&vararg, &pDispParams->rgvarg[0], lcid, 0, VT_I2);
1495 if (FAILED(hr))
1496 return hr;
1498 hr = IFont_put_Weight(&this->IFont_iface, V_I2(&vararg));
1500 VariantClear(&vararg);
1501 return hr;
1503 break;
1504 case DISPID_FONT_CHARSET:
1505 if (wFlags & DISPATCH_PROPERTYGET) {
1506 V_VT(pVarResult) = VT_I2;
1507 return OLEFontImpl_get_Charset(&this->IFont_iface, &V_I2(pVarResult));
1508 } else {
1509 VARIANTARG vararg;
1511 VariantInit(&vararg);
1512 hr = VariantChangeTypeEx(&vararg, &pDispParams->rgvarg[0], lcid, 0, VT_I2);
1513 if (FAILED(hr))
1514 return hr;
1516 hr = IFont_put_Charset(&this->IFont_iface, V_I2(&vararg));
1518 VariantClear(&vararg);
1519 return hr;
1521 break;
1522 default:
1523 ERR("member not found for dispid 0x%x\n", dispIdMember);
1524 return DISP_E_MEMBERNOTFOUND;
1528 static const IDispatchVtbl OLEFontImpl_IDispatch_VTable =
1530 OLEFontImpl_IDispatch_QueryInterface,
1531 OLEFontImpl_IDispatch_AddRef,
1532 OLEFontImpl_IDispatch_Release,
1533 OLEFontImpl_GetTypeInfoCount,
1534 OLEFontImpl_GetTypeInfo,
1535 OLEFontImpl_GetIDsOfNames,
1536 OLEFontImpl_Invoke
1539 /************************************************************************
1540 * OLEFontImpl_IPersistStream_QueryInterface (IUnknown)
1542 static HRESULT WINAPI OLEFontImpl_IPersistStream_QueryInterface(
1543 IPersistStream* iface,
1544 REFIID riid,
1545 VOID** ppvoid)
1547 OLEFontImpl *this = impl_from_IPersistStream(iface);
1549 return IFont_QueryInterface(&this->IFont_iface, riid, ppvoid);
1552 /************************************************************************
1553 * OLEFontImpl_IPersistStream_Release (IUnknown)
1555 static ULONG WINAPI OLEFontImpl_IPersistStream_Release(
1556 IPersistStream* iface)
1558 OLEFontImpl *this = impl_from_IPersistStream(iface);
1560 return IFont_Release(&this->IFont_iface);
1563 /************************************************************************
1564 * OLEFontImpl_IPersistStream_AddRef (IUnknown)
1566 static ULONG WINAPI OLEFontImpl_IPersistStream_AddRef(
1567 IPersistStream* iface)
1569 OLEFontImpl *this = impl_from_IPersistStream(iface);
1571 return IFont_AddRef(&this->IFont_iface);
1574 /************************************************************************
1575 * OLEFontImpl_GetClassID (IPersistStream)
1577 static HRESULT WINAPI OLEFontImpl_GetClassID(
1578 IPersistStream* iface,
1579 CLSID* pClassID)
1581 TRACE("(%p,%p)\n",iface,pClassID);
1582 if (pClassID==0)
1583 return E_POINTER;
1585 *pClassID = CLSID_StdFont;
1587 return S_OK;
1590 /************************************************************************
1591 * OLEFontImpl_IsDirty (IPersistStream)
1593 * See Windows documentation for more details on IPersistStream methods.
1595 static HRESULT WINAPI OLEFontImpl_IsDirty(
1596 IPersistStream* iface)
1598 TRACE("(%p)\n",iface);
1599 return S_OK;
1602 /************************************************************************
1603 * OLEFontImpl_Load (IPersistStream)
1605 * See Windows documentation for more details on IPersistStream methods.
1607 * This is the format of the standard font serialization as far as I
1608 * know
1610 * Offset Type Value Comment
1611 * 0x0000 Byte Unknown Probably a version number, contains 0x01
1612 * 0x0001 Short Charset Charset value from the FONTDESC structure
1613 * 0x0003 Byte Attributes Flags defined as follows:
1614 * 00000010 - Italic
1615 * 00000100 - Underline
1616 * 00001000 - Strikethrough
1617 * 0x0004 Short Weight Weight value from FONTDESC structure
1618 * 0x0006 DWORD size "Low" portion of the cySize member of the FONTDESC
1619 * structure/
1620 * 0x000A Byte name length Length of the font name string (no null character)
1621 * 0x000B String name Name of the font (ASCII, no nul character)
1623 static HRESULT WINAPI OLEFontImpl_Load(
1624 IPersistStream* iface,
1625 IStream* pLoadStream)
1627 OLEFontImpl *this = impl_from_IPersistStream(iface);
1628 BYTE version, attributes, string_size;
1629 char readBuffer[0x100];
1630 ULONG cbRead;
1631 INT len;
1633 /* Version */
1634 IStream_Read(pLoadStream, &version, sizeof(BYTE), &cbRead);
1635 if ((cbRead != sizeof(BYTE)) || (version != 0x01)) return E_FAIL;
1637 /* Charset */
1638 IStream_Read(pLoadStream, &this->description.sCharset, sizeof(WORD), &cbRead);
1639 if (cbRead != sizeof(WORD)) return E_FAIL;
1641 /* Attributes */
1642 IStream_Read(pLoadStream, &attributes, sizeof(BYTE), &cbRead);
1643 if (cbRead != sizeof(BYTE)) return E_FAIL;
1645 this->description.fItalic = (attributes & FONTPERSIST_ITALIC) != 0;
1646 this->description.fStrikethrough = (attributes & FONTPERSIST_STRIKETHROUGH) != 0;
1647 this->description.fUnderline = (attributes & FONTPERSIST_UNDERLINE) != 0;
1649 /* Weight */
1650 IStream_Read(pLoadStream, &this->description.sWeight, sizeof(WORD), &cbRead);
1651 if (cbRead != sizeof(WORD)) return E_FAIL;
1653 /* Size */
1654 IStream_Read(pLoadStream, &this->description.cySize.s.Lo, sizeof(DWORD), &cbRead);
1655 if (cbRead != sizeof(DWORD)) return E_FAIL;
1657 this->description.cySize.s.Hi = 0;
1659 /* Name */
1660 IStream_Read(pLoadStream, &string_size, sizeof(BYTE), &cbRead);
1661 if (cbRead != sizeof(BYTE)) return E_FAIL;
1663 IStream_Read(pLoadStream, readBuffer, string_size, &cbRead);
1664 if (cbRead != string_size) return E_FAIL;
1666 HeapFree(GetProcessHeap(), 0, this->description.lpstrName);
1668 len = MultiByteToWideChar( CP_ACP, 0, readBuffer, string_size, NULL, 0 );
1669 this->description.lpstrName = HeapAlloc( GetProcessHeap(), 0, (len+1) * sizeof(WCHAR) );
1670 MultiByteToWideChar( CP_ACP, 0, readBuffer, string_size, this->description.lpstrName, len );
1671 this->description.lpstrName[len] = 0;
1673 /* Ensure use of this font causes a new one to be created */
1674 dec_int_ref(this->gdiFont);
1675 this->gdiFont = 0;
1676 this->dirty = TRUE;
1678 return S_OK;
1681 /************************************************************************
1682 * OLEFontImpl_Save (IPersistStream)
1684 static HRESULT WINAPI OLEFontImpl_Save(
1685 IPersistStream* iface,
1686 IStream* pOutStream,
1687 BOOL fClearDirty)
1689 OLEFontImpl *this = impl_from_IPersistStream(iface);
1690 BYTE attributes, string_size;
1691 const BYTE version = 0x01;
1692 char* writeBuffer = NULL;
1693 ULONG written;
1695 TRACE("(%p)->(%p %d)\n", this, pOutStream, fClearDirty);
1697 /* Version */
1698 IStream_Write(pOutStream, &version, sizeof(BYTE), &written);
1699 if (written != sizeof(BYTE)) return E_FAIL;
1701 /* Charset */
1702 IStream_Write(pOutStream, &this->description.sCharset, sizeof(WORD), &written);
1703 if (written != sizeof(WORD)) return E_FAIL;
1705 /* Attributes */
1706 attributes = 0;
1708 if (this->description.fItalic)
1709 attributes |= FONTPERSIST_ITALIC;
1711 if (this->description.fStrikethrough)
1712 attributes |= FONTPERSIST_STRIKETHROUGH;
1714 if (this->description.fUnderline)
1715 attributes |= FONTPERSIST_UNDERLINE;
1717 IStream_Write(pOutStream, &attributes, sizeof(BYTE), &written);
1718 if (written != sizeof(BYTE)) return E_FAIL;
1720 /* Weight */
1721 IStream_Write(pOutStream, &this->description.sWeight, sizeof(WORD), &written);
1722 if (written != sizeof(WORD)) return E_FAIL;
1724 /* Size */
1725 IStream_Write(pOutStream, &this->description.cySize.s.Lo, sizeof(DWORD), &written);
1726 if (written != sizeof(DWORD)) return E_FAIL;
1728 /* FontName */
1729 if (this->description.lpstrName)
1730 string_size = WideCharToMultiByte( CP_ACP, 0, this->description.lpstrName,
1731 strlenW(this->description.lpstrName), NULL, 0, NULL, NULL );
1732 else
1733 string_size = 0;
1735 IStream_Write(pOutStream, &string_size, sizeof(BYTE), &written);
1736 if (written != sizeof(BYTE)) return E_FAIL;
1738 if (string_size)
1740 if (!(writeBuffer = HeapAlloc( GetProcessHeap(), 0, string_size ))) return E_OUTOFMEMORY;
1741 WideCharToMultiByte( CP_ACP, 0, this->description.lpstrName,
1742 strlenW(this->description.lpstrName),
1743 writeBuffer, string_size, NULL, NULL );
1745 IStream_Write(pOutStream, writeBuffer, string_size, &written);
1746 HeapFree(GetProcessHeap(), 0, writeBuffer);
1748 if (written != string_size) return E_FAIL;
1751 return S_OK;
1754 /************************************************************************
1755 * OLEFontImpl_GetSizeMax (IPersistStream)
1757 static HRESULT WINAPI OLEFontImpl_GetSizeMax(
1758 IPersistStream* iface,
1759 ULARGE_INTEGER* pcbSize)
1761 OLEFontImpl *this = impl_from_IPersistStream(iface);
1763 if (pcbSize==NULL)
1764 return E_POINTER;
1766 pcbSize->u.HighPart = 0;
1767 pcbSize->u.LowPart = 0;
1769 pcbSize->u.LowPart += sizeof(BYTE); /* Version */
1770 pcbSize->u.LowPart += sizeof(WORD); /* Lang code */
1771 pcbSize->u.LowPart += sizeof(BYTE); /* Flags */
1772 pcbSize->u.LowPart += sizeof(WORD); /* Weight */
1773 pcbSize->u.LowPart += sizeof(DWORD); /* Size */
1774 pcbSize->u.LowPart += sizeof(BYTE); /* StrLength */
1776 if (this->description.lpstrName!=0)
1777 pcbSize->u.LowPart += WideCharToMultiByte( CP_ACP, 0, this->description.lpstrName,
1778 strlenW(this->description.lpstrName),
1779 NULL, 0, NULL, NULL );
1781 return S_OK;
1784 static const IPersistStreamVtbl OLEFontImpl_IPersistStream_VTable =
1786 OLEFontImpl_IPersistStream_QueryInterface,
1787 OLEFontImpl_IPersistStream_AddRef,
1788 OLEFontImpl_IPersistStream_Release,
1789 OLEFontImpl_GetClassID,
1790 OLEFontImpl_IsDirty,
1791 OLEFontImpl_Load,
1792 OLEFontImpl_Save,
1793 OLEFontImpl_GetSizeMax
1796 /************************************************************************
1797 * OLEFontImpl_IConnectionPointContainer_QueryInterface (IUnknown)
1799 static HRESULT WINAPI OLEFontImpl_IConnectionPointContainer_QueryInterface(
1800 IConnectionPointContainer* iface,
1801 REFIID riid,
1802 VOID** ppvoid)
1804 OLEFontImpl *this = impl_from_IConnectionPointContainer(iface);
1806 return IFont_QueryInterface(&this->IFont_iface, riid, ppvoid);
1809 /************************************************************************
1810 * OLEFontImpl_IConnectionPointContainer_Release (IUnknown)
1812 static ULONG WINAPI OLEFontImpl_IConnectionPointContainer_Release(
1813 IConnectionPointContainer* iface)
1815 OLEFontImpl *this = impl_from_IConnectionPointContainer(iface);
1817 return IFont_Release(&this->IFont_iface);
1820 /************************************************************************
1821 * OLEFontImpl_IConnectionPointContainer_AddRef (IUnknown)
1823 static ULONG WINAPI OLEFontImpl_IConnectionPointContainer_AddRef(
1824 IConnectionPointContainer* iface)
1826 OLEFontImpl *this = impl_from_IConnectionPointContainer(iface);
1828 return IFont_AddRef(&this->IFont_iface);
1831 /************************************************************************
1832 * OLEFontImpl_EnumConnectionPoints (IConnectionPointContainer)
1834 static HRESULT WINAPI OLEFontImpl_EnumConnectionPoints(
1835 IConnectionPointContainer* iface,
1836 IEnumConnectionPoints **ppEnum)
1838 OLEFontImpl *this = impl_from_IConnectionPointContainer(iface);
1840 FIXME("(%p)->(%p): stub\n", this, ppEnum);
1841 return E_NOTIMPL;
1844 /************************************************************************
1845 * OLEFontImpl_FindConnectionPoint (IConnectionPointContainer)
1847 static HRESULT WINAPI OLEFontImpl_FindConnectionPoint(
1848 IConnectionPointContainer* iface,
1849 REFIID riid,
1850 IConnectionPoint **ppCp)
1852 OLEFontImpl *this = impl_from_IConnectionPointContainer(iface);
1853 TRACE("(%p)->(%s, %p)\n", this, debugstr_guid(riid), ppCp);
1855 if(IsEqualIID(riid, &IID_IPropertyNotifySink)) {
1856 return IConnectionPoint_QueryInterface(this->pPropertyNotifyCP, &IID_IConnectionPoint,
1857 (void**)ppCp);
1858 } else if(IsEqualIID(riid, &IID_IFontEventsDisp)) {
1859 return IConnectionPoint_QueryInterface(this->pFontEventsCP, &IID_IConnectionPoint,
1860 (void**)ppCp);
1861 } else {
1862 FIXME("no connection point for %s\n", debugstr_guid(riid));
1863 return CONNECT_E_NOCONNECTION;
1867 static const IConnectionPointContainerVtbl
1868 OLEFontImpl_IConnectionPointContainer_VTable =
1870 OLEFontImpl_IConnectionPointContainer_QueryInterface,
1871 OLEFontImpl_IConnectionPointContainer_AddRef,
1872 OLEFontImpl_IConnectionPointContainer_Release,
1873 OLEFontImpl_EnumConnectionPoints,
1874 OLEFontImpl_FindConnectionPoint
1877 /************************************************************************
1878 * OLEFontImpl implementation of IPersistPropertyBag.
1880 static HRESULT WINAPI OLEFontImpl_IPersistPropertyBag_QueryInterface(
1881 IPersistPropertyBag *iface, REFIID riid, LPVOID *ppvObj
1883 OLEFontImpl *this = impl_from_IPersistPropertyBag(iface);
1884 return IFont_QueryInterface(&this->IFont_iface,riid,ppvObj);
1887 static ULONG WINAPI OLEFontImpl_IPersistPropertyBag_AddRef(
1888 IPersistPropertyBag *iface
1890 OLEFontImpl *this = impl_from_IPersistPropertyBag(iface);
1891 return IFont_AddRef(&this->IFont_iface);
1894 static ULONG WINAPI OLEFontImpl_IPersistPropertyBag_Release(
1895 IPersistPropertyBag *iface
1897 OLEFontImpl *this = impl_from_IPersistPropertyBag(iface);
1898 return IFont_Release(&this->IFont_iface);
1901 static HRESULT WINAPI OLEFontImpl_IPersistPropertyBag_GetClassID(
1902 IPersistPropertyBag *iface, CLSID *classid
1904 FIXME("(%p,%p), stub!\n", iface, classid);
1905 return E_FAIL;
1908 static HRESULT WINAPI OLEFontImpl_IPersistPropertyBag_InitNew(
1909 IPersistPropertyBag *iface
1911 FIXME("(%p), stub!\n", iface);
1912 return S_OK;
1915 static HRESULT WINAPI OLEFontImpl_IPersistPropertyBag_Load(
1916 IPersistPropertyBag *iface, IPropertyBag* pPropBag, IErrorLog* pErrorLog
1918 /* (from Visual Basic 6 property bag)
1919 Name = "MS Sans Serif"
1920 Size = 13.8
1921 Charset = 0
1922 Weight = 400
1923 Underline = 0 'False
1924 Italic = 0 'False
1925 Strikethrough = 0 'False
1927 static const WCHAR sAttrName[] = {'N','a','m','e',0};
1928 static const WCHAR sAttrSize[] = {'S','i','z','e',0};
1929 static const WCHAR sAttrCharset[] = {'C','h','a','r','s','e','t',0};
1930 static const WCHAR sAttrWeight[] = {'W','e','i','g','h','t',0};
1931 static const WCHAR sAttrUnderline[] = {'U','n','d','e','r','l','i','n','e',0};
1932 static const WCHAR sAttrItalic[] = {'I','t','a','l','i','c',0};
1933 static const WCHAR sAttrStrikethrough[] = {'S','t','r','i','k','e','t','h','r','o','u','g','h',0};
1934 OLEFontImpl *this = impl_from_IPersistPropertyBag(iface);
1935 VARIANT value;
1936 HRESULT iRes;
1938 VariantInit(&value);
1940 iRes = IPropertyBag_Read(pPropBag, sAttrName, &value, pErrorLog);
1941 if (iRes == S_OK)
1943 iRes = VariantChangeType(&value, &value, 0, VT_BSTR);
1944 if (iRes == S_OK)
1945 iRes = IFont_put_Name(&this->IFont_iface, V_BSTR(&value));
1947 else if (iRes == E_INVALIDARG)
1948 iRes = S_OK;
1950 VariantClear(&value);
1952 if (iRes == S_OK) {
1953 iRes = IPropertyBag_Read(pPropBag, sAttrSize, &value, pErrorLog);
1954 if (iRes == S_OK)
1956 iRes = VariantChangeType(&value, &value, 0, VT_CY);
1957 if (iRes == S_OK)
1958 iRes = IFont_put_Size(&this->IFont_iface, V_CY(&value));
1960 else if (iRes == E_INVALIDARG)
1961 iRes = S_OK;
1963 VariantClear(&value);
1966 if (iRes == S_OK) {
1967 iRes = IPropertyBag_Read(pPropBag, sAttrCharset, &value, pErrorLog);
1968 if (iRes == S_OK)
1970 iRes = VariantChangeType(&value, &value, 0, VT_I2);
1971 if (iRes == S_OK)
1972 iRes = IFont_put_Charset(&this->IFont_iface, V_I2(&value));
1974 else if (iRes == E_INVALIDARG)
1975 iRes = S_OK;
1977 VariantClear(&value);
1980 if (iRes == S_OK) {
1981 iRes = IPropertyBag_Read(pPropBag, sAttrWeight, &value, pErrorLog);
1982 if (iRes == S_OK)
1984 iRes = VariantChangeType(&value, &value, 0, VT_I2);
1985 if (iRes == S_OK)
1986 iRes = IFont_put_Weight(&this->IFont_iface, V_I2(&value));
1988 else if (iRes == E_INVALIDARG)
1989 iRes = S_OK;
1991 VariantClear(&value);
1994 if (iRes == S_OK) {
1995 iRes = IPropertyBag_Read(pPropBag, sAttrUnderline, &value, pErrorLog);
1996 if (iRes == S_OK)
1998 iRes = VariantChangeType(&value, &value, 0, VT_BOOL);
1999 if (iRes == S_OK)
2000 iRes = IFont_put_Underline(&this->IFont_iface, V_BOOL(&value));
2002 else if (iRes == E_INVALIDARG)
2003 iRes = S_OK;
2005 VariantClear(&value);
2008 if (iRes == S_OK) {
2009 iRes = IPropertyBag_Read(pPropBag, sAttrItalic, &value, pErrorLog);
2010 if (iRes == S_OK)
2012 iRes = VariantChangeType(&value, &value, 0, VT_BOOL);
2013 if (iRes == S_OK)
2014 iRes = IFont_put_Italic(&this->IFont_iface, V_BOOL(&value));
2016 else if (iRes == E_INVALIDARG)
2017 iRes = S_OK;
2019 VariantClear(&value);
2022 if (iRes == S_OK) {
2023 iRes = IPropertyBag_Read(pPropBag, sAttrStrikethrough, &value, pErrorLog);
2024 if (iRes == S_OK)
2026 iRes = VariantChangeType(&value, &value, 0, VT_BOOL);
2027 if (iRes == S_OK)
2028 IFont_put_Strikethrough(&this->IFont_iface, V_BOOL(&value));
2030 else if (iRes == E_INVALIDARG)
2031 iRes = S_OK;
2033 VariantClear(&value);
2036 if (FAILED(iRes))
2037 WARN("-- 0x%08x\n", iRes);
2038 return iRes;
2041 static HRESULT WINAPI OLEFontImpl_IPersistPropertyBag_Save(
2042 IPersistPropertyBag *iface, IPropertyBag* pPropBag, BOOL fClearDirty,
2043 BOOL fSaveAllProperties
2045 FIXME("(%p,%p,%d,%d), stub!\n", iface, pPropBag, fClearDirty, fSaveAllProperties);
2046 return E_FAIL;
2049 static const IPersistPropertyBagVtbl OLEFontImpl_IPersistPropertyBag_VTable =
2051 OLEFontImpl_IPersistPropertyBag_QueryInterface,
2052 OLEFontImpl_IPersistPropertyBag_AddRef,
2053 OLEFontImpl_IPersistPropertyBag_Release,
2055 OLEFontImpl_IPersistPropertyBag_GetClassID,
2056 OLEFontImpl_IPersistPropertyBag_InitNew,
2057 OLEFontImpl_IPersistPropertyBag_Load,
2058 OLEFontImpl_IPersistPropertyBag_Save
2061 /************************************************************************
2062 * OLEFontImpl implementation of IPersistStreamInit.
2064 static HRESULT WINAPI OLEFontImpl_IPersistStreamInit_QueryInterface(
2065 IPersistStreamInit *iface, REFIID riid, LPVOID *ppvObj
2067 OLEFontImpl *this = impl_from_IPersistStreamInit(iface);
2068 return IFont_QueryInterface(&this->IFont_iface,riid,ppvObj);
2071 static ULONG WINAPI OLEFontImpl_IPersistStreamInit_AddRef(
2072 IPersistStreamInit *iface
2074 OLEFontImpl *this = impl_from_IPersistStreamInit(iface);
2075 return IFont_AddRef(&this->IFont_iface);
2078 static ULONG WINAPI OLEFontImpl_IPersistStreamInit_Release(
2079 IPersistStreamInit *iface
2081 OLEFontImpl *this = impl_from_IPersistStreamInit(iface);
2082 return IFont_Release(&this->IFont_iface);
2085 static HRESULT WINAPI OLEFontImpl_IPersistStreamInit_GetClassID(
2086 IPersistStreamInit *iface, CLSID *classid
2088 FIXME("(%p,%p), stub!\n", iface, classid);
2089 return E_FAIL;
2092 static HRESULT WINAPI OLEFontImpl_IPersistStreamInit_IsDirty(
2093 IPersistStreamInit *iface
2095 FIXME("(%p), stub!\n", iface);
2096 return E_FAIL;
2099 static HRESULT WINAPI OLEFontImpl_IPersistStreamInit_Load(
2100 IPersistStreamInit *iface, LPSTREAM pStm
2102 FIXME("(%p,%p), stub!\n", iface, pStm);
2103 return E_FAIL;
2106 static HRESULT WINAPI OLEFontImpl_IPersistStreamInit_Save(
2107 IPersistStreamInit *iface, LPSTREAM pStm, BOOL fClearDirty
2109 FIXME("(%p,%p,%d), stub!\n", iface, pStm, fClearDirty);
2110 return E_FAIL;
2113 static HRESULT WINAPI OLEFontImpl_IPersistStreamInit_GetSizeMax(
2114 IPersistStreamInit *iface, ULARGE_INTEGER *pcbSize
2116 FIXME("(%p,%p), stub!\n", iface, pcbSize);
2117 return E_FAIL;
2120 static HRESULT WINAPI OLEFontImpl_IPersistStreamInit_InitNew(
2121 IPersistStreamInit *iface
2123 FIXME("(%p), stub!\n", iface);
2124 return S_OK;
2127 static const IPersistStreamInitVtbl OLEFontImpl_IPersistStreamInit_VTable =
2129 OLEFontImpl_IPersistStreamInit_QueryInterface,
2130 OLEFontImpl_IPersistStreamInit_AddRef,
2131 OLEFontImpl_IPersistStreamInit_Release,
2133 OLEFontImpl_IPersistStreamInit_GetClassID,
2134 OLEFontImpl_IPersistStreamInit_IsDirty,
2135 OLEFontImpl_IPersistStreamInit_Load,
2136 OLEFontImpl_IPersistStreamInit_Save,
2137 OLEFontImpl_IPersistStreamInit_GetSizeMax,
2138 OLEFontImpl_IPersistStreamInit_InitNew
2141 /************************************************************************
2142 * OLEFontImpl_Construct
2144 * This method will construct a new instance of the OLEFontImpl
2145 * class.
2147 * The caller of this method must release the object when it's
2148 * done with it.
2150 static OLEFontImpl* OLEFontImpl_Construct(const FONTDESC *fontDesc)
2152 OLEFontImpl* newObject;
2154 newObject = HeapAlloc(GetProcessHeap(), 0, sizeof(OLEFontImpl));
2156 if (newObject==0)
2157 return newObject;
2159 newObject->IFont_iface.lpVtbl = &OLEFontImpl_VTable;
2160 newObject->IDispatch_iface.lpVtbl = &OLEFontImpl_IDispatch_VTable;
2161 newObject->IPersistStream_iface.lpVtbl = &OLEFontImpl_IPersistStream_VTable;
2162 newObject->IConnectionPointContainer_iface.lpVtbl = &OLEFontImpl_IConnectionPointContainer_VTable;
2163 newObject->IPersistPropertyBag_iface.lpVtbl = &OLEFontImpl_IPersistPropertyBag_VTable;
2164 newObject->IPersistStreamInit_iface.lpVtbl = &OLEFontImpl_IPersistStreamInit_VTable;
2166 newObject->ref = 1;
2168 newObject->description.cbSizeofstruct = sizeof(FONTDESC);
2169 newObject->description.lpstrName = strdupW(fontDesc->lpstrName);
2170 newObject->description.cySize = fontDesc->cySize;
2171 newObject->description.sWeight = fontDesc->sWeight;
2172 newObject->description.sCharset = fontDesc->sCharset;
2173 newObject->description.fItalic = fontDesc->fItalic;
2174 newObject->description.fUnderline = fontDesc->fUnderline;
2175 newObject->description.fStrikethrough = fontDesc->fStrikethrough;
2177 newObject->gdiFont = 0;
2178 newObject->dirty = TRUE;
2179 newObject->cyLogical = GetDeviceCaps(get_dc(), LOGPIXELSY);
2180 newObject->cyHimetric = 2540L;
2181 newObject->pPropertyNotifyCP = NULL;
2182 newObject->pFontEventsCP = NULL;
2184 CreateConnectionPoint((IUnknown*)&newObject->IFont_iface, &IID_IPropertyNotifySink, &newObject->pPropertyNotifyCP);
2185 CreateConnectionPoint((IUnknown*)&newObject->IFont_iface, &IID_IFontEventsDisp, &newObject->pFontEventsCP);
2187 if (!newObject->pPropertyNotifyCP || !newObject->pFontEventsCP)
2189 OLEFontImpl_Destroy(newObject);
2190 return NULL;
2193 InterlockedIncrement(&ifont_cnt);
2195 TRACE("returning %p\n", newObject);
2196 return newObject;
2199 /************************************************************************
2200 * OLEFontImpl_Destroy
2202 * This method is called by the Release method when the reference
2203 * count goes down to 0. It will free all resources used by
2204 * this object.
2206 static void OLEFontImpl_Destroy(OLEFontImpl* fontDesc)
2208 TRACE("(%p)\n", fontDesc);
2210 HeapFree(GetProcessHeap(), 0, fontDesc->description.lpstrName);
2212 if (fontDesc->pPropertyNotifyCP)
2213 IConnectionPoint_Release(fontDesc->pPropertyNotifyCP);
2214 if (fontDesc->pFontEventsCP)
2215 IConnectionPoint_Release(fontDesc->pFontEventsCP);
2217 HeapFree(GetProcessHeap(), 0, fontDesc);
2220 /*******************************************************************************
2221 * StdFont ClassFactory
2223 typedef struct
2225 /* IUnknown fields */
2226 IClassFactory IClassFactory_iface;
2227 LONG ref;
2228 } IClassFactoryImpl;
2230 static inline IClassFactoryImpl *impl_from_IClassFactory(IClassFactory *iface)
2232 return CONTAINING_RECORD(iface, IClassFactoryImpl, IClassFactory_iface);
2235 static HRESULT WINAPI
2236 SFCF_QueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj) {
2237 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
2239 FIXME("(%p)->(%s,%p),stub!\n",This,debugstr_guid(riid),ppobj);
2240 return E_NOINTERFACE;
2243 static ULONG WINAPI
2244 SFCF_AddRef(LPCLASSFACTORY iface) {
2245 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
2246 return InterlockedIncrement(&This->ref);
2249 static ULONG WINAPI SFCF_Release(LPCLASSFACTORY iface) {
2250 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
2251 /* static class, won't be freed */
2252 return InterlockedDecrement(&This->ref);
2255 static HRESULT WINAPI SFCF_CreateInstance(
2256 LPCLASSFACTORY iface,LPUNKNOWN pOuter,REFIID riid,LPVOID *ppobj
2258 return OleCreateFontIndirect(NULL,riid,ppobj);
2262 static HRESULT WINAPI SFCF_LockServer(LPCLASSFACTORY iface,BOOL dolock) {
2263 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
2264 FIXME("(%p)->(%d),stub!\n",This,dolock);
2265 return S_OK;
2268 static const IClassFactoryVtbl SFCF_Vtbl = {
2269 SFCF_QueryInterface,
2270 SFCF_AddRef,
2271 SFCF_Release,
2272 SFCF_CreateInstance,
2273 SFCF_LockServer
2275 static IClassFactoryImpl STDFONT_CF = {{&SFCF_Vtbl}, 1 };
2277 void _get_STDFONT_CF(LPVOID *ppv) { *ppv = &STDFONT_CF; }