-
Notifications
You must be signed in to change notification settings - Fork 341
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
typst: generic font families / font stack names #11918
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
--- | ||
format: | ||
html: | ||
quality: 1 | ||
pdf: | ||
quality: na | ||
typst: | ||
quality: 2 | ||
comment: "table only" | ||
include-in-header: | ||
text: | | ||
#set text(fallback: false) | ||
dashboard: | ||
quality: 1 | ||
docx: | ||
quality: na | ||
pptx: | ||
quality: na | ||
keep-typ: true | ||
_quarto: | ||
tests: | ||
typst: | ||
ensureTypstFileRegexMatches: | ||
- | ||
- '#set text\(font: \("Linux Libertine"\)\); #table\(' | ||
- '#show heading: set text\(font: "Roboto", \)' | ||
- '#show raw.where\(block: true\): set text\(font: "DejaVu Sans Mono", \)' | ||
- [] | ||
ensurePdfRegexMatches: | ||
- | ||
- 'heading is roboto' | ||
- 'linux libertine' | ||
- 'code should appear in a monospace font' | ||
- [] | ||
brand: | ||
typography: | ||
base: serif | ||
headings: sans-serif | ||
monospace: monospace | ||
--- | ||
# heading is `#context text.font`{=typst} | ||
|
||
base is `#context text.font`{=typst} | ||
|
||
```{=html} | ||
<table style="font-family: serif;"> | ||
<tr><td>A</td><td>B</td></tr> | ||
</table> | ||
``` | ||
|
||
``` | ||
// This code should appear in a monospace font | ||
``` | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -549,7 +549,7 @@ local function output_length(length, warnings) | |
if not csf then | ||
output_warning(warnings, 'unit ' .. length.unit .. ' is not supported in ' .. length.csslen ) | ||
return nil | ||
end | ||
end | ||
return csf(length.value, length.unit, length.csslen, warnings) | ||
end | ||
|
||
|
@@ -593,6 +593,10 @@ local function quote(s) | |
return '"' .. s .. '"' | ||
end | ||
|
||
local function dequote(s) | ||
return s:gsub('^["\']', ''):gsub('["\']$', '') | ||
end | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this is safe here, but it's always terrifying to consider the full implications of quoting, escaping, etc. There's no chance that fonts can have There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (this is also about L662 below) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. :shudder: The spec does not seem to ban commas in font family names. In practice this seems to be something that happens in PostScript because of weights and styles of a family, but CSS handles this differently (and better). |
||
|
||
local same_weights = { | ||
'thin', | ||
'light', | ||
|
@@ -634,6 +638,36 @@ local function translate_font_weight(w, warnings) | |
end | ||
end | ||
|
||
local generic_font_families = { | ||
['sans-serif'] = 'Roboto', | ||
serif = 'Linux Libertine', -- would be Libertinus Serif in Typst 0.12 but we also need to choose our own | ||
math = 'New Computer Modern Math', | ||
monospace = 'DejaVu Sans Mono', | ||
} | ||
|
||
local gff_synonyms = { | ||
['ui-sans-serif'] = 'sans-serif', | ||
['system-ui'] = 'sans-serif', | ||
['ui-serif'] = 'serif', | ||
['ui-monospace'] = 'monospace' | ||
} | ||
|
||
local function translate_font_family(ff) | ||
ff = gff_synonyms[ff] or ff | ||
return generic_font_families[ff] or ff | ||
end | ||
|
||
local function translate_font_family_list(sl) | ||
local strings = {} | ||
for s in sl:gmatch('([^,]+)') do | ||
s = dequote(trim(s)) | ||
s = translate_font_family(s) | ||
table.insert(strings, quote(s)) | ||
end | ||
return '(' .. table.concat(strings, ', ') ..')' | ||
end | ||
|
||
|
||
local function translate_border_style(v, _warnings) | ||
local dash | ||
if v == 'none' then | ||
|
@@ -760,6 +794,8 @@ return { | |
translate_border_style = translate_border_style, | ||
translate_border_color = translate_border_color, | ||
translate_font_weight = translate_font_weight, | ||
translate_font_family = translate_font_family, | ||
translate_font_family_list = translate_font_family_list, | ||
consume_width = consume_width, | ||
consume_style = consume_style, | ||
consume_color = consume_color | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
--- | ||
title: "Untitled" | ||
format: typst | ||
keep-typ: true | ||
--- | ||
|
||
```{=typst} | ||
#text(font: "Roboto")[Roboto] | ||
|
||
#text(font: "Linux Libertine")[Linux Libertine] | ||
|
||
#text(font: "New Computer Modern Math")[New Computer Modern Math] | ||
|
||
#text(font: "DejaVu Sans Mono")[DejaVu Sans Mono] | ||
``` | ||
|
||
```{r} | ||
library(gt) | ||
df <- data.frame(a = c("aa111bbb", "abcdef"), b = c(1, 2)) | ||
tab <- gt::gt(df) | ||
# reliably recreate fonts failure from https://github.com/quarto-dev/quarto-cli/issues/11683 | ||
opt_table_font(tab, | ||
font = c("InvalidFontName", "system-ui", "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji"), | ||
add = FALSE) | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We use
Deno.env.get("QUARTO_SRC_PATH") || join(quartoConfig.sharePath(), "../../src")
in a few different places in our codebase. I wonder if we should be adding asrcPath()
toquartoConfig