summaryrefslogtreecommitdiff
path: root/crates/typst-library/src
diff options
context:
space:
mode:
authorMalo <57839069+MDLC01@users.noreply.github.com>2025-04-02 13:47:42 +0200
committerGitHub <noreply@github.com>2025-04-02 11:47:42 +0000
commited2106e28d4b0cc213a4789d5e59c59ad08e9f29 (patch)
tree43d4da75aa1c0bc255078da68bd99bcaf4068e58 /crates/typst-library/src
parent417f5846b68777b8a4d3b9336761bd23c48a26b5 (diff)
Disallow empty font lists (#6049)
Diffstat (limited to 'crates/typst-library/src')
-rw-r--r--crates/typst-library/src/text/mod.rs16
1 files changed, 14 insertions, 2 deletions
diff --git a/crates/typst-library/src/text/mod.rs b/crates/typst-library/src/text/mod.rs
index 3aac15ba..462d1606 100644
--- a/crates/typst-library/src/text/mod.rs
+++ b/crates/typst-library/src/text/mod.rs
@@ -42,7 +42,7 @@ use ttf_parser::Tag;
use typst_syntax::Spanned;
use typst_utils::singleton;
-use crate::diag::{bail, warning, HintedStrResult, SourceResult};
+use crate::diag::{bail, warning, HintedStrResult, SourceResult, StrResult};
use crate::engine::Engine;
use crate::foundations::{
cast, dict, elem, Args, Array, Cast, Construct, Content, Dict, Fold, IntoValue,
@@ -891,9 +891,21 @@ cast! {
}
/// Font family fallback list.
+///
+/// Must contain at least one font.
#[derive(Debug, Default, Clone, PartialEq, Hash)]
pub struct FontList(pub Vec<FontFamily>);
+impl FontList {
+ pub fn new(fonts: Vec<FontFamily>) -> StrResult<Self> {
+ if fonts.is_empty() {
+ bail!("font fallback list must not be empty")
+ } else {
+ Ok(Self(fonts))
+ }
+ }
+}
+
impl<'a> IntoIterator for &'a FontList {
type IntoIter = std::slice::Iter<'a, FontFamily>;
type Item = &'a FontFamily;
@@ -911,7 +923,7 @@ cast! {
self.0.into_value()
},
family: FontFamily => Self(vec![family]),
- values: Array => Self(values.into_iter().map(|v| v.cast()).collect::<HintedStrResult<_>>()?),
+ values: Array => Self::new(values.into_iter().map(|v| v.cast()).collect::<HintedStrResult<_>>()?)?,
}
/// Resolve a prioritized iterator over the font families.