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-03-03 13:45:27 -0500
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
924ff54388d91c25886f719848d874a57c180672
924ff543
1 parent
6dd169b5
Add some color functions
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
182 additions
and
85 deletions
pdf/CHANGELOG.md
pdf/lib/src/color.dart
pdf/lib/src/compatibility.dart
pdf/lib/src/graphics.dart
pdf/pubspec.yaml
pdf/test/colors.dart
pdf/CHANGELOG.md
View file @
924ff54
# 1.3.5
*
Add some color functions
*
Remove color constants from PdfColor, use PdfColors
# 1.3.4
*
Add available dimensions for PdfPageFormat
*
Add Document properties
...
...
pdf/lib/src/color.dart
View file @
924ff54
...
...
@@ -17,13 +17,17 @@
part of
pdf
;
class
PdfColor
{
const
PdfColor
(
this
.
r
,
this
.
g
,
this
.
b
,
[
this
.
a
=
1.0
]);
const
PdfColor
(
this
.
red
,
this
.
green
,
this
.
blue
,
[
this
.
alpha
=
1.0
])
:
assert
(
red
>=
0
&&
red
<=
1
),
assert
(
green
>=
0
&&
green
<=
1
),
assert
(
blue
>=
0
&&
blue
<=
1
),
assert
(
alpha
>=
0
&&
alpha
<=
1
);
const
PdfColor
.
fromInt
(
int
color
)
:
r
=
(
color
>>
16
&
0xff
)
/
255.0
,
g
=
(
color
>>
8
&
0xff
)
/
255.0
,
b
=
(
color
&
0xff
)
/
255.0
,
a
=
(
color
>>
24
&
0xff
)
/
255.0
;
:
red
=
(
color
>>
16
&
0xff
)
/
255.0
,
green
=
(
color
>>
8
&
0xff
)
/
255.0
,
blue
=
(
color
&
0xff
)
/
255.0
,
alpha
=
(
color
>>
24
&
0xff
)
/
255.0
;
factory
PdfColor
.
fromHex
(
String
color
)
{
if
(
color
.
startsWith
(
'#'
))
{
...
...
@@ -36,73 +40,30 @@ class PdfColor {
(
int
.
parse
(
color
.
substring
(
6
,
7
),
radix:
16
)
>>
24
&
0xff
)
/
255.0
);
}
final
double
a
;
final
double
r
;
final
double
g
;
final
double
b
;
@deprecated
static
const
PdfColor
black
=
PdfColors
.
black
;
@deprecated
static
const
PdfColor
white
=
PdfColors
.
white
;
@deprecated
static
const
PdfColor
red
=
PdfColors
.
red
;
@deprecated
static
const
PdfColor
pink
=
PdfColors
.
pink
;
@deprecated
static
const
PdfColor
purple
=
PdfColors
.
purple
;
@deprecated
static
const
PdfColor
deepPurple
=
PdfColors
.
deepPurple
;
@deprecated
static
const
PdfColor
indigo
=
PdfColors
.
indigo
;
@deprecated
static
const
PdfColor
blue
=
PdfColors
.
blue
;
@deprecated
static
const
PdfColor
lightBlue
=
PdfColors
.
lightBlue
;
@deprecated
static
const
PdfColor
cyan
=
PdfColors
.
cyan
;
@deprecated
static
const
PdfColor
teal
=
PdfColors
.
teal
;
@deprecated
static
const
PdfColor
green
=
PdfColors
.
green
;
@deprecated
static
const
PdfColor
lightGreen
=
PdfColors
.
lightGreen
;
@deprecated
static
const
PdfColor
lime
=
PdfColors
.
lime
;
@deprecated
static
const
PdfColor
yellow
=
PdfColors
.
yellow
;
@deprecated
static
const
PdfColor
amber
=
PdfColors
.
amber
;
@deprecated
static
const
PdfColor
orange
=
PdfColors
.
orange
;
@deprecated
static
const
PdfColor
deepOrange
=
PdfColors
.
deepOrange
;
@deprecated
static
const
PdfColor
brown
=
PdfColors
.
brown
;
@deprecated
static
const
PdfColor
grey
=
PdfColors
.
grey
;
@deprecated
static
const
PdfColor
blueGrey
=
PdfColors
.
blueGrey
;
final
double
alpha
;
final
double
red
;
final
double
green
;
final
double
blue
;
int
toInt
()
=>
((((
a
*
255.0
).
round
()
&
0xff
)
<<
24
)
|
(((
r
*
255.0
).
round
()
&
0xff
)
<<
16
)
|
(((
g
*
255.0
).
round
()
&
0xff
)
<<
8
)
|
(((
b
*
255.0
).
round
()
&
0xff
)
<<
0
))
&
((((
alpha
*
255.0
).
round
()
&
0xff
)
<<
24
)
|
(((
red
*
255.0
).
round
()
&
0xff
)
<<
16
)
|
(((
green
*
255.0
).
round
()
&
0xff
)
<<
8
)
|
(((
blue
*
255.0
).
round
()
&
0xff
)
<<
0
))
&
0xFFFFFFFF
;
String
toHex
()
=>
'#'
+
toInt
().
toRadixString
(
16
);
PdfColorCmyk
toCmyk
()
{
return
PdfColorCmyk
.
fromRgb
(
r
,
g
,
b
,
a
);
return
PdfColorCmyk
.
fromRgb
(
r
ed
,
green
,
blue
,
alph
a
);
}
PdfColorHsv
toHsv
()
{
return
PdfColorHsv
.
fromRgb
(
r
,
g
,
b
,
a
);
return
PdfColorHsv
.
fromRgb
(
r
ed
,
green
,
blue
,
alph
a
);
}
PdfColorHsl
toHsl
()
{
return
PdfColorHsl
.
fromRgb
(
r
,
g
,
b
,
a
);
return
PdfColorHsl
.
fromRgb
(
r
ed
,
green
,
blue
,
alph
a
);
}
static
double
_linearizeColorComponent
(
double
component
)
{
...
...
@@ -113,35 +74,50 @@ class PdfColor {
}
double
get
luminance
{
final
double
R
=
_linearizeColorComponent
(
r
);
final
double
G
=
_linearizeColorComponent
(
g
);
final
double
B
=
_linearizeColorComponent
(
b
);
final
double
R
=
_linearizeColorComponent
(
red
);
final
double
G
=
_linearizeColorComponent
(
green
);
final
double
B
=
_linearizeColorComponent
(
blue
);
return
0.2126
*
R
+
0.7152
*
G
+
0.0722
*
B
;
}
/// Get a complementary color with hue shifted by -120°
PdfColor
get
complementary
=>
toHsv
().
complementary
;
/// Get some similar colors
List
<
PdfColor
>
get
monochromatic
=>
toHsv
().
monochromatic
;
List
<
PdfColor
>
get
splitcomplementary
=>
toHsv
().
splitcomplementary
;
List
<
PdfColor
>
get
tetradic
=>
toHsv
().
tetradic
;
List
<
PdfColor
>
get
triadic
=>
toHsv
().
triadic
;
List
<
PdfColor
>
get
analagous
=>
toHsv
().
analagous
;
@override
String
toString
()
=>
'
$runtimeType
(
$r
,
$g
,
$b
,
$
a
)'
;
String
toString
()
=>
'
$runtimeType
(
$r
ed
,
$green
,
$blue
,
$alph
a
)'
;
}
class
PdfColorCmyk
extends
PdfColor
{
const
PdfColorCmyk
(
this
.
c
,
this
.
m
,
this
.
y
,
this
.
k
,
[
double
a
=
1.0
])
:
super
((
1.0
-
c
)
*
(
1.0
-
k
),
(
1.0
-
m
)
*
(
1.0
-
k
),
(
1.0
-
y
)
*
(
1.0
-
k
),
a
);
const
PdfColorCmyk
(
this
.
cyan
,
this
.
magenta
,
this
.
yellow
,
this
.
black
,
[
double
a
=
1.0
])
:
super
((
1.0
-
cyan
)
*
(
1.0
-
black
),
(
1.0
-
magenta
)
*
(
1.0
-
black
),
(
1.0
-
yellow
)
*
(
1.0
-
black
),
a
);
const
PdfColorCmyk
.
fromRgb
(
double
r
,
double
g
,
double
b
,
[
double
a
=
1.0
])
:
k
=
1.0
-
r
>
g
?
r
:
g
>
b
?
r
>
g
?
r
:
g
:
b
,
c
=
(
1.0
-
r
-
(
1.0
-
r
>
g
?
r
:
g
>
b
?
r
>
g
?
r
:
g
:
b
))
/
:
black
=
1.0
-
r
>
g
?
r
:
g
>
b
?
r
>
g
?
r
:
g
:
b
,
cyan
=
(
1.0
-
r
-
(
1.0
-
r
>
g
?
r
:
g
>
b
?
r
>
g
?
r
:
g
:
b
))
/
(
1.0
-
(
1.0
-
r
>
g
?
r
:
g
>
b
?
r
>
g
?
r
:
g
:
b
)),
m
=
(
1.0
-
g
-
(
1.0
-
r
>
g
?
r
:
g
>
b
?
r
>
g
?
r
:
g
:
b
))
/
m
agenta
=
(
1.0
-
g
-
(
1.0
-
r
>
g
?
r
:
g
>
b
?
r
>
g
?
r
:
g
:
b
))
/
(
1.0
-
(
1.0
-
r
>
g
?
r
:
g
>
b
?
r
>
g
?
r
:
g
:
b
)),
y
=
(
1.0
-
b
-
(
1.0
-
r
>
g
?
r
:
g
>
b
?
r
>
g
?
r
:
g
:
b
))
/
y
ellow
=
(
1.0
-
b
-
(
1.0
-
r
>
g
?
r
:
g
>
b
?
r
>
g
?
r
:
g
:
b
))
/
(
1.0
-
(
1.0
-
r
>
g
?
r
:
g
>
b
?
r
>
g
?
r
:
g
:
b
)),
super
(
r
,
g
,
b
,
a
);
final
double
c
;
final
double
m
;
final
double
y
;
final
double
k
;
final
double
cyan
;
final
double
magenta
;
final
double
yellow
;
final
double
black
;
@override
PdfColorCmyk
toCmyk
()
{
...
...
@@ -149,7 +125,7 @@ class PdfColorCmyk extends PdfColor {
}
@override
String
toString
()
=>
'
$runtimeType
(
$c
,
$m
,
$y
,
$k
,
$
a
)'
;
String
toString
()
=>
'
$runtimeType
(
$c
yan
,
$magenta
,
$yellow
,
$black
,
$alph
a
)'
;
}
double
_getHue
(
...
...
@@ -170,6 +146,9 @@ double _getHue(
return
hue
;
}
/// Same as HSB, Cylindrical geometries with hue, their angular dimension,
/// starting at the red primary at 0°, passing through the green primary
/// at 120° and the blue primary at 240°, and then wrapping back to red at 360°
class
PdfColorHsv
extends
PdfColor
{
factory
PdfColorHsv
(
double
hue
,
double
saturation
,
double
value
,
[
double
alpha
=
1.0
])
{
...
...
@@ -213,7 +192,10 @@ class PdfColorHsv extends PdfColor {
const
PdfColorHsv
.
_
(
this
.
hue
,
this
.
saturation
,
this
.
value
,
double
red
,
double
green
,
double
blue
,
double
alpha
)
:
super
(
red
,
green
,
blue
,
alpha
);
:
assert
(
hue
>=
0
&&
hue
<
360
),
assert
(
saturation
>=
0
&&
saturation
<=
1
),
assert
(
value
>=
0
&&
value
<=
1
),
super
(
red
,
green
,
blue
,
alpha
);
factory
PdfColorHsv
.
fromRgb
(
double
red
,
double
green
,
double
blue
,
[
double
alpha
])
{
...
...
@@ -227,8 +209,13 @@ class PdfColorHsv extends PdfColor {
return
PdfColorHsv
.
_
(
hue
,
saturation
,
max
,
red
,
green
,
blue
,
alpha
);
}
/// Angular position the colorspace coordinate diagram in degrees from 0° to 360°
final
double
hue
;
/// Saturation of the color
final
double
saturation
;
/// Brightness
final
double
value
;
@override
...
...
@@ -236,8 +223,59 @@ class PdfColorHsv extends PdfColor {
return
this
;
}
/// Get a complementary color with hue shifted by -120°
@override
PdfColorHsv
get
complementary
=>
PdfColorHsv
((
hue
-
120
)
%
360
,
saturation
,
value
,
alpha
);
/// Get a similar color
@override
List
<
PdfColorHsv
>
get
monochromatic
=>
<
PdfColorHsv
>[
PdfColorHsv
(
hue
,
(
saturation
>
0.5
?
saturation
-
0.2
:
saturation
+
0.2
)
.
clamp
(
0
,
1
),
(
value
>
0.5
?
value
-
0.1
:
value
+
0.1
).
clamp
(
0
,
1
)),
PdfColorHsv
(
hue
,
(
saturation
>
0.5
?
saturation
-
0.4
:
saturation
+
0.4
)
.
clamp
(
0
,
1
),
(
value
>
0.5
?
value
-
0.2
:
value
+
0.2
).
clamp
(
0
,
1
)),
PdfColorHsv
(
hue
,
(
saturation
>
0.5
?
saturation
-
0.15
:
saturation
+
0.15
)
.
clamp
(
0
,
1
),
(
value
>
0.5
?
value
-
0.05
:
value
+
0.05
).
clamp
(
0
,
1
))
];
/// Get two complementary colors with hue shifted by -120°
@override
List
<
PdfColorHsv
>
get
splitcomplementary
=>
<
PdfColorHsv
>[
PdfColorHsv
((
hue
-
150
)
%
360
,
saturation
,
value
,
alpha
),
PdfColorHsv
((
hue
-
180
)
%
360
,
saturation
,
value
,
alpha
),
];
@override
List
<
PdfColorHsv
>
get
triadic
=>
<
PdfColorHsv
>[
PdfColorHsv
((
hue
+
80
)
%
360
,
saturation
,
value
,
alpha
),
PdfColorHsv
((
hue
-
120
)
%
360
,
saturation
,
value
,
alpha
),
];
@override
List
<
PdfColorHsv
>
get
tetradic
=>
<
PdfColorHsv
>[
PdfColorHsv
((
hue
+
120
)
%
360
,
saturation
,
value
,
alpha
),
PdfColorHsv
((
hue
-
150
)
%
360
,
saturation
,
value
,
alpha
),
PdfColorHsv
((
hue
+
60
)
%
360
,
saturation
,
value
,
alpha
),
];
@override
List
<
PdfColorHsv
>
get
analagous
=>
<
PdfColorHsv
>[
PdfColorHsv
((
hue
+
30
)
%
360
,
saturation
,
value
,
alpha
),
PdfColorHsv
((
hue
-
20
)
%
360
,
saturation
,
value
,
alpha
),
];
@override
String
toString
()
=>
'
$runtimeType
(
$hue
,
$saturation
,
$value
,
$a
)'
;
String
toString
()
=>
'
$runtimeType
(
$hue
,
$saturation
,
$value
,
$a
lpha
)'
;
}
class
PdfColorHsl
extends
PdfColor
{
...
...
@@ -309,5 +347,5 @@ class PdfColorHsl extends PdfColor {
}
@override
String
toString
()
=>
'
$runtimeType
(
$hue
,
$saturation
,
$lightness
,
$a
)'
;
String
toString
()
=>
'
$runtimeType
(
$hue
,
$saturation
,
$lightness
,
$a
lpha
)'
;
}
...
...
pdf/lib/src/compatibility.dart
View file @
924ff54
...
...
@@ -107,13 +107,59 @@ class PDFColor extends PdfColor {
factory
PDFColor
.
fromInt
(
int
color
)
{
final
PdfColor
c
=
PdfColor
.
fromInt
(
color
);
return
PDFColor
(
c
.
r
,
c
.
g
,
c
.
b
,
c
.
a
);
return
PDFColor
(
c
.
r
ed
,
c
.
green
,
c
.
blue
,
c
.
alph
a
);
}
factory
PDFColor
.
fromHex
(
String
color
)
{
final
PdfColor
c
=
PdfColor
.
fromHex
(
color
);
return
PDFColor
(
c
.
r
,
c
.
g
,
c
.
b
,
c
.
a
);
return
PDFColor
(
c
.
r
ed
,
c
.
green
,
c
.
blue
,
c
.
alph
a
);
}
@deprecated
static
const
PdfColor
black
=
PdfColors
.
black
;
@deprecated
static
const
PdfColor
white
=
PdfColors
.
white
;
@deprecated
static
const
PdfColor
pink
=
PdfColors
.
pink
;
@deprecated
static
const
PdfColor
purple
=
PdfColors
.
purple
;
@deprecated
static
const
PdfColor
deepPurple
=
PdfColors
.
deepPurple
;
@deprecated
static
const
PdfColor
indigo
=
PdfColors
.
indigo
;
@deprecated
static
const
PdfColor
lightBlue
=
PdfColors
.
lightBlue
;
@deprecated
static
const
PdfColor
cyan
=
PdfColors
.
cyan
;
@deprecated
static
const
PdfColor
teal
=
PdfColors
.
teal
;
@deprecated
static
const
PdfColor
lightGreen
=
PdfColors
.
lightGreen
;
@deprecated
static
const
PdfColor
lime
=
PdfColors
.
lime
;
@deprecated
static
const
PdfColor
yellow
=
PdfColors
.
yellow
;
@deprecated
static
const
PdfColor
amber
=
PdfColors
.
amber
;
@deprecated
static
const
PdfColor
orange
=
PdfColors
.
orange
;
@deprecated
static
const
PdfColor
deepOrange
=
PdfColors
.
deepOrange
;
@deprecated
static
const
PdfColor
brown
=
PdfColors
.
brown
;
@deprecated
static
const
PdfColor
grey
=
PdfColors
.
grey
;
@deprecated
static
const
PdfColor
blueGrey
=
PdfColors
.
blueGrey
;
@deprecated
double
get
r
=>
red
;
@deprecated
double
get
g
=>
green
;
@deprecated
double
get
b
=>
blue
;
}
@deprecated
...
...
pdf/lib/src/graphics.dart
View file @
924ff54
...
...
@@ -212,10 +212,11 @@ class PdfGraphics {
/// @param c Color to use
void
setFillColor
(
PdfColor
color
)
{
if
(
color
is
PdfColorCmyk
)
{
buf
.
putNumList
(<
double
>[
color
.
c
,
color
.
m
,
color
.
y
,
color
.
k
]);
buf
.
putNumList
(
<
double
>[
color
.
cyan
,
color
.
magenta
,
color
.
yellow
,
color
.
black
]);
buf
.
putString
(
' k
\n
'
);
}
else
{
buf
.
putNumList
(<
double
>[
color
.
r
,
color
.
g
,
color
.
b
]);
buf
.
putNumList
(<
double
>[
color
.
r
ed
,
color
.
green
,
color
.
blue
]);
buf
.
putString
(
' rg
\n
'
);
}
}
...
...
@@ -225,10 +226,11 @@ class PdfGraphics {
/// @param c Color to use
void
setStrokeColor
(
PdfColor
color
)
{
if
(
color
is
PdfColorCmyk
)
{
buf
.
putNumList
(<
double
>[
color
.
c
,
color
.
m
,
color
.
y
,
color
.
k
]);
buf
.
putNumList
(
<
double
>[
color
.
cyan
,
color
.
magenta
,
color
.
yellow
,
color
.
black
]);
buf
.
putString
(
' K
\n
'
);
}
else
{
buf
.
putNumList
(<
double
>[
color
.
r
,
color
.
g
,
color
.
b
]);
buf
.
putNumList
(<
double
>[
color
.
r
ed
,
color
.
green
,
color
.
blue
]);
buf
.
putString
(
' RG
\n
'
);
}
}
...
...
pdf/pubspec.yaml
View file @
924ff54
...
...
@@ -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.
4
version
:
1.3.
5
environment
:
sdk
:
"
>=2.1.0
<3.0.0"
...
...
pdf/test/colors.dart
View file @
924ff54
...
...
@@ -44,6 +44,13 @@ class Color extends StatelessWidget {
Text
(
varient
??
''
,
style:
style
),
Padding
(
padding:
const
EdgeInsets
.
all
(
2
*
PdfPageFormat
.
mm
)),
Text
(
color
.
toHex
(),
style:
hexStyle
),
Row
(
mainAxisSize:
MainAxisSize
.
max
,
mainAxisAlignment:
MainAxisAlignment
.
spaceEvenly
,
children:
color
.
monochromatic
.
map
<
Widget
>((
PdfColor
color
)
=>
Container
(
width:
30
,
height:
30
,
color:
color
))
.
toList
())
],
// )
));
...
...
Please
register
or
login
to post a comment