| OLD | NEW |
| 1 /* | 1 /* |
| 2 * This file is part of the internal font implementation. | 2 * This file is part of the internal font implementation. |
| 3 * | 3 * |
| 4 * Copyright (C) 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reserved. | 4 * Copyright (C) 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reserved. |
| 5 * Copyright (c) 2010 Google Inc. All rights reserved. | 5 * Copyright (c) 2010 Google Inc. All rights reserved. |
| 6 * | 6 * |
| 7 * This library is free software; you can redistribute it and/or | 7 * This library is free software; you can redistribute it and/or |
| 8 * modify it under the terms of the GNU Library General Public | 8 * modify it under the terms of the GNU Library General Public |
| 9 * License as published by the Free Software Foundation; either | 9 * License as published by the Free Software Foundation; either |
| 10 * version 2 of the License, or (at your option) any later version. | 10 * version 2 of the License, or (at your option) any later version. |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 * | 21 * |
| 22 */ | 22 */ |
| 23 | 23 |
| 24 #import "config.h" | 24 #import "config.h" |
| 25 #import "platform/fonts/FontPlatformData.h" | 25 #import "platform/fonts/FontPlatformData.h" |
| 26 | 26 |
| 27 #import <AppKit/NSFont.h> | 27 #import <AppKit/NSFont.h> |
| 28 #import <AvailabilityMacros.h> | 28 #import <AvailabilityMacros.h> |
| 29 #import <wtf/text/WTFString.h> | 29 #import <wtf/text/WTFString.h> |
| 30 | 30 |
| 31 #if OS(MACOSX) |
| 31 #import "platform/fonts/harfbuzz/HarfBuzzFace.h" | 32 #import "platform/fonts/harfbuzz/HarfBuzzFace.h" |
| 32 #include "third_party/skia/include/ports/SkTypeface_mac.h" | 33 #include "third_party/skia/include/ports/SkTypeface_mac.h" |
| 34 #endif |
| 33 | 35 |
| 34 namespace blink { | 36 namespace blink { |
| 35 | 37 |
| 36 unsigned FontPlatformData::hash() const | 38 unsigned FontPlatformData::hash() const |
| 37 { | 39 { |
| 38 ASSERT(m_font || !m_cgFont); | 40 ASSERT(m_font || !m_cgFont); |
| 39 uintptr_t hashCodes[3] = { (uintptr_t)m_font, m_widthVariant, static_cast<ui
ntptr_t>(m_isHashTableDeletedValue << 3 | m_orientation << 2 | m_syntheticBold <
< 1 | m_syntheticItalic) }; | 41 uintptr_t hashCodes[3] = { (uintptr_t)m_font, m_widthVariant, static_cast<ui
ntptr_t>(m_isHashTableDeletedValue << 3 | m_orientation << 2 | m_syntheticBold <
< 1 | m_syntheticItalic) }; |
| 40 return StringHasher::hashMemory<sizeof(hashCodes)>(hashCodes); | 42 return StringHasher::hashMemory<sizeof(hashCodes)>(hashCodes); |
| 41 } | 43 } |
| 42 | 44 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 70 #endif | 72 #endif |
| 71 } | 73 } |
| 72 #endif | 74 #endif |
| 73 | 75 |
| 74 if (m_font) | 76 if (m_font) |
| 75 CFRetain(m_font); | 77 CFRetain(m_font); |
| 76 | 78 |
| 77 m_cgFont.adoptCF(cgFont); | 79 m_cgFont.adoptCF(cgFont); |
| 78 } | 80 } |
| 79 | 81 |
| 82 FontPlatformData:: ~FontPlatformData() |
| 83 { |
| 84 if (m_font && m_font != reinterpret_cast<NSFont *>(-1)) |
| 85 CFRelease(m_font); |
| 86 } |
| 87 |
| 80 void FontPlatformData::platformDataInit(const FontPlatformData& f) | 88 void FontPlatformData::platformDataInit(const FontPlatformData& f) |
| 81 { | 89 { |
| 82 m_font = f.m_font ? [f.m_font retain] : f.m_font; | 90 m_font = f.m_font && f.m_font != reinterpret_cast<NSFont *>(-1) ? [f.m_font
retain] : f.m_font; |
| 83 | 91 |
| 84 m_cgFont = f.m_cgFont; | 92 m_cgFont = f.m_cgFont; |
| 85 m_CTFont = f.m_CTFont; | 93 m_CTFont = f.m_CTFont; |
| 86 | 94 |
| 95 #if OS(MACOSX) |
| 87 m_inMemoryFont = f.m_inMemoryFont; | 96 m_inMemoryFont = f.m_inMemoryFont; |
| 88 m_harfBuzzFace = f.m_harfBuzzFace; | 97 m_harfBuzzFace = f.m_harfBuzzFace; |
| 89 m_typeface = f.m_typeface; | 98 m_typeface = f.m_typeface; |
| 99 #endif |
| 90 } | 100 } |
| 91 | 101 |
| 92 const FontPlatformData& FontPlatformData::platformDataAssign(const FontPlatformD
ata& f) | 102 const FontPlatformData& FontPlatformData::platformDataAssign(const FontPlatformD
ata& f) |
| 93 { | 103 { |
| 94 m_cgFont = f.m_cgFont; | 104 m_cgFont = f.m_cgFont; |
| 95 if (m_font == f.m_font) | 105 if (m_font == f.m_font) |
| 96 return *this; | 106 return *this; |
| 97 if (f.m_font) | 107 if (f.m_font && f.m_font != reinterpret_cast<NSFont *>(-1)) |
| 98 CFRetain(f.m_font); | 108 CFRetain(f.m_font); |
| 99 if (m_font) | 109 if (m_font && m_font != reinterpret_cast<NSFont *>(-1)) |
| 100 CFRelease(m_font); | 110 CFRelease(m_font); |
| 101 m_font = f.m_font; | 111 m_font = f.m_font; |
| 102 m_CTFont = f.m_CTFont; | 112 m_CTFont = f.m_CTFont; |
| 103 | 113 #if OS(MACOSX) |
| 104 m_inMemoryFont = f.m_inMemoryFont; | 114 m_inMemoryFont = f.m_inMemoryFont; |
| 105 m_harfBuzzFace = f.m_harfBuzzFace; | 115 m_harfBuzzFace = f.m_harfBuzzFace; |
| 106 m_typeface = f.m_typeface; | 116 m_typeface = f.m_typeface; |
| 107 | 117 #endif |
| 108 return *this; | 118 return *this; |
| 109 } | 119 } |
| 110 | 120 |
| 121 bool FontPlatformData::platformIsEqual(const FontPlatformData& other) const |
| 122 { |
| 123 if (m_font || other.m_font) |
| 124 return m_font == other.m_font; |
| 125 return m_cgFont == other.m_cgFont; |
| 126 } |
| 111 | 127 |
| 112 void FontPlatformData::setFont(NSFont *font) | 128 void FontPlatformData::setFont(NSFont *font) |
| 113 { | 129 { |
| 114 ASSERT_ARG(font, font); | 130 ASSERT_ARG(font, font); |
| 131 ASSERT(m_font != reinterpret_cast<NSFont *>(-1)); |
| 115 | 132 |
| 116 if (m_font == font) | 133 if (m_font == font) |
| 117 return; | 134 return; |
| 118 | 135 |
| 119 CFRetain(font); | 136 CFRetain(font); |
| 120 if (m_font) | 137 if (m_font) |
| 121 CFRelease(m_font); | 138 CFRelease(m_font); |
| 122 m_font = font; | 139 m_font = font; |
| 123 m_textSize = [font pointSize]; | 140 m_textSize = [font pointSize]; |
| 124 | 141 |
| 125 CGFontRef cgFont = 0; | 142 CGFontRef cgFont = 0; |
| 126 NSFont* loadedFont = 0; | 143 NSFont* loadedFont = 0; |
| 127 loadFont(m_font, m_textSize, loadedFont, cgFont); | 144 loadFont(m_font, m_textSize, loadedFont, cgFont); |
| 128 | 145 |
| 146 #if OS(MACOSX) |
| 129 // If loadFont replaced m_font with a fallback font, then release the | 147 // If loadFont replaced m_font with a fallback font, then release the |
| 130 // previous font to counter the retain above. Then retain the new font. | 148 // previous font to counter the retain above. Then retain the new font. |
| 131 if (loadedFont != m_font) { | 149 if (loadedFont != m_font) { |
| 132 CFRelease(m_font); | 150 CFRelease(m_font); |
| 133 CFRetain(loadedFont); | 151 CFRetain(loadedFont); |
| 134 m_font = loadedFont; | 152 m_font = loadedFont; |
| 135 } | 153 } |
| 154 #endif |
| 136 | 155 |
| 137 m_cgFont.adoptCF(cgFont); | 156 m_cgFont.adoptCF(cgFont); |
| 138 #if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1070 | 157 #if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1070 |
| 139 { | 158 { |
| 140 CTFontSymbolicTraits traits = CTFontGetSymbolicTraits(toCTFontRef(m_font
)); | 159 CTFontSymbolicTraits traits = CTFontGetSymbolicTraits(toCTFontRef(m_font
)); |
| 141 m_isColorBitmapFont = traits & kCTFontColorGlyphsTrait; | 160 m_isColorBitmapFont = traits & kCTFontColorGlyphsTrait; |
| 142 #if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1080 | 161 #if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1080 |
| 143 m_isCompositeFontReference = traits & kCTFontCompositeTrait; | 162 m_isCompositeFontReference = traits & kCTFontCompositeTrait; |
| 144 #endif | 163 #endif |
| 145 } | 164 } |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 | 237 |
| 219 const void* keys[] = { kCTFontFeatureSettingsAttribute }; | 238 const void* keys[] = { kCTFontFeatureSettingsAttribute }; |
| 220 const void* values[] = { featureSettings.get() }; | 239 const void* values[] = { featureSettings.get() }; |
| 221 RetainPtr<CFDictionaryRef> attributes(AdoptCF, CFDictionaryCreate(kCFAllocat
orDefault, keys, values, WTF_ARRAY_LENGTH(keys), &kCFTypeDictionaryKeyCallBacks,
&kCFTypeDictionaryValueCallBacks)); | 240 RetainPtr<CFDictionaryRef> attributes(AdoptCF, CFDictionaryCreate(kCFAllocat
orDefault, keys, values, WTF_ARRAY_LENGTH(keys), &kCFTypeDictionaryKeyCallBacks,
&kCFTypeDictionaryValueCallBacks)); |
| 222 | 241 |
| 223 descriptor = CTFontDescriptorCreateCopyWithAttributes(cascadeToLastResortFon
tDescriptor(), attributes.get()); | 242 descriptor = CTFontDescriptorCreateCopyWithAttributes(cascadeToLastResortFon
tDescriptor(), attributes.get()); |
| 224 | 243 |
| 225 return descriptor; | 244 return descriptor; |
| 226 } | 245 } |
| 227 | 246 |
| 247 String FontPlatformData::fontFamilyName() const |
| 248 { |
| 249 return String(CTFontCopyDisplayName(ctFont())); |
| 250 } |
| 251 |
| 228 CTFontRef FontPlatformData::ctFont() const | 252 CTFontRef FontPlatformData::ctFont() const |
| 229 { | 253 { |
| 230 if (m_CTFont) | 254 if (m_CTFont) |
| 231 return m_CTFont.get(); | 255 return m_CTFont.get(); |
| 232 | 256 |
| 233 if (m_inMemoryFont) { | 257 if (m_inMemoryFont) { |
| 234 m_CTFont.adoptCF(CTFontCreateWithGraphicsFont(m_inMemoryFont->cgFont(),
m_textSize, 0, cascadeToLastResortFontDescriptor())); | 258 m_CTFont.adoptCF(CTFontCreateWithGraphicsFont(m_inMemoryFont->cgFont(),
m_textSize, 0, cascadeToLastResortFontDescriptor())); |
| 235 return m_CTFont.get(); | 259 return m_CTFont.get(); |
| 236 } | 260 } |
| 237 | 261 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 257 RetainPtr<CTFontDescriptorRef> newDescriptor(AdoptCF, CTFontDescriptorCr
eateCopyWithFeature(sourceDescriptor.get(), featureType.get(), featureSelector.g
et())); | 281 RetainPtr<CTFontDescriptorRef> newDescriptor(AdoptCF, CTFontDescriptorCr
eateCopyWithFeature(sourceDescriptor.get(), featureType.get(), featureSelector.g
et())); |
| 258 RetainPtr<CTFontRef> newFont(AdoptCF, CTFontCreateWithFontDescriptor(new
Descriptor.get(), m_textSize, 0)); | 282 RetainPtr<CTFontRef> newFont(AdoptCF, CTFontCreateWithFontDescriptor(new
Descriptor.get(), m_textSize, 0)); |
| 259 | 283 |
| 260 if (newFont) | 284 if (newFont) |
| 261 m_CTFont = newFont; | 285 m_CTFont = newFont; |
| 262 } | 286 } |
| 263 | 287 |
| 264 return m_CTFont.get(); | 288 return m_CTFont.get(); |
| 265 } | 289 } |
| 266 | 290 |
| 267 bool FontPlatformData::isAATFont(CTFontRef ctFont) const | 291 SkTypeface* FontPlatformData::typeface() const { |
| 292 if (m_typeface) |
| 293 return m_typeface.get(); |
| 294 |
| 295 m_typeface = adoptRef(SkCreateTypefaceFromCTFont(ctFont())); |
| 296 return m_typeface.get(); |
| 297 } |
| 298 |
| 299 #if OS(MACOSX) |
| 300 static bool isAATFont(CTFontRef ctFont) |
| 268 { | 301 { |
| 269 CFDataRef table = CTFontCopyTable(ctFont, kCTFontTableMort, 0); | 302 CFDataRef table = CTFontCopyTable(ctFont, kCTFontTableMort, 0); |
| 270 if (table) { | 303 if (table) { |
| 271 CFRelease(table); | 304 CFRelease(table); |
| 272 return true; | 305 return true; |
| 273 } | 306 } |
| 274 table = CTFontCopyTable(ctFont, kCTFontTableMorx, 0); | 307 table = CTFontCopyTable(ctFont, kCTFontTableMorx, 0); |
| 275 if (table) { | 308 if (table) { |
| 276 CFRelease(table); | 309 CFRelease(table); |
| 277 return true; | 310 return true; |
| 278 } | 311 } |
| 279 return false; | 312 return false; |
| 280 } | 313 } |
| 314 #endif |
| 315 |
| 316 HarfBuzzFace* FontPlatformData::harfBuzzFace() const |
| 317 { |
| 318 CTFontRef font = ctFont(); |
| 319 // HarfBuzz can't handle AAT font |
| 320 if (isAATFont(font)) |
| 321 return 0; |
| 322 |
| 323 if (!m_harfBuzzFace) { |
| 324 uint64_t uniqueID = reinterpret_cast<uintptr_t>(font); |
| 325 m_harfBuzzFace = HarfBuzzFace::create(const_cast<FontPlatformData*>(this
), uniqueID); |
| 326 } |
| 327 return m_harfBuzzFace.get(); |
| 328 } |
| 329 |
| 281 | 330 |
| 282 } // namespace blink | 331 } // namespace blink |
| OLD | NEW |