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 10 matching lines...) Expand all Loading... |
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_minSizeForSubpixel(0) |
| 60 , m_useSubpixelPositioning(false) |
| 61 #endif |
50 { | 62 { |
51 } | 63 } |
52 | 64 |
53 FontPlatformData::FontPlatformData() | 65 FontPlatformData::FontPlatformData() |
54 : m_textSize(0) | 66 : m_typeface(nullptr) |
| 67 #if !OS(WIN) |
| 68 , m_family(CString()) |
| 69 #endif |
| 70 , m_textSize(0) |
55 , m_syntheticBold(false) | 71 , m_syntheticBold(false) |
56 , m_syntheticItalic(false) | 72 , m_syntheticItalic(false) |
57 , m_orientation(Horizontal) | 73 , m_orientation(Horizontal) |
| 74 #if OS(MACOSX) |
58 , m_isColorBitmapFont(false) | 75 , m_isColorBitmapFont(false) |
59 , m_isCompositeFontReference(false) | 76 , m_isCompositeFontReference(false) |
| 77 #endif |
60 , m_widthVariant(RegularWidth) | 78 , m_widthVariant(RegularWidth) |
61 #if OS(MACOSX) | 79 #if OS(MACOSX) |
62 , m_font(nullptr) | 80 , m_font(nullptr) |
63 #endif | 81 #endif |
64 , m_isHashTableDeletedValue(false) | 82 , 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 |
65 { | 89 { |
66 } | 90 } |
67 | 91 |
68 FontPlatformData::FontPlatformData(float size, bool syntheticBold, bool syntheti
cItalic, FontOrientation orientation, FontWidthVariant widthVariant) | 92 FontPlatformData::FontPlatformData(float size, bool syntheticBold, bool syntheti
cItalic, FontOrientation orientation, FontWidthVariant widthVariant) |
69 : m_textSize(size) | 93 : m_typeface(nullptr) |
| 94 #if !OS(WIN) |
| 95 , m_family(CString()) |
| 96 #endif |
| 97 , m_textSize(size) |
70 , m_syntheticBold(syntheticBold) | 98 , m_syntheticBold(syntheticBold) |
71 , m_syntheticItalic(syntheticItalic) | 99 , m_syntheticItalic(syntheticItalic) |
72 , m_orientation(orientation) | 100 , m_orientation(orientation) |
| 101 #if OS(MACOSX) |
73 , m_isColorBitmapFont(false) | 102 , m_isColorBitmapFont(false) |
74 , m_isCompositeFontReference(false) | 103 , m_isCompositeFontReference(false) |
| 104 #endif |
75 , m_widthVariant(widthVariant) | 105 , m_widthVariant(widthVariant) |
76 #if OS(MACOSX) | 106 #if OS(MACOSX) |
77 , m_font(nullptr) | 107 , m_font(nullptr) |
78 #endif | 108 #endif |
79 , m_isHashTableDeletedValue(false) | 109 , 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 |
80 { | 116 { |
81 } | 117 } |
82 | 118 |
| 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 |
83 #if OS(MACOSX) | 151 #if OS(MACOSX) |
84 FontPlatformData::FontPlatformData(CGFontRef cgFont, float size, bool syntheticB
old, bool syntheticItalic, FontOrientation orientation, FontWidthVariant widthVa
riant) | 152 FontPlatformData::FontPlatformData(CGFontRef cgFont, float size, bool syntheticB
old, bool syntheticItalic, FontOrientation orientation, FontWidthVariant widthVa
riant) |
85 : m_textSize(size) | 153 : m_typeface(nullptr) |
| 154 #if !OS(WIN) |
| 155 , m_family(CString()) |
| 156 #endif |
| 157 , m_textSize(size) |
86 , m_syntheticBold(syntheticBold) | 158 , m_syntheticBold(syntheticBold) |
87 , m_syntheticItalic(syntheticItalic) | 159 , m_syntheticItalic(syntheticItalic) |
88 , m_orientation(orientation) | 160 , m_orientation(orientation) |
89 , m_isColorBitmapFont(false) | 161 , m_isColorBitmapFont(false) |
90 , m_isCompositeFontReference(false) | 162 , m_isCompositeFontReference(false) |
91 , m_widthVariant(widthVariant) | 163 , m_widthVariant(widthVariant) |
92 , m_font(nullptr) | 164 , m_font(nullptr) |
93 , m_cgFont(cgFont) | 165 , m_cgFont(cgFont) |
94 , m_isHashTableDeletedValue(false) | 166 , m_isHashTableDeletedValue(false) |
95 { | 167 { |
96 } | 168 } |
| 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 } |
97 #endif | 213 #endif |
98 | 214 |
99 FontPlatformData::FontPlatformData(const FontPlatformData& source) | 215 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 { | 216 { |
109 platformDataInit(source); | 217 #if OS(MACOSX) |
| 218 if (m_font) |
| 219 CFRelease(m_font); |
| 220 #endif |
110 } | 221 } |
111 | 222 |
112 const FontPlatformData& FontPlatformData::operator=(const FontPlatformData& othe
r) | 223 const FontPlatformData& FontPlatformData::operator=(const FontPlatformData& othe
r) |
113 { | 224 { |
114 // Check for self-assignment. | 225 // Check for self-assignment. |
115 if (this == &other) | 226 if (this == &other) |
116 return *this; | 227 return *this; |
117 | 228 |
| 229 m_typeface = other.m_typeface; |
| 230 #if !OS(WIN) |
| 231 m_family = other.m_family; |
| 232 #endif |
| 233 m_textSize = other.m_textSize; |
118 m_syntheticBold = other.m_syntheticBold; | 234 m_syntheticBold = other.m_syntheticBold; |
119 m_syntheticItalic = other.m_syntheticItalic; | 235 m_syntheticItalic = other.m_syntheticItalic; |
| 236 m_harfBuzzFace = nullptr; |
120 m_orientation = other.m_orientation; | 237 m_orientation = other.m_orientation; |
121 m_textSize = other.m_textSize; | |
122 m_widthVariant = other.m_widthVariant; | 238 m_widthVariant = other.m_widthVariant; |
| 239 #if OS(MACOSX) |
123 m_isColorBitmapFont = other.m_isColorBitmapFont; | 240 m_isColorBitmapFont = other.m_isColorBitmapFont; |
124 m_isCompositeFontReference = other.m_isCompositeFontReference; | 241 m_isCompositeFontReference = other.m_isCompositeFontReference; |
| 242 #else |
| 243 m_style = other.m_style; |
| 244 #endif |
| 245 m_widthVariant = other.m_widthVariant; |
125 | 246 |
| 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) |
126 return platformDataAssign(other); | 255 return platformDataAssign(other); |
| 256 #else |
| 257 return *this; |
| 258 #endif |
127 } | 259 } |
128 | 260 |
129 bool FontPlatformData::operator==(const FontPlatformData& a) const | 261 bool FontPlatformData::operator==(const FontPlatformData& a) const |
130 { | 262 { |
| 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 |
131 | 277 |
132 return platformIsEqual(a) | 278 return typefacesEqual |
133 && m_textSize == a.m_textSize | 279 && m_textSize == a.m_textSize |
134 && m_isHashTableDeletedValue == a.m_isHashTableDeletedValue | 280 && m_isHashTableDeletedValue == a.m_isHashTableDeletedValue |
135 && m_syntheticBold == a.m_syntheticBold | 281 && m_syntheticBold == a.m_syntheticBold |
136 && m_syntheticItalic == a.m_syntheticItalic | 282 && m_syntheticItalic == a.m_syntheticItalic |
137 && m_orientation == a.m_orientation | 283 && m_orientation == a.m_orientation |
138 #if !OS(MACOSX) | 284 #if !OS(MACOSX) |
139 && m_style == a.m_style | 285 && m_style == a.m_style |
140 #endif | 286 #else |
141 && m_isColorBitmapFont == a.m_isColorBitmapFont | 287 && m_isColorBitmapFont == a.m_isColorBitmapFont |
142 && m_isCompositeFontReference == a.m_isCompositeFontReference | 288 && m_isCompositeFontReference == a.m_isCompositeFontReference |
| 289 #endif |
143 && m_widthVariant == a.m_widthVariant; | 290 && m_widthVariant == a.m_widthVariant; |
144 } | 291 } |
145 | 292 |
| 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 } |
146 | 338 |
147 } // namespace blink | 339 } // namespace blink |
OLD | NEW |