Skip to content

Commit

Permalink
egh diacrtics
Browse files Browse the repository at this point in the history
  • Loading branch information
nclslbrn committed May 5, 2024
1 parent 42899a1 commit 3572375
Show file tree
Hide file tree
Showing 6 changed files with 477 additions and 82 deletions.
86 changes: 60 additions & 26 deletions demo/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,33 @@
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","ź","ẑ","ž","ż","ẓ","ẕ","ƍ","ƶ","ȥ","ʐ","ʑ","ɀ","ʒ","ǯ","ƹ","ƺ","ʓ","þ","ƿ","ƨ","ƽ","ƅ","ɂ","ʕ","ʡ","ʢ","ʖ","ʗ","ʘ","ʬ","ʭ"]
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źẑžżẓẕƍƶȥʐʑɀʒǯƹƺʓþƿƨƽƅɂʕʡʢʖʗʘʬʭ",
];
/*
console.log(
JSON.stringify(
Expand All @@ -13,23 +38,30 @@ console.log(
);
*/

const rotateGlyph = (g: Glyph) =>
g.map((l: Line) => l.map((p: Vec) => [1 - p[0], 1 - p[1]]));
const upscaleGlyph = (g: Glyph) =>
g.map((l: Line) => l.map((p: Vec) => [p[0] * 1.1 - 0.05, p[1] * 1.1 - 0.05]));

const rotateGlyph = (g: Glyph) => g.map((l: Line) => l.map((p: Vec) => [1 - p[0], 1 - p[1]]))
const scaleGlyph = (g: Glyph) => g.map((l: Line) => l.map((p: Vec) => [0.25 + p[0] * 0.5, 0.25 + p[1] * 0.5]))
const scaleGlyph = (g: Glyph) =>
g.map((l: Line) => l.map((p: Vec) => [0.166 + p[0] * 0.66, 0.166 + p[1] * 0.66]));
const mirrorXGlyph = (g: Glyph) =>
g.map((l: Line) => l.map((p: Vec) => [p[0], 1 - p[1]]));
const mirrorYGlyph = (g: Glyph) =>
g.map((l: Line) => l.map((p: Vec) => [1 - p[0], p[1]]));

// font["ʙ"] = scaleGlyph(font["B"])
// console.log(JSON.stringify(scaleGlyph(font['6'])))
// font["ɜ"] = mirrorYGlyph(font["ɛ"])
console.log(JSON.stringify(scaleGlyph(font["H"])));

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


const app = document.getElementById("app"),
form = document.createElement("form"),
namespace = "http://www.w3.org/2000/svg",
Expand All @@ -41,40 +73,42 @@ const app = document.getElementById("app"),
group = document.createElementNS(namespace, "g");

const update = () => {
let height = window.innerHeight
let height = window.innerHeight;
const userInput = input.value !== textAtLaunch ? input.value : glyphKeys,
text = userInput.split("") as string[],
fontScale = parseFloat(inputSize.value),
width = window.innerWidth - 40,
baseSize = Math.max(16, Math.min(Math.floor(Math.hypot(width, height) * fontScale), 264)),
baseSize = Math.max(
16,
Math.min(Math.floor(Math.hypot(width, height) * fontScale), 264),
),
textSize = [baseSize, baseSize],
charPerLine = Math.floor(width / textSize[0]) - 2,
nbLines = Math.ceil(text.length / charPerLine),
margin = [
(width - charPerLine * textSize[0]) / 2,
40,
];
margin = [(width - charPerLine * textSize[0]) / 2, 40];
group.textContent = "";

for (let y = 0; y < nbLines; y++) {
const remainingChar = Math.min(charPerLine, text.length - y * charPerLine);
if ((y+1)*textSize[1] >= height-margin[1]) height += (textSize[1]+margin[1])
if ((y + 1) * textSize[1] >= height - margin[1])
height += textSize[1] + margin[1];

for (let x = 0; x < remainingChar; x++) {
const char = text[y * charPerLine + x];
const lines = getGlyphPath(char, textSize, [
margin[0] + x * textSize[0],
margin[1] + y * textSize[1], textSize[1]
margin[1] + y * textSize[1],
textSize[1],
]);
const rect = document.createElementNS(namespace, "rect");
rect.setAttribute("x", `${margin[0] + x * textSize[0]}`);
rect.setAttribute("y", `${margin[1] + y * textSize[1]}`);
rect.setAttribute("width", `${textSize[0]}`);
rect.setAttribute("height", `${textSize[1]}`);
rect.setAttribute("title", char)
const title = document.createElementNS(namespace, "title")
title.textContent = char
rect.appendChild(title)
rect.setAttribute("title", char);
const title = document.createElementNS(namespace, "title");
title.textContent = char;
rect.appendChild(title);

lines.map((d: string) => {
const path = document.createElementNS(namespace, "path");
Expand All @@ -87,8 +121,8 @@ const update = () => {
group.setAttribute("stroke-width", `${fontScale * 40}`);

svg.setAttribute("width", `${width}`);
svg.setAttribute("height", `${height+40}`);
svg.setAttribute("viewbox", `0 0 ${width} ${height+40}`);
svg.setAttribute("height", `${height + 40}`);
svg.setAttribute("viewbox", `0 0 ${width} ${height + 40}`);
};

const init = () => {
Expand Down
9 changes: 9 additions & 0 deletions src/glyphs/diacritics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,15 @@ const diacritics = {
[0.6, 0.1],
],
],
// breve below
brb: [
[
[0.4, 0.8],
[0.4, 0.85],
[0.6, 0.85],
[0.6, 0.8]
]
],
// inverse breve
bri: [
[
Expand Down
Loading

0 comments on commit 3572375

Please sign in to comment.