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-04-05 12:51:47 -0300
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
4a9cd23bf35c70672ff9c2bca36029817746bb12
4a9cd23b
1 parent
d988aff4
Improve Table Of Content
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
141 additions
and
11 deletions
pdf/CHANGELOG.md
pdf/lib/src/pdf/obj/outline.dart
pdf/lib/src/widgets/annotations.dart
pdf/lib/src/widgets/content.dart
pdf/lib/src/widgets/widget.dart
pdf/test/all_tests.dart
pdf/test/widget_toc_test.dart
test/golden/widgets-toc.pdf
pdf/CHANGELOG.md
View file @
4a9cd23
...
...
@@ -8,6 +8,7 @@
-
Typo: rename "litteral" with "literal"
-
Fix tabs and other spaces placeholder
-
Prevent modifying the document once saved
-
Improve Table Of Content
## 3.7.4
...
...
pdf/lib/src/pdf/obj/outline.dart
View file @
4a9cd23
...
...
@@ -58,7 +58,7 @@ class PdfOutline extends PdfObjectDict {
this
.
color
,
this
.
destMode
=
PdfOutlineMode
.
fitPage
,
this
.
style
=
PdfOutlineStyle
.
normal
,
String
?
page
,
PdfPage
?
page
,
})
:
assert
(
anchor
==
null
||
(
dest
==
null
&&
rect
==
null
)),
_page
=
page
,
super
(
pdfDocument
);
...
...
@@ -76,12 +76,20 @@ class PdfOutline extends PdfObjectDict {
PdfPage
?
dest
;
/// Page number
String
?
get
page
=>
_page
??
(
dest
!=
null
?
(
pdfDocument
.
pdfPageList
.
pages
.
indexOf
(
dest
!)
+
1
).
toString
()
:
null
);
final
String
?
_page
;
String
?
get
page
{
final
int
?
num
;
if
(
_page
!=
null
)
{
num
=
pdfDocument
.
pdfPageList
.
pages
.
indexOf
(
_page
!);
}
else
if
(
dest
!=
null
)
{
num
=
pdfDocument
.
pdfPageList
.
pages
.
indexOf
(
dest
!);
}
else
{
num
=
null
;
}
return
num
==
null
?
null
:
(
num
+
1
).
toString
();
}
final
PdfPage
?
_page
;
/// The region on the destination page
final
PdfRect
?
rect
;
...
...
pdf/lib/src/widgets/annotations.dart
View file @
4a9cd23
...
...
@@ -59,8 +59,8 @@ class Anchor extends SingleChildWidget {
if
(
description
!=
null
)
{
final
rb
=
mat
.
transform3
(
Vector3
(
box
!.
right
,
box
!.
top
,
0
));
final
ibox
=
PdfRect
.
fromLTRB
(
lt
.
x
,
lt
.
y
,
rb
.
x
,
rb
.
y
);
PdfAnnot
(
context
.
page
,
PdfAnnotText
(
rect:
ibox
,
content:
description
!));
final
iBox
=
PdfRect
.
fromLTRB
(
lt
.
x
,
lt
.
y
,
rb
.
x
,
rb
.
y
);
PdfAnnot
(
context
.
page
,
PdfAnnotText
(
rect:
iBox
,
content:
description
!));
}
}
}
...
...
@@ -622,7 +622,7 @@ class Outline extends Anchor {
anchor:
name
,
color:
color
,
style:
style
,
page:
context
.
page
Label
,
page:
context
.
page
,
)..
effectiveLevel
=
level
;
final
root
=
context
.
document
.
outline
;
...
...
pdf/lib/src/widgets/content.dart
View file @
4a9cd23
...
...
@@ -151,7 +151,7 @@ class TableOfContent extends StatelessWidget {
thickness:
0.2
,
)),
SizedBox
(
width:
8
),
Text
(
'
${c.page}
'
),
DelayedWidget
(
build:
(
_
)
=>
Text
(
'
${c.page}
'
)
),
],
),
),
...
...
pdf/lib/src/widgets/widget.dart
View file @
4a9cd23
...
...
@@ -380,3 +380,37 @@ class InheritedWidget extends SingleChildWidget {
paintChild
(
_context
!);
}
}
class
DelayedWidget
extends
SingleChildWidget
{
DelayedWidget
({
required
this
.
build
})
:
super
();
final
BuildCallback
build
;
@override
Widget
?
get
child
=>
_child
;
Widget
?
_child
;
@override
void
layout
(
Context
context
,
BoxConstraints
constraints
,
{
bool
parentUsesSize
=
false
})
{
_child
=
build
(
context
);
super
.
layout
(
context
,
constraints
);
}
void
delayedPaint
(
Context
context
)
{
_child
=
build
(
context
);
child
!.
layout
(
context
,
BoxConstraints
.
tight
(
box
!.
size
),
parentUsesSize:
false
,
);
paintChild
(
context
);
}
@override
void
paint
(
Context
context
)
{
delayedPaint
(
context
);
super
.
paint
(
context
);
}
}
...
...
pdf/test/all_tests.dart
View file @
4a9cd23
...
...
@@ -48,6 +48,7 @@ import 'widget_table_test.dart' as widget_table;
import
'widget_test.dart'
as
widget
;
import
'widget_text_test.dart'
as
widget_text
;
import
'widget_theme_test.dart'
as
widget_theme
;
import
'widget_toc_test.dart'
as
widget_toc
;
import
'widget_watermark_test.dart'
as
widget_watermark
;
import
'widget_wrap_test.dart'
as
widget_wrap
;
...
...
@@ -83,6 +84,7 @@ void main() {
widget_table
.
main
();
widget_text
.
main
();
widget_theme
.
main
();
widget_toc
.
main
();
widget_watermark
.
main
();
widget_wrap
.
main
();
widget
.
main
();
...
...
pdf/test/widget_toc_test.dart
0 → 100644
View file @
4a9cd23
/*
* 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.
*/
import
'dart:io'
;
import
'dart:math'
;
import
'package:pdf/widgets.dart'
;
import
'package:test/test.dart'
;
late
Document
pdf
;
void
main
(
)
{
setUpAll
(()
{
Document
.
debug
=
true
;
pdf
=
Document
();
});
test
(
'Pdf Widgets TableOfContent'
,
()
{
pdf
.
addPage
(
Page
(
build:
(
context
)
=>
Center
(
child:
Text
(
'Document'
,
style:
Theme
.
of
(
context
).
header0
)),
),
);
pdf
.
addPage
(
MultiPage
(
footer:
(
c
)
=>
Padding
(
padding:
const
EdgeInsets
.
only
(
top:
20
),
child:
Align
(
alignment:
Alignment
.
centerRight
,
child:
Text
(
c
.
pageLabel
))),
build:
(
context
)
=>
[
...
Iterable
<
Widget
>.
generate
(
40
,
(
index
)
{
final
level
=
(
sin
(
index
/
5
)
*
6
).
abs
().
toInt
();
return
Column
(
children:
[
Header
(
child:
Text
(
'Hello
$index
level
$level
'
),
text:
'Hello
$index
'
,
level:
level
,
),
Lorem
(
length:
60
),
],
);
}),
],
),
);
pdf
.
addPage
(
MultiPage
(
footer:
(
c
)
=>
Padding
(
padding:
const
EdgeInsets
.
only
(
top:
20
),
child:
Align
(
alignment:
Alignment
.
centerRight
,
child:
Text
(
c
.
pageLabel
))),
build:
(
context
)
=>
[
Center
(
child:
Text
(
'Table of content'
,
style:
Theme
.
of
(
context
).
header0
)),
SizedBox
(
height:
20
),
TableOfContent
(),
],
),
index:
1
,
);
});
tearDownAll
(()
async
{
final
file
=
File
(
'widgets-toc.pdf'
);
await
file
.
writeAsBytes
(
await
pdf
.
save
());
});
}
...
...
test/golden/widgets-toc.pdf
0 → 100644
View file @
4a9cd23
No preview for this file type
Please
register
or
login
to post a comment