mirror of
https://github.com/alacritty/alacritty.git
synced 2024-11-25 14:05:41 -05:00
Add glyph offset option to user configuration
Add the ability to move glyphs within their cells on a global basis via an option in the configuration file.
This commit is contained in:
parent
1277e07671
commit
0a1dc56bcf
4 changed files with 66 additions and 5 deletions
|
@ -54,12 +54,20 @@ font:
|
|||
|
||||
# Point size of the font
|
||||
size: 11.0
|
||||
|
||||
# Offset is the extra space around each character. offset.y can be thought of
|
||||
# as modifying the linespacing, and offset.x as modifying the letter spacing.
|
||||
offset:
|
||||
x: 0.0
|
||||
y: 0.0
|
||||
|
||||
# Glyph offset determines the locations of the glyphs within their cells with
|
||||
# the default being at the bottom. Increase the x offset to move the glyph to
|
||||
# the right, increase the y offset to move the glyph upward.
|
||||
glyph_offset:
|
||||
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.
|
||||
|
|
|
@ -53,12 +53,20 @@ font:
|
|||
|
||||
# Point size of the font
|
||||
size: 12.0
|
||||
|
||||
# Offset is the extra space around each character. offset.y can be thought of
|
||||
# as modifying the linespacing, and offset.x as modifying the letter spacing.
|
||||
offset:
|
||||
x: 0.0
|
||||
y: 0.0
|
||||
|
||||
# Glyph offset determines the locations of the glyphs within their cells with
|
||||
# the default being at the bottom. Increase the x offset to move the glyph to
|
||||
# the right, increase the y offset to move the glyph upward.
|
||||
glyph_offset:
|
||||
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.
|
||||
|
|
|
@ -1195,6 +1195,25 @@ impl Default for FontOffset {
|
|||
}
|
||||
}
|
||||
|
||||
/// Modifications to glyph positions within their cells
|
||||
///
|
||||
/// By default the glyphs are located at the bottom of the cell which can be
|
||||
/// undesirable. This gives the user a way to shift where the glyphs are
|
||||
/// displayed in their cells.
|
||||
#[derive(Clone, Copy, Debug, Deserialize)]
|
||||
pub struct GlyphOffset {
|
||||
/// Horizontal position
|
||||
pub x: f32,
|
||||
/// Vertical position
|
||||
pub y: f32,
|
||||
}
|
||||
|
||||
impl Default for GlyphOffset {
|
||||
fn default() -> GlyphOffset {
|
||||
GlyphOffset { x: 0.0, y: 0.0 }
|
||||
}
|
||||
}
|
||||
|
||||
trait DeserializeFromF32 : Sized {
|
||||
fn deserialize_from_f32<D>(D) -> ::std::result::Result<Self, D::Error>
|
||||
where D: serde::de::Deserializer;
|
||||
|
@ -1256,6 +1275,10 @@ pub struct Font {
|
|||
/// Extra spacing per character
|
||||
offset: FontOffset,
|
||||
|
||||
/// Glyph offset within character cell
|
||||
#[serde(default)]
|
||||
glyph_offset: GlyphOffset,
|
||||
|
||||
#[serde(default="true_bool")]
|
||||
use_thin_strokes: bool
|
||||
}
|
||||
|
@ -1296,6 +1319,12 @@ impl Font {
|
|||
pub fn offset(&self) -> &FontOffset {
|
||||
&self.offset
|
||||
}
|
||||
|
||||
/// Get cell offsets for glyphs
|
||||
#[inline]
|
||||
pub fn glyph_offset(&self) -> &GlyphOffset {
|
||||
&self.glyph_offset
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
|
@ -1307,7 +1336,8 @@ impl Default for Font {
|
|||
italic: FontDescription::new_with_family("Menlo"),
|
||||
size: Size::new(11.0),
|
||||
use_thin_strokes: true,
|
||||
offset: Default::default()
|
||||
offset: Default::default(),
|
||||
glyph_offset: Default::default()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1321,7 +1351,8 @@ impl Default for Font {
|
|||
italic: FontDescription::new_with_family("monospace"),
|
||||
size: Size::new(11.0),
|
||||
use_thin_strokes: false,
|
||||
offset: Default::default()
|
||||
offset: Default::default(),
|
||||
glyph_offset: Default::default()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ use gl;
|
|||
use index::{Line, Column, RangeInclusive};
|
||||
use notify::{Watcher as WatcherApi, RecommendedWatcher as Watcher, op};
|
||||
|
||||
use config::Config;
|
||||
use config::{Config, GlyphOffset};
|
||||
use term::{self, cell, RenderableCell};
|
||||
use window::{Size, Pixels};
|
||||
|
||||
|
@ -154,6 +154,9 @@ pub struct GlyphCache {
|
|||
|
||||
/// font size
|
||||
font_size: font::Size,
|
||||
|
||||
/// glyph offset
|
||||
glyph_offset: GlyphOffset,
|
||||
}
|
||||
|
||||
impl GlyphCache {
|
||||
|
@ -166,6 +169,7 @@ impl GlyphCache {
|
|||
{
|
||||
let font = config.font();
|
||||
let size = font.size();
|
||||
let glyph_offset = *font.glyph_offset();
|
||||
|
||||
// Load regular font
|
||||
let regular_desc = if let Some(ref style) = font.normal.style {
|
||||
|
@ -223,6 +227,7 @@ impl GlyphCache {
|
|||
font_key: regular,
|
||||
bold_key: bold,
|
||||
italic_key: italic,
|
||||
glyph_offset: glyph_offset,
|
||||
};
|
||||
|
||||
macro_rules! load_glyphs_for_font {
|
||||
|
@ -253,9 +258,12 @@ impl GlyphCache {
|
|||
fn load_and_cache_glyph<L>(&mut self, glyph_key: GlyphKey, loader: &mut L)
|
||||
where L: LoadGlyph
|
||||
{
|
||||
let rasterized = self.rasterizer.get_glyph(&glyph_key)
|
||||
let mut rasterized = self.rasterizer.get_glyph(&glyph_key)
|
||||
.unwrap_or_else(|_| Default::default());
|
||||
|
||||
rasterized.left += self.glyph_offset.x as i32;
|
||||
rasterized.top += self.glyph_offset.y as i32;
|
||||
|
||||
let glyph = loader.load_glyph(&rasterized);
|
||||
self.cache.insert(glyph_key, glyph);
|
||||
}
|
||||
|
@ -263,12 +271,18 @@ impl GlyphCache {
|
|||
pub fn get<'a, L>(&'a mut self, glyph_key: &GlyphKey, loader: &mut L) -> &'a Glyph
|
||||
where L: LoadGlyph
|
||||
{
|
||||
let glyph_offset = self.glyph_offset;
|
||||
let rasterizer = &mut self.rasterizer;
|
||||
self.cache
|
||||
.entry(*glyph_key)
|
||||
.or_insert_with(|| {
|
||||
let rasterized = rasterizer.get_glyph(&glyph_key)
|
||||
let mut rasterized = rasterizer.get_glyph(&glyph_key)
|
||||
.unwrap_or_else(|_| Default::default());
|
||||
|
||||
// We need to apply the offset to glyphs that didn't get cached initially
|
||||
rasterized.left += glyph_offset.x as i32;
|
||||
rasterized.top += glyph_offset.y as i32;
|
||||
|
||||
loader.load_glyph(&rasterized)
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue