mirror of
https://github.com/wez/wezterm.git
synced 2024-11-26 08:25:50 +03:00
fixup bearing_x handling and unicode width
Trigger x-scaling based on the x_advance rather than the bitmap width. Also account for the unicode width of the fragment when scaling. The use of bearing_x was incorrect; we were subtracting it rather than adding it and making the glyphs look terrible at smaller sizes.
This commit is contained in:
parent
a5535d4c5b
commit
611e4b3505
@ -6,8 +6,15 @@ version = "0.1.0"
|
||||
[dependencies]
|
||||
failure = "0.1.1"
|
||||
hexdump = "0.1.0"
|
||||
sdl2 = {version="0.31.0", features=["bundled", "static-link"]}
|
||||
unicode-width = "0.1.4"
|
||||
vte = "0.3.2"
|
||||
|
||||
[dependencies.font]
|
||||
path = "font"
|
||||
|
||||
[dependencies.sdl2]
|
||||
features = [
|
||||
"bundled",
|
||||
"static-link",
|
||||
]
|
||||
version = "0.31.0"
|
||||
|
@ -87,13 +87,9 @@ impl Face {
|
||||
FT_Load_Glyph(self.face, glyph_pos, FT_LOAD_COLOR as i32);
|
||||
if res.succeeded() {
|
||||
let glyph = &(*(*self.face).glyph);
|
||||
// FIXME: I don't like this +1, but without it
|
||||
// we can end up with a width 1 pixel too small
|
||||
width = width.max(
|
||||
((glyph.metrics.horiAdvance as f64) /
|
||||
64f64)
|
||||
.ceil() as i64 + 1,
|
||||
);
|
||||
width = width.max(((glyph.metrics.horiAdvance as f64) /
|
||||
64f64)
|
||||
.ceil() as i64);
|
||||
}
|
||||
}
|
||||
(width, height)
|
||||
|
36
src/main.rs
36
src/main.rs
@ -1,6 +1,9 @@
|
||||
#[macro_use]
|
||||
extern crate failure;
|
||||
extern crate hexdump;
|
||||
extern crate unicode_width;
|
||||
|
||||
use unicode_width::UnicodeWidthStr;
|
||||
|
||||
use failure::Error;
|
||||
extern crate font;
|
||||
@ -134,20 +137,23 @@ impl<'a> Glyph<'a> {
|
||||
let mut bearing_x = glyph.bitmap_left;
|
||||
let mut bearing_y = glyph.bitmap_top;
|
||||
|
||||
let scale = if height as i64 > target_cell_height {
|
||||
target_cell_height as f64 / height as f64
|
||||
} else if (width / info.text.chars().count() as u32) as i64 >
|
||||
target_cell_width
|
||||
let uc_width = UnicodeWidthStr::width(info.text.as_str());
|
||||
|
||||
let scale = if (info.x_advance / uc_width as i32) as i64 >
|
||||
target_cell_width
|
||||
{
|
||||
target_cell_width as f64 / width as f64
|
||||
uc_width as f64 * (target_cell_width as f64 / info.x_advance as f64)
|
||||
} else if height as i64 > target_cell_height {
|
||||
target_cell_height as f64 / height as f64
|
||||
} else {
|
||||
1.0f64
|
||||
};
|
||||
|
||||
if scale != 1.0f64 {
|
||||
println!(
|
||||
"scaling {:?} w={} {}, h={} {} by {}",
|
||||
"scaling {:?} uc_width={} w={} {}, h={} {} by {}",
|
||||
info,
|
||||
uc_width,
|
||||
width,
|
||||
target_cell_width,
|
||||
height,
|
||||
@ -206,8 +212,10 @@ impl FontHolder {
|
||||
ftwrap::FT_LcdFilter::FT_LCD_FILTER_DEFAULT,
|
||||
)?;
|
||||
|
||||
let mut pattern = fcwrap::Pattern::new()?;
|
||||
pattern.family("Operator Mono SSm Lig")?;
|
||||
let mut pattern = fcwrap::Pattern::parse(
|
||||
"Operator Mono SSm:size=12:weight=SemiLight",
|
||||
)?;
|
||||
//pattern.family("Operator Mono SSm")?;
|
||||
pattern.monospace()?;
|
||||
pattern.config_substitute(fcwrap::MatchKind::Pattern)?;
|
||||
pattern.default_substitute();
|
||||
@ -432,7 +440,7 @@ fn glyphs_for_text<'a, T>(
|
||||
s: &str,
|
||||
) -> Result<Vec<Glyph<'a>>, Error> {
|
||||
|
||||
let mut font_holder = FontHolder::new(16)?;
|
||||
let mut font_holder = FontHolder::new(12)?;
|
||||
|
||||
// We always load the cell_height for font 0,
|
||||
// regardless of which font we are shaping here,
|
||||
@ -468,8 +476,10 @@ fn run() -> Result<(), Error> {
|
||||
.build()?;
|
||||
let mut canvas = window.into_canvas().build()?;
|
||||
let texture_creator = canvas.texture_creator();
|
||||
let mut glyphs =
|
||||
glyphs_for_text(&texture_creator, "!= foo->bar(); ❤ 😍🤢")?;
|
||||
let mut glyphs = glyphs_for_text(
|
||||
&texture_creator,
|
||||
"x_advance != foo->bar(); ❤ 😍🤢",
|
||||
)?;
|
||||
|
||||
for event in sdl_context
|
||||
.event_pump()
|
||||
@ -500,8 +510,8 @@ fn run() -> Result<(), Error> {
|
||||
&tex,
|
||||
None,
|
||||
Some(Rect::new(
|
||||
x + g.info.x_offset - g.bearing_x,
|
||||
y - (g.info.y_offset + g.bearing_y as i32) as i32,
|
||||
x + g.info.x_offset + g.bearing_x,
|
||||
y - g.info.y_offset - g.bearing_y ,
|
||||
g.width,
|
||||
g.height,
|
||||
)),
|
||||
|
Loading…
Reference in New Issue
Block a user