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-04-01 19:43:23 -0400
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
c71e8d4de9e10cb89833af4e42733f0638e6742b
c71e8d4d
1 parent
208d76b0
Allow Annotations in TextSpan
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
69 additions
and
48 deletions
pdf/CHANGELOG.md
pdf/lib/widgets/annotations.dart
pdf/lib/widgets/text.dart
pdf/CHANGELOG.md
View file @
c71e8d4
# 1.3.8
*
Add jpeg image loading function
*
Add Theme::copyFrom() method
*
Allow Annotations in TextSpan
# 1.3.7
*
Add Pdf Creation date
...
...
pdf/lib/widgets/annotations.dart
View file @
c71e8d4
...
...
@@ -42,69 +42,76 @@ class Anchor extends SingleChildWidget {
}
}
class
_Annotation
extends
SingleChildWidget
{
_Annotation
({
Widget
child
})
:
super
(
child:
child
);
@override
void
debugPaint
(
Context
context
)
{
context
.
canvas
..
setFillColor
(
PdfColors
.
pink
)
..
drawRect
(
box
.
x
,
box
.
y
,
box
.
width
,
box
.
height
)
..
fillPath
();
abstract
class
AnnotationBuilder
{
PdfRect
localToGlobal
(
Context
context
,
PdfRect
box
)
{
final
Matrix4
mat
=
context
.
canvas
.
getTransform
();
final
Vector3
lt
=
mat
.
transform3
(
Vector3
(
box
.
left
,
box
.
bottom
,
0
));
final
Vector3
rb
=
mat
.
transform3
(
Vector3
(
box
.
right
,
box
.
top
,
0
));
return
PdfRect
.
fromLTRB
(
lt
.
x
,
lt
.
y
,
rb
.
x
,
rb
.
y
);
}
@override
void
paint
(
Context
context
)
{
super
.
paint
(
context
);
paintChild
(
context
);
}
void
build
(
Context
context
,
PdfRect
box
);
}
class
Link
extends
_Annotation
{
Link
({
@required
Widget
child
,
this
.
destination
})
:
assert
(
child
!=
null
),
super
(
child:
child
);
class
AnnotationLink
extends
AnnotationBuilder
{
AnnotationLink
(
this
.
destination
)
:
assert
(
destination
!=
null
);
final
String
destination
;
@override
void
paint
(
Context
context
)
{
super
.
paint
(
context
);
if
(
destination
!=
null
)
{
final
Matrix4
mat
=
context
.
canvas
.
getTransform
();
final
Vector3
lt
=
mat
.
transform3
(
Vector3
(
box
.
left
,
box
.
bottom
,
0
));
final
Vector3
rb
=
mat
.
transform3
(
Vector3
(
box
.
right
,
box
.
top
,
0
));
final
PdfRect
ibox
=
PdfRect
.
fromLTRB
(
lt
.
x
,
lt
.
y
,
rb
.
x
,
rb
.
y
);
PdfAnnot
.
namedLink
(
context
.
page
,
rect:
ibox
,
dest:
destination
,
);
}
void
build
(
Context
context
,
PdfRect
box
)
{
PdfAnnot
.
namedLink
(
context
.
page
,
rect:
localToGlobal
(
context
,
box
),
dest:
destination
,
);
}
}
class
UrlLink
extends
_Annotation
{
UrlLink
({
@required
Widget
child
,
@required
this
.
destination
})
:
assert
(
child
!=
null
),
assert
(
destination
!=
null
),
super
(
child:
child
);
class
AnnotationUrl
extends
AnnotationBuilder
{
AnnotationUrl
(
this
.
destination
)
:
assert
(
destination
!=
null
);
final
String
destination
;
@override
void
paint
(
Context
context
)
{
super
.
paint
(
context
);
final
Matrix4
mat
=
context
.
canvas
.
getTransform
();
final
Vector3
lt
=
mat
.
transform3
(
Vector3
(
box
.
left
,
box
.
bottom
,
0
));
final
Vector3
rb
=
mat
.
transform3
(
Vector3
(
box
.
right
,
box
.
top
,
0
));
final
PdfRect
ibox
=
PdfRect
.
fromLTRB
(
lt
.
x
,
lt
.
y
,
rb
.
x
,
rb
.
y
);
void
build
(
Context
context
,
PdfRect
box
)
{
PdfAnnot
.
urlLink
(
context
.
page
,
rect:
ibox
,
rect:
localToGlobal
(
context
,
box
)
,
dest:
destination
,
);
}
}
class
Annotation
extends
SingleChildWidget
{
Annotation
({
Widget
child
,
this
.
builder
})
:
super
(
child:
child
);
final
AnnotationBuilder
builder
;
@override
void
debugPaint
(
Context
context
)
{
context
.
canvas
..
setFillColor
(
PdfColors
.
pink
)
..
drawRect
(
box
.
x
,
box
.
y
,
box
.
width
,
box
.
height
)
..
fillPath
();
}
@override
void
paint
(
Context
context
)
{
super
.
paint
(
context
);
paintChild
(
context
);
builder
?.
build
(
context
,
box
);
}
}
class
Link
extends
Annotation
{
Link
({
@required
Widget
child
,
String
destination
})
:
assert
(
child
!=
null
),
super
(
child:
child
,
builder:
AnnotationLink
(
destination
));
}
class
UrlLink
extends
Annotation
{
UrlLink
({
@required
Widget
child
,
String
destination
})
:
assert
(
child
!=
null
),
super
(
child:
child
,
builder:
AnnotationUrl
(
destination
));
}
...
...
pdf/lib/widgets/text.dart
View file @
c71e8d4
...
...
@@ -19,7 +19,7 @@ part of widget;
enum
TextAlign
{
left
,
right
,
center
,
justify
}
class
_Word
{
_Word
(
this
.
text
,
this
.
style
,
this
.
metrics
);
_Word
(
this
.
text
,
this
.
style
,
this
.
metrics
,
this
.
annotation
);
final
String
text
;
...
...
@@ -29,6 +29,8 @@ class _Word {
PdfPoint
offset
=
PdfPoint
.
zero
;
final
AnnotationBuilder
annotation
;
@override
String
toString
()
{
return
'Word "
$text
" offset:
$offset
metrics:
$metrics
style:
$style
'
;
...
...
@@ -53,7 +55,7 @@ class _Word {
}
class
TextSpan
{
const
TextSpan
({
this
.
style
,
this
.
text
,
this
.
children
});
const
TextSpan
({
this
.
style
,
this
.
text
,
this
.
children
,
this
.
annotation
});
final
TextStyle
style
;
...
...
@@ -61,6 +63,8 @@ class TextSpan {
final
List
<
TextSpan
>
children
;
final
AnnotationBuilder
annotation
;
String
toPlainText
()
{
final
StringBuffer
buffer
=
StringBuffer
();
visitTextSpan
((
TextSpan
span
)
{
...
...
@@ -210,7 +214,7 @@ class RichText extends Widget {
top
=
math
.
min
(
top
??
metrics
.
top
,
metrics
.
top
);
bottom
=
math
.
max
(
bottom
??
metrics
.
bottom
,
metrics
.
bottom
);
final
_Word
wd
=
_Word
(
word
,
style
,
metrics
);
final
_Word
wd
=
_Word
(
word
,
style
,
metrics
,
span
.
annotation
);
wd
.
offset
=
PdfPoint
(
offsetX
,
-
offsetY
);
_words
.
add
(
wd
);
...
...
@@ -264,6 +268,15 @@ class RichText extends Widget {
}
}
if
(
word
.
annotation
!=
null
)
{
final
PdfRect
wordBox
=
PdfRect
(
box
.
x
+
word
.
offset
.
x
+
word
.
metrics
.
left
,
box
.
top
+
word
.
offset
.
y
+
word
.
metrics
.
top
,
word
.
metrics
.
width
,
word
.
metrics
.
height
);
word
.
annotation
.
build
(
context
,
wordBox
);
}
context
.
canvas
.
drawString
(
currentStyle
.
font
.
getFont
(
context
),
currentStyle
.
fontSize
*
textScaleFactor
,
...
...
Please
register
or
login
to post a comment