Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions parley/src/layout/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use accesskit::{Node, NodeId, Role, TextDirection, TreeUpdate};
use alignment::unjustify;
#[cfg(feature = "accesskit")]
use alloc::vec::Vec;
use alloc::{string::String, sync::Arc};
use core::{cmp::Ordering, ops::Range};
use data::{ClusterData, LayoutData, LayoutItem, LayoutItemKind, LineData, LineItemData, RunData};
#[cfg(feature = "accesskit")]
Expand Down Expand Up @@ -314,6 +315,8 @@ pub struct Style<B: Brush> {
pub(crate) line_height: LayoutLineHeight,
/// Per-cluster overflow-wrap setting
pub(crate) overflow_wrap: OverflowWrap,
/// Replace graphemes with another grapheme.
pub(crate) grapheme_replacement: Option<Arc<String>>,
}

/// Underline or strikethrough decoration.
Expand Down
11 changes: 10 additions & 1 deletion parley/src/resolve/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pub(crate) mod tree;

pub(crate) use range::RangedStyleBuilder;

use alloc::{vec, vec::Vec};
use alloc::{string::String, sync::Arc, vec, vec::Vec};

use super::style::{
Brush, FontFamily, FontFeature, FontSettings, FontStack, FontStyle, FontVariation, FontWeight,
Expand Down Expand Up @@ -157,6 +157,7 @@ impl ResolveContext {
StyleProperty::LetterSpacing(value) => LetterSpacing(*value * scale),
StyleProperty::WordBreak(value) => WordBreak(*value),
StyleProperty::OverflowWrap(value) => OverflowWrap(*value),
StyleProperty::GraphemeReplacement(value) => GraphemeReplacement(value.clone()),
}
}

Expand Down Expand Up @@ -193,6 +194,7 @@ impl ResolveContext {
letter_spacing: raw_style.letter_spacing * scale,
word_break: raw_style.word_break,
overflow_wrap: raw_style.overflow_wrap,
grapheme_replacement: raw_style.grapheme_replacement.clone(),
}
}

Expand Down Expand Up @@ -374,6 +376,8 @@ pub(crate) enum ResolvedProperty<B: Brush> {
WordBreak(WordBreakStrength),
/// Control over "emergency" line-breaking.
OverflowWrap(OverflowWrap),
/// Replace graphemes with another grapheme.
GraphemeReplacement(Option<Arc<String>>),
}

/// Flattened group of style properties.
Expand Down Expand Up @@ -411,6 +415,8 @@ pub(crate) struct ResolvedStyle<B: Brush> {
pub(crate) word_break: WordBreakStrength,
/// Control over "emergency" line-breaking.
pub(crate) overflow_wrap: OverflowWrap,
/// Replace graphemes with another grapheme.
pub(crate) grapheme_replacement: Option<Arc<String>>,
}

impl<B: Brush> ResolvedStyle<B> {
Expand Down Expand Up @@ -440,6 +446,7 @@ impl<B: Brush> ResolvedStyle<B> {
LetterSpacing(value) => self.letter_spacing = value,
WordBreak(value) => self.word_break = value,
OverflowWrap(value) => self.overflow_wrap = value,
GraphemeReplacement(value) => self.grapheme_replacement = value,
}
}

Expand Down Expand Up @@ -468,6 +475,7 @@ impl<B: Brush> ResolvedStyle<B> {
LetterSpacing(value) => nearly_eq(self.letter_spacing, *value),
WordBreak(value) => self.word_break == *value,
OverflowWrap(value) => self.overflow_wrap == *value,
GraphemeReplacement(value) => self.grapheme_replacement == *value,
}
}

Expand All @@ -478,6 +486,7 @@ impl<B: Brush> ResolvedStyle<B> {
strikethrough: self.strikethrough.as_layout_decoration(&self.brush),
line_height: self.line_height.resolve(self.font_size),
overflow_wrap: self.overflow_wrap,
grapheme_replacement: self.grapheme_replacement.clone(),
}
}
}
Expand Down
7 changes: 6 additions & 1 deletion parley/src/style/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ mod brush;
mod font;
mod styleset;

use alloc::borrow::Cow;
use alloc::{borrow::Cow, string::String, sync::Arc};

pub use brush::*;
pub use font::{
Expand Down Expand Up @@ -140,6 +140,8 @@ pub enum StyleProperty<'a, B: Brush> {
WordBreak(WordBreakStrength),
/// Control over "emergency" line-breaking.
OverflowWrap(OverflowWrap),
/// Replace graphemes with another grapheme.
GraphemeReplacement(Option<Arc<String>>),
}

/// Unresolved styles.
Expand Down Expand Up @@ -189,6 +191,8 @@ pub struct TextStyle<'a, B: Brush> {
pub word_break: WordBreakStrength,
/// Control over "emergency" line-breaking.
pub overflow_wrap: OverflowWrap,
/// Replace graphemes with another grapheme.
pub grapheme_replacement: Option<Arc<String>>,
}

impl<B: Brush> Default for TextStyle<'_, B> {
Expand Down Expand Up @@ -216,6 +220,7 @@ impl<B: Brush> Default for TextStyle<'_, B> {
letter_spacing: Default::default(),
word_break: Default::default(),
overflow_wrap: Default::default(),
grapheme_replacement: Default::default(),
}
}
}
Expand Down
1 change: 1 addition & 0 deletions parley/src/tests/test_builders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ fn create_root_style() -> TextStyle<'static, ColorBrush> {
letter_spacing: 1.5,
word_break: WordBreakStrength::BreakAll,
overflow_wrap: OverflowWrap::Anywhere,
grapheme_replacement: None, // TODO: Set a non-default value
}
}

Expand Down
Loading