Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Render a dotted placeholder square when a component references an empty glyph #785

Merged
merged 2 commits into from
Sep 6, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion src/fontra/client/core/glyph-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
registerRepresentationFactory,
} from "./representation-cache.js";
import { Transform } from "./transform.js";
import { enumerate, makeAffineTransform } from "./utils.js";
import { enumerate, makeAffineTransform, range } from "./utils.js";
import { StaticGlyph } from "./var-glyph.js";
import {
VariationModel,
Expand Down Expand Up @@ -589,6 +589,9 @@ async function* iterFlattenedComponentPaths(
console.log(errorMessage);
return;
}
if (!inst.path.numPoints && !inst.components.length) {
inst = makeEmptyComponentPlaceholderGlyph();
}
}
let t = makeAffineTransform(compo.transformation);
if (transformation) {
Expand Down Expand Up @@ -823,6 +826,30 @@ function makeMissingComponentPlaceholderGlyph() {
return StaticGlyph.fromObject({ path: path });
}

function makeEmptyComponentPlaceholderGlyph() {
const path = new VarPackedPath();
const numSq = 12;
const side = 14;
const dist = side * 2;

function sq(x, y) {
path.moveTo(x, y);
path.lineTo(x, y + side);
path.lineTo(x + side, y + side);
path.lineTo(x + side, y);
path.closePath();
}

for (const i of range(numSq)) {
sq(dist * i, 0);
sq(0, dist + dist * i);
sq(dist + dist * i, 12 * dist);
sq(12 * dist, dist * i);
}

return StaticGlyph.fromObject({ path: path });
}

function makeDefaultLocation(axes) {
return Object.fromEntries(axes.map((axis) => [axis.name, axis.defaultValue]));
}
Expand Down
Loading