From ef495d874b84d881f51d0fcb6b1b4456310bdac3 Mon Sep 17 00:00:00 2001 From: bernhard Date: Thu, 28 Jul 2022 23:20:24 +0200 Subject: [PATCH] fix typings --- src/glyph.ts | 16 +++++++--------- src/value2glyphs.ts | 8 ++++---- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/src/glyph.ts b/src/glyph.ts index 991bb1d..0cdaf9d 100644 --- a/src/glyph.ts +++ b/src/glyph.ts @@ -1,6 +1,5 @@ -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, @@ -8,7 +7,7 @@ type GlyphObfuscationResult = { } export function obfuscateGlyphs( - originalGlyphs: Glyph[], + originalGlyphs: (Glyph & { path: Path })[], characterRange: EncryptionCharacterRange, strength: number ): GlyphObfuscationResult { @@ -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; } @@ -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, }); }); diff --git a/src/value2glyphs.ts b/src/value2glyphs.ts index a6c0301..89884c5 100644 --- a/src/value2glyphs.ts +++ b/src/value2glyphs.ts @@ -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") { @@ -20,16 +20,16 @@ const values = (object) => { ); }; -export default function value2glyphs(value: T, font: Font): Glyph[] { +export default function value2glyphs(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 })[]; }