mack-pdf_writer 0.8.1 → 0.8.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (74) hide show
  1. data/lib/gems/archive-tar-minitar-0.5.2/bin/minitar +27 -0
  2. data/lib/gems/archive-tar-minitar-0.5.2/lib/archive/tar/minitar/command.rb +814 -0
  3. data/lib/gems/archive-tar-minitar-0.5.2/lib/archive/tar/minitar.rb +979 -0
  4. data/lib/gems/color-1.4.0/lib/color/cmyk.rb +281 -0
  5. data/lib/gems/color-1.4.0/lib/color/css.rb +30 -0
  6. data/lib/gems/color-1.4.0/lib/color/grayscale.rb +214 -0
  7. data/lib/gems/color-1.4.0/lib/color/hsl.rb +223 -0
  8. data/lib/gems/color-1.4.0/lib/color/palette/adobecolor.rb +274 -0
  9. data/lib/gems/color-1.4.0/lib/color/palette/gimp.rb +118 -0
  10. data/lib/gems/color-1.4.0/lib/color/palette/monocontrast.rb +182 -0
  11. data/lib/gems/color-1.4.0/lib/color/palette.rb +18 -0
  12. data/lib/gems/color-1.4.0/lib/color/rgb/metallic.rb +45 -0
  13. data/lib/gems/color-1.4.0/lib/color/rgb-colors.rb +357 -0
  14. data/lib/gems/color-1.4.0/lib/color/rgb.rb +455 -0
  15. data/lib/gems/color-1.4.0/lib/color/yiq.rb +86 -0
  16. data/lib/gems/color-1.4.0/lib/color.rb +147 -0
  17. data/lib/gems/pdf-writer-1.1.8/bin/techbook +24 -0
  18. data/lib/gems/pdf-writer-1.1.8/lib/pdf/charts/stddev.rb +430 -0
  19. data/lib/gems/pdf-writer-1.1.8/lib/pdf/charts.rb +13 -0
  20. data/lib/gems/pdf-writer-1.1.8/lib/pdf/math.rb +108 -0
  21. data/lib/gems/pdf-writer-1.1.8/lib/pdf/quickref.rb +332 -0
  22. data/lib/gems/pdf-writer-1.1.8/lib/pdf/simpletable.rb +947 -0
  23. data/lib/gems/pdf-writer-1.1.8/lib/pdf/techbook.rb +901 -0
  24. data/lib/gems/pdf-writer-1.1.8/lib/pdf/writer/arc4.rb +63 -0
  25. data/lib/gems/pdf-writer-1.1.8/lib/pdf/writer/fontmetrics.rb +203 -0
  26. data/lib/gems/pdf-writer-1.1.8/lib/pdf/writer/fonts/Courier-Bold.afm +342 -0
  27. data/lib/gems/pdf-writer-1.1.8/lib/pdf/writer/fonts/Courier-BoldOblique.afm +342 -0
  28. data/lib/gems/pdf-writer-1.1.8/lib/pdf/writer/fonts/Courier-Oblique.afm +342 -0
  29. data/lib/gems/pdf-writer-1.1.8/lib/pdf/writer/fonts/Courier.afm +342 -0
  30. data/lib/gems/pdf-writer-1.1.8/lib/pdf/writer/fonts/Helvetica-Bold.afm +2827 -0
  31. data/lib/gems/pdf-writer-1.1.8/lib/pdf/writer/fonts/Helvetica-BoldOblique.afm +2827 -0
  32. data/lib/gems/pdf-writer-1.1.8/lib/pdf/writer/fonts/Helvetica-Oblique.afm +3051 -0
  33. data/lib/gems/pdf-writer-1.1.8/lib/pdf/writer/fonts/Helvetica.afm +3051 -0
  34. data/lib/gems/pdf-writer-1.1.8/lib/pdf/writer/fonts/MustRead.html +19 -0
  35. data/lib/gems/pdf-writer-1.1.8/lib/pdf/writer/fonts/Symbol.afm +213 -0
  36. data/lib/gems/pdf-writer-1.1.8/lib/pdf/writer/fonts/Times-Bold.afm +2588 -0
  37. data/lib/gems/pdf-writer-1.1.8/lib/pdf/writer/fonts/Times-BoldItalic.afm +2384 -0
  38. data/lib/gems/pdf-writer-1.1.8/lib/pdf/writer/fonts/Times-Italic.afm +2667 -0
  39. data/lib/gems/pdf-writer-1.1.8/lib/pdf/writer/fonts/Times-Roman.afm +2419 -0
  40. data/lib/gems/pdf-writer-1.1.8/lib/pdf/writer/fonts/ZapfDingbats.afm +225 -0
  41. data/lib/gems/pdf-writer-1.1.8/lib/pdf/writer/graphics/imageinfo.rb +365 -0
  42. data/lib/gems/pdf-writer-1.1.8/lib/pdf/writer/graphics.rb +813 -0
  43. data/lib/gems/pdf-writer-1.1.8/lib/pdf/writer/lang/en.rb +99 -0
  44. data/lib/gems/pdf-writer-1.1.8/lib/pdf/writer/lang.rb +43 -0
  45. data/lib/gems/pdf-writer-1.1.8/lib/pdf/writer/object/action.rb +35 -0
  46. data/lib/gems/pdf-writer-1.1.8/lib/pdf/writer/object/annotation.rb +42 -0
  47. data/lib/gems/pdf-writer-1.1.8/lib/pdf/writer/object/catalog.rb +39 -0
  48. data/lib/gems/pdf-writer-1.1.8/lib/pdf/writer/object/contents.rb +65 -0
  49. data/lib/gems/pdf-writer-1.1.8/lib/pdf/writer/object/destination.rb +40 -0
  50. data/lib/gems/pdf-writer-1.1.8/lib/pdf/writer/object/encryption.rb +53 -0
  51. data/lib/gems/pdf-writer-1.1.8/lib/pdf/writer/object/font.rb +72 -0
  52. data/lib/gems/pdf-writer-1.1.8/lib/pdf/writer/object/fontdescriptor.rb +34 -0
  53. data/lib/gems/pdf-writer-1.1.8/lib/pdf/writer/object/fontencoding.rb +40 -0
  54. data/lib/gems/pdf-writer-1.1.8/lib/pdf/writer/object/image.rb +304 -0
  55. data/lib/gems/pdf-writer-1.1.8/lib/pdf/writer/object/info.rb +51 -0
  56. data/lib/gems/pdf-writer-1.1.8/lib/pdf/writer/object/outline.rb +30 -0
  57. data/lib/gems/pdf-writer-1.1.8/lib/pdf/writer/object/outlines.rb +30 -0
  58. data/lib/gems/pdf-writer-1.1.8/lib/pdf/writer/object/page.rb +195 -0
  59. data/lib/gems/pdf-writer-1.1.8/lib/pdf/writer/object/pages.rb +115 -0
  60. data/lib/gems/pdf-writer-1.1.8/lib/pdf/writer/object/procset.rb +46 -0
  61. data/lib/gems/pdf-writer-1.1.8/lib/pdf/writer/object/viewerpreferences.rb +74 -0
  62. data/lib/gems/pdf-writer-1.1.8/lib/pdf/writer/object.rb +23 -0
  63. data/lib/gems/pdf-writer-1.1.8/lib/pdf/writer/ohash.rb +58 -0
  64. data/lib/gems/pdf-writer-1.1.8/lib/pdf/writer/oreader.rb +25 -0
  65. data/lib/gems/pdf-writer-1.1.8/lib/pdf/writer/state.rb +48 -0
  66. data/lib/gems/pdf-writer-1.1.8/lib/pdf/writer/strokestyle.rb +138 -0
  67. data/lib/gems/pdf-writer-1.1.8/lib/pdf/writer.rb +2729 -0
  68. data/lib/gems/transaction-simple-1.4.0/lib/transaction/simple/group.rb +146 -0
  69. data/lib/gems/transaction-simple-1.4.0/lib/transaction/simple/threadsafe/group.rb +36 -0
  70. data/lib/gems/transaction-simple-1.4.0/lib/transaction/simple/threadsafe.rb +68 -0
  71. data/lib/gems/transaction-simple-1.4.0/lib/transaction/simple.rb +486 -0
  72. data/lib/gems.rb +13 -0
  73. data/lib/mack-pdf_writer.rb +2 -0
  74. metadata +111 -16
@@ -0,0 +1,455 @@
1
+ #--
2
+ # Color
3
+ # Colour management with Ruby
4
+ # http://rubyforge.org/projects/color
5
+ # Version 1.4.0
6
+ #
7
+ # Licensed under a MIT-style licence. See Licence.txt in the main
8
+ # distribution for full licensing information.
9
+ #
10
+ # Copyright (c) 2005 - 2007 Austin Ziegler and Matt Lyon
11
+ #
12
+ # $Id: test_all.rb 55 2007-02-03 23:29:34Z austin $
13
+ #++
14
+
15
+ # An RGB colour object.
16
+ class Color::RGB
17
+ # The format of a DeviceRGB colour for PDF. In color-tools 2.0 this will
18
+ # be removed from this package and added back as a modification by the
19
+ # PDF::Writer package.
20
+ PDF_FORMAT_STR = "%.3f %.3f %.3f %s"
21
+
22
+ class << self
23
+ # Creates an RGB colour object from percentages 0..100.
24
+ #
25
+ # Color::RGB.from_percentage(10, 20 30)
26
+ def from_percentage(r = 0, g = 0, b = 0)
27
+ from_fraction(r / 100.0, g / 100.0, b / 100.0)
28
+ end
29
+
30
+ # Creates an RGB colour object from fractional values 0..1.
31
+ #
32
+ # Color::RGB.from_fraction(.3, .2, .1)
33
+ def from_fraction(r = 0.0, g = 0.0, b = 0.0)
34
+ colour = Color::RGB.new
35
+ colour.r = r
36
+ colour.g = g
37
+ colour.b = b
38
+ colour
39
+ end
40
+
41
+ # Creates an RGB colour object from an HTML colour descriptor (e.g.,
42
+ # <tt>"fed"</tt> or <tt>"#cabbed;"</tt>.
43
+ #
44
+ # Color::RGB.from_html("fed")
45
+ # Color::RGB.from_html("#fed")
46
+ # Color::RGB.from_html("#cabbed")
47
+ # Color::RGB.from_html("cabbed")
48
+ def from_html(html_colour)
49
+ html_colour = html_colour.gsub(%r{[#;]}, '')
50
+ case html_colour.size
51
+ when 3
52
+ colours = html_colour.scan(%r{[0-9A-Fa-f]}).map { |el| (el * 2).to_i(16) }
53
+ when 6
54
+ colours = html_colour.scan(%r<[0-9A-Fa-f]{2}>).map { |el| el.to_i(16) }
55
+ else
56
+ raise ArgumentError
57
+ end
58
+
59
+ Color::RGB.new(*colours)
60
+ end
61
+ end
62
+
63
+ # Compares the other colour to this one. The other colour will be
64
+ # converted to RGB before comparison, so the comparison between a RGB
65
+ # colour and a non-RGB colour will be approximate and based on the other
66
+ # colour's default #to_rgb conversion. If there is no #to_rgb conversion,
67
+ # this will raise an exception. This will report that two RGB colours are
68
+ # equivalent if all component values are within COLOR_TOLERANCE of each
69
+ # other.
70
+ def ==(other)
71
+ other = other.to_rgb
72
+ other.kind_of?(Color::RGB) and
73
+ ((@r - other.r).abs <= Color::COLOR_TOLERANCE) and
74
+ ((@g - other.g).abs <= Color::COLOR_TOLERANCE) and
75
+ ((@b - other.b).abs <= Color::COLOR_TOLERANCE)
76
+ end
77
+
78
+ # Creates an RGB colour object from the standard range 0..255.
79
+ #
80
+ # Color::RGB.new(32, 64, 128)
81
+ # Color::RGB.new(0x20, 0x40, 0x80)
82
+ def initialize(r = 0, g = 0, b = 0)
83
+ @r = r / 255.0
84
+ @g = g / 255.0
85
+ @b = b / 255.0
86
+ end
87
+
88
+ # Present the colour as a DeviceRGB fill colour string for PDF. This will
89
+ # be removed from the default package in color-tools 2.0.
90
+ def pdf_fill
91
+ PDF_FORMAT_STR % [ @r, @g, @b, "rg" ]
92
+ end
93
+
94
+ # Present the colour as a DeviceRGB stroke colour string for PDF. This
95
+ # will be removed from the default package in color-tools 2.0.
96
+ def pdf_stroke
97
+ PDF_FORMAT_STR % [ @r, @g, @b, "RG" ]
98
+ end
99
+
100
+ # Present the colour as an HTML/CSS colour string.
101
+ def html
102
+ r = (@r * 255).round
103
+ r = 255 if r > 255
104
+
105
+ g = (@g * 255).round
106
+ g = 255 if g > 255
107
+
108
+ b = (@b * 255).round
109
+ b = 255 if b > 255
110
+
111
+ "#%02x%02x%02x" % [ r, g, b ]
112
+ end
113
+
114
+ # Present the colour as an RGB HTML/CSS colour string (e.g., "rgb(0%, 50%,
115
+ # 100%)"). Note that this will perform a #to_rgb operation using the
116
+ # default conversion formula.
117
+ def css_rgb
118
+ "rgb(%3.2f%%, %3.2f%%, %3.2f%%)" % [ red_p, green_p, blue_p ]
119
+ end
120
+
121
+ # Present the colour as an RGBA (with alpha) HTML/CSS colour string (e.g.,
122
+ # "rgb(0%, 50%, 100%, 1)"). Note that this will perform a #to_rgb
123
+ # operation using the default conversion formula.
124
+ def css_rgba
125
+ "rgba(%3.2f%%, %3.2f%%, %3.2f%%, %3.2f)" % [ red_p, green_p, blue_p, 1 ]
126
+ end
127
+
128
+ # Present the colour as an HSL HTML/CSS colour string (e.g., "hsl(180,
129
+ # 25%, 35%)"). Note that this will perform a #to_hsl operation using the
130
+ # default conversion formula.
131
+ def css_hsl
132
+ to_hsl.css_hsl
133
+ end
134
+
135
+ # Present the colour as an HSLA (with alpha) HTML/CSS colour string (e.g.,
136
+ # "hsla(180, 25%, 35%, 1)"). Note that this will perform a #to_hsl
137
+ # operation using the default conversion formula.
138
+ def css_hsla
139
+ to_hsl.css_hsla
140
+ end
141
+
142
+ # Converts the RGB colour to CMYK. Most colour experts strongly suggest
143
+ # that this is not a good idea (some even suggesting that it's a very bad
144
+ # idea). CMYK represents additive percentages of inks on white paper,
145
+ # whereas RGB represents mixed colour intensities on a black screen.
146
+ #
147
+ # However, the colour conversion can be done. The basic method is
148
+ # multi-step:
149
+ #
150
+ # 1. Convert the R, G, and B components to C, M, and Y components.
151
+ # c = 1.0 - r
152
+ # m = 1.0 - g
153
+ # y = 1.0 - b
154
+ # 2. Compute the minimum amount of black (K) required to smooth the colour
155
+ # in inks.
156
+ # k = min(c, m, y)
157
+ # 3. Perform undercolour removal on the C, M, and Y components of the
158
+ # colours because less of each colour is needed for each bit of black.
159
+ # Also, regenerate the black (K) based on the undercolour removal so
160
+ # that the colour is more accurately represented in ink.
161
+ # c = min(1.0, max(0.0, c - UCR(k)))
162
+ # m = min(1.0, max(0.0, m - UCR(k)))
163
+ # y = min(1.0, max(0.0, y - UCR(k)))
164
+ # k = min(1.0, max(0.0, BG(k)))
165
+ #
166
+ # The undercolour removal function and the black generation functions
167
+ # return a value based on the brightness of the RGB colour.
168
+ def to_cmyk
169
+ c = 1.0 - @r.to_f
170
+ m = 1.0 - @g.to_f
171
+ y = 1.0 - @b.to_f
172
+
173
+ k = [c, m, y].min
174
+ k = k - (k * brightness)
175
+
176
+ c = [1.0, [0.0, c - k].max].min
177
+ m = [1.0, [0.0, m - k].max].min
178
+ y = [1.0, [0.0, y - k].max].min
179
+ k = [1.0, [0.0, k].max].min
180
+
181
+ Color::CMYK.from_fraction(c, m, y, k)
182
+ end
183
+
184
+ def to_rgb(ignored = nil)
185
+ self
186
+ end
187
+
188
+ # Returns the YIQ (NTSC) colour encoding of the RGB value.
189
+ def to_yiq
190
+ y = (@r * 0.299) + (@g * 0.587) + (@b * 0.114)
191
+ i = (@r * 0.596) + (@g * -0.275) + (@b * -0.321)
192
+ q = (@r * 0.212) + (@g * -0.523) + (@b * 0.311)
193
+ Color::YIQ.from_fraction(y, i, q)
194
+ end
195
+
196
+ # Returns the HSL colour encoding of the RGB value. The conversions here
197
+ # are based on forumlas from http://www.easyrgb.com/math.php and
198
+ # elsewhere.
199
+ def to_hsl
200
+ min = [ @r, @g, @b ].min
201
+ max = [ @r, @g, @b ].max
202
+ delta = (max - min).to_f
203
+
204
+ lum = (max + min) / 2.0
205
+
206
+ if Color.near_zero?(delta) # close to 0.0, so it's a grey
207
+ hue = 0
208
+ sat = 0
209
+ else
210
+ if Color.near_zero_or_less?(lum - 0.5)
211
+ sat = delta / (max + min).to_f
212
+ else
213
+ sat = delta / (2 - max - min).to_f
214
+ end
215
+
216
+ # This is based on the conversion algorithm from
217
+ # http://en.wikipedia.org/wiki/HSV_color_space#Conversion_from_RGB_to_HSL_or_HSV
218
+ # Contributed by Adam Johnson
219
+ sixth = 1 / 6.0
220
+ if @r == max # Color.near_zero_or_less?(@r - max)
221
+ hue = (sixth * ((@g - @b) / delta))
222
+ hue += 1.0 if @g < @b
223
+ elsif @g == max # Color.near_zero_or_less(@g - max)
224
+ hue = (sixth * ((@b - @r) / delta)) + (1.0 / 3.0)
225
+ elsif @b == max # Color.near_zero_or_less?(@b - max)
226
+ hue = (sixth * ((@r - @g) / delta)) + (2.0 / 3.0)
227
+ end
228
+
229
+ hue += 1 if hue < 0
230
+ hue -= 1 if hue > 1
231
+ end
232
+ Color::HSL.from_fraction(hue, sat, lum)
233
+ end
234
+
235
+ # Mix the RGB hue with White so that the RGB hue is the specified
236
+ # percentage of the resulting colour. Strictly speaking, this isn't a
237
+ # darken_by operation.
238
+ def lighten_by(percent)
239
+ mix_with(White, percent)
240
+ end
241
+
242
+ # Mix the RGB hue with Black so that the RGB hue is the specified
243
+ # percentage of the resulting colour. Strictly speaking, this isn't a
244
+ # darken_by operation.
245
+ def darken_by(percent)
246
+ mix_with(Black, percent)
247
+ end
248
+
249
+ # Mix the mask colour (which must be an RGB object) with the current
250
+ # colour at the stated opacity percentage (0..100).
251
+ def mix_with(mask, opacity)
252
+ opacity /= 100.0
253
+ rgb = self.dup
254
+
255
+ rgb.r = (@r * opacity) + (mask.r * (1 - opacity))
256
+ rgb.g = (@g * opacity) + (mask.g * (1 - opacity))
257
+ rgb.b = (@b * opacity) + (mask.b * (1 - opacity))
258
+
259
+ rgb
260
+ end
261
+
262
+ # Returns the brightness value for a colour, a number between 0..1. Based
263
+ # on the Y value of YIQ encoding, representing luminosity, or perceived
264
+ # brightness.
265
+ #
266
+ # This may be modified in a future version of color-tools to use the
267
+ # luminosity value of HSL.
268
+ def brightness
269
+ to_yiq.y
270
+ end
271
+ # Convert to grayscale.
272
+ def to_grayscale
273
+ Color::GrayScale.from_fraction(to_hsl.l)
274
+ end
275
+ alias to_greyscale to_grayscale
276
+
277
+ # Returns a new colour with the brightness adjusted by the specified
278
+ # percentage. Negative percentages will darken the colour; positive
279
+ # percentages will brighten the colour.
280
+ #
281
+ # Color::RGB::DarkBlue.adjust_brightness(10)
282
+ # Color::RGB::DarkBlue.adjust_brightness(-10)
283
+ def adjust_brightness(percent)
284
+ percent /= 100.0
285
+ percent += 1.0
286
+ percent = [ percent, 2.0 ].min
287
+ percent = [ 0.0, percent ].max
288
+
289
+ hsl = to_hsl
290
+ hsl.l *= percent
291
+ hsl.to_rgb
292
+ end
293
+
294
+ # Returns a new colour with the saturation adjusted by the specified
295
+ # percentage. Negative percentages will reduce the saturation; positive
296
+ # percentages will increase the saturation.
297
+ #
298
+ # Color::RGB::DarkBlue.adjust_saturation(10)
299
+ # Color::RGB::DarkBlue.adjust_saturation(-10)
300
+ def adjust_saturation(percent)
301
+ percent /= 100.0
302
+ percent += 1.0
303
+ percent = [ percent, 2.0 ].min
304
+ percent = [ 0.0, percent ].max
305
+
306
+ hsl = to_hsl
307
+ hsl.s *= percent
308
+ hsl.to_rgb
309
+ end
310
+
311
+ # Returns a new colour with the hue adjusted by the specified percentage.
312
+ # Negative percentages will reduce the hue; positive percentages will
313
+ # increase the hue.
314
+ #
315
+ # Color::RGB::DarkBlue.adjust_hue(10)
316
+ # Color::RGB::DarkBlue.adjust_hue(-10)
317
+ def adjust_hue(percent)
318
+ percent /= 100.0
319
+ percent += 1.0
320
+ percent = [ percent, 2.0 ].min
321
+ percent = [ 0.0, percent ].max
322
+
323
+ hsl = to_hsl
324
+ hsl.h *= percent
325
+ hsl.to_rgb
326
+ end
327
+
328
+ # Returns the red component of the colour in the normal 0 .. 255 range.
329
+ def red
330
+ @r * 255.0
331
+ end
332
+ # Returns the red component of the colour as a percentage.
333
+ def red_p
334
+ @r * 100.0
335
+ end
336
+ # Returns the red component of the colour as a fraction in the range 0.0
337
+ # .. 1.0.
338
+ def r
339
+ @r
340
+ end
341
+ # Sets the red component of the colour in the normal 0 .. 255 range.
342
+ def red=(rr)
343
+ @r = Color.normalize(rr / 255.0)
344
+ end
345
+ # Sets the red component of the colour as a percentage.
346
+ def red_p=(rr)
347
+ @r = Color.normalize(rr / 100.0)
348
+ end
349
+ # Sets the red component of the colour as a fraction in the range 0.0 ..
350
+ # 1.0.
351
+ def r=(rr)
352
+ @r = Color.normalize(rr)
353
+ end
354
+
355
+ # Returns the green component of the colour in the normal 0 .. 255 range.
356
+ def green
357
+ @g * 255.0
358
+ end
359
+ # Returns the green component of the colour as a percentage.
360
+ def green_p
361
+ @g * 100.0
362
+ end
363
+ # Returns the green component of the colour as a fraction in the range 0.0
364
+ # .. 1.0.
365
+ def g
366
+ @g
367
+ end
368
+ # Sets the green component of the colour in the normal 0 .. 255 range.
369
+ def green=(gg)
370
+ @g = Color.normalize(gg / 255.0)
371
+ end
372
+ # Sets the green component of the colour as a percentage.
373
+ def green_p=(gg)
374
+ @g = Color.normalize(gg / 100.0)
375
+ end
376
+ # Sets the green component of the colour as a fraction in the range 0.0 ..
377
+ # 1.0.
378
+ def g=(gg)
379
+ @g = Color.normalize(gg)
380
+ end
381
+
382
+ # Returns the blue component of the colour in the normal 0 .. 255 range.
383
+ def blue
384
+ @b * 255.0
385
+ end
386
+ # Returns the blue component of the colour as a percentage.
387
+ def blue_p
388
+ @b * 100.0
389
+ end
390
+ # Returns the blue component of the colour as a fraction in the range 0.0
391
+ # .. 1.0.
392
+ def b
393
+ @b
394
+ end
395
+ # Sets the blue component of the colour in the normal 0 .. 255 range.
396
+ def blue=(bb)
397
+ @b = Color.normalize(bb / 255.0)
398
+ end
399
+ # Sets the blue component of the colour as a percentage.
400
+ def blue_p=(bb)
401
+ @b = Color.normalize(bb / 100.0)
402
+ end
403
+ # Sets the blue component of the colour as a fraction in the range 0.0 ..
404
+ # 1.0.
405
+ def b=(bb)
406
+ @b = Color.normalize(bb)
407
+ end
408
+
409
+ # Adds another colour to the current colour. The other colour will be
410
+ # converted to RGB before addition. This conversion depends upon a #to_rgb
411
+ # method on the other colour.
412
+ #
413
+ # The addition is done using the RGB Accessor methods to ensure a valid
414
+ # colour in the result.
415
+ def +(other)
416
+ other = other.to_rgb
417
+ rgb = self.dup
418
+
419
+ rgb.r += other.r
420
+ rgb.g += other.g
421
+ rgb.b += other.b
422
+
423
+ rgb
424
+ end
425
+
426
+ # Subtracts another colour to the current colour. The other colour will be
427
+ # converted to RGB before subtraction. This conversion depends upon a
428
+ # #to_rgb method on the other colour.
429
+ #
430
+ # The subtraction is done using the RGB Accessor methods to ensure a valid
431
+ # colour in the result.
432
+ def -(other)
433
+ other = other.to_rgb
434
+ rgb = self.dup
435
+
436
+ rgb.r -= other.r
437
+ rgb.g -= other.g
438
+ rgb.b -= other.b
439
+
440
+ rgb
441
+ end
442
+
443
+ # Retrieve the maxmum RGB value from the current colour as a GrayScale
444
+ # colour
445
+ def max_rgb_as_grayscale
446
+ Color::GrayScale.from_fraction([@r, @g, @b].max)
447
+ end
448
+ alias max_rgb_as_greyscale max_rgb_as_grayscale
449
+
450
+ def inspect
451
+ "RGB [#{html}]"
452
+ end
453
+ end
454
+
455
+ require 'color/rgb-colors'
@@ -0,0 +1,86 @@
1
+ #--
2
+ # Color
3
+ # Colour management with Ruby
4
+ # http://rubyforge.org/projects/color
5
+ # Version 1.4.0
6
+ #
7
+ # Licensed under a MIT-style licence. See Licence.txt in the main
8
+ # distribution for full licensing information.
9
+ #
10
+ # Copyright (c) 2005 - 2007 Austin Ziegler and Matt Lyon
11
+ #
12
+ # $Id: test_all.rb 55 2007-02-03 23:29:34Z austin $
13
+ #++
14
+
15
+ # A colour object representing YIQ (NTSC) colour encoding.
16
+ class Color::YIQ
17
+ # Creates a YIQ colour object from fractional values 0 .. 1.
18
+ #
19
+ # Color::YIQ.new(0.3, 0.2, 0.1)
20
+ def self.from_fraction(y = 0, i = 0, q = 0)
21
+ color = Color::YIQ.new
22
+ color.y = y
23
+ color.i = i
24
+ color.q = q
25
+ color
26
+ end
27
+
28
+ # Creates a YIQ colour object from percentages 0 .. 100.
29
+ #
30
+ # Color::YIQ.new(10, 20, 30)
31
+ def initialize(y = 0, i = 0, q = 0)
32
+ @y = y / 100.0
33
+ @i = i / 100.0
34
+ @q = q / 100.0
35
+ end
36
+
37
+ # Compares the other colour to this one. The other colour will be
38
+ # converted to YIQ before comparison, so the comparison between a YIQ
39
+ # colour and a non-YIQ colour will be approximate and based on the other
40
+ # colour's #to_yiq conversion. If there is no #to_yiq conversion, this
41
+ # will raise an exception. This will report that two YIQ values are
42
+ # equivalent if all component colours are within COLOR_TOLERANCE of each
43
+ # other.
44
+ def ==(other)
45
+ other = other.to_yiq
46
+ other.kind_of?(Color::YIQ) and
47
+ ((@y - other.y).abs <= Color::COLOR_TOLERANCE) and
48
+ ((@i - other.i).abs <= Color::COLOR_TOLERANCE) and
49
+ ((@q - other.q).abs <= Color::COLOR_TOLERANCE)
50
+ end
51
+
52
+ def to_yiq
53
+ self
54
+ end
55
+
56
+ def brightness
57
+ @y
58
+ end
59
+ def to_grayscale
60
+ Color::GrayScale.new(@y)
61
+ end
62
+ alias to_greyscale to_grayscale
63
+
64
+ def y
65
+ @y
66
+ end
67
+ def y=(yy)
68
+ @y = Color.normalize(yy)
69
+ end
70
+ def i
71
+ @i
72
+ end
73
+ def i=(ii)
74
+ @i = Color.normalize(ii)
75
+ end
76
+ def q
77
+ @q
78
+ end
79
+ def q=(qq)
80
+ @q = Color.normalize(qq)
81
+ end
82
+
83
+ def inspect
84
+ "YIQ [%.2f%%, %.2f%%, %.2f%%]" % [ @y * 100, @i * 100, @q * 100 ]
85
+ end
86
+ end
@@ -0,0 +1,147 @@
1
+ # :title: Color -- Colour Management with Ruby
2
+ # :main: Readme.txt
3
+
4
+ #--
5
+ # Color
6
+ # Colour management with Ruby
7
+ # http://rubyforge.org/projects/color
8
+ # Version 1.4.0
9
+ #
10
+ # Licensed under a MIT-style licence. See Licence.txt in the main
11
+ # distribution for full licensing information.
12
+ #
13
+ # Copyright (c) 2005 - 2007 Austin Ziegler and Matt Lyon
14
+ #
15
+ # $Id: test_all.rb 55 2007-02-03 23:29:34Z austin $
16
+ #++
17
+
18
+ # = Colour Management with Ruby
19
+ module Color
20
+ COLOR_VERSION = '1.4.0'
21
+
22
+ class RGB; end
23
+ class CMYK; end
24
+ class GrayScale; end
25
+ class YIQ; end
26
+
27
+ # The maximum "resolution" for colour math; if any value is less than or
28
+ # equal to this value, it is treated as zero.
29
+ COLOR_EPSILON = 1e-5
30
+ # The tolerance for comparing the components of two colours. In general,
31
+ # colours are considered equal if all of their components are within this
32
+ # tolerance value of each other.
33
+ COLOR_TOLERANCE = 1e-4
34
+
35
+ class << self
36
+ # Returns +true+ if the value is less than COLOR_EPSILON.
37
+ def near_zero?(value)
38
+ (value.abs <= COLOR_EPSILON)
39
+ end
40
+
41
+ # Returns +true+ if the value is within COLOR_EPSILON of zero or less than
42
+ # zero.
43
+ def near_zero_or_less?(value)
44
+ (value < 0.0 or near_zero?(value))
45
+ end
46
+
47
+ # Returns +true+ if the value is within COLOR_EPSILON of one.
48
+ def near_one?(value)
49
+ near_zero?(value - 1.0)
50
+ end
51
+
52
+ # Returns +true+ if the value is within COLOR_EPSILON of one or more than
53
+ # one.
54
+ def near_one_or_more?(value)
55
+ (value > 1.0 or near_one?(value))
56
+ end
57
+
58
+ # Normalizes the value to the range (0.0) .. (1.0).
59
+ def normalize(value)
60
+ if near_zero_or_less? value
61
+ 0.0
62
+ elsif near_one_or_more? value
63
+ 1.0
64
+ else
65
+ value
66
+ end
67
+ end
68
+ alias normalize_fractional normalize
69
+
70
+ def normalize_to_range(value, range)
71
+ range = (range.end..range.begin) if (range.end < range.begin)
72
+
73
+ if value <= range.begin
74
+ range.begin
75
+ elsif value >= range.end
76
+ range.end
77
+ else
78
+ value
79
+ end
80
+ end
81
+
82
+ # Normalize the value to the range (0) .. (255).
83
+ def normalize_byte(value)
84
+ normalize_to_range(value, 0..255).to_i
85
+ end
86
+ alias normalize_8bit normalize_byte
87
+
88
+ # Normalize the value to the range (0) .. (65535).
89
+ def normalize_word(value)
90
+ normalize_to_range(value, 0..65535).to_i
91
+ end
92
+ alias normalize_16bit normalize_word
93
+ end
94
+ end
95
+
96
+ require 'color/rgb'
97
+ require 'color/cmyk'
98
+ require 'color/grayscale'
99
+ require 'color/hsl'
100
+ require 'color/yiq'
101
+ require 'color/rgb/metallic'
102
+
103
+ module Color
104
+ def self.const_missing(name) #:nodoc:
105
+ case name
106
+ when "VERSION", :VERSION, "COLOR_TOOLS_VERSION", :COLOR_TOOLS_VERSION
107
+ warn "Color::#{name} has been deprecated. Use Color::COLOR_VERSION instead."
108
+ Color::COLOR_VERSION
109
+ else
110
+ if Color::RGB.const_defined?(name)
111
+ warn "Color::#{name} has been deprecated. Use Color::RGB::#{name} instead."
112
+ Color::RGB.const_get(name)
113
+ else
114
+ super
115
+ end
116
+ end
117
+ end
118
+
119
+ # Provides a thin veneer over the Color module to make it seem like this
120
+ # is Color 0.1.0 (a class) and not Color 1.4.0 (a module). This
121
+ # "constructor" will be removed in the future.
122
+ #
123
+ # mode = :hsl:: +values+ must be an array of [ hue deg, sat %, lum % ].
124
+ # A Color::HSL object will be created.
125
+ # mode = :rgb:: +values+ will either be an HTML-style colour string or
126
+ # an array of [ red, green, blue ] (range 0 .. 255). A
127
+ # Color::RGB object will be created.
128
+ # mode = :cmyk:: +values+ must be an array of [ cyan %, magenta %, yellow
129
+ # %, black % ]. A Color::CMYK object will be created.
130
+ def self.new(values, mode = :rgb)
131
+ warn "Color.new has been deprecated. Use Color::#{mode.to_s.upcase}.new instead."
132
+ color = case mode
133
+ when :hsl
134
+ Color::HSL.new(*values)
135
+ when :rgb
136
+ values = [ values ].flatten
137
+ if values.size == 1
138
+ Color::RGB.from_html(*values)
139
+ else
140
+ Color::RGB.new(*values)
141
+ end
142
+ when :cmyk
143
+ Color::CMYK.new(*values)
144
+ end
145
+ color.to_hsl
146
+ end
147
+ end
@@ -0,0 +1,24 @@
1
+ #! /usr/bin/env ruby
2
+ #--
3
+ # PDF::Writer for Ruby.
4
+ # http://rubyforge.org/projects/ruby-pdf/
5
+ # Copyright 2003 - 2005 Austin Ziegler.
6
+ #
7
+ # Licensed under a MIT-style licence. See LICENCE in the main distribution
8
+ # for full licensing information.
9
+ #
10
+ # $Id: techbook 93 2005-06-13 20:03:53Z austin $
11
+ #++
12
+ begin
13
+ require 'pdf/techbook'
14
+ rescue LoadError => le
15
+ if le.message =~ %r{pdf/techbook$}
16
+ root = File.dirname(File.dirname(File.expand_path(__FILE__)))
17
+ $LOAD_PATH.unshift(File.join(root, "lib"))
18
+ require 'pdf/techbook'
19
+ else
20
+ raise
21
+ end
22
+ end
23
+
24
+ PDF::TechBook.run(ARGV)