color 1.7.1 → 2.0.0.pre.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.
- checksums.yaml +5 -13
- data/CHANGELOG.md +298 -0
- data/CODE_OF_CONDUCT.md +128 -0
- data/CONTRIBUTING.md +70 -0
- data/CONTRIBUTORS.md +10 -0
- data/LICENCE.md +27 -0
- data/Manifest.txt +11 -21
- data/README.md +54 -0
- data/Rakefile +74 -53
- data/SECURITY.md +34 -0
- data/lib/color/cielab.rb +348 -0
- data/lib/color/cmyk.rb +279 -213
- data/lib/color/grayscale.rb +128 -160
- data/lib/color/hsl.rb +205 -173
- data/lib/color/rgb/colors.rb +177 -163
- data/lib/color/rgb.rb +534 -537
- data/lib/color/version.rb +5 -0
- data/lib/color/xyz.rb +214 -0
- data/lib/color/yiq.rb +91 -46
- data/lib/color.rb +208 -141
- data/test/fixtures/cielab.json +444 -0
- data/test/minitest_helper.rb +20 -4
- data/test/test_cmyk.rb +49 -71
- data/test/test_color.rb +58 -106
- data/test/test_grayscale.rb +35 -56
- data/test/test_hsl.rb +72 -76
- data/test/test_rgb.rb +195 -267
- data/test/test_yiq.rb +12 -30
- metadata +165 -150
- checksums.yaml.gz.sig +0 -0
- data/.autotest +0 -5
- data/.gemtest +0 -0
- data/.hoerc +0 -2
- data/.minitest.rb +0 -2
- data/.travis.yml +0 -35
- data/Contributing.rdoc +0 -60
- data/Gemfile +0 -9
- data/History.rdoc +0 -172
- data/Licence.rdoc +0 -27
- data/README.rdoc +0 -50
- data/lib/color/css.rb +0 -7
- data/lib/color/palette/adobecolor.rb +0 -260
- data/lib/color/palette/gimp.rb +0 -104
- data/lib/color/palette/monocontrast.rb +0 -164
- data/lib/color/palette.rb +0 -4
- data/lib/color/rgb/contrast.rb +0 -57
- data/lib/color/rgb/metallic.rb +0 -28
- data/test/test_adobecolor.rb +0 -405
- data/test/test_css.rb +0 -19
- data/test/test_gimp.rb +0 -87
- data/test/test_monocontrast.rb +0 -130
- data.tar.gz.sig +0 -0
- metadata.gz.sig +0 -0
data/lib/color/cmyk.rb
CHANGED
@@ -1,263 +1,329 @@
|
|
1
|
-
#
|
2
|
-
|
3
|
-
|
4
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
##
|
4
|
+
# The \CMYK color model is a subtractive color model based on additive percentages of
|
5
|
+
# colored inks: cyan, magenta, yellow, and key (most often black).
|
6
|
+
#
|
7
|
+
# \CMYK [30% 0% 80% 30%] would be mixed from 30% cyan, 0% magenta, 80% yellow, and 30%
|
8
|
+
# black.
|
9
|
+
#
|
10
|
+
# \CMYK colors are immutable Data class instances. Array deconstruction is `[cyan,
|
11
|
+
# magenta, yellow, key]` and hash deconstruction is `{c:, cyan:, m:, magenta:, y:, yellow:
|
12
|
+
# k:, key:}`. See #c, #cyan, #m, #magenta, #y, #yellow, #k, #key.
|
5
13
|
class Color::CMYK
|
6
14
|
include Color
|
7
15
|
|
8
|
-
|
9
|
-
#
|
10
|
-
#
|
11
|
-
PDF_FORMAT_STR = "%.3f %.3f %.3f %.3f %s"
|
16
|
+
##
|
17
|
+
# :attr_reader: c
|
18
|
+
# Returns the cyan (`C`) component as a value 0.0 .. 1.0.
|
12
19
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
end
|
20
|
+
##
|
21
|
+
# :attr_reader: cyan
|
22
|
+
# Returns the cyan (`C`) component as a percentage value (0.0 .. 100.0).
|
17
23
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
# Color::CMYK.from_fraction(0.3, 0, 0.8, 0.3)
|
22
|
-
def from_fraction(c = 0, m = 0, y = 0, k = 0, &block)
|
23
|
-
new(c, m, y, k, 1.0, &block)
|
24
|
-
end
|
24
|
+
##
|
25
|
+
# :attr_reader: m
|
26
|
+
# Returns the magenta (`M`) component as a value 0.0 .. 1.0.
|
25
27
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
28
|
+
##
|
29
|
+
# :attr_reader: magenta
|
30
|
+
# Returns the magenta (`M`) component as a percentage value (0.0 .. 100.0).
|
31
|
+
|
32
|
+
##
|
33
|
+
# :attr_reader: y
|
34
|
+
# Returns the yellow (`Y`) component as a value 0.0 .. 1.0.
|
35
|
+
|
36
|
+
##
|
37
|
+
# :attr_reader: yellow
|
38
|
+
# Returns the yellow (`Y`) component as a percentage value (0.0 .. 100.0).
|
39
|
+
|
40
|
+
##
|
41
|
+
# :attr_reader: k
|
42
|
+
# Returns the key or black (`K`) component as a value 0.0 .. 1.0.
|
43
|
+
|
44
|
+
##
|
45
|
+
# :attr_reader: b
|
46
|
+
# Returns the key or black (`K`) component as a value 0.0 .. 1.0.
|
34
47
|
|
35
|
-
|
36
|
-
#
|
48
|
+
##
|
49
|
+
# :attr_reader: key
|
50
|
+
# Returns the key or black (`K`) component as a percentage value (0.0 .. 100.0).
|
51
|
+
|
52
|
+
##
|
53
|
+
# :attr_reader: black
|
54
|
+
# Returns the key or black (`K`) component as a percentage value (0.0 .. 100.0).
|
55
|
+
|
56
|
+
##
|
57
|
+
# Creates a CMYK color object from percentage values (0.0 .. 100.0).
|
37
58
|
#
|
38
|
-
#
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
59
|
+
# ```ruby
|
60
|
+
# Color::CMYK.from_percentage(30, 0, 80, 30) # => CMYK [30.00% 0.00% 80.00% 30.00%]
|
61
|
+
# Color::CMYK.from_values(30, 0, 80, 30) # => CMYK [30.00% 0.00% 80.00% 30.00%]
|
62
|
+
# ```
|
63
|
+
#
|
64
|
+
# :call-seq:
|
65
|
+
# from_percentage(c, m, y, k)
|
66
|
+
# from_percentage(c:, m:, y:, k:)
|
67
|
+
# from_values(c, m, y, k)
|
68
|
+
# from_values(c:, m:, y:, k:)
|
69
|
+
def self.from_percentage(*args, **kwargs)
|
70
|
+
c, m, y, k =
|
71
|
+
case [args, kwargs]
|
72
|
+
in [[_, _, _, _], {}]
|
73
|
+
args
|
74
|
+
in [[], {c:, m:, y:, k:}]
|
75
|
+
[c, m, y, k]
|
76
|
+
else
|
77
|
+
new(*args, **kwargs)
|
78
|
+
end
|
43
79
|
|
44
|
-
|
45
|
-
# be removed from the default package in color-tools 2.0.
|
46
|
-
def pdf_fill
|
47
|
-
PDF_FORMAT_STR % [ @c, @m, @y, @k, "k" ]
|
80
|
+
new(c: c / 100.0, m: m / 100.0, y: y / 100.0, k: k / 100.0)
|
48
81
|
end
|
49
82
|
|
50
|
-
|
51
|
-
|
52
|
-
def pdf_stroke
|
53
|
-
PDF_FORMAT_STR % [ @c, @m, @y, @k, "K" ]
|
54
|
-
end
|
83
|
+
class << self
|
84
|
+
alias_method :from_values, :from_percentage
|
55
85
|
|
56
|
-
|
57
|
-
|
58
|
-
# conversion formula.
|
59
|
-
def html
|
60
|
-
to_rgb.html
|
86
|
+
alias_method :from_fraction, :new
|
87
|
+
alias_method :from_internal, :new # :nodoc:
|
61
88
|
end
|
62
89
|
|
63
|
-
|
64
|
-
#
|
65
|
-
#
|
66
|
-
|
67
|
-
|
90
|
+
##
|
91
|
+
# Creates a CMYK color object from fractional values (0.0 .. 1.0).
|
92
|
+
#
|
93
|
+
# ```ruby
|
94
|
+
# Color::CMYK.from_fraction(0.3, 0, 0.8, 0.3) # => CMYK [30.00% 0.00% 80.00% 30.00%]
|
95
|
+
# Color::CMYK.new(0.3, 0, 0.8, 0.3) # => CMYK [30.00% 0.00% 80.00% 30.00%]
|
96
|
+
# Color::CMYK[c: 0.3, m: 0, y: 0.8, k: 0.3] # => CMYK [30.00% 0.00% 80.00% 30.00%]
|
97
|
+
# ```
|
98
|
+
def initialize(c:, m:, y:, k:)
|
99
|
+
super(c: normalize(c), m: normalize(m), y: normalize(y), k: normalize(k))
|
68
100
|
end
|
69
101
|
|
70
|
-
|
71
|
-
#
|
72
|
-
#
|
73
|
-
|
74
|
-
|
102
|
+
##
|
103
|
+
# Output a CSS representation of the CMYK color using `device-cmyk()`.
|
104
|
+
#
|
105
|
+
# If an `alpha` value is provided, it will be included in the output.
|
106
|
+
#
|
107
|
+
# A `fallback` may be provided or included automatically depending on the value
|
108
|
+
# provided, which may be `true`, `false`, a Color object, or a Hash with `:color` and/or
|
109
|
+
# `:alpha` keys. The default value is `true`.
|
110
|
+
#
|
111
|
+
# When `fallback` is:
|
112
|
+
#
|
113
|
+
# - `true`: this CMYK color will be converted to RGB and this will be provided as the
|
114
|
+
# fallback color. If an `alpha` value is provided, it will be used for the fallback.
|
115
|
+
# - `false`: no fallback color will be included.
|
116
|
+
# - a Color object will be used to produce the `fallback` value.
|
117
|
+
# - a Hash will be checked for `:color` and/or `:alpha` keys:
|
118
|
+
# - if `:color` is present, it will be used for the fallback color; if not present,
|
119
|
+
# the CMYK color will be converted to RGB.
|
120
|
+
# - if `:alpha` is present, it will be used for the fallback color; if not present,
|
121
|
+
# the fallback color will be presented _without_ alpha.
|
122
|
+
#
|
123
|
+
# Examples:
|
124
|
+
#
|
125
|
+
# ```ruby
|
126
|
+
# cmyk = Color::CMYK.from_percentage(30, 0, 80, 30)
|
127
|
+
# cmyk.css
|
128
|
+
# # => device-cmyk(30.00% 0 80.00% 30.00%, rgb(49.00% 70.00% 14.00%))
|
129
|
+
#
|
130
|
+
# cmyk.css(alpha: 0.5)
|
131
|
+
# # => device-cmyk(30.00% 0 80.00% 30.00% / 0.50, rgb(49.00% 70.00% 14.00% / 0.50))
|
132
|
+
#
|
133
|
+
# cmyk.css(fallback: false)
|
134
|
+
# # => device-cmyk(30.00% 0 80.00% 30.00%)
|
135
|
+
#
|
136
|
+
# cmyk.css(alpha: 0.5, fallback: false)
|
137
|
+
# # => device-cmyk(30.00% 0 80.00% 30.00% / 0.50)
|
138
|
+
#
|
139
|
+
# cmyk.css(fallback: Color::RGB::Blue)
|
140
|
+
# # => device-cmyk(30.00% 0 80.00% 30.00%, rgb(0.00% 0.00% 100.00%))
|
141
|
+
#
|
142
|
+
# cmyk.css(alpha: 0.5, fallback: Color::RGB::Blue)
|
143
|
+
# # => device-cmyk(30.00% 0 80.00% 30.00% / 0.50, rgb(0.00% 0.00% 100.00% / 0.50))
|
144
|
+
#
|
145
|
+
# cmyk.css(alpha: 0.5, fallback: { color: Color::RGB::Blue })
|
146
|
+
# # => device-cmyk(30.00% 0 80.00% 30.00% / 0.50, rgb(0.00% 0.00% 100.00%))
|
147
|
+
#
|
148
|
+
# cmyk.css(alpha: 0.5, fallback: { color: Color::RGB::Blue, alpha: 0.3 })
|
149
|
+
# # => device-cmyk(30.00% 0 80.00% 30.00% / 0.50, rgb(0.00% 0.00% 100.00% / 0.30))
|
150
|
+
#
|
151
|
+
# cmyk.css(alpha: 0.5, fallback: { alpha: 0.3 })
|
152
|
+
# # => device-cmyk(30.00% 0 80.00% 30.00% / 0.50, rgb(49.00% 70.00% 14.00% / 0.30))
|
153
|
+
# ```
|
154
|
+
def css(alpha: nil, fallback: true)
|
155
|
+
if fallback.is_a?(Color)
|
156
|
+
device_cmyk(alpha, fallback, alpha)
|
157
|
+
elsif fallback.is_a?(Hash)
|
158
|
+
device_cmyk(alpha, fallback.fetch(:color) { to_rgb }, fallback[:alpha])
|
159
|
+
elsif fallback == true
|
160
|
+
device_cmyk(alpha, to_rgb, alpha)
|
161
|
+
else
|
162
|
+
device_cmyk(alpha, nil, nil)
|
163
|
+
end
|
75
164
|
end
|
76
165
|
|
77
|
-
|
78
|
-
#
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
166
|
+
##
|
167
|
+
# Coerces the other Color object into CMYK.
|
168
|
+
def coerce(other) = other.to_cmyk
|
169
|
+
|
170
|
+
##
|
171
|
+
def to_cmyk(...) = self
|
83
172
|
|
84
|
-
|
85
|
-
#
|
86
|
-
#
|
87
|
-
|
88
|
-
|
173
|
+
##
|
174
|
+
# Converts CMYK to Color::Grayscale.
|
175
|
+
#
|
176
|
+
# There are multiple methods for grayscale conversion, but this implements a variant of
|
177
|
+
# the Adobe PDF conversion method with higher precision:
|
178
|
+
#
|
179
|
+
# ```
|
180
|
+
# g = 1.0 - min(1.0, 0.299 * c + 0.587 * m + 0.114 * y + k)
|
181
|
+
# ```
|
182
|
+
#
|
183
|
+
# The default Adobe conversion uses lower precision conversion constants (0.3, 0.59, and
|
184
|
+
# 0.11) instead of the more precise NTSC/YIQ values.
|
185
|
+
def to_grayscale(...)
|
186
|
+
gc = 0.299 * c
|
187
|
+
gm = 0.587 * m
|
188
|
+
gy = 0.114 * y
|
189
|
+
g = 1.0 - [1.0, gc + gm + gy + k].min
|
190
|
+
Color::Grayscale.from_fraction(g)
|
89
191
|
end
|
90
192
|
|
91
|
-
|
92
|
-
#
|
93
|
-
|
94
|
-
|
193
|
+
##
|
194
|
+
# Converts CMYK to Color::YIQ via Color::RGB.
|
195
|
+
def to_yiq(...) = to_rgb(...).to_yiq(...)
|
196
|
+
|
197
|
+
##
|
198
|
+
# Converts CMYK to Color::RGB.
|
199
|
+
#
|
200
|
+
# Most color experts strongly suggest that this is not a good idea (some suggesting that
|
201
|
+
# it's a very bad idea). CMYK represents additive percentages of inks on white paper,
|
202
|
+
# whereas RGB represents mixed color intensities on an unlit (black) screen.
|
95
203
|
#
|
96
|
-
#
|
97
|
-
#
|
98
|
-
#
|
204
|
+
# The color conversion can be done and there are two different methods (standard and
|
205
|
+
# Adobe PDF) that provide slightly different results. Using CMYK [33% 66% 83% 25%], the
|
206
|
+
# standard method provides an approximate RGB color of (128, 65, 33) or #804121. The
|
207
|
+
# Adobe PDF method provides an approximate RGB color of (107, 23, 0) or #6b1700.
|
99
208
|
#
|
100
|
-
#
|
209
|
+
# Which is correct? The colors may seem to be drastically different in the RGB color
|
210
|
+
# space, they differ mostly in intensity. The Adobe PDF conversion is a darker, slightly
|
211
|
+
# redder brown; the standard conversion is a lighter brown. Because of this subtlety,
|
212
|
+
# both methods are offered for conversion. The Adobe PDF method is not used by default;
|
213
|
+
# to use it, pass `rgb_method: :adobe` to #to_rgb.
|
214
|
+
#
|
215
|
+
# # Adobe PDF CMYK -> RGB Conversion
|
101
216
|
# r = 1.0 - min(1.0, c + k)
|
102
217
|
# g = 1.0 - min(1.0, m + k)
|
103
218
|
# b = 1.0 - min(1.0, y + k)
|
104
219
|
#
|
105
|
-
#
|
220
|
+
# # Standard CMYK -> RGB Conversion
|
106
221
|
# r = 1.0 - (c * (1.0 - k) + k)
|
107
222
|
# g = 1.0 - (m * (1.0 - k) + k)
|
108
223
|
# b = 1.0 - (y * (1.0 - k) + k)
|
109
224
|
#
|
110
|
-
#
|
111
|
-
#
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
# The Adobe method is not used by default; to enable it, pass +true+ to
|
120
|
-
# #to_rgb.
|
121
|
-
#
|
122
|
-
# Future versions of Color may offer other conversion mechanisms that
|
123
|
-
# offer greater colour fidelity, including recognition of ICC colour
|
124
|
-
# profiles.
|
125
|
-
def to_rgb(use_adobe_method = false)
|
126
|
-
if use_adobe_method
|
127
|
-
Color::RGB.from_fraction(*adobe_cmyk_rgb)
|
128
|
-
else
|
129
|
-
Color::RGB.from_fraction(*standard_cmyk_rgb)
|
130
|
-
end
|
131
|
-
end
|
225
|
+
# :call-seq:
|
226
|
+
# to_rgb(rgb_method: :standard)
|
227
|
+
def to_rgb(*args, **kwargs)
|
228
|
+
values =
|
229
|
+
if kwargs[:rgb_method] == :adobe || args.first == :adobe
|
230
|
+
adobe_cmyk_rgb
|
231
|
+
else
|
232
|
+
standard_cmyk_rgb
|
233
|
+
end
|
132
234
|
|
133
|
-
|
134
|
-
# undoubtedly multiple methods for this conversion, but only a minor
|
135
|
-
# variant of the Adobe conversion method will be used:
|
136
|
-
#
|
137
|
-
# g = 1.0 - min(1.0, 0.299 * c + 0.587 * m + 0.114 * y + k)
|
138
|
-
#
|
139
|
-
# This treats the CMY values similarly to YIQ (NTSC) values and then adds
|
140
|
-
# the level of black. This is a variant of the Adobe version because it
|
141
|
-
# uses the more precise YIQ (NTSC) conversion values for Y (intensity)
|
142
|
-
# rather than the approximates provided by Adobe (0.3, 0.59, and 0.11).
|
143
|
-
def to_grayscale
|
144
|
-
c = 0.299 * @c.to_f
|
145
|
-
m = 0.587 * @m.to_f
|
146
|
-
y = 0.114 * @y.to_f
|
147
|
-
g = 1.0 - [1.0, c + m + y + @k].min
|
148
|
-
Color::GrayScale.from_fraction(g)
|
235
|
+
Color::RGB.from_fraction(*values)
|
149
236
|
end
|
150
|
-
alias to_greyscale to_grayscale
|
151
237
|
|
152
|
-
|
153
|
-
|
154
|
-
|
238
|
+
##
|
239
|
+
# Converts CMYK to Color::HSL via Color::RGB.
|
240
|
+
def to_hsl(...) = to_rgb(...).to_hsl(...)
|
155
241
|
|
156
|
-
|
157
|
-
|
158
|
-
|
242
|
+
##
|
243
|
+
# Converts CMYK to Color::CIELAB via Color::RGB.
|
244
|
+
def to_lab(...) = to_rgb(...).to_lab(...)
|
159
245
|
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
end
|
246
|
+
##
|
247
|
+
# Converts CMYK to Color::XYZ via Color::RGB.
|
248
|
+
def to_xyz(...) = to_rgb(...).to_xyz(...)
|
164
249
|
|
165
|
-
|
166
|
-
def
|
167
|
-
to_rgb.to_hsl
|
168
|
-
end
|
250
|
+
##
|
251
|
+
def inspect = "CMYK [%.2f%% %.2f%% %.2f%% %.2f%%]" % [cyan, magenta, yellow, key] # :nodoc:
|
169
252
|
|
170
|
-
|
171
|
-
def
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
# 0.0 .. 1.0.
|
185
|
-
def c=(cc)
|
186
|
-
@c = Color.normalize(cc)
|
253
|
+
##
|
254
|
+
def pretty_print(q) # :nodoc:
|
255
|
+
q.text "CMYK"
|
256
|
+
q.breakable
|
257
|
+
q.group 2, "[", "]" do
|
258
|
+
q.text ".2f%%" % cyan
|
259
|
+
q.fill_breakable
|
260
|
+
q.text ".2f%%" % magenta
|
261
|
+
q.fill_breakable
|
262
|
+
q.text ".2f%%" % yellow
|
263
|
+
q.fill_breakable
|
264
|
+
q.text ".2f%%" % key
|
265
|
+
q.fill_breakable
|
266
|
+
end
|
187
267
|
end
|
188
268
|
|
189
|
-
|
190
|
-
#
|
191
|
-
def magenta
|
192
|
-
@m * 100.0
|
193
|
-
end
|
194
|
-
# Returns the magenta (M) component of the CMYK colour as a value in the
|
195
|
-
# range 0.0 .. 1.0.
|
196
|
-
def m
|
197
|
-
@m
|
198
|
-
end
|
199
|
-
# Sets the magenta (M) component of the CMYK colour as a percentage value.
|
200
|
-
def magenta=(mm)
|
201
|
-
@m = Color.normalize(mm / 100.0)
|
202
|
-
end
|
203
|
-
# Sets the magenta (M) component of the CMYK colour as a value in the
|
204
|
-
# range 0.0 .. 1.0.
|
205
|
-
def m=(mm)
|
206
|
-
@m = Color.normalize(mm)
|
207
|
-
end
|
269
|
+
##
|
270
|
+
def cyan = c * 100.0 # :nodoc:
|
208
271
|
|
209
|
-
|
210
|
-
#
|
211
|
-
def yellow
|
212
|
-
@y * 100.0
|
213
|
-
end
|
214
|
-
# Returns the yellow (Y) component of the CMYK colour as a value in the
|
215
|
-
# range 0.0 .. 1.0.
|
216
|
-
def y
|
217
|
-
@y
|
218
|
-
end
|
219
|
-
# Sets the yellow (Y) component of the CMYK colour as a percentage value.
|
220
|
-
def yellow=(yy)
|
221
|
-
@y = Color.normalize(yy / 100.0)
|
222
|
-
end
|
223
|
-
# Sets the yellow (Y) component of the CMYK colour as a value in the range
|
224
|
-
# 0.0 .. 1.0.
|
225
|
-
def y=(kk)
|
226
|
-
@y = Color.normalize(kk)
|
227
|
-
end
|
272
|
+
##
|
273
|
+
def magenta = m * 100.0 # :nodoc:
|
228
274
|
|
229
|
-
|
230
|
-
#
|
231
|
-
def black
|
232
|
-
@k * 100.0
|
233
|
-
end
|
234
|
-
# Returns the black (K) component of the CMYK colour as a value in the
|
235
|
-
# range 0.0 .. 1.0.
|
236
|
-
def k
|
237
|
-
@k
|
238
|
-
end
|
239
|
-
# Sets the black (K) component of the CMYK colour as a percentage value.
|
240
|
-
def black=(kk)
|
241
|
-
@k = Color.normalize(kk / 100.0)
|
242
|
-
end
|
243
|
-
# Sets the black (K) component of the CMYK colour as a value in the range
|
244
|
-
# 0.0 .. 1.0.
|
245
|
-
def k=(kk)
|
246
|
-
@k = Color.normalize(kk)
|
247
|
-
end
|
275
|
+
##
|
276
|
+
def yellow = y * 100.0 # :nodoc:
|
248
277
|
|
249
|
-
|
250
|
-
|
251
|
-
|
278
|
+
##
|
279
|
+
alias_method :b, :k # :nodoc:
|
280
|
+
|
281
|
+
##
|
282
|
+
def key = k * 100.0 # :nodoc:
|
283
|
+
|
284
|
+
##
|
285
|
+
alias_method :black, :key # :nodoc:
|
286
|
+
|
287
|
+
##
|
288
|
+
def to_a = [cyan, magenta, yellow, key] # :nodoc:
|
289
|
+
|
290
|
+
##
|
291
|
+
alias_method :deconstruct, :to_a # :nodoc:
|
292
|
+
|
293
|
+
##
|
294
|
+
def deconstruct_keys(_keys) = {c:, m:, y:, k:, cyan:, magenta:, yellow:, key:} # :nodoc:
|
295
|
+
|
296
|
+
##
|
297
|
+
def to_internal = [c, m, y, k] # :nodoc:
|
298
|
+
|
299
|
+
##
|
300
|
+
def components = 4 # :nodoc:
|
252
301
|
|
253
302
|
private
|
303
|
+
|
304
|
+
##
|
254
305
|
# Implements the Adobe PDF conversion of CMYK to RGB.
|
255
|
-
def adobe_cmyk_rgb
|
256
|
-
[ @c, @m, @y ].map { |v| 1.0 - [ 1.0, v + @k ].min }
|
257
|
-
end
|
306
|
+
def adobe_cmyk_rgb = [c, m, y].map { 1.0 - [1.0, _1 + k].min } # :nodoc:
|
258
307
|
|
308
|
+
##
|
259
309
|
# Implements the standard conversion of CMYK to RGB.
|
260
|
-
def standard_cmyk_rgb
|
261
|
-
|
310
|
+
def standard_cmyk_rgb = [c, m, y].map { 1.0 - (_1 * (1.0 - k) + k) } # :nodoc:
|
311
|
+
|
312
|
+
##
|
313
|
+
def device_cmyk(alpha, fallback, fallback_alpha) # :nodoc:
|
314
|
+
params = [
|
315
|
+
css_value(cyan, :percent),
|
316
|
+
css_value(magenta, :percent),
|
317
|
+
css_value(yellow, :percent),
|
318
|
+
css_value(key, :percent)
|
319
|
+
].join(" ")
|
320
|
+
params = "#{params} / #{css_value(alpha)}" if alpha
|
321
|
+
fallback = fallback&.css(alpha: fallback_alpha)
|
322
|
+
|
323
|
+
if fallback
|
324
|
+
"device-cmyk(#{params}, #{fallback})"
|
325
|
+
else
|
326
|
+
"device-cmyk(#{params})"
|
327
|
+
end
|
262
328
|
end
|
263
329
|
end
|