Skip to content
This repository has been archived by the owner on Jun 6, 2024. It is now read-only.

Commit

Permalink
Merge pull request #21 from schoenbergerb/fix-typings
Browse files Browse the repository at this point in the history
fix typings
  • Loading branch information
schoenbergerb authored Jul 28, 2022
2 parents f11576c + ef495d8 commit c8b9d14
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
16 changes: 7 additions & 9 deletions src/glyph.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import { Glyph } from "opentype.js";
import { Glyph, Path } from "opentype.js";
import { EncryptionCharacterRange } from "./encryption-character-range.enum";
import { ObfuscationOptions } from "./obfuscation-options";

type GlyphObfuscationResult = {
translation: Map<number, number>,
glyphs: Glyph[],
}

export function obfuscateGlyphs(
originalGlyphs: Glyph[],
originalGlyphs: (Glyph & { path: Path })[],
characterRange: EncryptionCharacterRange,
strength: number
): GlyphObfuscationResult {
Expand All @@ -19,7 +18,7 @@ export function obfuscateGlyphs(

translation.set(glyph.unicode, unicode);

const commands = glyph.path.commands.map((cmd) => {
const commands = glyph.path.commands.map((cmd: any) => {
if (!cmd.x || !cmd.y) {
return cmd;
}
Expand All @@ -31,16 +30,15 @@ export function obfuscateGlyphs(
};
});

const { path } = glyph
path.commands = commands;

return new Glyph({
index,
name: Number(unicode).toString(16),
unicode,
path: {
...glyph.path,
commands,
},
path,
advanceWidth: glyph.advanceWidth,
leftSideBearing: glyph.leftSideBearing,
});
});

Expand Down
8 changes: 4 additions & 4 deletions src/value2glyphs.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import _ from "lodash";
import { Font, Glyph } from "opentype.js";
import { Font, Glyph, Path } from "opentype.js";

const values = (object) => {
if (typeof object === "number") {
Expand All @@ -20,16 +20,16 @@ const values = (object) => {
);
};

export default function value2glyphs<T>(value: T, font: Font): Glyph[] {
export default function value2glyphs<T>(value: T, font: Font): (Glyph & { path: Path })[] {
const chars = values(value).join("").split("");

const uniqChars = _.union(chars);

const glyphs = font.stringToGlyphs(_.shuffle(uniqChars).join(""));

const notDefGlyph = font.glyphs.glyphs[0];
const notDefGlyph = font.glyphs.get(0);

glyphs.unshift(notDefGlyph);

return glyphs;
return glyphs as (Glyph & { path: Path })[];
}

0 comments on commit c8b9d14

Please sign in to comment.