David PHAM-VAN

Improve verbose output

... ... @@ -107,6 +107,10 @@ class PdfGraphics {
/// Ellipse 4-spline magic number
static const double _m4 = 0.551784;
static const int _commentIndent = 35;
static const int _indentAmount = 2;
int _indent = _indentAmount;
/// Graphic context
late _PdfGraphicsContext _context;
final Queue<_PdfGraphicsContext> _contextQueue = Queue<_PdfGraphicsContext>();
... ... @@ -122,78 +126,136 @@ class PdfGraphics {
/// 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
void fillPath({bool evenOdd = false}) {
var o = 0;
assert(() {
if (_page.pdfDocument.verbose) {
_buf.putComment('fillPath evenOdd:$evenOdd');
o = _buf.offset;
_buf.putString(' ' * (_indent));
}
return true;
}());
_buf.putString('f${evenOdd ? '*' : ''}\n');
_buf.putString('f${evenOdd ? '*' : ''} ');
assert(() {
if (_page.pdfDocument.verbose) {
_buf.putString(' ' * math.max(0, _commentIndent - _buf.offset + o));
_buf.putComment('fillPath(evenOdd: $evenOdd)');
}
return true;
}());
}
/// Draw the contour of the previously defined shape
void strokePath({bool close = false}) {
var o = 0;
assert(() {
if (_page.pdfDocument.verbose) {
_buf.putComment('strokePath close:$close');
o = _buf.offset;
_buf.putString(' ' * (_indent));
}
return true;
}());
_buf.putString('${close ? 's' : 'S'}\n');
_buf.putString('${close ? 's' : 'S'} ');
assert(() {
if (_page.pdfDocument.verbose) {
_buf.putString(' ' * math.max(0, _commentIndent - _buf.offset + o));
_buf.putComment('strokePath(close: $close)');
}
return true;
}());
}
/// Close the path with a line
void closePath() {
assert(() {
if (_page.pdfDocument.verbose) {
_buf.putComment('closePath');
_buf.putString(' ' * (_indent));
}
return true;
}());
_buf.putString('h\n');
_buf.putString('h ');
assert(() {
if (_page.pdfDocument.verbose) {
_buf.putString(' ' * (_commentIndent - 2 - _indent));
_buf.putComment('closePath()');
}
return true;
}());
}
/// Create a clipping surface from the previously defined shape,
/// to prevent any further drawing outside
void clipPath({bool evenOdd = false, bool end = true}) {
var o = 0;
assert(() {
if (_page.pdfDocument.verbose) {
_buf.putComment('clipPath evenOdd:$evenOdd end:$end');
o = _buf.offset;
_buf.putString(' ' * (_indent));
}
return true;
}());
_buf.putString('W${evenOdd ? '*' : ''}${end ? ' n' : ''}\n');
_buf.putString('W${evenOdd ? '*' : ''}${end ? ' n' : ''} ');
assert(() {
if (_page.pdfDocument.verbose) {
_buf.putString(' ' * math.max(0, _commentIndent - _buf.offset + o));
_buf.putComment('clipPath(evenOdd: $evenOdd, end: $end)');
}
return true;
}());
}
/// Draw a surface on the previously defined shape and then draw the contour
/// 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
void fillAndStrokePath({bool evenOdd = false, bool close = false}) {
var o = 0;
assert(() {
if (_page.pdfDocument.verbose) {
_buf.putComment('fillAndStrokePath evenOdd:$evenOdd close:$close');
o = _buf.offset;
_buf.putString(' ' * (_indent));
}
return true;
}());
_buf.putString('${close ? 'b' : 'B'}${evenOdd ? '*' : ''}\n');
_buf.putString('${close ? 'b' : 'B'}${evenOdd ? '*' : ''} ');
assert(() {
if (_page.pdfDocument.verbose) {
_buf.putString(' ' * math.max(0, _commentIndent - _buf.offset + o));
_buf.putComment('fillAndStrokePath(evenOdd:$evenOdd, close:$close)');
}
return true;
}());
}
/// Apply a shader
void applyShader(PdfShading shader) {
var o = 0;
assert(() {
if (_page.pdfDocument.verbose) {
_buf.putComment('applyShader');
o = _buf.offset;
_buf.putString(' ' * (_indent));
}
return true;
}());
// The shader needs to be registered in the page resources
_page.addShader(shader);
_buf.putString('${shader.name} sh\n');
_buf.putString('${shader.name} sh ');
assert(() {
if (_page.pdfDocument.verbose) {
_buf.putString(' ' * math.max(0, _commentIndent - _buf.offset + o));
_buf.putComment('applyShader(${shader.ref()})');
}
return true;
}());
}
/// This releases any resources used by this Graphics object. You must use
... ... @@ -202,17 +264,26 @@ class PdfGraphics {
/// When using [PdfPage], you can create another fresh Graphics instance,
/// which will draw over this one.
void restoreContext() {
if (_contextQueue.isNotEmpty) {
assert(() {
_indent -= _indentAmount;
if (_page.pdfDocument.verbose) {
_buf.putComment('restoreContext');
_buf.putString(' ' * (_indent));
}
return true;
}());
if (_contextQueue.isNotEmpty) {
// restore graphics context
_buf.putString('Q\n');
_buf.putString('Q ');
_context = _contextQueue.removeLast();
assert(() {
if (_page.pdfDocument.verbose) {
_buf.putString(' ' * (_commentIndent - 2 - _indent));
_buf.putComment('restoreContext()');
}
return true;
}());
}
}
... ... @@ -220,20 +291,29 @@ class PdfGraphics {
void saveContext() {
assert(() {
if (_page.pdfDocument.verbose) {
_buf.putComment('saveContext');
_buf.putString(' ' * (_indent));
}
return true;
}());
_buf.putString('q\n');
_buf.putString('q ');
_contextQueue.addLast(_context.copy());
assert(() {
if (_page.pdfDocument.verbose) {
_buf.putString(' ' * (_commentIndent - 2 - _indent));
_buf.putComment('saveContext()');
}
_indent += _indentAmount;
return true;
}());
}
/// Draws an image onto the page.
void drawImage(PdfImage img, double x, double y, [double? w, double? h]) {
var o = 0;
assert(() {
if (_page.pdfDocument.verbose) {
_buf.putComment('drawImage x:$x y:$y');
o = _buf.offset;
_buf.putString(' ' * (_indent));
}
return true;
}());
... ... @@ -273,18 +353,20 @@ class PdfGraphics {
break;
}
_buf.putString(' cm ${img.name} Do Q\n');
_buf.putString(' cm ${img.name} Do Q ');
}
/// Draws a line between two coordinates.
void drawLine(double x1, double y1, double x2, double y2) {
assert(() {
if (_page.pdfDocument.verbose) {
_buf.putComment('drawLine x1:$x1 y1:$y1 x2:$x2 y2:$y2');
_buf.putString(' ' * math.max(0, _commentIndent - _buf.offset + o));
_buf.putComment('drawImage(${img.ref()}, x: $x, y: $y, w: $w, h: $h)');
}
return true;
}());
}
/// Draws a line between two coordinates.
void drawLine(double x1, double y1, double x2, double y2) {
moveTo(x1, y1);
lineTo(x2, y2);
}
... ... @@ -294,13 +376,6 @@ class PdfGraphics {
/// Use clockwise=false to draw the inside of a donut
void drawEllipse(double x, double y, double r1, double r2,
{bool clockwise = true}) {
assert(() {
if (_page.pdfDocument.verbose) {
_buf.putComment('drawEllipse x:$x y:$y r1:$r1 r2:$r2');
}
return true;
}());
moveTo(x, y - r2);
if (clockwise) {
curveTo(x + _m4 * r1, y - r2, x + r1, y - _m4 * r2, x + r1, y);
... ... @@ -316,21 +391,26 @@ class PdfGraphics {
}
/// Draws a Rectangle
void drawRect(
double x,
double y,
double w,
double h,
) {
void drawRect(double x, double y, double w, double h) {
var o = 0;
assert(() {
if (_page.pdfDocument.verbose) {
_buf.putComment('drawRect x:$x y:$y w:$w h:$h');
o = _buf.offset;
_buf.putString(' ' * (_indent));
}
return true;
}());
PdfNumList([x, y, w, h]).output(_buf);
_buf.putString(' re\n');
_buf.putString(' re ');
assert(() {
if (_page.pdfDocument.verbose) {
_buf.putString(' ' * math.max(0, _commentIndent - _buf.offset + o));
_buf.putComment('drawRect(x: $x, y: $y, w: $w, h: $h)');
}
return true;
}());
}
/// Draws a Rectangle
... ... @@ -340,13 +420,6 @@ class PdfGraphics {
/// Draws a Rounded Rectangle
void drawRRect(double x, double y, double w, double h, double rv, double rh) {
assert(() {
if (_page.pdfDocument.verbose) {
_buf.putComment('drawRRect x:$x y:$y w:$w h:$h rv:$rv rh:$rh');
}
return true;
}());
moveTo(x, y + rv);
curveTo(x, y - _m4 * rv + rv, x - _m4 * rh + rh, y, x + rh, y);
lineTo(x + w - rh, y);
... ... @@ -366,38 +439,51 @@ class PdfGraphics {
double? charSpace,
double? wordSpace,
double? scale,
PdfTextRenderingMode? mode = PdfTextRenderingMode.fill,
PdfTextRenderingMode mode = PdfTextRenderingMode.fill,
double? rise,
}) {
var o = 0;
assert(() {
if (_page.pdfDocument.verbose) {
_buf.putComment('setFont');
o = _buf.offset;
_buf.putString(' ' * (_indent));
}
return true;
}());
_page.addFont(font);
_buf.putString('${font.name} ');
PdfNum(size).output(_buf);
_buf.putString(' Tf\n');
_buf.putString(' Tf ');
if (charSpace != null) {
PdfNum(charSpace).output(_buf);
_buf.putString(' Tc\n');
_buf.putString(' Tc ');
}
if (wordSpace != null) {
PdfNum(wordSpace).output(_buf);
_buf.putString(' Tw\n');
_buf.putString(' Tw ');
}
if (scale != null) {
PdfNum(scale * 100).output(_buf);
_buf.putString(' Tz\n');
_buf.putString(' Tz ');
}
if (rise != null) {
PdfNum(rise).output(_buf);
_buf.putString(' Ts\n');
_buf.putString(' Ts ');
}
if (mode != PdfTextRenderingMode.fill) {
_buf.putString('${mode!.index} Tr\n');
_buf.putString('${mode.index} Tr ');
}
assert(() {
if (_page.pdfDocument.verbose) {
_buf.putString(' ' * math.max(0, _commentIndent - _buf.offset + o));
_buf.putComment(
'setFont(${font.ref()}, size: $size, charSpace: $charSpace, wordSpace: $wordSpace, scale: $scale, mode: ${mode.name}, rise: $rise)');
}
return true;
}());
}
/// This draws a string.
... ... @@ -407,44 +493,103 @@ class PdfGraphics {
String s,
double x,
double y, {
double charSpace = 0,
double wordSpace = 0,
double scale = 1,
double? charSpace,
double? wordSpace,
double? scale,
PdfTextRenderingMode mode = PdfTextRenderingMode.fill,
double rise = 0,
double? rise,
}) {
assert(() {
if (_page.pdfDocument.verbose) {
_buf.putComment('drawString x:$x y:$y size:$size "$s"');
_buf.putString(' ' * (_indent));
}
return true;
}());
_page.addFont(font);
_buf.putString('BT ');
PdfNumList([x, y]).output(_buf);
_buf.putString(' Td ');
assert(() {
if (_page.pdfDocument.verbose) {
_buf.putString(' ' * (_commentIndent - 3 - _indent));
_buf.putComment('beginText()');
_indent += _indentAmount;
}
return true;
}());
setFont(font, size,
charSpace: charSpace,
mode: mode,
rise: rise,
scale: scale,
wordSpace: wordSpace);
var o = 0;
assert(() {
if (_page.pdfDocument.verbose) {
o = _buf.offset;
_buf.putString(' ' * (_indent));
}
return true;
}());
PdfNumList([x, y]).output(_buf);
_buf.putString(' Td ');
assert(() {
if (_page.pdfDocument.verbose) {
_buf.putString(' ' * math.max(0, _commentIndent - _buf.offset + o));
_buf.putComment('moveCursor($x, $y)');
o = _buf.offset;
_buf.putString(' ' * (_indent));
}
return true;
}());
_buf.putString('[');
font.putText(_buf, s);
_buf.putString(']TJ ET\n');
_buf.putString(']TJ ');
assert(() {
if (_page.pdfDocument.verbose) {
_buf.putString(' ' * math.max(0, _commentIndent - _buf.offset + o));
_buf.putComment('drawString("$s")');
o = _buf.offset;
_indent -= _indentAmount;
_buf.putString(' ' * (_indent));
}
return true;
}());
_buf.putString('ET ');
assert(() {
if (_page.pdfDocument.verbose) {
_buf.putString(' ' * (_commentIndent - 3 - _indent));
_buf.putComment('endText()');
}
return true;
}());
}
void reset() {
assert(() {
if (_page.pdfDocument.verbose) {
_buf.putComment('reset');
_buf.putString(' ' * (_indent));
}
return true;
}());
_buf.putString('0 Tr\n');
_buf.putString('0 Tr ');
assert(() {
if (_page.pdfDocument.verbose) {
_buf.putString(' ' * (_commentIndent - 5 - _indent));
_buf.putComment('reset()');
}
return true;
}());
}
/// Sets the color for drawing
... ... @@ -455,9 +600,11 @@ class PdfGraphics {
/// Sets the fill color for drawing
void setFillColor(PdfColor? color) {
var o = 0;
assert(() {
if (_page.pdfDocument.verbose) {
_buf.putComment('setFillColor ${color?.toHex()}');
o = _buf.offset;
_buf.putString(' ' * (_indent));
}
return true;
}());
... ... @@ -465,18 +612,28 @@ class PdfGraphics {
if (color is PdfColorCmyk) {
PdfNumList(<double>[color.cyan, color.magenta, color.yellow, color.black])
.output(_buf);
_buf.putString(' k\n');
_buf.putString(' k ');
} else {
PdfNumList(<double>[color!.red, color.green, color.blue]).output(_buf);
_buf.putString(' rg\n');
_buf.putString(' rg ');
}
assert(() {
if (_page.pdfDocument.verbose) {
_buf.putString(' ' * math.max(0, _commentIndent - _buf.offset + o));
_buf.putComment('setFillColor(${color?.toHex()})');
}
return true;
}());
}
/// Sets the stroke color for drawing
void setStrokeColor(PdfColor? color) {
var o = 0;
assert(() {
if (_page.pdfDocument.verbose) {
_buf.putComment('setStrokeColor ${color?.toHex()}');
o = _buf.offset;
_buf.putString(' ' * (_indent));
}
return true;
}());
... ... @@ -484,67 +641,116 @@ class PdfGraphics {
if (color is PdfColorCmyk) {
PdfNumList(<double>[color.cyan, color.magenta, color.yellow, color.black])
.output(_buf);
_buf.putString(' K\n');
_buf.putString(' K ');
} else {
PdfNumList(<double>[color!.red, color.green, color.blue]).output(_buf);
_buf.putString(' RG\n');
_buf.putString(' RG ');
}
assert(() {
if (_page.pdfDocument.verbose) {
_buf.putString(' ' * math.max(0, _commentIndent - _buf.offset + o));
_buf.putComment('setStrokeColor(${color?.toHex()})');
}
return true;
}());
}
/// Sets the fill pattern for drawing
void setFillPattern(PdfPattern pattern) {
var o = 0;
assert(() {
if (_page.pdfDocument.verbose) {
_buf.putComment('setFillPattern');
o = _buf.offset;
_buf.putString(' ' * (_indent));
}
return true;
}());
// The shader needs to be registered in the page resources
_page.addPattern(pattern);
_buf.putString('/Pattern cs${pattern.name} scn\n');
_buf.putString('/Pattern cs${pattern.name} scn ');
assert(() {
if (_page.pdfDocument.verbose) {
_buf.putString(' ' * math.max(0, _commentIndent - _buf.offset + o));
_buf.putComment('setFillPattern(${pattern.ref()})');
}
return true;
}());
}
/// Sets the stroke pattern for drawing
void setStrokePattern(PdfPattern pattern) {
var o = 0;
assert(() {
if (_page.pdfDocument.verbose) {
_buf.putComment('setStrokePattern');
o = _buf.offset;
_buf.putString(' ' * (_indent));
}
return true;
}());
// The shader needs to be registered in the page resources
_page.addPattern(pattern);
_buf.putString('/Pattern CS${pattern.name} SCN\n');
_buf.putString('/Pattern CS${pattern.name} SCN ');
assert(() {
if (_page.pdfDocument.verbose) {
_buf.putString(' ' * math.max(0, _commentIndent - _buf.offset + o));
_buf.putComment('setStrokePattern(${pattern.ref()})');
}
return true;
}());
}
/// Set the graphic state for drawing
void setGraphicState(PdfGraphicState state) {
var o = 0;
assert(() {
if (_page.pdfDocument.verbose) {
_buf.putComment('setGraphicState $state');
o = _buf.offset;
_buf.putString(' ' * (_indent));
}
return true;
}());
final name = _page.stateName(state);
_buf.putString('$name gs\n');
_buf.putString('$name gs ');
assert(() {
if (_page.pdfDocument.verbose) {
_buf.putString(' ' * math.max(0, _commentIndent - _buf.offset + o));
_buf.putComment('setGraphicState($state)');
}
return true;
}());
}
/// Set the transformation Matrix
void setTransform(Matrix4 t) {
var o = 0;
assert(() {
if (_page.pdfDocument.verbose) {
_buf.putComment('setTransform\n$t');
o = _buf.offset;
_buf.putString(' ' * (_indent));
}
return true;
}());
final s = t.storage;
PdfNumList(<double>[s[0], s[1], s[4], s[5], s[12], s[13]]).output(_buf);
_buf.putString(' cm\n');
_buf.putString(' cm ');
_context.ctm.multiply(t);
assert(() {
if (_page.pdfDocument.verbose) {
final n = math.max(0, _commentIndent - _buf.offset + o);
_buf.putString(' ' * n);
_buf.putComment('setTransform($s)');
}
return true;
}());
}
/// Get the transformation Matrix
... ... @@ -554,28 +760,48 @@ class PdfGraphics {
/// This adds a line segment to the current path
void lineTo(double x, double y) {
var o = 0;
assert(() {
if (_page.pdfDocument.verbose) {
_buf.putComment('lineTo x:$x y:$y');
o = _buf.offset;
_buf.putString(' ' * (_indent));
}
return true;
}());
PdfNumList([x, y]).output(_buf);
_buf.putString(' l\n');
_buf.putString(' l ');
assert(() {
if (_page.pdfDocument.verbose) {
_buf.putString(' ' * math.max(0, _commentIndent - _buf.offset + o));
_buf.putComment('lineTo($x, $y)');
}
return true;
}());
}
/// This moves the current drawing point.
void moveTo(double x, double y) {
var o = 0;
assert(() {
if (_page.pdfDocument.verbose) {
_buf.putComment('moveTo x:$x y:$y');
o = _buf.offset;
_buf.putString(' ' * (_indent));
}
return true;
}());
PdfNumList([x, y]).output(_buf);
_buf.putString(' m\n');
_buf.putString(' m ');
assert(() {
if (_page.pdfDocument.verbose) {
_buf.putString(' ' * math.max(0, _commentIndent - _buf.offset + o));
_buf.putComment('moveTo($x, $y)');
}
return true;
}());
}
/// Draw a cubic bézier curve from the current point to (x3,y3)
... ... @@ -583,15 +809,25 @@ class PdfGraphics {
/// 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) {
var o = 0;
assert(() {
if (_page.pdfDocument.verbose) {
_buf.putComment('curveTo x1:$x1 y1:$y1 x2:$x2 y2:$y2 x3:$x3 y3:$y3');
o = _buf.offset;
_buf.putString(' ' * (_indent));
}
return true;
}());
PdfNumList([x1, y1, x2, y2, x3, y3]).output(_buf);
_buf.putString(' c\n');
_buf.putString(' c ');
assert(() {
if (_page.pdfDocument.verbose) {
_buf.putString(' ' * math.max(0, _commentIndent - _buf.offset + o));
_buf.putComment('curveTo($x1, $y1, $x2, $y2, $x3, $y3)');
}
return true;
}());
}
double _vectorAngle(double ux, double uy, double vx, double vy) {
... ... @@ -753,51 +989,87 @@ class PdfGraphics {
void setLineCap(PdfLineCap cap) {
assert(() {
if (_page.pdfDocument.verbose) {
_buf.putComment('setLineCap $cap');
_buf.putString(' ' * (_indent));
}
return true;
}());
_buf.putString('${cap.index} J\n');
_buf.putString('${cap.index} J ');
assert(() {
if (_page.pdfDocument.verbose) {
_buf.putString(' ' * (_commentIndent - 4 - _indent));
_buf.putComment('setLineCap(${cap.name})');
}
return true;
}());
}
/// Set line join type
void setLineJoin(PdfLineJoin join) {
assert(() {
if (_page.pdfDocument.verbose) {
_buf.putComment('setLineJoin $join');
_buf.putString(' ' * (_indent));
}
return true;
}());
_buf.putString('${join.index} j\n');
_buf.putString('${join.index} j ');
assert(() {
if (_page.pdfDocument.verbose) {
_buf.putString(' ' * (_commentIndent - 4 - _indent));
_buf.putComment('setLineJoin(${join.name})');
}
return true;
}());
}
/// Set line width
void setLineWidth(double width) {
var o = 0;
assert(() {
if (_page.pdfDocument.verbose) {
_buf.putComment('setLineWidth $width');
o = _buf.offset;
_buf.putString(' ' * (_indent));
}
return true;
}());
PdfNum(width).output(_buf);
_buf.putString(' w\n');
_buf.putString(' w ');
assert(() {
if (_page.pdfDocument.verbose) {
_buf.putString(' ' * math.max(0, _commentIndent - _buf.offset + o));
_buf.putComment('setLineWidth($width)');
}
return true;
}());
}
/// Set line joint miter limit, applies if the
void setMiterLimit(double limit) {
var o = 0;
assert(() {
if (_page.pdfDocument.verbose) {
_buf.putComment('setMiterLimit $limit');
o = _buf.offset;
_buf.putString(' ' * (_indent));
}
return true;
}());
assert(limit >= 1.0);
PdfNum(limit).output(_buf);
_buf.putString(' M\n');
_buf.putString(' M ');
assert(() {
if (_page.pdfDocument.verbose) {
_buf.putString(' ' * math.max(0, _commentIndent - _buf.offset + o));
_buf.putComment('setMiterLimit($limit)');
}
return true;
}());
}
/// The dash array shall be cycled through, adding up the lengths of dashes and gaps.
... ... @@ -805,38 +1077,66 @@ class PdfGraphics {
///
/// Example: [2 1] will create a dash pattern with 2 on, 1 off, 2 on, 1 off, ...
void setLineDashPattern([List<num> array = const <num>[], int phase = 0]) {
var o = 0;
assert(() {
if (_page.pdfDocument.verbose) {
_buf.putComment('setLineDashPattern $array phase:$phase');
o = _buf.offset;
_buf.putString(' ' * (_indent));
}
return true;
}());
PdfArray.fromNum(array).output(_buf);
_buf.putString(' $phase d\n');
_buf.putString(' $phase d ');
assert(() {
if (_page.pdfDocument.verbose) {
_buf.putString(' ' * math.max(0, _commentIndent - _buf.offset + o));
_buf.putComment('setLineDashPattern($array, $phase)');
}
return true;
}());
}
void markContentBegin(PdfName tag) {
var o = 0;
assert(() {
if (_page.pdfDocument.verbose) {
_buf.putComment('markContentBegin');
o = _buf.offset;
_buf.putString(' ' * (_indent));
}
return true;
}());
tag.output(_buf);
_buf.putString(' BMC\n');
_buf.putString(' BMC ');
assert(() {
if (_page.pdfDocument.verbose) {
_buf.putString(' ' * math.max(0, _commentIndent - _buf.offset + o));
_buf.putComment('markContentBegin($tag)');
}
return true;
}());
}
void markContentEnd() {
assert(() {
if (_page.pdfDocument.verbose) {
_buf.putComment('markContentEnd');
_buf.putString(' ' * (_indent));
}
return true;
}());
_buf.putString('EMC\n');
_buf.putString('EMC ');
assert(() {
if (_page.pdfDocument.verbose) {
_buf.putString(' ' * (_commentIndent - 4 - _indent));
_buf.putComment('markContentEnd()');
}
return true;
}());
}
}
... ... @@ -891,8 +1191,8 @@ class _PathBBProxy extends PathProxy {
@override
void cubicTo(
double x1, double y1, double x2, double y2, double x3, double y3) {
final tvalues = <double>[];
double a, b, c, t, t1, t2, b2ac, sqrtb2ac;
final tValues = <double>[];
double a, b, c, t, t1, t2, b2ac, sqrtB2ac;
for (var i = 0; i < 2; ++i) {
if (i == 0) {
... ... @@ -910,7 +1210,7 @@ class _PathBBProxy extends PathProxy {
}
t = -c / b;
if (0 < t && t < 1) {
tvalues.add(t);
tValues.add(t);
}
continue;
}
... ... @@ -919,23 +1219,23 @@ class _PathBBProxy extends PathProxy {
if (b2ac.abs() < 1e-12) {
t = -b / (2 * a);
if (0 < t && t < 1) {
tvalues.add(t);
tValues.add(t);
}
}
continue;
}
sqrtb2ac = math.sqrt(b2ac);
t1 = (-b + sqrtb2ac) / (2 * a);
sqrtB2ac = math.sqrt(b2ac);
t1 = (-b + sqrtB2ac) / (2 * a);
if (0 < t1 && t1 < 1) {
tvalues.add(t1);
tValues.add(t1);
}
t2 = (-b - sqrtb2ac) / (2 * a);
t2 = (-b - sqrtB2ac) / (2 * a);
if (0 < t2 && t2 < 1) {
tvalues.add(t2);
tValues.add(t2);
}
}
for (final t in tvalues) {
for (final t in tValues) {
final mt = 1 - t;
_updateMinMax(
(mt * mt * mt * _pX) +
... ...
... ... @@ -94,7 +94,6 @@ class PdfOutput with PdfDiagnostic {
signatureID = ob;
}
xref.add(PdfXref(ob.objser, os.offset));
assert(() {
if (verbose) {
ob.setInsertion(os);
... ... @@ -102,6 +101,7 @@ class PdfOutput with PdfDiagnostic {
}
return true;
}());
xref.add(PdfXref(ob.objser, os.offset, generation: ob.objgen));
ob.write(os);
assert(() {
if (verbose) {
... ... @@ -145,36 +145,15 @@ class PdfOutput with PdfDiagnostic {
params['/Prev'] = PdfNum(rootID!.pdfDocument.prev!.xrefOffset);
}
final _xref = os.offset;
if (isCompressed) {
xref.outputCompressed(rootID!, os, params);
} else {
assert(() {
if (verbose) {
os.putComment('');
os.putComment('-' * 78);
}
return true;
}());
xref.output(os);
// the trailer object
assert(() {
if (verbose) {
os.putComment('');
os.putComment('-' * 78);
}
return true;
}());
os.putString('trailer\n');
params.output(os, verbose ? 0 : null);
os.putByte(0x0a);
}
final _xref = isCompressed
? xref.outputCompressed(rootID!, os, params)
: xref.outputLegacy(rootID!, os, params);
assert(() {
if (verbose) {
os.putComment('');
os.putComment('-' * 78);
os.putComment('$runtimeType');
}
return true;
}());
... ...
... ... @@ -83,7 +83,7 @@ class PdfXref {
}
@override
String toString() => '$runtimeType $id $generation $offset $type';
String toString() => '$id $generation obj ${type.name} $offset';
@override
int get hashCode => offset;
... ... @@ -101,8 +101,8 @@ class PdfXrefTable extends PdfDataType {
}
/// Writes a block of references to the Pdf file
void _writeblock(PdfStream s, int firstid, List<PdfXref> block) {
s.putString('$firstid ${block.length}\n');
void _writeBlock(PdfStream s, int firstId, List<PdfXref> block) {
s.putString('$firstId ${block.length}\n');
for (final x in block) {
s.putString(x.ref());
... ... @@ -111,14 +111,32 @@ class PdfXrefTable extends PdfDataType {
}
@override
void output(PdfStream s, [int? indent]) {
s.putString('xref\n');
void output(PdfStream s, [int? indent]) {}
@override
String toString() {
final s = StringBuffer();
for (final x in offsets) {
s.writeln(' $x');
}
return s.toString();
}
int outputLegacy(PdfObject object, PdfStream s, PdfDict params) {
// Now scan through the offsets list. They should be in sequence.
offsets.sort((a, b) => a.id.compareTo(b.id));
var firstid = 0; // First id in block
var lastid = 0; // The last id used
assert(() {
if (object.pdfDocument.verbose) {
s.putComment('');
s.putComment('-' * 78);
s.putComment('$runtimeType ${object.pdfDocument.version.name}\n$this');
}
return true;
}());
var firstId = 0; // First id in block
var lastId = 0; // The last id used
final block = <PdfXref>[]; // xrefs in this block
// We need block 0 to exist
... ... @@ -129,26 +147,42 @@ class PdfXrefTable extends PdfDataType {
type: PdfCrossRefEntryType.free,
));
final objOffset = s.offset;
s.putString('xref\n');
for (final x in offsets) {
// check to see if block is in range
if (x.id != (lastid + 1)) {
if (x.id != (lastId + 1)) {
// no, so write this block, and reset
_writeblock(s, firstid, block);
_writeBlock(s, firstId, block);
block.clear();
firstid = x.id;
firstId = x.id;
}
// now add to block
block.add(x);
lastid = x.id;
lastId = x.id;
}
// now write the last block
_writeblock(s, firstid, block);
_writeBlock(s, firstId, block);
// the trailer object
assert(() {
if (object.pdfDocument.verbose) {
s.putComment('');
}
return true;
}());
s.putString('trailer\n');
params.output(s, object.pdfDocument.verbose ? 0 : null);
s.putByte(0x0a);
return objOffset;
}
/// Output a compressed cross-reference table
void outputCompressed(PdfObject object, PdfStream s, PdfDict params) {
int outputCompressed(PdfObject object, PdfStream s, PdfDict params) {
final offset = s.offset;
// Sort all references
... ... @@ -161,24 +195,24 @@ class PdfXrefTable extends PdfDataType {
params['/Type'] = const PdfName('/XRef');
params['/Size'] = PdfNum(id + 1);
var firstid = 0; // First id in block
var lastid = 0; // The last id used
var firstId = 0; // First id in block
var lastId = 0; // The last id used
final blocks = <int>[]; // xrefs in this block first, count
// We need block 0 to exist
blocks.add(firstid);
blocks.add(firstId);
for (final x in offsets) {
// check to see if block is in range
if (x.id != (lastid + 1)) {
if (x.id != (lastId + 1)) {
// no, so store this block, and reset
blocks.add(lastid - firstid + 1);
firstid = x.id;
blocks.add(firstid);
blocks.add(lastId - firstId + 1);
firstId = x.id;
blocks.add(firstId);
}
lastid = x.id;
lastId = x.id;
}
blocks.add(lastid - firstid + 1);
blocks.add(lastId - firstId + 1);
if (!(blocks.length == 2 && blocks[0] == 0 && blocks[1] == id + 1)) {
params['/Index'] = PdfArray.fromNum(blocks);
... ... @@ -203,10 +237,13 @@ class PdfXrefTable extends PdfDataType {
if (object.pdfDocument.verbose) {
s.putComment('');
s.putComment('-' * 78);
s.putComment('$runtimeType $this');
s.putComment('$runtimeType ${object.pdfDocument.version.name}\n$this');
}
return true;
}());
final objOffset = s.offset;
s.putString('$id 0 obj\n');
PdfDictStream(
... ... @@ -218,5 +255,6 @@ class PdfXrefTable extends PdfDataType {
).output(s, object.pdfDocument.verbose ? 0 : null);
s.putString('endobj\n');
return objOffset;
}
}
... ...