From 83b68581461df8968e408bec1b979ed2e3a8f0c5 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Sun, 22 Jan 2023 13:26:42 +0100 Subject: Math framework --- src/doc.rs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'src/doc.rs') diff --git a/src/doc.rs b/src/doc.rs index 9e98ec88..d4ad2d93 100644 --- a/src/doc.rs +++ b/src/doc.rs @@ -7,7 +7,8 @@ use std::sync::Arc; use crate::font::Font; use crate::geom::{ - Abs, Align, Axes, Dir, Em, Numeric, Paint, Point, Shape, Size, Transform, + self, Abs, Align, Axes, Color, Dir, Em, Geometry, Numeric, Paint, Point, RgbaColor, + Shape, Size, Stroke, Transform, }; use crate::image::Image; use crate::model::{ @@ -160,7 +161,7 @@ impl Frame { self.size.y } - /// The baseline of the frame. + /// The vertical position of the frame's baseline. pub fn baseline(&self) -> Abs { self.baseline.unwrap_or(self.size.y) } @@ -170,6 +171,19 @@ impl Frame { self.baseline = Some(baseline); } + /// The distance from the baseline to the top of the frame. + /// + /// This is the same as `baseline()`, but more in line with the terminology + /// used in math layout. + pub fn ascent(&self) -> Abs { + self.baseline() + } + + /// The distance from the baseline to the bottom of the frame. + pub fn descent(&self) -> Abs { + self.size.y - self.baseline() + } + /// An iterator over the elements inside this frame alongside their /// positions relative to the top-left of the frame. pub fn elements(&self) -> std::slice::Iter<'_, (Point, Element)> { -- cgit v1.2.3