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
29 #define NONAMELESSUNION
30 #define NONAMELESSSTRUCT
37 #include "wine/list.h"
38 #include "wine/unicode.h"
40 #include "oleauto.h" /* for SysAllocString(....) */
43 #include "wine/debug.h"
44 #include "connpt.h" /* for CreateConnectionPoint */
47 WINE_DEFAULT_DEBUG_CHANNEL(ole);
49 /***********************************************************************
50 * Declaration of constants used when serializing the font object.
52 #define FONTPERSIST_ITALIC 0x02
53 #define FONTPERSIST_UNDERLINE 0x04
54 #define FONTPERSIST_STRIKETHROUGH 0x08
57 /***********************************************************************
58 * List of the HFONTs it has given out, with each one having a separate
61 typedef struct _HFONTItem
65 /* Reference count for that instance of the class. */
68 /* Contain the font associated with this object. */
71 } HFONTItem, *PHFONTItem;
73 static struct list OLEFontImpl_hFontList = LIST_INIT(OLEFontImpl_hFontList);
75 /* Counts how many fonts contain at least one lock */
76 static LONG ifont_cnt = 0;
78 /***********************************************************************
79 * Critical section for OLEFontImpl_hFontList
81 static CRITICAL_SECTION OLEFontImpl_csHFONTLIST;
82 static CRITICAL_SECTION_DEBUG OLEFontImpl_csHFONTLIST_debug =
84 0, 0, &OLEFontImpl_csHFONTLIST,
85 { &OLEFontImpl_csHFONTLIST_debug.ProcessLocksList,
86 &OLEFontImpl_csHFONTLIST_debug.ProcessLocksList },
87 0, 0, { (DWORD_PTR)(__FILE__ ": OLEFontImpl_csHFONTLIST") }
89 static CRITICAL_SECTION OLEFontImpl_csHFONTLIST = { &OLEFontImpl_csHFONTLIST_debug, -1, 0, 0, 0, 0 };
91 static void HFONTItem_Delete(PHFONTItem item)
93 DeleteObject(item->gdiFont);
94 list_remove(&item->entry);
95 HeapFree(GetProcessHeap(), 0, item);
98 /***********************************************************************
99 * Declaration of the implementation class for the IFont interface
101 typedef struct OLEFontImpl OLEFontImpl;
106 * This class supports many interfaces. IUnknown, IFont,
107 * IDispatch, IDispFont IPersistStream and IConnectionPointContainer.
108 * The first two are supported by the first vtable, the next two are
109 * supported by the second table and the last two have their own.
111 const IFontVtbl* lpVtbl;
112 const IDispatchVtbl* lpvtblIDispatch;
113 const IPersistStreamVtbl* lpvtblIPersistStream;
114 const IConnectionPointContainerVtbl* lpvtblIConnectionPointContainer;
115 const IPersistPropertyBagVtbl* lpvtblIPersistPropertyBag;
116 const IPersistStreamInitVtbl* lpvtblIPersistStreamInit;
118 * Reference count for that instance of the class.
123 * This structure contains the description of the class.
125 FONTDESC description;
128 * Contain the font associated with this object.
138 IConnectionPoint *pPropertyNotifyCP;
139 IConnectionPoint *pFontEventsCP;
143 * Here, I define utility macros to help with the casting of the
145 * There is a version to accommodate all of the VTables implemented
149 static inline OLEFontImpl *impl_from_IDispatch( IDispatch *iface )
151 return (OLEFontImpl *)((char*)iface - FIELD_OFFSET(OLEFontImpl, lpvtblIDispatch));
154 static inline OLEFontImpl *impl_from_IPersistStream( IPersistStream *iface )
156 return (OLEFontImpl *)((char*)iface - FIELD_OFFSET(OLEFontImpl, lpvtblIPersistStream));
159 static inline OLEFontImpl *impl_from_IConnectionPointContainer( IConnectionPointContainer *iface )
161 return (OLEFontImpl *)((char*)iface - FIELD_OFFSET(OLEFontImpl, lpvtblIConnectionPointContainer));
164 static inline OLEFontImpl *impl_from_IPersistPropertyBag( IPersistPropertyBag *iface )
166 return (OLEFontImpl *)((char*)iface - FIELD_OFFSET(OLEFontImpl, lpvtblIPersistPropertyBag));
169 static inline OLEFontImpl *impl_from_IPersistStreamInit( IPersistStreamInit *iface )
171 return (OLEFontImpl *)((char*)iface - FIELD_OFFSET(OLEFontImpl, lpvtblIPersistStreamInit));
175 /***********************************************************************
176 * Prototypes for the implementation functions for the IFont
179 static OLEFontImpl* OLEFontImpl_Construct(const FONTDESC *fontDesc);
180 static void OLEFontImpl_Destroy(OLEFontImpl* fontDesc);
181 static ULONG WINAPI OLEFontImpl_AddRef(IFont* iface);
183 /******************************************************************************
184 * OleCreateFontIndirect [OLEAUT32.420]
186 HRESULT WINAPI OleCreateFontIndirect(
187 LPFONTDESC lpFontDesc,
191 OLEFontImpl* newFont = 0;
194 TRACE("(%p, %s, %p)\n", lpFontDesc, debugstr_guid(riid), ppvObj);
206 static WCHAR fname[] = { 'S','y','s','t','e','m',0 };
208 fd.cbSizeofstruct = sizeof(fd);
209 fd.lpstrName = fname;
210 fd.cySize.s.Lo = 80000;
216 fd.fStrikethrough = 0;
221 * Try to construct a new instance of the class.
223 newFont = OLEFontImpl_Construct(lpFontDesc);
226 return E_OUTOFMEMORY;
229 * Make sure it supports the interface required by the caller.
231 hr = IFont_QueryInterface((IFont*)newFont, riid, ppvObj);
234 * Release the reference obtained in the constructor. If
235 * the QueryInterface was unsuccessful, it will free the class.
237 IFont_Release((IFont*)newFont);
243 /***********************************************************************
244 * Implementation of the OLEFontImpl class.
247 /***********************************************************************
248 * OLEFont_SendNotify (internal)
250 * Sends notification messages of changed properties to any interested
253 static void OLEFont_SendNotify(OLEFontImpl* this, DISPID dispID)
255 static const WCHAR wszName[] = {'N','a','m','e',0};
256 static const WCHAR wszSize[] = {'S','i','z','e',0};
257 static const WCHAR wszBold[] = {'B','o','l','d',0};
258 static const WCHAR wszItalic[] = {'I','t','a','l','i','c',0};
259 static const WCHAR wszUnder[] = {'U','n','d','e','r','l','i','n','e',0};
260 static const WCHAR wszStrike[] = {'S','t','r','i','k','e','t','h','r','o','u','g','h',0};
261 static const WCHAR wszWeight[] = {'W','e','i','g','h','t',0};
262 static const WCHAR wszCharset[] = {'C','h','a','r','s','s','e','t',0};
263 static const LPCWSTR dispid_mapping[] =
276 IEnumConnections *pEnum;
281 hres = IConnectionPoint_EnumConnections(this->pPropertyNotifyCP, &pEnum);
284 while(IEnumConnections_Next(pEnum, 1, &CD, NULL) == S_OK) {
285 IPropertyNotifySink *sink;
287 IUnknown_QueryInterface(CD.pUnk, &IID_IPropertyNotifySink, (LPVOID)&sink);
288 IPropertyNotifySink_OnChanged(sink, dispID);
289 IPropertyNotifySink_Release(sink);
290 IUnknown_Release(CD.pUnk);
292 IEnumConnections_Release(pEnum);
295 hres = IConnectionPoint_EnumConnections(this->pFontEventsCP, &pEnum);
298 DISPPARAMS dispparams;
301 VariantInit(&vararg);
302 V_VT(&vararg) = VT_BSTR;
303 V_BSTR(&vararg) = SysAllocString(dispid_mapping[dispID]);
305 dispparams.cArgs = 1;
306 dispparams.cNamedArgs = 0;
307 dispparams.rgdispidNamedArgs = NULL;
308 dispparams.rgvarg = &vararg;
310 while(IEnumConnections_Next(pEnum, 1, &CD, NULL) == S_OK) {
311 IFontEventsDisp *disp;
313 IUnknown_QueryInterface(CD.pUnk, &IID_IFontEventsDisp, (LPVOID)&disp);
314 IDispatch_Invoke(disp, DISPID_FONT_CHANGED, &IID_NULL,
315 LOCALE_NEUTRAL, INVOKE_FUNC, &dispparams, NULL,
318 IDispatch_Release(disp);
319 IUnknown_Release(CD.pUnk);
321 VariantClear(&vararg);
322 IEnumConnections_Release(pEnum);
326 /************************************************************************
327 * OLEFontImpl_QueryInterface (IUnknown)
329 * See Windows documentation for more details on IUnknown methods.
331 static HRESULT WINAPI OLEFontImpl_QueryInterface(
336 OLEFontImpl *this = (OLEFontImpl *)iface;
337 TRACE("(%p)->(%s, %p)\n", this, debugstr_guid(riid), ppvObject);
340 * Perform a sanity check on the parameters.
342 if ( (this==0) || (ppvObject==0) )
346 * Initialize the return parameter.
351 * Compare the riid with the interface IDs implemented by this object.
353 if (IsEqualGUID(&IID_IUnknown, riid))
354 *ppvObject = (IFont*)this;
355 if (IsEqualGUID(&IID_IFont, riid))
356 *ppvObject = (IFont*)this;
357 if (IsEqualGUID(&IID_IDispatch, riid))
358 *ppvObject = (IDispatch*)&(this->lpvtblIDispatch);
359 if (IsEqualGUID(&IID_IFontDisp, riid))
360 *ppvObject = (IDispatch*)&(this->lpvtblIDispatch);
361 if (IsEqualIID(&IID_IPersist, riid) || IsEqualGUID(&IID_IPersistStream, riid))
362 *ppvObject = (IPersistStream*)&(this->lpvtblIPersistStream);
363 if (IsEqualGUID(&IID_IConnectionPointContainer, riid))
364 *ppvObject = (IConnectionPointContainer*)&(this->lpvtblIConnectionPointContainer);
365 if (IsEqualGUID(&IID_IPersistPropertyBag, riid))
366 *ppvObject = (IPersistPropertyBag*)&(this->lpvtblIPersistPropertyBag);
367 if (IsEqualGUID(&IID_IPersistStreamInit, riid))
368 *ppvObject = (IPersistStreamInit*)&(this->lpvtblIPersistStreamInit);
371 * Check that we obtained an interface.
375 FIXME("() : asking for unsupported interface %s\n",debugstr_guid(riid));
376 return E_NOINTERFACE;
378 OLEFontImpl_AddRef((IFont*)this);
382 /************************************************************************
383 * OLEFontImpl_AddRef (IUnknown)
385 * See Windows documentation for more details on IUnknown methods.
387 static ULONG WINAPI OLEFontImpl_AddRef(
390 OLEFontImpl *this = (OLEFontImpl *)iface;
391 TRACE("(%p)->(ref=%d)\n", this, this->ref);
392 return InterlockedIncrement(&this->ref);
395 /************************************************************************
396 * OLEFontImpl_Release (IUnknown)
398 * See Windows documentation for more details on IUnknown methods.
400 static ULONG WINAPI OLEFontImpl_Release(
403 OLEFontImpl *this = (OLEFontImpl *)iface;
405 PHFONTItem ptr, next;
406 TRACE("(%p)->(ref=%d)\n", this, this->ref);
408 /* Decrease the reference count for current interface */
409 ret = InterlockedDecrement(&this->ref);
411 /* If the reference count goes down to 0, destroy. */
414 ULONG fontlist_refs = InterlockedDecrement(&ifont_cnt);
415 /* Check if all HFONT list refs are zero */
416 if (fontlist_refs == 0)
418 EnterCriticalSection(&OLEFontImpl_csHFONTLIST);
419 LIST_FOR_EACH_ENTRY_SAFE(ptr, next, &OLEFontImpl_hFontList, HFONTItem, entry)
420 HFONTItem_Delete(ptr);
421 LeaveCriticalSection(&OLEFontImpl_csHFONTLIST);
423 OLEFontImpl_Destroy(this);
429 /************************************************************************
430 * OLEFontImpl_get_Name (IFont)
432 * See Windows documentation for more details on IFont methods.
434 static HRESULT WINAPI OLEFontImpl_get_Name(
438 OLEFontImpl *this = (OLEFontImpl *)iface;
439 TRACE("(%p)->(%p)\n", this, pname);
446 if (this->description.lpstrName!=0)
447 *pname = SysAllocString(this->description.lpstrName);
454 /************************************************************************
455 * OLEFontImpl_put_Name (IFont)
457 * See Windows documentation for more details on IFont methods.
459 static HRESULT WINAPI OLEFontImpl_put_Name(
463 OLEFontImpl *this = (OLEFontImpl *)iface;
464 TRACE("(%p)->(%p)\n", this, name);
466 if (this->description.lpstrName==0)
468 this->description.lpstrName = HeapAlloc(GetProcessHeap(),
470 (lstrlenW(name)+1) * sizeof(WCHAR));
474 this->description.lpstrName = HeapReAlloc(GetProcessHeap(),
476 this->description.lpstrName,
477 (lstrlenW(name)+1) * sizeof(WCHAR));
480 if (this->description.lpstrName==0)
481 return E_OUTOFMEMORY;
483 strcpyW(this->description.lpstrName, name);
484 TRACE("new name %s\n", debugstr_w(this->description.lpstrName));
485 OLEFont_SendNotify(this, DISPID_FONT_NAME);
489 /************************************************************************
490 * OLEFontImpl_get_Size (IFont)
492 * See Windows documentation for more details on IFont methods.
494 static HRESULT WINAPI OLEFontImpl_get_Size(
498 OLEFontImpl *this = (OLEFontImpl *)iface;
499 TRACE("(%p)->(%p)\n", this, psize);
508 psize->s.Lo = this->description.cySize.s.Lo;
513 /************************************************************************
514 * OLEFontImpl_put_Size (IFont)
516 * See Windows documentation for more details on IFont methods.
518 static HRESULT WINAPI OLEFontImpl_put_Size(
522 OLEFontImpl *this = (OLEFontImpl *)iface;
523 TRACE("(%p)->(%d)\n", this, size.s.Lo);
524 this->description.cySize.s.Hi = 0;
525 this->description.cySize.s.Lo = size.s.Lo;
526 OLEFont_SendNotify(this, DISPID_FONT_SIZE);
531 /************************************************************************
532 * OLEFontImpl_get_Bold (IFont)
534 * See Windows documentation for more details on IFont methods.
536 static HRESULT WINAPI OLEFontImpl_get_Bold(
540 OLEFontImpl *this = (OLEFontImpl *)iface;
541 TRACE("(%p)->(%p)\n", this, pbold);
548 *pbold = this->description.sWeight > 550;
553 /************************************************************************
554 * OLEFontImpl_put_Bold (IFont)
556 * See Windows documentation for more details on IFont methods.
558 static HRESULT WINAPI OLEFontImpl_put_Bold(
562 OLEFontImpl *this = (OLEFontImpl *)iface;
563 TRACE("(%p)->(%d)\n", this, bold);
564 this->description.sWeight = bold ? FW_BOLD : FW_NORMAL;
565 OLEFont_SendNotify(this, DISPID_FONT_BOLD);
570 /************************************************************************
571 * OLEFontImpl_get_Italic (IFont)
573 * See Windows documentation for more details on IFont methods.
575 static HRESULT WINAPI OLEFontImpl_get_Italic(
579 OLEFontImpl *this = (OLEFontImpl *)iface;
580 TRACE("(%p)->(%p)\n", this, pitalic);
587 *pitalic = this->description.fItalic;
592 /************************************************************************
593 * OLEFontImpl_put_Italic (IFont)
595 * See Windows documentation for more details on IFont methods.
597 static HRESULT WINAPI OLEFontImpl_put_Italic(
601 OLEFontImpl *this = (OLEFontImpl *)iface;
602 TRACE("(%p)->(%d)\n", this, italic);
604 this->description.fItalic = italic;
606 OLEFont_SendNotify(this, DISPID_FONT_ITALIC);
610 /************************************************************************
611 * OLEFontImpl_get_Underline (IFont)
613 * See Windows documentation for more details on IFont methods.
615 static HRESULT WINAPI OLEFontImpl_get_Underline(
619 OLEFontImpl *this = (OLEFontImpl *)iface;
620 TRACE("(%p)->(%p)\n", this, punderline);
628 *punderline = this->description.fUnderline;
633 /************************************************************************
634 * OLEFontImpl_put_Underline (IFont)
636 * See Windows documentation for more details on IFont methods.
638 static HRESULT WINAPI OLEFontImpl_put_Underline(
642 OLEFontImpl *this = (OLEFontImpl *)iface;
643 TRACE("(%p)->(%d)\n", this, underline);
645 this->description.fUnderline = underline;
647 OLEFont_SendNotify(this, DISPID_FONT_UNDER);
651 /************************************************************************
652 * OLEFontImpl_get_Strikethrough (IFont)
654 * See Windows documentation for more details on IFont methods.
656 static HRESULT WINAPI OLEFontImpl_get_Strikethrough(
658 BOOL* pstrikethrough)
660 OLEFontImpl *this = (OLEFontImpl *)iface;
661 TRACE("(%p)->(%p)\n", this, pstrikethrough);
666 if (pstrikethrough==0)
669 *pstrikethrough = this->description.fStrikethrough;
674 /************************************************************************
675 * OLEFontImpl_put_Strikethrough (IFont)
677 * See Windows documentation for more details on IFont methods.
679 static HRESULT WINAPI OLEFontImpl_put_Strikethrough(
683 OLEFontImpl *this = (OLEFontImpl *)iface;
684 TRACE("(%p)->(%d)\n", this, strikethrough);
686 this->description.fStrikethrough = strikethrough;
687 OLEFont_SendNotify(this, DISPID_FONT_STRIKE);
692 /************************************************************************
693 * OLEFontImpl_get_Weight (IFont)
695 * See Windows documentation for more details on IFont methods.
697 static HRESULT WINAPI OLEFontImpl_get_Weight(
701 OLEFontImpl *this = (OLEFontImpl *)iface;
702 TRACE("(%p)->(%p)\n", this, pweight);
710 *pweight = this->description.sWeight;
715 /************************************************************************
716 * OLEFontImpl_put_Weight (IFont)
718 * See Windows documentation for more details on IFont methods.
720 static HRESULT WINAPI OLEFontImpl_put_Weight(
724 OLEFontImpl *this = (OLEFontImpl *)iface;
725 TRACE("(%p)->(%d)\n", this, weight);
727 this->description.sWeight = weight;
729 OLEFont_SendNotify(this, DISPID_FONT_WEIGHT);
733 /************************************************************************
734 * OLEFontImpl_get_Charset (IFont)
736 * See Windows documentation for more details on IFont methods.
738 static HRESULT WINAPI OLEFontImpl_get_Charset(
742 OLEFontImpl *this = (OLEFontImpl *)iface;
743 TRACE("(%p)->(%p)\n", this, pcharset);
751 *pcharset = this->description.sCharset;
756 /************************************************************************
757 * OLEFontImpl_put_Charset (IFont)
759 * See Windows documentation for more details on IFont methods.
761 static HRESULT WINAPI OLEFontImpl_put_Charset(
765 OLEFontImpl *this = (OLEFontImpl *)iface;
766 TRACE("(%p)->(%d)\n", this, charset);
768 this->description.sCharset = charset;
769 OLEFont_SendNotify(this, DISPID_FONT_CHARSET);
774 /************************************************************************
775 * OLEFontImpl_get_hFont (IFont)
777 * See Windows documentation for more details on IFont methods.
779 static HRESULT WINAPI OLEFontImpl_get_hFont(
783 OLEFontImpl *this = (OLEFontImpl *)iface;
784 TRACE("(%p)->(%p)\n", this, phfont);
789 * Realize the font if necessary
791 if (this->gdiFont==0)
799 * The height of the font returned by the get_Size property is the
800 * height of the font in points multiplied by 10000... Using some
801 * simple conversions and the ratio given by the application, it can
802 * be converted to a height in pixels.
804 IFont_get_Size(iface, &cySize);
806 /* Standard ratio is 72 / 2540, or 18 / 635 in lowest terms. */
807 /* Ratio is applied here relative to the standard. */
808 fontHeight = MulDiv( cySize.s.Lo, this->cyLogical*635, this->cyHimetric*18 );
810 memset(&logFont, 0, sizeof(LOGFONTW));
812 logFont.lfHeight = ((fontHeight%10000L)>5000L) ? (-fontHeight/10000L)-1 :
813 (-fontHeight/10000L);
814 logFont.lfItalic = this->description.fItalic;
815 logFont.lfUnderline = this->description.fUnderline;
816 logFont.lfStrikeOut = this->description.fStrikethrough;
817 logFont.lfWeight = this->description.sWeight;
818 logFont.lfCharSet = this->description.sCharset;
819 logFont.lfOutPrecision = OUT_CHARACTER_PRECIS;
820 logFont.lfClipPrecision = CLIP_DEFAULT_PRECIS;
821 logFont.lfQuality = DEFAULT_QUALITY;
822 logFont.lfPitchAndFamily = DEFAULT_PITCH;
823 strcpyW(logFont.lfFaceName,this->description.lpstrName);
825 this->gdiFont = CreateFontIndirectW(&logFont);
827 /* Add font to the cache */
828 newEntry = HeapAlloc(GetProcessHeap(), 0, sizeof(HFONTItem));
830 newEntry->gdiFont = this->gdiFont;
831 EnterCriticalSection(&OLEFontImpl_csHFONTLIST);
832 list_add_tail(&OLEFontImpl_hFontList,&newEntry->entry);
833 LeaveCriticalSection(&OLEFontImpl_csHFONTLIST);
836 *phfont = this->gdiFont;
837 TRACE("Returning %p\n", *phfont);
841 /************************************************************************
842 * OLEFontImpl_Clone (IFont)
844 * See Windows documentation for more details on IFont methods.
846 static HRESULT WINAPI OLEFontImpl_Clone(
850 OLEFontImpl* newObject = 0;
856 OLEFontImpl *this = (OLEFontImpl *)iface;
857 TRACE("(%p)->(%p)\n", this, ppfont);
865 * Allocate space for the object.
867 newObject = HeapAlloc(GetProcessHeap(), 0, sizeof(OLEFontImpl));
870 return E_OUTOFMEMORY;
874 /* We need to alloc new memory for the string, otherwise
875 * we free memory twice.
877 newObject->description.lpstrName = HeapAlloc(
879 (1+strlenW(this->description.lpstrName))*2
881 strcpyW(newObject->description.lpstrName, this->description.lpstrName);
882 /* We need to clone the HFONT too. This is just cut & paste from above */
883 IFont_get_Size(iface, &cySize);
885 fontHeight = MulDiv(cySize.s.Lo, this->cyLogical*635,this->cyHimetric*18);
887 memset(&logFont, 0, sizeof(LOGFONTW));
889 logFont.lfHeight = ((fontHeight%10000L)>5000L) ? (-fontHeight/10000L)-1 :
890 (-fontHeight/10000L);
891 logFont.lfItalic = this->description.fItalic;
892 logFont.lfUnderline = this->description.fUnderline;
893 logFont.lfStrikeOut = this->description.fStrikethrough;
894 logFont.lfWeight = this->description.sWeight;
895 logFont.lfCharSet = this->description.sCharset;
896 logFont.lfOutPrecision = OUT_CHARACTER_PRECIS;
897 logFont.lfClipPrecision = CLIP_DEFAULT_PRECIS;
898 logFont.lfQuality = DEFAULT_QUALITY;
899 logFont.lfPitchAndFamily = DEFAULT_PITCH;
900 strcpyW(logFont.lfFaceName,this->description.lpstrName);
902 newObject->gdiFont = CreateFontIndirectW(&logFont);
904 /* Add font to the cache */
905 InterlockedIncrement(&ifont_cnt);
906 newEntry = HeapAlloc(GetProcessHeap(), 0, sizeof(HFONTItem));
908 newEntry->gdiFont = newObject->gdiFont;
909 EnterCriticalSection(&OLEFontImpl_csHFONTLIST);
910 list_add_tail(&OLEFontImpl_hFontList,&newEntry->entry);
911 LeaveCriticalSection(&OLEFontImpl_csHFONTLIST);
913 /* create new connection points */
914 newObject->pPropertyNotifyCP = NULL;
915 newObject->pFontEventsCP = NULL;
916 CreateConnectionPoint((IUnknown*)newObject, &IID_IPropertyNotifySink, &newObject->pPropertyNotifyCP);
917 CreateConnectionPoint((IUnknown*)newObject, &IID_IFontEventsDisp, &newObject->pFontEventsCP);
919 if (!newObject->pPropertyNotifyCP || !newObject->pFontEventsCP)
921 OLEFontImpl_Destroy(newObject);
922 return E_OUTOFMEMORY;
925 /* The cloned object starts with a reference count of 1 */
928 *ppfont = (IFont*)newObject;
933 /************************************************************************
934 * OLEFontImpl_IsEqual (IFont)
936 * See Windows documentation for more details on IFont methods.
938 static HRESULT WINAPI OLEFontImpl_IsEqual(
942 OLEFontImpl *left = (OLEFontImpl *)iface;
943 OLEFontImpl *right = (OLEFontImpl *)pFontOther;
945 INT left_len,right_len;
947 if((iface == NULL) || (pFontOther == NULL))
949 else if (left->description.cySize.s.Lo != right->description.cySize.s.Lo)
951 else if (left->description.cySize.s.Hi != right->description.cySize.s.Hi)
953 else if (left->description.sWeight != right->description.sWeight)
955 else if (left->description.sCharset != right->description.sCharset)
957 else if (left->description.fItalic != right->description.fItalic)
959 else if (left->description.fUnderline != right->description.fUnderline)
961 else if (left->description.fStrikethrough != right->description.fStrikethrough)
964 /* Check from string */
965 left_len = strlenW(left->description.lpstrName);
966 right_len = strlenW(right->description.lpstrName);
967 ret = CompareStringW(0,0,left->description.lpstrName, left_len,
968 right->description.lpstrName, right_len);
969 if (ret != CSTR_EQUAL)
975 /************************************************************************
976 * OLEFontImpl_SetRatio (IFont)
978 * See Windows documentation for more details on IFont methods.
980 static HRESULT WINAPI OLEFontImpl_SetRatio(
985 OLEFontImpl *this = (OLEFontImpl *)iface;
986 TRACE("(%p)->(%d, %d)\n", this, cyLogical, cyHimetric);
988 this->cyLogical = cyLogical;
989 this->cyHimetric = cyHimetric;
994 /************************************************************************
995 * OLEFontImpl_QueryTextMetrics (IFont)
997 * See Windows documentation for more details on IFont methods.
999 static HRESULT WINAPI OLEFontImpl_QueryTextMetrics(
1004 HFONT hOldFont, hNewFont;
1007 OLEFontImpl_get_hFont(iface, &hNewFont);
1008 hOldFont = SelectObject(hdcRef, hNewFont);
1009 GetTextMetricsW(hdcRef, ptm);
1010 SelectObject(hdcRef, hOldFont);
1011 ReleaseDC(0, hdcRef);
1015 /************************************************************************
1016 * OLEFontImpl_AddRefHfont (IFont)
1018 * See Windows documentation for more details on IFont methods.
1020 static HRESULT WINAPI OLEFontImpl_AddRefHfont(
1024 OLEFontImpl *this = (OLEFontImpl *)iface;
1025 PHFONTItem ptr, next;
1026 HRESULT hres = S_FALSE; /* assume not present */
1028 TRACE("(%p)->(%p)\n", this, hfont);
1031 return E_INVALIDARG;
1033 /* Check of the hFont is already in the list */
1034 EnterCriticalSection(&OLEFontImpl_csHFONTLIST);
1035 LIST_FOR_EACH_ENTRY_SAFE(ptr, next, &OLEFontImpl_hFontList, HFONTItem, entry)
1037 if (ptr->gdiFont == hfont)
1044 LeaveCriticalSection(&OLEFontImpl_csHFONTLIST);
1049 /************************************************************************
1050 * OLEFontImpl_ReleaseHfont (IFont)
1052 * See Windows documentation for more details on IFont methods.
1054 static HRESULT WINAPI OLEFontImpl_ReleaseHfont(
1058 OLEFontImpl *this = (OLEFontImpl *)iface;
1059 PHFONTItem ptr, next;
1060 HRESULT hres = S_FALSE; /* assume not present */
1062 TRACE("(%p)->(%p)\n", this, hfont);
1065 return E_INVALIDARG;
1067 /* Check of the hFont is already in the list */
1068 EnterCriticalSection(&OLEFontImpl_csHFONTLIST);
1069 LIST_FOR_EACH_ENTRY_SAFE(ptr, next, &OLEFontImpl_hFontList, HFONTItem, entry)
1071 if ((ptr->gdiFont == hfont) && ptr->ref)
1073 /* Remove from cache and delete object if not referenced */
1076 if (ptr->gdiFont == this->gdiFont)
1077 this->gdiFont = NULL;
1083 LeaveCriticalSection(&OLEFontImpl_csHFONTLIST);
1088 /************************************************************************
1089 * OLEFontImpl_SetHdc (IFont)
1091 * See Windows documentation for more details on IFont methods.
1093 static HRESULT WINAPI OLEFontImpl_SetHdc(
1097 OLEFontImpl *this = (OLEFontImpl *)iface;
1098 FIXME("(%p)->(%p): Stub\n", this, hdc);
1103 * Virtual function tables for the OLEFontImpl class.
1105 static const IFontVtbl OLEFontImpl_VTable =
1107 OLEFontImpl_QueryInterface,
1109 OLEFontImpl_Release,
1110 OLEFontImpl_get_Name,
1111 OLEFontImpl_put_Name,
1112 OLEFontImpl_get_Size,
1113 OLEFontImpl_put_Size,
1114 OLEFontImpl_get_Bold,
1115 OLEFontImpl_put_Bold,
1116 OLEFontImpl_get_Italic,
1117 OLEFontImpl_put_Italic,
1118 OLEFontImpl_get_Underline,
1119 OLEFontImpl_put_Underline,
1120 OLEFontImpl_get_Strikethrough,
1121 OLEFontImpl_put_Strikethrough,
1122 OLEFontImpl_get_Weight,
1123 OLEFontImpl_put_Weight,
1124 OLEFontImpl_get_Charset,
1125 OLEFontImpl_put_Charset,
1126 OLEFontImpl_get_hFont,
1128 OLEFontImpl_IsEqual,
1129 OLEFontImpl_SetRatio,
1130 OLEFontImpl_QueryTextMetrics,
1131 OLEFontImpl_AddRefHfont,
1132 OLEFontImpl_ReleaseHfont,
1136 /************************************************************************
1137 * OLEFontImpl_IDispatch_QueryInterface (IUnknown)
1139 * See Windows documentation for more details on IUnknown methods.
1141 static HRESULT WINAPI OLEFontImpl_IDispatch_QueryInterface(
1146 OLEFontImpl *this = impl_from_IDispatch(iface);
1148 return IFont_QueryInterface((IFont *)this, riid, ppvoid);
1151 /************************************************************************
1152 * OLEFontImpl_IDispatch_Release (IUnknown)
1154 * See Windows documentation for more details on IUnknown methods.
1156 static ULONG WINAPI OLEFontImpl_IDispatch_Release(
1159 OLEFontImpl *this = impl_from_IDispatch(iface);
1161 return IFont_Release((IFont *)this);
1164 /************************************************************************
1165 * OLEFontImpl_IDispatch_AddRef (IUnknown)
1167 * See Windows documentation for more details on IUnknown methods.
1169 static ULONG WINAPI OLEFontImpl_IDispatch_AddRef(
1172 OLEFontImpl *this = impl_from_IDispatch(iface);
1174 return IFont_AddRef((IFont *)this);
1177 /************************************************************************
1178 * OLEFontImpl_GetTypeInfoCount (IDispatch)
1180 * See Windows documentation for more details on IDispatch methods.
1182 static HRESULT WINAPI OLEFontImpl_GetTypeInfoCount(
1184 unsigned int* pctinfo)
1186 OLEFontImpl *this = impl_from_IDispatch(iface);
1187 TRACE("(%p)->(%p)\n", this, pctinfo);
1193 /************************************************************************
1194 * OLEFontImpl_GetTypeInfo (IDispatch)
1196 * See Windows documentation for more details on IDispatch methods.
1198 static HRESULT WINAPI OLEFontImpl_GetTypeInfo(
1202 ITypeInfo** ppTInfo)
1204 static const WCHAR stdole2tlb[] = {'s','t','d','o','l','e','2','.','t','l','b',0};
1208 OLEFontImpl *this = impl_from_IDispatch(iface);
1209 TRACE("(%p, iTInfo=%d, lcid=%04x, %p)\n", this, iTInfo, (int)lcid, ppTInfo);
1212 hres = LoadTypeLib(stdole2tlb, &tl);
1214 ERR("Could not load the stdole2.tlb?\n");
1217 hres = ITypeLib_GetTypeInfoOfGuid(tl, &IID_IFontDisp, ppTInfo);
1218 ITypeLib_Release(tl);
1220 FIXME("Did not IDispatch typeinfo from typelib, hres %x\n",hres);
1225 /************************************************************************
1226 * OLEFontImpl_GetIDsOfNames (IDispatch)
1228 * See Windows documentation for more details on IDispatch methods.
1230 static HRESULT WINAPI OLEFontImpl_GetIDsOfNames(
1233 LPOLESTR* rgszNames,
1241 OLEFontImpl *this = impl_from_IDispatch(iface);
1243 TRACE("(%p,%s,%p,cNames=%d,lcid=%04x,%p)\n", this, debugstr_guid(riid),
1244 rgszNames, cNames, (int)lcid, rgDispId);
1248 return E_INVALIDARG;
1252 /* retrieve type information */
1253 hres = OLEFontImpl_GetTypeInfo(iface, 0, lcid, &pTInfo);
1257 ERR("GetTypeInfo failed.\n");
1261 /* convert names to DISPIDs */
1262 hres = DispGetIDsOfNames (pTInfo, rgszNames, cNames, rgDispId);
1263 ITypeInfo_Release(pTInfo);
1269 /************************************************************************
1270 * OLEFontImpl_Invoke (IDispatch)
1272 * See Windows documentation for more details on IDispatch methods.
1274 * Note: Do not call _put_Xxx methods, since setting things here
1275 * should not call notify functions as I found out debugging the generic
1278 static HRESULT WINAPI OLEFontImpl_Invoke(
1280 DISPID dispIdMember,
1284 DISPPARAMS* pDispParams,
1285 VARIANT* pVarResult,
1286 EXCEPINFO* pExepInfo,
1289 OLEFontImpl *this = impl_from_IDispatch(iface);
1292 TRACE("%p->(%d,%s,0x%x,0x%x,%p,%p,%p,%p)\n", this, dispIdMember,
1293 debugstr_guid(riid), lcid, wFlags, pDispParams, pVarResult, pExepInfo,
1296 /* validate parameters */
1298 if (!IsEqualIID(riid, &IID_NULL))
1300 ERR("riid was %s instead of IID_NULL\n", debugstr_guid(riid));
1301 return DISP_E_UNKNOWNINTERFACE;
1304 if (wFlags & DISPATCH_PROPERTYGET)
1308 ERR("null pVarResult not allowed when DISPATCH_PROPERTYGET specified\n");
1309 return DISP_E_PARAMNOTOPTIONAL;
1312 else if (wFlags & DISPATCH_PROPERTYPUT)
1316 ERR("null pDispParams not allowed when DISPATCH_PROPERTYPUT specified\n");
1317 return DISP_E_PARAMNOTOPTIONAL;
1319 if (pDispParams->cArgs != 1)
1321 ERR("param count for DISPATCH_PROPERTYPUT was %d instead of 1\n", pDispParams->cArgs);
1322 return DISP_E_BADPARAMCOUNT;
1327 ERR("one of DISPATCH_PROPERTYGET or DISPATCH_PROPERTYPUT must be specified\n");
1328 return DISP_E_MEMBERNOTFOUND;
1331 switch (dispIdMember) {
1332 case DISPID_FONT_NAME:
1333 if (wFlags & DISPATCH_PROPERTYGET) {
1334 V_VT(pVarResult) = VT_BSTR;
1335 return IFont_get_Name((IFont *)this, &V_BSTR(pVarResult));
1339 VariantInit(&vararg);
1340 hr = VariantChangeTypeEx(&vararg, &pDispParams->rgvarg[0], lcid, 0, VT_BSTR);
1344 hr = IFont_put_Name((IFont *)this, V_BSTR(&vararg));
1346 VariantClear(&vararg);
1350 case DISPID_FONT_BOLD:
1351 if (wFlags & DISPATCH_PROPERTYGET) {
1353 hr = IFont_get_Bold((IFont *)this, &value);
1354 V_VT(pVarResult) = VT_BOOL;
1355 V_BOOL(pVarResult) = value ? VARIANT_TRUE : VARIANT_FALSE;
1360 VariantInit(&vararg);
1361 hr = VariantChangeTypeEx(&vararg, &pDispParams->rgvarg[0], lcid, 0, VT_BOOL);
1365 hr = IFont_put_Bold((IFont *)this, V_BOOL(&vararg));
1367 VariantClear(&vararg);
1371 case DISPID_FONT_ITALIC:
1372 if (wFlags & DISPATCH_PROPERTYGET) {
1374 hr = IFont_get_Italic((IFont *)this, &value);
1375 V_VT(pVarResult) = VT_BOOL;
1376 V_BOOL(pVarResult) = value ? VARIANT_TRUE : VARIANT_FALSE;
1381 VariantInit(&vararg);
1382 hr = VariantChangeTypeEx(&vararg, &pDispParams->rgvarg[0], lcid, 0, VT_BOOL);
1386 hr = IFont_put_Italic((IFont *)this, V_BOOL(&vararg));
1388 VariantClear(&vararg);
1392 case DISPID_FONT_UNDER:
1393 if (wFlags & DISPATCH_PROPERTYGET) {
1395 hr = IFont_get_Underline((IFont *)this, &value);
1396 V_VT(pVarResult) = VT_BOOL;
1397 V_BOOL(pVarResult) = value ? VARIANT_TRUE : VARIANT_FALSE;
1402 VariantInit(&vararg);
1403 hr = VariantChangeTypeEx(&vararg, &pDispParams->rgvarg[0], lcid, 0, VT_BOOL);
1407 hr = IFont_put_Underline((IFont *)this, V_BOOL(&vararg));
1409 VariantClear(&vararg);
1413 case DISPID_FONT_STRIKE:
1414 if (wFlags & DISPATCH_PROPERTYGET) {
1416 hr = IFont_get_Strikethrough((IFont *)this, &value);
1417 V_VT(pVarResult) = VT_BOOL;
1418 V_BOOL(pVarResult) = value ? VARIANT_TRUE : VARIANT_FALSE;
1423 VariantInit(&vararg);
1424 hr = VariantChangeTypeEx(&vararg, &pDispParams->rgvarg[0], lcid, 0, VT_BOOL);
1428 hr = IFont_put_Strikethrough((IFont *)this, V_BOOL(&vararg));
1430 VariantClear(&vararg);
1434 case DISPID_FONT_SIZE:
1435 if (wFlags & DISPATCH_PROPERTYGET) {
1436 V_VT(pVarResult) = VT_CY;
1437 return OLEFontImpl_get_Size((IFont *)this, &V_CY(pVarResult));
1441 VariantInit(&vararg);
1442 hr = VariantChangeTypeEx(&vararg, &pDispParams->rgvarg[0], lcid, 0, VT_CY);
1446 hr = IFont_put_Size((IFont *)this, V_CY(&vararg));
1448 VariantClear(&vararg);
1452 case DISPID_FONT_WEIGHT:
1453 if (wFlags & DISPATCH_PROPERTYGET) {
1454 V_VT(pVarResult) = VT_I2;
1455 return OLEFontImpl_get_Weight((IFont *)this, &V_I2(pVarResult));
1459 VariantInit(&vararg);
1460 hr = VariantChangeTypeEx(&vararg, &pDispParams->rgvarg[0], lcid, 0, VT_I2);
1464 hr = IFont_put_Weight((IFont *)this, V_I2(&vararg));
1466 VariantClear(&vararg);
1470 case DISPID_FONT_CHARSET:
1471 if (wFlags & DISPATCH_PROPERTYGET) {
1472 V_VT(pVarResult) = VT_I2;
1473 return OLEFontImpl_get_Charset((IFont *)this, &V_I2(pVarResult));
1477 VariantInit(&vararg);
1478 hr = VariantChangeTypeEx(&vararg, &pDispParams->rgvarg[0], lcid, 0, VT_I2);
1482 hr = IFont_put_Charset((IFont *)this, V_I2(&vararg));
1484 VariantClear(&vararg);
1489 ERR("member not found for dispid 0x%x\n", dispIdMember);
1490 return DISP_E_MEMBERNOTFOUND;
1494 static const IDispatchVtbl OLEFontImpl_IDispatch_VTable =
1496 OLEFontImpl_IDispatch_QueryInterface,
1497 OLEFontImpl_IDispatch_AddRef,
1498 OLEFontImpl_IDispatch_Release,
1499 OLEFontImpl_GetTypeInfoCount,
1500 OLEFontImpl_GetTypeInfo,
1501 OLEFontImpl_GetIDsOfNames,
1505 /************************************************************************
1506 * OLEFontImpl_IPersistStream_QueryInterface (IUnknown)
1508 * See Windows documentation for more details on IUnknown methods.
1510 static HRESULT WINAPI OLEFontImpl_IPersistStream_QueryInterface(
1511 IPersistStream* iface,
1515 OLEFontImpl *this = impl_from_IPersistStream(iface);
1517 return IFont_QueryInterface((IFont *)this, riid, ppvoid);
1520 /************************************************************************
1521 * OLEFontImpl_IPersistStream_Release (IUnknown)
1523 * See Windows documentation for more details on IUnknown methods.
1525 static ULONG WINAPI OLEFontImpl_IPersistStream_Release(
1526 IPersistStream* iface)
1528 OLEFontImpl *this = impl_from_IPersistStream(iface);
1530 return IFont_Release((IFont *)this);
1533 /************************************************************************
1534 * OLEFontImpl_IPersistStream_AddRef (IUnknown)
1536 * See Windows documentation for more details on IUnknown methods.
1538 static ULONG WINAPI OLEFontImpl_IPersistStream_AddRef(
1539 IPersistStream* iface)
1541 OLEFontImpl *this = impl_from_IPersistStream(iface);
1543 return IFont_AddRef((IFont *)this);
1546 /************************************************************************
1547 * OLEFontImpl_GetClassID (IPersistStream)
1549 * See Windows documentation for more details on IPersistStream methods.
1551 static HRESULT WINAPI OLEFontImpl_GetClassID(
1552 IPersistStream* iface,
1555 TRACE("(%p,%p)\n",iface,pClassID);
1559 *pClassID = CLSID_StdFont;
1564 /************************************************************************
1565 * OLEFontImpl_IsDirty (IPersistStream)
1567 * See Windows documentation for more details on IPersistStream methods.
1569 static HRESULT WINAPI OLEFontImpl_IsDirty(
1570 IPersistStream* iface)
1572 TRACE("(%p)\n",iface);
1576 /************************************************************************
1577 * OLEFontImpl_Load (IPersistStream)
1579 * See Windows documentation for more details on IPersistStream methods.
1581 * This is the format of the standard font serialization as far as I
1584 * Offset Type Value Comment
1585 * 0x0000 Byte Unknown Probably a version number, contains 0x01
1586 * 0x0001 Short Charset Charset value from the FONTDESC structure
1587 * 0x0003 Byte Attributes Flags defined as follows:
1589 * 00000100 - Underline
1590 * 00001000 - Strikethrough
1591 * 0x0004 Short Weight Weight value from FONTDESC structure
1592 * 0x0006 DWORD size "Low" portion of the cySize member of the FONTDESC
1594 * 0x000A Byte name length Length of the font name string (no null character)
1595 * 0x000B String name Name of the font (ASCII, no nul character)
1597 static HRESULT WINAPI OLEFontImpl_Load(
1598 IPersistStream* iface,
1599 IStream* pLoadStream)
1601 char readBuffer[0x100];
1608 OLEFontImpl *this = impl_from_IPersistStream(iface);
1611 * Read the version byte
1613 IStream_Read(pLoadStream, &bVersion, 1, &cbRead);
1622 IStream_Read(pLoadStream, &this->description.sCharset, 2, &cbRead);
1630 IStream_Read(pLoadStream, &bAttributes, 1, &cbRead);
1635 this->description.fItalic = (bAttributes & FONTPERSIST_ITALIC) != 0;
1636 this->description.fStrikethrough = (bAttributes & FONTPERSIST_STRIKETHROUGH) != 0;
1637 this->description.fUnderline = (bAttributes & FONTPERSIST_UNDERLINE) != 0;
1642 IStream_Read(pLoadStream, &this->description.sWeight, 2, &cbRead);
1650 IStream_Read(pLoadStream, &this->description.cySize.s.Lo, 4, &cbRead);
1655 this->description.cySize.s.Hi = 0;
1660 IStream_Read(pLoadStream, &bStringSize, 1, &cbRead);
1665 IStream_Read(pLoadStream, readBuffer, bStringSize, &cbRead);
1667 if (cbRead!=bStringSize)
1670 HeapFree(GetProcessHeap(), 0, this->description.lpstrName);
1672 len = MultiByteToWideChar( CP_ACP, 0, readBuffer, bStringSize, NULL, 0 );
1673 this->description.lpstrName = HeapAlloc( GetProcessHeap(), 0, (len+1) * sizeof(WCHAR) );
1674 MultiByteToWideChar( CP_ACP, 0, readBuffer, bStringSize, this->description.lpstrName, len );
1675 this->description.lpstrName[len] = 0;
1677 /* Ensure use of this font causes a new one to be created @@@@ */
1678 DeleteObject(this->gdiFont);
1684 /************************************************************************
1685 * OLEFontImpl_Save (IPersistStream)
1687 * See Windows documentation for more details on IPersistStream methods.
1689 static HRESULT WINAPI OLEFontImpl_Save(
1690 IPersistStream* iface,
1691 IStream* pOutStream,
1694 char* writeBuffer = NULL;
1696 BYTE bVersion = 0x01;
1700 OLEFontImpl *this = impl_from_IPersistStream(iface);
1703 * Read the version byte
1705 IStream_Write(pOutStream, &bVersion, 1, &cbWritten);
1713 IStream_Write(pOutStream, &this->description.sCharset, 2, &cbWritten);
1723 if (this->description.fItalic)
1724 bAttributes |= FONTPERSIST_ITALIC;
1726 if (this->description.fStrikethrough)
1727 bAttributes |= FONTPERSIST_STRIKETHROUGH;
1729 if (this->description.fUnderline)
1730 bAttributes |= FONTPERSIST_UNDERLINE;
1732 IStream_Write(pOutStream, &bAttributes, 1, &cbWritten);
1740 IStream_Write(pOutStream, &this->description.sWeight, 2, &cbWritten);
1748 IStream_Write(pOutStream, &this->description.cySize.s.Lo, 4, &cbWritten);
1756 if (this->description.lpstrName!=0)
1757 bStringSize = WideCharToMultiByte( CP_ACP, 0, this->description.lpstrName,
1758 strlenW(this->description.lpstrName), NULL, 0, NULL, NULL );
1762 IStream_Write(pOutStream, &bStringSize, 1, &cbWritten);
1769 if (!(writeBuffer = HeapAlloc( GetProcessHeap(), 0, bStringSize ))) return E_OUTOFMEMORY;
1770 WideCharToMultiByte( CP_ACP, 0, this->description.lpstrName,
1771 strlenW(this->description.lpstrName),
1772 writeBuffer, bStringSize, NULL, NULL );
1774 IStream_Write(pOutStream, writeBuffer, bStringSize, &cbWritten);
1775 HeapFree(GetProcessHeap(), 0, writeBuffer);
1777 if (cbWritten!=bStringSize)
1784 /************************************************************************
1785 * OLEFontImpl_GetSizeMax (IPersistStream)
1787 * See Windows documentation for more details on IPersistStream methods.
1789 static HRESULT WINAPI OLEFontImpl_GetSizeMax(
1790 IPersistStream* iface,
1791 ULARGE_INTEGER* pcbSize)
1793 OLEFontImpl *this = impl_from_IPersistStream(iface);
1798 pcbSize->u.HighPart = 0;
1799 pcbSize->u.LowPart = 0;
1801 pcbSize->u.LowPart += sizeof(BYTE); /* Version */
1802 pcbSize->u.LowPart += sizeof(WORD); /* Lang code */
1803 pcbSize->u.LowPart += sizeof(BYTE); /* Flags */
1804 pcbSize->u.LowPart += sizeof(WORD); /* Weight */
1805 pcbSize->u.LowPart += sizeof(DWORD); /* Size */
1806 pcbSize->u.LowPart += sizeof(BYTE); /* StrLength */
1808 if (this->description.lpstrName!=0)
1809 pcbSize->u.LowPart += WideCharToMultiByte( CP_ACP, 0, this->description.lpstrName,
1810 strlenW(this->description.lpstrName),
1811 NULL, 0, NULL, NULL );
1816 static const IPersistStreamVtbl OLEFontImpl_IPersistStream_VTable =
1818 OLEFontImpl_IPersistStream_QueryInterface,
1819 OLEFontImpl_IPersistStream_AddRef,
1820 OLEFontImpl_IPersistStream_Release,
1821 OLEFontImpl_GetClassID,
1822 OLEFontImpl_IsDirty,
1825 OLEFontImpl_GetSizeMax
1828 /************************************************************************
1829 * OLEFontImpl_IConnectionPointContainer_QueryInterface (IUnknown)
1831 * See Windows documentation for more details on IUnknown methods.
1833 static HRESULT WINAPI OLEFontImpl_IConnectionPointContainer_QueryInterface(
1834 IConnectionPointContainer* iface,
1838 OLEFontImpl *this = impl_from_IConnectionPointContainer(iface);
1840 return IFont_QueryInterface((IFont*)this, riid, ppvoid);
1843 /************************************************************************
1844 * OLEFontImpl_IConnectionPointContainer_Release (IUnknown)
1846 * See Windows documentation for more details on IUnknown methods.
1848 static ULONG WINAPI OLEFontImpl_IConnectionPointContainer_Release(
1849 IConnectionPointContainer* iface)
1851 OLEFontImpl *this = impl_from_IConnectionPointContainer(iface);
1853 return IFont_Release((IFont*)this);
1856 /************************************************************************
1857 * OLEFontImpl_IConnectionPointContainer_AddRef (IUnknown)
1859 * See Windows documentation for more details on IUnknown methods.
1861 static ULONG WINAPI OLEFontImpl_IConnectionPointContainer_AddRef(
1862 IConnectionPointContainer* iface)
1864 OLEFontImpl *this = impl_from_IConnectionPointContainer(iface);
1866 return IFont_AddRef((IFont*)this);
1869 /************************************************************************
1870 * OLEFontImpl_EnumConnectionPoints (IConnectionPointContainer)
1872 * See Windows documentation for more details on IConnectionPointContainer
1875 static HRESULT WINAPI OLEFontImpl_EnumConnectionPoints(
1876 IConnectionPointContainer* iface,
1877 IEnumConnectionPoints **ppEnum)
1879 OLEFontImpl *this = impl_from_IConnectionPointContainer(iface);
1881 FIXME("(%p)->(%p): stub\n", this, ppEnum);
1885 /************************************************************************
1886 * OLEFontImpl_FindConnectionPoint (IConnectionPointContainer)
1888 * See Windows documentation for more details on IConnectionPointContainer
1891 static HRESULT WINAPI OLEFontImpl_FindConnectionPoint(
1892 IConnectionPointContainer* iface,
1894 IConnectionPoint **ppCp)
1896 OLEFontImpl *this = impl_from_IConnectionPointContainer(iface);
1897 TRACE("(%p)->(%s, %p)\n", this, debugstr_guid(riid), ppCp);
1899 if(IsEqualIID(riid, &IID_IPropertyNotifySink)) {
1900 return IConnectionPoint_QueryInterface(this->pPropertyNotifyCP,
1901 &IID_IConnectionPoint,
1903 } else if(IsEqualIID(riid, &IID_IFontEventsDisp)) {
1904 return IConnectionPoint_QueryInterface(this->pFontEventsCP,
1905 &IID_IConnectionPoint,
1908 FIXME("no connection point for %s\n", debugstr_guid(riid));
1909 return CONNECT_E_NOCONNECTION;
1913 static const IConnectionPointContainerVtbl
1914 OLEFontImpl_IConnectionPointContainer_VTable =
1916 OLEFontImpl_IConnectionPointContainer_QueryInterface,
1917 OLEFontImpl_IConnectionPointContainer_AddRef,
1918 OLEFontImpl_IConnectionPointContainer_Release,
1919 OLEFontImpl_EnumConnectionPoints,
1920 OLEFontImpl_FindConnectionPoint
1923 /************************************************************************
1924 * OLEFontImpl implementation of IPersistPropertyBag.
1926 static HRESULT WINAPI OLEFontImpl_IPersistPropertyBag_QueryInterface(
1927 IPersistPropertyBag *iface, REFIID riid, LPVOID *ppvObj
1929 OLEFontImpl *this = impl_from_IPersistPropertyBag(iface);
1930 return IFont_QueryInterface((IFont *)this,riid,ppvObj);
1933 static ULONG WINAPI OLEFontImpl_IPersistPropertyBag_AddRef(
1934 IPersistPropertyBag *iface
1936 OLEFontImpl *this = impl_from_IPersistPropertyBag(iface);
1937 return IFont_AddRef((IFont *)this);
1940 static ULONG WINAPI OLEFontImpl_IPersistPropertyBag_Release(
1941 IPersistPropertyBag *iface
1943 OLEFontImpl *this = impl_from_IPersistPropertyBag(iface);
1944 return IFont_Release((IFont *)this);
1947 static HRESULT WINAPI OLEFontImpl_IPersistPropertyBag_GetClassID(
1948 IPersistPropertyBag *iface, CLSID *classid
1950 FIXME("(%p,%p), stub!\n", iface, classid);
1954 static HRESULT WINAPI OLEFontImpl_IPersistPropertyBag_InitNew(
1955 IPersistPropertyBag *iface
1957 FIXME("(%p), stub!\n", iface);
1961 static HRESULT WINAPI OLEFontImpl_IPersistPropertyBag_Load(
1962 IPersistPropertyBag *iface, IPropertyBag* pPropBag, IErrorLog* pErrorLog
1964 /* (from Visual Basic 6 property bag)
1965 Name = "MS Sans Serif"
1969 Underline = 0 'False
1971 Strikethrough = 0 'False
1973 static const WCHAR sAttrName[] = {'N','a','m','e',0};
1974 static const WCHAR sAttrSize[] = {'S','i','z','e',0};
1975 static const WCHAR sAttrCharset[] = {'C','h','a','r','s','e','t',0};
1976 static const WCHAR sAttrWeight[] = {'W','e','i','g','h','t',0};
1977 static const WCHAR sAttrUnderline[] = {'U','n','d','e','r','l','i','n','e',0};
1978 static const WCHAR sAttrItalic[] = {'I','t','a','l','i','c',0};
1979 static const WCHAR sAttrStrikethrough[] = {'S','t','r','i','k','e','t','h','r','o','u','g','h',0};
1982 HRESULT iRes = S_OK;
1983 OLEFontImpl *this = impl_from_IPersistPropertyBag(iface);
1985 VariantInit(&rawAttr);
1986 VariantInit(&valueAttr);
1989 iRes = IPropertyBag_Read(pPropBag, sAttrName, &rawAttr, pErrorLog);
1992 iRes = VariantChangeType(&rawAttr, &valueAttr, 0, VT_BSTR);
1994 iRes = IFont_put_Name((IFont *)this, V_BSTR(&valueAttr));
1996 else if (iRes == E_INVALIDARG)
1998 VariantClear(&rawAttr);
1999 VariantClear(&valueAttr);
2003 iRes = IPropertyBag_Read(pPropBag, sAttrSize, &rawAttr, pErrorLog);
2006 iRes = VariantChangeType(&rawAttr, &valueAttr, 0, VT_CY);
2008 iRes = IFont_put_Size((IFont *)this, V_CY(&valueAttr));
2010 else if (iRes == E_INVALIDARG)
2012 VariantClear(&rawAttr);
2013 VariantClear(&valueAttr);
2017 iRes = IPropertyBag_Read(pPropBag, sAttrCharset, &rawAttr, pErrorLog);
2020 iRes = VariantChangeType(&rawAttr, &valueAttr, 0, VT_I2);
2022 iRes = IFont_put_Charset((IFont *)this, V_I2(&valueAttr));
2024 else if (iRes == E_INVALIDARG)
2026 VariantClear(&rawAttr);
2027 VariantClear(&valueAttr);
2031 iRes = IPropertyBag_Read(pPropBag, sAttrWeight, &rawAttr, pErrorLog);
2034 iRes = VariantChangeType(&rawAttr, &valueAttr, 0, VT_I2);
2036 iRes = IFont_put_Weight((IFont *)this, V_I2(&valueAttr));
2038 else if (iRes == E_INVALIDARG)
2040 VariantClear(&rawAttr);
2041 VariantClear(&valueAttr);
2046 iRes = IPropertyBag_Read(pPropBag, sAttrUnderline, &rawAttr, pErrorLog);
2049 iRes = VariantChangeType(&rawAttr, &valueAttr, 0, VT_BOOL);
2051 iRes = IFont_put_Underline((IFont *)this, V_BOOL(&valueAttr));
2053 else if (iRes == E_INVALIDARG)
2055 VariantClear(&rawAttr);
2056 VariantClear(&valueAttr);
2060 iRes = IPropertyBag_Read(pPropBag, sAttrItalic, &rawAttr, pErrorLog);
2063 iRes = VariantChangeType(&rawAttr, &valueAttr, 0, VT_BOOL);
2065 iRes = IFont_put_Italic((IFont *)this, V_BOOL(&valueAttr));
2067 else if (iRes == E_INVALIDARG)
2069 VariantClear(&rawAttr);
2070 VariantClear(&valueAttr);
2074 iRes = IPropertyBag_Read(pPropBag, sAttrStrikethrough, &rawAttr, pErrorLog);
2077 iRes = VariantChangeType(&rawAttr, &valueAttr, 0, VT_BOOL);
2079 IFont_put_Strikethrough((IFont *)this, V_BOOL(&valueAttr));
2081 else if (iRes == E_INVALIDARG)
2083 VariantClear(&rawAttr);
2084 VariantClear(&valueAttr);
2088 WARN("-- 0x%08x\n", iRes);
2092 static HRESULT WINAPI OLEFontImpl_IPersistPropertyBag_Save(
2093 IPersistPropertyBag *iface, IPropertyBag* pPropBag, BOOL fClearDirty,
2094 BOOL fSaveAllProperties
2096 FIXME("(%p,%p,%d,%d), stub!\n", iface, pPropBag, fClearDirty, fSaveAllProperties);
2100 static const IPersistPropertyBagVtbl OLEFontImpl_IPersistPropertyBag_VTable =
2102 OLEFontImpl_IPersistPropertyBag_QueryInterface,
2103 OLEFontImpl_IPersistPropertyBag_AddRef,
2104 OLEFontImpl_IPersistPropertyBag_Release,
2106 OLEFontImpl_IPersistPropertyBag_GetClassID,
2107 OLEFontImpl_IPersistPropertyBag_InitNew,
2108 OLEFontImpl_IPersistPropertyBag_Load,
2109 OLEFontImpl_IPersistPropertyBag_Save
2112 /************************************************************************
2113 * OLEFontImpl implementation of IPersistStreamInit.
2115 static HRESULT WINAPI OLEFontImpl_IPersistStreamInit_QueryInterface(
2116 IPersistStreamInit *iface, REFIID riid, LPVOID *ppvObj
2118 OLEFontImpl *this = impl_from_IPersistStreamInit(iface);
2119 return IFont_QueryInterface((IFont *)this,riid,ppvObj);
2122 static ULONG WINAPI OLEFontImpl_IPersistStreamInit_AddRef(
2123 IPersistStreamInit *iface
2125 OLEFontImpl *this = impl_from_IPersistStreamInit(iface);
2126 return IFont_AddRef((IFont *)this);
2129 static ULONG WINAPI OLEFontImpl_IPersistStreamInit_Release(
2130 IPersistStreamInit *iface
2132 OLEFontImpl *this = impl_from_IPersistStreamInit(iface);
2133 return IFont_Release((IFont *)this);
2136 static HRESULT WINAPI OLEFontImpl_IPersistStreamInit_GetClassID(
2137 IPersistStreamInit *iface, CLSID *classid
2139 FIXME("(%p,%p), stub!\n", iface, classid);
2143 static HRESULT WINAPI OLEFontImpl_IPersistStreamInit_IsDirty(
2144 IPersistStreamInit *iface
2146 FIXME("(%p), stub!\n", iface);
2150 static HRESULT WINAPI OLEFontImpl_IPersistStreamInit_Load(
2151 IPersistStreamInit *iface, LPSTREAM pStm
2153 FIXME("(%p,%p), stub!\n", iface, pStm);
2157 static HRESULT WINAPI OLEFontImpl_IPersistStreamInit_Save(
2158 IPersistStreamInit *iface, LPSTREAM pStm, BOOL fClearDirty
2160 FIXME("(%p,%p,%d), stub!\n", iface, pStm, fClearDirty);
2164 static HRESULT WINAPI OLEFontImpl_IPersistStreamInit_GetSizeMax(
2165 IPersistStreamInit *iface, ULARGE_INTEGER *pcbSize
2167 FIXME("(%p,%p), stub!\n", iface, pcbSize);
2171 static HRESULT WINAPI OLEFontImpl_IPersistStreamInit_InitNew(
2172 IPersistStreamInit *iface
2174 FIXME("(%p), stub!\n", iface);
2178 static const IPersistStreamInitVtbl OLEFontImpl_IPersistStreamInit_VTable =
2180 OLEFontImpl_IPersistStreamInit_QueryInterface,
2181 OLEFontImpl_IPersistStreamInit_AddRef,
2182 OLEFontImpl_IPersistStreamInit_Release,
2184 OLEFontImpl_IPersistStreamInit_GetClassID,
2185 OLEFontImpl_IPersistStreamInit_IsDirty,
2186 OLEFontImpl_IPersistStreamInit_Load,
2187 OLEFontImpl_IPersistStreamInit_Save,
2188 OLEFontImpl_IPersistStreamInit_GetSizeMax,
2189 OLEFontImpl_IPersistStreamInit_InitNew
2192 /************************************************************************
2193 * OLEFontImpl_Construct
2195 * This method will construct a new instance of the OLEFontImpl
2198 * The caller of this method must release the object when it's
2201 static OLEFontImpl* OLEFontImpl_Construct(const FONTDESC *fontDesc)
2203 OLEFontImpl* newObject = 0;
2206 * Allocate space for the object.
2208 newObject = HeapAlloc(GetProcessHeap(), 0, sizeof(OLEFontImpl));
2214 * Initialize the virtual function table.
2216 newObject->lpVtbl = &OLEFontImpl_VTable;
2217 newObject->lpvtblIDispatch = &OLEFontImpl_IDispatch_VTable;
2218 newObject->lpvtblIPersistStream = &OLEFontImpl_IPersistStream_VTable;
2219 newObject->lpvtblIConnectionPointContainer = &OLEFontImpl_IConnectionPointContainer_VTable;
2220 newObject->lpvtblIPersistPropertyBag = &OLEFontImpl_IPersistPropertyBag_VTable;
2221 newObject->lpvtblIPersistStreamInit = &OLEFontImpl_IPersistStreamInit_VTable;
2224 * Start with one reference count. The caller of this function
2225 * must release the interface pointer when it is done.
2230 * Copy the description of the font in the object.
2232 assert(fontDesc->cbSizeofstruct >= sizeof(FONTDESC));
2234 newObject->description.cbSizeofstruct = sizeof(FONTDESC);
2235 newObject->description.lpstrName = HeapAlloc(GetProcessHeap(),
2237 (lstrlenW(fontDesc->lpstrName)+1) * sizeof(WCHAR));
2238 strcpyW(newObject->description.lpstrName, fontDesc->lpstrName);
2239 newObject->description.cySize = fontDesc->cySize;
2240 newObject->description.sWeight = fontDesc->sWeight;
2241 newObject->description.sCharset = fontDesc->sCharset;
2242 newObject->description.fItalic = fontDesc->fItalic;
2243 newObject->description.fUnderline = fontDesc->fUnderline;
2244 newObject->description.fStrikethrough = fontDesc->fStrikethrough;
2247 * Initializing all the other members.
2249 newObject->gdiFont = 0;
2250 newObject->cyLogical = 72L;
2251 newObject->cyHimetric = 2540L;
2252 newObject->pPropertyNotifyCP = NULL;
2253 newObject->pFontEventsCP = NULL;
2255 CreateConnectionPoint((IUnknown*)newObject, &IID_IPropertyNotifySink, &newObject->pPropertyNotifyCP);
2256 CreateConnectionPoint((IUnknown*)newObject, &IID_IFontEventsDisp, &newObject->pFontEventsCP);
2258 if (!newObject->pPropertyNotifyCP || !newObject->pFontEventsCP)
2260 OLEFontImpl_Destroy(newObject);
2264 InterlockedIncrement(&ifont_cnt);
2266 TRACE("returning %p\n", newObject);
2270 /************************************************************************
2271 * OLEFontImpl_Destroy
2273 * This method is called by the Release method when the reference
2274 * count goes down to 0. It will free all resources used by
2277 static void OLEFontImpl_Destroy(OLEFontImpl* fontDesc)
2279 TRACE("(%p)\n", fontDesc);
2281 HeapFree(GetProcessHeap(), 0, fontDesc->description.lpstrName);
2283 if (fontDesc->gdiFont!=0)
2284 DeleteObject(fontDesc->gdiFont);
2286 if (fontDesc->pPropertyNotifyCP)
2287 IConnectionPoint_Release(fontDesc->pPropertyNotifyCP);
2288 if (fontDesc->pFontEventsCP)
2289 IConnectionPoint_Release(fontDesc->pFontEventsCP);
2291 HeapFree(GetProcessHeap(), 0, fontDesc);
2294 /*******************************************************************************
2295 * StdFont ClassFactory
2299 /* IUnknown fields */
2300 const IClassFactoryVtbl *lpVtbl;
2302 } IClassFactoryImpl;
2304 static HRESULT WINAPI
2305 SFCF_QueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj) {
2306 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
2308 FIXME("(%p)->(%s,%p),stub!\n",This,debugstr_guid(riid),ppobj);
2309 return E_NOINTERFACE;
2313 SFCF_AddRef(LPCLASSFACTORY iface) {
2314 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
2315 return InterlockedIncrement(&This->ref);
2318 static ULONG WINAPI SFCF_Release(LPCLASSFACTORY iface) {
2319 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
2320 /* static class, won't be freed */
2321 return InterlockedDecrement(&This->ref);
2324 static HRESULT WINAPI SFCF_CreateInstance(
2325 LPCLASSFACTORY iface,LPUNKNOWN pOuter,REFIID riid,LPVOID *ppobj
2327 return OleCreateFontIndirect(NULL,riid,ppobj);
2331 static HRESULT WINAPI SFCF_LockServer(LPCLASSFACTORY iface,BOOL dolock) {
2332 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
2333 FIXME("(%p)->(%d),stub!\n",This,dolock);
2337 static const IClassFactoryVtbl SFCF_Vtbl = {
2338 SFCF_QueryInterface,
2341 SFCF_CreateInstance,
2344 static IClassFactoryImpl STDFONT_CF = {&SFCF_Vtbl, 1 };
2346 void _get_STDFONT_CF(LPVOID *ppv) { *ppv = (LPVOID)&STDFONT_CF; }