Rename bold/italic to strong/emph ✏

This commit is contained in:
Laurenz 2020-10-03 11:18:25 +02:00
parent 730715c064
commit 75e6dbfbe6
7 changed files with 33 additions and 35 deletions

View File

@ -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,

View File

@ -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;

View File

@ -62,8 +62,8 @@ fn node(p: &mut Parser, at_start: bool) -> Option<Spanned<SynNode>> {
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 {

View File

@ -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]]" => );

View File

@ -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,

View File

@ -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),

View File

@ -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.