aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/ports
diff options
context:
space:
mode:
authorGravatar ccameron <ccameron@chromium.org>2016-10-04 15:02:02 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2016-10-04 15:02:02 -0700
commitf8ee5b4c6addc9c9670f82718187b19ab2be0798 (patch)
treefe12ac727a9f349cbc5b9bec68c241948112479e /src/ports
parent121563eb4a0203a8b85ea5fe7caedf6fb35f04bf (diff)
Mac: Remove use of deprecated font APIs
Remove use of CGContextSelectFont CGContextShowTextAtPoint APIs. Verified that the new calls create the same pixel value for the smoothing test as before. Also remove workarounds for 10.6, because it is not supported anymore. BUG=skia:5803 GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2395613002 Review-Url: https://codereview.chromium.org/2395613002
Diffstat (limited to 'src/ports')
-rw-r--r--src/ports/SkFontHost_mac.cpp36
1 files changed, 8 insertions, 28 deletions
diff --git a/src/ports/SkFontHost_mac.cpp b/src/ports/SkFontHost_mac.cpp
index 7d1ef750bd..b5d9858b5a 100644
--- a/src/ports/SkFontHost_mac.cpp
+++ b/src/ports/SkFontHost_mac.cpp
@@ -323,12 +323,17 @@ static bool supports_LCD() {
AutoCFRelease<CGColorSpaceRef> colorspace(CGColorSpaceCreateDeviceRGB());
AutoCFRelease<CGContextRef> cgContext(CGBitmapContextCreate(&rgb, 1, 1, 8, 4,
colorspace, BITMAP_INFO_RGB));
- CGContextSelectFont(cgContext, "Helvetica", 16, kCGEncodingMacRoman);
+ AutoCFRelease<CTFontRef> ctFont(CTFontCreateWithName(CFSTR("Helvetica"), 16, nullptr));
CGContextSetShouldSmoothFonts(cgContext, true);
CGContextSetShouldAntialias(cgContext, true);
CGContextSetTextDrawingMode(cgContext, kCGTextFill);
CGContextSetGrayFillColor(cgContext, 1, 1);
- CGContextShowTextAtPoint(cgContext, -1, 0, "|", 1);
+ CGPoint point = CGPointMake(-1, 0);
+ static const UniChar pipeChar = '|';
+ CGGlyph pipeGlyph;
+ CTFontGetGlyphsForCharacters(ctFont, &pipeChar, &pipeGlyph, 1);
+ CTFontDrawGlyphs(ctFont, &pipeGlyph, &point, 1, cgContext);
+
uint32_t r = (rgb >> 16) & 0xFF;
uint32_t g = (rgb >> 8) & 0xFF;
uint32_t b = (rgb >> 0) & 0xFF;
@@ -841,28 +846,9 @@ SkScalerContext_Mac::SkScalerContext_Mac(SkTypeface_Mac* typeface,
fFUnitMatrix.preScale(emPerFUnit, -emPerFUnit);
}
-/** This is an implementation of CTFontDrawGlyphs for 10.6; it was introduced in 10.7. */
-static void legacy_CTFontDrawGlyphs(CTFontRef, const CGGlyph glyphs[], const CGPoint points[],
- size_t count, CGContextRef cg) {
- CGContextShowGlyphsAtPositions(cg, glyphs, points, count);
-}
-
-typedef decltype(legacy_CTFontDrawGlyphs) CTFontDrawGlyphsProc;
-
-static CTFontDrawGlyphsProc* choose_CTFontDrawGlyphs() {
- if (void* real = dlsym(RTLD_DEFAULT, "CTFontDrawGlyphs")) {
- return (CTFontDrawGlyphsProc*)real;
- }
- return &legacy_CTFontDrawGlyphs;
-}
-
CGRGBPixel* Offscreen::getCG(const SkScalerContext_Mac& context, const SkGlyph& glyph,
CGGlyph glyphID, size_t* rowBytesPtr,
bool generateA8FromLCD) {
- static SkOnce once;
- static CTFontDrawGlyphsProc* ctFontDrawGlyphs;
- once([]{ ctFontDrawGlyphs = choose_CTFontDrawGlyphs(); });
-
if (!fRGBSpace) {
//It doesn't appear to matter what color space is specified.
//Regular blends and antialiased text are always (s*a + d*(1-a))
@@ -930,12 +916,6 @@ CGRGBPixel* Offscreen::getCG(const SkScalerContext_Mac& context, const SkGlyph&
fDoAA = !doAA;
fDoLCD = !doLCD;
- if (legacy_CTFontDrawGlyphs == ctFontDrawGlyphs) {
- // CTFontDrawGlyphs will apply the font, font size, and font matrix to the CGContext.
- // Our 'fake' one does not, so set up the CGContext here.
- CGContextSetFont(fCG, context.fCGFont);
- CGContextSetFontSize(fCG, CTFontGetSize(context.fCTFont));
- }
CGContextSetTextMatrix(fCG, context.fTransform);
}
@@ -981,7 +961,7 @@ CGRGBPixel* Offscreen::getCG(const SkScalerContext_Mac& context, const SkGlyph&
// So always make the font transform identity and place the transform on the context.
point = CGPointApplyAffineTransform(point, context.fInvTransform);
- ctFontDrawGlyphs(context.fCTFont, &glyphID, &point, 1, fCG);
+ CTFontDrawGlyphs(context.fCTFont, &glyphID, &point, 1, fCG);
SkASSERT(rowBytesPtr);
*rowBytesPtr = rowBytes;