diff options
| author | Laurenz <laurmaedje@gmail.com> | 2020-12-17 15:43:30 +0100 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2020-12-17 15:43:30 +0100 |
| commit | 6f111f941008f10ddc06e6f56da9e3582e90d2c4 (patch) | |
| tree | 0ee44f6c9d88353320893522cf14931863ddf742 /src | |
| parent | 7e91c8dc87e345ee38b934375d113e824a423a2b (diff) | |
Test [font] 🧣
Diffstat (limited to 'src')
| -rw-r--r-- | src/env.rs | 4 | ||||
| -rw-r--r-- | src/export/pdf.rs | 6 | ||||
| -rw-r--r-- | src/library/layout.rs | 20 | ||||
| -rw-r--r-- | src/library/style.rs | 18 | ||||
| -rw-r--r-- | src/shaping.rs | 4 |
5 files changed, 26 insertions, 26 deletions
@@ -60,7 +60,7 @@ impl ResourceLoader { } }; - Some((id, self.get_loaded(id))) + Some((id, self.loaded(id))) } /// Retrieve a previously loaded resource by its id. @@ -68,7 +68,7 @@ impl ResourceLoader { /// # Panics /// This panics if no resource with this id was loaded. #[track_caller] - pub fn get_loaded<R: 'static>(&self, id: ResourceId) -> &R { + pub fn loaded<R: 'static>(&self, id: ResourceId) -> &R { self.entries[id.0].downcast_ref().expect("bad resource type") } } diff --git a/src/export/pdf.rs b/src/export/pdf.rs index a9c94dc9..5a2aa0cc 100644 --- a/src/export/pdf.rs +++ b/src/export/pdf.rs @@ -51,7 +51,7 @@ impl<'a> PdfExporter<'a> { match element { LayoutElement::Text(shaped) => fonts.insert(shaped.face), LayoutElement::Image(image) => { - let img = env.resources.get_loaded::<ImageResource>(image.res); + let img = env.resources.loaded::<ImageResource>(image.res); if img.buf.color().has_alpha() { alpha_masks += 1; } @@ -181,7 +181,7 @@ impl<'a> PdfExporter<'a> { fn write_fonts(&mut self) { for (refs, face_id) in self.refs.fonts().zip(self.fonts.layout_indices()) { - let owned_face = self.env.fonts.get_loaded(face_id); + let owned_face = self.env.fonts.face(face_id); let face = owned_face.get(); let name = face @@ -292,7 +292,7 @@ impl<'a> PdfExporter<'a> { let mut masks_seen = 0; for (id, resource) in self.refs.images().zip(self.images.layout_indices()) { - let img = self.env.resources.get_loaded::<ImageResource>(resource); + let img = self.env.resources.loaded::<ImageResource>(resource); let (width, height) = img.buf.dimensions(); // Add the primary image. diff --git a/src/library/layout.rs b/src/library/layout.rs index 36a20821..23066fdc 100644 --- a/src/library/layout.rs +++ b/src/library/layout.rs @@ -21,10 +21,10 @@ use crate::prelude::*; pub fn align(mut args: Args, ctx: &mut EvalContext) -> Value { let snapshot = ctx.state.clone(); let body = args.find::<SynTree>(); - let first = args.get::<_, Spanned<AlignArg>>(ctx, 0); - let second = args.get::<_, Spanned<AlignArg>>(ctx, 1); - let hor = args.get::<_, Spanned<AlignArg>>(ctx, "horizontal"); - let ver = args.get::<_, Spanned<AlignArg>>(ctx, "vertical"); + let first = args.get::<_, Spanned<SpecAlign>>(ctx, 0); + let second = args.get::<_, Spanned<SpecAlign>>(ctx, 1); + let hor = args.get::<_, Spanned<SpecAlign>>(ctx, "horizontal"); + let ver = args.get::<_, Spanned<SpecAlign>>(ctx, "vertical"); args.done(ctx); let prev_main = ctx.state.align.main; @@ -58,7 +58,7 @@ pub fn align(mut args: Args, ctx: &mut EvalContext) -> Value { } else { // We don't know the axis: This has to be a `center` alignment for a // positional argument. - debug_assert_eq!(arg, AlignArg::Center); + debug_assert_eq!(arg, SpecAlign::Center); if had.main && had.cross { ctx.diag(error!(span, "duplicate alignment")); @@ -108,7 +108,7 @@ pub fn align(mut args: Args, ctx: &mut EvalContext) -> Value { /// An argument to `[align]`. #[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd)] -enum AlignArg { +enum SpecAlign { Left, Right, Top, @@ -116,7 +116,7 @@ enum AlignArg { Center, } -convert_ident!(AlignArg, "alignment", |v| match v { +convert_ident!(SpecAlign, "alignment", |v| match v { "left" => Some(Self::Left), "right" => Some(Self::Right), "top" => Some(Self::Top), @@ -125,7 +125,7 @@ convert_ident!(AlignArg, "alignment", |v| match v { _ => None, }); -impl AlignArg { +impl SpecAlign { /// The specific axis this alignment refers to. /// /// Returns `None` if this is `Center` since the axis is unknown. @@ -140,7 +140,7 @@ impl AlignArg { } } -impl Switch for AlignArg { +impl Switch for SpecAlign { type Other = Align; fn switch(self, flow: Flow) -> Self::Other { @@ -163,7 +163,7 @@ impl Switch for AlignArg { } } -impl Display for AlignArg { +impl Display for SpecAlign { fn fmt(&self, f: &mut Formatter) -> fmt::Result { f.pad(match self { Self::Left => "left", diff --git a/src/library/style.rs b/src/library/style.rs index 804e9424..c641a598 100644 --- a/src/library/style.rs +++ b/src/library/style.rs @@ -71,13 +71,6 @@ pub fn font(mut args: Args, ctx: &mut EvalContext) -> Value { } } - let mut needs_flattening = false; - let list: Vec<_> = args.find_all::<StringLike>().map(|s| s.to_lowercase()).collect(); - if !list.is_empty() { - Rc::make_mut(&mut ctx.state.font.families).list = list; - needs_flattening = true; - } - if let Some(style) = args.get::<_, FontStyle>(ctx, "style") { ctx.state.font.variant.style = style; } @@ -90,6 +83,13 @@ pub fn font(mut args: Args, ctx: &mut EvalContext) -> Value { ctx.state.font.variant.stretch = stretch; } + let mut needs_flattening = false; + let list: Vec<_> = args.find_all::<StringLike>().map(|s| s.to_lowercase()).collect(); + if !list.is_empty() { + Rc::make_mut(&mut ctx.state.font.families).list = list; + needs_flattening = true; + } + for (class, dict) in args.find_all_str::<Spanned<ValueDict>>() { let fallback = Args(dict) .find_all::<StringLike>() @@ -100,12 +100,12 @@ pub fn font(mut args: Args, ctx: &mut EvalContext) -> Value { needs_flattening = true; } - args.done(ctx); - if needs_flattening { Rc::make_mut(&mut ctx.state.font.families).flatten(); } + args.done(ctx); + if let Some(body) = body { body.eval(ctx); ctx.state = snapshot; diff --git a/src/shaping.rs b/src/shaping.rs index efc24d07..c42cd0ac 100644 --- a/src/shaping.rs +++ b/src/shaping.rs @@ -82,8 +82,8 @@ pub fn shape( for c in chars { let query = FaceQuery { fallback: fallback.iter(), variant, c }; - if let Some((id, owned_face)) = loader.query(query) { - let face = owned_face.get(); + if let Some(id) = loader.query(query) { + let face = loader.face(id).get(); let (glyph, width) = match lookup_glyph(face, c, font_size) { Some(v) => v, None => continue, |
