canvas-recorder-lib 0.7.4 → 0.8.1
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/BREAKING-CHANGES.md +15 -2
- package/dev/canvas-recorder.css +5 -1
- package/dev/canvas-recorder.ts +122 -14
- package/dev/character-panel.ts +201 -0
- package/dev/format-editor.ts +36 -0
- package/dev/fourier-panel.ts +3 -2
- package/dev/multi-text-dialog.ts +31 -2
- package/dev/multi-text-panel.ts +6 -0
- package/dist/dev/canvas-recorder.css +5 -1
- package/dist/dev/canvas-recorder.js +101 -14
- package/dist/dev/canvas-recorder.js.map +1 -1
- package/dist/dev/character-panel.d.ts +43 -0
- package/dist/dev/character-panel.d.ts.map +1 -0
- package/dist/dev/character-panel.js +133 -0
- package/dist/dev/character-panel.js.map +1 -0
- package/dist/dev/format-editor.d.ts +16 -0
- package/dist/dev/format-editor.d.ts.map +1 -1
- package/dist/dev/format-editor.js +31 -0
- package/dist/dev/format-editor.js.map +1 -1
- package/dist/dev/fourier-panel.d.ts.map +1 -1
- package/dist/dev/fourier-panel.js.map +1 -1
- package/dist/dev/multi-text-dialog.d.ts +2 -0
- package/dist/dev/multi-text-dialog.d.ts.map +1 -1
- package/dist/dev/multi-text-dialog.js +26 -2
- package/dist/dev/multi-text-dialog.js.map +1 -1
- package/dist/dev/multi-text-panel.d.ts.map +1 -1
- package/dist/dev/multi-text-panel.js +6 -0
- package/dist/dev/multi-text-panel.js.map +1 -1
- package/dist/src/glib/font-choices.d.ts +61 -0
- package/dist/src/glib/font-choices.d.ts.map +1 -0
- package/dist/src/glib/font-choices.js +101 -0
- package/dist/src/glib/font-choices.js.map +1 -0
- package/dist/src/glib/letters-base.d.ts +97 -0
- package/dist/src/glib/letters-base.d.ts.map +1 -1
- package/dist/src/glib/letters-base.js +120 -18
- package/dist/src/glib/letters-base.js.map +1 -1
- package/dist/src/glib/line-font.d.ts +23 -3
- package/dist/src/glib/line-font.d.ts.map +1 -1
- package/dist/src/glib/line-font.js +40 -1
- package/dist/src/glib/line-font.js.map +1 -1
- package/dist/src/peano-fourier/fourier-shared.d.ts +32 -1
- package/dist/src/peano-fourier/fourier-shared.d.ts.map +1 -1
- package/dist/src/peano-fourier/fourier-shared.js +21 -3
- package/dist/src/peano-fourier/fourier-shared.js.map +1 -1
- package/dist/src/slide-components/fourier.d.ts +8 -3
- package/dist/src/slide-components/fourier.d.ts.map +1 -1
- package/dist/src/slide-components/fourier.js +11 -4
- package/dist/src/slide-components/fourier.js.map +1 -1
- package/dist/src/slide-components/multi-text.d.ts +24 -0
- package/dist/src/slide-components/multi-text.d.ts.map +1 -1
- package/dist/src/slide-components/multi-text.js +75 -5
- package/dist/src/slide-components/multi-text.js.map +1 -1
- package/dist/src/slide-components/registry.d.ts.map +1 -1
- package/dist/src/slide-components/registry.js +3 -2
- package/dist/src/slide-components/registry.js.map +1 -1
- package/dist/src/slide-components/simple-text.d.ts +20 -0
- package/dist/src/slide-components/simple-text.d.ts.map +1 -1
- package/dist/src/slide-components/simple-text.js +58 -5
- package/dist/src/slide-components/simple-text.js.map +1 -1
- package/internals.md +402 -406
- package/package.json +1 -1
- package/src/glib/font-choices.ts +132 -0
- package/src/glib/letters-base.ts +212 -18
- package/src/glib/line-font.ts +56 -3
- package/src/peano-fourier/fourier-shared.ts +47 -5
- package/src/slide-components/fourier.ts +19 -8
- package/src/slide-components/multi-text.ts +100 -4
- package/src/slide-components/registry.ts +3 -2
- package/src/slide-components/simple-text.ts +76 -4
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { Font, FontOptions } from "./letters-base.ts";
|
|
2
|
+
/**
|
|
3
|
+
* The fonts the text components offer, by the names the Visual Editor shows.
|
|
4
|
+
*
|
|
5
|
+
* The Text Format and Text components have a Font property with these choices.
|
|
6
|
+
* Line Font is the default.
|
|
7
|
+
* @module
|
|
8
|
+
*/
|
|
9
|
+
/** Every font a text component can use, by the name the Visual Editor shows. */
|
|
10
|
+
export declare const FONT_NAMES: readonly ["Line Font", "Futura L", "Cursive"];
|
|
11
|
+
/** One of {@link FONT_NAMES}. */
|
|
12
|
+
export type FontName = (typeof FONT_NAMES)[number];
|
|
13
|
+
/**
|
|
14
|
+
* Make a font by its name.
|
|
15
|
+
*
|
|
16
|
+
* An unknown name, say from an old save file, gets the Line Font.
|
|
17
|
+
*/
|
|
18
|
+
export declare function makeFontByName(name: FontName, options: FontOptions): Font;
|
|
19
|
+
/**
|
|
20
|
+
* Every character `name` can draw, except the space, which the layout handles
|
|
21
|
+
* itself.
|
|
22
|
+
*/
|
|
23
|
+
export declare function fontCharacters(name: FontName): ReadonlySet<string>;
|
|
24
|
+
/**
|
|
25
|
+
* Every character any of {@link FONT_NAMES} can draw, in Unicode order.
|
|
26
|
+
* Except the space, which the layout handles itself.
|
|
27
|
+
*/
|
|
28
|
+
export declare function allFontCharacters(): readonly string[];
|
|
29
|
+
/**
|
|
30
|
+
* The characters in `text` that `name` can't draw, each once, in the order they first
|
|
31
|
+
* appear. The layout skips them, so they don't appear on the canvas.
|
|
32
|
+
*
|
|
33
|
+
* The space and "\n" aren't letters, so they're never missing.
|
|
34
|
+
*/
|
|
35
|
+
export declare function missingCharacters(text: string, name: FontName): string[];
|
|
36
|
+
/**
|
|
37
|
+
* Characters some text needs and its font doesn't have.
|
|
38
|
+
* See `MultiTextComponent.missingCharacters()`.
|
|
39
|
+
*/
|
|
40
|
+
export type MissingCharacters = {
|
|
41
|
+
/** The Text Format's name, or undefined for a component with one font, like Text. */
|
|
42
|
+
readonly formatName?: string;
|
|
43
|
+
readonly fontName: FontName;
|
|
44
|
+
/** Each once, in the order they first appear. */
|
|
45
|
+
readonly characters: readonly string[];
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* Check `text` against `font` at every moment either could change.
|
|
49
|
+
*
|
|
50
|
+
* Both are step functions: each keyframe holds until the next. So checking at each
|
|
51
|
+
* keyframe's time covers the whole timeline.
|
|
52
|
+
* @param keyframeTimes Every keyframe time of every schedule `pairsAt` reads.
|
|
53
|
+
* @param pairsAt The text and its font, at one time. Several, for several formats.
|
|
54
|
+
* @returns One entry per font and format with missing characters.
|
|
55
|
+
*/
|
|
56
|
+
export declare function checkCharacters(keyframeTimes: Iterable<number>, pairsAt: (timeInMs: number) => Iterable<{
|
|
57
|
+
text: string;
|
|
58
|
+
fontName: FontName;
|
|
59
|
+
formatName?: string;
|
|
60
|
+
}>): MissingCharacters[];
|
|
61
|
+
//# sourceMappingURL=font-choices.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"font-choices.d.ts","sourceRoot":"","sources":["../../../src/glib/font-choices.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAGtD;;;;;;GAMG;AAEH,gFAAgF;AAChF,eAAO,MAAM,UAAU,+CAAgD,CAAC;AAExE,iCAAiC;AACjC,MAAM,MAAM,QAAQ,GAAG,CAAC,OAAO,UAAU,CAAC,CAAC,MAAM,CAAC,CAAC;AAEnD;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,WAAW,GAAG,IAAI,CAYzE;AAID;;;GAGG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,QAAQ,GAAG,WAAW,CAAC,MAAM,CAAC,CAMlE;AAID;;;GAGG;AACH,wBAAgB,iBAAiB,IAAI,SAAS,MAAM,EAAE,CAKrD;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,GAAG,MAAM,EAAE,CASxE;AAED;;;GAGG;AACH,MAAM,MAAM,iBAAiB,GAAG;IAC9B,qFAAqF;IACrF,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC;IAC5B,iDAAiD;IACjD,QAAQ,CAAC,UAAU,EAAE,SAAS,MAAM,EAAE,CAAC;CACxC,CAAC;AAEF;;;;;;;;GAQG;AACH,wBAAgB,eAAe,CAC7B,aAAa,EAAE,QAAQ,CAAC,MAAM,CAAC,EAC/B,OAAO,EAAE,CACP,QAAQ,EAAE,MAAM,KACb,QAAQ,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,QAAQ,CAAC;IAAC,UAAU,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,GACvE,iBAAiB,EAAE,CAyBrB"}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { Font } from "./letters-base.js";
|
|
2
|
+
import { makeLineFont } from "./line-font.js";
|
|
3
|
+
/**
|
|
4
|
+
* The fonts the text components offer, by the names the Visual Editor shows.
|
|
5
|
+
*
|
|
6
|
+
* The Text Format and Text components have a Font property with these choices.
|
|
7
|
+
* Line Font is the default.
|
|
8
|
+
* @module
|
|
9
|
+
*/
|
|
10
|
+
/** Every font a text component can use, by the name the Visual Editor shows. */
|
|
11
|
+
export const FONT_NAMES = ["Line Font", "Futura L", "Cursive"];
|
|
12
|
+
/**
|
|
13
|
+
* Make a font by its name.
|
|
14
|
+
*
|
|
15
|
+
* An unknown name, say from an old save file, gets the Line Font.
|
|
16
|
+
*/
|
|
17
|
+
export function makeFontByName(name, options) {
|
|
18
|
+
switch (name) {
|
|
19
|
+
case "Futura L": {
|
|
20
|
+
return Font.futuraL(options);
|
|
21
|
+
}
|
|
22
|
+
case "Cursive": {
|
|
23
|
+
return Font.cursive(options);
|
|
24
|
+
}
|
|
25
|
+
default: {
|
|
26
|
+
return makeLineFont(options);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
const characterSets = new Map();
|
|
31
|
+
/**
|
|
32
|
+
* Every character `name` can draw, except the space, which the layout handles
|
|
33
|
+
* itself.
|
|
34
|
+
*/
|
|
35
|
+
export function fontCharacters(name) {
|
|
36
|
+
return characterSets.getOrInsertComputed(name, () => {
|
|
37
|
+
const result = new Set(makeFontByName(name, { size: 1 }).getAllLetters());
|
|
38
|
+
result.delete(" ");
|
|
39
|
+
return result;
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
let allCharacters;
|
|
43
|
+
/**
|
|
44
|
+
* Every character any of {@link FONT_NAMES} can draw, in Unicode order.
|
|
45
|
+
* Except the space, which the layout handles itself.
|
|
46
|
+
*/
|
|
47
|
+
export function allFontCharacters() {
|
|
48
|
+
allCharacters ??= [
|
|
49
|
+
...new Set(FONT_NAMES.flatMap((name) => [...fontCharacters(name)])),
|
|
50
|
+
].sort((a, b) => a.codePointAt(0) - b.codePointAt(0));
|
|
51
|
+
return allCharacters;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* The characters in `text` that `name` can't draw, each once, in the order they first
|
|
55
|
+
* appear. The layout skips them, so they don't appear on the canvas.
|
|
56
|
+
*
|
|
57
|
+
* The space and "\n" aren't letters, so they're never missing.
|
|
58
|
+
*/
|
|
59
|
+
export function missingCharacters(text, name) {
|
|
60
|
+
const available = fontCharacters(name);
|
|
61
|
+
const result = new Set();
|
|
62
|
+
for (const char of text) {
|
|
63
|
+
if (char != " " && char != "\n" && !available.has(char)) {
|
|
64
|
+
result.add(char);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return [...result];
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Check `text` against `font` at every moment either could change.
|
|
71
|
+
*
|
|
72
|
+
* Both are step functions: each keyframe holds until the next. So checking at each
|
|
73
|
+
* keyframe's time covers the whole timeline.
|
|
74
|
+
* @param keyframeTimes Every keyframe time of every schedule `pairsAt` reads.
|
|
75
|
+
* @param pairsAt The text and its font, at one time. Several, for several formats.
|
|
76
|
+
* @returns One entry per font and format with missing characters.
|
|
77
|
+
*/
|
|
78
|
+
export function checkCharacters(keyframeTimes, pairsAt) {
|
|
79
|
+
const found = new Map();
|
|
80
|
+
for (const timeInMs of new Set(keyframeTimes)) {
|
|
81
|
+
for (const { text, fontName, formatName } of pairsAt(timeInMs)) {
|
|
82
|
+
const missing = missingCharacters(text, fontName);
|
|
83
|
+
if (missing.length == 0) {
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
const key = JSON.stringify([formatName, fontName]);
|
|
87
|
+
const entry = found.getOrInsertComputed(key, () => ({
|
|
88
|
+
fontName,
|
|
89
|
+
formatName,
|
|
90
|
+
characters: new Set(),
|
|
91
|
+
}));
|
|
92
|
+
missing.forEach((char) => entry.characters.add(char));
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return [...found.values()].map(({ fontName, formatName, characters }) => ({
|
|
96
|
+
fontName,
|
|
97
|
+
formatName,
|
|
98
|
+
characters: [...characters],
|
|
99
|
+
}));
|
|
100
|
+
}
|
|
101
|
+
//# sourceMappingURL=font-choices.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"font-choices.js","sourceRoot":"","sources":["../../../src/glib/font-choices.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAe,MAAM,mBAAmB,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C;;;;;;GAMG;AAEH,gFAAgF;AAChF,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,WAAW,EAAE,UAAU,EAAE,SAAS,CAAU,CAAC;AAKxE;;;;GAIG;AACH,MAAM,UAAU,cAAc,CAAC,IAAc,EAAE,OAAoB;IACjE,QAAQ,IAAI,EAAE,CAAC;QACb,KAAK,UAAU,CAAC,CAAC,CAAC;YAChB,OAAO,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QAC/B,CAAC;QACD,KAAK,SAAS,CAAC,CAAC,CAAC;YACf,OAAO,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QAC/B,CAAC;QACD,OAAO,CAAC,CAAC,CAAC;YACR,OAAO,YAAY,CAAC,OAAO,CAAC,CAAC;QAC/B,CAAC;IACH,CAAC;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Width: number;
|
|
37
37
|
};
|
|
38
|
+
/**
|
|
39
|
+
* Everything about a font, all at once: its size, width, slant and stroke.
|
|
40
|
+
* For {@link Font.cursive}, {@link Font.futuraL} and `makeLineFont()`.
|
|
41
|
+
* Only `size` is required.
|
|
42
|
+
*
|
|
43
|
+
* Give `boldness` or `strokeWidth`, not both.
|
|
44
|
+
*/
|
|
45
|
+
export type FontOptions = {
|
|
46
|
+
/** The height of a capital M, the font's `mHeight`. Width doesn't change it. */
|
|
47
|
+
readonly size: number;
|
|
48
|
+
/**
|
|
49
|
+
* How wide the letters are, compared to normal. 1, the default, is
|
|
50
|
+
* normal. 2 is twice as wide, 0.5 half as wide. Must be positive.
|
|
51
|
+
* The height stays `size`. See {@link Font.stretch}.
|
|
52
|
+
*/
|
|
53
|
+
readonly width?: number;
|
|
54
|
+
/**
|
|
55
|
+
* The slant in degrees, like {@link Font.oblique}. 0, the default, is
|
|
56
|
+
* upright. It's the angle you see, whatever the width: the letters are
|
|
57
|
+
* stretched first, then slanted.
|
|
58
|
+
*/
|
|
59
|
+
readonly obliqueness?: number;
|
|
60
|
+
} & ({
|
|
61
|
+
/**
|
|
62
|
+
* The stroke width, compared to the font's own recommendation
|
|
63
|
+
* ({@link Font.strokeWidth}). 1, the default, is normal; 2 is twice
|
|
64
|
+
* as thick. Each font recommends its own: the line font a tenth of
|
|
65
|
+
* its size, the Hershey fonts about half that.
|
|
66
|
+
*
|
|
67
|
+
* The recommendation follows the geometric mean of the font's height
|
|
68
|
+
* and width, `size × √width`. So 1 is a little bolder in a wide font
|
|
69
|
+
* and a little lighter in a narrow one. See {@link Font.stretch}.
|
|
70
|
+
*/
|
|
71
|
+
readonly boldness?: number;
|
|
72
|
+
readonly strokeWidth?: never;
|
|
73
|
+
} | {
|
|
74
|
+
/** The stroke width, in the same units as `size`. */
|
|
75
|
+
readonly strokeWidth: number;
|
|
76
|
+
readonly boldness?: never;
|
|
77
|
+
});
|
|
38
78
|
export type DescriptionOfLetter = {
|
|
39
79
|
readonly shape: PathShape;
|
|
40
80
|
readonly advance: number;
|
|
@@ -156,11 +196,68 @@ export declare class Font {
|
|
|
156
196
|
* This says how much to *change* the font, not the final value.
|
|
157
197
|
* font.oblique(5) != font.oblique(5).oblique(5).oblique(5).
|
|
158
198
|
* This differs from resize() which takes the desired resulting value, where this takes the change as an input.
|
|
199
|
+
*
|
|
200
|
+
* Call {@link stretch} first, if you use both. It would stretch the slant too.
|
|
159
201
|
* @returns A new font. Or the same font if you request a 0° change.
|
|
160
202
|
*/
|
|
161
203
|
oblique(degreesRight?: number): Font;
|
|
162
204
|
resize(newSize: number): Font;
|
|
205
|
+
/**
|
|
206
|
+
* Make the letters wider or narrower, keeping their height.
|
|
207
|
+
*
|
|
208
|
+
* Only the shapes change, not the pen: stroke them with one line width, and
|
|
209
|
+
* the vertical lines are as thick as the horizontal ones.
|
|
210
|
+
*
|
|
211
|
+
* Everything horizontal scales with the letters: each letter's advance, the
|
|
212
|
+
* kerning and the space. So a line of text is exactly `widthRatio` times as
|
|
213
|
+
* long, and cursive letters still meet. `top`, `bottom` and `mHeight` don't
|
|
214
|
+
* change.
|
|
215
|
+
*
|
|
216
|
+
* The recommended {@link strokeWidth} changes by √`widthRatio`, the geometric
|
|
217
|
+
* mean of the change in width and the change in height (none). That's the
|
|
218
|
+
* rule resize() follows, where both change by the same amount. So a wide
|
|
219
|
+
* font is a little bolder and a narrow one a little lighter, as in a real type
|
|
220
|
+
* family, and narrow letters don't fill in.
|
|
221
|
+
*
|
|
222
|
+
* **Stretch first, then oblique.** Stretching a slanted font stretches its
|
|
223
|
+
* slant too: `font.oblique(15).stretch(2)` leans about 28°, and
|
|
224
|
+
* `font.stretch(2).oblique(15)` leans 15°.
|
|
225
|
+
*
|
|
226
|
+
* For the line font, `makeLineFont({ size, width })` does a little better
|
|
227
|
+
* than `makeLineFont(size).stretch(width)`. Some of its letters depend on the
|
|
228
|
+
* stroke width, like the K, whose lines meet exactly, and it builds those
|
|
229
|
+
* for the stretched size.
|
|
230
|
+
* @param widthRatio 2 for twice as wide, 0.5 for half as wide. Must be
|
|
231
|
+
* positive. Like oblique(), this is a change, not the final value:
|
|
232
|
+
* `font.stretch(2).stretch(2)` is 4 times as wide as `font`.
|
|
233
|
+
* @returns A new font. Or the same font if `widthRatio` is 1.
|
|
234
|
+
*/
|
|
235
|
+
stretch(widthRatio: number): Font;
|
|
236
|
+
/**
|
|
237
|
+
* A handwritten script, from the Hershey fonts. Its letters join up.
|
|
238
|
+
*
|
|
239
|
+
* It has the 96 printable ASCII characters and nothing else.
|
|
240
|
+
* @param size The height of a capital M.
|
|
241
|
+
* @param degreesRight Slant it this much more. See {@link oblique}.
|
|
242
|
+
*/
|
|
163
243
|
static cursive(size: number, degreesRight?: number): Font;
|
|
244
|
+
/**
|
|
245
|
+
* A handwritten script, from the Hershey fonts, with its size, width,
|
|
246
|
+
* slant and stroke set all at once. See {@link FontOptions}.
|
|
247
|
+
*/
|
|
248
|
+
static cursive(options: FontOptions): Font;
|
|
249
|
+
/**
|
|
250
|
+
* A simple sans-serif, from the Hershey fonts.
|
|
251
|
+
*
|
|
252
|
+
* It has the 96 printable ASCII characters and nothing else.
|
|
253
|
+
* @param size The height of a capital M.
|
|
254
|
+
* @param degreesRight Slant it this much. See {@link oblique}.
|
|
255
|
+
*/
|
|
164
256
|
static futuraL(size: number, degreesRight?: number): Font;
|
|
257
|
+
/**
|
|
258
|
+
* A simple sans-serif, from the Hershey fonts, with its size, width, slant
|
|
259
|
+
* and stroke set all at once. See {@link FontOptions}.
|
|
260
|
+
*/
|
|
261
|
+
static futuraL(options: FontOptions): Font;
|
|
165
262
|
}
|
|
166
263
|
//# sourceMappingURL=letters-base.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"letters-base.d.ts","sourceRoot":"","sources":["../../../src/glib/letters-base.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAM5C;;;GAGG;AACH,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BhC,MAAM,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI;IAmB7B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA6BG;IACH,OAAO,CAAC,UAAU,EAAE,MAAM,GAAG,IAAI;IAsGjC;;;;;;OAMG;IACH,MAAM,CAAC,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI;IACzD;;;OAGG;IACH,MAAM,CAAC,OAAO,CAAC,OAAO,EAAE,WAAW,GAAG,IAAI;IAO1C;;;;;;OAMG;IACH,MAAM,CAAC,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI;IACzD;;;OAGG;IACH,MAAM,CAAC,OAAO,CAAC,OAAO,EAAE,WAAW,GAAG,IAAI;CAO3C"}
|
|
@@ -138,6 +138,8 @@ export class Font {
|
|
|
138
138
|
* This says how much to *change* the font, not the final value.
|
|
139
139
|
* font.oblique(5) != font.oblique(5).oblique(5).oblique(5).
|
|
140
140
|
* This differs from resize() which takes the desired resulting value, where this takes the change as an input.
|
|
141
|
+
*
|
|
142
|
+
* Call {@link stretch} first, if you use both. It would stretch the slant too.
|
|
141
143
|
* @returns A new font. Or the same font if you request a 0° change.
|
|
142
144
|
*/
|
|
143
145
|
oblique(degreesRight = 15) {
|
|
@@ -146,13 +148,7 @@ export class Font {
|
|
|
146
148
|
}
|
|
147
149
|
const result = new Font(this.top, this.bottom, this.spaceWidth, this.strokeWidth, this.kerning, this.mHeight, []);
|
|
148
150
|
const matrix = new DOMMatrixReadOnly().skewX(-degreesRight);
|
|
149
|
-
this.#
|
|
150
|
-
const newLetter = {
|
|
151
|
-
advance: originalLetter.advance,
|
|
152
|
-
shape: originalLetter.shape.transform(matrix),
|
|
153
|
-
};
|
|
154
|
-
result.#letters.set(key, newLetter);
|
|
155
|
-
});
|
|
151
|
+
this.#copyLettersTo(result, matrix, 1);
|
|
156
152
|
return result;
|
|
157
153
|
}
|
|
158
154
|
resize(newSize) {
|
|
@@ -163,24 +159,130 @@ export class Font {
|
|
|
163
159
|
const result = new Font(ratio * this.top, ratio * this.bottom, ratio * this.spaceWidth, ratio * this.strokeWidth, ratio * this.kerning, newSize, []);
|
|
164
160
|
const matrix = new DOMMatrix();
|
|
165
161
|
matrix.scaleSelf(ratio);
|
|
162
|
+
this.#copyLettersTo(result, matrix, ratio);
|
|
163
|
+
return result;
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Make the letters wider or narrower, keeping their height.
|
|
167
|
+
*
|
|
168
|
+
* Only the shapes change, not the pen: stroke them with one line width, and
|
|
169
|
+
* the vertical lines are as thick as the horizontal ones.
|
|
170
|
+
*
|
|
171
|
+
* Everything horizontal scales with the letters: each letter's advance, the
|
|
172
|
+
* kerning and the space. So a line of text is exactly `widthRatio` times as
|
|
173
|
+
* long, and cursive letters still meet. `top`, `bottom` and `mHeight` don't
|
|
174
|
+
* change.
|
|
175
|
+
*
|
|
176
|
+
* The recommended {@link strokeWidth} changes by √`widthRatio`, the geometric
|
|
177
|
+
* mean of the change in width and the change in height (none). That's the
|
|
178
|
+
* rule resize() follows, where both change by the same amount. So a wide
|
|
179
|
+
* font is a little bolder and a narrow one a little lighter, as in a real type
|
|
180
|
+
* family, and narrow letters don't fill in.
|
|
181
|
+
*
|
|
182
|
+
* **Stretch first, then oblique.** Stretching a slanted font stretches its
|
|
183
|
+
* slant too: `font.oblique(15).stretch(2)` leans about 28°, and
|
|
184
|
+
* `font.stretch(2).oblique(15)` leans 15°.
|
|
185
|
+
*
|
|
186
|
+
* For the line font, `makeLineFont({ size, width })` does a little better
|
|
187
|
+
* than `makeLineFont(size).stretch(width)`. Some of its letters depend on the
|
|
188
|
+
* stroke width, like the K, whose lines meet exactly, and it builds those
|
|
189
|
+
* for the stretched size.
|
|
190
|
+
* @param widthRatio 2 for twice as wide, 0.5 for half as wide. Must be
|
|
191
|
+
* positive. Like oblique(), this is a change, not the final value:
|
|
192
|
+
* `font.stretch(2).stretch(2)` is 4 times as wide as `font`.
|
|
193
|
+
* @returns A new font. Or the same font if `widthRatio` is 1.
|
|
194
|
+
*/
|
|
195
|
+
stretch(widthRatio) {
|
|
196
|
+
if (widthRatio == 1) {
|
|
197
|
+
return this;
|
|
198
|
+
}
|
|
199
|
+
if (!(widthRatio > 0 && isFinite(widthRatio))) {
|
|
200
|
+
throw new Error(`widthRatio must be positive, not ${widthRatio}.`);
|
|
201
|
+
}
|
|
202
|
+
const result = new Font(this.top, this.bottom, widthRatio * this.spaceWidth, Math.sqrt(widthRatio) * this.strokeWidth, widthRatio * this.kerning, this.mHeight, []);
|
|
203
|
+
const matrix = new DOMMatrixReadOnly().scale(widthRatio, 1);
|
|
204
|
+
this.#copyLettersTo(result, matrix, widthRatio);
|
|
205
|
+
return result;
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Copy every letter into a new font, transformed. For resize(), oblique()
|
|
209
|
+
* and stretch().
|
|
210
|
+
*
|
|
211
|
+
* Each shape is transformed the first time something asks for it, not all
|
|
212
|
+
* at once. The line font has hundreds of letters, and a text component
|
|
213
|
+
* builds a new font every frame while its size, width or slant is animated,
|
|
214
|
+
* but only draws a few of them.
|
|
215
|
+
* @param advanceRatio Each letter's advance is multiplied by this.
|
|
216
|
+
*/
|
|
217
|
+
#copyLettersTo(result, matrix, advanceRatio) {
|
|
166
218
|
this.#letters.forEach((originalLetter, key) => {
|
|
219
|
+
let shape;
|
|
167
220
|
const newLetter = {
|
|
168
|
-
advance:
|
|
169
|
-
|
|
221
|
+
advance: advanceRatio * originalLetter.advance,
|
|
222
|
+
get shape() {
|
|
223
|
+
shape ??= originalLetter.shape.transform(matrix);
|
|
224
|
+
return shape;
|
|
225
|
+
},
|
|
170
226
|
};
|
|
171
227
|
result.#letters.set(key, newLetter);
|
|
172
228
|
});
|
|
173
|
-
return result;
|
|
174
229
|
}
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
230
|
+
/**
|
|
231
|
+
* The same font, recommending a different {@link strokeWidth}.
|
|
232
|
+
* The letters are shared, not copied.
|
|
233
|
+
*/
|
|
234
|
+
#withStrokeWidth(strokeWidth) {
|
|
235
|
+
if (strokeWidth == this.strokeWidth) {
|
|
236
|
+
return this;
|
|
237
|
+
}
|
|
238
|
+
return new Font(this.top, this.bottom, this.spaceWidth, strokeWidth, this.kerning, this.mHeight, this.#letters);
|
|
179
239
|
}
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
240
|
+
/**
|
|
241
|
+
* One of the Hershey fonts, from its JSON. Parsed once, the first time it's
|
|
242
|
+
* needed. A font never changes, so everyone can share it.
|
|
243
|
+
*
|
|
244
|
+
* These fonts came from 7-bit ASCII, which put a curly quote where `'` and
|
|
245
|
+
* `` ` `` are. So `'` and `` ` `` draw as `’` and `‘`. Without that, "don't"
|
|
246
|
+
* would lose its apostrophe.
|
|
247
|
+
*/
|
|
248
|
+
static #hershey(json) {
|
|
249
|
+
const font = Font.fromJSON(json);
|
|
250
|
+
for (const [ascii, curly] of [
|
|
251
|
+
["'", "’"],
|
|
252
|
+
["`", "‘"],
|
|
253
|
+
]) {
|
|
254
|
+
const letter = font.#letters.get(curly);
|
|
255
|
+
if (letter && !font.#letters.has(ascii)) {
|
|
256
|
+
font.#letters.set(ascii, letter);
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
return font;
|
|
260
|
+
}
|
|
261
|
+
static #cursiveBase;
|
|
262
|
+
static #futuraLBase;
|
|
263
|
+
/**
|
|
264
|
+
* Size, width, slant and stroke, all at once, in the right order.
|
|
265
|
+
* See {@link FontOptions}.
|
|
266
|
+
*/
|
|
267
|
+
static #fromOptions(base, options) {
|
|
268
|
+
const { size, width = 1, obliqueness = 0 } = options;
|
|
269
|
+
if (!(width > 0 && isFinite(width))) {
|
|
270
|
+
throw new Error(`width must be positive, not ${width}.`);
|
|
271
|
+
}
|
|
272
|
+
const shaped = base.resize(size).stretch(width).oblique(obliqueness);
|
|
273
|
+
return shaped.#withStrokeWidth(options.strokeWidth ?? shaped.strokeWidth * (options.boldness ?? 1));
|
|
274
|
+
}
|
|
275
|
+
static cursive(sizeOrOptions, degreesRight = 0) {
|
|
276
|
+
const base = (Font.#cursiveBase ??= Font.#hershey(cursiveBase));
|
|
277
|
+
return typeof sizeOrOptions === "number"
|
|
278
|
+
? base.resize(sizeOrOptions).oblique(degreesRight)
|
|
279
|
+
: Font.#fromOptions(base, sizeOrOptions);
|
|
280
|
+
}
|
|
281
|
+
static futuraL(sizeOrOptions, degreesRight = 0) {
|
|
282
|
+
const base = (Font.#futuraLBase ??= Font.#hershey(futuraLBase));
|
|
283
|
+
return typeof sizeOrOptions === "number"
|
|
284
|
+
? base.resize(sizeOrOptions).oblique(degreesRight)
|
|
285
|
+
: Font.#fromOptions(base, sizeOrOptions);
|
|
184
286
|
}
|
|
185
287
|
}
|
|
186
288
|
//# sourceMappingURL=letters-base.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"letters-base.js","sourceRoot":"","sources":["../../../src/glib/letters-base.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,YAAY,EAAW,MAAM,eAAe,CAAC;AACnE,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,0DAA0D;AAC1D,OAAO,WAAW,MAAM,iBAAiB,CAAC,OAAO,IAAI,EAAE,MAAM,EAAE,CAAC;AAChE,OAAO,WAAW,MAAM,gBAAgB,CAAC,OAAO,IAAI,EAAE,MAAM,EAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"letters-base.js","sourceRoot":"","sources":["../../../src/glib/letters-base.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,YAAY,EAAW,MAAM,eAAe,CAAC;AACnE,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,0DAA0D;AAC1D,OAAO,WAAW,MAAM,iBAAiB,CAAC,OAAO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C,YAAY,CAAC,IAAI,EAAE,aAAa,CAAC,CAAC;IAC7C,CAAC;CACF"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Font, FontMetrics } from "./letters-base.ts";
|
|
1
|
+
import { Font, FontMetrics, FontOptions } from "./letters-base.ts";
|
|
2
2
|
import { PathShape } from "./path-shape.ts";
|
|
3
3
|
declare class DescriptionOfLetter {
|
|
4
4
|
#private;
|
|
@@ -64,13 +64,33 @@ declare class DescriptionOfLetter {
|
|
|
64
64
|
*/
|
|
65
65
|
export type FontMap = Map<string, DescriptionOfLetter>;
|
|
66
66
|
/**
|
|
67
|
-
*
|
|
67
|
+
* Everything about a line font, all at once, for {@link makeLineFont}.
|
|
68
|
+
* The same options the other fonts take. See {@link FontOptions}.
|
|
69
|
+
*/
|
|
70
|
+
export type LineFontOptions = FontOptions;
|
|
71
|
+
/**
|
|
72
|
+
* Make a line font.
|
|
68
73
|
* @param fontMetrics How big to make the font.
|
|
69
74
|
* There are additional things you can configure with a LineFontMetrics object.
|
|
70
75
|
* In particular, some letters get a little wider if you use a thicker line width.
|
|
76
|
+
*
|
|
77
|
+
* Or a {@link LineFontOptions}, to set the size, boldness, width and slant all
|
|
78
|
+
* at once.
|
|
71
79
|
* @returns
|
|
72
80
|
*/
|
|
73
|
-
export declare function makeLineFont(fontMetrics: number | LineFontMetrics): Font;
|
|
81
|
+
export declare function makeLineFont(fontMetrics: number | LineFontMetrics | LineFontOptions): Font;
|
|
82
|
+
/**
|
|
83
|
+
* The narrowest `width` ({@link LineFontOptions}) the text components draw. A
|
|
84
|
+
* Font Width of 0 or less in the Visual Editor is drawn at this width, as
|
|
85
|
+
* thin as it goes, instead of throwing.
|
|
86
|
+
*/
|
|
87
|
+
export declare const MIN_FONT_WIDTH = 0.01;
|
|
88
|
+
/**
|
|
89
|
+
* The smallest `size` the text components draw. A Font Size of 0 or less in
|
|
90
|
+
* the Visual Editor is drawn at this size, too small to see, instead of
|
|
91
|
+
* throwing. Typing 0.5 passes through 0, and an animation can start at 0.
|
|
92
|
+
*/
|
|
93
|
+
export declare const MIN_FONT_SIZE = 0.000001;
|
|
74
94
|
/**
|
|
75
95
|
* Create a font whose full height (top margin through descender) equals
|
|
76
96
|
* `totalHeight`. The mHeight (cap height) is `totalHeight * 2/3` because
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"line-font.d.ts","sourceRoot":"","sources":["../../../src/glib/line-font.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"line-font.d.ts","sourceRoot":"","sources":["../../../src/glib/line-font.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACnE,OAAO,EACL,SAAS,EAMV,MAAM,iBAAiB,CAAC;AAczB,cAAM,mBAAmB;;IAerB;;;;OAIG;aACa,OAAO,EAAE,MAAM;aACf,WAAW,EAAE,WAAW;IApB1C;;;;OAIG;IACH,OAAO,CAAC,QAAQ,EAAE,SAAS;IAI3B,IAAI,KAAK,cAER;gBAEC,KAAK,EAAE,SAAS,GAAG,CAAC,MAAM,SAAS,CAAC;IACpC;;;;OAIG;IACa,OAAO,EAAE,MAAM,EACf,WAAW,EAAE,WAAW;IAQ1C;;;;OAIG;IACH,IAAI,OAAO,WAEV;IACD,IAAI,CAAC,WAEJ;IACD;;;;;;;;OAQG;IACH,WAAW,IAAI,cAAc;IAG7B;;;OAGG;IACH,YAAY;;;;;;;;;CAMb;AAED;;;;;;;GAOG;AACH,MAAM,MAAM,OAAO,GAAG,GAAG,CAAC,MAAM,EAAE,mBAAmB,CAAC,CAAC;AAEvD;;;GAGG;AACH,MAAM,MAAM,eAAe,GAAG,WAAW,CAAC;AAE1C;;;;;;;;;GASG;AACH,wBAAgB,YAAY,CAC1B,WAAW,EAAE,MAAM,GAAG,eAAe,GAAG,eAAe,GACtD,IAA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lD"}
|
|
@@ -76,18 +76,57 @@ class DescriptionOfLetter {
|
|
|
76
76
|
}
|
|
77
77
|
}
|
|
78
78
|
/**
|
|
79
|
-
*
|
|
79
|
+
* Make a line font.
|
|
80
80
|
* @param fontMetrics How big to make the font.
|
|
81
81
|
* There are additional things you can configure with a LineFontMetrics object.
|
|
82
82
|
* In particular, some letters get a little wider if you use a thicker line width.
|
|
83
|
+
*
|
|
84
|
+
* Or a {@link LineFontOptions}, to set the size, boldness, width and slant all
|
|
85
|
+
* at once.
|
|
83
86
|
* @returns
|
|
84
87
|
*/
|
|
85
88
|
export function makeLineFont(fontMetrics) {
|
|
89
|
+
if (typeof fontMetrics === "object" &&
|
|
90
|
+
!(fontMetrics instanceof LineFontMetrics)) {
|
|
91
|
+
return makeLineFontFromOptions(fontMetrics);
|
|
92
|
+
}
|
|
86
93
|
const fontMap = makeLineFontMap(fontMetrics);
|
|
87
94
|
const { top, bottom, spaceWidth, strokeWidth, defaultKerning, mHeight } = (fontMap.get("0") ?? pickAny(fontMap)).fontMetrics;
|
|
88
95
|
const result = new Font(top, bottom, spaceWidth, strokeWidth, defaultKerning, mHeight, fontMap);
|
|
89
96
|
return result;
|
|
90
97
|
}
|
|
98
|
+
/**
|
|
99
|
+
* The narrowest `width` ({@link LineFontOptions}) the text components draw. A
|
|
100
|
+
* Font Width of 0 or less in the Visual Editor is drawn at this width, as
|
|
101
|
+
* thin as it goes, instead of throwing.
|
|
102
|
+
*/
|
|
103
|
+
export const MIN_FONT_WIDTH = 0.01;
|
|
104
|
+
/**
|
|
105
|
+
* The smallest `size` the text components draw. A Font Size of 0 or less in
|
|
106
|
+
* the Visual Editor is drawn at this size, too small to see, instead of
|
|
107
|
+
* throwing. Typing 0.5 passes through 0, and an animation can start at 0.
|
|
108
|
+
*/
|
|
109
|
+
export const MIN_FONT_SIZE = 1e-6;
|
|
110
|
+
/** {@link makeLineFont} with a {@link LineFontOptions}. */
|
|
111
|
+
function makeLineFontFromOptions(options) {
|
|
112
|
+
const { size, width = 1, obliqueness = 0 } = options;
|
|
113
|
+
if (!(width > 0 && isFinite(width))) {
|
|
114
|
+
throw new Error(`width must be positive, not ${width}.`);
|
|
115
|
+
}
|
|
116
|
+
// Some letters are drawn for a particular stroke width at a particular size:
|
|
117
|
+
// the K's three lines meet exactly, for example. A stretched font has two
|
|
118
|
+
// sizes, so build it at their geometric mean, then scale it to the height and
|
|
119
|
+
// width asked for. With a width of 1, that's exactly makeLineFontRatio().
|
|
120
|
+
const buildSize = size * Math.sqrt(width);
|
|
121
|
+
const strokeWidth = options.strokeWidth ??
|
|
122
|
+
LineFontMetrics.defaultStrokeWidth(buildSize) * (options.boldness ?? 1);
|
|
123
|
+
// resize() scales the stroke width by size / buildSize, and stretch() by
|
|
124
|
+
// √width, so it comes out as strokeWidth.
|
|
125
|
+
return makeLineFont(new LineFontMetrics(buildSize, strokeWidth))
|
|
126
|
+
.resize(size)
|
|
127
|
+
.stretch(width)
|
|
128
|
+
.oblique(obliqueness);
|
|
129
|
+
}
|
|
91
130
|
/**
|
|
92
131
|
* Create a font whose full height (top margin through descender) equals
|
|
93
132
|
* `totalHeight`. The mHeight (cap height) is `totalHeight * 2/3` because
|