Перейти к содержимому
Топаз6.0 · До релиза
Загрузка →

Поиск в документации

Спецификация 6.0

Выберите результат стрелками и нажмите Enter, чтобы открыть его.

Введите имя API, номер диагностики, правило или тему проекта.

    Библиотека · std.typeset

    KnuthPlassPolicy.linePenalty

    Set the nonnegative base of each line demerit.

    KnuthPlassPolicy.linePenalty: int
    Модуль
    std.typeset →
    Получатель
    KnuthPlassPolicy
    Минимальное число аргументов
    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.

    Получатель

    KnuthPlassPolicy

    Ограничения параметров

    Every KnuthPlassPolicy field is a nonnegative int. A negative toleranceR, linePenalty, fitnessDemerit, flaggedDemerit, or finalFlaggedDemerit returns TypesetError.InvalidPolicy. Validation applies even when the selected CostModel is FixedPoint.

    KnuthPlass uses explicit GlueItem stretch and shrink. JustificationPolicy values are validated but do not replace these capacities or its ratio score. Leading glue is discarded for the natural width and capacities. An ordinary break discards trailing glue, while a Forced break consumes trailing glue so a caller can represent a ragged final line.

    Let slack be the target minus natural text width and selected penalty width. Nonnegative slack uses total stretch and negative slack uses total shrink. Zero capacity admits an exact fit and rejects a nonzero slack. Shrink admits ratios down to negative one. Positive ratios must be no greater than toleranceR divided by 100000000.

    The reported adjustment ratio is scaled by 100000000 and rounded to nearest with ties to even. Admission and fitness use the exact ratio before rounding. Badness is 100 times the absolute ratio cubed, rounded to nearest with ties to even and capped at 10000.

    Add linePenalty and badness, then square their sum for the basic line score. An Allowed penalty adds its squared value when nonnegative and subtracts its squared value when negative. Forced penalties add no such term. The resulting score is a signed checked int.

    The four fitness classes are ratios below negative one half, ratios from negative one half through one half, ratios above one half through one, and ratios above one. Add fitnessDemerit when consecutive lines differ by more than one class. The first line has no preceding fitness transition.

    Add flaggedDemerit when both the preceding and selected penalties are flagged. Add finalFlaggedDemerit when the final line follows a flagged penalty, whether or not its own penalty is flagged. The first line has no preceding flag.

    An exact fit with linePenalty equal to 10, zero penalty cost, and no transition demerit has line cost 100 and adjustmentRatioR equal to zero. A nonexact line with no usable stretch or shrink is inadmissible, including a final line whose caller supplied no terminal capacity.

    Результат

    The declared result type is int.

    Эффекты

    Ошибки

    Result and effects

    Ссылка

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

    Add linePenalty to cubic badness and square the sum before applying break and transition demerits.

    Tolerance controls acceptable adjustment and demerits control the relative cost of adjacent lines. Explicit glue capacities make final line behavior and flagged transitions reproducible without hidden default glue or a separate final line algorithm.

    Resolved contracts

    Ссылка

    Related entries

    Ссылка

    std.typeset →

    Set Knuth Plass tolerance and transition costs

    Ссылка
    Правилоtopaz.stdlib.contract.typeset-knuth-plass-policy.rule

    Set Knuth Plass tolerance and transition costs

    Every KnuthPlassPolicy field is a nonnegative int. A negative toleranceR, linePenalty, fitnessDemerit, flaggedDemerit, or finalFlaggedDemerit returns TypesetError.InvalidPolicy. Validation applies even when the selected CostModel is FixedPoint.

    KnuthPlass uses explicit GlueItem stretch and shrink. JustificationPolicy values are validated but do not replace these capacities or its ratio score. Leading glue is discarded for the natural width and capacities. An ordinary break discards trailing glue, while a Forced break consumes trailing glue so a caller can represent a ragged final line.

    Let slack be the target minus natural text width and selected penalty width. Nonnegative slack uses total stretch and negative slack uses total shrink. Zero capacity admits an exact fit and rejects a nonzero slack. Shrink admits ratios down to negative one. Positive ratios must be no greater than toleranceR divided by 100000000.

    The reported adjustment ratio is scaled by 100000000 and rounded to nearest with ties to even. Admission and fitness use the exact ratio before rounding. Badness is 100 times the absolute ratio cubed, rounded to nearest with ties to even and capped at 10000.

    Add linePenalty and badness, then square their sum for the basic line score. An Allowed penalty adds its squared value when nonnegative and subtracts its squared value when negative. Forced penalties add no such term. The resulting score is a signed checked int.

    The four fitness classes are ratios below negative one half, ratios from negative one half through one half, ratios above one half through one, and ratios above one. Add fitnessDemerit when consecutive lines differ by more than one class. The first line has no preceding fitness transition.

    Add flaggedDemerit when both the preceding and selected penalties are flagged. Add finalFlaggedDemerit when the final line follows a flagged penalty, whether or not its own penalty is flagged. The first line has no preceding flag.

    An exact fit with linePenalty equal to 10, zero penalty cost, and no transition demerit has line cost 100 and adjustmentRatioR equal to zero. A nonexact line with no usable stretch or shrink is inadmissible, including a final line whose caller supplied no terminal capacity.

    Причина

    Tolerance controls acceptable adjustment and demerits control the relative cost of adjacent lines. Explicit glue capacities make final line behavior and flagged transitions reproducible without hidden default glue or a separate final line algorithm.

    Score an exact Knuth Plass line

    Ссылка
    main.tpzScore an exact Knuth Plass lineОткрыть песочницу →
    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: 10pt, trackingAfter: 0pt }),
    5. ts.Item.PenaltyItem(ts.Penalty { unitEnd: 1, width: 0pt, rule: ts.BreakRule.Forced(), kind: ts.BreakKind.ForcedEnd(), flagged: false })
    6. ]
    7. let input = ts.Paragraph {
    8. grid: ts.DistanceGrid.MilliPoint(),
    9. items: items,
    10. geometry: ts.LineGeometry { bodyTarget: 10pt, firstTarget: 10pt, dropCapSpan: 0, dropCapInset: 0pt },
    11. justification: ts.JustificationPolicy {
    12. mode: ts.JustificationMode.Unjustified(), minGapCount: 0,
    13. minLineWidthRatioM: 0, minFinalLineWidthRatioM: None(),
    14. maxAdjustment: 0pt, maxGapAdjustment: 0pt, maxGapRatioR: 0,
    15. latinSpacing: None(), cjkStretchRatio: 0.0
    16. },
    17. costModel: ts.CostModel.KnuthPlass(),
    18. knuthPlass: ts.KnuthPlassPolicy { toleranceR: 100000000, linePenalty: 10, fitnessDemerit: 0, flaggedDemerit: 0, finalFlaggedDemerit: 0 }
    19. }
    20. match (ts.breakParagraph(input)) {
    21. case Ok(result) => {
    22. let line = result.optimized.lines[0]
    23. io.writeLine("{line.cost} {line.adjustmentRatioR} {result.optimized.totalCost}")
    24. match (line.postValidationWidthLimit) {
    25. case None() => io.writeLine("ratio admission")
    26. case Some(_) => io.writeLine("unexpected width limit")
    27. }
    28. }
    29. case Err(_) => io.writeLine("unexpected error")
    30. }
    Ожидаемый выводКод завершения 0
    100 0 100
    ratio admission
    
    $ topaz run main.tpz · Целевой продукт 5.21.3
    Ожидаемый результат

    Ожидаемый результат

    Выполнение завершается. Код завершения 0.

    Ожидаемый стандартный вывод
    1. 100 0 100
    2. ratio admission

    Validate Knuth Plass policy before choosing a cost model

    Ссылка
    main.tpzValidate Knuth Plass policy before choosing a cost modelОткрыть песочницу →
    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.ForcedEnd(), flagged: false })
    6. ]
    7. let input = ts.Paragraph {
    8. grid: ts.DistanceGrid.MilliPoint(),
    9. items: items,
    10. geometry: ts.LineGeometry { bodyTarget: 10pt, firstTarget: 10pt, dropCapSpan: 0, dropCapInset: 0pt },
    11. justification: ts.JustificationPolicy {
    12. mode: ts.JustificationMode.Unjustified(), minGapCount: 0,
    13. minLineWidthRatioM: 0, minFinalLineWidthRatioM: None(),
    14. maxAdjustment: 0pt, maxGapAdjustment: 0pt, maxGapRatioR: 0,
    15. latinSpacing: None(), cjkStretchRatio: 0.0
    16. },
    17. costModel: ts.CostModel.FixedPoint(),
    18. knuthPlass: ts.KnuthPlassPolicy { toleranceR: -1, linePenalty: 10, fitnessDemerit: 0, flaggedDemerit: 0, finalFlaggedDemerit: 0 }
    19. }
    20. match (ts.breakParagraph(input)) {
    21. case Err(InvalidPolicy(_)) => io.writeLine("InvalidPolicy")
    22. case _ => io.writeLine("unexpected result")
    23. }
    Ожидаемый выводКод завершения 0
    InvalidPolicy
    
    $ topaz run main.tpz · Целевой продукт 5.21.3
    Ожидаемый результат

    Ожидаемый результат

    Выполнение завершается. Код завершения 0.

    Ожидаемый стандартный вывод
    1. InvalidPolicy

    Report a line with no capacity to reach its target

    Ссылка
    main.tpzReport a line with no capacity to reach its targetОткрыть песочницу →
    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: 9pt, trackingAfter: 0pt }),
    5. ts.Item.PenaltyItem(ts.Penalty { unitEnd: 1, width: 0pt, rule: ts.BreakRule.Forced(), kind: ts.BreakKind.ForcedEnd(), flagged: false })
    6. ]
    7. let input = ts.Paragraph {
    8. grid: ts.DistanceGrid.MilliPoint(),
    9. items: items,
    10. geometry: ts.LineGeometry { bodyTarget: 10pt, firstTarget: 10pt, dropCapSpan: 0, dropCapInset: 0pt },
    11. justification: ts.JustificationPolicy {
    12. mode: ts.JustificationMode.Unjustified(), minGapCount: 0,
    13. minLineWidthRatioM: 0, minFinalLineWidthRatioM: None(),
    14. maxAdjustment: 0pt, maxGapAdjustment: 0pt, maxGapRatioR: 0,
    15. latinSpacing: None(), cjkStretchRatio: 0.0
    16. },
    17. costModel: ts.CostModel.KnuthPlass(),
    18. knuthPlass: ts.KnuthPlassPolicy { toleranceR: 100000000, linePenalty: 10, fitnessDemerit: 0, flaggedDemerit: 0, finalFlaggedDemerit: 0 }
    19. }
    20. match (ts.breakParagraph(input)) {
    21. case Err(NoGreedyPlan()) => io.writeLine("NoGreedyPlan")
    22. case _ => io.writeLine("unexpected result")
    23. }
    Ожидаемый выводКод завершения 0
    NoGreedyPlan
    
    $ topaz run main.tpz · Целевой продукт 5.21.3
    Ожидаемый результат

    Ожидаемый результат

    Выполнение завершается. Код завершения 0.

    Ожидаемый стандартный вывод
    1. NoGreedyPlan

    Меню

    Загрузка →