diff options
Diffstat (limited to 'src/library')
| -rw-r--r-- | src/library/font.rs | 26 | ||||
| -rw-r--r-- | src/library/image.rs | 11 | ||||
| -rw-r--r-- | src/library/mod.rs | 9 |
3 files changed, 29 insertions, 17 deletions
diff --git a/src/library/font.rs b/src/library/font.rs index 6afc617b..cf329567 100644 --- a/src/library/font.rs +++ b/src/library/font.rs @@ -1,5 +1,5 @@ +use crate::font::{FontStretch, FontStyle, FontWeight}; use crate::layout::Fill; -use fontdock::{FontStretch, FontStyle, FontWeight}; use super::*; @@ -156,7 +156,12 @@ typify! { FontWeight: "font weight", Value::Int(number) => { let [min, max] = [Self::THIN, Self::BLACK]; - let message = || format!("should be between {:#?} and {:#?}", min, max); + let message = || format!( + "should be between {} and {}", + min.to_number(), + max.to_number(), + ); + return if number < i64::from(min.to_number()) { CastResult::Warn(min, message()) } else if number > i64::from(max.to_number()) { @@ -170,11 +175,18 @@ typify! { typify! { FontStretch: "font stretch", Value::Relative(relative) => { - let f = |stretch: Self| Relative::new(stretch.to_ratio()); - let [min, max] = [f(Self::UltraCondensed), f(Self::UltraExpanded)]; - let value = Self::from_ratio(relative.get()); - return if relative < min || relative > max { - CastResult::Warn(value, format!("should be between {} and {}", min, max)) + let [min, max] = [Self::ULTRA_CONDENSED, Self::ULTRA_EXPANDED]; + let message = || format!( + "should be between {} and {}", + Relative::new(min.to_ratio() as f64), + Relative::new(max.to_ratio() as f64), + ); + + let ratio = relative.get() as f32; + let value = Self::from_ratio(ratio); + + return if ratio < min.to_ratio() || ratio > max.to_ratio() { + CastResult::Warn(value, message()) } else { CastResult::Ok(value) }; diff --git a/src/library/image.rs b/src/library/image.rs index 09b56336..134590bb 100644 --- a/src/library/image.rs +++ b/src/library/image.rs @@ -20,10 +20,11 @@ pub fn image(ctx: &mut EvalContext, args: &mut FuncArgs) -> Value { Value::template("image", move |ctx| { if let Some(path) = &path { - let loaded = ctx.env.resources.load(&path.v, ImageResource::parse); - if let Some((res, img)) = loaded { + let loaded = ctx.env.load_resource(&path.v, ImageResource::parse); + if let Some(id) = loaded { + let img = ctx.env.resource::<ImageResource>(id); let dimensions = img.buf.dimensions(); - ctx.push(ImageNode { res, dimensions, width, height }); + ctx.push(ImageNode { id, dimensions, width, height }); } else { ctx.diag(error!(path.span, "failed to load image")); } @@ -35,7 +36,7 @@ pub fn image(ctx: &mut EvalContext, args: &mut FuncArgs) -> Value { #[derive(Debug, Clone, PartialEq)] struct ImageNode { /// The resource id of the image file. - res: ResourceId, + id: ResourceId, /// The pixel dimensions of the image. dimensions: (u32, u32), /// The fixed width, if any. @@ -74,7 +75,7 @@ impl Layout for ImageNode { }; let mut frame = Frame::new(size, size.height); - frame.push(Point::ZERO, Element::Image(Image { res: self.res, size })); + frame.push(Point::ZERO, Element::Image(Image { id: self.id, size })); vec![frame] } diff --git a/src/library/mod.rs b/src/library/mod.rs index 738348ee..5018f0b4 100644 --- a/src/library/mod.rs +++ b/src/library/mod.rs @@ -29,12 +29,11 @@ pub use spacing::*; use std::fmt::{self, Display, Formatter}; -use fontdock::{FontStyle, FontWeight}; - -use crate::eval::{AnyValue, FuncValue, Scope}; -use crate::eval::{EvalContext, FuncArgs, TemplateValue, Value}; +use crate::eval::{ + AnyValue, EvalContext, FuncArgs, FuncValue, Scope, TemplateValue, Value, +}; use crate::exec::{Exec, FontFamily}; -use crate::font::VerticalFontMetric; +use crate::font::{FontStyle, FontWeight, VerticalFontMetric}; use crate::geom::*; use crate::syntax::{Node, Spanned}; |
