Skip to content

typst: generic font families / font stack names #11918

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ _quarto:
typst:
ensureTypstFileRegexMatches:
-
- '#set text\(font: \("Georgia", "serif"\)\); #table\('
- '#{set text\(font: \("Georgia", "Libertinus Serif"\)\); table\('
- []
---

Expand Down
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: \("Libertinus Serif"\)\); table\('
- '#show heading: set text\(font: "Noto Sans", \)'
- '#show raw.where\(block: true\): set text\(font: "DejaVu Sans Mono", \)'
- []
ensurePdfRegexMatches:
-
- 'heading is noto sans'
- 'base is libertinus serif'
- '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
```

1 change: 1 addition & 0 deletions news/changelog-1.7.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ All changes included in 1.7:

## `typst` format

- ([#11918](https://github.com/quarto-dev/quarto-cli/pull/11918)): Minimal implementation of CSS generic font families for Typst, so that the major generic font families will be resolved when included in font lists.
- ([#11578](https://github.com/quarto-dev/quarto-cli/issues/11578)): Typst column layout widths use fractional `fr` units instead of percent `%` units for unitless and default widths in order to fill the enclosing block and not spill outside it.
- ([#11676](https://github.com/quarto-dev/quarto-cli/pull/11676)): Convert unitless image widths from pixels to inches for column layouts.
- ([#11835](https://github.com/quarto-dev/quarto-cli/issues/11835)): Take markdown structure into account when detecting minimum heading level.
Expand Down
2 changes: 2 additions & 0 deletions src/command/render/pandoc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { Document } from "../../core/deno-dom.ts";
import { execProcess } from "../../core/process.ts";
import { dirAndStem, normalizePath } from "../../core/path.ts";
import { mergeConfigs } from "../../core/config.ts";
import { quartoConfig } from "../../core/quarto.ts";

import {
Format,
Expand Down Expand Up @@ -1601,6 +1602,7 @@ async function resolveExtras(
}
fontdirs.add(font_cache);
}
fontdirs.add(join(quartoConfig.srcPath(), "resources/fonts"));
let fontPaths = format.metadata[kFontPaths] as Array<string> || [];
if (typeof fontPaths === "string") {
fontPaths = [fontPaths];
Expand Down
3 changes: 1 addition & 2 deletions src/core/devconfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ export function createDevConfig(
scriptDir: string,
): DevConfig {
const scriptPath = join(scriptDir, "quarto" + (isWindows ? ".cmd" : ""));
const srcDir = Deno.env.get("QUARTO_SRC_PATH") ||
join(quartoConfig.sharePath(), "../../src");
const srcDir = quartoConfig.srcPath();
return {
deno,
deno_dom,
Expand Down
3 changes: 3 additions & 0 deletions src/core/quarto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ export const quartoConfig = {
binPath: () => getenv("QUARTO_BIN_PATH"),
toolsPath: () => join(getenv("QUARTO_BIN_PATH"), "tools"),
sharePath: () => getenv("QUARTO_SHARE_PATH"),
srcPath: () =>
getenv("QUARTO_SRC_PATH", "") ||
normalizePath(join(quartoConfig.sharePath(), "../../src")),
isDebug: () => getenv("QUARTO_DEBUG", "false") === "true",
version: () => {
const forceVersion = getenv("QUARTO_FORCE_VERSION", "");
Expand Down
38 changes: 37 additions & 1 deletion src/resources/filters/modules/typst_css.lua
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,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

Expand Down Expand Up @@ -595,6 +595,10 @@ local function quote(s)
return '"' .. s .. '"'
end

local function dequote(s)
return s:gsub('^["\']', ''):gsub('["\']$', '')
end

local same_weights = {
'thin',
'light',
Expand Down Expand Up @@ -636,6 +640,36 @@ local function translate_font_weight(w, warnings)
end
end

local generic_font_families = {
['sans-serif'] = 'Noto Sans',
serif = 'Libertinus Serif',
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
Expand Down Expand Up @@ -762,6 +796,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
Expand Down
10 changes: 5 additions & 5 deletions src/resources/filters/quarto-post/typst-brand-yaml.lua
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ function render_typst_brand_yaml()
if headings and next(headings) then
quarto.doc.include_text('in-header', table.concat({
'#show heading: set text(',
conditional_entry('font', headings.family),
conditional_entry('font', _quarto.modules.typst.css.translate_font_family(headings.family)),
conditional_entry('weight', _quarto.modules.typst.css.translate_font_weight(headings.weight)),
conditional_entry('style', headings.style),
conditional_entry('fill', headings.color, false),
Expand All @@ -138,7 +138,7 @@ function render_typst_brand_yaml()
if monospaceInline and next(monospaceInline) then
quarto.doc.include_text('in-header', table.concat({
'#show raw.where(block: false): set text(',
conditional_entry('font', monospaceInline.family),
conditional_entry('font', _quarto.modules.typst.css.translate_font_family(monospaceInline.family)),
conditional_entry('weight', _quarto.modules.typst.css.translate_font_weight(monospaceInline.weight)),
conditional_entry('size', monospaceInline.size, false),
conditional_entry('fill', monospaceInline.color, false),
Expand All @@ -157,7 +157,7 @@ function render_typst_brand_yaml()
if monospaceBlock and next(monospaceBlock) then
quarto.doc.include_text('in-header', table.concat({
'#show raw.where(block: true): set text(',
conditional_entry('font', monospaceBlock.family),
conditional_entry('font', _quarto.modules.typst.css.translate_font_family(monospaceBlock.family)),
conditional_entry('weight', _quarto.modules.typst.css.translate_font_weight(monospaceBlock.weight)),
conditional_entry('size', monospaceBlock.size, false),
conditional_entry('fill', monospaceBlock.color, false),
Expand Down Expand Up @@ -309,7 +309,7 @@ function render_typst_brand_yaml()
local base = _quarto.modules.brand.get_typography(brandMode, 'base')
if base and next(base) then
meta.brand.typography.base = {
family = base.family,
family = _quarto.modules.typst.css.translate_font_family(base.family),
size = base.size,
}
end
Expand All @@ -324,7 +324,7 @@ function render_typst_brand_yaml()
local weight = _quarto.modules.typst.css.translate_font_weight(headings.weight or base.weight)
weight = weight and pandoc.RawInline('typst', tostring(quote_string(weight)))
meta.brand.typography.headings = {
family = headings.family or base.family,
family = _quarto.modules.typst.css.translate_font_family(headings.family or base.family),
weight = weight,
style = headings.style or base.style,
decoration = headings.decoration or base.decoration,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,6 @@ function render_typst_css_property_processing()
end
end

local function dequote(s)
return s:gsub('^["\']', ''):gsub('["\']$', '')
end

local function quote(s)
return '"' .. s .. '"'
end

local function translate_vertical_align(va)
if va == 'top' then
return 'top'
Expand Down Expand Up @@ -270,15 +262,6 @@ function render_typst_css_property_processing()
end
return span
end

local function translate_string_list(sl)
local strings = {}
for s in sl:gmatch('([^,]+)') do
s = s:gsub('^%s+', '')
table.insert(strings, quote(dequote(s)))
end
return '(' .. table.concat(strings, ', ') ..')'
end

return {
Table = function(tab)
Expand All @@ -289,7 +272,7 @@ function render_typst_css_property_processing()
for clause in tabstyle:gmatch('([^;]+)') do
local k, v = to_kv(clause)
if k == 'font-family' then
tab.attributes['typst:text:font'] = translate_string_list(v)
tab.attributes['typst:text:font'] = _quarto.format.typst.css.translate_font_family_list(v)
has_typst_text = true
end
if k == 'font-size' then
Expand Down
Binary file added src/resources/fonts/Noto-Sans/NotoSans-Black.ttf
Binary file not shown.
Binary file not shown.
Binary file added src/resources/fonts/Noto-Sans/NotoSans-Bold.ttf
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added src/resources/fonts/Noto-Sans/NotoSans-Light.ttf
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added src/resources/fonts/Noto-Sans/NotoSans-Thin.ttf
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
93 changes: 93 additions & 0 deletions src/resources/fonts/Noto-Sans/OFL.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
Copyright 2022 The Noto Project Authors (https://github.com/notofonts/latin-greek-cyrillic)

This Font Software is licensed under the SIL Open Font License, Version 1.1.
This license is copied below, and is also available with a FAQ at:
https://openfontlicense.org


-----------------------------------------------------------
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
-----------------------------------------------------------

PREAMBLE
The goals of the Open Font License (OFL) are to stimulate worldwide
development of collaborative font projects, to support the font creation
efforts of academic and linguistic communities, and to provide a free and
open framework in which fonts may be shared and improved in partnership
with others.

The OFL allows the licensed fonts to be used, studied, modified and
redistributed freely as long as they are not sold by themselves. The
fonts, including any derivative works, can be bundled, embedded,
redistributed and/or sold with any software provided that any reserved
names are not used by derivative works. The fonts and derivatives,
however, cannot be released under any other type of license. The
requirement for fonts to remain under this license does not apply
to any document created using the fonts or their derivatives.

DEFINITIONS
"Font Software" refers to the set of files released by the Copyright
Holder(s) under this license and clearly marked as such. This may
include source files, build scripts and documentation.

"Reserved Font Name" refers to any names specified as such after the
copyright statement(s).

"Original Version" refers to the collection of Font Software components as
distributed by the Copyright Holder(s).

"Modified Version" refers to any derivative made by adding to, deleting,
or substituting -- in part or in whole -- any of the components of the
Original Version, by changing formats or by porting the Font Software to a
new environment.

"Author" refers to any designer, engineer, programmer, technical
writer or other person who contributed to the Font Software.

PERMISSION & CONDITIONS
Permission is hereby granted, free of charge, to any person obtaining
a copy of the Font Software, to use, study, copy, merge, embed, modify,
redistribute, and sell modified and unmodified copies of the Font
Software, subject to the following conditions:

1) Neither the Font Software nor any of its individual components,
in Original or Modified Versions, may be sold by itself.

2) Original or Modified Versions of the Font Software may be bundled,
redistributed and/or sold with any software, provided that each copy
contains the above copyright notice and this license. These can be
included either as stand-alone text files, human-readable headers or
in the appropriate machine-readable metadata fields within text or
binary files as long as those fields can be easily viewed by the user.

3) No Modified Version of the Font Software may use the Reserved Font
Name(s) unless explicit written permission is granted by the corresponding
Copyright Holder. This restriction only applies to the primary font name as
presented to the users.

4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
Software shall not be used to promote, endorse or advertise any
Modified Version, except to acknowledge the contribution(s) of the
Copyright Holder(s) and the Author(s) or with their explicit written
permission.

5) The Font Software, modified or unmodified, in part or in whole,
must be distributed entirely under this license, and must not be
distributed under any other license. The requirement for fonts to
remain under this license does not apply to any document created
using the Font Software.

TERMINATION
This license becomes null and void if any of the above conditions are
not met.

DISCLAIMER
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
OTHER DEALINGS IN THE FONT SOFTWARE.
Loading
Loading