Skip to content

Commit

Permalink
Enable vertical pixel-snapping when drawing glyph runs (#1890)
Browse files Browse the repository at this point in the history
- Devices with vertical antialiasing would render text as blurry if rendered on a fractional vertical coordinate.
   - CGContext functions that draw glyphs do not necessarily use coordinates from our custom text renderer,
     which already has pixel snapping enabled.
   - As such, manually round the y-translation in CGContext::DrawGlyphRun()
 - Updated reference images for two drawing tests dealing with line height.

 Fixes #1594
  • Loading branch information
ms-jihua committed Feb 1, 2017
1 parent e762f7b commit 1f0515a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
4 changes: 4 additions & 0 deletions Frameworks/CoreGraphics/CGContext.mm
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
#include <COMIncludes_end.h>

#import <atomic>
#import <cmath>
#import <list>
#import <vector>
#import <stack>
Expand Down Expand Up @@ -1925,6 +1926,9 @@ void CGContextSetPatternPhase(CGContextRef context, CGSize phase) {
CGAffineTransform textTransform = CGAffineTransformScale(textMatrix, 1.0, -1.0);
CGAffineTransform deviceTransform = CGContextGetUserSpaceToDeviceSpaceTransform(this);

// Snap the vertical baseline to the nearest pixel to avoid blurring on devices with vertical antialiasing
textTransform.ty = std::round(textTransform.ty);

CGAffineTransform finalTextTransform = CGAffineTransformConcat(textTransform, deviceTransform);
if ((fabs(finalTextTransform.a * glyphRun->fontEmSize) <= c_glyphThreshold &&
fabs(finalTextTransform.b * glyphRun->fontEmSize) <= c_glyphThreshold) ||
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 1f0515a

Please sign in to comment.