Showing
4 changed files
with
29 additions
and
5 deletions
| @@ -77,13 +77,16 @@ class TtfWriter { | @@ -77,13 +77,16 @@ class TtfWriter { | ||
| 77 | 77 | ||
| 78 | // Add compound glyphs | 78 | // Add compound glyphs |
| 79 | for (int compound in compounds.keys) { | 79 | for (int compound in compounds.keys) { |
| 80 | - final int index = chars.indexOf(compound); | ||
| 81 | - if (index >= 0) { | ||
| 82 | - compounds[compound] = index; | 80 | + final TtfGlyphInfo index = glyphsInfo.firstWhere( |
| 81 | + (TtfGlyphInfo glyph) => glyph.index == compound, | ||
| 82 | + orElse: () => null); | ||
| 83 | + if (index != null) { | ||
| 84 | + compounds[compound] = glyphsInfo.indexOf(index); | ||
| 85 | + assert(compounds[compound] >= 0, 'Unable to find the glyph'); | ||
| 83 | } else { | 86 | } else { |
| 84 | compounds[compound] = glyphsInfo.length; | 87 | compounds[compound] = glyphsInfo.length; |
| 85 | final TtfGlyphInfo glyph = ttf.readGlyph(compound); | 88 | final TtfGlyphInfo glyph = ttf.readGlyph(compound); |
| 86 | - assert(glyph.compounds.isEmpty); // This is a simple glyph | 89 | + assert(glyph.compounds.isEmpty, 'This is not a simple glyph'); |
| 87 | glyphsInfo.add(glyph); | 90 | glyphsInfo.add(glyph); |
| 88 | } | 91 | } |
| 89 | } | 92 | } |
| @@ -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.5 | 7 | +version: 1.3.6 |
| 8 | 8 | ||
| 9 | environment: | 9 | environment: |
| 10 | sdk: ">=2.1.0 <3.0.0" | 10 | sdk: ">=2.1.0 <3.0.0" |
| @@ -75,4 +75,22 @@ void main() { | @@ -75,4 +75,22 @@ void main() { | ||
| 75 | final File file = File('ttf.pdf'); | 75 | final File file = File('ttf.pdf'); |
| 76 | file.writeAsBytesSync(pdf.save()); | 76 | file.writeAsBytesSync(pdf.save()); |
| 77 | }); | 77 | }); |
| 78 | + | ||
| 79 | + test('Font SubSetting', () { | ||
| 80 | + final Uint8List fontData = File('open-sans.ttf').readAsBytesSync(); | ||
| 81 | + final TtfParser font = TtfParser(fontData.buffer.asByteData()); | ||
| 82 | + final TtfWriter ttfWriter = TtfWriter(font); | ||
| 83 | + final Uint8List data = ttfWriter.withChars('hçHée'.runes.toList()); | ||
| 84 | + final File output = File('${font.fontName}.ttf'); | ||
| 85 | + output.writeAsBytesSync(data); | ||
| 86 | + }); | ||
| 87 | + | ||
| 88 | + test('Font SubSetting CN', () { | ||
| 89 | + final Uint8List fontData = File('genyomintw.ttf').readAsBytesSync(); | ||
| 90 | + final TtfParser font = TtfParser(fontData.buffer.asByteData()); | ||
| 91 | + final TtfWriter ttfWriter = TtfWriter(font); | ||
| 92 | + final Uint8List data = ttfWriter.withChars('hçHée 你好 檯號 ☃'.runes.toList()); | ||
| 93 | + final File output = File('${font.fontName}.ttf'); | ||
| 94 | + output.writeAsBytesSync(data); | ||
| 95 | + }); | ||
| 78 | } | 96 | } |
-
Please register or login to post a comment