@@ -11,9 +11,10 @@ use super::TextDisplay;
1111use crate :: conv:: { to_u32, to_usize} ;
1212use crate :: fonts:: { self , FontSelector , NoFontMatch } ;
1313use crate :: format:: FormattableText ;
14- use crate :: { Direction , Range , script_to_fontique, shaper} ;
15- use swash:: text:: LineBreak as LB ;
16- use swash:: text:: cluster:: Boundary ;
14+ use crate :: util:: ends_with_hard_break;
15+ use crate :: { Direction , Range , shaper} ;
16+ use icu_properties:: { CodePointMapData , props:: Script } ;
17+ use icu_segmenter:: LineSegmenter ;
1718use unicode_bidi:: { BidiInfo , LTR_LEVEL , RTL_LEVEL } ;
1819
1920#[ derive( Clone , Copy , Debug , PartialEq ) ]
@@ -195,14 +196,17 @@ impl TextDisplay {
195196 text,
196197 dpem,
197198 level : levels. first ( ) . cloned ( ) . unwrap_or ( LTR_LEVEL ) ,
198- script : UNKNOWN_SCRIPT ,
199+ script : Script :: Unknown . into ( ) ,
199200 } ;
200201
201202 let mut start = 0 ;
202203 let mut breaks = Default :: default ( ) ;
203204
204- let mut analyzer = swash:: text:: analyze ( text. chars ( ) ) ;
205- let mut last_props = None ;
205+ // TODO: allow segmenter configuration
206+ let segmenter = LineSegmenter :: new_auto ( Default :: default ( ) ) ;
207+ let mut break_iter = segmenter. segment_str ( text) ;
208+ let mut next_break = break_iter. next ( ) ;
209+
206210 let mut first_real = None ;
207211
208212 let mut last_is_control = false ;
@@ -218,13 +222,15 @@ impl TextDisplay {
218222 let is_htab = c == '\t' ;
219223 let control_break = is_htab || ( last_is_control && !is_control) ;
220224
221- let ( props, boundary) = analyzer. next ( ) . unwrap ( ) ;
222- last_props = Some ( props) ;
225+ let script = CodePointMapData :: < Script > :: new ( ) . get ( c) ;
223226
224- // Forcibly end the line?
225- let hard_break = boundary == Boundary :: Mandatory ;
226227 // Is wrapping allowed at this position?
227- let is_break = hard_break || boundary == Boundary :: Line ;
228+ let is_break = next_break == Some ( index) ;
229+ // Forcibly end the line?
230+ let hard_break = is_break && ends_with_hard_break ( & text[ ..index] ) ;
231+ if is_break {
232+ next_break = break_iter. next ( ) ;
233+ }
228234
229235 // Force end of current run?
230236 let bidi_break = levels[ index] != input. level ;
@@ -238,14 +244,12 @@ impl TextDisplay {
238244 }
239245
240246 let mut new_script = None ;
241- if props . script ( ) . is_real ( ) {
247+ if ! matches ! ( script , Script :: Common | Script :: Unknown | Script :: Inherited ) {
242248 if first_real. is_none ( ) && !c. is_control ( ) {
243249 first_real = Some ( c) ;
244250 }
245- let script = script_to_fontique ( props. script ( ) ) ;
246- if input. script == UNKNOWN_SCRIPT {
247- input. script = script;
248- } else if script != UNKNOWN_SCRIPT && script != input. script {
251+ let script = script. into ( ) ;
252+ if script != input. script {
249253 new_script = Some ( script) ;
250254 }
251255 }
@@ -265,7 +269,7 @@ impl TextDisplay {
265269 start = index;
266270 non_control_end = index;
267271 input. level = levels[ index] ;
268- input. script = UNKNOWN_SCRIPT ;
272+ input. script = Script :: Unknown . into ( ) ;
269273 breaks = Default :: default ( ) ;
270274 } else if is_break && !is_control {
271275 // We do break runs when hitting control chars, but only when
@@ -281,10 +285,8 @@ impl TextDisplay {
281285 }
282286 }
283287
284- debug_assert ! ( analyzer. next( ) . is_none( ) ) ;
285- let hard_break = last_props
286- . map ( |props| matches ! ( props. line_break( ) , LB :: BK | LB :: CR | LB :: LF | LB :: NL ) )
287- . unwrap_or ( false ) ;
288+ let is_break = next_break == Some ( text. len ( ) ) ;
289+ let hard_break = is_break && ends_with_hard_break ( & text) ;
288290
289291 // Conclude: add last run. This may be empty, but we want it anyway.
290292 if !last_is_control {
@@ -340,16 +342,3 @@ impl TextDisplay {
340342 Ok ( ( ) )
341343 }
342344}
343-
344- trait ScriptExt {
345- #[ allow( clippy:: wrong_self_convention) ]
346- fn is_real ( self ) -> bool ;
347- }
348- impl ScriptExt for swash:: text:: Script {
349- fn is_real ( self ) -> bool {
350- use swash:: text:: Script :: * ;
351- !matches ! ( self , Common | Unknown | Inherited )
352- }
353- }
354-
355- pub ( crate ) const UNKNOWN_SCRIPT : fontique:: Script = fontique:: Script ( * b"Zzzz" ) ;
0 commit comments