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-02-24 11:40:51 -0500
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
ec2467e0422a5fe1b775d679f8c563080fca1e1f
ec2467e0
1 parent
aad91008
Update code to Dart 2.1.0
Show whitespace changes
Inline
Side-by-side
Showing
38 changed files
with
210 additions
and
183 deletions
.gitignore
Makefile
pdf/CHANGELOG.md
pdf/example/main.dart
pdf/lib/src/color.dart
pdf/lib/src/compatibility.dart
pdf/lib/src/font_metrics.dart
pdf/lib/src/graphics.dart
pdf/lib/src/page.dart
pdf/lib/src/polygon.dart
pdf/lib/src/rect.dart
pdf/lib/src/type1_font.dart
pdf/lib/src/type1_fonts.dart
pdf/lib/widgets/basic.dart
pdf/lib/widgets/container.dart
pdf/lib/widgets/content.dart
pdf/lib/widgets/document.dart
pdf/lib/widgets/flex.dart
pdf/lib/widgets/geometry.dart
pdf/lib/widgets/grid_view.dart
pdf/lib/widgets/placeholders.dart
pdf/lib/widgets/table.dart
pdf/lib/widgets/text.dart
pdf/lib/widgets/theme.dart
pdf/pubspec.yaml
pdf/test/annotations.dart
pdf/test/complex_test.dart
pdf/test/jpeg_test.dart
pdf/test/metrics.dart
pdf/test/minimal_test.dart
pdf/test/ttf_test.dart
pdf/test/type1_test.dart
pdf/test/widget_test.dart
printing/CHANGELOG.md
printing/example/lib/document.dart
printing/example/pubspec.yaml
printing/lib/src/printing.dart
printing/pubspec.yaml
.gitignore
View file @
ec2467e
...
...
@@ -31,3 +31,4 @@ printing/ios/Runner
.pana
pedantic_analyis_options_*.yaml
.dartfix
...
...
Makefile
View file @
ec2467e
...
...
@@ -43,6 +43,7 @@ test: pdf/.dart_tool $(FONTS)
cd
pdf; pub get
cd
pdf;
for
EXAMPLE
in
$(
shell
cd
pdf; find example -name
'*.dart'
)
;
do
dart
$$
EXAMPLE;
done
cd
pdf;
for
TEST
in
$(
shell
cd
pdf; find
test
-name
'*.dart'
)
;
do
dart
$$
TEST;
done
cd
printing/example; flutter packages get
cd
printing/example; flutter
test
clean
:
...
...
@@ -56,10 +57,20 @@ publish-printing: format clean
.pana
:
pub global activate pana
touch
.pana
touch
$@
analyze
:
.pana
@
pana --no-warning --source path pdf 2> /dev/null | python pana_report.py
@
pana --no-warning --source path printing 2> /dev/null | python pana_report.py
.dartfix
:
pub global activate dartfix
touch
$@
fix
:
.dartfix
cd
pdf; pub get
cd
pdf; dartfix --overwrite .
cd
printing; flutter packages get
cd
printing; dartfix --overwrite .
.PHONY
:
test format format-dart format-clang clean publish-pdf publish-printing analyze
...
...
pdf/CHANGELOG.md
View file @
ec2467e
# 1.3.3
*
Fix a bug with the RichText Widget
*
Update code to Dart 2.1.0
# 1.3.2
*
Fix dart lint warnings
...
...
pdf/example/main.dart
View file @
ec2467e
...
...
@@ -41,7 +41,7 @@ void main() {
child:
Row
(
mainAxisAlignment:
MainAxisAlignment
.
spaceBetween
,
children:
<
Widget
>[
Text
(
'Portable Document Format'
,
textScaleFactor:
2
.0
),
Text
(
'Portable Document Format'
,
textScaleFactor:
2
),
PdfLogo
()
])),
Paragraph
(
...
...
pdf/lib/src/color.dart
View file @
ec2467e
...
...
@@ -47,15 +47,15 @@ class PdfColor {
static
const
PdfColor
indigo
=
PdfColor
(
0.24705
,
0.31765
,
0.70980
);
static
const
PdfColor
blue
=
PdfColor
(
0.12941
,
0.58823
,
0.95294
);
static
const
PdfColor
lightBlue
=
PdfColor
(
0.01176
,
0.66274
,
0.95686
);
static
const
PdfColor
cyan
=
PdfColor
(
0.0
,
0.73725
,
0.83137
);
static
const
PdfColor
teal
=
PdfColor
(
0.0
,
0.58823
,
0.53333
);
static
const
PdfColor
cyan
=
PdfColor
(
0
,
0.73725
,
0.83137
);
static
const
PdfColor
teal
=
PdfColor
(
0
,
0.58823
,
0.53333
);
static
const
PdfColor
green
=
PdfColor
(
0.29803
,
0.68627
,
0.31372
);
static
const
PdfColor
lightGreen
=
PdfColor
(
0.54509
,
0.76470
,
0.29020
);
static
const
PdfColor
lime
=
PdfColor
(
0.80392
,
0.86274
,
0.22353
);
static
const
PdfColor
yellow
=
PdfColor
(
1.0
,
0.92157
,
0.23137
);
static
const
PdfColor
amber
=
PdfColor
(
1.0
,
0.75686
,
0.02745
);
static
const
PdfColor
orange
=
PdfColor
(
1.0
,
0.59608
,
0.0
);
static
const
PdfColor
deepOrange
=
PdfColor
(
1.0
,
0.34118
,
0.13333
);
static
const
PdfColor
yellow
=
PdfColor
(
1
,
0.92157
,
0.23137
);
static
const
PdfColor
amber
=
PdfColor
(
1
,
0.75686
,
0.02745
);
static
const
PdfColor
orange
=
PdfColor
(
1
,
0.59608
,
0
);
static
const
PdfColor
deepOrange
=
PdfColor
(
1
,
0.34118
,
0.13333
);
static
const
PdfColor
brown
=
PdfColor
(
0.47451
,
0.33333
,
0.28235
);
static
const
PdfColor
grey
=
PdfColor
(
0.61961
,
0.61961
,
0.61961
);
static
const
PdfColor
blueGrey
=
PdfColor
(
0.37647
,
0.49020
,
0.54510
);
...
...
pdf/lib/src/compatibility.dart
View file @
ec2467e
...
...
@@ -70,7 +70,7 @@ class PDFAnnot extends PdfAnnot {
static
const
PdfBorderStyle
BEVELED
=
PdfBorderStyle
.
beveled
;
static
const
PdfBorderStyle
INSET
=
PdfBorderStyle
.
inset
;
static
const
PdfBorderStyle
UNDERLINED
=
PdfBorderStyle
.
underlined
;
static
const
double
FULL_PAGE
=
-
9999
.0
;
static
const
double
FULL_PAGE
=
-
9999
;
}
@deprecated
...
...
pdf/lib/src/font_metrics.dart
View file @
ec2467e
...
...
@@ -44,7 +44,7 @@ class PdfFontMetrics {
double
left
;
double
top
;
double
right
=
0
.0
;
double
right
=
0
;
double
bottom
;
double
ascent
;
double
descent
;
...
...
@@ -72,7 +72,7 @@ class PdfFontMetrics {
}
static
const
PdfFontMetrics
zero
=
PdfFontMetrics
(
left:
0
.0
,
top:
0.0
,
right:
0.0
,
bottom:
0.
0
);
PdfFontMetrics
(
left:
0
,
top:
0
,
right:
0
,
bottom:
0
);
final
double
left
;
...
...
@@ -97,7 +97,7 @@ class PdfFontMetrics {
double
get
maxWidth
=>
math
.
max
(
advanceWidth
,
right
)
+
math
.
max
(-
leftBearing
,
0.0
);
double
get
effectiveLeft
=>
math
.
min
(
leftBearing
,
0
.0
);
double
get
effectiveLeft
=>
math
.
min
(
leftBearing
,
0
);
double
get
leftBearing
=>
left
;
...
...
pdf/lib/src/graphics.dart
View file @
ec2467e
...
...
@@ -97,7 +97,7 @@ class PdfGraphics {
// q w 0 0 h x y cm % the coordinate matrix
buf
.
putString
(
'q '
);
buf
.
putNumList
(<
double
>[
w
,
0
.0
,
0.
0
,
h
,
x
,
y
]);
buf
.
putNumList
(<
double
>[
w
,
0
,
0
,
h
,
x
,
y
]);
buf
.
putString
(
' cm
${img.name}
Do Q
\n
'
);
}
...
...
@@ -267,7 +267,7 @@ class PdfGraphics {
final
double
d
=
math
.
sqrt
(
ux
*
ux
+
uy
*
uy
)
*
math
.
sqrt
(
vx
*
vx
+
vy
*
vy
);
if
(
d
==
0.0
)
{
return
0
.0
;
return
0
;
}
double
c
=
(
ux
*
vx
+
uy
*
vy
)
/
d
;
if
(
c
<
-
1.0
)
{
...
...
@@ -315,8 +315,7 @@ class PdfGraphics {
final
double
cx
=
cxd
+
0.5
*
(
x1
+
x2
);
final
double
cy
=
cyd
+
0.5
*
(
y1
+
y2
);
final
double
theta
=
_vectorAngle
(
1.0
,
0.0
,
(
x1d
-
cxd
)
/
rx
,
(
y1d
-
cyd
)
/
ry
);
final
double
theta
=
_vectorAngle
(
1
,
0
,
(
x1d
-
cxd
)
/
rx
,
(
y1d
-
cyd
)
/
ry
);
double
dTheta
=
_vectorAngle
((
x1d
-
cxd
)
/
rx
,
(
y1d
-
cyd
)
/
ry
,
(-
x1d
-
cxd
)
/
rx
,
(-
y1d
-
cyd
)
/
ry
)
%
(
math
.
pi
*
2.0
);
...
...
@@ -400,8 +399,8 @@ class PdfGraphics {
final
Matrix4
mat
=
Matrix4
.
identity
();
mat
.
translate
(-
x1
,
-
y1
);
mat
.
rotateZ
(-
phi
);
final
Vector3
tr
=
mat
.
transform3
(
Vector3
(
x2
,
y2
,
0.0
));
_endToCenterParameters
(
0.0
,
0.0
,
tr
[
0
],
tr
[
1
],
large
,
sweep
,
rx
,
ry
);
final
Vector3
tr
=
mat
.
transform3
(
Vector3
(
x2
,
y2
,
0
));
_endToCenterParameters
(
0
,
0
,
tr
[
0
],
tr
[
1
],
large
,
sweep
,
rx
,
ry
);
}
else
{
_endToCenterParameters
(
x1
,
y1
,
x2
,
y2
,
large
,
sweep
,
rx
,
ry
);
}
...
...
@@ -415,8 +414,8 @@ class PdfGraphics {
String
action
;
String
lastAction
;
List
<
double
>
points
;
PdfPoint
lastControl
=
const
PdfPoint
(
0.0
,
0.0
);
PdfPoint
lastPoint
=
const
PdfPoint
(
0.0
,
0.0
);
PdfPoint
lastControl
=
const
PdfPoint
(
0
,
0
);
PdfPoint
lastPoint
=
const
PdfPoint
(
0
,
0
);
for
(
Match
m
in
matches
)
{
final
String
a
=
m
.
group
(
1
);
final
String
b
=
m
.
group
(
0
);
...
...
pdf/lib/src/page.dart
View file @
ec2467e
...
...
@@ -81,7 +81,7 @@ class PdfPage extends PdfObject {
// the /MediaBox for the page size
params
[
'/MediaBox'
]
=
PdfStream
()
..
putNumArray
(<
double
>[
0
.0
,
0.
0
,
pageFormat
.
width
,
pageFormat
.
height
]);
..
putNumArray
(<
double
>[
0
,
0
,
pageFormat
.
width
,
pageFormat
.
height
]);
// Rotation (if not zero)
// if(rotate!=0) {
...
...
pdf/lib/src/polygon.dart
View file @
ec2467e
...
...
@@ -23,6 +23,6 @@ class PdfPolygon {
PdfRect
getBounds
()
{
// TODO(me): Implement properly
return
const
PdfRect
(
0
.0
,
0.0
,
0.0
,
0.
0
);
return
const
PdfRect
(
0
,
0
,
0
,
0
);
}
}
...
...
pdf/lib/src/rect.dart
View file @
ec2467e
...
...
@@ -31,7 +31,7 @@ class PdfRect {
final
double
x
,
y
,
width
,
height
;
static
const
PdfRect
zero
=
PdfRect
(
0
.0
,
0.0
,
0.0
,
0.
0
);
static
const
PdfRect
zero
=
PdfRect
(
0
,
0
,
0
,
0
);
double
get
left
=>
x
;
double
get
bottom
=>
y
;
...
...
pdf/lib/src/type1_font.dart
View file @
ec2467e
...
...
@@ -45,7 +45,7 @@ class PdfType1Font extends PdfFont {
@override
PdfFontMetrics
glyphMetrics
(
int
charCode
)
{
return
PdfFontMetrics
(
left:
0
.0
,
left:
0
,
top:
descent
,
right:
charCode
<
widths
.
length
?
widths
[
charCode
]
...
...
pdf/lib/src/type1_fonts.dart
View file @
ec2467e
...
...
@@ -150,14 +150,14 @@ const List<double> _helveticaWidths = <double>[
0.222
,
0.278
,
0.333
,
1
.000
,
1
,
0.556
,
0.556
,
0.333
,
1
.000
,
1
,
0.667
,
0.250
,
1
.000
,
1
,
0.500
,
0.611
,
0.500
,
...
...
@@ -168,9 +168,9 @@ const List<double> _helveticaWidths = <double>[
0.333
,
0.350
,
0.556
,
1
.000
,
1
,
0.333
,
1
.000
,
1
,
0.500
,
0.250
,
0.938
,
...
...
@@ -215,7 +215,7 @@ const List<double> _helveticaWidths = <double>[
0.667
,
0.667
,
0.667
,
1
.000
,
1
,
0.722
,
0.667
,
0.667
,
...
...
@@ -409,14 +409,14 @@ const List<double> _helveticaBoldWidths = <double>[
0.278
,
0.556
,
0.500
,
1
.000
,
1
,
0.556
,
0.556
,
0.333
,
1
.000
,
1
,
0.667
,
0.333
,
1
.000
,
1
,
0.350
,
0.611
,
0.350
,
...
...
@@ -427,9 +427,9 @@ const List<double> _helveticaBoldWidths = <double>[
0.500
,
0.350
,
0.556
,
1
.000
,
1
,
0.333
,
1
.000
,
1
,
0.556
,
0.333
,
0.944
,
...
...
@@ -474,7 +474,7 @@ const List<double> _helveticaBoldWidths = <double>[
0.722
,
0.722
,
0.722
,
1
.000
,
1
,
0.722
,
0.667
,
0.667
,
...
...
@@ -668,14 +668,14 @@ const List<double> _helveticaBoldObliqueWidths = <double>[
0.278
,
0.556
,
0.500
,
1
.000
,
1
,
0.556
,
0.556
,
0.333
,
1
.000
,
1
,
0.667
,
0.333
,
1
.000
,
1
,
0.350
,
0.611
,
0.350
,
...
...
@@ -686,9 +686,9 @@ const List<double> _helveticaBoldObliqueWidths = <double>[
0.500
,
0.350
,
0.556
,
1
.000
,
1
,
0.333
,
1
.000
,
1
,
0.556
,
0.333
,
0.944
,
...
...
@@ -733,7 +733,7 @@ const List<double> _helveticaBoldObliqueWidths = <double>[
0.722
,
0.722
,
0.722
,
1
.000
,
1
,
0.722
,
0.667
,
0.667
,
...
...
@@ -927,14 +927,14 @@ const List<double> _helveticaObliqueWidths = <double>[
0.222
,
0.556
,
0.333
,
1
.000
,
1
,
0.556
,
0.556
,
0.333
,
1
.000
,
1
,
0.667
,
0.333
,
1
.000
,
1
,
0.350
,
0.611
,
0.350
,
...
...
@@ -945,9 +945,9 @@ const List<double> _helveticaObliqueWidths = <double>[
0.333
,
0.350
,
0.556
,
1
.000
,
1
,
0.333
,
1
.000
,
1
,
0.500
,
0.333
,
0.944
,
...
...
@@ -992,7 +992,7 @@ const List<double> _helveticaObliqueWidths = <double>[
0.667
,
0.667
,
0.667
,
1
.000
,
1
,
0.722
,
0.667
,
0.667
,
...
...
@@ -1186,11 +1186,11 @@ const List<double> _timesWidths = <double>[
0.333
,
0.500
,
0.444
,
1
.000
,
1
,
0.500
,
0.500
,
0.333
,
1
.000
,
1
,
0.556
,
0.333
,
0.889
,
...
...
@@ -1204,7 +1204,7 @@ const List<double> _timesWidths = <double>[
0.444
,
0.350
,
0.500
,
1
.000
,
1
,
0.333
,
0.980
,
0.389
,
...
...
@@ -1349,7 +1349,7 @@ const List<double> _timesBoldWidths = <double>[
0.555
,
0.500
,
0.500
,
1
.000
,
1
,
0.833
,
0.278
,
0.333
,
...
...
@@ -1399,7 +1399,7 @@ const List<double> _timesBoldWidths = <double>[
0.667
,
0.722
,
0.722
,
1
.000
,
1
,
0.722
,
0.722
,
0.667
,
...
...
@@ -1445,14 +1445,14 @@ const List<double> _timesBoldWidths = <double>[
0.333
,
0.500
,
0.500
,
1
.000
,
1
,
0.500
,
0.500
,
0.333
,
1
.000
,
1
,
0.556
,
0.333
,
1
.000
,
1
,
0.350
,
0.667
,
0.350
,
...
...
@@ -1463,9 +1463,9 @@ const List<double> _timesBoldWidths = <double>[
0.500
,
0.350
,
0.500
,
1
.000
,
1
,
0.333
,
1
.000
,
1
,
0.389
,
0.333
,
0.722
,
...
...
@@ -1510,7 +1510,7 @@ const List<double> _timesBoldWidths = <double>[
0.722
,
0.722
,
0.722
,
1
.000
,
1
,
0.722
,
0.667
,
0.667
,
...
...
@@ -1704,11 +1704,11 @@ const List<double> _timesBoldItalicWidths = <double>[
0.333
,
0.500
,
0.500
,
1
.000
,
1
,
0.500
,
0.500
,
0.333
,
1
.000
,
1
,
0.556
,
0.333
,
0.944
,
...
...
@@ -1722,9 +1722,9 @@ const List<double> _timesBoldItalicWidths = <double>[
0.500
,
0.350
,
0.500
,
1
.000
,
1
,
0.333
,
1
.000
,
1
,
0.389
,
0.333
,
0.722
,
...
...
@@ -1967,7 +1967,7 @@ const List<double> _timesItalicWidths = <double>[
0.500
,
0.500
,
0.333
,
1
.000
,
1
,
0.500
,
0.333
,
0.944
,
...
...
@@ -2277,9 +2277,9 @@ const List<double> _symbolWidths = <double>[
0.549
,
0.549
,
0.549
,
1
.000
,
1
,
0.603
,
1
.000
,
1
,
0.658
,
0.823
,
0.686
,
...
...
pdf/lib/widgets/basic.dart
View file @
ec2467e
...
...
@@ -141,7 +141,7 @@ class Transform extends SingleChildWidget {
Transform
.
translate
({
@required
PdfPoint
offset
,
Widget
child
,
})
:
transform
=
Matrix4
.
translationValues
(
offset
.
x
,
offset
.
y
,
0
.0
),
})
:
transform
=
Matrix4
.
translationValues
(
offset
.
x
,
offset
.
y
,
0
),
origin
=
null
,
alignment
=
null
,
super
(
child:
child
);
...
...
@@ -152,7 +152,7 @@ class Transform extends SingleChildWidget {
this
.
origin
,
this
.
alignment
=
Alignment
.
center
,
Widget
child
,
})
:
transform
=
Matrix4
.
diagonal3Values
(
scale
,
scale
,
1
.0
),
})
:
transform
=
Matrix4
.
diagonal3Values
(
scale
,
scale
,
1
),
super
(
child:
child
);
/// The matrix to transform the child by during painting.
...
...
@@ -329,8 +329,8 @@ class FittedBox extends SingleChildWidget {
alignment
.
inscribe
(
sizes
.
destination
,
box
);
final
Matrix4
mat
=
Matrix4
.
translationValues
(
destinationRect
.
x
,
destinationRect
.
y
,
0.0
)
..
scale
(
scaleX
,
scaleY
,
1.0
)
Matrix4
.
translationValues
(
destinationRect
.
x
,
destinationRect
.
y
,
0
)
..
scale
(
scaleX
,
scaleY
,
1
)
..
translate
(-
sourceRect
.
x
,
-
sourceRect
.
y
);
context
.
canvas
...
...
pdf/lib/widgets/container.dart
View file @
ec2467e
...
...
@@ -211,8 +211,8 @@ class Container extends StatelessWidget {
if
(
child
==
null
&&
(
constraints
==
null
||
!
constraints
.
isTight
))
{
current
=
LimitedBox
(
maxWidth:
0.0
,
maxHeight:
0.0
,
maxWidth:
0
,
maxHeight:
0
,
child:
ConstrainedBox
(
constraints:
const
BoxConstraints
.
expand
()));
}
...
...
pdf/lib/widgets/content.dart
View file @
ec2467e
...
...
@@ -52,7 +52,7 @@ class Header extends StatelessWidget {
_margin
??=
const
EdgeInsets
.
only
(
bottom:
5.0
*
PdfPageFormat
.
mm
);
_padding
??=
const
EdgeInsets
.
only
(
bottom:
1.0
*
PdfPageFormat
.
mm
);
_decoration
??=
const
BoxDecoration
(
border:
BoxBorder
(
bottom:
true
,
width:
1
.0
));
const
BoxDecoration
(
border:
BoxBorder
(
bottom:
true
,
width:
1
));
_textStyle
??=
Theme
.
of
(
context
).
header0
;
break
;
case
1
:
...
...
pdf/lib/widgets/document.dart
View file @
ec2467e
...
...
@@ -67,10 +67,10 @@ class Page extends BasePage {
void
debugPaint
(
Context
context
)
{
context
.
canvas
..
setFillColor
(
PdfColor
.
lightGreen
)
..
moveTo
(
0.0
,
0.0
)
..
lineTo
(
pageFormat
.
width
,
0.0
)
..
moveTo
(
0
,
0
)
..
lineTo
(
pageFormat
.
width
,
0
)
..
lineTo
(
pageFormat
.
width
,
pageFormat
.
height
)
..
lineTo
(
0
.0
,
pageFormat
.
height
)
..
lineTo
(
0
,
pageFormat
.
height
)
..
moveTo
(
margin
.
left
,
margin
.
bottom
)
..
lineTo
(
margin
.
left
,
pageFormat
.
height
-
margin
.
top
)
..
lineTo
(
pageFormat
.
width
-
margin
.
right
,
pageFormat
.
height
-
margin
.
top
)
...
...
pdf/lib/widgets/flex.dart
View file @
ec2467e
...
...
@@ -89,9 +89,9 @@ class Flex extends MultiChildWidget {
// INTRINSIC MAIN SIZE
// Intrinsic main size is the smallest size the flex container can take
// while maintaining the min/max-content contributions of its flex items.
double
totalFlex
=
0.0
;
double
inflexibleSpace
=
0.0
;
double
maxFlexFractionSoFar
=
0.0
;
double
totalFlex
=
0
;
double
inflexibleSpace
=
0
;
double
maxFlexFractionSoFar
=
0
;
for
(
Widget
child
in
children
)
{
final
int
flex
=
child
is
Expanded
?
child
.
flex
:
0
;
...
...
@@ -113,8 +113,8 @@ class Flex extends MultiChildWidget {
// Get inflexible space using the max intrinsic dimensions of fixed children in the main direction.
final
double
availableMainSpace
=
extent
;
int
totalFlex
=
0
;
double
inflexibleSpace
=
0.0
;
double
maxCrossSize
=
0.0
;
double
inflexibleSpace
=
0
;
double
maxCrossSize
=
0
;
for
(
Widget
child
in
children
)
{
final
int
flex
=
child
is
Expanded
?
child
.
flex
:
0
;
totalFlex
+=
flex
;
...
...
@@ -139,7 +139,7 @@ class Flex extends MultiChildWidget {
// Determine the spacePerFlex by allocating the remaining available space.
// When you're over-constrained spacePerFlex can be negative.
final
double
spacePerFlex
=
math
.
max
(
0
.0
,
(
availableMainSpace
-
inflexibleSpace
)
/
totalFlex
);
math
.
max
(
0
,
(
availableMainSpace
-
inflexibleSpace
)
/
totalFlex
);
// Size remaining (flexible) items, find the maximum cross size.
for
(
Widget
child
in
children
)
{
...
...
@@ -214,9 +214,8 @@ class Flex extends MultiChildWidget {
:
constraints
.
maxHeight
;
final
bool
canFlex
=
maxMainSize
<
double
.
infinity
;
double
crossSize
=
0.0
;
double
allocatedSize
=
0.0
;
// Sum of the sizes of the non-flexible children.
double
crossSize
=
0
;
double
allocatedSize
=
0
;
// Sum of the sizes of the non-flexible children.
for
(
Widget
child
in
children
)
{
final
int
flex
=
child
is
Expanded
?
child
.
flex
:
0
;
...
...
@@ -269,8 +268,8 @@ class Flex extends MultiChildWidget {
// Distribute free space to flexible children, and determine baseline.
final
double
freeSpace
=
math
.
max
(
0.0
,
(
canFlex
?
maxMainSize
:
0.0
)
-
allocatedSize
);
double
allocatedFlexSpace
=
0.0
;
math
.
max
(
0
,
(
canFlex
?
maxMainSize
:
0.0
)
-
allocatedSize
);
double
allocatedFlexSpace
=
0
;
if
(
totalFlex
>
0
)
{
final
double
spacePerFlex
=
canFlex
&&
totalFlex
>
0
?
(
freeSpace
/
totalFlex
)
:
double
.
nan
;
...
...
@@ -362,7 +361,7 @@ class Flex extends MultiChildWidget {
box
=
PdfRect
.
fromPoints
(
PdfPoint
.
zero
,
size
);
actualSizeDelta
=
actualSize
-
allocatedSize
;
final
double
remainingSpace
=
math
.
max
(
0
.0
,
actualSizeDelta
);
final
double
remainingSpace
=
math
.
max
(
0
,
actualSizeDelta
);
double
leadingSpace
;
double
betweenSpace
;
final
bool
flipMainAxis
=
(
verticalDirection
==
VerticalDirection
.
down
&&
...
...
pdf/lib/widgets/geometry.dart
View file @
ec2467e
...
...
@@ -74,7 +74,7 @@ class BoxConstraints {
PdfPoint
get
biggest
=>
PdfPoint
(
constrainWidth
(),
constrainHeight
());
/// The smallest size that satisfies the constraints.
PdfPoint
get
smallest
=>
PdfPoint
(
constrainWidth
(
0
.0
),
constrainHeight
(
0.
0
));
PdfPoint
get
smallest
=>
PdfPoint
(
constrainWidth
(
0
),
constrainHeight
(
0
));
/// Whether there is exactly one width value that satisfies the constraints.
bool
get
hasTightWidth
=>
minWidth
>=
maxWidth
;
...
...
@@ -162,8 +162,8 @@ class BoxConstraints {
assert
(
edges
!=
null
);
final
double
horizontal
=
edges
.
horizontal
;
final
double
vertical
=
edges
.
vertical
;
final
double
deflatedMinWidth
=
math
.
max
(
0.0
,
minWidth
-
horizontal
);
final
double
deflatedMinHeight
=
math
.
max
(
0.0
,
minHeight
-
vertical
);
final
double
deflatedMinWidth
=
math
.
max
(
0
,
minWidth
-
horizontal
);
final
double
deflatedMinHeight
=
math
.
max
(
0
,
minHeight
-
vertical
);
return
BoxConstraints
(
minWidth:
deflatedMinWidth
,
maxWidth:
math
.
max
(
deflatedMinWidth
,
maxWidth
-
horizontal
),
...
...
@@ -174,10 +174,11 @@ class BoxConstraints {
/// Returns new box constraints that remove the minimum width and height requirements.
BoxConstraints
loosen
()
{
return
BoxConstraints
(
minWidth:
0.
0
,
minWidth:
0
,
maxWidth:
maxWidth
,
minHeight:
0.0
,
maxHeight:
maxHeight
);
minHeight:
0
,
maxHeight:
maxHeight
,
);
}
/// Returns new box constraints that respect the given constraints while being
...
...
@@ -279,31 +280,31 @@ class Alignment {
final
double
y
;
/// The top left corner.
static
const
Alignment
topLeft
=
Alignment
(-
1
.0
,
1.0
);
static
const
Alignment
topLeft
=
Alignment
(-
1
,
1
);
/// The center point along the top edge.
static
const
Alignment
topCenter
=
Alignment
(
0
.0
,
1.0
);
static
const
Alignment
topCenter
=
Alignment
(
0
,
1
);
/// The top right corner.
static
const
Alignment
topRight
=
Alignment
(
1
.0
,
1.0
);
static
const
Alignment
topRight
=
Alignment
(
1
,
1
);
/// The center point along the left edge.
static
const
Alignment
centerLeft
=
Alignment
(-
1
.0
,
0.
0
);
static
const
Alignment
centerLeft
=
Alignment
(-
1
,
0
);
/// The center point, both horizontally and vertically.
static
const
Alignment
center
=
Alignment
(
0
.0
,
0.
0
);
static
const
Alignment
center
=
Alignment
(
0
,
0
);
/// The center point along the right edge.
static
const
Alignment
centerRight
=
Alignment
(
1
.0
,
0.
0
);
static
const
Alignment
centerRight
=
Alignment
(
1
,
0
);
/// The bottom left corner.
static
const
Alignment
bottomLeft
=
Alignment
(-
1
.0
,
-
1.0
);
static
const
Alignment
bottomLeft
=
Alignment
(-
1
,
-
1
);
/// The center point along the bottom edge.
static
const
Alignment
bottomCenter
=
Alignment
(
0
.0
,
-
1.0
);
static
const
Alignment
bottomCenter
=
Alignment
(
0
,
-
1
);
/// The bottom right corner.
static
const
Alignment
bottomRight
=
Alignment
(
1
.0
,
-
1.0
);
static
const
Alignment
bottomRight
=
Alignment
(
1
,
-
1
);
/// Returns the offset that is this fraction within the given size.
PdfPoint
alongSize
(
PdfPoint
other
)
{
...
...
@@ -414,7 +415,7 @@ FittedSizes applyBoxFit(BoxFit fit, PdfPoint inputSize, PdfPoint outputSize) {
}
PdfPoint
transformPoint
(
Matrix4
transform
,
PdfPoint
point
)
{
final
Vector3
position3
=
Vector3
(
point
.
x
,
point
.
y
,
0
.0
);
final
Vector3
position3
=
Vector3
(
point
.
x
,
point
.
y
,
0
);
final
Vector3
transformed3
=
transform
.
perspectiveTransform
(
position3
);
return
PdfPoint
(
transformed3
.
x
,
transformed3
.
y
);
}
...
...
pdf/lib/widgets/grid_view.dart
View file @
ec2467e
...
...
@@ -70,7 +70,7 @@ class GridView extends MultiChildWidget {
crossAxisSpacing
;
final
double
startX
=
padding
.
left
;
const
double
startY
=
0
.0
;
const
double
startY
=
0
;
double
mainAxis
;
double
crossAxis
;
BoxConstraints
innerConstraints
;
...
...
@@ -167,7 +167,7 @@ class GridView extends MultiChildWidget {
(
_childCrossAxis
+
crossAxisSpacing
)
*
c
-
crossAxisSpacing
,
box
.
bottom
+
padding
.
bottom
,
math
.
max
(
crossAxisSpacing
,
1
.0
),
math
.
max
(
crossAxisSpacing
,
1
),
box
.
height
-
padding
.
vertical
)
..
fillPath
();
break
;
...
...
@@ -187,7 +187,7 @@ class GridView extends MultiChildWidget {
(
_childMainAxis
+
mainAxisSpacing
)
*
c
-
mainAxisSpacing
,
box
.
width
-
padding
.
horizontal
,
math
.
max
(
mainAxisSpacing
,
1
.0
))
math
.
max
(
mainAxisSpacing
,
1
))
..
fillPath
();
break
;
case
Axis
.
horizontal
:
...
...
pdf/lib/widgets/placeholders.dart
View file @
ec2467e
...
...
@@ -35,8 +35,8 @@ class Placeholder extends Widget {
void
layout
(
Context
context
,
BoxConstraints
constraints
,
{
bool
parentUsesSize
=
false
})
{
box
=
PdfRect
(
0.0
,
0.0
,
0
,
0
,
constraints
.
constrainWidth
(
constraints
.
hasBoundedWidth
?
constraints
.
maxWidth
:
fallbackWidth
),
constraints
.
constrainHeight
(
constraints
.
hasBoundedHeight
...
...
@@ -71,7 +71,7 @@ class PdfLogo extends StatelessWidget {
@override
Widget
build
(
Context
context
)
{
return
Shape
(
pdf
,
width:
24
.0
,
height:
27.0
,
fillColor:
color
,
fit:
fit
);
return
Shape
(
pdf
,
width:
24
,
height:
27
,
fillColor:
color
,
fit:
fit
);
}
}
...
...
pdf/lib/widgets/table.dart
View file @
ec2467e
...
...
@@ -186,7 +186,7 @@ class Table extends Widget implements SpanningWidget {
// Compute column widths using flex and estimated width
if
(
constraints
.
hasBoundedWidth
)
{
final
double
totalFlex
=
flex
.
reduce
((
double
a
,
double
b
)
=>
a
+
b
);
double
flexSpace
=
0
.0
;
double
flexSpace
=
0
;
for
(
int
n
=
0
;
n
<
_widths
.
length
;
n
++)
{
if
(
flex
[
n
]
==
0.0
)
{
final
double
newWidth
=
_widths
[
n
]
/
maxWidth
*
constraints
.
maxWidth
;
...
...
@@ -212,7 +212,7 @@ class Table extends Widget implements SpanningWidget {
final
double
totalWidth
=
_widths
.
reduce
((
double
a
,
double
b
)
=>
a
+
b
);
// Compute final widths
double
totalHeight
=
0
.0
;
double
totalHeight
=
0
;
index
=
0
;
for
(
TableRow
row
in
children
)
{
if
(
index
++
<
_context
.
firstLine
&&
!
row
.
repeat
)
{
...
...
@@ -220,9 +220,9 @@ class Table extends Widget implements SpanningWidget {
}
int
n
=
0
;
double
x
=
0
.0
;
double
x
=
0
;
double
lineHeight
=
0
.0
;
double
lineHeight
=
0
;
for
(
Widget
child
in
row
.
children
)
{
final
BoxConstraints
childConstraints
=
BoxConstraints
.
tightFor
(
width:
_widths
[
n
]);
...
...
@@ -262,7 +262,7 @@ class Table extends Widget implements SpanningWidget {
}
}
box
=
PdfRect
(
0
.0
,
0.
0
,
totalWidth
,
totalHeight
);
box
=
PdfRect
(
0
,
0
,
totalWidth
,
totalHeight
);
}
@override
...
...
pdf/lib/widgets/text.dart
View file @
ec2467e
...
...
@@ -35,7 +35,7 @@ class _Word {
}
void
debugPaint
(
Context
context
,
double
textScaleFactor
,
PdfRect
globalBox
)
{
const
double
deb
=
5
.0
;
const
double
deb
=
5
;
context
.
canvas
..
drawRect
(
globalBox
.
x
+
offset
.
x
+
metrics
.
left
,
...
...
@@ -111,7 +111,7 @@ class RichText extends Widget {
double
_realignLine
(
List
<
_Word
>
words
,
double
totalWidth
,
double
wordsWidth
,
bool
last
,
double
baseline
)
{
double
delta
=
0
.0
;
double
delta
=
0
;
switch
(
textAlign
)
{
case
TextAlign
.
left
:
totalWidth
=
wordsWidth
;
...
...
@@ -128,7 +128,7 @@ class RichText extends Widget {
break
;
}
delta
=
(
totalWidth
-
wordsWidth
)
/
(
words
.
length
-
1
);
double
x
=
0
.0
;
double
x
=
0
;
for
(
_Word
word
in
words
)
{
word
.
offset
=
word
.
offset
.
translate
(
x
,
-
baseline
);
x
+=
delta
;
...
...
@@ -156,9 +156,9 @@ class RichText extends Widget {
?
constraints
.
maxHeight
:
constraints
.
constrainHeight
();
double
offsetX
=
0.0
;
double
offsetY
=
0.0
;
double
width
=
0.0
;
double
offsetX
=
0
;
double
offsetY
=
0
;
double
width
=
0
;
double
top
;
double
bottom
;
...
...
@@ -230,7 +230,7 @@ class RichText extends Widget {
bottom
??=
0.0
;
top
??=
0.0
;
box
=
PdfRect
(
0
.0
,
0.
0
,
constraints
.
constrainWidth
(
width
),
box
=
PdfRect
(
0
,
0
,
constraints
.
constrainWidth
(
width
),
constraints
.
constrainHeight
(
offsetY
+
bottom
-
top
));
}
...
...
pdf/lib/widgets/theme.dart
View file @
ec2467e
...
...
@@ -104,8 +104,8 @@ class Theme extends Inherited {
return
Theme
(
defaultTextStyle:
defaultTextStyle
,
defaultTextStyleBold:
defaultTextStyleBold
,
paragraphStyle:
defaultTextStyle
.
copyWith
(
lineSpacing:
5.0
),
bulletStyle:
defaultTextStyle
.
copyWith
(
lineSpacing:
5.0
),
paragraphStyle:
defaultTextStyle
.
copyWith
(
lineSpacing:
5
),
bulletStyle:
defaultTextStyle
.
copyWith
(
lineSpacing:
5
),
header0:
defaultTextStyleBold
.
copyWith
(
fontSize:
fontSize
*
2.0
),
header1:
defaultTextStyleBold
.
copyWith
(
fontSize:
fontSize
*
1.5
),
header2:
defaultTextStyleBold
.
copyWith
(
fontSize:
fontSize
*
1.4
),
...
...
pdf/pubspec.yaml
View file @
ec2467e
...
...
@@ -2,10 +2,12 @@ name: pdf
author
:
David PHAM-VAN <dev.nfet.net@gmail.com>
description
:
A pdf producer for Dart. It can create pdf files for both web or flutter.
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.3
environment
:
sdk
:
"
>=
1.8
.0
<3.0.0"
sdk
:
"
>=
2.1
.0
<3.0.0"
dependencies
:
meta
:
"
^1.1.5"
...
...
pdf/test/annotations.dart
View file @
ec2467e
...
...
@@ -23,18 +23,17 @@ void main() {
test
(
'Pdf'
,
()
{
final
PdfDocument
pdf
=
PdfDocument
();
final
PdfPage
page
=
PdfPage
(
pdf
,
pageFormat:
const
PdfPageFormat
(
500
.0
,
300.
0
));
PdfPage
(
pdf
,
pageFormat:
const
PdfPageFormat
(
500
,
30
0
));
final
PdfPage
page1
=
PdfPage
(
pdf
,
pageFormat:
const
PdfPageFormat
(
500
.0
,
300.
0
));
PdfPage
(
pdf
,
pageFormat:
const
PdfPageFormat
(
500
,
30
0
));
final
PdfGraphics
g
=
page
.
getGraphics
();
PdfAnnot
.
text
(
page
,
content:
'Hello'
,
rect:
const
PdfRect
(
100
.0
,
100.0
,
50.0
,
50.
0
));
content:
'Hello'
,
rect:
const
PdfRect
(
100
,
100
,
50
,
5
0
));
PdfAnnot
.
link
(
page
,
dest:
page1
,
srcRect:
const
PdfRect
(
100.0
,
150.0
,
50.0
,
50.0
));
g
.
drawRect
(
100.0
,
150.0
,
50.0
,
50.0
);
PdfAnnot
.
link
(
page
,
dest:
page1
,
srcRect:
const
PdfRect
(
100
,
150
,
50
,
50
));
g
.
drawRect
(
100
,
150
,
50
,
50
);
g
.
strokePath
();
final
File
file
=
File
(
'annotations.pdf'
);
...
...
pdf/test/complex_test.dart
View file @
ec2467e
...
...
@@ -34,16 +34,16 @@ void main() {
title:
'My Title'
,
subject:
'My Subject'
);
final
PdfPage
page
=
PdfPage
(
pdf
,
pageFormat:
const
PdfPageFormat
(
500
.0
,
300.
0
));
PdfPage
(
pdf
,
pageFormat:
const
PdfPageFormat
(
500
,
30
0
));
final
PdfGraphics
g
=
page
.
getGraphics
();
g
.
saveContext
();
Matrix4
tm
=
Matrix4
.
identity
();
tm
.
translate
(
10.0
,
290.0
);
tm
.
scale
(
1.0
,
-
1.0
);
tm
.
translate
(
10.0
,
290
);
tm
.
scale
(
1.0
,
-
1
);
g
.
setTransform
(
tm
);
g
.
setColor
(
const
PdfColor
(
0
.0
,
0.0
,
0.
0
));
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
);
...
...
@@ -52,10 +52,10 @@ void main() {
g
.
saveContext
();
tm
=
Matrix4
.
identity
();
tm
.
translate
(
200.0
,
290
.0
);
tm
.
translate
(
200.0
,
290
);
tm
.
scale
(.
1
,
-.
1
);
g
.
setTransform
(
tm
);
g
.
setColor
(
const
PdfColor
(
0
.0
,
0.0
,
0.
0
));
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
.
restoreContext
();
...
...
@@ -66,32 +66,32 @@ void main() {
final
PdfTtfFont
font2
=
PdfTtfFont
(
pdf
,
data
.
buffer
.
asByteData
());
const
String
s
=
'Hello World!'
;
final
PdfFontMetrics
r
=
font2
.
stringMetrics
(
s
);
const
double
FS
=
20.0
;
g
.
setColor
(
const
PdfColor
(
0.0
,
1.0
,
1.0
));
const
double
FS
=
20
;
g
.
setColor
(
const
PdfColor
(
0
,
1
,
1
));
g
.
drawRect
(
50.0
+
r
.
left
*
FS
,
30.0
+
r
.
top
*
FS
,
r
.
width
*
FS
,
r
.
height
*
FS
);
g
.
fillPath
();
g
.
setColor
(
const
PdfColor
(
0.3
,
0.3
,
0.3
));
g
.
drawString
(
font2
,
FS
,
s
,
50
.0
,
30.
0
);
g
.
drawString
(
font2
,
FS
,
s
,
50
,
3
0
);
g
.
setColor
(
const
PdfColor
(
1.0
,
0.0
,
0.0
));
g
.
drawString
(
font2
,
20.0
,
'Hé (Olà)'
,
50.0
,
10.0
);
g
.
drawLine
(
30.0
,
30.0
,
200.0
,
200.0
);
g
.
setColor
(
const
PdfColor
(
1
,
0
,
0
));
g
.
drawString
(
font2
,
20
,
'Hé (Olà)'
,
50
,
10
);
g
.
drawLine
(
30
,
30
,
200
,
200
);
g
.
strokePath
();
g
.
setColor
(
const
PdfColor
(
1.0
,
0.0
,
0.0
));
g
.
drawRect
(
300.0
,
150.0
,
50.0
,
50.0
);
g
.
setColor
(
const
PdfColor
(
1
,
0
,
0
));
g
.
drawRect
(
300
,
150
,
50
,
50
);
g
.
fillPath
();
g
.
setColor
(
const
PdfColor
(
0
.0
,
0.5
,
0.
0
));
g
.
setColor
(
const
PdfColor
(
0
,
0.5
,
0
));
final
PdfImage
image
=
PdfImage
(
pdf
,
image:
img
.
buffer
.
asUint8List
(),
width:
10
,
height:
10
);
for
(
double
i
=
10
.0
;
i
<
90.0
;
i
+=
5.0
)
{
for
(
double
i
=
10
;
i
<
90.0
;
i
+=
5.0
)
{
g
.
saveContext
();
final
Matrix4
tm
=
Matrix4
.
identity
();
tm
.
rotateZ
(
i
*
pi
/
360.0
);
tm
.
translate
(
300.0
,
-
100
.0
);
tm
.
translate
(
300.0
,
-
100
);
g
.
setTransform
(
tm
);
g
.
drawString
(
font1
,
12.0
,
'Hello
$i
'
,
20.0
,
100.0
);
g
.
drawImage
(
image
,
100.0
,
100.0
);
g
.
drawString
(
font1
,
12
,
'Hello
$i
'
,
20
,
100
);
g
.
drawImage
(
image
,
100
,
100
);
g
.
restoreContext
();
}
...
...
pdf/test/jpeg_test.dart
View file @
ec2467e
...
...
@@ -44,7 +44,7 @@ void main() {
alpha:
false
);
final
PdfGraphics
g
=
page
.
getGraphics
();
g
.
drawImage
(
image
,
30
.0
,
page
.
pageFormat
.
height
-
507.0
);
g
.
drawImage
(
image
,
30
,
page
.
pageFormat
.
height
-
507.0
);
final
File
file
=
File
(
'jpeg.pdf'
);
file
.
writeAsBytesSync
(
pdf
.
save
());
...
...
pdf/test/metrics.dart
View file @
ec2467e
...
...
@@ -30,7 +30,7 @@ void printMetrics(
final
double
fontSize
=
min
(
fontSizeW
,
fontSizeH
);
final
PdfFontMetrics
metrics
=
metricsUnscales
*
fontSize
;
const
double
deb
=
20
.0
;
const
double
deb
=
20
;
final
double
x
=
(
size
.
x
-
metrics
.
maxWidth
)
/
2.0
;
final
double
y
=
(
size
.
y
-
metrics
.
maxHeight
)
/
2.0
-
metrics
.
descent
;
...
...
@@ -70,7 +70,7 @@ void main() {
in
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz&%!?0123456789'
.
codeUnits
)
{
pdf
.
addPage
(
Page
(
pageFormat:
const
PdfPageFormat
(
500
.0
,
500.
0
,
marginAll:
20
),
pageFormat:
const
PdfPageFormat
(
500
,
50
0
,
marginAll:
20
),
build:
(
Context
context
)
{
return
ConstrainedBox
(
constraints:
const
BoxConstraints
.
expand
(),
...
...
pdf/test/minimal_test.dart
View file @
ec2467e
...
...
@@ -25,8 +25,8 @@ void main() {
final
PdfPage
page
=
PdfPage
(
pdf
,
pageFormat:
PdfPageFormat
.
a4
);
final
PdfGraphics
g
=
page
.
getGraphics
();
g
.
drawLine
(
30.0
,
page
.
pageFormat
.
height
-
30.0
,
200.0
,
page
.
pageFormat
.
height
-
200.0
);
g
.
drawLine
(
30
,
page
.
pageFormat
.
height
-
30.0
,
200
,
page
.
pageFormat
.
height
-
200.0
);
g
.
strokePath
();
final
File
file
=
File
(
'minimal.pdf'
);
...
...
pdf/test/ttf_test.dart
View file @
ec2467e
...
...
@@ -22,12 +22,12 @@ import 'package:test/test.dart';
void
printText
(
PdfGraphics
canvas
,
String
text
,
PdfFont
font
,
double
top
)
{
text
=
text
+
font
.
fontName
;
const
double
fontSize
=
20
.0
;
const
double
fontSize
=
20
;
final
PdfFontMetrics
metrics
=
font
.
stringMetrics
(
text
)
*
fontSize
;
const
double
deb
=
5
.0
;
const
double
deb
=
5
;
const
double
x
=
50
.0
;
const
double
x
=
50
;
final
double
y
=
canvas
.
page
.
pageFormat
.
height
-
top
;
canvas
...
...
@@ -61,7 +61,7 @@ void main() {
test
(
'Pdf'
,
()
{
final
PdfDocument
pdf
=
PdfDocument
();
final
PdfPage
page
=
PdfPage
(
pdf
,
pageFormat:
const
PdfPageFormat
(
500
.0
,
300.
0
));
PdfPage
(
pdf
,
pageFormat:
const
PdfPageFormat
(
500
,
30
0
));
final
PdfGraphics
g
=
page
.
getGraphics
();
int
top
=
0
;
...
...
pdf/test/type1_test.dart
View file @
ec2467e
...
...
@@ -21,12 +21,12 @@ import 'package:test/test.dart';
void
printText
(
PdfGraphics
canvas
,
String
text
,
PdfFont
font
,
double
top
)
{
text
=
text
+
font
.
fontName
;
const
double
fontSize
=
20
.0
;
const
double
fontSize
=
20
;
final
PdfFontMetrics
metrics
=
font
.
stringMetrics
(
text
)
*
fontSize
;
const
double
deb
=
5
.0
;
const
double
deb
=
5
;
const
double
x
=
50
.0
;
const
double
x
=
50
;
final
double
y
=
canvas
.
page
.
pageFormat
.
height
-
top
;
canvas
...
...
@@ -52,7 +52,7 @@ void main() {
test
(
'Pdf'
,
()
{
final
PdfDocument
pdf
=
PdfDocument
();
final
PdfPage
page
=
PdfPage
(
pdf
,
pageFormat:
const
PdfPageFormat
(
500
.0
,
430.
0
));
PdfPage
(
pdf
,
pageFormat:
const
PdfPageFormat
(
500
,
43
0
));
final
PdfGraphics
g
=
page
.
getGraphics
();
int
top
=
0
;
...
...
pdf/test/widget_test.dart
View file @
ec2467e
...
...
@@ -35,8 +35,8 @@ void main() {
PdfImage
(
pdf
.
document
,
image:
imData
,
width:
16
,
height:
20
);
pdf
.
addPage
(
Page
(
pageFormat:
const
PdfPageFormat
(
400.0
,
400.0
),
margin:
const
EdgeInsets
.
all
(
10.0
),
pageFormat:
const
PdfPageFormat
(
400
,
400
),
margin:
const
EdgeInsets
.
all
(
10
),
build:
(
Context
context
)
=>
Column
(
children:
<
Widget
>[
Container
(
padding:
const
EdgeInsets
.
all
(
5
),
...
...
@@ -48,11 +48,11 @@ void main() {
bottom:
true
,
left:
true
,
right:
true
,
width:
2
.0
)),
width:
2
)),
child:
Text
(
'Hello World'
,
textScaleFactor:
2
.0
,
textAlign:
TextAlign
.
center
)),
textScaleFactor:
2
,
textAlign:
TextAlign
.
center
)),
Align
(
alignment:
Alignment
.
topLeft
,
child:
Text
(
'Left align'
)),
Padding
(
padding:
const
EdgeInsets
.
all
(
5
.0
)),
Padding
(
padding:
const
EdgeInsets
.
all
(
5
)),
Row
(
mainAxisAlignment:
MainAxisAlignment
.
spaceEvenly
,
children:
<
Widget
>[
...
...
@@ -75,31 +75,31 @@ void main() {
Container
(
padding:
const
EdgeInsets
.
only
(
top:
5
),
decoration:
const
BoxDecoration
(
border:
BoxBorder
(
top:
true
,
width:
1
.0
)),
border:
BoxBorder
(
top:
true
,
width:
1
)),
child:
Text
(
"That's all Folks!"
,
textAlign:
TextAlign
.
center
,
style:
Theme
.
of
(
context
)
.
defaultTextStyle
.
copyWith
(
font:
Font
.
timesBoldItalic
()),
textScaleFactor:
3
.0
)),
textScaleFactor:
3
)),
])));
pdf
.
addPage
(
Page
(
pageFormat:
const
PdfPageFormat
(
400.0
,
400.0
),
margin:
const
EdgeInsets
.
all
(
10.0
),
pageFormat:
const
PdfPageFormat
(
400
,
400
),
margin:
const
EdgeInsets
.
all
(
10
),
build:
(
Context
context
)
=>
Center
(
child:
GridView
(
crossAxisCount:
3
,
direction:
Axis
.
vertical
,
crossAxisSpacing:
10.0
,
mainAxisSpacing:
10.0
,
padding:
const
EdgeInsets
.
all
(
10.0
),
crossAxisSpacing:
10
,
mainAxisSpacing:
10
,
padding:
const
EdgeInsets
.
all
(
10
),
children:
List
<
Widget
>.
generate
(
9
,
(
int
n
)
=>
FittedBox
(
child:
Text
(
'
${n + 1}
'
)))))));
pdf
.
addPage
(
MultiPage
(
pageFormat:
const
PdfPageFormat
(
400.0
,
200.0
),
margin:
const
EdgeInsets
.
all
(
10.0
),
pageFormat:
const
PdfPageFormat
(
400
,
200
),
margin:
const
EdgeInsets
.
all
(
10
),
build:
(
Context
context
)
=>
<
Widget
>[
Table
.
fromTextArray
(
context:
context
,
data:
<
List
<
String
>>[
<
String
>[
'Company'
,
'Contact'
,
'Country'
],
...
...
@@ -136,8 +136,8 @@ void main() {
]));
pdf
.
addPage
(
Page
(
pageFormat:
const
PdfPageFormat
(
400.0
,
200.0
),
margin:
const
EdgeInsets
.
all
(
10.0
),
pageFormat:
const
PdfPageFormat
(
400
,
200
),
margin:
const
EdgeInsets
.
all
(
10
),
build:
(
Context
context
)
=>
Stack
(
overflow:
Overflow
.
visible
,
// fit: StackFit.expand,
// alignment: Alignment.bottomRight,
...
...
printing/CHANGELOG.md
View file @
ec2467e
# 1.3.5
*
Restore compatibility with Flutter 1.0.0
*
Update code to Dart 2.1.0
# 1.3.4
*
Fix iOS build with Swift
...
...
printing/example/lib/document.dart
View file @
ec2467e
...
...
@@ -131,7 +131,7 @@ Future<PdfDocument> generateDocument(PdfPageFormat format) async {
crossAxisAlignment:
CrossAxisAlignment
.
start
,
children:
<
Widget
>[
Text
(
'Parnella Charlesbois'
,
textScaleFactor:
2
.0
,
textScaleFactor:
2
,
style:
Theme
.
of
(
context
).
defaultTextStyleBold
),
Padding
(
padding:
const
EdgeInsets
.
only
(
top:
10
)),
Text
(
'Electrotyper'
,
...
...
printing/example/pubspec.yaml
View file @
ec2467e
...
...
@@ -4,7 +4,7 @@ description: Pdf Printing Example
version
:
1.0.0+1
environment
:
sdk
:
"
>=2.
0
.0
<3.0.0"
sdk
:
"
>=2.
1
.0
<3.0.0"
dependencies
:
flutter
:
...
...
@@ -17,5 +17,11 @@ dev_dependencies:
flutter_test
:
sdk
:
flutter
dependency_overrides
:
printing
:
path
:
..
pdf
:
path
:
../../pdf
flutter
:
uses-material-design
:
true
...
...
printing/lib/src/printing.dart
View file @
ec2467e
...
...
@@ -75,7 +75,7 @@ mixin Printing {
bytes
=
document
.
save
();
}
bounds
??=
Rect
.
fromCircle
(
center:
Offset
.
zero
,
radius:
10
.0
);
bounds
??=
Rect
.
fromCircle
(
center:
Offset
.
zero
,
radius:
10
);
final
Map
<
String
,
dynamic
>
params
=
<
String
,
dynamic
>{
'doc'
:
Uint8List
.
fromList
(
bytes
),
...
...
printing/pubspec.yaml
View file @
ec2467e
...
...
@@ -2,10 +2,13 @@ name: printing
author
:
David PHAM-VAN <dev.nfet.net@gmail.com>
description
:
Plugin that allows Flutter apps to generate and print documents to android or ios compatible printers
homepage
:
https://github.com/DavBfr/dart_pdf/tree/master/printing
repository
:
https://github.com/DavBfr/dart_pdf
issue_tracker
:
https://github.com/DavBfr/dart_pdf/issues
version
:
1.3.5
environment
:
sdk
:
"
>=1.19.0
<3.0.0"
sdk
:
"
>=2.1.0
<3.0.0"
flutter
:
"
^1.2.0"
dependencies
:
flutter
:
...
...
@@ -16,6 +19,10 @@ dev_dependencies:
flutter_test
:
sdk
:
flutter
dependency_overrides
:
pdf
:
path
:
../pdf
flutter
:
plugin
:
androidPackage
:
net.nfet.flutter.printing
...
...
Please
register
or
login
to post a comment