diff --git a/app/services/font-manager.ts b/app/services/font-manager.ts index 815ba0a..a4f3eea 100644 --- a/app/services/font-manager.ts +++ b/app/services/font-manager.ts @@ -1,6 +1,7 @@ import Service from '@ember/service'; import config from 'text2stl/config/environment'; import { inject as service } from '@ember/service'; +import * as opentype from 'opentype.js'; import type HarfbuzzService from 'text2stl/services/harfbuzz'; import type { HBFont, HBFace } from 'harfbuzzjs/hbjs'; @@ -88,6 +89,7 @@ type GoogleFontApiResponse = { export interface FaceAndFont { font: HBFont; face: HBFace; + opentype: opentype.Font; // This is only used to determine outline type (TrueType / CFF). TODO: find how to do that with harfbuzz. } export default class FontManagerService extends Service { @@ -133,6 +135,8 @@ export default class FontManagerService extends Service { fontCache: Record = {}; + opentype = opentype; // For easy mock + _emojiFont?: FaceAndFont; get emojiFont() { @@ -241,6 +245,7 @@ export default class FontManagerService extends Service { return { font: this.harfbuzz.hb.createFont(face), face, + opentype: this.opentype.parse(buffer), }; } diff --git a/app/services/text-maker.ts b/app/services/text-maker.ts index 1bb7363..23ff9e9 100644 --- a/app/services/text-maker.ts +++ b/app/services/text-maker.ts @@ -101,7 +101,7 @@ export default class TextMakerService extends Service { // Following is only to manage "cff" font & detect hole shape const paths2D: Path2D[] = []; let path2D = new Path2D(); - + console.log(glyphPath); // https://github.com/opentypejs/opentype.js#path-commands for (let i = 0; i < glyphPath.length; i++) { const command = glyphPath[i]; @@ -412,6 +412,7 @@ export default class TextMakerService extends Service { lineText.glyphs[info.g], x, // x offset y - oy, // y offset + font.opentype.outlinesFormat === 'cff', ), ); ox += spacing + info.ax; diff --git a/package.json b/package.json index 43ae578..688204a 100644 --- a/package.json +++ b/package.json @@ -139,6 +139,7 @@ "@esri/calcite-components": "^1.9.1", "harfbuzzjs": "^0.3.4", "matter-js": "^0.17.1", + "opentype.js": "^1.3.3", "poly-decomp": "^0.3.0", "three": "^0.137.4" }, diff --git a/tests/helpers/mock-font-manager.ts b/tests/helpers/mock-font-manager.ts index b748137..f08eb9b 100644 --- a/tests/helpers/mock-font-manager.ts +++ b/tests/helpers/mock-font-manager.ts @@ -1,5 +1,6 @@ import Service, { inject as service } from '@ember/service'; import loadFont from 'text2stl/tests/helpers/load-font'; +import type { Font } from 'opentype.js'; import type { FaceAndFont } from 'text2stl/services/font-manager'; @@ -25,6 +26,7 @@ class FakeFontManager extends Service { return { font: this.harfbuzz.hb.createFont(face), face, + opentype: { outlinesFormat: 'trueType' } as Font, }; } @@ -38,6 +40,7 @@ class FakeFontManager extends Service { this.emojiFont = { font: this.harfbuzz.hb.createFont(face), face, + opentype: { outlinesFormat: 'trueType' } as Font, }; } } diff --git a/yarn.lock b/yarn.lock index 34204ec..6503a0b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -8943,6 +8943,14 @@ onetime@^5.1.0, onetime@^5.1.2: dependencies: mimic-fn "^2.1.0" +opentype.js@^1.3.3: + version "1.3.4" + resolved "https://registry.npmjs.org/opentype.js/-/opentype.js-1.3.4.tgz#1c0e72e46288473cc4a4c6a2dc60fd7fe6020d77" + integrity sha512-d2JE9RP/6uagpQAVtJoF0pJJA/fgai89Cc50Yp0EJHk+eLp6QQ7gBoblsnubRULNY132I0J1QKMJ+JTbMqz4sw== + dependencies: + string.prototype.codepointat "^0.2.1" + tiny-inflate "^1.0.3" + opter@^1.1.0: version "1.1.0" resolved "https://registry.npmjs.org/opter/-/opter-1.1.0.tgz#2598aebb60b3f1a7322af1097086f4e798c84a76" @@ -10524,6 +10532,11 @@ string-width@^2.1.0: is-fullwidth-code-point "^2.0.0" strip-ansi "^4.0.0" +string.prototype.codepointat@^0.2.1: + version "0.2.1" + resolved "https://registry.npmjs.org/string.prototype.codepointat/-/string.prototype.codepointat-0.2.1.tgz#004ad44c8afc727527b108cd462b4d971cd469bc" + integrity sha512-2cBVCj6I4IOvEnjgO/hWqXjqBGsY+zwPmHl12Srk9IXSZ56Jwwmy+66XO5Iut/oQVR7t5ihYdLB0GMa4alEUcg== + string.prototype.matchall@^4.0.5, string.prototype.matchall@^4.0.6: version "4.0.11" resolved "https://registry.npmjs.org/string.prototype.matchall/-/string.prototype.matchall-4.0.11.tgz#1092a72c59268d2abaad76582dccc687c0297e0a" @@ -10927,6 +10940,11 @@ tiny-glob@0.2.9: globalyzer "0.1.0" globrex "^0.1.2" +tiny-inflate@^1.0.3: + version "1.0.3" + resolved "https://registry.npmjs.org/tiny-inflate/-/tiny-inflate-1.0.3.tgz#122715494913a1805166aaf7c93467933eea26c4" + integrity sha512-pkY1fj1cKHb2seWDy0B16HeWyczlJA9/WW3u3c4z/NiWDsO3DOU5D7nhTLE9CF0yXv/QZFY7sEJmj24dK+Rrqw== + tiny-lr@^2.0.0: version "2.0.0" resolved "https://registry.npmjs.org/tiny-lr/-/tiny-lr-2.0.0.tgz#863659d7ce1ed201a117d8197d7f8b9a27bdc085"