diff options
| author | Laurenz <laurmaedje@gmail.com> | 2022-09-20 19:49:47 +0200 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2022-09-20 19:49:47 +0200 |
| commit | 3760748fddd3b793c79c370398a9d4a3fc5afc04 (patch) | |
| tree | b1a615e510aa231cfe9757a9c0a35a375e32e3ba /src/library/text | |
| parent | 757a701c1aa2a6fb80033c7e75666661818da6f9 (diff) | |
Refactor error handling
Diffstat (limited to 'src/library/text')
| -rw-r--r-- | src/library/text/deco.rs | 4 | ||||
| -rw-r--r-- | src/library/text/link.rs | 6 | ||||
| -rw-r--r-- | src/library/text/mod.rs | 18 | ||||
| -rw-r--r-- | src/library/text/par.rs | 14 | ||||
| -rw-r--r-- | src/library/text/raw.rs | 6 | ||||
| -rw-r--r-- | src/library/text/repeat.rs | 4 | ||||
| -rw-r--r-- | src/library/text/shaping.rs | 8 | ||||
| -rw-r--r-- | src/library/text/shift.rs | 6 |
8 files changed, 33 insertions, 33 deletions
diff --git a/src/library/text/deco.rs b/src/library/text/deco.rs index c58148b4..3d030d45 100644 --- a/src/library/text/deco.rs +++ b/src/library/text/deco.rs @@ -34,7 +34,7 @@ impl<const L: DecoLine> DecoNode<L> { /// with the glyphs. Does not apply to strikethrough. pub const EVADE: bool = true; - fn construct(_: &mut Vm, args: &mut Args) -> TypResult<Content> { + fn construct(_: &mut Vm, args: &mut Args) -> SourceResult<Content> { Ok(Content::show(Self(args.expect("body")?))) } } @@ -48,7 +48,7 @@ impl<const L: DecoLine> Show for DecoNode<L> { dict! { "body" => Value::Content(self.0.clone()) } } - fn realize(&self, _: &dyn World, styles: StyleChain) -> TypResult<Content> { + fn realize(&self, _: &dyn World, styles: StyleChain) -> SourceResult<Content> { Ok(self.0.clone().styled(TextNode::DECO, Decoration { line: L, stroke: styles.get(Self::STROKE).unwrap_or_default(), diff --git a/src/library/text/link.rs b/src/library/text/link.rs index 7d5c3109..f89bbd67 100644 --- a/src/library/text/link.rs +++ b/src/library/text/link.rs @@ -18,7 +18,7 @@ impl LinkNode { /// Whether to underline the link. pub const UNDERLINE: Smart<bool> = Smart::Auto; - fn construct(_: &mut Vm, args: &mut Args) -> TypResult<Content> { + fn construct(_: &mut Vm, args: &mut Args) -> SourceResult<Content> { Ok(Content::show({ let dest = args.expect::<Destination>("destination")?; let body = match dest { @@ -64,7 +64,7 @@ impl Show for LinkNode { } } - fn realize(&self, _: &dyn World, _: StyleChain) -> TypResult<Content> { + fn realize(&self, _: &dyn World, _: StyleChain) -> SourceResult<Content> { Ok(self.body.clone().unwrap_or_else(|| match &self.dest { Destination::Url(url) => { let mut text = url.as_str(); @@ -83,7 +83,7 @@ impl Show for LinkNode { _: &dyn World, styles: StyleChain, mut realized: Content, - ) -> TypResult<Content> { + ) -> SourceResult<Content> { let mut map = StyleMap::new(); map.set(TextNode::LINK, Some(self.dest.clone())); diff --git a/src/library/text/mod.rs b/src/library/text/mod.rs index be586874..55b866cb 100644 --- a/src/library/text/mod.rs +++ b/src/library/text/mod.rs @@ -128,7 +128,7 @@ impl TextNode { #[property(skip, fold)] pub const DECO: Decoration = vec![]; - fn construct(_: &mut Vm, args: &mut Args) -> TypResult<Content> { + fn construct(_: &mut Vm, args: &mut Args) -> SourceResult<Content> { // The text constructor is special: It doesn't create a text node. // Instead, it leaves the passed argument structurally unchanged, but // styles all text in it. @@ -422,17 +422,17 @@ impl Fold for Vec<(Tag, u32)> { } /// Convert a string or content to lowercase. -pub fn lower(_: &mut Vm, args: &mut Args) -> TypResult<Value> { +pub fn lower(_: &mut Vm, args: &mut Args) -> SourceResult<Value> { case(Case::Lower, args) } /// Convert a string or content to uppercase. -pub fn upper(_: &mut Vm, args: &mut Args) -> TypResult<Value> { +pub fn upper(_: &mut Vm, args: &mut Args) -> SourceResult<Value> { case(Case::Upper, args) } /// Change the case of text. -fn case(case: Case, args: &mut Args) -> TypResult<Value> { +fn case(case: Case, args: &mut Args) -> SourceResult<Value> { let Spanned { v, span } = args.expect("string or content")?; Ok(match v { Value::Str(v) => Value::Str(case.apply(&v).into()), @@ -461,7 +461,7 @@ impl Case { } /// Display text in small capitals. -pub fn smallcaps(_: &mut Vm, args: &mut Args) -> TypResult<Value> { +pub fn smallcaps(_: &mut Vm, args: &mut Args) -> SourceResult<Value> { let body: Content = args.expect("content")?; Ok(Value::Content(body.styled(TextNode::SMALLCAPS, true))) } @@ -493,7 +493,7 @@ pub struct StrongNode(pub Content); #[node(showable)] impl StrongNode { - fn construct(_: &mut Vm, args: &mut Args) -> TypResult<Content> { + fn construct(_: &mut Vm, args: &mut Args) -> SourceResult<Content> { Ok(Content::show(Self(args.expect("body")?))) } } @@ -507,7 +507,7 @@ impl Show for StrongNode { dict! { "body" => Value::Content(self.0.clone()) } } - fn realize(&self, _: &dyn World, _: StyleChain) -> TypResult<Content> { + fn realize(&self, _: &dyn World, _: StyleChain) -> SourceResult<Content> { Ok(self.0.clone().styled(TextNode::BOLD, Toggle)) } } @@ -518,7 +518,7 @@ pub struct EmphNode(pub Content); #[node(showable)] impl EmphNode { - fn construct(_: &mut Vm, args: &mut Args) -> TypResult<Content> { + fn construct(_: &mut Vm, args: &mut Args) -> SourceResult<Content> { Ok(Content::show(Self(args.expect("body")?))) } } @@ -532,7 +532,7 @@ impl Show for EmphNode { dict! { "body" => Value::Content(self.0.clone()) } } - fn realize(&self, _: &dyn World, _: StyleChain) -> TypResult<Content> { + fn realize(&self, _: &dyn World, _: StyleChain) -> SourceResult<Content> { Ok(self.0.clone().styled(TextNode::ITALIC, Toggle)) } } diff --git a/src/library/text/par.rs b/src/library/text/par.rs index e8282ef1..00a1e034 100644 --- a/src/library/text/par.rs +++ b/src/library/text/par.rs @@ -49,7 +49,7 @@ impl ParNode { #[property(resolve)] pub const LINEBREAKS: Smart<Linebreaks> = Smart::Auto; - fn construct(_: &mut Vm, args: &mut Args) -> TypResult<Content> { + fn construct(_: &mut Vm, args: &mut Args) -> SourceResult<Content> { // The paragraph constructor is special: It doesn't create a paragraph // node. Instead, it just ensures that the passed content lives is in a // separate paragraph and styles it. @@ -67,7 +67,7 @@ impl Layout for ParNode { world: &dyn World, regions: &Regions, styles: StyleChain, - ) -> TypResult<Vec<Frame>> { + ) -> SourceResult<Vec<Frame>> { // Collect all text into one string for BiDi analysis. let (text, segments) = collect(self, &styles); @@ -170,7 +170,7 @@ pub struct ParbreakNode; #[node] impl ParbreakNode { - fn construct(_: &mut Vm, _: &mut Args) -> TypResult<Content> { + fn construct(_: &mut Vm, _: &mut Args) -> SourceResult<Content> { Ok(Content::Parbreak) } } @@ -180,7 +180,7 @@ pub struct LinebreakNode; #[node] impl LinebreakNode { - fn construct(_: &mut Vm, args: &mut Args) -> TypResult<Content> { + fn construct(_: &mut Vm, args: &mut Args) -> SourceResult<Content> { let justified = args.named("justified")?.unwrap_or(false); Ok(Content::Linebreak { justified }) } @@ -502,7 +502,7 @@ fn prepare<'a>( segments: Vec<(Segment<'a>, StyleChain<'a>)>, regions: &Regions, styles: StyleChain<'a>, -) -> TypResult<Preparation<'a>> { +) -> SourceResult<Preparation<'a>> { let bidi = BidiInfo::new(&text, match styles.get(TextNode::DIR) { Dir::LTR => Some(Level::ltr()), Dir::RTL => Some(Level::rtl()), @@ -1025,7 +1025,7 @@ fn stack( world: &dyn World, lines: &[Line], regions: &Regions, -) -> TypResult<Vec<Frame>> { +) -> SourceResult<Vec<Frame>> { // Determine the paragraph's width: Full width of the region if we // should expand or there's fractional spacing, fit-to-width otherwise. let mut width = regions.first.x; @@ -1076,7 +1076,7 @@ fn commit( line: &Line, regions: &Regions, width: Length, -) -> TypResult<Frame> { +) -> SourceResult<Frame> { let mut remaining = width - line.width; let mut offset = Length::zero(); diff --git a/src/library/text/raw.rs b/src/library/text/raw.rs index c729fa40..5bce2a90 100644 --- a/src/library/text/raw.rs +++ b/src/library/text/raw.rs @@ -35,7 +35,7 @@ impl RawNode { #[property(resolve, shorthand(around))] pub const BELOW: Option<BlockSpacing> = Some(Ratio::one().into()); - fn construct(_: &mut Vm, args: &mut Args) -> TypResult<Content> { + fn construct(_: &mut Vm, args: &mut Args) -> SourceResult<Content> { Ok(Content::show(Self { text: args.expect("text")?, block: args.named("block")?.unwrap_or(false), @@ -59,7 +59,7 @@ impl Show for RawNode { } } - fn realize(&self, _: &dyn World, styles: StyleChain) -> TypResult<Content> { + fn realize(&self, _: &dyn World, styles: StyleChain) -> SourceResult<Content> { let lang = styles.get(Self::LANG).as_ref().map(|s| s.to_lowercase()); let foreground = THEME .settings @@ -114,7 +114,7 @@ impl Show for RawNode { _: &dyn World, styles: StyleChain, mut realized: Content, - ) -> TypResult<Content> { + ) -> SourceResult<Content> { let mut map = StyleMap::new(); map.set_family(styles.get(Self::FAMILY).clone(), styles); map.set(TextNode::OVERHANG, false); diff --git a/src/library/text/repeat.rs b/src/library/text/repeat.rs index c2a0de70..78a21069 100644 --- a/src/library/text/repeat.rs +++ b/src/library/text/repeat.rs @@ -6,7 +6,7 @@ pub struct RepeatNode(pub LayoutNode); #[node] impl RepeatNode { - fn construct(_: &mut Vm, args: &mut Args) -> TypResult<Content> { + fn construct(_: &mut Vm, args: &mut Args) -> SourceResult<Content> { Ok(Content::inline(Self(args.expect("body")?))) } } @@ -17,7 +17,7 @@ impl Layout for RepeatNode { world: &dyn World, regions: &Regions, styles: StyleChain, - ) -> TypResult<Vec<Frame>> { + ) -> SourceResult<Vec<Frame>> { // The actual repeating happens directly in the paragraph. self.0.layout(world, regions, styles) } diff --git a/src/library/text/shaping.rs b/src/library/text/shaping.rs index 6e505702..c1d0341b 100644 --- a/src/library/text/shaping.rs +++ b/src/library/text/shaping.rs @@ -165,7 +165,7 @@ impl<'a> ShapedText<'a> { if let Some(font) = world .book() .select(family, self.variant) - .and_then(|id| world.font(id).ok()) + .and_then(|id| world.font(id)) { expand(&font); break; @@ -223,7 +223,7 @@ impl<'a> ShapedText<'a> { let font = world .book() .select(family, self.variant) - .and_then(|id| world.font(id).ok())?; + .and_then(|id| world.font(id))?; let ttf = font.ttf(); let glyph_id = ttf.glyph_index('-')?; let x_advance = font.to_em(ttf.glyph_hor_advance(glyph_id)?); @@ -371,7 +371,7 @@ fn shape_segment<'a>( let book = ctx.world.book(); let mut selection = families.find_map(|family| { book.select(family, ctx.variant) - .and_then(|id| ctx.world.font(id).ok()) + .and_then(|id| ctx.world.font(id)) .filter(|font| !ctx.used.contains(font)) }); @@ -380,7 +380,7 @@ fn shape_segment<'a>( let first = ctx.used.first().map(Font::info); selection = book .select_fallback(first, ctx.variant, text) - .and_then(|id| ctx.world.font(id).ok()) + .and_then(|id| ctx.world.font(id)) .filter(|font| !ctx.used.contains(font)); } diff --git a/src/library/text/shift.rs b/src/library/text/shift.rs index 5da36da1..b359c5ed 100644 --- a/src/library/text/shift.rs +++ b/src/library/text/shift.rs @@ -28,7 +28,7 @@ impl<const S: ScriptKind> ShiftNode<S> { /// The font size for synthetic sub- and superscripts. pub const SIZE: TextSize = TextSize(Em::new(0.6).into()); - fn construct(_: &mut Vm, args: &mut Args) -> TypResult<Content> { + fn construct(_: &mut Vm, args: &mut Args) -> SourceResult<Content> { Ok(Content::show(Self(args.expect("body")?))) } } @@ -42,7 +42,7 @@ impl<const S: ScriptKind> Show for ShiftNode<S> { dict! { "body" => Value::Content(self.0.clone()) } } - fn realize(&self, world: &dyn World, styles: StyleChain) -> TypResult<Content> { + fn realize(&self, world: &dyn World, styles: StyleChain) -> SourceResult<Content> { let mut transformed = None; if styles.get(Self::TYPOGRAPHIC) { if let Some(text) = search_text(&self.0, S) { @@ -96,7 +96,7 @@ fn is_shapable(world: &dyn World, text: &str, styles: StyleChain) -> bool { if let Some(font) = world .book() .select(family.as_str(), variant(styles)) - .and_then(|id| world.font(id).ok()) + .and_then(|id| world.font(id)) { return text.chars().all(|c| font.ttf().glyph_index(c).is_some()); } |
