@@ -613,63 +613,13 @@ bool MCBlock::fit(int2 x, uint2 maxwidth, uint2& r_break_index, bool& r_break_fi
613613 else
614614 t_next_block_char = -1 ;
615615
616- // If this is a text block and we fit inside maxwidth fully then check
617- // for a break point at the end.
618- if (getwidth (NULL , x) <= maxwidth)
619- {
620- uint2 t_last_char, t_break_index;
621- if (hasunicode () && (size & 1 ) == 0 )
622- t_last_char = *(uint2 *)&text[index + size - 2 ], t_break_index = index + size - 2 ;
623- else
624- t_last_char = MCUnicodeMapFromNative (text[index + size - 1 ]), t_break_index = index + size - 1 ;
625-
626- // If this is the last block, or we can break between this and the
627- // next block, return the end point.
628- if (t_next_block_char != -2 )
629- {
630- if (t_next_block_char == -1 || MCUnicodeCanBreakBetween (t_last_char, t_next_block_char))
631- {
632- r_break_index = index + size;
633- r_break_fits = true ;
634- return true ;
635- }
636- }
637-
638- // Compute the last possible break position in the block by looping
639- // back over the characters;
640- if (t_break_index > index)
641- {
642- do
643- {
644- uint2 i;
645- i = t_break_index;
646-
647- uint2 t_prev_char;
648- if (hasunicode ())
649- {
650- i -= 2 ;
651- t_prev_char = *(uint2 *)&text[i];
652- }
653- else
654- {
655- i -= 1 ;
656- t_prev_char = MCUnicodeMapFromNative (text[i]);
657- }
658-
659- if (MCUnicodeCanBreakBetween (t_prev_char, t_last_char))
660- break ;
661-
662- t_break_index = i;
663-
664- t_last_char = t_prev_char;
665- }
666- while (t_break_index > index);
667- }
668-
669- r_break_index = t_break_index;
670- r_break_fits = true ;
671- return true ;
672- }
616+ // FG-2013-10-21 [[ Field speedups ]]
617+ // Previously, we used to calculate the length of the entire block here in order
618+ // to determine if splitting was required. Unfortunately, this tends to bypass
619+ // the text layout cache resulting in very slow laying out now that the "proper"
620+ // Unicode text layout APIs are in use.
621+ //
622+ // Now, all text is laid out word-at-a-time.
673623
674624 // We don't completely fit within maxwidth, so compute the last break point in
675625 // the block by measuring
@@ -700,6 +650,8 @@ bool MCBlock::fit(int2 x, uint2 maxwidth, uint2& r_break_index, bool& r_break_fi
700650
701651 // MW-2013-08-01: [[ Bug 10932 ]] Optimized loop only measuring between potential break
702652 // points, rather than char by char.
653+ bool t_whole_block;
654+ t_whole_block = false ;
703655 while (i < index + size)
704656 {
705657 uint4 initial_i;
@@ -709,6 +661,8 @@ bool MCBlock::fit(int2 x, uint2 maxwidth, uint2& r_break_index, bool& r_break_fi
709661 t_can_break = false ;
710662
711663 uint2 t_this_char;
664+ bool t_end_of_block;
665+ t_end_of_block = false ;
712666 while (i < index + size)
713667 {
714668 t_this_char = (uint2)t_next_char;
@@ -720,14 +674,20 @@ bool MCBlock::fit(int2 x, uint2 maxwidth, uint2& r_break_index, bool& r_break_fi
720674 if (i < index + size)
721675 t_next_char = *(uint2 *)&text[i];
722676 else
723- t_next_char = t_next_block_char;
677+ {
678+ t_next_char = t_next_block_char;
679+ t_end_of_block = true ;
680+ }
724681 }
725682 else
726683 {
727684 if (i < index + size)
728685 t_next_char = (uint2)MCUnicodeMapFromNative (text[i]);
729686 else
730- t_next_char = t_next_block_char;
687+ {
688+ t_next_char = t_next_block_char;
689+ t_end_of_block = true ;
690+ }
731691 }
732692
733693 if (t_this_char == ' \t ' ||
@@ -768,27 +728,29 @@ bool MCBlock::fit(int2 x, uint2 maxwidth, uint2& r_break_index, bool& r_break_fi
768728 break ;
769729
770730 if (t_can_break)
771- {
772731 t_break_index = i;
773732
774- if (twidth <= maxwidth)
775- t_can_fit = true ;
733+ if (twidth <= maxwidth)
734+ {
735+ t_can_fit = true ;
736+ t_whole_block = t_end_of_block;
737+ }
776738
777- if (twidth >= maxwidth)
778- break ;
779- }
739+ if (twidth >= maxwidth)
740+ break ;
780741 }
781742
782743 // We now have a suitable break point in t_break_index. This could be index if
783744 // there are none in the block. We now loop forward until we get to the end of
784745 // any suitable run of spaces.
785746 while (t_break_index < index + size && textisspace (&text[t_break_index]))
786747 t_break_index += indexincrement (t_break_index);
787-
748+
788749 r_break_fits = t_can_fit;
789750 r_break_index = t_break_index;
790751
791- return false ;
752+ // If we found a break, was it before the end of the block?
753+ return t_whole_block;
792754}
793755
794756void MCBlock::split (uint2 p_index)
0 commit comments