David PHAM-VAN

Improve path operations

... ... @@ -81,6 +81,7 @@
- Add Divider and VerticalDivider Widget
- Replace Theme with ThemeData
- Implement ImageProvider
- Improve path operations
## 1.6.2
... ...
... ... @@ -114,24 +114,31 @@ class PdfGraphics {
PdfFont get defaultFont => _page.getDefaultFont();
/// Draw a surface on the previously defined shape
void fillPath() {
buf.putString('f\n');
/// 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}) {
buf.putString('f${evenOdd ? '*' : ''}\n');
}
/// Draw the contour of the previously defined shape
void strokePath() {
buf.putString('S\n');
void strokePath({bool close = false}) {
buf.putString('${close ? 's' : 'S'}\n');
}
/// Close the path with a line
void closePath() {
buf.putString('s\n');
buf.putString('h\n');
}
/// Create a clipping surface from the previously defined shape,
/// to prevent any further drawing outside
void clipPath() {
buf.putString('W n\n');
void clipPath({bool evenOdd = false, bool end = true}) {
buf.putString('W${evenOdd ? '*' : ''}${end ? ' n' : ''}\n');
}
/// 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}) {
buf.putString('${close ? 'b' : 'B'}${evenOdd ? '*' : ''}\n');
}
/// Apply a shader
... ... @@ -516,8 +523,8 @@ class PdfGraphics {
}
/// Draw an SVG path
void drawShape(String d, {bool stroke = true}) {
final proxy = _PathProxy(this, stroke);
void drawShape(String d) {
final proxy = _PathProxy(this);
writeSvgPathDataToPath(d, proxy);
}
... ... @@ -554,16 +561,13 @@ class PdfGraphics {
}
class _PathProxy extends PathProxy {
_PathProxy(this.canvas, this.stroke);
_PathProxy(this.canvas);
final PdfGraphics canvas;
final bool stroke;
@override
void close() {
if (stroke) {
canvas.closePath();
}
canvas.closePath();
}
@override
... ...
... ... @@ -112,7 +112,7 @@ class BoxBorder {
context.canvas.moveTo(box.x, box.y);
context.canvas.lineTo(box.x, box.top);
} else if (right && top) {
context.canvas.closePath();
context.canvas.strokePath(close: true);
} else {
context.canvas.lineTo(box.x, box.top);
}
... ...
... ... @@ -203,14 +203,15 @@ class Shape extends Widget {
if (fillColor != null) {
context.canvas
..setFillColor(fillColor)
..drawShape(shape, stroke: false)
..drawShape(shape)
..fillPath();
}
if (strokeColor != null) {
context.canvas
..setStrokeColor(strokeColor)
..drawShape(shape, stroke: true);
..drawShape(shape)
..strokePath();
}
context.canvas.restoreContext();
... ...
... ... @@ -44,8 +44,8 @@ void main() {
g.setTransform(tm);
g.setColor(const PdfColor(0, 0, 0));
g.drawShape(
'M37 0H9C6.24 0 4 2.24 4 5v38c0 2.76 2.24 5 5 5h28c2.76 0 5-2.24 5-5V5c0-2.76-2.24-5-5-5zM23 46c-1.66 0-3-1.34-3-3s1.34-3 3-3 3 1.34 3 3-1.34 3-3 3zm15-8H8V6h30v32z',
stroke: false);
'M37 0H9C6.24 0 4 2.24 4 5v38c0 2.76 2.24 5 5 5h28c2.76 0 5-2.24 5-5V5c0-2.76-2.24-5-5-5zM23 46c-1.66 0-3-1.34-3-3s1.34-3 3-3 3 1.34 3 3-1.34 3-3 3zm15-8H8V6h30v32z',
);
g.fillPath();
g.restoreContext();
... ... @@ -57,6 +57,7 @@ void main() {
g.setColor(const PdfColor(0, 0, 0));
g.drawShape(
'M300,200 h-150 a150,150 0 1,0 150,-150 z M275,175 v-150 a150,150 0 0,0 -150,150 z');
g.strokePath();
g.restoreContext();
final font1 = g.defaultFont;
... ...
No preview for this file type