Execute and render TeX--XeT direction spans in native layouts
This commit is contained in:
1 parent
a93d1bb902
commit
22e3ba993d
17 files changed
+460
-54
No files matched your search
@@ -79,6 +79,7 @@ pub enum TextNode {
|
||||
AccentKern(i32),
|
||||
AutoKern(i32),
|
||||
MarginKern { width: i32, right: bool, font: FontId, slot: u8 },
|
||||
Direction(DirectionBoundary),
|
||||
}
|
||||
#[derive(Clone, Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
|
||||
pub struct NativeParagraph {
|
||||
@@ -493,6 +494,7 @@ fn discardable(n: &TextNode) -> bool {
|
||||
| TextNode::Leaders(_)
|
||||
| TextNode::Kern { .. }
|
||||
| TextNode::MathBoundary { .. }
|
||||
| TextNode::Direction(_)
|
||||
| TextNode::Penalty(_)
|
||||
)
|
||||
}
|
||||
@@ -609,6 +611,7 @@ fn line_material(
|
||||
width: 0,
|
||||
explicit: *explicit,
|
||||
},
|
||||
TextNode::Direction(boundary) => TextNode::Direction(*boundary),
|
||||
TextNode::MathBoundary { after, .. } => TextNode::MathBoundary {
|
||||
width: 0,
|
||||
after: *after,
|
||||
@@ -735,7 +738,7 @@ fn break_lines(
|
||||
forced: false,
|
||||
})
|
||||
}
|
||||
BreakNode::Kern { explicit: true, .. } | BreakNode::MathBoundary { .. }
|
||||
BreakNode::Kern { explicit: true, .. } | BreakNode::MathBoundary { .. } | BreakNode::Direction
|
||||
if auto_breaking && matches!(projected.get(i + 1), Some(BreakNode::Glue(_))) =>
|
||||
{
|
||||
Some(Break {
|
||||
@@ -943,7 +946,7 @@ fn break_lines(
|
||||
TextNode::Discretionary { .. } => ParagraphBreakKind::Discretionary,
|
||||
TextNode::Penalty(_) => ParagraphBreakKind::Penalty,
|
||||
TextNode::Kern { .. } => ParagraphBreakKind::Kern,
|
||||
TextNode::MathBoundary { .. } => ParagraphBreakKind::Math,
|
||||
TextNode::MathBoundary { .. } | TextNode::Direction(_) => ParagraphBreakKind::Math,
|
||||
_ => ParagraphBreakKind::Glue,
|
||||
}
|
||||
},
|
||||
@@ -1068,6 +1071,7 @@ fn pack(
|
||||
keep_par_fill: bool,
|
||||
terminal_marker: bool,
|
||||
ends_in_pre_break: bool,
|
||||
direction_stack: &[super::direction::Region],
|
||||
state: &mut State,
|
||||
span: Span,
|
||||
files: &mut impl SourceProvider,
|
||||
@@ -1098,6 +1102,7 @@ fn pack(
|
||||
Parameter::Parfillskip,
|
||||
));
|
||||
}
|
||||
super::direction::close(&mut material, direction_stack);
|
||||
material.push(TextNode::NamedGlue(
|
||||
p[&Parameter::Rightskip].glue(),
|
||||
Parameter::Rightskip,
|
||||
@@ -1286,8 +1291,10 @@ pub(super) fn finish(
|
||||
let mut packed_diagnostic = Vec::new();
|
||||
let mut packed_shrinking = Vec::new();
|
||||
let mut pre_display_size = -1073741823;
|
||||
let directions = super::direction::has_directions(&b.nodes);
|
||||
let mut direction_stack = Vec::new();
|
||||
for (i, (point, bad)) in path.iter().enumerate() {
|
||||
let material = line_material(
|
||||
let mut material = line_material(
|
||||
&b.nodes,
|
||||
start,
|
||||
point.end,
|
||||
@@ -1304,6 +1311,10 @@ pub(super) fn finish(
|
||||
|| matches!(b.nodes.get(point.end), Some(TextNode::Penalty(_)))
|
||||
|| (point.pre_break.is_some() && !ends_in_pre_break);
|
||||
let keep_par_fill = i + 1 == path.len() && (i == 0 || !material.is_empty());
|
||||
if directions {
|
||||
// Keep a real breakpoint marker before the synthetic line closers.
|
||||
super::direction::line(&mut material, &mut direction_stack);
|
||||
}
|
||||
let (line, line_box, adjustments, shrinking) = pack(
|
||||
&material,
|
||||
¶meters,
|
||||
@@ -1311,6 +1322,7 @@ pub(super) fn finish(
|
||||
keep_par_fill,
|
||||
terminal_marker,
|
||||
ends_in_pre_break,
|
||||
&direction_stack,
|
||||
state,
|
||||
b.span,
|
||||
files,
|
||||
@@ -1360,7 +1372,11 @@ pub(super) fn finish(
|
||||
badness.push(*bad);
|
||||
start = point.next;
|
||||
post = point.pre_break;
|
||||
// A retained zero-tail breakpoint is already included in the line.
|
||||
while !has_post(&b.nodes, post) && start < b.nodes.len() && discardable(&b.nodes[start]) {
|
||||
if directions {
|
||||
super::direction::observe(&mut direction_stack, &b.nodes[start]);
|
||||
}
|
||||
start += 1;
|
||||
}
|
||||
}
|
||||
@@ -1445,6 +1461,7 @@ fn add_hyphens(
|
||||
.rev()
|
||||
.find(|n| match n {
|
||||
TextNode::Language(_)
|
||||
| TextNode::Direction(_)
|
||||
| TextNode::Output(_)
|
||||
| TextNode::Kern {
|
||||
explicit: false, ..
|
||||
@@ -1484,6 +1501,7 @@ fn add_hyphens(
|
||||
matches!(
|
||||
n,
|
||||
TextNode::Language(_)
|
||||
| TextNode::Direction(_)
|
||||
| TextNode::Adjustment(_)
|
||||
| TextNode::Insertion(_)
|
||||
| TextNode::Mark(_)
|
||||
|
||||
Reference in new issue
Block a user