@connectedxm/zpl-generator 0.0.19 → 0.0.21
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 +25 -30
- package/dist/index.es.js +372 -318
- package/dist/src/generate.d.ts +11 -4
- package/dist/src/interfaces.d.ts +11 -0
- package/dist/src/validate.d.ts +52 -8
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -329,38 +329,33 @@ const zpl = generate(badgeWithData);
|
|
|
329
329
|
|
|
330
330
|
### Accurate Text Wrapping
|
|
331
331
|
|
|
332
|
-
For precise
|
|
332
|
+
For precise auto-shrink sizing with proportional fonts, measure each word of
|
|
333
|
+
the **rendered** value (after `transformation`/`maxCharacters` — use the
|
|
334
|
+
exported `applyTextTransformation`) and provide `wordWidths` on the text
|
|
335
|
+
field. Tokenize with the exported `tokenizeWords` so words line up with the
|
|
336
|
+
generator's wrap simulation. Widths are measured at the field's `fontHeight`;
|
|
337
|
+
the generator scales them when searching for a fitting height.
|
|
333
338
|
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
// Measure word widths (e.g., using canvas or font metrics)
|
|
338
|
-
const wordWidths: WordWidth[] = [
|
|
339
|
-
{ word: 'Hello', width: 50, spaceWidth: 10 },
|
|
340
|
-
{ word: 'World', width: 60, spaceWidth: 10 },
|
|
341
|
-
];
|
|
342
|
-
|
|
343
|
-
const fieldBlock: FieldBlock = {
|
|
344
|
-
type: 'field',
|
|
345
|
-
name: 'text',
|
|
346
|
-
x: 0,
|
|
347
|
-
y: 0,
|
|
348
|
-
data: 'Hello World',
|
|
349
|
-
font: 'A',
|
|
350
|
-
fontHeight: 20,
|
|
351
|
-
maxWidth: 100,
|
|
352
|
-
maxLines: 5,
|
|
353
|
-
lineSpacing: 0,
|
|
354
|
-
alignment: TextAlignment.Left,
|
|
355
|
-
fontOrientation: FontOrientation.NoRotation,
|
|
356
|
-
hangingIndent: 0,
|
|
357
|
-
verticalAlignment: VerticalAlignment.End,
|
|
358
|
-
wordWidths, // Provide measured widths
|
|
359
|
-
};
|
|
339
|
+
Line counting priority: `wordWidths` (exact `^FB` word-wrap simulation, used
|
|
340
|
+
only when the measured words match the rendered value) → `measuredWidth`
|
|
341
|
+
(continuous-stream estimate) → `charsPerLine` heuristic.
|
|
360
342
|
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
343
|
+
```typescript
|
|
344
|
+
import {
|
|
345
|
+
applyTextTransformation,
|
|
346
|
+
tokenizeWords,
|
|
347
|
+
generate,
|
|
348
|
+
WordWidth,
|
|
349
|
+
} from "@connectedxm/zpl-generator";
|
|
350
|
+
|
|
351
|
+
// In the consumer, after resolving the field's value:
|
|
352
|
+
const printed = applyTextTransformation(field, rawValue);
|
|
353
|
+
const spaceWidth = measure(" "); // e.g. canvas measureText at field.fontHeight
|
|
354
|
+
const wordWidths: WordWidth[] = tokenizeWords(printed)
|
|
355
|
+
.flat()
|
|
356
|
+
.map((word) => ({ word, width: measure(word), spaceWidth }));
|
|
357
|
+
|
|
358
|
+
const sizedField = { ...field, wordWidths };
|
|
364
359
|
```
|
|
365
360
|
|
|
366
361
|
### Validating JSON Configuration
|