summaryrefslogtreecommitdiffstats
path: root/lib/Spreadsheet/ParseXLSX.pm
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2013-06-04 18:32:02 -0500
committerJesse Luehrs <doy@tozt.net>2013-06-04 18:32:02 -0500
commitd91245496d5828392dc54911ca7688c57efae4c0 (patch)
tree5d918bc31dd9e10c97f53079d84534aef49d913a /lib/Spreadsheet/ParseXLSX.pm
parent2350ee47eb2d19c6d74b052992f2f86ee5599ac6 (diff)
downloadspreadsheet-parsexlsx-d91245496d5828392dc54911ca7688c57efae4c0.tar.gz
spreadsheet-parsexlsx-d91245496d5828392dc54911ca7688c57efae4c0.zip
handle color tints
Diffstat (limited to 'lib/Spreadsheet/ParseXLSX.pm')
-rw-r--r--lib/Spreadsheet/ParseXLSX.pm22
1 files changed, 21 insertions, 1 deletions
diff --git a/lib/Spreadsheet/ParseXLSX.pm b/lib/Spreadsheet/ParseXLSX.pm
index 3e7a5c3..880d2e0 100644
--- a/lib/Spreadsheet/ParseXLSX.pm
+++ b/lib/Spreadsheet/ParseXLSX.pm
@@ -3,6 +3,7 @@ use strict;
use warnings;
use Archive::Zip;
+use Graphics::ColorUtils 'rgb2hls', 'hls2rgb';
use Scalar::Util 'openhandle';
use Spreadsheet::ParseExcel;
use XML::Twig;
@@ -527,10 +528,29 @@ sub _color {
if defined $color_node->att('rgb');
$color = '#' . $colors->[$color_node->att('theme')]
if defined $color_node->att('theme');
- # XXX tint?
+
+ $color = $self->_apply_tint($color, $color_node->att('tint'))
+ if $color_node->att('tint');
}
return $color;
}
+sub _apply_tint {
+ my $self = shift;
+ my ($color, $tint) = @_;
+
+ my ($r, $g, $b) = map { oct("0x$_") } $color =~ /#(..)(..)(..)/;
+ my ($h, $l, $s) = rgb2hls($r, $g, $b);
+
+ if ($tint < 0) {
+ $l = $l * (1.0 + $tint);
+ }
+ else {
+ $l = $l * (1.0 - $tint) + (1.0 - 1.0 * (1.0 - $tint));
+ }
+
+ return scalar hls2rgb($h, $l, $s);
+}
+
1;