Files
texrra-engine/crates/texrra-tex-core/src/execution/marks.rs
T

53 lines
1.8 KiB
Rust

//! Marks and adjustments which migrate into the enclosing vertical list.
use super::*;
use std::sync::Arc;
#[derive(Clone, Debug, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
pub struct NativeMark {
pub class: u16,
pub tokens: Arc<[Token]>,
pub span: Span,
}
#[derive(Clone, Debug, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
pub struct NativeAdjustment {
pub pre: bool,
pub nodes: Vec<NativeVerticalNode>,
}
#[derive(Clone, Debug, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
pub struct SplitMarks {
pub first: Arc<[Token]>,
pub bottom: Arc<[Token]>,
}
#[derive(Clone, Debug, Default, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
pub struct PageMarks {
pub top: Option<Arc<[Token]>>,
pub first: Option<Arc<[Token]>>,
pub bottom: Option<Arc<[Token]>>,
}
#[derive(Default)]
#[derive(Clone)]
pub(super) struct MigratingMaterial {
pub pre: Vec<NativeVerticalNode>,
pub post: Vec<NativeVerticalNode>,
}
/// Only top-level adjustment and mark nodes migrate during hpack. A packed
/// child remains an owner until it is explicitly unboxed.
pub(super) fn extract(nodes: Vec<TextNode>) -> (Vec<TextNode>, MigratingMaterial) {
let mut content = Vec::with_capacity(nodes.len());
let mut adjustments = MigratingMaterial::default();
for node in nodes {
match node {
TextNode::Mark(mark) => adjustments.post.push(NativeVerticalNode::Mark(mark)),
TextNode::Insertion(n) => adjustments.post.push(NativeVerticalNode::Insertion(n)),
TextNode::Adjustment(value) if value.pre => adjustments.pre.extend(value.nodes),
TextNode::Adjustment(value) => adjustments.post.extend(value.nodes),
other => content.push(other),
}
}
(content, adjustments)
}