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
2023-03-13 09:14:06 -0300
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
06ca6850ef6893e605cee13b4d83a1ac456af52a
06ca6850
1 parent
daeeedf6
Draw page content only if not empty
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
28 additions
and
6 deletions
pdf/CHANGELOG.md
pdf/lib/src/pdf/graphics.dart
pdf/lib/src/pdf/obj/page.dart
pdf/CHANGELOG.md
View file @
06ca685
...
...
@@ -9,6 +9,7 @@
-
Improve verbose output
-
Import already defined form
-
Add support for deleted objects
-
Draw page content only if not empty
## 3.9.0
...
...
pdf/lib/src/pdf/graphics.dart
View file @
06ca685
...
...
@@ -123,6 +123,9 @@ class PdfGraphics {
/// Default font if none selected
PdfFont
?
get
defaultFont
=>
_page
.
getDefaultFont
();
bool
_altered
=
false
;
bool
get
altered
=>
_altered
;
/// Draw a surface on the previously defined shape
/// set evenOdd to false to use the nonzero winding number rule to determine the region to fill and to true to use the even-odd rule to determine the region to fill
void
fillPath
({
bool
evenOdd
=
false
})
{
...
...
@@ -136,6 +139,7 @@ class PdfGraphics {
}());
_buf
.
putString
(
'f
${evenOdd ? '*' : ''}
'
);
_altered
=
true
;
assert
(()
{
if
(
_page
.
pdfDocument
.
verbose
)
{
...
...
@@ -158,6 +162,7 @@ class PdfGraphics {
}());
_buf
.
putString
(
'
${close ? 's' : 'S'}
'
);
_altered
=
true
;
assert
(()
{
if
(
_page
.
pdfDocument
.
verbose
)
{
...
...
@@ -178,6 +183,7 @@ class PdfGraphics {
}());
_buf
.
putString
(
'h '
);
_altered
=
true
;
assert
(()
{
if
(
_page
.
pdfDocument
.
verbose
)
{
...
...
@@ -224,6 +230,7 @@ class PdfGraphics {
}());
_buf
.
putString
(
'
${close ? 'b' : 'B'}${evenOdd ? '*' : ''}
'
);
_altered
=
true
;
assert
(()
{
if
(
_page
.
pdfDocument
.
verbose
)
{
...
...
@@ -248,6 +255,7 @@ class PdfGraphics {
// The shader needs to be registered in the page resources
_page
.
addShader
(
shader
);
_buf
.
putString
(
'
${shader.name}
sh '
);
_altered
=
true
;
assert
(()
{
if
(
_page
.
pdfDocument
.
verbose
)
{
...
...
@@ -354,7 +362,7 @@ class PdfGraphics {
}
_buf
.
putString
(
' cm
${img.name}
Do Q '
);
}
_altered
=
true
;
assert
(()
{
if
(
_page
.
pdfDocument
.
verbose
)
{
...
...
@@ -571,6 +579,7 @@ class PdfGraphics {
return
true
;
}());
_altered
=
true
;
}
void
reset
()
{
...
...
pdf/lib/src/pdf/obj/page.dart
View file @
06ca685
...
...
@@ -20,6 +20,7 @@ import '../graphics.dart';
import
'../page_format.dart'
;
import
'annotation.dart'
;
import
'graphic_stream.dart'
;
import
'object.dart'
;
import
'object_dict.dart'
;
import
'object_stream.dart'
;
...
...
@@ -64,11 +65,13 @@ class PdfPage extends PdfObjectDict with PdfGraphicStream {
PdfPageRotation
rotate
;
/// This holds the contents of the page.
final
contents
=
<
PdfObject
Stream
>[];
final
contents
=
<
PdfObject
>[];
/// This holds any Annotations contained within this page.
final
annotations
=
<
PdfAnnot
>[];
final
_contentGraphics
=
<
PdfObject
,
PdfGraphics
>{};
/// This returns a [PdfGraphics] object, which can then be used to render
/// on to this page. If a previous [PdfGraphics] object was used, this object
/// is appended to the page, and will be drawn over the top of any previous
...
...
@@ -76,6 +79,7 @@ class PdfPage extends PdfObjectDict with PdfGraphicStream {
PdfGraphics
getGraphics
()
{
final
stream
=
PdfObjectStream
(
pdfDocument
);
final
g
=
PdfGraphics
(
this
,
stream
.
buf
);
_contentGraphics
[
stream
]
=
g
;
contents
.
add
(
stream
);
return
g
;
}
...
...
@@ -100,8 +104,15 @@ class PdfPage extends PdfObjectDict with PdfGraphicStream {
params
[
'/MediaBox'
]
=
PdfArray
.
fromNum
(<
double
>[
0
,
0
,
pageFormat
.
width
,
pageFormat
.
height
]);
for
(
final
content
in
contents
)
{
if
(!
_contentGraphics
[
content
]!.
altered
)
{
content
.
inUse
=
false
;
}
}
// The graphic operations to draw the page
final
contentList
=
PdfArray
.
fromObjects
(
contents
);
final
contentList
=
PdfArray
.
fromObjects
(
contents
.
where
((
e
)
=>
e
.
inUse
).
toList
());
if
(
params
.
containsKey
(
'/Contents'
))
{
final
prevContent
=
params
[
'/Contents'
]!;
...
...
@@ -124,9 +135,10 @@ class PdfPage extends PdfObjectDict with PdfGraphicStream {
// The /Annots object
if
(
annotations
.
isNotEmpty
)
{
if
(
params
.
containsKey
(
'/Annots'
))
{
final
annotsList
=
params
[
'/Annots'
];
if
(
annotsList
is
PdfArray
)
{
annotsList
.
values
.
addAll
(
PdfArray
.
fromObjects
(
annotations
).
values
);
final
annotationList
=
params
[
'/Annots'
];
if
(
annotationList
is
PdfArray
)
{
annotationList
.
values
.
addAll
(
PdfArray
.
fromObjects
(
annotations
).
values
);
}
}
else
{
params
[
'/Annots'
]
=
PdfArray
.
fromObjects
(
annotations
);
...
...
Please
register
or
login
to post a comment