wined3d: Get rid of the invymat.
[wine] / dlls / 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 /* FIXME: use graphics */
92 GpStatus WINGDIPAPI GdipGetLogFontW(GpFont *font, GpGraphics *graphics,
93     LOGFONTW *lfw)
94 {
95     if(!font || !graphics || !lfw)
96         return InvalidParameter;
97
98     memcpy(lfw, &font->lfw, sizeof(LOGFONTW));
99
100     return Ok;
101 }