Showing
5 changed files
with
194 additions
and
29 deletions
@@ -33,11 +33,11 @@ class PdfArray<T extends PdfDataType> extends PdfDataType { | @@ -33,11 +33,11 @@ class PdfArray<T extends PdfDataType> extends PdfDataType { | ||
33 | } | 33 | } |
34 | } | 34 | } |
35 | 35 | ||
36 | - static PdfArray<PdfIndirect> fromObjects(List<PdfObjectBase> objects) { | 36 | + static PdfArray<PdfIndirect> fromObjects(Iterable<PdfObjectBase> objects) { |
37 | return PdfArray(objects.map<PdfIndirect>((e) => e.ref()).toList()); | 37 | return PdfArray(objects.map<PdfIndirect>((e) => e.ref()).toList()); |
38 | } | 38 | } |
39 | 39 | ||
40 | - static PdfArray<PdfNum> fromNum(List<num> list) { | 40 | + static PdfArray<PdfNum> fromNum(Iterable<num> list) { |
41 | return PdfArray(list.map<PdfNum>((num e) => PdfNum(e)).toList()); | 41 | return PdfArray(list.map<PdfNum>((num e) => PdfNum(e)).toList()); |
42 | } | 42 | } |
43 | 43 |
@@ -38,86 +38,222 @@ abstract class PdfFont extends PdfObjectDict { | @@ -38,86 +38,222 @@ abstract class PdfFont extends PdfObjectDict { | ||
38 | /// Monospaced slab serif typeface. | 38 | /// Monospaced slab serif typeface. |
39 | factory PdfFont.courier(PdfDocument pdfDocument) { | 39 | factory PdfFont.courier(PdfDocument pdfDocument) { |
40 | return PdfType1Font.create( | 40 | return PdfType1Font.create( |
41 | - pdfDocument, 'Courier', 0.910, -0.220, const <double>[]); | 41 | + pdfDocument, |
42 | + fontName: 'Courier', | ||
43 | + ascent: 0.910, | ||
44 | + descent: -0.220, | ||
45 | + fontBBox: [-23, -250, 715, 805], | ||
46 | + capHeight: 562, | ||
47 | + stdHW: 84, | ||
48 | + stdVW: 106, | ||
49 | + isFixedPitch: true, | ||
50 | + missingWidth: 600, | ||
51 | + ); | ||
42 | } | 52 | } |
43 | 53 | ||
44 | /// Bold monospaced slab serif typeface. | 54 | /// Bold monospaced slab serif typeface. |
45 | factory PdfFont.courierBold(PdfDocument pdfDocument) { | 55 | factory PdfFont.courierBold(PdfDocument pdfDocument) { |
46 | return PdfType1Font.create( | 56 | return PdfType1Font.create( |
47 | - pdfDocument, 'Courier-Bold', 0.910, -0.220, const <double>[]); | 57 | + pdfDocument, |
58 | + fontName: 'Courier-Bold', | ||
59 | + ascent: 0.910, | ||
60 | + descent: -0.220, | ||
61 | + fontBBox: [-113, -250, 749, 801], | ||
62 | + capHeight: 562, | ||
63 | + stdHW: 51, | ||
64 | + stdVW: 51, | ||
65 | + isFixedPitch: true, | ||
66 | + missingWidth: 600, | ||
67 | + ); | ||
48 | } | 68 | } |
49 | 69 | ||
50 | /// Bold and Italic monospaced slab serif typeface. | 70 | /// Bold and Italic monospaced slab serif typeface. |
51 | factory PdfFont.courierBoldOblique(PdfDocument pdfDocument) { | 71 | factory PdfFont.courierBoldOblique(PdfDocument pdfDocument) { |
52 | return PdfType1Font.create( | 72 | return PdfType1Font.create( |
53 | - pdfDocument, 'Courier-BoldOblique', 0.910, -0.220, const <double>[]); | 73 | + pdfDocument, |
74 | + fontName: 'Courier-BoldOblique', | ||
75 | + ascent: 0.910, | ||
76 | + descent: -0.220, | ||
77 | + fontBBox: [-57, -250, 869, 801], | ||
78 | + capHeight: 562, | ||
79 | + italicAngle: -12, | ||
80 | + isFixedPitch: true, | ||
81 | + stdHW: 84, | ||
82 | + stdVW: 106, | ||
83 | + missingWidth: 600, | ||
84 | + ); | ||
54 | } | 85 | } |
55 | 86 | ||
56 | /// Italic monospaced slab serif typeface. | 87 | /// Italic monospaced slab serif typeface. |
57 | factory PdfFont.courierOblique(PdfDocument pdfDocument) { | 88 | factory PdfFont.courierOblique(PdfDocument pdfDocument) { |
58 | return PdfType1Font.create( | 89 | return PdfType1Font.create( |
59 | - pdfDocument, 'Courier-Oblique', 0.910, -0.220, const <double>[]); | 90 | + pdfDocument, |
91 | + fontName: 'Courier-Oblique', | ||
92 | + ascent: 0.910, | ||
93 | + descent: -0.220, | ||
94 | + fontBBox: [-27, -250, 849, 805], | ||
95 | + capHeight: 562, | ||
96 | + isFixedPitch: true, | ||
97 | + italicAngle: -12, | ||
98 | + stdHW: 51, | ||
99 | + stdVW: 51, | ||
100 | + missingWidth: 600, | ||
101 | + ); | ||
60 | } | 102 | } |
61 | 103 | ||
62 | /// Neo-grotesque design sans-serif typeface | 104 | /// Neo-grotesque design sans-serif typeface |
63 | factory PdfFont.helvetica(PdfDocument pdfDocument) { | 105 | factory PdfFont.helvetica(PdfDocument pdfDocument) { |
64 | return PdfType1Font.create( | 106 | return PdfType1Font.create( |
65 | - pdfDocument, 'Helvetica', 0.931, -0.225, helveticaWidths); | 107 | + pdfDocument, |
108 | + fontName: 'Helvetica', | ||
109 | + ascent: 0.931, | ||
110 | + descent: -0.225, | ||
111 | + widths: helveticaWidths, | ||
112 | + fontBBox: [-166, -225, 1000, 931], | ||
113 | + capHeight: 718, | ||
114 | + stdHW: 76, | ||
115 | + stdVW: 88, | ||
116 | + ); | ||
66 | } | 117 | } |
67 | 118 | ||
68 | /// Bold Neo-grotesque design sans-serif typeface | 119 | /// Bold Neo-grotesque design sans-serif typeface |
69 | factory PdfFont.helveticaBold(PdfDocument pdfDocument) { | 120 | factory PdfFont.helveticaBold(PdfDocument pdfDocument) { |
70 | return PdfType1Font.create( | 121 | return PdfType1Font.create( |
71 | - pdfDocument, 'Helvetica-Bold', 0.962, -0.228, helveticaBoldWidths); | 122 | + pdfDocument, |
123 | + fontName: 'Helvetica-Bold', | ||
124 | + ascent: 0.962, | ||
125 | + descent: -0.228, | ||
126 | + widths: helveticaBoldWidths, | ||
127 | + fontBBox: [-170, -228, 1003, 962], | ||
128 | + capHeight: 718, | ||
129 | + stdHW: 118, | ||
130 | + stdVW: 140, | ||
131 | + ); | ||
72 | } | 132 | } |
73 | 133 | ||
74 | /// Bold and Italic Neo-grotesque design sans-serif typeface | 134 | /// Bold and Italic Neo-grotesque design sans-serif typeface |
75 | factory PdfFont.helveticaBoldOblique(PdfDocument pdfDocument) { | 135 | factory PdfFont.helveticaBoldOblique(PdfDocument pdfDocument) { |
76 | - return PdfType1Font.create(pdfDocument, 'Helvetica-BoldOblique', 0.962, | ||
77 | - -0.228, helveticaBoldObliqueWidths); | 136 | + return PdfType1Font.create( |
137 | + pdfDocument, | ||
138 | + fontName: 'Helvetica-BoldOblique', | ||
139 | + ascent: 0.962, | ||
140 | + descent: -0.228, | ||
141 | + widths: helveticaBoldObliqueWidths, | ||
142 | + italicAngle: -12, | ||
143 | + fontBBox: [-170, -228, 1114, 962], | ||
144 | + capHeight: 718, | ||
145 | + stdHW: 118, | ||
146 | + stdVW: 140, | ||
147 | + ); | ||
78 | } | 148 | } |
79 | 149 | ||
80 | /// Italic Neo-grotesque design sans-serif typeface | 150 | /// Italic Neo-grotesque design sans-serif typeface |
81 | factory PdfFont.helveticaOblique(PdfDocument pdfDocument) { | 151 | factory PdfFont.helveticaOblique(PdfDocument pdfDocument) { |
82 | - return PdfType1Font.create(pdfDocument, 'Helvetica-Oblique', 0.931, -0.225, | ||
83 | - helveticaObliqueWidths); | 152 | + return PdfType1Font.create( |
153 | + pdfDocument, | ||
154 | + fontName: 'Helvetica-Oblique', | ||
155 | + ascent: 0.931, | ||
156 | + descent: -0.225, | ||
157 | + widths: helveticaObliqueWidths, | ||
158 | + italicAngle: -12, | ||
159 | + fontBBox: [-170, -225, 1116, 931], | ||
160 | + capHeight: 718, | ||
161 | + stdHW: 76, | ||
162 | + stdVW: 88, | ||
163 | + ); | ||
84 | } | 164 | } |
85 | 165 | ||
86 | /// Serif typeface commissioned by the British newspaper The Times | 166 | /// Serif typeface commissioned by the British newspaper The Times |
87 | factory PdfFont.times(PdfDocument pdfDocument) { | 167 | factory PdfFont.times(PdfDocument pdfDocument) { |
88 | return PdfType1Font.create( | 168 | return PdfType1Font.create( |
89 | - pdfDocument, 'Times-Roman', 0.898, -0.218, timesWidths); | 169 | + pdfDocument, |
170 | + fontName: 'Times-Roman', | ||
171 | + ascent: 0.898, | ||
172 | + descent: -0.218, | ||
173 | + widths: timesWidths, | ||
174 | + fontBBox: [-168, -218, 1000, 898], | ||
175 | + capHeight: 662, | ||
176 | + stdHW: 28, | ||
177 | + stdVW: 84, | ||
178 | + ); | ||
90 | } | 179 | } |
91 | 180 | ||
92 | /// Bold serif typeface commissioned by the British newspaper The Times | 181 | /// Bold serif typeface commissioned by the British newspaper The Times |
93 | factory PdfFont.timesBold(PdfDocument pdfDocument) { | 182 | factory PdfFont.timesBold(PdfDocument pdfDocument) { |
94 | return PdfType1Font.create( | 183 | return PdfType1Font.create( |
95 | - pdfDocument, 'Times-Bold', 0.935, -0.218, timesBoldWidths); | 184 | + pdfDocument, |
185 | + fontName: 'Times-Bold', | ||
186 | + ascent: 0.935, | ||
187 | + descent: -0.218, | ||
188 | + widths: timesBoldWidths, | ||
189 | + fontBBox: [-168, -218, 1000, 935], | ||
190 | + capHeight: 676, | ||
191 | + stdHW: 44, | ||
192 | + stdVW: 139, | ||
193 | + ); | ||
96 | } | 194 | } |
97 | 195 | ||
98 | /// Bold and Italic serif typeface commissioned by the British newspaper The Times | 196 | /// Bold and Italic serif typeface commissioned by the British newspaper The Times |
99 | factory PdfFont.timesBoldItalic(PdfDocument pdfDocument) { | 197 | factory PdfFont.timesBoldItalic(PdfDocument pdfDocument) { |
100 | return PdfType1Font.create( | 198 | return PdfType1Font.create( |
101 | - pdfDocument, 'Times-BoldItalic', 0.921, -0.218, timesBoldItalicWidths); | 199 | + pdfDocument, |
200 | + fontName: 'Times-BoldItalic', | ||
201 | + ascent: 0.921, | ||
202 | + descent: -0.218, | ||
203 | + widths: timesBoldItalicWidths, | ||
204 | + italicAngle: -15, | ||
205 | + fontBBox: [-200, -218, 996, 921], | ||
206 | + capHeight: 669, | ||
207 | + stdHW: 42, | ||
208 | + stdVW: 121, | ||
209 | + ); | ||
102 | } | 210 | } |
103 | 211 | ||
104 | /// Italic serif typeface commissioned by the British newspaper The Times | 212 | /// Italic serif typeface commissioned by the British newspaper The Times |
105 | factory PdfFont.timesItalic(PdfDocument pdfDocument) { | 213 | factory PdfFont.timesItalic(PdfDocument pdfDocument) { |
106 | return PdfType1Font.create( | 214 | return PdfType1Font.create( |
107 | - pdfDocument, 'Times-Italic', 0.883, -0.217, timesItalicWidths); | 215 | + pdfDocument, |
216 | + fontName: 'Times-Italic', | ||
217 | + ascent: 0.883, | ||
218 | + descent: -0.217, | ||
219 | + widths: timesItalicWidths, | ||
220 | + italicAngle: -15.5, | ||
221 | + fontBBox: [-169, -217, 1010, 883], | ||
222 | + capHeight: 653, | ||
223 | + stdHW: 32, | ||
224 | + stdVW: 76, | ||
225 | + ); | ||
108 | } | 226 | } |
109 | 227 | ||
110 | /// Complete unaccented serif Greek alphabet (upper and lower case) and a | 228 | /// Complete unaccented serif Greek alphabet (upper and lower case) and a |
111 | /// selection of commonly used mathematical symbols. | 229 | /// selection of commonly used mathematical symbols. |
112 | factory PdfFont.symbol(PdfDocument pdfDocument) { | 230 | factory PdfFont.symbol(PdfDocument pdfDocument) { |
113 | return PdfType1Font.create( | 231 | return PdfType1Font.create( |
114 | - pdfDocument, 'Symbol', 1.010, -0.293, symbolWidths); | 232 | + pdfDocument, |
233 | + fontName: 'Symbol', | ||
234 | + ascent: 1.010, | ||
235 | + descent: -0.293, | ||
236 | + widths: symbolWidths, | ||
237 | + fontBBox: [-180, -293, 1090, 1010], | ||
238 | + capHeight: 653, | ||
239 | + stdHW: 92, | ||
240 | + stdVW: 85, | ||
241 | + ); | ||
115 | } | 242 | } |
116 | 243 | ||
117 | /// Hermann Zapf ornament glyphs or spacers, often employed to create box frames | 244 | /// Hermann Zapf ornament glyphs or spacers, often employed to create box frames |
118 | factory PdfFont.zapfDingbats(PdfDocument pdfDocument) { | 245 | factory PdfFont.zapfDingbats(PdfDocument pdfDocument) { |
119 | return PdfType1Font.create( | 246 | return PdfType1Font.create( |
120 | - pdfDocument, 'ZapfDingbats', 0.820, -0.143, zapfDingbatsWidths); | 247 | + pdfDocument, |
248 | + fontName: 'ZapfDingbats', | ||
249 | + ascent: 0.820, | ||
250 | + descent: -0.143, | ||
251 | + widths: zapfDingbatsWidths, | ||
252 | + fontBBox: [-1, -143, 981, 820], | ||
253 | + capHeight: 653, | ||
254 | + stdHW: 28, | ||
255 | + stdVW: 90, | ||
256 | + ); | ||
121 | } | 257 | } |
122 | 258 | ||
123 | static const String _cannotDecodeMessage = | 259 | static const String _cannotDecodeMessage = |
@@ -14,10 +14,12 @@ | @@ -14,10 +14,12 @@ | ||
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | 16 | ||
17 | +import '../../priv.dart'; | ||
17 | import '../document.dart'; | 18 | import '../document.dart'; |
18 | import '../font/font_metrics.dart'; | 19 | import '../font/font_metrics.dart'; |
19 | -import '../format/name.dart'; | 20 | +import '../format/object_base.dart'; |
20 | import 'font.dart'; | 21 | import 'font.dart'; |
22 | +import 'object_dict.dart'; | ||
21 | import 'ttffont.dart'; | 23 | import 'ttffont.dart'; |
22 | 24 | ||
23 | /// Type 1 font object. | 25 | /// Type 1 font object. |
@@ -30,15 +32,48 @@ import 'ttffont.dart'; | @@ -30,15 +32,48 @@ import 'ttffont.dart'; | ||
30 | /// see https://github.com/DavBfr/dart_pdf/wiki/Fonts-Management | 32 | /// see https://github.com/DavBfr/dart_pdf/wiki/Fonts-Management |
31 | class PdfType1Font extends PdfFont { | 33 | class PdfType1Font extends PdfFont { |
32 | /// Constructs a [PdfTtfFont] | 34 | /// Constructs a [PdfTtfFont] |
33 | - PdfType1Font.create(PdfDocument pdfDocument, this.fontName, this.ascent, | ||
34 | - this.descent, this.widths) | 35 | + PdfType1Font.create(PdfDocument pdfDocument, |
36 | + {required this.fontName, | ||
37 | + required this.ascent, | ||
38 | + required this.descent, | ||
39 | + required List<int> fontBBox, | ||
40 | + double italicAngle = 0, | ||
41 | + required int capHeight, | ||
42 | + required int stdHW, | ||
43 | + required int stdVW, | ||
44 | + bool isFixedPitch = false, | ||
45 | + int? missingWidth, | ||
46 | + this.widths = const <double>[]}) | ||
35 | : assert(() { | 47 | : assert(() { |
36 | // ignore: avoid_print | 48 | // ignore: avoid_print |
37 | print( | 49 | print( |
38 | '$fontName has no Unicode support see https://github.com/DavBfr/dart_pdf/wiki/Fonts-Management'); | 50 | '$fontName has no Unicode support see https://github.com/DavBfr/dart_pdf/wiki/Fonts-Management'); |
39 | return true; | 51 | return true; |
40 | }()), | 52 | }()), |
41 | - super.create(pdfDocument, subtype: '/Type1'); | 53 | + super.create(pdfDocument, subtype: '/Type1') { |
54 | + params['/BaseFont'] = PdfName('/$fontName'); | ||
55 | + if (version.index >= PdfVersion.pdf_1_5.index) { | ||
56 | + params['/FirstChar'] = const PdfNum(0); | ||
57 | + params['/LastChar'] = const PdfNum(256); | ||
58 | + params['/Widths'] = PdfArray.fromNum(widths.map((e) => e * 1000)); | ||
59 | + | ||
60 | + final fontDescriptor = PdfObjectDict(pdfDocument, type: '/FontDescriptor') | ||
61 | + ..params['/FontName'] = PdfName('/$fontName') | ||
62 | + ..params['/Flags'] = PdfNum(32 + (isFixedPitch ? 1 : 0)) | ||
63 | + ..params['/FontBBox'] = PdfArray.fromNum(fontBBox) | ||
64 | + ..params['/Ascent'] = PdfNum((ascent * 1000).toInt()) | ||
65 | + ..params['/Descent'] = PdfNum((descent * 1000).toInt()) | ||
66 | + ..params['/ItalicAngle'] = PdfNum(italicAngle) | ||
67 | + ..params['/CapHeight'] = PdfNum(capHeight) | ||
68 | + ..params['/StemV'] = PdfNum(stdVW) | ||
69 | + ..params['/StemH'] = PdfNum(stdHW); | ||
70 | + if (missingWidth != null) { | ||
71 | + fontDescriptor.params['/MissingWidth'] = PdfNum(missingWidth); | ||
72 | + } | ||
73 | + | ||
74 | + params['/FontDescriptor'] = fontDescriptor.ref(); | ||
75 | + } | ||
76 | + } | ||
42 | 77 | ||
43 | @override | 78 | @override |
44 | final String fontName; | 79 | final String fontName; |
@@ -56,13 +91,6 @@ class PdfType1Font extends PdfFont { | @@ -56,13 +91,6 @@ class PdfType1Font extends PdfFont { | ||
56 | final List<double> widths; | 91 | final List<double> widths; |
57 | 92 | ||
58 | @override | 93 | @override |
59 | - void prepare() { | ||
60 | - super.prepare(); | ||
61 | - | ||
62 | - params['/BaseFont'] = PdfName('/$fontName'); | ||
63 | - } | ||
64 | - | ||
65 | - @override | ||
66 | PdfFontMetrics glyphMetrics(int charCode) { | 94 | PdfFontMetrics glyphMetrics(int charCode) { |
67 | if (!isRuneSupported(charCode)) { | 95 | if (!isRuneSupported(charCode)) { |
68 | throw Exception( | 96 | throw Exception( |
No preview for this file type
-
Please register or login to post a comment