Toggle navigation
Toggle navigation
This project
Loading...
Sign in
flutter_package
/
dart_pdf
Go to a project
Toggle navigation
Projects
Groups
Snippets
Help
Toggle navigation pinning
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
David PHAM-VAN
2021-02-09 10:23:37 -0400
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
25f5c43349c87c5d64705d2d1debbc1052d86e2c
25f5c433
1 parent
29a7008e
Convert BorderStyle to a class
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
75 additions
and
67 deletions
pdf/CHANGELOG.md
pdf/lib/src/widgets/box_border.dart
pdf/lib/src/widgets/grid_paper.dart
pdf/lib/src/widgets/table.dart
pdf/CHANGELOG.md
View file @
25f5c43
...
...
@@ -3,6 +3,8 @@
## 3.0.0-nullsafety.1
-
Fix Table border
-
Convert BorderStyle to a class
-
Implement dashed Divider
## 3.0.0-nullsafety.0
...
...
pdf/lib/src/widgets/box_border.dart
View file @
25f5c43
...
...
@@ -21,7 +21,43 @@ import 'border_radius.dart';
import
'decoration.dart'
;
import
'widget.dart'
;
enum
BorderStyle
{
none
,
solid
,
dashed
,
dotted
}
class
BorderStyle
{
const
BorderStyle
({
this
.
paint
=
true
,
this
.
pattern
,
this
.
phase
=
0
,
});
static
const
none
=
BorderStyle
(
paint:
false
);
static
const
solid
=
BorderStyle
();
static
const
dashed
=
BorderStyle
(
pattern:
<
int
>[
3
,
3
]);
static
const
dotted
=
BorderStyle
(
pattern:
<
int
>[
1
,
1
]);
/// Paint this line
final
bool
paint
;
/// Lengths of alternating dashes and gaps. The numbers shall be nonnegative
/// and not all zero.
final
List
<
num
>?
pattern
;
/// Specify the distance into the dash pattern at which to start the dash.
final
int
phase
;
void
setStyle
(
Context
context
)
{
if
(
paint
&&
pattern
!=
null
)
{
context
.
canvas
..
saveContext
()
..
setLineCap
(
PdfLineCap
.
butt
)
..
setLineDashPattern
(
pattern
!,
phase
);
}
}
void
unsetStyle
(
Context
context
)
{
if
(
paint
&&
pattern
!=
null
)
{
context
.
canvas
.
restoreContext
();
}
}
}
@immutable
abstract
class
BoxBorder
{
...
...
@@ -41,51 +77,21 @@ abstract class BoxBorder {
BorderRadius
?
borderRadius
,
});
static
void
setStyle
(
Context
context
,
BorderStyle
style
)
{
switch
(
style
)
{
case
BorderStyle
.
none
:
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
;
}
}
static
void
unsetStyle
(
Context
context
,
BorderStyle
style
)
{
switch
(
style
)
{
case
BorderStyle
.
none
:
case
BorderStyle
.
solid
:
break
;
case
BorderStyle
.
dashed
:
case
BorderStyle
.
dotted
:
context
.
canvas
.
restoreContext
();
break
;
}
}
static
void
_paintUniformBorderWithCircle
(
Context
context
,
PdfRect
box
,
BorderSide
side
)
{
s
etStyle
(
context
,
side
.
style
);
s
ide
.
style
.
setStyle
(
context
);
context
.
canvas
..
setStrokeColor
(
side
.
color
)
..
setLineWidth
(
side
.
width
)
..
drawEllipse
(
box
.
x
+
box
.
width
/
2.0
,
box
.
y
+
box
.
height
/
2.0
,
box
.
width
/
2.0
,
box
.
height
/
2.0
)
..
strokePath
();
unsetStyle
(
context
,
side
.
style
);
side
.
style
.
unsetStyle
(
context
);
}
static
void
_paintUniformBorderWithRadius
(
Context
context
,
PdfRect
box
,
BorderSide
side
,
BorderRadius
borderRadius
)
{
s
etStyle
(
context
,
side
.
style
);
s
ide
.
style
.
setStyle
(
context
);
context
.
canvas
..
setLineJoin
(
PdfLineJoin
.
miter
)
..
setMiterLimit
(
4
)
...
...
@@ -93,12 +99,12 @@ abstract class BoxBorder {
..
setLineWidth
(
side
.
width
);
borderRadius
.
paint
(
context
,
box
);
context
.
canvas
.
strokePath
();
unsetStyle
(
context
,
side
.
style
);
side
.
style
.
unsetStyle
(
context
);
}
static
void
_paintUniformBorderWithRectangle
(
Context
context
,
PdfRect
box
,
BorderSide
side
)
{
s
etStyle
(
context
,
side
.
style
);
s
ide
.
style
.
setStyle
(
context
);
context
.
canvas
..
setLineJoin
(
PdfLineJoin
.
miter
)
..
setMiterLimit
(
4
)
...
...
@@ -106,7 +112,7 @@ abstract class BoxBorder {
..
setLineWidth
(
side
.
width
)
..
drawBox
(
box
)
..
strokePath
();
unsetStyle
(
context
,
side
.
style
);
side
.
style
.
unsetStyle
(
context
);
}
}
...
...
@@ -251,44 +257,44 @@ class Border extends BoxBorder {
..
setMiterLimit
(
4
)
..
setLineJoin
(
PdfLineJoin
.
miter
);
if
(
top
.
style
!=
BorderStyle
.
none
)
{
BoxBorder
.
setStyle
(
context
,
top
.
style
);
if
(
top
.
style
.
paint
)
{
top
.
style
.
setStyle
(
context
);
context
.
canvas
..
setStrokeColor
(
top
.
color
)
..
setLineWidth
(
top
.
width
)
..
drawLine
(
box
.
left
,
box
.
top
,
box
.
right
,
box
.
top
)
..
strokePath
();
BoxBorder
.
unsetStyle
(
context
,
top
.
style
);
top
.
style
.
unsetStyle
(
context
);
}
if
(
right
.
style
!=
BorderStyle
.
none
)
{
BoxBorder
.
setStyle
(
context
,
right
.
style
);
if
(
right
.
style
.
paint
)
{
right
.
style
.
setStyle
(
context
);
context
.
canvas
..
setStrokeColor
(
right
.
color
)
..
setLineWidth
(
right
.
width
)
..
drawLine
(
box
.
right
,
box
.
top
,
box
.
right
,
box
.
bottom
)
..
strokePath
();
BoxBorder
.
unsetStyle
(
context
,
right
.
style
);
right
.
style
.
unsetStyle
(
context
);
}
if
(
bottom
.
style
!=
BorderStyle
.
none
)
{
BoxBorder
.
setStyle
(
context
,
bottom
.
style
);
if
(
bottom
.
style
.
paint
)
{
bottom
.
style
.
setStyle
(
context
);
context
.
canvas
..
setStrokeColor
(
bottom
.
color
)
..
setLineWidth
(
bottom
.
width
)
..
drawLine
(
box
.
right
,
box
.
bottom
,
box
.
left
,
box
.
bottom
)
..
strokePath
();
BoxBorder
.
unsetStyle
(
context
,
bottom
.
style
);
bottom
.
style
.
unsetStyle
(
context
);
}
if
(
left
.
style
!=
BorderStyle
.
none
)
{
BoxBorder
.
setStyle
(
context
,
left
.
style
);
if
(
left
.
style
.
paint
)
{
left
.
style
.
setStyle
(
context
);
context
.
canvas
..
setStrokeColor
(
left
.
color
)
..
setLineWidth
(
left
.
width
)
..
drawLine
(
box
.
left
,
box
.
top
,
box
.
left
,
box
.
bottom
)
..
strokePath
();
BoxBorder
.
unsetStyle
(
context
,
left
.
style
);
left
.
style
.
unsetStyle
(
context
);
}
}
}
...
...
pdf/lib/src/widgets/grid_paper.dart
View file @
25f5c43
...
...
@@ -270,45 +270,45 @@ class GridPaper extends SingleChildWidget {
n
++;
}
if
(
border
.
left
.
style
!=
BorderStyle
.
none
)
{
BoxBorder
.
setStyle
(
context
,
border
.
left
.
style
);
if
(
border
.
left
.
style
.
paint
)
{
border
.
left
.
style
.
setStyle
(
context
);
context
.
canvas
..
setStrokeColor
(
border
.
left
.
color
)
..
setLineWidth
(
border
.
left
.
width
)
..
drawLine
(
box
!.
left
+
margin
.
left
,
box
!.
top
,
box
!.
left
+
margin
.
left
,
box
!.
bottom
)
..
strokePath
();
BoxBorder
.
unsetStyle
(
context
,
border
.
left
.
style
);
border
.
left
.
style
.
unsetStyle
(
context
);
}
if
(
border
.
right
.
style
!=
BorderStyle
.
none
)
{
BoxBorder
.
setStyle
(
context
,
border
.
right
.
style
);
if
(
border
.
right
.
style
.
paint
)
{
border
.
right
.
style
.
setStyle
(
context
);
context
.
canvas
..
setStrokeColor
(
border
.
right
.
color
)
..
setLineWidth
(
border
.
right
.
width
)
..
drawLine
(
box
!.
right
-
margin
.
right
,
box
!.
top
,
box
!.
right
-
margin
.
right
,
box
!.
bottom
)
..
strokePath
();
BoxBorder
.
unsetStyle
(
context
,
border
.
right
.
style
);
border
.
right
.
style
.
unsetStyle
(
context
);
}
if
(
border
.
top
.
style
!=
BorderStyle
.
none
)
{
BoxBorder
.
setStyle
(
context
,
border
.
top
.
style
);
if
(
border
.
top
.
style
.
paint
)
{
border
.
top
.
style
.
setStyle
(
context
);
context
.
canvas
..
setStrokeColor
(
border
.
top
.
color
)
..
setLineWidth
(
border
.
top
.
width
)
..
drawLine
(
box
!.
left
,
box
!.
top
-
margin
.
top
,
box
!.
right
,
box
!.
top
-
margin
.
top
)
..
strokePath
();
BoxBorder
.
unsetStyle
(
context
,
border
.
top
.
style
);
border
.
top
.
style
.
unsetStyle
(
context
);
}
if
(
border
.
bottom
.
style
!=
BorderStyle
.
none
)
{
BoxBorder
.
setStyle
(
context
,
border
.
bottom
.
style
);
if
(
border
.
bottom
.
style
.
paint
)
{
border
.
bottom
.
style
.
setStyle
(
context
);
context
.
canvas
..
setStrokeColor
(
border
.
bottom
.
color
)
..
setLineWidth
(
border
.
bottom
.
width
)
..
drawLine
(
box
!.
left
,
box
!.
bottom
+
margin
.
bottom
,
box
!.
right
,
box
!.
bottom
+
margin
.
bottom
)
..
strokePath
();
BoxBorder
.
unsetStyle
(
context
,
border
.
bottom
.
style
);
border
.
bottom
.
style
.
unsetStyle
(
context
);
}
context
.
canvas
.
restoreContext
();
...
...
pdf/lib/src/widgets/table.dart
View file @
25f5c43
...
...
@@ -105,8 +105,8 @@ class TableBorder extends Border {
[
List
<
double
?>?
widths
,
List
<
double
>?
heights
])
{
super
.
paint
(
context
,
box
);
if
(
verticalInside
.
style
!=
BorderStyle
.
none
)
{
BoxBorder
.
setStyle
(
context
,
verticalInside
.
style
);
if
(
verticalInside
.
style
.
paint
)
{
verticalInside
.
style
.
setStyle
(
context
);
var
offset
=
box
.
x
;
for
(
var
width
in
widths
!.
sublist
(
0
,
widths
.
length
-
1
))
{
offset
+=
width
!;
...
...
@@ -117,11 +117,11 @@ class TableBorder extends Border {
context
.
canvas
.
setLineWidth
(
verticalInside
.
width
);
context
.
canvas
.
strokePath
();
BoxBorder
.
unsetStyle
(
context
,
verticalInside
.
style
);
verticalInside
.
style
.
unsetStyle
(
context
);
}
if
(
horizontalInside
.
style
!=
BorderStyle
.
none
)
{
BoxBorder
.
setStyle
(
context
,
verticalInside
.
style
);
if
(
horizontalInside
.
style
.
paint
)
{
horizontalInside
.
style
.
setStyle
(
context
);
var
offset
=
box
.
top
;
for
(
var
height
in
heights
!.
sublist
(
0
,
heights
.
length
-
1
))
{
offset
-=
height
;
...
...
@@ -131,7 +131,7 @@ class TableBorder extends Border {
context
.
canvas
.
setStrokeColor
(
verticalInside
.
color
);
context
.
canvas
.
setLineWidth
(
verticalInside
.
width
);
context
.
canvas
.
strokePath
();
BoxBorder
.
unsetStyle
(
context
,
verticalInside
.
style
);
horizontalInside
.
style
.
unsetStyle
(
context
);
}
}
}
...
...
Please
register
or
login
to post a comment