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

Side by Side Diff: src/ports/SkFontHost_mac.cpp

Issue 1061123002: Attempted mitigation of font tables released early. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Add SkToBool Created 5 years, 8 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2006 The Android Open Source Project 3 * Copyright 2006 The Android Open Source Project
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 #include "SkTypes.h" // Keep this before any #ifdef ... 9 #include "SkTypes.h" // Keep this before any #ifdef ...
10 10
(...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after
446 static const uint32_t SkCTFontColorGlyphsTrait = (1 << 13); 446 static const uint32_t SkCTFontColorGlyphsTrait = (1 << 13);
447 #endif 447 #endif
448 448
449 class SkTypeface_Mac : public SkTypeface { 449 class SkTypeface_Mac : public SkTypeface {
450 public: 450 public:
451 SkTypeface_Mac(const SkFontStyle& fs, SkFontID fontID, bool isFixedPitch, 451 SkTypeface_Mac(const SkFontStyle& fs, SkFontID fontID, bool isFixedPitch,
452 CTFontRef fontRef, const char requestedName[], bool isLocalSt ream) 452 CTFontRef fontRef, const char requestedName[], bool isLocalSt ream)
453 : SkTypeface(fs, fontID, isFixedPitch) 453 : SkTypeface(fs, fontID, isFixedPitch)
454 , fRequestedName(requestedName) 454 , fRequestedName(requestedName)
455 , fFontRef(fontRef) // caller has already called CFRetain for us 455 , fFontRef(fontRef) // caller has already called CFRetain for us
456 , fHasColorGlyphs(SkToBool(CTFontGetSymbolicTraits(fFontRef) & SkCTFontC olorGlyphsTrait))
456 , fIsLocalStream(isLocalStream) 457 , fIsLocalStream(isLocalStream)
457 , fHasColorGlyphs(CTFontGetSymbolicTraits(fFontRef) & SkCTFontColorGlyph sTrait)
458 { 458 {
459 SkASSERT(fontRef); 459 SkASSERT(fontRef);
460 } 460 }
461 461
462 SkString fRequestedName; 462 SkString fRequestedName;
463 AutoCFRelease<CTFontRef> fFontRef; 463 AutoCFRelease<CTFontRef> fFontRef;
464 const bool fHasColorGlyphs;
464 465
465 protected: 466 protected:
466 int onGetUPEM() const override; 467 int onGetUPEM() const override;
467 SkStreamAsset* onOpenStream(int* ttcIndex) const override; 468 SkStreamAsset* onOpenStream(int* ttcIndex) const override;
468 void onGetFamilyName(SkString* familyName) const override; 469 void onGetFamilyName(SkString* familyName) const override;
469 SkTypeface::LocalizedStrings* onCreateFamilyNameIterator() const override; 470 SkTypeface::LocalizedStrings* onCreateFamilyNameIterator() const override;
470 int onGetTableTags(SkFontTableTag tags[]) const override; 471 int onGetTableTags(SkFontTableTag tags[]) const override;
471 virtual size_t onGetTableData(SkFontTableTag, size_t offset, 472 virtual size_t onGetTableData(SkFontTableTag, size_t offset,
472 size_t length, void* data) const override; 473 size_t length, void* data) const override;
473 SkScalerContext* onCreateScalerContext(const SkDescriptor*) const override; 474 SkScalerContext* onCreateScalerContext(const SkDescriptor*) const override;
474 void onFilterRec(SkScalerContextRec*) const override; 475 void onFilterRec(SkScalerContextRec*) const override;
475 void onGetFontDescriptor(SkFontDescriptor*, bool*) const override; 476 void onGetFontDescriptor(SkFontDescriptor*, bool*) const override;
476 virtual SkAdvancedTypefaceMetrics* onGetAdvancedTypefaceMetrics( 477 virtual SkAdvancedTypefaceMetrics* onGetAdvancedTypefaceMetrics(
477 SkAdvancedTypefaceMetrics::PerGlyphInfo, 478 SkAdvancedTypefaceMetrics::PerGlyphInfo,
478 const uint32_t*, uint32_t) const override; 479 const uint32_t*, uint32_t) const override;
479 virtual int onCharsToGlyphs(const void* chars, Encoding, uint16_t glyphs[], 480 virtual int onCharsToGlyphs(const void* chars, Encoding, uint16_t glyphs[],
480 int glyphCount) const override; 481 int glyphCount) const override;
481 int onCountGlyphs() const override; 482 int onCountGlyphs() const override;
482 483
483 private: 484 private:
484 bool fIsLocalStream; 485 bool fIsLocalStream;
485 bool fHasColorGlyphs;
486 486
487 typedef SkTypeface INHERITED; 487 typedef SkTypeface INHERITED;
488 }; 488 };
489 489
490 static SkTypeface* NewFromFontRef(CTFontRef fontRef, const char name[], bool isL ocalStream) { 490 static SkTypeface* NewFromFontRef(CTFontRef fontRef, const char name[], bool isL ocalStream) {
491 SkASSERT(fontRef); 491 SkASSERT(fontRef);
492 bool isFixedPitch; 492 bool isFixedPitch;
493 SkFontStyle style = SkFontStyle(computeStyleBits(fontRef, &isFixedPitch)); 493 SkFontStyle style = SkFontStyle(computeStyleBits(fontRef, &isFixedPitch));
494 SkFontID fontID = CTFontRef_to_SkFontID(fontRef); 494 SkFontID fontID = CTFontRef_to_SkFontID(fontRef);
495 495
(...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after
900 CGPoint point = CGPointMake(-glyph.fLeft + subX, glyph.fTop + glyph.fHeight - subY); 900 CGPoint point = CGPointMake(-glyph.fLeft + subX, glyph.fTop + glyph.fHeight - subY);
901 // Prior to 10.10, CTFontDrawGlyphs acted like CGContextShowGlyphsAtPosition s and took 901 // Prior to 10.10, CTFontDrawGlyphs acted like CGContextShowGlyphsAtPosition s and took
902 // 'positions' which are in text space. The glyph location (in device space) must be 902 // 'positions' which are in text space. The glyph location (in device space) must be
903 // mapped into text space, so that CG can convert it back into device space. 903 // mapped into text space, so that CG can convert it back into device space.
904 // In 10.10.1, this is handled directly in CTFontDrawGlyphs. 904 // In 10.10.1, this is handled directly in CTFontDrawGlyphs.
905 905
906 // However, in 10.10.2 color glyphs no longer rotate based on the font trans form. 906 // However, in 10.10.2 color glyphs no longer rotate based on the font trans form.
907 // So always make the font transform identity and place the transform on the context. 907 // So always make the font transform identity and place the transform on the context.
908 point = CGPointApplyAffineTransform(point, context.fInvTransform); 908 point = CGPointApplyAffineTransform(point, context.fInvTransform);
909 909
910 // Attempt to keep on the stack a hard reference to the font tables.
911 // This is an experiment to see if this affects crbug.com/413332 .
912 // When 10.6 headers are no longer supported, 'sbix' can be replaced with kC TFontTableSbix.
913 AutoCFRelease<CFDataRef> sbix;
914 if (static_cast<SkTypeface_Mac*>(context.getTypeface())->fHasColorGlyphs) {
915 sbix.reset(CGFontCopyTableForTag(context.fCGFont, 'sbix'));
916 }
910 ctFontDrawGlyphs(context.fCTUnrotatedFont, &glyphID, &point, 1, fCG); 917 ctFontDrawGlyphs(context.fCTUnrotatedFont, &glyphID, &point, 1, fCG);
911 918
912 SkASSERT(rowBytesPtr); 919 SkASSERT(rowBytesPtr);
913 *rowBytesPtr = rowBytes; 920 *rowBytesPtr = rowBytes;
914 return image; 921 return image;
915 } 922 }
916 923
917 void SkScalerContext_Mac::getVerticalOffset(CGGlyph glyphID, SkPoint* offset) co nst { 924 void SkScalerContext_Mac::getVerticalOffset(CGGlyph glyphID, SkPoint* offset) co nst {
918 // Snow Leopard returns cgVertOffset in completely un-transformed FUnits (em space, y up). 925 // Snow Leopard returns cgVertOffset in completely un-transformed FUnits (em space, y up).
919 // Lion and Leopard return cgVertOffset in CG units (pixels, y up). 926 // Lion and Leopard return cgVertOffset in CG units (pixels, y up).
(...skipping 1366 matching lines...) Expand 10 before | Expand all | Expand 10 after
2286 } 2293 }
2287 return face; 2294 return face;
2288 } 2295 }
2289 }; 2296 };
2290 2297
2291 /////////////////////////////////////////////////////////////////////////////// 2298 ///////////////////////////////////////////////////////////////////////////////
2292 2299
2293 SkFontMgr* SkFontMgr::Factory() { 2300 SkFontMgr* SkFontMgr::Factory() {
2294 return SkNEW(SkFontMgr_Mac); 2301 return SkNEW(SkFontMgr_Mac);
2295 } 2302 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698