|
48 | 48 | #define kCTFontOrientationDefault kCTFontDefaultOrientation |
49 | 49 | #endif // MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_8 |
50 | 50 |
|
| 51 | +extern void CGContextSetFontSmoothingStyle(CGContextRef, int); |
| 52 | +extern int CGContextGetFontSmoothingStyle(CGContextRef); |
| 53 | +#define fontSmoothingStyleLight (2 << 3) |
| 54 | + |
51 | 55 | #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_7 |
52 | 56 | static void |
53 | 57 | CTFontDrawGlyphs(CTFontRef fontRef, const CGGlyph glyphs[], |
@@ -396,6 +400,11 @@ - (void)setLigatures:(BOOL)state |
396 | 400 | ligatures = state; |
397 | 401 | } |
398 | 402 |
|
| 403 | +- (void)setThinStrokes:(BOOL)state |
| 404 | +{ |
| 405 | + thinStrokes = state; |
| 406 | +} |
| 407 | + |
399 | 408 | - (void)setImControl:(BOOL)enable |
400 | 409 | { |
401 | 410 | [helper setImControl:enable]; |
@@ -1299,6 +1308,13 @@ - (void)drawString:(const UniChar *)chars length:(UniCharCount)length |
1299 | 1308 |
|
1300 | 1309 | CGContextSaveGState(context); |
1301 | 1310 |
|
| 1311 | + int originalFontSmoothingStyle = 0; |
| 1312 | + if (thinStrokes) { |
| 1313 | + CGContextSetShouldSmoothFonts(context, YES); |
| 1314 | + originalFontSmoothingStyle = CGContextGetFontSmoothingStyle(context); |
| 1315 | + CGContextSetFontSmoothingStyle(context, fontSmoothingStyleLight); |
| 1316 | + } |
| 1317 | + |
1302 | 1318 | // NOTE! 'cells' is zero if we're drawing a composing character |
1303 | 1319 | CGFloat clipWidth = cells > 0 ? cells*cellSize.width : w; |
1304 | 1320 | CGRect clipRect = { {x, y}, {clipWidth, cellSize.height} }; |
@@ -1389,6 +1405,8 @@ - (void)drawString:(const UniChar *)chars length:(UniCharCount)length |
1389 | 1405 | recurseDraw(chars, glyphs, positions, length, context, fontRef, fontCache, ligatures); |
1390 | 1406 |
|
1391 | 1407 | CFRelease(fontRef); |
| 1408 | + if (thinStrokes) |
| 1409 | + CGContextSetFontSmoothingStyle(context, originalFontSmoothingStyle); |
1392 | 1410 | CGContextRestoreGState(context); |
1393 | 1411 | } |
1394 | 1412 |
|
|
0 commit comments