David PHAM-VAN

Fix Font Subsetting

# 1.3.6
* Fix TTF Font SubSetting
# 1.3.5
* Add some color functions
* Remove color constants from PdfColor, use PdfColors
... ...
... ... @@ -77,13 +77,16 @@ class TtfWriter {
// Add compound glyphs
for (int compound in compounds.keys) {
final int index = chars.indexOf(compound);
if (index >= 0) {
compounds[compound] = index;
final TtfGlyphInfo index = glyphsInfo.firstWhere(
(TtfGlyphInfo glyph) => glyph.index == compound,
orElse: () => null);
if (index != null) {
compounds[compound] = glyphsInfo.indexOf(index);
assert(compounds[compound] >= 0, 'Unable to find the glyph');
} else {
compounds[compound] = glyphsInfo.length;
final TtfGlyphInfo glyph = ttf.readGlyph(compound);
assert(glyph.compounds.isEmpty); // This is a simple glyph
assert(glyph.compounds.isEmpty, 'This is not a simple glyph');
glyphsInfo.add(glyph);
}
}
... ...
... ... @@ -4,7 +4,7 @@ description: A pdf producer for Dart. It can create pdf files for both web or fl
homepage: https://github.com/DavBfr/dart_pdf/tree/master/pdf
repository: https://github.com/DavBfr/dart_pdf
issue_tracker: https://github.com/DavBfr/dart_pdf/issues
version: 1.3.5
version: 1.3.6
environment:
sdk: ">=2.1.0 <3.0.0"
... ...
... ... @@ -75,4 +75,22 @@ void main() {
final File file = File('ttf.pdf');
file.writeAsBytesSync(pdf.save());
});
test('Font SubSetting', () {
final Uint8List fontData = File('open-sans.ttf').readAsBytesSync();
final TtfParser font = TtfParser(fontData.buffer.asByteData());
final TtfWriter ttfWriter = TtfWriter(font);
final Uint8List data = ttfWriter.withChars('hçHée'.runes.toList());
final File output = File('${font.fontName}.ttf');
output.writeAsBytesSync(data);
});
test('Font SubSetting CN', () {
final Uint8List fontData = File('genyomintw.ttf').readAsBytesSync();
final TtfParser font = TtfParser(fontData.buffer.asByteData());
final TtfWriter ttfWriter = TtfWriter(font);
final Uint8List data = ttfWriter.withChars('hçHée 你好 檯號 ☃'.runes.toList());
final File output = File('${font.fontName}.ttf');
output.writeAsBytesSync(data);
});
}
... ...