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

519 lines
15 KiB
Rust

//! Owned paragraph parameter meanings and TeX INITEX defaults.
use super::{Flex, Glue, RegisterKind, RegisterValue};
pub(super) const IGNORE_DEPTH: i32 = -1000 * 65536;
#[derive(
Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, serde::Serialize, serde::Deserialize,
)]
pub enum Parameter {
Pdfoutput,
Pdfmajorversion,
Pdfminorversion,
Pdfobjcompresslevel,
Pdfcompresslevel,
Pdfdecimaldigits,
Pdfpkresolution,
Pdfimageresolution,
Pdfinclusioncopyfonts,
Pdfgentounicode,
Pdfsuppresswarningdupmap,
Pdfsuppresswarningdupdest,
Pdfinfoomitdate,
Pdfomitcharset,
Pdfomitinfodict,
Pdfomitprocset,
Pdfinclusionerrorlevel,
Pdfoptionpdfinclusionerrorlevel,
Pdfpagebox,
Pdfforcepagebox,
Pdfoptionalwaysusepdfpagebox,
Tracingcommands,
Tracingrestores,
Tracingassigns,
Tracingmacros,
Tracingoutput,
Tracingstats,
Tracingpages,
Tracingparagraphs,
Tracinggroups,
Tracingifs,
Tracingscantokens,
Tracingnesting,
Mag,
Hoffset,
Voffset,
Pdfpagewidth,
Pdfpageheight,
Pdfhorigin,
Pdfvorigin,
Pdflinkmargin,
Pdfdestmargin,
Pdfthreadmargin,
Errorcontextlines,
Showboxbreadth,
Showboxdepth,
Delimiterfactor,
Delimitershortfall,
Defaultskewchar,
Tracinglostchars,
Tracingonline,
Showstream,
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,
Pdfprependkern,
Pdfappendkern,
Pdfadjustspacing,
Partokencontext,
XeTeXuseglyphmetrics,
XeTeXdashbreakstate,
Suppressfontnotfounderror,
TeXXeTstate,
XeTeXinterchartokenstate,
XeTeXprotrudechars,
XeTeXhyphenatablelength,
XeTeXgenerateactualtext,
XeTeXinterwordspaceshaping,
XeTeXlinebreakskip,
XeTeXlinebreakpenalty,
XeTeXinputnormalization,
Pdfdraftmode,
Pdfsuppressptexinfo,
Pdfptexuseunderscore,
Ignoreprimitiveerror,
Lastlinefit,
Savinghyphcodes,
Pdfignoreddimen,
Pdfeachlineheight,
Pdfeachlinedepth,
Pdffirstlineheight,
Pdflastlinedepth,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
pub enum ParameterValue {
Integer(i32),
Quantity(RegisterValue),
}
impl Parameter {
pub(super) const PDF_LINE_DIMENSIONS: [Self; 5] = [
Self::Pdfignoreddimen,
Self::Pdfeachlineheight,
Self::Pdfeachlinedepth,
Self::Pdffirstlineheight,
Self::Pdflastlinedepth,
];
pub(super) fn pdftex_only(self) -> bool {
matches!(
self,
Self::Pdfoutput
| Self::Pdfmajorversion
| Self::Pdfminorversion
| Self::Pdfobjcompresslevel
| Self::Pdfcompresslevel
| Self::Pdfdraftmode
| Self::Pdfsuppressptexinfo
| Self::Pdfptexuseunderscore
| Self::Pdfdecimaldigits
| Self::Pdfpkresolution
| Self::Pdfimageresolution
| Self::Pdfinclusioncopyfonts
| Self::Pdfgentounicode
| Self::Pdfsuppresswarningdupmap
| Self::Pdfsuppresswarningdupdest
| Self::Pdfinfoomitdate
| Self::Pdfomitcharset
| Self::Pdfomitinfodict
| Self::Pdfomitprocset
| Self::Pdfinclusionerrorlevel
| Self::Pdfoptionpdfinclusionerrorlevel
| Self::Pdfpagebox
| Self::Pdfforcepagebox
| Self::Pdfoptionalwaysusepdfpagebox
| Self::Pdfhorigin
| Self::Pdfvorigin
| Self::Pdflinkmargin
| Self::Pdfdestmargin
| Self::Pdfthreadmargin
| Self::Pdfprotrudechars
| Self::Pdfprependkern
| Self::Pdfappendkern
| Self::Pdfadjustspacing
| Self::Pdfignoreddimen
| Self::Pdfeachlineheight
| Self::Pdfeachlinedepth
| Self::Pdffirstlineheight
| Self::Pdflastlinedepth
)
}
pub(super) const XETEX: [Self; 11] = [
Self::XeTeXuseglyphmetrics,
Self::XeTeXdashbreakstate,
Self::Suppressfontnotfounderror,
Self::XeTeXinterchartokenstate,
Self::XeTeXprotrudechars,
Self::XeTeXhyphenatablelength,
Self::XeTeXgenerateactualtext,
Self::XeTeXinterwordspaceshaping,
Self::XeTeXlinebreakskip,
Self::XeTeXlinebreakpenalty,
Self::XeTeXinputnormalization,
];
pub const ALL: &'static [Self] = &[
Self::Pdfoutput,
Self::Pdfmajorversion,
Self::Pdfminorversion,
Self::Pdfobjcompresslevel,
Self::Pdfcompresslevel,
Self::Pdfdraftmode,
Self::Pdfsuppressptexinfo,
Self::Pdfptexuseunderscore,
Self::Pdfdecimaldigits,
Self::Pdfpkresolution,
Self::Pdfimageresolution,
Self::Pdfinclusioncopyfonts,
Self::Pdfgentounicode,
Self::Pdfsuppresswarningdupmap,
Self::Pdfsuppresswarningdupdest,
Self::Pdfinfoomitdate,
Self::Pdfomitcharset,
Self::Pdfomitinfodict,
Self::Pdfomitprocset,
Self::Pdfinclusionerrorlevel,
Self::Pdfoptionpdfinclusionerrorlevel,
Self::Pdfpagebox,
Self::Pdfforcepagebox,
Self::Pdfoptionalwaysusepdfpagebox,
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::Pdfdestmargin,
Self::Pdfthreadmargin,
Self::Errorcontextlines,
Self::Showboxbreadth,
Self::Showboxdepth,
Self::Delimiterfactor,
Self::Delimitershortfall,
Self::Defaultskewchar,
Self::Tracinglostchars,
Self::Tracingonline,
Self::Showstream,
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::Ignoreprimitiveerror,
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::Pdfprependkern,
Self::Pdfappendkern,
Self::Pdfadjustspacing,
Self::Partokencontext,
Self::XeTeXuseglyphmetrics,
Self::XeTeXdashbreakstate,
Self::Suppressfontnotfounderror,
Self::TeXXeTstate,
Self::XeTeXinterchartokenstate,
Self::XeTeXprotrudechars,
Self::XeTeXhyphenatablelength,
Self::XeTeXgenerateactualtext,
Self::XeTeXinterwordspaceshaping,
Self::XeTeXlinebreakskip,
Self::XeTeXlinebreakpenalty,
Self::XeTeXinputnormalization,
Self::Lastlinefit,
Self::Savinghyphcodes,
Self::Pdfignoreddimen,
Self::Pdfeachlineheight,
Self::Pdfeachlinedepth,
Self::Pdffirstlineheight,
Self::Pdflastlinedepth,
];
pub fn name(self) -> String {
match self {
Self::XeTeXuseglyphmetrics => "XeTeXuseglyphmetrics".into(),
Self::XeTeXdashbreakstate => "XeTeXdashbreakstate".into(),
Self::TeXXeTstate => "TeXXeTstate".into(),
Self::XeTeXinterchartokenstate => "XeTeXinterchartokenstate".into(),
Self::XeTeXprotrudechars => "XeTeXprotrudechars".into(),
Self::XeTeXhyphenatablelength => "XeTeXhyphenatablelength".into(),
Self::XeTeXgenerateactualtext => "XeTeXgenerateactualtext".into(),
Self::XeTeXinterwordspaceshaping => "XeTeXinterwordspaceshaping".into(),
Self::XeTeXlinebreakskip => "XeTeXlinebreakskip".into(),
Self::XeTeXlinebreakpenalty => "XeTeXlinebreakpenalty".into(),
Self::XeTeXinputnormalization => "XeTeXinputnormalization".into(),
_ => 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::Pdfdestmargin
| Self::Pdfthreadmargin
| Self::Pdfignoreddimen
| Self::Pdfeachlineheight
| Self::Pdfeachlinedepth
| Self::Pdffirstlineheight
| Self::Pdflastlinedepth
| 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
| Self::XeTeXlinebreakskip => Some(RegisterKind::Skip),
_ => None,
}
}
pub fn initial(self) -> ParameterValue {
if let Some(kind) = self.kind() {
ParameterValue::Quantity(if kind == RegisterKind::Dimen {
RegisterValue::Dimension(match self {
Self::Pdfhorigin | Self::Pdfvorigin => 4_736_287,
p if Self::PDF_LINE_DIMENSIONS.contains(&p) => IGNORE_DEPTH,
_ => 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,
Self::Showstream => -1,
Self::XeTeXhyphenatablelength => 63,
_ => 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()
}))
}
}