mirror of
https://github.com/typst/typst
synced 2025-05-14 17:15:28 +08:00
Disallow empty font lists (#6049)
This commit is contained in:
parent
417f5846b6
commit
ed2106e28d
@ -42,7 +42,7 @@ use ttf_parser::Tag;
|
|||||||
use typst_syntax::Spanned;
|
use typst_syntax::Spanned;
|
||||||
use typst_utils::singleton;
|
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::engine::Engine;
|
||||||
use crate::foundations::{
|
use crate::foundations::{
|
||||||
cast, dict, elem, Args, Array, Cast, Construct, Content, Dict, Fold, IntoValue,
|
cast, dict, elem, Args, Array, Cast, Construct, Content, Dict, Fold, IntoValue,
|
||||||
@ -891,9 +891,21 @@ cast! {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Font family fallback list.
|
/// Font family fallback list.
|
||||||
|
///
|
||||||
|
/// Must contain at least one font.
|
||||||
#[derive(Debug, Default, Clone, PartialEq, Hash)]
|
#[derive(Debug, Default, Clone, PartialEq, Hash)]
|
||||||
pub struct FontList(pub Vec<FontFamily>);
|
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 {
|
impl<'a> IntoIterator for &'a FontList {
|
||||||
type IntoIter = std::slice::Iter<'a, FontFamily>;
|
type IntoIter = std::slice::Iter<'a, FontFamily>;
|
||||||
type Item = &'a FontFamily;
|
type Item = &'a FontFamily;
|
||||||
@ -911,7 +923,7 @@ cast! {
|
|||||||
self.0.into_value()
|
self.0.into_value()
|
||||||
},
|
},
|
||||||
family: FontFamily => Self(vec![family]),
|
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.
|
/// Resolve a prioritized iterator over the font families.
|
||||||
|
@ -149,3 +149,7 @@ The number 123.
|
|||||||
#set text(-1pt)
|
#set text(-1pt)
|
||||||
|
|
||||||
a
|
a
|
||||||
|
|
||||||
|
--- empty-text-font-array ---
|
||||||
|
// Error: 17-19 font fallback list must not be empty
|
||||||
|
#set text(font: ())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user