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
2019-07-15 20:59:53 -0400
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
4e4e872a7035287524b7789fbaa857fb11c4b982
4e4e872a
1 parent
763ffcb4
Fix Image shape inside BoxDecoration
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
158 additions
and
16 deletions
pdf/CHANGELOG.md
pdf/lib/widgets/container.dart
pdf/lib/widgets/table.dart
pdf/pubspec.yaml
pdf/test/widget_container_test.dart
printing/pubspec.yaml
pdf/CHANGELOG.md
View file @
4e4e872
# Changelog
## 1.3.15
*
Fix Image shape inside BoxDecoration
## 1.3.14
*
Add Document ID
...
...
pdf/lib/widgets/container.dart
View file @
4e4e872
...
...
@@ -42,7 +42,7 @@ class BoxBorder {
/// The width of the
final
double
width
;
void
paint
Borders
(
Context
context
,
PdfRect
box
)
{
void
paint
Rect
(
Context
context
,
PdfRect
box
)
{
assert
(
box
.
x
!=
null
);
assert
(
box
.
y
!=
null
);
assert
(
box
.
width
!=
null
);
...
...
@@ -85,6 +85,34 @@ class BoxBorder {
context
.
canvas
.
strokePath
();
}
}
void
paintEllipse
(
Context
context
,
PdfRect
box
)
{
assert
(
box
.
x
!=
null
);
assert
(
box
.
y
!=
null
);
assert
(
box
.
width
!=
null
);
assert
(
box
.
height
!=
null
);
context
.
canvas
..
setStrokeColor
(
color
)
..
setLineWidth
(
width
)
..
drawEllipse
(
box
.
x
+
box
.
width
/
2.0
,
box
.
y
+
box
.
height
/
2.0
,
box
.
width
/
2.0
,
box
.
height
/
2.0
)
..
strokePath
();
}
void
paintRRect
(
Context
context
,
PdfRect
box
,
double
borderRadius
)
{
assert
(
box
.
x
!=
null
);
assert
(
box
.
y
!=
null
);
assert
(
box
.
width
!=
null
);
assert
(
box
.
height
!=
null
);
context
.
canvas
..
setStrokeColor
(
color
)
..
setLineWidth
(
width
)
..
drawRRect
(
box
.
x
,
box
.
y
,
box
.
width
,
box
.
height
,
borderRadius
,
borderRadius
)
..
strokePath
();
}
}
@immutable
...
...
@@ -101,7 +129,7 @@ class DecorationImage {
final
BoxFit
fit
;
final
Alignment
alignment
;
void
paint
Image
(
Context
context
,
PdfRect
box
)
{
void
paint
(
Context
context
,
PdfRect
box
)
{
final
PdfPoint
imageSize
=
PdfPoint
(
image
.
width
.
toDouble
(),
image
.
height
.
toDouble
());
final
FittedSizes
sizes
=
applyBoxFit
(
fit
,
imageSize
,
box
.
size
);
...
...
@@ -134,7 +162,8 @@ class BoxDecoration {
this
.
border
,
this
.
borderRadius
,
this
.
image
,
this
.
shape
=
BoxShape
.
rectangle
});
this
.
shape
=
BoxShape
.
rectangle
})
:
assert
(
shape
!=
null
);
/// The color to fill in the background of the box.
final
PdfColor
color
;
...
...
@@ -143,7 +172,7 @@ class BoxDecoration {
final
BoxShape
shape
;
final
DecorationImage
image
;
void
paint
Background
(
Context
context
,
PdfRect
box
)
{
void
paint
(
Context
context
,
PdfRect
box
)
{
assert
(
box
.
x
!=
null
);
assert
(
box
.
y
!=
null
);
assert
(
box
.
width
!=
null
);
...
...
@@ -168,6 +197,44 @@ class BoxDecoration {
..
setFillColor
(
color
)
..
fillPath
();
}
if
(
image
!=
null
)
{
context
.
canvas
.
saveContext
();
switch
(
shape
)
{
case
BoxShape
.
circle
:
context
.
canvas
..
drawEllipse
(
box
.
x
+
box
.
width
/
2.0
,
box
.
y
+
box
.
height
/
2.0
,
box
.
width
/
2.0
,
box
.
height
/
2.0
)
..
clipPath
();
break
;
case
BoxShape
.
rectangle
:
if
(
borderRadius
!=
null
)
{
context
.
canvas
..
drawRRect
(
box
.
x
,
box
.
y
,
box
.
width
,
box
.
height
,
borderRadius
,
borderRadius
)
..
clipPath
();
}
break
;
}
image
.
paint
(
context
,
box
);
context
.
canvas
.
restoreContext
();
}
if
(
border
!=
null
)
{
switch
(
shape
)
{
case
BoxShape
.
circle
:
border
.
paintEllipse
(
context
,
box
);
break
;
case
BoxShape
.
rectangle
:
if
(
borderRadius
!=
null
)
{
border
.
paintRRect
(
context
,
box
,
borderRadius
);
}
else
{
border
.
paintRect
(
context
,
box
);
}
break
;
}
}
}
}
...
...
@@ -190,15 +257,11 @@ class DecoratedBox extends SingleChildWidget {
void
paint
(
Context
context
)
{
super
.
paint
(
context
);
if
(
position
==
DecorationPosition
.
background
)
{
decoration
.
paintBackground
(
context
,
box
);
decoration
.
image
?.
paintImage
(
context
,
box
);
decoration
.
border
?.
paintBorders
(
context
,
box
);
decoration
.
paint
(
context
,
box
);
}
paintChild
(
context
);
if
(
position
==
DecorationPosition
.
foreground
)
{
decoration
.
paintBackground
(
context
,
box
);
decoration
.
image
?.
paintImage
(
context
,
box
);
decoration
.
border
?.
paintBorders
(
context
,
box
);
decoration
.
paint
(
context
,
box
);
}
}
}
...
...
pdf/lib/widgets/table.dart
View file @
4e4e872
...
...
@@ -53,10 +53,9 @@ class TableBorder extends BoxBorder {
final
bool
horizontalInside
;
final
bool
verticalInside
;
@override
void
paintBorders
(
Context
context
,
PdfRect
box
,
void
paint
(
Context
context
,
PdfRect
box
,
[
List
<
double
>
widths
,
List
<
double
>
heights
])
{
super
.
paint
Borders
(
context
,
box
);
super
.
paint
Rect
(
context
,
box
);
if
(
verticalInside
)
{
double
offset
=
box
.
x
;
...
...
@@ -307,7 +306,7 @@ class Table extends Widget implements SpanningWidget {
context
.
canvas
.
restoreContext
();
if
(
border
!=
null
)
{
border
.
paint
Borders
(
context
,
box
,
_widths
,
_heights
);
border
.
paint
(
context
,
box
,
_widths
,
_heights
);
}
}
}
...
...
pdf/pubspec.yaml
View file @
4e4e872
...
...
@@ -4,7 +4,7 @@ description: A pdf producer for Dart. It can create pdf files for both web or fl
homepage
:
https://github.com/DavBfr/dart_pdf/tree/master/pdf
repository
:
https://github.com/DavBfr/dart_pdf
issue_tracker
:
https://github.com/DavBfr/dart_pdf/issues
version
:
1.3.1
4
version
:
1.3.1
5
environment
:
sdk
:
"
>=2.1.0
<3.0.0"
...
...
pdf/test/widget_container_test.dart
View file @
4e4e872
...
...
@@ -90,6 +90,80 @@ void main() {
));
});
test
(
'Container Widgets BoxShape Image'
,
()
{
final
Uint32List
img
=
generateBitmap
(
100
,
100
);
final
PdfImage
image
=
PdfImage
(
pdf
.
document
,
image:
img
.
buffer
.
asUint8List
(),
width:
100
,
height:
100
);
pdf
.
addPage
(
Page
(
build:
(
Context
context
)
=>
Center
(
child:
Column
(
mainAxisAlignment:
MainAxisAlignment
.
spaceEvenly
,
children:
<
Widget
>[
Container
(
height:
200.0
,
width:
200.0
,
decoration:
BoxDecoration
(
shape:
BoxShape
.
circle
,
image:
DecorationImage
(
image:
image
,
fit:
BoxFit
.
cover
),
),
),
Container
(
height:
200.0
,
width:
200.0
,
decoration:
BoxDecoration
(
shape:
BoxShape
.
rectangle
,
borderRadius:
40
,
image:
DecorationImage
(
image:
image
,
fit:
BoxFit
.
cover
),
),
),
],
),
),
));
});
test
(
'Container Widgets BoxShape Border'
,
()
{
pdf
.
addPage
(
Page
(
build:
(
Context
context
)
=>
Center
(
child:
Column
(
mainAxisAlignment:
MainAxisAlignment
.
spaceEvenly
,
children:
<
Widget
>[
Container
(
height:
200.0
,
width:
200.0
,
decoration:
const
BoxDecoration
(
shape:
BoxShape
.
circle
,
border:
BoxBorder
(
bottom:
true
,
top:
true
,
left:
true
,
right:
true
,
color:
PdfColors
.
blue
,
width:
3
),
),
),
Container
(
height:
200.0
,
width:
200.0
,
decoration:
const
BoxDecoration
(
shape:
BoxShape
.
rectangle
,
borderRadius:
40
,
border:
BoxBorder
(
bottom:
true
,
top:
true
,
left:
true
,
right:
true
,
color:
PdfColors
.
blue
,
width:
3
),
),
),
],
),
),
));
});
tearDownAll
(()
{
final
File
file
=
File
(
'widgets-container.pdf'
);
file
.
writeAsBytesSync
(
pdf
.
save
());
...
...
printing/pubspec.yaml
View file @
4e4e872
...
...
@@ -13,7 +13,7 @@ environment:
dependencies
:
flutter
:
sdk
:
flutter
pdf
:
"
^1.3.1
4
"
pdf
:
"
^1.3.1
5
"
dev_dependencies
:
flutter_test
:
...
...
Please
register
or
login
to post a comment