Skip to content

Commit

Permalink
ABCD
Browse files Browse the repository at this point in the history
  • Loading branch information
nclslbrn committed May 10, 2024
1 parent 723441e commit be6123d
Show file tree
Hide file tree
Showing 9 changed files with 424 additions and 151 deletions.
40 changes: 7 additions & 33 deletions demo/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,34 +1,8 @@
import { font, getGlyphPath } from "../../src/index.ts";
import { Glyph, Line, Vec } from "../../src/type";
const lowercase = [
..."aáàăắằẵẳâấầẫẩǎåǻäǟãȧǡąāảȁȃạặậḁæǽǣẚɐɑɒ",
..."bḃḅḇʙƀɓƃ",
..."cćĉčċçḉȼƈɕ",
..."dďḋḑđḍḓḏðȸdzʣdžʥʤɖɗƌȡẟ",
..."eéèĕêếềễểěëẽėȩḝęēḗḕẻȅȇẹệḙḛɇǝəɛɘɚɜɝɞʚɤ",
..."fḟʩƒ",
..."gǵğĝǧġģḡɡɢǥɠʛɣ",
..."ƣhĥȟḧḣḩħḥḫẖʜƕɦɧ",
..."iíìĭîǐïḯĩįīỉȉȋịḭijıɪɨɩ",
..."jĵǰȷɉʝɟʄ",
..."kḱǩķḳḵƙʞ",
..."lĺľļłḷḹḽḻŀljỻʪʫʟƚɫɬɭȴɮƛʎ",
..."mḿṁṃɱ",
..."nńǹňñṅņṇṋṉnjɴɲƞɳȵŋ",
..."oóòŏôốồỗổǒöȫőõṍṏȭȯȱøǿǫǭōṓṑỏȍȏơớờỡởợọộœɶɔɵɷȣ",
..."pṕṗƥɸqȹʠ",
..."ɋĸ",
..."rŕřṙŗȑȓṛṝṟʀɍɹɺɻɼɽɾɿʁ",
..."sśṥŝšṧṡşṣṩșſẛßʂȿẜẝʃƪʅʆ",
..."tťẗṫţṭțṱṯʨƾʦʧŧƫƭʈȶʇ",
..."uúùŭûǔůüǘǜǚǖűũṹųūṻủȕȗưứừữửựụṳṷṵʉɥʮʯɯɰʊ",
..."vṽṿʋỽʌ",
..."wẃẁŵẘẅẇẉʍ",
..."xẍẋ",
..."yýỳŷẙÿỹẏȳỷỵʏɏƴỿȝ",
..."zźẑžżẓẕƍƶȥʐʑɀʒǯƹƺʓþƿƨƽƅɂʕʡʢʖʗʘʬʭ",
],
DEBUG = false;
import letters from "./letters"

const DEBUG = false;

const rotateGlyph = (g: Glyph) =>
g.map((l: Line) => l.map((p: Vec) => [1 - p[0], 1 - p[1]]));
Expand All @@ -47,12 +21,12 @@ const mirrorYGlyph = (g: Glyph) =>
// font["ɜ"] = mirrorYGlyph(font["ɛ"])
// alert(`ʖ: ${JSON.stringify(rotateGlyph(font["ʕ"]))},`);

for (let l = 0; l < lowercase.length; l++) {
if (font[lowercase[l]] === undefined) {
console.log(`%c ${lowercase[l]}`, "font-size: 3em");
for (let l = 0; l < letters.length; l++) {
if (font[letters[l]] === undefined) {
console.log(`%c ${letters[l]}`, "font-size: 3em");
break;
} else {
console.log(`%c ✅${lowercase[l]}`, "font-size: 2.5em");
console.log(`%c ✅${letters[l]}`, "font-size: 2.5em");
}
}

Expand Down
56 changes: 56 additions & 0 deletions demo/src/letters.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
export default [
// lowercase
..."aáàăắằẵẳâấầẫẩǎåǻäǟãȧǡąāảȁȃạặậḁæǽǣẚɐɑɒ",
..."bḃḅḇʙƀɓƃ",
..."cćĉčċçḉȼƈɕ",
..."dďḋḑđḍḓḏðȸdzʣdžʥʤɖɗƌȡẟ",
..."eéèĕêếềễểěëẽėȩḝęēḗḕẻȅȇẹệḙḛɇǝəɛɘɚɜɝɞʚɤ",
..."fḟʩƒ",
..."gǵğĝǧġģḡɡɢǥɠʛɣ",
..."ƣhĥȟḧḣḩħḥḫẖʜƕɦɧ",
..."iíìĭîǐïḯĩįīỉȉȋịḭijıɪɨɩ",
..."jĵǰȷɉʝɟʄ",
..."kḱǩķḳḵƙʞ",
..."lĺľļłḷḹḽḻŀljỻʪʫʟƚɫɬɭȴɮƛʎ",
..."mḿṁṃɱ",
..."nńǹňñṅņṇṋṉnjɴɲƞɳȵŋ",
..."oóòŏôốồỗổǒöȫőõṍṏȭȯȱøǿǫǭōṓṑỏȍȏơớờỡởợọộœɶɔɵɷȣ",
..."pṕṗƥɸqȹʠ",
..."ɋĸ",
..."rŕřṙŗȑȓṛṝṟʀɍɹɺɻɼɽɾɿʁ",
..."sśṥŝšṧṡşṣṩșſẛßʂȿẜẝʃƪʅʆ",
..."tťẗṫţṭțṱṯʨƾʦʧŧƫƭʈȶʇ",
..."uúùŭûǔůüǘǜǚǖűũṹųūṻủȕȗưứừữửựụṳṷṵʉɥʮʯɯɰʊ",
..."vṽṿʋỽʌ",
..."wẃẁŵẘẅẇẉʍ",
..."xẍẋ",
..."yýỳŷẙÿỹẏȳỷỵʏɏƴỿȝ",
..."zźẑžżẓẕƍƶȥʐʑɀʒǯƹƺʓþƿƨƽƅɂʕʡʢʖʗʘʬʭ",
// uppercase
..."AÁÀĂẮẰẴẲÂẤẦẪẨǍÅǺÄǞÃȦǠĄĀẢȀȂẠẶẬḀÆǼǢȺ",
..."BḂḄḆɃƁƂ",
..."CĆĈČĊÇḈȻƇ",
..."DĎḊḐĐḌḒḎÐDZƉƊƋ",
..."EÉÈĔÊẾỀỄỂĚËẼĖȨḜĘĒḖḔẺȄȆẸỆḘḚɆƎƏƐ",
..."FḞƑ",
..."GǴĞĜǦĠĢḠǤƓƔƢ",
..."HĤȞḦḢḨĦḤḪǶ",
..."IÍÌĬÎǏÏḮĨİĮĪỈȈȊỊḬIJƗƖ",
..."JĴɈ",
..."KḰǨĶḲḴƘ",
..."LĹĽĻŁḶḸḼḺĿLJỺȽ",
..."MḾṀṂ",
..."NŃǸŇÑṄŅṆṊṈNJƝȠŊ",
..."OÓÒŎÔỐỒỖỔǑÖȪŐÕṌṎȬȮȰØǾǪǬŌṒṐỎȌȎƠỚỜỠỞỢỌỘŒƆƟȢ",
..."PṔṖƤ",
..."QɊ",
..."RŔŘṘŖȐȒṚṜṞƦɌ",
..."SŚṤŜŠṦṠŞṢṨȘẞƩ",
..."TŤṪŢṬȚṰṮŦȾƬƮ",
..."UÚÙŬÛǓŮÜǗǛǙǕŰŨṸŲŪṺỦȔȖƯỨỪỮỬỰỤṲṶṴɄƜƱ",
..."VṼṾƲỼɅ",
..."WẂẀŴẄẆẈ",
..."XẌẊ",
..."YÝỲŶŸỸẎȲỶỴɎƳỾ",
..."ȜZŹẐŽŻẒẔƵȤⱿƷǮƸÞǷƧƼƄɁ",
];
13 changes: 12 additions & 1 deletion src/glyphs/diacritics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,17 @@ const diacritics = {
[0.45, 0.15],
],
],
// angstorm or circle or ring (bottom)
gsb: [
[
[0.45, 0.9],
[0.45, 0.85],
[0.55, 0.85],
[0.55, 0.9],
[0.45, 0.9],
],
],

// cedilla
cd: [
[
Expand Down Expand Up @@ -235,7 +246,7 @@ const diacritics = {
// barred (kind of /)
brd: [
[
[0.55, 0.2],
[0.65, 0.1],
[0.35, 0.8],
],
],
Expand Down
119 changes: 6 additions & 113 deletions src/glyphs/lowercase/index.ts
Original file line number Diff line number Diff line change
@@ -1,127 +1,20 @@
import { Font, Glyph, DiaGroup, Line, Vec } from "../../type";
import diacritics from "../diacritics";
import { Font, Glyph, DiaGroup } from "../../type";
import { base } from "./base";
import { diaBaseAssociation } from "./diaBaseAssociation";

// A list of top keys diactricts
// Use to detect and move diacritics
const topDia = [
"gr",
"ct",
"cr",
"dr",
"tl",
"br",
"bri",
"hcr",
"mc",
"gs",
"da",
"ha",
"hc"
] as Array<keyof Font>;

const topDiaCount = (diaKey: keyof Font): number =>
topDia.includes(diaKey) ? 1 : 0;

const moveDia = {
tp: (g: Glyph) => g.map((l: Line) => l.map((p: Vec) => [p[0], p[1] - 0.125])),
bt: (g: Glyph) => g.map((l: Line) => l.map((p: Vec) => [p[0], p[1] + 0.1])),
lf: (g: Glyph) => g.map((l: Line) => l.map((p: Vec) => [p[0] - 0.125, p[1]])),
rg: (g: Glyph) => g.map((l: Line) => l.map((p: Vec) => [p[0] + 0.125, p[1]])),
};

const joinVector = (diaStack: Glyph[], movedDia: Glyph): Glyph =>
diaStack.reduce(
(out: Glyph, curr: Glyph) => [...out, ...curr],
[...movedDia],
);

const mergeDia = (diaKeys: DiaGroup): Glyph => {
// check if theres is two diacritics and
// both are situated on top of letter
const multipleTopDia = diaKeys.reduce(
(acc: number, dia: keyof Font) => (acc += topDiaCount(dia)),
0,
);
if (diaKeys.length > 1 && multipleTopDia > 1) {
// check double grave
if (
diaKeys.reduce((ct: number, k: keyof Font)=> ct += k === 'gr' ? 1 : 0, 0) > 1) {
return joinVector(
diaKeys.filter((k) => k != "gr").map((k) => diacritics[k]),
[...moveDia.lf(diacritics['gr']), ...moveDia.rg(diacritics['gr'])]
)
}
// check double acute
if (
diaKeys.reduce((ct: number, k: keyof Font)=> ct += k === 'ct' ? 1 : 0, 0) > 1) {
return joinVector(
diaKeys.filter((k) => k != "ct").map((k) => diacritics[k]),
[...moveDia.lf(diacritics['ct']), ...moveDia.rg(diacritics['ct'])]
)
}
// move tild down
if (diaKeys.includes("tl")) {
return joinVector(
diaKeys.filter((k) => k != "tl").map((k) => diacritics[k]),
moveDia.bt(diacritics["tl"]),
);
}
// move hacek down
else if (diaKeys.includes("hc")) {
return joinVector(
diaKeys.filter((k) => k != "hc").map((k) => diacritics[k]),
moveDia.bt(diacritics["hc"]),
);
}  
// move macron down
else if (diaKeys.includes("mc")) {
return joinVector(
diaKeys.filter((k) => k != "mc").map((k) => diacritics[k]),
moveDia.bt(diacritics["mc"]),
);
}
// move acute accent left
else if (diaKeys.includes("ct")) {
return joinVector(
diaKeys.filter((k) => k != "ct").map((k) => diacritics[k]),
moveDia.bt(diacritics["ct"]),
);
}
// move grave accent right
else if (diaKeys.includes("gr")) {
return joinVector(
diaKeys.filter((k) => k != "gr").map((k) => diacritics[k]),
moveDia.bt(diacritics["gr"]),
);
}
else {
return diaKeys.reduce(
(acc: Glyph, k: keyof Font) => [...acc, ...diacritics[k]],
[] as Glyph,
);
}
} else {
return diaKeys.reduce(
(acc: Glyph, k: keyof Font) => [...acc, ...diacritics[k]],
[] as Glyph,
);
}
};
import { mergeDia } from "../mergeDia";

// Clone exisiting glyph and add diacritical marks
const accented = {} as Font;
const diacriticized = {} as Font;
Object.keys(diaBaseAssociation).map((char) => {
accented[char as keyof typeof accented] = [
diacriticized[char as keyof typeof diacriticized] = [
...base[diaBaseAssociation[char][0] as keyof Font],
...mergeDia(diaBaseAssociation[char][1] as DiaGroup),
] as Glyph;
});

// Merge all glyphs and add some ligature
// Merge all glyphs (with and without diacritical marks)
const lowercase = {
...base,
...accented,
...diacriticized,
};
export default lowercase;
112 changes: 112 additions & 0 deletions src/glyphs/mergeDia.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
import { Font, Glyph, DiaGroup, Line, Vec } from "../type";
import diacritics from "./diacritics";


// A list of top keys diactricts
// Use to detect and move diacritics
const topDia = [
"gr",
"ct",
"cr",
"dr",
"tl",
"br",
"bri",
"hcr",
"mc",
"gs",
"da",
"ha",
"hc"
] as Array<keyof Font>;

const topDiaCount = (diaKey: keyof Font): number =>
topDia.includes(diaKey) ? 1 : 0;

const moveDia = {
tp: (g: Glyph) => g.map((l: Line) => l.map((p: Vec) => [p[0], p[1] - 0.125])),
bt: (g: Glyph) => g.map((l: Line) => l.map((p: Vec) => [p[0], p[1] + 0.1])),
lf: (g: Glyph) => g.map((l: Line) => l.map((p: Vec) => [p[0] - 0.125, p[1]])),
rg: (g: Glyph) => g.map((l: Line) => l.map((p: Vec) => [p[0] + 0.125, p[1]])),
};

const joinVector = (diaStack: Glyph[], movedDia: Glyph): Glyph =>
diaStack.reduce(
(out: Glyph, curr: Glyph) => [...out, ...curr],
[...movedDia],
);

const mergeDia = (diaKeys: DiaGroup): Glyph => {
// check if theres is two diacritics and
// both are situated on top of letter
const multipleTopDia = diaKeys.reduce(
(acc: number, dia: keyof Font) => (acc += topDiaCount(dia)),
0,
);
if (diaKeys.length > 1 && multipleTopDia > 1) {
// check double grave
if (
diaKeys.reduce((ct: number, k: keyof Font)=> ct += k === 'gr' ? 1 : 0, 0) > 1) {
return joinVector(
diaKeys.filter((k) => k != "gr").map((k) => diacritics[k]),
[...moveDia.lf(diacritics['gr']), ...moveDia.rg(diacritics['gr'])]
)
}
// check double acute
if (
diaKeys.reduce((ct: number, k: keyof Font)=> ct += k === 'ct' ? 1 : 0, 0) > 1) {
return joinVector(
diaKeys.filter((k) => k != "ct").map((k) => diacritics[k]),
[...moveDia.lf(diacritics['ct']), ...moveDia.rg(diacritics['ct'])]
)
}
// move tild down
if (diaKeys.includes("tl")) {
return joinVector(
diaKeys.filter((k) => k != "tl").map((k) => diacritics[k]),
moveDia.bt(diacritics["tl"]),
);
}
// move hacek down
else if (diaKeys.includes("hc")) {
return joinVector(
diaKeys.filter((k) => k != "hc").map((k) => diacritics[k]),
moveDia.bt(diacritics["hc"]),
);
}  
// move macron down
else if (diaKeys.includes("mc")) {
return joinVector(
diaKeys.filter((k) => k != "mc").map((k) => diacritics[k]),
moveDia.bt(diacritics["mc"]),
);
}
// move acute accent left
else if (diaKeys.includes("ct")) {
return joinVector(
diaKeys.filter((k) => k != "ct").map((k) => diacritics[k]),
moveDia.bt(diacritics["ct"]),
);
}
// move grave accent right
else if (diaKeys.includes("gr")) {
return joinVector(
diaKeys.filter((k) => k != "gr").map((k) => diacritics[k]),
moveDia.bt(diacritics["gr"]),
);
}
else {
return diaKeys.reduce(
(acc: Glyph, k: keyof Font) => [...acc, ...diacritics[k]],
[] as Glyph,
);
}
} else {
return diaKeys.reduce(
(acc: Glyph, k: keyof Font) => [...acc, ...diacritics[k]],
[] as Glyph,
);
}
};

export { mergeDia }
Loading

0 comments on commit be6123d

Please sign in to comment.