Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(45)

Side by Side Diff: Source/platform/fonts/FontPlatformData.cpp

Issue 557823003: Revert "Merge FontPlatformDataHarfBuzz into FontPlatformData" (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011 Brent Fulgham 2 * Copyright (C) 2011 Brent Fulgham
3 * 3 *
4 * This library is free software; you can redistribute it and/or 4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public 5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either 6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version. 7 * version 2 of the License, or (at your option) any later version.
8 * 8 *
9 * This library is distributed in the hope that it will be useful, 9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details. 12 * Library General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU Library General Public License 14 * You should have received a copy of the GNU Library General Public License
15 * along with this library; see the file COPYING.LIB. If not, write to 15 * along with this library; see the file COPYING.LIB. If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA. 17 * Boston, MA 02110-1301, USA.
18 * 18 *
19 */ 19 */
20 20
21 #include "config.h" 21 #include "config.h"
22 #include "platform/fonts/FontPlatformData.h" 22 #include "platform/fonts/FontPlatformData.h"
23 23
24 #include "SkTypeface.h" 24 #include "SkTypeface.h"
25 #include "platform/fonts/harfbuzz/HarfBuzzFace.h" 25 #include "platform/fonts/harfbuzz/HarfBuzzFace.h"
26 #include "wtf/HashMap.h" 26 #include "wtf/HashMap.h"
27 #include "wtf/text/StringHash.h" 27 #include "wtf/text/StringHash.h"
28 #include "wtf/text/WTFString.h" 28 #include "wtf/text/WTFString.h"
29 29
30 #if OS(MACOSX)
31 #include "third_party/skia/include/ports/SkTypeface_mac.h"
32 #endif
33
34 using namespace std; 30 using namespace std;
35 31
36 namespace blink { 32 namespace blink {
37 33
38 FontPlatformData::FontPlatformData(WTF::HashTableDeletedValueType) 34 FontPlatformData::FontPlatformData(WTF::HashTableDeletedValueType)
39 : m_typeface(nullptr) 35 : m_textSize(0)
40 #if !OS(WIN)
41 , m_family(CString())
42 #endif
43 , m_textSize(0)
44 , m_syntheticBold(false) 36 , m_syntheticBold(false)
45 , m_syntheticItalic(false) 37 , m_syntheticItalic(false)
46 , m_orientation(Horizontal) 38 , m_orientation(Horizontal)
47 #if OS(MACOSX)
48 , m_isColorBitmapFont(false) 39 , m_isColorBitmapFont(false)
49 , m_isCompositeFontReference(false) 40 , m_isCompositeFontReference(false)
50 #endif
51 , m_widthVariant(RegularWidth) 41 , m_widthVariant(RegularWidth)
52 #if OS(MACOSX) 42 #if OS(MACOSX)
53 , m_font(nullptr) 43 , m_font(nullptr)
54 #endif 44 #endif
55 , m_isHashTableDeletedValue(true) 45 , m_isHashTableDeletedValue(true)
56 #if OS(WIN)
57 , m_paintTextFlags(0)
58 , m_minSizeForAntiAlias(0)
59 , m_minSizeForSubpixel(0)
60 , m_useSubpixelPositioning(false)
61 #endif
62 { 46 {
63 } 47 }
64 48
65 FontPlatformData::FontPlatformData() 49 FontPlatformData::FontPlatformData()
66 : m_typeface(nullptr) 50 : m_textSize(0)
67 #if !OS(WIN)
68 , m_family(CString())
69 #endif
70 , m_textSize(0)
71 , m_syntheticBold(false) 51 , m_syntheticBold(false)
72 , m_syntheticItalic(false) 52 , m_syntheticItalic(false)
73 , m_orientation(Horizontal) 53 , m_orientation(Horizontal)
74 #if OS(MACOSX)
75 , m_isColorBitmapFont(false) 54 , m_isColorBitmapFont(false)
76 , m_isCompositeFontReference(false) 55 , m_isCompositeFontReference(false)
77 #endif
78 , m_widthVariant(RegularWidth) 56 , m_widthVariant(RegularWidth)
79 #if OS(MACOSX) 57 #if OS(MACOSX)
80 , m_font(nullptr) 58 , m_font(nullptr)
81 #endif 59 #endif
82 , m_isHashTableDeletedValue(false) 60 , m_isHashTableDeletedValue(false)
83 #if OS(WIN)
84 , m_paintTextFlags(0)
85 , m_minSizeForAntiAlias(0)
86 , m_minSizeForSubpixel(0)
87 , m_useSubpixelPositioning(false)
88 #endif
89 { 61 {
90 } 62 }
91 63
92 FontPlatformData::FontPlatformData(float size, bool syntheticBold, bool syntheti cItalic, FontOrientation orientation, FontWidthVariant widthVariant) 64 FontPlatformData::FontPlatformData(float size, bool syntheticBold, bool syntheti cItalic, FontOrientation orientation, FontWidthVariant widthVariant)
93 : m_typeface(nullptr) 65 : m_textSize(size)
94 #if !OS(WIN)
95 , m_family(CString())
96 #endif
97 , m_textSize(size)
98 , m_syntheticBold(syntheticBold) 66 , m_syntheticBold(syntheticBold)
99 , m_syntheticItalic(syntheticItalic) 67 , m_syntheticItalic(syntheticItalic)
100 , m_orientation(orientation) 68 , m_orientation(orientation)
101 #if OS(MACOSX)
102 , m_isColorBitmapFont(false) 69 , m_isColorBitmapFont(false)
103 , m_isCompositeFontReference(false) 70 , m_isCompositeFontReference(false)
104 #endif
105 , m_widthVariant(widthVariant) 71 , m_widthVariant(widthVariant)
106 #if OS(MACOSX) 72 #if OS(MACOSX)
107 , m_font(nullptr) 73 , m_font(nullptr)
108 #endif 74 #endif
109 , m_isHashTableDeletedValue(false) 75 , m_isHashTableDeletedValue(false)
110 #if OS(WIN)
111 , m_paintTextFlags(0)
112 , m_minSizeForAntiAlias(0)
113 , m_minSizeForSubpixel(0)
114 , m_useSubpixelPositioning(false)
115 #endif
116 { 76 {
117 } 77 }
118 78
119 FontPlatformData::FontPlatformData(const FontPlatformData& source)
120 : m_typeface(source.m_typeface)
121 #if !OS(WIN)
122 , m_family(source.m_family)
123 #endif
124 , m_textSize(source.m_textSize)
125 , m_syntheticBold(source.m_syntheticBold)
126 , m_syntheticItalic(source.m_syntheticItalic)
127 , m_orientation(source.m_orientation)
128 #if OS(MACOSX)
129 , m_isColorBitmapFont(source.m_isColorBitmapFont)
130 , m_isCompositeFontReference(source.m_isCompositeFontReference)
131 #endif
132 , m_widthVariant(source.m_widthVariant)
133 #if !OS(MACOSX)
134 , m_style(source.m_style)
135 #endif
136 , m_harfBuzzFace(nullptr)
137 , m_isHashTableDeletedValue(false)
138 #if OS(WIN)
139 , m_paintTextFlags(source.m_paintTextFlags)
140 , m_minSizeForAntiAlias(source.m_minSizeForAntiAlias)
141 , m_minSizeForSubpixel(source.m_minSizeForSubpixel)
142 , m_useSubpixelPositioning(source.m_useSubpixelPositioning)
143 #endif
144 {
145 #if OS(MACOSX)
146 platformDataInit(source);
147 #endif
148 }
149
150
151 #if OS(MACOSX) 79 #if OS(MACOSX)
152 FontPlatformData::FontPlatformData(CGFontRef cgFont, float size, bool syntheticB old, bool syntheticItalic, FontOrientation orientation, FontWidthVariant widthVa riant) 80 FontPlatformData::FontPlatformData(CGFontRef cgFont, float size, bool syntheticB old, bool syntheticItalic, FontOrientation orientation, FontWidthVariant widthVa riant)
153 : m_typeface(nullptr) 81 : m_textSize(size)
154 #if !OS(WIN)
155 , m_family(CString())
156 #endif
157 , m_textSize(size)
158 , m_syntheticBold(syntheticBold) 82 , m_syntheticBold(syntheticBold)
159 , m_syntheticItalic(syntheticItalic) 83 , m_syntheticItalic(syntheticItalic)
160 , m_orientation(orientation) 84 , m_orientation(orientation)
161 , m_isColorBitmapFont(false) 85 , m_isColorBitmapFont(false)
162 , m_isCompositeFontReference(false) 86 , m_isCompositeFontReference(false)
163 , m_widthVariant(widthVariant) 87 , m_widthVariant(widthVariant)
164 , m_font(nullptr) 88 , m_font(nullptr)
165 , m_cgFont(cgFont) 89 , m_cgFont(cgFont)
166 , m_isHashTableDeletedValue(false) 90 , m_isHashTableDeletedValue(false)
167 { 91 {
168 } 92 }
169
170 #else
171
172 FontPlatformData::FontPlatformData(PassRefPtr<SkTypeface> tf, const char* family , float textSize, bool syntheticBold, bool syntheticItalic, FontOrientation orie ntation, bool subpixelTextPosition)
173 : m_typeface(tf)
174 #if !OS(WIN)
175 , m_family(family)
176 #endif
177 , m_textSize(textSize)
178 , m_syntheticBold(syntheticBold)
179 , m_syntheticItalic(syntheticItalic)
180 , m_orientation(orientation)
181 , m_isHashTableDeletedValue(false)
182 #if OS(WIN)
183 , m_paintTextFlags(0)
184 , m_minSizeForAntiAlias(0)
185 , m_minSizeForSubpixel(0)
186 , m_useSubpixelPositioning(subpixelTextPosition)
187 #endif
188 {
189 querySystemForRenderStyle(subpixelTextPosition);
190 }
191
192
193 FontPlatformData::FontPlatformData(const FontPlatformData& src, float textSize)
194 : m_typeface(src.m_typeface)
195 #if !OS(WIN)
196 , m_family(src.m_family)
197 #endif
198 , m_textSize(textSize)
199 , m_syntheticBold(src.m_syntheticBold)
200 , m_syntheticItalic(src.m_syntheticItalic)
201 , m_orientation(src.m_orientation)
202 , m_harfBuzzFace(nullptr)
203 , m_isHashTableDeletedValue(false)
204 #if OS(WIN)
205 , m_paintTextFlags(src.m_paintTextFlags)
206 , m_minSizeForAntiAlias(src.m_minSizeForAntiAlias)
207 , m_minSizeForSubpixel(src.m_minSizeForSubpixel)
208 , m_useSubpixelPositioning(src.m_useSubpixelPositioning)
209 #endif
210 {
211 querySystemForRenderStyle(FontDescription::subpixelPositioning());
212 }
213 #endif 93 #endif
214 94
215 FontPlatformData::~FontPlatformData() 95 FontPlatformData::FontPlatformData(const FontPlatformData& source)
96 : m_textSize(source.m_textSize)
97 , m_syntheticBold(source.m_syntheticBold)
98 , m_syntheticItalic(source.m_syntheticItalic)
99 , m_orientation(source.m_orientation)
100 , m_isColorBitmapFont(source.m_isColorBitmapFont)
101 , m_isCompositeFontReference(source.m_isCompositeFontReference)
102 , m_widthVariant(source.m_widthVariant)
103 , m_isHashTableDeletedValue(false)
216 { 104 {
217 #if OS(MACOSX) 105 platformDataInit(source);
218 if (m_font)
219 CFRelease(m_font);
220 #endif
221 } 106 }
222 107
223 const FontPlatformData& FontPlatformData::operator=(const FontPlatformData& othe r) 108 const FontPlatformData& FontPlatformData::operator=(const FontPlatformData& othe r)
224 { 109 {
225 // Check for self-assignment. 110 // Check for self-assignment.
226 if (this == &other) 111 if (this == &other)
227 return *this; 112 return *this;
228 113
229 m_typeface = other.m_typeface;
230 #if !OS(WIN)
231 m_family = other.m_family;
232 #endif
233 m_textSize = other.m_textSize;
234 m_syntheticBold = other.m_syntheticBold; 114 m_syntheticBold = other.m_syntheticBold;
235 m_syntheticItalic = other.m_syntheticItalic; 115 m_syntheticItalic = other.m_syntheticItalic;
236 m_harfBuzzFace = nullptr;
237 m_orientation = other.m_orientation; 116 m_orientation = other.m_orientation;
117 m_textSize = other.m_textSize;
238 m_widthVariant = other.m_widthVariant; 118 m_widthVariant = other.m_widthVariant;
239 #if OS(MACOSX)
240 m_isColorBitmapFont = other.m_isColorBitmapFont; 119 m_isColorBitmapFont = other.m_isColorBitmapFont;
241 m_isCompositeFontReference = other.m_isCompositeFontReference; 120 m_isCompositeFontReference = other.m_isCompositeFontReference;
242 #else
243 m_style = other.m_style;
244 #endif
245 m_widthVariant = other.m_widthVariant;
246 121
247 #if OS(WIN)
248 m_paintTextFlags = 0;
249 m_minSizeForAntiAlias = other.m_minSizeForAntiAlias;
250 m_minSizeForSubpixel = other.m_minSizeForSubpixel;
251 m_useSubpixelPositioning = other.m_useSubpixelPositioning;
252 #endif
253
254 #if OS(MACOSX)
255 return platformDataAssign(other); 122 return platformDataAssign(other);
256 #else
257 return *this;
258 #endif
259 } 123 }
260 124
261 bool FontPlatformData::operator==(const FontPlatformData& a) const 125 bool FontPlatformData::operator==(const FontPlatformData& a) const
262 { 126 {
263 // If either of the typeface pointers are null then we test for pointer
264 // equality. Otherwise, we call SkTypeface::Equal on the valid pointers.
265 bool typefacesEqual = false;
266 #if !OS(MACOSX)
267 if (!m_typeface || !a.m_typeface)
268 typefacesEqual = m_typeface == a.m_typeface;
269 else
270 typefacesEqual = SkTypeface::Equal(m_typeface.get(), a.m_typeface.get()) ;
271 #else
272 if (m_font || a.m_font)
273 typefacesEqual = m_font == a.m_font;
274 else
275 typefacesEqual = m_cgFont == a.m_cgFont;
276 #endif
277 127
278 return typefacesEqual 128 return platformIsEqual(a)
279 && m_textSize == a.m_textSize 129 && m_textSize == a.m_textSize
280 && m_isHashTableDeletedValue == a.m_isHashTableDeletedValue 130 && m_isHashTableDeletedValue == a.m_isHashTableDeletedValue
281 && m_syntheticBold == a.m_syntheticBold 131 && m_syntheticBold == a.m_syntheticBold
282 && m_syntheticItalic == a.m_syntheticItalic 132 && m_syntheticItalic == a.m_syntheticItalic
283 && m_orientation == a.m_orientation 133 && m_orientation == a.m_orientation
284 #if !OS(MACOSX) 134 #if !OS(MACOSX)
285 && m_style == a.m_style 135 && m_style == a.m_style
286 #else 136 #endif
287 && m_isColorBitmapFont == a.m_isColorBitmapFont 137 && m_isColorBitmapFont == a.m_isColorBitmapFont
288 && m_isCompositeFontReference == a.m_isCompositeFontReference 138 && m_isCompositeFontReference == a.m_isCompositeFontReference
289 #endif
290 && m_widthVariant == a.m_widthVariant; 139 && m_widthVariant == a.m_widthVariant;
291 } 140 }
292 141
293 SkFontID FontPlatformData::uniqueID() const
294 {
295 return typeface()->uniqueID();
296 }
297
298 String FontPlatformData::fontFamilyName() const
299 {
300 // FIXME(crbug.com/326582): come up with a proper way of handling SVG.
301 if (!this->typeface())
302 return "";
303 SkTypeface::LocalizedStrings* fontFamilyIterator = this->typeface()->createF amilyNameIterator();
304 SkTypeface::LocalizedString localizedString;
305 while (fontFamilyIterator->next(&localizedString) && !localizedString.fStrin g.size()) { }
306 fontFamilyIterator->unref();
307 return String(localizedString.fString.c_str());
308 }
309
310 bool FontPlatformData::isFixedPitch() const
311 {
312 return typeface() && typeface()->isFixedPitch();
313 }
314
315 SkTypeface* FontPlatformData::typeface() const
316 {
317 #if OS(MACOSX)
318 if (!m_typeface)
319 m_typeface = adoptRef(SkCreateTypefaceFromCTFont(ctFont()));
320 #endif
321 return m_typeface.get();
322 }
323
324 HarfBuzzFace* FontPlatformData::harfBuzzFace() const
325 {
326 #if OS(MACOSX)
327 CTFontRef font = ctFont();
328 // Keeping the decision not to pass AAT font to HarfBuzz for now,
329 // until we switch to HarfBuzz as a shaper for all cases.
330 if (isAATFont(font))
331 return 0;
332 #endif
333 if (!m_harfBuzzFace)
334 m_harfBuzzFace = HarfBuzzFace::create(const_cast<FontPlatformData*>(this ), uniqueID());
335
336 return m_harfBuzzFace.get();
337 }
338 142
339 } // namespace blink 143 } // namespace blink
OLDNEW
« no previous file with comments | « Source/platform/fonts/FontPlatformData.h ('k') | Source/platform/fonts/cocoa/FontPlatformDataCocoa.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698