Fix rendering, draw curved underline

This commit is contained in:
daa84 2017-09-12 12:56:40 +03:00
parent 8b15361a84
commit 61fdb83427
5 changed files with 25 additions and 19 deletions

View File

@ -3,7 +3,7 @@ environment:
PROJECT_NAME: rustfmt
matrix:
- TARGET: x86_64-pc-windows-gnu
RUST_VERSION: 1.18.0
RUST_VERSION: 1.20.0
install:
# - ps: Start-FileDownload "https://static.rust-lang.org/dist/channel-rust-stable"

View File

@ -81,12 +81,18 @@ pub fn render(
// TODO: properly draw undercurl
let sp = color_model.actual_cell_sp(cell);
ctx.set_source_rgba(sp.0, sp.1, sp.2, 0.7);
ctx.set_dash(&[4.0, 2.0], 0.0);
ctx.set_line_width(underline_thickness);
ctx.move_to(line_x, line_y + underline_position);
ctx.line_to(line_x + char_width, line_y + underline_position);
ctx.stroke();
ctx.set_dash(&[], 0.0);
ctx.show_error_underline(
line_x,
line_y + underline_position,
char_width,
underline_thickness * 5.0,
);
//ctx.set_dash(&[4.0, 2.0], 0.0);
//ctx.set_line_width(underline_thickness);
//ctx.move_to(line_x, line_y + underline_position);
//ctx.line_to(line_x + char_width, line_y + underline_position);
//ctx.stroke();
//ctx.set_dash(&[], 0.0);
} else if cell.attrs.underline {
ctx.set_source_rgb(fg.0, fg.1, fg.2);
ctx.set_line_width(underline_thickness);

View File

@ -41,8 +41,4 @@ impl Item {
pub fn offset(&self) -> (usize, usize, usize) {
(self.0.offset as usize, self.0.length as usize, self.0.num_chars as usize)
}
pub fn length(&self) -> i32 {
self.0.length
}
}

View File

@ -69,11 +69,10 @@ impl Line {
fn set_cell_to_item(&mut self, new_item: &PangoItemPosition) -> bool {
let start_item_idx = self.cell_to_item(new_item.start_cell);
let start_item_len = if start_item_idx >= 0 {
let start_item_cells_count = if start_item_idx >= 0 {
self.item_line[start_item_idx as usize]
.as_ref()
.map(|item| item.item.length())
.unwrap_or(-1)
.map_or(-1, |item| item.cells_count as i32)
} else {
-1
};
@ -84,7 +83,7 @@ impl Line {
// in case different item length was in previous iteration
// mark all item as dirty
if start_item_idx != new_item.start_cell as i32 ||
new_item.item.length() != start_item_len || start_item_idx == -1 ||
new_item.cells_count() != start_item_cells_count || start_item_idx == -1 ||
end_item_idx == -1
{
self.initialize_cell_item(new_item.start_cell, new_item.end_cell, new_item.item);
@ -237,6 +236,11 @@ impl<'a> PangoItemPosition<'a> {
end_cell,
}
}
#[inline]
fn cells_count(&self) -> i32 {
(self.end_cell - self.start_cell) as i32 + 1
}
}
pub struct StyledLine {