aboutsummaryrefslogtreecommitdiff
path: root/font
diff options
context:
space:
mode:
authorJoe Wilm <joe@jwilm.com>2017-10-08 18:10:29 -0700
committerJoe Wilm <jwilm@users.noreply.github.com>2017-10-08 22:20:58 -0700
commit2ea20f4823ae96f92f47a1984a6dd118a9632fdb (patch)
tree910d61cc1b310fffeb0143a9f15ab34a332dd8e1 /font
parentb03ec0df37cc7967733a53383e1bb450e8e05369 (diff)
downloadalacritty-2ea20f4823ae96f92f47a1984a6dd118a9632fdb.tar.gz
alacritty-2ea20f4823ae96f92f47a1984a6dd118a9632fdb.zip
Scale all fonts based on device-pixel-ratio
Rather than use DPI from config, use device-pixel-ratio from winit. This is computed using the display DPI anyhow, so it should have the same effect.
Diffstat (limited to 'font')
-rw-r--r--font/src/darwin/mod.rs2
-rw-r--r--font/src/ft/mod.rs15
-rw-r--r--font/src/lib.rs2
3 files changed, 7 insertions, 12 deletions
diff --git a/font/src/darwin/mod.rs b/font/src/darwin/mod.rs
index 45423123..70b9e1f3 100644
--- a/font/src/darwin/mod.rs
+++ b/font/src/darwin/mod.rs
@@ -130,7 +130,7 @@ 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, use_thin_strokes: bool) -> Result<Rasterizer, Error> {
+ fn new(device_pixel_ratio: f32, use_thin_strokes: bool) -> Result<Rasterizer, Error> {
info!("device_pixel_ratio: {}", device_pixel_ratio);
Ok(Rasterizer {
fonts: HashMap::new(),
diff --git a/font/src/ft/mod.rs b/font/src/ft/mod.rs
index f37a500e..42134a88 100644
--- a/font/src/ft/mod.rs
+++ b/font/src/ft/mod.rs
@@ -63,9 +63,7 @@ pub struct FreeTypeRasterizer {
faces: HashMap<FontKey, Face>,
library: Library,
keys: HashMap<PathBuf, FontKey>,
- dpi_x: u32,
- dpi_y: u32,
- dpr: f32,
+ device_pixel_ratio: f32,
}
#[inline]
@@ -76,16 +74,14 @@ 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, _: bool) -> Result<FreeTypeRasterizer, Error> {
+ fn new(device_pixel_ratio: f32, _: bool) -> Result<FreeTypeRasterizer, Error> {
let library = Library::init()?;
Ok(FreeTypeRasterizer {
faces: HashMap::new(),
keys: HashMap::new(),
library: library,
- dpi_x: dpi_x as u32,
- dpi_y: dpi_y as u32,
- dpr: device_pixel_ratio,
+ device_pixel_ratio: device_pixel_ratio,
})
}
@@ -152,8 +148,7 @@ impl FreeTypeRasterizer {
/// Load a font face accoring to `FontDesc`
fn get_face(&mut self, desc: &FontDesc, size: Size) -> Result<Face, Error> {
// Adjust for DPI
- let scale = self.dpi_x as f32 / 72.;
- let size = Size::new(size.as_f32_pts() * scale);
+ let size = Size::new(size.as_f32_pts() * self.device_pixel_ratio * 96. / 72.);
match desc.style {
Style::Description { slant, weight } => {
@@ -278,7 +273,7 @@ impl FreeTypeRasterizer {
let size = face.non_scalable.as_ref()
.map(|v| v.pixelsize as f32)
- .unwrap_or_else(|| glyph_key.size.as_f32_pts() * self.dpi_x as f32 / 72.);
+ .unwrap_or_else(|| glyph_key.size.as_f32_pts() * self.device_pixel_ratio * 96. / 72.);
face.ft_face.set_char_size(to_freetype_26_6(size), 0, 0, 0)?;
diff --git a/font/src/lib.rs b/font/src/lib.rs
index f02df436..181fd88c 100644
--- a/font/src/lib.rs
+++ b/font/src/lib.rs
@@ -229,7 +229,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, use_thin_strokes: bool) -> Result<Self, Self::Err>
+ fn new(device_pixel_ratio: f32, use_thin_strokes: bool) -> Result<Self, Self::Err>
where Self: Sized;
/// Get `Metrics` for the given `FontKey`