David PHAM-VAN

Add dashed lines to Decoration Widgets

... ... @@ -4,6 +4,7 @@
- Implement Linear and Radial gradients in BoxDecoration
- Fix PdfColors.shade()
- Add dashed lines to Decoration Widgets
## 1.6.2
... ...
... ... @@ -700,4 +700,9 @@ class PdfGraphics {
PdfNum(limit).output(buf);
buf.putString(' M\n');
}
void setLineDashPattern([List<int> array = const <int>[], int phase = 0]) {
PdfArray.fromNum(array).output(buf);
buf.putString(' $phase d\n');
}
}
... ...
... ... @@ -20,24 +20,30 @@ part of widget;
enum DecorationPosition { background, foreground }
enum BorderStyle { none, solid, dashed, dotted }
@immutable
class BoxBorder {
const BoxBorder(
{this.left = false,
const BoxBorder({
this.left = false,
this.top = false,
this.right = false,
this.bottom = false,
this.color = PdfColors.black,
this.width = 1.0})
: assert(color != null),
this.width = 1.0,
this.style = BorderStyle.solid,
}) : assert(color != null),
assert(width != null),
assert(width >= 0.0);
assert(width >= 0.0),
assert(style != null);
final bool top;
final bool bottom;
final bool left;
final bool right;
final BorderStyle style;
/// The color of the
final PdfColor color;
... ... @@ -50,7 +56,27 @@ class BoxBorder {
assert(box.width != null);
assert(box.height != null);
if (top || bottom || left || right) {
if (!(top || bottom || left || right)) {
return;
}
switch (style) {
case BorderStyle.none:
return;
case BorderStyle.solid:
break;
case BorderStyle.dashed:
context.canvas
..saveContext()
..setLineDashPattern(const <int>[3, 3]);
break;
case BorderStyle.dotted:
context.canvas
..saveContext()
..setLineDashPattern(const <int>[1, 1]);
break;
}
context.canvas
..setStrokeColor(color)
..setLineWidth(width);
... ... @@ -85,6 +111,8 @@ class BoxBorder {
}
context.canvas.strokePath();
if (style != BorderStyle.solid) {
context.canvas.restoreContext();
}
}
... ... @@ -349,6 +377,8 @@ class RadialGradient extends Gradient {
enum BoxShape { circle, rectangle }
enum PaintPhase { all, background, foreground }
@immutable
class BoxDecoration {
const BoxDecoration(
... ... @@ -368,12 +398,17 @@ class BoxDecoration {
final DecorationImage image;
final Gradient gradient;
void paint(Context context, PdfRect box) {
void paint(
Context context,
PdfRect box, [
PaintPhase phase = PaintPhase.all,
]) {
assert(box.x != null);
assert(box.y != null);
assert(box.width != null);
assert(box.height != null);
if (phase == PaintPhase.all || phase == PaintPhase.background) {
if (color != null) {
switch (shape) {
case BoxShape.rectangle:
... ... @@ -435,7 +470,9 @@ class BoxDecoration {
image.paint(context, box);
context.canvas.restoreContext();
}
}
if (phase == PaintPhase.all || phase == PaintPhase.foreground) {
if (border != null) {
switch (shape) {
case BoxShape.circle:
... ... @@ -451,4 +488,5 @@ class BoxDecoration {
}
}
}
}
}
... ...