From 8250d37e9fe4741871fe33eb578d2832ac31eb0f Mon Sep 17 00:00:00 2001 From: nclslbrn Date: Tue, 30 Apr 2024 19:33:09 +0200 Subject: [PATCH] add a bunch of Vietnamese alphabet grapheme + some control --- demo/src/index.ts | 12 ++++- src/glyphs/diacritics.ts | 7 +++ src/glyphs/lowercase.ts | 90 ++++++++++++++++++++++++++----- src/glyphs/poncuation.ts | 113 +++++++++++++++++++++++++++++++++++++-- 4 files changed, 204 insertions(+), 18 deletions(-) diff --git a/demo/src/index.ts b/demo/src/index.ts index f319040..b4a1c32 100644 --- a/demo/src/index.ts +++ b/demo/src/index.ts @@ -1,4 +1,13 @@ import { font, getGlyphPath } from "../../src/index.ts"; +import { Glyph, Line, Vec } from "../../src/type"; + +console.log( + JSON.stringify( + font["3"].map( + (l: Line) => l.map((v: Vec) => [0.33 + v[0] * 0.33, 0.166 + v[1] * 0.33] as Vec) as Line, + ) as Glyph, + ), +); const app = document.getElementById("app"), form = document.createElement("form"), @@ -24,7 +33,7 @@ const update = () => { (width - charPerLine * textSize[0]) / 2, (height - 40 - nbLines * textSize[1]) / 2, ]; - group.textContent = ""; + group.textContent = ""; for (let y = 0; y < nbLines; y++) { const remainingChar = Math.min(charPerLine, text.length - y * charPerLine); @@ -82,7 +91,6 @@ const init = () => { app.appendChild(form); app.appendChild(svg); }; - window.addEventListener("resize", update); init(); diff --git a/src/glyphs/diacritics.ts b/src/glyphs/diacritics.ts index 46bc930..47eac94 100644 --- a/src/glyphs/diacritics.ts +++ b/src/glyphs/diacritics.ts @@ -153,6 +153,13 @@ const diacritics = { [0.3, 0.8], [0.7, 0.8] ] + ], + // horn + hr: [ + [ + [0.75, 0.35], + [0.8, 0.25] + ] ] } as Font; diff --git a/src/glyphs/lowercase.ts b/src/glyphs/lowercase.ts index f077f73..ed76db7 100644 --- a/src/glyphs/lowercase.ts +++ b/src/glyphs/lowercase.ts @@ -202,6 +202,9 @@ const lowercase = { [0.2, 0.3], [0.2, 0.7], [0.8, 0.7], + ], + [ + [0.8, 0.75], [0.8, 0.3], ], ], @@ -258,6 +261,20 @@ const lowercase = { // Associate diacritics with existing glyph const accentTable = { + // a + ḁ: ["a", ["db"]], + ả: ["a", ["ha"]], + ấ: ["a", ["cr", "ct"]], + ầ: ["a", ["cr", "gr"]], + ẩ: ["a", ["cr", "ha"]], + ẫ: ["a", ["cr", "tl"]], + ậ: ["a", ["cr", "db"]], + ắ: ["a", ["br", "ct"]], + ằ: ["a", ["br", "gr"]], + ẳ: ["a", ["br", "ct"]], + ẵ: ["a", ["br", "tl"]], + ặ: ["a", ["br", "db"]], + à: ["a", ["gr"]], á: ["a", ["ct"]], â: ["a", ["cr"]], @@ -266,35 +283,81 @@ const accentTable = { ă: ["a", ["br"]], ǎ: ["a", ["hc"]], ā: ["a", ["mc"]], - ḁ: ["a", ["db"]], - ả: ["a", ["ha"]], - ẩ: ["a", ["cr", "ha"]], - ẫ: ["a", ["cr", "tl"]], - ậ: ["a", ["cr", "da"]], - ắ: ["a", ["br", "ct"]], + + // b ḃ: ["b", ["da"]], ḅ: ["b", ["db"]], ḇ: ["b", ["lb"]], + + // c ć: ["c", ["ct"]], ĉ: ["c", ["cr"]], ç: ["c", ["cd"]], + + // d + ḋ: ["d", ["da"]], + ḍ: ["d", ["db"]], + ḏ: ["d", ["lb"]], + ḑ: ["d", ["cd"]], + ḓ: ["d", ["crb"]], + + // e ẹ: ["e", ["db"]], ẻ: ["e", ["ha"]], ẽ: ["e", ["tl"]], + ế: ["e", ["cr", "ct"]], + ề: ["e", ["cr", "gr"]], + ể: ["e", ["cr", "ha"]], + ễ: ["e", ["cr", "tl"]], + ệ: ["e", ["cr", "db"]], + ḙ: ["e", ["crb"]], ḛ: ["e", ["tlb"]], + + // f ḟ: ["f", ["da"]], + + // g ḡ: ["g", ["mc"]], + + // h ḣ: ["h", ["da"]], ḥ: ["h", ["db"]], ḧ: ["h", ["dr"]], ḩ: ["h", ["cdl"]], - ḋ: ["d", ["da"]], - ḍ: ["d", ["db"]], - ḏ: ["d", ["lb"]], - ḑ: ["d", ["cd"]], - ḓ: ["d", ["crb"]] + // i + Ỉ: ["i", ["ha"]], + Ị: ["i", ["db"]], + + // o + ọ: ["o", ["db"]], + ỏ: ["o", ["ha"]], + ố: ["o", ["cr", "ct"]], + ồ: ["o", ["cr", "gr"]], + ổ: ["o", ["cr", "ha"]], + ỗ: ["o", ["cr", "tl"]], + ộ: ["o", ["cr", "db"]], + ớ: ["o", ["hr", "ct"]], + ờ: ["o", ["hr", "gr"]], + ở: ["o", ["hr", "ha"]], + ỡ: ["o", ["hr", "tl"]], + ợ: ["o", ["hr", "db"]], + + // u + ụ: ["u", ["db"]], + ủ: ["u", ["ha"]], + ứ: ["u", ["hr", "ct"]], + ừ: ["u", ["hr", "gr"]], + ử: ["u", ["hr", "ha"]], + ữ: ["u", ["hr", "tl"]], + ự: ["u", ["hr", "db"]], + + // y + ỳ: ["y", ["gr"]], + ỵ: ["y", ["db"]], + ỷ: ["y", ["ha"]], + ỹ: ["y", ["tl"]], } as ExtendedTable; // Clone exisiting glyph and add diacritical marks @@ -302,7 +365,10 @@ const accented = {} as Font; Object.keys(accentTable).map((char) => { accented[char as keyof typeof accented] = [ ...lowercase[accentTable[char][0] as keyof Font], - ...accentTable[char][1].reduce((acc: Glyph, a: keyof Font) => [...acc, ...diacritics[a]], []), + ...accentTable[char][1].reduce( + (acc: Glyph, a: keyof Font) => [...acc, ...diacritics[a]], + [], + ), ] as Glyph; }); diff --git a/src/glyphs/poncuation.ts b/src/glyphs/poncuation.ts index f1ecc88..ae007e9 100644 --- a/src/glyphs/poncuation.ts +++ b/src/glyphs/poncuation.ts @@ -43,9 +43,18 @@ const ponctuation = { [0.5, 0.7], ], ], + "¡": [ + [ + [0.5, 0.2], + [0.5, 0.25], + ], + [ + [0.5, 0.375], + [0.5, 0.7], + ], + ], "?": [ [ - //[0.35, 0.225], [0.35, 0.2], [0.5, 0.165], [0.65, 0.2], @@ -58,6 +67,20 @@ const ponctuation = { [0.5, 0.7], ], ], + "¿": [ + [ + [0.65, 0.7], + [0.5, 0.735], + [0.35, 0.7], + [0.35, 0.5], + [0.5, 0.4], + [0.5, 0.3], + ], + [ + [0.5, 0.25], + [0.5, 0.2], + ], + ], "*": [ [ [0.5, 0.4], @@ -140,14 +163,29 @@ const ponctuation = { [0.65, 0.45], ], ], + "±": [ + [ + [0.5, 0.375], + [0.5, 0.525], + ], + [ + [0.375, 0.45], + [0.625, 0.45], + ], + [ + [0.375, 0.6], + [0.625, 0.6], + ], + ], "=": [ [ [0.3, 0.35], [0.7, 0.35], - ], [ + ], + [ [0.3, 0.55], [0.7, 0.55], - ] + ], ], "-": [ [ @@ -215,6 +253,19 @@ const ponctuation = { [0.4, 0.7], ], ], + "^": [ + [ + [0.3, 0.4], + [0.5, 0.2], + [0.7, 0.4], + ], + ], + "`": [ + [ + [0.45, 0.2], + [0.55, 0.3], + ], + ], "(": [ [ [0.5, 0.2], @@ -293,6 +344,60 @@ const ponctuation = { [0.5, 0.3], ], ], + "²": [ + [ + [0.4125, 0.232], + [0.5775, 0.232], + [0.5775, 0.3], + [0.4125, 0.3], + [0.4125, 0.4], + [0.5775, 0.4], + ], + ], + "³": [ + [ + [0.4125, 0.232], + [0.5775, 0.232], + [0.5775, 0.4], + [0.4125, 0.4], + ], + [ + [0.495, 0.3], + [0.5775, 0.3], + ], + ], + "´": [ + [ + [0.45, 0.3], + [0.55, 0.2], + ], + ], + µ: [ + [ + [0.2, 0.3], + [0.2, 0.9], + ], + [ + [0.2, 0.7], + [0.8, 0.7], + ], + [ + [0.8, 0.75], + [0.8, 0.3], + ], + ], + "¶": [ + [ + [0.65, 0.9], + [0.65, 0.3], + [0.25, 0.3], + [0.25, 0.7], + [0.65, 0.7], + ], + [ + [0.75, 0.9], + [0.75, 0.3], + ], + ], }; - export default ponctuation;