dpnet: Assign to structs instead of using memcpy.
[wine.git] / dlls / oleaut32 / olefont.c
blobfe787a7db704dcc63bc4462a31f51d366ee02575
1 /*
2 * OLE Font encapsulation implementation
4 * This file contains an implementation of the IFont
5 * interface and the OleCreateFontIndirect API call.
7 * Copyright 1999 Francis Beaudet
8 * Copyright 2006 (Google) Benjamin Arai
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #include <assert.h>
25 #include <stdarg.h>
26 #include <string.h>
28 #define COBJMACROS
29 #define NONAMELESSUNION
30 #define NONAMELESSSTRUCT
32 #include "winerror.h"
33 #include "windef.h"
34 #include "winbase.h"
35 #include "wingdi.h"
36 #include "winuser.h"
37 #include "wine/list.h"
38 #include "wine/unicode.h"
39 #include "objbase.h"
40 #include "oleauto.h" /* for SysAllocString(....) */
41 #include "ole2.h"
42 #include "olectl.h"
43 #include "wine/debug.h"
44 #include "connpt.h" /* for CreateConnectionPoint */
45 #include "oaidl.h"
47 WINE_DEFAULT_DEBUG_CHANNEL(ole);
49 /***********************************************************************
50 * Declaration of constants used when serializing the font object.
52 #define FONTPERSIST_ITALIC 0x02
53 #define FONTPERSIST_UNDERLINE 0x04
54 #define FONTPERSIST_STRIKETHROUGH 0x08
57 /***********************************************************************
58 * List of the HFONTs it has given out, with each one having a separate
59 * ref count.
61 typedef struct _HFONTItem
63 struct list entry;
65 /* Reference count for that instance of the class. */
66 LONG ref;
68 /* Contain the font associated with this object. */
69 HFONT gdiFont;
71 } HFONTItem, *PHFONTItem;
73 static struct list OLEFontImpl_hFontList = LIST_INIT(OLEFontImpl_hFontList);
75 /* Counts how many fonts contain at least one lock */
76 static LONG ifont_cnt = 0;
78 /***********************************************************************
79 * Critical section for OLEFontImpl_hFontList
81 static CRITICAL_SECTION OLEFontImpl_csHFONTLIST;
82 static CRITICAL_SECTION_DEBUG OLEFontImpl_csHFONTLIST_debug =
84 0, 0, &OLEFontImpl_csHFONTLIST,
85 { &OLEFontImpl_csHFONTLIST_debug.ProcessLocksList,
86 &OLEFontImpl_csHFONTLIST_debug.ProcessLocksList },
87 0, 0, { (DWORD_PTR)(__FILE__ ": OLEFontImpl_csHFONTLIST") }
89 static CRITICAL_SECTION OLEFontImpl_csHFONTLIST = { &OLEFontImpl_csHFONTLIST_debug, -1, 0, 0, 0, 0 };
91 static void HFONTItem_Delete(PHFONTItem item)
93 DeleteObject(item->gdiFont);
94 list_remove(&item->entry);
95 HeapFree(GetProcessHeap(), 0, item);
98 /***********************************************************************
99 * Declaration of the implementation class for the IFont interface
101 typedef struct OLEFontImpl OLEFontImpl;
103 struct OLEFontImpl
106 * This class supports many interfaces. IUnknown, IFont,
107 * IDispatch, IDispFont IPersistStream and IConnectionPointContainer.
108 * The first two are supported by the first vtable, the next two are
109 * supported by the second table and the last two have their own.
111 const IFontVtbl* lpVtbl;
112 const IDispatchVtbl* lpvtblIDispatch;
113 const IPersistStreamVtbl* lpvtblIPersistStream;
114 const IConnectionPointContainerVtbl* lpvtblIConnectionPointContainer;
115 const IPersistPropertyBagVtbl* lpvtblIPersistPropertyBag;
116 const IPersistStreamInitVtbl* lpvtblIPersistStreamInit;
118 * Reference count for that instance of the class.
120 LONG ref;
123 * This structure contains the description of the class.
125 FONTDESC description;
128 * Contain the font associated with this object.
130 HFONT gdiFont;
133 * Size ratio
135 long cyLogical;
136 long cyHimetric;
138 IConnectionPoint *pPropertyNotifyCP;
139 IConnectionPoint *pFontEventsCP;
143 * Here, I define utility macros to help with the casting of the
144 * "this" parameter.
145 * There is a version to accommodate all of the VTables implemented
146 * by this object.
149 static inline OLEFontImpl *impl_from_IDispatch( IDispatch *iface )
151 return (OLEFontImpl *)((char*)iface - FIELD_OFFSET(OLEFontImpl, lpvtblIDispatch));
154 static inline OLEFontImpl *impl_from_IPersistStream( IPersistStream *iface )
156 return (OLEFontImpl *)((char*)iface - FIELD_OFFSET(OLEFontImpl, lpvtblIPersistStream));
159 static inline OLEFontImpl *impl_from_IConnectionPointContainer( IConnectionPointContainer *iface )
161 return (OLEFontImpl *)((char*)iface - FIELD_OFFSET(OLEFontImpl, lpvtblIConnectionPointContainer));
164 static inline OLEFontImpl *impl_from_IPersistPropertyBag( IPersistPropertyBag *iface )
166 return (OLEFontImpl *)((char*)iface - FIELD_OFFSET(OLEFontImpl, lpvtblIPersistPropertyBag));
169 static inline OLEFontImpl *impl_from_IPersistStreamInit( IPersistStreamInit *iface )
171 return (OLEFontImpl *)((char*)iface - FIELD_OFFSET(OLEFontImpl, lpvtblIPersistStreamInit));
175 /***********************************************************************
176 * Prototypes for the implementation functions for the IFont
177 * interface
179 static OLEFontImpl* OLEFontImpl_Construct(const FONTDESC *fontDesc);
180 static void OLEFontImpl_Destroy(OLEFontImpl* fontDesc);
181 static ULONG WINAPI OLEFontImpl_AddRef(IFont* iface);
183 /******************************************************************************
184 * OleCreateFontIndirect [OLEAUT32.420]
186 HRESULT WINAPI OleCreateFontIndirect(
187 LPFONTDESC lpFontDesc,
188 REFIID riid,
189 LPVOID* ppvObj)
191 OLEFontImpl* newFont = 0;
192 HRESULT hr = S_OK;
194 TRACE("(%p, %s, %p)\n", lpFontDesc, debugstr_guid(riid), ppvObj);
196 * Sanity check
198 if (ppvObj==0)
199 return E_POINTER;
201 *ppvObj = 0;
203 if (!lpFontDesc) {
204 FONTDESC fd;
206 static WCHAR fname[] = { 'S','y','s','t','e','m',0 };
208 fd.cbSizeofstruct = sizeof(fd);
209 fd.lpstrName = fname;
210 fd.cySize.s.Lo = 80000;
211 fd.cySize.s.Hi = 0;
212 fd.sWeight = 0;
213 fd.sCharset = 0;
214 fd.fItalic = 0;
215 fd.fUnderline = 0;
216 fd.fStrikethrough = 0;
217 lpFontDesc = &fd;
221 * Try to construct a new instance of the class.
223 newFont = OLEFontImpl_Construct(lpFontDesc);
225 if (newFont == 0)
226 return E_OUTOFMEMORY;
229 * Make sure it supports the interface required by the caller.
231 hr = IFont_QueryInterface((IFont*)newFont, riid, ppvObj);
234 * Release the reference obtained in the constructor. If
235 * the QueryInterface was unsuccessful, it will free the class.
237 IFont_Release((IFont*)newFont);
239 return hr;
243 /***********************************************************************
244 * Implementation of the OLEFontImpl class.
247 /***********************************************************************
248 * OLEFont_SendNotify (internal)
250 * Sends notification messages of changed properties to any interested
251 * connections.
253 static void OLEFont_SendNotify(OLEFontImpl* this, DISPID dispID)
255 static const WCHAR wszName[] = {'N','a','m','e',0};
256 static const WCHAR wszSize[] = {'S','i','z','e',0};
257 static const WCHAR wszBold[] = {'B','o','l','d',0};
258 static const WCHAR wszItalic[] = {'I','t','a','l','i','c',0};
259 static const WCHAR wszUnder[] = {'U','n','d','e','r','l','i','n','e',0};
260 static const WCHAR wszStrike[] = {'S','t','r','i','k','e','t','h','r','o','u','g','h',0};
261 static const WCHAR wszWeight[] = {'W','e','i','g','h','t',0};
262 static const WCHAR wszCharset[] = {'C','h','a','r','s','s','e','t',0};
263 static const LPCWSTR dispid_mapping[] =
265 wszName,
266 NULL,
267 wszSize,
268 wszBold,
269 wszItalic,
270 wszUnder,
271 wszStrike,
272 wszWeight,
273 wszCharset
276 IEnumConnections *pEnum;
277 CONNECTDATA CD;
278 HRESULT hres;
280 this->gdiFont = 0;
281 hres = IConnectionPoint_EnumConnections(this->pPropertyNotifyCP, &pEnum);
282 if (SUCCEEDED(hres))
284 while(IEnumConnections_Next(pEnum, 1, &CD, NULL) == S_OK) {
285 IPropertyNotifySink *sink;
287 IUnknown_QueryInterface(CD.pUnk, &IID_IPropertyNotifySink, (LPVOID)&sink);
288 IPropertyNotifySink_OnChanged(sink, dispID);
289 IPropertyNotifySink_Release(sink);
290 IUnknown_Release(CD.pUnk);
292 IEnumConnections_Release(pEnum);
295 hres = IConnectionPoint_EnumConnections(this->pFontEventsCP, &pEnum);
296 if (SUCCEEDED(hres))
298 DISPPARAMS dispparams;
299 VARIANTARG vararg;
301 VariantInit(&vararg);
302 V_VT(&vararg) = VT_BSTR;
303 V_BSTR(&vararg) = SysAllocString(dispid_mapping[dispID]);
305 dispparams.cArgs = 1;
306 dispparams.cNamedArgs = 0;
307 dispparams.rgdispidNamedArgs = NULL;
308 dispparams.rgvarg = &vararg;
310 while(IEnumConnections_Next(pEnum, 1, &CD, NULL) == S_OK) {
311 IFontEventsDisp *disp;
313 IUnknown_QueryInterface(CD.pUnk, &IID_IFontEventsDisp, (LPVOID)&disp);
314 IDispatch_Invoke(disp, DISPID_FONT_CHANGED, &IID_NULL,
315 LOCALE_NEUTRAL, INVOKE_FUNC, &dispparams, NULL,
316 NULL, NULL);
318 IDispatch_Release(disp);
319 IUnknown_Release(CD.pUnk);
321 VariantClear(&vararg);
322 IEnumConnections_Release(pEnum);
326 /************************************************************************
327 * OLEFontImpl_QueryInterface (IUnknown)
329 * See Windows documentation for more details on IUnknown methods.
331 HRESULT WINAPI OLEFontImpl_QueryInterface(
332 IFont* iface,
333 REFIID riid,
334 void** ppvObject)
336 OLEFontImpl *this = (OLEFontImpl *)iface;
337 TRACE("(%p)->(%s, %p)\n", this, debugstr_guid(riid), ppvObject);
340 * Perform a sanity check on the parameters.
342 if ( (this==0) || (ppvObject==0) )
343 return E_INVALIDARG;
346 * Initialize the return parameter.
348 *ppvObject = 0;
351 * Compare the riid with the interface IDs implemented by this object.
353 if (IsEqualGUID(&IID_IUnknown, riid))
354 *ppvObject = (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.
373 if ((*ppvObject)==0)
375 FIXME("() : asking for unsupported interface %s\n",debugstr_guid(riid));
376 return E_NOINTERFACE;
378 OLEFontImpl_AddRef((IFont*)this);
379 return S_OK;
382 /************************************************************************
383 * OLEFontImpl_AddRef (IUnknown)
385 * See Windows documentation for more details on IUnknown methods.
387 ULONG WINAPI OLEFontImpl_AddRef(
388 IFont* iface)
390 OLEFontImpl *this = (OLEFontImpl *)iface;
391 TRACE("(%p)->(ref=%d)\n", this, this->ref);
392 return InterlockedIncrement(&this->ref);
395 /************************************************************************
396 * OLEFontImpl_Release (IUnknown)
398 * See Windows documentation for more details on IUnknown methods.
400 ULONG WINAPI OLEFontImpl_Release(
401 IFont* iface)
403 OLEFontImpl *this = (OLEFontImpl *)iface;
404 ULONG ret;
405 PHFONTItem ptr, next;
406 TRACE("(%p)->(ref=%d)\n", this, this->ref);
408 /* Decrease the reference count for current interface */
409 ret = InterlockedDecrement(&this->ref);
411 /* If the reference count goes down to 0, destroy. */
412 if (ret == 0)
414 ULONG fontlist_refs = InterlockedDecrement(&ifont_cnt);
415 /* Check if all HFONT list refs are zero */
416 if (fontlist_refs == 0)
418 EnterCriticalSection(&OLEFontImpl_csHFONTLIST);
419 LIST_FOR_EACH_ENTRY_SAFE(ptr, next, &OLEFontImpl_hFontList, HFONTItem, entry)
420 HFONTItem_Delete(ptr);
421 LeaveCriticalSection(&OLEFontImpl_csHFONTLIST);
423 OLEFontImpl_Destroy(this);
426 return ret;
429 /************************************************************************
430 * OLEFontImpl_get_Name (IFont)
432 * See Windows documentation for more details on IFont methods.
434 static HRESULT WINAPI OLEFontImpl_get_Name(
435 IFont* iface,
436 BSTR* pname)
438 OLEFontImpl *this = (OLEFontImpl *)iface;
439 TRACE("(%p)->(%p)\n", this, pname);
441 * Sanity check.
443 if (pname==0)
444 return E_POINTER;
446 if (this->description.lpstrName!=0)
447 *pname = SysAllocString(this->description.lpstrName);
448 else
449 *pname = 0;
451 return S_OK;
454 /************************************************************************
455 * OLEFontImpl_put_Name (IFont)
457 * See Windows documentation for more details on IFont methods.
459 static HRESULT WINAPI OLEFontImpl_put_Name(
460 IFont* iface,
461 BSTR name)
463 OLEFontImpl *this = (OLEFontImpl *)iface;
464 TRACE("(%p)->(%p)\n", this, name);
466 if (this->description.lpstrName==0)
468 this->description.lpstrName = HeapAlloc(GetProcessHeap(),
470 (lstrlenW(name)+1) * sizeof(WCHAR));
472 else
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);
486 return S_OK;
489 /************************************************************************
490 * OLEFontImpl_get_Size (IFont)
492 * See Windows documentation for more details on IFont methods.
494 static HRESULT WINAPI OLEFontImpl_get_Size(
495 IFont* iface,
496 CY* psize)
498 OLEFontImpl *this = (OLEFontImpl *)iface;
499 TRACE("(%p)->(%p)\n", this, psize);
502 * Sanity check
504 if (psize==0)
505 return E_POINTER;
507 psize->s.Hi = 0;
508 psize->s.Lo = this->description.cySize.s.Lo;
510 return S_OK;
513 /************************************************************************
514 * OLEFontImpl_put_Size (IFont)
516 * See Windows documentation for more details on IFont methods.
518 static HRESULT WINAPI OLEFontImpl_put_Size(
519 IFont* iface,
520 CY 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);
528 return S_OK;
531 /************************************************************************
532 * OLEFontImpl_get_Bold (IFont)
534 * See Windows documentation for more details on IFont methods.
536 static HRESULT WINAPI OLEFontImpl_get_Bold(
537 IFont* iface,
538 BOOL* pbold)
540 OLEFontImpl *this = (OLEFontImpl *)iface;
541 TRACE("(%p)->(%p)\n", this, pbold);
543 * Sanity check
545 if (pbold==0)
546 return E_POINTER;
548 *pbold = this->description.sWeight > 550;
550 return S_OK;
553 /************************************************************************
554 * OLEFontImpl_put_Bold (IFont)
556 * See Windows documentation for more details on IFont methods.
558 static HRESULT WINAPI OLEFontImpl_put_Bold(
559 IFont* iface,
560 BOOL 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);
567 return S_OK;
570 /************************************************************************
571 * OLEFontImpl_get_Italic (IFont)
573 * See Windows documentation for more details on IFont methods.
575 static HRESULT WINAPI OLEFontImpl_get_Italic(
576 IFont* iface,
577 BOOL* pitalic)
579 OLEFontImpl *this = (OLEFontImpl *)iface;
580 TRACE("(%p)->(%p)\n", this, pitalic);
582 * Sanity check
584 if (pitalic==0)
585 return E_POINTER;
587 *pitalic = this->description.fItalic;
589 return S_OK;
592 /************************************************************************
593 * OLEFontImpl_put_Italic (IFont)
595 * See Windows documentation for more details on IFont methods.
597 static HRESULT WINAPI OLEFontImpl_put_Italic(
598 IFont* iface,
599 BOOL 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);
607 return S_OK;
610 /************************************************************************
611 * OLEFontImpl_get_Underline (IFont)
613 * See Windows documentation for more details on IFont methods.
615 static HRESULT WINAPI OLEFontImpl_get_Underline(
616 IFont* iface,
617 BOOL* punderline)
619 OLEFontImpl *this = (OLEFontImpl *)iface;
620 TRACE("(%p)->(%p)\n", this, punderline);
623 * Sanity check
625 if (punderline==0)
626 return E_POINTER;
628 *punderline = this->description.fUnderline;
630 return S_OK;
633 /************************************************************************
634 * OLEFontImpl_put_Underline (IFont)
636 * See Windows documentation for more details on IFont methods.
638 static HRESULT WINAPI OLEFontImpl_put_Underline(
639 IFont* iface,
640 BOOL 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);
648 return S_OK;
651 /************************************************************************
652 * OLEFontImpl_get_Strikethrough (IFont)
654 * See Windows documentation for more details on IFont methods.
656 static HRESULT WINAPI OLEFontImpl_get_Strikethrough(
657 IFont* iface,
658 BOOL* pstrikethrough)
660 OLEFontImpl *this = (OLEFontImpl *)iface;
661 TRACE("(%p)->(%p)\n", this, pstrikethrough);
664 * Sanity check
666 if (pstrikethrough==0)
667 return E_POINTER;
669 *pstrikethrough = this->description.fStrikethrough;
671 return S_OK;
674 /************************************************************************
675 * OLEFontImpl_put_Strikethrough (IFont)
677 * See Windows documentation for more details on IFont methods.
679 static HRESULT WINAPI OLEFontImpl_put_Strikethrough(
680 IFont* iface,
681 BOOL 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);
689 return S_OK;
692 /************************************************************************
693 * OLEFontImpl_get_Weight (IFont)
695 * See Windows documentation for more details on IFont methods.
697 static HRESULT WINAPI OLEFontImpl_get_Weight(
698 IFont* iface,
699 short* pweight)
701 OLEFontImpl *this = (OLEFontImpl *)iface;
702 TRACE("(%p)->(%p)\n", this, pweight);
705 * Sanity check
707 if (pweight==0)
708 return E_POINTER;
710 *pweight = this->description.sWeight;
712 return S_OK;
715 /************************************************************************
716 * OLEFontImpl_put_Weight (IFont)
718 * See Windows documentation for more details on IFont methods.
720 static HRESULT WINAPI OLEFontImpl_put_Weight(
721 IFont* iface,
722 short 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);
730 return S_OK;
733 /************************************************************************
734 * OLEFontImpl_get_Charset (IFont)
736 * See Windows documentation for more details on IFont methods.
738 static HRESULT WINAPI OLEFontImpl_get_Charset(
739 IFont* iface,
740 short* pcharset)
742 OLEFontImpl *this = (OLEFontImpl *)iface;
743 TRACE("(%p)->(%p)\n", this, pcharset);
746 * Sanity check
748 if (pcharset==0)
749 return E_POINTER;
751 *pcharset = this->description.sCharset;
753 return S_OK;
756 /************************************************************************
757 * OLEFontImpl_put_Charset (IFont)
759 * See Windows documentation for more details on IFont methods.
761 static HRESULT WINAPI OLEFontImpl_put_Charset(
762 IFont* iface,
763 short 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);
771 return S_OK;
774 /************************************************************************
775 * OLEFontImpl_get_hFont (IFont)
777 * See Windows documentation for more details on IFont methods.
779 static HRESULT WINAPI OLEFontImpl_get_hFont(
780 IFont* iface,
781 HFONT* phfont)
783 OLEFontImpl *this = (OLEFontImpl *)iface;
784 TRACE("(%p)->(%p)\n", this, phfont);
785 if (phfont==NULL)
786 return E_POINTER;
789 * Realize the font if necessary
791 if (this->gdiFont==0)
793 LOGFONTW logFont;
794 INT fontHeight;
795 CY cySize;
796 PHFONTItem newEntry;
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));
829 newEntry->ref = 1;
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);
838 return S_OK;
841 /************************************************************************
842 * OLEFontImpl_Clone (IFont)
844 * See Windows documentation for more details on IFont methods.
846 static HRESULT WINAPI OLEFontImpl_Clone(
847 IFont* iface,
848 IFont** ppfont)
850 OLEFontImpl* newObject = 0;
851 LOGFONTW logFont;
852 INT fontHeight;
853 CY cySize;
854 PHFONTItem newEntry;
856 OLEFontImpl *this = (OLEFontImpl *)iface;
857 TRACE("(%p)->(%p)\n", this, ppfont);
859 if (ppfont == NULL)
860 return E_POINTER;
862 *ppfont = NULL;
865 * Allocate space for the object.
867 newObject = HeapAlloc(GetProcessHeap(), 0, sizeof(OLEFontImpl));
869 if (newObject==NULL)
870 return E_OUTOFMEMORY;
872 *newObject = *this;
874 /* We need to alloc new memory for the string, otherwise
875 * we free memory twice.
877 newObject->description.lpstrName = HeapAlloc(
878 GetProcessHeap(),0,
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));
907 newEntry->ref = 1;
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 */
926 newObject->ref = 1;
928 *ppfont = (IFont*)newObject;
930 return S_OK;
933 /************************************************************************
934 * OLEFontImpl_IsEqual (IFont)
936 * See Windows documentation for more details on IFont methods.
938 static HRESULT WINAPI OLEFontImpl_IsEqual(
939 IFont* iface,
940 IFont* pFontOther)
942 OLEFontImpl *left = (OLEFontImpl *)iface;
943 OLEFontImpl *right = (OLEFontImpl *)pFontOther;
944 HRESULT hres;
945 INT left_len,right_len;
947 if((iface == NULL) || (pFontOther == NULL))
948 return E_POINTER;
949 else if (left->description.cySize.s.Lo != right->description.cySize.s.Lo)
950 return S_FALSE;
951 else if (left->description.cySize.s.Hi != right->description.cySize.s.Hi)
952 return S_FALSE;
953 else if (left->description.sWeight != right->description.sWeight)
954 return S_FALSE;
955 else if (left->description.sCharset != right->description.sCharset)
956 return S_FALSE;
957 else if (left->description.fItalic != right->description.fItalic)
958 return S_FALSE;
959 else if (left->description.fUnderline != right->description.fUnderline)
960 return S_FALSE;
961 else if (left->description.fStrikethrough != right->description.fStrikethrough)
962 return S_FALSE;
964 /* Check from string */
965 left_len = strlenW(left->description.lpstrName);
966 right_len = strlenW(right->description.lpstrName);
967 hres = CompareStringW(0,0,left->description.lpstrName, left_len,
968 right->description.lpstrName, right_len);
969 if (hres != CSTR_EQUAL)
970 return S_FALSE;
972 return S_OK;
975 /************************************************************************
976 * OLEFontImpl_SetRatio (IFont)
978 * See Windows documentation for more details on IFont methods.
980 static HRESULT WINAPI OLEFontImpl_SetRatio(
981 IFont* iface,
982 LONG cyLogical,
983 LONG cyHimetric)
985 OLEFontImpl *this = (OLEFontImpl *)iface;
986 TRACE("(%p)->(%d, %d)\n", this, cyLogical, cyHimetric);
988 this->cyLogical = cyLogical;
989 this->cyHimetric = cyHimetric;
991 return S_OK;
994 /************************************************************************
995 * OLEFontImpl_QueryTextMetrics (IFont)
997 * See Windows documentation for more details on IFont methods.
999 static HRESULT WINAPI OLEFontImpl_QueryTextMetrics(
1000 IFont* iface,
1001 TEXTMETRICOLE* ptm)
1003 HDC hdcRef;
1004 HFONT hOldFont, hNewFont;
1006 hdcRef = GetDC(0);
1007 OLEFontImpl_get_hFont(iface, &hNewFont);
1008 hOldFont = SelectObject(hdcRef, hNewFont);
1009 GetTextMetricsW(hdcRef, ptm);
1010 SelectObject(hdcRef, hOldFont);
1011 ReleaseDC(0, hdcRef);
1012 return S_OK;
1015 /************************************************************************
1016 * OLEFontImpl_AddRefHfont (IFont)
1018 * See Windows documentation for more details on IFont methods.
1020 static HRESULT WINAPI OLEFontImpl_AddRefHfont(
1021 IFont* iface,
1022 HFONT hfont)
1024 OLEFontImpl *this = (OLEFontImpl *)iface;
1025 PHFONTItem ptr, next;
1026 HRESULT hres = S_FALSE; /* assume not present */
1028 TRACE("(%p)->(%p)\n", this, hfont);
1030 if (!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)
1039 ptr->ref++;
1040 hres = S_OK;
1041 break;
1044 LeaveCriticalSection(&OLEFontImpl_csHFONTLIST);
1046 return hres;
1049 /************************************************************************
1050 * OLEFontImpl_ReleaseHfont (IFont)
1052 * See Windows documentation for more details on IFont methods.
1054 static HRESULT WINAPI OLEFontImpl_ReleaseHfont(
1055 IFont* iface,
1056 HFONT hfont)
1058 OLEFontImpl *this = (OLEFontImpl *)iface;
1059 PHFONTItem ptr, next;
1060 HRESULT hres = S_FALSE; /* assume not present */
1062 TRACE("(%p)->(%p)\n", this, hfont);
1064 if (!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 */
1074 if (!--ptr->ref)
1076 if (ptr->gdiFont == this->gdiFont)
1077 this->gdiFont = NULL;
1079 hres = S_OK;
1080 break;
1083 LeaveCriticalSection(&OLEFontImpl_csHFONTLIST);
1085 return hres;
1088 /************************************************************************
1089 * OLEFontImpl_SetHdc (IFont)
1091 * See Windows documentation for more details on IFont methods.
1093 static HRESULT WINAPI OLEFontImpl_SetHdc(
1094 IFont* iface,
1095 HDC hdc)
1097 OLEFontImpl *this = (OLEFontImpl *)iface;
1098 FIXME("(%p)->(%p): Stub\n", this, hdc);
1099 return E_NOTIMPL;
1103 * Virtual function tables for the OLEFontImpl class.
1105 static const IFontVtbl OLEFontImpl_VTable =
1107 OLEFontImpl_QueryInterface,
1108 OLEFontImpl_AddRef,
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,
1127 OLEFontImpl_Clone,
1128 OLEFontImpl_IsEqual,
1129 OLEFontImpl_SetRatio,
1130 OLEFontImpl_QueryTextMetrics,
1131 OLEFontImpl_AddRefHfont,
1132 OLEFontImpl_ReleaseHfont,
1133 OLEFontImpl_SetHdc
1136 /************************************************************************
1137 * OLEFontImpl_IDispatch_QueryInterface (IUnknown)
1139 * See Windows documentation for more details on IUnknown methods.
1141 static HRESULT WINAPI OLEFontImpl_IDispatch_QueryInterface(
1142 IDispatch* iface,
1143 REFIID riid,
1144 VOID** ppvoid)
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(
1157 IDispatch* iface)
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(
1170 IDispatch* iface)
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(
1183 IDispatch* iface,
1184 unsigned int* pctinfo)
1186 OLEFontImpl *this = impl_from_IDispatch(iface);
1187 TRACE("(%p)->(%p)\n", this, pctinfo);
1188 *pctinfo = 1;
1190 return S_OK;
1193 /************************************************************************
1194 * OLEFontImpl_GetTypeInfo (IDispatch)
1196 * See Windows documentation for more details on IDispatch methods.
1198 static HRESULT WINAPI OLEFontImpl_GetTypeInfo(
1199 IDispatch* iface,
1200 UINT iTInfo,
1201 LCID lcid,
1202 ITypeInfo** ppTInfo)
1204 static const WCHAR stdole2tlb[] = {'s','t','d','o','l','e','2','.','t','l','b',0};
1205 ITypeLib *tl;
1206 HRESULT hres;
1208 OLEFontImpl *this = impl_from_IDispatch(iface);
1209 TRACE("(%p, iTInfo=%d, lcid=%04x, %p)\n", this, iTInfo, (int)lcid, ppTInfo);
1210 if (iTInfo != 0)
1211 return E_FAIL;
1212 hres = LoadTypeLib(stdole2tlb, &tl);
1213 if (FAILED(hres)) {
1214 ERR("Could not load the stdole2.tlb?\n");
1215 return hres;
1217 hres = ITypeLib_GetTypeInfoOfGuid(tl, &IID_IFontDisp, ppTInfo);
1218 ITypeLib_Release(tl);
1219 if (FAILED(hres)) {
1220 FIXME("Did not IDispatch typeinfo from typelib, hres %x\n",hres);
1222 return hres;
1225 /************************************************************************
1226 * OLEFontImpl_GetIDsOfNames (IDispatch)
1228 * See Windows documentation for more details on IDispatch methods.
1230 static HRESULT WINAPI OLEFontImpl_GetIDsOfNames(
1231 IDispatch* iface,
1232 REFIID riid,
1233 LPOLESTR* rgszNames,
1234 UINT cNames,
1235 LCID lcid,
1236 DISPID* rgDispId)
1238 ITypeInfo * pTInfo;
1239 HRESULT hres;
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);
1246 if (cNames == 0)
1248 return E_INVALIDARG;
1250 else
1252 /* retrieve type information */
1253 hres = OLEFontImpl_GetTypeInfo(iface, 0, lcid, &pTInfo);
1255 if (FAILED(hres))
1257 ERR("GetTypeInfo failed.\n");
1258 return hres;
1261 /* convert names to DISPIDs */
1262 hres = DispGetIDsOfNames (pTInfo, rgszNames, cNames, rgDispId);
1263 ITypeInfo_Release(pTInfo);
1265 return hres;
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
1276 * MS VB5 installer.
1278 static HRESULT WINAPI OLEFontImpl_Invoke(
1279 IDispatch* iface,
1280 DISPID dispIdMember,
1281 REFIID riid,
1282 LCID lcid,
1283 WORD wFlags,
1284 DISPPARAMS* pDispParams,
1285 VARIANT* pVarResult,
1286 EXCEPINFO* pExepInfo,
1287 UINT* puArgErr)
1289 OLEFontImpl *this = impl_from_IDispatch(iface);
1290 HRESULT hr;
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,
1294 puArgErr);
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)
1306 if (!pVarResult)
1308 ERR("null pVarResult not allowed when DISPATCH_PROPERTYGET specified\n");
1309 return DISP_E_PARAMNOTOPTIONAL;
1312 else if (wFlags & DISPATCH_PROPERTYPUT)
1314 if (!pDispParams)
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;
1325 else
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));
1336 } else {
1337 VARIANTARG vararg;
1339 VariantInit(&vararg);
1340 hr = VariantChangeTypeEx(&vararg, &pDispParams->rgvarg[0], lcid, 0, VT_BSTR);
1341 if (FAILED(hr))
1342 return hr;
1344 hr = IFont_put_Name((IFont *)this, V_BSTR(&vararg));
1346 VariantClear(&vararg);
1347 return hr;
1349 break;
1350 case DISPID_FONT_BOLD:
1351 if (wFlags & DISPATCH_PROPERTYGET) {
1352 BOOL value;
1353 hr = IFont_get_Bold((IFont *)this, &value);
1354 V_VT(pVarResult) = VT_BOOL;
1355 V_BOOL(pVarResult) = value ? VARIANT_TRUE : VARIANT_FALSE;
1356 return hr;
1357 } else {
1358 VARIANTARG vararg;
1360 VariantInit(&vararg);
1361 hr = VariantChangeTypeEx(&vararg, &pDispParams->rgvarg[0], lcid, 0, VT_BOOL);
1362 if (FAILED(hr))
1363 return hr;
1365 hr = IFont_put_Bold((IFont *)this, V_BOOL(&vararg));
1367 VariantClear(&vararg);
1368 return hr;
1370 break;
1371 case DISPID_FONT_ITALIC:
1372 if (wFlags & DISPATCH_PROPERTYGET) {
1373 BOOL value;
1374 hr = IFont_get_Italic((IFont *)this, &value);
1375 V_VT(pVarResult) = VT_BOOL;
1376 V_BOOL(pVarResult) = value ? VARIANT_TRUE : VARIANT_FALSE;
1377 return hr;
1378 } else {
1379 VARIANTARG vararg;
1380 HRESULT hr;
1382 VariantInit(&vararg);
1383 hr = VariantChangeTypeEx(&vararg, &pDispParams->rgvarg[0], lcid, 0, VT_BOOL);
1384 if (FAILED(hr))
1385 return hr;
1387 hr = IFont_put_Italic((IFont *)this, V_BOOL(&vararg));
1389 VariantClear(&vararg);
1390 return hr;
1392 break;
1393 case DISPID_FONT_UNDER:
1394 if (wFlags & DISPATCH_PROPERTYGET) {
1395 BOOL value;
1396 hr = IFont_get_Underline((IFont *)this, &value);
1397 V_VT(pVarResult) = VT_BOOL;
1398 V_BOOL(pVarResult) = value ? VARIANT_TRUE : VARIANT_FALSE;
1399 return hr;
1400 } else {
1401 VARIANTARG vararg;
1402 HRESULT hr;
1404 VariantInit(&vararg);
1405 hr = VariantChangeTypeEx(&vararg, &pDispParams->rgvarg[0], lcid, 0, VT_BOOL);
1406 if (FAILED(hr))
1407 return hr;
1409 hr = IFont_put_Underline((IFont *)this, V_BOOL(&vararg));
1411 VariantClear(&vararg);
1412 return hr;
1414 break;
1415 case DISPID_FONT_STRIKE:
1416 if (wFlags & DISPATCH_PROPERTYGET) {
1417 BOOL value;
1418 hr = IFont_get_Strikethrough((IFont *)this, &value);
1419 V_VT(pVarResult) = VT_BOOL;
1420 V_BOOL(pVarResult) = value ? VARIANT_TRUE : VARIANT_FALSE;
1421 return hr;
1422 } else {
1423 VARIANTARG vararg;
1424 HRESULT hr;
1426 VariantInit(&vararg);
1427 hr = VariantChangeTypeEx(&vararg, &pDispParams->rgvarg[0], lcid, 0, VT_BOOL);
1428 if (FAILED(hr))
1429 return hr;
1431 hr = IFont_put_Strikethrough((IFont *)this, V_BOOL(&vararg));
1433 VariantClear(&vararg);
1434 return hr;
1436 break;
1437 case DISPID_FONT_SIZE:
1438 if (wFlags & DISPATCH_PROPERTYGET) {
1439 V_VT(pVarResult) = VT_CY;
1440 return OLEFontImpl_get_Size((IFont *)this, &V_CY(pVarResult));
1441 } else {
1442 VARIANTARG vararg;
1443 HRESULT hr;
1445 VariantInit(&vararg);
1446 hr = VariantChangeTypeEx(&vararg, &pDispParams->rgvarg[0], lcid, 0, VT_CY);
1447 if (FAILED(hr))
1448 return hr;
1450 hr = IFont_put_Size((IFont *)this, V_CY(&vararg));
1452 VariantClear(&vararg);
1453 return hr;
1455 break;
1456 case DISPID_FONT_WEIGHT:
1457 if (wFlags & DISPATCH_PROPERTYGET) {
1458 V_VT(pVarResult) = VT_I2;
1459 return OLEFontImpl_get_Weight((IFont *)this, &V_I2(pVarResult));
1460 } else {
1461 VARIANTARG vararg;
1462 HRESULT hr;
1464 VariantInit(&vararg);
1465 hr = VariantChangeTypeEx(&vararg, &pDispParams->rgvarg[0], lcid, 0, VT_I2);
1466 if (FAILED(hr))
1467 return hr;
1469 hr = IFont_put_Weight((IFont *)this, V_I2(&vararg));
1471 VariantClear(&vararg);
1472 return hr;
1474 break;
1475 case DISPID_FONT_CHARSET:
1476 if (wFlags & DISPATCH_PROPERTYGET) {
1477 V_VT(pVarResult) = VT_I2;
1478 return OLEFontImpl_get_Charset((IFont *)this, &V_I2(pVarResult));
1479 } else {
1480 VARIANTARG vararg;
1481 HRESULT hr;
1483 VariantInit(&vararg);
1484 hr = VariantChangeTypeEx(&vararg, &pDispParams->rgvarg[0], lcid, 0, VT_I2);
1485 if (FAILED(hr))
1486 return hr;
1488 hr = IFont_put_Charset((IFont *)this, V_I2(&vararg));
1490 VariantClear(&vararg);
1491 return hr;
1493 break;
1494 default:
1495 ERR("member not found for dispid 0x%x\n", dispIdMember);
1496 return DISP_E_MEMBERNOTFOUND;
1500 static const IDispatchVtbl OLEFontImpl_IDispatch_VTable =
1502 OLEFontImpl_IDispatch_QueryInterface,
1503 OLEFontImpl_IDispatch_AddRef,
1504 OLEFontImpl_IDispatch_Release,
1505 OLEFontImpl_GetTypeInfoCount,
1506 OLEFontImpl_GetTypeInfo,
1507 OLEFontImpl_GetIDsOfNames,
1508 OLEFontImpl_Invoke
1511 /************************************************************************
1512 * OLEFontImpl_IPersistStream_QueryInterface (IUnknown)
1514 * See Windows documentation for more details on IUnknown methods.
1516 static HRESULT WINAPI OLEFontImpl_IPersistStream_QueryInterface(
1517 IPersistStream* iface,
1518 REFIID riid,
1519 VOID** ppvoid)
1521 OLEFontImpl *this = impl_from_IPersistStream(iface);
1523 return IFont_QueryInterface((IFont *)this, riid, ppvoid);
1526 /************************************************************************
1527 * OLEFontImpl_IPersistStream_Release (IUnknown)
1529 * See Windows documentation for more details on IUnknown methods.
1531 static ULONG WINAPI OLEFontImpl_IPersistStream_Release(
1532 IPersistStream* iface)
1534 OLEFontImpl *this = impl_from_IPersistStream(iface);
1536 return IFont_Release((IFont *)this);
1539 /************************************************************************
1540 * OLEFontImpl_IPersistStream_AddRef (IUnknown)
1542 * See Windows documentation for more details on IUnknown methods.
1544 static ULONG WINAPI OLEFontImpl_IPersistStream_AddRef(
1545 IPersistStream* iface)
1547 OLEFontImpl *this = impl_from_IPersistStream(iface);
1549 return IFont_AddRef((IFont *)this);
1552 /************************************************************************
1553 * OLEFontImpl_GetClassID (IPersistStream)
1555 * See Windows documentation for more details on IPersistStream methods.
1557 static HRESULT WINAPI OLEFontImpl_GetClassID(
1558 IPersistStream* iface,
1559 CLSID* pClassID)
1561 TRACE("(%p,%p)\n",iface,pClassID);
1562 if (pClassID==0)
1563 return E_POINTER;
1565 memcpy(pClassID, &CLSID_StdFont, sizeof(CLSID_StdFont));
1567 return S_OK;
1570 /************************************************************************
1571 * OLEFontImpl_IsDirty (IPersistStream)
1573 * See Windows documentation for more details on IPersistStream methods.
1575 static HRESULT WINAPI OLEFontImpl_IsDirty(
1576 IPersistStream* iface)
1578 TRACE("(%p)\n",iface);
1579 return S_OK;
1582 /************************************************************************
1583 * OLEFontImpl_Load (IPersistStream)
1585 * See Windows documentation for more details on IPersistStream methods.
1587 * This is the format of the standard font serialization as far as I
1588 * know
1590 * Offset Type Value Comment
1591 * 0x0000 Byte Unknown Probably a version number, contains 0x01
1592 * 0x0001 Short Charset Charset value from the FONTDESC structure
1593 * 0x0003 Byte Attributes Flags defined as follows:
1594 * 00000010 - Italic
1595 * 00000100 - Underline
1596 * 00001000 - Strikethrough
1597 * 0x0004 Short Weight Weight value from FONTDESC structure
1598 * 0x0006 DWORD size "Low" portion of the cySize member of the FONTDESC
1599 * structure/
1600 * 0x000A Byte name length Length of the font name string (no null character)
1601 * 0x000B String name Name of the font (ASCII, no nul character)
1603 static HRESULT WINAPI OLEFontImpl_Load(
1604 IPersistStream* iface,
1605 IStream* pLoadStream)
1607 char readBuffer[0x100];
1608 ULONG cbRead;
1609 BYTE bVersion;
1610 BYTE bAttributes;
1611 BYTE bStringSize;
1612 INT len;
1614 OLEFontImpl *this = impl_from_IPersistStream(iface);
1617 * Read the version byte
1619 IStream_Read(pLoadStream, &bVersion, 1, &cbRead);
1621 if ( (cbRead!=1) ||
1622 (bVersion!=0x01) )
1623 return E_FAIL;
1626 * Charset
1628 IStream_Read(pLoadStream, &this->description.sCharset, 2, &cbRead);
1630 if (cbRead!=2)
1631 return E_FAIL;
1634 * Attributes
1636 IStream_Read(pLoadStream, &bAttributes, 1, &cbRead);
1638 if (cbRead!=1)
1639 return E_FAIL;
1641 this->description.fItalic = (bAttributes & FONTPERSIST_ITALIC) != 0;
1642 this->description.fStrikethrough = (bAttributes & FONTPERSIST_STRIKETHROUGH) != 0;
1643 this->description.fUnderline = (bAttributes & FONTPERSIST_UNDERLINE) != 0;
1646 * Weight
1648 IStream_Read(pLoadStream, &this->description.sWeight, 2, &cbRead);
1650 if (cbRead!=2)
1651 return E_FAIL;
1654 * Size
1656 IStream_Read(pLoadStream, &this->description.cySize.s.Lo, 4, &cbRead);
1658 if (cbRead!=4)
1659 return E_FAIL;
1661 this->description.cySize.s.Hi = 0;
1664 * FontName
1666 IStream_Read(pLoadStream, &bStringSize, 1, &cbRead);
1668 if (cbRead!=1)
1669 return E_FAIL;
1671 IStream_Read(pLoadStream, readBuffer, bStringSize, &cbRead);
1673 if (cbRead!=bStringSize)
1674 return E_FAIL;
1676 HeapFree(GetProcessHeap(), 0, this->description.lpstrName);
1678 len = MultiByteToWideChar( CP_ACP, 0, readBuffer, bStringSize, NULL, 0 );
1679 this->description.lpstrName = HeapAlloc( GetProcessHeap(), 0, (len+1) * sizeof(WCHAR) );
1680 MultiByteToWideChar( CP_ACP, 0, readBuffer, bStringSize, this->description.lpstrName, len );
1681 this->description.lpstrName[len] = 0;
1683 /* Ensure use of this font causes a new one to be created @@@@ */
1684 DeleteObject(this->gdiFont);
1685 this->gdiFont = 0;
1687 return S_OK;
1690 /************************************************************************
1691 * OLEFontImpl_Save (IPersistStream)
1693 * See Windows documentation for more details on IPersistStream methods.
1695 static HRESULT WINAPI OLEFontImpl_Save(
1696 IPersistStream* iface,
1697 IStream* pOutStream,
1698 BOOL fClearDirty)
1700 char* writeBuffer = NULL;
1701 ULONG cbWritten;
1702 BYTE bVersion = 0x01;
1703 BYTE bAttributes;
1704 BYTE bStringSize;
1706 OLEFontImpl *this = impl_from_IPersistStream(iface);
1709 * Read the version byte
1711 IStream_Write(pOutStream, &bVersion, 1, &cbWritten);
1713 if (cbWritten!=1)
1714 return E_FAIL;
1717 * Charset
1719 IStream_Write(pOutStream, &this->description.sCharset, 2, &cbWritten);
1721 if (cbWritten!=2)
1722 return E_FAIL;
1725 * Attributes
1727 bAttributes = 0;
1729 if (this->description.fItalic)
1730 bAttributes |= FONTPERSIST_ITALIC;
1732 if (this->description.fStrikethrough)
1733 bAttributes |= FONTPERSIST_STRIKETHROUGH;
1735 if (this->description.fUnderline)
1736 bAttributes |= FONTPERSIST_UNDERLINE;
1738 IStream_Write(pOutStream, &bAttributes, 1, &cbWritten);
1740 if (cbWritten!=1)
1741 return E_FAIL;
1744 * Weight
1746 IStream_Write(pOutStream, &this->description.sWeight, 2, &cbWritten);
1748 if (cbWritten!=2)
1749 return E_FAIL;
1752 * Size
1754 IStream_Write(pOutStream, &this->description.cySize.s.Lo, 4, &cbWritten);
1756 if (cbWritten!=4)
1757 return E_FAIL;
1760 * FontName
1762 if (this->description.lpstrName!=0)
1763 bStringSize = WideCharToMultiByte( CP_ACP, 0, this->description.lpstrName,
1764 strlenW(this->description.lpstrName), NULL, 0, NULL, NULL );
1765 else
1766 bStringSize = 0;
1768 IStream_Write(pOutStream, &bStringSize, 1, &cbWritten);
1770 if (cbWritten!=1)
1771 return E_FAIL;
1773 if (bStringSize!=0)
1775 if (!(writeBuffer = HeapAlloc( GetProcessHeap(), 0, bStringSize ))) return E_OUTOFMEMORY;
1776 WideCharToMultiByte( CP_ACP, 0, this->description.lpstrName,
1777 strlenW(this->description.lpstrName),
1778 writeBuffer, bStringSize, NULL, NULL );
1780 IStream_Write(pOutStream, writeBuffer, bStringSize, &cbWritten);
1781 HeapFree(GetProcessHeap(), 0, writeBuffer);
1783 if (cbWritten!=bStringSize)
1784 return E_FAIL;
1787 return S_OK;
1790 /************************************************************************
1791 * OLEFontImpl_GetSizeMax (IPersistStream)
1793 * See Windows documentation for more details on IPersistStream methods.
1795 static HRESULT WINAPI OLEFontImpl_GetSizeMax(
1796 IPersistStream* iface,
1797 ULARGE_INTEGER* pcbSize)
1799 OLEFontImpl *this = impl_from_IPersistStream(iface);
1801 if (pcbSize==NULL)
1802 return E_POINTER;
1804 pcbSize->u.HighPart = 0;
1805 pcbSize->u.LowPart = 0;
1807 pcbSize->u.LowPart += sizeof(BYTE); /* Version */
1808 pcbSize->u.LowPart += sizeof(WORD); /* Lang code */
1809 pcbSize->u.LowPart += sizeof(BYTE); /* Flags */
1810 pcbSize->u.LowPart += sizeof(WORD); /* Weight */
1811 pcbSize->u.LowPart += sizeof(DWORD); /* Size */
1812 pcbSize->u.LowPart += sizeof(BYTE); /* StrLength */
1814 if (this->description.lpstrName!=0)
1815 pcbSize->u.LowPart += lstrlenW(this->description.lpstrName);
1817 return S_OK;
1820 static const IPersistStreamVtbl OLEFontImpl_IPersistStream_VTable =
1822 OLEFontImpl_IPersistStream_QueryInterface,
1823 OLEFontImpl_IPersistStream_AddRef,
1824 OLEFontImpl_IPersistStream_Release,
1825 OLEFontImpl_GetClassID,
1826 OLEFontImpl_IsDirty,
1827 OLEFontImpl_Load,
1828 OLEFontImpl_Save,
1829 OLEFontImpl_GetSizeMax
1832 /************************************************************************
1833 * OLEFontImpl_IConnectionPointContainer_QueryInterface (IUnknown)
1835 * See Windows documentation for more details on IUnknown methods.
1837 static HRESULT WINAPI OLEFontImpl_IConnectionPointContainer_QueryInterface(
1838 IConnectionPointContainer* iface,
1839 REFIID riid,
1840 VOID** ppvoid)
1842 OLEFontImpl *this = impl_from_IConnectionPointContainer(iface);
1844 return IFont_QueryInterface((IFont*)this, riid, ppvoid);
1847 /************************************************************************
1848 * OLEFontImpl_IConnectionPointContainer_Release (IUnknown)
1850 * See Windows documentation for more details on IUnknown methods.
1852 static ULONG WINAPI OLEFontImpl_IConnectionPointContainer_Release(
1853 IConnectionPointContainer* iface)
1855 OLEFontImpl *this = impl_from_IConnectionPointContainer(iface);
1857 return IFont_Release((IFont*)this);
1860 /************************************************************************
1861 * OLEFontImpl_IConnectionPointContainer_AddRef (IUnknown)
1863 * See Windows documentation for more details on IUnknown methods.
1865 static ULONG WINAPI OLEFontImpl_IConnectionPointContainer_AddRef(
1866 IConnectionPointContainer* iface)
1868 OLEFontImpl *this = impl_from_IConnectionPointContainer(iface);
1870 return IFont_AddRef((IFont*)this);
1873 /************************************************************************
1874 * OLEFontImpl_EnumConnectionPoints (IConnectionPointContainer)
1876 * See Windows documentation for more details on IConnectionPointContainer
1877 * methods.
1879 static HRESULT WINAPI OLEFontImpl_EnumConnectionPoints(
1880 IConnectionPointContainer* iface,
1881 IEnumConnectionPoints **ppEnum)
1883 OLEFontImpl *this = impl_from_IConnectionPointContainer(iface);
1885 FIXME("(%p)->(%p): stub\n", this, ppEnum);
1886 return E_NOTIMPL;
1889 /************************************************************************
1890 * OLEFontImpl_FindConnectionPoint (IConnectionPointContainer)
1892 * See Windows documentation for more details on IConnectionPointContainer
1893 * methods.
1895 static HRESULT WINAPI OLEFontImpl_FindConnectionPoint(
1896 IConnectionPointContainer* iface,
1897 REFIID riid,
1898 IConnectionPoint **ppCp)
1900 OLEFontImpl *this = impl_from_IConnectionPointContainer(iface);
1901 TRACE("(%p)->(%s, %p)\n", this, debugstr_guid(riid), ppCp);
1903 if(IsEqualIID(riid, &IID_IPropertyNotifySink)) {
1904 return IConnectionPoint_QueryInterface(this->pPropertyNotifyCP,
1905 &IID_IConnectionPoint,
1906 (LPVOID)ppCp);
1907 } else if(IsEqualIID(riid, &IID_IFontEventsDisp)) {
1908 return IConnectionPoint_QueryInterface(this->pFontEventsCP,
1909 &IID_IConnectionPoint,
1910 (LPVOID)ppCp);
1911 } else {
1912 FIXME("no connection point for %s\n", debugstr_guid(riid));
1913 return CONNECT_E_NOCONNECTION;
1917 static const IConnectionPointContainerVtbl
1918 OLEFontImpl_IConnectionPointContainer_VTable =
1920 OLEFontImpl_IConnectionPointContainer_QueryInterface,
1921 OLEFontImpl_IConnectionPointContainer_AddRef,
1922 OLEFontImpl_IConnectionPointContainer_Release,
1923 OLEFontImpl_EnumConnectionPoints,
1924 OLEFontImpl_FindConnectionPoint
1927 /************************************************************************
1928 * OLEFontImpl implementation of IPersistPropertyBag.
1930 static HRESULT WINAPI OLEFontImpl_IPersistPropertyBag_QueryInterface(
1931 IPersistPropertyBag *iface, REFIID riid, LPVOID *ppvObj
1933 OLEFontImpl *this = impl_from_IPersistPropertyBag(iface);
1934 return IFont_QueryInterface((IFont *)this,riid,ppvObj);
1937 static ULONG WINAPI OLEFontImpl_IPersistPropertyBag_AddRef(
1938 IPersistPropertyBag *iface
1940 OLEFontImpl *this = impl_from_IPersistPropertyBag(iface);
1941 return IFont_AddRef((IFont *)this);
1944 static ULONG WINAPI OLEFontImpl_IPersistPropertyBag_Release(
1945 IPersistPropertyBag *iface
1947 OLEFontImpl *this = impl_from_IPersistPropertyBag(iface);
1948 return IFont_Release((IFont *)this);
1951 static HRESULT WINAPI OLEFontImpl_IPersistPropertyBag_GetClassID(
1952 IPersistPropertyBag *iface, CLSID *classid
1954 FIXME("(%p,%p), stub!\n", iface, classid);
1955 return E_FAIL;
1958 static HRESULT WINAPI OLEFontImpl_IPersistPropertyBag_InitNew(
1959 IPersistPropertyBag *iface
1961 FIXME("(%p), stub!\n", iface);
1962 return S_OK;
1965 static HRESULT WINAPI OLEFontImpl_IPersistPropertyBag_Load(
1966 IPersistPropertyBag *iface, IPropertyBag* pPropBag, IErrorLog* pErrorLog
1968 /* (from Visual Basic 6 property bag)
1969 Name = "MS Sans Serif"
1970 Size = 13.8
1971 Charset = 0
1972 Weight = 400
1973 Underline = 0 'False
1974 Italic = 0 'False
1975 Strikethrough = 0 'False
1977 static const WCHAR sAttrName[] = {'N','a','m','e',0};
1978 static const WCHAR sAttrSize[] = {'S','i','z','e',0};
1979 static const WCHAR sAttrCharset[] = {'C','h','a','r','s','e','t',0};
1980 static const WCHAR sAttrWeight[] = {'W','e','i','g','h','t',0};
1981 static const WCHAR sAttrUnderline[] = {'U','n','d','e','r','l','i','n','e',0};
1982 static const WCHAR sAttrItalic[] = {'I','t','a','l','i','c',0};
1983 static const WCHAR sAttrStrikethrough[] = {'S','t','r','i','k','e','t','h','r','o','u','g','h',0};
1984 VARIANT rawAttr;
1985 VARIANT valueAttr;
1986 HRESULT iRes = S_OK;
1987 OLEFontImpl *this = impl_from_IPersistPropertyBag(iface);
1989 VariantInit(&rawAttr);
1990 VariantInit(&valueAttr);
1992 if (iRes == S_OK) {
1993 iRes = IPropertyBag_Read(pPropBag, sAttrName, &rawAttr, pErrorLog);
1994 if (iRes == S_OK)
1996 iRes = VariantChangeType(&rawAttr, &valueAttr, 0, VT_BSTR);
1997 if (iRes == S_OK)
1998 iRes = IFont_put_Name((IFont *)this, V_BSTR(&valueAttr));
2000 else if (iRes == E_INVALIDARG)
2001 iRes = S_OK;
2002 VariantClear(&rawAttr);
2003 VariantClear(&valueAttr);
2006 if (iRes == S_OK) {
2007 iRes = IPropertyBag_Read(pPropBag, sAttrSize, &rawAttr, pErrorLog);
2008 if (iRes == S_OK)
2010 iRes = VariantChangeType(&rawAttr, &valueAttr, 0, VT_CY);
2011 if (iRes == S_OK)
2012 iRes = IFont_put_Size((IFont *)this, V_CY(&valueAttr));
2014 else if (iRes == E_INVALIDARG)
2015 iRes = S_OK;
2016 VariantClear(&rawAttr);
2017 VariantClear(&valueAttr);
2020 if (iRes == S_OK) {
2021 iRes = IPropertyBag_Read(pPropBag, sAttrCharset, &rawAttr, pErrorLog);
2022 if (iRes == S_OK)
2024 iRes = VariantChangeType(&rawAttr, &valueAttr, 0, VT_I2);
2025 if (iRes == S_OK)
2026 iRes = IFont_put_Charset((IFont *)this, V_I2(&valueAttr));
2028 else if (iRes == E_INVALIDARG)
2029 iRes = S_OK;
2030 VariantClear(&rawAttr);
2031 VariantClear(&valueAttr);
2034 if (iRes == S_OK) {
2035 iRes = IPropertyBag_Read(pPropBag, sAttrWeight, &rawAttr, pErrorLog);
2036 if (iRes == S_OK)
2038 iRes = VariantChangeType(&rawAttr, &valueAttr, 0, VT_I2);
2039 if (iRes == S_OK)
2040 iRes = IFont_put_Weight((IFont *)this, V_I2(&valueAttr));
2042 else if (iRes == E_INVALIDARG)
2043 iRes = S_OK;
2044 VariantClear(&rawAttr);
2045 VariantClear(&valueAttr);
2049 if (iRes == S_OK) {
2050 iRes = IPropertyBag_Read(pPropBag, sAttrUnderline, &rawAttr, pErrorLog);
2051 if (iRes == S_OK)
2053 iRes = VariantChangeType(&rawAttr, &valueAttr, 0, VT_BOOL);
2054 if (iRes == S_OK)
2055 iRes = IFont_put_Underline((IFont *)this, V_BOOL(&valueAttr));
2057 else if (iRes == E_INVALIDARG)
2058 iRes = S_OK;
2059 VariantClear(&rawAttr);
2060 VariantClear(&valueAttr);
2063 if (iRes == S_OK) {
2064 iRes = IPropertyBag_Read(pPropBag, sAttrItalic, &rawAttr, pErrorLog);
2065 if (iRes == S_OK)
2067 iRes = VariantChangeType(&rawAttr, &valueAttr, 0, VT_BOOL);
2068 if (iRes == S_OK)
2069 iRes = IFont_put_Italic((IFont *)this, V_BOOL(&valueAttr));
2071 else if (iRes == E_INVALIDARG)
2072 iRes = S_OK;
2073 VariantClear(&rawAttr);
2074 VariantClear(&valueAttr);
2077 if (iRes == S_OK) {
2078 iRes = IPropertyBag_Read(pPropBag, sAttrStrikethrough, &rawAttr, pErrorLog);
2079 if (iRes == S_OK)
2081 iRes = VariantChangeType(&rawAttr, &valueAttr, 0, VT_BOOL);
2082 if (iRes == S_OK)
2083 IFont_put_Strikethrough((IFont *)this, V_BOOL(&valueAttr));
2085 else if (iRes == E_INVALIDARG)
2086 iRes = S_OK;
2087 VariantClear(&rawAttr);
2088 VariantClear(&valueAttr);
2091 if (FAILED(iRes))
2092 WARN("-- 0x%08x\n", iRes);
2093 return iRes;
2096 static HRESULT WINAPI OLEFontImpl_IPersistPropertyBag_Save(
2097 IPersistPropertyBag *iface, IPropertyBag* pPropBag, BOOL fClearDirty,
2098 BOOL fSaveAllProperties
2100 FIXME("(%p,%p,%d,%d), stub!\n", iface, pPropBag, fClearDirty, fSaveAllProperties);
2101 return E_FAIL;
2104 static const IPersistPropertyBagVtbl OLEFontImpl_IPersistPropertyBag_VTable =
2106 OLEFontImpl_IPersistPropertyBag_QueryInterface,
2107 OLEFontImpl_IPersistPropertyBag_AddRef,
2108 OLEFontImpl_IPersistPropertyBag_Release,
2110 OLEFontImpl_IPersistPropertyBag_GetClassID,
2111 OLEFontImpl_IPersistPropertyBag_InitNew,
2112 OLEFontImpl_IPersistPropertyBag_Load,
2113 OLEFontImpl_IPersistPropertyBag_Save
2116 /************************************************************************
2117 * OLEFontImpl implementation of IPersistStreamInit.
2119 static HRESULT WINAPI OLEFontImpl_IPersistStreamInit_QueryInterface(
2120 IPersistStreamInit *iface, REFIID riid, LPVOID *ppvObj
2122 OLEFontImpl *this = impl_from_IPersistStreamInit(iface);
2123 return IFont_QueryInterface((IFont *)this,riid,ppvObj);
2126 static ULONG WINAPI OLEFontImpl_IPersistStreamInit_AddRef(
2127 IPersistStreamInit *iface
2129 OLEFontImpl *this = impl_from_IPersistStreamInit(iface);
2130 return IFont_AddRef((IFont *)this);
2133 static ULONG WINAPI OLEFontImpl_IPersistStreamInit_Release(
2134 IPersistStreamInit *iface
2136 OLEFontImpl *this = impl_from_IPersistStreamInit(iface);
2137 return IFont_Release((IFont *)this);
2140 static HRESULT WINAPI OLEFontImpl_IPersistStreamInit_GetClassID(
2141 IPersistStreamInit *iface, CLSID *classid
2143 FIXME("(%p,%p), stub!\n", iface, classid);
2144 return E_FAIL;
2147 static HRESULT WINAPI OLEFontImpl_IPersistStreamInit_IsDirty(
2148 IPersistStreamInit *iface
2150 FIXME("(%p), stub!\n", iface);
2151 return E_FAIL;
2154 static HRESULT WINAPI OLEFontImpl_IPersistStreamInit_Load(
2155 IPersistStreamInit *iface, LPSTREAM pStm
2157 FIXME("(%p,%p), stub!\n", iface, pStm);
2158 return E_FAIL;
2161 static HRESULT WINAPI OLEFontImpl_IPersistStreamInit_Save(
2162 IPersistStreamInit *iface, LPSTREAM pStm, BOOL fClearDirty
2164 FIXME("(%p,%p,%d), stub!\n", iface, pStm, fClearDirty);
2165 return E_FAIL;
2168 static HRESULT WINAPI OLEFontImpl_IPersistStreamInit_GetSizeMax(
2169 IPersistStreamInit *iface, ULARGE_INTEGER *pcbSize
2171 FIXME("(%p,%p), stub!\n", iface, pcbSize);
2172 return E_FAIL;
2175 static HRESULT WINAPI OLEFontImpl_IPersistStreamInit_InitNew(
2176 IPersistStreamInit *iface
2178 FIXME("(%p), stub!\n", iface);
2179 return S_OK;
2182 static const IPersistStreamInitVtbl OLEFontImpl_IPersistStreamInit_VTable =
2184 OLEFontImpl_IPersistStreamInit_QueryInterface,
2185 OLEFontImpl_IPersistStreamInit_AddRef,
2186 OLEFontImpl_IPersistStreamInit_Release,
2188 OLEFontImpl_IPersistStreamInit_GetClassID,
2189 OLEFontImpl_IPersistStreamInit_IsDirty,
2190 OLEFontImpl_IPersistStreamInit_Load,
2191 OLEFontImpl_IPersistStreamInit_Save,
2192 OLEFontImpl_IPersistStreamInit_GetSizeMax,
2193 OLEFontImpl_IPersistStreamInit_InitNew
2196 /************************************************************************
2197 * OLEFontImpl_Construct
2199 * This method will construct a new instance of the OLEFontImpl
2200 * class.
2202 * The caller of this method must release the object when it's
2203 * done with it.
2205 static OLEFontImpl* OLEFontImpl_Construct(const FONTDESC *fontDesc)
2207 OLEFontImpl* newObject = 0;
2210 * Allocate space for the object.
2212 newObject = HeapAlloc(GetProcessHeap(), 0, sizeof(OLEFontImpl));
2214 if (newObject==0)
2215 return newObject;
2218 * Initialize the virtual function table.
2220 newObject->lpVtbl = &OLEFontImpl_VTable;
2221 newObject->lpvtblIDispatch = &OLEFontImpl_IDispatch_VTable;
2222 newObject->lpvtblIPersistStream = &OLEFontImpl_IPersistStream_VTable;
2223 newObject->lpvtblIConnectionPointContainer = &OLEFontImpl_IConnectionPointContainer_VTable;
2224 newObject->lpvtblIPersistPropertyBag = &OLEFontImpl_IPersistPropertyBag_VTable;
2225 newObject->lpvtblIPersistStreamInit = &OLEFontImpl_IPersistStreamInit_VTable;
2228 * Start with one reference count. The caller of this function
2229 * must release the interface pointer when it is done.
2231 newObject->ref = 1;
2234 * Copy the description of the font in the object.
2236 assert(fontDesc->cbSizeofstruct >= sizeof(FONTDESC));
2238 newObject->description.cbSizeofstruct = sizeof(FONTDESC);
2239 newObject->description.lpstrName = HeapAlloc(GetProcessHeap(),
2241 (lstrlenW(fontDesc->lpstrName)+1) * sizeof(WCHAR));
2242 strcpyW(newObject->description.lpstrName, fontDesc->lpstrName);
2243 newObject->description.cySize = fontDesc->cySize;
2244 newObject->description.sWeight = fontDesc->sWeight;
2245 newObject->description.sCharset = fontDesc->sCharset;
2246 newObject->description.fItalic = fontDesc->fItalic;
2247 newObject->description.fUnderline = fontDesc->fUnderline;
2248 newObject->description.fStrikethrough = fontDesc->fStrikethrough;
2251 * Initializing all the other members.
2253 newObject->gdiFont = 0;
2254 newObject->cyLogical = 72L;
2255 newObject->cyHimetric = 2540L;
2256 newObject->pPropertyNotifyCP = NULL;
2257 newObject->pFontEventsCP = NULL;
2259 CreateConnectionPoint((IUnknown*)newObject, &IID_IPropertyNotifySink, &newObject->pPropertyNotifyCP);
2260 CreateConnectionPoint((IUnknown*)newObject, &IID_IFontEventsDisp, &newObject->pFontEventsCP);
2262 if (!newObject->pPropertyNotifyCP || !newObject->pFontEventsCP)
2264 OLEFontImpl_Destroy(newObject);
2265 return NULL;
2268 InterlockedIncrement(&ifont_cnt);
2270 TRACE("returning %p\n", newObject);
2271 return newObject;
2274 /************************************************************************
2275 * OLEFontImpl_Destroy
2277 * This method is called by the Release method when the reference
2278 * count goes down to 0. It will free all resources used by
2279 * this object.
2281 static void OLEFontImpl_Destroy(OLEFontImpl* fontDesc)
2283 TRACE("(%p)\n", fontDesc);
2285 HeapFree(GetProcessHeap(), 0, fontDesc->description.lpstrName);
2287 if (fontDesc->gdiFont!=0)
2288 DeleteObject(fontDesc->gdiFont);
2290 if (fontDesc->pPropertyNotifyCP)
2291 IConnectionPoint_Release(fontDesc->pPropertyNotifyCP);
2292 if (fontDesc->pFontEventsCP)
2293 IConnectionPoint_Release(fontDesc->pFontEventsCP);
2295 HeapFree(GetProcessHeap(), 0, fontDesc);
2298 /*******************************************************************************
2299 * StdFont ClassFactory
2301 typedef struct
2303 /* IUnknown fields */
2304 const IClassFactoryVtbl *lpVtbl;
2305 LONG ref;
2306 } IClassFactoryImpl;
2308 static HRESULT WINAPI
2309 SFCF_QueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj) {
2310 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
2312 FIXME("(%p)->(%s,%p),stub!\n",This,debugstr_guid(riid),ppobj);
2313 return E_NOINTERFACE;
2316 static ULONG WINAPI
2317 SFCF_AddRef(LPCLASSFACTORY iface) {
2318 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
2319 return InterlockedIncrement(&This->ref);
2322 static ULONG WINAPI SFCF_Release(LPCLASSFACTORY iface) {
2323 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
2324 /* static class, won't be freed */
2325 return InterlockedDecrement(&This->ref);
2328 static HRESULT WINAPI SFCF_CreateInstance(
2329 LPCLASSFACTORY iface,LPUNKNOWN pOuter,REFIID riid,LPVOID *ppobj
2331 return OleCreateFontIndirect(NULL,riid,ppobj);
2335 static HRESULT WINAPI SFCF_LockServer(LPCLASSFACTORY iface,BOOL dolock) {
2336 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
2337 FIXME("(%p)->(%d),stub!\n",This,dolock);
2338 return S_OK;
2341 static const IClassFactoryVtbl SFCF_Vtbl = {
2342 SFCF_QueryInterface,
2343 SFCF_AddRef,
2344 SFCF_Release,
2345 SFCF_CreateInstance,
2346 SFCF_LockServer
2348 static IClassFactoryImpl STDFONT_CF = {&SFCF_Vtbl, 1 };
2350 void _get_STDFONT_CF(LPVOID *ppv) { *ppv = (LPVOID)&STDFONT_CF; }