mirror of
https://github.com/typst/typst
synced 2025-05-17 02:25:27 +08:00
Go from String
to &str
when passing font names to SVG code (#4500)
This commit is contained in:
parent
3b32aa7929
commit
b847cccba4
@ -196,7 +196,7 @@ fn layout_image(
|
|||||||
format,
|
format,
|
||||||
elem.alt(styles),
|
elem.alt(styles),
|
||||||
engine.world,
|
engine.world,
|
||||||
&families(styles).map(|s| s.into()).collect::<Vec<_>>(),
|
&families(styles).collect::<Vec<_>>(),
|
||||||
)
|
)
|
||||||
.at(span)?;
|
.at(span)?;
|
||||||
|
|
||||||
@ -360,7 +360,7 @@ impl Image {
|
|||||||
format: ImageFormat,
|
format: ImageFormat,
|
||||||
alt: Option<EcoString>,
|
alt: Option<EcoString>,
|
||||||
world: Tracked<dyn World + '_>,
|
world: Tracked<dyn World + '_>,
|
||||||
families: &[String],
|
families: &[&str],
|
||||||
) -> StrResult<Image> {
|
) -> StrResult<Image> {
|
||||||
let kind = match format {
|
let kind = match format {
|
||||||
ImageFormat::Raster(format) => {
|
ImageFormat::Raster(format) => {
|
||||||
|
@ -40,7 +40,7 @@ impl SvgImage {
|
|||||||
pub fn with_fonts(
|
pub fn with_fonts(
|
||||||
data: Bytes,
|
data: Bytes,
|
||||||
world: Tracked<dyn World + '_>,
|
world: Tracked<dyn World + '_>,
|
||||||
families: &[String],
|
families: &[&str],
|
||||||
) -> StrResult<SvgImage> {
|
) -> StrResult<SvgImage> {
|
||||||
let book = world.book();
|
let book = world.book();
|
||||||
let resolver = Mutex::new(FontResolver::new(world, book, families));
|
let resolver = Mutex::new(FontResolver::new(world, book, families));
|
||||||
@ -142,7 +142,7 @@ struct FontResolver<'a> {
|
|||||||
/// The world we use to load fonts.
|
/// The world we use to load fonts.
|
||||||
world: Tracked<'a, dyn World + 'a>,
|
world: Tracked<'a, dyn World + 'a>,
|
||||||
/// The active list of font families at the location of the SVG.
|
/// The active list of font families at the location of the SVG.
|
||||||
families: &'a [String],
|
families: &'a [&'a str],
|
||||||
/// A mapping from Typst font indices to fontdb IDs.
|
/// A mapping from Typst font indices to fontdb IDs.
|
||||||
to_id: HashMap<usize, Option<fontdb::ID>>,
|
to_id: HashMap<usize, Option<fontdb::ID>>,
|
||||||
/// The reverse mapping.
|
/// The reverse mapping.
|
||||||
@ -156,7 +156,7 @@ impl<'a> FontResolver<'a> {
|
|||||||
fn new(
|
fn new(
|
||||||
world: Tracked<'a, dyn World + 'a>,
|
world: Tracked<'a, dyn World + 'a>,
|
||||||
book: &'a FontBook,
|
book: &'a FontBook,
|
||||||
families: &'a [String],
|
families: &'a [&'a str],
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self {
|
Self {
|
||||||
book,
|
book,
|
||||||
@ -191,11 +191,11 @@ impl FontResolver<'_> {
|
|||||||
font.families()
|
font.families()
|
||||||
.iter()
|
.iter()
|
||||||
.filter_map(|family| match family {
|
.filter_map(|family| match family {
|
||||||
usvg::FontFamily::Named(named) => Some(named),
|
usvg::FontFamily::Named(named) => Some(named.as_str()),
|
||||||
// We don't support generic families at the moment.
|
// We don't support generic families at the moment.
|
||||||
_ => None,
|
_ => None,
|
||||||
})
|
})
|
||||||
.chain(self.families)
|
.chain(self.families.iter().copied())
|
||||||
.filter_map(|named| self.book.select(&named.to_lowercase(), variant))
|
.filter_map(|named| self.book.select(&named.to_lowercase(), variant))
|
||||||
.find_map(|index| self.get_or_load(index, db))
|
.find_map(|index| self.get_or_load(index, db))
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user