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-12-20 16:37:13 -0500
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
a5456817d3c6d2dfa045080775a32f3b7546bed4
a5456817
1 parent
7798ae99
Add Roll Paper support
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
153 additions
and
34 deletions
pdf/CHANGELOG.md
pdf/lib/src/page.dart
pdf/lib/src/page_format.dart
pdf/lib/src/stream.dart
pdf/lib/widgets/basic.dart
pdf/lib/widgets/multi_page.dart
pdf/lib/widgets/page.dart
pdf/pubspec.yaml
pdf/test/all_tests.dart
pdf/test/roll_paper_test.dart
test/golden/roll-paper.pdf
pdf/CHANGELOG.md
View file @
a545681
# Changelog
## 1.3.27
-
Add Roll Paper support
## 1.3.26
-
Update Analysis options
...
...
pdf/lib/src/page.dart
View file @
a545681
...
...
@@ -32,7 +32,7 @@ class PdfPage extends PdfObject {
}
/// This is this page format, ie the size of the page, margins, and rotation
final
PdfPageFormat
pageFormat
;
PdfPageFormat
pageFormat
;
/// This holds the contents of the page.
List
<
PdfObjectStream
>
contents
=
<
PdfObjectStream
>[];
...
...
pdf/lib/src/page_format.dart
View file @
a545681
...
...
@@ -23,7 +23,9 @@ class PdfPageFormat {
double
marginLeft
=
0.0
,
double
marginRight
=
0.0
,
double
marginAll
})
:
marginTop
=
marginAll
??
marginTop
,
:
assert
(
width
>
0
),
assert
(
height
>
0
),
marginTop
=
marginAll
??
marginTop
,
marginBottom
=
marginAll
??
marginBottom
,
marginLeft
=
marginAll
??
marginLeft
,
marginRight
=
marginAll
??
marginRight
;
...
...
@@ -39,6 +41,14 @@ class PdfPageFormat {
static
const
PdfPageFormat
legal
=
PdfPageFormat
(
8.5
*
inch
,
14.0
*
inch
,
marginAll:
inch
);
static
const
PdfPageFormat
roll57
=
PdfPageFormat
(
57
*
mm
,
double
.
infinity
,
marginAll:
5
*
mm
);
static
const
PdfPageFormat
roll80
=
PdfPageFormat
(
80
*
mm
,
double
.
infinity
,
marginAll:
5
*
mm
);
static
const
PdfPageFormat
undefined
=
PdfPageFormat
(
double
.
infinity
,
double
.
infinity
);
static
const
PdfPageFormat
standard
=
a4
;
static
const
double
point
=
1.0
;
...
...
pdf/lib/src/stream.dart
View file @
a545681
...
...
@@ -50,11 +50,15 @@ class PdfStream {
}
void
putNum
(
double
d
)
{
assert
(
d
!=
double
.
infinity
);
putString
(
d
.
toStringAsFixed
(
precision
));
}
void
putNumList
(
List
<
double
>
d
)
{
putString
(
d
.
map
((
double
v
)
=>
v
.
toStringAsFixed
(
precision
)).
join
(
' '
));
putString
(
d
.
map
((
double
v
)
{
assert
(
v
!=
double
.
infinity
);
return
v
.
toStringAsFixed
(
precision
);
}).
join
(
' '
));
}
void
putIntList
(
List
<
int
>
d
)
{
...
...
pdf/lib/widgets/basic.dart
View file @
a545681
...
...
@@ -679,6 +679,9 @@ class FullPage extends SingleChildWidget {
final
bool
ignoreMargins
;
BoxConstraints
_getConstraints
(
Context
context
)
{
assert
(
context
.
page
.
pageFormat
.
width
!=
double
.
infinity
);
assert
(
context
.
page
.
pageFormat
.
height
!=
double
.
infinity
);
return
ignoreMargins
?
BoxConstraints
.
tightFor
(
width:
context
.
page
.
pageFormat
.
width
,
...
...
pdf/lib/widgets/multi_page.dart
View file @
a545681
...
...
@@ -111,6 +111,9 @@ class MultiPage extends Page {
return
;
}
assert
(
pageFormat
.
width
>
0
&&
pageFormat
.
width
<
double
.
infinity
);
assert
(
pageFormat
.
height
>
0
&&
pageFormat
.
height
<
double
.
infinity
);
final
EdgeInsets
_margin
=
margin
;
final
bool
_mustRotate
=
mustRotate
;
final
double
pageHeight
=
...
...
pdf/lib/widgets/page.dart
View file @
a545681
...
...
@@ -52,7 +52,7 @@ class Page {
final
PageTheme
pageTheme
;
PdfPageFormat
get
pageFormat
=>
pageTheme
.
pageFormat
;
PdfPageFormat
get
pageFormat
=>
_pdfPage
?.
pageFormat
??
pageTheme
.
pageFormat
;
PageOrientation
get
orientation
=>
pageTheme
.
orientation
;
...
...
@@ -92,7 +92,7 @@ class Page {
void
postProcess
(
Document
document
)
{
final
PdfGraphics
canvas
=
_pdfPage
.
getGraphics
();
final
EdgeInsets
_margin
=
margin
;
final
BoxConstraints
constraints
=
mustRotate
BoxConstraints
constraints
=
mustRotate
?
BoxConstraints
(
maxWidth:
pageFormat
.
height
-
_margin
.
vertical
,
maxHeight:
pageFormat
.
width
-
_margin
.
horizontal
)
...
...
@@ -107,6 +107,43 @@ class Page {
canvas:
canvas
,
).
inheritFrom
(
calculatedTheme
);
Widget
background
;
Widget
content
;
Widget
foreground
;
if
(
_build
!=
null
)
{
content
=
_build
(
context
);
if
(
content
!=
null
)
{
final
PdfPoint
size
=
layout
(
content
,
context
,
constraints
);
if
(
_pdfPage
.
pageFormat
.
height
==
double
.
infinity
)
{
_pdfPage
.
pageFormat
=
_pdfPage
.
pageFormat
.
copyWith
(
width:
size
.
x
,
height:
size
.
y
);
constraints
=
mustRotate
?
BoxConstraints
(
maxWidth:
_pdfPage
.
pageFormat
.
height
-
_margin
.
vertical
,
maxHeight:
_pdfPage
.
pageFormat
.
width
-
_margin
.
horizontal
)
:
BoxConstraints
(
maxWidth:
_pdfPage
.
pageFormat
.
width
-
_margin
.
horizontal
,
maxHeight:
_pdfPage
.
pageFormat
.
height
-
_margin
.
vertical
);
}
}
}
if
(
pageTheme
.
buildBackground
!=
null
)
{
background
=
pageTheme
.
buildBackground
(
context
);
if
(
background
!=
null
)
{
layout
(
background
,
context
,
constraints
);
}
}
if
(
pageTheme
.
buildForeground
!=
null
)
{
foreground
=
pageTheme
.
buildForeground
(
context
);
if
(
foreground
!=
null
)
{
layout
(
foreground
,
context
,
constraints
);
}
}
assert
(()
{
if
(
Document
.
debug
)
{
debugPaint
(
context
);
...
...
@@ -114,44 +151,42 @@ class Page {
return
true
;
}());
if
(
pageTheme
.
buildBackground
!=
null
)
{
final
Widget
child
=
pageTheme
.
buildBackground
(
context
);
if
(
child
!=
null
)
{
layout
(
child
,
context
,
constraints
);
paint
(
child
,
context
);
}
if
(
background
!=
null
)
{
paint
(
background
,
context
);
}
if
(
_build
!=
null
)
{
final
Widget
child
=
_build
(
context
);
if
(
child
!=
null
)
{
layout
(
child
,
context
,
constraints
);
paint
(
child
,
context
);
}
if
(
content
!=
null
)
{
paint
(
content
,
context
);
}
if
(
pageTheme
.
buildForeground
!=
null
)
{
final
Widget
child
=
pageTheme
.
buildForeground
(
context
);
if
(
child
!=
null
)
{
layout
(
child
,
context
,
constraints
);
paint
(
child
,
context
);
}
if
(
foreground
!=
null
)
{
paint
(
foreground
,
context
);
}
}
@protected
void
layout
(
Widget
child
,
Context
context
,
BoxConstraints
constraints
,
PdfPoint
layout
(
Widget
child
,
Context
context
,
BoxConstraints
constraints
,
{
bool
parentUsesSize
=
false
})
{
if
(
child
!=
null
)
{
final
EdgeInsets
_margin
=
margin
;
child
.
layout
(
context
,
constraints
,
parentUsesSize:
parentUsesSize
);
assert
(
child
.
box
!=
null
);
child
.
box
=
PdfRect
(
_margin
.
left
,
pageFormat
.
height
-
child
.
box
.
height
-
_margin
.
top
,
child
.
box
.
width
,
child
.
box
.
height
);
if
(
child
==
null
)
{
return
PdfPoint
(
pageFormat
.
width
,
pageFormat
.
height
);
}
final
EdgeInsets
_margin
=
margin
;
child
.
layout
(
context
,
constraints
,
parentUsesSize:
parentUsesSize
);
assert
(
child
.
box
!=
null
);
final
double
width
=
pageFormat
.
width
==
double
.
infinity
?
child
.
box
.
width
+
_margin
.
left
+
_margin
.
right
:
pageFormat
.
width
;
final
double
height
=
pageFormat
.
height
==
double
.
infinity
?
child
.
box
.
height
+
_margin
.
top
+
_margin
.
bottom
:
pageFormat
.
height
;
child
.
box
=
PdfRect
(
_margin
.
left
,
height
-
child
.
box
.
height
-
_margin
.
top
,
child
.
box
.
width
,
child
.
box
.
height
);
return
PdfPoint
(
width
,
height
);
}
@protected
...
...
pdf/pubspec.yaml
View file @
a545681
...
...
@@ -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.2
6
version
:
1.3.2
7
environment
:
sdk
:
"
>=2.3.0
<3.0.0"
...
...
pdf/test/all_tests.dart
View file @
a545681
...
...
@@ -25,6 +25,7 @@ import 'jpeg_test.dart' as jpeg;
import
'metrics_test.dart'
as
metrics
;
import
'minimal_test.dart'
as
minimal
;
import
'orientation_test.dart'
as
orientation
;
import
'roll_paper_test.dart'
as
roll
;
import
'ttf_test.dart'
as
ttf
;
import
'type1_test.dart'
as
type1
;
import
'widget_basic_test.dart'
as
widget_basic
;
...
...
@@ -49,6 +50,7 @@ void main() {
metrics
.
main
();
minimal
.
main
();
orientation
.
main
();
roll
.
main
();
ttf
.
main
();
type1
.
main
();
widget_basic
.
main
();
...
...
pdf/test/roll_paper_test.dart
0 → 100644
View file @
a545681
/*
* Copyright (C) 2017, David PHAM-VAN <dev.nfet.net@gmail.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// ignore_for_file: omit_local_variable_types
import
'dart:io'
;
import
'package:pdf/pdf.dart'
;
import
'package:pdf/widgets.dart'
;
import
'package:test/test.dart'
;
Document
pdf
;
void
main
(
)
{
setUpAll
(()
{
Document
.
debug
=
true
;
pdf
=
Document
();
});
test
(
'Pdf Roll Paper'
,
()
async
{
pdf
.
addPage
(
Page
(
pageFormat:
PdfPageFormat
.
roll80
,
build:
(
Context
context
)
=>
Padding
(
padding:
const
EdgeInsets
.
all
(
30
),
child:
Center
(
child:
Text
(
'Hello World!'
),
),
),
));
});
test
(
'Pdf Automatic Paper'
,
()
async
{
pdf
.
addPage
(
Page
(
pageFormat:
PdfPageFormat
.
undefined
,
build:
(
Context
context
)
=>
Text
(
'Hello World!'
)));
});
tearDownAll
(()
{
final
File
file
=
File
(
'roll-paper.pdf'
);
file
.
writeAsBytesSync
(
pdf
.
save
());
});
}
...
...
test/golden/roll-paper.pdf
0 → 100644
View file @
a545681
No preview for this file type
Please
register
or
login
to post a comment