diff --git a/src/core/brand/brand.ts b/src/core/brand/brand.ts index afeed6a309d..2a881a3de8c 100644 --- a/src/core/brand/brand.ts +++ b/src/core/brand/brand.ts @@ -10,15 +10,15 @@ import { Brand as BrandJson, BrandFont, BrandLogoExplicitResource, - BrandNamedLogo, BrandNamedThemeColor, - BrandStringLightDark, BrandTypography, BrandTypographyOptionsBase, BrandTypographyOptionsHeadings, } from "../../resources/types/schema-types.ts"; import { InternalError } from "../lib/error.ts"; +import { join, relative } from "../../deno_ral/path.ts"; + // we can't programmatically convert typescript types to string arrays, // so we have to define this manually. They should match `BrandNamedThemeColor` in schema-types.ts @@ -237,14 +237,14 @@ export class Brand { if (!entry) { return { path: name }; } + const pathPrefix = relative(this.projectDir, this.brandDir); if (typeof entry === "string") { - return { path: entry }; + return { path: join(pathPrefix, entry) }; } + entry.path = join(pathPrefix, entry.path); return entry; } - // the same implementation as getColor except we can also return {light,dark} - // assuming for now that with only contains strings, not {light,dark} getLogo(name: "small" | "medium" | "large"): CanonicalLogoInfo | undefined { const entry = this.data.logo?.[name]; if (!entry) { diff --git a/src/resources/filters/quarto-post/typst-brand-yaml.lua b/src/resources/filters/quarto-post/typst-brand-yaml.lua index 52b61764038..979923a3585 100644 --- a/src/resources/filters/quarto-post/typst-brand-yaml.lua +++ b/src/resources/filters/quarto-post/typst-brand-yaml.lua @@ -250,13 +250,18 @@ function render_typst_brand_yaml() location_to_typst_align(logoOptions.location) or 'left+top' quarto.log.debug('logo options', logoOptions) local altProp = logoOptions.alt and (', alt: "' .. logoOptions.alt .. '"') or '' + local dblbackslash = string.gsub(logoOptions.path, '\\', '\\\\') -- double backslash? quarto.doc.include_text('in-header', - '#set page(background: align(' .. logoOptions.location .. ', box(inset: ' .. logoOptions.padding .. ', image("' .. logoOptions.path .. '", width: ' .. logoOptions.width .. altProp .. '))))') + '#set page(background: align(' .. logoOptions.location .. ', box(inset: ' .. logoOptions.padding .. ', image("' .. dblbackslash .. '", width: ' .. logoOptions.width .. altProp .. '))))') end end end, Meta = function(meta) - meta.brand = meta.brand or {typography = {}} + -- it can contain the path but we want to store an object here + if not meta.brand or pandoc.utils.type(meta.brand) == 'Inlines' then + meta.brand = {} + end + meta.brand.typography = meta.brand.typography or {} local base = _quarto.modules.brand.get_typography('base') if base and next(base) then meta.brand.typography.base = { diff --git a/tests/docs/smoke-all/typst/brand-yaml/logo/relative-path/brand-logo.qmd b/tests/docs/smoke-all/typst/brand-yaml/logo/relative-path/brand-logo.qmd new file mode 100644 index 00000000000..b51305cdfe9 --- /dev/null +++ b/tests/docs/smoke-all/typst/brand-yaml/logo/relative-path/brand-logo.qmd @@ -0,0 +1,19 @@ +--- +title: logo background +brand: brand_yaml/quarto-brand.yml +format: + typst: + keep-typ: true +logo: + padding: 2rem +_quarto: + tests: + typst: + ensureTypstFileRegexMatches: + - + - '#set page\(background: align\(center\+top, box\(inset: 2em, image\("brand_yaml(/|\\\\)resources(/|\\\\)quarto.png", width: 225pt\)\)\)\)' + - [] +--- + +{{< lipsum 4 >}} + diff --git a/tests/docs/smoke-all/typst/brand-yaml/logo/relative-path/brand_yaml/quarto-brand.yml b/tests/docs/smoke-all/typst/brand-yaml/logo/relative-path/brand_yaml/quarto-brand.yml new file mode 100644 index 00000000000..07a148be5d2 --- /dev/null +++ b/tests/docs/smoke-all/typst/brand-yaml/logo/relative-path/brand_yaml/quarto-brand.yml @@ -0,0 +1,13 @@ +logo: + images: + large-light: resources/quarto.png + large: large-light +defaults: + quarto: + format: + typst: + logo: + src: large + location: center-top + width: 300px + padding: 1in diff --git a/tests/docs/smoke-all/typst/brand-yaml/logo/relative-path/brand_yaml/resources/quarto.png b/tests/docs/smoke-all/typst/brand-yaml/logo/relative-path/brand_yaml/resources/quarto.png new file mode 100644 index 00000000000..616d17b92cb Binary files /dev/null and b/tests/docs/smoke-all/typst/brand-yaml/logo/relative-path/brand_yaml/resources/quarto.png differ diff --git a/tests/docs/smoke-all/typst/brand-yaml/typography/relative-path/brand-typography.qmd b/tests/docs/smoke-all/typst/brand-yaml/typography/relative-path/brand-typography.qmd new file mode 100644 index 00000000000..b0485dcca22 --- /dev/null +++ b/tests/docs/smoke-all/typst/brand-yaml/typography/relative-path/brand-typography.qmd @@ -0,0 +1,35 @@ +--- +title: title is `#context text.font`{=typst} `#context text.weight`{=typst} `#context text.style`{=typst} `#context text.size`{=typst} +format: typst +brand: branding/brand.yml +include-in-header: + text: | + #set text(fallback: false) +_quarto: + tests: + typst: + ensurePdfRegexMatches: + - + - 'title is roboto slab semibold normal 16.5pt' + - 'heading-2 is roboto slab semibold normal 15.4pt' + - 'paragraph is open sans regular normal 11pt' + - 'fib = num => num < 2' + - [] +--- + +## heading-2 is `#context text.font`{=typst} `#context text.weight`{=typst} `#context text.style`{=typst} `#context text.size`{=typst} + +paragraph is `#context text.font`{=typst} `#context text.weight`{=typst} `#context text.style`{=typst} `#context text.size`{=typst}. + +```{=typst} +#block(text(font: "Fira Code", weight: "black")[Some text with font set explicitly to #context text.font #context text.weight #context text.style #context text.size]) + +``` + +``` +const fib = num => num < 2 ? num : fib(num-1) + fib(num - 2); +console.log(fib(12)) +``` + +{{< lipsum 3 >}} + diff --git a/tests/docs/smoke-all/typst/brand-yaml/typography/relative-path/branding/brand.yml b/tests/docs/smoke-all/typst/brand-yaml/typography/relative-path/branding/brand.yml new file mode 100644 index 00000000000..0fed9b28e9e --- /dev/null +++ b/tests/docs/smoke-all/typst/brand-yaml/typography/relative-path/branding/brand.yml @@ -0,0 +1,27 @@ +typography: + fonts: + - family: "Open Sans" + source: file + files: + - resources/fonts/opensans/OpenSans-VariableFont_wdth,wght.ttf + - family: "Fira Code" + source: file + files: + - resources/fonts/firacode/FiraCode-VF.ttf + - family: "Roboto Slab" + source: file + files: + - path: resources/fonts/robotoslab/RobotoSlab-VariableFont_wght.ttf + weight: 600 + style: normal + base: + family: Open Sans + line-height: 1.25em + size: 1rem + headings: + family: Roboto Slab + color: primary + weight: 600 + monospace: + family: Fira Code + size: 0.9em diff --git a/tests/docs/smoke-all/typst/brand-yaml/typography/relative-path/branding/resources/fonts/firacode/FiraCode-VF.ttf b/tests/docs/smoke-all/typst/brand-yaml/typography/relative-path/branding/resources/fonts/firacode/FiraCode-VF.ttf new file mode 100644 index 00000000000..c05ac827c58 Binary files /dev/null and b/tests/docs/smoke-all/typst/brand-yaml/typography/relative-path/branding/resources/fonts/firacode/FiraCode-VF.ttf differ diff --git a/tests/docs/smoke-all/typst/brand-yaml/typography/relative-path/branding/resources/fonts/opensans/OpenSans-VariableFont_wdth,wght.ttf b/tests/docs/smoke-all/typst/brand-yaml/typography/relative-path/branding/resources/fonts/opensans/OpenSans-VariableFont_wdth,wght.ttf new file mode 100644 index 00000000000..ac587b482b8 Binary files /dev/null and b/tests/docs/smoke-all/typst/brand-yaml/typography/relative-path/branding/resources/fonts/opensans/OpenSans-VariableFont_wdth,wght.ttf differ diff --git a/tests/docs/smoke-all/typst/brand-yaml/typography/relative-path/branding/resources/fonts/robotoslab/RobotoSlab-VariableFont_wght.ttf b/tests/docs/smoke-all/typst/brand-yaml/typography/relative-path/branding/resources/fonts/robotoslab/RobotoSlab-VariableFont_wght.ttf new file mode 100644 index 00000000000..d78883c1283 Binary files /dev/null and b/tests/docs/smoke-all/typst/brand-yaml/typography/relative-path/branding/resources/fonts/robotoslab/RobotoSlab-VariableFont_wght.ttf differ