@unmade/text-renderer 1.2.0 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +47 -0
- package/dist/fitting/index.d.ts +3 -3
- package/dist/index.d.ts +1 -0
- package/dist/index.js +535 -408
- package/dist/layout/index.d.ts +77 -0
- package/dist/node/fitting/index.d.ts +3 -3
- package/dist/node/index.d.ts +1 -0
- package/dist/node/index.js +303 -174
- package/dist/node/layout/index.d.ts +77 -0
- package/dist/node/renderText.d.ts +3 -0
- package/dist/renderText.d.ts +3 -0
- package/dist/worker/fitting/index.d.ts +3 -3
- package/dist/worker/index.d.ts +1 -0
- package/dist/worker/index.js +1839 -1712
- package/dist/worker/layout/index.d.ts +77 -0
- package/dist/worker/renderText.d.ts +3 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -147,6 +147,53 @@ rendered output. Rotating the frame rather than reasoning about rotation inside
|
|
|
147
147
|
solver keeps it working in one coordinate space, and is also what lets a rotated tall
|
|
148
148
|
placement use its long side for the baseline.
|
|
149
149
|
|
|
150
|
+
## Measuring text
|
|
151
|
+
|
|
152
|
+
`renderText` returns artwork; `measureText` returns its dimensions, for the same
|
|
153
|
+
inputs.
|
|
154
|
+
|
|
155
|
+
```typescript
|
|
156
|
+
import { measureText } from '@unmade/text-renderer';
|
|
157
|
+
|
|
158
|
+
const m = measureText({
|
|
159
|
+
font,
|
|
160
|
+
text: 'HELLO',
|
|
161
|
+
boxDimensions,
|
|
162
|
+
physicalSize: [20, 'mm'],
|
|
163
|
+
spacing: { outlineWidth: 0, letterSpacing: 0, letterSpacingOutline: 0 },
|
|
164
|
+
baseline: 'flat',
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
m.bbox; // { x, y, width, height } in box pixels
|
|
168
|
+
m.physicalWidth; // in the box's units
|
|
169
|
+
m.physicalHeight;
|
|
170
|
+
m.physicalCapHeight; // see below
|
|
171
|
+
m.lines; // per line, in rendered order
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
It measures the **same positioned glyphs that get drawn**, rather than
|
|
175
|
+
re-deriving dimensions from font metrics. That matters for more than tidiness: a
|
|
176
|
+
curved line's bounds follow the arch, which no flat metrics calculation can know
|
|
177
|
+
about, and any second implementation eventually disagrees with the first.
|
|
178
|
+
`renderText` and `measureText` share one layout pass for exactly that reason.
|
|
179
|
+
|
|
180
|
+
It throws where `renderText` would throw, and for the same reasons — so if
|
|
181
|
+
measuring succeeds, rendering the same options will too.
|
|
182
|
+
|
|
183
|
+
### Cap height is reported, not derived
|
|
184
|
+
|
|
185
|
+
`physicalCapHeight` is the physical height of a standard capital at the chosen
|
|
186
|
+
font size. It is **not** `physicalHeight`, and can't be calculated from it:
|
|
187
|
+
|
|
188
|
+
- `physicalHeight` measures the glyphs actually present, so it grows with
|
|
189
|
+
descenders, accents and punctuation
|
|
190
|
+
- `physicalCapHeight` is a property of the font and size alone, so the same size
|
|
191
|
+
always reports the same cap height regardless of what was typed
|
|
192
|
+
|
|
193
|
+
Both are needed. Cap height is what a fixed size preset targets and what gets
|
|
194
|
+
persisted against a design for manufacturing; the measured height is what the
|
|
195
|
+
artwork actually occupies.
|
|
196
|
+
|
|
150
197
|
## Configuration Engine adapter
|
|
151
198
|
|
|
152
199
|
The `ce-adapter` sub-package bridges CE (Configuration Engine) editor state to renderer options:
|
package/dist/fitting/index.d.ts
CHANGED
|
@@ -67,9 +67,9 @@ export interface FitAndTruncateTextToBoxResult extends FitTextToBoxResult {
|
|
|
67
67
|
/**
|
|
68
68
|
* Calculate the font size at which `text` fills `boxDimensions` as closely
|
|
69
69
|
* as possible without overflowing, for any baseline shape. This replaces
|
|
70
|
-
* binary-searching for a fitting font size:
|
|
71
|
-
*
|
|
72
|
-
* numeric solve (see solveCurvedFit).
|
|
70
|
+
* binary-searching for a fitting font size: flat and custom baselines are
|
|
71
|
+
* solved in one step, from a single measurement, while curved baselines need
|
|
72
|
+
* a bounded numeric solve (see solveCurvedFit).
|
|
73
73
|
*
|
|
74
74
|
* `fits: false` means the text doesn't fit even at minFontSize — the caller
|
|
75
75
|
* (e.g. fitAndTruncateTextToBox) should either shorten the text or accept
|
package/dist/index.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ export { type GenerateCurvedBaselineOptions, type GenerateFlatBaselineOptions, g
|
|
|
3
3
|
export { DEFAULT_OUTLINE_FACTOR, DEFAULT_SPACING, LINE_HEIGHT, } from './constants';
|
|
4
4
|
export { type FitAndTruncateTextToBoxResult, type FitConstraint, type FitSize, type FitTextToBoxOptions, type FitTextToBoxResult, fitAndTruncateTextToBox, getFontSizeToFitBox, } from './fitting';
|
|
5
5
|
export { getFontColours } from './glyph/svg-glyph-converter';
|
|
6
|
+
export { type LayoutTextOptions, layoutText, type MeasuredLine, measureText, type TextLayout, type TextMeasurement, } from './layout';
|
|
6
7
|
export { getFontCache, type LoadedFont, loadFont } from './loading';
|
|
7
8
|
export { type GetFontSizeFromPhysicalSizeOptions, type GetTextMetricsAtFontSizeOptions, getFontSizeFromPhysicalSize, getTextMetricsAtFontSize, } from './measuring';
|
|
8
9
|
export type { GetTextAsPathDataOptions, SvgGlyphEntry } from './rendering';
|