diff options
Diffstat (limited to '')
-rw-r--r-- | core/src/renderer/null.rs | 2 | ||||
-rw-r--r-- | core/src/text.rs | 22 | ||||
-rw-r--r-- | core/src/widget/text.rs | 21 |
3 files changed, 43 insertions, 2 deletions
diff --git a/core/src/renderer/null.rs b/core/src/renderer/null.rs index 88c58825..f62a4338 100644 --- a/core/src/renderer/null.rs +++ b/core/src/renderer/null.rs @@ -62,6 +62,7 @@ impl text::Renderer for Null { _size: f32, _font: Font, _bounds: Size, + _needs_shaping: bool, ) -> (f32, f32) { (0.0, 20.0) } @@ -74,6 +75,7 @@ impl text::Renderer for Null { _bounds: Size, _point: Point, _nearest_only: bool, + _advanced_shape: bool, ) -> Option<text::Hit> { None } diff --git a/core/src/text.rs b/core/src/text.rs index 4c72abc3..0111cf31 100644 --- a/core/src/text.rs +++ b/core/src/text.rs @@ -27,6 +27,15 @@ pub struct Text<'a, Font> { /// The vertical alignment of the [`Text`]. pub vertical_alignment: alignment::Vertical, + + /// Whether the [`Text`] needs advanced shaping and font fallback. + /// + /// You will need to enable this flag if the text contains a complex + /// script, the font used needs it, and/or multiple fonts in your system + /// may be needed to display all of the glyphs. + /// + /// Advanced shaping is expensive! You should only enable it when necessary. + pub advanced_shape: bool, } /// The result of hit testing on text. @@ -77,11 +86,19 @@ pub trait Renderer: crate::Renderer { size: f32, font: Self::Font, bounds: Size, + advanced_shape: bool, ) -> (f32, f32); /// Measures the width of the text as if it were laid out in a single line. - fn measure_width(&self, content: &str, size: f32, font: Self::Font) -> f32 { - let (width, _) = self.measure(content, size, font, Size::INFINITY); + fn measure_width( + &self, + content: &str, + size: f32, + font: Self::Font, + advanced_shape: bool, + ) -> f32 { + let (width, _) = + self.measure(content, size, font, Size::INFINITY, advanced_shape); width } @@ -101,6 +118,7 @@ pub trait Renderer: crate::Renderer { bounds: Size, point: Point, nearest_only: bool, + advanced_shape: bool, ) -> Option<Hit>; /// Loads a [`Self::Font`] from its bytes. diff --git a/core/src/widget/text.rs b/core/src/widget/text.rs index 3193ba84..2df4556d 100644 --- a/core/src/widget/text.rs +++ b/core/src/widget/text.rs @@ -25,6 +25,7 @@ where vertical_alignment: alignment::Vertical, font: Option<Renderer::Font>, style: <Renderer::Theme as StyleSheet>::Style, + advanced_shape: bool, } impl<'a, Renderer> Text<'a, Renderer> @@ -43,6 +44,7 @@ where horizontal_alignment: alignment::Horizontal::Left, vertical_alignment: alignment::Vertical::Top, style: Default::default(), + advanced_shape: false, } } @@ -98,6 +100,20 @@ where self.vertical_alignment = alignment; self } + + /// Enables advanced text shaping and font fallback for the [`Text`]. + /// + /// You will need to enable this if the text contains a complex script, the + /// font used needs it, and/or multiple fonts in your system may be needed + /// to display all of the glyphs. + /// + /// If your text isn't displaying properly, try enabling this! + /// + /// Advanced shaping is expensive! You should only enable it when necessary. + pub fn advanced_shape(mut self) -> Self { + self.advanced_shape = true; + self + } } impl<'a, Message, Renderer> Widget<Message, Renderer> for Text<'a, Renderer> @@ -129,6 +145,7 @@ where size, self.font.unwrap_or_else(|| renderer.default_font()), bounds, + self.advanced_shape, ); let size = limits.resolve(Size::new(width, height)); @@ -156,6 +173,7 @@ where theme.appearance(self.style.clone()), self.horizontal_alignment, self.vertical_alignment, + self.advanced_shape, ); } } @@ -180,6 +198,7 @@ pub fn draw<Renderer>( appearance: Appearance, horizontal_alignment: alignment::Horizontal, vertical_alignment: alignment::Vertical, + advanced_shape: bool, ) where Renderer: text::Renderer, { @@ -205,6 +224,7 @@ pub fn draw<Renderer>( font: font.unwrap_or_else(|| renderer.default_font()), horizontal_alignment, vertical_alignment, + advanced_shape, }); } @@ -234,6 +254,7 @@ where vertical_alignment: self.vertical_alignment, font: self.font, style: self.style.clone(), + advanced_shape: self.advanced_shape, } } } |