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

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

Issue 550083005: Merge FontPlatformDataHarfBuzz into FontPlatformData (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Rebased 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
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
(...skipping 10 matching lines...) Expand all
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) 30 #if OS(MACOSX)
31 #include "platform/fonts/harfbuzz/HarfBuzzFace.h" 31 #include "third_party/skia/include/ports/SkTypeface_mac.h"
32 #endif 32 #endif
33 33
34 using namespace std; 34 using namespace std;
35 35
36 namespace blink { 36 namespace blink {
37 37
38 FontPlatformData::FontPlatformData(WTF::HashTableDeletedValueType) 38 FontPlatformData::FontPlatformData(WTF::HashTableDeletedValueType)
39 : m_textSize(0) 39 : m_typeface(nullptr)
40 #if !OS(WIN)
41 , m_family(CString())
42 #endif
43 , m_textSize(0)
40 , m_syntheticBold(false) 44 , m_syntheticBold(false)
41 , m_syntheticItalic(false) 45 , m_syntheticItalic(false)
42 , m_orientation(Horizontal) 46 , m_orientation(Horizontal)
47 #if OS(MACOSX)
43 , m_isColorBitmapFont(false) 48 , m_isColorBitmapFont(false)
44 , m_isCompositeFontReference(false) 49 , m_isCompositeFontReference(false)
50 #endif
45 , m_widthVariant(RegularWidth) 51 , m_widthVariant(RegularWidth)
46 #if OS(MACOSX) 52 #if OS(MACOSX)
47 , m_font(nullptr) 53 , m_font(nullptr)
48 #endif 54 #endif
49 , m_isHashTableDeletedValue(true) 55 , m_isHashTableDeletedValue(true)
56 #if OS(WIN)
57 , m_paintTextFlags(0)
58 , m_minSizeForAntiAlias(0)
59 , m_useSubpixelPositioning(false)
60 #endif
50 { 61 {
51 } 62 }
52 63
53 FontPlatformData::FontPlatformData() 64 FontPlatformData::FontPlatformData()
54 : m_textSize(0) 65 : m_typeface(nullptr)
66 #if !OS(WIN)
67 , m_family(CString())
68 #endif
69 , m_textSize(0)
55 , m_syntheticBold(false) 70 , m_syntheticBold(false)
56 , m_syntheticItalic(false) 71 , m_syntheticItalic(false)
57 , m_orientation(Horizontal) 72 , m_orientation(Horizontal)
73 #if OS(MACOSX)
58 , m_isColorBitmapFont(false) 74 , m_isColorBitmapFont(false)
59 , m_isCompositeFontReference(false) 75 , m_isCompositeFontReference(false)
76 #endif
60 , m_widthVariant(RegularWidth) 77 , m_widthVariant(RegularWidth)
61 #if OS(MACOSX) 78 #if OS(MACOSX)
62 , m_font(nullptr) 79 , m_font(nullptr)
63 #endif 80 #endif
64 , m_isHashTableDeletedValue(false) 81 , m_isHashTableDeletedValue(false)
82 #if OS(WIN)
83 , m_paintTextFlags(0)
84 , m_minSizeForAntiAlias(0)
85 , m_useSubpixelPositioning(false)
86 #endif
65 { 87 {
66 } 88 }
67 89
68 FontPlatformData::FontPlatformData(float size, bool syntheticBold, bool syntheti cItalic, FontOrientation orientation, FontWidthVariant widthVariant) 90 FontPlatformData::FontPlatformData(float size, bool syntheticBold, bool syntheti cItalic, FontOrientation orientation, FontWidthVariant widthVariant)
69 : m_textSize(size) 91 : m_typeface(nullptr)
92 #if !OS(WIN)
93 , m_family(CString())
94 #endif
95 , m_textSize(size)
70 , m_syntheticBold(syntheticBold) 96 , m_syntheticBold(syntheticBold)
71 , m_syntheticItalic(syntheticItalic) 97 , m_syntheticItalic(syntheticItalic)
72 , m_orientation(orientation) 98 , m_orientation(orientation)
99 #if OS(MACOSX)
73 , m_isColorBitmapFont(false) 100 , m_isColorBitmapFont(false)
74 , m_isCompositeFontReference(false) 101 , m_isCompositeFontReference(false)
102 #endif
75 , m_widthVariant(widthVariant) 103 , m_widthVariant(widthVariant)
76 #if OS(MACOSX) 104 #if OS(MACOSX)
77 , m_font(nullptr) 105 , m_font(nullptr)
78 #endif 106 #endif
79 , m_isHashTableDeletedValue(false) 107 , m_isHashTableDeletedValue(false)
108 #if OS(WIN)
109 , m_paintTextFlags(0)
110 , m_minSizeForAntiAlias(0)
111 , m_useSubpixelPositioning(false)
112 #endif
80 { 113 {
81 } 114 }
82 115
116 FontPlatformData::FontPlatformData(const FontPlatformData& source)
117 : m_typeface(source.m_typeface)
118 #if !OS(WIN)
119 , m_family(source.m_family)
120 #endif
121 , m_textSize(source.m_textSize)
122 , m_syntheticBold(source.m_syntheticBold)
123 , m_syntheticItalic(source.m_syntheticItalic)
124 , m_orientation(source.m_orientation)
125 #if OS(MACOSX)
126 , m_isColorBitmapFont(source.m_isColorBitmapFont)
127 , m_isCompositeFontReference(source.m_isCompositeFontReference)
128 #endif
129 , m_widthVariant(source.m_widthVariant)
130 #if !OS(MACOSX)
131 , m_style(source.m_style)
132 #endif
133 , m_isHashTableDeletedValue(false)
134 #if OS(WIN)
135 , m_paintTextFlags(source.m_paintTextFlags)
136 , m_minSizeForAntiAlias(source.m_minSizeForAntiAlias)
137 , m_useSubpixelPositioning(source.m_useSubpixelPositioning)
138 #endif
139 {
140 #if OS(MACOSX)
141 platformDataInit(source);
142 #endif
143 }
144
145
83 #if OS(MACOSX) 146 #if OS(MACOSX)
84 FontPlatformData::FontPlatformData(CGFontRef cgFont, float size, bool syntheticB old, bool syntheticItalic, FontOrientation orientation, FontWidthVariant widthVa riant) 147 FontPlatformData::FontPlatformData(CGFontRef cgFont, float size, bool syntheticB old, bool syntheticItalic, FontOrientation orientation, FontWidthVariant widthVa riant)
85 : m_textSize(size) 148 : m_typeface(nullptr)
149 #if !OS(WIN)
150 , m_family(CString())
151 #endif
152 , m_textSize(size)
86 , m_syntheticBold(syntheticBold) 153 , m_syntheticBold(syntheticBold)
87 , m_syntheticItalic(syntheticItalic) 154 , m_syntheticItalic(syntheticItalic)
88 , m_orientation(orientation) 155 , m_orientation(orientation)
89 , m_isColorBitmapFont(false) 156 , m_isColorBitmapFont(false)
90 , m_isCompositeFontReference(false) 157 , m_isCompositeFontReference(false)
91 , m_widthVariant(widthVariant) 158 , m_widthVariant(widthVariant)
92 , m_font(nullptr) 159 , m_font(nullptr)
93 , m_cgFont(cgFont) 160 , m_cgFont(cgFont)
94 , m_isHashTableDeletedValue(false) 161 , m_isHashTableDeletedValue(false)
95 { 162 {
96 } 163 }
164
165 #else
166
167 FontPlatformData::FontPlatformData(PassRefPtr<SkTypeface> tf, const char* family , float textSize, bool syntheticBold, bool syntheticItalic, FontOrientation orie ntation, bool subpixelTextPosition)
168 : m_typeface(tf)
169 #if !OS(WIN)
170 , m_family(family)
171 #endif
172 , m_textSize(textSize)
173 , m_syntheticBold(syntheticBold)
174 , m_syntheticItalic(syntheticItalic)
175 , m_orientation(orientation)
176 , m_isHashTableDeletedValue(false)
177 #if OS(WIN)
178 , m_paintTextFlags(0)
179 , m_minSizeForAntiAlias(0)
180 , m_useSubpixelPositioning(subpixelTextPosition)
181 #endif
182 {
183 querySystemForRenderStyle(subpixelTextPosition);
184 }
185
186
187 FontPlatformData::FontPlatformData(const FontPlatformData& src, float textSize)
188 : m_typeface(src.m_typeface)
189 #if !OS(WIN)
190 , m_family(src.m_family)
191 #endif
192 , m_textSize(textSize)
193 , m_syntheticBold(src.m_syntheticBold)
194 , m_syntheticItalic(src.m_syntheticItalic)
195 , m_orientation(src.m_orientation)
196 , m_harfBuzzFace(nullptr)
197 , m_isHashTableDeletedValue(false)
198 #if OS(WIN)
199 , m_paintTextFlags(src.m_paintTextFlags)
200 , m_minSizeForAntiAlias(src.m_minSizeForAntiAlias)
201 , m_useSubpixelPositioning(src.m_useSubpixelPositioning)
202 #endif
203 {
204 querySystemForRenderStyle(FontDescription::subpixelPositioning());
205 }
97 #endif 206 #endif
98 207
99 FontPlatformData::FontPlatformData(const FontPlatformData& source) 208 FontPlatformData::~FontPlatformData()
100 : m_textSize(source.m_textSize)
101 , m_syntheticBold(source.m_syntheticBold)
102 , m_syntheticItalic(source.m_syntheticItalic)
103 , m_orientation(source.m_orientation)
104 , m_isColorBitmapFont(source.m_isColorBitmapFont)
105 , m_isCompositeFontReference(source.m_isCompositeFontReference)
106 , m_widthVariant(source.m_widthVariant)
107 , m_isHashTableDeletedValue(false)
108 { 209 {
109 platformDataInit(source); 210 #if OS(MACOSX)
211 if (m_font)
212 CFRelease(m_font);
213 #endif
110 } 214 }
111 215
112 const FontPlatformData& FontPlatformData::operator=(const FontPlatformData& othe r) 216 const FontPlatformData& FontPlatformData::operator=(const FontPlatformData& othe r)
113 { 217 {
114 // Check for self-assignment. 218 // Check for self-assignment.
115 if (this == &other) 219 if (this == &other)
116 return *this; 220 return *this;
117 221
222 m_typeface = other.m_typeface;
223 #if !OS(WIN)
224 m_family = other.m_family;
225 #endif
226 m_textSize = other.m_textSize;
118 m_syntheticBold = other.m_syntheticBold; 227 m_syntheticBold = other.m_syntheticBold;
119 m_syntheticItalic = other.m_syntheticItalic; 228 m_syntheticItalic = other.m_syntheticItalic;
120 m_orientation = other.m_orientation; 229 m_orientation = other.m_orientation;
121 m_textSize = other.m_textSize;
122 m_widthVariant = other.m_widthVariant; 230 m_widthVariant = other.m_widthVariant;
231 #if OS(MACOSX)
123 m_isColorBitmapFont = other.m_isColorBitmapFont; 232 m_isColorBitmapFont = other.m_isColorBitmapFont;
124 m_isCompositeFontReference = other.m_isCompositeFontReference; 233 m_isCompositeFontReference = other.m_isCompositeFontReference;
234 #else
235 m_style = other.m_style;
236 #endif
237 m_widthVariant = other.m_widthVariant;
125 238
239 #if OS(MACOSX)
126 return platformDataAssign(other); 240 return platformDataAssign(other);
241 #else
242 return *this;
243 #endif
127 } 244 }
128 245
129 bool FontPlatformData::operator==(const FontPlatformData& a) const 246 bool FontPlatformData::operator==(const FontPlatformData& a) const
130 { 247 {
248 // If either of the typeface pointers are null then we test for pointer
249 // equality. Otherwise, we call SkTypeface::Equal on the valid pointers.
250 bool typefacesEqual = false;
251 #if !OS(MACOSX)
252 if (!m_typeface || !a.m_typeface)
253 typefacesEqual = m_typeface == a.m_typeface;
254 else
255 typefacesEqual = SkTypeface::Equal(m_typeface.get(), a.m_typeface.get()) ;
256 #else
257 if (m_font || a.m_font)
258 typefacesEqual = m_font == a.m_font;
259 else
260 typefacesEqual = m_cgFont == a.m_cgFont;
261 #endif
131 262
132 return platformIsEqual(a) 263 return typefacesEqual
133 && m_textSize == a.m_textSize 264 && m_textSize == a.m_textSize
134 && m_isHashTableDeletedValue == a.m_isHashTableDeletedValue 265 && m_isHashTableDeletedValue == a.m_isHashTableDeletedValue
135 && m_syntheticBold == a.m_syntheticBold 266 && m_syntheticBold == a.m_syntheticBold
136 && m_syntheticItalic == a.m_syntheticItalic 267 && m_syntheticItalic == a.m_syntheticItalic
137 && m_orientation == a.m_orientation 268 && m_orientation == a.m_orientation
138 #if !OS(MACOSX) 269 #if !OS(MACOSX)
139 && m_style == a.m_style 270 && m_style == a.m_style
140 #endif 271 #else
141 && m_isColorBitmapFont == a.m_isColorBitmapFont 272 && m_isColorBitmapFont == a.m_isColorBitmapFont
142 && m_isCompositeFontReference == a.m_isCompositeFontReference 273 && m_isCompositeFontReference == a.m_isCompositeFontReference
274 #endif
143 && m_widthVariant == a.m_widthVariant; 275 && m_widthVariant == a.m_widthVariant;
144 } 276 }
145 277
146 278
279
280 SkFontID FontPlatformData::uniqueID() const
281 {
282 return m_typeface->uniqueID();
283 }
284
285 String FontPlatformData::fontFamilyName() const
286 {
287 // FIXME(crbug.com/326582): come up with a proper way of handling SVG.
288 if (!this->typeface())
289 return "";
290 SkTypeface::LocalizedStrings* fontFamilyIterator = this->typeface()->createF amilyNameIterator();
291 SkTypeface::LocalizedString localizedString;
292 while (fontFamilyIterator->next(&localizedString) && !localizedString.fStrin g.size()) { }
293 fontFamilyIterator->unref();
294 return String(localizedString.fString.c_str());
295 }
296
297
298
299 bool FontPlatformData::isFixedPitch() const
300 {
301 return typeface() && typeface()->isFixedPitch();
302 }
303
304 SkTypeface* FontPlatformData::typeface() const
305 {
306 #if OS(MACOSX)
307 if (m_typeface)
308 return m_typeface.get();
309
310 m_typeface = adoptRef(SkCreateTypefaceFromCTFont(ctFont()));
311 return m_typeface.get();
312 #else
313 return m_typeface.get();
314 #endif
315 }
316
317 HarfBuzzFace* FontPlatformData::harfBuzzFace() const
318 {
319 #if OS(MACOSX)
320 CTFontRef font = ctFont();
321 // Keeping the decision not to pass AAT font to HarfBuzz for now,
322 // until we switch to HarfBuzz as a shaper for all cases.
323 if (isAATFont(font))
324 return 0;
325 #endif
326
327 if (!m_harfBuzzFace)
328 m_harfBuzzFace = HarfBuzzFace::create(const_cast<FontPlatformData*>(this ), uniqueID());
329
330 return m_harfBuzzFace.get();
331 }
332
333
334
147 } // namespace blink 335 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698