From 75e6dbfbe6cbd3c3245c825627881a16bfbd6c5d Mon Sep 17 00:00:00 2001 From: Laurenz Date: Sat, 3 Oct 2020 11:18:25 +0200 Subject: [PATCH] =?UTF-8?q?Rename=20bold/italic=20to=20strong/emph=20?= =?UTF-8?q?=E2=9C=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/layout/shaping.rs | 6 +++--- src/layout/tree.rs | 22 +++++++++++----------- src/parse/mod.rs | 4 ++-- src/parse/tests.rs | 8 +++----- src/style.rs | 12 ++++++------ src/syntax/ast/tree.rs | 8 ++++---- src/syntax/mod.rs | 8 ++++---- 7 files changed, 33 insertions(+), 35 deletions(-) diff --git a/src/layout/shaping.rs b/src/layout/shaping.rs index 115a23e25..0f42d4bb5 100644 --- a/src/layout/shaping.rs +++ b/src/layout/shaping.rs @@ -14,7 +14,7 @@ use crate::font::FontLoader; use crate::geom::Size; use crate::style::TextStyle; -/// Layouts text into a box. +/// Shape text into a box. pub async fn shape(text: &str, ctx: ShapeOptions<'_>) -> BoxLayout { Shaper::new(text, ctx).layout().await } @@ -115,11 +115,11 @@ impl<'a> Shaper<'a> { async fn select_font(&mut self, c: char) -> Option<(FaceId, GlyphId, f64)> { let mut variant = self.opts.style.variant; - if self.opts.style.bolder { + if self.opts.style.strong { variant.weight = variant.weight.thicken(300); } - if self.opts.style.italic { + if self.opts.style.emph { variant.style = match variant.style { FontStyle::Normal => FontStyle::Italic, FontStyle::Italic => FontStyle::Normal, diff --git a/src/layout/tree.rs b/src/layout/tree.rs index 14359b86d..b43ef089e 100644 --- a/src/layout/tree.rs +++ b/src/layout/tree.rs @@ -60,24 +60,24 @@ impl<'a> TreeLayouter<'a> { match &node.v { SynNode::Space => self.layout_space(), SynNode::Text(text) => { - if self.style.text.italic { - decorate(self, Decoration::Italic); + if self.style.text.emph { + decorate(self, Decoration::Emph); } - if self.style.text.bolder { - decorate(self, Decoration::Bold); + if self.style.text.strong { + decorate(self, Decoration::Strong); } self.layout_text(text).await; } SynNode::Linebreak => self.layouter.finish_line(), SynNode::Parbreak => self.layout_parbreak(), - SynNode::ToggleItalic => { - self.style.text.italic = !self.style.text.italic; - decorate(self, Decoration::Italic); + SynNode::Emph => { + self.style.text.emph = !self.style.text.emph; + decorate(self, Decoration::Emph); } - SynNode::ToggleBolder => { - self.style.text.bolder = !self.style.text.bolder; - decorate(self, Decoration::Bold); + SynNode::Strong => { + self.style.text.strong = !self.style.text.strong; + decorate(self, Decoration::Strong); } SynNode::Heading(heading) => self.layout_heading(heading).await, @@ -116,7 +116,7 @@ impl<'a> TreeLayouter<'a> { async fn layout_heading(&mut self, heading: &NodeHeading) { let style = self.style.text.clone(); self.style.text.font_scale *= 1.5 - 0.1 * heading.level.v as f64; - self.style.text.bolder = true; + self.style.text.strong = true; self.layout_parbreak(); self.layout_tree(&heading.contents).await; diff --git a/src/parse/mod.rs b/src/parse/mod.rs index 395090af2..42102bf54 100644 --- a/src/parse/mod.rs +++ b/src/parse/mod.rs @@ -62,8 +62,8 @@ fn node(p: &mut Parser, at_start: bool) -> Option> { Token::LineComment(_) | Token::BlockComment(_) => return None, // Markup. - Token::Star => SynNode::ToggleBolder, - Token::Underscore => SynNode::ToggleItalic, + Token::Star => SynNode::Strong, + Token::Underscore => SynNode::Emph, Token::Backslash => SynNode::Linebreak, Token::Hashtag => { if at_start { diff --git a/src/parse/tests.rs b/src/parse/tests.rs index a1b1fb13c..feff2b9ab 100644 --- a/src/parse/tests.rs +++ b/src/parse/tests.rs @@ -13,9 +13,7 @@ use crate::syntax::*; // ------------------------------ Construct Syntax Nodes ------------------------------ // use Decoration::*; -use SynNode::{ - Linebreak as L, Parbreak as P, Space as S, ToggleBolder as B, ToggleItalic as I, -}; +use SynNode::{Emph as E, Linebreak as L, Parbreak as P, Space as S, Strong as B}; fn T(text: &str) -> SynNode { SynNode::Text(text.to_string()) @@ -230,7 +228,7 @@ fn test_parse_simple_nodes() { t!("" => ); t!("hi" => T("hi")); t!("*hi" => B, T("hi")); - t!("hi_" => T("hi"), I); + t!("hi_" => T("hi"), E); t!("hi you" => T("hi"), S, T("you")); t!("special~name" => T("special"), T("\u{00A0}"), T("name")); t!("special\\~name" => T("special"), T("~"), T("name")); @@ -415,7 +413,7 @@ fn test_parse_values() { v!("\"a\n[]\\\"string\"" => Str("a\n[]\"string")); // Content. - v!("{_hi_}" => Tree![I, T("hi"), I]); + v!("{_hi_}" => Tree![E, T("hi"), E]); e!("[val: {_hi_}]" => ); v!("[hi]" => Tree![F!("hi")]); e!("[val: [hi]]" => ); diff --git a/src/style.rs b/src/style.rs index 9402f11d1..7da7f0c67 100644 --- a/src/style.rs +++ b/src/style.rs @@ -22,12 +22,12 @@ pub struct TextStyle { pub fallback: FallbackTree, /// The selected font variant. pub variant: FontVariant, - /// Whether the bolder toggle is active or inactive. This determines + /// Whether the strong toggle is active or inactive. This determines /// whether the next `*` adds or removes font weight. - pub bolder: bool, - /// Whether the italic toggle is active or inactive. This determines + pub strong: bool, + /// Whether the emphasis toggle is active or inactive. This determines /// whether the next `_` makes italic or non-italic. - pub italic: bool, + pub emph: bool, /// The base font size. pub base_font_size: f64, /// The font scale to apply on the base font size. @@ -83,8 +83,8 @@ impl Default for TextStyle { weight: FontWeight::REGULAR, stretch: FontStretch::Normal, }, - bolder: false, - italic: false, + strong: false, + emph: false, base_font_size: Length::pt(11.0).as_raw(), font_scale: 1.0, word_spacing_scale: 0.25, diff --git a/src/syntax/ast/tree.rs b/src/syntax/ast/tree.rs index 03aa34396..c5dc4c65b 100644 --- a/src/syntax/ast/tree.rs +++ b/src/syntax/ast/tree.rs @@ -18,10 +18,10 @@ pub enum SynNode { Linebreak, /// A paragraph break. Parbreak, - /// Italics were enabled / disabled. - ToggleItalic, - /// Bolder was enabled / disabled. - ToggleBolder, + /// Emphasized text was enabled / disabled. + Emph, + /// Strong text was enabled / disabled. + Strong, /// A section heading. Heading(NodeHeading), diff --git a/src/syntax/mod.rs b/src/syntax/mod.rs index 98e1b4d74..3ac5176b6 100644 --- a/src/syntax/mod.rs +++ b/src/syntax/mod.rs @@ -16,10 +16,10 @@ pub use token::*; #[cfg_attr(feature = "serialize", derive(serde::Serialize))] #[cfg_attr(feature = "serialize", serde(rename_all = "camelCase"))] pub enum Decoration { - /// Text in italics. - Italic, - /// Text in bold. - Bold, + /// Emphasized text. + Emph, + /// Strong text. + Strong, /// A valid, successfully resolved name. Resolved, /// An invalid, unresolved name.