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

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

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

Powered by Google App Engine
This is Rietveld 408576698