Skip to content

Commit 290a729

Browse files
import all brand.typography.fonts
whether or not they are referenced in typography elements fixes #11929
1 parent 230825b commit 290a729

File tree

12 files changed

+73
-133
lines changed

12 files changed

+73
-133
lines changed

news/changelog-1.9.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ All changes included in 1.9:
1818

1919
### `html`
2020

21+
- ([#11929](https://github.com/quarto-dev/quarto-cli/issues/11929)): Import all `brand.typography.fonts` in CSS, whether or not fonts are referenced by typography elements.
2122
- ([#13413](https://github.com/quarto-dev/quarto-cli/issues/13413)): Fix uncentered play button in `video` shortcodes from cross-reference divs. (author: @bruvellu)
2223

2324
### `typst`

src/core/sass/brand.ts

Lines changed: 45 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import {
1515
} from "../../config/types.ts";
1616
import { ProjectContext } from "../../project/types.ts";
1717
import {
18-
BrandFont,
1918
// BrandFontBunny,
2019
BrandFontCommon,
2120
BrandFontFile,
@@ -338,104 +337,6 @@ const brandTypographyLayer = (
338337
const typographyImports: Set<string> = new Set();
339338
const fonts = brand.data?.typography?.fonts ?? [];
340339

341-
const getFontFamilies = (family: string | undefined) => {
342-
return fonts.filter((font) =>
343-
typeof font !== "string" && font.family === family
344-
);
345-
};
346-
347-
const resolveGoogleFontFamily = (
348-
font: BrandFont[],
349-
): string | undefined => {
350-
let googleFamily = "";
351-
for (const _resolvedFont of font) {
352-
const safeResolvedFont = Zod.BrandFontGoogle.safeParse(_resolvedFont);
353-
if (!safeResolvedFont.success) {
354-
return undefined;
355-
}
356-
const resolvedFont = safeResolvedFont.data;
357-
const thisFamily = resolvedFont.family;
358-
if (!thisFamily) {
359-
continue;
360-
}
361-
if (googleFamily === "") {
362-
googleFamily = thisFamily;
363-
} else if (googleFamily !== thisFamily) {
364-
throw new Error(
365-
`Inconsistent Google font families found: ${googleFamily} and ${thisFamily}`,
366-
);
367-
}
368-
typographyImports.add(googleFontImportString(resolvedFont));
369-
}
370-
if (googleFamily === "") {
371-
return undefined;
372-
}
373-
return googleFamily;
374-
};
375-
376-
const resolveBunnyFontFamily = (
377-
font: BrandFont[],
378-
): string | undefined => {
379-
let bunnyFamily = "";
380-
for (const _resolvedFont of font) {
381-
const safeResolvedFont = Zod.BrandFontBunny.safeParse(_resolvedFont);
382-
if (!safeResolvedFont.success) {
383-
return undefined;
384-
}
385-
const resolvedFont = safeResolvedFont.data;
386-
// Typescript's type checker doesn't understand that it's ok to attempt
387-
// to access a property that might not exist on a type when you're
388-
// only testing for its existence.
389-
390-
const thisFamily = resolvedFont.family;
391-
if (!thisFamily) {
392-
continue;
393-
}
394-
if (bunnyFamily === "") {
395-
bunnyFamily = thisFamily;
396-
} else if (bunnyFamily !== thisFamily) {
397-
throw new Error(
398-
`Inconsistent Bunny font families found: ${bunnyFamily} and ${thisFamily}`,
399-
);
400-
}
401-
typographyImports.add(bunnyFontImportString(resolvedFont));
402-
}
403-
if (bunnyFamily === "") {
404-
return undefined;
405-
}
406-
return bunnyFamily;
407-
};
408-
409-
const resolveFileFontFamily = (
410-
brand: Brand,
411-
font: BrandFont[],
412-
): string | undefined => {
413-
let fileFamily = "";
414-
for (const _resolvedFont of font) {
415-
const safeResolvedFont = Zod.BrandFontFile.safeParse(_resolvedFont);
416-
if (!safeResolvedFont.success) {
417-
return undefined;
418-
}
419-
const resolvedFont = safeResolvedFont.data;
420-
const thisFamily = resolvedFont.family;
421-
if (!thisFamily) {
422-
continue;
423-
}
424-
if (fileFamily === "") {
425-
fileFamily = thisFamily;
426-
} else if (fileFamily !== thisFamily) {
427-
throw new Error(
428-
`Inconsistent Files font families found: ${fileFamily} and ${thisFamily}`,
429-
);
430-
}
431-
typographyImports.add(fileFontImportString(brand, resolvedFont));
432-
}
433-
if (fileFamily === "") {
434-
return undefined;
435-
}
436-
return fileFamily;
437-
};
438-
439340
type HTMLFontInformation = { [key: string]: unknown };
440341

441342
type FontKind =
@@ -461,11 +362,7 @@ const brandTypographyLayer = (
461362
// that we can attempt to extract the family from.
462363
const family =
463364
(resolvedFontOptions as Record<string, string | undefined>).family;
464-
const font = getFontFamilies(family);
465-
result.family = resolveGoogleFontFamily(font) ??
466-
resolveBunnyFontFamily(font) ??
467-
resolveFileFontFamily(brand, font) ??
468-
family;
365+
result.family = family;
469366
for (
470367
const entry of [
471368
"line-height",
@@ -576,6 +473,50 @@ const brandTypographyLayer = (
576473
],
577474
};
578475

476+
for (const font of fonts) {
477+
switch (font.source) {
478+
case "google": {
479+
const safeResolvedFont = Zod.BrandFontGoogle.safeParse(font);
480+
if (!safeResolvedFont.success) {
481+
continue;
482+
}
483+
const resolvedFont = safeResolvedFont.data;
484+
const thisFamily = resolvedFont.family;
485+
if (!thisFamily) {
486+
continue;
487+
}
488+
typographyImports.add(googleFontImportString(resolvedFont));
489+
break;
490+
}
491+
case "bunny": {
492+
const safeResolvedFont = Zod.BrandFontBunny.safeParse(font);
493+
if (!safeResolvedFont.success) {
494+
continue;
495+
}
496+
const resolvedFont = safeResolvedFont.data;
497+
const thisFamily = resolvedFont.family;
498+
if (!thisFamily) {
499+
continue;
500+
}
501+
typographyImports.add(bunnyFontImportString(resolvedFont));
502+
break;
503+
}
504+
case "file": {
505+
const safeResolvedFont = Zod.BrandFontFile.safeParse(font);
506+
if (!safeResolvedFont.success) {
507+
continue;
508+
}
509+
const resolvedFont = safeResolvedFont.data;
510+
const thisFamily = resolvedFont.family;
511+
if (!thisFamily) {
512+
continue;
513+
}
514+
typographyImports.add(fileFontImportString(brand, resolvedFont));
515+
break;
516+
}
517+
}
518+
}
519+
579520
for (
580521
const kind of [
581522
// more specific entries go first

src/resources/schema/definitions.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3168,7 +3168,7 @@
31683168
#
31693169
# in Quarto, the default source for typst is `google`
31703170
# and the default source for html formats is `bunny`
3171-
- ref: brand-font-common
3171+
31723172
- id: brand-font-weight
31733173
description: A font weight.
31743174
enum:
@@ -3237,6 +3237,7 @@
32373237
properties:
32383238
source:
32393239
enum: [system]
3240+
required: [source]
32403241

32413242
- id: brand-font-google
32423243
description: A font definition from Google Fonts.
@@ -3247,6 +3248,7 @@
32473248
properties:
32483249
source:
32493250
enum: [google]
3251+
required: [source]
32503252

32513253
- id: brand-font-bunny
32523254
description: A font definition from fonts.bunny.net.
@@ -3257,6 +3259,7 @@
32573259
properties:
32583260
source:
32593261
enum: [bunny]
3262+
required: [source]
32603263

32613264
- id: brand-font-file
32623265
description: A method for providing font files directly, either locally or from an online location.

tests/docs/smoke-all/brand/logo/source-sans-pro/brand.yml

Lines changed: 0 additions & 28 deletions
This file was deleted.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
title: Load all brand fonts
3+
4+
brand:
5+
typography:
6+
fonts:
7+
- family: Barrio
8+
source: google
9+
- family: Roboto
10+
source: google
11+
base: Roboto
12+
# headings: Barrio
13+
---
14+
15+
## Base font
16+
17+
{{< lipsum 1 >}}
18+
19+
## Barrio font
20+
21+
::: {style="font-family: Barrio"}
22+
{{< lipsum 1 >}}
23+
:::

0 commit comments

Comments
 (0)