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

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

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