diff options
Diffstat (limited to 'src/library')
| -rw-r--r-- | src/library/graphics/hide.rs | 3 | ||||
| -rw-r--r-- | src/library/graphics/shape.rs | 2 | ||||
| -rw-r--r-- | src/library/graphics/transform.rs | 2 | ||||
| -rw-r--r-- | src/library/layout/columns.rs | 2 | ||||
| -rw-r--r-- | src/library/layout/grid.rs | 2 | ||||
| -rw-r--r-- | src/library/layout/pad.rs | 2 | ||||
| -rw-r--r-- | src/library/layout/page.rs | 2 | ||||
| -rw-r--r-- | src/library/layout/place.rs | 3 | ||||
| -rw-r--r-- | src/library/layout/stack.rs | 3 | ||||
| -rw-r--r-- | src/library/math/rex.rs | 2 | ||||
| -rw-r--r-- | src/library/prelude.rs | 2 | ||||
| -rw-r--r-- | src/library/text/deco.rs | 4 | ||||
| -rw-r--r-- | src/library/text/link.rs | 12 | ||||
| -rw-r--r-- | src/library/text/mod.rs | 42 | ||||
| -rw-r--r-- | src/library/text/par.rs | 27 | ||||
| -rw-r--r-- | src/library/text/repeat.rs | 2 | ||||
| -rw-r--r-- | src/library/text/shaping.rs | 14 | ||||
| -rw-r--r-- | src/library/text/shift.rs | 17 | ||||
| -rw-r--r-- | src/library/utility/math.rs | 2 | ||||
| -rw-r--r-- | src/library/utility/string.rs | 10 |
20 files changed, 68 insertions, 87 deletions
diff --git a/src/library/graphics/hide.rs b/src/library/graphics/hide.rs index 0ed02d1b..f40635a0 100644 --- a/src/library/graphics/hide.rs +++ b/src/library/graphics/hide.rs @@ -19,12 +19,9 @@ impl Layout for HideNode { styles: StyleChain, ) -> TypResult<Vec<Frame>> { let mut frames = self.0.layout(ctx, regions, styles)?; - - // Clear the frames. for frame in &mut frames { frame.clear(); } - Ok(frames) } } diff --git a/src/library/graphics/shape.rs b/src/library/graphics/shape.rs index bf581815..eed3c9d9 100644 --- a/src/library/graphics/shape.rs +++ b/src/library/graphics/shape.rs @@ -165,7 +165,7 @@ impl<const S: ShapeKind> Layout for ShapeNode<S> { frame.prepend(pos, Element::Shape(shape)); } else { frame.prepend_multiple( - Rect::new(size, radius) + RoundedRect::new(size, radius) .shapes(fill, stroke) .into_iter() .map(|x| (pos, Element::Shape(x))), diff --git a/src/library/graphics/transform.rs b/src/library/graphics/transform.rs index 2a0149bc..48cadb1b 100644 --- a/src/library/graphics/transform.rs +++ b/src/library/graphics/transform.rs @@ -107,6 +107,8 @@ impl<const T: TransformKind> Layout for TransformNode<T> { } /// Kinds of transformations. +/// +/// The move transformation is handled separately. pub type TransformKind = usize; /// A rotational transformation. diff --git a/src/library/layout/columns.rs b/src/library/layout/columns.rs index 33ceab86..efc435aa 100644 --- a/src/library/layout/columns.rs +++ b/src/library/layout/columns.rs @@ -58,10 +58,10 @@ impl Layout for ColumnsNode { // Layout the children. let mut frames = self.child.layout(ctx, &pod, styles)?.into_iter(); + let mut finished = vec![]; let dir = styles.get(TextNode::DIR); let total_regions = (frames.len() as f32 / columns as f32).ceil() as usize; - let mut finished = vec![]; // Stitch together the columns for each region. for region in regions.iter().take(total_regions) { diff --git a/src/library/layout/grid.rs b/src/library/layout/grid.rs index c02662a6..5e86f3d0 100644 --- a/src/library/layout/grid.rs +++ b/src/library/layout/grid.rs @@ -67,7 +67,7 @@ pub enum TrackSizing { castable! { Vec<TrackSizing>, - Expected: "integer, auto, relative length, fraction, or array of the latter three)", + Expected: "integer, auto, relative length, fraction, or array of the latter three", Value::Auto => vec![TrackSizing::Auto], Value::Length(v) => vec![TrackSizing::Relative(v.into())], Value::Ratio(v) => vec![TrackSizing::Relative(v.into())], diff --git a/src/library/layout/pad.rs b/src/library/layout/pad.rs index dfd425bd..9d91c641 100644 --- a/src/library/layout/pad.rs +++ b/src/library/layout/pad.rs @@ -65,7 +65,7 @@ fn shrink(size: Size, padding: Sides<Relative<Length>>) -> Size { /// (Vertical axis is analogous.) /// /// Let w be the grown target width, -/// s be given width, +/// s be the given width, /// l be the left padding, /// r be the right padding, /// p = l + r. diff --git a/src/library/layout/page.rs b/src/library/layout/page.rs index e2f414ab..0a7c7579 100644 --- a/src/library/layout/page.rs +++ b/src/library/layout/page.rs @@ -18,7 +18,7 @@ impl PageNode { /// Whether the page is flipped into landscape orientation. pub const FLIPPED: bool = false; - /// The page margin. + /// The page's margins. #[property(fold)] pub const MARGINS: Sides<Option<Smart<Relative<RawLength>>>> = Sides::splat(Smart::Auto); diff --git a/src/library/layout/place.rs b/src/library/layout/place.rs index 67e46d3b..4c6d0062 100644 --- a/src/library/layout/place.rs +++ b/src/library/layout/place.rs @@ -39,9 +39,8 @@ impl Layout for PlaceNode { // If expansion is off, zero all sizes so that we don't take up any // space in our parent. Otherwise, respect the expand settings. - let frame = &mut frames[0]; let target = regions.expand.select(regions.first, Size::zero()); - frame.resize(target, Align::LEFT_TOP); + frames[0].resize(target, Align::LEFT_TOP); Ok(frames) } diff --git a/src/library/layout/stack.rs b/src/library/layout/stack.rs index b1268404..d8dc0e1a 100644 --- a/src/library/layout/stack.rs +++ b/src/library/layout/stack.rs @@ -176,7 +176,8 @@ impl<'a> StackLayouter<'a> { self.finish_region(); } - // Align nodes' block-axis alignment is respected by the stack node. + // Block-axis alignment of the `AlignNode` is respected + // by the stack node. let align = node .downcast::<AlignNode>() .and_then(|node| node.aligns.get(self.axis)) diff --git a/src/library/math/rex.rs b/src/library/math/rex.rs index a1777372..9319d8ca 100644 --- a/src/library/math/rex.rs +++ b/src/library/math/rex.rs @@ -34,7 +34,7 @@ impl Layout for RexNode { .ok_or("failed to find math font") .at(span)?; - // Prepare the font. + // Prepare the font context. let face = ctx.fonts.get(face_id); let ctx = face .math() diff --git a/src/library/prelude.rs b/src/library/prelude.rs index a61157a7..c033b631 100644 --- a/src/library/prelude.rs +++ b/src/library/prelude.rs @@ -19,5 +19,5 @@ pub use crate::model::{ StyleChain, StyleMap, StyleVec, }; pub use crate::syntax::{Span, Spanned}; -pub use crate::util::{EcoString, OptionExt}; +pub use crate::util::EcoString; pub use crate::Context; diff --git a/src/library/text/deco.rs b/src/library/text/deco.rs index c5217e8e..e6a65eba 100644 --- a/src/library/text/deco.rs +++ b/src/library/text/deco.rs @@ -20,8 +20,8 @@ pub type OverlineNode = DecoNode<OVERLINE>; #[node(showable)] impl<const L: DecoLine> DecoNode<L> { - /// How to stroke the line. The text color and thickness read from the font - /// tables if `auto`. + /// How to stroke the line. The text color and thickness are read from the + /// font tables if `auto`. #[property(shorthand, resolve, fold)] pub const STROKE: Smart<RawStroke> = Smart::Auto; /// Position of the line relative to the baseline, read from the font tables diff --git a/src/library/text/link.rs b/src/library/text/link.rs index 12cbaf59..740426a3 100644 --- a/src/library/text/link.rs +++ b/src/library/text/link.rs @@ -1,7 +1,7 @@ use super::TextNode; use crate::library::prelude::*; -/// Link text and other elements to an URL. +/// Link text and other elements to a destination. #[derive(Debug, Hash)] pub struct LinkNode { /// The destination the link points to. @@ -15,7 +15,7 @@ impl LinkNode { /// The fill color of text in the link. Just the surrounding text color /// if `auto`. pub const FILL: Smart<Paint> = Smart::Auto; - /// Whether to underline link. + /// Whether to underline the link. pub const UNDERLINE: Smart<bool> = Smart::Auto; fn construct(_: &mut Machine, args: &mut Args) -> TypResult<Content> { @@ -35,10 +35,10 @@ castable! { Expected: "string or dictionary with `page`, `x`, and `y` keys", Value::Str(string) => Self::Url(string), Value::Dict(dict) => { - let page: i64 = dict.get(&"page".into())?.clone().cast()?; - let x: RawLength = dict.get(&"x".into())?.clone().cast()?; - let y: RawLength = dict.get(&"y".into())?.clone().cast()?; - Self::Internal(Location { page: page as usize, pos: Point::new(x.length, y.length) }) + let page = dict.get("page")?.clone().cast()?; + let x: RawLength = dict.get("x")?.clone().cast()?; + let y: RawLength = dict.get("y")?.clone().cast()?; + Self::Internal(Location { page, pos: Point::new(x.length, y.length) }) }, } diff --git a/src/library/text/mod.rs b/src/library/text/mod.rs index be20b3ef..91eab2fd 100644 --- a/src/library/text/mod.rs +++ b/src/library/text/mod.rs @@ -59,13 +59,13 @@ impl TextNode { /// The amount of space that should be added between characters. #[property(resolve)] pub const TRACKING: RawLength = RawLength::zero(); - /// The width of spaces relative to the default space width. + /// The width of spaces relative to the font's space width. #[property(resolve)] pub const SPACING: Relative<RawLength> = Relative::one(); /// The offset of the baseline. #[property(resolve)] pub const BASELINE: RawLength = RawLength::zero(); - /// Whether glyphs can hang over into the margin. + /// Whether certain glyphs can hang over into the margin. pub const OVERHANG: bool = true; /// The top end of the text bounding box. pub const TOP_EDGE: TextEdge = TextEdge::Metric(VerticalFontMetric::CapHeight); @@ -114,7 +114,7 @@ impl TextNode { /// Whether the font weight should be increased by 300. #[property(skip, fold)] pub const BOLD: Toggle = false; - /// Whether the the font style should be inverted. + /// Whether the font style should be inverted. #[property(skip, fold)] pub const ITALIC: Toggle = false; /// A case transformation that should be applied to the text. @@ -123,7 +123,7 @@ impl TextNode { /// Whether small capital glyphs should be used. ("smcp") #[property(skip)] pub const SMALLCAPS: bool = false; - /// An URL the text should link to. + /// A destination the text should be linked to. #[property(skip, referenced)] pub const LINK: Option<Destination> = None; /// Decorative lines. @@ -168,7 +168,7 @@ impl TextNode { } } -/// A font family like "Arial". +/// A lowercased font family like "arial". #[derive(Clone, Eq, PartialEq, Hash)] pub struct FontFamily(EcoString); @@ -338,7 +338,7 @@ impl Resolve for Smart<Hyphenate> { pub struct StylisticSet(u8); impl StylisticSet { - /// Creates a new set, clamping to 1-20. + /// Create a new set, clamping to 1-20. pub fn new(index: u8) -> Self { Self(index.clamp(1, 20)) } @@ -363,7 +363,7 @@ castable! { pub enum NumberType { /// Numbers that fit well with capital text. ("lnum") Lining, - /// Numbers that fit well into flow of upper- and lowercase text. ("onum") + /// Numbers that fit well into a flow of upper- and lowercase text. ("onum") OldStyle, } @@ -396,28 +396,6 @@ castable! { }, } -/// How to position numbers. -#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)] -pub enum NumberPosition { - /// Numbers are positioned on the same baseline as text. - Normal, - /// Numbers are smaller and placed at the bottom. ("subs") - Subscript, - /// Numbers are smaller and placed at the top. ("sups") - Superscript, -} - -castable! { - NumberPosition, - Expected: "string", - Value::Str(string) => match string.as_str() { - "normal" => Self::Normal, - "subscript" => Self::Subscript, - "superscript" => Self::Superscript, - _ => Err(r#"expected "normal", "subscript" or "superscript""#)?, - }, -} - castable! { Vec<(Tag, u32)>, Expected: "array of strings or dictionary mapping tags to integers", @@ -445,12 +423,12 @@ impl Fold for Vec<(Tag, u32)> { } } -/// Convert text to lowercase. +/// Convert a string or content to lowercase. pub fn lower(_: &mut Machine, args: &mut Args) -> TypResult<Value> { case(Case::Lower, args) } -/// Convert text to uppercase. +/// Convert a string or content to uppercase. pub fn upper(_: &mut Machine, args: &mut Args) -> TypResult<Value> { case(Case::Upper, args) } @@ -475,7 +453,7 @@ pub enum Case { } impl Case { - /// Apply the case to a string of text. + /// Apply the case to a string. pub fn apply(self, text: &str) -> String { match self { Self::Upper => text.to_uppercase(), diff --git a/src/library/text/par.rs b/src/library/text/par.rs index e4013163..38240b3d 100644 --- a/src/library/text/par.rs +++ b/src/library/text/par.rs @@ -297,7 +297,7 @@ impl Segment<'_> { /// A prepared item in a paragraph layout. #[derive(Debug)] enum Item<'a> { - /// A shaped text run with consistent direction. + /// A shaped text run with consistent style and direction. Text(ShapedText<'a>), /// Absolute spacing between other items. Absolute(Length), @@ -305,7 +305,7 @@ enum Item<'a> { Fractional(Fraction), /// A layouted child node. Frame(Frame), - /// A repeating node. + /// A repeating node that fills the remaining space. Repeat(&'a RepeatNode, StyleChain<'a>), /// A pin identified by index. Pin(usize), @@ -330,7 +330,7 @@ impl<'a> Item<'a> { } } - /// The natural width of the item. + /// The natural layouted width of the item. fn width(&self) -> Length { match self { Self::Text(shaped) => shaped.width, @@ -366,7 +366,7 @@ struct Line<'a> { last: Option<Item<'a>>, /// The width of the line. width: Length, - /// Whether the line is allowed to be justified. + /// Whether the line should be justified. justify: bool, /// Whether the line ends with a hyphen or dash, either naturally or through /// hyphenation. @@ -403,7 +403,7 @@ impl<'a> Line<'a> { self.items().skip(start).take(end - start) } - // How many justifiable glyphs the line contains. + /// How many justifiable glyphs the line contains. fn justifiables(&self) -> usize { let mut count = 0; for shaped in self.items().filter_map(Item::text) { @@ -528,7 +528,7 @@ fn prepare<'a>( let mut cursor = 0; let mut items = vec![]; - // Layout the children and collect them into items. + // Shape / layout the children and collect them into items. for (segment, styles) in segments { let end = cursor + segment.len(); match segment { @@ -654,7 +654,7 @@ fn linebreak<'a>( } /// Perform line breaking in simple first-fit style. This means that we build -/// lines a greedily, always taking the longest possible line. This may lead to +/// lines greedily, always taking the longest possible line. This may lead to /// very unbalanced line, but is fast and simple. fn linebreak_simple<'a>( p: &'a Preparation<'a>, @@ -670,8 +670,8 @@ fn linebreak_simple<'a>( let mut attempt = line(p, fonts, start .. end, mandatory, hyphen); // If the line doesn't fit anymore, we push the last fitting attempt - // into the stack and rebuild the line from its end. The resulting - // line cannot be broken up further. + // into the stack and rebuild the line from the attempt's end. The + // resulting line cannot be broken up further. if !width.fits(attempt.width) { if let Some((last_attempt, last_end)) = last.take() { lines.push(last_attempt); @@ -771,17 +771,18 @@ fn linebreak_optimized<'a>( ratio = ratio.min(10.0); // Determine the cost of the line. - let mut cost = if ratio < if attempt.justify { MIN_RATIO } else { 0.0 } { + let min_ratio = if attempt.justify { MIN_RATIO } else { 0.0 }; + let mut cost = if ratio < min_ratio { // The line is overfull. This is the case if - // - justification is on, but we'd need to shrink to much + // - justification is on, but we'd need to shrink too much // - justification is off and the line just doesn't fit // Since any longer line will also be overfull, we can deactive // this breakpoint. active = i + 1; MAX_COST } else if eof { - // This is the final line and its not overfull since then - // we would have taken the above branch. + // This is the final line and its not overfull since then we + // would have taken the above branch. 0.0 } else if mandatory { // This is a mandatory break and the line is not overfull, so it diff --git a/src/library/text/repeat.rs b/src/library/text/repeat.rs index a3e83ac7..aca281fc 100644 --- a/src/library/text/repeat.rs +++ b/src/library/text/repeat.rs @@ -1,6 +1,6 @@ use crate::library::prelude::*; -/// Fill space by repeating something horizontally. +/// A node that should be repeated to fill up a line. #[derive(Debug, Hash)] pub struct RepeatNode(pub LayoutNode); diff --git a/src/library/text/shaping.rs b/src/library/text/shaping.rs index bb88836c..9465fbd9 100644 --- a/src/library/text/shaping.rs +++ b/src/library/text/shaping.rs @@ -43,7 +43,9 @@ pub struct ShapedGlyph { pub x_offset: Em, /// The vertical offset of the glyph. pub y_offset: Em, - /// A value that is the same for all glyphs belong to one cluster. + /// The byte index in the source text where this glyph's cluster starts. A + /// cluster is a sequence of one or multiple glyphs that cannot be + /// separated and must always be treated as a union. pub cluster: usize, /// Whether splitting the shaping result before this glyph would yield the /// same results as shaping the parts to both sides of `text_index` @@ -67,9 +69,9 @@ impl ShapedGlyph { /// A side you can go toward. enum Side { - /// Go toward the west. + /// To the left-hand side. Left, - /// Go toward the east. + /// To the right-hand side. Right, } @@ -141,7 +143,7 @@ impl<'a> ShapedText<'a> { frame } - /// Measure the top and bottom extent of a this text. + /// Measure the top and bottom extent of this text. fn measure(&self, fonts: &mut FontStore) -> (Length, Length) { let mut top = Length::zero(); let mut bottom = Length::zero(); @@ -498,7 +500,7 @@ fn shape_tofus(ctx: &mut ShapingContext, base: usize, text: &str, face_id: FaceI } } -/// Apply tracking and spacing to a slice of shaped glyphs. +/// Apply tracking and spacing to the shaped glyphs. fn track_and_space(ctx: &mut ShapingContext) { let tracking = Em::from_length(ctx.styles.get(TextNode::TRACKING), ctx.size); let spacing = ctx @@ -522,7 +524,7 @@ fn track_and_space(ctx: &mut ShapingContext) { } } -/// Resolve the font variant with `STRONG` and `EMPH` factored in. +/// Resolve the font variant with `BOLD` and `ITALIC` factored in. pub fn variant(styles: StyleChain) -> FontVariant { let mut variant = FontVariant::new( styles.get(TextNode::STYLE), diff --git a/src/library/text/shift.rs b/src/library/text/shift.rs index 4eacd3c8..744479f2 100644 --- a/src/library/text/shift.rs +++ b/src/library/text/shift.rs @@ -3,11 +3,12 @@ use crate::font::FontStore; use crate::library::prelude::*; use crate::util::EcoString; -/// Sub or superscript text. The text is rendered smaller and its baseline is raised. +/// Sub or superscript text. /// -/// To provide the best typography possible, we first try to transform the -/// text to superscript codepoints. If that fails, we fall back to rendering -/// shrunk normal letters in a raised way. +/// The text is rendered smaller and its baseline is raised. To provide the best +/// typography possible, we first try to transform the text to superscript +/// codepoints. If that fails, we fall back to rendering shrunk normal letters +/// in a raised way. #[derive(Debug, Hash)] pub struct ShiftNode<const S: ScriptKind>(pub Content); @@ -19,7 +20,8 @@ pub type SubNode = ShiftNode<SUBSCRIPT>; #[node] impl<const S: ScriptKind> ShiftNode<S> { - /// Whether to prefer the dedicated sub- and superscript characters of the font. + /// Whether to prefer the dedicated sub- and superscript characters of the + /// font. pub const TYPOGRAPHIC: bool = true; /// The baseline shift for synthetic sub- and superscripts. pub const BASELINE: RawLength = @@ -60,9 +62,8 @@ impl<const S: ScriptKind> Show for ShiftNode<S> { } } -/// Find and transform the text contained in `content` iff it only consists of -/// `Text`, `Space`, and `Empty` leaf nodes. The text is transformed to the -/// given script kind. +/// Find and transform the text contained in `content` to the given script kind +/// if and only if it only consists of `Text`, `Space`, and `Empty` leaf nodes. fn search_text(content: &Content, mode: ScriptKind) -> Option<EcoString> { match content { Content::Text(_) => { diff --git a/src/library/utility/math.rs b/src/library/utility/math.rs index 05c706ca..f68cc1bf 100644 --- a/src/library/utility/math.rs +++ b/src/library/utility/math.rs @@ -2,7 +2,7 @@ use std::cmp::Ordering; use crate::library::prelude::*; -/// Convert a value to a integer. +/// Convert a value to an integer. pub fn int(_: &mut Machine, args: &mut Args) -> TypResult<Value> { let Spanned { v, span } = args.expect("value")?; Ok(Value::Int(match v { diff --git a/src/library/utility/string.rs b/src/library/utility/string.rs index ecfded2b..4739dbf4 100644 --- a/src/library/utility/string.rs +++ b/src/library/utility/string.rs @@ -6,7 +6,7 @@ pub fn repr(_: &mut Machine, args: &mut Args) -> TypResult<Value> { Ok(args.expect::<Value>("value")?.repr().into()) } -/// Cconvert a value to a string. +/// Convert a value to a string. pub fn str(_: &mut Machine, args: &mut Args) -> TypResult<Value> { let Spanned { v, span } = args.expect("value")?; Ok(Value::Str(match v { @@ -31,20 +31,20 @@ pub fn regex(_: &mut Machine, args: &mut Args) -> TypResult<Value> { /// Converts an integer into one or multiple letters. pub fn letter(_: &mut Machine, args: &mut Args) -> TypResult<Value> { - convert(Numbering::Letter, args) + numbered(Numbering::Letter, args) } /// Converts an integer into a roman numeral. pub fn roman(_: &mut Machine, args: &mut Args) -> TypResult<Value> { - convert(Numbering::Roman, args) + numbered(Numbering::Roman, args) } /// Convert a number into a symbol. pub fn symbol(_: &mut Machine, args: &mut Args) -> TypResult<Value> { - convert(Numbering::Symbol, args) + numbered(Numbering::Symbol, args) } -fn convert(numbering: Numbering, args: &mut Args) -> TypResult<Value> { +fn numbered(numbering: Numbering, args: &mut Args) -> TypResult<Value> { let n = args.expect::<usize>("non-negative integer")?; Ok(Value::Str(numbering.apply(n))) } |
