color-tools 1.2.0 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Changelog +35 -1
- data/Install +11 -2
- data/README +44 -12
- data/Rakefile +11 -2
- data/lib/color.rb +35 -158
- data/lib/color/cmyk.rb +62 -18
- data/lib/color/css.rb +27 -0
- data/lib/color/grayscale.rb +43 -13
- data/lib/color/hsl.rb +130 -0
- data/lib/color/palette.rb +4 -0
- data/lib/color/palette/gimp.rb +47 -12
- data/lib/color/palette/monocontrast.rb +41 -11
- data/lib/color/rgb-colors.rb +189 -0
- data/lib/color/rgb.rb +163 -27
- data/lib/color/rgb/metallic.rb +28 -0
- data/lib/color/yiq.rb +35 -9
- data/metaconfig +11 -2
- data/pre-setup.rb +12 -3
- data/tests/test_cmyk.rb +116 -0
- data/tests/test_css.rb +28 -0
- data/tests/test_gimp.rb +79 -0
- data/tests/test_grayscale.rb +87 -0
- data/tests/test_hsl.rb +93 -0
- data/tests/test_monocontrast.rb +145 -0
- data/tests/test_rgb.rb +160 -0
- data/tests/test_yiq.rb +81 -0
- data/tests/testall.rb +20 -0
- metadata +23 -8
data/Changelog
CHANGED
@@ -1,3 +1,28 @@
|
|
1
|
+
= color-tools Change Log
|
2
|
+
|
3
|
+
== color-utils 1.3.0
|
4
|
+
* Added new metallic colours suggested by Jim Freeze <jfn@freeze.org>. These
|
5
|
+
are in the namespace Color::Metallic.
|
6
|
+
* Colours that were defined in the Color namespace (e.g., Color::Red,
|
7
|
+
Color::AliceBlue) are now defined in Color::RGB (e.g., Color::RGB::Red,
|
8
|
+
Color::RGB::AliceBlue). They are added back to the Color namespace on the
|
9
|
+
first use of the old colours and a warning is printed. In version 1.4, this
|
10
|
+
warning will be printed on every use of the old colours. In version 1.5,
|
11
|
+
the backwards compatible support for colours like Color::Red will be
|
12
|
+
removed completely.
|
13
|
+
* Added the Color::CSS module, color/css or Color::CSS that provides a name
|
14
|
+
lookup of Color::RGB-namespaced constants with Color::CSS[name]. Most of
|
15
|
+
these colours (which are mirrored from the Color::RGB default colours) are
|
16
|
+
only "officially" recognised under the CSS3 colour module or SVG.
|
17
|
+
* Added the Color::HSL colour space and some helper utilities to Color::RGB
|
18
|
+
for colour manipulation using the HSL value.
|
19
|
+
* Controlled internal value replacement to be between 0 and 1 for all
|
20
|
+
colours.
|
21
|
+
* Updated Color::Palette::Gimp to more meaningfully deal with duplicate named
|
22
|
+
colours. Named colours now return an array of colours.
|
23
|
+
* Indicated the plans for some methods and constants out to color-tools 2.0.
|
24
|
+
* Added unit tests and fixed a number of hidden bugs because of them.
|
25
|
+
|
1
26
|
== color-utils 1.2.0
|
2
27
|
* Changed installer from a custom-written install.rb to setup.rb
|
3
28
|
3.3.1-modified.
|
@@ -12,5 +37,14 @@
|
|
12
37
|
== color-utils 1.0.0
|
13
38
|
* Initial release.
|
14
39
|
|
15
|
-
|
40
|
+
#--
|
41
|
+
# Colour management with Ruby.
|
42
|
+
#
|
43
|
+
# Copyright 2005 Austin Ziegler
|
44
|
+
# http://rubyforge.org/ruby-pdf/
|
45
|
+
#
|
46
|
+
# Licensed under a MIT-style licence.
|
47
|
+
#
|
48
|
+
# $Id: Changelog,v 1.8 2005/08/08 02:44:17 austin Exp $
|
49
|
+
#++
|
16
50
|
# vim: sts=2 sw=2 ts=4 et ai tw=77
|
data/Install
CHANGED
@@ -3,7 +3,16 @@ Installing this package is as simple as:
|
|
3
3
|
% ruby setup.rb
|
4
4
|
|
5
5
|
Alternatively, you can use the RubyGem version of color-tools available as
|
6
|
-
color-tools-1.
|
6
|
+
color-tools-1.3.0.gem from the usual sources.
|
7
7
|
|
8
|
-
|
8
|
+
#--
|
9
|
+
# Colour management with Ruby.
|
10
|
+
#
|
11
|
+
# Copyright 2005 Austin Ziegler
|
12
|
+
# http://rubyforge.org/ruby-pdf/
|
13
|
+
#
|
14
|
+
# Licensed under a MIT-style licence.
|
15
|
+
#
|
16
|
+
# $Id: Install,v 1.6 2005/08/05 23:07:20 austin Exp $
|
17
|
+
#++
|
9
18
|
# vim: sts=2 sw=2 ts=4 et ai tw=77
|
data/README
CHANGED
@@ -1,15 +1,38 @@
|
|
1
1
|
= color-tools README
|
2
|
-
color-tools is a Ruby library to provide RGB, CMYK, and other
|
3
|
-
support to applications that require it. It provides
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
2
|
+
color-tools is a Ruby library to provide RGB, CMYK, and other colourspace
|
3
|
+
support to applications that require it. It also provides 152 named RGB
|
4
|
+
colours. It offers 152 named RGB colours (184 with spelling variations)
|
5
|
+
that are commonly supported and used in HTML, SVG, and X11 applications. A
|
6
|
+
technique for generating a monochromatic contrasting palette is also
|
7
|
+
included.
|
8
|
+
|
9
|
+
Version 1.3 offers significant enhancements over color-tools 1.2, and a
|
10
|
+
plan for an incompatible change to the library.
|
11
|
+
|
12
|
+
* Colours that were defined in the Color namespace (e.g., Color::Red,
|
13
|
+
Color::AliceBlue) are now defined in Color::RGB (e.g., Color::RGB::Red,
|
14
|
+
Color::RGB::AliceBlue). They are added back to the Color namespace on
|
15
|
+
the first use of the old colours and a warning is printed. In version
|
16
|
+
1.4, this warning will be printed on every use of the old colours. In
|
17
|
+
version 1.5, the backwards compatible support for colours like
|
18
|
+
Color::Red will be removed completely.
|
19
|
+
|
20
|
+
* A CSS colour name module has been added. It is based on the Color::RGB
|
21
|
+
predefined colours. It is called with "Color::CSS[color]". The provided
|
22
|
+
colour name will be looked up ignoring case so that "DarkSalmon" and
|
23
|
+
"darksalmon" (and :darksalmon) are the same value. This makes it easier
|
24
|
+
on web or SVG developers who wish to be able to manipulate a colour
|
25
|
+
based on a CSS colour name.
|
26
|
+
|
27
|
+
* A new predefined colour namespace has been added for RGB metallic
|
28
|
+
colours (Color::Metallic, in color/rgb/metallic), suggested by Jim
|
29
|
+
Freeze <jfn@freeze.org>.
|
30
|
+
|
31
|
+
* A new colour space, Color::HSL (hue, saturation, and luminosity) has
|
32
|
+
been added with some helper methods to Color::RGB for colour
|
33
|
+
manipulation.
|
34
|
+
|
35
|
+
* Added unit tests and fixed various little bugs.
|
13
36
|
|
14
37
|
== Copyright
|
15
38
|
Copyright 2005 by Austin Ziegler
|
@@ -46,5 +69,14 @@ DEALINGS IN THE SOFTWARE.
|
|
46
69
|
[2] http://slayeroffice.com/tools/color_palette/
|
47
70
|
[3] http://www.barelyfitz.com/projects/csscolor/
|
48
71
|
|
49
|
-
|
72
|
+
#--
|
73
|
+
# Colour management with Ruby.
|
74
|
+
#
|
75
|
+
# Copyright 2005 Austin Ziegler
|
76
|
+
# http://rubyforge.org/ruby-pdf/
|
77
|
+
#
|
78
|
+
# Licensed under a MIT-style licence.
|
79
|
+
#
|
80
|
+
# $Id: README,v 1.9 2005/08/08 02:44:17 austin Exp $
|
81
|
+
#++
|
50
82
|
# vim: sts=2 sw=2 ts=4 et ai tw=74
|
data/Rakefile
CHANGED
@@ -1,5 +1,14 @@
|
|
1
1
|
#! /usr/bin/env rake
|
2
|
-
|
2
|
+
#--
|
3
|
+
# Colour management with Ruby.
|
4
|
+
#
|
5
|
+
# Copyright 2005 Austin Ziegler
|
6
|
+
# http://rubyforge.org/ruby-pdf/
|
7
|
+
#
|
8
|
+
# Licensed under a MIT-style licence.
|
9
|
+
#
|
10
|
+
# $Id: Rakefile,v 1.7 2005/08/08 02:53:16 austin Exp $
|
11
|
+
#++
|
3
12
|
# vim: sts=2 sw=2 ts=4 et ai tw=77
|
4
13
|
|
5
14
|
$LOAD_PATH.unshift('lib')
|
@@ -36,7 +45,7 @@ task :test do |t|
|
|
36
45
|
|
37
46
|
$LOAD_PATH.unshift('tests')
|
38
47
|
$stderr.puts "Checking for test cases:" if t.verbose
|
39
|
-
Dir['tests/
|
48
|
+
Dir['tests/test_*.rb'].each do |testcase|
|
40
49
|
$stderr.puts "\t#{testcase}" if t.verbose
|
41
50
|
load testcase
|
42
51
|
end
|
data/lib/color.rb
CHANGED
@@ -1,3 +1,14 @@
|
|
1
|
+
#--
|
2
|
+
# Colour management with Ruby.
|
3
|
+
#
|
4
|
+
# Copyright 2005 Austin Ziegler
|
5
|
+
# http://rubyforge.org/ruby-pdf/
|
6
|
+
#
|
7
|
+
# Licensed under a MIT-style licence.
|
8
|
+
#
|
9
|
+
# $Id: color.rb,v 1.8 2005/08/08 02:44:17 austin Exp $
|
10
|
+
#++
|
11
|
+
|
1
12
|
# = Colour Management with Ruby
|
2
13
|
#
|
3
14
|
# == Copyright
|
@@ -35,9 +46,8 @@
|
|
35
46
|
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
36
47
|
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
37
48
|
# DEALINGS IN THE SOFTWARE.
|
38
|
-
|
39
49
|
module Color
|
40
|
-
COLOR_TOOLS_VERSION = '1.
|
50
|
+
COLOR_TOOLS_VERSION = '1.3.0'
|
41
51
|
|
42
52
|
class RGB; end
|
43
53
|
class CMYK; end
|
@@ -48,163 +58,30 @@ end
|
|
48
58
|
require 'color/rgb'
|
49
59
|
require 'color/cmyk'
|
50
60
|
require 'color/grayscale'
|
61
|
+
require 'color/hsl'
|
51
62
|
require 'color/yiq'
|
63
|
+
require 'color/rgb/metallic'
|
64
|
+
|
65
|
+
# We load EVERYTHING if we're being run under ZenTest.
|
66
|
+
if defined? $ZENTEST and $ZENTEST
|
67
|
+
require 'color/css'
|
68
|
+
require 'color/palette/gimp'
|
69
|
+
require 'color/palette/monocontrast'
|
70
|
+
end
|
52
71
|
|
53
72
|
module Color
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
Aqua = Color::RGB.new(0x00, 0xff, 0xff)
|
69
|
-
Cyan = Color::RGB.new(0x00, 0xff, 0xff)
|
70
|
-
MidnightBlue = Color::RGB.new(0x19, 0x19, 0x70)
|
71
|
-
DodgerBlue = Color::RGB.new(0x1e, 0x90, 0xff)
|
72
|
-
LightSeaGreen = Color::RGB.new(0x20, 0xb2, 0xaa)
|
73
|
-
ForestGreen = Color::RGB.new(0x22, 0x8b, 0x22)
|
74
|
-
SeaGreen = Color::RGB.new(0x2e, 0x8b, 0x57)
|
75
|
-
DarkSlateGray = Color::RGB.new(0x2f, 0x4f, 0x4f)
|
76
|
-
DarkSlateGrey = DarkSlateGray
|
77
|
-
LimeGreen = Color::RGB.new(0x32, 0xcd, 0x32)
|
78
|
-
MediumSeaGreen = Color::RGB.new(0x3c, 0xb3, 0x71)
|
79
|
-
Turquoise = Color::RGB.new(0x40, 0xe0, 0xd0)
|
80
|
-
RoyalBlue = Color::RGB.new(0x41, 0x69, 0xe1)
|
81
|
-
SteelBlue = Color::RGB.new(0x46, 0x82, 0xb4)
|
82
|
-
DarkSlateBlue = Color::RGB.new(0x48, 0x3d, 0x8b)
|
83
|
-
MediumTurquoise = Color::RGB.new(0x48, 0xd1, 0xcc)
|
84
|
-
Indigo = Color::RGB.new(0x4b, 0x00, 0x82)
|
85
|
-
DarkoliveGreen = Color::RGB.new(0x55, 0x6b, 0x2f)
|
86
|
-
CadetBlue = Color::RGB.new(0x5f, 0x9e, 0xa0)
|
87
|
-
CornflowerBlue = Color::RGB.new(0x64, 0x95, 0xed)
|
88
|
-
MediumAquamarine = Color::RGB.new(0x66, 0xcd, 0xaa)
|
89
|
-
DimGray = Color::RGB.new(0x69, 0x69, 0x69)
|
90
|
-
DimGrey = DimGray
|
91
|
-
SlateBlue = Color::RGB.new(0x6a, 0x5a, 0xcd)
|
92
|
-
Olivedrab = Color::RGB.new(0x6b, 0x8e, 0x23)
|
93
|
-
SlateGray = Color::RGB.new(0x70, 0x80, 0x90)
|
94
|
-
SlateGrey = SlateGray
|
95
|
-
LightSlateGray = Color::RGB.new(0x77, 0x88, 0x99)
|
96
|
-
LightSlateGrey = LightSlateGray
|
97
|
-
MediumSlateBlue = Color::RGB.new(0x7b, 0x68, 0xee)
|
98
|
-
LawnGreen = Color::RGB.new(0x7c, 0xfc, 0x00)
|
99
|
-
Chartreuse = Color::RGB.new(0x7f, 0xff, 0x00)
|
100
|
-
Aquamarine = Color::RGB.new(0x7f, 0xff, 0xd4)
|
101
|
-
Maroon = Color::RGB.new(0x80, 0x00, 0x00)
|
102
|
-
Purple = Color::RGB.new(0x80, 0x00, 0x80)
|
103
|
-
Olive = Color::RGB.new(0x80, 0x80, 0x00)
|
104
|
-
Gray = Color::RGB.new(0x80, 0x80, 0x80)
|
105
|
-
Grey = Gray
|
106
|
-
SkyBlue = Color::RGB.new(0x87, 0xce, 0xeb)
|
107
|
-
LightSkyBlue = Color::RGB.new(0x87, 0xce, 0xfa)
|
108
|
-
BlueViolet = Color::RGB.new(0x8a, 0x2b, 0xe2)
|
109
|
-
DarkRed = Color::RGB.new(0x8b, 0x00, 0x00)
|
110
|
-
DarkMagenta = Color::RGB.new(0x8b, 0x00, 0x8b)
|
111
|
-
SaddleBrown = Color::RGB.new(0x8b, 0x45, 0x13)
|
112
|
-
DarkSeaGreen = Color::RGB.new(0x8f, 0xbc, 0x8f)
|
113
|
-
LightGreen = Color::RGB.new(0x90, 0xee, 0x90)
|
114
|
-
MediumPurple = Color::RGB.new(0x93, 0x70, 0xdb)
|
115
|
-
DarkViolet = Color::RGB.new(0x94, 0x00, 0xd3)
|
116
|
-
PaleGreen = Color::RGB.new(0x98, 0xfb, 0x98)
|
117
|
-
DarkOrchid = Color::RGB.new(0x99, 0x32, 0xcc)
|
118
|
-
YellowGreen = Color::RGB.new(0x9a, 0xcd, 0x32)
|
119
|
-
Sienna = Color::RGB.new(0xa0, 0x52, 0x2d)
|
120
|
-
Brown = Color::RGB.new(0xa5, 0x2a, 0x2a)
|
121
|
-
DarkGray = Color::RGB.new(0xa9, 0xa9, 0xa9)
|
122
|
-
DarkGrey = DarkGray
|
123
|
-
LightBlue = Color::RGB.new(0xad, 0xd8, 0xe6)
|
124
|
-
GreenYellow = Color::RGB.new(0xad, 0xff, 0x2f)
|
125
|
-
PaleTurquoise = Color::RGB.new(0xaf, 0xee, 0xee)
|
126
|
-
LightsteelBlue = Color::RGB.new(0xb0, 0xc4, 0xde)
|
127
|
-
PowderBlue = Color::RGB.new(0xb0, 0xe0, 0xe6)
|
128
|
-
Firebrick = Color::RGB.new(0xb2, 0x22, 0x22)
|
129
|
-
DarkGoldenrod = Color::RGB.new(0xb8, 0x86, 0x0b)
|
130
|
-
MediumOrchid = Color::RGB.new(0xba, 0x55, 0xd3)
|
131
|
-
RosyBrown = Color::RGB.new(0xbc, 0x8f, 0x8f)
|
132
|
-
DarkKhaki = Color::RGB.new(0xbd, 0xb7, 0x6b)
|
133
|
-
Silver = Color::RGB.new(0xc0, 0xc0, 0xc0)
|
134
|
-
MediumVioletRed = Color::RGB.new(0xc7, 0x15, 0x85)
|
135
|
-
IndianRed = Color::RGB.new(0xcd, 0x5c, 0x5c)
|
136
|
-
Peru = Color::RGB.new(0xcd, 0x85, 0x3f)
|
137
|
-
Chocolate = Color::RGB.new(0xd2, 0x69, 0x1e)
|
138
|
-
Tan = Color::RGB.new(0xd2, 0xb4, 0x8c)
|
139
|
-
LightGray = Color::RGB.new(0xd3, 0xd3, 0xd3)
|
140
|
-
LightGrey = LightGray
|
141
|
-
Thistle = Color::RGB.new(0xd8, 0xbf, 0xd8)
|
142
|
-
Orchid = Color::RGB.new(0xda, 0x70, 0xd6)
|
143
|
-
Goldenrod = Color::RGB.new(0xda, 0xa5, 0x20)
|
144
|
-
PaleVioletRed = Color::RGB.new(0xdb, 0x70, 0x93)
|
145
|
-
Crimson = Color::RGB.new(0xdc, 0x14, 0x3c)
|
146
|
-
Gainsboro = Color::RGB.new(0xdc, 0xdc, 0xdc)
|
147
|
-
Plum = Color::RGB.new(0xdd, 0xa0, 0xdd)
|
148
|
-
Burlywood = Color::RGB.new(0xde, 0xb8, 0x87)
|
149
|
-
LightCyan = Color::RGB.new(0xe0, 0xff, 0xff)
|
150
|
-
Lavender = Color::RGB.new(0xe6, 0xe6, 0xfa)
|
151
|
-
Darksalmon = Color::RGB.new(0xe9, 0x96, 0x7a)
|
152
|
-
Violet = Color::RGB.new(0xee, 0x82, 0xee)
|
153
|
-
PaleGoldenrod = Color::RGB.new(0xee, 0xe8, 0xaa)
|
154
|
-
LightCoral = Color::RGB.new(0xf0, 0x80, 0x80)
|
155
|
-
Khaki = Color::RGB.new(0xf0, 0xe6, 0x8c)
|
156
|
-
AliceBlue = Color::RGB.new(0xf0, 0xf8, 0xff)
|
157
|
-
Honeydew = Color::RGB.new(0xf0, 0xff, 0xf0)
|
158
|
-
Azure = Color::RGB.new(0xf0, 0xff, 0xff)
|
159
|
-
SandyBrown = Color::RGB.new(0xf4, 0xa4, 0x60)
|
160
|
-
Wheat = Color::RGB.new(0xf5, 0xde, 0xb3)
|
161
|
-
Beige = Color::RGB.new(0xf5, 0xf5, 0xdc)
|
162
|
-
WhiteSmoke = Color::RGB.new(0xf5, 0xf5, 0xf5)
|
163
|
-
MintCream = Color::RGB.new(0xf5, 0xff, 0xfa)
|
164
|
-
GhostWhite = Color::RGB.new(0xf8, 0xf8, 0xff)
|
165
|
-
Salmon = Color::RGB.new(0xfa, 0x80, 0x72)
|
166
|
-
AntiqueWhite = Color::RGB.new(0xfa, 0xeb, 0xd7)
|
167
|
-
Linen = Color::RGB.new(0xfa, 0xf0, 0xe6)
|
168
|
-
LightGoldenrodYellow = Color::RGB.new(0xfa, 0xfa, 0xd2)
|
169
|
-
OldLace = Color::RGB.new(0xfd, 0xf5, 0xe6)
|
170
|
-
Red = Color::RGB.new(0xff, 0x00, 0x00)
|
171
|
-
Fuchsia = Color::RGB.new(0xff, 0x00, 0xff)
|
172
|
-
Magenta = Color::RGB.new(0xff, 0x00, 0xff)
|
173
|
-
DeepPink = Color::RGB.new(0xff, 0x14, 0x93)
|
174
|
-
OrangeRed = Color::RGB.new(0xff, 0x45, 0x00)
|
175
|
-
Tomato = Color::RGB.new(0xff, 0x63, 0x47)
|
176
|
-
HotPink = Color::RGB.new(0xff, 0x69, 0xb4)
|
177
|
-
Coral = Color::RGB.new(0xff, 0x7f, 0x50)
|
178
|
-
Darkorange = Color::RGB.new(0xff, 0x8c, 0x00)
|
179
|
-
Lightsalmon = Color::RGB.new(0xff, 0xa0, 0x7a)
|
180
|
-
Orange = Color::RGB.new(0xff, 0xa5, 0x00)
|
181
|
-
LightPink = Color::RGB.new(0xff, 0xb6, 0xc1)
|
182
|
-
Pink = Color::RGB.new(0xff, 0xc0, 0xcb)
|
183
|
-
Gold = Color::RGB.new(0xff, 0xd7, 0x00)
|
184
|
-
Peachpuff = Color::RGB.new(0xff, 0xda, 0xb9)
|
185
|
-
NavajoWhite = Color::RGB.new(0xff, 0xde, 0xad)
|
186
|
-
Moccasin = Color::RGB.new(0xff, 0xe4, 0xb5)
|
187
|
-
Bisque = Color::RGB.new(0xff, 0xe4, 0xc4)
|
188
|
-
MistyRose = Color::RGB.new(0xff, 0xe4, 0xe1)
|
189
|
-
BlanchedAlmond = Color::RGB.new(0xff, 0xeb, 0xcd)
|
190
|
-
PapayaWhip = Color::RGB.new(0xff, 0xef, 0xd5)
|
191
|
-
LavenderBlush = Color::RGB.new(0xff, 0xf0, 0xf5)
|
192
|
-
Seashell = Color::RGB.new(0xff, 0xf5, 0xee)
|
193
|
-
Cornsilk = Color::RGB.new(0xff, 0xf8, 0xdc)
|
194
|
-
LemonChiffon = Color::RGB.new(0xff, 0xfa, 0xcd)
|
195
|
-
FloralWhite = Color::RGB.new(0xff, 0xfa, 0xf0)
|
196
|
-
Snow = Color::RGB.new(0xff, 0xfa, 0xfa)
|
197
|
-
Yellow = Color::RGB.new(0xff, 0xff, 0x00)
|
198
|
-
LightYellow = Color::RGB.new(0xff, 0xff, 0xe0)
|
199
|
-
Ivory = Color::RGB.new(0xff, 0xff, 0xf0)
|
200
|
-
White = Color::RGB.new(0xff, 0xff, 0xff)
|
201
|
-
Gray10 = Grey10 = Color::RGB.from_percentage(10, 10, 10)
|
202
|
-
Gray20 = Grey20 = Color::RGB.from_percentage(20, 20, 20)
|
203
|
-
Gray30 = Grey30 = Color::RGB.from_percentage(30, 30, 30)
|
204
|
-
Gray40 = Grey40 = Color::RGB.from_percentage(40, 40, 40)
|
205
|
-
Gray50 = Grey50 = Color::RGB.from_percentage(50, 50, 50)
|
206
|
-
Gray60 = Grey60 = Color::RGB.from_percentage(60, 60, 60)
|
207
|
-
Gray70 = Grey70 = Color::RGB.from_percentage(70, 70, 70)
|
208
|
-
Gray80 = Grey80 = Color::RGB.from_percentage(80, 80, 80)
|
209
|
-
Gray90 = Grey90 = Color::RGB.from_percentage(90, 90, 90)
|
73
|
+
def self.const_missing(name) #:nodoc:
|
74
|
+
if Color::RGB.const_defined?(name)
|
75
|
+
warn "These colour constants have been deprecated. Use Color::RGB::#{name} instead."
|
76
|
+
Color::RGB::constants.each do |const|
|
77
|
+
next if const == "PDF_FORMAT_STR"
|
78
|
+
next if const == "Metallic"
|
79
|
+
const_set(const, Color::RGB.const_get(const))
|
80
|
+
end
|
81
|
+
class << Color; remove_method :const_missing; end
|
82
|
+
Color.const_get(name)
|
83
|
+
else
|
84
|
+
super
|
85
|
+
end
|
86
|
+
end
|
210
87
|
end
|
data/lib/color/cmyk.rb
CHANGED
@@ -3,27 +3,41 @@
|
|
3
3
|
#
|
4
4
|
# Copyright 2005 Austin Ziegler
|
5
5
|
# http://rubyforge.org/ruby-pdf/
|
6
|
+
#
|
7
|
+
# Licensed under a MIT-style licence.
|
8
|
+
#
|
9
|
+
# $Id: cmyk.rb,v 1.5 2005/08/08 02:44:17 austin Exp $
|
6
10
|
#++
|
7
11
|
|
8
|
-
# An CMYK colour object.
|
12
|
+
# An CMYK colour object. CMYK (cyan, magenta, yellow, and black) colours
|
13
|
+
# are based on additive percentages of ink. A CMYK colour of (0.3, 0, 0.8,
|
14
|
+
# 0.3) would be mixed from 30% cyan, 0% magenta, 80% yellow, and 30%
|
15
|
+
# black.
|
9
16
|
class Color::CMYK
|
17
|
+
# The format of a DeviceCMYK colour for PDF. In color-tools 2.0 this
|
18
|
+
# will be removed from this package and added back as a modification by
|
19
|
+
# the PDF::Writer package.
|
10
20
|
PDF_FORMAT_STR = "%.3f %.3f %.3f %.3f %s"
|
11
21
|
|
12
22
|
# Compares the other colour to this one. The other colour will be
|
13
23
|
# converted to CMYK before comparison, so the comparison between a CMYK
|
14
24
|
# colour and a non-CMYK colour will be approximate and based on the
|
15
25
|
# other colour's #to_cmyk conversion. If there is no #to_cmyk
|
16
|
-
# conversion, this will raise an exception.
|
26
|
+
# conversion, this will raise an exception. This will report that two
|
27
|
+
# CMYK colours are equivalent if all component values are within 1e-4
|
28
|
+
# (0.0001) of each other.
|
17
29
|
def ==(other)
|
18
30
|
other = other.to_cmyk
|
19
31
|
other.kind_of?(Color::CMYK) and
|
20
|
-
(@c
|
21
|
-
(@m
|
22
|
-
(@y
|
23
|
-
(@k
|
32
|
+
((@c - other.c).abs <= 1e-4) and
|
33
|
+
((@m - other.m).abs <= 1e-4) and
|
34
|
+
((@y - other.y).abs <= 1e-4) and
|
35
|
+
((@k - other.k).abs <= 1e-4)
|
24
36
|
end
|
25
37
|
|
26
|
-
# Creates a CMYK colour object from fractional values 0
|
38
|
+
# Creates a CMYK colour object from fractional values 0..1.
|
39
|
+
#
|
40
|
+
# Color::CMYK.from_fraction(0.3, 0, 0.8, 0.3)
|
27
41
|
def self.from_fraction(c = 0, m = 0, y = 0, k = 0)
|
28
42
|
colour = Color::CMYK.new
|
29
43
|
colour.c = c
|
@@ -33,7 +47,10 @@ class Color::CMYK
|
|
33
47
|
colour
|
34
48
|
end
|
35
49
|
|
36
|
-
# Creates a CMYK colour object from percentages.
|
50
|
+
# Creates a CMYK colour object from percentages. Internally, the colour
|
51
|
+
# is managed as fractional values 0..1.
|
52
|
+
#
|
53
|
+
# Color::CMYK.from_fraction(30, 0, 80, 30)
|
37
54
|
def initialize(c = 0, m = 0, y = 0, k = 0)
|
38
55
|
@c = c / 100.0
|
39
56
|
@m = m / 100.0
|
@@ -41,18 +58,20 @@ class Color::CMYK
|
|
41
58
|
@k = k / 100.0
|
42
59
|
end
|
43
60
|
|
44
|
-
# Present the colour as a DeviceCMYK fill colour string for PDF.
|
61
|
+
# Present the colour as a DeviceCMYK fill colour string for PDF. This
|
62
|
+
# will be removed from the default package in color-tools 2.0.
|
45
63
|
def pdf_fill
|
46
64
|
PDF_FORMAT_STR % [ @c, @m, @y, @k, "k" ]
|
47
65
|
end
|
48
66
|
|
49
|
-
# Present the colour as a DeviceCMYK stroke colour string for PDF.
|
67
|
+
# Present the colour as a DeviceCMYK stroke colour string for PDF. This
|
68
|
+
# will be removed from the default package in color-tools 2.0.
|
50
69
|
def pdf_stroke
|
51
70
|
PDF_FORMAT_STR % [ @c, @m, @y, @k, "K" ]
|
52
71
|
end
|
53
72
|
|
54
73
|
# Present the colour as an RGB HTML/CSS colour string. Note that this
|
55
|
-
# will perform a #to_rgb
|
74
|
+
# will perform a #to_rgb operation using the default conversion formula.
|
56
75
|
def html
|
57
76
|
to_rgb.html
|
58
77
|
end
|
@@ -88,6 +107,9 @@ class Color::CMYK
|
|
88
107
|
# Because of this subtlety, both methods are now offered for conversion
|
89
108
|
# in color-tools 1.2 or later. The Adobe method is not used by default;
|
90
109
|
# to enable it, pass +true+ to #to_rgb.
|
110
|
+
#
|
111
|
+
# Future versions of color-tools may offer other conversion mechanisms
|
112
|
+
# that offer greater colour fidelity.
|
91
113
|
def to_rgb(use_adobe_method = false)
|
92
114
|
if use_adobe_method
|
93
115
|
r = 1.0 - [1.0, @c + @k].min
|
@@ -117,7 +139,7 @@ class Color::CMYK
|
|
117
139
|
m = 0.587 * @m.to_f
|
118
140
|
y = 0.114 * @y.to_f
|
119
141
|
g = 1.0 - [1.0, c + m + y + @k].min
|
120
|
-
Color::
|
142
|
+
Color::GrayScale.from_fraction(g)
|
121
143
|
end
|
122
144
|
alias to_greyscale to_grayscale
|
123
145
|
|
@@ -125,14 +147,36 @@ class Color::CMYK
|
|
125
147
|
self
|
126
148
|
end
|
127
149
|
|
128
|
-
#
|
129
|
-
# done by first con
|
150
|
+
# Converts to RGB then YIQ.
|
130
151
|
def to_yiq
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
152
|
+
to_rgb.to_yiq
|
153
|
+
end
|
154
|
+
|
155
|
+
# Converts to RGB then HSL.
|
156
|
+
def to_hsl
|
157
|
+
to_rgb.to_hsl
|
135
158
|
end
|
136
159
|
|
137
160
|
attr_accessor :c, :m, :y, :k
|
161
|
+
remove_method :c=, :m=, :y=, :k= ;
|
162
|
+
def c=(cc) #:nodoc:
|
163
|
+
cc = 1.0 if cc > 1
|
164
|
+
cc = 0.0 if cc < 0
|
165
|
+
@c = cc
|
166
|
+
end
|
167
|
+
def m=(mm) #:nodoc:
|
168
|
+
mm = 1.0 if mm > 1
|
169
|
+
mm = 0.0 if mm < 0
|
170
|
+
@m = mm
|
171
|
+
end
|
172
|
+
def y=(yy) #:nodoc:
|
173
|
+
yy = 1.0 if yy > 1
|
174
|
+
yy = 0.0 if yy < 0
|
175
|
+
@y = yy
|
176
|
+
end
|
177
|
+
def k=(kk) #:nodoc:
|
178
|
+
kk = 1.0 if kk > 1
|
179
|
+
kk = 0.0 if kk < 0
|
180
|
+
@k = kk
|
181
|
+
end
|
138
182
|
end
|