add subpixel tweaking
Bug: skia: Change-Id: Ibf5fdf00694e29cb3f3268ea577a8d317e6c7614 Reviewed-on: https://skia-review.googlesource.com/c/193697 Reviewed-by: Mike Reed <reed@google.com> Commit-Queue: Mike Reed <reed@google.com> Auto-Submit: Mike Reed <reed@google.com>
This commit is contained in:
parent
f0aefa2bc1
commit
11bfaf160b
@ -12,6 +12,25 @@
|
||||
|
||||
#import <ApplicationServices/ApplicationServices.h>
|
||||
|
||||
static void std_cg_setup(CGContextRef ctx) {
|
||||
CGContextSetAllowsFontSubpixelQuantization(ctx, false);
|
||||
CGContextSetShouldSubpixelQuantizeFonts(ctx, false);
|
||||
|
||||
// Because CG always draws from the horizontal baseline,
|
||||
// if there is a non-integral translation from the horizontal origin to the vertical origin,
|
||||
// then CG cannot draw the glyph in the correct location without subpixel positioning.
|
||||
CGContextSetAllowsFontSubpixelPositioning(ctx, true);
|
||||
CGContextSetShouldSubpixelPositionFonts(ctx, true);
|
||||
|
||||
CGContextSetAllowsFontSmoothing(ctx, true);
|
||||
CGContextSetShouldAntialias(ctx, true);
|
||||
|
||||
CGContextSetTextDrawingMode(ctx, kCGTextFill);
|
||||
|
||||
// Draw black on white to create mask. (Special path exists to speed this up in CG.)
|
||||
CGContextSetGrayFillColor(ctx, 0.0f, 1.0f);
|
||||
}
|
||||
|
||||
static CGContextRef make_cg_ctx(const SkPixmap& pm) {
|
||||
CGBitmapInfo info;
|
||||
CGColorSpaceRef cs;
|
||||
@ -32,14 +51,15 @@ static CGContextRef make_cg_ctx(const SkPixmap& pm) {
|
||||
default:
|
||||
return nullptr;
|
||||
}
|
||||
return CGBitmapContextCreate(pm.writable_addr(), pm.width(), pm.height(), 8, pm.rowBytes(),
|
||||
cs, info);
|
||||
auto ctx = CGBitmapContextCreate(pm.writable_addr(), pm.width(), pm.height(), 8, pm.rowBytes(),
|
||||
cs, info);
|
||||
std_cg_setup(ctx);
|
||||
return ctx;
|
||||
}
|
||||
|
||||
static void test_mac_fonts(SkCanvas* canvas, SkScalar size) {
|
||||
static void test_mac_fonts(SkCanvas* canvas, SkScalar size, SkScalar xpos) {
|
||||
int w = 32;
|
||||
int h = 32;
|
||||
bool shouldAA = true;
|
||||
|
||||
canvas->scale(10, 10);
|
||||
SkScalar y = 1;
|
||||
@ -50,15 +70,13 @@ static void test_mac_fonts(SkCanvas* canvas, SkScalar size) {
|
||||
SkPixmap pm;
|
||||
surf->peekPixels(&pm);
|
||||
CGContextRef ctx = make_cg_ctx(pm);
|
||||
CGContextSetAllowsFontSmoothing(ctx, true);
|
||||
CGContextSetShouldAntialias(ctx, shouldAA);
|
||||
CGContextSelectFont(ctx, "Helvetica", size, kCGEncodingMacRoman);
|
||||
|
||||
SkScalar x = 1;
|
||||
for (bool smooth : {false, true}) {
|
||||
surf->getCanvas()->clear(ct == kGray_8_SkColorType ? 0xFFFFFFFF : 0);
|
||||
CGContextSetShouldSmoothFonts(ctx, smooth);
|
||||
CGContextShowTextAtPoint(ctx, 2, 2, "A", 1);
|
||||
CGContextShowTextAtPoint(ctx, 2 + xpos, 2, "A", 1);
|
||||
|
||||
surf->draw(canvas, x, y, nullptr);
|
||||
x += pm.width();
|
||||
@ -69,13 +87,15 @@ static void test_mac_fonts(SkCanvas* canvas, SkScalar size) {
|
||||
|
||||
class MacAAFontsGM : public skiagm::GM {
|
||||
SkScalar fSize = 16;
|
||||
SkScalar fXPos = 0;
|
||||
|
||||
public:
|
||||
MacAAFontsGM() {}
|
||||
~MacAAFontsGM() override {}
|
||||
|
||||
protected:
|
||||
DrawResult onDraw(SkCanvas* canvas, SkString* errorMsg) override {
|
||||
test_mac_fonts(canvas, fSize);
|
||||
test_mac_fonts(canvas, fSize, fXPos);
|
||||
|
||||
return DrawResult::kOk;
|
||||
}
|
||||
@ -88,6 +108,8 @@ protected:
|
||||
switch (uni) {
|
||||
case 'i': fSize += 1; return true;
|
||||
case 'k': fSize -= 1; return true;
|
||||
case 'j': fXPos -= 1.0f/16; return true;
|
||||
case 'l': fXPos += 1.0f/16; return true;
|
||||
default: break;
|
||||
}
|
||||
return false;
|
||||
|
Loading…
Reference in New Issue
Block a user