Skip to content

Commit

Permalink
downscale move glyph to the bottom to fix diacritics on uppercase + c…
Browse files Browse the repository at this point in the history
…leaning
  • Loading branch information
nclslbrn committed May 16, 2024
1 parent be6123d commit d79514a
Show file tree
Hide file tree
Showing 17 changed files with 6,314 additions and 3,241 deletions.
552 changes: 552 additions & 0 deletions src/diacritics/glyphs.ts

Large diffs are not rendered by default.

105 changes: 105 additions & 0 deletions src/diacritics/mergeDiacritics.ts
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 };
36 changes: 36 additions & 0 deletions src/diacritics/utility.ts
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 };
Loading

0 comments on commit d79514a

Please sign in to comment.