mirror of
https://github.com/alacritty/alacritty.git
synced 2024-11-25 14:05:41 -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
|
||||
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
|
||||
render_timer: false
|
||||
|
||||
|
|
|
@ -40,6 +40,11 @@ font:
|
|||
x: 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
|
||||
render_timer: false
|
||||
|
||||
|
|
|
@ -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.
|
||||
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);
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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`
|
||||
|
|
|
@ -890,6 +890,12 @@ impl Config {
|
|||
self.render_timer
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn use_thin_strokes(&self) -> bool {
|
||||
self.font.use_thin_strokes
|
||||
}
|
||||
|
||||
|
||||
pub fn path(&self) -> Option<&Path> {
|
||||
self.config_path
|
||||
.as_ref()
|
||||
|
@ -1034,6 +1040,9 @@ pub struct Font {
|
|||
|
||||
/// Extra spacing per character
|
||||
offset: FontOffset,
|
||||
|
||||
#[serde(default="true_bool")]
|
||||
use_thin_strokes: bool
|
||||
}
|
||||
|
||||
fn default_bold_desc() -> FontDescription {
|
||||
|
@ -1082,6 +1091,7 @@ impl Default for Font {
|
|||
bold: FontDescription::new_with_family("Menlo"),
|
||||
italic: FontDescription::new_with_family("Menlo"),
|
||||
size: Size::new(11.0),
|
||||
use_thin_strokes: true,
|
||||
offset: FontOffset {
|
||||
x: 0.0,
|
||||
y: 0.0
|
||||
|
@ -1098,6 +1108,7 @@ impl Default for Font {
|
|||
bold: FontDescription::new_with_family("monospace"),
|
||||
italic: FontDescription::new_with_family("monospace"),
|
||||
size: Size::new(11.0),
|
||||
use_thin_strokes: false,
|
||||
offset: FontOffset {
|
||||
// TODO should improve freetype metrics... shouldn't need such
|
||||
// drastic offsets for the default!
|
||||
|
|
|
@ -148,7 +148,7 @@ impl Display {
|
|||
|
||||
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
|
||||
let mut renderer = QuadRenderer::new(config, size)?;
|
||||
|
|
Loading…
Reference in a new issue