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-28 05:03:45 -0500
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
89e48f70eba56d98624a7d48d2f0e46d9b0c2b1b
89e48f70
1 parent
18ebd364
Improve Build Context
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
32 additions
and
8 deletions
pdf/lib/widgets/document.dart
pdf/lib/widgets/font.dart
pdf/lib/widgets/widget.dart
pdf/lib/widgets/document.dart
View file @
89e48f7
...
...
@@ -104,8 +104,11 @@ class Page extends BasePage {
final
Theme
calculatedTheme
=
theme
??
document
.
theme
??
Theme
.
base
();
final
Map
<
Type
,
Inherited
>
inherited
=
<
Type
,
Inherited
>{};
inherited
[
calculatedTheme
.
runtimeType
]
=
calculatedTheme
;
final
Context
context
=
Context
(
page:
pdfPage
,
canvas:
canvas
,
inherited:
inherited
);
final
Context
context
=
Context
(
document:
document
.
document
,
page:
pdfPage
,
canvas:
canvas
,
inherited:
inherited
);
if
(
_build
!=
null
)
{
final
Widget
child
=
_build
(
context
);
layout
(
child
,
context
,
constraints
);
...
...
@@ -187,7 +190,9 @@ class MultiPage extends Page {
double
offsetEnd
;
double
offsetStart
;
int
index
=
0
;
final
List
<
Widget
>
children
=
_buildList
(
Context
(
inherited:
inherited
));
final
Context
baseContext
=
Context
(
document:
document
.
document
,
inherited:
inherited
);
final
List
<
Widget
>
children
=
_buildList
(
baseContext
);
WidgetContext
widgetContext
;
while
(
index
<
children
.
length
)
{
...
...
@@ -197,7 +202,7 @@ class MultiPage extends Page {
final
PdfPage
pdfPage
=
PdfPage
(
document
.
document
,
pageFormat:
pageFormat
);
final
PdfGraphics
canvas
=
pdfPage
.
getGraphics
();
context
=
Context
(
page:
pdfPage
,
canvas:
canvas
,
inherited:
inherited
);
context
=
baseContext
.
copyWith
(
page:
pdfPage
,
canvas:
canvas
);
assert
(()
{
if
(
Document
.
debug
)
{
debugPaint
(
context
);
...
...
pdf/lib/widgets/font.dart
View file @
89e48f7
...
...
@@ -125,7 +125,7 @@ class Font {
PdfFont
getFont
(
Context
context
)
{
if
(
_pdfFont
==
null
)
{
final
PdfDocument
pdfDocument
=
context
.
page
.
pdfD
ocument
;
final
PdfDocument
pdfDocument
=
context
.
d
ocument
;
_pdfFont
=
buildFont
(
pdfDocument
);
}
...
...
pdf/lib/widgets/widget.dart
View file @
89e48f7
...
...
@@ -18,7 +18,13 @@ part of widget;
@immutable
class
Context
{
const
Context
({
this
.
page
,
this
.
canvas
,
this
.
inherited
});
const
Context
({
@required
this
.
document
,
this
.
page
,
this
.
canvas
,
@required
this
.
inherited
,
})
:
assert
(
document
!=
null
),
assert
(
inherited
!=
null
);
final
PdfPage
page
;
...
...
@@ -26,11 +32,19 @@ class Context {
final
Map
<
Type
,
Inherited
>
inherited
;
int
get
pageNumber
=>
page
.
pdfDocument
.
pdfPageList
.
pages
.
indexOf
(
page
)
+
1
;
final
PdfDocument
document
;
int
get
pageNumber
=>
document
.
pdfPageList
.
pages
.
indexOf
(
page
)
+
1
;
int
get
pagesCount
=>
document
.
pdfPageList
.
pages
.
length
;
Context
copyWith
(
{
PdfPage
page
,
PdfGraphics
canvas
,
Map
<
Type
,
Inherited
>
inherited
})
{
{
PdfPage
page
,
PdfGraphics
canvas
,
Matrix4
ctm
,
Map
<
Type
,
Inherited
>
inherited
})
{
return
Context
(
document:
document
,
page:
page
??
this
.
page
,
canvas:
canvas
??
this
.
canvas
,
inherited:
inherited
??
this
.
inherited
);
...
...
@@ -48,12 +62,17 @@ class Inherited {}
abstract
class
Widget
{
Widget
();
/// The bounding box of this widget, calculated at layout time
PdfRect
box
;
/// First widget pass to calculate the children layout and
/// bounding [box]
@protected
void
layout
(
Context
context
,
BoxConstraints
constraints
,
{
bool
parentUsesSize
=
false
});
/// Draw itself and its children, according to the calculated
/// [box.offset]
@protected
void
paint
(
Context
context
)
{
assert
(()
{
...
...
Please
register
or
login
to post a comment