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-16 09:37:57 -0300
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
895c3a1d1aea6a991e77e8984dc49f6b6b525ee1
895c3a1d
1 parent
7cee8078
Add PdfObjectBase to PdfDataType.output
Hide whitespace changes
Inline
Side-by-side
Showing
25 changed files
with
127 additions
and
138 deletions
pdf/lib/src/pdf/format/array.dart
pdf/lib/src/pdf/format/base.dart
pdf/lib/src/pdf/format/bool.dart
pdf/lib/src/pdf/format/dict.dart
pdf/lib/src/pdf/format/dict_stream.dart
pdf/lib/src/pdf/format/indirect.dart
pdf/lib/src/pdf/format/name.dart
pdf/lib/src/pdf/format/null.dart
pdf/lib/src/pdf/format/num.dart
pdf/lib/src/pdf/format/object_base.dart
pdf/lib/src/pdf/format/string.dart
pdf/lib/src/pdf/format/xref.dart
pdf/lib/src/pdf/graphics.dart
pdf/lib/src/pdf/obj/annotation.dart
pdf/lib/src/pdf/obj/font.dart
pdf/lib/src/pdf/obj/info.dart
pdf/lib/src/pdf/obj/metadata.dart
pdf/lib/src/pdf/obj/names.dart
pdf/lib/src/pdf/obj/object.dart
pdf/lib/src/pdf/obj/object_dict.dart
pdf/lib/src/pdf/obj/object_stream.dart
pdf/lib/src/pdf/obj/outline.dart
pdf/lib/src/pdf/obj/page_label.dart
pdf/lib/src/pdf/obj/ttffont.dart
pdf/test/minimal_test.dart
pdf/lib/src/pdf/format/array.dart
View file @
895c3a1
...
...
@@ -65,7 +65,7 @@ class PdfArray<T extends PdfDataType> extends PdfDataType {
}
@override
void
output
(
PdfStream
s
,
[
int
?
indent
])
{
void
output
(
Pdf
ObjectBase
o
,
Pdf
Stream
s
,
[
int
?
indent
])
{
if
(
indent
!=
null
)
{
s
.
putBytes
(
List
<
int
>.
filled
(
indent
,
0x20
));
indent
+=
kIndentSize
;
...
...
@@ -88,7 +88,7 @@ class PdfArray<T extends PdfDataType> extends PdfDataType {
s
.
putByte
(
0x20
);
}
}
val
.
output
(
s
,
indent
);
val
.
output
(
o
,
s
,
indent
);
}
if
(
indent
!=
null
)
{
s
.
putByte
(
0x0a
);
...
...
pdf/lib/src/pdf/format/base.dart
View file @
895c3a1
...
...
@@ -18,6 +18,7 @@ import 'dart:typed_data';
import
'package:meta/meta.dart'
;
import
'object_base.dart'
;
import
'stream.dart'
;
const
kIndentSize
=
2
;
...
...
@@ -25,11 +26,11 @@ const kIndentSize = 2;
abstract
class
PdfDataType
{
const
PdfDataType
();
void
output
(
PdfStream
s
,
[
int
?
indent
]);
void
output
(
Pdf
ObjectBase
o
,
Pdf
Stream
s
,
[
int
?
indent
]);
PdfStream
_toStream
()
{
final
s
=
PdfStream
();
output
(
s
);
output
(
const
PdfObjectBase
(
objser:
0
),
s
);
return
s
;
}
...
...
pdf/lib/src/pdf/format/bool.dart
View file @
895c3a1
...
...
@@ -15,6 +15,7 @@
*/
import
'base.dart'
;
import
'object_base.dart'
;
import
'stream.dart'
;
class
PdfBool
extends
PdfDataType
{
...
...
@@ -23,7 +24,7 @@ class PdfBool extends PdfDataType {
final
bool
value
;
@override
void
output
(
PdfStream
s
,
[
int
?
indent
])
{
void
output
(
Pdf
ObjectBase
o
,
Pdf
Stream
s
,
[
int
?
indent
])
{
s
.
putString
(
value
?
'true'
:
'false'
);
}
...
...
pdf/lib/src/pdf/format/dict.dart
View file @
895c3a1
...
...
@@ -58,7 +58,7 @@ class PdfDict<T extends PdfDataType> extends PdfDataType {
}
@override
void
output
(
PdfStream
s
,
[
int
?
indent
])
{
void
output
(
Pdf
ObjectBase
o
,
Pdf
Stream
s
,
[
int
?
indent
])
{
if
(
indent
!=
null
)
{
s
.
putBytes
(
List
<
int
>.
filled
(
indent
,
0x20
));
}
...
...
@@ -87,7 +87,7 @@ class PdfDict<T extends PdfDataType> extends PdfDataType {
s
.
putByte
(
0x20
);
}
}
v
.
output
(
s
,
indent
);
v
.
output
(
o
,
s
,
indent
);
if
(
indent
!=
null
)
{
s
.
putByte
(
0x0a
);
}
...
...
pdf/lib/src/pdf/format/dict_stream.dart
View file @
895c3a1
...
...
@@ -26,7 +26,6 @@ import 'stream.dart';
class
PdfDictStream
extends
PdfDict
<
PdfDataType
>
{
factory
PdfDictStream
({
required
PdfObjectBase
object
,
Map
<
String
,
PdfDataType
>?
values
,
Uint8List
?
data
,
bool
isBinary
=
false
,
...
...
@@ -34,7 +33,6 @@ class PdfDictStream extends PdfDict<PdfDataType> {
bool
compress
=
true
,
})
{
return
PdfDictStream
.
values
(
object:
object
,
values:
values
??
{},
data:
data
??
Uint8List
(
0
),
encrypt:
encrypt
,
...
...
@@ -44,7 +42,6 @@ class PdfDictStream extends PdfDict<PdfDataType> {
}
PdfDictStream
.
values
({
required
this
.
object
,
required
Map
<
String
,
PdfDataType
>
values
,
required
this
.
data
,
this
.
isBinary
=
false
,
...
...
@@ -54,8 +51,6 @@ class PdfDictStream extends PdfDict<PdfDataType> {
Uint8List
data
;
final
PdfObjectBase
object
;
final
bool
isBinary
;
final
bool
encrypt
;
...
...
@@ -63,7 +58,7 @@ class PdfDictStream extends PdfDict<PdfDataType> {
final
bool
compress
;
@override
void
output
(
PdfStream
s
,
[
int
?
indent
])
{
void
output
(
Pdf
ObjectBase
o
,
Pdf
Stream
s
,
[
int
?
indent
])
{
final
_values
=
PdfDict
(
values
);
Uint8List
?
_data
;
...
...
@@ -71,9 +66,9 @@ class PdfDictStream extends PdfDict<PdfDataType> {
if
(
_values
.
containsKey
(
'/Filter'
))
{
// The data is already in the right format
_data
=
data
;
}
else
if
(
compress
&&
o
bject
.
deflate
!=
null
)
{
}
else
if
(
compress
&&
o
.
deflate
!=
null
)
{
// Compress the data
final
newData
=
Uint8List
.
fromList
(
o
bject
.
deflate
!(
data
));
final
newData
=
Uint8List
.
fromList
(
o
.
deflate
!(
data
));
if
(
newData
.
lengthInBytes
<
data
.
lengthInBytes
)
{
_values
[
'/Filter'
]
=
const
PdfName
(
'/FlateDecode'
);
_data
=
newData
;
...
...
@@ -92,13 +87,13 @@ class PdfDictStream extends PdfDict<PdfDataType> {
}
}
if
(
encrypt
&&
object
.
encryptCallback
!=
null
)
{
_data
=
object
.
encryptCallback
!(
_data
,
object
);
if
(
encrypt
&&
o
.
encryptCallback
!=
null
)
{
_data
=
o
.
encryptCallback
!(
_data
,
o
);
}
_values
[
'/Length'
]
=
PdfNum
(
_data
.
length
);
_values
.
output
(
s
,
indent
);
_values
.
output
(
o
,
s
,
indent
);
if
(
indent
!=
null
)
{
s
.
putByte
(
0x0a
);
}
...
...
pdf/lib/src/pdf/format/indirect.dart
View file @
895c3a1
...
...
@@ -15,6 +15,7 @@
*/
import
'base.dart'
;
import
'object_base.dart'
;
import
'stream.dart'
;
class
PdfIndirect
extends
PdfDataType
{
...
...
@@ -25,7 +26,7 @@ class PdfIndirect extends PdfDataType {
final
int
gen
;
@override
void
output
(
PdfStream
s
,
[
int
?
indent
])
{
void
output
(
Pdf
ObjectBase
o
,
Pdf
Stream
s
,
[
int
?
indent
])
{
s
.
putString
(
'
$ser
$gen
R'
);
}
...
...
pdf/lib/src/pdf/format/name.dart
View file @
895c3a1
...
...
@@ -15,6 +15,7 @@
*/
import
'base.dart'
;
import
'object_base.dart'
;
import
'stream.dart'
;
class
PdfName
extends
PdfDataType
{
...
...
@@ -23,7 +24,7 @@ class PdfName extends PdfDataType {
final
String
value
;
@override
void
output
(
PdfStream
s
,
[
int
?
indent
])
{
void
output
(
Pdf
ObjectBase
o
,
Pdf
Stream
s
,
[
int
?
indent
])
{
assert
(
value
[
0
]
==
'/'
);
final
bytes
=
<
int
>[];
for
(
final
c
in
value
.
codeUnits
)
{
...
...
pdf/lib/src/pdf/format/null.dart
View file @
895c3a1
...
...
@@ -15,13 +15,14 @@
*/
import
'base.dart'
;
import
'object_base.dart'
;
import
'stream.dart'
;
class
PdfNull
extends
PdfDataType
{
const
PdfNull
();
@override
void
output
(
PdfStream
s
,
[
int
?
indent
])
{
void
output
(
Pdf
ObjectBase
o
,
Pdf
Stream
s
,
[
int
?
indent
])
{
s
.
putString
(
'null'
);
}
...
...
pdf/lib/src/pdf/format/num.dart
View file @
895c3a1
...
...
@@ -15,6 +15,7 @@
*/
import
'base.dart'
;
import
'object_base.dart'
;
import
'stream.dart'
;
class
PdfNum
extends
PdfDataType
{
...
...
@@ -27,7 +28,7 @@ class PdfNum extends PdfDataType {
final
num
value
;
@override
void
output
(
PdfStream
s
,
[
int
?
indent
])
{
void
output
(
Pdf
ObjectBase
o
,
Pdf
Stream
s
,
[
int
?
indent
])
{
assert
(!
value
.
isNaN
);
assert
(!
value
.
isInfinite
);
...
...
@@ -72,12 +73,12 @@ class PdfNumList extends PdfDataType {
final
List
<
num
>
values
;
@override
void
output
(
PdfStream
s
,
[
int
?
indent
])
{
void
output
(
Pdf
ObjectBase
o
,
Pdf
Stream
s
,
[
int
?
indent
])
{
for
(
var
n
=
0
;
n
<
values
.
length
;
n
++)
{
if
(
n
>
0
)
{
s
.
putByte
(
0x20
);
}
PdfNum
(
values
[
n
]).
output
(
s
,
indent
);
PdfNum
(
values
[
n
]).
output
(
o
,
s
,
indent
);
}
}
...
...
pdf/lib/src/pdf/format/object_base.dart
View file @
895c3a1
...
...
@@ -34,12 +34,17 @@ enum PdfVersion {
pdf_1_5
,
}
mixin
PdfObjectBase
{
class
PdfObjectBase
{
const
PdfObjectBase
({
required
this
.
objser
,
this
.
objgen
=
0
,
});
/// This is the unique serial number for this object.
int
ge
t
objser
;
final
in
t
objser
;
/// This is the generation number for this object.
int
get
objgen
=>
0
;
final
int
objgen
;
/// Callback used to compress the data
DeflateCallback
?
get
deflate
=>
null
;
...
...
pdf/lib/src/pdf/format/string.dart
View file @
895c3a1
...
...
@@ -167,7 +167,7 @@ class PdfString extends PdfDataType {
}
@override
void
output
(
PdfStream
s
,
[
int
?
indent
])
{
void
output
(
Pdf
ObjectBase
o
,
Pdf
Stream
s
,
[
int
?
indent
])
{
_output
(
s
,
value
);
}
...
...
@@ -185,51 +185,44 @@ class PdfString extends PdfDataType {
}
class
PdfSecString
extends
PdfString
{
const
PdfSecString
(
this
.
object
,
Uint8List
value
,
const
PdfSecString
(
Uint8List
value
,
[
PdfStringFormat
format
=
PdfStringFormat
.
binary
])
:
super
(
value
,
format
);
factory
PdfSecString
.
fromString
(
PdfObjectBase
object
,
String
value
,
[
PdfStringFormat
format
=
PdfStringFormat
.
literal
,
])
{
return
PdfSecString
(
object
,
PdfString
.
_string
(
value
),
format
,
);
}
factory
PdfSecString
.
fromStream
(
PdfObjectBase
object
,
PdfStream
value
,
[
PdfStringFormat
format
=
PdfStringFormat
.
literal
,
])
{
return
PdfSecString
(
object
,
value
.
output
(),
format
,
);
}
factory
PdfSecString
.
fromDate
(
PdfObjectBase
object
,
DateTime
date
)
{
factory
PdfSecString
.
fromDate
(
DateTime
date
)
{
return
PdfSecString
(
object
,
PdfString
.
_date
(
date
),
PdfStringFormat
.
literal
,
);
}
final
PdfObjectBase
object
;
@override
void
output
(
PdfStream
s
,
[
int
?
indent
])
{
if
(
object
.
encryptCallback
==
null
)
{
return
super
.
output
(
s
,
indent
);
void
output
(
PdfObjectBase
o
,
PdfStream
s
,
[
int
?
indent
])
{
if
(
o
.
encryptCallback
==
null
)
{
return
super
.
output
(
o
,
s
,
indent
);
}
final
enc
=
o
bject
.
encryptCallback
!(
value
,
object
);
final
enc
=
o
.
encryptCallback
!(
value
,
o
);
_output
(
s
,
enc
);
}
}
...
...
pdf/lib/src/pdf/format/xref.dart
View file @
895c3a1
...
...
@@ -117,7 +117,7 @@ class PdfXrefTable extends PdfDataType {
}
@override
void
output
(
PdfStream
s
,
[
int
?
indent
])
{}
void
output
(
Pdf
ObjectBase
o
,
Pdf
Stream
s
,
[
int
?
indent
])
{}
@override
String
toString
()
{
...
...
@@ -181,7 +181,7 @@ class PdfXrefTable extends PdfDataType {
return
true
;
}());
s
.
putString
(
'trailer
\n
'
);
params
.
output
(
s
,
object
.
verbose
?
0
:
null
);
params
.
output
(
object
,
s
,
object
.
verbose
?
0
:
null
);
s
.
putByte
(
0x0a
);
return
objOffset
;
...
...
@@ -253,12 +253,11 @@ class PdfXrefTable extends PdfDataType {
s
.
putString
(
'
$id
0 obj
\n
'
);
PdfDictStream
(
object:
object
,
data:
o
.
buffer
.
asUint8List
(),
isBinary:
false
,
encrypt:
false
,
values:
params
.
values
,
).
output
(
s
,
object
.
verbose
?
0
:
null
);
).
output
(
object
,
s
,
object
.
verbose
?
0
:
null
);
s
.
putString
(
'endobj
\n
'
);
return
objOffset
;
...
...
pdf/lib/src/pdf/graphics.dart
View file @
895c3a1
...
...
@@ -338,28 +338,28 @@ class PdfGraphics {
_buf
.
putString
(
'q '
);
switch
(
img
.
orientation
)
{
case
PdfImageOrientation
.
topLeft
:
PdfNumList
(<
double
>[
w
,
0
,
0
,
h
,
x
,
y
]).
output
(
_buf
);
PdfNumList
(<
double
>[
w
,
0
,
0
,
h
,
x
,
y
]).
output
(
_
page
,
_
buf
);
break
;
case
PdfImageOrientation
.
topRight
:
PdfNumList
(<
double
>[-
w
,
0
,
0
,
h
,
w
+
x
,
y
]).
output
(
_buf
);
PdfNumList
(<
double
>[-
w
,
0
,
0
,
h
,
w
+
x
,
y
]).
output
(
_
page
,
_
buf
);
break
;
case
PdfImageOrientation
.
bottomRight
:
PdfNumList
(<
double
>[-
w
,
0
,
0
,
-
h
,
w
+
x
,
h
+
y
]).
output
(
_buf
);
PdfNumList
(<
double
>[-
w
,
0
,
0
,
-
h
,
w
+
x
,
h
+
y
]).
output
(
_
page
,
_
buf
);
break
;
case
PdfImageOrientation
.
bottomLeft
:
PdfNumList
(<
double
>[
w
,
0
,
0
,
-
h
,
x
,
h
+
y
]).
output
(
_buf
);
PdfNumList
(<
double
>[
w
,
0
,
0
,
-
h
,
x
,
h
+
y
]).
output
(
_
page
,
_
buf
);
break
;
case
PdfImageOrientation
.
leftTop
:
PdfNumList
(<
double
>[
0
,
-
h
,
-
w
,
0
,
w
+
x
,
h
+
y
]).
output
(
_buf
);
PdfNumList
(<
double
>[
0
,
-
h
,
-
w
,
0
,
w
+
x
,
h
+
y
]).
output
(
_
page
,
_
buf
);
break
;
case
PdfImageOrientation
.
rightTop
:
PdfNumList
(<
double
>[
0
,
-
h
,
w
,
0
,
x
,
h
+
y
]).
output
(
_buf
);
PdfNumList
(<
double
>[
0
,
-
h
,
w
,
0
,
x
,
h
+
y
]).
output
(
_
page
,
_
buf
);
break
;
case
PdfImageOrientation
.
rightBottom
:
PdfNumList
(<
double
>[
0
,
h
,
w
,
0
,
x
,
y
]).
output
(
_buf
);
PdfNumList
(<
double
>[
0
,
h
,
w
,
0
,
x
,
y
]).
output
(
_
page
,
_
buf
);
break
;
case
PdfImageOrientation
.
leftBottom
:
PdfNumList
(<
double
>[
0
,
h
,
-
w
,
0
,
w
+
x
,
y
]).
output
(
_buf
);
PdfNumList
(<
double
>[
0
,
h
,
-
w
,
0
,
w
+
x
,
y
]).
output
(
_
page
,
_
buf
);
break
;
}
...
...
@@ -411,7 +411,7 @@ class PdfGraphics {
return
true
;
}());
PdfNumList
([
x
,
y
,
w
,
h
]).
output
(
_buf
);
PdfNumList
([
x
,
y
,
w
,
h
]).
output
(
_
page
,
_
buf
);
_buf
.
putString
(
' re '
);
assert
(()
{
...
...
@@ -464,22 +464,22 @@ class PdfGraphics {
_page
.
addFont
(
font
);
_buf
.
putString
(
'
${font.name}
'
);
PdfNum
(
size
).
output
(
_buf
);
PdfNum
(
size
).
output
(
_
page
,
_
buf
);
_buf
.
putString
(
' Tf '
);
if
(
charSpace
!=
null
)
{
PdfNum
(
charSpace
).
output
(
_buf
);
PdfNum
(
charSpace
).
output
(
_
page
,
_
buf
);
_buf
.
putString
(
' Tc '
);
}
if
(
wordSpace
!=
null
)
{
PdfNum
(
wordSpace
).
output
(
_buf
);
PdfNum
(
wordSpace
).
output
(
_
page
,
_
buf
);
_buf
.
putString
(
' Tw '
);
}
if
(
scale
!=
null
)
{
PdfNum
(
scale
*
100
).
output
(
_buf
);
PdfNum
(
scale
*
100
).
output
(
_
page
,
_
buf
);
_buf
.
putString
(
' Tz '
);
}
if
(
rise
!=
null
)
{
PdfNum
(
rise
).
output
(
_buf
);
PdfNum
(
rise
).
output
(
_
page
,
_
buf
);
_buf
.
putString
(
' Ts '
);
}
if
(
mode
!=
PdfTextRenderingMode
.
fill
)
{
...
...
@@ -543,7 +543,7 @@ class PdfGraphics {
return
true
;
}());
PdfNumList
([
x
,
y
]).
output
(
_buf
);
PdfNumList
([
x
,
y
]).
output
(
_
page
,
_
buf
);
_buf
.
putString
(
' Td '
);
assert
(()
{
...
...
@@ -622,10 +622,11 @@ class PdfGraphics {
if
(
color
is
PdfColorCmyk
)
{
PdfNumList
(<
double
>[
color
.
cyan
,
color
.
magenta
,
color
.
yellow
,
color
.
black
])
.
output
(
_buf
);
.
output
(
_
page
,
_
buf
);
_buf
.
putString
(
' k '
);
}
else
{
PdfNumList
(<
double
>[
color
!.
red
,
color
.
green
,
color
.
blue
]).
output
(
_buf
);
PdfNumList
(<
double
>[
color
!.
red
,
color
.
green
,
color
.
blue
])
.
output
(
_page
,
_buf
);
_buf
.
putString
(
' rg '
);
}
...
...
@@ -651,10 +652,11 @@ class PdfGraphics {
if
(
color
is
PdfColorCmyk
)
{
PdfNumList
(<
double
>[
color
.
cyan
,
color
.
magenta
,
color
.
yellow
,
color
.
black
])
.
output
(
_buf
);
.
output
(
_
page
,
_
buf
);
_buf
.
putString
(
' K '
);
}
else
{
PdfNumList
(<
double
>[
color
!.
red
,
color
.
green
,
color
.
blue
]).
output
(
_buf
);
PdfNumList
(<
double
>[
color
!.
red
,
color
.
green
,
color
.
blue
])
.
output
(
_page
,
_buf
);
_buf
.
putString
(
' RG '
);
}
...
...
@@ -750,7 +752,8 @@ class PdfGraphics {
}());
final
s
=
t
.
storage
;
PdfNumList
(<
double
>[
s
[
0
],
s
[
1
],
s
[
4
],
s
[
5
],
s
[
12
],
s
[
13
]]).
output
(
_buf
);
PdfNumList
(<
double
>[
s
[
0
],
s
[
1
],
s
[
4
],
s
[
5
],
s
[
12
],
s
[
13
]])
.
output
(
_page
,
_buf
);
_buf
.
putString
(
' cm '
);
_context
.
ctm
.
multiply
(
t
);
...
...
@@ -780,7 +783,7 @@ class PdfGraphics {
return
true
;
}());
PdfNumList
([
x
,
y
]).
output
(
_buf
);
PdfNumList
([
x
,
y
]).
output
(
_
page
,
_
buf
);
_buf
.
putString
(
' l '
);
assert
(()
{
...
...
@@ -803,7 +806,7 @@ class PdfGraphics {
return
true
;
}());
PdfNumList
([
x
,
y
]).
output
(
_buf
);
PdfNumList
([
x
,
y
]).
output
(
_
page
,
_
buf
);
_buf
.
putString
(
' m '
);
assert
(()
{
...
...
@@ -829,7 +832,7 @@ class PdfGraphics {
return
true
;
}());
PdfNumList
([
x1
,
y1
,
x2
,
y2
,
x3
,
y3
]).
output
(
_buf
);
PdfNumList
([
x1
,
y1
,
x2
,
y2
,
x3
,
y3
]).
output
(
_
page
,
_
buf
);
_buf
.
putString
(
' c '
);
assert
(()
{
...
...
@@ -1047,7 +1050,7 @@ class PdfGraphics {
return
true
;
}());
PdfNum
(
width
).
output
(
_buf
);
PdfNum
(
width
).
output
(
_
page
,
_
buf
);
_buf
.
putString
(
' w '
);
assert
(()
{
...
...
@@ -1071,7 +1074,7 @@ class PdfGraphics {
}());
assert
(
limit
>=
1.0
);
PdfNum
(
limit
).
output
(
_buf
);
PdfNum
(
limit
).
output
(
_
page
,
_
buf
);
_buf
.
putString
(
' M '
);
assert
(()
{
...
...
@@ -1097,7 +1100,7 @@ class PdfGraphics {
return
true
;
}());
PdfArray
.
fromNum
(
array
).
output
(
_buf
);
PdfArray
.
fromNum
(
array
).
output
(
_
page
,
_
buf
);
_buf
.
putString
(
'
$phase
d '
);
assert
(()
{
...
...
@@ -1119,7 +1122,7 @@ class PdfGraphics {
return
true
;
}());
tag
.
output
(
_buf
);
tag
.
output
(
_
page
,
_
buf
);
_buf
.
putString
(
' BMC '
);
assert
(()
{
...
...
pdf/lib/src/pdf/obj/annotation.dart
View file @
895c3a1
...
...
@@ -87,7 +87,7 @@ class PdfChoiceField extends PdfAnnotWidget {
g
.
setFillColor
(
textColor
);
g
.
setFont
(
font
,
fontSize
);
params
[
'/DA'
]
=
PdfSecString
.
fromStream
(
object
,
buf
);
params
[
'/DA'
]
=
PdfSecString
.
fromStream
(
buf
);
// What is /TU? Tooltip?
//params['/TU'] = PdfString.fromString('Select from list');
...
...
@@ -257,9 +257,9 @@ abstract class PdfAnnotBase {
[
matrix
[
0
],
matrix
[
1
],
matrix
[
4
],
matrix
[
5
],
matrix
[
12
],
matrix
[
13
]]);
}
final
b
b
ox
=
boundingBox
??
PdfRect
.
fromPoints
(
PdfPoint
.
zero
,
rect
.
size
);
final
b
B
ox
=
boundingBox
??
PdfRect
.
fromPoints
(
PdfPoint
.
zero
,
rect
.
size
);
s
.
params
[
'/BBox'
]
=
PdfArray
.
fromNum
([
b
box
.
x
,
bbox
.
y
,
bbox
.
width
,
bb
ox
.
height
]);
PdfArray
.
fromNum
([
b
Box
.
x
,
bBox
.
y
,
bBox
.
width
,
bB
ox
.
height
]);
final
g
=
PdfGraphics
(
s
,
s
.
buf
);
if
(
selected
&&
name
!=
null
)
{
...
...
@@ -285,11 +285,11 @@ abstract class PdfAnnotBase {
}
if
(
content
!=
null
)
{
params
[
'/Contents'
]
=
PdfSecString
.
fromString
(
object
,
content
!);
params
[
'/Contents'
]
=
PdfSecString
.
fromString
(
content
!);
}
if
(
name
!=
null
)
{
params
[
'/NM'
]
=
PdfSecString
.
fromString
(
object
,
name
!);
params
[
'/NM'
]
=
PdfSecString
.
fromString
(
name
!);
}
if
(
flags
!=
null
&&
flags
!.
isNotEmpty
)
{
...
...
@@ -297,7 +297,7 @@ abstract class PdfAnnotBase {
}
if
(
date
!=
null
)
{
params
[
'/M'
]
=
PdfSecString
.
fromDate
(
object
,
date
!);
params
[
'/M'
]
=
PdfSecString
.
fromDate
(
date
!);
}
if
(
color
!=
null
)
{
...
...
@@ -305,11 +305,11 @@ abstract class PdfAnnotBase {
}
if
(
subject
!=
null
)
{
params
[
'/Subj'
]
=
PdfSecString
.
fromString
(
object
,
subject
!);
params
[
'/Subj'
]
=
PdfSecString
.
fromString
(
subject
!);
}
if
(
author
!=
null
)
{
params
[
'/T'
]
=
PdfSecString
.
fromString
(
object
,
author
!);
params
[
'/T'
]
=
PdfSecString
.
fromString
(
author
!);
}
if
(
_appearances
.
isNotEmpty
)
{
...
...
@@ -377,7 +377,7 @@ class PdfAnnotNamedLink extends PdfAnnotBase {
params
[
'/A'
]
=
PdfDict
(
{
'/S'
:
const
PdfName
(
'/GoTo'
),
'/D'
:
PdfSecString
.
fromString
(
object
,
dest
),
'/D'
:
PdfSecString
.
fromString
(
dest
),
},
);
}
...
...
@@ -413,7 +413,7 @@ class PdfAnnotUrlLink extends PdfAnnotBase {
params
[
'/A'
]
=
PdfDict
(
{
'/S'
:
const
PdfName
(
'/URI'
),
'/URI'
:
PdfSecString
.
fromString
(
object
,
url
),
'/URI'
:
PdfSecString
.
fromString
(
url
),
},
);
}
...
...
@@ -522,13 +522,13 @@ class PdfAnnotPolygon extends PdfAnnotBase {
final
flippedPoints
=
points
.
map
((
e
)
=>
PdfPoint
(
e
.
x
,
rect
.
height
-
e
.
y
)).
toList
();
final
vertic
i
es
=
<
num
>[];
final
vertices
=
<
num
>[];
for
(
var
i
=
0
;
i
<
flippedPoints
.
length
;
i
++)
{
verticies
.
add
(
flippedPoints
[
i
].
x
);
verticies
.
add
(
flippedPoints
[
i
].
y
);
vertices
.
add
(
flippedPoints
[
i
].
x
);
vertices
.
add
(
flippedPoints
[
i
].
y
);
}
params
[
'/Vertices'
]
=
PdfArray
.
fromNum
(
vertic
i
es
);
params
[
'/Vertices'
]
=
PdfArray
.
fromNum
(
vertices
);
if
(
interiorColor
!=
null
)
{
params
[
'/IC'
]
=
PdfArray
.
fromColor
(
interiorColor
!);
...
...
@@ -573,20 +573,20 @@ class PdfAnnotInk extends PdfAnnotBase {
)
{
super
.
build
(
page
,
object
,
params
);
final
vertic
i
es
=
List
<
List
<
num
>>.
filled
(
points
.
length
,
<
num
>[]);
final
vertices
=
List
<
List
<
num
>>.
filled
(
points
.
length
,
<
num
>[]);
for
(
var
listIndex
=
0
;
listIndex
<
points
.
length
;
listIndex
++)
{
// Flip the points on the Y axis.
final
flippedPoints
=
points
[
listIndex
]
.
map
((
e
)
=>
PdfPoint
(
e
.
x
,
rect
.
height
-
e
.
y
))
.
toList
();
for
(
var
i
=
0
;
i
<
flippedPoints
.
length
;
i
++)
{
verticies
[
listIndex
].
add
(
flippedPoints
[
i
].
x
);
verticies
[
listIndex
].
add
(
flippedPoints
[
i
].
y
);
vertices
[
listIndex
].
add
(
flippedPoints
[
i
].
x
);
vertices
[
listIndex
].
add
(
flippedPoints
[
i
].
y
);
}
}
params
[
'/InkList'
]
=
PdfArray
(
vertic
i
es
.
map
((
v
)
=>
PdfArray
.
fromNum
(
v
)).
toList
());
PdfArray
(
vertices
.
map
((
v
)
=>
PdfArray
.
fromNum
(
v
)).
toList
());
}
}
...
...
@@ -632,7 +632,7 @@ abstract class PdfAnnotWidget extends PdfAnnotBase {
params
[
'/FT'
]
=
PdfName
(
fieldType
);
if
(
fieldName
!=
null
)
{
params
[
'/T'
]
=
PdfSecString
.
fromString
(
object
,
fieldName
!);
params
[
'/T'
]
=
PdfSecString
.
fromString
(
fieldName
!);
}
final
mk
=
PdfDict
();
...
...
@@ -847,10 +847,10 @@ class PdfFormField extends PdfAnnotWidget {
void
build
(
PdfPage
page
,
PdfObject
object
,
PdfDict
params
)
{
super
.
build
(
page
,
object
,
params
);
if
(
alternateName
!=
null
)
{
params
[
'/TU'
]
=
PdfSecString
.
fromString
(
object
,
alternateName
!);
params
[
'/TU'
]
=
PdfSecString
.
fromString
(
alternateName
!);
}
if
(
mappingName
!=
null
)
{
params
[
'/TM'
]
=
PdfSecString
.
fromString
(
object
,
mappingName
!);
params
[
'/TM'
]
=
PdfSecString
.
fromString
(
mappingName
!);
}
params
[
'/Ff'
]
=
PdfNum
(
fieldFlagsValue
);
...
...
@@ -923,13 +923,13 @@ class PdfTextField extends PdfFormField {
final
g
=
PdfGraphics
(
page
,
buf
);
g
.
setFillColor
(
textColor
);
g
.
setFont
(
font
,
fontSize
);
params
[
'/DA'
]
=
PdfSecString
.
fromStream
(
object
,
buf
);
params
[
'/DA'
]
=
PdfSecString
.
fromStream
(
buf
);
if
(
value
!=
null
)
{
params
[
'/V'
]
=
PdfSecString
.
fromString
(
object
,
value
!);
params
[
'/V'
]
=
PdfSecString
.
fromString
(
value
!);
}
if
(
defaultValue
!=
null
)
{
params
[
'/DV'
]
=
PdfSecString
.
fromString
(
object
,
defaultValue
!);
params
[
'/DV'
]
=
PdfSecString
.
fromString
(
defaultValue
!);
}
if
(
textAlign
!=
null
)
{
params
[
'/Q'
]
=
PdfNum
(
textAlign
!.
index
);
...
...
pdf/lib/src/pdf/obj/font.dart
View file @
895c3a1
...
...
@@ -195,7 +195,8 @@ See https://github.com/DavBfr/dart_pdf/wiki/Fonts-Management
/// Draw some text
void
putText
(
PdfStream
stream
,
String
text
)
{
try
{
PdfString
(
latin1
.
encode
(
text
),
PdfStringFormat
.
literal
).
output
(
stream
);
PdfString
(
latin1
.
encode
(
text
),
PdfStringFormat
.
literal
)
.
output
(
this
,
stream
);
}
catch
(
_
)
{
assert
(()
{
print
(
_cannotDecodeMessage
);
...
...
pdf/lib/src/pdf/obj/info.dart
View file @
895c3a1
...
...
@@ -30,28 +30,28 @@ class PdfInfo extends PdfObjectDict {
this
.
producer
})
:
super
(
pdfDocument
)
{
if
(
author
!=
null
)
{
params
[
'/Author'
]
=
PdfSecString
.
fromString
(
this
,
author
!);
params
[
'/Author'
]
=
PdfSecString
.
fromString
(
author
!);
}
if
(
creator
!=
null
)
{
params
[
'/Creator'
]
=
PdfSecString
.
fromString
(
this
,
creator
!);
params
[
'/Creator'
]
=
PdfSecString
.
fromString
(
creator
!);
}
if
(
title
!=
null
)
{
params
[
'/Title'
]
=
PdfSecString
.
fromString
(
t
his
,
t
itle
!);
params
[
'/Title'
]
=
PdfSecString
.
fromString
(
title
!);
}
if
(
subject
!=
null
)
{
params
[
'/Subject'
]
=
PdfSecString
.
fromString
(
this
,
subject
!);
params
[
'/Subject'
]
=
PdfSecString
.
fromString
(
subject
!);
}
if
(
keywords
!=
null
)
{
params
[
'/Keywords'
]
=
PdfSecString
.
fromString
(
this
,
keywords
!);
params
[
'/Keywords'
]
=
PdfSecString
.
fromString
(
keywords
!);
}
if
(
producer
!=
null
)
{
params
[
'/Producer'
]
=
PdfSecString
.
fromString
(
this
,
'
$producer
(
$_libraryName
)'
);
PdfSecString
.
fromString
(
'
$producer
(
$_libraryName
)'
);
}
else
{
params
[
'/Producer'
]
=
PdfSecString
.
fromString
(
this
,
_libraryName
);
params
[
'/Producer'
]
=
PdfSecString
.
fromString
(
_libraryName
);
}
params
[
'/CreationDate'
]
=
PdfSecString
.
fromDate
(
this
,
DateTime
.
now
());
params
[
'/CreationDate'
]
=
PdfSecString
.
fromDate
(
DateTime
.
now
());
}
static
const
String
_libraryName
=
'https://github.com/DavBfr/dart_pdf'
;
...
...
pdf/lib/src/pdf/obj/metadata.dart
View file @
895c3a1
...
...
@@ -33,7 +33,6 @@ class PdfMetadata extends PdfObject<PdfDictStream> {
)
:
super
(
pdfDocument
,
params:
PdfDictStream
(
object:
pdfDocument
.
catalog
,
compress:
false
,
encrypt:
false
,
),
...
...
pdf/lib/src/pdf/obj/names.dart
View file @
895c3a1
...
...
@@ -62,7 +62,7 @@ class PdfNames extends PdfObjectDict {
final
keys
=
_dests
.
keys
.
toList
()..
sort
();
for
(
final
name
in
keys
)
{
dests
.
add
(
PdfSecString
.
fromString
(
this
,
name
));
dests
.
add
(
PdfSecString
.
fromString
(
name
));
dests
.
add
(
_dests
[
name
]!);
}
...
...
@@ -70,8 +70,8 @@ class PdfNames extends PdfObjectDict {
if
(
dests
.
values
.
isNotEmpty
)
{
dict
[
'/Names'
]
=
dests
;
dict
[
'/Limits'
]
=
PdfArray
([
PdfSecString
.
fromString
(
this
,
keys
.
first
),
PdfSecString
.
fromString
(
this
,
keys
.
last
),
PdfSecString
.
fromString
(
keys
.
first
),
PdfSecString
.
fromString
(
keys
.
last
),
]);
}
params
[
'/Dests'
]
=
dict
;
...
...
pdf/lib/src/pdf/obj/object.dart
View file @
895c3a1
...
...
@@ -23,28 +23,22 @@ import '../format/stream.dart';
import
'diagnostic.dart'
;
/// Base Object used in the PDF file
abstract
class
PdfObject
<
T
extends
PdfDataType
>
with
PdfDiagnostic
,
PdfObjectBase
{
abstract
class
PdfObject
<
T
extends
PdfDataType
>
extends
PdfObjectBase
with
PdfDiagnostic
{
/// This is usually called by extensors to this class, and sets the
/// Pdf Object Type
PdfObject
(
this
.
pdfDocument
,
{
required
this
.
params
,
this
.
objgen
=
0
,
int
objgen
=
0
,
int
?
objser
,
})
:
objser
=
objser
??
pdfDocument
.
genSerial
(
)
{
})
:
super
(
objser:
objser
??
pdfDocument
.
genSerial
(),
objgen:
objgen
)
{
pdfDocument
.
objects
.
add
(
this
);
}
/// This is the object parameters.
final
T
params
;
@override
final
int
objser
;
@override
final
int
objgen
;
/// This allows any Pdf object to refer to the document being constructed.
final
PdfDocument
pdfDocument
;
...
...
@@ -81,7 +75,7 @@ abstract class PdfObject<T extends PdfDataType>
}
void
writeContent
(
PdfStream
os
)
{
params
.
output
(
os
,
verbose
?
0
:
null
);
params
.
output
(
this
,
os
,
verbose
?
0
:
null
);
os
.
putByte
(
0x0a
);
}
...
...
pdf/lib/src/pdf/obj/object_dict.dart
View file @
895c3a1
...
...
@@ -38,7 +38,7 @@ class PdfObjectDict extends PdfObject<PdfDict> {
@override
void
writeContent
(
PdfStream
os
)
{
if
(
params
.
isNotEmpty
)
{
params
.
output
(
os
,
pdfDocument
.
verbose
?
0
:
null
);
params
.
output
(
this
,
os
,
pdfDocument
.
verbose
?
0
:
null
);
os
.
putByte
(
0x0a
);
}
}
...
...
pdf/lib/src/pdf/obj/object_stream.dart
View file @
895c3a1
...
...
@@ -37,10 +37,9 @@ class PdfObjectStream extends PdfObjectDict {
@override
void
writeContent
(
PdfStream
os
)
{
PdfDictStream
.
values
(
object:
this
,
isBinary:
isBinary
,
values:
params
.
values
,
data:
buf
.
output
(),
).
output
(
os
,
pdfDocument
.
verbose
?
0
:
null
);
).
output
(
this
,
os
,
pdfDocument
.
verbose
?
0
:
null
);
}
}
...
...
pdf/lib/src/pdf/obj/outline.dart
View file @
895c3a1
...
...
@@ -125,7 +125,7 @@ class PdfOutline extends PdfObjectDict {
// These are for kids only
if
(
parent
!=
null
)
{
params
[
'/Title'
]
=
PdfSecString
.
fromString
(
t
his
,
t
itle
!);
params
[
'/Title'
]
=
PdfSecString
.
fromString
(
title
!);
if
(
color
!=
null
)
{
params
[
'/C'
]
=
PdfArray
.
fromColor
(
color
!);
...
...
@@ -136,7 +136,7 @@ class PdfOutline extends PdfObjectDict {
}
if
(
anchor
!=
null
)
{
params
[
'/Dest'
]
=
PdfSecString
.
fromString
(
this
,
anchor
!);
params
[
'/Dest'
]
=
PdfSecString
.
fromString
(
anchor
!);
}
else
{
final
dests
=
PdfArray
();
dests
.
add
(
dest
!.
ref
());
...
...
pdf/lib/src/pdf/obj/page_label.dart
View file @
895c3a1
...
...
@@ -20,7 +20,6 @@ import '../format/dict.dart';
import
'../format/name.dart'
;
import
'../format/num.dart'
;
import
'../format/string.dart'
;
import
'object.dart'
;
import
'object_dict.dart'
;
enum
PdfPageLabelStyle
{
...
...
@@ -53,7 +52,7 @@ class PdfPageLabel {
final
String
?
prefix
;
final
int
?
subsequent
;
PdfDict
toDict
(
PdfObject
obj
)
{
PdfDict
toDict
()
{
final
PdfName
?
s
;
switch
(
style
)
{
case
PdfPageLabelStyle
.
arabic
:
...
...
@@ -77,7 +76,7 @@ class PdfPageLabel {
return
PdfDict
({
if
(
s
!=
null
)
'/S'
:
s
,
if
(
prefix
!=
null
&&
prefix
!.
isNotEmpty
)
'/P'
:
PdfSecString
.
fromString
(
obj
,
prefix
!),
'/P'
:
PdfSecString
.
fromString
(
prefix
!),
if
(
subsequent
!=
null
)
'/St'
:
PdfNum
(
subsequent
!)
});
}
...
...
@@ -191,7 +190,7 @@ class PdfPageLabels extends PdfObjectDict {
final
nums
=
PdfArray
();
for
(
final
entry
in
labels
.
entries
)
{
nums
.
add
(
PdfNum
(
entry
.
key
));
nums
.
add
(
entry
.
value
.
toDict
(
this
));
nums
.
add
(
entry
.
value
.
toDict
());
}
params
[
'/Nums'
]
=
nums
;
...
...
pdf/lib/src/pdf/obj/ttffont.dart
View file @
895c3a1
...
...
@@ -129,8 +129,8 @@ class PdfTtfFont extends PdfFont {
'/Subtype'
:
const
PdfName
(
'/CIDFontType2'
),
'/CIDSystemInfo'
:
PdfDict
({
'/Supplement'
:
const
PdfNum
(
0
),
'/Registry'
:
PdfSecString
.
fromString
(
this
,
'Adobe'
),
'/Ordering'
:
PdfSecString
.
fromString
(
this
,
'Identity-H'
),
'/Registry'
:
PdfSecString
.
fromString
(
'Adobe'
),
'/Ordering'
:
PdfSecString
.
fromString
(
'Identity-H'
),
})
});
...
...
pdf/test/minimal_test.dart
View file @
895c3a1
...
...
@@ -20,18 +20,15 @@ import 'dart:io';
import
'package:pdf/src/priv.dart'
;
import
'package:test/test.dart'
;
class
BasicObject
with
PdfObjectBase
{
const
BasicObject
(
this
.
objser
);
@override
final
int
objser
;
class
BasicObject
extends
PdfObjectBase
{
const
BasicObject
(
int
objser
)
:
super
(
objser:
objser
);
@override
bool
get
verbose
=>
true
;
void
write
(
PdfStream
os
,
PdfDataType
value
)
{
os
.
putString
(
'
$objser
$objgen
obj
\n
'
);
value
.
output
(
os
,
verbose
?
0
:
null
);
value
.
output
(
this
,
os
,
verbose
?
0
:
null
);
os
.
putByte
(
0x0a
);
os
.
putString
(
'endobj
\n
'
);
}
...
...
@@ -57,7 +54,6 @@ void main() {
});
final
content
=
PdfDictStream
(
object:
const
BasicObject
(
1
),
data:
latin1
.
encode
(
'30 811.88976 m 200 641.88976 l S'
),
);
...
...
Please
register
or
login
to post a comment