OLD | NEW |
| (Empty) |
1 /* | |
2 * This file is part of the internal font implementation. It should not be incl
uded by anyone other than | |
3 * FontMac.cpp, FontWin.cpp and Font.cpp. | |
4 * | |
5 * Copyright (C) 2006, 2007, 2008 Apple Inc. | |
6 * Copyright (C) 2007 Alp Toker | |
7 * Copyright (C) 2008, 2010, 2011 Brent Fulgham | |
8 * | |
9 * This library is free software; you can redistribute it and/or | |
10 * modify it under the terms of the GNU Library General Public | |
11 * License as published by the Free Software Foundation; either | |
12 * version 2 of the License, or (at your option) any later version. | |
13 * | |
14 * This library is distributed in the hope that it will be useful, | |
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
17 * Library General Public License for more details. | |
18 * | |
19 * You should have received a copy of the GNU Library General Public License | |
20 * along with this library; see the file COPYING.LIB. If not, write to | |
21 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | |
22 * Boston, MA 02110-1301, USA. | |
23 * | |
24 */ | |
25 | |
26 #include "config.h" | |
27 #include "FontPlatformData.h" | |
28 | |
29 #include <wtf/HashMap.h> | |
30 #include <wtf/RetainPtr.h> | |
31 #include <wtf/Vector.h> | |
32 #include <wtf/text/StringHash.h> | |
33 #include <wtf/text/WTFString.h> | |
34 | |
35 #include <cairo-win32.h> | |
36 | |
37 using namespace std; | |
38 | |
39 namespace WebCore { | |
40 | |
41 void FontPlatformData::platformDataInit(HFONT font, float size, HDC hdc, WCHAR*
faceName) | |
42 { | |
43 cairo_font_face_t* fontFace = cairo_win32_font_face_create_for_hfont(font); | |
44 | |
45 cairo_matrix_t sizeMatrix, ctm; | |
46 cairo_matrix_init_identity(&ctm); | |
47 cairo_matrix_init_scale(&sizeMatrix, size, size); | |
48 | |
49 static cairo_font_options_t* fontOptions = 0; | |
50 if (!fontOptions) { | |
51 fontOptions = cairo_font_options_create(); | |
52 cairo_font_options_set_antialias(fontOptions, CAIRO_ANTIALIAS_SUBPIXEL); | |
53 } | |
54 | |
55 m_scaledFont = cairo_scaled_font_create(fontFace, &sizeMatrix, &ctm, fontOpt
ions); | |
56 cairo_font_face_destroy(fontFace); | |
57 } | |
58 | |
59 FontPlatformData::FontPlatformData(cairo_font_face_t* fontFace, float size, bool
bold, bool oblique) | |
60 : m_font(0) | |
61 , m_size(size) | |
62 , m_orientation(Horizontal) | |
63 , m_widthVariant(RegularWidth) | |
64 , m_scaledFont(0) | |
65 , m_isColorBitmapFont(false) | |
66 , m_syntheticBold(bold) | |
67 , m_syntheticOblique(oblique) | |
68 , m_useGDI(false) | |
69 { | |
70 cairo_matrix_t fontMatrix; | |
71 cairo_matrix_init_scale(&fontMatrix, size, size); | |
72 cairo_matrix_t ctm; | |
73 cairo_matrix_init_identity(&ctm); | |
74 cairo_font_options_t* options = cairo_font_options_create(); | |
75 | |
76 // We force antialiasing and disable hinting to provide consistent | |
77 // typographic qualities for custom fonts on all platforms. | |
78 cairo_font_options_set_hint_style(options, CAIRO_HINT_STYLE_NONE); | |
79 cairo_font_options_set_antialias(options, CAIRO_ANTIALIAS_GRAY); | |
80 | |
81 if (syntheticOblique()) { | |
82 static const float syntheticObliqueSkew = -tanf(14 * acosf(0) / 90); | |
83 cairo_matrix_t skew = {1, 0, syntheticObliqueSkew, 1, 0, 0}; | |
84 cairo_matrix_multiply(&fontMatrix, &skew, &fontMatrix); | |
85 } | |
86 | |
87 m_scaledFont = cairo_scaled_font_create(fontFace, &fontMatrix, &ctm, options)
; | |
88 cairo_font_options_destroy(options); | |
89 } | |
90 | |
91 FontPlatformData::~FontPlatformData() | |
92 { | |
93 if (m_scaledFont && m_scaledFont != hashTableDeletedFontValue()) | |
94 cairo_scaled_font_destroy(m_scaledFont); | |
95 } | |
96 | |
97 void FontPlatformData::platformDataInit(const FontPlatformData& source) | |
98 { | |
99 m_font = source.m_font; | |
100 m_useGDI = source.m_useGDI; | |
101 m_scaledFont = 0; | |
102 | |
103 if (source.m_scaledFont) | |
104 m_scaledFont = cairo_scaled_font_reference(source.m_scaledFont); | |
105 } | |
106 | |
107 const FontPlatformData& FontPlatformData::platformDataAssign(const FontPlatformD
ata& other) | |
108 { | |
109 m_font = other.m_font; | |
110 m_useGDI = other.m_useGDI; | |
111 | |
112 if (m_scaledFont && m_scaledFont != hashTableDeletedFontValue()) | |
113 cairo_scaled_font_destroy(m_scaledFont); | |
114 | |
115 m_scaledFont = cairo_scaled_font_reference(other.m_scaledFont); | |
116 | |
117 return *this; | |
118 } | |
119 | |
120 bool FontPlatformData::platformIsEqual(const FontPlatformData& other) const | |
121 { | |
122 return m_font == other.m_font | |
123 && m_scaledFont == other.m_scaledFont | |
124 && m_useGDI == other.m_useGDI; | |
125 } | |
126 | |
127 } | |
OLD | NEW |