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

351 lines
9.0 KiB
Rust

//! Owned paragraph parameter meanings and TeX INITEX defaults.
use super::{Flex, Glue, RegisterKind, RegisterValue};
#[derive(
Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, serde::Serialize, serde::Deserialize,
)]
pub enum Parameter {
Pdfoutput,
Pdfmajorversion,
Pdfminorversion,
Pdfobjcompresslevel,
Pdfcompresslevel,
Pdfdecimaldigits,
Pdfpkresolution,
Pdfimageresolution,
Pdfgentounicode,
Pdfinfoomitdate,
Tracingcommands,
Tracingrestores,
Tracingassigns,
Tracingmacros,
Tracingoutput,
Tracingstats,
Tracingpages,
Tracingparagraphs,
Tracinggroups,
Tracingifs,
Tracingscantokens,
Tracingnesting,
Mag,
Hoffset,
Voffset,
Pdfpagewidth,
Pdfpageheight,
Pdfhorigin,
Pdfvorigin,
Pdflinkmargin,
Errorcontextlines,
Showboxbreadth,
Showboxdepth,
Delimiterfactor,
Delimitershortfall,
Defaultskewchar,
Tracinglostchars,
Tracingonline,
Displaywidowpenalty,
Predisplaypenalty,
Postdisplaypenalty,
Abovedisplayskip,
Belowdisplayskip,
Abovedisplayshortskip,
Belowdisplayshortskip,
Predisplaysize,
Displaywidth,
Displayindent,
Interlinepenalty,
Clubpenalty,
Widowpenalty,
Brokenpenalty,
Binoppenalty,
Relpenalty,
Fam,
Scriptspace,
Nulldelimiterspace,
Mathsurround,
Thinmuskip,
Medmuskip,
Thickmuskip,
Pretolerance,
Tolerance,
Hbadness,
Vbadness,
Vfuzz,
Hfuzz,
Overfullrule,
Boxmaxdepth,
Splitmaxdepth,
Splittopskip,
Maxdepth,
Vsize,
Topskip,
Maxdeadcycles,
Outputpenalty,
Floatingpenalty,
Holdinginserts,
Savingvdiscards,
Linepenalty,
Hyphenpenalty,
Exhyphenpenalty,
Doublehyphendemerits,
Finalhyphendemerits,
Adjdemerits,
Looseness,
Hangafter,
Lefthyphenmin,
Righthyphenmin,
Uchyph,
Language,
Defaulthyphenchar,
Hsize,
Parindent,
Hangindent,
Emergencystretch,
Lineskiplimit,
Leftskip,
Rightskip,
Parfillskip,
Spaceskip,
Xspaceskip,
Parskip,
Baselineskip,
Lineskip,
Tabskip,
Pdfprotrudechars,
Pdfadjustspacing,
Partokencontext,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
pub enum ParameterValue {
Integer(i32),
Quantity(RegisterValue),
}
impl Parameter {
pub const ALL: &'static [Self] = &[
Self::Pdfoutput,
Self::Pdfmajorversion,
Self::Pdfminorversion,
Self::Pdfobjcompresslevel,
Self::Pdfcompresslevel,
Self::Pdfdecimaldigits,
Self::Pdfpkresolution,
Self::Pdfimageresolution,
Self::Pdfgentounicode,
Self::Pdfinfoomitdate,
Self::Tracingcommands,
Self::Tracingrestores,
Self::Tracingassigns,
Self::Tracingmacros,
Self::Tracingoutput,
Self::Tracingstats,
Self::Tracingpages,
Self::Tracingparagraphs,
Self::Tracinggroups,
Self::Tracingifs,
Self::Tracingscantokens,
Self::Tracingnesting,
Self::Mag,
Self::Hoffset,
Self::Voffset,
Self::Pdfpagewidth,
Self::Pdfpageheight,
Self::Pdfhorigin,
Self::Pdfvorigin,
Self::Pdflinkmargin,
Self::Errorcontextlines,
Self::Showboxbreadth,
Self::Showboxdepth,
Self::Delimiterfactor,
Self::Delimitershortfall,
Self::Defaultskewchar,
Self::Tracinglostchars,
Self::Tracingonline,
Self::Displaywidowpenalty,
Self::Predisplaypenalty,
Self::Postdisplaypenalty,
Self::Abovedisplayskip,
Self::Belowdisplayskip,
Self::Abovedisplayshortskip,
Self::Belowdisplayshortskip,
Self::Predisplaysize,
Self::Displaywidth,
Self::Displayindent,
Self::Interlinepenalty,
Self::Clubpenalty,
Self::Widowpenalty,
Self::Brokenpenalty,
Self::Binoppenalty,
Self::Relpenalty,
Self::Fam,
Self::Scriptspace,
Self::Nulldelimiterspace,
Self::Mathsurround,
Self::Thinmuskip,
Self::Medmuskip,
Self::Thickmuskip,
Self::Pretolerance,
Self::Tolerance,
Self::Hbadness,
Self::Vbadness,
Self::Vfuzz,
Self::Hfuzz,
Self::Overfullrule,
Self::Boxmaxdepth,
Self::Splitmaxdepth,
Self::Splittopskip,
Self::Maxdepth,
Self::Vsize,
Self::Topskip,
Self::Maxdeadcycles,
Self::Outputpenalty,
Self::Floatingpenalty,
Self::Holdinginserts,
Self::Savingvdiscards,
Self::Linepenalty,
Self::Hyphenpenalty,
Self::Exhyphenpenalty,
Self::Doublehyphendemerits,
Self::Finalhyphendemerits,
Self::Adjdemerits,
Self::Looseness,
Self::Hangafter,
Self::Lefthyphenmin,
Self::Righthyphenmin,
Self::Uchyph,
Self::Language,
Self::Defaulthyphenchar,
Self::Hsize,
Self::Parindent,
Self::Hangindent,
Self::Emergencystretch,
Self::Lineskiplimit,
Self::Leftskip,
Self::Rightskip,
Self::Parfillskip,
Self::Spaceskip,
Self::Xspaceskip,
Self::Parskip,
Self::Baselineskip,
Self::Lineskip,
Self::Tabskip,
Self::Pdfprotrudechars,
Self::Pdfadjustspacing,
Self::Partokencontext,
];
pub fn name(self) -> String {
format!("{self:?}").to_ascii_lowercase()
}
pub fn kind(self) -> Option<RegisterKind> {
match self {
Self::Thinmuskip | Self::Medmuskip | Self::Thickmuskip => Some(RegisterKind::Muskip),
Self::Hoffset
| Self::Voffset
| Self::Pdfpagewidth
| Self::Pdfpageheight
| Self::Pdfhorigin
| Self::Pdfvorigin
| Self::Pdflinkmargin
| Self::Delimitershortfall
| Self::Predisplaysize
| Self::Displaywidth
| Self::Displayindent
| Self::Scriptspace
| Self::Nulldelimiterspace
| Self::Mathsurround
| Self::Vfuzz
| Self::Hfuzz
| Self::Overfullrule
| Self::Boxmaxdepth
| Self::Splitmaxdepth
| Self::Maxdepth
| Self::Vsize
| Self::Hsize
| Self::Parindent
| Self::Hangindent
| Self::Emergencystretch
| Self::Lineskiplimit => Some(RegisterKind::Dimen),
Self::Abovedisplayskip
| Self::Belowdisplayskip
| Self::Abovedisplayshortskip
| Self::Belowdisplayshortskip
| Self::Leftskip
| Self::Rightskip
| Self::Parfillskip
| Self::Spaceskip
| Self::Xspaceskip
| Self::Parskip
| Self::Baselineskip
| Self::Splittopskip
| Self::Topskip
| Self::Lineskip
| Self::Tabskip => Some(RegisterKind::Skip),
_ => None,
}
}
pub fn initial(self) -> ParameterValue {
if let Some(kind) = self.kind() {
ParameterValue::Quantity(if kind == RegisterKind::Dimen {
RegisterValue::Dimension(if matches!(self, Self::Pdfhorigin | Self::Pdfvorigin) {
4_736_287
} else {
0
})
} else {
RegisterValue::Glue(Glue::default())
})
} else {
ParameterValue::Integer(match self {
Self::Pdfmajorversion => 1,
Self::Pdfminorversion => 4,
Self::Pdfcompresslevel => 9,
Self::Pdfdecimaldigits => 3,
Self::Mag => 1000,
Self::Tolerance => 10000,
Self::Hangafter => 1,
Self::Maxdeadcycles => 25,
_ => 0,
})
}
}
}
impl ParameterValue {
pub fn text(self) -> String {
match self {
Self::Integer(n) => n.to_string(),
Self::Quantity(q) => q.text(false),
}
}
pub fn width(self) -> i32 {
match self {
Self::Integer(n) => n,
Self::Quantity(q) => q.width(),
}
}
pub fn glue(self) -> Glue {
match self {
Self::Quantity(RegisterValue::Glue(g)) => g,
_ => unreachable!("typed parameter access"),
}
}
pub fn dimension(n: i32) -> Self {
Self::Quantity(RegisterValue::Dimension(n))
}
pub fn skip(n: i32) -> Self {
Self::Quantity(RegisterValue::Glue(Glue {
canonical_zero: n == 0,
width: n,
..Glue::default()
}))
}
pub fn fill() -> Self {
Self::Quantity(RegisterValue::Glue(Glue {
canonical_zero: false,
stretch: Flex {
amount: 65536,
order: 1,
},
..Glue::default()
}))
}
}