Justification Policy. min Line Width Ratio M: int- Модуль
- std.
typeset → - Получатель
- Justification
Policy - Минимальное число аргументов
- 0
- Максимальное число аргументов
- 0
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.
Получатель
JustificationPolicy
Ограничения параметров
JustificationPolicy describes how FixedPoint scores a measured line. It does not change text, insert glyphs, or create break opportunities. Constructing the record does not run validation. breakParagraph validates it before measuring items.
minGapCount, minLineWidthRatioM, maxGapRatioR, and a present minFinalLineWidthRatioM must be nonnegative. maxAdjustment and maxGapAdjustment must be nonnegative point lengths. cjkStretchRatio must be finite and nonnegative. Violations return TypesetError.InvalidPolicy with an explanatory string.
The width ratio fields use 1000 for one whole target width. maxGapRatioR uses 100000000 for a ratio of one. These ratios have no additional upper bound. A threshold above the attainable width can increase cost without making the policy malformed.
A present LatinSpacing value follows its typed length contract. minWordSpaceRatio ranges from 0.8 through 1.0. maxWordSpaceRatio ranges from 1.0 through 1.33. maxLetterSpacingEm ranges from 0em through 0.015em and fontSizePt is positive. Both float ratios must be finite. Invalid values return TypesetError.InvalidPolicy even when the selected model does not use their capacities.
Unjustified contributes zero justification cost and supplies no inferred spacing capacity. LatinWordSpace scores eligible word spaces. CjkInterCharacter also recognizes eligible boundaries between single CJK units. All policy fields are validated in every mode.
KnuthPlass computes its adjustment ratio from the supplied Glue stretch and shrink values. JustificationPolicy does not alter that ratio or its demerits. The policy still undergoes validation. The KnuthPlass policy defines tolerance and line costs.
For FixedPoint, a present LatinSpacing value takes precedence when the trimmed line contains Latin letter units without other alphabetic scripts, or contains a recognized single CJK unit. The inferred capacity replaces the fallback minimum gap count, minimum nonfinal width, total adjustment, per gap adjustment, and gap ratio tests for that line.
Inferred shrink capacity is the floor of the total U+0020 unit width multiplied by one minus minWordSpaceRatio. Stretch capacity adds three separately evaluated contributions. They are the floor of that space width multiplied by maxWordSpaceRatio minus one, the eligible Latin letter gap count multiplied by the resolved typed letter maximum, and the floor of the eligible CJK width multiplied by cjkStretchRatio. The CJK contribution is zero in LatinWordSpace mode.
An inferred Latin letter unit contains an Alphabetic scalar and has every scalar in U+0041 through U+024F, U+0300 through U+036F, or U+1E00 through U+1EFF. A letter gap joins two adjacent such units. A CJK capacity contribution uses the left width of adjacent single CJK units. Resolve the typed letter maximum with the explicit font size before grid conversion. Preserve each independent floor for dimensionless word and CJK ratios.
Without an inferred capacity, word gaps are units whose complete text is U+0020. CJK gaps join adjacent recognized single CJK units and count both sides of an intervening U+0020 or U+00A0 unit. Recognized CJK scalars are U+1100 through U+11FF, U+3130 through U+318F, U+3400 through U+4DBF, U+4E00 through U+9FFF, U+AC00 through U+D7A3, and U+F900 through U+FAFF. Punctuation does not provide a CJK gap.
The fallback nonfinal calculation first scores a line below minLineWidthRatioM. It then checks the total positive adjustment against maxAdjustment. LatinWordSpace uses minGapCount and maxGapAdjustment on word gaps. CjkInterCharacter uses word gaps when present and otherwise uses CJK gaps, minGapCount, maxGapAdjustment, and maxGapRatioR. Falling short raises the justification cost rather than returning an input error.
FixedPoint calculations use the millipoint grid. A total positive adjustment of at most one millipoint has zero fallback cost. For a larger adjustment, maxAdjustment is the exact total bound. Per gap checks tolerate one millipoint per gap. The CJK ratio comparison tolerates 100000 units of maxGapRatioR. These allowances do not add spacing to the returned text.
For a final FixedPoint line in a justified mode, None() in minFinalLineWidthRatioM contributes zero justification cost. Some supplies a minimum final width ratio and applies to that final line. It never replaces the nonfinal checks. Compare the attainable width after the permitted positive adjustment with the target times the ratio divided by 1000, rounded halfway upward.
For that final threshold, attainable width adds inferred stretch when available. Otherwise it adds the smaller of maxAdjustment and the word gap count times maxGapAdjustment. Meeting the threshold contributes zero. A shortfall contributes 25000000000 plus the halfway upward rounded shortfall times 1000000 divided by the target, multiplied by 1000000.
The optimized FixedPoint planner can try a pass that requires bounded fill before its ordinary pass. The paragraph plan reports whether that pass succeeded. A returned plan does not distribute the requested adjustment into the original units. Consumers use the reported widths and the selected policy when rendering.
When the exact nonfinal minimum width comparison fails, the scoring shortfall is target minus natural width, with a minimum of zero. Scale that shortfall by 1000000, divide by target with halfway upward rounding, then multiply by 1000000 for LatinWordSpace or 100000 for CjkInterCharacter. Add 25000000000 to this nonnegative contribution. These operations use checked arithmetic.
For every FixedPoint justification comparison, natural width is the trimmed text width plus selectedPenaltyWidth. The target remains PlanLine.target. A selected insertion supplies no word gap, CJK gap, letter gap, stretch, or shrink capacity.
Связанное правило · Score justification with explicit policy precedence →Результат
The declared result type is int.
Эффекты
Ошибки
Result and effects
СсылкаSelect this field from a value of its named type without call parentheses.
Set the minimum natural nonfinal width ratio for fallback scoring, using 1000 for one target width.
Why
СсылкаPolicy validation and explicit precedence give every field one defined effect.
Resolved contracts
СсылкаRelated entries
СсылкаScore justification with explicit policy precedence
СсылкаScore justification with explicit policy precedence
JustificationPolicy describes how FixedPoint scores a measured line. It does not change text, insert glyphs, or create break opportunities. Constructing the record does not run validation. breakParagraph validates it before measuring items.
minGapCount, minLineWidthRatioM, maxGapRatioR, and a present minFinalLineWidthRatioM must be nonnegative. maxAdjustment and maxGapAdjustment must be nonnegative point lengths. cjkStretchRatio must be finite and nonnegative. Violations return TypesetError.InvalidPolicy with an explanatory string.
The width ratio fields use 1000 for one whole target width. maxGapRatioR uses 100000000 for a ratio of one. These ratios have no additional upper bound. A threshold above the attainable width can increase cost without making the policy malformed.
A present LatinSpacing value follows its typed length contract. minWordSpaceRatio ranges from 0.8 through 1.0. maxWordSpaceRatio ranges from 1.0 through 1.33. maxLetterSpacingEm ranges from 0em through 0.015em and fontSizePt is positive. Both float ratios must be finite. Invalid values return TypesetError.InvalidPolicy even when the selected model does not use their capacities.
Unjustified contributes zero justification cost and supplies no inferred spacing capacity. LatinWordSpace scores eligible word spaces. CjkInterCharacter also recognizes eligible boundaries between single CJK units. All policy fields are validated in every mode.
KnuthPlass computes its adjustment ratio from the supplied Glue stretch and shrink values. JustificationPolicy does not alter that ratio or its demerits. The policy still undergoes validation. The KnuthPlass policy defines tolerance and line costs.
For FixedPoint, a present LatinSpacing value takes precedence when the trimmed line contains Latin letter units without other alphabetic scripts, or contains a recognized single CJK unit. The inferred capacity replaces the fallback minimum gap count, minimum nonfinal width, total adjustment, per gap adjustment, and gap ratio tests for that line.
Inferred shrink capacity is the floor of the total U+0020 unit width multiplied by one minus minWordSpaceRatio. Stretch capacity adds three separately evaluated contributions. They are the floor of that space width multiplied by maxWordSpaceRatio minus one, the eligible Latin letter gap count multiplied by the resolved typed letter maximum, and the floor of the eligible CJK width multiplied by cjkStretchRatio. The CJK contribution is zero in LatinWordSpace mode.
An inferred Latin letter unit contains an Alphabetic scalar and has every scalar in U+0041 through U+024F, U+0300 through U+036F, or U+1E00 through U+1EFF. A letter gap joins two adjacent such units. A CJK capacity contribution uses the left width of adjacent single CJK units. Resolve the typed letter maximum with the explicit font size before grid conversion. Preserve each independent floor for dimensionless word and CJK ratios.
Without an inferred capacity, word gaps are units whose complete text is U+0020. CJK gaps join adjacent recognized single CJK units and count both sides of an intervening U+0020 or U+00A0 unit. Recognized CJK scalars are U+1100 through U+11FF, U+3130 through U+318F, U+3400 through U+4DBF, U+4E00 through U+9FFF, U+AC00 through U+D7A3, and U+F900 through U+FAFF. Punctuation does not provide a CJK gap.
The fallback nonfinal calculation first scores a line below minLineWidthRatioM. It then checks the total positive adjustment against maxAdjustment. LatinWordSpace uses minGapCount and maxGapAdjustment on word gaps. CjkInterCharacter uses word gaps when present and otherwise uses CJK gaps, minGapCount, maxGapAdjustment, and maxGapRatioR. Falling short raises the justification cost rather than returning an input error.
FixedPoint calculations use the millipoint grid. A total positive adjustment of at most one millipoint has zero fallback cost. For a larger adjustment, maxAdjustment is the exact total bound. Per gap checks tolerate one millipoint per gap. The CJK ratio comparison tolerates 100000 units of maxGapRatioR. These allowances do not add spacing to the returned text.
For a final FixedPoint line in a justified mode, None() in minFinalLineWidthRatioM contributes zero justification cost. Some supplies a minimum final width ratio and applies to that final line. It never replaces the nonfinal checks. Compare the attainable width after the permitted positive adjustment with the target times the ratio divided by 1000, rounded halfway upward.
For that final threshold, attainable width adds inferred stretch when available. Otherwise it adds the smaller of maxAdjustment and the word gap count times maxGapAdjustment. Meeting the threshold contributes zero. A shortfall contributes 25000000000 plus the halfway upward rounded shortfall times 1000000 divided by the target, multiplied by 1000000.
The optimized FixedPoint planner can try a pass that requires bounded fill before its ordinary pass. The paragraph plan reports whether that pass succeeded. A returned plan does not distribute the requested adjustment into the original units. Consumers use the reported widths and the selected policy when rendering.
When the exact nonfinal minimum width comparison fails, the scoring shortfall is target minus natural width, with a minimum of zero. Scale that shortfall by 1000000, divide by target with halfway upward rounding, then multiply by 1000000 for LatinWordSpace or 100000 for CjkInterCharacter. Add 25000000000 to this nonnegative contribution. These operations use checked arithmetic.
For every FixedPoint justification comparison, natural width is the trimmed text width plus selectedPenaltyWidth. The target remains PlanLine.target. A selected insertion supplies no word gap, CJK gap, letter gap, stretch, or shrink capacity.
Причина
A caller needs to know which spacing controls determine a line cost. Explicit capacity precedence keeps the two cost models predictable. A distinct final line threshold gives its name one meaning and preserves ordinary nonfinal checks.
Choose a justification mode explicitly
Ссылкаimport std.typeset as tsimport std.iofunction name(mode: ts.JustificationMode) -> string {match (mode) {case Unjustified() => "unjustified"case LatinWordSpace() => "latin"case CjkInterCharacter() => "cjk"}}io.writeLine(name(ts.JustificationMode.Unjustified()))io.writeLine(name(ts.JustificationMode.LatinWordSpace()))io.writeLine(name(ts.JustificationMode.CjkInterCharacter()))
unjustified
latin
cjk
Ожидаемый результат
Ожидаемый результат
Выполнение завершается. Код завершения 0.
unjustifiedlatincjk
Reject a negative gap count even in Unjustified mode
Ссылкаimport std.typeset as tsimport std.iolet items: Array<ts.Item> = [ts.Item.BoxItem(ts.Box { unitIndex: 0, text: "word", width: 10pt, 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: -1,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(InvalidPolicy(_)) => io.writeLine("InvalidPolicy")case _ => io.writeLine("unexpected result")}
InvalidPolicy
Ожидаемый результат
Ожидаемый результат
Выполнение завершается. Код завершения 0.
InvalidPolicy
Reject a negative physical adjustment cap
Ссылкаimport std.typeset as tsimport std.iolet items: Array<ts.Item> = [ts.Item.BoxItem(ts.Box { unitIndex: 0, text: "word", width: 10pt, 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: -1pt, 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(InvalidPolicy(_)) => io.writeLine("InvalidPolicy")case _ => io.writeLine("unexpected result")}
InvalidPolicy
Ожидаемый результат
Ожидаемый результат
Выполнение завершается. Код завершения 0.
InvalidPolicy
Reject a negative final line ratio
Ссылкаimport std.typeset as tsimport std.iolet items: Array<ts.Item> = [ts.Item.BoxItem(ts.Box { unitIndex: 0, text: "word", width: 10pt, 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: Some(-1),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(InvalidPolicy(_)) => io.writeLine("InvalidPolicy")case _ => io.writeLine("unexpected result")}
InvalidPolicy
Ожидаемый результат
Ожидаемый результат
Выполнение завершается. Код завершения 0.
InvalidPolicy
Score an underfilled nonfinal line without changing measured text
Ссылкаimport std.typeset as tsimport std.ioimport std.testfunction sample(justification: ts.JustificationPolicy) -> ts.ParagraphResult {let items: Array<ts.Item> = [ts.Item.BoxItem(ts.Box { unitIndex: 0, text: "word", width: 4pt, trackingAfter: 0pt }),ts.Item.PenaltyItem(ts.Penalty { unitEnd: 1, width: 0pt, rule: ts.BreakRule.Forced(), kind: ts.BreakKind.ForcedEnd(), flagged: false }),ts.Item.BoxItem(ts.Box { unitIndex: 1, text: "next", width: 4pt, trackingAfter: 0pt }),ts.Item.PenaltyItem(ts.Penalty { unitEnd: 2, 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: justification,costModel: ts.CostModel.FixedPoint(),knuthPlass: ts.KnuthPlassPolicy { toleranceR: 100000000, linePenalty: 10, fitnessDemerit: 0, flaggedDemerit: 0, finalFlaggedDemerit: 0 }}test.assertOk(ts.breakParagraph(input))}let natural = sample(ts.JustificationPolicy {mode: ts.JustificationMode.Unjustified(), minGapCount: 0,minLineWidthRatioM: 0, minFinalLineWidthRatioM: None(),maxAdjustment: 0pt, maxGapAdjustment: 0pt, maxGapRatioR: 0,latinSpacing: None(), cjkStretchRatio: 0.0})let justified = sample(ts.JustificationPolicy {mode: ts.JustificationMode.LatinWordSpace(), minGapCount: 1,minLineWidthRatioM: 900, minFinalLineWidthRatioM: None(),maxAdjustment: 2pt, maxGapAdjustment: 1pt, maxGapRatioR: 0,latinSpacing: None(), cjkStretchRatio: 0.0})io.writeLine("{justified.optimized.lines.length}")io.writeLine("{justified.optimized.lines[0].cost > natural.optimized.lines[0].cost}")io.writeLine("{justified.optimized.lines[1].cost == natural.optimized.lines[1].cost}")io.writeLine("{justified.optimized.lines[0].adjustmentRatioR}")
2
true
true
0
Ожидаемый результат
Ожидаемый результат
Выполнение завершается. Код завершения 0.
2truetrue0
Apply the final line threshold to the final line
Ссылкаimport std.typeset as tsimport std.ioimport std.testfunction sample(justification: ts.JustificationPolicy) -> ts.ParagraphResult {let items: Array<ts.Item> = [ts.Item.BoxItem(ts.Box { unitIndex: 0, text: "word", width: 10pt, 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: 20pt, firstTarget: 20pt, dropCapSpan: 0, dropCapInset: 0pt },justification: justification,costModel: ts.CostModel.FixedPoint(),knuthPlass: ts.KnuthPlassPolicy { toleranceR: 100000000, linePenalty: 10, fitnessDemerit: 0, flaggedDemerit: 0, finalFlaggedDemerit: 0 }}test.assertOk(ts.breakParagraph(input))}let unconstrained = sample(ts.JustificationPolicy {mode: ts.JustificationMode.LatinWordSpace(), minGapCount: 0,minLineWidthRatioM: 0, minFinalLineWidthRatioM: None(),maxAdjustment: 0pt, maxGapAdjustment: 0pt, maxGapRatioR: 0,latinSpacing: None(), cjkStretchRatio: 0.0})let constrained = sample(ts.JustificationPolicy {mode: ts.JustificationMode.LatinWordSpace(), minGapCount: 0,minLineWidthRatioM: 0, minFinalLineWidthRatioM: Some(1000),maxAdjustment: 0pt, maxGapAdjustment: 0pt, maxGapRatioR: 0,latinSpacing: None(), cjkStretchRatio: 0.0})io.writeLine("{constrained.optimized.lines[0].cost > unconstrained.optimized.lines[0].cost}")
true
Ожидаемый результат
Ожидаемый результат
Выполнение завершается. Код завершения 0.
true
Keep the final line threshold out of nonfinal scoring
Ссылкаimport std.typeset as tsimport std.ioimport std.testfunction sample(justification: ts.JustificationPolicy) -> ts.ParagraphResult {let items: Array<ts.Item> = [ts.Item.BoxItem(ts.Box { unitIndex: 0, text: "word", width: 4pt, trackingAfter: 0pt }),ts.Item.PenaltyItem(ts.Penalty { unitEnd: 1, width: 0pt, rule: ts.BreakRule.Forced(), kind: ts.BreakKind.ForcedEnd(), flagged: false }),ts.Item.BoxItem(ts.Box { unitIndex: 1, text: "next", width: 4pt, trackingAfter: 0pt }),ts.Item.PenaltyItem(ts.Penalty { unitEnd: 2, 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: justification,costModel: ts.CostModel.FixedPoint(),knuthPlass: ts.KnuthPlassPolicy { toleranceR: 100000000, linePenalty: 10, fitnessDemerit: 0, flaggedDemerit: 0, finalFlaggedDemerit: 0 }}test.assertOk(ts.breakParagraph(input))}let ordinary = sample(ts.JustificationPolicy {mode: ts.JustificationMode.LatinWordSpace(), minGapCount: 1,minLineWidthRatioM: 0, minFinalLineWidthRatioM: None(),maxAdjustment: 0pt, maxGapAdjustment: 0pt, maxGapRatioR: 0,latinSpacing: None(), cjkStretchRatio: 0.0})let finalZero = sample(ts.JustificationPolicy {mode: ts.JustificationMode.LatinWordSpace(), minGapCount: 1,minLineWidthRatioM: 0, minFinalLineWidthRatioM: Some(0),maxAdjustment: 0pt, maxGapAdjustment: 0pt, maxGapRatioR: 0,latinSpacing: None(), cjkStretchRatio: 0.0})io.writeLine("{ordinary.optimized.lines[0].cost == finalZero.optimized.lines[0].cost}")
true
Ожидаемый результат
Ожидаемый результат
Выполнение завершается. Код завершения 0.
true
Use explicit glue capacities for the KnuthPlass model
Ссылкаimport std.typeset as tsimport std.ioimport std.testfunction sample(justification: ts.JustificationPolicy) -> ts.ParagraphResult {let items: Array<ts.Item> = [ts.Item.BoxItem(ts.Box { unitIndex: 0, text: "word", width: 10pt, 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: justification,costModel: ts.CostModel.KnuthPlass(),knuthPlass: ts.KnuthPlassPolicy { toleranceR: 100000000, linePenalty: 10, fitnessDemerit: 0, flaggedDemerit: 0, finalFlaggedDemerit: 0 }}test.assertOk(ts.breakParagraph(input))}let natural = sample(ts.JustificationPolicy {mode: ts.JustificationMode.Unjustified(), minGapCount: 0,minLineWidthRatioM: 0, minFinalLineWidthRatioM: None(),maxAdjustment: 0pt, maxGapAdjustment: 0pt, maxGapRatioR: 0,latinSpacing: None(), cjkStretchRatio: 0.0})let scored = sample(ts.JustificationPolicy {mode: ts.JustificationMode.CjkInterCharacter(), minGapCount: 2,minLineWidthRatioM: 900, minFinalLineWidthRatioM: Some(1000),maxAdjustment: 3pt, maxGapAdjustment: 1pt, maxGapRatioR: 0,latinSpacing: None(), cjkStretchRatio: 0.2})io.writeLine("{natural.optimized.totalCost}")io.writeLine("{scored.optimized.totalCost}")io.writeLine("{scored.optimized.lines[0].adjustmentRatioR}")
100
100
0
Ожидаемый результат
Ожидаемый результат
Выполнение завершается. Код завершения 0.
1001000
Raise the score when an overwide unit misses a larger minimum
Ссылкаimport std.typeset as tsimport std.ioimport std.testfunction sample(ratio: int) -> ts.ParagraphResult {let items: Array<ts.Item> = [ts.Item.BoxItem(ts.Box { unitIndex: 0, text: "wide", width: 1.5pt, trackingAfter: 0pt }),ts.Item.PenaltyItem(ts.Penalty { unitEnd: 1, width: 0pt, rule: ts.BreakRule.Forced(), kind: ts.BreakKind.ForcedEnd(), flagged: false }),ts.Item.BoxItem(ts.Box { unitIndex: 1, text: "end", width: 1pt, trackingAfter: 0pt }),ts.Item.PenaltyItem(ts.Penalty { unitEnd: 2, 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.LatinWordSpace(), minGapCount: 0,minLineWidthRatioM: ratio, 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 }}test.assertOk(ts.breakParagraph(input))}let ordinary = sample(0)let thresholded = sample(2000)io.writeLine("{thresholded.optimized.lines[0].cost > ordinary.optimized.lines[0].cost}")
true
Ожидаемый результат
Ожидаемый результат
Выполнение завершается. Код завершения 0.
true
Include an inserted width in justification without adding gaps
Ссылкаimport std.typeset as tsimport std.ioimport std.testfunction sample(textWidth: Length<Pt>, insertionWidth: Length<Pt>) -> ts.ParagraphResult {let items: Array<ts.Item> = [ts.Item.BoxItem(ts.Box { unitIndex: 0, text: "a", width: textWidth, trackingAfter: 0pt }),ts.Item.PenaltyItem(ts.Penalty { unitEnd: 1, width: insertionWidth, rule: ts.BreakRule.Forced(), kind: ts.BreakKind.LatinHyphen(), flagged: false }),ts.Item.BoxItem(ts.Box { unitIndex: 1, text: "tail", width: 5pt, trackingAfter: 0pt }),ts.Item.PenaltyItem(ts.Penalty { unitEnd: 2, 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: 5pt, firstTarget: 5pt, dropCapSpan: 0, dropCapInset: 0pt },justification: ts.JustificationPolicy {mode: ts.JustificationMode.LatinWordSpace(), minGapCount: 0,minLineWidthRatioM: 1000, 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 }}test.assertOk(ts.breakParagraph(input))}let inserted = sample(4pt, 1pt)let measured = sample(5pt, 0pt)io.writeLine("{inserted.optimized.lines[0].cost == measured.optimized.lines[0].cost}")
true
Ожидаемый результат
Ожидаемый результат
Выполнение завершается. Код завершения 0.
true