Showing
5 changed files
with
25 additions
and
9 deletions
@@ -16,19 +16,28 @@ | @@ -16,19 +16,28 @@ | ||
16 | 16 | ||
17 | part of pdf; | 17 | part of pdf; |
18 | 18 | ||
19 | +@immutable | ||
19 | class TtfGlyphInfo { | 20 | class TtfGlyphInfo { |
20 | - TtfGlyphInfo(this.index, this.data, this.compounds); | 21 | + const TtfGlyphInfo(this.index, this.data, this.compounds); |
21 | 22 | ||
22 | final int index; | 23 | final int index; |
23 | final Uint8List data; | 24 | final Uint8List data; |
24 | final List<int> compounds; | 25 | final List<int> compounds; |
25 | 26 | ||
27 | + TtfGlyphInfo copy() { | ||
28 | + return TtfGlyphInfo( | ||
29 | + index, | ||
30 | + Uint8List.fromList(data), | ||
31 | + List<int>.from(compounds), | ||
32 | + ); | ||
33 | + } | ||
34 | + | ||
26 | @override | 35 | @override |
27 | String toString() => 'Glyph $index $compounds'; | 36 | String toString() => 'Glyph $index $compounds'; |
28 | } | 37 | } |
29 | 38 | ||
30 | class TtfParser { | 39 | class TtfParser { |
31 | - TtfParser(this.bytes) { | 40 | + TtfParser(ByteData bytes) : bytes = UnmodifiableByteDataView(bytes) { |
32 | final int numTables = bytes.getUint16(4); | 41 | final int numTables = bytes.getUint16(4); |
33 | 42 | ||
34 | for (int i = 0; i < numTables; i++) { | 43 | for (int i = 0; i < numTables; i++) { |
@@ -54,7 +63,7 @@ class TtfParser { | @@ -54,7 +63,7 @@ class TtfParser { | ||
54 | static const String loca_table = 'loca'; | 63 | static const String loca_table = 'loca'; |
55 | static const String glyf_table = 'glyf'; | 64 | static const String glyf_table = 'glyf'; |
56 | 65 | ||
57 | - final ByteData bytes; | 66 | + final UnmodifiableByteDataView bytes; |
58 | final Map<String, int> tableOffsets = <String, int>{}; | 67 | final Map<String, int> tableOffsets = <String, int>{}; |
59 | final Map<String, int> tableSize = <String, int>{}; | 68 | final Map<String, int> tableSize = <String, int>{}; |
60 | String _fontName; | 69 | String _fontName; |
@@ -284,7 +293,7 @@ class TtfParser { | @@ -284,7 +293,7 @@ class TtfParser { | ||
284 | return TtfGlyphInfo( | 293 | return TtfGlyphInfo( |
285 | glyph, | 294 | glyph, |
286 | Uint8List.view(bytes.buffer, start, offset - start), | 295 | Uint8List.view(bytes.buffer, start, offset - start), |
287 | - <int>[], | 296 | + const <int>[], |
288 | ); | 297 | ); |
289 | } | 298 | } |
290 | 299 | ||
@@ -322,7 +331,7 @@ class TtfParser { | @@ -322,7 +331,7 @@ class TtfParser { | ||
322 | return TtfGlyphInfo( | 331 | return TtfGlyphInfo( |
323 | glyph, | 332 | glyph, |
324 | Uint8List.view(bytes.buffer, start, offset - start), | 333 | Uint8List.view(bytes.buffer, start, offset - start), |
325 | - <int>[], | 334 | + const <int>[], |
326 | ); | 335 | ); |
327 | } | 336 | } |
328 | 337 |
@@ -62,13 +62,14 @@ class TtfWriter { | @@ -62,13 +62,14 @@ class TtfWriter { | ||
62 | 62 | ||
63 | for (int index = 0; index < chars.length; index++) { | 63 | for (int index = 0; index < chars.length; index++) { |
64 | if (chars[index] == 32) { | 64 | if (chars[index] == 32) { |
65 | - final TtfGlyphInfo glyph = TtfGlyphInfo(32, Uint8List(0), <int>[]); | 65 | + final TtfGlyphInfo glyph = |
66 | + TtfGlyphInfo(32, Uint8List(0), const <int>[]); | ||
66 | glyphsInfo.add(glyph); | 67 | glyphsInfo.add(glyph); |
67 | continue; | 68 | continue; |
68 | } | 69 | } |
69 | 70 | ||
70 | final TtfGlyphInfo glyph = | 71 | final TtfGlyphInfo glyph = |
71 | - ttf.readGlyph(ttf.charToGlyphIndexMap[chars[index]] ?? 0); | 72 | + ttf.readGlyph(ttf.charToGlyphIndexMap[chars[index]] ?? 0).copy(); |
72 | for (int g in glyph.compounds) { | 73 | for (int g in glyph.compounds) { |
73 | compounds[g] = null; | 74 | compounds[g] = null; |
74 | } | 75 | } |
@@ -92,7 +93,7 @@ class TtfWriter { | @@ -92,7 +93,7 @@ class TtfWriter { | ||
92 | } | 93 | } |
93 | 94 | ||
94 | // Add one last empty glyph | 95 | // Add one last empty glyph |
95 | - final TtfGlyphInfo glyph = TtfGlyphInfo(32, Uint8List(0), <int>[]); | 96 | + final TtfGlyphInfo glyph = TtfGlyphInfo(32, Uint8List(0), const <int>[]); |
96 | glyphsInfo.add(glyph); | 97 | glyphsInfo.add(glyph); |
97 | 98 | ||
98 | // update compound indices | 99 | // update compound indices |
@@ -131,6 +131,9 @@ class Font { | @@ -131,6 +131,9 @@ class Font { | ||
131 | _pdfFont = buildFont(pdfDocument); | 131 | _pdfFont = buildFont(pdfDocument); |
132 | } | 132 | } |
133 | 133 | ||
134 | + assert(_pdfFont.pdfDocument == context.document, | ||
135 | + 'Do not reuse a Font object across multiple documents'); | ||
136 | + | ||
134 | return _pdfFont; | 137 | return _pdfFont; |
135 | } | 138 | } |
136 | 139 |
@@ -4,7 +4,7 @@ description: A pdf producer for Dart. It can create pdf files for both web or fl | @@ -4,7 +4,7 @@ description: A pdf producer for Dart. It can create pdf files for both web or fl | ||
4 | homepage: https://github.com/DavBfr/dart_pdf/tree/master/pdf | 4 | homepage: https://github.com/DavBfr/dart_pdf/tree/master/pdf |
5 | repository: https://github.com/DavBfr/dart_pdf | 5 | repository: https://github.com/DavBfr/dart_pdf |
6 | issue_tracker: https://github.com/DavBfr/dart_pdf/issues | 6 | issue_tracker: https://github.com/DavBfr/dart_pdf/issues |
7 | -version: 1.3.12 | 7 | +version: 1.3.13 |
8 | 8 | ||
9 | environment: | 9 | environment: |
10 | sdk: ">=2.1.0 <3.0.0" | 10 | sdk: ">=2.1.0 <3.0.0" |
-
Please register or login to post a comment