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-06-15 09:54:13 -0400
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
5f6123a322033cdff8a336f6a5d5647eac53e434
5f6123a3
1 parent
21077927
Fix TextStyle constructor
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
133 additions
and
21 deletions
pdf/CHANGELOG.md
pdf/lib/widgets/text.dart
pdf/lib/widgets/theme.dart
pdf/pubspec.yaml
pdf/test/all_tests.dart
pdf/test/widget_test.dart
pdf/test/widget_theme_test.dart
pdf/CHANGELOG.md
View file @
5f6123a
# 1.3.12
*
Fix TextStyle constructor
# 1.3.11
*
Update Readme
...
...
pdf/lib/widgets/text.dart
View file @
5f6123a
...
...
@@ -179,7 +179,7 @@ class RichText extends Widget {
return
true
;
}
final
PdfFont
font
=
style
.
paintF
ont
.
getFont
(
context
);
final
PdfFont
font
=
style
.
f
ont
.
getFont
(
context
);
final
PdfFontMetrics
space
=
font
.
stringMetrics
(
' '
)
*
(
style
.
fontSize
*
textScaleFactor
);
...
...
@@ -322,7 +322,7 @@ class RichText extends Widget {
}
context
.
canvas
.
drawString
(
currentStyle
.
paintF
ont
.
getFont
(
context
),
currentStyle
.
f
ont
.
getFont
(
context
),
currentStyle
.
fontSize
*
textScaleFactor
,
word
.
text
,
box
.
x
+
word
.
offset
.
x
,
...
...
pdf/lib/widgets/theme.dart
View file @
5f6123a
...
...
@@ -25,10 +25,11 @@ class TextStyle {
const
TextStyle
({
this
.
inherit
=
true
,
this
.
color
,
this
.
font
,
this
.
fontBold
,
this
.
fontItalic
,
this
.
fontBoldItalic
,
Font
font
,
Font
fontNormal
,
Font
fontBold
,
Font
fontItalic
,
Font
fontBoldItalic
,
this
.
fontSize
,
this
.
fontWeight
,
this
.
fontStyle
,
...
...
@@ -45,12 +46,28 @@ class TextStyle {
assert
(
inherit
||
letterSpacing
!=
null
),
assert
(
inherit
||
wordSpacing
!=
null
),
assert
(
inherit
||
lineSpacing
!=
null
),
assert
(
inherit
||
height
!=
null
);
assert
(
inherit
||
height
!=
null
),
fontNormal
=
fontNormal
??
(
fontStyle
!=
FontStyle
.
italic
&&
fontWeight
!=
FontWeight
.
bold
?
font
:
null
),
fontBold
=
fontBold
??
(
fontStyle
!=
FontStyle
.
italic
&&
fontWeight
==
FontWeight
.
bold
?
font
:
null
),
fontItalic
=
fontItalic
??
(
fontStyle
==
FontStyle
.
italic
&&
fontWeight
!=
FontWeight
.
bold
?
font
:
null
),
fontBoldItalic
=
fontBoldItalic
??
(
fontStyle
==
FontStyle
.
italic
&&
fontWeight
==
FontWeight
.
bold
?
font
:
null
);
factory
TextStyle
.
defaultStyle
()
{
return
TextStyle
(
color:
PdfColors
.
black
,
font:
Font
.
helvetica
(),
font
Normal
:
Font
.
helvetica
(),
fontBold:
Font
.
helveticaBold
(),
fontItalic:
Font
.
helveticaOblique
(),
fontBoldItalic:
Font
.
helveticaBoldOblique
(),
...
...
@@ -68,7 +85,7 @@ class TextStyle {
final
PdfColor
color
;
final
Font
font
;
final
Font
font
Normal
;
final
Font
fontBold
;
...
...
@@ -103,6 +120,7 @@ class TextStyle {
TextStyle
copyWith
({
PdfColor
color
,
Font
font
,
Font
fontNormal
,
Font
fontBold
,
Font
fontItalic
,
Font
fontBoldItalic
,
...
...
@@ -119,6 +137,7 @@ class TextStyle {
inherit:
inherit
,
color:
color
??
this
.
color
,
font:
font
??
this
.
font
,
fontNormal:
fontNormal
??
this
.
fontNormal
,
fontBold:
fontBold
??
this
.
fontBold
,
fontItalic:
fontItalic
??
this
.
fontItalic
,
fontBoldItalic:
fontBoldItalic
??
this
.
fontBoldItalic
,
...
...
@@ -138,6 +157,7 @@ class TextStyle {
TextStyle
apply
({
PdfColor
color
,
Font
font
,
Font
fontNormal
,
Font
fontBold
,
Font
fontItalic
,
Font
fontBoldItalic
,
...
...
@@ -169,6 +189,7 @@ class TextStyle {
inherit:
inherit
,
color:
color
??
this
.
color
,
font:
font
??
this
.
font
,
fontNormal:
fontNormal
??
this
.
fontNormal
,
fontBold:
fontBold
??
this
.
fontBold
,
fontItalic:
fontItalic
??
this
.
fontItalic
,
fontBoldItalic:
fontBoldItalic
??
this
.
fontBoldItalic
,
...
...
@@ -201,6 +222,8 @@ class TextStyle {
return
copyWith
(
color:
other
.
color
,
font:
other
.
font
,
fontNormal:
other
.
fontNormal
,
fontBold:
other
.
fontBold
,
fontItalic:
other
.
fontItalic
,
fontBoldItalic:
other
.
fontBoldItalic
,
fontSize:
other
.
fontSize
,
...
...
@@ -214,25 +237,32 @@ class TextStyle {
);
}
Font
get
paintFont
{
if
(
fontWeight
==
FontWeight
.
normal
)
{
if
(
fontStyle
==
FontStyle
.
normal
)
{
return
font
;
@Deprecated
(
'use font instead'
)
Font
get
paintFont
=>
font
;
Font
get
font
{
if
(
fontWeight
!=
FontWeight
.
bold
)
{
if
(
fontStyle
!=
FontStyle
.
italic
)
{
// normal
return
fontNormal
??
fontBold
??
fontItalic
??
fontBoldItalic
;
}
else
{
return
fontItalic
??
font
;
// italic
return
fontItalic
??
fontNormal
??
fontBold
??
fontBoldItalic
;
}
}
else
{
if
(
fontStyle
==
FontStyle
.
normal
)
{
return
fontBold
??
font
;
if
(
fontStyle
!=
FontStyle
.
italic
)
{
// bold
return
fontBold
??
fontNormal
??
fontItalic
??
fontBoldItalic
;
}
else
{
return
fontBoldItalic
??
fontBold
??
fontItalic
??
font
;
// bold + italic
return
fontBoldItalic
??
fontBold
??
fontItalic
??
fontNormal
;
}
}
}
@override
String
toString
()
=>
'TextStyle(color:
$color
font:
$
paintF
ont
size:
$fontSize
weight:
$fontWeight
style:
$fontStyle
letterSpacing:
$letterSpacing
wordSpacing:
$wordSpacing
lineSpacing:
$lineSpacing
height:
$height
background:
$background
)'
;
'TextStyle(color:
$color
font:
$
f
ont
size:
$fontSize
weight:
$fontWeight
style:
$fontStyle
letterSpacing:
$letterSpacing
wordSpacing:
$wordSpacing
lineSpacing:
$lineSpacing
height:
$height
background:
$background
)'
;
}
@immutable
...
...
pdf/pubspec.yaml
View file @
5f6123a
...
...
@@ -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
:
1.3.1
1
version
:
1.3.1
2
environment
:
sdk
:
"
>=2.1.0
<3.0.0"
...
...
pdf/test/all_tests.dart
View file @
5f6123a
...
...
@@ -31,11 +31,13 @@ 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
;
import
'widget_theme_test.dart'
as
widget_theme
;
void
main
(
)
{
annotations
.
main
();
colors
.
main
();
complex
.
main
();
example
.
main
();
jpeg
.
main
();
metrics
.
main
();
minimal
.
main
();
...
...
@@ -46,6 +48,6 @@ void main() {
widget_container
.
main
();
widget_table
.
main
();
widget_text
.
main
();
widget_theme
.
main
();
widget
.
main
();
example
.
main
();
}
...
...
pdf/test/widget_test.dart
View file @
5f6123a
...
...
@@ -175,7 +175,7 @@ void main() {
text:
'Hello '
,
style:
Theme
.
of
(
context
).
defaultTextStyle
,
children:
<
TextSpan
>[
const
TextSpan
(
TextSpan
(
text:
'bold'
,
style:
TextStyle
(
fontWeight:
FontWeight
.
bold
,
...
...
pdf/test/widget_theme_test.dart
0 → 100644
View file @
5f6123a
/*
* 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:typed_data'
;
import
'package:pdf/pdf.dart'
;
import
'package:test/test.dart'
;
import
'package:pdf/widgets.dart'
;
Document
pdf
;
Font
openSans
;
Font
openSansBold
;
Font
roboto
;
Font
notoSans
;
Font
genyomintw
;
Font
loadFont
(
String
filename
)
{
final
Uint8List
data
=
File
(
filename
).
readAsBytesSync
();
return
Font
.
ttf
(
data
.
buffer
.
asByteData
());
}
void
main
(
)
{
setUpAll
(()
{
Document
.
debug
=
true
;
RichText
.
debug
=
true
;
openSans
=
loadFont
(
'open-sans.ttf'
);
openSansBold
=
loadFont
(
'open-sans-bold.ttf'
);
roboto
=
loadFont
(
'roboto.ttf'
);
notoSans
=
loadFont
(
'noto-sans.ttf'
);
genyomintw
=
loadFont
(
'genyomintw.ttf'
);
pdf
=
Document
();
});
test
(
'Theme FontStyle'
,
()
{
final
TextStyle
style
=
TextStyle
(
font:
roboto
,
fontBold:
openSansBold
,
fontNormal:
openSans
,
fontItalic:
notoSans
,
fontBoldItalic:
genyomintw
,
fontWeight:
FontWeight
.
bold
,
fontSize:
20
,
color:
PdfColors
.
blue
);
pdf
.
addPage
(
Page
(
build:
(
Context
context
)
=>
ListView
(
children:
<
Widget
>[
Text
(
style
.
font
.
fontName
,
style:
style
,
),
],
),
));
});
tearDownAll
(()
{
final
File
file
=
File
(
'widgets-theme.pdf'
);
file
.
writeAsBytesSync
(
pdf
.
save
());
});
}
...
...
Please
register
or
login
to post a comment