-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
downscale move glyph to the bottom to fix diacritics on uppercase + c…
…leaning
- Loading branch information
Showing
17 changed files
with
6,314 additions
and
3,241 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
import { Font, Glyph, DiaGroup } from "../type"; | ||
import { topDiaCount, moveDia, joinVector } from "../diacritics/utility"; | ||
|
||
const mergeDiacritics = (diaKeys: DiaGroup, diacritics: Font): 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) { | ||
// double grave move first one on left and second on right | ||
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"])], | ||
); | ||
} | ||
|
||
// double acute move first one on left and second on right | ||
else 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 | ||
else if (diaKeys.includes("tl")) { | ||
return joinVector( | ||
diaKeys.filter((k) => k != "tl").map((k) => diacritics[k]), | ||
moveDia.bt(diacritics["tl"]), | ||
); | ||
} | ||
|
||
// move circumflex down | ||
else if (diaKeys.includes("cr")) { | ||
return joinVector( | ||
diaKeys | ||
.filter((k) => k != "cr") | ||
.map((k) => (k == "ha" ? moveDia.tp(diacritics[k]) : diacritics[k])), | ||
moveDia.bt(diacritics["cr"]), | ||
); | ||
} | ||
|
||
// move breve down | ||
else if (diaKeys.includes("br")) { | ||
return joinVector( | ||
diaKeys | ||
.filter((k) => k != "br") | ||
.map((k) => (k == "ha" ? moveDia.tp(diacritics[k]) : diacritics[k])), | ||
moveDia.bt(diacritics["br"]), | ||
); | ||
} | ||
|
||
// 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 angstorm down | ||
else if (diaKeys.includes("gs")) { | ||
return joinVector( | ||
diaKeys.filter((k) => k != "gs").map((k) => diacritics[k]), | ||
moveDia.bt(diacritics["gs"]), | ||
); | ||
} | ||
|
||
|
||
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 { mergeDiacritics }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { Font, Glyph, Line, Vec } from "../type"; | ||
// 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.14])), | ||
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], | ||
); | ||
|
||
export { topDia, topDiaCount, moveDia, joinVector }; |
Oops, something went wrong.