mirror of
https://github.com/typst/typst
synced 2025-05-15 17:45:27 +08:00
Warn about unknown font families during parsing (#3854)
This commit is contained in:
parent
21c78abd6e
commit
0523f22d83
@ -51,6 +51,11 @@ impl FontBook {
|
|||||||
self.infos.get(index)
|
self.infos.get(index)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns true if the book contains a font family with the given name.
|
||||||
|
pub fn contains_family(&self, family: &str) -> bool {
|
||||||
|
self.families.contains_key(family)
|
||||||
|
}
|
||||||
|
|
||||||
/// An ordered iterator over all font families this book knows and details
|
/// An ordered iterator over all font families this book knows and details
|
||||||
/// about the fonts that are part of them.
|
/// about the fonts that are part of them.
|
||||||
pub fn families(
|
pub fn families(
|
||||||
|
@ -35,7 +35,7 @@ use rustybuzz::{Feature, Tag};
|
|||||||
use smallvec::SmallVec;
|
use smallvec::SmallVec;
|
||||||
use ttf_parser::Rect;
|
use ttf_parser::Rect;
|
||||||
|
|
||||||
use crate::diag::{bail, SourceResult, StrResult};
|
use crate::diag::{bail, warning, SourceResult, StrResult};
|
||||||
use crate::engine::Engine;
|
use crate::engine::Engine;
|
||||||
use crate::foundations::Packed;
|
use crate::foundations::Packed;
|
||||||
use crate::foundations::{
|
use crate::foundations::{
|
||||||
@ -47,6 +47,7 @@ use crate::layout::{Abs, Axis, Dir, Length, Rel};
|
|||||||
use crate::model::ParElem;
|
use crate::model::ParElem;
|
||||||
use crate::syntax::Spanned;
|
use crate::syntax::Spanned;
|
||||||
use crate::visualize::{Color, Paint, RelativeTo, Stroke};
|
use crate::visualize::{Color, Paint, RelativeTo, Stroke};
|
||||||
|
use crate::World;
|
||||||
|
|
||||||
/// Text styling.
|
/// Text styling.
|
||||||
///
|
///
|
||||||
@ -122,6 +123,22 @@ pub struct TextElem {
|
|||||||
/// This is Latin. \
|
/// This is Latin. \
|
||||||
/// هذا عربي.
|
/// هذا عربي.
|
||||||
/// ```
|
/// ```
|
||||||
|
#[parse({
|
||||||
|
let font_list: Option<Spanned<FontList>> = args.named("font")?;
|
||||||
|
if let Some(font_list) = &font_list {
|
||||||
|
let book = engine.world.book();
|
||||||
|
for family in &font_list.v {
|
||||||
|
if !book.contains_family(family.as_str()) {
|
||||||
|
engine.tracer.warn(warning!(
|
||||||
|
font_list.span,
|
||||||
|
"unknown font family: {}",
|
||||||
|
family.as_str(),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
font_list.map(|font_list| font_list.v)
|
||||||
|
})]
|
||||||
#[default(FontList(vec![FontFamily::new("Linux Libertine")]))]
|
#[default(FontList(vec![FontFamily::new("Linux Libertine")]))]
|
||||||
#[borrowed]
|
#[borrowed]
|
||||||
#[ghost]
|
#[ghost]
|
||||||
|
BIN
tests/ref/text-unknown-font-family-warning.png
Normal file
BIN
tests/ref/text-unknown-font-family-warning.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 499 B |
@ -17,6 +17,7 @@ $ x := #table(columns: 2)[x][y]/mat(1, 2, 3)
|
|||||||
|
|
||||||
--- math-font-switch ---
|
--- math-font-switch ---
|
||||||
// Test font switch.
|
// Test font switch.
|
||||||
|
// Warning: 29-40 unknown font family: noto sans
|
||||||
#let here = text.with(font: "Noto Sans")
|
#let here = text.with(font: "Noto Sans")
|
||||||
$#here[f] := #here[Hi there]$.
|
$#here[f] := #here[Hi there]$.
|
||||||
|
|
||||||
|
@ -5,11 +5,13 @@
|
|||||||
#set text(size: 8pt)
|
#set text(size: 8pt)
|
||||||
|
|
||||||
#let try(top, bottom) = rect(inset: 0pt, fill: conifer)[
|
#let try(top, bottom) = rect(inset: 0pt, fill: conifer)[
|
||||||
|
// Warning: 19-34 unknown font family: ibm plex mono
|
||||||
#set text(font: "IBM Plex Mono", top-edge: top, bottom-edge: bottom)
|
#set text(font: "IBM Plex Mono", top-edge: top, bottom-edge: bottom)
|
||||||
From #top to #bottom
|
From #top to #bottom
|
||||||
]
|
]
|
||||||
|
|
||||||
#let try-bounds(top, bottom) = rect(inset: 0pt, fill: conifer)[
|
#let try-bounds(top, bottom) = rect(inset: 0pt, fill: conifer)[
|
||||||
|
// Warning: 19-34 unknown font family: ibm plex mono
|
||||||
#set text(font: "IBM Plex Mono", top-edge: top, bottom-edge: bottom)
|
#set text(font: "IBM Plex Mono", top-edge: top, bottom-edge: bottom)
|
||||||
#top to #bottom: "yay, Typst"
|
#top to #bottom: "yay, Typst"
|
||||||
]
|
]
|
||||||
|
@ -64,3 +64,15 @@ Emoji: 🐪, 🌋, 🏞
|
|||||||
--- text-bad-named-argument ---
|
--- text-bad-named-argument ---
|
||||||
// Error: 11-31 unexpected argument: something
|
// Error: 11-31 unexpected argument: something
|
||||||
#set text(something: "invalid")
|
#set text(something: "invalid")
|
||||||
|
|
||||||
|
--- text-unknown-font-family-warning ---
|
||||||
|
#text(font: "linux libertine", "I exist, ")
|
||||||
|
// Warning: 13-27 unknown font family: non-existing
|
||||||
|
#text(font: "non-existing", "but")
|
||||||
|
// Warning: 17-36 unknown font family: also-non-existing
|
||||||
|
#set text(font: "also-non-existing")
|
||||||
|
I
|
||||||
|
// Warning: 23-56 unknown font family: list-of
|
||||||
|
// Warning: 23-56 unknown font family: non-existing-fonts
|
||||||
|
#let var = text(font: ("list-of", "non-existing-fonts"))[don't]
|
||||||
|
#var
|
||||||
|
Loading…
x
Reference in New Issue
Block a user