typst/tests/typ/library/font.typ
Laurenz 54a9ccb1a5 Configurable font edges ⚙
Adds top-edge and bottom-edge parameters to the font function. These define how
the box around a word is computed. The possible values are:
- ascender
- cap-height (default top edge)
- x-height
- baseline (default bottom edge)
- descender

The defaults are chosen so that it's easy to create good-looking designs with
vertical alignment. Since they are much tighter than what most other software
uses by default, the default leading had to be increased to 50% of the font size
and paragraph spacing to 100% of the font size.

The values cap-height and x-height fall back to ascender in case they are zero
because this value may occur in fonts that don't have glyphs with cap- or
x-height (like Twitter Color Emoji). Since cap-height is the default top edge,
doing no fallback would break things badly.

Removes softness in favor of a simple boolean for pages and a more finegread u8
for spacing. This is needed to make paragraph spacing consume line spacing
created by hard line breaks.
2021-03-19 13:20:58 +01:00

67 lines
1.3 KiB
Typst
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// Test the `font` function.
---
// Test configuring font properties.
// Set same font size in three different ways.
#font(22pt)[A]
#font(200%)[A]
#font(16.5pt + 50%)[A]
// Do nothing.
#font[Normal]
// Set style (is available).
#font(style: italic)[Italic]
// Set weight (is available).
#font(weight: bold)[Bold]
// Set stretch (not available, matching closest).
#font(stretch: 50%)[Condensed]
// Set family.
#font("PT Sans")[Sans serif]
// Emoji.
Emoji: 🐪, 🌋, 🏞
// Math.
#font("Latin Modern Math")[
𝛼 + 3𝛽 d𝑡
]
---
// Test top and bottom edge.
#page(width: 170pt)
#let try(top, bottom) = rect(fill: #9feb52)[
#font(top-edge: top, bottom-edge: bottom)
`From `#top` to `#bottom
]
#try(ascender, descender)
#try(ascender, baseline)
#try(cap-height, baseline)
#try(x-height, baseline)
---
// Ref: false
// Error: 7-12 unexpected argument
#font(false)
// Error: 3:14-3:18 expected font style, found font weight
// Error: 2:28-2:34 expected font weight, found string
// Error: 1:43-1:44 expected font family or array of font families, found integer
#font(style: bold, weight: "thin", serif: 0)
// Warning: 15-19 should be between 100 and 900
#font(weight: 2700)
// Warning: 16-21 should be between 50% and 200%
#font(stretch: 1000%)
// Error: 7-27 unexpected argument
#font(something: "invalid")