source: trunk/src/oleaut32/olefont.cpp@ 631

Last change on this file since 631 was 631, checked in by sandervl, 26 years ago

Created (WINE Port of OLEAUT32)

File size: 35.7 KB
Line 
1/*
2 * OLE Font encapsulation implementation
3 *
4 * This file contains an implementation of the IFont
5 * interface and the OleCreateFontIndirect API call.
6 *
7 * Copyright 1999 Francis Beaudet
8 * Copyright 1999 Sander van Leeuwen (WINE OS/2 Port 990815)
9 *
10 * Project Odin Software License can be found in LICENSE.TXT
11 *
12 */
13#include "oleaut32.h"
14#include <assert.h>
15#include <string.h>
16#include "winerror.h"
17#include "oleauto.h"
18#include "ocidl.h"
19#include "olectl.h"
20#include "debugtools.h"
21#include "heap.h"
22
23DEFAULT_DEBUG_CHANNEL(ole)
24
25/***********************************************************************
26 * Declaration of constants used when serializing the font object.
27 */
28#define FONTPERSIST_ITALIC 0x02
29#define FONTPERSIST_UNDERLINE 0x04
30#define FONTPERSIST_STRIKETHROUGH 0x08
31
32/***********************************************************************
33 * Declaration of the implementation class for the IFont interface
34 */
35typedef struct OLEFontImpl OLEFontImpl;
36
37struct OLEFontImpl
38{
39 /*
40 * This class supports many interfaces. IUnknown, IFont,
41 * IDispatch, IDispFont and IPersistStream. The first two are
42 * supported by the first vtablem the next two are supported by
43 * the second table and the last one has it's own.
44 */
45 ICOM_VTABLE(IFont)* lpvtbl1;
46 ICOM_VTABLE(IDispatch)* lpvtbl2;
47 ICOM_VTABLE(IPersistStream)* lpvtbl3;
48
49 /*
50 * Reference count for that instance of the class.
51 */
52 ULONG ref;
53
54 /*
55 * This structure contains the description of the class.
56 */
57 FONTDESC description;
58
59 /*
60 * Contain the font associated with this object.
61 */
62 HFONT gdiFont;
63
64 /*
65 * Font lock count.
66 */
67 DWORD fontLock;
68
69 /*
70 * Size ratio
71 */
72 long cyLogical;
73 long cyHimetric;
74};
75
76/*
77 * Here, I define utility macros to help with the casting of the
78 * "thisptr" parameter.
79 * There is a version to accomodate all of the VTables implemented
80 * by this object.
81 */
82#define _ICOM_THIS(class,name) class* thisptr = (class*)name;
83#define _ICOM_THIS_From_IDispatch(class, name) class* thisptr = (class*)(((char*)name)-sizeof(void*));
84#define _ICOM_THIS_From_IPersistStream(class, name) class* thisptr = (class*)(((char*)name)-2*sizeof(void*));
85
86/***********************************************************************
87 * Prototypes for the implementation functions for the IFont
88 * interface
89 */
90static OLEFontImpl* OLEFontImpl_Construct(LPFONTDESC fontDesc);
91static void OLEFontImpl_Destroy(OLEFontImpl* fontDesc);
92static HRESULT WINAPI OLEFontImpl_QueryInterface(IFont* iface, REFIID riid, VOID** ppvoid);
93static ULONG WINAPI OLEFontImpl_AddRef(IFont* iface);
94static ULONG WINAPI OLEFontImpl_Release(IFont* iface);
95static HRESULT WINAPI OLEFontImpl_get_Name(IFont* iface, BSTR* pname);
96static HRESULT WINAPI OLEFontImpl_put_Name(IFont* iface, BSTR name);
97static HRESULT WINAPI OLEFontImpl_get_Size(IFont* iface, CY* psize);
98static HRESULT WINAPI OLEFontImpl_put_Size(IFont* iface, CY size);
99static HRESULT WINAPI OLEFontImpl_get_Bold(IFont* iface, BOOL* pbold);
100static HRESULT WINAPI OLEFontImpl_put_Bold(IFont* iface, BOOL bold);
101static HRESULT WINAPI OLEFontImpl_get_Italic(IFont* iface, BOOL* pitalic);
102static HRESULT WINAPI OLEFontImpl_put_Italic(IFont* iface, BOOL italic);
103static HRESULT WINAPI OLEFontImpl_get_Underline(IFont* iface, BOOL* punderline);
104static HRESULT WINAPI OLEFontImpl_put_Underline(IFont* iface, BOOL underline);
105static HRESULT WINAPI OLEFontImpl_get_Strikethrough(IFont* iface, BOOL* pstrikethrough);
106static HRESULT WINAPI OLEFontImpl_put_Strikethrough(IFont* iface, BOOL strikethrough);
107static HRESULT WINAPI OLEFontImpl_get_Weight(IFont* iface, short* pweight);
108static HRESULT WINAPI OLEFontImpl_put_Weight(IFont* iface, short weight);
109static HRESULT WINAPI OLEFontImpl_get_Charset(IFont* iface, short* pcharset);
110static HRESULT WINAPI OLEFontImpl_put_Charset(IFont* iface, short charset);
111static HRESULT WINAPI OLEFontImpl_get_hFont(IFont* iface, HFONT* phfont);
112static HRESULT WINAPI OLEFontImpl_Clone(IFont* iface, IFont** ppfont);
113static HRESULT WINAPI OLEFontImpl_IsEqual(IFont* iface, IFont* pFontOther);
114static HRESULT WINAPI OLEFontImpl_SetRatio(IFont* iface, long cyLogical, long cyHimetric);
115static HRESULT WINAPI OLEFontImpl_QueryTextMetrics(IFont* iface, TEXTMETRICOLE* ptm);
116static HRESULT WINAPI OLEFontImpl_AddRefHfont(IFont* iface, HFONT hfont);
117static HRESULT WINAPI OLEFontImpl_ReleaseHfont(IFont* iface, HFONT hfont);
118static HRESULT WINAPI OLEFontImpl_SetHdc(IFont* iface, HDC hdc);
119
120/***********************************************************************
121 * Prototypes for the implementation functions for the IDispatch
122 * interface
123 */
124static HRESULT WINAPI OLEFontImpl_IDispatch_QueryInterface(IDispatch* iface,
125 REFIID riid,
126 VOID** ppvoid);
127static ULONG WINAPI OLEFontImpl_IDispatch_AddRef(IDispatch* iface);
128static ULONG WINAPI OLEFontImpl_IDispatch_Release(IDispatch* iface);
129static HRESULT WINAPI OLEFontImpl_GetTypeInfoCount(IDispatch* iface,
130 unsigned int* pctinfo);
131static HRESULT WINAPI OLEFontImpl_GetTypeInfo(IDispatch* iface,
132 UINT iTInfo,
133 LCID lcid,
134 ITypeInfo** ppTInfo);
135static HRESULT WINAPI OLEFontImpl_GetIDsOfNames(IDispatch* iface,
136 REFIID riid,
137 LPOLESTR* rgszNames,
138 UINT cNames,
139 LCID lcid,
140 DISPID* rgDispId);
141static HRESULT WINAPI OLEFontImpl_Invoke(IDispatch* iface,
142 DISPID dispIdMember,
143 REFIID riid,
144 LCID lcid,
145 WORD wFlags,
146 DISPPARAMS* pDispParams,
147 VARIANT* pVarResult,
148 EXCEPINFO* pExepInfo,
149 UINT* puArgErr);
150
151/***********************************************************************
152 * Prototypes for the implementation functions for the IPersistStream
153 * interface
154 */
155static HRESULT WINAPI OLEFontImpl_IPersistStream_QueryInterface(IPersistStream* iface,
156 REFIID riid,
157 VOID** ppvoid);
158static ULONG WINAPI OLEFontImpl_IPersistStream_AddRef(IPersistStream* iface);
159static ULONG WINAPI OLEFontImpl_IPersistStream_Release(IPersistStream* iface);
160static HRESULT WINAPI OLEFontImpl_GetClassID(IPersistStream* iface,
161 CLSID* pClassID);
162static HRESULT WINAPI OLEFontImpl_IsDirty(IPersistStream* iface);
163static HRESULT WINAPI OLEFontImpl_Load(IPersistStream* iface,
164 IStream* pLoadStream);
165static HRESULT WINAPI OLEFontImpl_Save(IPersistStream* iface,
166 IStream* pOutStream,
167 BOOL fClearDirty);
168static HRESULT WINAPI OLEFontImpl_GetSizeMax(IPersistStream* iface,
169 ULARGE_INTEGER* pcbSize);
170
171/*
172 * Virtual function tables for the OLEFontImpl class.
173 */
174static ICOM_VTABLE(IFont) OLEFontImpl_VTable =
175{
176 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
177 OLEFontImpl_QueryInterface,
178 OLEFontImpl_AddRef,
179 OLEFontImpl_Release,
180 OLEFontImpl_get_Name,
181 OLEFontImpl_put_Name,
182 OLEFontImpl_get_Size,
183 OLEFontImpl_put_Size,
184 OLEFontImpl_get_Bold,
185 OLEFontImpl_put_Bold,
186 OLEFontImpl_get_Italic,
187 OLEFontImpl_put_Italic,
188 OLEFontImpl_get_Underline,
189 OLEFontImpl_put_Underline,
190 OLEFontImpl_get_Strikethrough,
191 OLEFontImpl_put_Strikethrough,
192 OLEFontImpl_get_Weight,
193 OLEFontImpl_put_Weight,
194 OLEFontImpl_get_Charset,
195 OLEFontImpl_put_Charset,
196 OLEFontImpl_get_hFont,
197 OLEFontImpl_Clone,
198 OLEFontImpl_IsEqual,
199 OLEFontImpl_SetRatio,
200 OLEFontImpl_QueryTextMetrics,
201 OLEFontImpl_AddRefHfont,
202 OLEFontImpl_ReleaseHfont,
203 OLEFontImpl_SetHdc
204};
205
206static ICOM_VTABLE(IDispatch) OLEFontImpl_IDispatch_VTable =
207{
208 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
209 OLEFontImpl_IDispatch_QueryInterface,
210 OLEFontImpl_IDispatch_AddRef,
211 OLEFontImpl_IDispatch_Release,
212 OLEFontImpl_GetTypeInfoCount,
213 OLEFontImpl_GetTypeInfo,
214 OLEFontImpl_GetIDsOfNames,
215 OLEFontImpl_Invoke
216};
217
218static ICOM_VTABLE(IPersistStream) OLEFontImpl_IPersistStream_VTable =
219{
220 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
221 OLEFontImpl_IPersistStream_QueryInterface,
222 OLEFontImpl_IPersistStream_AddRef,
223 OLEFontImpl_IPersistStream_Release,
224 OLEFontImpl_GetClassID,
225 OLEFontImpl_IsDirty,
226 OLEFontImpl_Load,
227 OLEFontImpl_Save,
228 OLEFontImpl_GetSizeMax
229};
230
231/******************************************************************************
232 * OleCreateFontIndirect [OLEAUT32.420]
233 */
234INT WINAPI OleCreateFontIndirect(
235 LPFONTDESC lpFontDesc,
236 REFIID riid,
237 VOID** ppvObj)
238{
239 OLEFontImpl* newFont = 0;
240 HRESULT hr = S_OK;
241
242 /*
243 * Sanity check
244 */
245 if (ppvObj==0)
246 return E_POINTER;
247
248 *ppvObj = 0;
249
250 /*
251 * Try to construct a new instance of the class.
252 */
253 newFont = OLEFontImpl_Construct(lpFontDesc);
254
255 if (newFont == 0)
256 return E_OUTOFMEMORY;
257
258 /*
259 * Make sure it supports the interface required by the caller.
260 */
261 hr = IFont_QueryInterface((IFont*)newFont, riid, ppvObj);
262
263 /*
264 * Release the reference obtained in the constructor. If
265 * the QueryInterface was unsuccessful, it will free the class.
266 */
267 IFont_Release((IFont*)newFont);
268
269 return hr;
270}
271
272
273/***********************************************************************
274 * Implementation of the OLEFontImpl class.
275 */
276
277/************************************************************************
278 * OLEFontImpl_Construct
279 *
280 * This method will construct a new instance of the OLEFontImpl
281 * class.
282 *
283 * The caller of this method must release the object when it's
284 * done with it.
285 */
286static OLEFontImpl* OLEFontImpl_Construct(LPFONTDESC fontDesc)
287{
288 OLEFontImpl* newObject = 0;
289
290 /*
291 * Allocate space for the object.
292 */
293 newObject = (OLEFontImpl*)HeapAlloc(GetProcessHeap(), 0, sizeof(OLEFontImpl));
294
295 if (newObject==0)
296 return newObject;
297
298 /*
299 * Initialize the virtual function table.
300 */
301 newObject->lpvtbl1 = &OLEFontImpl_VTable;
302 newObject->lpvtbl2 = &OLEFontImpl_IDispatch_VTable;
303 newObject->lpvtbl3 = &OLEFontImpl_IPersistStream_VTable;
304
305 /*
306 * Start with one reference count. The caller of this function
307 * must release the interface pointer when it is done.
308 */
309 newObject->ref = 1;
310
311 /*
312 * Copy the description of the font in the object.
313 */
314 assert(fontDesc->cbSizeofstruct >= sizeof(FONTDESC));
315
316 newObject->description.cbSizeofstruct = sizeof(FONTDESC);
317 newObject->description.lpstrName = (LPWSTR)HeapAlloc(GetProcessHeap(),
318 0,
319 (lstrlenW(fontDesc->lpstrName)+1) * sizeof(WCHAR));
320 lstrcpyW(newObject->description.lpstrName, fontDesc->lpstrName);
321 newObject->description.cySize = fontDesc->cySize;
322 newObject->description.sWeight = fontDesc->sWeight;
323 newObject->description.sCharset = fontDesc->sCharset;
324 newObject->description.fItalic = fontDesc->fItalic;
325 newObject->description.fUnderline = fontDesc->fUnderline;
326 newObject->description.fStrikethrough = fontDesc->fStrikethrough;
327
328 /*
329 * Initializing all the other members.
330 */
331 newObject->gdiFont = 0;
332 newObject->fontLock = 0;
333 newObject->cyHimetric = 1;
334 newObject->cyLogical = 1;
335
336 return newObject;
337}
338
339/************************************************************************
340 * OLEFontImpl_Construct
341 *
342 * This method is called by the Release method when the reference
343 * count goes doen to 0. it will free all resources used by
344 * this object.
345 */
346static void OLEFontImpl_Destroy(OLEFontImpl* fontDesc)
347{
348 if (fontDesc->description.lpstrName!=0)
349 HeapFree(GetProcessHeap(), 0, fontDesc->description.lpstrName);
350
351 if (fontDesc->gdiFont!=0)
352 DeleteObject(fontDesc->gdiFont);
353
354 HeapFree(GetProcessHeap(), 0, fontDesc);
355}
356
357/************************************************************************
358 * OLEFontImpl_QueryInterface (IUnknown)
359 *
360 * See Windows documentation for more details on IUnknown methods.
361 */
362HRESULT WINAPI OLEFontImpl_QueryInterface(
363 IFont* iface,
364 REFIID riid,
365 void** ppvObject)
366{
367 _ICOM_THIS(OLEFontImpl, iface);
368
369 /*
370 * Perform a sanity check on the parameters.
371 */
372 if ( (thisptr==0) || (ppvObject==0) )
373 return E_INVALIDARG;
374
375 /*
376 * Initialize the return parameter.
377 */
378 *ppvObject = 0;
379
380 /*
381 * Compare the riid with the interface IDs implemented by this object.
382 */
383 if (memcmp(&IID_IUnknown, riid, sizeof(IID_IUnknown)) == 0)
384 {
385 *ppvObject = (IFont*)thisptr;
386 }
387 else if (memcmp(&IID_IFont, riid, sizeof(IID_IFont)) == 0)
388 {
389 *ppvObject = (IFont*)thisptr;
390 }
391 else if (memcmp(&IID_IDispatch, riid, sizeof(IID_IDispatch)) == 0)
392 {
393 *ppvObject = (IDispatch*)&(thisptr->lpvtbl2);
394 }
395 else if (memcmp(&IID_IFontDisp, riid, sizeof(IID_IFontDisp)) == 0)
396 {
397 *ppvObject = (IDispatch*)&(thisptr->lpvtbl2);
398 }
399 else if (memcmp(&IID_IPersistStream, riid, sizeof(IID_IPersistStream)) == 0)
400 {
401 *ppvObject = (IPersistStream*)&(thisptr->lpvtbl3);
402 }
403
404 /*
405 * Check that we obtained an interface.
406 */
407 if ((*ppvObject)==0)
408 {
409 char clsid[50];
410
411 WINE_StringFromCLSID((LPCLSID)riid,clsid);
412
413 WARN(
414 "() : asking for un supported interface %s\n",
415 clsid);
416
417 return E_NOINTERFACE;
418 }
419
420 /*
421 * Query Interface always increases the reference count by one when it is
422 * successful
423 */
424 OLEFontImpl_AddRef((IFont*)thisptr);
425
426 return S_OK;;
427}
428
429/************************************************************************
430 * OLEFontImpl_AddRef (IUnknown)
431 *
432 * See Windows documentation for more details on IUnknown methods.
433 */
434ULONG WINAPI OLEFontImpl_AddRef(
435 IFont* iface)
436{
437 _ICOM_THIS(OLEFontImpl, iface);
438
439 thisptr->ref++;
440
441 return thisptr->ref;
442}
443
444/************************************************************************
445 * OLEFontImpl_Release (IUnknown)
446 *
447 * See Windows documentation for more details on IUnknown methods.
448 */
449ULONG WINAPI OLEFontImpl_Release(
450 IFont* iface)
451{
452 _ICOM_THIS(OLEFontImpl, iface);
453
454 /*
455 * Decrease the reference count on this object.
456 */
457 thisptr->ref--;
458
459 /*
460 * If the reference count goes down to 0, perform suicide.
461 */
462 if (thisptr->ref==0)
463 {
464 OLEFontImpl_Destroy(thisptr);
465
466 return 0;
467 }
468
469 return thisptr->ref;
470}
471
472/************************************************************************
473 * OLEFontImpl_get_Name (IFont)
474 *
475 * See Windows documentation for more details on IFont methods.
476 */
477static HRESULT WINAPI OLEFontImpl_get_Name(
478 IFont* iface,
479 BSTR* pname)
480{
481 _ICOM_THIS(OLEFontImpl, iface);
482
483 /*
484 * Sanity check.
485 */
486 if (pname==0)
487 return E_POINTER;
488
489 if (thisptr->description.lpstrName!=0)
490 *pname = SysAllocString(thisptr->description.lpstrName);
491 else
492 *pname = 0;
493
494 return S_OK;
495}
496
497/************************************************************************
498 * OLEFontImpl_put_Name (IFont)
499 *
500 * See Windows documentation for more details on IFont methods.
501 */
502static HRESULT WINAPI OLEFontImpl_put_Name(
503 IFont* iface,
504 BSTR name)
505{
506 _ICOM_THIS(OLEFontImpl, iface);
507
508 if (thisptr->description.lpstrName==0)
509 {
510 thisptr->description.lpstrName = (LPWSTR)HeapAlloc(GetProcessHeap(),
511 0,
512 (lstrlenW(name)+1) * sizeof(WCHAR));
513 }
514 else
515 {
516 thisptr->description.lpstrName = (LPWSTR)HeapReAlloc(GetProcessHeap(),
517 0,
518 thisptr->description.lpstrName,
519 (lstrlenW(name)+1) * sizeof(WCHAR));
520 }
521
522 if (thisptr->description.lpstrName==0)
523 return E_OUTOFMEMORY;
524
525 lstrcpyW(thisptr->description.lpstrName, name);
526
527 return S_OK;
528}
529
530/************************************************************************
531 * OLEFontImpl_get_Size (IFont)
532 *
533 * See Windows documentation for more details on IFont methods.
534 */
535static HRESULT WINAPI OLEFontImpl_get_Size(
536 IFont* iface,
537 CY* psize)
538{
539 _ICOM_THIS(OLEFontImpl, iface);
540
541 /*
542 * Sanity check
543 */
544 if (psize==0)
545 return E_POINTER;
546
547 psize->u.Hi = 0;
548 psize->u.Lo = thisptr->description.cySize.u.Lo;
549
550 return S_OK;
551}
552
553/************************************************************************
554 * OLEFontImpl_put_Size (IFont)
555 *
556 * See Windows documentation for more details on IFont methods.
557 */
558static HRESULT WINAPI OLEFontImpl_put_Size(
559 IFont* iface,
560 CY size)
561{
562 _ICOM_THIS(OLEFontImpl, iface);
563
564 thisptr->description.cySize.u.Hi = 0;
565 thisptr->description.cySize.u.Lo = thisptr->description.cySize.u.Lo;
566
567 return S_OK;
568}
569
570/************************************************************************
571 * OLEFontImpl_get_Bold (IFont)
572 *
573 * See Windows documentation for more details on IFont methods.
574 */
575static HRESULT WINAPI OLEFontImpl_get_Bold(
576 IFont* iface,
577 BOOL* pbold)
578{
579 FIXME("():Stub\n");
580 return E_NOTIMPL;
581}
582
583/************************************************************************
584 * OLEFontImpl_put_Bold (IFont)
585 *
586 * See Windows documentation for more details on IFont methods.
587 */
588static HRESULT WINAPI OLEFontImpl_put_Bold(
589 IFont* iface,
590 BOOL bold)
591{
592 FIXME("():Stub\n");
593 return E_NOTIMPL;
594}
595
596/************************************************************************
597 * OLEFontImpl_get_Italic (IFont)
598 *
599 * See Windows documentation for more details on IFont methods.
600 */
601static HRESULT WINAPI OLEFontImpl_get_Italic(
602 IFont* iface,
603 BOOL* pitalic)
604{
605 _ICOM_THIS(OLEFontImpl, iface);
606
607 /*
608 * Sanity check
609 */
610 if (pitalic==0)
611 return E_POINTER;
612
613 *pitalic = thisptr->description.fItalic;
614
615 return S_OK;
616}
617
618/************************************************************************
619 * OLEFontImpl_put_Italic (IFont)
620 *
621 * See Windows documentation for more details on IFont methods.
622 */
623static HRESULT WINAPI OLEFontImpl_put_Italic(
624 IFont* iface,
625 BOOL italic)
626{
627 _ICOM_THIS(OLEFontImpl, iface);
628
629 thisptr->description.fItalic = italic;
630
631 return S_OK;
632}
633
634/************************************************************************
635 * OLEFontImpl_get_Underline (IFont)
636 *
637 * See Windows documentation for more details on IFont methods.
638 */
639static HRESULT WINAPI OLEFontImpl_get_Underline(
640 IFont* iface,
641 BOOL* punderline)
642{
643 _ICOM_THIS(OLEFontImpl, iface);
644
645 /*
646 * Sanity check
647 */
648 if (punderline==0)
649 return E_POINTER;
650
651 *punderline = thisptr->description.fUnderline;
652
653 return S_OK;
654}
655
656/************************************************************************
657 * OLEFontImpl_put_Underline (IFont)
658 *
659 * See Windows documentation for more details on IFont methods.
660 */
661static HRESULT WINAPI OLEFontImpl_put_Underline(
662 IFont* iface,
663 BOOL underline)
664{
665 _ICOM_THIS(OLEFontImpl, iface);
666
667 thisptr->description.fUnderline = underline;
668
669 return S_OK;
670}
671
672/************************************************************************
673 * OLEFontImpl_get_Strikethrough (IFont)
674 *
675 * See Windows documentation for more details on IFont methods.
676 */
677static HRESULT WINAPI OLEFontImpl_get_Strikethrough(
678 IFont* iface,
679 BOOL* pstrikethrough)
680{
681 _ICOM_THIS(OLEFontImpl, iface);
682
683 /*
684 * Sanity check
685 */
686 if (pstrikethrough==0)
687 return E_POINTER;
688
689 *pstrikethrough = thisptr->description.fStrikethrough;
690
691 return S_OK;
692}
693
694/************************************************************************
695 * OLEFontImpl_put_Strikethrough (IFont)
696 *
697 * See Windows documentation for more details on IFont methods.
698 */
699static HRESULT WINAPI OLEFontImpl_put_Strikethrough(
700 IFont* iface,
701 BOOL strikethrough)
702{
703 _ICOM_THIS(OLEFontImpl, iface);
704
705 thisptr->description.fStrikethrough = strikethrough;
706
707 return S_OK;
708}
709
710/************************************************************************
711 * OLEFontImpl_get_Weight (IFont)
712 *
713 * See Windows documentation for more details on IFont methods.
714 */
715static HRESULT WINAPI OLEFontImpl_get_Weight(
716 IFont* iface,
717 short* pweight)
718{
719 _ICOM_THIS(OLEFontImpl, iface);
720
721 /*
722 * Sanity check
723 */
724 if (pweight==0)
725 return E_POINTER;
726
727 *pweight = thisptr->description.sWeight;
728
729 return S_OK;
730}
731
732/************************************************************************
733 * OLEFontImpl_put_Weight (IFont)
734 *
735 * See Windows documentation for more details on IFont methods.
736 */
737static HRESULT WINAPI OLEFontImpl_put_Weight(
738 IFont* iface,
739 short weight)
740{
741 _ICOM_THIS(OLEFontImpl, iface);
742
743 thisptr->description.sWeight = weight;
744
745 return S_OK;
746}
747
748/************************************************************************
749 * OLEFontImpl_get_Charset (IFont)
750 *
751 * See Windows documentation for more details on IFont methods.
752 */
753static HRESULT WINAPI OLEFontImpl_get_Charset(
754 IFont* iface,
755 short* pcharset)
756{
757 _ICOM_THIS(OLEFontImpl, iface);
758
759 /*
760 * Sanity check
761 */
762 if (pcharset==0)
763 return E_POINTER;
764
765 *pcharset = thisptr->description.sCharset;
766
767 return S_OK;
768}
769
770/************************************************************************
771 * OLEFontImpl_put_Charset (IFont)
772 *
773 * See Windows documentation for more details on IFont methods.
774 */
775static HRESULT WINAPI OLEFontImpl_put_Charset(
776 IFont* iface,
777 short charset)
778{
779 _ICOM_THIS(OLEFontImpl, iface);
780
781 thisptr->description.sCharset = charset;
782
783 return S_OK;
784}
785
786/************************************************************************
787 * OLEFontImpl_get_hFont (IFont)
788 *
789 * See Windows documentation for more details on IFont methods.
790 */
791static HRESULT WINAPI OLEFontImpl_get_hFont(
792 IFont* iface,
793 HFONT* phfont)
794{
795 _ICOM_THIS(OLEFontImpl, iface);
796
797 if (phfont==NULL)
798 return E_POINTER;
799
800 /*
801 * Realize the font if necessary
802 */
803 if (thisptr->gdiFont==0)
804{
805 LOGFONTW logFont;
806 INT fontHeight;
807 CY cySize;
808
809 /*
810 * The height of the font returned by the get_Size property is the
811 * height of the font in points multiplied by 10000... Using some
812 * simple conversions and the ratio given by the application, it can
813 * be converted to a height in pixels.
814 */
815 IFont_get_Size(iface, &cySize);
816
817 fontHeight = MulDiv(cySize.u.Lo, 2540L, 72L);
818 fontHeight = MulDiv(fontHeight, thisptr->cyLogical,thisptr->cyHimetric);
819
820 memset(&logFont, 0, sizeof(LOGFONTW));
821
822 logFont.lfHeight = ((fontHeight%10000L)>5000L) ? (-fontHeight/10000L)-1 :
823 (-fontHeight/10000L);
824 logFont.lfItalic = thisptr->description.fItalic;
825 logFont.lfUnderline = thisptr->description.fUnderline;
826 logFont.lfStrikeOut = thisptr->description.fStrikethrough;
827 logFont.lfWeight = thisptr->description.sWeight;
828 logFont.lfCharSet = thisptr->description.sCharset;
829 logFont.lfOutPrecision = OUT_CHARACTER_PRECIS;
830 logFont.lfClipPrecision = CLIP_DEFAULT_PRECIS;
831 logFont.lfQuality = DEFAULT_QUALITY;
832 logFont.lfPitchAndFamily = DEFAULT_PITCH;
833 lstrcpyW(logFont.lfFaceName,thisptr->description.lpstrName);
834
835 thisptr->gdiFont = CreateFontIndirectW(&logFont);
836 }
837
838 *phfont = thisptr->gdiFont;
839
840 return S_OK;
841}
842
843/************************************************************************
844 * OLEFontImpl_Clone (IFont)
845 *
846 * See Windows documentation for more details on IFont methods.
847 */
848static HRESULT WINAPI OLEFontImpl_Clone(
849 IFont* iface,
850 IFont** ppfont)
851{
852 OLEFontImpl* newObject = 0;
853
854 _ICOM_THIS(OLEFontImpl, iface);
855
856 if (ppfont == NULL)
857 return E_POINTER;
858
859 *ppfont = NULL;
860
861 /*
862 * Allocate space for the object.
863 */
864 newObject = (OLEFontImpl*) HeapAlloc(GetProcessHeap(), 0, sizeof(OLEFontImpl));
865
866 if (newObject==NULL)
867 return E_OUTOFMEMORY;
868
869 *newObject = *thisptr;
870
871 /*
872 * That new object starts with a reference count of 1
873 */
874 newObject->ref = 1;
875
876 *ppfont = (IFont*)newObject;
877
878 return S_OK;
879}
880
881/************************************************************************
882 * OLEFontImpl_IsEqual (IFont)
883 *
884 * See Windows documentation for more details on IFont methods.
885 */
886static HRESULT WINAPI OLEFontImpl_IsEqual(
887 IFont* iface,
888 IFont* pFontOther)
889{
890 FIXME("():Stub\n");
891 return E_NOTIMPL;
892}
893
894/************************************************************************
895 * OLEFontImpl_SetRatio (IFont)
896 *
897 * See Windows documentation for more details on IFont methods.
898 */
899static HRESULT WINAPI OLEFontImpl_SetRatio(
900 IFont* iface,
901 long cyLogical,
902 long cyHimetric)
903{
904 _ICOM_THIS(OLEFontImpl, iface);
905
906 thisptr->cyLogical = cyLogical;
907 thisptr->cyHimetric = cyHimetric;
908
909 return S_OK;
910}
911
912/************************************************************************
913 * OLEFontImpl_QueryTextMetrics (IFont)
914 *
915 * See Windows documentation for more details on IFont methods.
916 */
917static HRESULT WINAPI OLEFontImpl_QueryTextMetrics(
918 IFont* iface,
919 TEXTMETRICOLE* ptm)
920{
921 FIXME("():Stub\n");
922 return E_NOTIMPL;
923}
924
925/************************************************************************
926 * OLEFontImpl_AddRefHfont (IFont)
927 *
928 * See Windows documentation for more details on IFont methods.
929 */
930static HRESULT WINAPI OLEFontImpl_AddRefHfont(
931 IFont* iface,
932 HFONT hfont)
933{
934 _ICOM_THIS(OLEFontImpl, iface);
935
936 if ( (hfont == 0) ||
937 (hfont != thisptr->gdiFont) )
938 return E_INVALIDARG;
939
940 thisptr->fontLock++;
941
942 return S_OK;
943}
944
945/************************************************************************
946 * OLEFontImpl_ReleaseHfont (IFont)
947 *
948 * See Windows documentation for more details on IFont methods.
949 */
950static HRESULT WINAPI OLEFontImpl_ReleaseHfont(
951 IFont* iface,
952 HFONT hfont)
953{
954 _ICOM_THIS(OLEFontImpl, iface);
955
956 if ( (hfont == 0) ||
957 (hfont != thisptr->gdiFont) )
958 return E_INVALIDARG;
959
960 thisptr->fontLock--;
961
962 /*
963 * If we just released our last font reference, destroy it.
964 */
965 if (thisptr->fontLock==0)
966 {
967 DeleteObject(thisptr->gdiFont);
968 thisptr->gdiFont = 0;
969}
970
971 return S_OK;
972}
973
974/************************************************************************
975 * OLEFontImpl_SetHdc (IFont)
976 *
977 * See Windows documentation for more details on IFont methods.
978 */
979static HRESULT WINAPI OLEFontImpl_SetHdc(
980 IFont* iface,
981 HDC hdc)
982{
983 FIXME("():Stub\n");
984 return E_NOTIMPL;
985}
986
987/************************************************************************
988 * OLEFontImpl_IDispatch_QueryInterface (IUnknown)
989 *
990 * See Windows documentation for more details on IUnknown methods.
991 */
992static HRESULT WINAPI OLEFontImpl_IDispatch_QueryInterface(
993 IDispatch* iface,
994 REFIID riid,
995 VOID** ppvoid)
996{
997 _ICOM_THIS_From_IDispatch(IFont, iface);
998
999 return IFont_QueryInterface(thisptr, riid, ppvoid);
1000}
1001
1002/************************************************************************
1003 * OLEFontImpl_IDispatch_Release (IUnknown)
1004 *
1005 * See Windows documentation for more details on IUnknown methods.
1006 */
1007static ULONG WINAPI OLEFontImpl_IDispatch_Release(
1008 IDispatch* iface)
1009{
1010 _ICOM_THIS_From_IDispatch(IFont, iface);
1011
1012 return IFont_Release(thisptr);
1013}
1014
1015/************************************************************************
1016 * OLEFontImpl_IDispatch_AddRef (IUnknown)
1017 *
1018 * See Windows documentation for more details on IUnknown methods.
1019 */
1020static ULONG WINAPI OLEFontImpl_IDispatch_AddRef(
1021 IDispatch* iface)
1022{
1023 _ICOM_THIS_From_IDispatch(IFont, iface);
1024
1025 return IFont_AddRef(thisptr);
1026}
1027
1028/************************************************************************
1029 * OLEFontImpl_GetTypeInfoCount (IDispatch)
1030 *
1031 * See Windows documentation for more details on IDispatch methods.
1032 */
1033static HRESULT WINAPI OLEFontImpl_GetTypeInfoCount(
1034 IDispatch* iface,
1035 unsigned int* pctinfo)
1036{
1037 FIXME("():Stub\n");
1038
1039 return E_NOTIMPL;
1040}
1041
1042/************************************************************************
1043 * OLEFontImpl_GetTypeInfo (IDispatch)
1044 *
1045 * See Windows documentation for more details on IDispatch methods.
1046 */
1047static HRESULT WINAPI OLEFontImpl_GetTypeInfo(
1048 IDispatch* iface,
1049 UINT iTInfo,
1050 LCID lcid,
1051 ITypeInfo** ppTInfo)
1052{
1053 FIXME("():Stub\n");
1054
1055 return E_NOTIMPL;
1056}
1057
1058/************************************************************************
1059 * OLEFontImpl_GetIDsOfNames (IDispatch)
1060 *
1061 * See Windows documentation for more details on IDispatch methods.
1062 */
1063static HRESULT WINAPI OLEFontImpl_GetIDsOfNames(
1064 IDispatch* iface,
1065 REFIID riid,
1066 LPOLESTR* rgszNames,
1067 UINT cNames,
1068 LCID lcid,
1069 DISPID* rgDispId)
1070{
1071 FIXME("():Stub\n");
1072
1073 return E_NOTIMPL;
1074}
1075
1076/************************************************************************
1077 * OLEFontImpl_Invoke (IDispatch)
1078 *
1079 * See Windows documentation for more details on IDispatch methods.
1080 */
1081static HRESULT WINAPI OLEFontImpl_Invoke(
1082 IDispatch* iface,
1083 DISPID dispIdMember,
1084 REFIID riid,
1085 LCID lcid,
1086 WORD wFlags,
1087 DISPPARAMS* pDispParams,
1088 VARIANT* pVarResult,
1089 EXCEPINFO* pExepInfo,
1090 UINT* puArgErr)
1091{
1092 FIXME("():Stub\n");
1093
1094 return E_NOTIMPL;
1095}
1096
1097/************************************************************************
1098 * OLEFontImpl_IPersistStream_QueryInterface (IUnknown)
1099 *
1100 * See Windows documentation for more details on IUnknown methods.
1101 */
1102static HRESULT WINAPI OLEFontImpl_IPersistStream_QueryInterface(
1103 IPersistStream* iface,
1104 REFIID riid,
1105 VOID** ppvoid)
1106{
1107 _ICOM_THIS_From_IPersistStream(IFont, iface);
1108
1109 return IFont_QueryInterface(thisptr, riid, ppvoid);
1110}
1111
1112/************************************************************************
1113 * OLEFontImpl_IPersistStream_Release (IUnknown)
1114 *
1115 * See Windows documentation for more details on IUnknown methods.
1116 */
1117static ULONG WINAPI OLEFontImpl_IPersistStream_Release(
1118 IPersistStream* iface)
1119{
1120 _ICOM_THIS_From_IPersistStream(IFont, iface);
1121
1122 return IFont_Release(thisptr);
1123}
1124
1125/************************************************************************
1126 * OLEFontImpl_IPersistStream_AddRef (IUnknown)
1127 *
1128 * See Windows documentation for more details on IUnknown methods.
1129 */
1130static ULONG WINAPI OLEFontImpl_IPersistStream_AddRef(
1131 IPersistStream* iface)
1132{
1133 _ICOM_THIS_From_IPersistStream(IFont, iface);
1134
1135 return IFont_AddRef(thisptr);
1136}
1137
1138/************************************************************************
1139 * OLEFontImpl_GetClassID (IPersistStream)
1140 *
1141 * See Windows documentation for more details on IPersistStream methods.
1142 */
1143static HRESULT WINAPI OLEFontImpl_GetClassID(
1144 IPersistStream* iface,
1145 CLSID* pClassID)
1146{
1147 if (pClassID==0)
1148 return E_POINTER;
1149
1150 memcpy(pClassID, &CLSID_StdFont, sizeof(CLSID_StdFont));
1151
1152 return S_OK;
1153}
1154
1155/************************************************************************
1156 * OLEFontImpl_IsDirty (IPersistStream)
1157 *
1158 * See Windows documentation for more details on IPersistStream methods.
1159 */
1160static HRESULT WINAPI OLEFontImpl_IsDirty(
1161 IPersistStream* iface)
1162{
1163 return S_OK;
1164}
1165
1166/************************************************************************
1167 * OLEFontImpl_Load (IPersistStream)
1168 *
1169 * See Windows documentation for more details on IPersistStream methods.
1170 *
1171 * This is the format of the standard font serialization as far as I
1172 * know
1173 *
1174 * Offset Type Value Comment
1175 * 0x0000 Byte Unknown Probably a version number, contains 0x01
1176 * 0x0001 Short Charset Charset value from the FONTDESC structure
1177 * 0x0003 Byte Attributes Flags defined as follows:
1178 * 00000010 - Italic
1179 * 00000100 - Underline
1180 * 00001000 - Strikethrough
1181 * 0x0004 Short Weight Weight value from FONTDESC structure
1182 * 0x0006 DWORD size "Low" portion of the cySize member of the FONTDESC
1183 * structure/
1184 * 0x000A Byte name length Length of the font name string (no null character)
1185 * 0x000B String name Name of the font (ASCII, no nul character)
1186 */
1187static HRESULT WINAPI OLEFontImpl_Load(
1188 IPersistStream* iface,
1189 IStream* pLoadStream)
1190{
1191 char readBuffer[0x100];
1192 ULONG cbRead;
1193 BYTE bVersion;
1194 BYTE bAttributes;
1195 BYTE bStringSize;
1196
1197 _ICOM_THIS_From_IPersistStream(OLEFontImpl, iface);
1198
1199 /*
1200 * Read the version byte
1201 */
1202 IStream_Read(pLoadStream, &bVersion, 1, &cbRead);
1203
1204 if ( (cbRead!=1) ||
1205 (bVersion!=0x01) )
1206 return E_FAIL;
1207
1208 /*
1209 * Charset
1210 */
1211 IStream_Read(pLoadStream, &thisptr->description.sCharset, 2, &cbRead);
1212
1213 if (cbRead!=2)
1214 return E_FAIL;
1215
1216 /*
1217 * Attributes
1218 */
1219 IStream_Read(pLoadStream, &bAttributes, 1, &cbRead);
1220
1221 if (cbRead!=1)
1222 return E_FAIL;
1223
1224 thisptr->description.fItalic = (bAttributes & FONTPERSIST_ITALIC) != 0;
1225 thisptr->description.fStrikethrough = (bAttributes & FONTPERSIST_STRIKETHROUGH) != 0;
1226 thisptr->description.fUnderline = (bAttributes & FONTPERSIST_UNDERLINE) != 0;
1227
1228 /*
1229 * Weight
1230 */
1231 IStream_Read(pLoadStream, &thisptr->description.sWeight, 2, &cbRead);
1232
1233 if (cbRead!=2)
1234 return E_FAIL;
1235
1236 /*
1237 * Size
1238 */
1239 IStream_Read(pLoadStream, &thisptr->description.cySize.u.Lo, 4, &cbRead);
1240
1241 if (cbRead!=4)
1242 return E_FAIL;
1243
1244 thisptr->description.cySize.u.Hi = 0;
1245
1246 /*
1247 * FontName
1248 */
1249 IStream_Read(pLoadStream, &bStringSize, 1, &cbRead);
1250
1251 if (cbRead!=1)
1252 return E_FAIL;
1253
1254 memset(readBuffer, 0, 0x100);
1255 IStream_Read(pLoadStream, readBuffer, bStringSize, &cbRead);
1256
1257 if (cbRead!=bStringSize)
1258 return E_FAIL;
1259
1260 if (thisptr->description.lpstrName!=0)
1261 HeapFree(GetProcessHeap(), 0, thisptr->description.lpstrName);
1262
1263 thisptr->description.lpstrName = HEAP_strdupAtoW(GetProcessHeap(),
1264 HEAP_ZERO_MEMORY,
1265 readBuffer);
1266
1267 return S_OK;
1268}
1269
1270/************************************************************************
1271 * OLEFontImpl_Save (IPersistStream)
1272 *
1273 * See Windows documentation for more details on IPersistStream methods.
1274 */
1275static HRESULT WINAPI OLEFontImpl_Save(
1276 IPersistStream* iface,
1277 IStream* pOutStream,
1278 BOOL fClearDirty)
1279{
1280 char* writeBuffer = NULL;
1281 ULONG cbWritten;
1282 BYTE bVersion = 0x01;
1283 BYTE bAttributes;
1284 BYTE bStringSize;
1285
1286 _ICOM_THIS_From_IPersistStream(OLEFontImpl, iface);
1287
1288 /*
1289 * Read the version byte
1290 */
1291 IStream_Write(pOutStream, &bVersion, 1, &cbWritten);
1292
1293 if (cbWritten!=1)
1294 return E_FAIL;
1295
1296 /*
1297 * Charset
1298 */
1299 IStream_Write(pOutStream, &thisptr->description.sCharset, 2, &cbWritten);
1300
1301 if (cbWritten!=2)
1302 return E_FAIL;
1303
1304 /*
1305 * Attributes
1306 */
1307 bAttributes = 0;
1308
1309 if (thisptr->description.fItalic)
1310 bAttributes |= FONTPERSIST_ITALIC;
1311
1312 if (thisptr->description.fStrikethrough)
1313 bAttributes |= FONTPERSIST_STRIKETHROUGH;
1314
1315 if (thisptr->description.fUnderline)
1316 bAttributes |= FONTPERSIST_UNDERLINE;
1317
1318 IStream_Write(pOutStream, &bAttributes, 1, &cbWritten);
1319
1320 if (cbWritten!=1)
1321 return E_FAIL;
1322
1323 /*
1324 * Weight
1325 */
1326 IStream_Write(pOutStream, &thisptr->description.sWeight, 2, &cbWritten);
1327
1328 if (cbWritten!=2)
1329 return E_FAIL;
1330
1331 /*
1332 * Size
1333 */
1334 IStream_Write(pOutStream, &thisptr->description.cySize.u.Lo, 4, &cbWritten);
1335
1336 if (cbWritten!=4)
1337 return E_FAIL;
1338
1339 /*
1340 * FontName
1341 */
1342 if (thisptr->description.lpstrName!=0)
1343 bStringSize = lstrlenW(thisptr->description.lpstrName);
1344 else
1345 bStringSize = 0;
1346
1347 IStream_Write(pOutStream, &bStringSize, 1, &cbWritten);
1348
1349 if (cbWritten!=1)
1350 return E_FAIL;
1351
1352 if (bStringSize!=0)
1353 {
1354 writeBuffer = HEAP_strdupWtoA(GetProcessHeap(),
1355 HEAP_ZERO_MEMORY,
1356 thisptr->description.lpstrName);
1357
1358 if (writeBuffer==0)
1359 return E_OUTOFMEMORY;
1360
1361 IStream_Write(pOutStream, writeBuffer, bStringSize, &cbWritten);
1362
1363 HeapFree(GetProcessHeap(), 0, writeBuffer);
1364
1365 if (cbWritten!=bStringSize)
1366 return E_FAIL;
1367 }
1368
1369 return S_OK;
1370}
1371
1372/************************************************************************
1373 * OLEFontImpl_GetSizeMax (IPersistStream)
1374 *
1375 * See Windows documentation for more details on IPersistStream methods.
1376 */
1377static HRESULT WINAPI OLEFontImpl_GetSizeMax(
1378 IPersistStream* iface,
1379 ULARGE_INTEGER* pcbSize)
1380{
1381 _ICOM_THIS_From_IPersistStream(OLEFontImpl, iface);
1382
1383 if (pcbSize==NULL)
1384 return E_POINTER;
1385
1386 pcbSize->HighPart = 0;
1387 pcbSize->LowPart = 0;
1388
1389 pcbSize->LowPart += sizeof(BYTE); /* Version */
1390 pcbSize->LowPart += sizeof(WORD); /* Lang code */
1391 pcbSize->LowPart += sizeof(BYTE); /* Flags */
1392 pcbSize->LowPart += sizeof(WORD); /* Weight */
1393 pcbSize->LowPart += sizeof(DWORD); /* Size */
1394 pcbSize->LowPart += sizeof(BYTE); /* StrLength */
1395
1396 if (thisptr->description.lpstrName!=0)
1397 pcbSize->LowPart += lstrlenW(thisptr->description.lpstrName);
1398
1399 return S_OK;
1400}
Note: See TracBrowser for help on using the repository browser.