@logomarks/typemarks 0.1.0 → 0.2.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/CHANGELOG.md +18 -0
- package/README.md +4 -0
- package/package.json +1 -1
- package/src/edits/index.js +3 -1
- package/src/edits/short.js +445 -0
- package/src/index.d.ts +5 -0
- package/src/index.js +1 -1
- package/src/ops.js +2 -2
- package/src/suggest.js +21 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.2.0 (2026-11-27)
|
|
4
|
+
|
|
5
|
+
- **Short names** (`src/edits/short.js`, `isShort`, `SHORT_EDITS`): nine moves for names of one to three letters, which
|
|
6
|
+
a quiet edit can't carry (a page for JO was 27 filled counters, one for X 27 full stops): `monoJoin` (two capitals
|
|
7
|
+
sharing a stroke), `inset` (one letter inside the other's counter or open side), `stack` (two capitals one above the
|
|
8
|
+
other, or three with the first big), `knock` and `frame` (a single letter cut out of, or framed by, a square, rounded
|
|
9
|
+
square or disc), `link` (two capitals passing over and under), `split` (a single letter cut through and slid),
|
|
10
|
+
`echo` (a solid block shadow, capitals in a heavy face only: stroke a fifth of the cap height or more) and `lines` (two or three level gaps). A stack takes
|
|
11
|
+
letters of like widths (within 1.25 to 1) that make a lockup near square; stacks and shadows rank below the rest, and a
|
|
12
|
+
page holds at most two stacks and three shadows. Each keeps its banned reads out by letter
|
|
13
|
+
(`docs/edits.md`). They find nothing for a longer name: the pages for LUCIA, TRAVIS and NORTHWIND COFFEE are
|
|
14
|
+
byte-identical to 0.1.0's.
|
|
15
|
+
- `suggest()`: on a short name no move takes more than eight of a page of forty (moves on a page of 40 in the test
|
|
16
|
+
fonts, before → after: JO 4 → 8, OX 3 → 5, X 2 → 5, Q 2 → 7, AI 6 → 8, KAI 8 → 9; the most of one move, before →
|
|
17
|
+
after: JO 27 → 8, OX 28 → 8, X 27 → 8, Q 24 → 8; a single X or OX fills 35 of 40, every move at its cap), and a short name's lowercase q, b or d is never given a filled
|
|
18
|
+
counter.
|
|
19
|
+
- `ops.bolder` and `ops.counterOf` are exported.
|
|
20
|
+
|
|
3
21
|
## 0.1.0 (2026-11-26)
|
|
4
22
|
|
|
5
23
|
- `suggest()` sets like a designer: one case through the word (capitals or lowercase, never as typed unless `lock.case`
|
package/README.md
CHANGED
|
@@ -13,6 +13,10 @@ through its spine… Each is made of general operations (stretch, shorten, detac
|
|
|
13
13
|
tuck letters under a bar) on the strokes measured from the outline: bars with free or held ends, stems, slanted legs,
|
|
14
14
|
forks.
|
|
15
15
|
|
|
16
|
+
A name of one to three letters gets monogram moves instead: two capitals set into each other or linked, one letter
|
|
17
|
+
inside the other's counter, stacked, a single letter knocked out of a square or disc or framed by one, split, echoed by
|
|
18
|
+
a block shadow, or cut by lines (`docs/edits.md`, "Short names").
|
|
19
|
+
|
|
16
20
|
## Install
|
|
17
21
|
|
|
18
22
|
```sh
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@logomarks/typemarks",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Wordmarks from any font, no AI: a name set in a font and cut by design rules (a crossbar dropped, a shared stroke, a stencil break, one slice across the word, a bar extended, a letter swapped…), each edit found from the font's own outlines, ranked into a page of diverse results. Runs in the browser and in Node; reads TTF, OTF and WOFF (TrueType or CFF outlines) with opentype.js.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/index.js",
|
package/src/edits/index.js
CHANGED
|
@@ -14,9 +14,11 @@ import counter from './counter.js';
|
|
|
14
14
|
import round from './round.js';
|
|
15
15
|
import accent from './accent.js';
|
|
16
16
|
import { PIXEL_EDITS } from './pixel.js';
|
|
17
|
+
import { SHORT_EDITS } from './short.js';
|
|
17
18
|
import { RULES } from './rules.js';
|
|
18
19
|
|
|
19
|
-
export const EDITS = Object.fromEntries([drop, cut, stencil, slice, ligature, overlap, bar, underline, swap, counter, round, accent, ...PIXEL_EDITS, ...RULES].map((e) => [e.id, e]));
|
|
20
|
+
export const EDITS = Object.fromEntries([drop, cut, stencil, slice, ligature, overlap, bar, underline, swap, counter, round, accent, ...PIXEL_EDITS, ...SHORT_EDITS, ...RULES].map((e) => [e.id, e]));
|
|
20
21
|
|
|
21
22
|
export { RULES, fits } from './rules.js';
|
|
22
23
|
export { pixelOf } from './pixel.js';
|
|
24
|
+
export { isShort, SHORT_EDITS } from './short.js';
|
|
@@ -0,0 +1,445 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Moves for short names: one to three letters (JO, OX, AI, KAI, a single Q). A long name has room for a quiet edit to
|
|
3
|
+
* carry it; a short one has too few letters for that, so these treat the letters as a monogram: two set into each other
|
|
4
|
+
* until they share a stroke, one set inside the other's counter or open side, stacked one above the other, linked with
|
|
5
|
+
* an over and under, echoed by a shadow, cut by lines, a single letter split or knocked out of a solid shape. Each finds
|
|
6
|
+
* nothing for a name of four letters or more, so a long name's page is as it was.
|
|
7
|
+
*
|
|
8
|
+
* Banned reads are kept out by letter: two holed letters side by side (a face, glasses), a round letter inside a round
|
|
9
|
+
* one (a target), an X or a stem inside a ring (a cancel or power sign), straight letters crossed (a cross), and the
|
|
10
|
+
* letters that read as a sign or a known logo in a frame (® © ⓘ ⓧ, H for a hospital or a helipad, P for parking, f, t,
|
|
11
|
+
* N, M, Y, W, K and U as app icons and certification marks, A in a ring).
|
|
12
|
+
*/
|
|
13
|
+
import { U, D, I, mapPts, rect, rr, circle, poly } from '@logomarks/core/geometry';
|
|
14
|
+
import { grown } from '@logomarks/core/geometry';
|
|
15
|
+
import { moved, ink } from '../geo.js';
|
|
16
|
+
import { boxOf, featuresOf, runsAt } from '../features.js';
|
|
17
|
+
import { fill } from '../raster.js';
|
|
18
|
+
import { CAP, shiftFrom, strokeOf } from '../word.js';
|
|
19
|
+
import { roomBetween, bolder, counterOf } from '../ops.js';
|
|
20
|
+
|
|
21
|
+
/** The letters with ink. */
|
|
22
|
+
const inked = (word) => word.letters.filter((l) => l.shape.length);
|
|
23
|
+
/** A name of one to three letters, one word. */
|
|
24
|
+
export const isShort = (word) => { const n = inked(word).length; return n >= 1 && n <= 3 && !word.letters.some((l) => /\s/.test(l.char)); };
|
|
25
|
+
const stemOf = (word) => word.stem || strokeOf(word);
|
|
26
|
+
|
|
27
|
+
const STRAIGHT = 'IiLlTtJj1|';
|
|
28
|
+
/** Two letters whose crossing reads as a cross (IT, TL, XI …). */
|
|
29
|
+
const crossy = (a, b) => (STRAIGHT.includes(a) && STRAIGHT.includes(b)) || ('Xx+'.includes(a) && STRAIGHT.includes(b)) || ('Xx+'.includes(b) && STRAIGHT.includes(a));
|
|
30
|
+
const holed = (l) => (l.f?.holes?.length ?? 0) > 0;
|
|
31
|
+
/** A letter more than its stem (an I or an l set into another vanishes). */
|
|
32
|
+
const wide = (l) => l.f && l.f.w > l.f.stem * 1.8;
|
|
33
|
+
/**
|
|
34
|
+
* A pair that can be set into each other: capitals (a lowercase stem set into a bowl makes another letter: j and o
|
|
35
|
+
* become a p), neither narrow (condensed letters overlapped are a smudge), never a cross, never two holes side by side.
|
|
36
|
+
*/
|
|
37
|
+
const capital = (c) => c !== c.toLowerCase() && c === c.toUpperCase();
|
|
38
|
+
const ROUND = 'OQ0CGD';
|
|
39
|
+
/** A round letter set into an X is a fish (and an alpha). */
|
|
40
|
+
const fishy = (a, b) => (a === 'X' && ROUND.includes(b)) || (b === 'X' && ROUND.includes(a));
|
|
41
|
+
const pairable = (a, b) => wide(a) && wide(b) && capital(a.char) && capital(b.char) && Math.min(a.f.w, b.f.w) > CAP * 0.6 && !crossy(a.char, b.char) && !fishy(a.char, b.char) && !(holed(a) && holed(b));
|
|
42
|
+
|
|
43
|
+
/** Consecutive pairs of inked letters, as letter indices. */
|
|
44
|
+
function pairsOf(word) {
|
|
45
|
+
const idx = word.letters.map((l, i) => (l.shape.length ? i : -1)).filter((i) => i >= 0), out = [];
|
|
46
|
+
for (let k = 1; k < idx.length; k++) out.push([idx[k - 1], idx[k]]);
|
|
47
|
+
return out;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** A shape scaled by s from its box's top-left corner to (x0, y0). */
|
|
51
|
+
const placedAt = (shape, s, x0, y0) => { const b = boxOf(shape); return mapPts(shape, ([x, y]) => [x0 + (x - b[0]) * s, y0 + (y - b[1]) * s]); };
|
|
52
|
+
/** The weight a letter set at s loses, given back (no more than a fifth of a counter at its size). */
|
|
53
|
+
const thickenFor = (word, s) => { const stem = stemOf(word); return Math.min((stem * (1 - s)) / 2 * 0.85, 0.2 * counterOf(word, stem) * s); };
|
|
54
|
+
/** A letter's shape set at scale s, its top-left at (x0, y0), made a touch bolder for the size it lost. */
|
|
55
|
+
function smaller(word, l, s, x0, y0) {
|
|
56
|
+
let shape = placedAt(l.shape, s, x0, y0);
|
|
57
|
+
const t = s < 1 ? thickenFor(word, s) : 0;
|
|
58
|
+
if (t > stemOf(word) * 0.04) shape = bolder(shape, t);
|
|
59
|
+
return shape;
|
|
60
|
+
}
|
|
61
|
+
/** Puts a letter's new shape in, moving its x with it and measuring it again. */
|
|
62
|
+
function setShape(l, shape, flag = 'tucked') {
|
|
63
|
+
const dx = boxOf(shape)[0] - boxOf(l.shape)[0];
|
|
64
|
+
l.shape = shape; l.x += dx; l.f = featuresOf(shape, l.char);
|
|
65
|
+
l.edited = true; l[flag] = true;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/* ---------- Monogram: two letters set into each other until they share a stroke ---------- */
|
|
69
|
+
|
|
70
|
+
const joinable = (word, [i, j]) => pairable(word.letters[i], word.letters[j]);
|
|
71
|
+
|
|
72
|
+
export const monoJoin = {
|
|
73
|
+
id: 'monoJoin', name: 'Monogram', line: 'Two letters set into each other until they share a stroke.',
|
|
74
|
+
controls: [
|
|
75
|
+
{ key: 'share', label: 'Share', type: 'choice', options: ['stroke', 'more'], value: 'stroke' },
|
|
76
|
+
{ key: 'pair', label: 'Pair', type: 'choice', options: ['first', 'last'], value: 'first' },
|
|
77
|
+
],
|
|
78
|
+
find: (word) => (isShort(word) ? pairsOf(word).filter((pr) => joinable(word, pr)).map(([i]) => i) : []),
|
|
79
|
+
apply(word, p) {
|
|
80
|
+
const prs = pairsOf(word).filter((pr) => joinable(word, pr));
|
|
81
|
+
if (!prs.length) return false;
|
|
82
|
+
const [i, j] = p.pair === 'last' ? prs.at(-1) : prs[0], a = word.letters[i], b = word.letters[j], stem = stemOf(word);
|
|
83
|
+
// closed until the nearest ink of the two overlaps by one stroke (or a stroke and a half): the stroke they share
|
|
84
|
+
const shift = roomBetween(a.shape, b.shape, 0) + stem * (p.share === 'more' ? 1.5 : 1);
|
|
85
|
+
shiftFrom(word, j, -shift);
|
|
86
|
+
b.shape = U(a.shape, b.shape);
|
|
87
|
+
a.shape = [];
|
|
88
|
+
b.edited = true; b.joined = true;
|
|
89
|
+
word.fused = true;
|
|
90
|
+
return true;
|
|
91
|
+
},
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
/* ---------- Inset: one letter set inside the other's counter or open side ---------- */
|
|
95
|
+
|
|
96
|
+
const ROUNDISH = 'OQ0CGDUocgdeaqbpu';
|
|
97
|
+
/** An inner letter that reads as a sign inside this outer one: a ring in a ring (a target), an X or a stem in a ring. */
|
|
98
|
+
function insetBanned(outer, inner) {
|
|
99
|
+
const o = outer.char, n = inner.char;
|
|
100
|
+
if ('OQ0o'.includes(n) && (holed(outer) || ROUNDISH.includes(o))) return true;
|
|
101
|
+
if ('Xx+'.includes(n) && ROUNDISH.includes(o)) return true;
|
|
102
|
+
if ('Ii1l|'.includes(n) && 'OQ0oC'.includes(o)) return true;
|
|
103
|
+
return false;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Where `inner` fits inside `outer`'s box, clear of its ink by `gap`: the biggest scale (down to `min`) at which a box of
|
|
108
|
+
* inner's shape fits in the white of outer's box, placed nearest the middle of all the places it fits. From a bitmap of
|
|
109
|
+
* outer, its ink grown by the gap, and a summed-area table, so each try is a lookup. The inner letter keeps the reading
|
|
110
|
+
* order: the second letter sits in the right half or the middle, the first in the left half or the middle.
|
|
111
|
+
*/
|
|
112
|
+
function fitInside(outer, inner, gap, min, side = 0) {
|
|
113
|
+
const ob = boxOf(outer), ib = boxOf(inner), ow = ob[2] - ob[0], oh = ob[3] - ob[1], iw = ib[2] - ib[0], ih = ib[3] - ib[1];
|
|
114
|
+
const R = 120, u = Math.max(ow, oh) / R, W = Math.ceil(ow / u), H = Math.ceil(oh / u);
|
|
115
|
+
const bits = fill(outer, [ob[0], ob[1], ob[0] + W * u, ob[1] + H * u], W, H);
|
|
116
|
+
// the ink grown by the gap, cell by cell (a square reach: a little more than the gap on the diagonal)
|
|
117
|
+
const g = Math.ceil(gap / u), grownBits = new Uint8Array(W * H);
|
|
118
|
+
for (let r = 0; r < H; r++) for (let c = 0; c < W; c++) {
|
|
119
|
+
if (!bits[r * W + c]) continue;
|
|
120
|
+
for (let rr2 = Math.max(0, r - g); rr2 <= Math.min(H - 1, r + g); rr2++) for (let cc = Math.max(0, c - g); cc <= Math.min(W - 1, c + g); cc++) grownBits[rr2 * W + cc] = 1;
|
|
121
|
+
}
|
|
122
|
+
const S = new Int32Array((W + 1) * (H + 1));
|
|
123
|
+
for (let r = 0; r < H; r++) for (let c = 0; c < W; c++) S[(r + 1) * (W + 1) + c + 1] = grownBits[r * W + c] + S[r * (W + 1) + c + 1] + S[(r + 1) * (W + 1) + c] - S[r * (W + 1) + c];
|
|
124
|
+
const sum = (r0, c0, r1, c1) => S[r1 * (W + 1) + c1] - S[r0 * (W + 1) + c1] - S[r1 * (W + 1) + c0] + S[r0 * (W + 1) + c0];
|
|
125
|
+
for (let s = 0.8; s >= min; s -= 0.02) {
|
|
126
|
+
const w = Math.ceil((iw * s) / u), h = Math.ceil((ih * s) / u);
|
|
127
|
+
if (w >= W || h >= H) continue;
|
|
128
|
+
const spots = [];
|
|
129
|
+
// side: the inner letter's middle right of the outer's (it is the second letter) or left of it (the first)
|
|
130
|
+
for (let r = 0; r + h <= H; r++) for (let c = 0; c + w <= W; c++) if (!sum(r, c, r + h, c + w) && (side * (c + w / 2 - W / 2) >= -W * 0.04)) spots.push([r, c]);
|
|
131
|
+
if (!spots.length) continue;
|
|
132
|
+
// held: the outer letter's ink on three sides of the spot of four (a counter on all four, a C's mouth on three); a
|
|
133
|
+
// spot in a corner of the box, beside an A's apex or a J's hook, is outside the letter, not in it
|
|
134
|
+
const ink1 = (r, c) => bits[r * W + c] === 1;
|
|
135
|
+
const held = ([r, c]) => {
|
|
136
|
+
const rm = Math.min(H - 1, r + (h >> 1)), cm = Math.min(W - 1, c + (w >> 1));
|
|
137
|
+
let n = 0;
|
|
138
|
+
for (let k = c - 1; k >= 0; k--) if (ink1(rm, k)) { n++; break; }
|
|
139
|
+
for (let k = c + w; k < W; k++) if (ink1(rm, k)) { n++; break; }
|
|
140
|
+
for (let k = r - 1; k >= 0; k--) if (ink1(k, cm)) { n++; break; }
|
|
141
|
+
for (let k = r + h; k < H; k++) if (ink1(k, cm)) { n++; break; }
|
|
142
|
+
return n >= 3;
|
|
143
|
+
};
|
|
144
|
+
for (let k = spots.length - 1; k >= 0; k--) if (!held(spots[k])) spots.splice(k, 1);
|
|
145
|
+
if (!spots.length) continue;
|
|
146
|
+
const mr = spots.reduce((t, [r]) => t + r, 0) / spots.length, mc = spots.reduce((t, [, c]) => t + c, 0) / spots.length;
|
|
147
|
+
const [r, c] = spots.reduce((best, sp) => (Math.hypot(sp[0] - mr, sp[1] - mc) < Math.hypot(best[0] - mr, best[1] - mc) ? sp : best));
|
|
148
|
+
return { s, x0: ob[0] + c * u + (w * u - iw * s) / 2, y0: ob[1] + r * u + (h * u - ih * s) / 2 };
|
|
149
|
+
}
|
|
150
|
+
return null;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
export const inset = {
|
|
154
|
+
id: 'inset', name: 'Inset', line: 'One letter set inside the other’s counter or open side.',
|
|
155
|
+
controls: [{ key: 'order', label: 'Inside', type: 'choice', options: ['auto', 'second', 'first'], value: 'auto' }],
|
|
156
|
+
find(word) {
|
|
157
|
+
if (!isShort(word) || inked(word).length !== 2) return [];
|
|
158
|
+
const [a, b] = inked(word);
|
|
159
|
+
return insetBanned(a, b) && insetBanned(b, a) ? [] : [0];
|
|
160
|
+
},
|
|
161
|
+
apply(word, p) {
|
|
162
|
+
const [a, b] = inked(word), gap = stemOf(word) * 0.75;
|
|
163
|
+
// 'second': the second letter goes inside the first; 'first': the first inside the second
|
|
164
|
+
const tries = p.order === 'second' ? [[a, b]] : p.order === 'first' ? [[b, a]] : [[a, b], [b, a]];
|
|
165
|
+
let best = null;
|
|
166
|
+
for (const [outer, inner] of tries) {
|
|
167
|
+
if (insetBanned(outer, inner)) continue;
|
|
168
|
+
const at = fitInside(outer.shape, inner.shape, gap, 0.34, inner === b ? 1 : -1);
|
|
169
|
+
if (at && (!best || at.s > best.at.s)) best = { outer, inner, at };
|
|
170
|
+
}
|
|
171
|
+
if (!best) return false;
|
|
172
|
+
const { outer, inner, at } = best;
|
|
173
|
+
let shape = smaller(word, inner, at.s, at.x0, at.y0);
|
|
174
|
+
// grown a touch for its weight: still clear of the outer letter, or back to its plain size
|
|
175
|
+
if (I(shape, outer.shape).length) shape = placedAt(inner.shape, at.s, at.x0, at.y0);
|
|
176
|
+
if (I(shape, outer.shape).length) return false;
|
|
177
|
+
setShape(inner, shape);
|
|
178
|
+
return true;
|
|
179
|
+
},
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
/* ---------- Stack: the letters one above the other ---------- */
|
|
183
|
+
|
|
184
|
+
export const stack = {
|
|
185
|
+
id: 'stack', name: 'Stacked', line: 'Two capitals one above the other, or three with the first big and two stacked beside it.',
|
|
186
|
+
controls: [
|
|
187
|
+
{ key: 'mode', label: 'Stack', type: 'choice', options: ['rows', 'lead'], value: 'rows' },
|
|
188
|
+
{ key: 'align', label: 'Align', type: 'choice', options: ['centre', 'left'], value: 'centre' },
|
|
189
|
+
],
|
|
190
|
+
// capitals: lowercase letters stacked sit at three heights and read as a list
|
|
191
|
+
// …and each wider than its stem: an A over an I is an arrow, an I over an O a pin
|
|
192
|
+
// …and no round letter on top: a ring over a letter is a head over a body
|
|
193
|
+
find: (word) => (isShort(word) && inked(word).length >= 2 && inked(word).every((l) => capital(l.char) && wide(l)) && !'OQ0'.includes(inked(word)[0].char) ? [0] : []),
|
|
194
|
+
apply(word, p) {
|
|
195
|
+
const ls = inked(word), stem = stemOf(word), gap = Math.max(stem * 0.8, CAP * 0.07);
|
|
196
|
+
if (p.mode === 'rows' && ls.length !== 2) return false; // three rows are a tall thin column
|
|
197
|
+
// letters of like widths only, and a lockup near square (a J balanced on an O reads as a figure or a key)
|
|
198
|
+
const like = (x, y) => { const wx = boxOf(x.shape)[2] - boxOf(x.shape)[0], wy = boxOf(y.shape)[2] - boxOf(y.shape)[0]; return Math.max(wx, wy) / Math.min(wx, wy) <= 1.25; };
|
|
199
|
+
if (p.mode === 'rows') {
|
|
200
|
+
const [A, B] = ls, ba = boxOf(A.shape), bb = boxOf(B.shape);
|
|
201
|
+
const w = Math.max(ba[2] - ba[0], bb[2] - bb[0]), h = ba[3] - ba[1] + bb[3] - bb[1] + gap;
|
|
202
|
+
if (!like(A, B) || w / h < 0.6) return false;
|
|
203
|
+
} else if (ls.length === 3 && !like(ls[1], ls[2])) return false;
|
|
204
|
+
if (p.mode === 'lead') {
|
|
205
|
+
if (ls.length !== 3) return false;
|
|
206
|
+
const [A, B, C] = ls, ba = boxOf(A.shape), bb = boxOf(B.shape), bc = boxOf(C.shape);
|
|
207
|
+
const s = (ba[3] - ba[1] - gap) / (bb[3] - bb[1] + bc[3] - bc[1]);
|
|
208
|
+
if (s < 0.4) return false;
|
|
209
|
+
const x0 = ba[2] + gap;
|
|
210
|
+
const top = smaller(word, B, s, x0, ba[1]);
|
|
211
|
+
const foot = smaller(word, C, s, x0, ba[3] - (bc[3] - bc[1]) * s);
|
|
212
|
+
// the weight given back mustn't close the gap between the two small ones
|
|
213
|
+
if (I(top, foot).length || I(top, A.shape).length || I(foot, A.shape).length) return false;
|
|
214
|
+
setShape(B, top); setShape(C, foot);
|
|
215
|
+
return true;
|
|
216
|
+
}
|
|
217
|
+
// rows: each letter on its own row, the gap between
|
|
218
|
+
const boxes = ls.map((l) => boxOf(l.shape)), cx = (boxes[0][0] + boxes[0][2]) / 2, x0 = boxes[0][0];
|
|
219
|
+
let y = 0;
|
|
220
|
+
for (let k = ls.length - 1; k >= 0; k--) {
|
|
221
|
+
const b = boxes[k], h = b[3] - b[1], w = b[2] - b[0];
|
|
222
|
+
const left = p.align === 'left' ? x0 : cx - w / 2;
|
|
223
|
+
setShape(ls[k], moved(ls[k].shape, left - b[0], y - b[3]));
|
|
224
|
+
y -= h + gap;
|
|
225
|
+
}
|
|
226
|
+
return true;
|
|
227
|
+
},
|
|
228
|
+
};
|
|
229
|
+
|
|
230
|
+
/* ---------- Knock-out and frame: a single letter in a solid shape, or in an outline of one ---------- */
|
|
231
|
+
|
|
232
|
+
/** The letters a container turns into a sign or a known mark (by its upper case). */
|
|
233
|
+
const FRAME_BANNED = {
|
|
234
|
+
disc: 'ABCGHIKOPQRSUWX0E',
|
|
235
|
+
square: 'FHIMNOPUXY0',
|
|
236
|
+
round: 'EFHIMNOPQTUVXY0',
|
|
237
|
+
};
|
|
238
|
+
const banned = (shape, ch) => FRAME_BANNED[shape].includes(ch.toUpperCase());
|
|
239
|
+
|
|
240
|
+
/** The container round a single letter: a square, a rounded square or a disc, `pad` clear of its ink. */
|
|
241
|
+
function containerOf(l, kind, pad) {
|
|
242
|
+
const b = boxOf(l.shape), cx = (b[0] + b[2]) / 2, cy = (b[1] + b[3]) / 2;
|
|
243
|
+
if (kind === 'disc') {
|
|
244
|
+
let r = 0;
|
|
245
|
+
for (const pg of l.shape) for (const [x, y] of pg[0]) r = Math.max(r, Math.hypot(x - cx, y - cy));
|
|
246
|
+
return { make: (extra) => circle(cx, cy, r + pad + extra, 180), cx, cy };
|
|
247
|
+
}
|
|
248
|
+
const side = Math.max(b[2] - b[0], b[3] - b[1]) + 2 * pad;
|
|
249
|
+
return {
|
|
250
|
+
make: (extra) => { const sd = side + 2 * extra; return kind === 'round' ? rr(cx - sd / 2, cy - sd / 2, sd, sd, sd * 0.22) : rect(cx - sd / 2, cy - sd / 2, sd, sd); },
|
|
251
|
+
cx, cy,
|
|
252
|
+
};
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
const single = (word) => isShort(word) && inked(word).length === 1;
|
|
256
|
+
|
|
257
|
+
export const knock = {
|
|
258
|
+
id: 'knock', name: 'Knock-out', line: 'The letter cut out of a solid square, rounded square or disc.',
|
|
259
|
+
controls: [
|
|
260
|
+
{ key: 'shape', label: 'Shape', type: 'choice', options: ['square', 'round', 'disc'], value: 'square' },
|
|
261
|
+
{ key: 'pad', label: 'Margin', type: 'range', min: 0.9, max: 1.8, step: 0.05, value: 1.2 },
|
|
262
|
+
],
|
|
263
|
+
find: (word) => (single(word) && Object.keys(FRAME_BANNED).some((k) => !banned(k, inked(word)[0].char)) ? [0] : []),
|
|
264
|
+
apply(word, p) {
|
|
265
|
+
const l = inked(word)[0];
|
|
266
|
+
if (banned(p.shape, l.char)) return false;
|
|
267
|
+
const box = containerOf(l, p.shape, stemOf(word) * p.pad).make(0);
|
|
268
|
+
word.extra.push(D(box, l.shape));
|
|
269
|
+
l.shape = []; l.edited = true;
|
|
270
|
+
word.fused = true;
|
|
271
|
+
return true;
|
|
272
|
+
},
|
|
273
|
+
};
|
|
274
|
+
|
|
275
|
+
export const frame = {
|
|
276
|
+
id: 'frame', name: 'Framed', line: 'The letter inside an outline of a square, rounded square or disc.',
|
|
277
|
+
controls: [
|
|
278
|
+
{ key: 'shape', label: 'Shape', type: 'choice', options: ['round', 'disc', 'square'], value: 'round' },
|
|
279
|
+
{ key: 'pad', label: 'Margin', type: 'range', min: 0.8, max: 1.6, step: 0.05, value: 1.05 },
|
|
280
|
+
],
|
|
281
|
+
find: knock.find,
|
|
282
|
+
apply(word, p) {
|
|
283
|
+
const l = inked(word)[0];
|
|
284
|
+
if (banned(p.shape, l.char)) return false;
|
|
285
|
+
const stem = stemOf(word), c = containerOf(l, p.shape, stem * p.pad);
|
|
286
|
+
word.extra.push(D(c.make(stem * 0.85), c.make(0)));
|
|
287
|
+
l.edited = true;
|
|
288
|
+
word.fused = true;
|
|
289
|
+
return true;
|
|
290
|
+
},
|
|
291
|
+
};
|
|
292
|
+
|
|
293
|
+
/* ---------- Linked: two letters overlapping, passing over and under each other ---------- */
|
|
294
|
+
|
|
295
|
+
const linkable = (word, [i, j]) => pairable(word.letters[i], word.letters[j]);
|
|
296
|
+
|
|
297
|
+
export const link = {
|
|
298
|
+
id: 'link', name: 'Linked', line: 'Two letters overlapping, passing over and under each other where they cross.',
|
|
299
|
+
controls: [
|
|
300
|
+
{ key: 'depth', label: 'Overlap', type: 'range', min: 0.2, max: 0.45, step: 0.01, value: 0.32 },
|
|
301
|
+
{ key: 'gap', label: 'Gap', type: 'range', min: 0.3, max: 0.6, step: 0.02, value: 0.4 },
|
|
302
|
+
{ key: 'front', label: 'In front', type: 'choice', options: ['alternate', 'right', 'left'], value: 'alternate' },
|
|
303
|
+
],
|
|
304
|
+
find: (word) => (isShort(word) ? pairsOf(word).filter((pr) => linkable(word, pr)).map(([i]) => i) : []),
|
|
305
|
+
apply(word, p) {
|
|
306
|
+
const prs = pairsOf(word).filter((pr) => linkable(word, pr));
|
|
307
|
+
if (!prs.length) return false;
|
|
308
|
+
const stem = stemOf(word), g = stem * p.gap;
|
|
309
|
+
for (const [i, j] of prs) {
|
|
310
|
+
const a = word.letters[i], b = word.letters[j];
|
|
311
|
+
shiftFrom(word, j, -(roomBetween(a.shape, b.shape, 0) + p.depth * Math.min(a.f.w, b.f.w)));
|
|
312
|
+
const crossings = I(a.shape, b.shape).filter((pg) => ink([pg]) > stem * stem * 0.15);
|
|
313
|
+
if (!crossings.length) return false;
|
|
314
|
+
const A = a.shape, B = b.shape;
|
|
315
|
+
if (p.front === 'alternate' && crossings.length >= 2) {
|
|
316
|
+
// top to bottom, the crossings take turns: the second letter over the first, then under it
|
|
317
|
+
crossings.sort((p1, p2) => boxOf([p1])[1] - boxOf([p2])[1]);
|
|
318
|
+
let na = A, nb = B;
|
|
319
|
+
crossings.forEach((c, k) => {
|
|
320
|
+
const near = grown([c], g * 1.6), front = k % 2 ? A : B;
|
|
321
|
+
const cutter = I(grown(front, g), near);
|
|
322
|
+
if (k % 2) nb = D(nb, cutter); else na = D(na, cutter);
|
|
323
|
+
});
|
|
324
|
+
a.shape = na; b.shape = nb;
|
|
325
|
+
} else if (p.front === 'left') b.shape = D(B, grown(A, g));
|
|
326
|
+
else a.shape = D(A, grown(B, g));
|
|
327
|
+
a.edited = b.edited = true;
|
|
328
|
+
}
|
|
329
|
+
word.fused = true;
|
|
330
|
+
return true;
|
|
331
|
+
},
|
|
332
|
+
};
|
|
333
|
+
|
|
334
|
+
/** Whether (x, y) is in the shape's ink. */
|
|
335
|
+
const inkAt = (shape, x, y) => runsAt(shape, y).some(([a, b]) => x >= a && x <= b);
|
|
336
|
+
|
|
337
|
+
/* ---------- Split: a single letter cut in two, one half slid along the cut ---------- */
|
|
338
|
+
|
|
339
|
+
export const split = {
|
|
340
|
+
id: 'split', name: 'Split', line: 'A single letter cut through the middle, one half slid along the cut.',
|
|
341
|
+
controls: [
|
|
342
|
+
{ key: 'mode', label: 'Cut', type: 'choice', options: ['level', 'upright', 'slant'], value: 'level' },
|
|
343
|
+
{ key: 'shift', label: 'Slide', type: 'range', min: 0.4, max: 1.2, step: 0.05, value: 0.75 },
|
|
344
|
+
{ key: 'gap', label: 'Gap', type: 'range', min: 0.25, max: 0.6, step: 0.02, value: 0.35 },
|
|
345
|
+
],
|
|
346
|
+
find: (word) => (single(word) ? [0] : []),
|
|
347
|
+
apply(word, p) {
|
|
348
|
+
const l = inked(word)[0], stem = stemOf(word), b = boxOf(l.shape), g = stem * p.gap;
|
|
349
|
+
let cx = (b[0] + b[2]) / 2, cy = (b[1] + b[3]) / 2;
|
|
350
|
+
// a level cut never runs along a crossbar: it moves halfway to the top instead
|
|
351
|
+
if (p.mode === 'level' && l.f?.crossbar) { const c = l.f.crossbar; if (cy > c.y0 - g * 1.5 && cy < c.y1 + g * 1.5) cy = (b[1] + c.y0) / 2; }
|
|
352
|
+
const deg = p.mode === 'level' ? 0 : p.mode === 'upright' ? 90 : -62, t = (deg * Math.PI) / 180;
|
|
353
|
+
const ux = Math.cos(t), uy = Math.sin(t), nx = -uy, ny = ux, F = CAP * 4;
|
|
354
|
+
const side = (k) => poly([
|
|
355
|
+
[cx + nx * k * g / 2 - ux * F, cy + ny * k * g / 2 - uy * F], [cx + nx * k * g / 2 + ux * F, cy + ny * k * g / 2 + uy * F],
|
|
356
|
+
[cx + nx * k * F + ux * F, cy + ny * k * F + uy * F], [cx + nx * k * F - ux * F, cy + ny * k * F - uy * F],
|
|
357
|
+
]);
|
|
358
|
+
// the cut must cross strokes, never a junction (an X cut through its crossing is two chevrons): where it crosses
|
|
359
|
+
// ink, a line beside it a stroke and a third off meets one stroke there, not two arms parting
|
|
360
|
+
const step = stem / 10, crossings = [];
|
|
361
|
+
let start = null;
|
|
362
|
+
for (let t = -CAP * 1.5; t <= CAP * 1.5; t += step) {
|
|
363
|
+
const inside = inkAt(l.shape, cx + ux * t, cy + uy * t);
|
|
364
|
+
if (inside && start === null) start = t;
|
|
365
|
+
if (!inside && start !== null) { crossings.push((start + t) / 2); start = null; }
|
|
366
|
+
}
|
|
367
|
+
// each crossing looks along its own stretch of the line, up to halfway to the next crossing (an O's two walls)
|
|
368
|
+
const runsBeside = (t, k, lo, hi) => {
|
|
369
|
+
let n = 0, was = false;
|
|
370
|
+
for (let q = lo; q <= hi; q += step) {
|
|
371
|
+
const x = cx + ux * (t + q) + nx * k * 1.3 * stem, y = cy + uy * (t + q) + ny * k * 1.3 * stem, now = inkAt(l.shape, x, y);
|
|
372
|
+
if (now && !was) n++;
|
|
373
|
+
was = now;
|
|
374
|
+
}
|
|
375
|
+
return n;
|
|
376
|
+
};
|
|
377
|
+
const reach = (i) => [i > 0 ? Math.max(-3 * stem, (crossings[i - 1] - crossings[i]) / 2) : -3 * stem, i < crossings.length - 1 ? Math.min(3 * stem, (crossings[i + 1] - crossings[i]) / 2) : 3 * stem];
|
|
378
|
+
if (!crossings.length || crossings.some((t, i) => runsBeside(t, 1, ...reach(i)) > 1 || runsBeside(t, -1, ...reach(i)) > 1)) return false;
|
|
379
|
+
const s = stem * p.shift, one = I(l.shape, side(1)), two = moved(I(l.shape, side(-1)), ux * s, uy * s);
|
|
380
|
+
const total = ink(l.shape), pieces = [...one, ...two];
|
|
381
|
+
// a cut that leaves a crumb (a serif's tip, an arm's end) isn't a split
|
|
382
|
+
if (!one.length || !two.length || pieces.some((pg) => ink([pg]) < total * 0.04)) return false;
|
|
383
|
+
l.shape = pieces; l.edited = true; l.sliced = true;
|
|
384
|
+
return true;
|
|
385
|
+
},
|
|
386
|
+
};
|
|
387
|
+
|
|
388
|
+
/* ---------- Echo: the letters and a shadow of them, cut free by a gap ---------- */
|
|
389
|
+
|
|
390
|
+
export const echo = {
|
|
391
|
+
id: 'echo', name: 'Echo', line: 'The letters with a solid block shadow behind, cut free by a gap.',
|
|
392
|
+
controls: [
|
|
393
|
+
{ key: 'dir', label: 'Falls', type: 'choice', options: ['drop', 'rise'], value: 'drop' }, // a shadow rising reads as a fall: by hand only
|
|
394
|
+
{ key: 'depth', label: 'Depth', type: 'range', min: 0.7, max: 1.6, step: 0.05, value: 1.1 },
|
|
395
|
+
{ key: 'gap', label: 'Gap', type: 'range', min: 0.25, max: 0.5, step: 0.01, value: 0.32 },
|
|
396
|
+
],
|
|
397
|
+
// capitals in a heavy face only: a shadow behind lowercase or a light face is a blur at 32 px
|
|
398
|
+
find: (word) => (isShort(word) && inked(word).every((l) => capital(l.char)) && stemOf(word) / CAP >= 0.21 ? [0] : []),
|
|
399
|
+
apply(word, p) {
|
|
400
|
+
if (!this.find(word).length) return false;
|
|
401
|
+
const front = U(...inked(word).map((l) => l.shape)), stem = stemOf(word), d = stem * p.depth, sy = p.dir === 'rise' ? -1 : 1;
|
|
402
|
+
// the letters swept back along the shadow's line, exactly (every edge drawn out into a parallelogram), so the
|
|
403
|
+
// shadow is one solid block with straight sides; kept outside the letters' outlines (a shadow in a counter is
|
|
404
|
+
// clutter), a gap clear of them
|
|
405
|
+
const vx = d, vy = sy * d, quads = [];
|
|
406
|
+
for (const pg of front) for (const ring of pg) for (let i = 0; i < ring.length; i++) {
|
|
407
|
+
const [ax, ay] = ring[i], [bx, by] = ring[(i + 1) % ring.length];
|
|
408
|
+
if (Math.hypot(bx - ax, by - ay) < 0.5) continue;
|
|
409
|
+
quads.push(poly([[ax, ay], [bx, by], [bx + vx, by + vy], [ax + vx, ay + vy]]));
|
|
410
|
+
}
|
|
411
|
+
const solid = U(front, moved(front, vx, vy), ...quads);
|
|
412
|
+
const outline = U(...front.map((pg) => [pg[0]]));
|
|
413
|
+
const total = ink(front);
|
|
414
|
+
const back = D(solid, grown(outline, stem * p.gap)).filter((pg) => ink([pg]) > total * 0.03);
|
|
415
|
+
if (!back.length || ink(back) < total * 0.15) return false;
|
|
416
|
+
word.extra.push(back);
|
|
417
|
+
word.fused = true;
|
|
418
|
+
return true;
|
|
419
|
+
},
|
|
420
|
+
};
|
|
421
|
+
|
|
422
|
+
/* ---------- Lines: two or three level gaps across the letters ---------- */
|
|
423
|
+
|
|
424
|
+
export const lines = {
|
|
425
|
+
id: 'lines', name: 'Lines', line: 'Two or three level gaps cut across the letters.',
|
|
426
|
+
controls: [
|
|
427
|
+
{ key: 'lines', label: 'Lines', type: 'range', min: 2, max: 3, step: 1, value: 2 },
|
|
428
|
+
{ key: 'gap', label: 'Gap', type: 'range', min: 0.22, max: 0.45, step: 0.01, value: 0.3 },
|
|
429
|
+
],
|
|
430
|
+
// three heavy capitals in stripes are a known computing logo
|
|
431
|
+
find: (word) => (isShort(word) && inked(word).map((l) => l.char).join('').toUpperCase() !== 'IBM' ? [0] : []),
|
|
432
|
+
apply(word, p) {
|
|
433
|
+
const ls = inked(word), stem = stemOf(word), g = stem * p.gap, n = Math.round(p.lines);
|
|
434
|
+
const b = boxOf(U(...ls.map((l) => l.shape))), x0 = b[0] - CAP, x1 = b[2] + CAP, top = Math.max(b[1], -CAP), h = Math.min(b[3], 0) - top;
|
|
435
|
+
const cuts = U(...Array.from({ length: n }, (_, k) => rect(x0, top + (h * (k + 1)) / (n + 1) - g / 2, x1 - x0, g)));
|
|
436
|
+
for (const l of ls) {
|
|
437
|
+
const total = ink(l.shape), cut = D(l.shape, cuts);
|
|
438
|
+
if (cut.some((pg) => ink([pg]) < total * 0.025)) return false;
|
|
439
|
+
l.shape = cut; l.edited = true; l.sliced = true;
|
|
440
|
+
}
|
|
441
|
+
return true;
|
|
442
|
+
},
|
|
443
|
+
};
|
|
444
|
+
|
|
445
|
+
export const SHORT_EDITS = [monoJoin, inset, stack, knock, frame, link, split, echo, lines];
|
package/src/index.d.ts
CHANGED
|
@@ -72,6 +72,11 @@ export function typemark(name: string, o: { font: TypeFont; edits?: EditCall[];
|
|
|
72
72
|
export function suggest(name: string, o: { fonts: TypeFont[] | FontRegistry; count?: number; seed?: number | string; lock?: { fonts?: string[]; edits?: string[]; slant?: number; tracking?: number } }): Promise<Typemark[]>;
|
|
73
73
|
/** Every edit, by id (the general edits and the rule book's rules alike). */
|
|
74
74
|
export const EDITS: Record<string, Edit>;
|
|
75
|
+
|
|
76
|
+
/** Whether a set word is a short name: one to three letters, one word (the short-name moves act only on these). */
|
|
77
|
+
export function isShort(word: unknown): boolean;
|
|
78
|
+
/** The short-name moves: monoJoin, inset, stack, knock, frame, link, split, echo, lines (also in `EDITS`). */
|
|
79
|
+
export const SHORT_EDITS: Edit[];
|
|
75
80
|
/** A rule of the letter rule book: an edit keyed on the letters a name has. */
|
|
76
81
|
export interface Rule extends Edit {
|
|
77
82
|
/** The letters any one of which makes the rule fit a name ('RKQ'), or the pairs a pair rule needs (['TT', 'TH', …]). */
|
package/src/index.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
export { loadFont, registry } from './font.js';
|
|
5
5
|
export { typemark } from './typemark.js';
|
|
6
6
|
export { suggest, WEIGHT } from './suggest.js';
|
|
7
|
-
export { EDITS, RULES, fits } from './edits/index.js';
|
|
7
|
+
export { EDITS, RULES, fits, isShort, SHORT_EDITS } from './edits/index.js';
|
|
8
8
|
export { strokesOf } from './strokes.js';
|
|
9
9
|
export * as ops from './ops.js';
|
|
10
10
|
export { setWord, strokeOf, CAP } from './word.js';
|
package/src/ops.js
CHANGED
|
@@ -171,7 +171,7 @@ export function shortenStem(shape, f, x0, x1, edge, len) {
|
|
|
171
171
|
|
|
172
172
|
/** The font's counter width, in word units: the white between an H's stems (or an n's), cached per font. */
|
|
173
173
|
const counters = new WeakMap();
|
|
174
|
-
function counterOf(word, stem) {
|
|
174
|
+
export function counterOf(word, stem) {
|
|
175
175
|
const font = word.font;
|
|
176
176
|
if (!counters.has(font)) {
|
|
177
177
|
let gap = 0;
|
|
@@ -193,7 +193,7 @@ function counterOf(word, stem) {
|
|
|
193
193
|
* counter or a C's mouth, so half is tried, then none.
|
|
194
194
|
*/
|
|
195
195
|
const topology = (shape) => `${shape.length}:${shape.map((p) => p.length).join(',')}`;
|
|
196
|
-
function bolder(shape, d) {
|
|
196
|
+
export function bolder(shape, d) {
|
|
197
197
|
const key = topology(U(shape));
|
|
198
198
|
for (const k of [1, 0.5]) {
|
|
199
199
|
const b = grown(shape, d * k);
|
package/src/suggest.js
CHANGED
|
@@ -20,6 +20,7 @@ export const WEIGHT = {
|
|
|
20
20
|
crossbarDrop: 1, crossShift: 0.96, sharedBar: 0.95, ligature: 0.9, legRun: 0.92, eArms: 0.92, ringLink: 0.9, tRoof: 0.9, lFloor: 0.9,
|
|
21
21
|
nestPair: 0.85, pointCut: 0.8, hBar: 0.78, counter: 0.72, tCut: 0.72, xCut: 0.7, yFork: 0.7, terminalCut: 0.68, crossbarCut: 0.66,
|
|
22
22
|
pixelStep: 0.98, pixelCursor: 0.9, pixelBar: 0.86, pixelShift: 0.6,
|
|
23
|
+
monoJoin: 0.96, inset: 0.96, knock: 0.95, link: 0.93, stack: 0.6, echo: 0.7, split: 0.86, frame: 0.85, lines: 0.8,
|
|
23
24
|
sSlice: 0.62, diagCut: 0.6, stemShort: 0.6, legFree: 0.6, stemCut: 0.58, swap: 0.55, slice: 0.55, stencil: 0.5, accent: 0.42,
|
|
24
25
|
};
|
|
25
26
|
/** Edits `suggest()` never picks on its own: loud, or decoration rather than an idea. They stay in `EDITS` for hand use. */
|
|
@@ -37,7 +38,20 @@ const HOUSE = {
|
|
|
37
38
|
pixelShift: [{ row: 0.45, rows: 1, by: 1 }],
|
|
38
39
|
pixelStep: [{ mode: 'alternate', by: 1 }, { mode: 'stairs', by: 1 }, { mode: 'arch', by: 1 }],
|
|
39
40
|
pixelBar: [{ ends: 'steps', weight: 1 }, { ends: 'dots', weight: 1 }],
|
|
41
|
+
monoJoin: [{ share: 'stroke', pair: 'first' }, { share: 'stroke', pair: 'last' }],
|
|
42
|
+
inset: [{ order: 'auto' }],
|
|
43
|
+
stack: [{ mode: 'rows', align: 'centre' }, { mode: 'rows', align: 'left' }, { mode: 'lead' }],
|
|
44
|
+
knock: [{ shape: 'square', pad: 1.2 }, { shape: 'round', pad: 1.2 }, { shape: 'disc', pad: 1.1 }],
|
|
45
|
+
frame: [{ shape: 'round', pad: 1.05 }, { shape: 'disc', pad: 1 }, { shape: 'square', pad: 1.05 }],
|
|
46
|
+
link: [{ front: 'alternate' }, { front: 'right' }],
|
|
47
|
+
split: [{ mode: 'level' }, { mode: 'upright' }, { mode: 'slant' }],
|
|
48
|
+
echo: [{ dir: 'drop', depth: 1.1 }, { dir: 'drop', depth: 0.8, gap: 0.28 }],
|
|
49
|
+
lines: [{ lines: 2, gap: 0.3 }, { lines: 3, gap: 0.26 }],
|
|
40
50
|
};
|
|
51
|
+
/** The short-name moves (./edits/short.js): a monogram resets the letters, so like a roof it is judged as a big move. */
|
|
52
|
+
/** Moves a page holds only a few of, however many pass: stacks render small, shadows are busy. */
|
|
53
|
+
const PAGE_CAP = { stack: 2, echo: 3 };
|
|
54
|
+
const SHORT_IDS = ['monoJoin', 'inset', 'stack', 'knock', 'frame', 'link', 'split', 'echo', 'lines'];
|
|
41
55
|
|
|
42
56
|
/**
|
|
43
57
|
* The tracking a setting wants, as a share of the cap height, from its case and its weight (stroke over cap height):
|
|
@@ -103,7 +117,7 @@ export async function suggest(name, { fonts, count = 48, seed = 1, lock = {} } =
|
|
|
103
117
|
if (lock.fonts?.length) list = list.filter((f) => lock.fonts.includes(f.id));
|
|
104
118
|
const ids = (lock.edits?.length ? lock.edits : Object.keys(EDITS).filter((id) => !EDITS[id].alias && !HAND_ONLY.includes(id))).filter((id) => EDITS[id]);
|
|
105
119
|
const found = [];
|
|
106
|
-
const started = Date.now(), long = [...name].length > 10;
|
|
120
|
+
const started = Date.now(), long = [...name].length > 10, short = [...name.trim()].length <= 3 && !/\s/.test(name.trim());
|
|
107
121
|
let fontsDone = 0;
|
|
108
122
|
for (const font of list) {
|
|
109
123
|
// a long name is slow to set: past the time budget, the fonts already tried make the page
|
|
@@ -126,11 +140,12 @@ export async function suggest(name, { fonts, count = 48, seed = 1, lock = {} } =
|
|
|
126
140
|
if ((id === 'tRoof' || id === 'lFloor') && (!carries(id, text) || font.tags?.includes('serif') || weight > 0.23)) continue; // a roof on serifs tangles, and in a very heavy face the tucked letters cramp
|
|
127
141
|
if (id === 'crossbarCut' && !isUpper) continue; // a cut through a lowercase e's bar closes it into an o
|
|
128
142
|
if (id === 'counter' && !/[oOqQ0]/.test(text)) continue; // a ring or slot belongs in a round letter: in an a or e it is a blob
|
|
143
|
+
if (id === 'counter' && short && !/[oOQ0]/.test(text)) continue; // a short name's lowercase q with its counter shut is a blob
|
|
129
144
|
for (const params of long ? tries(EDITS[id]).slice(0, 1) : tries(EDITS[id])) {
|
|
130
145
|
const tracking = lock.tracking ?? (pixel ? 0 : JOINED.includes(id) ? Math.min(0.02, opticalTracking(weight, isUpper)) : opticalTracking(weight, isUpper));
|
|
131
146
|
const m = typemark(text, { font, edits: [{ id, params }], slant: lock.slant ?? 0, tracking });
|
|
132
147
|
if (m.problems.length || !m.applied.length) continue;
|
|
133
|
-
const main = m.applied[0], rule = RULE[main.id], big = main.id === 'tRoof' || main.id === 'lFloor' || main.id.startsWith('pixel');
|
|
148
|
+
const main = m.applied[0], rule = RULE[main.id], big = main.id === 'tRoof' || main.id === 'lFloor' || main.id.startsWith('pixel') || SHORT_IDS.includes(main.id);
|
|
134
149
|
const score = 0.4 * visibleOf(m.change, big) + 0.5 * (WEIGHT[main.id] ?? 0.4) - (rule ? quiet(rule, main.params) : 0) + 0.06 * rand();
|
|
135
150
|
found.push({ ...m, score, key: `${font.id}|${main.id}|${isUpper ? 'U' : 'l'}`, pair: `${font.id}|${main.id}` });
|
|
136
151
|
}
|
|
@@ -143,7 +158,7 @@ export async function suggest(name, { fonts, count = 48, seed = 1, lock = {} } =
|
|
|
143
158
|
for (const m of found) {
|
|
144
159
|
if (picked.length >= count) break;
|
|
145
160
|
const f = m.record.fontId, e = m.applied[0].id;
|
|
146
|
-
if ((nFont.get(f) || 0) >= perFont || (nEdit.get(e) || 0) >= perEdit || (nKey.get(m.key) || 0) >= 1) continue;
|
|
161
|
+
if ((nFont.get(f) || 0) >= perFont || (nEdit.get(e) || 0) >= Math.min(perEdit, PAGE_CAP[e] ?? Infinity) || (nKey.get(m.key) || 0) >= 1) continue;
|
|
147
162
|
nFont.set(f, (nFont.get(f) || 0) + 1); nEdit.set(e, (nEdit.get(e) || 0) + 1); nKey.set(m.key, (nKey.get(m.key) || 0) + 1);
|
|
148
163
|
picked.push(m);
|
|
149
164
|
}
|
|
@@ -151,7 +166,10 @@ export async function suggest(name, { fonts, count = 48, seed = 1, lock = {} } =
|
|
|
151
166
|
for (const m of found) {
|
|
152
167
|
if (picked.length >= count) break;
|
|
153
168
|
if (picked.includes(m) || (nFont.get(m.record.fontId) || 0) >= perFont + 2 || (nKey.get(m.key) || 0) >= 2) continue;
|
|
169
|
+
// a short name has few moves: none may fill the page (a long name's pass is as it was)
|
|
170
|
+
if (short && (nEdit.get(m.applied[0].id) || 0) >= Math.min(perEdit + 2, PAGE_CAP[m.applied[0].id] ?? Infinity)) continue;
|
|
154
171
|
nFont.set(m.record.fontId, (nFont.get(m.record.fontId) || 0) + 1); nKey.set(m.key, (nKey.get(m.key) || 0) + 1);
|
|
172
|
+
nEdit.set(m.applied[0].id, (nEdit.get(m.applied[0].id) || 0) + 1);
|
|
155
173
|
picked.push(m);
|
|
156
174
|
}
|
|
157
175
|
// order the page: best first, but never the same edit twice running, nor the same font, where another is to be had
|