Skip to content

Commit

Permalink
Merge branch 'pango_144_fix'
Browse files Browse the repository at this point in the history
  • Loading branch information
daa committed Nov 29, 2019
2 parents 4c41529 + 68c2ad3 commit 482d9c7
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 17 deletions.
20 changes: 9 additions & 11 deletions src/render/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,21 +111,19 @@ pub struct CellMetrics {

impl CellMetrics {
fn new(font_metrics: &pango::FontMetrics, line_space: i32) -> Self {
let ascent = (f64::from(font_metrics.get_ascent()) / f64::from(pango::SCALE)).ceil();
let descent = (f64::from(font_metrics.get_descent()) / f64::from(pango::SCALE)).ceil();
let underline_position = (f64::from(font_metrics.get_underline_position()) / f64::from(pango::SCALE)).ceil();
CellMetrics {
pango_ascent: font_metrics.get_ascent(),
pango_descent: font_metrics.get_descent(),
pango_char_width: font_metrics.get_approximate_digit_width(),
ascent: f64::from(font_metrics.get_ascent()) / f64::from(pango::SCALE),
line_height: f64::from(font_metrics.get_ascent() + font_metrics.get_descent())
/ f64::from(pango::SCALE)
+ f64::from(line_space),
char_width: f64::from(font_metrics.get_approximate_digit_width())
/ f64::from(pango::SCALE),
underline_position: f64::from(
font_metrics.get_ascent() - font_metrics.get_underline_position(),
) / f64::from(pango::SCALE),
underline_thickness: f64::from(font_metrics.get_underline_thickness())
pango_char_width: font_metrics.get_approximate_char_width(),
ascent,
line_height: ascent + descent + f64::from(line_space),
char_width: f64::from(font_metrics.get_approximate_char_width())
/ f64::from(pango::SCALE),
underline_position: ascent - underline_position,
underline_thickness: f64::from(font_metrics.get_underline_thickness()) / f64::from(pango::SCALE),
}
}

Expand Down
6 changes: 6 additions & 0 deletions src/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ pub fn render<C: Cursor>(
let &CellMetrics { char_width, .. } = cell_metrics;

// draw background
// disable antialiase for rectangle borders, so they will not be visible
ctx.set_antialias(cairo::Antialias::None);
for row_view in ui_model.get_clip_iterator(ctx, cell_metrics) {
let mut line_x = 0.0;

Expand All @@ -55,6 +57,7 @@ pub fn render<C: Cursor>(
line_x += char_width;
}
}
ctx.set_antialias(cairo::Antialias::Default);

// draw text
for row_view in ui_model.get_clip_iterator(ctx, cell_metrics) {
Expand Down Expand Up @@ -110,9 +113,12 @@ fn draw_cursor<C: Cursor>(
ctx.clip();

// repaint cell backgound
// disable antialiase for rectangle borders, so they will not be visible
ctx.set_antialias(cairo::Antialias::None);
ctx.set_operator(cairo::Operator::Source);
fill_background(ctx, hl, bg_alpha);
draw_cell_bg(&row_view, hl, cell, cursor_col, line_x, bg_alpha);
ctx.set_antialias(cairo::Antialias::Default);

// reapint cursor and text
ctx.set_operator(cairo::Operator::Over);
Expand Down
14 changes: 8 additions & 6 deletions src/ui_model/model_rect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,9 @@ impl ModelRect {
}

fn extend_left_right_area(&self, model: Option<&UiModel>, cell_metrics: &CellMetrics) -> (i32, i32) {
let x = self.left as i32 * cell_metrics.char_width as i32;
let x2 = (self.right + 1) as i32 * cell_metrics.char_width as i32;
// when convert to i32 area must be bigger then original f64 version
let x = (self.left as f64 * cell_metrics.char_width).floor() as i32;
let x2 = ((self.right + 1) as f64 * cell_metrics.char_width).ceil() as i32;

if model.is_none() {
return (x, x2);
Expand Down Expand Up @@ -280,11 +281,12 @@ impl ModelRect {
..
} = cell_metrics;

// when convert to i32 area must be bigger then original f64 version
(
self.left as i32 * char_width as i32,
self.top as i32 * line_height as i32,
(self.right - self.left + 1) as i32 * char_width as i32,
(self.bot - self.top + 1) as i32 * line_height as i32,
(self.left as f64 * char_width).floor() as i32,
(self.top as f64 * line_height).floor() as i32,
((self.right - self.left + 1) as f64 * char_width).ceil() as i32,
((self.bot - self.top + 1) as f64 * line_height).ceil() as i32,
)
}

Expand Down

0 comments on commit 482d9c7

Please sign in to comment.