summaryrefslogtreecommitdiffstats
path: root/font
diff options
context:
space:
mode:
authorJoe Wilm <joe@jwilm.com>2016-08-03 19:53:48 -0700
committerJoe Wilm <joe@jwilm.com>2016-08-03 19:53:48 -0700
commit874719580ce3e12f09d01a9a53c5e64205ef5b5d (patch)
tree35083a4b139eb0d4b7a2049e10a3c9b0725118e0 /font
parent16ed2ddfe9a40fb6f069c018aa9ea76dfb4a8b9b (diff)
Add support for CGContextSetFontSmoothingStyle
This enables narrower rendering of glyphs and it tends to look a bit better. iTerm2 and Terminal both do this.
Diffstat (limited to 'font')
-rw-r--r--font/src/darwin/mod.rs14
1 files changed, 13 insertions, 1 deletions
diff --git a/font/src/darwin/mod.rs b/font/src/darwin/mod.rs
index 10449e3e..31eb1292 100644
--- a/font/src/darwin/mod.rs
+++ b/font/src/darwin/mod.rs
@@ -37,7 +37,7 @@ use core_text::font_descriptor::kCTFontHorizontalOrientation;
use core_text::font_descriptor::kCTFontVerticalOrientation;
use core_text::font_descriptor::{CTFontDescriptor, CTFontDescriptorRef, CTFontOrientation};
-use libc::size_t;
+use libc::{size_t, c_int};
use euclid::point::Point2D;
use euclid::rect::Rect;
@@ -279,6 +279,10 @@ impl Font {
rasterized_height as f64));
cg_context.fill_rect(context_rect);
+ // Uses thin strokes
+ // TODO make this configurable since it's undesirable on non-retina displays.
+ cg_context.set_font_smoothing_style(16);
+
cg_context.set_allows_font_smoothing(true);
cg_context.set_should_smooth_fonts(true);
cg_context.set_allows_font_subpixel_quantization(true);
@@ -342,6 +346,7 @@ pub trait CGContextExt {
fn show_glyphs_at_positions(&self, &[CGGlyph], &[CGPoint]);
fn set_font(&self, &CGFont);
fn set_font_size(&self, size: f64);
+ fn set_font_smoothing_style(&self, style: i32);
}
impl CGContextExt for CGContext {
@@ -415,6 +420,12 @@ impl CGContextExt for CGContext {
CGContextSetFontSize(self.as_concrete_TypeRef(), size as CGFloat);
}
}
+
+ fn set_font_smoothing_style(&self, style: i32) {
+ unsafe {
+ CGContextSetFontSmoothingStyle(self.as_concrete_TypeRef(), style as _);
+ }
+ }
}
#[link(name = "ApplicationServices", kind = "framework")]
@@ -431,6 +442,7 @@ extern {
positions: *const CGPoint, count: size_t);
fn CGContextSetFont(c: CGContextRef, font: CGFontRef);
fn CGContextSetFontSize(c: CGContextRef, size: CGFloat);
+ fn CGContextSetFontSmoothingStyle(c: CGContextRef, style: c_int);
}
#[cfg(test)]