Skip to content

Commit

Permalink
fix: provide metrics for fallback
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe committed Feb 22, 2024
1 parent 4a9bc4d commit 4ada63d
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/css/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,18 @@ export function generateFontFace (family: string, font: NormalizedFontFaceData)
export async function generateFontFallbacks (family: string, data: NormalizedFontFaceData, fallbacks?: Array<{ name: string, font: string }>) {
if (!fallbacks?.length) return []

const fontURL = data.src!.find(s => 'url' in s) as RemoteFontSource | undefined
const metrics = await getMetricsForFamily(family) || fontURL && await readMetrics(fontURL.url)
// TODO: read metrics from URLs
// const fontURL = data.src!.find(s => 'url' in s) as RemoteFontSource | undefined
const metrics = await getMetricsForFamily(family) // || fontURL && await readMetrics(fontURL.url)

if (!metrics) return []

const css: string[] = []
for (const fallback of fallbacks) {
css.push(generateFallbackFontFace(metrics, fallback))
css.push(generateFallbackFontFace(metrics, {
...fallback,
metrics: await getMetricsForFamily(fallback.name) || undefined
}))
}
return css
}
Expand Down

0 comments on commit 4ada63d

Please sign in to comment.