| 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 { |
| 179 } |
| 180 |
| 222 #if OS(MACOSX) | 181 #if OS(MACOSX) |
| 223 if (m_font) | 182 CTFontRef FontPlatformData::ctFont() const |
| 224 CFRelease(m_font); | 183 { |
| 184 return SkTypeface_GetCTFontRef(m_typeface.get()); |
| 185 }; |
| 186 |
| 187 CGFontRef FontPlatformData::cgFont() const |
| 188 { |
| 189 return CTFontCopyGraphicsFont(ctFont(), 0); |
| 190 } |
| 225 #endif | 191 #endif |
| 226 } | |
| 227 | 192 |
| 228 const FontPlatformData& FontPlatformData::operator=(const FontPlatformData& othe
r) | 193 const FontPlatformData& FontPlatformData::operator=(const FontPlatformData& othe
r) |
| 229 { | 194 { |
| 230 // Check for self-assignment. | 195 // Check for self-assignment. |
| 231 if (this == &other) | 196 if (this == &other) |
| 232 return *this; | 197 return *this; |
| 233 | 198 |
| 234 m_typeface = other.m_typeface; | 199 m_typeface = other.m_typeface; |
| 235 #if !OS(WIN) | 200 #if !OS(WIN) |
| 236 m_family = other.m_family; | 201 m_family = other.m_family; |
| 237 #endif | 202 #endif |
| 238 m_textSize = other.m_textSize; | 203 m_textSize = other.m_textSize; |
| 239 m_syntheticBold = other.m_syntheticBold; | 204 m_syntheticBold = other.m_syntheticBold; |
| 240 m_syntheticItalic = other.m_syntheticItalic; | 205 m_syntheticItalic = other.m_syntheticItalic; |
| 241 m_harfBuzzFace = nullptr; | 206 m_harfBuzzFace = nullptr; |
| 242 m_orientation = other.m_orientation; | 207 m_orientation = other.m_orientation; |
| 243 #if OS(MACOSX) | 208 #if !OS(MACOSX) |
| 244 m_isColorBitmapFont = other.m_isColorBitmapFont; | |
| 245 m_isCompositeFontReference = other.m_isCompositeFontReference; | |
| 246 #else | |
| 247 m_style = other.m_style; | 209 m_style = other.m_style; |
| 248 #endif | 210 #endif |
| 249 | 211 |
| 250 #if OS(WIN) | 212 #if OS(WIN) |
| 251 m_paintTextFlags = 0; | 213 m_paintTextFlags = 0; |
| 252 m_minSizeForAntiAlias = other.m_minSizeForAntiAlias; | 214 m_minSizeForAntiAlias = other.m_minSizeForAntiAlias; |
| 253 m_minSizeForSubpixel = other.m_minSizeForSubpixel; | 215 m_minSizeForSubpixel = other.m_minSizeForSubpixel; |
| 254 m_useSubpixelPositioning = other.m_useSubpixelPositioning; | 216 m_useSubpixelPositioning = other.m_useSubpixelPositioning; |
| 255 #endif | 217 #endif |
| 256 | 218 |
| 257 #if OS(MACOSX) | |
| 258 return platformDataAssign(other); | |
| 259 #else | |
| 260 return *this; | 219 return *this; |
| 261 #endif | |
| 262 } | 220 } |
| 263 | 221 |
| 264 bool FontPlatformData::operator==(const FontPlatformData& a) const | 222 bool FontPlatformData::operator==(const FontPlatformData& a) const |
| 265 { | 223 { |
| 266 // If either of the typeface pointers are null then we test for pointer | 224 // If either of the typeface pointers are null then we test for pointer |
| 267 // equality. Otherwise, we call SkTypeface::Equal on the valid pointers. | 225 // equality. Otherwise, we call SkTypeface::Equal on the valid pointers. |
| 268 bool typefacesEqual = false; | 226 bool typefacesEqual = false; |
| 269 if (!typeface() || !a.typeface()) | 227 if (!typeface() || !a.typeface()) |
| 270 typefacesEqual = typeface() == a.typeface(); | 228 typefacesEqual = typeface() == a.typeface(); |
| 271 else | 229 else |
| 272 typefacesEqual = SkTypeface::Equal(typeface(), a.typeface()); | 230 typefacesEqual = SkTypeface::Equal(typeface(), a.typeface()); |
| 273 | 231 |
| 274 return typefacesEqual | 232 return typefacesEqual |
| 275 && m_textSize == a.m_textSize | 233 && m_textSize == a.m_textSize |
| 276 && m_isHashTableDeletedValue == a.m_isHashTableDeletedValue | 234 && m_isHashTableDeletedValue == a.m_isHashTableDeletedValue |
| 277 && m_syntheticBold == a.m_syntheticBold | 235 && m_syntheticBold == a.m_syntheticBold |
| 278 && m_syntheticItalic == a.m_syntheticItalic | 236 && m_syntheticItalic == a.m_syntheticItalic |
| 279 && m_orientation == a.m_orientation | |
| 280 #if !OS(MACOSX) | 237 #if !OS(MACOSX) |
| 281 && m_style == a.m_style; | 238 && m_style == a.m_style |
| 282 #else | |
| 283 && m_isColorBitmapFont == a.m_isColorBitmapFont | |
| 284 && m_isCompositeFontReference == a.m_isCompositeFontReference; | |
| 285 #endif | 239 #endif |
| 240 && m_orientation == a.m_orientation; |
| 286 } | 241 } |
| 287 | 242 |
| 288 SkFontID FontPlatformData::uniqueID() const | 243 SkFontID FontPlatformData::uniqueID() const |
| 289 { | 244 { |
| 290 return typeface()->uniqueID(); | 245 return typeface()->uniqueID(); |
| 291 } | 246 } |
| 292 | 247 |
| 293 String FontPlatformData::fontFamilyName() const | 248 String FontPlatformData::fontFamilyName() const |
| 294 { | 249 { |
| 295 ASSERT(this->typeface()); | 250 ASSERT(this->typeface()); |
| 296 SkTypeface::LocalizedStrings* fontFamilyIterator = this->typeface()->createF
amilyNameIterator(); | 251 SkTypeface::LocalizedStrings* fontFamilyIterator = this->typeface()->createF
amilyNameIterator(); |
| 297 SkTypeface::LocalizedString localizedString; | 252 SkTypeface::LocalizedString localizedString; |
| 298 while (fontFamilyIterator->next(&localizedString) && !localizedString.fStrin
g.size()) { } | 253 while (fontFamilyIterator->next(&localizedString) && !localizedString.fStrin
g.size()) { } |
| 299 fontFamilyIterator->unref(); | 254 fontFamilyIterator->unref(); |
| 300 return String(localizedString.fString.c_str()); | 255 return String(localizedString.fString.c_str()); |
| 301 } | 256 } |
| 302 | 257 |
| 303 bool FontPlatformData::isFixedPitch() const | 258 bool FontPlatformData::isFixedPitch() const |
| 304 { | 259 { |
| 305 return typeface() && typeface()->isFixedPitch(); | 260 return typeface() && typeface()->isFixedPitch(); |
| 306 } | 261 } |
| 307 | 262 |
| 308 SkTypeface* FontPlatformData::typeface() const | 263 SkTypeface* FontPlatformData::typeface() const |
| 309 { | 264 { |
| 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 | |
| 317 return m_typeface.get(); | 265 return m_typeface.get(); |
| 318 } | 266 } |
| 319 | 267 |
| 320 HarfBuzzFace* FontPlatformData::harfBuzzFace() const | 268 HarfBuzzFace* FontPlatformData::harfBuzzFace() const |
| 321 { | 269 { |
| 322 if (!m_harfBuzzFace) | 270 if (!m_harfBuzzFace) |
| 323 m_harfBuzzFace = HarfBuzzFace::create(const_cast<FontPlatformData*>(this
), uniqueID()); | 271 m_harfBuzzFace = HarfBuzzFace::create(const_cast<FontPlatformData*>(this
), uniqueID()); |
| 324 | 272 |
| 325 return m_harfBuzzFace.get(); | 273 return m_harfBuzzFace.get(); |
| 326 } | 274 } |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 367 const size_t tableSize = m_typeface->getTableSize(tag); | 315 const size_t tableSize = m_typeface->getTableSize(tag); |
| 368 if (tableSize) { | 316 if (tableSize) { |
| 369 Vector<char> tableBuffer(tableSize); | 317 Vector<char> tableBuffer(tableSize); |
| 370 m_typeface->getTableData(tag, 0, tableSize, &tableBuffer[0]); | 318 m_typeface->getTableData(tag, 0, tableSize, &tableBuffer[0]); |
| 371 buffer = SharedBuffer::adoptVector(tableBuffer); | 319 buffer = SharedBuffer::adoptVector(tableBuffer); |
| 372 } | 320 } |
| 373 return buffer.release(); | 321 return buffer.release(); |
| 374 } | 322 } |
| 375 | 323 |
| 376 } // namespace blink | 324 } // namespace blink |
| OLD | NEW |