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
2021-09-10 08:53:41 -0300
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
02e0dcace03b318766ad14eae0f6712aa051ec7e
02e0dcac
1 parent
43a99f49
Fix text justify with multiple paragraphs
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
42 additions
and
14 deletions
pdf/CHANGELOG.md
pdf/lib/src/widgets/text.dart
pdf/pubspec.yaml
pdf/test/widget_text_test.dart
test/golden/widgets-text.pdf
pdf/CHANGELOG.md
View file @
02e0dca
# Changelog
## 3.6.0
-
Fix text justify with multiple paragraphs
## 3.5.0
-
Add annotations
[
John Harris
]
...
...
pdf/lib/src/widgets/text.dart
View file @
02e0dca
...
...
@@ -483,6 +483,7 @@ class _Line {
this
.
baseline
,
this
.
wordsWidth
,
this
.
textDirection
,
this
.
justify
,
);
final
RichText
parent
;
...
...
@@ -499,6 +500,8 @@ class _Line {
final
TextDirection
textDirection
;
final
bool
justify
;
double
get
height
=>
parent
.
_spans
.
sublist
(
firstSpan
,
lastSpan
)
.
reduce
((
a
,
b
)
=>
a
.
height
>
b
.
height
?
a
:
b
)
...
...
@@ -508,7 +511,7 @@ class _Line {
String
toString
()
=>
'
$runtimeType
$firstSpan
-
$lastSpan
baseline:
$baseline
width:
$wordsWidth
'
;
void
realign
(
double
totalWidth
,
bool
isLast
)
{
void
realign
(
double
totalWidth
)
{
final
spans
=
parent
.
_spans
.
sublist
(
firstSpan
,
lastSpan
);
var
delta
=
0.0
;
...
...
@@ -522,7 +525,7 @@ class _Line {
delta
=
(
totalWidth
-
wordsWidth
)
/
2.0
;
break
;
case
TextAlign
.
justify
:
if
(
isLast
)
{
if
(
!
justify
)
{
totalWidth
=
wordsWidth
;
break
;
}
...
...
@@ -712,6 +715,7 @@ class RichText extends Widget with SpanningWidget {
space
.
advanceWidth
*
style
.
wordSpacing
!
-
style
.
letterSpacing
!,
_textDirection
,
true
,
));
spanStart
+=
spanCount
;
...
...
@@ -778,14 +782,16 @@ class RichText extends Widget with SpanningWidget {
if
(
line
<
spanLines
.
length
-
1
)
{
lines
.
add
(
_Line
(
this
,
spanStart
,
spanCount
,
bottom
,
offsetX
-
space
.
advanceWidth
*
style
.
wordSpacing
!
-
style
.
letterSpacing
!,
_textDirection
));
this
,
spanStart
,
spanCount
,
bottom
,
offsetX
-
space
.
advanceWidth
*
style
.
wordSpacing
!
-
style
.
letterSpacing
!,
_textDirection
,
false
,
));
spanStart
+=
spanCount
;
...
...
@@ -834,6 +840,7 @@ class RichText extends Widget with SpanningWidget {
bottom
,
offsetX
,
_textDirection
,
true
,
));
spanStart
+=
spanCount
;
...
...
@@ -890,6 +897,7 @@ class RichText extends Widget with SpanningWidget {
bottom
,
offsetX
,
_textDirection
,
false
,
));
offsetY
+=
bottom
-
top
;
}
...
...
@@ -906,10 +914,9 @@ class RichText extends Widget with SpanningWidget {
}
// Realign all the lines
for
(
final
line
in
lines
.
sublist
(
0
,
lines
.
length
-
1
))
{
line
.
realign
(
width
,
false
);
for
(
final
line
in
lines
)
{
line
.
realign
(
width
);
}
lines
.
last
.
realign
(
width
,
true
);
}
box
=
PdfRect
(
0
,
0
,
constraints
.
constrainWidth
(
width
),
...
...
pdf/pubspec.yaml
View file @
02e0dca
...
...
@@ -4,7 +4,7 @@ description: A pdf producer for Dart. It can create pdf files for both web or fl
homepage
:
https://github.com/DavBfr/dart_pdf/tree/master/pdf
repository
:
https://github.com/DavBfr/dart_pdf
issue_tracker
:
https://github.com/DavBfr/dart_pdf/issues
version
:
3.
5
.0
version
:
3.
6
.0
environment
:
sdk
:
"
>=2.12.0
<3.0.0"
...
...
pdf/test/widget_text_test.dart
View file @
02e0dca
...
...
@@ -340,6 +340,23 @@ void main() {
);
});
test
(
'Text Widgets Justify multiple paragraphs'
,
()
{
const
para
=
'This is the first paragraph with a small nice text.
\n
Here is a new line.
\n
Another one.
\n
And finally a long paragraph to finish this test with a three lines text that finishes well.'
;
pdf
.
addPage
(
Page
(
build:
(
Context
context
)
=>
SizedBox
(
width:
200
,
child:
Text
(
para
,
textAlign:
TextAlign
.
justify
,
),
),
),
);
});
tearDownAll
(()
async
{
final
file
=
File
(
'widgets-text.pdf'
);
await
file
.
writeAsBytes
(
await
pdf
.
save
());
...
...
test/golden/widgets-text.pdf
View file @
02e0dca
No preview for this file type
Please
register
or
login
to post a comment