summaryrefslogtreecommitdiff
path: root/library/src
diff options
context:
space:
mode:
Diffstat (limited to 'library/src')
-rw-r--r--library/src/base/calc.rs14
-rw-r--r--library/src/base/color.rs26
-rw-r--r--library/src/base/data.rs5
-rw-r--r--library/src/base/mod.rs8
-rw-r--r--library/src/ext.rs16
-rw-r--r--library/src/graphics/mod.rs6
-rw-r--r--library/src/layout/columns.rs8
-rw-r--r--library/src/layout/grid.rs12
-rw-r--r--library/src/layout/mod.rs86
-rw-r--r--library/src/layout/page.rs7
-rw-r--r--library/src/math/mod.rs9
-rw-r--r--library/src/structure/list.rs12
-rw-r--r--library/src/structure/mod.rs10
-rw-r--r--library/src/text/deco.rs17
-rw-r--r--library/src/text/mod.rs14
-rw-r--r--library/src/text/par.rs47
-rw-r--r--library/src/text/quotes.rs24
-rw-r--r--library/src/text/shaping.rs28
-rw-r--r--library/src/text/shift.rs9
19 files changed, 164 insertions, 194 deletions
diff --git a/library/src/base/calc.rs b/library/src/base/calc.rs
index dd37e8e7..355e5c02 100644
--- a/library/src/base/calc.rs
+++ b/library/src/base/calc.rs
@@ -101,14 +101,12 @@ pub fn mod_(_: &mut Vm, args: &mut Args) -> SourceResult<Value> {
(Value::Int(a), Value::Float(b)) => (a as f64, b),
(Value::Float(a), Value::Int(b)) => (a, b as f64),
(Value::Float(a), Value::Float(b)) => (a, b),
- (Value::Int(_), b) | (Value::Float(_), b) => bail!(
- span2,
- format!("expected integer or float, found {}", b.type_name())
- ),
- (a, _) => bail!(
- span1,
- format!("expected integer or float, found {}", a.type_name())
- ),
+ (Value::Int(_), b) | (Value::Float(_), b) => {
+ bail!(span2, format!("expected integer or float, found {}", b.type_name()))
+ }
+ (a, _) => {
+ bail!(span1, format!("expected integer or float, found {}", a.type_name()))
+ }
};
if b == 0.0 {
diff --git a/library/src/base/color.rs b/library/src/base/color.rs
index 8bb12334..d54911ca 100644
--- a/library/src/base/color.rs
+++ b/library/src/base/color.rs
@@ -10,20 +10,18 @@ pub fn luma(_: &mut Vm, args: &mut Args) -> SourceResult<Value> {
/// Create an RGB(A) color.
pub fn rgb(_: &mut Vm, args: &mut Args) -> SourceResult<Value> {
- Ok(Value::Color(
- if let Some(string) = args.find::<Spanned<EcoString>>()? {
- match RgbaColor::from_str(&string.v) {
- Ok(color) => color.into(),
- Err(msg) => bail!(string.span, msg),
- }
- } else {
- let Component(r) = args.expect("red component")?;
- let Component(g) = args.expect("green component")?;
- let Component(b) = args.expect("blue component")?;
- let Component(a) = args.eat()?.unwrap_or(Component(255));
- RgbaColor::new(r, g, b, a).into()
- },
- ))
+ Ok(Value::Color(if let Some(string) = args.find::<Spanned<EcoString>>()? {
+ match RgbaColor::from_str(&string.v) {
+ Ok(color) => color.into(),
+ Err(msg) => bail!(string.span, msg),
+ }
+ } else {
+ let Component(r) = args.expect("red component")?;
+ let Component(g) = args.expect("green component")?;
+ let Component(b) = args.expect("blue component")?;
+ let Component(a) = args.eat()?.unwrap_or(Component(255));
+ RgbaColor::new(r, g, b, a).into()
+ }))
}
/// Create a CMYK color.
diff --git a/library/src/base/data.rs b/library/src/base/data.rs
index 1199056f..67ef2f2c 100644
--- a/library/src/base/data.rs
+++ b/library/src/base/data.rs
@@ -81,10 +81,7 @@ fn convert_json(value: serde_json::Value) -> Value {
/// Format the user-facing JSON error message.
fn format_json_error(error: serde_json::Error) -> String {
assert!(error.is_syntax() || error.is_eof());
- format!(
- "failed to parse json file: syntax error in line {}",
- error.line()
- )
+ format!("failed to parse json file: syntax error in line {}", error.line())
}
/// Read structured data from an XML file.
diff --git a/library/src/base/mod.rs b/library/src/base/mod.rs
index bb1c8c51..f1fdd2b9 100644
--- a/library/src/base/mod.rs
+++ b/library/src/base/mod.rs
@@ -5,10 +5,10 @@ mod color;
mod data;
mod string;
-pub use calc::*;
-pub use color::*;
-pub use data::*;
-pub use string::*;
+pub use self::calc::*;
+pub use self::color::*;
+pub use self::data::*;
+pub use self::string::*;
use comemo::Track;
use typst::model::{Eval, Route, Scopes, Vm};
diff --git a/library/src/ext.rs b/library/src/ext.rs
index 6f5b1b67..70b69dce 100644
--- a/library/src/ext.rs
+++ b/library/src/ext.rs
@@ -55,24 +55,16 @@ impl ContentExt for Content {
let mut seq = vec![];
if let Some(above) = above {
seq.push(
- layout::VNode {
- amount: above.into(),
- weak: true,
- generated: true,
- }
- .pack(),
+ layout::VNode { amount: above.into(), weak: true, generated: true }
+ .pack(),
);
}
seq.push(self);
if let Some(below) = below {
seq.push(
- layout::VNode {
- amount: below.into(),
- weak: true,
- generated: true,
- }
- .pack(),
+ layout::VNode { amount: below.into(), weak: true, generated: true }
+ .pack(),
);
}
diff --git a/library/src/graphics/mod.rs b/library/src/graphics/mod.rs
index 34182121..d77dfe36 100644
--- a/library/src/graphics/mod.rs
+++ b/library/src/graphics/mod.rs
@@ -5,7 +5,7 @@ mod image;
mod line;
mod shape;
+pub use self::hide::*;
pub use self::image::*;
-pub use hide::*;
-pub use line::*;
-pub use shape::*;
+pub use self::line::*;
+pub use self::shape::*;
diff --git a/library/src/layout/columns.rs b/library/src/layout/columns.rs
index 8eae922b..2faa6329 100644
--- a/library/src/layout/columns.rs
+++ b/library/src/layout/columns.rs
@@ -74,12 +74,8 @@ impl LayoutBlock for ColumnsNode {
let mut output = Frame::new(Size::new(regions.first.x, height));
let mut cursor = Abs::zero();
- for _ in 0 .. columns {
- let frame = match frames.next() {
- Some(frame) => frame,
- None => break,
- };
-
+ for _ in 0..columns {
+ let Some(frame) = frames.next() else { break };
if !regions.expand.y {
output.size_mut().y.set_max(frame.height());
}
diff --git a/library/src/layout/grid.rs b/library/src/layout/grid.rs
index a6f93ab6..8e1cb7a2 100644
--- a/library/src/layout/grid.rs
+++ b/library/src/layout/grid.rs
@@ -170,13 +170,13 @@ impl<'a> GridLayouter<'a> {
};
// Collect content and gutter columns.
- for x in 0 .. c {
+ for x in 0..c {
cols.push(get_or(tracks.x, x, auto));
cols.push(get_or(gutter.x, x, zero));
}
// Collect content and gutter rows.
- for y in 0 .. r {
+ for y in 0..r {
rows.push(get_or(tracks.y, y, auto));
rows.push(get_or(gutter.y, y, zero));
}
@@ -214,7 +214,7 @@ impl<'a> GridLayouter<'a> {
fn layout(mut self) -> SourceResult<Vec<Frame>> {
self.measure_columns()?;
- for y in 0 .. self.rows.len() {
+ for y in 0..self.rows.len() {
// Skip to next region if current one is full, but only for content
// rows, not for gutter rows.
if y % 2 == 0 && self.regions.is_full() {
@@ -295,7 +295,7 @@ impl<'a> GridLayouter<'a> {
}
let mut resolved = Abs::zero();
- for y in 0 .. self.rows.len() {
+ for y in 0..self.rows.len() {
if let Some(cell) = self.cell(x, y) {
let size = Size::new(available, self.regions.base.y);
let mut pod =
@@ -412,7 +412,7 @@ impl<'a> GridLayouter<'a> {
// eaten up by any fr rows.
if self.fr.is_zero() {
let len = resolved.len();
- for (region, target) in self.regions.iter().zip(&mut resolved[.. len - 1]) {
+ for (region, target) in self.regions.iter().zip(&mut resolved[..len - 1]) {
target.set_max(region.y);
}
}
@@ -502,7 +502,7 @@ impl<'a> GridLayouter<'a> {
// Prepare regions.
let size = Size::new(self.used.x, heights[0]);
let mut pod = Regions::one(size, self.regions.base, Axes::splat(true));
- pod.backlog = heights[1 ..].to_vec();
+ pod.backlog = heights[1..].to_vec();
// Layout the row.
let mut pos = Point::zero();
diff --git a/library/src/layout/mod.rs b/library/src/layout/mod.rs
index 5ab5f42e..e116f159 100644
--- a/library/src/layout/mod.rs
+++ b/library/src/layout/mod.rs
@@ -12,17 +12,17 @@ mod spacing;
mod stack;
mod transform;
-pub use align::*;
-pub use columns::*;
-pub use container::*;
-pub use flow::*;
-pub use grid::*;
-pub use pad::*;
-pub use page::*;
-pub use place::*;
-pub use spacing::*;
-pub use stack::*;
-pub use transform::*;
+pub use self::align::*;
+pub use self::columns::*;
+pub use self::container::*;
+pub use self::flow::*;
+pub use self::grid::*;
+pub use self::pad::*;
+pub use self::page::*;
+pub use self::place::*;
+pub use self::spacing::*;
+pub use self::stack::*;
+pub use self::transform::*;
use std::mem;
@@ -357,18 +357,19 @@ impl<'a> Builder<'a> {
content: &'a Content,
styles: StyleChain<'a>,
) -> SourceResult<bool> {
- if let Some(mut realized) = styles.apply(self.world, Target::Node(content))? {
- let mut map = StyleMap::new();
- let barrier = Barrier::new(content.id());
- map.push(StyleEntry::Barrier(barrier));
- map.push(StyleEntry::Barrier(barrier));
- realized = realized.styled_with_map(map);
- let stored = self.scratch.templates.alloc(realized);
- self.accept(stored, styles)?;
- Ok(true)
- } else {
- Ok(false)
- }
+ let Some(mut realized) = styles.apply(self.world, Target::Node(content))? else {
+ return Ok(false);
+ };
+
+ let mut map = StyleMap::new();
+ let barrier = Barrier::new(content.id());
+ map.push(StyleEntry::Barrier(barrier));
+ map.push(StyleEntry::Barrier(barrier));
+ realized = realized.styled_with_map(map);
+ let stored = self.scratch.templates.alloc(realized);
+ self.accept(stored, styles)?;
+
+ Ok(true)
}
fn styled(
@@ -466,10 +467,7 @@ impl<'a> DocBuilder<'a> {
impl Default for DocBuilder<'_> {
fn default() -> Self {
- Self {
- pages: StyleVecBuilder::new(),
- keep_next: true,
- }
+ Self { pages: StyleVecBuilder::new(), keep_next: true }
}
}
@@ -658,30 +656,25 @@ impl<'a> ListBuilder<'a> {
{
self.items.push(item.clone(), styles);
self.tight &= self.staged.drain(..).all(|(t, _)| !t.is::<ParbreakNode>());
- } else {
- return false;
+ return true;
}
} else if !self.items.is_empty()
&& (content.is::<SpaceNode>() || content.is::<ParbreakNode>())
{
self.staged.push((content, styles));
- } else {
- return false;
+ return true;
}
- true
+ false
}
fn finish(self, parent: &mut Builder<'a>) -> SourceResult<()> {
let (items, shared) = self.items.finish();
- let kind = match items.items().next() {
- Some(item) => item.kind(),
- None => return Ok(()),
- };
+ let Some(item) = items.items().next() else { return Ok(()) };
let tight = self.tight;
let attached = tight && self.attachable;
- let content = match kind {
+ let content = match item.kind() {
LIST => ListNode::<LIST> { tight, attached, items }.pack(),
ENUM => ListNode::<ENUM> { tight, attached, items }.pack(),
DESC | _ => ListNode::<DESC> { tight, attached, items }.pack(),
@@ -765,18 +758,15 @@ impl<'a, T> CollapsingBuilder<'a, T> {
}
if self.last == Last::Weak {
- if let Some(i) =
- self.staged.iter().position(|(prev_item, _, prev_weakness)| {
- prev_weakness.map_or(false, |prev_weakness| {
- weakness < prev_weakness
- || (weakness == prev_weakness && item > *prev_item)
- })
+ let weak = self.staged.iter().position(|(prev_item, _, prev_weakness)| {
+ prev_weakness.map_or(false, |prev_weakness| {
+ weakness < prev_weakness
+ || (weakness == prev_weakness && item > *prev_item)
})
- {
- self.staged.remove(i);
- } else {
- return;
- }
+ });
+
+ let Some(weak) = weak else { return };
+ self.staged.remove(weak);
}
self.staged.push((item, styles, Some(weakness)));
diff --git a/library/src/layout/page.rs b/library/src/layout/page.rs
index 7ce0d633..e1af6ec5 100644
--- a/library/src/layout/page.rs
+++ b/library/src/layout/page.rs
@@ -111,12 +111,7 @@ impl PageNode {
let pw = size.x - pad.left - pad.right;
let py = size.y - pad.bottom;
for (role, marginal, pos, area) in [
- (
- Role::Header,
- header,
- Point::with_x(pad.left),
- Size::new(pw, pad.top),
- ),
+ (Role::Header, header, Point::with_x(pad.left), Size::new(pw, pad.top)),
(
Role::Footer,
footer,
diff --git a/library/src/math/mod.rs b/library/src/math/mod.rs
index e46ba040..dae869ed 100644
--- a/library/src/math/mod.rs
+++ b/library/src/math/mod.rs
@@ -69,12 +69,7 @@ impl LayoutInline for MathNode {
_: &Regions,
styles: StyleChain,
) -> SourceResult<Vec<Frame>> {
- Ok(vec![layout_tex(
- &self.texify(),
- self.display,
- world,
- styles,
- )?])
+ Ok(vec![layout_tex(&self.texify(), self.display, world, styles)?])
}
}
@@ -181,7 +176,7 @@ fn escape_char(c: char) -> EcoString {
/// Trim grouping parenthesis≤.
fn unparen(s: EcoString) -> EcoString {
if s.starts_with('(') && s.ends_with(')') {
- s[1 .. s.len() - 1].into()
+ s[1..s.len() - 1].into()
} else {
s
}
diff --git a/library/src/structure/list.rs b/library/src/structure/list.rs
index d461ef2d..a5e1380a 100644
--- a/library/src/structure/list.rs
+++ b/library/src/structure/list.rs
@@ -95,9 +95,9 @@ impl<const L: ListKind> Show for ListNode<L> {
match name {
"tight" => Some(Value::Bool(self.tight)),
"attached" => Some(Value::Bool(self.attached)),
- "items" => Some(Value::Array(
- self.items.items().map(|item| item.encode()).collect(),
- )),
+ "items" => {
+ Some(Value::Array(self.items.items().map(|item| item.encode()).collect()))
+ }
_ => None,
}
}
@@ -139,11 +139,7 @@ impl<const L: ListKind> Show for ListNode<L> {
ListItem::List(body) => body.as_ref().clone(),
ListItem::Enum(_, body) => body.as_ref().clone(),
ListItem::Desc(item) => Content::sequence(vec![
- HNode {
- amount: (-body_indent).into(),
- weak: false,
- }
- .pack(),
+ HNode { amount: (-body_indent).into(), weak: false }.pack(),
(item.term.clone() + TextNode(':'.into()).pack()).strong(),
SpaceNode.pack(),
item.body.clone(),
diff --git a/library/src/structure/mod.rs b/library/src/structure/mod.rs
index 088d1e6c..8e13f76a 100644
--- a/library/src/structure/mod.rs
+++ b/library/src/structure/mod.rs
@@ -6,8 +6,8 @@ mod list;
mod reference;
mod table;
-pub use doc::*;
-pub use heading::*;
-pub use list::*;
-pub use reference::*;
-pub use table::*;
+pub use self::doc::*;
+pub use self::heading::*;
+pub use self::list::*;
+pub use self::reference::*;
+pub use self::table::*;
diff --git a/library/src/text/deco.rs b/library/src/text/deco.rs
index aaf6cfa8..10f3db38 100644
--- a/library/src/text/deco.rs
+++ b/library/src/text/deco.rs
@@ -56,13 +56,16 @@ impl<const L: DecoLine> Show for DecoNode<L> {
_: Tracked<dyn World>,
styles: StyleChain,
) -> SourceResult<Content> {
- Ok(self.0.clone().styled(TextNode::DECO, Decoration {
- line: L,
- stroke: styles.get(Self::STROKE).unwrap_or_default(),
- offset: styles.get(Self::OFFSET),
- extent: styles.get(Self::EXTENT),
- evade: styles.get(Self::EVADE),
- }))
+ Ok(self.0.clone().styled(
+ TextNode::DECO,
+ Decoration {
+ line: L,
+ stroke: styles.get(Self::STROKE).unwrap_or_default(),
+ offset: styles.get(Self::OFFSET),
+ extent: styles.get(Self::EXTENT),
+ evade: styles.get(Self::EVADE),
+ },
+ ))
}
}
diff --git a/library/src/text/mod.rs b/library/src/text/mod.rs
index 61edacbe..6643f821 100644
--- a/library/src/text/mod.rs
+++ b/library/src/text/mod.rs
@@ -8,12 +8,12 @@ mod raw;
mod shaping;
mod shift;
-pub use deco::*;
-pub use link::*;
-pub use par::*;
-pub use raw::*;
-pub use shaping::*;
-pub use shift::*;
+pub use self::deco::*;
+pub use self::link::*;
+pub use self::par::*;
+pub use self::raw::*;
+pub use self::shaping::*;
+pub use self::shift::*;
use std::borrow::Cow;
@@ -152,7 +152,7 @@ impl TextNode {
if count > 0 {
let mut list = Vec::with_capacity(count);
- for _ in 0 .. count {
+ for _ in 0..count {
list.push(args.find()?.unwrap());
}
diff --git a/library/src/text/par.rs b/library/src/text/par.rs
index 95371e1a..de948a98 100644
--- a/library/src/text/par.rs
+++ b/library/src/text/par.rs
@@ -222,7 +222,7 @@ impl<'a> Preparation<'a> {
let mut cursor = 0;
for item in &self.items {
let end = cursor + item.len();
- if (cursor .. end).contains(&text_offset) {
+ if (cursor..end).contains(&text_offset) {
return Some(item);
}
cursor = end;
@@ -256,7 +256,7 @@ impl<'a> Preparation<'a> {
cursor += len;
}
- (expanded, &self.items[start .. end])
+ (expanded, &self.items[start..end])
}
}
@@ -500,11 +500,14 @@ fn prepare<'a>(
regions: &Regions,
styles: StyleChain<'a>,
) -> SourceResult<Preparation<'a>> {
- let bidi = BidiInfo::new(text, match styles.get(TextNode::DIR) {
- Dir::LTR => Some(BidiLevel::ltr()),
- Dir::RTL => Some(BidiLevel::rtl()),
- _ => None,
- });
+ let bidi = BidiInfo::new(
+ text,
+ match styles.get(TextNode::DIR) {
+ Dir::LTR => Some(BidiLevel::ltr()),
+ Dir::RTL => Some(BidiLevel::rtl()),
+ _ => None,
+ },
+ );
let mut cursor = 0;
let mut items = vec![];
@@ -514,7 +517,7 @@ fn prepare<'a>(
let end = cursor + segment.len();
match segment {
Segment::Text(_) => {
- shape_range(&mut items, world, &bidi, cursor .. end, styles);
+ shape_range(&mut items, world, &bidi, cursor..end, styles);
}
Segment::Spacing(spacing) => match spacing {
Spacing::Relative(v) => {
@@ -574,18 +577,18 @@ fn shape_range<'a>(
let mut cursor = range.start;
// Group by embedding level and script.
- for i in cursor .. range.end {
+ for i in cursor..range.end {
if !bidi.text.is_char_boundary(i) {
continue;
}
let level = bidi.levels[i];
let script =
- bidi.text[i ..].chars().next().map_or(Script::Unknown, |c| c.script());
+ bidi.text[i..].chars().next().map_or(Script::Unknown, |c| c.script());
if level != prev_level || !is_compatible(script, prev_script) {
if cursor < i {
- process(&bidi.text[cursor .. i], prev_level);
+ process(&bidi.text[cursor..i], prev_level);
}
cursor = i;
prev_level = level;
@@ -595,7 +598,7 @@ fn shape_range<'a>(
}
}
- process(&bidi.text[cursor .. range.end], prev_level);
+ process(&bidi.text[cursor..range.end], prev_level);
}
/// Whether this is not a specific script.
@@ -655,7 +658,7 @@ fn linebreak_simple<'a>(
for (end, mandatory, hyphen) in breakpoints(p) {
// Compute the line and its size.
- let mut attempt = line(p, world, start .. end, mandatory, hyphen);
+ let mut attempt = line(p, world, 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 the attempt's end. The
@@ -664,7 +667,7 @@ fn linebreak_simple<'a>(
if let Some((last_attempt, last_end)) = last.take() {
lines.push(last_attempt);
start = last_end;
- attempt = line(p, world, start .. end, mandatory, hyphen);
+ attempt = line(p, world, start..end, mandatory, hyphen);
}
}
@@ -731,7 +734,7 @@ fn linebreak_optimized<'a>(
let mut table = vec![Entry {
pred: 0,
total: 0.0,
- line: line(p, world, 0 .. 0, false, false),
+ line: line(p, world, 0..0, false, false),
}];
let em = p.styles.get(TextNode::SIZE);
@@ -745,7 +748,7 @@ fn linebreak_optimized<'a>(
for (i, pred) in table.iter_mut().enumerate().skip(active) {
// Layout the line.
let start = pred.line.end;
- let attempt = line(p, world, start .. end, mandatory, hyphen);
+ let attempt = line(p, world, start..end, mandatory, hyphen);
// Determine how much the line's spaces would need to be stretched
// to make it the desired width.
@@ -877,7 +880,7 @@ impl Iterator for Breakpoints<'_> {
// Hyphenate the next word.
if self.p.hyphenate != Some(false) {
if let Some(lang) = self.lang(self.offset) {
- let word = &self.p.bidi.text[self.offset .. self.end];
+ let word = &self.p.bidi.text[self.offset..self.end];
let trimmed = word.trim_end_matches(|c: char| !c.is_alphabetic());
if !trimmed.is_empty() {
self.suffix = self.offset + trimmed.len();
@@ -953,7 +956,7 @@ fn line<'a>(
// end of the line.
let base = expanded.end - shaped.text.len();
let start = range.start.max(base);
- let text = &p.bidi.text[start .. range.end];
+ let text = &p.bidi.text[start..range.end];
let trimmed = text.trim_end();
range.end = start + trimmed.len();
@@ -973,7 +976,7 @@ fn line<'a>(
// are no other items in the line.
if hyphen || start + shaped.text.len() > range.end {
if hyphen || start < range.end || before.is_empty() {
- let shifted = start - base .. range.end - base;
+ let shifted = start - base..range.end - base;
let mut reshaped = shaped.reshape(world, shifted);
if hyphen || shy {
reshaped.push_hyphen(world);
@@ -996,7 +999,7 @@ fn line<'a>(
// Reshape if necessary.
if range.start + shaped.text.len() > end {
if range.start < end {
- let shifted = range.start - base .. end - base;
+ let shifted = range.start - base..end - base;
let reshaped = shaped.reshape(world, shifted);
width += reshaped.width;
first = Some(Item::Text(reshaped));
@@ -1168,7 +1171,7 @@ fn commit(
offset += p.align.position(remaining);
}
if width > Abs::zero() {
- for _ in 0 .. (count as usize).min(1000) {
+ for _ in 0..(count as usize).min(1000) {
push(&mut offset, frame.clone());
offset += apart;
}
@@ -1229,7 +1232,7 @@ fn reorder<'a>(line: &'a Line<'a>) -> Vec<&Item<'a>> {
reordered.extend(line.slice(run.clone()));
if levels[run.start].is_rtl() {
- reordered[prev ..].reverse();
+ reordered[prev..].reverse();
}
}
diff --git a/library/src/text/quotes.rs b/library/src/text/quotes.rs
index af10de46..87a965af 100644
--- a/library/src/text/quotes.rs
+++ b/library/src/text/quotes.rs
@@ -117,22 +117,38 @@ impl<'s> Quotes<'s> {
/// The opening quote.
fn open(&self, double: bool) -> &'s str {
- if double { self.double_open } else { self.single_open }
+ if double {
+ self.double_open
+ } else {
+ self.single_open
+ }
}
/// The closing quote.
fn close(&self, double: bool) -> &'s str {
- if double { self.double_close } else { self.single_close }
+ if double {
+ self.double_close
+ } else {
+ self.single_close
+ }
}
/// Which character should be used as a prime.
fn prime(&self, double: bool) -> &'static str {
- if double { "″" } else { "′" }
+ if double {
+ "″"
+ } else {
+ "′"
+ }
}
/// Which character should be used as a fallback quote.
fn fallback(&self, double: bool) -> &'static str {
- if double { "\"" } else { "’" }
+ if double {
+ "\""
+ } else {
+ "’"
+ }
}
}
diff --git a/library/src/text/shaping.rs b/library/src/text/shaping.rs
index bab02eca..b67ce411 100644
--- a/library/src/text/shaping.rs
+++ b/library/src/text/shaping.rs
@@ -98,7 +98,6 @@ impl<'a> ShapedText<'a> {
self.glyphs.as_ref().group_by_key(|g| (g.font.clone(), g.y_offset))
{
let pos = Point::new(offset, top + shift + y_offset.at(self.size));
-
let glyphs = group
.iter()
.map(|glyph| Glyph {
@@ -115,14 +114,7 @@ impl<'a> ShapedText<'a> {
})
.collect();
- let text = Text {
- font,
- size: self.size,
- lang,
- fill,
- glyphs,
- };
-
+ let text = Text { font, size: self.size, lang, fill, glyphs };
let text_layer = frame.layer();
let width = text.width();
@@ -253,7 +245,7 @@ impl<'a> ShapedText<'a> {
let left = self.find_safe_to_break(start, Side::Left)?;
let right = self.find_safe_to_break(end, Side::Right)?;
- Some(&self.glyphs[left .. right])
+ Some(&self.glyphs[left..right])
}
/// Find the glyph offset matching the text index that is most towards the
@@ -274,7 +266,11 @@ impl<'a> ShapedText<'a> {
.glyphs
.binary_search_by(|g| {
let ordering = g.cluster.cmp(&text_index);
- if ltr { ordering } else { ordering.reverse() }
+ if ltr {
+ ordering
+ } else {
+ ordering.reverse()
+ }
})
.ok()?;
@@ -385,9 +381,7 @@ fn shape_segment<'a>(
}
// Extract the font id or shape notdef glyphs if we couldn't find any font.
- let font = if let Some(font) = selection {
- font
- } else {
+ let Some(font) = selection else {
if let Some(font) = ctx.used.first().cloned() {
shape_tofus(ctx, base, text, font);
}
@@ -429,7 +423,7 @@ fn shape_segment<'a>(
y_offset: font.to_em(pos[i].y_offset),
cluster: base + cluster,
safe_to_break: !info.unsafe_to_break(),
- c: text[cluster ..].chars().next().unwrap(),
+ c: text[cluster..].chars().next().unwrap(),
});
} else {
// Determine the source text range for the tofu sequence.
@@ -466,11 +460,11 @@ fn shape_segment<'a>(
.and_then(|last| infos.get(last))
.map_or(text.len(), |info| info.cluster as usize);
- start .. end
+ start..end
};
// Trim half-baked cluster.
- let remove = base + range.start .. base + range.end;
+ let remove = base + range.start..base + range.end;
while ctx.glyphs.last().map_or(false, |g| remove.contains(&g.cluster)) {
ctx.glyphs.pop();
}
diff --git a/library/src/text/shift.rs b/library/src/text/shift.rs
index 856d0f96..1117cc00 100644
--- a/library/src/text/shift.rs
+++ b/library/src/text/shift.rs
@@ -78,10 +78,7 @@ fn search_text(content: &Content, mode: ShiftKind) -> Option<EcoString> {
} else if content.is::<SpaceNode>() {
Some(' '.into())
} else if let Some(text) = content.downcast::<TextNode>() {
- if let Some(sup) = convert_script(&text.0, mode) {
- return Some(sup);
- }
- None
+ convert_script(&text.0, mode)
} else if let Some(seq) = content.downcast::<SequenceNode>() {
let mut full = EcoString::new();
for item in seq.0.iter() {
@@ -138,7 +135,7 @@ fn to_superscript_codepoint(c: char) -> Option<char> {
'1' => 0x00B9,
'2' => 0x00B2,
'3' => 0x00B3,
- '4' ..= '9' => 0x2070 + (c as u32 + 4 - '4' as u32),
+ '4'..='9' => 0x2070 + (c as u32 + 4 - '4' as u32),
'+' => 0x207A,
'-' => 0x207B,
'=' => 0x207C,
@@ -155,7 +152,7 @@ fn to_superscript_codepoint(c: char) -> Option<char> {
fn to_subscript_codepoint(c: char) -> Option<char> {
char::from_u32(match c {
'0' => 0x2080,
- '1' ..= '9' => 0x2080 + (c as u32 - '0' as u32),
+ '1'..='9' => 0x2080 + (c as u32 - '0' as u32),
'+' => 0x208A,
'-' => 0x208B,
'=' => 0x208C,