summaryrefslogtreecommitdiff
path: root/src/library
diff options
context:
space:
mode:
Diffstat (limited to 'src/library')
-rw-r--r--src/library/graphics/line.rs16
-rw-r--r--src/library/graphics/shape.rs10
-rw-r--r--src/library/graphics/transform.rs4
-rw-r--r--src/library/layout/columns.rs2
-rw-r--r--src/library/layout/flow.rs14
-rw-r--r--src/library/layout/grid.rs82
-rw-r--r--src/library/layout/pad.rs6
-rw-r--r--src/library/layout/page.rs10
-rw-r--r--src/library/layout/spacing.rs20
-rw-r--r--src/library/layout/stack.rs24
-rw-r--r--src/library/mod.rs8
-rw-r--r--src/library/structure/heading.rs2
-rw-r--r--src/library/structure/list.rs12
-rw-r--r--src/library/structure/table.rs4
-rw-r--r--src/library/text/deco.rs12
-rw-r--r--src/library/text/mod.rs22
-rw-r--r--src/library/text/par.rs16
-rw-r--r--src/library/utility/color.rs8
-rw-r--r--src/library/utility/math.rs8
19 files changed, 142 insertions, 138 deletions
diff --git a/src/library/graphics/line.rs b/src/library/graphics/line.rs
index a650c76c..1ca25bd9 100644
--- a/src/library/graphics/line.rs
+++ b/src/library/graphics/line.rs
@@ -3,24 +3,24 @@ use crate::library::prelude::*;
/// Display a line without affecting the layout.
#[derive(Debug, Hash)]
pub struct LineNode {
- origin: Spec<Linear>,
- delta: Spec<Linear>,
+ origin: Spec<Relative>,
+ delta: Spec<Relative>,
}
#[node]
impl LineNode {
- /// How the stroke the line.
+ /// How to stroke the line.
pub const STROKE: Paint = Color::BLACK.into();
/// The line's thickness.
pub const THICKNESS: Length = Length::pt(1.0);
fn construct(_: &mut Context, args: &mut Args) -> TypResult<Content> {
- let origin = args.named::<Spec<Linear>>("origin")?.unwrap_or_default();
- let delta = match args.named::<Spec<Linear>>("to")? {
+ let origin = args.named::<Spec<Relative>>("origin")?.unwrap_or_default();
+ let delta = match args.named::<Spec<Relative>>("to")? {
Some(to) => to.zip(origin).map(|(to, from)| to - from),
None => {
let length =
- args.named::<Linear>("length")?.unwrap_or(Length::cm(1.0).into());
+ args.named::<Relative>("length")?.unwrap_or(Length::cm(1.0).into());
let angle = args.named::<Angle>("angle")?.unwrap_or_default();
let x = angle.cos() * length;
@@ -48,9 +48,9 @@ impl Layout for LineNode {
});
let resolved_origin =
- self.origin.zip(regions.base).map(|(l, b)| Linear::resolve(l, b));
+ self.origin.zip(regions.base).map(|(l, b)| Relative::resolve(l, b));
let resolved_delta =
- self.delta.zip(regions.base).map(|(l, b)| Linear::resolve(l, b));
+ self.delta.zip(regions.base).map(|(l, b)| Relative::resolve(l, b));
let geometry = Geometry::Line(resolved_delta.to_point());
let shape = Shape { geometry, fill: None, stroke };
diff --git a/src/library/graphics/shape.rs b/src/library/graphics/shape.rs
index 177f466e..3f338d1a 100644
--- a/src/library/graphics/shape.rs
+++ b/src/library/graphics/shape.rs
@@ -23,17 +23,17 @@ pub type EllipseNode = ShapeNode<ELLIPSE>;
impl<const S: ShapeKind> ShapeNode<S> {
/// How to fill the shape.
pub const FILL: Option<Paint> = None;
- /// How the stroke the shape.
+ /// How to stroke the shape.
pub const STROKE: Smart<Option<Paint>> = Smart::Auto;
/// The stroke's thickness.
pub const THICKNESS: Length = Length::pt(1.0);
/// How much to pad the shape's content.
- pub const PADDING: Linear = Linear::zero();
+ pub const PADDING: Relative = Relative::zero();
fn construct(_: &mut Context, args: &mut Args) -> TypResult<Content> {
let size = match S {
- SQUARE => args.named::<Length>("size")?.map(Linear::from),
- CIRCLE => args.named::<Length>("radius")?.map(|r| 2.0 * Linear::from(r)),
+ SQUARE => args.named::<Length>("size")?.map(Relative::from),
+ CIRCLE => args.named::<Length>("radius")?.map(|r| 2.0 * Relative::from(r)),
_ => None,
};
@@ -64,7 +64,7 @@ impl<const S: ShapeKind> Layout for ShapeNode<S> {
if let Some(child) = &self.0 {
let mut padding = styles.get(Self::PADDING);
if is_round(S) {
- padding.rel += Relative::new(0.5 - SQRT_2 / 4.0);
+ padding.rel += Ratio::new(0.5 - SQRT_2 / 4.0);
}
// Pad the child.
diff --git a/src/library/graphics/transform.rs b/src/library/graphics/transform.rs
index 0dc50166..1ce91f28 100644
--- a/src/library/graphics/transform.rs
+++ b/src/library/graphics/transform.rs
@@ -37,8 +37,8 @@ impl<const T: TransformKind> TransformNode<T> {
}
SCALE | _ => {
let all = args.find()?;
- let sx = args.named("x")?.or(all).unwrap_or(Relative::one());
- let sy = args.named("y")?.or(all).unwrap_or(Relative::one());
+ let sx = args.named("x")?.or(all).unwrap_or(Ratio::one());
+ let sy = args.named("y")?.or(all).unwrap_or(Ratio::one());
Transform::scale(sx, sy)
}
};
diff --git a/src/library/layout/columns.rs b/src/library/layout/columns.rs
index b5ec7de9..56e55d57 100644
--- a/src/library/layout/columns.rs
+++ b/src/library/layout/columns.rs
@@ -14,7 +14,7 @@ pub struct ColumnsNode {
#[node]
impl ColumnsNode {
/// The size of the gutter space between each column.
- pub const GUTTER: Linear = Relative::new(0.04).into();
+ pub const GUTTER: Relative = Ratio::new(0.04).into();
fn construct(_: &mut Context, args: &mut Args) -> TypResult<Content> {
Ok(Content::block(Self {
diff --git a/src/library/layout/flow.rs b/src/library/layout/flow.rs
index 9f398277..ffda6925 100644
--- a/src/library/layout/flow.rs
+++ b/src/library/layout/flow.rs
@@ -100,8 +100,8 @@ pub struct FlowLayouter {
full: Size,
/// The size used by the frames for the current region.
used: Size,
- /// The sum of fractional ratios in the current region.
- fr: Fractional,
+ /// The sum of fractions in the current region.
+ fr: Fraction,
/// Spacing and layouted nodes.
items: Vec<FlowItem>,
/// Finished frames for previous regions.
@@ -113,7 +113,7 @@ enum FlowItem {
/// Absolute spacing between other items.
Absolute(Length),
/// Fractional spacing between other items.
- Fractional(Fractional),
+ Fractional(Fraction),
/// A frame for a layouted child node and how to align it.
Frame(Arc<Frame>, Spec<Align>),
/// An absolutely placed frame.
@@ -135,7 +135,7 @@ impl FlowLayouter {
expand,
full,
used: Size::zero(),
- fr: Fractional::zero(),
+ fr: Fraction::zero(),
items: vec![],
finished: vec![],
}
@@ -144,8 +144,8 @@ impl FlowLayouter {
/// Layout spacing.
pub fn layout_spacing(&mut self, spacing: Spacing) {
match spacing {
- Spacing::Linear(v) => {
- // Resolve the linear and limit it to the remaining space.
+ Spacing::Relative(v) => {
+ // Resolve the spacing and limit it to the remaining space.
let resolved = v.resolve(self.full.y);
let limited = resolved.min(self.regions.first.y);
self.regions.first.y -= limited;
@@ -254,7 +254,7 @@ impl FlowLayouter {
self.regions.next();
self.full = self.regions.first;
self.used = Size::zero();
- self.fr = Fractional::zero();
+ self.fr = Fraction::zero();
self.finished.push(Arc::new(output));
}
diff --git a/src/library/layout/grid.rs b/src/library/layout/grid.rs
index 716ac853..ee485bd2 100644
--- a/src/library/layout/grid.rs
+++ b/src/library/layout/grid.rs
@@ -54,22 +54,24 @@ impl Layout for GridNode {
/// Defines how to size a grid cell along an axis.
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
pub enum TrackSizing {
- /// Fit the cell to its contents.
+ /// A track that fits its cell's contents.
Auto,
- /// A length stated in absolute values and/or relative to the parent's size.
- Linear(Linear),
- /// A length that is the fraction of the remaining free space in the parent.
- Fractional(Fractional),
+ /// A track size specified in absolute terms and relative to the parent's
+ /// size.
+ Relative(Relative),
+ /// A track size specified as a fraction of the remaining free space in the
+ /// parent.
+ Fractional(Fraction),
}
castable! {
Vec<TrackSizing>,
- Expected: "integer or (auto, linear, fractional, or array thereof)",
+ Expected: "integer, auto, relative length, fraction, or array of the latter three)",
Value::Auto => vec![TrackSizing::Auto],
- Value::Length(v) => vec![TrackSizing::Linear(v.into())],
- Value::Relative(v) => vec![TrackSizing::Linear(v.into())],
- Value::Linear(v) => vec![TrackSizing::Linear(v)],
- Value::Fractional(v) => vec![TrackSizing::Fractional(v)],
+ Value::Length(v) => vec![TrackSizing::Relative(v.into())],
+ Value::Ratio(v) => vec![TrackSizing::Relative(v.into())],
+ Value::Relative(v) => vec![TrackSizing::Relative(v)],
+ Value::Fraction(v) => vec![TrackSizing::Fractional(v)],
Value::Int(v) => vec![TrackSizing::Auto; Value::Int(v).cast::<NonZeroUsize>()?.get()],
Value::Array(values) => values
.into_iter()
@@ -79,12 +81,12 @@ castable! {
castable! {
TrackSizing,
- Expected: "auto, linear, or fractional",
+ Expected: "auto, relative length, or fraction",
Value::Auto => Self::Auto,
- Value::Length(v) => Self::Linear(v.into()),
- Value::Relative(v) => Self::Linear(v.into()),
- Value::Linear(v) => Self::Linear(v),
- Value::Fractional(v) => Self::Fractional(v),
+ Value::Length(v) => Self::Relative(v.into()),
+ Value::Ratio(v) => Self::Relative(v.into()),
+ Value::Relative(v) => Self::Relative(v),
+ Value::Fraction(v) => Self::Fractional(v),
}
/// Performs grid layout.
@@ -108,19 +110,19 @@ pub struct GridLayouter<'a> {
/// The used-up size of the current region. The horizontal size is
/// determined once after columns are resolved and not touched again.
used: Size,
- /// The sum of fractional ratios in the current region.
- fr: Fractional,
+ /// The sum of fractions in the current region.
+ fr: Fraction,
/// Frames for finished regions.
finished: Vec<Arc<Frame>>,
}
-/// Produced by initial row layout, auto and linear rows are already finished,
+/// Produced by initial row layout, auto and relative rows are already finished,
/// fractional rows not yet.
enum Row {
- /// Finished row frame of auto or linear row.
+ /// Finished row frame of auto or relative row.
Frame(Frame),
- /// Ratio of a fractional row and y index of the track.
- Fr(Fractional, usize),
+ /// Fractional row with y index.
+ Fr(Fraction, usize),
}
impl<'a> GridLayouter<'a> {
@@ -150,7 +152,7 @@ impl<'a> GridLayouter<'a> {
};
let auto = TrackSizing::Auto;
- let zero = TrackSizing::Linear(Linear::zero());
+ let zero = TrackSizing::Relative(Relative::zero());
let get_or = |tracks: &[_], idx, default| {
tracks.get(idx).or(tracks.last()).copied().unwrap_or(default)
};
@@ -190,7 +192,7 @@ impl<'a> GridLayouter<'a> {
lrows,
full,
used: Size::zero(),
- fr: Fractional::zero(),
+ fr: Fraction::zero(),
finished: vec![],
}
}
@@ -208,7 +210,7 @@ impl<'a> GridLayouter<'a> {
match self.rows[y] {
TrackSizing::Auto => self.layout_auto_row(ctx, y)?,
- TrackSizing::Linear(v) => self.layout_linear_row(ctx, v, y)?,
+ TrackSizing::Relative(v) => self.layout_relative_row(ctx, v, y)?,
TrackSizing::Fractional(v) => {
self.lrows.push(Row::Fr(v, y));
self.fr += v;
@@ -222,28 +224,28 @@ impl<'a> GridLayouter<'a> {
/// Determine all column sizes.
fn measure_columns(&mut self, ctx: &mut Context) -> TypResult<()> {
- // Sum of sizes of resolved linear tracks.
- let mut linear = Length::zero();
+ // Sum of sizes of resolved relative tracks.
+ let mut rel = Length::zero();
// Sum of fractions of all fractional tracks.
- let mut fr = Fractional::zero();
+ let mut fr = Fraction::zero();
- // Resolve the size of all linear columns and compute the sum of all
+ // Resolve the size of all relative columns and compute the sum of all
// fractional tracks.
for (&col, rcol) in self.cols.iter().zip(&mut self.rcols) {
match col {
TrackSizing::Auto => {}
- TrackSizing::Linear(v) => {
+ TrackSizing::Relative(v) => {
let resolved = v.resolve(self.regions.base.x);
*rcol = resolved;
- linear += resolved;
+ rel += resolved;
}
TrackSizing::Fractional(v) => fr += v,
}
}
// Size that is not used by fixed-size columns.
- let available = self.regions.first.x - linear;
+ let available = self.regions.first.x - rel;
if available >= Length::zero() {
// Determine size of auto columns.
let (auto, count) = self.measure_auto_columns(ctx, available)?;
@@ -289,10 +291,10 @@ impl<'a> GridLayouter<'a> {
let mut pod =
Regions::one(size, self.regions.base, Spec::splat(false));
- // For linear rows, we can already resolve the correct
+ // For relative rows, we can already resolve the correct
// base, for auto it's already correct and for fr we could
// only guess anyway.
- if let TrackSizing::Linear(v) = self.rows[y] {
+ if let TrackSizing::Relative(v) = self.rows[y] {
pod.base.y = v.resolve(self.regions.base.y);
}
@@ -310,7 +312,7 @@ impl<'a> GridLayouter<'a> {
}
/// Distribute remaining space to fractional columns.
- fn grow_fractional_columns(&mut self, remaining: Length, fr: Fractional) {
+ fn grow_fractional_columns(&mut self, remaining: Length, fr: Fraction) {
for (&col, rcol) in self.cols.iter().zip(&mut self.rcols) {
if let TrackSizing::Fractional(v) = col {
*rcol = v.resolve(fr, remaining);
@@ -415,12 +417,12 @@ impl<'a> GridLayouter<'a> {
Ok(())
}
- /// Layout a row with linear height. Such a row cannot break across multiple
- /// regions, but it may force a region break.
- fn layout_linear_row(
+ /// Layout a row with relative height. Such a row cannot break across
+ /// multiple regions, but it may force a region break.
+ fn layout_relative_row(
&mut self,
ctx: &mut Context,
- v: Linear,
+ v: Relative,
y: usize,
) -> TypResult<()> {
let resolved = v.resolve(self.regions.base.y);
@@ -457,7 +459,7 @@ impl<'a> GridLayouter<'a> {
let size = Size::new(rcol, height);
// Set the base to the region's base for auto rows and to the
- // size for linear and fractional rows.
+ // size for relative and fractional rows.
let base = Spec::new(self.cols[x], self.rows[y])
.map(|s| s == TrackSizing::Auto)
.select(self.regions.base, size);
@@ -555,7 +557,7 @@ impl<'a> GridLayouter<'a> {
self.regions.next();
self.full = self.regions.first.y;
self.used.y = Length::zero();
- self.fr = Fractional::zero();
+ self.fr = Fraction::zero();
Ok(())
}
diff --git a/src/library/layout/pad.rs b/src/library/layout/pad.rs
index 664c63ac..1ec5f124 100644
--- a/src/library/layout/pad.rs
+++ b/src/library/layout/pad.rs
@@ -4,7 +4,7 @@ use crate::library::prelude::*;
#[derive(Debug, Hash)]
pub struct PadNode {
/// The amount of padding.
- pub padding: Sides<Linear>,
+ pub padding: Sides<Relative>,
/// The child node whose sides to pad.
pub child: LayoutNode,
}
@@ -54,7 +54,7 @@ impl Layout for PadNode {
}
/// Shrink a size by padding relative to the size itself.
-fn shrink(size: Size, padding: Sides<Linear>) -> Size {
+fn shrink(size: Size, padding: Sides<Relative>) -> Size {
size - padding.resolve(size).sum_by_axis()
}
@@ -77,7 +77,7 @@ fn shrink(size: Size, padding: Sides<Linear>) -> Size {
/// <=> w - p.rel * w - p.abs = s
/// <=> (1 - p.rel) * w = s + p.abs
/// <=> w = (s + p.abs) / (1 - p.rel)
-fn grow(size: Size, padding: Sides<Linear>) -> Size {
+fn grow(size: Size, padding: Sides<Relative>) -> Size {
size.zip(padding.sum_by_axis())
.map(|(s, p)| (s + p.abs).safe_div(1.0 - p.rel.get()))
}
diff --git a/src/library/layout/page.rs b/src/library/layout/page.rs
index c8af4843..abe1786f 100644
--- a/src/library/layout/page.rs
+++ b/src/library/layout/page.rs
@@ -16,13 +16,13 @@ impl PageNode {
/// Whether the page is flipped into landscape orientation.
pub const FLIPPED: bool = false;
/// The left margin.
- pub const LEFT: Smart<Linear> = Smart::Auto;
+ pub const LEFT: Smart<Relative> = Smart::Auto;
/// The right margin.
- pub const RIGHT: Smart<Linear> = Smart::Auto;
+ pub const RIGHT: Smart<Relative> = Smart::Auto;
/// The top margin.
- pub const TOP: Smart<Linear> = Smart::Auto;
+ pub const TOP: Smart<Relative> = Smart::Auto;
/// The bottom margin.
- pub const BOTTOM: Smart<Linear> = Smart::Auto;
+ pub const BOTTOM: Smart<Relative> = Smart::Auto;
/// The page's background color.
pub const FILL: Option<Paint> = None;
/// How many columns the page has.
@@ -90,7 +90,7 @@ impl PageNode {
}
// Determine the margins.
- let default = Linear::from(0.1190 * min);
+ let default = Relative::from(0.1190 * min);
let padding = Sides {
left: styles.get(Self::LEFT).unwrap_or(default),
right: styles.get(Self::RIGHT).unwrap_or(default),
diff --git a/src/library/layout/spacing.rs b/src/library/layout/spacing.rs
index 8aea780c..633093e9 100644
--- a/src/library/layout/spacing.rs
+++ b/src/library/layout/spacing.rs
@@ -23,10 +23,10 @@ impl VNode {
/// Kinds of spacing.
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
pub enum Spacing {
- /// A length stated in absolute values and/or relative to the parent's size.
- Linear(Linear),
- /// A length that is the fraction of the remaining free space in the parent.
- Fractional(Fractional),
+ /// Spacing specified in absolute terms and relative to the parent's size.
+ Relative(Relative),
+ /// Spacing specified as a fraction of the remaining free space in the parent.
+ Fractional(Fraction),
}
impl Spacing {
@@ -38,15 +38,15 @@ impl Spacing {
impl From<Length> for Spacing {
fn from(length: Length) -> Self {
- Self::Linear(length.into())
+ Self::Relative(length.into())
}
}
castable! {
Spacing,
- Expected: "linear or fractional",
- Value::Length(v) => Self::Linear(v.into()),
- Value::Relative(v) => Self::Linear(v.into()),
- Value::Linear(v) => Self::Linear(v),
- Value::Fractional(v) => Self::Fractional(v),
+ Expected: "relative length or fraction",
+ Value::Length(v) => Self::Relative(v.into()),
+ Value::Ratio(v) => Self::Relative(v.into()),
+ Value::Relative(v) => Self::Relative(v),
+ Value::Fraction(v) => Self::Fractional(v),
}
diff --git a/src/library/layout/stack.rs b/src/library/layout/stack.rs
index 11d45bb4..b0e2e160 100644
--- a/src/library/layout/stack.rs
+++ b/src/library/layout/stack.rs
@@ -76,11 +76,11 @@ impl Debug for StackChild {
castable! {
StackChild,
- Expected: "linear, fractional or content",
- Value::Length(v) => Self::Spacing(Spacing::Linear(v.into())),
- Value::Relative(v) => Self::Spacing(Spacing::Linear(v.into())),
- Value::Linear(v) => Self::Spacing(Spacing::Linear(v)),
- Value::Fractional(v) => Self::Spacing(Spacing::Fractional(v)),
+ Expected: "relative length, fraction, or content",
+ Value::Length(v) => Self::Spacing(Spacing::Relative(v.into())),
+ Value::Ratio(v) => Self::Spacing(Spacing::Relative(v.into())),
+ Value::Relative(v) => Self::Spacing(Spacing::Relative(v)),
+ Value::Fraction(v) => Self::Spacing(Spacing::Fractional(v)),
Value::Content(v) => Self::Node(v.pack()),
}
@@ -98,8 +98,8 @@ pub struct StackLayouter {
full: Size,
/// The generic size used by the frames for the current region.
used: Gen<Length>,
- /// The sum of fractional ratios in the current region.
- fr: Fractional,
+ /// The sum of fractions in the current region.
+ fr: Fraction,
/// Already layouted items whose exact positions are not yet known due to
/// fractional spacing.
items: Vec<StackItem>,
@@ -112,7 +112,7 @@ enum StackItem {
/// Absolute spacing between other items.
Absolute(Length),
/// Fractional spacing between other items.
- Fractional(Fractional),
+ Fractional(Fraction),
/// A frame for a layouted child node.
Frame(Arc<Frame>, Align),
}
@@ -135,7 +135,7 @@ impl StackLayouter {
expand,
full,
used: Gen::zero(),
- fr: Fractional::zero(),
+ fr: Fraction::zero(),
items: vec![],
finished: vec![],
}
@@ -144,8 +144,8 @@ impl StackLayouter {
/// Add spacing along the spacing direction.
pub fn layout_spacing(&mut self, spacing: Spacing) {
match spacing {
- Spacing::Linear(v) => {
- // Resolve the linear and limit it to the remaining space.
+ Spacing::Relative(v) => {
+ // Resolve the spacing and limit it to the remaining space.
let resolved = v.resolve(self.regions.base.get(self.axis));
let remaining = self.regions.first.get_mut(self.axis);
let limited = resolved.min(*remaining);
@@ -247,7 +247,7 @@ impl StackLayouter {
self.regions.next();
self.full = self.regions.first;
self.used = Gen::zero();
- self.fr = Fractional::zero();
+ self.fr = Fraction::zero();
self.finished.push(Arc::new(output));
}
diff --git a/src/library/mod.rs b/src/library/mod.rs
index bba002de..af9ab575 100644
--- a/src/library/mod.rs
+++ b/src/library/mod.rs
@@ -167,13 +167,13 @@ castable! {
}
castable! {
- Spec<Linear>,
- Expected: "array of exactly two linears",
+ Spec<Relative>,
+ Expected: "array of two relative lengths",
Value::Array(array) => {
match array.as_slice() {
[a, b] => {
- let a = a.clone().cast::<Linear>()?;
- let b = b.clone().cast::<Linear>()?;
+ let a = a.clone().cast::<Relative>()?;
+ let b = b.clone().cast::<Relative>()?;
Spec::new(a, b)
},
_ => return Err("point array must contain exactly two entries".to_string()),
diff --git a/src/library/structure/heading.rs b/src/library/structure/heading.rs
index 7b00c643..8b143865 100644
--- a/src/library/structure/heading.rs
+++ b/src/library/structure/heading.rs
@@ -23,7 +23,7 @@ impl HeadingNode {
#[property(referenced)]
pub const SIZE: Leveled<FontSize> = Leveled::Mapping(|level| {
let upscale = (1.6 - 0.1 * level as f64).max(0.75);
- FontSize(Relative::new(upscale).into())
+ FontSize(Ratio::new(upscale).into())
});
/// Whether text in the heading is strengthend.
#[property(referenced)]
diff --git a/src/library/structure/list.rs b/src/library/structure/list.rs
index 1b22e166..532ec625 100644
--- a/src/library/structure/list.rs
+++ b/src/library/structure/list.rs
@@ -34,11 +34,11 @@ impl<const L: ListKind> ListNode<L> {
#[property(referenced)]
pub const LABEL: Label = Label::Default;
/// The spacing between the list items of a non-wide list.
- pub const SPACING: Linear = Linear::zero();
+ pub const SPACING: Relative = Relative::zero();
/// The indentation of each item's label.
- pub const INDENT: Linear = Relative::new(0.0).into();
+ pub const INDENT: Relative = Ratio::new(0.0).into();
/// The space between the label and the body of each item.
- pub const BODY_INDENT: Linear = Relative::new(0.5).into();
+ pub const BODY_INDENT: Relative = Ratio::new(0.5).into();
/// The extra padding above the list.
pub const ABOVE: Length = Length::zero();
/// The extra padding below the list.
@@ -91,12 +91,12 @@ impl<const L: ListKind> Show for ListNode<L> {
Content::block(GridNode {
tracks: Spec::with_x(vec![
- TrackSizing::Linear(indent.into()),
+ TrackSizing::Relative(indent.into()),
TrackSizing::Auto,
- TrackSizing::Linear(body_indent.into()),
+ TrackSizing::Relative(body_indent.into()),
TrackSizing::Auto,
]),
- gutter: Spec::with_y(vec![TrackSizing::Linear(gutter.into())]),
+ gutter: Spec::with_y(vec![TrackSizing::Relative(gutter.into())]),
children,
})
};
diff --git a/src/library/structure/table.rs b/src/library/structure/table.rs
index 64785006..9317e43f 100644
--- a/src/library/structure/table.rs
+++ b/src/library/structure/table.rs
@@ -18,12 +18,12 @@ impl TableNode {
pub const PRIMARY: Option<Paint> = None;
/// The secondary cell fill color.
pub const SECONDARY: Option<Paint> = None;
- /// How the stroke the cells.
+ /// How to stroke the cells.
pub const STROKE: Option<Paint> = Some(Color::BLACK.into());
/// The stroke's thickness.
pub const THICKNESS: Length = Length::pt(1.0);
/// How much to pad the cells's content.
- pub const PADDING: Linear = Length::pt(5.0).into();
+ pub const PADDING: Relative = Length::pt(5.0).into();
fn construct(_: &mut Context, args: &mut Args) -> TypResult<Content> {
let columns = args.named("columns")?.unwrap_or_default();
diff --git a/src/library/text/deco.rs b/src/library/text/deco.rs
index a6375e4e..a81f0374 100644
--- a/src/library/text/deco.rs
+++ b/src/library/text/deco.rs
@@ -26,13 +26,13 @@ impl<const L: DecoLine> DecoNode<L> {
/// Thickness of the line's strokes (dependent on scaled font size), read
/// from the font tables if `None`.
#[property(shorthand)]
- pub const THICKNESS: Option<Linear> = None;
+ pub const THICKNESS: Option<Relative> = None;
/// Position of the line relative to the baseline (dependent on scaled font
/// size), read from the font tables if `None`.
- pub const OFFSET: Option<Linear> = None;
+ pub const OFFSET: Option<Relative> = None;
/// Amount that the line will be longer or shorter than its associated text
/// (dependent on scaled font size).
- pub const EXTENT: Linear = Linear::zero();
+ pub const EXTENT: Relative = Relative::zero();
/// Whether the line skips sections in which it would collide
/// with the glyphs. Does not apply to strikethrough.
pub const EVADE: bool = true;
@@ -66,9 +66,9 @@ impl<const L: DecoLine> Show for DecoNode<L> {
pub struct Decoration {
pub line: DecoLine,
pub stroke: Option<Paint>,
- pub thickness: Option<Linear>,
- pub offset: Option<Linear>,
- pub extent: Linear,
+ pub thickness: Option<Relative>,
+ pub offset: Option<Relative>,
+ pub extent: Relative,
pub evade: bool,
}
diff --git a/src/library/text/mod.rs b/src/library/text/mod.rs
index 64994136..975a4805 100644
--- a/src/library/text/mod.rs
+++ b/src/library/text/mod.rs
@@ -49,7 +49,7 @@ impl TextNode {
/// The amount of space that should be added between characters.
pub const TRACKING: Em = Em::zero();
/// The ratio by which spaces should be stretched.
- pub const SPACING: Relative = Relative::one();
+ pub const SPACING: Ratio = Ratio::one();
/// Whether glyphs can hang over into the margin.
pub const OVERHANG: bool = true;
/// The top end of the text bounding box.
@@ -182,13 +182,13 @@ castable! {
castable! {
FontStretch,
- Expected: "relative",
- Value::Relative(v) => Self::from_ratio(v.get() as f32),
+ Expected: "ratio",
+ Value::Ratio(v) => Self::from_ratio(v.get() as f32),
}
/// The size of text.
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
-pub struct FontSize(pub Linear);
+pub struct FontSize(pub Relative);
impl Fold for FontSize {
type Output = Length;
@@ -200,10 +200,10 @@ impl Fold for FontSize {
castable! {
FontSize,
- Expected: "linear",
+ Expected: "relative length",
Value::Length(v) => Self(v.into()),
- Value::Relative(v) => Self(v.into()),
- Value::Linear(v) => Self(v),
+ Value::Ratio(v) => Self(v.into()),
+ Value::Relative(v) => Self(v),
}
castable! {
@@ -214,10 +214,10 @@ castable! {
castable! {
VerticalFontMetric,
- Expected: "linear or string",
- Value::Length(v) => Self::Linear(v.into()),
- Value::Relative(v) => Self::Linear(v.into()),
- Value::Linear(v) => Self::Linear(v),
+ Expected: "string or relative length",
+ Value::Length(v) => Self::Relative(v.into()),
+ Value::Ratio(v) => Self::Relative(v.into()),
+ Value::Relative(v) => Self::Relative(v),
Value::Str(string) => match string.as_str() {
"ascender" => Self::Ascender,
"cap-height" => Self::CapHeight,
diff --git a/src/library/text/par.rs b/src/library/text/par.rs
index 1695e010..a05aff44 100644
--- a/src/library/text/par.rs
+++ b/src/library/text/par.rs
@@ -42,11 +42,11 @@ impl ParNode {
/// will will be hyphenated if and only if justification is enabled.
pub const HYPHENATE: Smart<bool> = Smart::Auto;
/// The spacing between lines (dependent on scaled font size).
- pub const LEADING: Linear = Relative::new(0.65).into();
+ pub const LEADING: Relative = Ratio::new(0.65).into();
/// The extra spacing between paragraphs (dependent on scaled font size).
- pub const SPACING: Linear = Relative::new(0.55).into();
+ pub const SPACING: Relative = Ratio::new(0.55).into();
/// The indent the first line of a consecutive paragraph should have.
- pub const INDENT: Linear = Linear::zero();
+ pub const INDENT: Relative = Relative::zero();
fn construct(_: &mut Context, args: &mut Args) -> TypResult<Content> {
// The paragraph constructor is special: It doesn't create a paragraph
@@ -249,7 +249,7 @@ enum ParItem<'a> {
/// Absolute spacing between other items.
Absolute(Length),
/// Fractional spacing between other items.
- Fractional(Fractional),
+ Fractional(Fraction),
/// A shaped text run with consistent direction.
Text(ShapedText<'a>),
/// A layouted child node.
@@ -285,8 +285,8 @@ struct Line<'a> {
size: Size,
/// The baseline of the line.
baseline: Length,
- /// The sum of fractional ratios in the line.
- fr: Fractional,
+ /// The sum of fractions in the line.
+ fr: Fraction,
/// Whether the line ends at a mandatory break.
mandatory: bool,
/// Whether the line ends with a hyphen or dash, either naturally or through
@@ -370,7 +370,7 @@ fn prepare<'a>(
}
}
ParChild::Spacing(spacing) => match *spacing {
- Spacing::Linear(v) => {
+ Spacing::Relative(v) => {
let resolved = v.resolve(regions.base.x);
items.push(ParItem::Absolute(resolved));
ranges.push(range);
@@ -731,7 +731,7 @@ fn line<'a>(
let mut width = Length::zero();
let mut top = Length::zero();
let mut bottom = Length::zero();
- let mut fr = Fractional::zero();
+ let mut fr = Fraction::zero();
// Measure the size of the line.
for item in first.iter().chain(items).chain(&last) {
diff --git a/src/library/utility/color.rs b/src/library/utility/color.rs
index df24f615..409af177 100644
--- a/src/library/utility/color.rs
+++ b/src/library/utility/color.rs
@@ -15,12 +15,12 @@ pub fn rgb(_: &mut Context, args: &mut Args) -> TypResult<Value> {
castable! {
Component,
- Expected: "integer or relative",
+ Expected: "integer or ratio",
Value::Int(v) => match v {
0 ..= 255 => Self(v as u8),
_ => Err("must be between 0 and 255")?,
},
- Value::Relative(v) => if (0.0 ..= 1.0).contains(&v.get()) {
+ Value::Ratio(v) => if (0.0 ..= 1.0).contains(&v.get()) {
Self((v.get() * 255.0).round() as u8)
} else {
Err("must be between 0% and 100%")?
@@ -42,8 +42,8 @@ pub fn cmyk(_: &mut Context, args: &mut Args) -> TypResult<Value> {
castable! {
Component,
- Expected: "relative",
- Value::Relative(v) => if (0.0 ..= 1.0).contains(&v.get()) {
+ Expected: "ratio",
+ Value::Ratio(v) => if (0.0 ..= 1.0).contains(&v.get()) {
Self((v.get() * 255.0).round() as u8)
} else {
Err("must be between 0% and 100%")?
diff --git a/src/library/utility/math.rs b/src/library/utility/math.rs
index 0aebc573..272ececa 100644
--- a/src/library/utility/math.rs
+++ b/src/library/utility/math.rs
@@ -39,9 +39,11 @@ pub fn abs(_: &mut Context, args: &mut Args) -> TypResult<Value> {
Value::Float(v) => Value::Float(v.abs()),
Value::Length(v) => Value::Length(v.abs()),
Value::Angle(v) => Value::Angle(v.abs()),
- Value::Relative(v) => Value::Relative(v.abs()),
- Value::Fractional(v) => Value::Fractional(v.abs()),
- Value::Linear(_) => bail!(span, "cannot take absolute value of a linear"),
+ Value::Ratio(v) => Value::Ratio(v.abs()),
+ Value::Fraction(v) => Value::Fraction(v.abs()),
+ Value::Relative(_) => {
+ bail!(span, "cannot take absolute value of a relative length")
+ }
v => bail!(span, "expected numeric value, found {}", v.type_name()),
})
}