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

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

Issue 559433002: Merge FontPlatformDataHarfBuzz and FontPlatformData headers (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: 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 17 matching lines...) Expand all
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 #if OS(MACOSX)
32 #import "platform/fonts/harfbuzz/HarfBuzzFace.h" 32 #import "platform/fonts/harfbuzz/HarfBuzzFace.h"
33 #include "third_party/skia/include/ports/SkTypeface_mac.h" 33 #include "third_party/skia/include/ports/SkTypeface_mac.h"
34 #endif 34 #endif
35 35
36 namespace blink { 36 namespace blink {
37 37
38 unsigned FontPlatformData::hash() const
39 {
40 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) };
42 return StringHasher::hashMemory<sizeof(hashCodes)>(hashCodes);
43 }
44
38 // These CoreText Text Spacing feature selectors are not defined in CoreText. 45 // These CoreText Text Spacing feature selectors are not defined in CoreText.
39 enum TextSpacingCTFeatureSelector { TextSpacingProportional, TextSpacingFullWidt h, TextSpacingHalfWidth, TextSpacingThirdWidth, TextSpacingQuarterWidth }; 46 enum TextSpacingCTFeatureSelector { TextSpacingProportional, TextSpacingFullWidt h, TextSpacingHalfWidth, TextSpacingThirdWidth, TextSpacingQuarterWidth };
40 47
41 FontPlatformData::FontPlatformData(NSFont *nsFont, float size, bool syntheticBol d, bool syntheticOblique, FontOrientation orientation, FontWidthVariant widthVar iant) 48 FontPlatformData::FontPlatformData(NSFont *nsFont, float size, bool syntheticBol d, bool syntheticItalic, FontOrientation orientation, FontWidthVariant widthVari ant)
42 : m_syntheticBold(syntheticBold) 49 : m_textSize(size)
43 , m_syntheticOblique(syntheticOblique) 50 , m_syntheticBold(syntheticBold)
51 , m_syntheticItalic(syntheticItalic)
44 , m_orientation(orientation) 52 , m_orientation(orientation)
45 , m_size(size) 53 , m_isColorBitmapFont(false)
54 , m_isCompositeFontReference(false)
46 , m_widthVariant(widthVariant) 55 , m_widthVariant(widthVariant)
47 , m_font(nsFont) 56 , m_font(nsFont)
48 , m_isColorBitmapFont(false) 57 , m_isHashTableDeletedValue(false)
49 , m_isCompositeFontReference(false)
50 { 58 {
51 ASSERT_ARG(nsFont, nsFont); 59 ASSERT_ARG(nsFont, nsFont);
52 60
53 CGFontRef cgFont = 0; 61 CGFontRef cgFont = 0;
54 loadFont(nsFont, size, m_font, cgFont); 62 loadFont(nsFont, size, m_font, cgFont);
55 63
56 #if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1070 64 #if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
57 // FIXME: Chromium: The following code isn't correct for the Chromium port s ince the sandbox might 65 // FIXME: Chromium: The following code isn't correct for the Chromium port s ince the sandbox might
58 // have blocked font loading, in which case we'll only have the real loaded font file after the call to loadFont(). 66 // have blocked font loading, in which case we'll only have the real loaded font file after the call to loadFont().
59 { 67 {
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 ASSERT_ARG(font, font); 130 ASSERT_ARG(font, font);
123 ASSERT(m_font != reinterpret_cast<NSFont *>(-1)); 131 ASSERT(m_font != reinterpret_cast<NSFont *>(-1));
124 132
125 if (m_font == font) 133 if (m_font == font)
126 return; 134 return;
127 135
128 CFRetain(font); 136 CFRetain(font);
129 if (m_font) 137 if (m_font)
130 CFRelease(m_font); 138 CFRelease(m_font);
131 m_font = font; 139 m_font = font;
132 m_size = [font pointSize]; 140 m_textSize = [font pointSize];
133 141
134 CGFontRef cgFont = 0; 142 CGFontRef cgFont = 0;
135 NSFont* loadedFont = 0; 143 NSFont* loadedFont = 0;
136 loadFont(m_font, m_size, loadedFont, cgFont); 144 loadFont(m_font, m_textSize, loadedFont, cgFont);
137 145
138 #if OS(MACOSX) 146 #if OS(MACOSX)
139 // 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
140 // 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.
141 if (loadedFont != m_font) { 149 if (loadedFont != m_font) {
142 CFRelease(m_font); 150 CFRelease(m_font);
143 CFRetain(loadedFont); 151 CFRetain(loadedFont);
144 m_font = loadedFont; 152 m_font = loadedFont;
145 } 153 }
146 #endif 154 #endif
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 { 248 {
241 return String(CTFontCopyDisplayName(ctFont())); 249 return String(CTFontCopyDisplayName(ctFont()));
242 } 250 }
243 251
244 CTFontRef FontPlatformData::ctFont() const 252 CTFontRef FontPlatformData::ctFont() const
245 { 253 {
246 if (m_CTFont) 254 if (m_CTFont)
247 return m_CTFont.get(); 255 return m_CTFont.get();
248 256
249 if (m_inMemoryFont) { 257 if (m_inMemoryFont) {
250 m_CTFont.adoptCF(CTFontCreateWithGraphicsFont(m_inMemoryFont->cgFont(), m_size, 0, cascadeToLastResortFontDescriptor())); 258 m_CTFont.adoptCF(CTFontCreateWithGraphicsFont(m_inMemoryFont->cgFont(), m_textSize, 0, cascadeToLastResortFontDescriptor()));
251 return m_CTFont.get(); 259 return m_CTFont.get();
252 } 260 }
253 261
254 m_CTFont = toCTFontRef(m_font); 262 m_CTFont = toCTFontRef(m_font);
255 if (m_CTFont) { 263 if (m_CTFont) {
256 CTFontDescriptorRef fontDescriptor; 264 CTFontDescriptorRef fontDescriptor;
257 RetainPtr<CFStringRef> postScriptName(AdoptCF, CTFontCopyPostScriptName( m_CTFont.get())); 265 RetainPtr<CFStringRef> postScriptName(AdoptCF, CTFontCopyPostScriptName( m_CTFont.get()));
258 // Hoefler Text Italic has line-initial and -final swashes enabled by de fault, so disable them. 266 // Hoefler Text Italic has line-initial and -final swashes enabled by de fault, so disable them.
259 if (CFEqual(postScriptName.get(), CFSTR("HoeflerText-Italic")) || CFEqua l(postScriptName.get(), CFSTR("HoeflerText-BlackItalic"))) 267 if (CFEqual(postScriptName.get(), CFSTR("HoeflerText-Italic")) || CFEqua l(postScriptName.get(), CFSTR("HoeflerText-BlackItalic")))
260 fontDescriptor = cascadeToLastResortAndDisableSwashesFontDescriptor( ); 268 fontDescriptor = cascadeToLastResortAndDisableSwashesFontDescriptor( );
261 else 269 else
262 fontDescriptor = cascadeToLastResortFontDescriptor(); 270 fontDescriptor = cascadeToLastResortFontDescriptor();
263 m_CTFont.adoptCF(CTFontCreateCopyWithAttributes(m_CTFont.get(), m_size, 0, fontDescriptor)); 271 m_CTFont.adoptCF(CTFontCreateCopyWithAttributes(m_CTFont.get(), m_textSi ze, 0, fontDescriptor));
264 } else 272 } else
265 m_CTFont.adoptCF(CTFontCreateWithGraphicsFont(m_cgFont.get(), m_size, 0, cascadeToLastResortFontDescriptor())); 273 m_CTFont.adoptCF(CTFontCreateWithGraphicsFont(m_cgFont.get(), m_textSize , 0, cascadeToLastResortFontDescriptor()));
266 274
267 if (m_widthVariant != RegularWidth) { 275 if (m_widthVariant != RegularWidth) {
268 int featureTypeValue = kTextSpacingType; 276 int featureTypeValue = kTextSpacingType;
269 int featureSelectorValue = mapFontWidthVariantToCTFeatureSelector(m_widt hVariant); 277 int featureSelectorValue = mapFontWidthVariantToCTFeatureSelector(m_widt hVariant);
270 RetainPtr<CTFontDescriptorRef> sourceDescriptor(AdoptCF, CTFontCopyFontD escriptor(m_CTFont.get())); 278 RetainPtr<CTFontDescriptorRef> sourceDescriptor(AdoptCF, CTFontCopyFontD escriptor(m_CTFont.get()));
271 RetainPtr<CFNumberRef> featureType(AdoptCF, CFNumberCreate(kCFAllocatorD efault, kCFNumberIntType, &featureTypeValue)); 279 RetainPtr<CFNumberRef> featureType(AdoptCF, CFNumberCreate(kCFAllocatorD efault, kCFNumberIntType, &featureTypeValue));
272 RetainPtr<CFNumberRef> featureSelector(AdoptCF, CFNumberCreate(kCFAlloca torDefault, kCFNumberIntType, &featureSelectorValue)); 280 RetainPtr<CFNumberRef> featureSelector(AdoptCF, CFNumberCreate(kCFAlloca torDefault, kCFNumberIntType, &featureSelectorValue));
273 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()));
274 RetainPtr<CTFontRef> newFont(AdoptCF, CTFontCreateWithFontDescriptor(new Descriptor.get(), m_size, 0)); 282 RetainPtr<CTFontRef> newFont(AdoptCF, CTFontCreateWithFontDescriptor(new Descriptor.get(), m_textSize, 0));
275 283
276 if (newFont) 284 if (newFont)
277 m_CTFont = newFont; 285 m_CTFont = newFont;
278 } 286 }
279 287
280 return m_CTFont.get(); 288 return m_CTFont.get();
281 } 289 }
282 290
283 SkTypeface* FontPlatformData::typeface() const{ 291 SkTypeface* FontPlatformData::typeface() const {
284 if (m_typeface) 292 if (m_typeface)
285 return m_typeface.get(); 293 return m_typeface.get();
286 294
287 m_typeface = adoptRef(SkCreateTypefaceFromCTFont(ctFont())); 295 m_typeface = adoptRef(SkCreateTypefaceFromCTFont(ctFont()));
288 return m_typeface.get(); 296 return m_typeface.get();
289 } 297 }
290 298
291 #if OS(MACOSX) 299 #if OS(MACOSX)
292 static bool isAATFont(CTFontRef ctFont) 300 static bool isAATFont(CTFontRef ctFont)
293 { 301 {
294 CFDataRef table = CTFontCopyTable(ctFont, kCTFontTableMort, 0); 302 CFDataRef table = CTFontCopyTable(ctFont, kCTFontTableMort, 0);
295 if (table) { 303 if (table) {
296 CFRelease(table); 304 CFRelease(table);
297 return true; 305 return true;
298 } 306 }
299 table = CTFontCopyTable(ctFont, kCTFontTableMorx, 0); 307 table = CTFontCopyTable(ctFont, kCTFontTableMorx, 0);
300 if (table) { 308 if (table) {
301 CFRelease(table); 309 CFRelease(table);
302 return true; 310 return true;
303 } 311 }
304 return false; 312 return false;
305 } 313 }
314 #endif
306 315
307 HarfBuzzFace* FontPlatformData::harfBuzzFace() 316 HarfBuzzFace* FontPlatformData::harfBuzzFace() const
308 { 317 {
309 CTFontRef font = ctFont(); 318 CTFontRef font = ctFont();
310 // HarfBuzz can't handle AAT font 319 // HarfBuzz can't handle AAT font
311 if (isAATFont(font)) 320 if (isAATFont(font))
312 return 0; 321 return 0;
313 322
314 if (!m_harfBuzzFace) { 323 if (!m_harfBuzzFace) {
315 uint64_t uniqueID = reinterpret_cast<uintptr_t>(font); 324 uint64_t uniqueID = reinterpret_cast<uintptr_t>(font);
316 m_harfBuzzFace = HarfBuzzFace::create(const_cast<FontPlatformData*>(this ), uniqueID); 325 m_harfBuzzFace = HarfBuzzFace::create(const_cast<FontPlatformData*>(this ), uniqueID);
317 } 326 }
318 return m_harfBuzzFace.get(); 327 return m_harfBuzzFace.get();
319 } 328 }
320 #endif
321 329
322 #ifndef NDEBUG 330 #ifndef NDEBUG
323 String FontPlatformData::description() const 331 String FontPlatformData::description() const
324 { 332 {
325 RetainPtr<CFStringRef> cgFontDescription(AdoptCF, CFCopyDescription(cgFont() )); 333 RetainPtr<CFStringRef> cgFontDescription(AdoptCF, CFCopyDescription(cgFont() ));
326 return String(cgFontDescription.get()) + " " + String::number(m_size) 334 return String(cgFontDescription.get()) + " " + String::number(m_textSize)
327 + (m_syntheticBold ? " synthetic bold" : "") + (m_syntheticOblique ? " synthetic oblique" : "") + (m_orientation ? " vertical orientation" : ""); 335 + (m_syntheticBold ? " synthetic bold" : "") + (m_syntheticItalic ? " synthetic oblique" : "") + (m_orientation ? " vertical orientation" : "");
328 } 336 }
329 #endif 337 #endif
330 338
331 } // namespace blink 339 } // namespace blink
OLDNEW
« no previous file with comments | « Source/platform/fonts/FontPlatformData.cpp ('k') | Source/platform/fonts/harfbuzz/FontPlatformDataHarfBuzz.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698