1 /*
2 * This file is part of the internal font implementation. It should not be included by anyone other than
3 * FontMac.cpp, FontWin.cpp and Font.cpp.
4 *
5 * Copyright (C) 2006, 2007, 2008 Apple Inc.
6 * Copyright (C) 2008 Brent Fulgham
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
12 *
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
17 *
18 * You should have received a copy of the GNU Library General Public License
19 * along with this library; see the file COPYING.LIB. If not, write to
20 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301, USA.
22 *
23 */
24
25 #include "config.h"
26 #include "FontPlatformData.h"
27
28 #include "PlatformString.h"
29 #include "StringHash.h"
30 #include <wtf/HashMap.h>
31 #include <wtf/RetainPtr.h>
32 #include <wtf/Vector.h>
33
34 using std::min;
35
36 namespace WebCore {
37
FontPlatformData(HFONT font,float size,bool bold,bool oblique,bool useGDI)38 FontPlatformData::FontPlatformData(HFONT font, float size, bool bold, bool oblique, bool useGDI)
39 : m_font(RefCountedHFONT::create(font))
40 , m_size(size)
41 #if PLATFORM(CG)
42 , m_cgFont(0)
43 #elif PLATFORM(CAIRO)
44 , m_fontFace(0)
45 , m_scaledFont(0)
46 #endif
47 , m_syntheticBold(bold)
48 , m_syntheticOblique(oblique)
49 , m_useGDI(useGDI)
50 {
51 HDC hdc = GetDC(0);
52 SaveDC(hdc);
53
54 SelectObject(hdc, font);
55 UINT bufferSize = GetOutlineTextMetrics(hdc, 0, NULL);
56
57 ASSERT_WITH_MESSAGE(bufferSize, "Bitmap fonts not supported with CoreGraphics.");
58
59 if (bufferSize) {
60 OUTLINETEXTMETRICW* metrics = (OUTLINETEXTMETRICW*)malloc(bufferSize);
61
62 GetOutlineTextMetricsW(hdc, bufferSize, metrics);
63 WCHAR* faceName = (WCHAR*)((uintptr_t)metrics + (uintptr_t)metrics->otmpFaceName);
64
65 platformDataInit(font, size, hdc, faceName);
66
67 free(metrics);
68 }
69
70 RestoreDC(hdc, -1);
71 ReleaseDC(0, hdc);
72 }
73
FontPlatformData(float size,bool bold,bool oblique)74 FontPlatformData::FontPlatformData(float size, bool bold, bool oblique)
75 : m_size(size)
76 #if PLATFORM(CG)
77 , m_cgFont(0)
78 #elif PLATFORM(CAIRO)
79 , m_fontFace(0)
80 , m_scaledFont(0)
81 #endif
82 , m_syntheticBold(bold)
83 , m_syntheticOblique(oblique)
84 , m_useGDI(false)
85 {
86 }
87
88 #ifndef NDEBUG
description() const89 String FontPlatformData::description() const
90 {
91 return String();
92 }
93 #endif
94
95 }
96