Skip to main content

ParagraphObjective

Struct ParagraphObjective 

Source
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: u64

Base penalty added to every line’s badness before squaring (TeX \linepenalty). Higher values prefer fewer lines. Default: 10 (TeX standard).

§fitness_demerit: u64

Additional demerit when consecutive lines have incompatible fitness classes. Default: 100 (TeX \adjdemerits).

§double_hyphen_demerit: u64

Additional demerit when two consecutive lines both end with flagged breaks (typically hyphens). Default: 100 (TeX \doublehyphendemerits).

§final_hyphen_demerit: u64

Additional demerit when the penultimate line has a flagged break and the last line is short. Default: 100 (TeX \finalhyphendemerits).

§max_adjustment_ratio: f64

Maximum 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: f64

Minimum allowed adjustment ratio (negative = compression). Default: -1.0 (allow moderate compression).

§widow_demerit: u64

Widow penalty: extra demerit if the last line of a paragraph has fewer than widow_threshold characters. Default: 150.

§widow_threshold: usize

Character count below which the last line triggers widow_demerit. Default: 15 (approximately one short word).

§orphan_demerit: u64

Orphan penalty: extra demerit if the first line of a paragraph followed by a break has fewer than orphan_threshold characters. Default: 150.

§orphan_threshold: usize

Character count below which a first-line break triggers orphan_demerit. Default: 20.

§badness_scale: u64

Scale factor for badness computation. Matches TeX convention. Default: 10_000.

Implementations§

Source§

impl ParagraphObjective

Source

pub fn terminal() -> Self

Preset optimized for terminal rendering where cells are monospaced and compression is not possible (no inter-character stretch).

Source

pub fn typographic() -> Self

Preset for high-quality proportional typography (closest to TeX defaults).

Source

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).

Source

pub fn adjustment_ratio(&self, slack: i64, width: usize) -> f64

Compute the adjustment ratio for a line.

Source

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.

Source

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.

Source

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.

Source

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

Source§

fn clone(&self) -> ParagraphObjective

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ParagraphObjective

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for ParagraphObjective

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl PartialEq for ParagraphObjective

Source§

fn eq(&self, other: &ParagraphObjective) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for ParagraphObjective

Source§

impl StructuralPartialEq for ParagraphObjective

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more