Showing
3 changed files
with
43 additions
and
14 deletions
| @@ -360,7 +360,10 @@ class _WidgetSpan extends _Span { | @@ -360,7 +360,10 @@ class _WidgetSpan extends _Span { | ||
| 360 | } | 360 | } |
| 361 | 361 | ||
| 362 | typedef _VisitorCallback = bool Function( | 362 | typedef _VisitorCallback = bool Function( |
| 363 | - InlineSpan span, TextStyle? parentStyle); | 363 | + InlineSpan span, |
| 364 | + TextStyle? parentStyle, | ||
| 365 | + AnnotationBuilder? annotation, | ||
| 366 | +); | ||
| 364 | 367 | ||
| 365 | @immutable | 368 | @immutable |
| 366 | abstract class InlineSpan { | 369 | abstract class InlineSpan { |
| @@ -374,16 +377,24 @@ abstract class InlineSpan { | @@ -374,16 +377,24 @@ abstract class InlineSpan { | ||
| 374 | 377 | ||
| 375 | String toPlainText() { | 378 | String toPlainText() { |
| 376 | final buffer = StringBuffer(); | 379 | final buffer = StringBuffer(); |
| 377 | - visitChildren((InlineSpan span, TextStyle? style) { | 380 | + visitChildren(( |
| 381 | + InlineSpan span, | ||
| 382 | + TextStyle? style, | ||
| 383 | + AnnotationBuilder? annotation, | ||
| 384 | + ) { | ||
| 378 | if (span is TextSpan) { | 385 | if (span is TextSpan) { |
| 379 | buffer.write(span.text); | 386 | buffer.write(span.text); |
| 380 | } | 387 | } |
| 381 | return true; | 388 | return true; |
| 382 | - }, null); | 389 | + }, null, null); |
| 383 | return buffer.toString(); | 390 | return buffer.toString(); |
| 384 | } | 391 | } |
| 385 | 392 | ||
| 386 | - bool visitChildren(_VisitorCallback visitor, TextStyle? parentStyle); | 393 | + bool visitChildren( |
| 394 | + _VisitorCallback visitor, | ||
| 395 | + TextStyle? parentStyle, | ||
| 396 | + AnnotationBuilder? annotation, | ||
| 397 | + ); | ||
| 387 | } | 398 | } |
| 388 | 399 | ||
| 389 | class WidgetSpan extends InlineSpan { | 400 | class WidgetSpan extends InlineSpan { |
| @@ -400,10 +411,15 @@ class WidgetSpan extends InlineSpan { | @@ -400,10 +411,15 @@ class WidgetSpan extends InlineSpan { | ||
| 400 | 411 | ||
| 401 | /// Calls `visitor` on this [WidgetSpan]. There are no children spans to walk. | 412 | /// Calls `visitor` on this [WidgetSpan]. There are no children spans to walk. |
| 402 | @override | 413 | @override |
| 403 | - bool visitChildren(_VisitorCallback visitor, TextStyle? parentStyle) { | 414 | + bool visitChildren( |
| 415 | + _VisitorCallback visitor, | ||
| 416 | + TextStyle? parentStyle, | ||
| 417 | + AnnotationBuilder? annotation, | ||
| 418 | + ) { | ||
| 404 | final _style = parentStyle?.merge(style); | 419 | final _style = parentStyle?.merge(style); |
| 420 | + final _a = this.annotation ?? annotation; | ||
| 405 | 421 | ||
| 406 | - return visitor(this, _style); | 422 | + return visitor(this, _style, _a); |
| 407 | } | 423 | } |
| 408 | } | 424 | } |
| 409 | 425 | ||
| @@ -421,17 +437,22 @@ class TextSpan extends InlineSpan { | @@ -421,17 +437,22 @@ class TextSpan extends InlineSpan { | ||
| 421 | final List<InlineSpan>? children; | 437 | final List<InlineSpan>? children; |
| 422 | 438 | ||
| 423 | @override | 439 | @override |
| 424 | - bool visitChildren(_VisitorCallback visitor, TextStyle? parentStyle) { | 440 | + bool visitChildren( |
| 441 | + _VisitorCallback visitor, | ||
| 442 | + TextStyle? parentStyle, | ||
| 443 | + AnnotationBuilder? annotation, | ||
| 444 | + ) { | ||
| 425 | final _style = parentStyle?.merge(style); | 445 | final _style = parentStyle?.merge(style); |
| 446 | + final _a = this.annotation ?? annotation; | ||
| 426 | 447 | ||
| 427 | if (text != null) { | 448 | if (text != null) { |
| 428 | - if (!visitor(this, _style)) { | 449 | + if (!visitor(this, _style, _a)) { |
| 429 | return false; | 450 | return false; |
| 430 | } | 451 | } |
| 431 | } | 452 | } |
| 432 | if (children != null) { | 453 | if (children != null) { |
| 433 | for (var child in children!) { | 454 | for (var child in children!) { |
| 434 | - if (!child.visitChildren(visitor, _style)) { | 455 | + if (!child.visitChildren(visitor, _style, _a)) { |
| 435 | return false; | 456 | return false; |
| 436 | } | 457 | } |
| 437 | } | 458 | } |
| @@ -571,7 +592,11 @@ class RichText extends Widget { | @@ -571,7 +592,11 @@ class RichText extends Widget { | ||
| 571 | var spanStart = 0; | 592 | var spanStart = 0; |
| 572 | var decorationStart = 0; | 593 | var decorationStart = 0; |
| 573 | 594 | ||
| 574 | - text.visitChildren((InlineSpan span, TextStyle? style) { | 595 | + text.visitChildren(( |
| 596 | + InlineSpan span, | ||
| 597 | + TextStyle? style, | ||
| 598 | + AnnotationBuilder? annotation, | ||
| 599 | + ) { | ||
| 575 | if (span is TextSpan) { | 600 | if (span is TextSpan) { |
| 576 | if (span.text == null) { | 601 | if (span.text == null) { |
| 577 | return true; | 602 | return true; |
| @@ -653,7 +678,7 @@ class RichText extends Widget { | @@ -653,7 +678,7 @@ class RichText extends Widget { | ||
| 653 | spanCount > 1, | 678 | spanCount > 1, |
| 654 | _TextDecoration( | 679 | _TextDecoration( |
| 655 | style, | 680 | style, |
| 656 | - span.annotation, | 681 | + annotation, |
| 657 | _spans.length - 1, | 682 | _spans.length - 1, |
| 658 | _spans.length - 1, | 683 | _spans.length - 1, |
| 659 | ), | 684 | ), |
| @@ -764,7 +789,7 @@ class RichText extends Widget { | @@ -764,7 +789,7 @@ class RichText extends Widget { | ||
| 764 | spanCount > 1, | 789 | spanCount > 1, |
| 765 | _TextDecoration( | 790 | _TextDecoration( |
| 766 | style, | 791 | style, |
| 767 | - span.annotation, | 792 | + annotation, |
| 768 | _spans.length - 1, | 793 | _spans.length - 1, |
| 769 | _spans.length - 1, | 794 | _spans.length - 1, |
| 770 | ), | 795 | ), |
| @@ -774,7 +799,7 @@ class RichText extends Widget { | @@ -774,7 +799,7 @@ class RichText extends Widget { | ||
| 774 | } | 799 | } |
| 775 | 800 | ||
| 776 | return true; | 801 | return true; |
| 777 | - }, defaultstyle); | 802 | + }, defaultstyle, null); |
| 778 | 803 | ||
| 779 | width = math.max( | 804 | width = math.max( |
| 780 | width, | 805 | width, |
| @@ -7,7 +7,7 @@ description: > | @@ -7,7 +7,7 @@ description: > | ||
| 7 | homepage: https://github.com/DavBfr/dart_pdf/tree/master/printing | 7 | homepage: https://github.com/DavBfr/dart_pdf/tree/master/printing |
| 8 | repository: https://github.com/DavBfr/dart_pdf | 8 | repository: https://github.com/DavBfr/dart_pdf |
| 9 | issue_tracker: https://github.com/DavBfr/dart_pdf/issues | 9 | issue_tracker: https://github.com/DavBfr/dart_pdf/issues |
| 10 | -version: 5.0.2 | 10 | +version: 5.0.3 |
| 11 | 11 | ||
| 12 | environment: | 12 | environment: |
| 13 | sdk: ">=2.12.0-0 <3.0.0" | 13 | sdk: ">=2.12.0-0 <3.0.0" |
-
Please register or login to post a comment