tangled
alpha
login
or
join now
timtinkers.online
/
onomatopoeia
0
fork
atom
bluesky quote bot
0
fork
atom
overview
issues
pulls
pipelines
fixed Google Font URLs
timtinkers.online
1 year ago
6070ac40
cd85fc6f
+11
-8
2 changed files
expand all
collapse all
unified
split
deno.json
utils
imageUtils.ts
+4
deno.json
reviewed
···
11
11
"exclude": [
12
12
"public/bundle.js"
13
13
]
14
14
+
},
15
15
+
"fmt": {
16
16
+
"useTabs": true,
17
17
+
"indentWidth": 4
14
18
}
15
19
}
+7
-8
utils/imageUtils.ts
reviewed
···
25
25
26
26
const fonts: Record<string, Font> = {
27
27
normal: {
28
28
-
url: "https://github.com/google/fonts/raw/refs/heads/main/ofl/merriweather/Merriweather-Regular.ttf",
28
28
+
url: "https://github.com/google/fonts/raw/refs/heads/main/ofl/merriweather/Merriweather%5Bopsz,wdth,wght%5D.ttf",
29
29
family: "Merriweather",
30
30
weight: "400",
31
31
},
32
32
italic: {
33
33
-
url: "https://github.com/google/fonts/raw/refs/heads/main/ofl/merriweather/Merriweather-Italic.ttf",
33
33
+
url: "https://github.com/google/fonts/raw/refs/heads/main/ofl/merriweather/Merriweather-Italic%5Bopsz,wdth,wght%5D.ttf",
34
34
family: "Merriweather",
35
35
weight: "400",
36
36
},
···
43
43
font.data = fontData;
44
44
}),
45
45
);
46
46
+
47
47
+
// Parse font
48
48
+
const fontData: ArrayBuffer = fonts.normal.data!;
49
49
+
const font = fontkit.create(Buffer.from(fontData));
46
50
47
51
function formatText(quote: string) {
48
52
const paragraphs = quote.split("\\n");
···
134
138
135
139
function measureText(
136
140
text: string,
137
137
-
fontSize: number = defaultFontSize,
138
138
-
fontData: ArrayBuffer = fonts.normal.data!,
139
141
) {
140
140
-
// Parse font
141
141
-
const font = fontkit.create(Buffer.from(fontData));
142
142
-
143
142
// Get width (scale based on fontSize)
144
144
-
const scale = fontSize / font.unitsPerEm;
143
143
+
const scale = defaultFontSize / font.unitsPerEm;
145
144
const width = font.layout(
146
145
text.replace(/\*/g, "")
147
146
.replace(" ", " "), // hack, because single space made it look smushed