Item.Penalty Item(Penalty)- Модуль
- std.
typeset → - Получатель
- Неприменимо
- Минимальное число аргументов
- 1
- Максимальное число аргументов
- 1
Declaration and parameters
СсылкаДоступность
Включено по умолчанию · Не определено
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.
Получатель
Ограничения параметров
Item.BoxItem, Item.GlueItem, and Item.PenaltyItem preserve their record payloads. Constructing these records and variants does not plan a paragraph or validate its measurements.
BoxItem and GlueItem contribute one measured unit each in their encounter order. Their unitIndex fields must be exactly zero through the unit count minus one. PenaltyItem contributes a boundary without consuming a unit index.
Box.text and Glue.text retain the supplied string, including empty text and multiple Unicode scalars. A measured unit remains indivisible. Unit indices count these records rather than bytes, scalars, or grapheme clusters.
Box.width and Glue.width include trackingAfter. Width and width minus trackingAfter must both be nonnegative. Tracking may be positive, zero, or negative while those two conditions hold.
Each width, tracking amount, stretch, and shrink is a Length<Pt>. Paragraph planning quantizes it through the selected grid. A line span sums its unit widths and removes the final unit's trackingAfter.
Glue.stretch and Glue.shrink are nonnegative adjustment capacities. A box supplies zero capacity. The selected cost and justification policies determine how capacities participate in planning.
Positive capacity does not itself insert text or change the input records. Unjustified planning performs no distributed adjustment. Text trimming and model-specific glue treatment follow the PlanLine and paragraph contracts.
breakParagraph returns InvalidInput for a noncontiguous unitIndex, a negative width or capacity, or a negative width before tracking. Validation applies even when a later candidate would discard that unit.
The function uses the supplied measurements without shaping the text again. It does not reorder or mutate the caller's item array or its records.
Связанное правило · Preserve measured units and validate their physical extents →Результат
Эффекты
Ошибки
Result and effects
СсылкаWraps a Penalty without consuming a unit index. Its unitEnd selects the boundary independently of array position.
Why
СсылкаThe record keeps source identity, measured geometry, and boundary policy explicit at the paragraph planning call.
Resolved contracts
СсылкаRelated entries
СсылкаPreserve measured units and validate their physical extents
СсылкаPreserve measured units and validate their physical extents
Item.BoxItem, Item.GlueItem, and Item.PenaltyItem preserve their record payloads. Constructing these records and variants does not plan a paragraph or validate its measurements.
BoxItem and GlueItem contribute one measured unit each in their encounter order. Their unitIndex fields must be exactly zero through the unit count minus one. PenaltyItem contributes a boundary without consuming a unit index.
Box.text and Glue.text retain the supplied string, including empty text and multiple Unicode scalars. A measured unit remains indivisible. Unit indices count these records rather than bytes, scalars, or grapheme clusters.
Box.width and Glue.width include trackingAfter. Width and width minus trackingAfter must both be nonnegative. Tracking may be positive, zero, or negative while those two conditions hold.
Each width, tracking amount, stretch, and shrink is a Length<Pt>. Paragraph planning quantizes it through the selected grid. A line span sums its unit widths and removes the final unit's trackingAfter.
Glue.stretch and Glue.shrink are nonnegative adjustment capacities. A box supplies zero capacity. The selected cost and justification policies determine how capacities participate in planning.
Positive capacity does not itself insert text or change the input records. Unjustified planning performs no distributed adjustment. Text trimming and model-specific glue treatment follow the PlanLine and paragraph contracts.
breakParagraph returns InvalidInput for a noncontiguous unitIndex, a negative width or capacity, or a negative width before tracking. Validation applies even when a later candidate would discard that unit.
The function uses the supplied measurements without shaping the text again. It does not reorder or mutate the caller's item array or its records.
Причина
Measured text already has a source order and physical advances. Preserving those units keeps line breaking compatible with shaping. Explicit tracking and capacities give every planner the same measured input.
Keep measured units and signed tracking in source order
Ссылкаimport std.typeset as tsimport std.iolet items: Array<ts.Item> = [ts.Item.PenaltyItem(ts.Penalty { unitEnd: 3, width: 0pt, rule: ts.BreakRule.Forced(), kind: ts.BreakKind.ForcedEnd(), flagged: false }),ts.Item.BoxItem(ts.Box { unitIndex: 0, text: "AB", width: 3pt, trackingAfter: 1pt }),ts.Item.GlueItem(ts.Glue { unitIndex: 1, text: " ", width: 2pt, trackingAfter: 0.5pt, stretch: 1pt, shrink: 1pt }),ts.Item.BoxItem(ts.Box { unitIndex: 2, text: "C", width: 4pt, trackingAfter: -1pt })]let input = ts.Paragraph {grid: ts.DistanceGrid.MilliPoint(),items: items,geometry: ts.LineGeometry { bodyTarget: 10pt, firstTarget: 10pt, dropCapSpan: 0, dropCapInset: 0pt },justification: ts.JustificationPolicy {mode: ts.JustificationMode.Unjustified(), minGapCount: 0,minLineWidthRatioM: 0, minFinalLineWidthRatioM: None(),maxAdjustment: 0pt, maxGapAdjustment: 0pt, maxGapRatioR: 0,latinSpacing: None(), cjkStretchRatio: 0.0},costModel: ts.CostModel.FixedPoint(),knuthPlass: ts.KnuthPlassPolicy { toleranceR: 100000000, linePenalty: 10, fitnessDemerit: 0, flaggedDemerit: 0, finalFlaggedDemerit: 0 }}match (ts.breakParagraph(input)) {case Ok(result) => {let line = result.optimized.lines[0]io.writeLine("{line.start}:{line.endExclusive}:{line.displayTextScalarLength}")io.writeLine("{line.rawTextWidth == 10pt}:{line.trimmedTextWidth == 10pt}")io.writeLine("{items.length}")match (items[0]) {case PenaltyItem(_) => io.writeLine("penalty first")case _ => io.writeLine("changed input")}}case Err(_) => io.writeLine("unexpected error")}
0:3:4
true:true
4
penalty first
Ожидаемый результат
Ожидаемый результат
Выполнение завершается. Код завершения 0.
0:3:4true:true4penalty first
Keep a zero width unit with empty display text
Ссылкаimport std.typeset as tsimport std.iolet items: Array<ts.Item> = [ts.Item.BoxItem(ts.Box { unitIndex: 0, text: "", width: 0pt, trackingAfter: 0pt }),ts.Item.PenaltyItem(ts.Penalty { unitEnd: 1, width: 0pt, rule: ts.BreakRule.Forced(), kind: ts.BreakKind.ForcedEnd(), flagged: false })]let input = ts.Paragraph {grid: ts.DistanceGrid.MilliPoint(),items: items,geometry: ts.LineGeometry { bodyTarget: 1pt, firstTarget: 1pt, dropCapSpan: 0, dropCapInset: 0pt },justification: ts.JustificationPolicy {mode: ts.JustificationMode.Unjustified(), minGapCount: 0,minLineWidthRatioM: 0, minFinalLineWidthRatioM: None(),maxAdjustment: 0pt, maxGapAdjustment: 0pt, maxGapRatioR: 0,latinSpacing: None(), cjkStretchRatio: 0.0},costModel: ts.CostModel.FixedPoint(),knuthPlass: ts.KnuthPlassPolicy { toleranceR: 100000000, linePenalty: 10, fitnessDemerit: 0, flaggedDemerit: 0, finalFlaggedDemerit: 0 }}match (ts.breakParagraph(input)) {case Ok(result) => {let line = result.optimized.lines[0]io.writeLine("{line.endExclusive}:{line.displayTextScalarLength}:{line.rawTextWidth == 0pt}")}case Err(_) => io.writeLine("unexpected error")}
1:0:true
Ожидаемый результат
Ожидаемый результат
Выполнение завершается. Код завершения 0.
1:0:true
Reject a gap in measured unit indices
Ссылкаimport std.typeset as tsimport std.iolet items: Array<ts.Item> = [ts.Item.BoxItem(ts.Box { unitIndex: 1, text: "a", width: 1pt, trackingAfter: 0pt }),ts.Item.PenaltyItem(ts.Penalty { unitEnd: 1, width: 0pt, rule: ts.BreakRule.Forced(), kind: ts.BreakKind.ForcedEnd(), flagged: false })]let input = ts.Paragraph {grid: ts.DistanceGrid.MilliPoint(),items: items,geometry: ts.LineGeometry { bodyTarget: 10pt, firstTarget: 10pt, dropCapSpan: 0, dropCapInset: 0pt },justification: ts.JustificationPolicy {mode: ts.JustificationMode.Unjustified(), minGapCount: 0,minLineWidthRatioM: 0, minFinalLineWidthRatioM: None(),maxAdjustment: 0pt, maxGapAdjustment: 0pt, maxGapRatioR: 0,latinSpacing: None(), cjkStretchRatio: 0.0},costModel: ts.CostModel.FixedPoint(),knuthPlass: ts.KnuthPlassPolicy { toleranceR: 100000000, linePenalty: 10, fitnessDemerit: 0, flaggedDemerit: 0, finalFlaggedDemerit: 0 }}match (ts.breakParagraph(input)) {case Err(InvalidInput(_)) => io.writeLine("InvalidInput")case _ => io.writeLine("unexpected result")}
InvalidInput
Ожидаемый результат
Ожидаемый результат
Выполнение завершается. Код завершения 0.
InvalidInput
Reject negative glue stretch and shrink
Ссылкаimport std.typeset as tsimport std.iofunction report(items: Array<ts.Item>) -> () {let input = ts.Paragraph {grid: ts.DistanceGrid.MilliPoint(),items: items,geometry: ts.LineGeometry { bodyTarget: 10pt, firstTarget: 10pt, dropCapSpan: 0, dropCapInset: 0pt },justification: ts.JustificationPolicy {mode: ts.JustificationMode.Unjustified(), minGapCount: 0,minLineWidthRatioM: 0, minFinalLineWidthRatioM: None(),maxAdjustment: 0pt, maxGapAdjustment: 0pt, maxGapRatioR: 0,latinSpacing: None(), cjkStretchRatio: 0.0},costModel: ts.CostModel.FixedPoint(),knuthPlass: ts.KnuthPlassPolicy { toleranceR: 100000000, linePenalty: 10, fitnessDemerit: 0, flaggedDemerit: 0, finalFlaggedDemerit: 0 }}match (ts.breakParagraph(input)) {case Err(InvalidInput(_)) => io.writeLine("InvalidInput")case _ => io.writeLine("unexpected result")}}report([ts.Item.GlueItem(ts.Glue { unitIndex: 0, text: " ", width: 1pt, trackingAfter: 0pt, stretch: -1pt, shrink: 0pt }), ts.Item.PenaltyItem(ts.Penalty { unitEnd: 1, width: 0pt, rule: ts.BreakRule.Forced(), kind: ts.BreakKind.ForcedEnd(), flagged: false })])report([ts.Item.GlueItem(ts.Glue { unitIndex: 0, text: " ", width: 1pt, trackingAfter: 0pt, stretch: 0pt, shrink: -1pt }), ts.Item.PenaltyItem(ts.Penalty { unitEnd: 1, width: 0pt, rule: ts.BreakRule.Forced(), kind: ts.BreakKind.ForcedEnd(), flagged: false })])
InvalidInput
InvalidInput
Ожидаемый результат
Ожидаемый результат
Выполнение завершается. Код завершения 0.
InvalidInputInvalidInput
Reject negative widths and negative extents before tracking
Ссылкаimport std.typeset as tsimport std.iofunction report(items: Array<ts.Item>) -> () {let input = ts.Paragraph {grid: ts.DistanceGrid.MilliPoint(),items: items,geometry: ts.LineGeometry { bodyTarget: 10pt, firstTarget: 10pt, dropCapSpan: 0, dropCapInset: 0pt },justification: ts.JustificationPolicy {mode: ts.JustificationMode.Unjustified(), minGapCount: 0,minLineWidthRatioM: 0, minFinalLineWidthRatioM: None(),maxAdjustment: 0pt, maxGapAdjustment: 0pt, maxGapRatioR: 0,latinSpacing: None(), cjkStretchRatio: 0.0},costModel: ts.CostModel.FixedPoint(),knuthPlass: ts.KnuthPlassPolicy { toleranceR: 100000000, linePenalty: 10, fitnessDemerit: 0, flaggedDemerit: 0, finalFlaggedDemerit: 0 }}match (ts.breakParagraph(input)) {case Err(InvalidInput(_)) => io.writeLine("InvalidInput")case _ => io.writeLine("unexpected result")}}report([ts.Item.BoxItem(ts.Box { unitIndex: 0, text: "a", width: -1pt, trackingAfter: 0pt }), ts.Item.PenaltyItem(ts.Penalty { unitEnd: 1, width: 0pt, rule: ts.BreakRule.Forced(), kind: ts.BreakKind.ForcedEnd(), flagged: false })])report([ts.Item.GlueItem(ts.Glue { unitIndex: 0, text: " ", width: -1pt, trackingAfter: 0pt, stretch: 0pt, shrink: 0pt }), ts.Item.PenaltyItem(ts.Penalty { unitEnd: 1, width: 0pt, rule: ts.BreakRule.Forced(), kind: ts.BreakKind.ForcedEnd(), flagged: false })])report([ts.Item.BoxItem(ts.Box { unitIndex: 0, text: "a", width: 1pt, trackingAfter: 2pt }), ts.Item.PenaltyItem(ts.Penalty { unitEnd: 1, width: 0pt, rule: ts.BreakRule.Forced(), kind: ts.BreakKind.ForcedEnd(), flagged: false })])report([ts.Item.GlueItem(ts.Glue { unitIndex: 0, text: " ", width: 1pt, trackingAfter: 2pt, stretch: 0pt, shrink: 0pt }), ts.Item.PenaltyItem(ts.Penalty { unitEnd: 1, width: 0pt, rule: ts.BreakRule.Forced(), kind: ts.BreakKind.ForcedEnd(), flagged: false })])
InvalidInput
InvalidInput
InvalidInput
InvalidInput
Ожидаемый результат
Ожидаемый результат
Выполнение завершается. Код завершения 0.
InvalidInputInvalidInputInvalidInputInvalidInput