pub struct ParagraphObjective {
pub line_penalty: u64,
pub fitness_demerit: u64,
pub double_hyphen_demerit: u64,
pub final_hyphen_demerit: u64,
pub max_adjustment_ratio: f64,
pub min_adjustment_ratio: f64,
pub widow_demerit: u64,
pub widow_threshold: usize,
pub orphan_demerit: u64,
pub orphan_threshold: usize,
pub badness_scale: u64,
}Expand description
Configuration for the paragraph objective function.
All weight values are in the same “demerit” unit space. Higher values
mean stronger penalties. The TeX defaults are provided by Default.
Fields§
§line_penalty: u64Base penalty added to every line’s badness before squaring (TeX \linepenalty).
Higher values prefer fewer lines.
Default: 10 (TeX standard).
fitness_demerit: u64Additional demerit when consecutive lines have incompatible fitness classes.
Default: 100 (TeX \adjdemerits).
double_hyphen_demerit: u64Additional demerit when two consecutive lines both end with flagged breaks
(typically hyphens). Default: 100 (TeX \doublehyphendemerits).
final_hyphen_demerit: u64Additional demerit when the penultimate line has a flagged break and the
last line is short. Default: 100 (TeX \finalhyphendemerits).
max_adjustment_ratio: f64Maximum allowed adjustment ratio before the line is considered infeasible.
Lines looser than this threshold get BADNESS_INF.
Default: 2.0 (generous for terminal rendering).
min_adjustment_ratio: f64Minimum allowed adjustment ratio (negative = compression). Default: -1.0 (allow moderate compression).
widow_demerit: u64Widow penalty: extra demerit if the last line of a paragraph has
fewer than widow_threshold characters.
Default: 150.
widow_threshold: usizeCharacter count below which the last line triggers widow_demerit.
Default: 15 (approximately one short word).
orphan_demerit: u64Orphan penalty: extra demerit if the first line of a paragraph
followed by a break has fewer than orphan_threshold characters.
Default: 150.
orphan_threshold: usizeCharacter count below which a first-line break triggers orphan_demerit.
Default: 20.
badness_scale: u64Scale factor for badness computation. Matches TeX convention. Default: 10_000.
Implementations§
Source§impl ParagraphObjective
impl ParagraphObjective
Sourcepub fn terminal() -> Self
pub fn terminal() -> Self
Preset optimized for terminal rendering where cells are monospaced and compression is not possible (no inter-character stretch).
Sourcepub fn typographic() -> Self
pub fn typographic() -> Self
Preset for high-quality proportional typography (closest to TeX defaults).
Sourcepub fn badness(&self, slack: i64, width: usize) -> Option<u64>
pub fn badness(&self, slack: i64, width: usize) -> Option<u64>
Compute the badness of a line with the given slack and target width.
Badness is (|ratio|^3) * badness_scale where ratio = slack / width.
Returns None if the line is infeasible (ratio outside bounds).
Sourcepub fn adjustment_ratio(&self, slack: i64, width: usize) -> f64
pub fn adjustment_ratio(&self, slack: i64, width: usize) -> f64
Compute the adjustment ratio for a line.
Sourcepub fn demerits(
&self,
slack: i64,
width: usize,
penalty: &BreakPenalty,
) -> Option<u64>
pub fn demerits( &self, slack: i64, width: usize, penalty: &BreakPenalty, ) -> Option<u64>
Compute demerits for a single break point.
This is the full TeX demerit formula: demerit = (line_penalty + badness)^2 + penalty^2
For forced breaks (negative penalty), the formula becomes: demerit = (line_penalty + badness)^2 - penalty^2
Returns None if the line is infeasible.
Sourcepub fn adjacency_demerits(
&self,
prev_fitness: FitnessClass,
curr_fitness: FitnessClass,
prev_flagged: bool,
curr_flagged: bool,
) -> u64
pub fn adjacency_demerits( &self, prev_fitness: FitnessClass, curr_fitness: FitnessClass, prev_flagged: bool, curr_flagged: bool, ) -> u64
Compute adjacency demerits between two consecutive line breaks.
Returns the additional demerit to add when prev and curr are
consecutive break points.
Sourcepub fn widow_demerits(&self, last_line_chars: usize) -> u64
pub fn widow_demerits(&self, last_line_chars: usize) -> u64
Check if the last line triggers widow penalty.
A “widow” here means the last line of a paragraph is very short, leaving a visually orphaned fragment.
Sourcepub fn orphan_demerits(&self, first_line_chars: usize) -> u64
pub fn orphan_demerits(&self, first_line_chars: usize) -> u64
Check if the first line triggers orphan penalty.
An “orphan” here means the first line before a break is very short.
Trait Implementations§
Source§impl Clone for ParagraphObjective
impl Clone for ParagraphObjective
Source§fn clone(&self) -> ParagraphObjective
fn clone(&self) -> ParagraphObjective
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more