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

Unified Diff: src/ports/SkFontHost_mac.cpp

Issue 2395613002: Mac: Remove use of deprecated font APIs (Closed)
Patch Set: Created 4 years, 2 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 7d1ef750bd5d3f74336fe7e0a14d25c942103f53..b5d9858b5a8aa2adc0e9403f1078892c510ee8e2 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;
« 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