pub struct Context {Show 29 fields
pub font: FontKey,
pub math_font: FontKey,
pub font_size: Length,
pub leading: Length,
pub paragraph_width: Length,
pub paragraph_top: Length,
pub paragraph_bottom: Length,
pub manual_rising: Length,
pub dominant_wide_script: Script,
pub dominant_narrow_script: Script,
pub langsys_scheme: [Language; 4],
pub font_scheme: [ScriptFont; 4],
pub script_space_map: [[f64; 4]; 4],
pub text_color: Color,
pub hyphen_badness: i64,
pub hyphen_dictionary: Option<HyphenLang>,
pub left_hyphen_min: i64,
pub right_hyphen_min: i64,
pub space_natural: f64,
pub space_shrink: f64,
pub space_stretch: f64,
pub adjacent_stretch: f64,
pub math_command: Option<MathCmdId>,
pub code_text_command: Option<MathCmdId>,
pub math_char_class: MathCharClass,
pub math_class_map: Arc<BTreeMap<String, (String, MathKind)>>,
pub math_variant_char_map: Arc<BTreeMap<(char, MathCharClass), char>>,
pub math_script_level: MathScriptLevel,
pub math_cramped: bool,
}Expand description
The typesetting context (a subset of context_main in horzBox.ml).
Fields§
§font: FontKey§math_font: FontKeyThe dedicated math font (v0.0.6 context_main.math_font; set-math-font).
Math layout measures/emits glyphs under THIS key, falling back to font
per-glyph when it has no glyph (see primitives::math_glyph_font). The
OpenType MATH-table lookups key on this same FontKey.
font_size: Length§leading: LengthBaseline-to-baseline distance.
paragraph_width: LengthWrap width for paragraphs.
paragraph_top: LengthExtra vertical skip inserted above a paragraph
(set-paragraph-margin’s first argument; v0.0.6
context_main.paragraph_top, horzBox.ml:227). Emitted by
prim_line_break as a leading VertBox::Skip. A skip at the
very top of a page/column is discarded by chop_page (upstream’s
page-top glue suppression), so this adds no space above a page’s first
paragraph.
paragraph_bottom: LengthExtra vertical skip inserted below a paragraph
(set-paragraph-margin’s second argument; v0.0.6
context_main.paragraph_bottom, horzBox.ml:228) — a trailing
VertBox::Skip.
manual_rising: LengthA manual vertical shift applied to text set under this context
(set-manual-rising’s argument; v0.0.6 context_main.manual_rising,
horzBox.ml:232). Stored only: nothing downstream reads it (upstream’s
PHGRising box has no analogue here).
dominant_wide_script: Scriptset-dominant-wide-script (v0.0.6 context_main.dominant_wide_script,
horzBox.ml:218). Storage only; no layout consumer yet.
dominant_narrow_script: Scriptset-dominant-narrow-script (horzBox.ml:219). Same status.
langsys_scheme: [Language; 4]set-language/get-language (v0.0.6 context_main.langsys_scheme,
horzBox.ml:216 — a script→language_system map). Stored as a dense
4-slot array indexed by Script’s discriminant; upstream’s “absent
from map” IS NoLanguageSystem (get_language_system’s default,
horzBox.ml:483-487), so the empty map and [NoLanguageSystem; 4]
are indistinguishable — no Option needed.
font_scheme: [ScriptFont; 4]set-font’s per-script font/ratio/rising scheme (v0.0.6
context_main.font_scheme, horzBox.ml:214), indexed by Script’s
discriminant. Resolution rule (back-compat critical, see set-font’s
doc in rustyfi-lang): Latin-script text reads Context::font
directly, NOT this scheme’s Latin slot — set-font Latin f writes
BOTH so the two stay in sync, leaving a bare
set-font-key/\bold/\emph (which only touches font) unaffected.
script_space_map: [[f64; 4]; 4]set-space-ratio-between-scripts (v0.0.6
context_main.script_space_map, horzBox.ml:222) — the space inserted
between two adjacent runs of DIFFERENT scripts, as a ratio of
font_size. Indexed [left script][right script] by Script’s
discriminant, so the map is directional: upstream keys
ScriptSpaceMap on the ordered pair and registers the four Latin↔CJK
directions separately (primitives.cppo.ml:491-494).
Only the NATURAL ratio is stored, because only it is observable.
The primitive takes three (natural, shrink, stretch), and upstream’s
ScriptSpaceMap really does hold all three — but
pure_space_between_scripts spends them as
LBAtom((natural (size *% r0), size *% r1, size *% r2), _), whose
first field is metrics = length_info * length * length, i.e. (width
info, height, depth). r1 and r2 land in the height and depth slots
and never reach the glue’s elasticity; see primitives.rs’s
interscript_glue for the full argument. Keeping the two dead ratios
here would imply a stretch this glue does not have.
Upstream’s map is SPARSE and a miss falls through to the JLreq class
table and then to adjacent_space; this dense array cannot distinguish
“absent” from “present and 0.0”. That costs nothing, because the port
only ever consults it at a is_latin_cjk_boundary, where upstream’s
fall-through is already unreachable — the four Latin↔CJK keys are
exactly the ones the default map fills. A 0.0 entry still emits a
zero-width glue rather than nothing, keeping the break opportunity
upstream’s discretionary_if_breakable wrapper grants regardless of
the box’s width.
text_color: Colorset-text-color/get-text-color (row 1-2; v0.0.6
context_main.text_color). Copied into each run’s
HorzStringInfo::color at box-construction time — which is what both
PDF writers emit their fill-color op from.
hyphen_badness: i64set-hyphen-penalty (row 3; v0.0.6 context_main.hyphen_badness).
Consumed by rustyfi-lang’s flush_word injection as each injected
Discretionary’s penalty, but only when hyphen_dictionary is
Some(_); with no dictionary installed it has no layout effect.
hyphen_dictionary: Option<HyphenLang>The installed hyphenation dictionary
(set-hyphenation-dictionary/load-hyphenation-dictionary; v0.0.6
context_main.hyphen_dictionary). flush_word (rustyfi-lang) runs
the hyphenation branch iff this is Some(tag) and the run’s
script is Latin.
left_hyphen_min: i64Minimum number of chars that must PRECEDE an accepted hyphenation
break (set-hyphen-min’s first argument; v0.0.6
context_main.left_hyphen_min). Default 3.
right_hyphen_min: i64Minimum number of chars that must FOLLOW it (set-hyphen-min’s
second argument). Default 2.
space_natural: f64set-space-ratio’s three fields (row 4; v0.0.6
context_main.space_natural/space_shrink/space_stretch). Each is
a ratio of font_size DIRECTLY, not of the natural width:
text_to_boxes’s interword glue is natural = font_size * space_natural, shrink/stretch likewise.
space_shrink: f64§space_stretch: f64§adjacent_stretch: f64set-adjacent-stretch (v0.0.6 context_main.adjacent_stretch) — the
stretch, as a ratio of font_size, of the glue SATySFi puts between
two DIRECTLY ADJACENT CJK characters (convertText.ml:101
adjacent_space: natural 0, shrink 0, stretch font_size * ratio).
This is what lets a Japanese line fill its column: unspaced CJK has no
interword glue, so without it a CJK line’s only elasticity is whatever
incidental Latin spaces it happens to contain.
math_command: Option<MathCmdId>The installed [math] inline-cmd applied to bare ${…} in inline
text (v0.0.6 context_main.math_command). None only for contexts
built by Context::initial directly (unit tests) — the
get-initial-context primitive always installs its second argument.
code_text_command: Option<MathCmdId>set-code-text-command (v0.0.6 context_main.code_text_command) — the
[string] inline-cmd a backtick literal inside inline text is handed
to. None is upstream’s DefaultCodeTextCommand: the literal is set as
ordinary text. Same id-into-Interp handle as math_command.
math_char_class: MathCharClass\mathrm/\bm/… restyling target (v0.0.6 context_main. math_char_class): which Mathematical- Alphanumeric style block a
plain ${…} letter resolves to. Set by Math::ChangeCharClass’s
layout arm (primitives.rs), consulted by resolve_variant_char.
Defaults to Italic, v0.0.6’s own default.
math_class_map: Arc<BTreeMap<String, (String, MathKind)>>Upstream default_math_class_map (primitives.cppo.ml:465-480):
whole-TOKEN entries (=, -, ,, …) consulted BEFORE the per-char
variant lookup below. Arc so that cloning a Context (every ..ctx
spread) stays a refcount bump.
math_variant_char_map: Arc<BTreeMap<(char, MathCharClass), char>>set-math-variant-char’s runtime override table: (source char, style) -> replacement char, consulted BEFORE
default_math_variant_char’s built-in Mathematical-Alphanumeric
remap. Empty by default; copy-on-written via Arc::make_mut.
math_script_level: MathScriptLevelV0_1-only (enter_script, port of dev-0-1-0 src/frontend/context.ml:52-68). Base under V0_0 always.
math_cramped: boolWhether the current math sub-formula is laid out “cramped” (TeXbook
Appendix G): set on the recursive layout Context for a radical’s
radicand, a fraction’s denominator, and any subscript. Read by BOTH
V0_0 and V0_1 (the bit rides the shared layout-recursion clone, not a
version-gated primitive). Only consumed by sup_shift_clamped’s
superscript shift-up formula.