line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# You may distribute under the terms of either the GNU General Public License |
2
|
|
|
|
|
|
|
# or the Artistic License (the same terms as Perl itself) |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
# (C) Paul Evans, 2014 -- leonerd@leonerd.org.uk |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
package Convert::Color::HTML; |
7
|
|
|
|
|
|
|
|
8
|
2
|
|
|
2
|
|
31394
|
use strict; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
89
|
|
9
|
2
|
|
|
2
|
|
19
|
use warnings; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
77
|
|
10
|
2
|
|
|
2
|
|
13
|
use base qw( Convert::Color::Library ); |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
556
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
# Ensure that Color::Library::Dictionary::HTML is loaded |
13
|
2
|
|
|
2
|
|
869
|
use Color::Library; |
|
2
|
|
|
|
|
272950
|
|
|
2
|
|
|
|
|
1090
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
__PACKAGE__->register_color_space( 'html' ); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
our $VERSION = '0.04'; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=head1 NAME |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
C - color conversion using C |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=head1 SYNOPSIS |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
Directly: |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
use Convert::Color::HTML; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
my $red = Convert::Color::HTML->new( 'red' ); |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
my $blue = Convert::Color::HTML->new( '#0000FF' ); |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
Via L: |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
use Convert::Color; |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
my $cyan = Convert::Color->new( 'html:cyan' ); |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
Conversion from RGB: |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
my $green = Convert::Color::RGB->( 0, 1.0, 0 )->as_html; |
42
|
|
|
|
|
|
|
say "HTML colour name is " . $green->name; |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=head1 DESCRIPTION |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
This subclass of L provides a shortcut to performing |
47
|
|
|
|
|
|
|
library lookups specifically within the C dictionary. Additionally it |
48
|
|
|
|
|
|
|
will parse C<#RRGGBB> color specifications. |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=cut |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=head1 CONSTRUCTOR |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=cut |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=head2 $color = Convert::Color::HTML->new( $name ) |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
Returns a new object to represent the named color from the C dictionary |
59
|
|
|
|
|
|
|
or plain RGB triplet. |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=cut |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub new |
64
|
|
|
|
|
|
|
{ |
65
|
21
|
|
|
21
|
1
|
14101
|
my $class = shift; |
66
|
21
|
|
|
|
|
29
|
my ( $name ) = @_; |
67
|
|
|
|
|
|
|
|
68
|
21
|
100
|
|
|
|
62
|
if( $name =~ m/^#([0-9a-f]{6})$/i ) { |
69
|
2
|
|
|
|
|
16
|
my $self = $class->Convert::Color::RGB8::new( $1 ); |
70
|
2
|
|
|
|
|
68
|
$self->[3] = uc "#$1"; |
71
|
2
|
|
|
|
|
10
|
return $self; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
19
|
|
|
|
|
73
|
return $class->SUPER::new( "html/$name" ); |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=head1 METHODS |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=cut |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=head2 $name = $color->name |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
Returns the name of the color instance; either the C dictionary name, or |
84
|
|
|
|
|
|
|
the plain RGB triplet notation, as was passed to the constructor. |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=cut |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
# Don't register this as a palette space, because we can always represent any |
89
|
|
|
|
|
|
|
# RGB8 colour. Instead, provide the methods directly |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
my %palette; |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
sub new_from_rgb8 |
94
|
|
|
|
|
|
|
{ |
95
|
2
|
|
|
2
|
0
|
219
|
my $class = shift; |
96
|
2
|
|
|
|
|
5
|
my ( $rgb8 ) = @_; |
97
|
|
|
|
|
|
|
|
98
|
2
|
|
|
|
|
9
|
my $hex = $rgb8->hex; |
99
|
|
|
|
|
|
|
|
100
|
2
|
100
|
|
|
|
52
|
unless( keys %palette ) { |
101
|
17
|
|
|
|
|
267
|
%palette = map { |
102
|
1
|
|
|
|
|
15
|
my $color = $class->new( $_ ); |
103
|
17
|
|
|
|
|
38
|
$color->hex => $color |
104
|
|
|
|
|
|
|
} Color::Library::Dictionary::HTML->color_names; |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
2
|
|
66
|
|
|
51
|
return $palette{$hex} || $class->new( "#$hex" ); |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
sub new_rgb |
111
|
|
|
|
|
|
|
{ |
112
|
2
|
|
|
2
|
0
|
358
|
my $class = shift; |
113
|
2
|
|
|
|
|
13
|
return $class->new_from_rgb8( Convert::Color::RGB->new( @_ )->as_rgb8 ); |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=head1 AUTHOR |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
Paul Evans |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=cut |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
0x55AA; |