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
ilja
2023-12-19 14:14:52 +0100
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Committed by
David PHAM-VAN
2024-01-27 11:37:54 -0400
Commit
0a7acd8d182fbb54e52cbba05e1ea15fc6066b07
0a7acd8d
1 parent
77dd4fec
Add support for hyphenation
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
0 deletions
pdf/CHANGELOG.md
pdf/lib/src/widgets/text.dart
pdf/CHANGELOG.md
View file @
0a7acd8
...
...
@@ -5,6 +5,7 @@
-
Add Flutter's Logical Pixel constant
-
Add support for existing reference objects
-
Update barcode golden pdf
-
Add support for hyphenation
[
ilja
]
## 3.10.7
...
...
pdf/lib/src/widgets/text.dart
View file @
0a7acd8
...
...
@@ -658,6 +658,8 @@ class RichTextContext extends WidgetContext {
'
$runtimeType
Offset:
$startOffset
->
$endOffset
Span:
$spanStart
->
$spanEnd
'
;
}
typedef
Hyphenation
=
List
<
String
>
Function
(
String
word
);
class
RichText
extends
Widget
with
SpanningWidget
{
RichText
({
required
this
.
text
,
...
...
@@ -668,6 +670,7 @@ class RichText extends Widget with SpanningWidget {
this
.
textScaleFactor
=
1.0
,
this
.
maxLines
,
this
.
overflow
=
TextOverflow
.
visible
,
this
.
hyphenation
,
});
static
bool
debug
=
false
;
...
...
@@ -700,6 +703,8 @@ class RichText extends Widget with SpanningWidget {
List
<
InlineSpan
>?
_preprocessed
;
final
Hyphenation
?
hyphenation
;
void
_appendDecoration
(
bool
append
,
_TextDecoration
td
)
{
if
(
append
&&
_decorations
.
isNotEmpty
)
{
final
last
=
_decorations
.
last
;
...
...
@@ -946,6 +951,32 @@ class RichText extends Widget with SpanningWidget {
if
(
_softWrap
&&
offsetX
+
metrics
.
width
>
constraintWidth
+
0.00001
)
{
if
(
hyphenation
!=
null
)
{
final
syllables
=
hyphenation
!(
word
);
if
(
syllables
.
length
>
1
)
{
var
fits
=
''
;
for
(
var
syllable
in
syllables
)
{
if
(
offsetX
+
((
font
.
stringMetrics
(
'
$fits$syllable
-'
,
letterSpacing:
style
.
letterSpacing
!
/
(
style
.
fontSize
!
*
textScaleFactor
))
*
(
style
.
fontSize
!
*
textScaleFactor
))
.
width
)
>
constraintWidth
+
0.00001
)
{
break
;
}
fits
+=
syllable
;
}
if
(
fits
.
isNotEmpty
)
{
words
[
index
]
=
'
$fits
-'
;
words
.
insert
(
index
+
1
,
word
.
substring
(
fits
.
length
));
index
--;
continue
;
}
}
}
if
(
spanCount
>
0
&&
metrics
.
width
<=
constraintWidth
)
{
overflow
=
true
;
lines
.
add
(
_Line
(
...
...
Please
register
or
login
to post a comment