OLD | NEW |
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 28 matching lines...) Expand all Loading... |
39 | 39 |
40 FontPlatformData::FontPlatformData(WTF::HashTableDeletedValueType) | 40 FontPlatformData::FontPlatformData(WTF::HashTableDeletedValueType) |
41 : m_typeface(nullptr) | 41 : m_typeface(nullptr) |
42 #if !OS(WIN) | 42 #if !OS(WIN) |
43 , m_family(CString()) | 43 , m_family(CString()) |
44 #endif | 44 #endif |
45 , m_textSize(0) | 45 , m_textSize(0) |
46 , m_syntheticBold(false) | 46 , m_syntheticBold(false) |
47 , m_syntheticItalic(false) | 47 , m_syntheticItalic(false) |
48 , m_orientation(Horizontal) | 48 , m_orientation(Horizontal) |
49 #if OS(MACOSX) | 49 #if !OS(MACOSX) |
50 , m_isColorBitmapFont(false) | |
51 , m_isCompositeFontReference(false) | |
52 , m_font(nullptr) | |
53 #else | |
54 , m_style(FontRenderStyle()) | 50 , m_style(FontRenderStyle()) |
55 #endif | 51 #endif |
56 , m_isHashTableDeletedValue(true) | 52 , m_isHashTableDeletedValue(true) |
57 #if OS(WIN) | 53 #if OS(WIN) |
58 , m_paintTextFlags(0) | 54 , m_paintTextFlags(0) |
59 , m_useSubpixelPositioning(false) | 55 , m_useSubpixelPositioning(false) |
60 , m_minSizeForAntiAlias(0) | 56 , m_minSizeForAntiAlias(0) |
61 , m_minSizeForSubpixel(0) | 57 , m_minSizeForSubpixel(0) |
62 #endif | 58 #endif |
63 { | 59 { |
64 } | 60 } |
65 | 61 |
66 FontPlatformData::FontPlatformData() | 62 FontPlatformData::FontPlatformData() |
67 : m_typeface(nullptr) | 63 : m_typeface(nullptr) |
68 #if !OS(WIN) | 64 #if !OS(WIN) |
69 , m_family(CString()) | 65 , m_family(CString()) |
70 #endif | 66 #endif |
71 , m_textSize(0) | 67 , m_textSize(0) |
72 , m_syntheticBold(false) | 68 , m_syntheticBold(false) |
73 , m_syntheticItalic(false) | 69 , m_syntheticItalic(false) |
74 , m_orientation(Horizontal) | 70 , m_orientation(Horizontal) |
75 #if OS(MACOSX) | 71 #if !OS(MACOSX) |
76 , m_isColorBitmapFont(false) | |
77 , m_isCompositeFontReference(false) | |
78 , m_font(nullptr) | |
79 #else | |
80 , m_style(FontRenderStyle()) | 72 , m_style(FontRenderStyle()) |
81 #endif | 73 #endif |
82 , m_isHashTableDeletedValue(false) | 74 , m_isHashTableDeletedValue(false) |
83 #if OS(WIN) | 75 #if OS(WIN) |
84 , m_paintTextFlags(0) | 76 , m_paintTextFlags(0) |
85 , m_useSubpixelPositioning(false) | 77 , m_useSubpixelPositioning(false) |
86 , m_minSizeForAntiAlias(0) | 78 , m_minSizeForAntiAlias(0) |
87 , m_minSizeForSubpixel(0) | 79 , m_minSizeForSubpixel(0) |
88 #endif | 80 #endif |
89 { | 81 { |
90 } | 82 } |
91 | 83 |
92 FontPlatformData::FontPlatformData(float size, bool syntheticBold, bool syntheti
cItalic, FontOrientation orientation) | 84 FontPlatformData::FontPlatformData(float size, bool syntheticBold, bool syntheti
cItalic, FontOrientation orientation) |
93 : m_typeface(nullptr) | 85 : m_typeface(nullptr) |
94 #if !OS(WIN) | 86 #if !OS(WIN) |
95 , m_family(CString()) | 87 , m_family(CString()) |
96 #endif | 88 #endif |
97 , m_textSize(size) | 89 , m_textSize(size) |
98 , m_syntheticBold(syntheticBold) | 90 , m_syntheticBold(syntheticBold) |
99 , m_syntheticItalic(syntheticItalic) | 91 , m_syntheticItalic(syntheticItalic) |
100 , m_orientation(orientation) | 92 , m_orientation(orientation) |
101 #if OS(MACOSX) | 93 #if !OS(MACOSX) |
102 , m_isColorBitmapFont(false) | |
103 , m_isCompositeFontReference(false) | |
104 , m_font(nullptr) | |
105 #else | |
106 , m_style(FontRenderStyle()) | 94 , m_style(FontRenderStyle()) |
107 #endif | 95 #endif |
108 , m_isHashTableDeletedValue(false) | 96 , m_isHashTableDeletedValue(false) |
109 #if OS(WIN) | 97 #if OS(WIN) |
110 , m_paintTextFlags(0) | 98 , m_paintTextFlags(0) |
111 , m_useSubpixelPositioning(false) | 99 , m_useSubpixelPositioning(false) |
112 , m_minSizeForAntiAlias(0) | 100 , m_minSizeForAntiAlias(0) |
113 , m_minSizeForSubpixel(0) | 101 , m_minSizeForSubpixel(0) |
114 #endif | 102 #endif |
115 { | 103 { |
116 } | 104 } |
117 | 105 |
118 FontPlatformData::FontPlatformData(const FontPlatformData& source) | 106 FontPlatformData::FontPlatformData(const FontPlatformData& source) |
119 : m_typeface(source.m_typeface) | 107 : m_typeface(source.m_typeface) |
120 #if !OS(WIN) | 108 #if !OS(WIN) |
121 , m_family(source.m_family) | 109 , m_family(source.m_family) |
122 #endif | 110 #endif |
123 , m_textSize(source.m_textSize) | 111 , m_textSize(source.m_textSize) |
124 , m_syntheticBold(source.m_syntheticBold) | 112 , m_syntheticBold(source.m_syntheticBold) |
125 , m_syntheticItalic(source.m_syntheticItalic) | 113 , m_syntheticItalic(source.m_syntheticItalic) |
126 , m_orientation(source.m_orientation) | 114 , m_orientation(source.m_orientation) |
127 #if OS(MACOSX) | |
128 , m_isColorBitmapFont(source.m_isColorBitmapFont) | |
129 , m_isCompositeFontReference(source.m_isCompositeFontReference) | |
130 #endif | |
131 #if !OS(MACOSX) | 115 #if !OS(MACOSX) |
132 , m_style(source.m_style) | 116 , m_style(source.m_style) |
133 #endif | 117 #endif |
134 , m_harfBuzzFace(nullptr) | 118 , m_harfBuzzFace(nullptr) |
135 , m_isHashTableDeletedValue(false) | 119 , m_isHashTableDeletedValue(false) |
136 #if OS(WIN) | 120 #if OS(WIN) |
137 , m_paintTextFlags(source.m_paintTextFlags) | 121 , m_paintTextFlags(source.m_paintTextFlags) |
138 , m_useSubpixelPositioning(source.m_useSubpixelPositioning) | 122 , m_useSubpixelPositioning(source.m_useSubpixelPositioning) |
139 , m_minSizeForAntiAlias(source.m_minSizeForAntiAlias) | 123 , m_minSizeForAntiAlias(source.m_minSizeForAntiAlias) |
140 , m_minSizeForSubpixel(source.m_minSizeForSubpixel) | 124 , m_minSizeForSubpixel(source.m_minSizeForSubpixel) |
141 #endif | 125 #endif |
142 { | 126 { |
143 #if OS(MACOSX) | |
144 platformDataInit(source); | |
145 #endif | |
146 } | 127 } |
147 | 128 |
148 FontPlatformData::FontPlatformData(const FontPlatformData& src, float textSize) | 129 FontPlatformData::FontPlatformData(const FontPlatformData& src, float textSize) |
149 : m_typeface(src.m_typeface) | 130 : m_typeface(src.m_typeface) |
150 #if !OS(WIN) | 131 #if !OS(WIN) |
151 , m_family(src.m_family) | 132 , m_family(src.m_family) |
152 #endif | 133 #endif |
153 , m_textSize(textSize) | 134 , m_textSize(textSize) |
154 , m_syntheticBold(src.m_syntheticBold) | 135 , m_syntheticBold(src.m_syntheticBold) |
155 , m_syntheticItalic(src.m_syntheticItalic) | 136 , m_syntheticItalic(src.m_syntheticItalic) |
156 , m_orientation(src.m_orientation) | 137 , m_orientation(src.m_orientation) |
157 #if OS(MACOSX) | |
158 , m_isColorBitmapFont(src.m_isColorBitmapFont) | |
159 , m_isCompositeFontReference(src.m_isCompositeFontReference) | |
160 #endif | |
161 #if !OS(MACOSX) | 138 #if !OS(MACOSX) |
162 , m_style(src.m_style) | 139 , m_style(src.m_style) |
163 #endif | 140 #endif |
164 , m_harfBuzzFace(nullptr) | 141 , m_harfBuzzFace(nullptr) |
165 , m_isHashTableDeletedValue(false) | 142 , m_isHashTableDeletedValue(false) |
166 #if OS(WIN) | 143 #if OS(WIN) |
167 , m_paintTextFlags(src.m_paintTextFlags) | 144 , m_paintTextFlags(src.m_paintTextFlags) |
168 , m_useSubpixelPositioning(src.m_useSubpixelPositioning) | 145 , m_useSubpixelPositioning(src.m_useSubpixelPositioning) |
169 , m_minSizeForAntiAlias(src.m_minSizeForAntiAlias) | 146 , m_minSizeForAntiAlias(src.m_minSizeForAntiAlias) |
170 , m_minSizeForSubpixel(src.m_minSizeForSubpixel) | 147 , m_minSizeForSubpixel(src.m_minSizeForSubpixel) |
171 #endif | 148 #endif |
172 { | 149 { |
173 #if OS(MACOSX) | 150 #if !OS(MACOSX) |
174 platformDataInit(src); | |
175 #else | |
176 querySystemForRenderStyle(FontDescription::subpixelPositioning()); | 151 querySystemForRenderStyle(FontDescription::subpixelPositioning()); |
177 #endif | 152 #endif |
178 } | 153 } |
179 | 154 |
180 #if OS(MACOSX) | |
181 FontPlatformData::FontPlatformData(CGFontRef cgFont, PassRefPtr<SkTypeface> tf,
float size, bool syntheticBold, bool syntheticItalic, FontOrientation orientatio
n) | |
182 : m_typeface(tf) | |
183 , m_family(CString()) | |
184 , m_textSize(size) | |
185 , m_syntheticBold(syntheticBold) | |
186 , m_syntheticItalic(syntheticItalic) | |
187 , m_orientation(orientation) | |
188 , m_isColorBitmapFont(false) | |
189 , m_isCompositeFontReference(false) | |
190 , m_font(nullptr) | |
191 , m_cgFont(cgFont) | |
192 , m_isHashTableDeletedValue(false) | |
193 { | |
194 } | |
195 | |
196 #else | |
197 | |
198 FontPlatformData::FontPlatformData(PassRefPtr<SkTypeface> tf, const char* family
, float textSize, bool syntheticBold, bool syntheticItalic, FontOrientation orie
ntation, bool subpixelTextPosition) | 155 FontPlatformData::FontPlatformData(PassRefPtr<SkTypeface> tf, const char* family
, float textSize, bool syntheticBold, bool syntheticItalic, FontOrientation orie
ntation, bool subpixelTextPosition) |
199 : m_typeface(tf) | 156 : m_typeface(tf) |
200 #if !OS(WIN) | 157 #if !OS(WIN) |
201 , m_family(family) | 158 , m_family(family) |
202 #endif | 159 #endif |
203 , m_textSize(textSize) | 160 , m_textSize(textSize) |
204 , m_syntheticBold(syntheticBold) | 161 , m_syntheticBold(syntheticBold) |
205 , m_syntheticItalic(syntheticItalic) | 162 , m_syntheticItalic(syntheticItalic) |
206 , m_orientation(orientation) | 163 , m_orientation(orientation) |
207 , m_isHashTableDeletedValue(false) | 164 , m_isHashTableDeletedValue(false) |
208 #if OS(WIN) | 165 #if OS(WIN) |
209 , m_paintTextFlags(0) | 166 , m_paintTextFlags(0) |
210 , m_useSubpixelPositioning(subpixelTextPosition) | 167 , m_useSubpixelPositioning(subpixelTextPosition) |
211 , m_minSizeForAntiAlias(0) | 168 , m_minSizeForAntiAlias(0) |
212 , m_minSizeForSubpixel(0) | 169 , m_minSizeForSubpixel(0) |
213 #endif | 170 #endif |
214 { | 171 { |
| 172 #if !OS(MACOSX) |
215 querySystemForRenderStyle(subpixelTextPosition); | 173 querySystemForRenderStyle(subpixelTextPosition); |
| 174 #endif |
216 } | 175 } |
217 | 176 |
218 #endif | |
219 | |
220 FontPlatformData::~FontPlatformData() | 177 FontPlatformData::~FontPlatformData() |
221 { | 178 { |
222 #if OS(MACOSX) | 179 } |
223 if (m_font) | 180 |
224 CFRelease(m_font); | 181 CTFontRef FontPlatformData::ctFont() const |
225 #endif | 182 { |
| 183 return SkTypeface_GetCTFontRef(m_typeface.get()); |
| 184 }; |
| 185 |
| 186 CGFontRef FontPlatformData::cgFont() const |
| 187 { |
| 188 return CTFontCopyGraphicsFont(ctFont(), 0); |
226 } | 189 } |
227 | 190 |
228 const FontPlatformData& FontPlatformData::operator=(const FontPlatformData& othe
r) | 191 const FontPlatformData& FontPlatformData::operator=(const FontPlatformData& othe
r) |
229 { | 192 { |
230 // Check for self-assignment. | 193 // Check for self-assignment. |
231 if (this == &other) | 194 if (this == &other) |
232 return *this; | 195 return *this; |
233 | 196 |
234 m_typeface = other.m_typeface; | 197 m_typeface = other.m_typeface; |
235 #if !OS(WIN) | 198 #if !OS(WIN) |
236 m_family = other.m_family; | 199 m_family = other.m_family; |
237 #endif | 200 #endif |
238 m_textSize = other.m_textSize; | 201 m_textSize = other.m_textSize; |
239 m_syntheticBold = other.m_syntheticBold; | 202 m_syntheticBold = other.m_syntheticBold; |
240 m_syntheticItalic = other.m_syntheticItalic; | 203 m_syntheticItalic = other.m_syntheticItalic; |
241 m_harfBuzzFace = nullptr; | 204 m_harfBuzzFace = nullptr; |
242 m_orientation = other.m_orientation; | 205 m_orientation = other.m_orientation; |
243 #if OS(MACOSX) | 206 #if !OS(MACOSX) |
244 m_isColorBitmapFont = other.m_isColorBitmapFont; | |
245 m_isCompositeFontReference = other.m_isCompositeFontReference; | |
246 #else | |
247 m_style = other.m_style; | 207 m_style = other.m_style; |
248 #endif | 208 #endif |
249 | 209 |
250 #if OS(WIN) | 210 #if OS(WIN) |
251 m_paintTextFlags = 0; | 211 m_paintTextFlags = 0; |
252 m_minSizeForAntiAlias = other.m_minSizeForAntiAlias; | 212 m_minSizeForAntiAlias = other.m_minSizeForAntiAlias; |
253 m_minSizeForSubpixel = other.m_minSizeForSubpixel; | 213 m_minSizeForSubpixel = other.m_minSizeForSubpixel; |
254 m_useSubpixelPositioning = other.m_useSubpixelPositioning; | 214 m_useSubpixelPositioning = other.m_useSubpixelPositioning; |
255 #endif | 215 #endif |
256 | 216 |
257 #if OS(MACOSX) | |
258 return platformDataAssign(other); | |
259 #else | |
260 return *this; | 217 return *this; |
261 #endif | |
262 } | 218 } |
263 | 219 |
264 bool FontPlatformData::operator==(const FontPlatformData& a) const | 220 bool FontPlatformData::operator==(const FontPlatformData& a) const |
265 { | 221 { |
266 // If either of the typeface pointers are null then we test for pointer | 222 // If either of the typeface pointers are null then we test for pointer |
267 // equality. Otherwise, we call SkTypeface::Equal on the valid pointers. | 223 // equality. Otherwise, we call SkTypeface::Equal on the valid pointers. |
268 bool typefacesEqual = false; | 224 bool typefacesEqual = false; |
269 if (!typeface() || !a.typeface()) | 225 if (!typeface() || !a.typeface()) |
270 typefacesEqual = typeface() == a.typeface(); | 226 typefacesEqual = typeface() == a.typeface(); |
271 else | 227 else |
272 typefacesEqual = SkTypeface::Equal(typeface(), a.typeface()); | 228 typefacesEqual = SkTypeface::Equal(typeface(), a.typeface()); |
273 | 229 |
274 return typefacesEqual | 230 return typefacesEqual |
275 && m_textSize == a.m_textSize | 231 && m_textSize == a.m_textSize |
276 && m_isHashTableDeletedValue == a.m_isHashTableDeletedValue | 232 && m_isHashTableDeletedValue == a.m_isHashTableDeletedValue |
277 && m_syntheticBold == a.m_syntheticBold | 233 && m_syntheticBold == a.m_syntheticBold |
278 && m_syntheticItalic == a.m_syntheticItalic | 234 && m_syntheticItalic == a.m_syntheticItalic |
279 && m_orientation == a.m_orientation | |
280 #if !OS(MACOSX) | 235 #if !OS(MACOSX) |
281 && m_style == a.m_style; | 236 && m_style == a.m_style |
282 #else | |
283 && m_isColorBitmapFont == a.m_isColorBitmapFont | |
284 && m_isCompositeFontReference == a.m_isCompositeFontReference; | |
285 #endif | 237 #endif |
| 238 && m_orientation == a.m_orientation; |
286 } | 239 } |
287 | 240 |
288 SkFontID FontPlatformData::uniqueID() const | 241 SkFontID FontPlatformData::uniqueID() const |
289 { | 242 { |
290 return typeface()->uniqueID(); | 243 return typeface()->uniqueID(); |
291 } | 244 } |
292 | 245 |
293 String FontPlatformData::fontFamilyName() const | 246 String FontPlatformData::fontFamilyName() const |
294 { | 247 { |
295 ASSERT(this->typeface()); | 248 ASSERT(this->typeface()); |
296 SkTypeface::LocalizedStrings* fontFamilyIterator = this->typeface()->createF
amilyNameIterator(); | 249 SkTypeface::LocalizedStrings* fontFamilyIterator = this->typeface()->createF
amilyNameIterator(); |
297 SkTypeface::LocalizedString localizedString; | 250 SkTypeface::LocalizedString localizedString; |
298 while (fontFamilyIterator->next(&localizedString) && !localizedString.fStrin
g.size()) { } | 251 while (fontFamilyIterator->next(&localizedString) && !localizedString.fStrin
g.size()) { } |
299 fontFamilyIterator->unref(); | 252 fontFamilyIterator->unref(); |
300 return String(localizedString.fString.c_str()); | 253 return String(localizedString.fString.c_str()); |
301 } | 254 } |
302 | 255 |
303 bool FontPlatformData::isFixedPitch() const | 256 bool FontPlatformData::isFixedPitch() const |
304 { | 257 { |
305 return typeface() && typeface()->isFixedPitch(); | 258 return typeface() && typeface()->isFixedPitch(); |
306 } | 259 } |
307 | 260 |
308 SkTypeface* FontPlatformData::typeface() const | 261 SkTypeface* FontPlatformData::typeface() const |
309 { | 262 { |
310 #if OS(MACOSX) | 263 #if OS(MACOSX) |
311 // ctFont() will always generate a typeface, even for uninitialized font mem
bers. | 264 // TODO(dro): Ensure that we won't get here to retrieve a default font, |
312 // We only want to generate a Skia typeface if we have a valid font to start
from, | 265 // and remove this code. |
313 // to keep hashing and comparisons to the empty object consistent. | 266 if (!m_typeface) |
314 if (!m_typeface && (m_font || m_cgFont || m_CTFont || m_inMemoryFont)) | 267 m_typeface = adoptRef(SkTypeface::CreateFromName(0, SkTypeface::kNormal)
); |
315 m_typeface = adoptRef(SkCreateTypefaceFromCTFont(ctFont())); | |
316 #endif | 268 #endif |
317 return m_typeface.get(); | 269 return m_typeface.get(); |
318 } | 270 } |
319 | 271 |
320 HarfBuzzFace* FontPlatformData::harfBuzzFace() const | 272 HarfBuzzFace* FontPlatformData::harfBuzzFace() const |
321 { | 273 { |
322 if (!m_harfBuzzFace) | 274 if (!m_harfBuzzFace) |
323 m_harfBuzzFace = HarfBuzzFace::create(const_cast<FontPlatformData*>(this
), uniqueID()); | 275 m_harfBuzzFace = HarfBuzzFace::create(const_cast<FontPlatformData*>(this
), uniqueID()); |
324 | 276 |
325 return m_harfBuzzFace.get(); | 277 return m_harfBuzzFace.get(); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
367 const size_t tableSize = m_typeface->getTableSize(tag); | 319 const size_t tableSize = m_typeface->getTableSize(tag); |
368 if (tableSize) { | 320 if (tableSize) { |
369 Vector<char> tableBuffer(tableSize); | 321 Vector<char> tableBuffer(tableSize); |
370 m_typeface->getTableData(tag, 0, tableSize, &tableBuffer[0]); | 322 m_typeface->getTableData(tag, 0, tableSize, &tableBuffer[0]); |
371 buffer = SharedBuffer::adoptVector(tableBuffer); | 323 buffer = SharedBuffer::adoptVector(tableBuffer); |
372 } | 324 } |
373 return buffer.release(); | 325 return buffer.release(); |
374 } | 326 } |
375 | 327 |
376 } // namespace blink | 328 } // namespace blink |
OLD | NEW |