Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 615d089

Browse files
committed
Remove the discrepancies
1 parent 2fedf31 commit 615d089

File tree

2 files changed

+18
-56
lines changed

2 files changed

+18
-56
lines changed

lib/web_ui/lib/src/engine/text/ruler.dart

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -737,16 +737,26 @@ class ParagraphRuler {
737737
? double.infinity
738738
: style.maxLines * lineHeightDimensions.height;
739739

740+
html.Rectangle<num> previousRect;
740741
for (html.Rectangle<num> rect in clientRects) {
741-
if (rect.top < maxLinesLimit) {
742-
boxes.add(ui.TextBox.fromLTRBD(
743-
rect.left + alignOffset,
744-
rect.top,
745-
rect.right + alignOffset,
746-
rect.bottom,
747-
textDirection,
748-
));
742+
// If [rect] is an empty box on the same line as the previous box, don't
743+
// include it in the result.
744+
if (rect.top == previousRect?.top && rect.left == rect.right) {
745+
continue;
749746
}
747+
// As soon as we go beyond [maxLines], stop adding boxes.
748+
if (rect.top >= maxLinesLimit) {
749+
break;
750+
}
751+
752+
boxes.add(ui.TextBox.fromLTRBD(
753+
rect.left + alignOffset,
754+
rect.top,
755+
rect.right + alignOffset,
756+
rect.bottom,
757+
textDirection,
758+
));
759+
previousRect = rect;
750760
}
751761

752762
// Cleanup after measuring the boxes.

lib/web_ui/test/paragraph_test.dart

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -441,12 +441,6 @@ void main() async {
441441
final Paragraph paragraph = builder.build();
442442
paragraph.layout(const ParagraphConstraints(width: 100));
443443

444-
// In the dom-based measurement (except Firefox), there will be some
445-
// discrepancies around line ends.
446-
final isDiscrepancyExpected =
447-
!TextMeasurementService.enableExperimentalCanvasImplementation &&
448-
browserEngine != BrowserEngine.firefox;
449-
450444
// First line: "abcd\n"
451445

452446
// At the beginning of the first line.
@@ -497,8 +491,6 @@ void main() async {
497491
paragraph.getBoxesForRange(2, 5),
498492
<TextBox>[
499493
TextBox.fromLTRBD(20.0, 0.0, 40.0, 10.0, TextDirection.ltr),
500-
if (isDiscrepancyExpected)
501-
TextBox.fromLTRBD(40.0, 0.0, 40.0, 10.0, TextDirection.ltr),
502494
],
503495
);
504496

@@ -533,8 +525,6 @@ void main() async {
533525
paragraph.getBoxesForRange(10, 13),
534526
<TextBox>[
535527
TextBox.fromLTRBD(50.0, 10.0, 70.0, 20.0, TextDirection.ltr),
536-
if (isDiscrepancyExpected)
537-
TextBox.fromLTRBD(70.0, 10.0, 70.0, 20.0, TextDirection.ltr),
538528
],
539529
);
540530

@@ -573,8 +563,6 @@ void main() async {
573563
paragraph.getBoxesForRange(2, 8),
574564
<TextBox>[
575565
TextBox.fromLTRBD(20.0, 0.0, 40.0, 10.0, TextDirection.ltr),
576-
if (isDiscrepancyExpected)
577-
TextBox.fromLTRBD(40.0, 0.0, 40.0, 10.0, TextDirection.ltr),
578566
TextBox.fromLTRBD(0.0, 10.0, 30.0, 20.0, TextDirection.ltr),
579567
],
580568
);
@@ -593,11 +581,7 @@ void main() async {
593581
paragraph.getBoxesForRange(3, 14),
594582
<TextBox>[
595583
TextBox.fromLTRBD(30.0, 0.0, 40.0, 10.0, TextDirection.ltr),
596-
if (isDiscrepancyExpected)
597-
TextBox.fromLTRBD(40.0, 0.0, 40.0, 10.0, TextDirection.ltr),
598584
TextBox.fromLTRBD(0.0, 10.0, 70.0, 20.0, TextDirection.ltr),
599-
if (isDiscrepancyExpected)
600-
TextBox.fromLTRBD(70.0, 10.0, 70.0, 20.0, TextDirection.ltr),
601585
TextBox.fromLTRBD(0.0, 20.0, 10.0, 30.0, TextDirection.ltr),
602586
],
603587
);
@@ -607,11 +591,7 @@ void main() async {
607591
paragraph.getBoxesForRange(0, 13),
608592
<TextBox>[
609593
TextBox.fromLTRBD(0.0, 0.0, 40.0, 10.0, TextDirection.ltr),
610-
if (isDiscrepancyExpected)
611-
TextBox.fromLTRBD(40.0, 0.0, 40.0, 10.0, TextDirection.ltr),
612594
TextBox.fromLTRBD(0.0, 10.0, 70.0, 20.0, TextDirection.ltr),
613-
if (isDiscrepancyExpected)
614-
TextBox.fromLTRBD(70.0, 10.0, 70.0, 20.0, TextDirection.ltr),
615595
],
616596
);
617597

@@ -620,11 +600,7 @@ void main() async {
620600
paragraph.getBoxesForRange(0, 15),
621601
<TextBox>[
622602
TextBox.fromLTRBD(0.0, 0.0, 40.0, 10.0, TextDirection.ltr),
623-
if (isDiscrepancyExpected)
624-
TextBox.fromLTRBD(40.0, 0.0, 40.0, 10.0, TextDirection.ltr),
625603
TextBox.fromLTRBD(0.0, 10.0, 70.0, 20.0, TextDirection.ltr),
626-
if (isDiscrepancyExpected)
627-
TextBox.fromLTRBD(70.0, 10.0, 70.0, 20.0, TextDirection.ltr),
628604
TextBox.fromLTRBD(0.0, 20.0, 20.0, 30.0, TextDirection.ltr),
629605
],
630606
);
@@ -645,12 +621,6 @@ void main() async {
645621
final Paragraph paragraph = builder.build();
646622
paragraph.layout(const ParagraphConstraints(width: 100));
647623

648-
// In the dom-based measurement (except Firefox), there will be some
649-
// discrepancies around line ends.
650-
final isDiscrepancyExpected =
651-
!TextMeasurementService.enableExperimentalCanvasImplementation &&
652-
browserEngine != BrowserEngine.firefox;
653-
654624
// First line: "abcd\n"
655625

656626
// At the beginning of the first line.
@@ -701,8 +671,6 @@ void main() async {
701671
paragraph.getBoxesForRange(2, 5),
702672
<TextBox>[
703673
TextBox.fromLTRBD(20.0, 0.0, 40.0, 10.0, TextDirection.ltr),
704-
if (isDiscrepancyExpected)
705-
TextBox.fromLTRBD(40.0, 0.0, 40.0, 10.0, TextDirection.ltr),
706674
],
707675
);
708676

@@ -737,8 +705,6 @@ void main() async {
737705
paragraph.getBoxesForRange(10, 13),
738706
<TextBox>[
739707
TextBox.fromLTRBD(50.0, 10.0, 70.0, 20.0, TextDirection.ltr),
740-
if (isDiscrepancyExpected)
741-
TextBox.fromLTRBD(70.0, 10.0, 70.0, 20.0, TextDirection.ltr),
742708
],
743709
);
744710

@@ -773,8 +739,6 @@ void main() async {
773739
paragraph.getBoxesForRange(2, 8),
774740
<TextBox>[
775741
TextBox.fromLTRBD(20.0, 0.0, 40.0, 10.0, TextDirection.ltr),
776-
if (isDiscrepancyExpected)
777-
TextBox.fromLTRBD(40.0, 0.0, 40.0, 10.0, TextDirection.ltr),
778742
TextBox.fromLTRBD(0.0, 10.0, 30.0, 20.0, TextDirection.ltr),
779743
],
780744
);
@@ -793,11 +757,7 @@ void main() async {
793757
paragraph.getBoxesForRange(3, 14),
794758
<TextBox>[
795759
TextBox.fromLTRBD(30.0, 0.0, 40.0, 10.0, TextDirection.ltr),
796-
if (isDiscrepancyExpected)
797-
TextBox.fromLTRBD(40.0, 0.0, 40.0, 10.0, TextDirection.ltr),
798760
TextBox.fromLTRBD(0.0, 10.0, 70.0, 20.0, TextDirection.ltr),
799-
if (isDiscrepancyExpected)
800-
TextBox.fromLTRBD(70.0, 10.0, 70.0, 20.0, TextDirection.ltr),
801761
],
802762
);
803763

@@ -806,11 +766,7 @@ void main() async {
806766
paragraph.getBoxesForRange(0, 13),
807767
<TextBox>[
808768
TextBox.fromLTRBD(0.0, 0.0, 40.0, 10.0, TextDirection.ltr),
809-
if (isDiscrepancyExpected)
810-
TextBox.fromLTRBD(40.0, 0.0, 40.0, 10.0, TextDirection.ltr),
811769
TextBox.fromLTRBD(0.0, 10.0, 70.0, 20.0, TextDirection.ltr),
812-
if (isDiscrepancyExpected)
813-
TextBox.fromLTRBD(70.0, 10.0, 70.0, 20.0, TextDirection.ltr),
814770
],
815771
);
816772

@@ -819,11 +775,7 @@ void main() async {
819775
paragraph.getBoxesForRange(0, 15),
820776
<TextBox>[
821777
TextBox.fromLTRBD(0.0, 0.0, 40.0, 10.0, TextDirection.ltr),
822-
if (isDiscrepancyExpected)
823-
TextBox.fromLTRBD(40.0, 0.0, 40.0, 10.0, TextDirection.ltr),
824778
TextBox.fromLTRBD(0.0, 10.0, 70.0, 20.0, TextDirection.ltr),
825-
if (isDiscrepancyExpected)
826-
TextBox.fromLTRBD(70.0, 10.0, 70.0, 20.0, TextDirection.ltr),
827779
],
828780
);
829781
});

0 commit comments

Comments
 (0)