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
2022-08-26 11:44:12 -0300
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
016cba4849fedebeea6f60caad35b6dc53570bed
016cba48
1 parent
ae6e6bed
Improve Multi-Page layout
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
55 additions
and
36 deletions
pdf/CHANGELOG.md
pdf/lib/src/widgets/grid_view.dart
pdf/lib/src/widgets/multi_page.dart
pdf/lib/src/widgets/partitions.dart
pdf/lib/src/widgets/table.dart
pdf/lib/src/widgets/text.dart
pdf/lib/src/widgets/wrap.dart
pdf/pubspec.yaml
pdf/CHANGELOG.md
View file @
016cba4
# Changelog
## 3.8.4
-
Improve Multi-Page layout
## 3.8.3
-
Fix Arabic TextAlign.justify issues Set default text align based on text direction
[
Milad akarie
]
...
...
pdf/lib/src/widgets/grid_view.dart
View file @
016cba4
...
...
@@ -35,17 +35,13 @@ class _GridViewContext extends WidgetContext {
void
apply
(
_GridViewContext
other
)
{
firstChild
=
other
.
firstChild
;
lastChild
=
other
.
lastChild
;
childCrossAxis
=
other
.
childCrossAxis
;
childMainAxis
=
other
.
childMainAxis
;
childCrossAxis
=
other
.
childCrossAxis
??
childCrossAxis
;
childMainAxis
=
other
.
childMainAxis
??
childMainAxis
;
}
@override
WidgetContext
clone
()
{
return
_GridViewContext
()
..
firstChild
=
firstChild
..
lastChild
=
lastChild
..
childCrossAxis
=
childCrossAxis
..
childMainAxis
=
childMainAxis
;
return
_GridViewContext
()..
apply
(
this
);
}
@override
...
...
pdf/lib/src/widgets/multi_page.dart
View file @
016cba4
...
...
@@ -32,8 +32,11 @@ import 'theme.dart';
import
'widget.dart'
;
abstract
class
WidgetContext
{
/// Called after layout to save the state
WidgetContext
clone
();
/// Called before relayout to restore the saved state and
/// restart the layout in the same conditions
void
apply
(
covariant
WidgetContext
other
);
}
...
...
@@ -46,9 +49,20 @@ mixin SpanningWidget on Widget {
@protected
WidgetContext
saveContext
();
/// Apply the context for next layout
/// Apply the context for next page layout.
/// Called before layout to prepare for next page
@protected
void
restoreContext
(
covariant
WidgetContext
context
);
/// Called after layout to save the state
@protected
WidgetContext
cloneContext
()
=>
saveContext
().
clone
();
/// Called before relayout to restore the saved state and
/// restart the layout in the same conditions
@protected
void
applyContext
(
covariant
WidgetContext
context
)
=>
saveContext
().
apply
(
context
);
}
class
NewPage
extends
Widget
{
...
...
@@ -88,7 +102,7 @@ class _MultiPageInstance {
final
List
<
_MultiPageWidget
>
widgets
=
<
_MultiPageWidget
>[];
}
/// Create a mult-page section, with automatic overflow from one page to another
/// Create a mult
i
-page section, with automatic overflow from one page to another
///
/// ```dart
/// final pdf = Document();
...
...
@@ -101,7 +115,7 @@ class _MultiPageInstance {
/// ```
///
/// An inner widget tree cannot be bigger than a page: A [Widget] cannot be drawn
/// partially on one page and the remaining on another page: It's
insec
able.
/// partially on one page and the remaining on another page: It's
unbreak
able.
///
/// A small set of [Widget] can automatically span over multiple pages, and can
/// be used as a direct child of the build method: [Flex], [Partition], [Table], [Wrap],
...
...
@@ -288,9 +302,13 @@ class MultiPage extends Page {
}
// If we are processing a multi-page widget, we restore its context
if
(
widgetContext
!=
null
&&
child
is
SpanningWidget
)
{
child
.
restoreContext
(
widgetContext
);
widgetContext
=
null
;
WidgetContext
?
savedContext
;
if
(
child
is
SpanningWidget
&&
child
.
canSpan
)
{
if
(
widgetContext
!=
null
)
{
child
.
restoreContext
(
widgetContext
);
widgetContext
=
null
;
}
savedContext
=
child
.
cloneContext
();
}
child
.
layout
(
context
,
constraints
,
parentUsesSize:
false
);
...
...
@@ -307,7 +325,7 @@ class MultiPage extends Page {
continue
;
}
// Else we crash if the widget is too big and cannot be s
plit
ted
// Else we crash if the widget is too big and cannot be s
epara
ted
if
(!
canSpan
)
{
throw
Exception
(
'Widget won
\'
t fit into the page as its height (
${child.box!.height}
) '
...
...
@@ -317,14 +335,19 @@ class MultiPage extends Page {
final
span
=
child
as
SpanningWidget
;
if
(
savedContext
!=
null
)
{
// Restore saved context
span
.
applyContext
(
savedContext
);
}
final
localConstraints
=
constraints
.
copyWith
(
maxHeight:
offsetStart
-
offsetEnd
);
child
.
layout
(
context
,
localConstraints
,
parentUsesSize:
false
);
assert
(
child
.
box
!=
null
);
span
.
layout
(
context
,
localConstraints
,
parentUsesSize:
false
);
assert
(
span
.
box
!=
null
);
widgetContext
=
span
.
saveContext
();
_pages
.
last
.
widgets
.
add
(
_MultiPageWidget
(
child:
child
,
child:
span
,
constraints:
localConstraints
,
widgetContext:
widgetContext
.
clone
(),
),
...
...
@@ -345,9 +368,8 @@ class MultiPage extends Page {
_MultiPageWidget
(
child:
child
,
constraints:
constraints
,
widgetContext:
child
is
SpanningWidget
&&
canSpan
?
child
.
saveContext
().
clone
()
:
null
,
widgetContext:
child
is
SpanningWidget
&&
canSpan
?
child
.
cloneContext
()
:
null
,
),
);
...
...
@@ -394,8 +416,7 @@ class MultiPage extends Page {
lastFlexChild
=
child
;
}
else
{
if
(
child
is
SpanningWidget
&&
child
.
canSpan
)
{
final
context
=
child
.
saveContext
();
context
.
apply
(
widget
.
widgetContext
!);
child
.
applyContext
(
widget
.
widgetContext
!);
}
child
.
layout
(
page
.
context
,
widget
.
constraints
,
parentUsesSize:
false
);
...
...
@@ -522,6 +543,10 @@ class MultiPage extends Page {
x
=
0
;
break
;
}
final
child
=
widget
.
child
;
if
(
child
is
SpanningWidget
&&
child
.
canSpan
)
{
child
.
applyContext
(
widget
.
widgetContext
!);
}
_paintChild
(
page
.
context
,
widget
.
child
,
_margin
.
left
+
x
,
pos
,
pageFormat
.
height
);
pos
-=
betweenSpace
;
...
...
pdf/lib/src/widgets/partitions.dart
View file @
016cba4
...
...
@@ -84,11 +84,9 @@ class _PartitionsContext extends WidgetContext {
final
List
<
WidgetContext
?>
partitionContext
;
@override
void
apply
(
WidgetContext
other
)
{
if
(
other
is
_PartitionsContext
)
{
for
(
var
index
=
0
;
index
<
partitionContext
.
length
;
index
++)
{
partitionContext
[
index
]?.
apply
(
other
.
partitionContext
[
index
]!);
}
void
apply
(
_PartitionsContext
other
)
{
for
(
var
index
=
0
;
index
<
partitionContext
.
length
;
index
++)
{
partitionContext
[
index
]?.
apply
(
other
.
partitionContext
[
index
]!);
}
}
...
...
@@ -220,7 +218,7 @@ class Partitions extends Widget with SpanningWidget {
}
@override
void
restoreContext
(
Widget
Context
context
)
{
void
restoreContext
(
_Partitions
Context
context
)
{
_context
.
apply
(
context
);
var
index
=
0
;
for
(
final
child
in
children
)
{
...
...
pdf/lib/src/widgets/table.dart
View file @
016cba4
...
...
@@ -148,9 +148,7 @@ class _TableContext extends WidgetContext {
@override
WidgetContext
clone
()
{
return
_TableContext
()
..
firstLine
=
firstLine
..
lastLine
=
lastLine
;
return
_TableContext
()..
apply
(
this
);
}
@override
...
...
pdf/lib/src/widgets/text.dart
View file @
016cba4
...
...
@@ -1294,7 +1294,7 @@ class RichText extends Widget with SpanningWidget {
bool
get
canSpan
=>
overflow
==
TextOverflow
.
span
;
@override
bool
get
hasMoreWidgets
=>
overflow
==
TextOverflow
.
s
pan
;
bool
get
hasMoreWidgets
=>
canS
pan
;
@override
void
restoreContext
(
_RichTextContext
context
)
{
...
...
pdf/lib/src/widgets/wrap.dart
View file @
016cba4
...
...
@@ -57,9 +57,7 @@ class _WrapContext extends WidgetContext {
@override
WidgetContext
clone
()
{
return
_WrapContext
()
..
firstChild
=
firstChild
..
lastChild
=
lastChild
;
return
_WrapContext
()..
apply
(
this
);
}
@override
...
...
pdf/pubspec.yaml
View file @
016cba4
...
...
@@ -3,7 +3,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
:
3.8.
3
version
:
3.8.
4
environment
:
sdk
:
"
>=2.12.0
<3.0.0"
...
...
Please
register
or
login
to post a comment