Skip to content

Commit

Permalink
🔨 vertically center test glyphs
Browse files Browse the repository at this point in the history
- removes fiddly y-offset param
  • Loading branch information
samizdatco committed Oct 23, 2023
1 parent 4c040d4 commit 97b41de
Showing 1 changed file with 8 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,25 +47,24 @@ export class StaticChartRasterizer {
// text drawn in non-loaded fonts will simply be invisible). This method will block rendering
// for up to {retries × delay} seconds or until it verifies that all the fonts in the `faces`
// array are ready for use
const MAX_RETRIES = 5,
RETRY_DELAY_MS = 100

const faces = [
{ font: "40px Lato", offset: 17 },
{ font: "bold 40px Lato", offset: 17 },
{ font: "500 75px 'Playfair Display'", offset: 27 },
]
"60px Lato",
"bold 60px Lato",
"75px 'Playfair Display'",
],
MAX_RETRIES = 5,
RETRY_DELAY_MS = 100

for (let retry = 0; retry < MAX_RETRIES; retry++) {
const ctx = canvas.getContext("2d", { alpha: false })!
const outcomes = []

for (const { font, offset } of faces) {
for (const font of faces) {
// draw a bullet character that's big enough to fill the entire 10×10 canvas
const testBlob = blobFromSVG(
`<svg xmlns="http://www.w3.org/2000/svg" version="1.1" style="font:${font};" width="10" height="10" viewBox="0 0 10 10">
<defs><style>${this.embeddedFonts}</style></defs>
<text x="5.0" y="${offset}.0" text-anchor="middle" fill="white">•</text>
<text x="5.0" y="5.0" fill="white" text-anchor="middle" alignment-baseline="central" >•</text>
</svg>`
),
testUrl = await urlFromBlob(testBlob),
Expand Down

0 comments on commit 97b41de

Please sign in to comment.