Optimal Measure Characters-Per-Line

Greedy whitespace-only wrapping from caller measured word advances/character counts to audit actual CPL and unbreakable-word overflow; no shaping/hyphenation/bidi engine or universal optimal measure.

Description

Characters per line depend on word advances and wrapping, not just nominal font size.

Characters per line depend on word advances and wrapping, not just nominal font size. A greedy word model makes unbreakable overflows visible.1

Enter aligned nonempty nonnegative word advances/positive integer character counts, nonnegative space, positive line width and ordered nonnegative integer CPL bounds. Greedily wrap; count one separating space as a character. Return line counts/widths and outside/overwide indices.

When to use Optimal Measure Characters-Per-Line

Use Optimal Measure Characters-Per-Line when you need to evaluate the supplied records under the calculation and evidence rules below. No shaping, hyphenation, bidirectional layout or universal optimal line length is modeled.

Prepare measured font or typeset-layout values and the explicit design policy requested. For text or font bytes, use the supported syntax explained below.

How to use Optimal Measure Characters-Per-Line and understand its results

  1. Prepare measured font or typeset-layout values and the explicit design policy requested. For text or font bytes, use the supported syntax explained below.
  2. Enter wordAdvanceWidthsPx, wordCharacterCounts, spaceAdvancePx, availableLineWidthPx, callerCplBounds using the field table and calculation rules, then run the tool.
  3. Read greedyLineCharacterCounts, greedyLineAdvanceWidthsPx, overwideUnbrokenWordIndices, linesOutsideCallerCplIndices. The explanation below defines the units, signs, ordering and any flags or placeholder values.
  4. If the tool reports an input issue, correct the values and run it again. Apply the stated assumptions when interpreting a successfully returned result.
Input fieldMeaningValue type; see rules belowRequirement
wordAdvanceWidthsPxWord advance widths pxlist of numberRequired
wordCharacterCountsWord character countslist of numberRequired
spaceAdvancePxSpace advance pxnumberRequired
availableLineWidthPxAvailable line width pxnumberRequired
callerCplBoundsCaller cpl boundslist of numberRequired

Enter aligned nonempty nonnegative word advances/positive integer character counts, nonnegative space, positive line width and ordered nonnegative integer CPL bounds. Greedily wrap; count one separating space as a character. Return line counts/widths and outside/overwide indices.

wrap before next word when currentWidth+space+wordWidth>availableWidth

Units, indexing, boundary conditions and exceptional cases are defined in the calculation rules above.

Output fieldMeaningValue type
greedyLineCharacterCountsGreedy line character countslist of number
greedyLineAdvanceWidthsPxGreedy line advance widths pxlist of number
overwideUnbrokenWordIndicesOverwide unbroken word indiceslist of number
linesOutsideCallerCplIndicesLines outside caller cpl indiceslist of number
json
{
  "input": {
    "wordAdvanceWidthsPx": [
      20,
      30,
      25
    ],
    "wordCharacterCounts": [
      4,
      5,
      5
    ],
    "spaceAdvancePx": 5,
    "availableLineWidthPx": 60,
    "callerCplBounds": [
      5,
      12
    ]
  },
  "output": {
    "greedyLineCharacterCounts": [
      10,
      5
    ],
    "greedyLineAdvanceWidthsPx": [
      55,
      25
    ],
    "overwideUnbrokenWordIndices": [],
    "linesOutsideCallerCplIndices": []
  }
}

Limitations and assumptions

No shaping, hyphenation, bidirectional layout or universal optimal line length is modeled.

Numeric inputs, where present, must be finite. Follow the calculation-specific rules for overflow, underflow and exceptional cases. Numeric lists are limited to 10,000 entries; string lists to 128 strings of at most 128 characters each. The rules above may impose smaller limits. Missing required fields, extra fields, wrong value types and violations of the calculation rules are input errors.

Alternative or Complementary methods

Use ch Unit Line Length Checker: CSS ch measures the zero glyph’s advance. Actual characters per line depend on the mean advance of the text being set. For a complementary task, use Column Count From Text Width: Column packing accounts for N−1 gutters between N columns. Insufficient width should yield an explicit zero-column result.

References

  1. Optimal Measure Characters-Per-Line — tool.io

Similar or alternative tools

  • ch Unit Line Length Checker

    CSS ch measures the zero glyph’s advance. Actual characters per line depend on the mean advance of the text being set.

  • Column Count From Text Width

    Column packing accounts for N−1 gutters between N columns. Insufficient width should yield an explicit zero-column result.

Don't forget to set a bookmark for tool.io!
Privacy | Imprint | Cookies