Sets the fill gradient from color1 to color2.
It accepts CMYK and RGB colors, like #. Both colors must be of the same type.
point, width and height define a bounding box in which the gradient will be rendered. For example, if you want to have page full of text with gradually changing color:
pdf.fill_gradient [0, pdf.bounds.height], pdf.bounds.width,
pdf.bounds.height, 'FF0000', '0000FF'
pdf.text 'lots of text'*1000
:stroke_bounds - draw gradient bounds
# File lib/prawn/graphics/gradient.rb, line 26
26: def fill_gradient(point, width, height, color1, color2, options = {})
27: set_gradient(:fill, point, width, height, color1, color2, options)
28: end
Sets the stroke gradient from color1 to color2.
See # for details.
# File lib/prawn/graphics/gradient.rb, line 33
33: def stroke_gradient(point, width, height, color1, color2, options = {})
34: set_gradient(:stroke, point, width, height, color1, color2, options)
35: end
# File lib/prawn/graphics/gradient.rb, line 39
39: def set_gradient(type, point, width, height, color1, color2, options)
40: if options[:stroke_bounds]
41: stroke_color 0, 0, 0, 100
42: stroke_rectangle point, width, height
43: end
44:
45: if color_type(color1) != color_type(color2)
46: raise ArgumentError, 'both colors must be of the same type: RGB or CMYK'
47: end
48:
49: process_color color1
50: process_color color2
51:
52: shader = ref!({
53: :FunctionType => 2,
54: :Domain => [0.0, 1.0],
55: :C0 => normalize_color(color1),
56: :C1 => normalize_color(color2),
57: :N => 1,
58: })
59:
60: shading = ref!({
61: :ShadingType => 2, # axial shading
62: :ColorSpace => color_type(color1) == :RGB ? :DeviceRGB : :DeviceCMYK,
63: :Coords => [0.0, 0.0, 1.0, 0.0],
64: :Function => shader,
65: :Extend => [true, true],
66: })
67:
68: x, y = *point
69: shading_pattern = ref!({
70: :PatternType => 2, # shading pattern
71: :Shading => shading,
72: :Matrix => [0,-height, -width, 0, x, y],
73: })
74:
75: patterns = page.resources[:Pattern] ||= {}
76: id = patterns.empty? ? 'SP1' : patterns.keys.sort.last.succ
77: patterns[id] = shading_pattern
78:
79: set_color type, id, :pattern => true
80: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.