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-05-17 14:22:09 -0400
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
4c439fb9e9f8b1a37dffdf5492d3893eb69d5111
4c439fb9
1 parent
eeab5432
Add Text Widget tests
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
196 additions
and
1 deletions
pdf/lib/widgets/text.dart
pdf/test/all_tests.dart
pdf/test/widget_text_test.dart
pdf/lib/widgets/text.dart
View file @
4c439fb
...
...
@@ -103,7 +103,7 @@ class RichText extends Widget {
this
.
maxLines
})
:
assert
(
text
!=
null
);
static
const
bool
debug
=
false
;
static
bool
debug
=
false
;
final
TextSpan
text
;
...
...
pdf/test/all_tests.dart
View file @
4c439fb
...
...
@@ -30,6 +30,7 @@ import 'widget_clip_test.dart' as widget_clip;
import
'widget_container_test.dart'
as
widget_container
;
import
'widget_table_test.dart'
as
widget_table
;
import
'widget_test.dart'
as
widget
;
import
'widget_text_test.dart'
as
widget_text
;
void
main
(
)
{
annotations
.
main
();
...
...
@@ -44,6 +45,7 @@ void main() {
widget_clip
.
main
();
widget_container
.
main
();
widget_table
.
main
();
widget_text
.
main
();
widget
.
main
();
example
.
main
();
}
...
...
pdf/test/widget_text_test.dart
0 → 100644
View file @
4c439fb
/*
* Copyright (C) 2017, David PHAM-VAN <dev.nfet.net@gmail.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import
'dart:io'
;
import
'dart:math'
as
math
;
import
'dart:typed_data'
;
import
'package:test/test.dart'
;
import
'package:pdf/pdf.dart'
;
import
'package:pdf/widgets.dart'
;
Document
pdf
;
Font
ttf
;
Font
ttfBold
;
void
main
(
)
{
setUpAll
(()
{
Document
.
debug
=
true
;
RichText
.
debug
=
true
;
final
Uint8List
fontData
=
File
(
'open-sans.ttf'
).
readAsBytesSync
();
ttf
=
Font
.
ttf
(
fontData
.
buffer
.
asByteData
());
final
Uint8List
fontDataBold
=
File
(
'open-sans-bold.ttf'
).
readAsBytesSync
();
ttfBold
=
Font
.
ttf
(
fontDataBold
.
buffer
.
asByteData
());
pdf
=
Document
();
});
test
(
'Text Widgets Quotes'
,
()
{
pdf
.
addPage
(
Page
(
build:
(
Context
context
)
=>
Text
(
'Text containing
\'
or " works!'
)));
});
test
(
'Text Widgets Unicode Quotes'
,
()
{
pdf
.
addPage
(
Page
(
build:
(
Context
context
)
=>
Text
(
'Text containing ’ and ” works!'
,
style:
TextStyle
(
font:
ttf
))));
});
test
(
'Text Widgets softWrap'
,
()
{
pdf
.
addPage
(
MultiPage
(
build:
(
Context
context
)
=>
<
Widget
>[
Text
(
'Text with
\n
soft wrap
\n
enabled'
,
softWrap:
true
,
),
Text
(
'Text with
\n
soft wrap
\n
disabled'
,
softWrap:
false
,
),
]));
});
test
(
'Text Widgets Alignement'
,
()
{
final
String
para
=
LoremText
().
paragraph
(
40
);
final
List
<
Widget
>
widgets
=
<
Widget
>[];
for
(
TextAlign
align
in
TextAlign
.
values
)
{
widgets
.
add
(
Text
(
'
$align
:
\n
'
+
para
,
textAlign:
align
,
softWrap:
true
,
),
);
}
pdf
.
addPage
(
MultiPage
(
build:
(
Context
context
)
=>
widgets
));
});
test
(
'Text Widgets lineSpacing'
,
()
{
final
String
para
=
LoremText
().
paragraph
(
40
);
final
List
<
Widget
>
widgets
=
<
Widget
>[];
for
(
double
spacing
=
0.0
;
spacing
<
10.0
;
spacing
+=
2.0
)
{
widgets
.
add
(
Text
(
para
,
style:
TextStyle
(
font:
ttf
,
lineSpacing:
spacing
)),
);
widgets
.
add
(
SizedBox
(
height:
30
),
);
}
pdf
.
addPage
(
MultiPage
(
build:
(
Context
context
)
=>
widgets
));
});
test
(
'Text Widgets wordSpacing'
,
()
{
final
String
para
=
LoremText
().
paragraph
(
40
);
final
List
<
Widget
>
widgets
=
<
Widget
>[];
for
(
double
spacing
=
0.0
;
spacing
<
10.0
;
spacing
+=
2.0
)
{
widgets
.
add
(
Text
(
para
,
style:
TextStyle
(
font:
ttf
,
wordSpacing:
spacing
)),
);
widgets
.
add
(
SizedBox
(
height:
30
),
);
}
pdf
.
addPage
(
MultiPage
(
build:
(
Context
context
)
=>
widgets
));
});
test
(
'Text Widgets letterSpacing'
,
()
{
final
String
para
=
LoremText
().
paragraph
(
40
);
final
List
<
Widget
>
widgets
=
<
Widget
>[];
for
(
double
spacing
=
0.0
;
spacing
<
10.0
;
spacing
+=
2.0
)
{
widgets
.
add
(
Text
(
para
,
style:
TextStyle
(
font:
ttf
,
letterSpacing:
spacing
)),
);
widgets
.
add
(
SizedBox
(
height:
30
),
);
}
pdf
.
addPage
(
MultiPage
(
build:
(
Context
context
)
=>
widgets
));
});
test
(
'Text Widgets background'
,
()
{
final
String
para
=
LoremText
().
paragraph
(
40
);
pdf
.
addPage
(
MultiPage
(
build:
(
Context
context
)
=>
<
Widget
>[
Text
(
para
,
style:
TextStyle
(
font:
ttf
,
background:
PdfColors
.
purple50
,
),
),
]));
});
test
(
'Text Widgets RichText'
,
()
{
final
math
.
Random
rnd
=
math
.
Random
(
42
);
final
String
para
=
LoremText
(
random:
rnd
).
paragraph
(
40
);
final
List
<
TextSpan
>
spans
=
<
TextSpan
>[];
for
(
String
word
in
para
.
split
(
' '
))
{
spans
.
add
(
TextSpan
(
text:
'
$word
'
,
style:
TextStyle
(
font:
ttf
,
fontSize:
rnd
.
nextDouble
()
*
20
+
20
,
color:
PdfColors
.
primaries
[
rnd
.
nextInt
(
PdfColors
.
primaries
.
length
)]),
),
);
spans
.
add
(
const
TextSpan
(
text:
' '
));
}
pdf
.
addPage
(
MultiPage
(
build:
(
Context
context
)
=>
<
Widget
>[
RichText
(
text:
TextSpan
(
text:
'Hello '
,
style:
TextStyle
(
font:
ttf
,
fontSize:
20
,
),
children:
<
TextSpan
>[
TextSpan
(
text:
'bold'
,
style:
TextStyle
(
font:
ttfBold
,
fontSize:
40
,
color:
PdfColors
.
blue
)),
TextSpan
(
text:
' world!
\n
'
,
children:
spans
,
),
],
),
),
]));
});
tearDownAll
(()
{
final
File
file
=
File
(
'widgets-text.pdf'
);
file
.
writeAsBytesSync
(
pdf
.
save
());
});
}
...
...
Please
register
or
login
to post a comment