David PHAM-VAN

Fix some null-safety issues

... ... @@ -123,7 +123,7 @@ abstract class PdfAnnotBase {
/// Color
final PdfColor? color;
final Map<String, PdfDataType> _appearances = <String, PdfDataType>{};
final _appearances = <String, PdfDataType>{};
PdfName? _as;
... ... @@ -171,19 +171,13 @@ abstract class PdfAnnotBase {
}
if (matrix != null) {
s.params['/Matrix'] = PdfArray.fromNum(<double>[
matrix[0],
matrix[1],
matrix[4],
matrix[5],
matrix[12],
matrix[13]
]);
s.params['/Matrix'] = PdfArray.fromNum(
[matrix[0], matrix[1], matrix[4], matrix[5], matrix[12], matrix[13]]);
}
final bbox = boundingBox ?? PdfRect.fromPoints(PdfPoint.zero, rect.size);
s.params['/BBox'] =
PdfArray.fromNum(<double?>[bbox.x, bbox.y, bbox.width, bbox.height]);
PdfArray.fromNum([bbox.x, bbox.y, bbox.width, bbox.height]);
final g = PdfGraphics(s, s.buf);
if (selected && name != null) {
... ... @@ -196,14 +190,14 @@ abstract class PdfAnnotBase {
@mustCallSuper
void build(PdfPage page, PdfObject object, PdfDict params) {
params['/Subtype'] = PdfName(subtype);
params['/Rect'] = PdfArray.fromNum(
<double?>[rect.left, rect.bottom, rect.right, rect.top]);
params['/Rect'] =
PdfArray.fromNum([rect.left, rect.bottom, rect.right, rect.top]);
params['/P'] = page.ref();
// handle the border
if (border == null) {
params['/Border'] = PdfArray.fromNum(const <int>[0, 0, 0]);
params['/Border'] = PdfArray.fromNum(const [0, 0, 0]);
} else {
params['/BS'] = border!.ref();
}
... ... @@ -283,7 +277,7 @@ class PdfAnnotNamedLink extends PdfAnnotBase {
void build(PdfPage page, PdfObject object, PdfDict params) {
super.build(page, object, params);
params['/A'] = PdfDict(
<String, PdfDataType>{
{
'/S': const PdfName('/GoTo'),
'/D': PdfSecString.fromString(object, dest),
},
... ... @@ -315,7 +309,7 @@ class PdfAnnotUrlLink extends PdfAnnotBase {
void build(PdfPage page, PdfObject object, PdfDict params) {
super.build(page, object, params);
params['/A'] = PdfDict(
<String, PdfDataType>{
{
'/S': const PdfName('/URI'),
'/URI': PdfSecString.fromString(object, url),
},
... ...
... ... @@ -115,7 +115,7 @@ class PdfNum extends PdfDataType {
class PdfNumList extends PdfDataType {
PdfNumList(this.values);
final List<num?> values;
final List<num> values;
@override
void output(PdfStream s) {
... ... @@ -123,7 +123,7 @@ class PdfNumList extends PdfDataType {
if (n > 0) {
s.putByte(0x20);
}
PdfNum(values[n]!).output(s);
PdfNum(values[n]).output(s);
}
}
... ... @@ -448,13 +448,13 @@ class PdfArray<T extends PdfDataType> extends PdfDataType {
}
}
static PdfArray<PdfIndirect> fromObjects(List<PdfObject?> objects) {
static PdfArray<PdfIndirect> fromObjects(List<PdfObject> objects) {
return PdfArray(
objects.map<PdfIndirect>((PdfObject? e) => e!.ref()).toList());
objects.map<PdfIndirect>((PdfObject e) => e.ref()).toList());
}
static PdfArray<PdfNum> fromNum(List<num?> list) {
return PdfArray(list.map<PdfNum>((num? e) => PdfNum(e!)).toList());
static PdfArray<PdfNum> fromNum(List<num> list) {
return PdfArray(list.map<PdfNum>((num e) => PdfNum(e)).toList());
}
final List<T> values = <T>[];
... ...
... ... @@ -111,13 +111,13 @@ class PdfGraphics {
late _PdfGraphicsContext _context;
final Queue<_PdfGraphicsContext> _contextQueue = Queue<_PdfGraphicsContext>();
final PdfGraphicStream? _page;
final PdfGraphicStream _page;
/// Buffer where to write the graphic operations
final PdfStream buf;
/// Default font if none selected
PdfFont? get defaultFont => _page!.getDefaultFont();
PdfFont? get defaultFont => _page.getDefaultFont();
/// Draw a surface on the previously defined shape
/// set evenOdd to false to use the nonzero winding number rule to determine the region to fill and to true to use the even-odd rule to determine the region to fill
... ... @@ -150,7 +150,7 @@ class PdfGraphics {
/// Apply a shader
void applyShader(PdfShading shader) {
// The shader needs to be registered in the page resources
_page!.addShader(shader);
_page.addShader(shader);
buf.putString('${shader.name} sh\n');
}
... ... @@ -179,7 +179,7 @@ class PdfGraphics {
h ??= img.height.toDouble() * w / img.width.toDouble();
// The image needs to be registered in the page resources
_page!.addXObject(img);
_page.addXObject(img);
// q w 0 0 h x y cm % the coordinate matrix
buf.putString('q ');
... ... @@ -214,7 +214,7 @@ class PdfGraphics {
}
/// Draws a line between two coordinates.
void drawLine(double? x1, double? y1, double? x2, double? y2) {
void drawLine(double x1, double y1, double x2, double y2) {
moveTo(x1, y1);
lineTo(x2, y2);
}
... ... @@ -230,12 +230,12 @@ class PdfGraphics {
/// Draws a Rectangle
void drawRect(
double? x,
double? y,
double? w,
double? h,
double x,
double y,
double w,
double h,
) {
PdfNumList(<double?>[x, y, w, h]).output(buf);
PdfNumList([x, y, w, h]).output(buf);
buf.putString(' re\n');
}
... ... @@ -297,18 +297,18 @@ class PdfGraphics {
PdfFont font,
double size,
String s,
double? x,
double x,
double y, {
double? charSpace = 0,
double charSpace = 0,
double wordSpace = 0,
double scale = 1,
PdfTextRenderingMode? mode = PdfTextRenderingMode.fill,
PdfTextRenderingMode mode = PdfTextRenderingMode.fill,
double rise = 0,
}) {
_page!.addFont(font);
_page.addFont(font);
buf.putString('BT ');
PdfNumList(<double?>[x, y]).output(buf);
PdfNumList([x, y]).output(buf);
buf.putString(' Td ');
setFont(font, size,
charSpace: charSpace,
... ... @@ -358,20 +358,20 @@ class PdfGraphics {
/// Sets the fill pattern for drawing
void setFillPattern(PdfPattern pattern) {
// The shader needs to be registered in the page resources
_page!.addPattern(pattern);
_page.addPattern(pattern);
buf.putString('/Pattern cs${pattern.name} scn\n');
}
/// Sets the stroke pattern for drawing
void setStrokePattern(PdfPattern pattern) {
// The shader needs to be registered in the page resources
_page!.addPattern(pattern);
_page.addPattern(pattern);
buf.putString('/Pattern CS${pattern.name} SCN\n');
}
/// Set the graphic state for drawing
void setGraphicState(PdfGraphicState state) {
final name = _page!.stateName(state);
final name = _page.stateName(state);
buf.putString('$name gs\n');
}
... ... @@ -389,14 +389,14 @@ class PdfGraphics {
}
/// This adds a line segment to the current path
void lineTo(double? x, double? y) {
PdfNumList(<double?>[x, y]).output(buf);
void lineTo(double x, double y) {
PdfNumList([x, y]).output(buf);
buf.putString(' l\n');
}
/// This moves the current drawing point.
void moveTo(double? x, double? y) {
PdfNumList(<double?>[x, y]).output(buf);
void moveTo(double x, double y) {
PdfNumList([x, y]).output(buf);
buf.putString(' m\n');
}
... ... @@ -404,8 +404,8 @@ class PdfGraphics {
/// using (x1,y1) as the control point at the beginning of the curve
/// and (x2,y2) as the control point at the end of the curve.
void curveTo(
double? x1, double? y1, double? x2, double? y2, double? x3, double? y3) {
PdfNumList(<double?>[x1, y1, x2, y2, x3, y3]).output(buf);
double x1, double y1, double x2, double y2, double x3, double y3) {
PdfNumList([x1, y1, x2, y2, x3, y3]).output(buf);
buf.putString(' c\n');
}
... ... @@ -524,7 +524,7 @@ class PdfGraphics {
/// the constraints imposed by the other parameters. large and sweep flags
/// contribute to the automatic calculations and help determine how the arc is drawn.
void bezierArc(
double? x1, double? y1, double rx, double ry, double? x2, double? y2,
double x1, double y1, double rx, double ry, double x2, double y2,
{bool large = false, bool sweep = false, double phi = 0.0}) {
if (x1 == x2 && y1 == y2) {
// From https://www.w3.org/TR/SVG/implnote.html#ArcImplementationNotes:
... ... @@ -542,12 +542,12 @@ class PdfGraphics {
// Our box bézier arcs can't handle rotations directly
// move to a well known point, eliminate phi and transform the other point
final mat = Matrix4.identity();
mat.translate(-x1!, -y1!);
mat.translate(-x1, -y1);
mat.rotateZ(-phi);
final tr = mat.transform3(Vector3(x2!, y2!, 0));
final tr = mat.transform3(Vector3(x2, y2, 0));
_endToCenterParameters(0, 0, tr[0], tr[1], large, sweep, rx, ry);
} else {
_endToCenterParameters(x1!, y1!, x2!, y2!, large, sweep, rx, ry);
_endToCenterParameters(x1, y1, x2, y2, large, sweep, rx, ry);
}
}
... ...
... ... @@ -64,7 +64,7 @@ class PdfShading extends PdfObject {
params['/ShadingType'] = PdfNum(shadingType.index + 2);
if (boundingBox != null) {
params['/BBox'] = PdfArray.fromNum(<double?>[
params['/BBox'] = PdfArray.fromNum([
boundingBox!.left,
boundingBox!.bottom,
boundingBox!.right,
... ... @@ -75,13 +75,12 @@ class PdfShading extends PdfObject {
params['/ColorSpace'] = const PdfName('/DeviceRGB');
if (shadingType == PdfShadingType.axial) {
params['/Coords'] =
PdfArray.fromNum(<double?>[start.x, start.y, end.x, end.y]);
params['/Coords'] = PdfArray.fromNum([start.x, start.y, end.x, end.y]);
} else if (shadingType == PdfShadingType.radial) {
assert(radius0 != null);
assert(radius1 != null);
params['/Coords'] = PdfArray.fromNum(
<double?>[start.x, start.y, radius0, end.x, end.y, radius1]);
[start.x, start.y, radius0!, end.x, end.y, radius1!]);
}
// params['/Domain'] = PdfArray.fromNum(<num>[0, 1]);
if (extendStart || extendEnd) {
... ...
... ... @@ -30,19 +30,19 @@ class PdfSoftMask {
bool knockout = false,
bool invert = false}) {
_mask = PdfGraphicXObject(document);
_mask!.params['/BBox'] = PdfArray.fromNum([
_mask.params['/BBox'] = PdfArray.fromNum([
boundingBox.x,
boundingBox.y,
boundingBox.width,
boundingBox.height,
]);
if (isolated) {
_mask!.params['/I'] = const PdfBool(true);
_mask.params['/I'] = const PdfBool(true);
}
if (knockout) {
_mask!.params['/K'] = const PdfBool(true);
_mask.params['/K'] = const PdfBool(true);
}
_graphics = PdfGraphics(_mask, _mask!.buf);
_graphics = PdfGraphics(_mask, _mask.buf);
if (invert) {
_tr = PdfFunction(
... ... @@ -54,7 +54,7 @@ class PdfSoftMask {
final PdfDocument document;
PdfGraphicXObject? _mask;
late PdfGraphicXObject _mask;
PdfGraphics? _graphics;
... ... @@ -65,7 +65,7 @@ class PdfSoftMask {
PdfDict output() {
final params = PdfDict({
'/S': const PdfName('/Luminosity'),
'/G': _mask!.ref(),
'/G': _mask.ref(),
});
if (_tr != null) {
... ...
... ... @@ -55,7 +55,7 @@ abstract class _Span {
void paint(
Context context,
TextStyle? style,
TextStyle style,
double textScaleFactor,
PdfPoint point,
);
... ... @@ -261,18 +261,18 @@ class _Word extends _Span {
@override
void paint(
Context context,
TextStyle? style,
TextStyle style,
double textScaleFactor,
PdfPoint point,
) {
context.canvas.drawString(
style!.font!.getFont(context)!,
style.font!.getFont(context)!,
style.fontSize! * textScaleFactor,
text,
point.x + offset.x,
point.y + offset.y,
mode: style.renderingMode,
charSpace: style.letterSpacing,
mode: style.renderingMode ?? PdfTextRenderingMode.fill,
charSpace: style.letterSpacing ?? 0,
);
}
... ... @@ -312,10 +312,10 @@ class _WidgetSpan extends _Span {
double get top => 0;
@override
double? get width => widget.box!.width;
double get width => widget.box!.width;
@override
double? get height => widget.box!.height;
double get height => widget.box!.height;
@override
PdfPoint get offset => widget.box!.offset;
... ... @@ -755,7 +755,7 @@ class RichText extends Widget {
style,
);
if (offsetX + ws.width! > constraintWidth && spanCount > 0) {
if (offsetX + ws.width > constraintWidth && spanCount > 0) {
overflow = true;
lines.add(_Line(
this,
... ... @@ -786,8 +786,8 @@ class RichText extends Widget {
final baseline = span.baseline! * textScaleFactor;
top = math.min(top ?? baseline, baseline);
bottom = math.max(
bottom ?? ws.height! + baseline,
ws.height! + baseline,
bottom ?? ws.height + baseline,
ws.height + baseline,
);
ws.offset = PdfPoint(offsetX, -offsetY + baseline);
... ... @@ -804,7 +804,7 @@ class RichText extends Widget {
),
);
offsetX += ws.left + ws.width!;
offsetX += ws.left + ws.width;
}
return true;
... ... @@ -897,7 +897,7 @@ class RichText extends Widget {
span.paint(
context,
currentStyle,
currentStyle!,
textScaleFactor,
PdfPoint(box!.left, box!.top),
);
... ...