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

Side by Side Diff: Source/platform/fonts/cocoa/FontPlatformDataCocoa.mm

Issue 550083005: Merge FontPlatformDataHarfBuzz into FontPlatformData (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Formatting fix in FontPlatformData.h (Daniel's comment) Created 6 years, 3 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
OLDNEW
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
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)
32 #import "platform/fonts/harfbuzz/HarfBuzzFace.h" 31 #import "platform/fonts/harfbuzz/HarfBuzzFace.h"
33 #include "third_party/skia/include/ports/SkTypeface_mac.h" 32 #include "third_party/skia/include/ports/SkTypeface_mac.h"
34 #endif
35 33
36 namespace blink { 34 namespace blink {
37 35
38 unsigned FontPlatformData::hash() const 36 unsigned FontPlatformData::hash() const
39 { 37 {
40 ASSERT(m_font || !m_cgFont); 38 ASSERT(m_font || !m_cgFont);
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) }; 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) };
42 return StringHasher::hashMemory<sizeof(hashCodes)>(hashCodes); 40 return StringHasher::hashMemory<sizeof(hashCodes)>(hashCodes);
43 } 41 }
44 42
(...skipping 27 matching lines...) Expand all
72 #endif 70 #endif
73 } 71 }
74 #endif 72 #endif
75 73
76 if (m_font) 74 if (m_font)
77 CFRetain(m_font); 75 CFRetain(m_font);
78 76
79 m_cgFont.adoptCF(cgFont); 77 m_cgFont.adoptCF(cgFont);
80 } 78 }
81 79
82 FontPlatformData:: ~FontPlatformData()
83 {
84 if (m_font && m_font != reinterpret_cast<NSFont *>(-1))
85 CFRelease(m_font);
86 }
87
88 void FontPlatformData::platformDataInit(const FontPlatformData& f) 80 void FontPlatformData::platformDataInit(const FontPlatformData& f)
89 { 81 {
90 m_font = f.m_font && f.m_font != reinterpret_cast<NSFont *>(-1) ? [f.m_font retain] : f.m_font; 82 m_font = f.m_font ? [f.m_font retain] : f.m_font;
91 83
92 m_cgFont = f.m_cgFont; 84 m_cgFont = f.m_cgFont;
93 m_CTFont = f.m_CTFont; 85 m_CTFont = f.m_CTFont;
94 86
95 #if OS(MACOSX)
96 m_inMemoryFont = f.m_inMemoryFont; 87 m_inMemoryFont = f.m_inMemoryFont;
97 m_harfBuzzFace = f.m_harfBuzzFace; 88 m_harfBuzzFace = f.m_harfBuzzFace;
98 m_typeface = f.m_typeface; 89 m_typeface = f.m_typeface;
99 #endif
100 } 90 }
101 91
102 const FontPlatformData& FontPlatformData::platformDataAssign(const FontPlatformD ata& f) 92 const FontPlatformData& FontPlatformData::platformDataAssign(const FontPlatformD ata& f)
103 { 93 {
104 m_cgFont = f.m_cgFont; 94 m_cgFont = f.m_cgFont;
105 if (m_font == f.m_font) 95 if (m_font == f.m_font)
106 return *this; 96 return *this;
107 if (f.m_font && f.m_font != reinterpret_cast<NSFont *>(-1)) 97 if (f.m_font)
108 CFRetain(f.m_font); 98 CFRetain(f.m_font);
109 if (m_font && m_font != reinterpret_cast<NSFont *>(-1)) 99 if (m_font)
110 CFRelease(m_font); 100 CFRelease(m_font);
111 m_font = f.m_font; 101 m_font = f.m_font;
112 m_CTFont = f.m_CTFont; 102 m_CTFont = f.m_CTFont;
113 #if OS(MACOSX) 103
114 m_inMemoryFont = f.m_inMemoryFont; 104 m_inMemoryFont = f.m_inMemoryFont;
115 m_harfBuzzFace = f.m_harfBuzzFace; 105 m_harfBuzzFace = f.m_harfBuzzFace;
116 m_typeface = f.m_typeface; 106 m_typeface = f.m_typeface;
117 #endif 107
118 return *this; 108 return *this;
119 } 109 }
120 110
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 }
127 111
128 void FontPlatformData::setFont(NSFont *font) 112 void FontPlatformData::setFont(NSFont *font)
129 { 113 {
130 ASSERT_ARG(font, font); 114 ASSERT_ARG(font, font);
131 ASSERT(m_font != reinterpret_cast<NSFont *>(-1));
132 115
133 if (m_font == font) 116 if (m_font == font)
134 return; 117 return;
135 118
136 CFRetain(font); 119 CFRetain(font);
137 if (m_font) 120 if (m_font)
138 CFRelease(m_font); 121 CFRelease(m_font);
139 m_font = font; 122 m_font = font;
140 m_textSize = [font pointSize]; 123 m_textSize = [font pointSize];
141 124
142 CGFontRef cgFont = 0; 125 CGFontRef cgFont = 0;
143 NSFont* loadedFont = 0; 126 NSFont* loadedFont = 0;
144 loadFont(m_font, m_textSize, loadedFont, cgFont); 127 loadFont(m_font, m_textSize, loadedFont, cgFont);
145 128
146 #if OS(MACOSX)
147 // If loadFont replaced m_font with a fallback font, then release the 129 // If loadFont replaced m_font with a fallback font, then release the
148 // previous font to counter the retain above. Then retain the new font. 130 // previous font to counter the retain above. Then retain the new font.
149 if (loadedFont != m_font) { 131 if (loadedFont != m_font) {
150 CFRelease(m_font); 132 CFRelease(m_font);
151 CFRetain(loadedFont); 133 CFRetain(loadedFont);
152 m_font = loadedFont; 134 m_font = loadedFont;
153 } 135 }
154 #endif
155 136
156 m_cgFont.adoptCF(cgFont); 137 m_cgFont.adoptCF(cgFont);
157 #if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1070 138 #if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
158 { 139 {
159 CTFontSymbolicTraits traits = CTFontGetSymbolicTraits(toCTFontRef(m_font )); 140 CTFontSymbolicTraits traits = CTFontGetSymbolicTraits(toCTFontRef(m_font ));
160 m_isColorBitmapFont = traits & kCTFontColorGlyphsTrait; 141 m_isColorBitmapFont = traits & kCTFontColorGlyphsTrait;
161 #if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1080 142 #if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1080
162 m_isCompositeFontReference = traits & kCTFontCompositeTrait; 143 m_isCompositeFontReference = traits & kCTFontCompositeTrait;
163 #endif 144 #endif
164 } 145 }
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 218
238 const void* keys[] = { kCTFontFeatureSettingsAttribute }; 219 const void* keys[] = { kCTFontFeatureSettingsAttribute };
239 const void* values[] = { featureSettings.get() }; 220 const void* values[] = { featureSettings.get() };
240 RetainPtr<CFDictionaryRef> attributes(AdoptCF, CFDictionaryCreate(kCFAllocat orDefault, keys, values, WTF_ARRAY_LENGTH(keys), &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks)); 221 RetainPtr<CFDictionaryRef> attributes(AdoptCF, CFDictionaryCreate(kCFAllocat orDefault, keys, values, WTF_ARRAY_LENGTH(keys), &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks));
241 222
242 descriptor = CTFontDescriptorCreateCopyWithAttributes(cascadeToLastResortFon tDescriptor(), attributes.get()); 223 descriptor = CTFontDescriptorCreateCopyWithAttributes(cascadeToLastResortFon tDescriptor(), attributes.get());
243 224
244 return descriptor; 225 return descriptor;
245 } 226 }
246 227
247 String FontPlatformData::fontFamilyName() const
248 {
249 return String(CTFontCopyDisplayName(ctFont()));
250 }
251
252 CTFontRef FontPlatformData::ctFont() const 228 CTFontRef FontPlatformData::ctFont() const
253 { 229 {
254 if (m_CTFont) 230 if (m_CTFont)
255 return m_CTFont.get(); 231 return m_CTFont.get();
256 232
257 if (m_inMemoryFont) { 233 if (m_inMemoryFont) {
258 m_CTFont.adoptCF(CTFontCreateWithGraphicsFont(m_inMemoryFont->cgFont(), m_textSize, 0, cascadeToLastResortFontDescriptor())); 234 m_CTFont.adoptCF(CTFontCreateWithGraphicsFont(m_inMemoryFont->cgFont(), m_textSize, 0, cascadeToLastResortFontDescriptor()));
259 return m_CTFont.get(); 235 return m_CTFont.get();
260 } 236 }
261 237
(...skipping 19 matching lines...) Expand all
281 RetainPtr<CTFontDescriptorRef> newDescriptor(AdoptCF, CTFontDescriptorCr eateCopyWithFeature(sourceDescriptor.get(), featureType.get(), featureSelector.g et())); 257 RetainPtr<CTFontDescriptorRef> newDescriptor(AdoptCF, CTFontDescriptorCr eateCopyWithFeature(sourceDescriptor.get(), featureType.get(), featureSelector.g et()));
282 RetainPtr<CTFontRef> newFont(AdoptCF, CTFontCreateWithFontDescriptor(new Descriptor.get(), m_textSize, 0)); 258 RetainPtr<CTFontRef> newFont(AdoptCF, CTFontCreateWithFontDescriptor(new Descriptor.get(), m_textSize, 0));
283 259
284 if (newFont) 260 if (newFont)
285 m_CTFont = newFont; 261 m_CTFont = newFont;
286 } 262 }
287 263
288 return m_CTFont.get(); 264 return m_CTFont.get();
289 } 265 }
290 266
291 SkTypeface* FontPlatformData::typeface() const { 267 bool FontPlatformData::isAATFont(CTFontRef ctFont) 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)
301 { 268 {
302 CFDataRef table = CTFontCopyTable(ctFont, kCTFontTableMort, 0); 269 CFDataRef table = CTFontCopyTable(ctFont, kCTFontTableMort, 0);
303 if (table) { 270 if (table) {
304 CFRelease(table); 271 CFRelease(table);
305 return true; 272 return true;
306 } 273 }
307 table = CTFontCopyTable(ctFont, kCTFontTableMorx, 0); 274 table = CTFontCopyTable(ctFont, kCTFontTableMorx, 0);
308 if (table) { 275 if (table) {
309 CFRelease(table); 276 CFRelease(table);
310 return true; 277 return true;
311 } 278 }
312 return false; 279 return false;
313 } 280 }
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
330 281
331 } // namespace blink 282 } // namespace blink
OLDNEW
« no previous file with comments | « Source/platform/fonts/FontPlatformData.cpp ('k') | Source/platform/fonts/harfbuzz/FontPlatformDataHarfBuzz.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698