Expose stored left and right margin kerns from native boxes
This commit is contained in:
1 parent
432c1d2ba7
commit
d46d6d79a8
9 files changed
+104
-31
No files matched your search
@@ -896,6 +896,22 @@ impl Executor {
|
||||
let number = self.pdf_page_reference(files)?;
|
||||
self.print_tokens(&number.to_string(), token)?;
|
||||
}
|
||||
Leftmarginkern | Rightmarginkern => {
|
||||
let register = self.register_index(files)?;
|
||||
self.reads.insert(Dependency::BoxRegister(register));
|
||||
let Some(NativeBox { content: BoxContent::Horizontal(nodes), .. }) =
|
||||
self.state.box_register(register)
|
||||
else {
|
||||
return self.fail("margin kern requires a non-void horizontal box");
|
||||
};
|
||||
let width = paragraph::stored_margin_kern(nodes, primitive == Rightmarginkern);
|
||||
let value = if width == 0 {
|
||||
"0pt".to_owned()
|
||||
} else {
|
||||
format!("{}pt", registers::print_scaled(width))
|
||||
};
|
||||
self.print_tokens(&value, token)?;
|
||||
}
|
||||
Pdfcolorstackinit => {
|
||||
let stack = self.init_pdf_color_stack(files)?;
|
||||
self.print_tokens(&stack.to_string(), token)?;
|
||||
|
||||
@@ -8,8 +8,8 @@ use std::{
|
||||
sync::{Arc, Mutex, OnceLock, Weak},
|
||||
};
|
||||
|
||||
const SCHEMA: u32 = 38;
|
||||
const COMPATIBLE_SCHEMAS: [u32; 10] = [27, 28, 31, 32, 33, 34, 35, 36, 37, SCHEMA];
|
||||
const SCHEMA: u32 = 39;
|
||||
const COMPATIBLE_SCHEMAS: [u32; 11] = [27, 28, 31, 32, 33, 34, 35, 36, 37, 38, SCHEMA];
|
||||
const ENGINE: &str = concat!("texrra-native/", env!("CARGO_PKG_VERSION"));
|
||||
|
||||
#[derive(serde::Serialize, serde::Deserialize)]
|
||||
|
||||
@@ -6,6 +6,7 @@ use std::collections::BTreeMap;
|
||||
mod break_cache;
|
||||
mod expansion;
|
||||
mod protrusion;
|
||||
pub(super) use protrusion::stored_margin_kern;
|
||||
use break_cache::BreakNode;
|
||||
pub use break_cache::{LineBreakCache, LineBreakWork};
|
||||
|
||||
|
||||
@@ -43,32 +43,7 @@ impl Edge {
|
||||
}) if boxed.width == 0 && boxed.height == 0 && boxed.depth == 0 => Self::Skip,
|
||||
_ => Self::Solid,
|
||||
},
|
||||
TextNode::Language(_)
|
||||
| TextNode::Mark(_)
|
||||
| TextNode::Adjustment(_)
|
||||
| TextNode::Insertion(_)
|
||||
| TextNode::Penalty(_)
|
||||
| TextNode::Indent(0)
|
||||
| TextNode::AccentKern(0)
|
||||
| TextNode::MathBoundary { width: 0, .. }
|
||||
| TextNode::Kern {
|
||||
explicit: false, ..
|
||||
}
|
||||
| TextNode::Kern { width: 0, .. } => Self::Skip,
|
||||
TextNode::Output(node) if node.dimensions().is_none() => Self::Skip,
|
||||
TextNode::Glue(glue)
|
||||
| TextNode::NamedGlue(glue, _)
|
||||
| TextNode::Leaders(LeaderGlue { glue, .. })
|
||||
if glue.canonical_zero =>
|
||||
{
|
||||
Self::Skip
|
||||
}
|
||||
TextNode::Discretionary {
|
||||
pre_break,
|
||||
post_break,
|
||||
replacement_count: 0,
|
||||
..
|
||||
} if pre_break.is_empty() && post_break.is_empty() => Self::Skip,
|
||||
_ if skippable(node) => Self::Skip,
|
||||
_ => Self::character(node),
|
||||
}
|
||||
}
|
||||
@@ -107,6 +82,58 @@ impl Edge {
|
||||
}
|
||||
}
|
||||
|
||||
fn skippable(node: &TextNode) -> bool {
|
||||
match node {
|
||||
TextNode::Box(boxed) => matches!(
|
||||
boxed.native_box.as_deref(),
|
||||
Some(NativeBox { content: BoxContent::Horizontal(nodes), .. })
|
||||
if nodes.is_empty() && boxed.width == 0 && boxed.height == 0 && boxed.depth == 0
|
||||
),
|
||||
TextNode::Language(_)
|
||||
| TextNode::Mark(_)
|
||||
| TextNode::Adjustment(_)
|
||||
| TextNode::Insertion(_)
|
||||
| TextNode::Penalty(_)
|
||||
| TextNode::Indent(0)
|
||||
| TextNode::AccentKern(0)
|
||||
| TextNode::MathBoundary { width: 0, .. }
|
||||
| TextNode::Kern { explicit: false, .. }
|
||||
| TextNode::Kern { width: 0, .. } => true,
|
||||
TextNode::Output(node) => node.dimensions().is_none(),
|
||||
TextNode::Glue(glue)
|
||||
| TextNode::NamedGlue(glue, _)
|
||||
| TextNode::Leaders(LeaderGlue { glue, .. }) => glue.canonical_zero,
|
||||
TextNode::Discretionary {
|
||||
pre_break,
|
||||
post_break,
|
||||
replacement_count: 0,
|
||||
..
|
||||
} => pre_break.is_empty() && post_break.is_empty(),
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
pub(in crate::execution) fn stored_margin_kern(nodes: &[TextNode], right: bool) -> i32 {
|
||||
let side_skip = if right { Parameter::Rightskip } else { Parameter::Leftskip };
|
||||
let non_skippable = |node: &&TextNode| {
|
||||
!matches!(node, TextNode::NamedGlue(_, parameter) if *parameter == side_skip)
|
||||
&& !skippable(node)
|
||||
};
|
||||
// The query walks only the stored hlist. It does not descend into a nested
|
||||
// box or recalculate protrusion using the current font codes.
|
||||
let edge = if right {
|
||||
nodes.iter().rev().find(non_skippable)
|
||||
} else {
|
||||
nodes.iter().find(non_skippable)
|
||||
};
|
||||
match edge {
|
||||
Some(TextNode::MarginKern { width, right: actual_side, .. }) if *actual_side == right => {
|
||||
*width
|
||||
}
|
||||
_ => 0,
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn margin_kern(
|
||||
state: &State,
|
||||
nodes: &[TextNode],
|
||||
|
||||
@@ -329,6 +329,8 @@ pub enum Primitive {
|
||||
Pdfpageref,
|
||||
Partokenname,
|
||||
Pdfliteral,
|
||||
Leftmarginkern,
|
||||
Rightmarginkern,
|
||||
}
|
||||
|
||||
impl Primitive {
|
||||
@@ -384,6 +386,8 @@ impl Primitive {
|
||||
| Pdfuniformdeviate
|
||||
| Pdfnormaldeviate
|
||||
| Pdfpageref
|
||||
| Leftmarginkern
|
||||
| Rightmarginkern
|
||||
| Pdfcolorstackinit
|
||||
| Csname
|
||||
| Unless
|
||||
@@ -972,6 +976,8 @@ impl Default for State {
|
||||
("pdfpageref", Pdfpageref),
|
||||
("partokenname", Partokenname),
|
||||
("pdfliteral", Pdfliteral),
|
||||
("leftmarginkern", Leftmarginkern),
|
||||
("rightmarginkern", Rightmarginkern),
|
||||
("pdfcolorstack", Pdfcolorstack),
|
||||
("pdfsave", Pdfsave),
|
||||
("pdfstartlink", Pdfstartlink),
|
||||
|
||||
Reference in new issue
Block a user