Skip to content

Commit

Permalink
Disable baseline snapping, and enable rounding to integers for scroll…
Browse files Browse the repository at this point in the history
… offsets again

The baseline snapping needs to be disabled so that the lines are
properly placed, and not snapped to pixels. While using integer based
scroll offsets greatly reduces the pressure on the Skia font cache.
  • Loading branch information
fredizzimo committed Apr 14, 2024
1 parent 18ac7a5 commit 35c412b
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/renderer/fonts/font_loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ pub struct FontPair {
impl FontPair {
fn new(key: FontKey, mut skia_font: Font) -> Option<FontPair> {
skia_font.set_subpixel(true);
skia_font.set_baseline_snap(false);
skia_font.set_hinting(font_hinting(&key.hinting));
skia_font.set_edging(font_edging(&key.edging));

Expand Down
2 changes: 1 addition & 1 deletion src/renderer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ impl Renderer {
result.font_changed = true;
}
DrawCommand::LineSpaceChanged(new_linespace) => {
self.grid_renderer.update_linespace(new_linespace as f32);
self.grid_renderer.update_linespace(new_linespace);
result.font_changed = true;
}
DrawCommand::DefaultStyleChanged(new_style) => {
Expand Down
4 changes: 2 additions & 2 deletions src/renderer/rendered_window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ impl RenderedWindow {
let scroll_offset_lines = self.scroll_animation.position.floor();
let scroll_offset = scroll_offset_lines - self.scroll_animation.position;
let scroll_offset_lines = scroll_offset_lines as isize;
let scroll_offset_pixels = scroll_offset * grid_scale.0.height;
let scroll_offset_pixels = (scroll_offset * grid_scale.0.height).round();
let line_height = grid_scale.0.height;
let mut has_transparency = false;

Expand All @@ -249,7 +249,7 @@ impl RenderedWindow {
pixel_region.top()
+ (scroll_offset_pixels
+ ((i + self.viewport_margins.top as isize) as f32
* grid_scale.0.height)) as f32,
* grid_scale.0.height)),
));
(matrix, line)
})
Expand Down

0 comments on commit 35c412b

Please sign in to comment.