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-04-29 08:59:54 -0400
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
00c1734b545a985b93dd191b5a6e303ec0ad141e
00c1734b
1 parent
eb0dc554
Fix PdfColors.fromHex()
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
87 additions
and
14 deletions
pdf/CHANGELOG.md
pdf/lib/src/color.dart
pdf/test/colors_test.dart
pdf/test/widget_table_test.dart
test/golden/colors.pdf
test/golden/widgets-chart.pdf
test/golden/widgets-table.pdf
pdf/CHANGELOG.md
View file @
00c1734
...
...
@@ -4,6 +4,7 @@
-
Improve Table.fromTextArray()
-
Add curved LineDataSet Chart
-
Fix PdfColors.fromHex()
## 1.7.1
...
...
pdf/lib/src/color.dart
View file @
00c1734
...
...
@@ -19,27 +19,56 @@
part of
pdf
;
class
PdfColor
{
/// Create a color with red, green, blue and alpha components
/// values between 0 and 1
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
);
/// Return a color with: 0xAARRGGBB
const
PdfColor
.
fromInt
(
int
color
)
:
red
=
(
color
>>
16
&
0xff
)
/
255.0
,
green
=
(
color
>>
8
&
0xff
)
/
255.0
,
blue
=
(
color
&
0xff
)
/
255.0
,
alpha
=
(
color
>>
24
&
0xff
)
/
255.0
;
/// Can parse colors in the form:
/// * #RRGGBBAA
/// * #RRGGBB
/// * #RGB
/// * RRGGBBAA
/// * RRGGBB
/// * RGB
factory
PdfColor
.
fromHex
(
String
color
)
{
if
(
color
.
startsWith
(
'#'
))
{
color
=
color
.
substring
(
1
);
}
return
PdfColor
(
(
int
.
parse
(
color
.
substring
(
0
,
1
),
radix:
16
)
>>
16
&
0xff
)
/
255.0
,
(
int
.
parse
(
color
.
substring
(
2
,
3
),
radix:
16
)
>>
8
&
0xff
)
/
255.0
,
(
int
.
parse
(
color
.
substring
(
4
,
5
),
radix:
16
)
&
0xff
)
/
255.0
,
(
int
.
parse
(
color
.
substring
(
6
,
7
),
radix:
16
)
>>
24
&
0xff
)
/
255.0
);
double
red
;
double
green
;
double
blue
;
double
alpha
=
1
;
if
(
color
.
length
==
3
)
{
red
=
int
.
parse
(
color
.
substring
(
0
,
1
)
*
2
,
radix:
16
)
/
255
;
green
=
int
.
parse
(
color
.
substring
(
1
,
2
)
*
2
,
radix:
16
)
/
255
;
blue
=
int
.
parse
(
color
.
substring
(
2
,
3
)
*
2
,
radix:
16
)
/
255
;
return
PdfColor
(
red
,
green
,
blue
,
alpha
);
}
assert
(
color
.
length
==
3
||
color
.
length
==
6
||
color
.
length
==
8
);
red
=
int
.
parse
(
color
.
substring
(
0
,
2
),
radix:
16
)
/
255
;
green
=
int
.
parse
(
color
.
substring
(
2
,
4
),
radix:
16
)
/
255
;
blue
=
int
.
parse
(
color
.
substring
(
4
,
6
),
radix:
16
)
/
255
;
if
(
color
.
length
==
8
)
{
alpha
=
int
.
parse
(
color
.
substring
(
6
,
8
),
radix:
16
)
/
255
;
}
return
PdfColor
(
red
,
green
,
blue
,
alpha
);
}
factory
PdfColor
.
fromRYB
(
double
red
,
double
yellow
,
double
blue
,
...
...
@@ -113,7 +142,12 @@ class PdfColor {
(((
blue
*
255.0
).
round
()
&
0xff
)
<<
0
))
&
0xFFFFFFFF
;
String
toHex
()
=>
'#'
+
toInt
().
toRadixString
(
16
);
String
toHex
()
{
final
int
i
=
toInt
();
final
String
rgb
=
(
i
&
0xffffff
).
toRadixString
(
16
);
final
String
a
=
((
i
&
0xff000000
)
>>
24
).
toRadixString
(
16
);
return
'#
$rgb$a
'
;
}
PdfColorCmyk
toCmyk
()
{
return
PdfColorCmyk
.
fromRgb
(
red
,
green
,
blue
,
alpha
);
...
...
pdf/test/colors_test.dart
View file @
00c1734
...
...
@@ -45,7 +45,7 @@ class Color extends StatelessWidget {
children:
<
Widget
>[
Text
(
name
,
style:
style
),
Text
(
varient
??
''
,
style:
style
),
Padding
(
padding:
const
EdgeInsets
.
all
(
2
*
PdfPageFormat
.
mm
)
),
SizedBox
(
height:
4
*
PdfPageFormat
.
mm
),
Text
(
color
.
toHex
(),
style:
hexStyle
),
Row
(
mainAxisSize:
MainAxisSize
.
max
,
...
...
@@ -709,6 +709,44 @@ void main() {
]));
});
group
(
'Pdf Colors Conversions'
,
()
{
test
(
'fromHex #RRGGBBAA'
,
()
{
final
PdfColor
c
=
PdfColor
.
fromHex
(
'#12345678'
);
expect
(
c
.
red
,
0x12
/
255
);
expect
(
c
.
green
,
0x34
/
255
);
expect
(
c
.
blue
,
0x56
/
255
);
expect
(
c
.
alpha
,
0x78
/
255
);
});
test
(
'fromHex RRGGBBAA'
,
()
{
final
PdfColor
c
=
PdfColor
.
fromHex
(
'12345678'
);
expect
(
c
.
red
,
0x12
/
255
);
expect
(
c
.
green
,
0x34
/
255
);
expect
(
c
.
blue
,
0x56
/
255
);
expect
(
c
.
alpha
,
0x78
/
255
);
});
test
(
'fromHex RRGGBB'
,
()
{
final
PdfColor
c
=
PdfColor
.
fromHex
(
'123456'
);
expect
(
c
.
red
,
0x12
/
255
);
expect
(
c
.
green
,
0x34
/
255
);
expect
(
c
.
blue
,
0x56
/
255
);
expect
(
c
.
alpha
,
1
);
});
test
(
'fromHex RGB'
,
()
{
final
PdfColor
c
=
PdfColor
.
fromHex
(
'18f'
);
expect
(
c
.
red
,
0x11
/
255
);
expect
(
c
.
green
,
0x88
/
255
);
expect
(
c
.
blue
,
0xff
/
255
);
expect
(
c
.
alpha
,
1
);
});
test
(
'toHex RGB'
,
()
{
expect
(
PdfColor
.
fromHex
(
'#12345678'
).
toHex
(),
'#12345678'
);
});
});
tearDownAll
(()
{
final
File
file
=
File
(
'colors.pdf'
);
file
.
writeAsBytesSync
(
pdf
.
save
());
...
...
pdf/test/widget_table_test.dart
View file @
00c1734
...
...
@@ -31,7 +31,7 @@ List<TableRow> buildTable(
final
List
<
TableRow
>
rows
=
<
TableRow
>[];
{
final
List
<
Widget
>
tableRow
=
<
Widget
>[];
for
(
String
cell
in
<
String
>[
'Hue'
,
'Color'
,
'
ARGB
'
])
{
for
(
String
cell
in
<
String
>[
'Hue'
,
'Color'
,
'
RGBA
'
])
{
tableRow
.
add
(
Container
(
alignment:
Alignment
.
center
,
margin:
const
EdgeInsets
.
all
(
5
),
...
...
test/golden/colors.pdf
View file @
00c1734
No preview for this file type
test/golden/widgets-chart.pdf
View file @
00c1734
No preview for this file type
test/golden/widgets-table.pdf
View file @
00c1734
No preview for this file type
Please
register
or
login
to post a comment