David PHAM-VAN

Fix TTF font issues

@@ -15,7 +15,7 @@ @@ -15,7 +15,7 @@
15 DART_SRC=$(shell find . -name '*.dart') 15 DART_SRC=$(shell find . -name '*.dart')
16 CLNG_SRC=$(shell find printing/ios -name '*.java' -o -name '*.m' -o -name '*.h') $(shell find printing/android -name '*.java' -o -name '*.m' -o -name '*.h') 16 CLNG_SRC=$(shell find printing/ios -name '*.java' -o -name '*.m' -o -name '*.h') $(shell find printing/android -name '*.java' -o -name '*.m' -o -name '*.h')
17 SWFT_SRC=$(shell find . -name '*.swift') 17 SWFT_SRC=$(shell find . -name '*.swift')
18 - FONTS=pdf/open-sans.ttf pdf/roboto.ttf pdf/noto-sans.ttf 18 + FONTS=pdf/open-sans.ttf pdf/roboto.ttf pdf/noto-sans.ttf pdf/genyomintw.ttf
19 19
20 all: $(FONTS) format 20 all: $(FONTS) format
21 21
@@ -28,6 +28,9 @@ pdf/roboto.ttf: @@ -28,6 +28,9 @@ pdf/roboto.ttf:
28 pdf/noto-sans.ttf: 28 pdf/noto-sans.ttf:
29 curl -L "https://raw.githubusercontent.com/google/fonts/master/ofl/notosans/NotoSans-Regular.ttf" > $@ 29 curl -L "https://raw.githubusercontent.com/google/fonts/master/ofl/notosans/NotoSans-Regular.ttf" > $@
30 30
  31 +pdf/genyomintw.ttf:
  32 + curl -L "https://github.com/ButTaiwan/genyo-font/raw/master/TW/GenYoMinTW-Heavy.ttf" > $@
  33 +
31 format: format-dart format-clang format-swift 34 format: format-dart format-clang format-swift
32 35
33 format-dart: $(DART_SRC) 36 format-dart: $(DART_SRC)
@@ -49,7 +49,7 @@ void main() { @@ -49,7 +49,7 @@ void main() {
49 'The Portable Document Format (PDF) is a file format developed by Adobe in the 1990s to present documents, including text formatting and images, in a manner independent of application software, hardware, and operating systems. Based on the PostScript language, each PDF file encapsulates a complete description of a fixed-layout flat document, including the text, fonts, vector graphics, raster images and other information needed to display it. PDF was standardized as an open format, ISO 32000, in 2008, and no longer requires any royalties for its implementation.'), 49 'The Portable Document Format (PDF) is a file format developed by Adobe in the 1990s to present documents, including text formatting and images, in a manner independent of application software, hardware, and operating systems. Based on the PostScript language, each PDF file encapsulates a complete description of a fixed-layout flat document, including the text, fonts, vector graphics, raster images and other information needed to display it. PDF was standardized as an open format, ISO 32000, in 2008, and no longer requires any royalties for its implementation.'),
50 Paragraph( 50 Paragraph(
51 text: 51 text:
52 - 'Today, PDF files may contain a variety of content besides flat text and graphics including logical structuring elements, interactive elements such as annotations and form-fields, layers, rich media (including video content) and three dimensional objects using U3D or PRC, and various other data formats.[citation needed] The PDF specification also provides for encryption and digital signatures, file attachments and metadata to enable workflows requiring these features.'), 52 + 'Today, PDF files may contain a variety of content besides flat text and graphics including logical structuring elements, interactive elements such as annotations and form-fields, layers, rich media (including video content) and three dimensional objects using U3D or PRC, and various other data formats. The PDF specification also provides for encryption and digital signatures, file attachments and metadata to enable workflows requiring these features.'),
53 Header(level: 1, text: 'History and standardization'), 53 Header(level: 1, text: 'History and standardization'),
54 Paragraph( 54 Paragraph(
55 text: 55 text:
@@ -67,8 +67,8 @@ class TtfWriter { @@ -67,8 +67,8 @@ class TtfWriter {
67 continue; 67 continue;
68 } 68 }
69 69
70 - final TtfGlyphInfo glyph = ttf.readGlyph(  
71 - chars[index] == 0 ? 0 : ttf.charToGlyphIndexMap[chars[index]]); 70 + final TtfGlyphInfo glyph =
  71 + ttf.readGlyph(ttf.charToGlyphIndexMap[chars[index]] ?? 0);
72 for (int g in glyph.compounds) { 72 for (int g in glyph.compounds) {
73 compounds[g] = null; 73 compounds[g] = null;
74 } 74 }
@@ -56,6 +56,7 @@ class Font { @@ -56,6 +56,7 @@ class Font {
56 factory Font.timesItalic() => Font.type1(Type1Fonts.timesItalic); 56 factory Font.timesItalic() => Font.type1(Type1Fonts.timesItalic);
57 factory Font.symbol() => Font.type1(Type1Fonts.symbol); 57 factory Font.symbol() => Font.type1(Type1Fonts.symbol);
58 factory Font.zapfDingbats() => Font.type1(Type1Fonts.zapfDingbats); 58 factory Font.zapfDingbats() => Font.type1(Type1Fonts.zapfDingbats);
  59 + factory Font.ttf(ByteData data) => TtfFont(data);
59 60
60 final Type1Fonts font; 61 final Type1Fonts font;
61 62
@@ -70,6 +70,7 @@ void main() { @@ -70,6 +70,7 @@ void main() {
70 printTextTtf(g, s, File('open-sans.ttf'), 30.0 + 30.0 * top++); 70 printTextTtf(g, s, File('open-sans.ttf'), 30.0 + 30.0 * top++);
71 printTextTtf(g, s, File('roboto.ttf'), 30.0 + 30.0 * top++); 71 printTextTtf(g, s, File('roboto.ttf'), 30.0 + 30.0 * top++);
72 printTextTtf(g, s, File('noto-sans.ttf'), 30.0 + 30.0 * top++); 72 printTextTtf(g, s, File('noto-sans.ttf'), 30.0 + 30.0 * top++);
  73 + printTextTtf(g, '你好 檯號 ', File('genyomintw.ttf'), 30.0 + 30.0 * top++);
73 74
74 final File file = File('ttf.pdf'); 75 final File file = File('ttf.pdf');
75 file.writeAsBytesSync(pdf.save()); 76 file.writeAsBytesSync(pdf.save());