// SPDX-License-Identifier: MIT OR Apache-2.0 #![allow(clippy::too_many_arguments)] #[cfg(not(feature = "std"))] use alloc::vec::Vec; use core::cmp::{max, min}; use core::fmt; use core::mem; use core::ops::Range; use unicode_script::{Script, UnicodeScript}; use unicode_segmentation::UnicodeSegmentation; use crate::fallback::FontFallbackIter; use crate::{ math, Align, AttrsList, CacheKeyFlags, Color, Font, FontSystem, LayoutGlyph, LayoutLine, Metrics, Wrap, }; /// The shaping strategy of some text. #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] pub enum Shaping { /// Basic shaping with no font fallback. /// /// This shaping strategy is very cheap, but it will not display complex /// scripts properly nor try to find missing glyphs in your system fonts. /// /// You should use this strategy when you have complete control of the text /// and the font you are displaying in your application. #[cfg(feature = "swash")] Basic, /// Advanced text shaping and font fallback. /// /// You will need to enable this strategy 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, } impl Shaping { fn run( self, glyphs: &mut Vec, font_system: &mut FontSystem, line: &str, attrs_list: &AttrsList, start_run: usize, end_run: usize, span_rtl: bool, ) { match self { #[cfg(feature = "swash")] Self::Basic => shape_skip(font_system, glyphs, line, attrs_list, start_run, end_run), #[cfg(not(feature = "shape-run-cache"))] Self::Advanced => shape_run( glyphs, font_system, line, attrs_list, start_run, end_run, span_rtl, ), #[cfg(feature = "shape-run-cache")] Self::Advanced => shape_run_cached( glyphs, font_system, line, attrs_list, start_run, end_run, span_rtl, ), } } } /// A set of buffers containing allocations for shaped text. #[derive(Default)] pub struct ShapeBuffer { /// Buffer for holding unicode text. rustybuzz_buffer: Option, /// Temporary buffers for scripts. scripts: Vec