summaryrefslogtreecommitdiff
path: root/src/library
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2022-05-19 13:11:00 +0200
committerLaurenz <laurmaedje@gmail.com>2022-05-19 13:11:00 +0200
commit08554380f8813d4105c13abacb08fff8e5a0f318 (patch)
treea03df3fecd9d5ec774a087f8f2a9540b88d9f815 /src/library
parent5a7c901f2195a746e0982723b959c07431844077 (diff)
Fix generated strong and emphasized text
Diffstat (limited to 'src/library')
-rw-r--r--src/library/structure/heading.rs6
-rw-r--r--src/library/text/mod.rs12
-rw-r--r--src/library/text/raw.rs11
-rw-r--r--src/library/text/shaping.rs4
4 files changed, 16 insertions, 17 deletions
diff --git a/src/library/structure/heading.rs b/src/library/structure/heading.rs
index 70589de0..1cfcb6d0 100644
--- a/src/library/structure/heading.rs
+++ b/src/library/structure/heading.rs
@@ -1,6 +1,6 @@
use crate::library::layout::BlockSpacing;
use crate::library::prelude::*;
-use crate::library::text::{FontFamily, TextNode, TextSize, Toggle};
+use crate::library::text::{FontFamily, TextNode, TextSize};
/// A section heading.
#[derive(Debug, Hash)]
@@ -103,11 +103,11 @@ impl Show for HeadingNode {
}
if resolve!(Self::STRONG) {
- map.set(TextNode::STRONG, Toggle);
+ realized = realized.strong();
}
if resolve!(Self::EMPH) {
- map.set(TextNode::EMPH, Toggle);
+ realized = realized.emph();
}
if resolve!(Self::UNDERLINE) {
diff --git a/src/library/text/mod.rs b/src/library/text/mod.rs
index ae7024e5..1b83b0f4 100644
--- a/src/library/text/mod.rs
+++ b/src/library/text/mod.rs
@@ -110,10 +110,10 @@ impl TextNode {
/// Whether the font weight should be increased by 300.
#[property(skip, fold)]
- pub const STRONG: Toggle = false;
+ pub const BOLD: Toggle = false;
/// Whether the the font style should be inverted.
#[property(skip, fold)]
- pub const EMPH: Toggle = false;
+ pub const ITALIC: Toggle = false;
/// A case transformation that should be applied to the text.
#[property(skip)]
pub const CASE: Option<Case> = None;
@@ -508,7 +508,7 @@ impl Fold for Decoration {
}
}
-/// Strong text, rendered in boldface.
+/// Strong text, rendered in boldface by default.
#[derive(Debug, Hash)]
pub struct StrongNode(pub Content);
@@ -529,11 +529,11 @@ impl Show for StrongNode {
}
fn realize(&self, _: &mut Context, _: StyleChain) -> TypResult<Content> {
- Ok(self.0.clone().styled(TextNode::STRONG, Toggle))
+ Ok(self.0.clone().styled(TextNode::BOLD, Toggle))
}
}
-/// Emphasized text, rendered with an italic face.
+/// Emphasized text, rendered with an italic face by default.
#[derive(Debug, Hash)]
pub struct EmphNode(pub Content);
@@ -554,6 +554,6 @@ impl Show for EmphNode {
}
fn realize(&self, _: &mut Context, _: StyleChain) -> TypResult<Content> {
- Ok(self.0.clone().styled(TextNode::EMPH, Toggle))
+ Ok(self.0.clone().styled(TextNode::ITALIC, Toggle))
}
}
diff --git a/src/library/text/raw.rs b/src/library/text/raw.rs
index 9db9c443..75964efe 100644
--- a/src/library/text/raw.rs
+++ b/src/library/text/raw.rs
@@ -7,7 +7,7 @@ use syntect::highlighting::{
};
use syntect::parsing::SyntaxSet;
-use super::{FontFamily, Hyphenate, TextNode, Toggle};
+use super::{FontFamily, Hyphenate, TextNode};
use crate::library::layout::BlockSpacing;
use crate::library::prelude::*;
use crate::source::SourceId;
@@ -137,27 +137,26 @@ impl Show for RawNode {
/// Style a piece of text with a syntect style.
fn styled(piece: &str, foreground: Paint, style: Style) -> Content {
- let mut styles = StyleMap::new();
let mut body = Content::Text(piece.into());
let paint = style.foreground.into();
if paint != foreground {
- styles.set(TextNode::FILL, paint);
+ body = body.styled(TextNode::FILL, paint);
}
if style.font_style.contains(FontStyle::BOLD) {
- styles.set(TextNode::STRONG, Toggle);
+ body = body.strong();
}
if style.font_style.contains(FontStyle::ITALIC) {
- styles.set(TextNode::EMPH, Toggle);
+ body = body.emph();
}
if style.font_style.contains(FontStyle::UNDERLINE) {
body = body.underlined();
}
- body.styled_with_map(styles)
+ body
}
/// The lazily-loaded syntect syntax definitions.
diff --git a/src/library/text/shaping.rs b/src/library/text/shaping.rs
index 29973bc7..68499a01 100644
--- a/src/library/text/shaping.rs
+++ b/src/library/text/shaping.rs
@@ -517,11 +517,11 @@ pub fn variant(styles: StyleChain) -> FontVariant {
styles.get(TextNode::STRETCH),
);
- if styles.get(TextNode::STRONG) {
+ if styles.get(TextNode::BOLD) {
variant.weight = variant.weight.thicken(300);
}
- if styles.get(TextNode::EMPH) {
+ if styles.get(TextNode::ITALIC) {
variant.style = match variant.style {
FontStyle::Normal => FontStyle::Italic,
FontStyle::Italic => FontStyle::Normal,