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
2020-02-02 19:33:52 -0500
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
eae822d5362893cd2090a4f70e13f64f7cec833d
eae822d5
1 parent
3b6f6134
Add more font drawing options
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
85 additions
and
9 deletions
pdf/CHANGELOG.md
pdf/lib/src/graphics.dart
pdf/lib/src/ttffont.dart
pdf/lib/src/unicode_cmap.dart
pdf/lib/widgets/font.dart
pdf/lib/widgets/text.dart
pdf/lib/widgets/text_style.dart
pdf/CHANGELOG.md
View file @
eae822d
...
...
@@ -8,6 +8,7 @@
-
Fix Bullet widget styling
-
Fix HSV and HSL Color constructors
-
Add PageTheme.copyWith
-
Add more font drawing options
## 1.4.1
...
...
pdf/lib/src/graphics.dart
View file @
eae822d
...
...
@@ -20,6 +20,32 @@ part of pdf;
enum
PdfLineCap
{
joinMiter
,
joinRound
,
joinBevel
}
enum
PdfTextRenderingMode
{
/// Fill text
fill
,
/// Stroke text
stroke
,
/// Fill, then stroke text
fillAndStroke
,
/// Neither fill nor stroke text (invisible)
invisible
,
/// Fill text and add to path for clipping
fillAndClip
,
/// Stroke text and add to path for clipping
strokeAndClip
,
/// Fill, then stroke text and add to path for clipping
fillStrokeAndClip
,
/// Add text to path for clipping
clip
}
@immutable
class
_PdfGraphicsContext
{
const
_PdfGraphicsContext
({
@required
this
.
ctm
})
:
assert
(
ctm
!=
null
);
...
...
@@ -213,7 +239,18 @@ class PdfGraphics {
/// @param x coordinate
/// @param y coordinate
/// @param s String to draw
void
drawString
(
PdfFont
font
,
double
size
,
String
s
,
double
x
,
double
y
)
{
void
drawString
(
PdfFont
font
,
double
size
,
String
s
,
double
x
,
double
y
,
{
double
charSpace
=
0
,
double
wordSpace
=
0
,
double
scale
=
1
,
PdfTextRenderingMode
mode
=
PdfTextRenderingMode
.
fill
,
double
rise
=
0
,
})
{
if
(!
page
.
fonts
.
containsKey
(
font
.
name
))
{
page
.
fonts
[
font
.
name
]
=
font
;
}
...
...
@@ -223,8 +260,28 @@ class PdfGraphics {
buf
.
putString
(
' Td
${font.name}
'
);
buf
.
putNum
(
size
);
buf
.
putString
(
' Tf '
);
if
(
charSpace
!=
0
)
{
buf
.
putNum
(
charSpace
);
buf
.
putString
(
' Tc '
);
}
if
(
wordSpace
!=
0
)
{
buf
.
putNum
(
wordSpace
);
buf
.
putString
(
' Tw '
);
}
if
(
scale
!=
1
)
{
buf
.
putNum
(
scale
*
100
);
buf
.
putString
(
' Tz '
);
}
if
(
rise
!=
0
)
{
buf
.
putNum
(
rise
);
buf
.
putString
(
' Ts '
);
}
if
(
mode
!=
PdfTextRenderingMode
.
fill
)
{
buf
.
putString
(
'
${mode.index}
Tr '
);
}
buf
.
putString
(
'['
);
buf
.
putStream
(
font
.
putText
(
s
));
buf
.
putString
(
'
Tj
ET
\n
'
);
buf
.
putString
(
'
]TJ
ET
\n
'
);
}
/// Sets the color for drawing
...
...
pdf/lib/src/ttffont.dart
View file @
eae822d
...
...
@@ -20,11 +20,11 @@ part of pdf;
class
PdfTtfFont
extends
PdfFont
{
/// Constructs a [PdfTtfFont]
PdfTtfFont
(
PdfDocument
pdfDocument
,
ByteData
bytes
)
PdfTtfFont
(
PdfDocument
pdfDocument
,
ByteData
bytes
,
{
bool
protect
=
false
}
)
:
font
=
TtfParser
(
bytes
),
super
.
_create
(
pdfDocument
,
subtype:
'/TrueType'
)
{
file
=
PdfObjectStream
(
pdfDocument
,
isBinary:
true
);
unicodeCMap
=
PdfUnicodeCmap
(
pdfDocument
);
unicodeCMap
=
PdfUnicodeCmap
(
pdfDocument
,
protect
);
descriptor
=
PdfFontDescriptor
(
this
,
file
);
widthsObject
=
PdfArrayObject
(
pdfDocument
,
<
String
>[]);
}
...
...
pdf/lib/src/unicode_cmap.dart
View file @
eae822d
...
...
@@ -19,12 +19,18 @@
part of
pdf
;
class
PdfUnicodeCmap
extends
PdfObjectStream
{
PdfUnicodeCmap
(
PdfDocument
pdfDocument
)
:
super
(
pdfDocument
);
PdfUnicodeCmap
(
PdfDocument
pdfDocument
,
this
.
protect
)
:
super
(
pdfDocument
);
final
List
<
int
>
cmap
=
<
int
>[
0
];
final
bool
protect
;
@override
void
_prepare
()
{
if
(
protect
)
{
cmap
.
fillRange
(
1
,
cmap
.
length
,
0x20
);
}
buf
.
putString
(
'/CIDInit/ProcSet findresource begin
\n
'
'12 dict begin
\n
'
'begincmap
\n
'
...
...
pdf/lib/widgets/font.dart
View file @
eae822d
...
...
@@ -144,13 +144,15 @@ class Font {
}
class
TtfFont
extends
Font
{
TtfFont
(
this
.
data
);
TtfFont
(
this
.
data
,
{
this
.
protect
=
false
}
);
final
ByteData
data
;
final
bool
protect
;
@override
PdfFont
buildFont
(
PdfDocument
pdfDocument
)
{
return
PdfTtfFont
(
pdfDocument
,
data
);
return
PdfTtfFont
(
pdfDocument
,
data
,
protect:
protect
);
}
@override
...
...
pdf/lib/widgets/text.dart
View file @
eae822d
...
...
@@ -222,7 +222,9 @@ class _Word extends _Span {
style
.
fontSize
*
textScaleFactor
,
text
,
point
.
x
+
offset
.
x
,
point
.
y
+
offset
.
y
);
point
.
y
+
offset
.
y
,
mode:
style
.
renderingMode
,
);
}
@override
...
...
pdf/lib/widgets/text_style.dart
View file @
eae822d
...
...
@@ -112,6 +112,7 @@ class TextStyle {
this
.
decorationColor
,
this
.
decorationStyle
,
this
.
decorationThickness
,
this
.
renderingMode
,
})
:
assert
(
inherit
||
color
!=
null
),
assert
(
inherit
||
fontNormal
!=
null
),
assert
(
inherit
||
fontBold
!=
null
),
...
...
@@ -127,6 +128,7 @@ class TextStyle {
assert
(
inherit
||
decoration
!=
null
),
assert
(
inherit
||
decorationStyle
!=
null
),
assert
(
inherit
||
decorationThickness
!=
null
),
assert
(
inherit
||
renderingMode
!=
null
),
fontNormal
=
fontNormal
??
(
fontStyle
!=
FontStyle
.
italic
&&
fontWeight
!=
FontWeight
.
bold
?
font
...
...
@@ -163,6 +165,7 @@ class TextStyle {
decorationColor:
null
,
decorationStyle:
TextDecorationStyle
.
solid
,
decorationThickness:
1
,
renderingMode:
PdfTextRenderingMode
.
fill
,
);
}
...
...
@@ -210,6 +213,8 @@ class TextStyle {
final
double
decorationThickness
;
final
PdfTextRenderingMode
renderingMode
;
TextStyle
copyWith
({
PdfColor
color
,
Font
font
,
...
...
@@ -229,6 +234,7 @@ class TextStyle {
PdfColor
decorationColor
,
TextDecorationStyle
decorationStyle
,
double
decorationThickness
,
PdfTextRenderingMode
renderingMode
,
})
{
return
TextStyle
(
inherit:
inherit
,
...
...
@@ -250,6 +256,7 @@ class TextStyle {
decorationColor:
decorationColor
??
this
.
decorationColor
,
decorationStyle:
decorationStyle
??
this
.
decorationStyle
,
decorationThickness:
decorationThickness
??
this
.
decorationThickness
,
renderingMode:
renderingMode
??
this
.
renderingMode
,
);
}
...
...
@@ -342,6 +349,7 @@ class TextStyle {
decorationColor:
other
.
decorationColor
,
decorationStyle:
other
.
decorationStyle
,
decorationThickness:
other
.
decorationThickness
,
renderingMode:
other
.
renderingMode
,
);
}
...
...
@@ -370,5 +378,5 @@ class TextStyle {
@override
String
toString
()
=>
'TextStyle(color:
$color
font:
$font
size:
$fontSize
weight:
$fontWeight
style:
$fontStyle
letterSpacing:
$letterSpacing
wordSpacing:
$wordSpacing
lineSpacing:
$lineSpacing
height:
$height
background:
$background
decoration:
$decoration
decorationColor:
$decorationColor
decorationStyle:
$decorationStyle
decorationThickness:
$decorationThickness
)'
;
'TextStyle(color:
$color
font:
$font
size:
$fontSize
weight:
$fontWeight
style:
$fontStyle
letterSpacing:
$letterSpacing
wordSpacing:
$wordSpacing
lineSpacing:
$lineSpacing
height:
$height
background:
$background
decoration:
$decoration
decorationColor:
$decorationColor
decorationStyle:
$decorationStyle
decorationThickness:
$decorationThickness
, renderingMode:
$renderingMode
)'
;
}
...
...
Please
register
or
login
to post a comment