Break Cluster. text: string- Module
- std.
typeset - Receiver
- Break
Cluster - Minimum arity
- 0
- Maximum arity
- 0
Declaration and parameters
LinkAvailability
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
- compiler/crates/topaz_resolve/src/std/typeset/model.tpz at
b48527d0a174· 31 - compiler/crates/topaz_resolve/src/stdlib.rs at
b48527d0a174· 40
Receiver
BreakCluster
Parameter constraints
classifyBreaks reads measured clusters in array order and returns Result<Array<Break. It does not shape text, normalize strings, split a cluster, or change any supplied record or array.
Each BreakCluster.text is the scalar string for one indivisible measured unit. Empty text still occupies one cluster index. advance includes trackingAfter. A span width sums its advances and removes the trackingAfter of its final cluster.
advance and advance minus trackingAfter must be nonnegative point lengths. Zero advance and signed trackingAfter are accepted. Invalid extents return TypesetError.InvalidInput. Length arithmetic follows the common Length contract.
classifyBreaks sums stored point ticks and compares them with the stored point targets. It has no DistanceGrid argument and does not quantize to a paragraph grid. Exact equality with a target counts as fitting.
boundaryAllowed has exactly one entry for each cluster. Entry i governs the boundary after cluster i. The last entry must be true for nonempty input. A wrong mask length or a false last entry returns TypesetError.InvalidInput.
Validation checks mask length and terminal permission, word targets, forbidBefore, forbidAfter, generated hyphen indices, and measured extents in that order. Array checks visit entries in input order. Unicode mandatory crossings are checked before boundary conflicts are visited in increasing cluster order. An empty result follows successful structural and policy validation.
An empty cluster array with a valid empty boundary mask returns Ok with an empty opportunity array. It does not create a synthetic unit or terminal opportunity.
Successful nonempty results contain increasing, unique unitEnd values from one through the cluster count. unitEnd is an exclusive cluster index rather than a byte or scalar offset. The final opportunity has unitEnd equal to the cluster count and kind ForcedEnd.
Repeated calls with equal cluster values and equal policies produce the same ordered opportunities and categories. Validation and classification do not read host locale, perform I/O, invoke caller callbacks, or mutate input values. Argument expressions use the ordinary language evaluation order.
A BreakOpportunity carries a boundary and its category. It does not carry a penalty width or BreakRule. A caller preserving mandatory boundaries maps every ForcedEnd opportunity to a Forced penalty before calling breakParagraph.
Related rule: Classify measured clusters into an ordered boundary sequenceResult
The declared result type is string.
Effects
Failures
Result and effects
LinkSelect this field from a value of its named type without call parentheses.
The string is preserved without normalization or segmentation. It can contain several scalars or be empty. Every supplied cluster still has one position in the cluster array.
Why
LinkThe cluster text preserves the measured unit that shaping supplied. Break classification examines its characters while the boundary mask prevents a line break from splitting a unit that must stay together.
Resolved contracts
LinkRelated entries
LinkClassify measured clusters into an ordered boundary sequence
LinkClassify measured clusters into an ordered boundary sequence
classifyBreaks reads measured clusters in array order and returns Result<Array<Break. It does not shape text, normalize strings, split a cluster, or change any supplied record or array.
Each BreakCluster.text is the scalar string for one indivisible measured unit. Empty text still occupies one cluster index. advance includes trackingAfter. A span width sums its advances and removes the trackingAfter of its final cluster.
advance and advance minus trackingAfter must be nonnegative point lengths. Zero advance and signed trackingAfter are accepted. Invalid extents return TypesetError.InvalidInput. Length arithmetic follows the common Length contract.
classifyBreaks sums stored point ticks and compares them with the stored point targets. It has no DistanceGrid argument and does not quantize to a paragraph grid. Exact equality with a target counts as fitting.
boundaryAllowed has exactly one entry for each cluster. Entry i governs the boundary after cluster i. The last entry must be true for nonempty input. A wrong mask length or a false last entry returns TypesetError.InvalidInput.
Validation checks mask length and terminal permission, word targets, forbidBefore, forbidAfter, generated hyphen indices, and measured extents in that order. Array checks visit entries in input order. Unicode mandatory crossings are checked before boundary conflicts are visited in increasing cluster order. An empty result follows successful structural and policy validation.
An empty cluster array with a valid empty boundary mask returns Ok with an empty opportunity array. It does not create a synthetic unit or terminal opportunity.
Successful nonempty results contain increasing, unique unitEnd values from one through the cluster count. unitEnd is an exclusive cluster index rather than a byte or scalar offset. The final opportunity has unitEnd equal to the cluster count and kind ForcedEnd.
Repeated calls with equal cluster values and equal policies produce the same ordered opportunities and categories. Validation and classification do not read host locale, perform I/O, invoke caller callbacks, or mutate input values. Argument expressions use the ordinary language evaluation order.
A BreakOpportunity carries a boundary and its category. It does not carry a penalty width or BreakRule. A caller preserving mandatory boundaries maps every ForcedEnd opportunity to a Forced penalty before calling breakParagraph.
Why
A measured cluster is the unit that shaping can safely keep together. Exclusive indices connect classification to paragraph items without converting through text offsets. A complete terminal boundary and deterministic order make the output suitable for reproducible layout.
Source evidence
- compiler/crates/topaz_resolve/src/std/typeset/model.tpz at
f3807a34248e· 24-32 - compiler/crates/topaz_resolve/src/std/typeset/breaks.tpz at
f3807a34248e· 1-94 - compiler/crates/topaz_resolve/src/std/typeset/measure.tpz at
f3807a34248e· 24-25 - compiler/crates/topaz_resolve/src/std/typeset/measure.tpz at
f3807a34248e· 52-66 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
f3807a34248e· 691-713 - compiler/crates/topaz_self_frontend/topaz/checker/call_complete.tpz at
f3807a34248e· 1319-1340 -
topaz.stdlib.contract.typeset-break-inputsatworking-tree
Classify atomic clusters in repeatable boundary order
Linkimport std.typeset as tsimport std.ioimport std.testlet clusters = [ts.BreakCluster { text: "한", advance: 1pt, trackingAfter: 0pt }, ts.BreakCluster { text: "글", advance: 1pt, trackingAfter: 0pt }]let selected = ts.BreakPolicy {mode: ts.BreakMode.Character(),rules: ts.KinsokuRules.AtlasDefault(),forbidBefore: [],forbidAfter: [],boundaryAllowed: [true, true],generatedHyphenEnds: [],protectFittingLatin: false,preserveShortWords: false,narrowestWordTarget: 0pt,bodyWordTarget: 0pt}for pass in ([0, 1]) {let breaks = test.assertOk(ts.classifyBreaks(clusters, selected))for boundary in (breaks) {let category = match (boundary.kind) {case CjkCluster() => "CJK"case ForcedEnd() => "end"case _ => "unexpected kind"}io.writeLine("{pass} {boundary.unitEnd} {category}")}}io.writeLine(clusters[0].text)
0 1 CJK 0 2 end 1 1 CJK 1 2 end 한
Expected result
Expected result
Execution completes. Exit code 0.
0 1 CJK0 2 end1 1 CJK1 2 end한
Source evidence
- compiler/crates/topaz_resolve/src/std/typeset/model.tpz at
f3807a34248e· 24-32 - compiler/crates/topaz_resolve/src/std/typeset/breaks.tpz at
f3807a34248e· 1-94 - compiler/crates/topaz_resolve/src/std/typeset/measure.tpz at
f3807a34248e· 24-25 - compiler/crates/topaz_resolve/src/std/typeset/measure.tpz at
f3807a34248e· 52-66 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
f3807a34248e· 691-713 - compiler/crates/topaz_self_frontend/topaz/checker/call_complete.tpz at
f3807a34248e· 1319-1340 -
topaz.stdlib.contract.typeset-break-inputsatworking-tree
Classify an empty cluster sequence
Linkimport std.typeset as tsimport std.ioimport std.testlet clusters: Array<ts.BreakCluster> = []let selected = ts.BreakPolicy {mode: ts.BreakMode.Character(),rules: ts.KinsokuRules.AtlasDefault(),forbidBefore: [],forbidAfter: [],boundaryAllowed: [],generatedHyphenEnds: [],protectFittingLatin: false,preserveShortWords: false,narrowestWordTarget: 0pt,bodyWordTarget: 0pt}let breaks = test.assertOk(ts.classifyBreaks(clusters, selected))io.writeLine("{breaks.length}")
0
Expected result
Expected result
Execution completes. Exit code 0.
0
Source evidence
- compiler/crates/topaz_resolve/src/std/typeset/model.tpz at
f3807a34248e· 24-32 - compiler/crates/topaz_resolve/src/std/typeset/breaks.tpz at
f3807a34248e· 1-94 - compiler/crates/topaz_resolve/src/std/typeset/measure.tpz at
f3807a34248e· 24-25 - compiler/crates/topaz_resolve/src/std/typeset/measure.tpz at
f3807a34248e· 52-66 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
f3807a34248e· 691-713 - compiler/crates/topaz_self_frontend/topaz/checker/call_complete.tpz at
f3807a34248e· 1319-1340 -
topaz.stdlib.contract.typeset-break-inputsatworking-tree
Reject a mask with the wrong number of entries
Linkimport std.typeset as tsimport std.ioimport std.testfunction outcome(value: Result<Array<ts.BreakOpportunity>, ts.TypesetError>) -> string {match (value) {case Ok(_) => "Ok"case Err(InvalidInput(_)) => "InvalidInput"case Err(InvalidPolicy(_)) => "InvalidPolicy"case Err(_) => "unexpected error"}}let clusters = [ts.BreakCluster { text: "a", advance: 1pt, trackingAfter: 0pt }]let selected = ts.BreakPolicy {mode: ts.BreakMode.Character(),rules: ts.KinsokuRules.AtlasDefault(),forbidBefore: [],forbidAfter: [],boundaryAllowed: [],generatedHyphenEnds: [],protectFittingLatin: false,preserveShortWords: false,narrowestWordTarget: 0pt,bodyWordTarget: 0pt}io.writeLine(outcome(ts.classifyBreaks(clusters, selected)))
InvalidInput
Expected result
Expected result
Execution completes. Exit code 0.
InvalidInput
Source evidence
- compiler/crates/topaz_resolve/src/std/typeset/model.tpz at
f3807a34248e· 24-32 - compiler/crates/topaz_resolve/src/std/typeset/breaks.tpz at
f3807a34248e· 1-94 - compiler/crates/topaz_resolve/src/std/typeset/measure.tpz at
f3807a34248e· 24-25 - compiler/crates/topaz_resolve/src/std/typeset/measure.tpz at
f3807a34248e· 52-66 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
f3807a34248e· 691-713 - compiler/crates/topaz_self_frontend/topaz/checker/call_complete.tpz at
f3807a34248e· 1319-1340 -
topaz.stdlib.contract.typeset-break-inputsatworking-tree
Reject negative measured and untracked cluster extents
Linkimport std.typeset as tsimport std.ioimport std.testfunction outcome(value: Result<Array<ts.BreakOpportunity>, ts.TypesetError>) -> string {match (value) {case Ok(_) => "Ok"case Err(InvalidInput(_)) => "InvalidInput"case Err(InvalidPolicy(_)) => "InvalidPolicy"case Err(_) => "unexpected error"}}let selected = ts.BreakPolicy {mode: ts.BreakMode.Character(),rules: ts.KinsokuRules.AtlasDefault(),forbidBefore: [],forbidAfter: [],boundaryAllowed: [true],generatedHyphenEnds: [],protectFittingLatin: false,preserveShortWords: false,narrowestWordTarget: 0pt,bodyWordTarget: 0pt}io.writeLine(outcome(ts.classifyBreaks([ts.BreakCluster { text: "a", advance: -1pt, trackingAfter: 0pt }], selected)))io.writeLine(outcome(ts.classifyBreaks([ts.BreakCluster { text: "b", advance: 1pt, trackingAfter: 2pt }], selected)))
InvalidInput InvalidInput
Expected result
Expected result
Execution completes. Exit code 0.
InvalidInputInvalidInput
Source evidence
- compiler/crates/topaz_resolve/src/std/typeset/model.tpz at
f3807a34248e· 24-32 - compiler/crates/topaz_resolve/src/std/typeset/breaks.tpz at
f3807a34248e· 1-94 - compiler/crates/topaz_resolve/src/std/typeset/measure.tpz at
f3807a34248e· 24-25 - compiler/crates/topaz_resolve/src/std/typeset/measure.tpz at
f3807a34248e· 52-66 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
f3807a34248e· 691-713 - compiler/crates/topaz_self_frontend/topaz/checker/call_complete.tpz at
f3807a34248e· 1319-1340 -
topaz.stdlib.contract.typeset-break-inputsatworking-tree
Reject a masked paragraph end in every ruleset
Linkimport std.typeset as tsimport std.ioimport std.testfunction outcome(value: Result<Array<ts.BreakOpportunity>, ts.TypesetError>) -> string {match (value) {case Ok(_) => "Ok"case Err(InvalidInput(_)) => "InvalidInput"case Err(InvalidPolicy(_)) => "InvalidPolicy"case Err(_) => "unexpected error"}}let clusters = [ts.BreakCluster { text: "a", advance: 1pt, trackingAfter: 0pt }]let atlas = ts.BreakPolicy {mode: ts.BreakMode.Character(),rules: ts.KinsokuRules.AtlasDefault(),forbidBefore: [],forbidAfter: [],boundaryAllowed: [false],generatedHyphenEnds: [],protectFittingLatin: false,preserveShortWords: false,narrowestWordTarget: 0pt,bodyWordTarget: 0pt}let unicode = ts.BreakPolicy {mode: ts.BreakMode.Character(),rules: ts.KinsokuRules.Unicode16Ja(),forbidBefore: [],forbidAfter: [],boundaryAllowed: [false],generatedHyphenEnds: [],protectFittingLatin: false,preserveShortWords: false,narrowestWordTarget: 0pt,bodyWordTarget: 0pt}io.writeLine(outcome(ts.classifyBreaks(clusters, atlas)))io.writeLine(outcome(ts.classifyBreaks(clusters, unicode)))
InvalidInput InvalidInput
Expected result
Expected result
Execution completes. Exit code 0.
InvalidInputInvalidInput
Source evidence
- compiler/crates/topaz_resolve/src/std/typeset/model.tpz at
f3807a34248e· 24-32 - compiler/crates/topaz_resolve/src/std/typeset/breaks.tpz at
f3807a34248e· 1-94 - compiler/crates/topaz_resolve/src/std/typeset/measure.tpz at
f3807a34248e· 24-25 - compiler/crates/topaz_resolve/src/std/typeset/measure.tpz at
f3807a34248e· 52-66 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
f3807a34248e· 691-713 - compiler/crates/topaz_self_frontend/topaz/checker/call_complete.tpz at
f3807a34248e· 1319-1340 -
topaz.stdlib.contract.typeset-break-inputsatworking-tree
Keep exact point measurements at the classifier boundary
Linkimport std.typeset as tsimport std.testimport std.iolet clusters = [ts.BreakCluster { text: "a", advance: 0.5002pt, trackingAfter: 0pt },ts.BreakCluster { text: "b", advance: 0.5002pt, trackingAfter: 0pt }]let policy = ts.BreakPolicy {mode: ts.BreakMode.Word(), rules: ts.KinsokuRules.AtlasDefault(),forbidBefore: [], forbidAfter: [], boundaryAllowed: [true, true],generatedHyphenEnds: [], protectFittingLatin: false, preserveShortWords: false,narrowestWordTarget: 0pt, bodyWordTarget: 1pt}let result = test.assertOk(ts.classifyBreaks(clusters, policy))for boundary in (result) {io.writeLine("{boundary.unitEnd}")}
1 2
Expected result
Expected result
Execution completes. Exit code 0.
12
Source evidence
- compiler/crates/topaz_resolve/src/std/typeset/model.tpz at
f3807a34248e· 24-32 - compiler/crates/topaz_resolve/src/std/typeset/breaks.tpz at
f3807a34248e· 1-94 - compiler/crates/topaz_resolve/src/std/typeset/measure.tpz at
f3807a34248e· 24-25 - compiler/crates/topaz_resolve/src/std/typeset/measure.tpz at
f3807a34248e· 52-66 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
f3807a34248e· 691-713 - compiler/crates/topaz_self_frontend/topaz/checker/call_complete.tpz at
f3807a34248e· 1319-1340 -
topaz.stdlib.contract.typeset-break-inputsatworking-tree