mirror of
https://github.com/alacritty/alacritty.git
synced 2024-11-18 13:55:23 -05:00
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.
This commit is contained in:
parent
32cfca7727
commit
f85cc353a6
7 changed files with 32 additions and 9 deletions
|
@ -40,6 +40,11 @@ font:
|
||||||
x: 2.0
|
x: 2.0
|
||||||
y: -7.0
|
y: -7.0
|
||||||
|
|
||||||
|
# OS X only: use thin stroke font rendering. Thin strokes are suitable
|
||||||
|
# for retina displays, but for non-retina you probably want this set to
|
||||||
|
# false.
|
||||||
|
use_thin_strokes: true
|
||||||
|
|
||||||
# Should display the render timer
|
# Should display the render timer
|
||||||
render_timer: false
|
render_timer: false
|
||||||
|
|
||||||
|
|
|
@ -40,6 +40,11 @@ font:
|
||||||
x: 0.0
|
x: 0.0
|
||||||
y: 0.0
|
y: 0.0
|
||||||
|
|
||||||
|
# OS X only: use thin stroke font rendering. Thin strokes are suitable
|
||||||
|
# for retina displays, but for non-retina you probably want this set to
|
||||||
|
# false.
|
||||||
|
use_thin_strokes: true
|
||||||
|
|
||||||
# Should display the render timer
|
# Should display the render timer
|
||||||
render_timer: false
|
render_timer: false
|
||||||
|
|
||||||
|
|
|
@ -78,6 +78,7 @@ pub struct Rasterizer {
|
||||||
fonts: HashMap<FontKey, Font>,
|
fonts: HashMap<FontKey, Font>,
|
||||||
keys: HashMap<(FontDesc, Size), FontKey>,
|
keys: HashMap<(FontDesc, Size), FontKey>,
|
||||||
device_pixel_ratio: f32,
|
device_pixel_ratio: f32,
|
||||||
|
use_thin_strokes: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Errors occurring when using the core text rasterizer
|
/// Errors occurring when using the core text rasterizer
|
||||||
|
@ -122,12 +123,13 @@ impl ::std::fmt::Display for Error {
|
||||||
impl ::Rasterize for Rasterizer {
|
impl ::Rasterize for Rasterizer {
|
||||||
type Err = Error;
|
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);
|
println!("device_pixel_ratio: {}", device_pixel_ratio);
|
||||||
Ok(Rasterizer {
|
Ok(Rasterizer {
|
||||||
fonts: HashMap::new(),
|
fonts: HashMap::new(),
|
||||||
keys: HashMap::new(),
|
keys: HashMap::new(),
|
||||||
device_pixel_ratio: device_pixel_ratio,
|
device_pixel_ratio: device_pixel_ratio,
|
||||||
|
use_thin_strokes: use_thin_strokes,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -164,7 +166,7 @@ impl ::Rasterize for Rasterizer {
|
||||||
self.fonts
|
self.fonts
|
||||||
.get(&glyph.font_key)
|
.get(&glyph.font_key)
|
||||||
.ok_or(Error::FontNotLoaded)?
|
.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)
|
let glyph_index = self.glyph_index(character)
|
||||||
.ok_or(Error::MissingGlyph(character))?;
|
.ok_or(Error::MissingGlyph(character))?;
|
||||||
|
|
||||||
|
@ -402,9 +404,9 @@ impl Font {
|
||||||
|
|
||||||
cg_context.fill_rect(context_rect);
|
cg_context.fill_rect(context_rect);
|
||||||
|
|
||||||
// Uses thin strokes
|
if use_thin_strokes {
|
||||||
// TODO make this configurable since it's undesirable on non-retina displays.
|
cg_context.set_font_smoothing_style(16);
|
||||||
cg_context.set_font_smoothing_style(16);
|
}
|
||||||
|
|
||||||
cg_context.set_allows_font_smoothing(true);
|
cg_context.set_allows_font_smoothing(true);
|
||||||
cg_context.set_should_smooth_fonts(true);
|
cg_context.set_should_smooth_fonts(true);
|
||||||
|
|
|
@ -41,7 +41,7 @@ fn to_freetype_26_6(f: f32) -> isize {
|
||||||
impl ::Rasterize for FreeTypeRasterizer {
|
impl ::Rasterize for FreeTypeRasterizer {
|
||||||
type Err = Error;
|
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()?;
|
let library = Library::init()?;
|
||||||
|
|
||||||
Ok(FreeTypeRasterizer {
|
Ok(FreeTypeRasterizer {
|
||||||
|
|
|
@ -199,7 +199,7 @@ pub trait Rasterize {
|
||||||
type Err: ::std::error::Error + Send + Sync + 'static;
|
type Err: ::std::error::Error + Send + Sync + 'static;
|
||||||
|
|
||||||
/// Create a new Rasterize
|
/// 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;
|
where Self: Sized;
|
||||||
|
|
||||||
/// Get `Metrics` for the given `FontKey` and `Size`
|
/// Get `Metrics` for the given `FontKey` and `Size`
|
||||||
|
|
|
@ -890,6 +890,12 @@ impl Config {
|
||||||
self.render_timer
|
self.render_timer
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn use_thin_strokes(&self) -> bool {
|
||||||
|
self.font.use_thin_strokes
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
pub fn path(&self) -> Option<&Path> {
|
pub fn path(&self) -> Option<&Path> {
|
||||||
self.config_path
|
self.config_path
|
||||||
.as_ref()
|
.as_ref()
|
||||||
|
@ -1034,6 +1040,9 @@ pub struct Font {
|
||||||
|
|
||||||
/// Extra spacing per character
|
/// Extra spacing per character
|
||||||
offset: FontOffset,
|
offset: FontOffset,
|
||||||
|
|
||||||
|
#[serde(default="true_bool")]
|
||||||
|
use_thin_strokes: bool
|
||||||
}
|
}
|
||||||
|
|
||||||
fn default_bold_desc() -> FontDescription {
|
fn default_bold_desc() -> FontDescription {
|
||||||
|
@ -1082,6 +1091,7 @@ impl Default for Font {
|
||||||
bold: FontDescription::new_with_family("Menlo"),
|
bold: FontDescription::new_with_family("Menlo"),
|
||||||
italic: FontDescription::new_with_family("Menlo"),
|
italic: FontDescription::new_with_family("Menlo"),
|
||||||
size: Size::new(11.0),
|
size: Size::new(11.0),
|
||||||
|
use_thin_strokes: true,
|
||||||
offset: FontOffset {
|
offset: FontOffset {
|
||||||
x: 0.0,
|
x: 0.0,
|
||||||
y: 0.0
|
y: 0.0
|
||||||
|
@ -1098,6 +1108,7 @@ impl Default for Font {
|
||||||
bold: FontDescription::new_with_family("monospace"),
|
bold: FontDescription::new_with_family("monospace"),
|
||||||
italic: FontDescription::new_with_family("monospace"),
|
italic: FontDescription::new_with_family("monospace"),
|
||||||
size: Size::new(11.0),
|
size: Size::new(11.0),
|
||||||
|
use_thin_strokes: false,
|
||||||
offset: FontOffset {
|
offset: FontOffset {
|
||||||
// TODO should improve freetype metrics... shouldn't need such
|
// TODO should improve freetype metrics... shouldn't need such
|
||||||
// drastic offsets for the default!
|
// drastic offsets for the default!
|
||||||
|
|
|
@ -148,7 +148,7 @@ impl Display {
|
||||||
|
|
||||||
println!("device_pixel_ratio: {}", dpr);
|
println!("device_pixel_ratio: {}", dpr);
|
||||||
|
|
||||||
let rasterizer = font::Rasterizer::new(dpi.x(), dpi.y(), dpr)?;
|
let rasterizer = font::Rasterizer::new(dpi.x(), dpi.y(), dpr, config.use_thin_strokes())?;
|
||||||
|
|
||||||
// Create renderer
|
// Create renderer
|
||||||
let mut renderer = QuadRenderer::new(config, size)?;
|
let mut renderer = QuadRenderer::new(config, size)?;
|
||||||
|
|
Loading…
Reference in a new issue