21#include <initializer_list>
23#ifdef SK_BUILD_FOR_MAC
27#import <ApplicationServices/ApplicationServices.h>
29static void std_cg_setup(CGContextRef ctx) {
30 CGContextSetAllowsFontSubpixelQuantization(ctx,
false);
31 CGContextSetShouldSubpixelQuantizeFonts(ctx,
false);
36 CGContextSetAllowsFontSubpixelPositioning(ctx,
true);
37 CGContextSetShouldSubpixelPositionFonts(ctx,
true);
39 CGContextSetAllowsFontSmoothing(ctx,
true);
40 CGContextSetShouldAntialias(ctx,
true);
42 CGContextSetTextDrawingMode(ctx, kCGTextFill);
45 CGContextSetGrayFillColor(ctx, 0.0f, 1.0f);
48static CGContextRef make_cg_ctx(
const SkPixmap& pm) {
54 info = kCGBitmapByteOrder32Host | (CGBitmapInfo)kCGImageAlphaNoneSkipFirst;
55 cs = CGColorSpaceCreateDeviceRGB();
58 info = kCGImageAlphaNone;
59 cs = CGColorSpaceCreateDeviceGray();
62 info = kCGImageAlphaOnly;
78 canvas->
scale(10, 10);
85 surf->peekPixels(&pm);
86 CGContextRef ctx = make_cg_ctx(pm);
87 CGContextSelectFont(ctx,
"Times", size, kCGEncodingMacRoman);
90 for (
bool smooth : {
false,
true}) {
92 CGContextSetShouldSmoothFonts(ctx, smooth);
93 CGContextShowTextAtPoint(ctx, 2 + xpos, 2,
"A", 1);
95 surf->draw(canvas,
x,
y);
108 ~MacAAFontsGM()
override {}
112 test_mac_fonts(canvas, fSize, fXPos);
123 case 'i': fSize += 1;
return true;
124 case 'k': fSize -= 1;
return true;
125 case 'j': fXPos -= 1.0f/16;
return true;
126 case 'l': fXPos += 1.0f/16;
return true;
132DEF_GM(
return new MacAAFontsGM;)
137 const SkColor GRAY = 0xFF808080;
144 const SkScalar sizes[] = {10, 12, 15, 18, 24};
148 const char str[] =
"Hamburgefons";
149 const size_t len = strlen(str);
157 for (
size_t i = 0; i < std::size(colors); i += 2) {
161 paint.setColor(colors[i+1]);
163 paint.setColor(colors[i]);
169 for (
bool lcd : {
false,
true}) {
175 y += font.getSpacing() + 2;
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
@ kPremul_SkAlphaType
pixel components are premultiplied by alpha
@ kAlpha_8_SkColorType
pixel with alpha in 8-bit byte
@ kGray_8_SkColorType
pixel with grayscale level in 8-bit byte
@ kRGBA_8888_SkColorType
pixel with 8 bits for red, green, blue, alpha; in 32-bit word
constexpr SkColor SK_ColorBLACK
constexpr SkColor SK_ColorWHITE
@ kNormal
glyph outlines modified to improve constrast
@ kNone
glyph outlines unchanged
@ kUTF8
uses bytes to represent UTF-8 or ASCII
void drawRect(const SkRect &rect, const SkPaint &paint)
void drawSimpleText(const void *text, size_t byteLength, SkTextEncoding encoding, SkScalar x, SkScalar y, const SkFont &font, const SkPaint &paint)
void translate(SkScalar dx, SkScalar dy)
void scale(SkScalar sx, SkScalar sy)
@ kAntiAlias
may have transparent pixels on glyph edges
@ kSubpixelAntiAlias
glyph positioned in pixel using transparency
SkColorType colorType() const
void * writable_addr() const
virtual bool onChar(SkUnichar)
virtual SkISize getISize()=0
virtual SkString getName() const =0
virtual DrawResult onDraw(SkCanvas *, SkString *errorMsg)
#define DEF_SIMPLE_GM(NAME, CANVAS, W, H)
SK_API sk_sp< SkSurface > Raster(const SkImageInfo &imageInfo, size_t rowBytes, const SkSurfaceProps *surfaceProps)
static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at)