- Synchronize with wine head
[reactos.git] / reactos / dll / win32 / gdiplus / font.c
1 /*
2 * Copyright (C) 2007 Google (Evan Stade)
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17 */
18
19 #include <stdarg.h>
20
21 #include "windef.h"
22 #include "winbase.h"
23 #include "wingdi.h"
24 #include "winnls.h"
25
26 #include "objbase.h"
27
28 #include "gdiplus.h"
29 #include "gdiplus_private.h"
30
31 GpStatus WINGDIPAPI GdipCreateFontFromLogfontW(HDC hdc,
32 GDIPCONST LOGFONTW *logfont, GpFont **font)
33 {
34 HFONT hfont, oldfont;
35 TEXTMETRICW textmet;
36
37 if(!logfont || !font)
38 return InvalidParameter;
39
40 *font = GdipAlloc(sizeof(GpFont));
41 if(!*font) return OutOfMemory;
42
43 memcpy(&(*font)->lfw.lfFaceName, logfont->lfFaceName, LF_FACESIZE *
44 sizeof(WCHAR));
45 (*font)->lfw.lfHeight = logfont->lfHeight;
46 (*font)->lfw.lfItalic = logfont->lfItalic;
47 (*font)->lfw.lfUnderline = logfont->lfUnderline;
48 (*font)->lfw.lfStrikeOut = logfont->lfStrikeOut;
49
50 hfont = CreateFontIndirectW(&(*font)->lfw);
51 oldfont = SelectObject(hdc, hfont);
52 GetTextMetricsW(hdc, &textmet);
53
54 (*font)->lfw.lfHeight = -textmet.tmHeight;
55 (*font)->lfw.lfWeight = textmet.tmWeight;
56
57 SelectObject(hdc, oldfont);
58 DeleteObject(hfont);
59
60 return Ok;
61 }
62
63 GpStatus WINGDIPAPI GdipCreateFontFromLogfontA(HDC hdc,
64 GDIPCONST LOGFONTA *lfa, GpFont **font)
65 {
66 LOGFONTW lfw;
67
68 if(!lfa || !font)
69 return InvalidParameter;
70
71 memcpy(&lfw, lfa, sizeof(LOGFONTA));
72
73 if(!MultiByteToWideChar(CP_ACP, 0, lfa->lfFaceName, -1, lfw.lfFaceName, LF_FACESIZE))
74 return GenericError;
75
76 GdipCreateFontFromLogfontW(hdc, &lfw, font);
77
78 return Ok;
79 }
80
81 GpStatus WINGDIPAPI GdipDeleteFont(GpFont* font)
82 {
83 if(!font)
84 return InvalidParameter;
85
86 GdipFree(font);
87
88 return Ok;
89 }
90
91 GpStatus WINGDIPAPI GdipCreateFontFromDC(HDC hdc, GpFont **font)
92 {
93 HFONT hfont;
94 LOGFONTW lfw;
95
96 if(!font)
97 return InvalidParameter;
98
99 hfont = (HFONT)GetCurrentObject(hdc, OBJ_FONT);
100 if(!hfont)
101 return GenericError;
102
103 if(!GetObjectW(hfont, sizeof(LOGFONTW), &lfw))
104 return GenericError;
105
106 return GdipCreateFontFromLogfontW(hdc, &lfw, font);
107 }
108
109 /* FIXME: use graphics */
110 GpStatus WINGDIPAPI GdipGetLogFontW(GpFont *font, GpGraphics *graphics,
111 LOGFONTW *lfw)
112 {
113 if(!font || !graphics || !lfw)
114 return InvalidParameter;
115
116 *lfw = font->lfw;
117
118 return Ok;
119 }
120
121 GpStatus WINGDIPAPI GdipCloneFont(GpFont *font, GpFont **cloneFont)
122 {
123 if(!font || !cloneFont)
124 return InvalidParameter;
125
126 *cloneFont = GdipAlloc(sizeof(GpFont));
127 if(!*cloneFont) return OutOfMemory;
128
129 **cloneFont = *font;
130
131 return Ok;
132 }