Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle cjk medicalwei #7

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/render/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ struct FontMetrix {

impl FontMetrix {
pub fn new(pango_context: pango::Context, line_space: i32) -> Self {
let font_metrics = pango_context.metrics(None, None).unwrap();
let font_metrics = pango_context
.metrics(None, Some(&pango::Language::from_string("en_US")))
.unwrap();
let font_desc = pango_context.font_description().unwrap();

FontMetrix {
Expand Down Expand Up @@ -128,18 +130,16 @@ impl CellMetrics {

let strikethrough_position =
(f64::from(font_metrics.strikethrough_position()) / f64::from(pango::SCALE)).ceil();
let strikethrough_thickness = (f64::from(font_metrics.strikethrough_thickness())
/ f64::from(pango::SCALE))
.ceil();
let strikethrough_thickness =
(f64::from(font_metrics.strikethrough_thickness()) / f64::from(pango::SCALE)).ceil();

CellMetrics {
pango_ascent: font_metrics.ascent(),
pango_descent: font_metrics.descent(),
pango_char_width: font_metrics.approximate_char_width(),
ascent,
line_height: ascent + descent + f64::from(line_space),
char_width: f64::from(font_metrics.approximate_char_width())
/ f64::from(pango::SCALE),
char_width: f64::from(font_metrics.approximate_char_width()) / f64::from(pango::SCALE),
underline_position: ascent - underline_position + underline_thickness / 2.0,
underline_thickness,
strikethrough_position: ascent - strikethrough_position + strikethrough_thickness / 2.0,
Expand Down
13 changes: 11 additions & 2 deletions src/render/itemize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ use std::str::CharIndices;
pub struct ItemizeIterator<'a> {
char_iter: CharIndices<'a>,
line: &'a str,
prev_char: Option<(usize, char)>,
}

impl<'a> ItemizeIterator<'a> {
pub fn new(line: &'a str) -> Self {
ItemizeIterator {
char_iter: line.char_indices(),
line,
prev_char: None,
}
}
}
Expand All @@ -21,13 +23,20 @@ impl<'a> Iterator for ItemizeIterator<'a> {
let mut start_index = None;

let end_index = loop {
if let Some((index, ch)) = self.char_iter.next() {
let cha = self.prev_char.or_else(|| self.char_iter.next());
self.prev_char = None;
if let Some((index, ch)) = cha {
let is_whitespace = ch.is_whitespace();
let is_ascii = ch.is_ascii();

if start_index.is_none() && !is_whitespace {
start_index = Some(index);
if !is_ascii {
break index + ch.len_utf8();
}
}
if start_index.is_some() && is_whitespace {
if start_index.is_some() && (is_whitespace || !is_ascii) {
self.prev_char = cha;
break index;
}
} else {
Expand Down