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-03-02 08:18:45 -0500
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
16c1dd116c9bb921f2b9f2161c17ebaf36c56fd1
16c1dd11
1 parent
6da22fc2
Add a graphic context stack
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
6 deletions
pdf/lib/pdf.dart
pdf/lib/src/graphics.dart
pdf/lib/pdf.dart
View file @
16c1dd1
...
...
@@ -16,6 +16,7 @@
library
pdf
;
import
'dart:collection'
;
import
'dart:convert'
;
import
'dart:math'
as
math
;
import
'dart:typed_data'
;
...
...
pdf/lib/src/graphics.dart
View file @
16c1dd1
...
...
@@ -18,14 +18,25 @@ part of pdf;
enum
PdfLineCap
{
joinMiter
,
joinRound
,
joinBevel
}
@immutable
class
_PdfGraphicsContext
{
const
_PdfGraphicsContext
({
@required
this
.
ctm
})
:
assert
(
ctm
!=
null
);
final
Matrix4
ctm
;
_PdfGraphicsContext
copy
()
=>
_PdfGraphicsContext
(
ctm:
ctm
.
clone
());
}
class
PdfGraphics
{
PdfGraphics
(
this
.
page
,
this
.
buf
);
PdfGraphics
(
this
.
page
,
this
.
buf
)
{
_context
=
_PdfGraphicsContext
(
ctm:
Matrix4
.
identity
());
}
/// Ellipse 4-spline magic number
static
const
double
_m4
=
0.551784
;
/// Graphic context number
int
_context
=
0
;
/// Graphic context
_PdfGraphicsContext
_context
;
final
Queue
<
_PdfGraphicsContext
>
_contextQueue
=
Queue
<
_PdfGraphicsContext
>();
final
PdfPage
page
;
...
...
@@ -61,17 +72,17 @@ class PdfGraphics {
/// When using [PdfPage], you can create another fresh Graphics instance,
/// which will draw over this one.
void
restoreContext
()
{
if
(
_context
>
0
)
{
if
(
_context
Queue
.
isNotEmpty
)
{
// restore graphics context
buf
.
putString
(
'Q
\n
'
);
_context
--
;
_context
=
_contextQueue
.
removeLast
()
;
}
}
void
saveContext
()
{
// save graphics context
buf
.
putString
(
'q
\n
'
);
_context
++
;
_context
Queue
.
addLast
(
_context
.
copy
())
;
}
/// Draws an image onto the page.
...
...
@@ -227,6 +238,12 @@ class PdfGraphics {
final
Float64List
s
=
t
.
storage
;
buf
.
putNumList
(<
double
>[
s
[
0
],
s
[
1
],
s
[
4
],
s
[
5
],
s
[
12
],
s
[
13
]]);
buf
.
putString
(
' cm
\n
'
);
_context
.
ctm
.
multiply
(
t
);
}
/// Get the transformation Matrix
Matrix4
getTransform
()
{
return
_context
.
ctm
.
clone
();
}
/// This adds a line segment to the current path
...
...
Please
register
or
login
to post a comment