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

Unified Diff: src/ports/SkFontHost_mac.cpp

Issue 975493002: Draw glyphs on Mac without font transform. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Undo unneeded change. Created 5 years, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/ports/SkFontHost_mac.cpp
diff --git a/src/ports/SkFontHost_mac.cpp b/src/ports/SkFontHost_mac.cpp
index a4ee0866f9d307571928056570ab0678c12ffc6e..79fca8083f96147674ab30797165c1857d2fe90e 100755
--- a/src/ports/SkFontHost_mac.cpp
+++ b/src/ports/SkFontHost_mac.cpp
@@ -675,6 +675,7 @@ private:
Offscreen fOffscreen;
AutoCFRelease<CTFontRef> fCTFont;
+ CGAffineTransform fTransform;
CGAffineTransform fInvTransform;
/** Unrotated variant of fCTFont.
@@ -724,12 +725,12 @@ SkScalerContext_Mac::SkScalerContext_Mac(SkTypeface_Mac* typeface,
SkMatrix skTransform;
fRec.computeMatrices(SkScalerContextRec::kVertical_PreMatrixScale, &scale, &skTransform,
NULL, NULL, &fFUnitMatrix);
- CGAffineTransform transform = MatrixToCGAffineTransform(skTransform);
- fInvTransform = CGAffineTransformInvert(transform);
+ fTransform = MatrixToCGAffineTransform(skTransform);
+ fInvTransform = CGAffineTransformInvert(fTransform);
AutoCFRelease<CTFontDescriptorRef> ctFontDesc;
if (fVertical) {
- // Setting the vertical orientation here affects the character to glyph mapping.
+ // Setting the vertical orientation here is required for vertical metrics on some versions.
AutoCFRelease<CFMutableDictionaryRef> cfAttributes(CFDictionaryCreateMutable(
kCFAllocatorDefault, 0,
&kCFTypeDictionaryKeyCallBacks,
@@ -747,7 +748,7 @@ SkScalerContext_Mac::SkScalerContext_Mac(SkTypeface_Mac* typeface,
// Some properties, like 'trak', are based on the text size (before applying the matrix).
CGFloat textSize = ScalarToCG(scale.y());
- fCTFont.reset(CTFontCreateCopyWithAttributes(ctFont, textSize, &transform, ctFontDesc));
+ fCTFont.reset(CTFontCreateCopyWithAttributes(ctFont, textSize, &fTransform, ctFontDesc));
fCGFont.reset(CTFontCopyGraphicsFont(fCTFont, NULL));
fCTUnrotatedFont.reset(CTFontCreateCopyWithAttributes(ctFont, textSize,
&CGAffineTransformIdentity, NULL));
@@ -859,8 +860,8 @@ CGRGBPixel* Offscreen::getCG(const SkScalerContext_Mac& context, const SkGlyph&
// Our 'fake' one does not, so set up the CGContext here.
CGContextSetFont(fCG, context.fCGFont);
CGContextSetFontSize(fCG, CTFontGetSize(context.fCTFont));
- CGContextSetTextMatrix(fCG, CTFontGetMatrix(context.fCTFont));
}
+ CGContextSetTextMatrix(fCG, context.fTransform);
}
if (fDoAA != doAA) {
@@ -895,14 +896,16 @@ CGRGBPixel* Offscreen::getCG(const SkScalerContext_Mac& context, const SkGlyph&
}
CGPoint point = CGPointMake(-glyph.fLeft + subX, glyph.fTop + glyph.fHeight - subY);
- if (darwinVersion() < 14) {
- // Prior to 10.10, CTFontDrawGlyphs acted like CGContextShowGlyphsAtPositions and took
- // 'positions' which are in text space. The glyph location (in device space) must be
- // mapped into text space, so that CG can convert it back into device space.
- // In 10.10 and later, this is handled directly in CTFontDrawGlyphs.
- point = CGPointApplyAffineTransform(point, context.fInvTransform);
- }
- ctFontDrawGlyphs(context.fCTFont, &glyphID, &point, 1, fCG);
+ // Prior to 10.10, CTFontDrawGlyphs acted like CGContextShowGlyphsAtPositions and took
+ // 'positions' which are in text space. The glyph location (in device space) must be
+ // mapped into text space, so that CG can convert it back into device space.
+ // In 10.10.1, this is handled directly in CTFontDrawGlyphs.
+
+ // However, in 10.10.2 color glyphs no longer rotate based on the font transform.
+ // So always make the font transform identity and place the transform on the context.
+ point = CGPointApplyAffineTransform(point, context.fInvTransform);
+
+ ctFontDrawGlyphs(context.fCTUnrotatedFont, &glyphID, &point, 1, fCG);
SkASSERT(rowBytesPtr);
*rowBytesPtr = rowBytes;
« 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