Skip to content
Topaz6.0 · Before release
Download

Search documentation

Specification 6.0 · Not released · Tested product 5.21.3

Use arrow keys to choose a result. Press Enter to open.

Type an API name, diagnostic number, rule, or project topic.

    Library · std.typeset

    Paragraph.grid

    Choose the paragraph calculation grid.

    Paragraph.grid: DistanceGrid
    Receiver
    Paragraph
    Minimum arity
    0
    Maximum arity
    0

    Declaration and parameters

    Link

    Availability

    Included by default: Pending

    Import std.typeset in language mode 5.21.

    The current compiler selects std/typeset.tpz for this language mode. Availability in other released editions and inclusion in each installed distribution are Pending.

    Source evidence

    Receiver

    Paragraph

    Parameter constraints

    Public measurement fields use Length<Pt>. Widths, advances, tracking, stretch, shrink, physical targets, insets, font sizes, and optional width limits keep that type across input and output records. Explicit Length conversion functions remain the integer interchange boundary.

    Box.width, Box.trackingAfter, Glue.width, Glue.trackingAfter, Glue.stretch, Glue.shrink, and Penalty.width have type Length<Pt>.

    BreakCluster.advance, BreakCluster.trackingAfter, BreakPolicy.narrowestWordTarget, and BreakPolicy.bodyWordTarget have type Length<Pt>.

    LatinSpacing.fontSizePt, JustificationPolicy.maxAdjustment, and JustificationPolicy.maxGapAdjustment have type Length<Pt>.

    LineGeometry.bodyTarget, LineGeometry.firstTarget, and LineGeometry.dropCapInset have type Length<Pt>.

    PlanLine.target, PlanLine.rawTextWidth, PlanLine.trimmedTextWidth, PlanLine.costTextWidth, and PlanLine.selectedPenaltyWidth have type Length<Pt>. PlanLine.postValidationWidthLimit has type Option<Length<Pt>>.

    An int, a float, or a Length with another unit marker is not an implicit point-length argument. Convert physical units explicitly with toPt() before constructing a typesetting record.

    Indices, counts, penalties, costs, and dimensionless ratios retain their declared types. LatinSpacing.maxLetterSpacingEm is a relative Length<Em>. Resolve it to Length<Pt> with fontSizePt before selecting the computation grid.

    Paragraph.grid selects quantization at the computation boundary. ScaledPoint uses the exact scaled-point integer. MilliPoint uses the existing nearest-even conversion to millipoints. The selected grid never changes the physical interpretation of a public Length<Pt> value.

    Returned distances are converted from the computation grid into Length<Pt> at the output boundary. ParagraphPlan.grid reports the computation policy and is not needed to interpret its distances.

    The public type change preserves the selected cost model. FixedPoint retains its MilliPoint computation requirement. Word-space and CJK ratio calculations keep their independent floor rules. The relative letter-spacing distance is resolved and quantized through the shared Length conversions before it contributes to capacity.

    The public line-badness entry point also receives width, target, and hyphen advance as Length<Pt>. It converts those distances to millipoints at entry and preserves its existing integer cost calculation.

    breakParagraph evaluates its Paragraph argument through the ordinary call rules, then reads its item sequence and policies. Planning performs no input mutation, text shaping, external I/O, or random selection. The same ordered input and computation rules produce the same lines and scores.

    Paragraph.items supplies measured BoxItem and GlueItem units with contiguous indices from zero. PenaltyItem entries refer to boundaries between those units. The planner uses these measurements and supplied penalties directly. It does not call classifyBreaks or insert a terminal penalty.

    Paragraph.grid selects integer quantization at the computation boundary. Every public distance remains Length<Pt>. FixedPoint requires MilliPoint. KnuthPlass accepts either DistanceGrid. The ordinary checked length conversion applies before integer planning.

    Policy validation precedes item validation. Geometry, the cost model and grid combination, justification values, and KnuthPlassPolicy are validated even when a chosen model does not use a policy field for scoring. Invalid configuration returns TypesetError.InvalidPolicy. Invalid unit indices, capacities, or penalty endpoints return TypesetError.InvalidInput.

    A valid empty items array returns two empty plans with zero totalCost and zero breakOpportunityCount. This case still validates the policies. Each empty plan reports its selected grid and None() for boundedFillFeasible.

    For nonempty input, the planner orders penalties by increasing unitEnd and preserves supplied order at equal boundaries. Allowed and Forced entries are candidates. Forbidden entries are excluded individually. Duplicate candidates remain distinct. A Forced entry requires the plan to visit its boundary, where another eligible entry may be selected.

    No candidates returns TypesetError.NoBreakOpportunities. The planner constructs the greedy baseline before the optimized search. Failure to complete that baseline returns TypesetError.NoGreedyPlan. A completed baseline followed by an unsuccessful optimized search returns TypesetError.NoPlan. An Err result contains no partial ParagraphResult.

    For FixedPoint, greedy chooses the farthest raw width that fits the next target before the first overwide candidate or Forced boundary. If the first candidate is already overwide, greedy chooses it to advance. For KnuthPlass, greedy chooses the last ratio-admissible candidate up to the next Forced boundary. Every chosen boundary advances past the previous one.

    FixedPoint optimization starts with the preceding 80 candidates at each destination. It extends the search backward while the preceding span fits the larger base target plus available shrink and one grid unit. It retains the least score for each boundary and semantic state. It admits at most two consecutive LatinSoftHyphen breaks.

    FixedPoint optimized admission uses trimmed text width plus the selected penalty width. The width limit is the target plus available shrink for a nonfinal line, with one grid unit of rounding allowance. A line containing one unit can exceed this limit so an indivisible unit can make progress. Greedy reports the same limit but selects candidates using its raw width rule.

    With FixedPoint, a justified mode, and Some(latinSpacing), optimization first searches for a complete plan whose lines satisfy the bounded fill check. It prefers that plan when found. Otherwise it repeats the search without that check. This preference can select a plan with a higher totalCost than the greedy plan.

    KnuthPlass optimization considers every preceding candidate and retains each distinct line geometry bucket, fitness class, and flagged state at a boundary. FixedPoint also retains its soft hyphen streak. State buckets distinguish drop cap lines and collapse after the inset ends.

    Equal scores retain the first visited predecessor. Candidates are visited in boundary order, with supplied order at equal boundaries. States are visited by increasing line geometry bucket, soft hyphen streak, fitness class, and then unflagged before flagged. Final selection uses the same first-on-equal rule.

    The optimized field reports the selected model search and admission policy. The greedy field reports its baseline from the same input. Each reported cost belongs to the plan selected by these candidate, state, and admission rules. Ordinary checked arithmetic faults remain faults and are not converted into a TypesetError value.

    Result

    The declared result type is DistanceGrid.

    Effects

    Failures

    Result and effects

    Link

    Select this field from a value of its named type without call parentheses.

    Select MilliPoint for FixedPoint or either supported grid for KnuthPlass. Quantize at computation entry while every public input and output distance remains Length<Pt>.

    Why

    Link

    Applications need reproducible line boundaries and a clear choice between a bounded fixed point search and a Knuth Plass state search. Reporting both selected plans preserves the baseline for inspection. Keeping policy failure, missing candidates, and unsuccessful searches distinct lets a caller decide which input to revise.

    Related entries

    Link

    std.typeset

    Give public typesetting distances a point-length type

    Link
    Ruletopaz.stdlib.contract.typeset-length-pt.rule

    Give public typesetting distances a point-length type

    Public measurement fields use Length<Pt>. Widths, advances, tracking, stretch, shrink, physical targets, insets, font sizes, and optional width limits keep that type across input and output records. Explicit Length conversion functions remain the integer interchange boundary.

    Box.width, Box.trackingAfter, Glue.width, Glue.trackingAfter, Glue.stretch, Glue.shrink, and Penalty.width have type Length<Pt>.

    BreakCluster.advance, BreakCluster.trackingAfter, BreakPolicy.narrowestWordTarget, and BreakPolicy.bodyWordTarget have type Length<Pt>.

    LatinSpacing.fontSizePt, JustificationPolicy.maxAdjustment, and JustificationPolicy.maxGapAdjustment have type Length<Pt>.

    LineGeometry.bodyTarget, LineGeometry.firstTarget, and LineGeometry.dropCapInset have type Length<Pt>.

    PlanLine.target, PlanLine.rawTextWidth, PlanLine.trimmedTextWidth, PlanLine.costTextWidth, and PlanLine.selectedPenaltyWidth have type Length<Pt>. PlanLine.postValidationWidthLimit has type Option<Length<Pt>>.

    An int, a float, or a Length with another unit marker is not an implicit point-length argument. Convert physical units explicitly with toPt() before constructing a typesetting record.

    Indices, counts, penalties, costs, and dimensionless ratios retain their declared types. LatinSpacing.maxLetterSpacingEm is a relative Length<Em>. Resolve it to Length<Pt> with fontSizePt before selecting the computation grid.

    Paragraph.grid selects quantization at the computation boundary. ScaledPoint uses the exact scaled-point integer. MilliPoint uses the existing nearest-even conversion to millipoints. The selected grid never changes the physical interpretation of a public Length<Pt> value.

    Returned distances are converted from the computation grid into Length<Pt> at the output boundary. ParagraphPlan.grid reports the computation policy and is not needed to interpret its distances.

    The public type change preserves the selected cost model. FixedPoint retains its MilliPoint computation requirement. Word-space and CJK ratio calculations keep their independent floor rules. The relative letter-spacing distance is resolved and quantized through the shared Length conversions before it contributes to capacity.

    The public line-badness entry point also receives width, target, and hyphen advance as Length<Pt>. It converts those distances to millipoints at entry and preserves its existing integer cost calculation.

    Why

    A physical distance carries the same Length<Pt> type in application geometry and paragraph planning. The type prevents a grid selector or an unlabelled scalar from silently changing the distance.

    Source evidence

    Use point lengths in Box

    Link
    main.tpzUse point lengths in BoxOpen in Playground
    1. import std.typeset as ts
    2. let value: ts.Box = ts.Box {
    3. unitIndex: 0,
    4. text: "A",
    5. width: 12pt,
    6. trackingAfter: 0pt
    7. }
    8. let distance: Length<Pt> = value.width
    Expected outputexit 0
    No stdout.
    $ topaz check main.tpz --format json · target product 5.21.3
    Expected result

    Expected result

    Checking accepts the program. Exit code 0.

    Source evidence

    Reject untyped physical distances in Box

    Link
    main.tpzReject untyped physical distances in BoxOpen in Playground
    1. import std.typeset as ts
    2. let value: ts.Box = ts.Box {
    3. unitIndex: 0,
    4. text: "A",
    5. width: 12,
    6. trackingAfter: 0
    7. }
    Expected outputNonzero exit
    No stdout.
    $ topaz check main.tpz --format json · target product 5.21.3
    Expected result

    Expected result

    Rejection during check. Nonzero exit.

    • TPZ5001 stdlib-physical-distance-requires-points at main.tpz:5:10
    Source evidence

    Use point lengths in Glue

    Link
    main.tpzUse point lengths in GlueOpen in Playground
    1. import std.typeset as ts
    2. let value: ts.Glue = ts.Glue {
    3. unitIndex: 1,
    4. text: " ",
    5. width: 3pt,
    6. trackingAfter: 0pt,
    7. stretch: 1pt,
    8. shrink: 1pt
    9. }
    10. let distance: Length<Pt> = value.width
    Expected outputexit 0
    No stdout.
    $ topaz check main.tpz --format json · target product 5.21.3
    Expected result

    Expected result

    Checking accepts the program. Exit code 0.

    Source evidence

    Reject untyped physical distances in Glue

    Link
    main.tpzReject untyped physical distances in GlueOpen in Playground
    1. import std.typeset as ts
    2. let value: ts.Glue = ts.Glue {
    3. unitIndex: 1,
    4. text: " ",
    5. width: 3,
    6. trackingAfter: 0,
    7. stretch: 1,
    8. shrink: 1
    9. }
    Expected outputNonzero exit
    No stdout.
    $ topaz check main.tpz --format json · target product 5.21.3
    Expected result

    Expected result

    Rejection during check. Nonzero exit.

    • TPZ5001 stdlib-physical-distance-requires-points at main.tpz:5:10
    Source evidence

    Use point lengths in Penalty

    Link
    main.tpzUse point lengths in PenaltyOpen in Playground
    1. import std.typeset as ts
    2. let value: ts.Penalty = ts.Penalty {
    3. unitEnd: 1,
    4. width: 0pt,
    5. rule: ts.BreakRule.Forced(),
    6. kind: ts.BreakKind.ForcedEnd(),
    7. flagged: false
    8. }
    9. let distance: Length<Pt> = value.width
    Expected outputexit 0
    No stdout.
    $ topaz check main.tpz --format json · target product 5.21.3
    Expected result

    Expected result

    Checking accepts the program. Exit code 0.

    Source evidence

    Reject untyped physical distances in Penalty

    Link
    main.tpzReject untyped physical distances in PenaltyOpen in Playground
    1. import std.typeset as ts
    2. let value: ts.Penalty = ts.Penalty {
    3. unitEnd: 1,
    4. width: 0,
    5. rule: ts.BreakRule.Forced(),
    6. kind: ts.BreakKind.ForcedEnd(),
    7. flagged: false
    8. }
    Expected outputNonzero exit
    No stdout.
    $ topaz check main.tpz --format json · target product 5.21.3
    Expected result

    Expected result

    Rejection during check. Nonzero exit.

    • TPZ5001 stdlib-physical-distance-requires-points at main.tpz:4:10
    Source evidence

    Use point lengths in BreakPolicy

    Link
    main.tpzUse point lengths in BreakPolicyOpen in Playground
    1. import std.typeset as ts
    2. let value: ts.BreakPolicy = ts.BreakPolicy {
    3. mode: ts.BreakMode.Character(),
    4. rules: ts.KinsokuRules.Unicode16Ja(),
    5. forbidBefore: [],
    6. forbidAfter: [],
    7. boundaryAllowed: [true],
    8. generatedHyphenEnds: [],
    9. protectFittingLatin: true,
    10. preserveShortWords: true,
    11. narrowestWordTarget: 12pt,
    12. bodyWordTarget: 24pt
    13. }
    14. let distance: Length<Pt> = value.narrowestWordTarget
    Expected outputexit 0
    No stdout.
    $ topaz check main.tpz --format json · target product 5.21.3
    Expected result

    Expected result

    Checking accepts the program. Exit code 0.

    Source evidence

    Reject untyped physical distances in BreakPolicy

    Link
    main.tpzReject untyped physical distances in BreakPolicyOpen in Playground
    1. import std.typeset as ts
    2. let value: ts.BreakPolicy = ts.BreakPolicy {
    3. mode: ts.BreakMode.Character(),
    4. rules: ts.KinsokuRules.Unicode16Ja(),
    5. forbidBefore: [],
    6. forbidAfter: [],
    7. boundaryAllowed: [true],
    8. generatedHyphenEnds: [],
    9. protectFittingLatin: true,
    10. preserveShortWords: true,
    11. narrowestWordTarget: 12,
    12. bodyWordTarget: 24
    13. }
    Expected outputNonzero exit
    No stdout.
    $ topaz check main.tpz --format json · target product 5.21.3
    Expected result

    Expected result

    Rejection during check. Nonzero exit.

    • TPZ5001 stdlib-physical-distance-requires-points at main.tpz:11:24
    Source evidence

    Use point lengths in BreakCluster

    Link
    main.tpzUse point lengths in BreakClusterOpen in Playground
    1. import std.typeset as ts
    2. let value: ts.BreakCluster = ts.BreakCluster {
    3. text: "A",
    4. advance: 12pt,
    5. trackingAfter: 0pt
    6. }
    7. let distance: Length<Pt> = value.advance
    Expected outputexit 0
    No stdout.
    $ topaz check main.tpz --format json · target product 5.21.3
    Expected result

    Expected result

    Checking accepts the program. Exit code 0.

    Source evidence

    Reject untyped physical distances in BreakCluster

    Link
    main.tpzReject untyped physical distances in BreakClusterOpen in Playground
    1. import std.typeset as ts
    2. let value: ts.BreakCluster = ts.BreakCluster {
    3. text: "A",
    4. advance: 12,
    5. trackingAfter: 0
    6. }
    Expected outputNonzero exit
    No stdout.
    $ topaz check main.tpz --format json · target product 5.21.3
    Expected result

    Expected result

    Rejection during check. Nonzero exit.

    • TPZ5001 stdlib-physical-distance-requires-points at main.tpz:4:12
    Source evidence

    Use point lengths in LatinSpacing

    Link
    main.tpzUse point lengths in LatinSpacingOpen in Playground
    1. import std.typeset as ts
    2. let value: ts.LatinSpacing = ts.LatinSpacing {
    3. minWordSpaceRatio: 0.8,
    4. maxWordSpaceRatio: 1.33,
    5. maxLetterSpacingEm: 0.01em,
    6. fontSizePt: 12pt
    7. }
    8. let distance: Length<Pt> = value.fontSizePt
    Expected outputexit 0
    No stdout.
    $ topaz check main.tpz --format json · target product 5.21.3
    Expected result

    Expected result

    Checking accepts the program. Exit code 0.

    Source evidence

    Reject untyped physical distances in LatinSpacing

    Link
    main.tpzReject untyped physical distances in LatinSpacingOpen in Playground
    1. import std.typeset as ts
    2. let value: ts.LatinSpacing = ts.LatinSpacing {
    3. minWordSpaceRatio: 0.8,
    4. maxWordSpaceRatio: 1.33,
    5. maxLetterSpacingEm: 0.01em,
    6. fontSizePt: 12.0
    7. }
    Expected outputNonzero exit
    No stdout.
    $ topaz check main.tpz --format json · target product 5.21.3
    Expected result

    Expected result

    Rejection during check. Nonzero exit.

    • TPZ5001 stdlib-physical-distance-requires-points at main.tpz:6:15
    Source evidence

    Use point lengths in JustificationPolicy

    Link
    main.tpzUse point lengths in JustificationPolicyOpen in Playground
    1. import std.typeset as ts
    2. let value: ts.JustificationPolicy = ts.JustificationPolicy {
    3. mode: ts.JustificationMode.Unjustified(),
    4. minGapCount: 0,
    5. minLineWidthRatioM: 0,
    6. minFinalLineWidthRatioM: None(),
    7. maxAdjustment: 12pt,
    8. maxGapAdjustment: 3pt,
    9. maxGapRatioR: 0,
    10. latinSpacing: None(),
    11. cjkStretchRatio: 0.0
    12. }
    13. let distance: Length<Pt> = value.maxAdjustment
    Expected outputexit 0
    No stdout.
    $ topaz check main.tpz --format json · target product 5.21.3
    Expected result

    Expected result

    Checking accepts the program. Exit code 0.

    Source evidence

    Reject untyped physical distances in JustificationPolicy

    Link
    main.tpzReject untyped physical distances in JustificationPolicyOpen in Playground
    1. import std.typeset as ts
    2. let value: ts.JustificationPolicy = ts.JustificationPolicy {
    3. mode: ts.JustificationMode.Unjustified(),
    4. minGapCount: 0,
    5. minLineWidthRatioM: 0,
    6. minFinalLineWidthRatioM: None(),
    7. maxAdjustment: 12,
    8. maxGapAdjustment: 3,
    9. maxGapRatioR: 0,
    10. latinSpacing: None(),
    11. cjkStretchRatio: 0.0
    12. }
    Expected outputNonzero exit
    No stdout.
    $ topaz check main.tpz --format json · target product 5.21.3
    Expected result

    Expected result

    Rejection during check. Nonzero exit.

    • TPZ5001 stdlib-physical-distance-requires-points at main.tpz:7:18
    Source evidence

    Use point lengths in LineGeometry

    Link
    main.tpzUse point lengths in LineGeometryOpen in Playground
    1. import std.typeset as ts
    2. let value: ts.LineGeometry = ts.LineGeometry {
    3. bodyTarget: 24pt,
    4. firstTarget: 20pt,
    5. dropCapSpan: 0,
    6. dropCapInset: 0pt
    7. }
    8. let distance: Length<Pt> = value.bodyTarget
    Expected outputexit 0
    No stdout.
    $ topaz check main.tpz --format json · target product 5.21.3
    Expected result

    Expected result

    Checking accepts the program. Exit code 0.

    Source evidence

    Reject untyped physical distances in LineGeometry

    Link
    main.tpzReject untyped physical distances in LineGeometryOpen in Playground
    1. import std.typeset as ts
    2. let value: ts.LineGeometry = ts.LineGeometry {
    3. bodyTarget: 24,
    4. firstTarget: 20,
    5. dropCapSpan: 0,
    6. dropCapInset: 0
    7. }
    Expected outputNonzero exit
    No stdout.
    $ topaz check main.tpz --format json · target product 5.21.3
    Expected result

    Expected result

    Rejection during check. Nonzero exit.

    • TPZ5001 stdlib-physical-distance-requires-points at main.tpz:3:15
    Source evidence

    Use point lengths in PlanLine

    Link
    main.tpzUse point lengths in PlanLineOpen in Playground
    1. import std.typeset as ts
    2. let value: ts.PlanLine = ts.PlanLine {
    3. start: 0,
    4. endExclusive: 1,
    5. trimmedEndExclusive: 1,
    6. displayTextScalarLength: 1,
    7. kind: ts.BreakKind.ForcedEnd(),
    8. target: 12pt,
    9. rawTextWidth: 10pt,
    10. trimmedTextWidth: 10pt,
    11. costTextWidth: 10pt,
    12. selectedPenaltyWidth: 0pt,
    13. postValidationWidthLimit: Some(13pt),
    14. cost: 0,
    15. adjustmentRatioR: 0
    16. }
    17. let distance: Length<Pt> = value.target
    18. let limit: Option<Length<Pt>> = value.postValidationWidthLimit
    Expected outputexit 0
    No stdout.
    $ topaz check main.tpz --format json · target product 5.21.3
    Expected result

    Expected result

    Checking accepts the program. Exit code 0.

    Source evidence

    Reject untyped physical distances in PlanLine

    Link
    main.tpzReject untyped physical distances in PlanLineOpen in Playground
    1. import std.typeset as ts
    2. let value: ts.PlanLine = ts.PlanLine {
    3. start: 0,
    4. endExclusive: 1,
    5. trimmedEndExclusive: 1,
    6. displayTextScalarLength: 1,
    7. kind: ts.BreakKind.ForcedEnd(),
    8. target: 12,
    9. rawTextWidth: 10,
    10. trimmedTextWidth: 10,
    11. costTextWidth: 10,
    12. selectedPenaltyWidth: 0,
    13. postValidationWidthLimit: Some(13),
    14. cost: 0,
    15. adjustmentRatioR: 0
    16. }
    Expected outputNonzero exit
    No stdout.
    $ topaz check main.tpz --format json · target product 5.21.3
    Expected result

    Expected result

    Rejection during check. Nonzero exit.

    • TPZ5001 stdlib-physical-distance-requires-points at main.tpz:8:11
    Source evidence

    Pass typed distances to the line-cost function

    Link
    main.tpzPass typed distances to the line-cost functionOpen in Playground
    1. import std.typeset as ts
    2. let value = ts.lineBadness(20pt, 20pt, 4, 1, ts.BreakKind.ForcedEnd(), false, 0, 0pt)
    Expected outputexit 0
    No stdout.
    $ topaz check main.tpz --format json · target product 5.21.3
    Expected result

    Expected result

    Checking accepts the program. Exit code 0.

    Source evidence

    Reject raw distances at the line-cost boundary

    Link
    main.tpzReject raw distances at the line-cost boundaryOpen in Playground
    1. import std.typeset as ts
    2. let value = ts.lineBadness(20, 20, 4, 1, ts.BreakKind.ForcedEnd(), false, 0, 0)
    Expected outputNonzero exit
    No stdout.
    $ topaz check main.tpz --format json · target product 5.21.3
    Expected result

    Expected result

    Rejection during check. Nonzero exit.

    • TPZ5001 stdlib-physical-distance-requires-points at main.tpz:2:28
    Source evidence

    Diagnostics

    Link

    TPZ5001

    Choose deterministic paragraph plans

    Link

    Choose deterministic paragraph plans

    breakParagraph evaluates its Paragraph argument through the ordinary call rules, then reads its item sequence and policies. Planning performs no input mutation, text shaping, external I/O, or random selection. The same ordered input and computation rules produce the same lines and scores.

    Paragraph.items supplies measured BoxItem and GlueItem units with contiguous indices from zero. PenaltyItem entries refer to boundaries between those units. The planner uses these measurements and supplied penalties directly. It does not call classifyBreaks or insert a terminal penalty.

    Paragraph.grid selects integer quantization at the computation boundary. Every public distance remains Length<Pt>. FixedPoint requires MilliPoint. KnuthPlass accepts either DistanceGrid. The ordinary checked length conversion applies before integer planning.

    Policy validation precedes item validation. Geometry, the cost model and grid combination, justification values, and KnuthPlassPolicy are validated even when a chosen model does not use a policy field for scoring. Invalid configuration returns TypesetError.InvalidPolicy. Invalid unit indices, capacities, or penalty endpoints return TypesetError.InvalidInput.

    A valid empty items array returns two empty plans with zero totalCost and zero breakOpportunityCount. This case still validates the policies. Each empty plan reports its selected grid and None() for boundedFillFeasible.

    For nonempty input, the planner orders penalties by increasing unitEnd and preserves supplied order at equal boundaries. Allowed and Forced entries are candidates. Forbidden entries are excluded individually. Duplicate candidates remain distinct. A Forced entry requires the plan to visit its boundary, where another eligible entry may be selected.

    No candidates returns TypesetError.NoBreakOpportunities. The planner constructs the greedy baseline before the optimized search. Failure to complete that baseline returns TypesetError.NoGreedyPlan. A completed baseline followed by an unsuccessful optimized search returns TypesetError.NoPlan. An Err result contains no partial ParagraphResult.

    For FixedPoint, greedy chooses the farthest raw width that fits the next target before the first overwide candidate or Forced boundary. If the first candidate is already overwide, greedy chooses it to advance. For KnuthPlass, greedy chooses the last ratio-admissible candidate up to the next Forced boundary. Every chosen boundary advances past the previous one.

    FixedPoint optimization starts with the preceding 80 candidates at each destination. It extends the search backward while the preceding span fits the larger base target plus available shrink and one grid unit. It retains the least score for each boundary and semantic state. It admits at most two consecutive LatinSoftHyphen breaks.

    FixedPoint optimized admission uses trimmed text width plus the selected penalty width. The width limit is the target plus available shrink for a nonfinal line, with one grid unit of rounding allowance. A line containing one unit can exceed this limit so an indivisible unit can make progress. Greedy reports the same limit but selects candidates using its raw width rule.

    With FixedPoint, a justified mode, and Some(latinSpacing), optimization first searches for a complete plan whose lines satisfy the bounded fill check. It prefers that plan when found. Otherwise it repeats the search without that check. This preference can select a plan with a higher totalCost than the greedy plan.

    KnuthPlass optimization considers every preceding candidate and retains each distinct line geometry bucket, fitness class, and flagged state at a boundary. FixedPoint also retains its soft hyphen streak. State buckets distinguish drop cap lines and collapse after the inset ends.

    Equal scores retain the first visited predecessor. Candidates are visited in boundary order, with supplied order at equal boundaries. States are visited by increasing line geometry bucket, soft hyphen streak, fitness class, and then unflagged before flagged. Final selection uses the same first-on-equal rule.

    The optimized field reports the selected model search and admission policy. The greedy field reports its baseline from the same input. Each reported cost belongs to the plan selected by these candidate, state, and admission rules. Ordinary checked arithmetic faults remain faults and are not converted into a TypesetError value.

    Why

    Applications need reproducible line boundaries and a clear choice between a bounded fixed point search and a Knuth Plass state search. Reporting both selected plans preserves the baseline for inspection. Keeping policy failure, missing candidates, and unsuccessful searches distinct lets a caller decide which input to revise.

    Source evidence

    Plan a paragraph through its supplied boundaries

    Link
    main.tpzPlan a paragraph through its supplied boundariesOpen in Playground
    1. import std.typeset as ts
    2. import std.io
    3. let items: Array<ts.Item> = [
    4. ts.Item.BoxItem(ts.Box { unitIndex: 0, text: "a", width: 1pt, trackingAfter: 0pt }),
    5. ts.Item.BoxItem(ts.Box { unitIndex: 1, text: "a", width: 1pt, trackingAfter: 0pt }),
    6. ts.Item.PenaltyItem(ts.Penalty { unitEnd: 2, width: 0pt, rule: ts.BreakRule.Allowed(0), kind: ts.BreakKind.LatinSpace(), flagged: false }),
    7. ts.Item.BoxItem(ts.Box { unitIndex: 2, text: "a", width: 1pt, trackingAfter: 0pt }),
    8. ts.Item.BoxItem(ts.Box { unitIndex: 3, text: "a", width: 1pt, trackingAfter: 0pt }),
    9. ts.Item.PenaltyItem(ts.Penalty { unitEnd: 4, width: 0pt, rule: ts.BreakRule.Forced(), kind: ts.BreakKind.ForcedEnd(), flagged: false })
    10. ]
    11. let input = ts.Paragraph {
    12. grid: ts.DistanceGrid.MilliPoint(),
    13. items: items,
    14. geometry: ts.LineGeometry { bodyTarget: 2pt, firstTarget: 2pt, dropCapSpan: 0, dropCapInset: 0pt },
    15. justification: ts.JustificationPolicy {
    16. mode: ts.JustificationMode.Unjustified(), minGapCount: 0,
    17. minLineWidthRatioM: 0, minFinalLineWidthRatioM: None(),
    18. maxAdjustment: 0pt, maxGapAdjustment: 0pt, maxGapRatioR: 0,
    19. latinSpacing: None(), cjkStretchRatio: 0.0
    20. },
    21. costModel: ts.CostModel.FixedPoint(),
    22. knuthPlass: ts.KnuthPlassPolicy { toleranceR: 100000000, linePenalty: 10, fitnessDemerit: 0, flaggedDemerit: 0, finalFlaggedDemerit: 0 }
    23. }
    24. match (ts.breakParagraph(input)) {
    25. case Ok(result) => {
    26. for line in (result.optimized.lines) {
    27. io.writeLine("{line.start} {line.endExclusive}")
    28. }
    29. io.writeLine("{result.greedy.lines.length} {result.breakOpportunityCount}")
    30. }
    31. case Err(_) => io.writeLine("unexpected error")
    32. }
    Expected outputexit 0
    0 2
    2 4
    2 2
    
    $ topaz run main.tpz · target product 5.21.3
    Expected result

    Expected result

    Execution completes. Exit code 0.

    Expected stdout
    1. 0 2
    2. 2 4
    3. 2 2
    Source evidence

    Plan a valid empty paragraph

    Link
    main.tpzPlan a valid empty paragraphOpen in Playground
    1. import std.typeset as ts
    2. import std.io
    3. let items: Array<ts.Item> = [
    4. ]
    5. let input = ts.Paragraph {
    6. grid: ts.DistanceGrid.MilliPoint(),
    7. items: items,
    8. geometry: ts.LineGeometry { bodyTarget: 10pt, firstTarget: 10pt, dropCapSpan: 0, dropCapInset: 0pt },
    9. justification: ts.JustificationPolicy {
    10. mode: ts.JustificationMode.Unjustified(), minGapCount: 0,
    11. minLineWidthRatioM: 0, minFinalLineWidthRatioM: None(),
    12. maxAdjustment: 0pt, maxGapAdjustment: 0pt, maxGapRatioR: 0,
    13. latinSpacing: None(), cjkStretchRatio: 0.0
    14. },
    15. costModel: ts.CostModel.FixedPoint(),
    16. knuthPlass: ts.KnuthPlassPolicy { toleranceR: 100000000, linePenalty: 10, fitnessDemerit: 0, flaggedDemerit: 0, finalFlaggedDemerit: 0 }
    17. }
    18. match (ts.breakParagraph(input)) {
    19. case Ok(result) => {
    20. io.writeLine("{result.optimized.lines.length} {result.greedy.lines.length}")
    21. io.writeLine("{result.optimized.totalCost} {result.greedy.totalCost} {result.breakOpportunityCount}")
    22. }
    23. case Err(_) => io.writeLine("unexpected error")
    24. }
    Expected outputexit 0
    0 0
    0 0 0
    
    $ topaz run main.tpz · target product 5.21.3
    Expected result

    Expected result

    Execution completes. Exit code 0.

    Expected stdout
    1. 0 0
    2. 0 0 0
    Source evidence

    Report absent break opportunities

    Link
    main.tpzReport absent break opportunitiesOpen in Playground
    1. import std.typeset as ts
    2. import std.io
    3. let items: Array<ts.Item> = [
    4. ts.Item.BoxItem(ts.Box { unitIndex: 0, text: "a", width: 1pt, trackingAfter: 0pt })
    5. ]
    6. let input = ts.Paragraph {
    7. grid: ts.DistanceGrid.MilliPoint(),
    8. items: items,
    9. geometry: ts.LineGeometry { bodyTarget: 10pt, firstTarget: 10pt, dropCapSpan: 0, dropCapInset: 0pt },
    10. justification: ts.JustificationPolicy {
    11. mode: ts.JustificationMode.Unjustified(), minGapCount: 0,
    12. minLineWidthRatioM: 0, minFinalLineWidthRatioM: None(),
    13. maxAdjustment: 0pt, maxGapAdjustment: 0pt, maxGapRatioR: 0,
    14. latinSpacing: None(), cjkStretchRatio: 0.0
    15. },
    16. costModel: ts.CostModel.FixedPoint(),
    17. knuthPlass: ts.KnuthPlassPolicy { toleranceR: 100000000, linePenalty: 10, fitnessDemerit: 0, flaggedDemerit: 0, finalFlaggedDemerit: 0 }
    18. }
    19. match (ts.breakParagraph(input)) {
    20. case Err(NoBreakOpportunities()) => io.writeLine("NoBreakOpportunities")
    21. case _ => io.writeLine("unexpected result")
    22. }
    Expected outputexit 0
    NoBreakOpportunities
    
    $ topaz run main.tpz · target product 5.21.3
    Expected result

    Expected result

    Execution completes. Exit code 0.

    Expected stdout
    1. NoBreakOpportunities
    Source evidence

    Report a missing greedy completion

    Link
    main.tpzReport a missing greedy completionOpen in Playground
    1. import std.typeset as ts
    2. import std.io
    3. let items: Array<ts.Item> = [
    4. ts.Item.BoxItem(ts.Box { unitIndex: 0, text: "a", width: 1pt, trackingAfter: 0pt }),
    5. ts.Item.BoxItem(ts.Box { unitIndex: 1, text: "a", width: 1pt, trackingAfter: 0pt }),
    6. ts.Item.PenaltyItem(ts.Penalty { unitEnd: 1, width: 0pt, rule: ts.BreakRule.Allowed(0), kind: ts.BreakKind.ForcedEnd(), flagged: false })
    7. ]
    8. let input = ts.Paragraph {
    9. grid: ts.DistanceGrid.MilliPoint(),
    10. items: items,
    11. geometry: ts.LineGeometry { bodyTarget: 10pt, firstTarget: 10pt, dropCapSpan: 0, dropCapInset: 0pt },
    12. justification: ts.JustificationPolicy {
    13. mode: ts.JustificationMode.Unjustified(), minGapCount: 0,
    14. minLineWidthRatioM: 0, minFinalLineWidthRatioM: None(),
    15. maxAdjustment: 0pt, maxGapAdjustment: 0pt, maxGapRatioR: 0,
    16. latinSpacing: None(), cjkStretchRatio: 0.0
    17. },
    18. costModel: ts.CostModel.FixedPoint(),
    19. knuthPlass: ts.KnuthPlassPolicy { toleranceR: 100000000, linePenalty: 10, fitnessDemerit: 0, flaggedDemerit: 0, finalFlaggedDemerit: 0 }
    20. }
    21. match (ts.breakParagraph(input)) {
    22. case Err(NoGreedyPlan()) => io.writeLine("NoGreedyPlan")
    23. case _ => io.writeLine("unexpected result")
    24. }
    Expected outputexit 0
    NoGreedyPlan
    
    $ topaz run main.tpz · target product 5.21.3
    Expected result

    Expected result

    Execution completes. Exit code 0.

    Expected stdout
    1. NoGreedyPlan
    Source evidence

    Report three forced soft hyphens in a row

    Link
    main.tpzReport three forced soft hyphens in a rowOpen in Playground
    1. import std.typeset as ts
    2. import std.io
    3. let items: Array<ts.Item> = [
    4. ts.Item.BoxItem(ts.Box { unitIndex: 0, text: "a", width: 1pt, trackingAfter: 0pt }),
    5. ts.Item.PenaltyItem(ts.Penalty { unitEnd: 1, width: 0pt, rule: ts.BreakRule.Forced(), kind: ts.BreakKind.LatinSoftHyphen(), flagged: false }),
    6. ts.Item.BoxItem(ts.Box { unitIndex: 1, text: "a", width: 1pt, trackingAfter: 0pt }),
    7. ts.Item.PenaltyItem(ts.Penalty { unitEnd: 2, width: 0pt, rule: ts.BreakRule.Forced(), kind: ts.BreakKind.LatinSoftHyphen(), flagged: false }),
    8. ts.Item.BoxItem(ts.Box { unitIndex: 2, text: "a", width: 1pt, trackingAfter: 0pt }),
    9. ts.Item.PenaltyItem(ts.Penalty { unitEnd: 3, width: 0pt, rule: ts.BreakRule.Forced(), kind: ts.BreakKind.LatinSoftHyphen(), flagged: false })
    10. ]
    11. let input = ts.Paragraph {
    12. grid: ts.DistanceGrid.MilliPoint(),
    13. items: items,
    14. geometry: ts.LineGeometry { bodyTarget: 1pt, firstTarget: 1pt, dropCapSpan: 0, dropCapInset: 0pt },
    15. justification: ts.JustificationPolicy {
    16. mode: ts.JustificationMode.Unjustified(), minGapCount: 0,
    17. minLineWidthRatioM: 0, minFinalLineWidthRatioM: None(),
    18. maxAdjustment: 0pt, maxGapAdjustment: 0pt, maxGapRatioR: 0,
    19. latinSpacing: None(), cjkStretchRatio: 0.0
    20. },
    21. costModel: ts.CostModel.FixedPoint(),
    22. knuthPlass: ts.KnuthPlassPolicy { toleranceR: 100000000, linePenalty: 10, fitnessDemerit: 0, flaggedDemerit: 0, finalFlaggedDemerit: 0 }
    23. }
    24. match (ts.breakParagraph(input)) {
    25. case Err(NoPlan()) => io.writeLine("NoPlan")
    26. case _ => io.writeLine("unexpected result")
    27. }
    Expected outputexit 0
    NoPlan
    
    $ topaz run main.tpz · target product 5.21.3
    Expected result

    Expected result

    Execution completes. Exit code 0.

    Expected stdout
    1. NoPlan
    Source evidence

    Menu

    Download