SvgParser constructor
SvgParser({
- required XmlDocument xml,
- PdfColor? colorFilter,
Create an SVG parser
Implementation
factory SvgParser({
required XmlDocument xml,
PdfColor? colorFilter,
}) {
final root = xml.rootElement;
final vbattr = root.getAttribute('viewBox');
final width = getNumeric(root, 'width', null)?.sizeValue;
final height = getNumeric(root, 'height', null)?.sizeValue;
final vb = vbattr == null
? <double>[0, 0, width ?? 1000, height ?? 1000]
: splitDoubles(vbattr);
if (vb.isEmpty || vb.length > 4) {
throw Exception('viewBox must contain 1..4 parameters');
}
final fvb = [
...List<double>.filled(4 - vb.length, 0),
...vb,
];
final viewBox = PdfRect(fvb[0], fvb[1], fvb[2], fvb[3]);
return SvgParser._(
width,
height,
viewBox,
root,
colorFilter,
);
}