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 PROJECT_NAME: rustfmt
matrix: matrix:
- TARGET: x86_64-pc-windows-gnu - TARGET: x86_64-pc-windows-gnu
RUST_VERSION: 1.18.0 RUST_VERSION: 1.20.0
install: install:
# - ps: Start-FileDownload "https://static.rust-lang.org/dist/channel-rust-stable" # - ps: Start-FileDownload "https://static.rust-lang.org/dist/channel-rust-stable"

View File

@ -1,11 +1,11 @@
use std::str::CharIndices; use std::str::CharIndices;
pub struct ItemizeIterator <'a> { pub struct ItemizeIterator<'a> {
char_iter: CharIndices<'a>, char_iter: CharIndices<'a>,
line: &'a str, line: &'a str,
} }
impl <'a> ItemizeIterator <'a> { impl<'a> ItemizeIterator<'a> {
pub fn new(line: &'a str) -> Self { pub fn new(line: &'a str) -> Self {
ItemizeIterator { ItemizeIterator {
char_iter: line.char_indices(), char_iter: line.char_indices(),
@ -14,7 +14,7 @@ impl <'a> ItemizeIterator <'a> {
} }
} }
impl <'a> Iterator for ItemizeIterator<'a> { impl<'a> Iterator for ItemizeIterator<'a> {
type Item = (usize, usize); type Item = (usize, usize);
fn next(&mut self) -> Option<Self::Item> { fn next(&mut self) -> Option<Self::Item> {
@ -26,7 +26,7 @@ impl <'a> Iterator for ItemizeIterator<'a> {
if start_index.is_none() && !is_whitespace { if start_index.is_none() && !is_whitespace {
start_index = Some(index); start_index = Some(index);
} }
if start_index.is_some() && is_whitespace { if start_index.is_some() && is_whitespace {
break index; break index;
} }

View File

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

View File

@ -41,8 +41,4 @@ impl Item {
pub fn offset(&self) -> (usize, usize, usize) { pub fn offset(&self) -> (usize, usize, usize) {
(self.0.offset as usize, self.0.length as usize, self.0.num_chars as 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 { 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_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] self.item_line[start_item_idx as usize]
.as_ref() .as_ref()
.map(|item| item.item.length()) .map_or(-1, |item| item.cells_count as i32)
.unwrap_or(-1)
} else { } else {
-1 -1
}; };
@ -84,7 +83,7 @@ impl Line {
// in case different item length was in previous iteration // in case different item length was in previous iteration
// mark all item as dirty // mark all item as dirty
if start_item_idx != new_item.start_cell as i32 || 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 end_item_idx == -1
{ {
self.initialize_cell_item(new_item.start_cell, new_item.end_cell, new_item.item); 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, end_cell,
} }
} }
#[inline]
fn cells_count(&self) -> i32 {
(self.end_cell - self.start_cell) as i32 + 1
}
} }
pub struct StyledLine { pub struct StyledLine {