David PHAM-VAN

Fix Type1 font widths

# Changelog
## 3.10.2
- Fix Type1 font widths
## 3.10.1
- Fix web debug build
... ...
... ... @@ -47,7 +47,6 @@ abstract class PdfFont extends PdfObjectDict {
stdHW: 84,
stdVW: 106,
isFixedPitch: true,
missingWidth: 600,
);
}
... ... @@ -63,7 +62,6 @@ abstract class PdfFont extends PdfObjectDict {
stdHW: 51,
stdVW: 51,
isFixedPitch: true,
missingWidth: 600,
);
}
... ... @@ -80,7 +78,6 @@ abstract class PdfFont extends PdfObjectDict {
isFixedPitch: true,
stdHW: 84,
stdVW: 106,
missingWidth: 600,
);
}
... ... @@ -97,7 +94,6 @@ abstract class PdfFont extends PdfObjectDict {
italicAngle: -12,
stdHW: 51,
stdVW: 51,
missingWidth: 600,
);
}
... ... @@ -280,9 +276,6 @@ See https://github.com/DavBfr/dart_pdf/wiki/Fonts-Management
/// Spans the distance between the baseline and the lowest descending glyph
double get descent;
/// Default width of a glyph
static const double defaultGlyphWidth = 0.600;
/// Internal units per
int get unitsPerEm;
... ...
... ... @@ -42,7 +42,7 @@ class PdfType1Font extends PdfFont {
required int stdHW,
required int stdVW,
bool isFixedPitch = false,
int? missingWidth,
this.missingWidth = 0.600,
this.widths = const <double>[]})
: assert(() {
// ignore: avoid_print
... ... @@ -54,22 +54,26 @@ class PdfType1Font extends PdfFont {
params['/BaseFont'] = PdfName('/$fontName');
if (settings.version.index >= PdfVersion.pdf_1_5.index) {
params['/FirstChar'] = const PdfNum(0);
params['/LastChar'] = const PdfNum(256);
params['/Widths'] = PdfArray.fromNum(widths.map((e) => e * 1000));
params['/LastChar'] = const PdfNum(255);
if (widths.isNotEmpty) {
params['/Widths'] =
PdfArray.fromNum(widths.map((e) => (e * unitsPerEm).toInt()));
} else {
params['/Widths'] = PdfArray.fromNum(
List<int>.filled(256, (missingWidth * unitsPerEm).toInt()));
}
final fontDescriptor = PdfObjectDict(pdfDocument, type: '/FontDescriptor')
..params['/FontName'] = PdfName('/$fontName')
..params['/Flags'] = PdfNum(32 + (isFixedPitch ? 1 : 0))
..params['/FontBBox'] = PdfArray.fromNum(fontBBox)
..params['/Ascent'] = PdfNum((ascent * 1000).toInt())
..params['/Descent'] = PdfNum((descent * 1000).toInt())
..params['/Ascent'] = PdfNum((ascent * unitsPerEm).toInt())
..params['/Descent'] = PdfNum((descent * unitsPerEm).toInt())
..params['/ItalicAngle'] = PdfNum(italicAngle)
..params['/CapHeight'] = PdfNum(capHeight)
..params['/StemV'] = PdfNum(stdVW)
..params['/StemH'] = PdfNum(stdHW);
if (missingWidth != null) {
fontDescriptor.params['/MissingWidth'] = PdfNum(missingWidth);
}
..params['/StemH'] = PdfNum(stdHW)
..params['/MissingWidth'] = PdfNum((missingWidth * unitsPerEm).toInt());
params['/FontDescriptor'] = fontDescriptor.ref();
}
... ... @@ -90,6 +94,9 @@ class PdfType1Font extends PdfFont {
/// Width of each glyph
final List<double> widths;
/// Default width of a glyph
final double missingWidth;
@override
PdfFontMetrics glyphMetrics(int charCode) {
if (!isRuneSupported(charCode)) {
... ... @@ -98,12 +105,11 @@ class PdfType1Font extends PdfFont {
}
return PdfFontMetrics(
left: 0,
top: descent,
right: charCode < widths.length
? widths[charCode]
: PdfFont.defaultGlyphWidth,
bottom: ascent);
left: 0,
top: descent,
right: charCode < widths.length ? widths[charCode] : missingWidth,
bottom: ascent,
);
}
@override
... ...
... ... @@ -6,7 +6,7 @@ issue_tracker: https://github.com/DavBfr/dart_pdf/issues
screenshots:
- description: 'Example of a generated document'
path: example.jpg
version: 3.10.1
version: 3.10.2
environment:
sdk: ">=2.18.0 <3.0.0"
... ...