OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2006 The Android Open Source Project | 2 * Copyright 2006 The Android Open Source Project |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "SkTypes.h" // Keep this before any #ifdef ... | 8 #include "SkTypes.h" // Keep this before any #ifdef ... |
9 #if defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS) | 9 #if defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS) |
10 | 10 |
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
316 */ | 316 */ |
317 static bool supports_LCD() { | 317 static bool supports_LCD() { |
318 static int gSupportsLCD = -1; | 318 static int gSupportsLCD = -1; |
319 if (gSupportsLCD >= 0) { | 319 if (gSupportsLCD >= 0) { |
320 return (bool) gSupportsLCD; | 320 return (bool) gSupportsLCD; |
321 } | 321 } |
322 uint32_t rgb = 0; | 322 uint32_t rgb = 0; |
323 AutoCFRelease<CGColorSpaceRef> colorspace(CGColorSpaceCreateDeviceRGB()); | 323 AutoCFRelease<CGColorSpaceRef> colorspace(CGColorSpaceCreateDeviceRGB()); |
324 AutoCFRelease<CGContextRef> cgContext(CGBitmapContextCreate(&rgb, 1, 1, 8, 4
, | 324 AutoCFRelease<CGContextRef> cgContext(CGBitmapContextCreate(&rgb, 1, 1, 8, 4
, |
325 colorspace, BITM
AP_INFO_RGB)); | 325 colorspace, BITM
AP_INFO_RGB)); |
326 CGContextSelectFont(cgContext, "Helvetica", 16, kCGEncodingMacRoman); | 326 AutoCFRelease<CTFontRef> ctFont(CTFontCreateWithName(CFSTR("Helvetica"), 16,
nullptr)); |
327 CGContextSetShouldSmoothFonts(cgContext, true); | 327 CGContextSetShouldSmoothFonts(cgContext, true); |
328 CGContextSetShouldAntialias(cgContext, true); | 328 CGContextSetShouldAntialias(cgContext, true); |
329 CGContextSetTextDrawingMode(cgContext, kCGTextFill); | 329 CGContextSetTextDrawingMode(cgContext, kCGTextFill); |
330 CGContextSetGrayFillColor(cgContext, 1, 1); | 330 CGContextSetGrayFillColor(cgContext, 1, 1); |
331 CGContextShowTextAtPoint(cgContext, -1, 0, "|", 1); | 331 CGPoint point = CGPointMake(-1, 0); |
| 332 static const UniChar pipeChar = '|'; |
| 333 CGGlyph pipeGlyph; |
| 334 CTFontGetGlyphsForCharacters(ctFont, &pipeChar, &pipeGlyph, 1); |
| 335 CTFontDrawGlyphs(ctFont, &pipeGlyph, &point, 1, cgContext); |
| 336 |
332 uint32_t r = (rgb >> 16) & 0xFF; | 337 uint32_t r = (rgb >> 16) & 0xFF; |
333 uint32_t g = (rgb >> 8) & 0xFF; | 338 uint32_t g = (rgb >> 8) & 0xFF; |
334 uint32_t b = (rgb >> 0) & 0xFF; | 339 uint32_t b = (rgb >> 0) & 0xFF; |
335 gSupportsLCD = (r != g || r != b); | 340 gSupportsLCD = (r != g || r != b); |
336 return (bool) gSupportsLCD; | 341 return (bool) gSupportsLCD; |
337 } | 342 } |
338 | 343 |
339 class Offscreen { | 344 class Offscreen { |
340 public: | 345 public: |
341 Offscreen() | 346 Offscreen() |
(...skipping 492 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
834 // Some properties, like 'trak', are based on the text size (before applying
the matrix). | 839 // Some properties, like 'trak', are based on the text size (before applying
the matrix). |
835 CGFloat textSize = ScalarToCG(scale.y()); | 840 CGFloat textSize = ScalarToCG(scale.y()); |
836 fCTFont.reset(ctfont_create_exact_copy(ctFont, textSize, nullptr)); | 841 fCTFont.reset(ctfont_create_exact_copy(ctFont, textSize, nullptr)); |
837 fCGFont.reset(CTFontCopyGraphicsFont(fCTFont, nullptr)); | 842 fCGFont.reset(CTFontCopyGraphicsFont(fCTFont, nullptr)); |
838 | 843 |
839 // The fUnitMatrix includes the text size (and em) as it is used to scale th
e raw font data. | 844 // The fUnitMatrix includes the text size (and em) as it is used to scale th
e raw font data. |
840 SkScalar emPerFUnit = SkScalarInvert(SkIntToScalar(CGFontGetUnitsPerEm(fCGFo
nt))); | 845 SkScalar emPerFUnit = SkScalarInvert(SkIntToScalar(CGFontGetUnitsPerEm(fCGFo
nt))); |
841 fFUnitMatrix.preScale(emPerFUnit, -emPerFUnit); | 846 fFUnitMatrix.preScale(emPerFUnit, -emPerFUnit); |
842 } | 847 } |
843 | 848 |
844 /** This is an implementation of CTFontDrawGlyphs for 10.6; it was introduced in
10.7. */ | |
845 static void legacy_CTFontDrawGlyphs(CTFontRef, const CGGlyph glyphs[], const CGP
oint points[], | |
846 size_t count, CGContextRef cg) { | |
847 CGContextShowGlyphsAtPositions(cg, glyphs, points, count); | |
848 } | |
849 | |
850 typedef decltype(legacy_CTFontDrawGlyphs) CTFontDrawGlyphsProc; | |
851 | |
852 static CTFontDrawGlyphsProc* choose_CTFontDrawGlyphs() { | |
853 if (void* real = dlsym(RTLD_DEFAULT, "CTFontDrawGlyphs")) { | |
854 return (CTFontDrawGlyphsProc*)real; | |
855 } | |
856 return &legacy_CTFontDrawGlyphs; | |
857 } | |
858 | |
859 CGRGBPixel* Offscreen::getCG(const SkScalerContext_Mac& context, const SkGlyph&
glyph, | 849 CGRGBPixel* Offscreen::getCG(const SkScalerContext_Mac& context, const SkGlyph&
glyph, |
860 CGGlyph glyphID, size_t* rowBytesPtr, | 850 CGGlyph glyphID, size_t* rowBytesPtr, |
861 bool generateA8FromLCD) { | 851 bool generateA8FromLCD) { |
862 static SkOnce once; | |
863 static CTFontDrawGlyphsProc* ctFontDrawGlyphs; | |
864 once([]{ ctFontDrawGlyphs = choose_CTFontDrawGlyphs(); }); | |
865 | |
866 if (!fRGBSpace) { | 852 if (!fRGBSpace) { |
867 //It doesn't appear to matter what color space is specified. | 853 //It doesn't appear to matter what color space is specified. |
868 //Regular blends and antialiased text are always (s*a + d*(1-a)) | 854 //Regular blends and antialiased text are always (s*a + d*(1-a)) |
869 //and smoothed text is always g=2.0. | 855 //and smoothed text is always g=2.0. |
870 fRGBSpace.reset(CGColorSpaceCreateDeviceRGB()); | 856 fRGBSpace.reset(CGColorSpaceCreateDeviceRGB()); |
871 } | 857 } |
872 | 858 |
873 // default to kBW_Format | 859 // default to kBW_Format |
874 bool doAA = false; | 860 bool doAA = false; |
875 bool doLCD = false; | 861 bool doLCD = false; |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
923 | 909 |
924 CGContextSetTextDrawingMode(fCG, kCGTextFill); | 910 CGContextSetTextDrawingMode(fCG, kCGTextFill); |
925 | 911 |
926 // Draw black on white to create mask. (Special path exists to speed thi
s up in CG.) | 912 // Draw black on white to create mask. (Special path exists to speed thi
s up in CG.) |
927 CGContextSetGrayFillColor(fCG, 0.0f, 1.0f); | 913 CGContextSetGrayFillColor(fCG, 0.0f, 1.0f); |
928 | 914 |
929 // force our checks below to happen | 915 // force our checks below to happen |
930 fDoAA = !doAA; | 916 fDoAA = !doAA; |
931 fDoLCD = !doLCD; | 917 fDoLCD = !doLCD; |
932 | 918 |
933 if (legacy_CTFontDrawGlyphs == ctFontDrawGlyphs) { | |
934 // CTFontDrawGlyphs will apply the font, font size, and font matrix
to the CGContext. | |
935 // Our 'fake' one does not, so set up the CGContext here. | |
936 CGContextSetFont(fCG, context.fCGFont); | |
937 CGContextSetFontSize(fCG, CTFontGetSize(context.fCTFont)); | |
938 } | |
939 CGContextSetTextMatrix(fCG, context.fTransform); | 919 CGContextSetTextMatrix(fCG, context.fTransform); |
940 } | 920 } |
941 | 921 |
942 if (fDoAA != doAA) { | 922 if (fDoAA != doAA) { |
943 CGContextSetShouldAntialias(fCG, doAA); | 923 CGContextSetShouldAntialias(fCG, doAA); |
944 fDoAA = doAA; | 924 fDoAA = doAA; |
945 } | 925 } |
946 if (fDoLCD != doLCD) { | 926 if (fDoLCD != doLCD) { |
947 CGContextSetShouldSmoothFonts(fCG, doLCD); | 927 CGContextSetShouldSmoothFonts(fCG, doLCD); |
948 fDoLCD = doLCD; | 928 fDoLCD = doLCD; |
(...skipping 25 matching lines...) Expand all Loading... |
974 CGPoint point = CGPointMake(-glyph.fLeft + subX, glyph.fTop + glyph.fHeight
- subY); | 954 CGPoint point = CGPointMake(-glyph.fLeft + subX, glyph.fTop + glyph.fHeight
- subY); |
975 // Prior to 10.10, CTFontDrawGlyphs acted like CGContextShowGlyphsAtPosition
s and took | 955 // Prior to 10.10, CTFontDrawGlyphs acted like CGContextShowGlyphsAtPosition
s and took |
976 // 'positions' which are in text space. The glyph location (in device space)
must be | 956 // 'positions' which are in text space. The glyph location (in device space)
must be |
977 // mapped into text space, so that CG can convert it back into device space. | 957 // mapped into text space, so that CG can convert it back into device space. |
978 // In 10.10.1, this is handled directly in CTFontDrawGlyphs. | 958 // In 10.10.1, this is handled directly in CTFontDrawGlyphs. |
979 // | 959 // |
980 // However, in 10.10.2 color glyphs no longer rotate based on the font trans
form. | 960 // However, in 10.10.2 color glyphs no longer rotate based on the font trans
form. |
981 // So always make the font transform identity and place the transform on the
context. | 961 // So always make the font transform identity and place the transform on the
context. |
982 point = CGPointApplyAffineTransform(point, context.fInvTransform); | 962 point = CGPointApplyAffineTransform(point, context.fInvTransform); |
983 | 963 |
984 ctFontDrawGlyphs(context.fCTFont, &glyphID, &point, 1, fCG); | 964 CTFontDrawGlyphs(context.fCTFont, &glyphID, &point, 1, fCG); |
985 | 965 |
986 SkASSERT(rowBytesPtr); | 966 SkASSERT(rowBytesPtr); |
987 *rowBytesPtr = rowBytes; | 967 *rowBytesPtr = rowBytes; |
988 return image; | 968 return image; |
989 } | 969 } |
990 | 970 |
991 void SkScalerContext_Mac::getVerticalOffset(CGGlyph glyphID, SkPoint* offset) co
nst { | 971 void SkScalerContext_Mac::getVerticalOffset(CGGlyph glyphID, SkPoint* offset) co
nst { |
992 // Snow Leopard returns cgVertOffset in completely un-transformed FUnits (em
space, y up). | 972 // Snow Leopard returns cgVertOffset in completely un-transformed FUnits (em
space, y up). |
993 // Lion and Leopard return cgVertOffset in CG units (pixels, y up). | 973 // Lion and Leopard return cgVertOffset in CG units (pixels, y up). |
994 CGSize cgVertOffset; | 974 CGSize cgVertOffset; |
(...skipping 1636 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2631 | 2611 |
2632 return SkSafeRef(GetDefaultFace()); | 2612 return SkSafeRef(GetDefaultFace()); |
2633 } | 2613 } |
2634 }; | 2614 }; |
2635 | 2615 |
2636 /////////////////////////////////////////////////////////////////////////////// | 2616 /////////////////////////////////////////////////////////////////////////////// |
2637 | 2617 |
2638 SkFontMgr* SkFontMgr::Factory() { return new SkFontMgr_Mac; } | 2618 SkFontMgr* SkFontMgr::Factory() { return new SkFontMgr_Mac; } |
2639 | 2619 |
2640 #endif//defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS) | 2620 #endif//defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS) |
OLD | NEW |