David PHAM-VAN

Improve font bounds calculation

Too many changes to show.

To preserve performance only 10 of 10+ files are displayed.

# 1.3.3
* Fix dart lint warnings
* Improve font bounds calculation
# 1.3.2
* Update Readme
... ...
... ... @@ -34,6 +34,7 @@ part 'src/compatibility.dart';
part 'src/document.dart';
part 'src/font.dart';
part 'src/font_descriptor.dart';
part 'src/font_metrics.dart';
part 'src/formxobject.dart';
part 'src/graphics.dart';
part 'src/image.dart';
... ... @@ -52,5 +53,6 @@ part 'src/stream.dart';
part 'src/ttf_parser.dart';
part 'src/ttffont.dart';
part 'src/type1_font.dart';
part 'src/type1_fonts.dart';
part 'src/xobject.dart';
part 'src/xref.dart';
... ...
... ... @@ -128,6 +128,11 @@ class PDFFont extends PdfFont {
subtype ??= baseFont;
return PdfFont.helvetica(pdfDocument);
}
@override
PdfFontMetrics glyphMetrics(int charCode) {
return PdfFontMetrics.zero;
}
}
@deprecated
... ...
... ... @@ -16,7 +16,7 @@
part of pdf;
class PdfFont extends PdfObject {
abstract class PdfFont extends PdfObject {
/// Constructs a [PdfFont]. This will attempt to map the font from a known
/// font name to that in Pdf, defaulting to Helvetica if not possible.
///
... ... @@ -24,2647 +24,79 @@ class PdfFont extends PdfObject {
/// @param subtype The pdf type, ie /Type1
/// @param baseFont The font name, ie /Helvetica
PdfFont._create(PdfDocument pdfDocument, {@required this.subtype})
: super(pdfDocument, '/Font') {
: assert(subtype != null),
super(pdfDocument, '/Font') {
pdfDocument.fonts.add(this);
}
factory PdfFont.courier(PdfDocument pdfDocument) {
return PdfType1Font._create(pdfDocument, 'Courier', 0.910, -0.220,
List<double>.generate(256, (int index) => 0.600));
return PdfType1Font._create(
pdfDocument, 'Courier', 0.910, -0.220, const <double>[]);
}
factory PdfFont.courierBold(PdfDocument pdfDocument) {
return PdfType1Font._create(pdfDocument, 'Courier-Bold', 0.910, -0.220,
List<double>.generate(256, (int index) => 0.600));
return PdfType1Font._create(
pdfDocument, 'Courier-Bold', 0.910, -0.220, const <double>[]);
}
factory PdfFont.courierBoldOblique(PdfDocument pdfDocument) {
return PdfType1Font._create(pdfDocument, 'Courier-BoldOblique', 0.910,
-0.220, List<double>.generate(256, (int index) => 0.600));
return PdfType1Font._create(
pdfDocument, 'Courier-BoldOblique', 0.910, -0.220, const <double>[]);
}
factory PdfFont.courierOblique(PdfDocument pdfDocument) {
return PdfType1Font._create(pdfDocument, 'Courier-Oblique', 0.910, -0.220,
List<double>.generate(256, (int index) => 0.600));
return PdfType1Font._create(
pdfDocument, 'Courier-Oblique', 0.910, -0.220, const <double>[]);
}
factory PdfFont.helvetica(PdfDocument pdfDocument) {
return PdfType1Font._create(
pdfDocument, 'Helvetica', 0.931, -0.225, const <double>[
0.500,
0.500,
0.500,
0.500,
0.500,
0.500,
0.500,
0.500,
0.500,
0.500,
0.500,
0.500,
0.500,
0.500,
0.500,
0.500,
0.500,
0.500,
0.500,
0.500,
0.500,
0.500,
0.500,
0.500,
0.500,
0.500,
0.500,
0.500,
0.500,
0.500,
0.500,
0.500,
0.278,
0.278,
0.355,
0.556,
0.556,
0.889,
0.667,
0.191,
0.333,
0.333,
0.389,
0.584,
0.278,
0.333,
0.278,
0.278,
0.556,
0.556,
0.556,
0.556,
0.556,
0.556,
0.556,
0.556,
0.556,
0.556,
0.278,
0.278,
0.584,
0.584,
0.584,
0.556,
1.015,
0.667,
0.667,
0.722,
0.722,
0.667,
0.611,
0.778,
0.722,
0.278,
0.500,
0.667,
0.556,
0.833,
0.722,
0.778,
0.667,
0.778,
0.722,
0.667,
0.611,
0.722,
0.667,
0.944,
0.667,
0.667,
0.611,
0.278,
0.278,
0.277,
0.469,
0.556,
0.333,
0.556,
0.556,
0.500,
0.556,
0.556,
0.278,
0.556,
0.556,
0.222,
0.222,
0.500,
0.222,
0.833,
0.556,
0.556,
0.556,
0.556,
0.333,
0.500,
0.278,
0.556,
0.500,
0.722,
0.500,
0.500,
0.500,
0.334,
0.260,
0.334,
0.584,
0.500,
0.655,
0.500,
0.222,
0.278,
0.333,
1.000,
0.556,
0.556,
0.333,
1.000,
0.667,
0.250,
1.000,
0.500,
0.611,
0.500,
0.500,
0.222,
0.221,
0.333,
0.333,
0.350,
0.556,
1.000,
0.333,
1.000,
0.500,
0.250,
0.938,
0.500,
0.500,
0.667,
0.278,
0.278,
0.556,
0.556,
0.556,
0.556,
0.260,
0.556,
0.333,
0.737,
0.370,
0.448,
0.584,
0.333,
0.737,
0.333,
0.606,
0.584,
0.350,
0.350,
0.333,
0.556,
0.537,
0.278,
0.333,
0.350,
0.365,
0.448,
0.869,
0.869,
0.879,
0.556,
0.667,
0.667,
0.667,
0.667,
0.667,
0.667,
1.000,
0.722,
0.667,
0.667,
0.667,
0.667,
0.278,
0.278,
0.278,
0.278,
0.722,
0.722,
0.778,
0.778,
0.778,
0.778,
0.778,
0.584,
0.778,
0.722,
0.722,
0.722,
0.722,
0.667,
0.666,
0.611,
0.556,
0.556,
0.556,
0.556,
0.556,
0.556,
0.896,
0.500,
0.556,
0.556,
0.556,
0.556,
0.251,
0.251,
0.251,
0.251,
0.556,
0.556,
0.556,
0.556,
0.556,
0.556,
0.556,
0.584,
0.611,
0.556,
0.556,
0.556,
0.556,
0.500,
0.555,
0.500
]);
pdfDocument, 'Helvetica', 0.931, -0.225, _helveticaWidths);
}
factory PdfFont.helveticaBold(PdfDocument pdfDocument) {
return PdfType1Font._create(
pdfDocument, 'Helvetica-Bold', 0.962, -0.228, const <double>[
0.278,
0.278,
0.278,
0.278,
0.278,
0.278,
0.278,
0.278,
0.278,
0.278,
0.278,
0.278,
0.278,
0.278,
0.278,
0.278,
0.278,
0.278,
0.278,
0.278,
0.278,
0.278,
0.278,
0.278,
0.278,
0.278,
0.278,
0.278,
0.278,
0.278,
0.278,
0.278,
0.278,
0.333,
0.474,
0.556,
0.556,
0.889,
0.722,
0.238,
0.333,
0.333,
0.389,
0.584,
0.278,
0.333,
0.278,
0.278,
0.556,
0.556,
0.556,
0.556,
0.556,
0.556,
0.556,
0.556,
0.556,
0.556,
0.333,
0.333,
0.584,
0.584,
0.584,
0.611,
0.975,
0.722,
0.722,
0.722,
0.722,
0.667,
0.611,
0.778,
0.722,
0.278,
0.556,
0.722,
0.611,
0.833,
0.722,
0.778,
0.667,
0.778,
0.722,
0.667,
0.611,
0.722,
0.667,
0.944,
0.667,
0.667,
0.611,
0.333,
0.278,
0.333,
0.584,
0.556,
0.333,
0.556,
0.611,
0.556,
0.611,
0.556,
0.333,
0.611,
0.611,
0.278,
0.278,
0.556,
0.278,
0.889,
0.611,
0.611,
0.611,
0.611,
0.389,
0.556,
0.333,
0.611,
0.556,
0.778,
0.556,
0.556,
0.500,
0.389,
0.280,
0.389,
0.584,
0.350,
0.556,
0.350,
0.278,
0.556,
0.500,
1.000,
0.556,
0.556,
0.333,
1.000,
0.667,
0.333,
1.000,
0.350,
0.611,
0.350,
0.350,
0.278,
0.278,
0.500,
0.500,
0.350,
0.556,
1.000,
0.333,
1.000,
0.556,
0.333,
0.944,
0.350,
0.500,
0.667,
0.278,
0.333,
0.556,
0.556,
0.556,
0.556,
0.280,
0.556,
0.333,
0.737,
0.370,
0.556,
0.584,
0.333,
0.737,
0.333,
0.400,
0.584,
0.333,
0.333,
0.333,
0.611,
0.556,
0.278,
0.333,
0.333,
0.365,
0.556,
0.834,
0.834,
0.834,
0.611,
0.722,
0.722,
0.722,
0.722,
0.722,
0.722,
1.000,
0.722,
0.667,
0.667,
0.667,
0.667,
0.278,
0.278,
0.278,
0.278,
0.722,
0.722,
0.778,
0.778,
0.778,
0.778,
0.778,
0.584,
0.778,
0.722,
0.722,
0.722,
0.722,
0.667,
0.667,
0.611,
0.556,
0.556,
0.556,
0.556,
0.556,
0.556,
0.889,
0.556,
0.556,
0.556,
0.556,
0.556,
0.278,
0.278,
0.278,
0.278,
0.611,
0.611,
0.611,
0.611,
0.611,
0.611,
0.611,
0.584,
0.611,
0.611,
0.611,
0.611,
0.611,
0.556,
0.611,
0.556
]);
pdfDocument, 'Helvetica-Bold', 0.962, -0.228, _helveticaBoldWidths);
}
factory PdfFont.helveticaBoldOblique(PdfDocument pdfDocument) {
return PdfType1Font._create(
pdfDocument, 'Helvetica-BoldOblique', 0.962, -0.228, const <double>[
0.278,
0.278,
0.278,
0.278,
0.278,
0.278,
0.278,
0.278,
0.278,
0.278,
0.278,
0.278,
0.278,
0.278,
0.278,
0.278,
0.278,
0.278,
0.278,
0.278,
0.278,
0.278,
0.278,
0.278,
0.278,
0.278,
0.278,
0.278,
0.278,
0.278,
0.278,
0.278,
0.278,
0.333,
0.474,
0.556,
0.556,
0.889,
0.722,
0.238,
0.333,
0.333,
0.389,
0.584,
0.278,
0.333,
0.278,
0.278,
0.556,
0.556,
0.556,
0.556,
0.556,
0.556,
0.556,
0.556,
0.556,
0.556,
0.333,
0.333,
0.584,
0.584,
0.584,
0.611,
0.975,
0.722,
0.722,
0.722,
0.722,
0.667,
0.611,
0.778,
0.722,
0.278,
0.556,
0.722,
0.611,
0.833,
0.722,
0.778,
0.667,
0.778,
0.722,
0.667,
0.611,
0.722,
0.667,
0.944,
0.667,
0.667,
0.611,
0.333,
0.278,
0.333,
0.584,
0.556,
0.333,
0.556,
0.611,
0.556,
0.611,
0.556,
0.333,
0.611,
0.611,
0.278,
0.278,
0.556,
0.278,
0.889,
0.611,
0.611,
0.611,
0.611,
0.389,
0.556,
0.333,
0.611,
0.556,
0.778,
0.556,
0.556,
0.500,
0.389,
0.280,
0.389,
0.584,
0.350,
0.556,
0.350,
0.278,
0.556,
0.500,
1.000,
0.556,
0.556,
0.333,
1.000,
0.667,
0.333,
1.000,
0.350,
0.611,
0.350,
0.350,
0.278,
0.278,
0.500,
0.500,
0.350,
0.556,
1.000,
0.333,
1.000,
0.556,
0.333,
0.944,
0.350,
0.500,
0.667,
0.278,
0.333,
0.556,
0.556,
0.556,
0.556,
0.280,
0.556,
0.333,
0.737,
0.370,
0.556,
0.584,
0.333,
0.737,
0.333,
0.400,
0.584,
0.333,
0.333,
0.333,
0.611,
0.556,
0.278,
0.333,
0.333,
0.365,
0.556,
0.834,
0.834,
0.834,
0.611,
0.722,
0.722,
0.722,
0.722,
0.722,
0.722,
1.000,
0.722,
0.667,
0.667,
0.667,
0.667,
0.278,
0.278,
0.278,
0.278,
0.722,
0.722,
0.778,
0.778,
0.778,
0.778,
0.778,
0.584,
0.778,
0.722,
0.722,
0.722,
0.722,
0.667,
0.667,
0.611,
0.556,
0.556,
0.556,
0.556,
0.556,
0.556,
0.889,
0.556,
0.556,
0.556,
0.556,
0.556,
0.278,
0.278,
0.278,
0.278,
0.611,
0.611,
0.611,
0.611,
0.611,
0.611,
0.611,
0.584,
0.611,
0.611,
0.611,
0.611,
0.611,
0.556,
0.611,
0.556
]);
return PdfType1Font._create(pdfDocument, 'Helvetica-BoldOblique', 0.962,
-0.228, _helveticaBoldObliqueWidths);
}
factory PdfFont.helveticaOblique(PdfDocument pdfDocument) {
return PdfType1Font._create(
pdfDocument, 'Helvetica-Oblique', 0.931, -0.225, <double>[
0.278,
0.278,
0.278,
0.278,
0.278,
0.278,
0.278,
0.278,
0.278,
0.278,
0.278,
0.278,
0.278,
0.278,
0.278,
0.278,
0.278,
0.278,
0.278,
0.278,
0.278,
0.278,
0.278,
0.278,
0.278,
0.278,
0.278,
0.278,
0.278,
0.278,
0.278,
0.278,
0.278,
0.278,
0.355,
0.556,
0.556,
0.889,
0.667,
0.191,
0.333,
0.333,
0.389,
0.584,
0.278,
0.333,
0.278,
0.278,
0.556,
0.556,
0.556,
0.556,
0.556,
0.556,
0.556,
0.556,
0.556,
0.556,
0.278,
0.278,
0.584,
0.584,
0.584,
0.556,
1.015,
0.667,
0.667,
0.722,
0.722,
0.667,
0.611,
0.778,
0.722,
0.278,
0.500,
0.667,
0.556,
0.833,
0.722,
0.778,
0.667,
0.778,
0.722,
0.667,
0.611,
0.722,
0.667,
0.944,
0.667,
0.667,
0.611,
0.278,
0.278,
0.278,
0.469,
0.556,
0.333,
0.556,
0.556,
0.500,
0.556,
0.556,
0.278,
0.556,
0.556,
0.222,
0.222,
0.500,
0.222,
0.833,
0.556,
0.556,
0.556,
0.556,
0.333,
0.500,
0.278,
0.556,
0.500,
0.722,
0.500,
0.500,
0.500,
0.334,
0.260,
0.334,
0.584,
0.350,
0.556,
0.350,
0.222,
0.556,
0.333,
1.000,
0.556,
0.556,
0.333,
1.000,
0.667,
0.333,
1.000,
0.350,
0.611,
0.350,
0.350,
0.222,
0.222,
0.333,
0.333,
0.350,
0.556,
1.000,
0.333,
1.000,
0.500,
0.333,
0.944,
0.350,
0.500,
0.667,
0.278,
0.333,
0.556,
0.556,
0.556,
0.556,
0.260,
0.556,
0.333,
0.737,
0.370,
0.556,
0.584,
0.333,
0.737,
0.333,
0.400,
0.584,
0.333,
0.333,
0.333,
0.556,
0.537,
0.278,
0.333,
0.333,
0.365,
0.556,
0.834,
0.834,
0.834,
0.611,
0.667,
0.667,
0.667,
0.667,
0.667,
0.667,
1.000,
0.722,
0.667,
0.667,
0.667,
0.667,
0.278,
0.278,
0.278,
0.278,
0.722,
0.722,
0.778,
0.778,
0.778,
0.778,
0.778,
0.584,
0.778,
0.722,
0.722,
0.722,
0.722,
0.667,
0.667,
0.611,
0.556,
0.556,
0.556,
0.556,
0.556,
0.556,
0.889,
0.500,
0.556,
0.556,
0.556,
0.556,
0.278,
0.278,
0.278,
0.278,
0.556,
0.556,
0.556,
0.556,
0.556,
0.556,
0.556,
0.584,
0.611,
0.556,
0.556,
0.556,
0.556,
0.500,
0.556,
0.500
]);
return PdfType1Font._create(pdfDocument, 'Helvetica-Oblique', 0.931, -0.225,
_helveticaObliqueWidths);
}
factory PdfFont.times(PdfDocument pdfDocument) {
return PdfType1Font._create(
pdfDocument, 'Times-Roman', 0.898, -0.218, <double>[
0.250,
0.250,
0.250,
0.250,
0.250,
0.250,
0.250,
0.250,
0.250,
0.250,
0.250,
0.250,
0.250,
0.250,
0.250,
0.250,
0.250,
0.250,
0.250,
0.250,
0.250,
0.250,
0.250,
0.250,
0.250,
0.250,
0.250,
0.250,
0.250,
0.250,
0.250,
0.250,
0.250,
0.333,
0.408,
0.500,
0.500,
0.833,
0.778,
0.180,
0.333,
0.333,
0.500,
0.564,
0.250,
0.333,
0.250,
0.278,
0.500,
0.500,
0.500,
0.500,
0.500,
0.500,
0.500,
0.500,
0.500,
0.500,
0.278,
0.278,
0.564,
0.564,
0.564,
0.444,
0.921,
0.722,
0.667,
0.667,
0.722,
0.611,
0.556,
0.722,
0.722,
0.333,
0.389,
0.722,
0.611,
0.889,
0.722,
0.722,
0.556,
0.722,
0.667,
0.556,
0.611,
0.722,
0.722,
0.944,
0.722,
0.722,
0.611,
0.333,
0.278,
0.333,
0.469,
0.500,
0.333,
0.444,
0.500,
0.444,
0.500,
0.444,
0.333,
0.500,
0.500,
0.278,
0.278,
0.500,
0.278,
0.778,
0.500,
0.500,
0.500,
0.500,
0.333,
0.389,
0.278,
0.500,
0.500,
0.722,
0.500,
0.500,
0.444,
0.480,
0.200,
0.480,
0.541,
0.350,
0.500,
0.350,
0.333,
0.500,
0.444,
1.000,
0.500,
0.500,
0.333,
1.000,
0.556,
0.333,
0.889,
0.350,
0.611,
0.350,
0.350,
0.333,
0.333,
0.444,
0.444,
0.350,
0.500,
1.000,
0.333,
0.980,
0.389,
0.333,
0.722,
0.350,
0.444,
0.722,
0.250,
0.333,
0.500,
0.500,
0.500,
0.500,
0.200,
0.500,
0.333,
0.760,
0.276,
0.500,
0.564,
0.333,
0.760,
0.333,
0.400,
0.564,
0.300,
0.300,
0.333,
0.500,
0.453,
0.250,
0.333,
0.300,
0.310,
0.500,
0.750,
0.750,
0.750,
0.444,
0.722,
0.722,
0.722,
0.722,
0.722,
0.722,
0.889,
0.667,
0.611,
0.611,
0.611,
0.611,
0.333,
0.333,
0.333,
0.333,
0.722,
0.722,
0.722,
0.722,
0.722,
0.722,
0.722,
0.564,
0.722,
0.722,
0.722,
0.722,
0.722,
0.722,
0.556,
0.500,
0.444,
0.444,
0.444,
0.444,
0.444,
0.444,
0.667,
0.444,
0.444,
0.444,
0.444,
0.444,
0.278,
0.278,
0.278,
0.278,
0.500,
0.500,
0.500,
0.500,
0.500,
0.500,
0.500,
0.564,
0.500,
0.500,
0.500,
0.500,
0.500,
0.500,
0.500,
0.500
]);
pdfDocument, 'Times-Roman', 0.898, -0.218, _timesWidths);
}
factory PdfFont.timesBold(PdfDocument pdfDocument) {
return PdfType1Font._create(
pdfDocument, 'Times-Bold', 0.935, -0.218, <double>[
0.250,
0.250,
0.250,
0.250,
0.250,
0.250,
0.250,
0.250,
0.250,
0.250,
0.250,
0.250,
0.250,
0.250,
0.250,
0.250,
0.250,
0.250,
0.250,
0.250,
0.250,
0.250,
0.250,
0.250,
0.250,
0.250,
0.250,
0.250,
0.250,
0.250,
0.250,
0.250,
0.250,
0.333,
0.555,
0.500,
0.500,
1.000,
0.833,
0.278,
0.333,
0.333,
0.500,
0.570,
0.250,
0.333,
0.250,
0.278,
0.500,
0.500,
0.500,
0.500,
0.500,
0.500,
0.500,
0.500,
0.500,
0.500,
0.333,
0.333,
0.570,
0.570,
0.570,
0.500,
0.930,
0.722,
0.667,
0.722,
0.722,
0.667,
0.611,
0.778,
0.778,
0.389,
0.500,
0.778,
0.667,
0.944,
0.722,
0.778,
0.611,
0.778,
0.722,
0.556,
0.667,
0.722,
0.722,
1.000,
0.722,
0.722,
0.667,
0.333,
0.278,
0.333,
0.581,
0.500,
0.333,
0.500,
0.556,
0.444,
0.556,
0.444,
0.333,
0.500,
0.556,
0.278,
0.333,
0.556,
0.278,
0.833,
0.556,
0.500,
0.556,
0.556,
0.444,
0.389,
0.333,
0.556,
0.500,
0.722,
0.500,
0.500,
0.444,
0.394,
0.220,
0.394,
0.520,
0.350,
0.500,
0.350,
0.333,
0.500,
0.500,
1.000,
0.500,
0.500,
0.333,
1.000,
0.556,
0.333,
1.000,
0.350,
0.667,
0.350,
0.350,
0.333,
0.333,
0.500,
0.500,
0.350,
0.500,
1.000,
0.333,
1.000,
0.389,
0.333,
0.722,
0.350,
0.444,
0.722,
0.250,
0.333,
0.500,
0.500,
0.500,
0.500,
0.220,
0.500,
0.333,
0.747,
0.300,
0.500,
0.570,
0.333,
0.747,
0.333,
0.400,
0.570,
0.300,
0.300,
0.333,
0.556,
0.540,
0.250,
0.333,
0.300,
0.330,
0.500,
0.750,
0.750,
0.750,
0.500,
0.722,
0.722,
0.722,
0.722,
0.722,
0.722,
1.000,
0.722,
0.667,
0.667,
0.667,
0.667,
0.389,
0.389,
0.389,
0.389,
0.722,
0.722,
0.778,
0.778,
0.778,
0.778,
0.778,
0.570,
0.778,
0.722,
0.722,
0.722,
0.722,
0.722,
0.611,
0.556,
0.500,
0.500,
0.500,
0.500,
0.500,
0.500,
0.722,
0.444,
0.444,
0.444,
0.444,
0.444,
0.278,
0.278,
0.278,
0.278,
0.500,
0.556,
0.500,
0.500,
0.500,
0.500,
0.500,
0.570,
0.500,
0.556,
0.556,
0.556,
0.556,
0.500,
0.556,
0.500
]);
pdfDocument, 'Times-Bold', 0.935, -0.218, _timesBoldWidths);
}
factory PdfFont.timesBoldItalic(PdfDocument pdfDocument) {
return PdfType1Font._create(
pdfDocument, 'Times-BoldItalic', 0.921, -0.218, <double>[
0.250,
0.250,
0.250,
0.250,
0.250,
0.250,
0.250,
0.250,
0.250,
0.250,
0.250,
0.250,
0.250,
0.250,
0.250,
0.250,
0.250,
0.250,
0.250,
0.250,
0.250,
0.250,
0.250,
0.250,
0.250,
0.250,
0.250,
0.250,
0.250,
0.250,
0.250,
0.250,
0.250,
0.389,
0.555,
0.500,
0.500,
0.833,
0.778,
0.278,
0.333,
0.333,
0.500,
0.570,
0.250,
0.333,
0.250,
0.278,
0.500,
0.500,
0.500,
0.500,
0.500,
0.500,
0.500,
0.500,
0.500,
0.500,
0.333,
0.333,
0.570,
0.570,
0.570,
0.500,
0.832,
0.667,
0.667,
0.667,
0.722,
0.667,
0.667,
0.722,
0.778,
0.389,
0.500,
0.667,
0.611,
0.889,
0.722,
0.722,
0.611,
0.722,
0.667,
0.556,
0.611,
0.722,
0.667,
0.889,
0.667,
0.611,
0.611,
0.333,
0.278,
0.333,
0.570,
0.500,
0.333,
0.500,
0.500,
0.444,
0.500,
0.444,
0.333,
0.500,
0.556,
0.278,
0.278,
0.500,
0.278,
0.778,
0.556,
0.500,
0.500,
0.500,
0.389,
0.389,
0.278,
0.556,
0.444,
0.667,
0.500,
0.444,
0.389,
0.348,
0.220,
0.348,
0.570,
0.350,
0.500,
0.350,
0.333,
0.500,
0.500,
1.000,
0.500,
0.500,
0.333,
1.000,
0.556,
0.333,
0.944,
0.350,
0.611,
0.350,
0.350,
0.333,
0.333,
0.500,
0.500,
0.350,
0.500,
1.000,
0.333,
1.000,
0.389,
0.333,
0.722,
0.350,
0.389,
0.611,
0.250,
0.389,
0.500,
0.500,
0.500,
0.500,
0.220,
0.500,
0.333,
0.747,
0.266,
0.500,
0.606,
0.333,
0.747,
0.333,
0.400,
0.570,
0.300,
0.300,
0.333,
0.576,
0.500,
0.250,
0.333,
0.300,
0.300,
0.500,
0.750,
0.750,
0.750,
0.500,
0.667,
0.667,
0.667,
0.667,
0.667,
0.667,
0.944,
0.667,
0.667,
0.667,
0.667,
0.667,
0.389,
0.389,
0.389,
0.389,
0.722,
0.722,
0.722,
0.722,
0.722,
0.722,
0.722,
0.570,
0.722,
0.722,
0.722,
0.722,
0.722,
0.611,
0.611,
0.500,
0.500,
0.500,
0.500,
0.500,
0.500,
0.500,
0.722,
0.444,
0.444,
0.444,
0.444,
0.444,
0.278,
0.278,
0.278,
0.278,
0.500,
0.556,
0.500,
0.500,
0.500,
0.500,
0.500,
0.570,
0.500,
0.556,
0.556,
0.556,
0.556,
0.444,
0.500,
0.444
]);
pdfDocument, 'Times-BoldItalic', 0.921, -0.218, _timesBoldItalicWidths);
}
factory PdfFont.timesItalic(PdfDocument pdfDocument) {
return PdfType1Font._create(
pdfDocument, 'Times-Italic', 0.883, -0.217, <double>[
0.250,
0.250,
0.250,
0.250,
0.250,
0.250,
0.250,
0.250,
0.250,
0.250,
0.250,
0.250,
0.250,
0.250,
0.250,
0.250,
0.250,
0.250,
0.250,
0.250,
0.250,
0.250,
0.250,
0.250,
0.250,
0.250,
0.250,
0.250,
0.250,
0.250,
0.250,
0.250,
0.250,
0.333,
0.420,
0.500,
0.500,
0.833,
0.778,
0.214,
0.333,
0.333,
0.500,
0.675,
0.250,
0.333,
0.250,
0.278,
0.500,
0.500,
0.500,
0.500,
0.500,
0.500,
0.500,
0.500,
0.500,
0.500,
0.333,
0.333,
0.675,
0.675,
0.675,
0.500,
0.920,
0.611,
0.611,
0.667,
0.722,
0.611,
0.611,
0.722,
0.722,
0.333,
0.444,
0.667,
0.556,
0.833,
0.667,
0.722,
0.611,
0.722,
0.611,
0.500,
0.556,
0.722,
0.611,
0.833,
0.611,
0.556,
0.556,
0.389,
0.278,
0.389,
0.422,
0.500,
0.333,
0.500,
0.500,
0.444,
0.500,
0.444,
0.278,
0.500,
0.500,
0.278,
0.278,
0.444,
0.278,
0.722,
0.500,
0.500,
0.500,
0.500,
0.389,
0.389,
0.278,
0.500,
0.444,
0.667,
0.444,
0.444,
0.389,
0.400,
0.275,
0.400,
0.541,
0.350,
0.500,
0.350,
0.333,
0.500,
0.556,
0.889,
0.500,
0.500,
0.333,
1.000,
0.500,
0.333,
0.944,
0.350,
0.556,
0.350,
0.350,
0.333,
0.333,
0.556,
0.556,
0.350,
0.500,
0.889,
0.333,
0.980,
0.389,
0.333,
0.667,
0.350,
0.389,
0.556,
0.250,
0.389,
0.500,
0.500,
0.500,
0.500,
0.275,
0.500,
0.333,
0.760,
0.276,
0.500,
0.675,
0.333,
0.760,
0.333,
0.400,
0.675,
0.300,
0.300,
0.333,
0.500,
0.523,
0.250,
0.333,
0.300,
0.310,
0.500,
0.750,
0.750,
0.750,
0.500,
0.611,
0.611,
0.611,
0.611,
0.611,
0.611,
0.889,
0.667,
0.611,
0.611,
0.611,
0.611,
0.333,
0.333,
0.333,
0.333,
0.722,
0.667,
0.722,
0.722,
0.722,
0.722,
0.722,
0.675,
0.722,
0.722,
0.722,
0.722,
0.722,
0.556,
0.611,
0.500,
0.500,
0.500,
0.500,
0.500,
0.500,
0.500,
0.667,
0.444,
0.444,
0.444,
0.444,
0.444,
0.278,
0.278,
0.278,
0.278,
0.500,
0.500,
0.500,
0.500,
0.500,
0.500,
0.500,
0.675,
0.500,
0.500,
0.500,
0.500,
0.500,
0.444,
0.500,
0.444
]);
pdfDocument, 'Times-Italic', 0.883, -0.217, _timesItalicWidths);
}
factory PdfFont.symbol(PdfDocument pdfDocument) {
return PdfType1Font._create(pdfDocument, 'Symbol', 1.010, -0.293, <double>[
0.587,
0.587,
0.587,
0.587,
0.587,
0.587,
0.587,
0.587,
0.587,
0.587,
0.587,
0.587,
0.587,
0.587,
0.587,
0.587,
0.587,
0.587,
0.587,
0.587,
0.587,
0.587,
0.587,
0.587,
0.587,
0.587,
0.587,
0.587,
0.587,
0.587,
0.587,
0.587,
0.250,
0.333,
0.713,
0.500,
0.549,
0.833,
0.778,
0.439,
0.333,
0.333,
0.500,
0.549,
0.250,
0.549,
0.250,
0.278,
0.500,
0.500,
0.500,
0.500,
0.500,
0.500,
0.500,
0.500,
0.500,
0.500,
0.278,
0.278,
0.549,
0.549,
0.549,
0.444,
0.549,
0.722,
0.667,
0.722,
0.612,
0.611,
0.763,
0.603,
0.722,
0.333,
0.631,
0.722,
0.686,
0.889,
0.722,
0.722,
0.768,
0.741,
0.556,
0.592,
0.611,
0.690,
0.439,
0.768,
0.645,
0.795,
0.611,
0.333,
0.863,
0.333,
0.658,
0.500,
0.500,
0.631,
0.549,
0.549,
0.494,
0.439,
0.521,
0.411,
0.603,
0.329,
0.603,
0.549,
0.549,
0.576,
0.521,
0.549,
0.549,
0.521,
0.549,
0.603,
0.439,
0.576,
0.713,
0.686,
0.493,
0.686,
0.494,
0.480,
0.200,
0.480,
0.549,
0.587,
0.587,
0.587,
0.587,
0.587,
0.587,
0.587,
0.587,
0.587,
0.587,
0.587,
0.587,
0.587,
0.587,
0.587,
0.587,
0.587,
0.587,
0.587,
0.587,
0.587,
0.587,
0.587,
0.587,
0.587,
0.587,
0.587,
0.587,
0.587,
0.587,
0.587,
0.587,
0.587,
0.750,
0.620,
0.247,
0.549,
0.167,
0.713,
0.500,
0.753,
0.753,
0.753,
0.753,
1.042,
0.987,
0.603,
0.987,
0.603,
0.400,
0.549,
0.411,
0.549,
0.549,
0.713,
0.494,
0.460,
0.549,
0.549,
0.549,
0.549,
1.000,
0.603,
1.000,
0.658,
0.823,
0.686,
0.795,
0.987,
0.768,
0.768,
0.823,
0.768,
0.768,
0.713,
0.713,
0.713,
0.713,
0.713,
0.713,
0.713,
0.768,
0.713,
0.790,
0.790,
0.890,
0.823,
0.549,
0.250,
0.713,
0.603,
0.603,
1.042,
0.987,
0.603,
0.987,
0.603,
0.494,
0.329,
0.790,
0.790,
0.786,
0.713,
0.384,
0.384,
0.384,
0.384,
0.384,
0.384,
0.494,
0.494,
0.494,
0.494,
0.587,
0.329,
0.274,
0.686,
0.686,
0.686,
0.384,
0.384,
0.384,
0.384,
0.384,
0.384,
0.494,
0.494,
0.494,
0.587
]);
return PdfType1Font._create(
pdfDocument, 'Symbol', 1.010, -0.293, _symbolWidths);
}
factory PdfFont.zapfDingbats(PdfDocument pdfDocument) {
return PdfType1Font._create(
pdfDocument, 'ZapfDingbats', 0.820, -0.143, <double>[
0.746,
0.746,
0.746,
0.746,
0.746,
0.746,
0.746,
0.746,
0.746,
0.746,
0.746,
0.746,
0.746,
0.746,
0.746,
0.746,
0.746,
0.746,
0.746,
0.746,
0.746,
0.746,
0.746,
0.746,
0.746,
0.746,
0.746,
0.746,
0.746,
0.746,
0.746,
0.746,
0.278,
0.974,
0.961,
0.974,
0.980,
0.719,
0.789,
0.790,
0.791,
0.690,
0.960,
0.939,
0.549,
0.855,
0.911,
0.933,
0.911,
0.945,
0.974,
0.755,
0.846,
0.762,
0.761,
0.571,
0.677,
0.763,
0.760,
0.759,
0.754,
0.494,
0.552,
0.537,
0.577,
0.692,
0.786,
0.788,
0.788,
0.790,
0.793,
0.794,
0.816,
0.823,
0.789,
0.841,
0.823,
0.833,
0.816,
0.831,
0.923,
0.744,
0.723,
0.749,
0.790,
0.792,
0.695,
0.776,
0.768,
0.792,
0.759,
0.707,
0.708,
0.682,
0.701,
0.826,
0.815,
0.789,
0.789,
0.707,
0.687,
0.696,
0.689,
0.786,
0.787,
0.713,
0.791,
0.785,
0.791,
0.873,
0.761,
0.762,
0.762,
0.759,
0.759,
0.892,
0.892,
0.788,
0.784,
0.438,
0.138,
0.277,
0.415,
0.392,
0.392,
0.668,
0.668,
0.746,
0.390,
0.390,
0.317,
0.317,
0.276,
0.276,
0.509,
0.509,
0.410,
0.410,
0.234,
0.234,
0.334,
0.334,
0.746,
0.746,
0.746,
0.746,
0.746,
0.746,
0.746,
0.746,
0.746,
0.746,
0.746,
0.746,
0.746,
0.746,
0.746,
0.746,
0.746,
0.746,
0.746,
0.732,
0.544,
0.544,
0.910,
0.667,
0.760,
0.760,
0.776,
0.595,
0.694,
0.626,
0.788,
0.788,
0.788,
0.788,
0.788,
0.788,
0.788,
0.788,
0.788,
0.788,
0.788,
0.788,
0.788,
0.788,
0.788,
0.788,
0.788,
0.788,
0.788,
0.788,
0.788,
0.788,
0.788,
0.788,
0.788,
0.788,
0.788,
0.788,
0.788,
0.788,
0.788,
0.788,
0.788,
0.788,
0.788,
0.788,
0.788,
0.788,
0.788,
0.788,
0.894,
0.838,
1.016,
0.458,
0.748,
0.924,
0.748,
0.918,
0.927,
0.928,
0.928,
0.834,
0.873,
0.828,
0.924,
0.924,
0.917,
0.930,
0.931,
0.463,
0.883,
0.836,
0.836,
0.867,
0.867,
0.696,
0.696,
0.874,
0.746,
0.874,
0.760,
0.946,
0.771,
0.865,
0.771,
0.888,
0.967,
0.888,
0.831,
0.873,
0.927,
0.970,
0.918,
0.746
]);
pdfDocument, 'ZapfDingbats', 0.820, -0.143, _zapfDingbatsWidths);
}
/// The df type of the font, usually /Type1
... ... @@ -2674,6 +106,12 @@ class PdfFont extends PdfObject {
String get fontName => null;
double get ascent => null;
double get descent => null;
static const double defaultGlyphWidth = 0.600;
/// @param os OutputStream to send the object to
@override
void _prepare() {
... ... @@ -2684,58 +122,35 @@ class PdfFont extends PdfObject {
params['/Encoding'] = PdfStream.string('/WinAnsiEncoding');
}
double glyphAdvance(int charCode) {
return 0.454;
}
// Use glyphMetrics instead
@deprecated
double glyphAdvance(int charCode) => glyphMetrics(charCode).advanceWidth;
PdfRect glyphBounds(int charCode) {
return PdfRect(0.0, 0.0, glyphAdvance(charCode), 1.0);
}
PdfFontMetrics glyphMetrics(int charCode);
PdfRect stringBounds(String s) {
final Uint8List chars = latin1.encode(s);
// Use glyphMetrics instead
@deprecated
PdfRect glyphBounds(int charCode) => glyphMetrics(charCode).toPdfRect();
if (chars.isEmpty) {
return const PdfRect(0.0, 0.0, 0.0, 0.0);
PdfFontMetrics stringMetrics(String s) {
if (s.isEmpty) {
return PdfFontMetrics.zero;
}
int n = 0;
int c = chars[n];
PdfRect r = glyphBounds(c);
final double x = r.x;
double y = r.y;
double h = r.height;
double w = n == chars.length - 1 ? r.width : glyphAdvance(c);
while (++n < chars.length) {
c = chars[n];
r = glyphBounds(c);
if (r.y < y) {
y = r.y;
}
if (r.height > h) {
h = r.height;
}
w += n == chars.length - 1 ? r.width : glyphAdvance(c);
}
return PdfRect(x, y, w, h);
}
PdfPoint stringSize(String s) {
final Uint8List chars = latin1.encode(s);
final Iterable<PdfFontMetrics> metrics = chars.map(glyphMetrics);
return PdfFontMetrics.append(metrics);
}
double w = 0.0;
double h = 0.0;
for (int c in chars) {
final PdfRect r = glyphBounds(c);
if (r.height > h) {
h = r.height;
}
w += glyphAdvance(c);
}
// Use stringMetrics instead
@deprecated
PdfRect stringBounds(String s) => stringMetrics(s).toPdfRect();
return PdfPoint(w, h);
PdfPoint stringSize(String s) {
final PdfFontMetrics metrics = stringMetrics(s);
return PdfPoint(metrics.width, metrics.height);
}
@override
String toString() => 'Font($fontName)';
}
... ...
... ... @@ -28,18 +28,18 @@ class PdfFontDescriptor extends PdfObject {
void _prepare() {
super._prepare();
params['/FontName'] = PdfStream.string(ttfFont.fontName);
params['/FontName'] = PdfStream.string('/' + ttfFont.fontName);
params['/FontFile2'] = file.ref();
params['/Flags'] = PdfStream.intNum(32);
params['/FontBBox'] = PdfStream()
..putIntArray(<int>[
ttfFont.font.xMin,
ttfFont.font.yMin,
ttfFont.font.xMax,
ttfFont.font.yMax
(ttfFont.font.xMin / ttfFont.font.unitsPerEm * 1000).toInt(),
(ttfFont.font.yMin / ttfFont.font.unitsPerEm * 1000).toInt(),
(ttfFont.font.xMax / ttfFont.font.unitsPerEm * 1000).toInt(),
(ttfFont.font.yMax / ttfFont.font.unitsPerEm * 1000).toInt()
]);
params['/Ascent'] = PdfStream.intNum(ttfFont.font.ascent);
params['/Descent'] = PdfStream.intNum(ttfFont.font.descent);
params['/Ascent'] = PdfStream.intNum((ttfFont.ascent * 1000).toInt());
params['/Descent'] = PdfStream.intNum((ttfFont.descent * 1000).toInt());
params['/ItalicAngle'] = PdfStream.intNum(0);
params['/CapHeight'] = PdfStream.intNum(10);
params['/StemV'] = PdfStream.intNum(79);
... ...
/*
* Copyright (C) 2017, David PHAM-VAN <dev.nfet.net@gmail.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
part of pdf;
@immutable
class PdfFontMetrics {
const PdfFontMetrics(
{@required this.left,
@required this.top,
@required this.right,
@required this.bottom,
double ascent,
double descent,
double advanceWidth})
: ascent = ascent ?? bottom,
descent = descent ?? top,
advanceWidth = advanceWidth ?? right - left,
assert(left != null),
assert(top != null),
assert(right != null),
assert(bottom != null),
assert(left <= right),
assert(top <= bottom),
assert((descent ?? top) <= (ascent ?? bottom));
factory PdfFontMetrics.append(Iterable<PdfFontMetrics> metrics) {
if (metrics.isEmpty) {
return PdfFontMetrics.zero;
}
double left;
double top;
double right = 0.0;
double bottom;
double ascent;
double descent;
double lastBearing;
for (PdfFontMetrics metric in metrics) {
left ??= metric.left;
right += metric.advanceWidth;
lastBearing = metric.rightBearing;
top = math.min(top ?? metric.top, metric.top);
bottom = math.max(bottom ?? metric.bottom, metric.bottom);
descent = math.min(descent ?? metric.descent, metric.descent);
ascent = math.max(ascent ?? metric.ascent, metric.ascent);
}
return PdfFontMetrics(
left: left,
top: top,
right: right - lastBearing,
bottom: bottom,
ascent: ascent,
descent: descent,
advanceWidth: right);
}
static const PdfFontMetrics zero =
PdfFontMetrics(left: 0.0, top: 0.0, right: 0.0, bottom: 0.0);
final double left;
final double top;
final double bottom;
final double right;
final double ascent;
final double descent;
final double advanceWidth;
double get width => right - left;
double get height => bottom - top;
double get maxHeight => ascent - descent;
double get maxWidth =>
math.max(advanceWidth, right) + math.max(-leftBearing, 0.0);
double get effectiveLeft => math.min(leftBearing, 0.0);
double get leftBearing => left;
double get rightBearing => advanceWidth - right;
@override
String toString() =>
'PdfFontMetrics(left:$left, top:$top, right:$right, bottom:$bottom, ascent:$ascent, descent:$descent, advanceWidth:$advanceWidth)';
PdfFontMetrics copyWith(
{double left,
double top,
double right,
double bottom,
double ascent,
double descent,
double advanceWidth}) {
return PdfFontMetrics(
left: left ?? this.left,
top: top ?? this.top,
right: right ?? this.right,
bottom: bottom ?? this.bottom,
ascent: ascent ?? this.ascent,
descent: descent ?? this.descent,
advanceWidth: advanceWidth ?? this.advanceWidth);
}
PdfFontMetrics operator *(double factor) {
return copyWith(
left: left * factor,
top: top * factor,
right: right * factor,
bottom: bottom * factor,
ascent: ascent * factor,
descent: descent * factor,
advanceWidth: advanceWidth * factor,
);
}
PdfRect toPdfRect() => PdfRect.fromLTRB(left, top, right, bottom);
}
... ...
... ... @@ -32,4 +32,7 @@ class PdfPoint {
@override
String toString() => 'PdfPoint($x, $y)';
PdfPoint translate(double offsetX, double offsetY) =>
PdfPoint(x + offsetX, y + offsetY);
}
... ...
... ... @@ -27,7 +27,6 @@ class TtfParser {
}
_parseFontName();
_parseHmtx();
_parseCMap();
_parseIndexes();
_parseGlyf();
... ... @@ -45,10 +44,9 @@ class TtfParser {
final ByteData bytes;
final Map<String, int> _tableOffsets = <String, int>{};
String _fontName;
final List<double> advanceWidth = <double>[];
final Map<int, int> charToGlyphIndexMap = <int, int>{};
final List<int> glyphOffsets = <int>[];
final Map<int, PdfRect> glyphInfoMap = <int, PdfRect>{};
final Map<int, PdfFontMetrics> glyphInfoMap = <int, PdfFontMetrics>{};
int get unitsPerEm => bytes.getUint16(_tableOffsets[_HEAD] + 18);
... ... @@ -72,6 +70,7 @@ class TtfParser {
String get fontName => _fontName;
// https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6name.html
void _parseFontName() {
final int basePosition = _tableOffsets[_NAME];
final int count = bytes.getUint16(basePosition + 2);
... ... @@ -84,22 +83,27 @@ class TtfParser {
final int offset = bytes.getUint16(pos + 10);
pos += 12;
if (platformID == 1 && nameID == 6) {
_fontName = utf8.decode(bytes.buffer
.asUint8List(basePosition + stringOffset + offset, length));
return;
try {
_fontName = utf8.decode(bytes.buffer
.asUint8List(basePosition + stringOffset + offset, length));
return;
} catch (a) {
print('Error: $platformID $nameID $a');
}
}
if (platformID == 3 && nameID == 6) {
try {
_fontName = decodeUtf16(bytes.buffer
.asUint8List(basePosition + stringOffset + offset, length));
return;
} catch (a) {
print('Error: $platformID $nameID $a');
}
}
}
_fontName = hashCode.toString();
}
void _parseHmtx() {
final int offset = _tableOffsets[_HMTX];
final int unitsPerEm = this.unitsPerEm;
for (int i = 0; i < numOfLongHorMetrics; i++) {
advanceWidth.add(bytes.getInt16(offset + i * 4).toDouble() / unitsPerEm);
}
}
void _parseCMap() {
final int basePosition = _tableOffsets[_CMAP];
final int numSubTables = bytes.getUint16(basePosition + 2);
... ... @@ -199,8 +203,10 @@ class TtfParser {
}
}
/// https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6glyf.html
void _parseGlyf() {
final int baseOffset = _tableOffsets[_GLYF];
final int hmtxOffset = _tableOffsets[_HMTX];
final int unitsPerEm = this.unitsPerEm;
int glyphIndex = 0;
for (int offset in glyphOffsets) {
... ... @@ -208,11 +214,17 @@ class TtfParser {
final int yMin = bytes.getInt16(baseOffset + offset + 4); // 4
final int xMax = bytes.getInt16(baseOffset + offset + 6); // 6
final int yMax = bytes.getInt16(baseOffset + offset + 8); // 8
glyphInfoMap[glyphIndex] = PdfRect(
xMin.toDouble() / unitsPerEm,
yMin.toDouble() / unitsPerEm,
xMax.toDouble() / unitsPerEm,
yMax.toDouble() / unitsPerEm);
final double advanceWidth = glyphIndex < numOfLongHorMetrics
? bytes.getInt16(hmtxOffset + glyphIndex * 4).toDouble() / unitsPerEm
: null;
glyphInfoMap[glyphIndex] = PdfFontMetrics(
left: xMin.toDouble() / unitsPerEm,
top: yMin.toDouble() / unitsPerEm,
right: xMax.toDouble() / unitsPerEm,
bottom: yMax.toDouble() / unitsPerEm,
ascent: ascent.toDouble() / unitsPerEm,
descent: descent.toDouble() / unitsPerEm,
advanceWidth: advanceWidth);
glyphIndex++;
}
}
... ...
... ... @@ -29,8 +29,10 @@ class PdfTtfFont extends PdfFont {
_charMin = 32;
_charMax = 255;
final List<String> widths = <String>[];
for (int i = _charMin; i <= _charMax; i++) {
widths.add((glyphAdvance(i) * 1000.0).toString());
widths.add((glyphMetrics(i).advanceWidth * 1000.0).toInt().toString());
}
unicodeCMap = PdfObject(pdfDocument);
... ... @@ -44,8 +46,6 @@ class PdfTtfFont extends PdfFont {
PdfArrayObject widthsObject;
final List<String> widths = <String>[];
final TtfParser font;
int _charMin;
... ... @@ -53,36 +53,30 @@ class PdfTtfFont extends PdfFont {
int _charMax;
@override
String get fontName => '/' + font.fontName.replaceAll(' ', '');
String get fontName => font.fontName;
@override
double glyphAdvance(int charCode) {
final int g = font.charToGlyphIndexMap[charCode];
if (g == null) {
return super.glyphAdvance(charCode);
}
double get ascent => font.ascent.toDouble() / font.unitsPerEm;
return (g < font.advanceWidth.length ? font.advanceWidth[g] : null) ??
super.glyphAdvance(charCode);
}
@override
double get descent => font.descent.toDouble() / font.unitsPerEm;
@override
PdfRect glyphBounds(int charCode) {
PdfFontMetrics glyphMetrics(int charCode) {
final int g = font.charToGlyphIndexMap[charCode];
if (g == null) {
return super.glyphBounds(charCode);
return PdfFontMetrics.zero;
}
return font.glyphInfoMap[g] ?? super.glyphBounds(charCode);
return font.glyphInfoMap[g] ?? PdfFontMetrics.zero;
}
@override
void _prepare() {
super._prepare();
params['/BaseFont'] = PdfStream.string(fontName);
params['/BaseFont'] = PdfStream.string('/' + fontName);
params['/FirstChar'] = PdfStream.intNum(_charMin);
params['/LastChar'] = PdfStream.intNum(_charMax);
params['/Widths'] = widthsObject.ref();
... ...
... ... @@ -26,8 +26,10 @@ class PdfType1Font extends PdfFont {
@override
final String fontName;
@override
final double ascent;
@override
final double descent;
final List<double> widths;
... ... @@ -41,16 +43,13 @@ class PdfType1Font extends PdfFont {
}
@override
double glyphAdvance(int charCode) {
if (charCode > widths.length) {
return super.glyphAdvance(charCode);
}
return widths[charCode];
}
@override
PdfRect glyphBounds(int charCode) {
return PdfRect(0.0, descent, glyphAdvance(charCode), ascent);
PdfFontMetrics glyphMetrics(int charCode) {
return PdfFontMetrics(
left: 0.0,
top: descent,
right: charCode < widths.length
? widths[charCode]
: PdfFont.defaultGlyphWidth,
bottom: ascent);
}
}
... ...