Showing
2 changed files
with
27 additions
and
1 deletions
@@ -315,7 +315,27 @@ class PdfName extends PdfDataType { | @@ -315,7 +315,27 @@ class PdfName extends PdfDataType { | ||
315 | @override | 315 | @override |
316 | void output(PdfStream s) { | 316 | void output(PdfStream s) { |
317 | assert(value[0] == '/'); | 317 | assert(value[0] == '/'); |
318 | - s.putString(value); | 318 | + final bytes = <int>[]; |
319 | + for (final c in value.codeUnits) { | ||
320 | + assert(c < 0xff && c > 0x00); | ||
321 | + | ||
322 | + if (c < 0x21 || | ||
323 | + c > 0x7E || | ||
324 | + c == 0x23 || | ||
325 | + (c == 0x2f && bytes.isNotEmpty) || | ||
326 | + c == 0x5b || | ||
327 | + c == 0x5d || | ||
328 | + c == 0x28 || | ||
329 | + c == 0x3c || | ||
330 | + c == 0x3e) { | ||
331 | + bytes.add(0x23); | ||
332 | + final x = c.toRadixString(16).padLeft(2, '0'); | ||
333 | + bytes.addAll(x.codeUnits); | ||
334 | + } else { | ||
335 | + bytes.add(c); | ||
336 | + } | ||
337 | + } | ||
338 | + s.putBytes(bytes); | ||
319 | } | 339 | } |
320 | } | 340 | } |
321 | 341 |
@@ -25,6 +25,12 @@ void main() { | @@ -25,6 +25,12 @@ void main() { | ||
25 | expect(const PdfBool(false).toString(), 'false'); | 25 | expect(const PdfBool(false).toString(), 'false'); |
26 | }); | 26 | }); |
27 | 27 | ||
28 | + test('PdfDataTypes Name ', () { | ||
29 | + expect(const PdfName('/Test').toString(), '/Test'); | ||
30 | + expect(const PdfName('/Type 1').toString(), '/Type#201'); | ||
31 | + expect(const PdfName('/Num#1').toString(), '/Num#231'); | ||
32 | + }); | ||
33 | + | ||
28 | test('PdfDataTypes Num', () { | 34 | test('PdfDataTypes Num', () { |
29 | expect(const PdfNum(0).toString(), '0'); | 35 | expect(const PdfNum(0).toString(), '0'); |
30 | expect(const PdfNum(.5).toString(), '0.5'); | 36 | expect(const PdfNum(.5).toString(), '0.5'); |
-
Please register or login to post a comment