Skip to content

Commit

Permalink
Keep the unbreakables from being chopped off
Browse files Browse the repository at this point in the history
  • Loading branch information
baskerville committed Apr 20, 2022
1 parent 670f428 commit 0f7fdea
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
12 changes: 7 additions & 5 deletions src/document/html/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ use super::layout::{WordSpacing, ListStyleType, LineStats};
use super::layout::{hyph_lang, collapse_margins, DEFAULT_HYPH_LANG, HYPHENATION_PATTERNS};
use super::layout::{EM_SPACE_RATIOS, WORD_SPACE_RATIOS, FONT_SPACES};
use super::style::{StyleSheet, specified_values};
use super::xml::XmlExt;

const DEFAULT_DPI: u16 = 300;
const DEFAULT_WIDTH: u32 = 1404;
Expand Down Expand Up @@ -875,8 +876,8 @@ impl Engine {
}
});

if !parent_style.retain_whitespace && (c == ' ' || c.is_control()) &&
(last_c.map(|c| c == ' ' || c.is_control()) == Some(true)) {
if !parent_style.retain_whitespace && c.is_xml_whitespace() &&
(last_c.map(|c| c.is_xml_whitespace()) == Some(true)) {
start_index += chunk.len();
continue;
}
Expand All @@ -897,12 +898,13 @@ impl Engine {
WordSpacing::Ratio(r) => (r * width as f32) as i32,
} + style.letter_spacing;

if parent_style.retain_whitespace && last_c == Some('\n') {
let is_unbreakable = c == '\u{00A0}' || c == '\u{202F}' || c == '\u{2007}';

if (is_unbreakable || (parent_style.retain_whitespace && c.is_xml_whitespace())) &&
(last_c == Some('\n') || last_c.is_none()) {
items.push(ParagraphItem::Box { width: 0, data: ParagraphElement::Nothing });
}

let is_unbreakable = c == '\u{00A0}' || c == '\u{202F}' || c == '\u{2007}';

if is_unbreakable {
items.push(ParagraphItem::Penalty { width: 0, penalty: INFINITE_PENALTY, flagged: false });
}
Expand Down
2 changes: 1 addition & 1 deletion src/document/html/xml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ impl<'a> XmlParser<'a> {
}
}

trait XmlExt {
pub trait XmlExt {
fn is_xml_whitespace(&self) -> bool;
}

Expand Down

0 comments on commit 0f7fdea

Please sign in to comment.