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
2020-12-30 10:06:18 -0400
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
cd485026dbed5ae1cbf074a1911df389221e7528
cd485026
1 parent
8a7a7d91
Add Widget.draw() to paint any widget on a canvas
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
64 additions
and
0 deletions
pdf/CHANGELOG.md
pdf/lib/src/widgets/widget.dart
pdf/CHANGELOG.md
View file @
cd48502
...
...
@@ -10,6 +10,7 @@
-
Add document loading
-
Remove deprecated methods
-
Document.save() now returns a Future
-
Add Widget.draw() to paint any widget on a canvas
## 1.13.0
...
...
pdf/lib/src/widgets/widget.dart
View file @
cd48502
...
...
@@ -24,6 +24,7 @@ import 'package:vector_math/vector_math_64.dart';
import
'document.dart'
;
import
'geometry.dart'
;
import
'page.dart'
;
import
'theme.dart'
;
@immutable
class
Context
{
...
...
@@ -113,6 +114,68 @@ abstract class Widget {
/// The bounding box of this widget, calculated at layout time
PdfRect
box
;
/// Draw a widget to a page canvas.
static
void
draw
(
Widget
widget
,
{
PdfPage
page
,
PdfGraphics
canvas
,
BoxConstraints
constraints
,
@required
PdfPoint
offset
,
Alignment
alignment
,
Context
context
,
})
{
assert
(
offset
!=
null
);
context
??=
Context
(
document:
page
?.
pdfDocument
,
page:
page
,
canvas:
canvas
,
).
inheritFromAll
(<
Inherited
>[
ThemeData
.
base
(),
]);
widget
.
layout
(
context
,
constraints
??
const
BoxConstraints
(),
);
assert
(
widget
.
box
!=
null
);
if
(
alignment
!=
null
)
{
final
d
=
alignment
.
withinRect
(
widget
.
box
);
offset
=
PdfPoint
(
offset
.
x
-
d
.
x
,
offset
.
y
-
d
.
y
);
}
widget
.
box
=
PdfRect
.
fromPoints
(
offset
,
widget
.
box
.
size
);
widget
.
paint
(
context
);
}
/// Measure the size of a widget to a page canvas.
static
PdfPoint
measure
(
Widget
widget
,
{
PdfPage
page
,
PdfGraphics
canvas
,
BoxConstraints
constraints
,
Context
context
,
})
{
context
??=
Context
(
document:
page
?.
pdfDocument
,
page:
page
,
canvas:
canvas
,
).
inheritFromAll
(<
Inherited
>[
ThemeData
.
base
(),
]);
widget
.
layout
(
context
,
constraints
??
const
BoxConstraints
(),
);
assert
(
widget
.
box
!=
null
);
return
widget
.
box
.
size
;
}
/// First widget pass to calculate the children layout and
/// bounding [box]
void
layout
(
Context
context
,
BoxConstraints
constraints
,
...
...
Please
register
or
login
to post a comment