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
- Prepare measured font or typeset-layout values and the explicit design policy requested. For text or font bytes, use the supported syntax explained below.
- Enter wordAdvanceWidthsPx, wordCharacterCounts, spaceAdvancePx, availableLineWidthPx, callerCplBounds using the field table and calculation rules, then run the tool.
- Read greedyLineCharacterCounts, greedyLineAdvanceWidthsPx, overwideUnbrokenWordIndices, linesOutsideCallerCplIndices. The explanation below defines the units, signs, ordering and any flags or placeholder values.
- 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 field | Meaning | Value type; see rules below | Requirement |
|---|---|---|---|
| wordAdvanceWidthsPx | Word advance widths px | list of number | Required |
| wordCharacterCounts | Word character counts | list of number | Required |
| spaceAdvancePx | Space advance px | number | Required |
| availableLineWidthPx | Available line width px | number | Required |
| callerCplBounds | Caller cpl bounds | list of number | Required |
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 field | Meaning | Value type |
|---|---|---|
| greedyLineCharacterCounts | Greedy line character counts | list of number |
| greedyLineAdvanceWidthsPx | Greedy line advance widths px | list of number |
| overwideUnbrokenWordIndices | Overwide unbroken word indices | list of number |
| linesOutsideCallerCplIndices | Lines outside caller cpl indices | list of number |
{
"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
-
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.