Showing
4 changed files
with
26 additions
and
23 deletions
| @@ -47,7 +47,6 @@ abstract class PdfFont extends PdfObjectDict { | @@ -47,7 +47,6 @@ abstract class PdfFont extends PdfObjectDict { | ||
| 47 | stdHW: 84, | 47 | stdHW: 84, |
| 48 | stdVW: 106, | 48 | stdVW: 106, |
| 49 | isFixedPitch: true, | 49 | isFixedPitch: true, |
| 50 | - missingWidth: 600, | ||
| 51 | ); | 50 | ); |
| 52 | } | 51 | } |
| 53 | 52 | ||
| @@ -63,7 +62,6 @@ abstract class PdfFont extends PdfObjectDict { | @@ -63,7 +62,6 @@ abstract class PdfFont extends PdfObjectDict { | ||
| 63 | stdHW: 51, | 62 | stdHW: 51, |
| 64 | stdVW: 51, | 63 | stdVW: 51, |
| 65 | isFixedPitch: true, | 64 | isFixedPitch: true, |
| 66 | - missingWidth: 600, | ||
| 67 | ); | 65 | ); |
| 68 | } | 66 | } |
| 69 | 67 | ||
| @@ -80,7 +78,6 @@ abstract class PdfFont extends PdfObjectDict { | @@ -80,7 +78,6 @@ abstract class PdfFont extends PdfObjectDict { | ||
| 80 | isFixedPitch: true, | 78 | isFixedPitch: true, |
| 81 | stdHW: 84, | 79 | stdHW: 84, |
| 82 | stdVW: 106, | 80 | stdVW: 106, |
| 83 | - missingWidth: 600, | ||
| 84 | ); | 81 | ); |
| 85 | } | 82 | } |
| 86 | 83 | ||
| @@ -97,7 +94,6 @@ abstract class PdfFont extends PdfObjectDict { | @@ -97,7 +94,6 @@ abstract class PdfFont extends PdfObjectDict { | ||
| 97 | italicAngle: -12, | 94 | italicAngle: -12, |
| 98 | stdHW: 51, | 95 | stdHW: 51, |
| 99 | stdVW: 51, | 96 | stdVW: 51, |
| 100 | - missingWidth: 600, | ||
| 101 | ); | 97 | ); |
| 102 | } | 98 | } |
| 103 | 99 | ||
| @@ -280,9 +276,6 @@ See https://github.com/DavBfr/dart_pdf/wiki/Fonts-Management | @@ -280,9 +276,6 @@ See https://github.com/DavBfr/dart_pdf/wiki/Fonts-Management | ||
| 280 | /// Spans the distance between the baseline and the lowest descending glyph | 276 | /// Spans the distance between the baseline and the lowest descending glyph |
| 281 | double get descent; | 277 | double get descent; |
| 282 | 278 | ||
| 283 | - /// Default width of a glyph | ||
| 284 | - static const double defaultGlyphWidth = 0.600; | ||
| 285 | - | ||
| 286 | /// Internal units per | 279 | /// Internal units per |
| 287 | int get unitsPerEm; | 280 | int get unitsPerEm; |
| 288 | 281 |
| @@ -42,7 +42,7 @@ class PdfType1Font extends PdfFont { | @@ -42,7 +42,7 @@ class PdfType1Font extends PdfFont { | ||
| 42 | required int stdHW, | 42 | required int stdHW, |
| 43 | required int stdVW, | 43 | required int stdVW, |
| 44 | bool isFixedPitch = false, | 44 | bool isFixedPitch = false, |
| 45 | - int? missingWidth, | 45 | + this.missingWidth = 0.600, |
| 46 | this.widths = const <double>[]}) | 46 | this.widths = const <double>[]}) |
| 47 | : assert(() { | 47 | : assert(() { |
| 48 | // ignore: avoid_print | 48 | // ignore: avoid_print |
| @@ -54,22 +54,26 @@ class PdfType1Font extends PdfFont { | @@ -54,22 +54,26 @@ class PdfType1Font extends PdfFont { | ||
| 54 | params['/BaseFont'] = PdfName('/$fontName'); | 54 | params['/BaseFont'] = PdfName('/$fontName'); |
| 55 | if (settings.version.index >= PdfVersion.pdf_1_5.index) { | 55 | if (settings.version.index >= PdfVersion.pdf_1_5.index) { |
| 56 | params['/FirstChar'] = const PdfNum(0); | 56 | params['/FirstChar'] = const PdfNum(0); |
| 57 | - params['/LastChar'] = const PdfNum(256); | ||
| 58 | - params['/Widths'] = PdfArray.fromNum(widths.map((e) => e * 1000)); | 57 | + params['/LastChar'] = const PdfNum(255); |
| 58 | + if (widths.isNotEmpty) { | ||
| 59 | + params['/Widths'] = | ||
| 60 | + PdfArray.fromNum(widths.map((e) => (e * unitsPerEm).toInt())); | ||
| 61 | + } else { | ||
| 62 | + params['/Widths'] = PdfArray.fromNum( | ||
| 63 | + List<int>.filled(256, (missingWidth * unitsPerEm).toInt())); | ||
| 64 | + } | ||
| 59 | 65 | ||
| 60 | final fontDescriptor = PdfObjectDict(pdfDocument, type: '/FontDescriptor') | 66 | final fontDescriptor = PdfObjectDict(pdfDocument, type: '/FontDescriptor') |
| 61 | ..params['/FontName'] = PdfName('/$fontName') | 67 | ..params['/FontName'] = PdfName('/$fontName') |
| 62 | ..params['/Flags'] = PdfNum(32 + (isFixedPitch ? 1 : 0)) | 68 | ..params['/Flags'] = PdfNum(32 + (isFixedPitch ? 1 : 0)) |
| 63 | ..params['/FontBBox'] = PdfArray.fromNum(fontBBox) | 69 | ..params['/FontBBox'] = PdfArray.fromNum(fontBBox) |
| 64 | - ..params['/Ascent'] = PdfNum((ascent * 1000).toInt()) | ||
| 65 | - ..params['/Descent'] = PdfNum((descent * 1000).toInt()) | 70 | + ..params['/Ascent'] = PdfNum((ascent * unitsPerEm).toInt()) |
| 71 | + ..params['/Descent'] = PdfNum((descent * unitsPerEm).toInt()) | ||
| 66 | ..params['/ItalicAngle'] = PdfNum(italicAngle) | 72 | ..params['/ItalicAngle'] = PdfNum(italicAngle) |
| 67 | ..params['/CapHeight'] = PdfNum(capHeight) | 73 | ..params['/CapHeight'] = PdfNum(capHeight) |
| 68 | ..params['/StemV'] = PdfNum(stdVW) | 74 | ..params['/StemV'] = PdfNum(stdVW) |
| 69 | - ..params['/StemH'] = PdfNum(stdHW); | ||
| 70 | - if (missingWidth != null) { | ||
| 71 | - fontDescriptor.params['/MissingWidth'] = PdfNum(missingWidth); | ||
| 72 | - } | 75 | + ..params['/StemH'] = PdfNum(stdHW) |
| 76 | + ..params['/MissingWidth'] = PdfNum((missingWidth * unitsPerEm).toInt()); | ||
| 73 | 77 | ||
| 74 | params['/FontDescriptor'] = fontDescriptor.ref(); | 78 | params['/FontDescriptor'] = fontDescriptor.ref(); |
| 75 | } | 79 | } |
| @@ -90,6 +94,9 @@ class PdfType1Font extends PdfFont { | @@ -90,6 +94,9 @@ class PdfType1Font extends PdfFont { | ||
| 90 | /// Width of each glyph | 94 | /// Width of each glyph |
| 91 | final List<double> widths; | 95 | final List<double> widths; |
| 92 | 96 | ||
| 97 | + /// Default width of a glyph | ||
| 98 | + final double missingWidth; | ||
| 99 | + | ||
| 93 | @override | 100 | @override |
| 94 | PdfFontMetrics glyphMetrics(int charCode) { | 101 | PdfFontMetrics glyphMetrics(int charCode) { |
| 95 | if (!isRuneSupported(charCode)) { | 102 | if (!isRuneSupported(charCode)) { |
| @@ -98,12 +105,11 @@ class PdfType1Font extends PdfFont { | @@ -98,12 +105,11 @@ class PdfType1Font extends PdfFont { | ||
| 98 | } | 105 | } |
| 99 | 106 | ||
| 100 | return PdfFontMetrics( | 107 | return PdfFontMetrics( |
| 101 | - left: 0, | ||
| 102 | - top: descent, | ||
| 103 | - right: charCode < widths.length | ||
| 104 | - ? widths[charCode] | ||
| 105 | - : PdfFont.defaultGlyphWidth, | ||
| 106 | - bottom: ascent); | 108 | + left: 0, |
| 109 | + top: descent, | ||
| 110 | + right: charCode < widths.length ? widths[charCode] : missingWidth, | ||
| 111 | + bottom: ascent, | ||
| 112 | + ); | ||
| 107 | } | 113 | } |
| 108 | 114 | ||
| 109 | @override | 115 | @override |
| @@ -6,7 +6,7 @@ issue_tracker: https://github.com/DavBfr/dart_pdf/issues | @@ -6,7 +6,7 @@ issue_tracker: https://github.com/DavBfr/dart_pdf/issues | ||
| 6 | screenshots: | 6 | screenshots: |
| 7 | - description: 'Example of a generated document' | 7 | - description: 'Example of a generated document' |
| 8 | path: example.jpg | 8 | path: example.jpg |
| 9 | -version: 3.10.1 | 9 | +version: 3.10.2 |
| 10 | 10 | ||
| 11 | environment: | 11 | environment: |
| 12 | sdk: ">=2.18.0 <3.0.0" | 12 | sdk: ">=2.18.0 <3.0.0" |
-
Please register or login to post a comment