Skip to content

Commit 755da0b

Browse files
Introduce grapheme replacement style for password fields
1 parent b985214 commit 755da0b

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

parley/src/layout/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ use accesskit::{Node, NodeId, Role, TextDirection, TreeUpdate};
2222
use alignment::unjustify;
2323
#[cfg(feature = "accesskit")]
2424
use alloc::vec::Vec;
25+
use alloc::{string::String, sync::Arc};
2526
use core::{cmp::Ordering, ops::Range};
2627
use data::{ClusterData, LayoutData, LayoutItem, LayoutItemKind, LineData, LineItemData, RunData};
2728
#[cfg(feature = "accesskit")]
@@ -314,6 +315,8 @@ pub struct Style<B: Brush> {
314315
pub(crate) line_height: LayoutLineHeight,
315316
/// Per-cluster overflow-wrap setting
316317
pub(crate) overflow_wrap: OverflowWrap,
318+
/// Replace graphemes with another grapheme.
319+
pub(crate) grapheme_replacement: Option<Arc<String>>,
317320
}
318321

319322
/// Underline or strikethrough decoration.

parley/src/resolve/mod.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ pub(crate) mod tree;
88

99
pub(crate) use range::RangedStyleBuilder;
1010

11-
use alloc::{vec, vec::Vec};
11+
use alloc::{string::String, sync::Arc, vec, vec::Vec};
1212

1313
use super::style::{
1414
Brush, FontFamily, FontFeature, FontSettings, FontStack, FontStyle, FontVariation, FontWeight,
@@ -157,6 +157,7 @@ impl ResolveContext {
157157
StyleProperty::LetterSpacing(value) => LetterSpacing(*value * scale),
158158
StyleProperty::WordBreak(value) => WordBreak(*value),
159159
StyleProperty::OverflowWrap(value) => OverflowWrap(*value),
160+
StyleProperty::GraphemeReplacement(value) => GraphemeReplacement(value.clone()),
160161
}
161162
}
162163

@@ -193,6 +194,7 @@ impl ResolveContext {
193194
letter_spacing: raw_style.letter_spacing * scale,
194195
word_break: raw_style.word_break,
195196
overflow_wrap: raw_style.overflow_wrap,
197+
grapheme_replacement: raw_style.grapheme_replacement.clone(),
196198
}
197199
}
198200

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

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

416422
impl<B: Brush> ResolvedStyle<B> {
@@ -440,6 +446,7 @@ impl<B: Brush> ResolvedStyle<B> {
440446
LetterSpacing(value) => self.letter_spacing = value,
441447
WordBreak(value) => self.word_break = value,
442448
OverflowWrap(value) => self.overflow_wrap = value,
449+
GraphemeReplacement(value) => self.grapheme_replacement = value,
443450
}
444451
}
445452

@@ -468,6 +475,7 @@ impl<B: Brush> ResolvedStyle<B> {
468475
LetterSpacing(value) => nearly_eq(self.letter_spacing, *value),
469476
WordBreak(value) => self.word_break == *value,
470477
OverflowWrap(value) => self.overflow_wrap == *value,
478+
GraphemeReplacement(value) => self.grapheme_replacement == *value,
471479
}
472480
}
473481

@@ -478,6 +486,7 @@ impl<B: Brush> ResolvedStyle<B> {
478486
strikethrough: self.strikethrough.as_layout_decoration(&self.brush),
479487
line_height: self.line_height.resolve(self.font_size),
480488
overflow_wrap: self.overflow_wrap,
489+
grapheme_replacement: self.grapheme_replacement.clone(),
481490
}
482491
}
483492
}

parley/src/style/mod.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ mod brush;
77
mod font;
88
mod styleset;
99

10-
use alloc::borrow::Cow;
10+
use alloc::{borrow::Cow, string::String, sync::Arc};
1111

1212
pub use brush::*;
1313
pub use font::{
@@ -140,6 +140,8 @@ pub enum StyleProperty<'a, B: Brush> {
140140
WordBreak(WordBreakStrength),
141141
/// Control over "emergency" line-breaking.
142142
OverflowWrap(OverflowWrap),
143+
/// Replace graphemes with another grapheme.
144+
GraphemeReplacement(Option<Arc<String>>),
143145
}
144146

145147
/// Unresolved styles.
@@ -189,6 +191,8 @@ pub struct TextStyle<'a, B: Brush> {
189191
pub word_break: WordBreakStrength,
190192
/// Control over "emergency" line-breaking.
191193
pub overflow_wrap: OverflowWrap,
194+
/// Replace graphemes with another grapheme.
195+
pub grapheme_replacement: Option<Arc<String>>,
192196
}
193197

194198
impl<B: Brush> Default for TextStyle<'_, B> {
@@ -216,6 +220,7 @@ impl<B: Brush> Default for TextStyle<'_, B> {
216220
letter_spacing: Default::default(),
217221
word_break: Default::default(),
218222
overflow_wrap: Default::default(),
223+
grapheme_replacement: Default::default(),
219224
}
220225
}
221226
}

0 commit comments

Comments
 (0)