summaryrefslogtreecommitdiffstats
path: root/font
diff options
context:
space:
mode:
authorTom Crayford <tcrayford@googlemail.com>2017-01-10 13:58:54 +0000
committerJoe Wilm <jwilm@users.noreply.github.com>2017-01-12 21:19:40 -0800
commitf85cc353a68fa67b9ac7985c38412c103221e24d (patch)
treed51d411d1cd95fa5c8d30a15798a8e17b954089a /font
parent32cfca772798d13e9c96c5d66250f6ca5ae9baef (diff)
make thin stroke rendering configurable
Makes thin stroke rendering for darwin configurable by a new toplevel key under `font:` in the config file. Defaults to false, has no impact on non macos.
Diffstat (limited to 'font')
-rw-r--r--font/src/darwin/mod.rs14
-rw-r--r--font/src/ft/mod.rs2
-rw-r--r--font/src/lib.rs2
3 files changed, 10 insertions, 8 deletions
diff --git a/font/src/darwin/mod.rs b/font/src/darwin/mod.rs
index 35336df9..69a9f29a 100644
--- a/font/src/darwin/mod.rs
+++ b/font/src/darwin/mod.rs
@@ -78,6 +78,7 @@ pub struct Rasterizer {
fonts: HashMap<FontKey, Font>,
keys: HashMap<(FontDesc, Size), FontKey>,
device_pixel_ratio: f32,
+ use_thin_strokes: bool,
}
/// Errors occurring when using the core text rasterizer
@@ -122,12 +123,13 @@ impl ::std::fmt::Display for Error {
impl ::Rasterize for Rasterizer {
type Err = Error;
- fn new(_dpi_x: f32, _dpi_y: f32, device_pixel_ratio: f32) -> Result<Rasterizer, Error> {
+ fn new(_dpi_x: f32, _dpi_y: f32, device_pixel_ratio: f32, use_thin_strokes: bool) -> Result<Rasterizer, Error> {
println!("device_pixel_ratio: {}", device_pixel_ratio);
Ok(Rasterizer {
fonts: HashMap::new(),
keys: HashMap::new(),
device_pixel_ratio: device_pixel_ratio,
+ use_thin_strokes: use_thin_strokes,
})
}
@@ -164,7 +166,7 @@ impl ::Rasterize for Rasterizer {
self.fonts
.get(&glyph.font_key)
.ok_or(Error::FontNotLoaded)?
- .get_glyph(glyph.c, scaled_size as _)
+ .get_glyph(glyph.c, scaled_size as _, self.use_thin_strokes)
}
}
@@ -357,7 +359,7 @@ impl Font {
)
}
- pub fn get_glyph(&self, character: char, _size: f64) -> Result<RasterizedGlyph, Error> {
+ pub fn get_glyph(&self, character: char, _size: f64, use_thin_strokes: bool) -> Result<RasterizedGlyph, Error> {
let glyph_index = self.glyph_index(character)
.ok_or(Error::MissingGlyph(character))?;
@@ -402,9 +404,9 @@ impl Font {
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);
+ if use_thin_strokes {
+ cg_context.set_font_smoothing_style(16);
+ }
cg_context.set_allows_font_smoothing(true);
cg_context.set_should_smooth_fonts(true);
diff --git a/font/src/ft/mod.rs b/font/src/ft/mod.rs
index 0ffecf03..f9170ed3 100644
--- a/font/src/ft/mod.rs
+++ b/font/src/ft/mod.rs
@@ -41,7 +41,7 @@ fn to_freetype_26_6(f: f32) -> isize {
impl ::Rasterize for FreeTypeRasterizer {
type Err = Error;
- fn new(dpi_x: f32, dpi_y: f32, device_pixel_ratio: f32) -> Result<FreeTypeRasterizer, Error> {
+ fn new(dpi_x: f32, dpi_y: f32, device_pixel_ratio: f32, _: bool) -> Result<FreeTypeRasterizer, Error> {
let library = Library::init()?;
Ok(FreeTypeRasterizer {
diff --git a/font/src/lib.rs b/font/src/lib.rs
index bc4a2006..cf697c8a 100644
--- a/font/src/lib.rs
+++ b/font/src/lib.rs
@@ -199,7 +199,7 @@ pub trait Rasterize {
type Err: ::std::error::Error + Send + Sync + 'static;
/// Create a new Rasterize
- fn new(dpi_x: f32, dpi_y: f32, device_pixel_ratio: f32) -> Result<Self, Self::Err>
+ fn new(dpi_x: f32, dpi_y: f32, device_pixel_ratio: f32, use_thin_strokes: bool) -> Result<Self, Self::Err>
where Self: Sized;
/// Get `Metrics` for the given `FontKey` and `Size`