Skip to content

Commit

Permalink
add a bunch of Vietnamese alphabet grapheme + some control
Browse files Browse the repository at this point in the history
  • Loading branch information
nclslbrn committed Apr 30, 2024
1 parent dd5d829 commit 8250d37
Show file tree
Hide file tree
Showing 4 changed files with 204 additions and 18 deletions.
12 changes: 10 additions & 2 deletions demo/src/index.ts
Original file line number Diff line number Diff line change
@@ -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"),
Expand All @@ -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);
Expand Down Expand Up @@ -82,7 +91,6 @@ const init = () => {
app.appendChild(form);
app.appendChild(svg);
};

window.addEventListener("resize", update);

init();
Expand Down
7 changes: 7 additions & 0 deletions src/glyphs/diacritics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
90 changes: 78 additions & 12 deletions src/glyphs/lowercase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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],
],
],
Expand Down Expand Up @@ -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"]],
Expand All @@ -266,43 +283,92 @@ 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
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;
});

Expand Down
113 changes: 109 additions & 4 deletions src/glyphs/poncuation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand All @@ -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],
Expand Down Expand Up @@ -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],
]
],
],
"-": [
[
Expand Down Expand Up @@ -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],
Expand Down Expand Up @@ -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;

0 comments on commit 8250d37

Please sign in to comment.