diff options
| author | Laurenz <laurmaedje@gmail.com> | 2022-11-04 09:30:44 +0100 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2022-11-04 11:38:09 +0100 |
| commit | eb951c008beea502042db4a3a0e8d1f8b51f6f52 (patch) | |
| tree | 9856ee4ed0222222669de10e616a580b2a60135e /library/src/text | |
| parent | 33928a00dc58250e24da1dae4e5db17e7b598d70 (diff) | |
Style changes
Diffstat (limited to 'library/src/text')
| -rw-r--r-- | library/src/text/deco.rs | 17 | ||||
| -rw-r--r-- | library/src/text/mod.rs | 14 | ||||
| -rw-r--r-- | library/src/text/par.rs | 47 | ||||
| -rw-r--r-- | library/src/text/quotes.rs | 24 | ||||
| -rw-r--r-- | library/src/text/shaping.rs | 28 | ||||
| -rw-r--r-- | library/src/text/shift.rs | 9 |
6 files changed, 76 insertions, 63 deletions
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, |
