Allow reusing an ImageProvider and Font on multiple documents
Showing
3 changed files
with
11 additions
and
9 deletions
| @@ -3,6 +3,7 @@ | @@ -3,6 +3,7 @@ | ||
| 3 | ## 3.4.1 | 3 | ## 3.4.1 |
| 4 | 4 | ||
| 5 | - Fix Nunito font parsing | 5 | - Fix Nunito font parsing |
| 6 | +- Allow reusing an ImageProvider and Font on multiple documents | ||
| 6 | 7 | ||
| 7 | ## 3.4.0 | 8 | ## 3.4.0 |
| 8 | 9 | ||
| @@ -19,7 +20,7 @@ | @@ -19,7 +20,7 @@ | ||
| 19 | 20 | ||
| 20 | ## 3.3.0 | 21 | ## 3.3.0 |
| 21 | 22 | ||
| 22 | -- Implement To be signed flieds | 23 | +- Implement To be signed fields |
| 23 | - Improve Text rendering | 24 | - Improve Text rendering |
| 24 | - Add individual cell decoration | 25 | - Add individual cell decoration |
| 25 | - Improve Bullet Widget | 26 | - Improve Bullet Widget |
| @@ -128,14 +128,11 @@ class Font { | @@ -128,14 +128,11 @@ class Font { | ||
| 128 | PdfFont? _pdfFont; | 128 | PdfFont? _pdfFont; |
| 129 | 129 | ||
| 130 | PdfFont? getFont(Context context) { | 130 | PdfFont? getFont(Context context) { |
| 131 | - if (_pdfFont == null) { | 131 | + if (_pdfFont == null || _pdfFont!.pdfDocument != context.document) { |
| 132 | final pdfDocument = context.document; | 132 | final pdfDocument = context.document; |
| 133 | _pdfFont = buildFont(pdfDocument); | 133 | _pdfFont = buildFont(pdfDocument); |
| 134 | } | 134 | } |
| 135 | 135 | ||
| 136 | - assert(_pdfFont!.pdfDocument == context.document, | ||
| 137 | - 'Do not reuse a Font object across multiple documents'); | ||
| 138 | - | ||
| 139 | return _pdfFont; | 136 | return _pdfFont; |
| 140 | } | 137 | } |
| 141 | 138 |
| @@ -57,8 +57,10 @@ abstract class ImageProvider { | @@ -57,8 +57,10 @@ abstract class ImageProvider { | ||
| 57 | if (effectiveDpi == null || _cache[0] != null) { | 57 | if (effectiveDpi == null || _cache[0] != null) { |
| 58 | _cache[0] ??= buildImage(context); | 58 | _cache[0] ??= buildImage(context); |
| 59 | 59 | ||
| 60 | - assert(_cache[0]!.pdfDocument == context.document, | ||
| 61 | - 'Do not reuse an ImageProvider object across multiple documents'); | 60 | + if (_cache[0]!.pdfDocument != context.document) { |
| 61 | + _cache[0] = buildImage(context); | ||
| 62 | + } | ||
| 63 | + | ||
| 62 | return _cache[0]!; | 64 | return _cache[0]!; |
| 63 | } | 65 | } |
| 64 | 66 | ||
| @@ -69,8 +71,10 @@ abstract class ImageProvider { | @@ -69,8 +71,10 @@ abstract class ImageProvider { | ||
| 69 | _cache[width] ??= buildImage(context, width: width, height: height); | 71 | _cache[width] ??= buildImage(context, width: width, height: height); |
| 70 | } | 72 | } |
| 71 | 73 | ||
| 72 | - assert(_cache[width]!.pdfDocument == context.document, | ||
| 73 | - 'Do not reuse an ImageProvider object across multiple documents'); | 74 | + if (_cache[width]!.pdfDocument != context.document) { |
| 75 | + _cache[width] = buildImage(context, width: width, height: height); | ||
| 76 | + } | ||
| 77 | + | ||
| 74 | return _cache[width]!; | 78 | return _cache[width]!; |
| 75 | } | 79 | } |
| 76 | } | 80 | } |
-
Please register or login to post a comment