From 35d2dd1868a12e030cd322427ad6644185b803b0 Mon Sep 17 00:00:00 2001 From: daa Date: Thu, 9 Mar 2017 15:07:19 +0300 Subject: [PATCH] Fix underline/curl rendering --- src/ui.rs | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/ui.rs b/src/ui.rs index 3ef752f..8a0fb4d 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -364,20 +364,30 @@ fn draw(ui: &Ui, ctx: &cairo::Context) { if cell.attrs.underline || cell.attrs.undercurl { // [TODO]: Current gtk-rs bindings does not provide fontmetrics access // so it is not possible to find right position for underline or undercurl position - // update_font_description(&mut desc, &cell.attrs); - // layout.get_context().unwrap().get_metrics(); - - let top_offset = line_height - 1.0; + // > update_font_description(&mut desc, &cell.attrs); + // > layout.get_context().unwrap().get_metrics(); + let top_offset = line_height - 2.0; + + let sp = if let Some(ref sp) = cell.attrs.special { + sp + } else { + &ui.sp_color + }; + + ctx.set_source_rgba(sp.0, sp.1, sp.2, 0.7); if cell.attrs.undercurl { + ctx.set_line_width(2.0); ctx.move_to(current_point.0, line_y + top_offset); ctx.line_to(current_point.0 + char_width, line_y + top_offset); } else if cell.attrs.underline { + ctx.set_line_width(1.0); ctx.move_to(current_point.0, line_y + top_offset); ctx.line_to(current_point.0 + char_width, line_y + top_offset); } + ctx.stroke(); } ctx.move_to(current_point.0 + char_width, current_point.1);