RomanIvn
Committed by David PHAM-VAN

Fix underline on spans

@@ -5,6 +5,7 @@ @@ -5,6 +5,7 @@
5 - Fix Type1 font widths 5 - Fix Type1 font widths
6 - Deprecate PdfArrayObject and PdfObjectDict 6 - Deprecate PdfArrayObject and PdfObjectDict
7 - Improve PdfArray and PdfDict constructors 7 - Improve PdfArray and PdfDict constructors
  8 +- Fix underline on spans [RomanIvn]
8 9
9 ## 3.10.1 10 ## 3.10.1
10 11
@@ -49,12 +49,14 @@ enum TextOverflow { @@ -49,12 +49,14 @@ enum TextOverflow {
49 } 49 }
50 50
51 abstract class _Span { 51 abstract class _Span {
52 - _Span(this.style); 52 + _Span(this.style, this.realWidth);
53 53
54 final TextStyle style; 54 final TextStyle style;
55 55
56 var offset = PdfPoint.zero; 56 var offset = PdfPoint.zero;
57 57
  58 + double realWidth;
  59 +
58 double get left; 60 double get left;
59 61
60 double get top; 62 double get top;
@@ -103,9 +105,13 @@ class _TextDecoration { @@ -103,9 +105,13 @@ class _TextDecoration {
103 return _box; 105 return _box;
104 } 106 }
105 107
106 - final x1 = spans[startSpan].offset.x + spans[startSpan].left;  
107 - final x2 =  
108 - spans[endSpan].offset.x + spans[endSpan].left + spans[endSpan].width; 108 + final x1 = spans[startSpan].offset.x +
  109 + spans[startSpan].left +
  110 + spans[startSpan].realWidth;
  111 + final x2 = spans[endSpan].offset.x +
  112 + spans[endSpan].left +
  113 + spans[endSpan].width -
  114 + spans[endSpan].realWidth;
109 var y1 = spans[startSpan].offset.y + spans[startSpan].top; 115 var y1 = spans[startSpan].offset.y + spans[startSpan].top;
110 var y2 = y1 + spans[startSpan].height; 116 var y2 = y1 + spans[startSpan].height;
111 117
@@ -178,11 +184,13 @@ class _TextDecoration { @@ -178,11 +184,13 @@ class _TextDecoration {
178 184
179 if (style.decoration!.contains(TextDecoration.underline)) { 185 if (style.decoration!.contains(TextDecoration.underline)) {
180 final base = -font.descent * style.fontSize! * textScaleFactor / 2; 186 final base = -font.descent * style.fontSize! * textScaleFactor / 2;
181 - 187 + final l = box!.left;
  188 + final r = box.right;
  189 + final x = globalBox!.x;
182 context.canvas.drawLine( 190 context.canvas.drawLine(
183 - globalBox!.x + box!.left, 191 + x + l,
184 globalBox.top + box.bottom + base, 192 globalBox.top + box.bottom + base,
185 - globalBox.x + box.right, 193 + x + r,
186 globalBox.top + box.bottom + base, 194 globalBox.top + box.bottom + base,
187 ); 195 );
188 if (style.decorationStyle == TextDecorationStyle.double) { 196 if (style.decorationStyle == TextDecorationStyle.double) {
@@ -257,7 +265,7 @@ class _Word extends _Span { @@ -257,7 +265,7 @@ class _Word extends _Span {
257 this.text, 265 this.text,
258 TextStyle style, 266 TextStyle style,
259 this.metrics, 267 this.metrics,
260 - ) : super(style); 268 + ) : super(style, metrics.advanceWidth);
261 269
262 final String text; 270 final String text;
263 271
@@ -323,7 +331,7 @@ class _Word extends _Span { @@ -323,7 +331,7 @@ class _Word extends _Span {
323 } 331 }
324 332
325 class _WidgetSpan extends _Span { 333 class _WidgetSpan extends _Span {
326 - _WidgetSpan(this.widget, TextStyle style, this.baseline) : super(style); 334 + _WidgetSpan(this.widget, TextStyle style, this.baseline) : super(style, 0);
327 335
328 final Widget widget; 336 final Widget widget;
329 337
No preview for this file type
No preview for this file type
No preview for this file type