Skip to content

Commit

Permalink
Merge pull request #785 from googlefonts/issue775
Browse files Browse the repository at this point in the history
Render a dotted placeholder square when a component references an empty glyph
  • Loading branch information
justvanrossum authored Sep 6, 2023
2 parents b69ab8d + 3a13684 commit c9b42c2
Showing 1 changed file with 28 additions and 1 deletion.
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

0 comments on commit c9b42c2

Please sign in to comment.