module Prawn::Graphics::Color
Implements color handling.
Constants
- COLOR_SPACES
Public Instance Methods
Source
# File lib/prawn/graphics/color.rb, line 35 def fill_color(*color) return current_fill_color if color.empty? self.current_fill_color = process_color(*color) set_fill_color end
Sets or returns the fill color.
@overload fill_color
Returns the current fill color. @return [String, Array<Number>]
@overload fill_color(color)
Sets the fill color. If a single argument is provided, it should be a 6 digit HTML color code. ```ruby pdf.fill_color "f0ffc1" ``` If 4 arguments are provided, the color is assumed to be a CMYK value. Values range is 0–100. ```ruby pdf.fill_color 0, 99, 95, 0 ``` @param color [String, Array<Number>] @return [void]
Also aliased as: fill_color=
Source
# File lib/prawn/graphics/color.rb, line 101 def hex2rgb(hex) r = hex[0..1] g = hex[2..3] b = hex[4..5] [r, g, b].map { |e| e.to_i(16) } end
Converts hex string into RGB value array.
@example
Prawn::Graphics::Color.hex2rgb("ff7808") #=> [255, 120, 8]
@param hex [String] must be 6-digits long. @return [Array(Integer, Integer, Integer)]
Source
# File lib/prawn/graphics/color.rb, line 89 def rgb2hex(rgb) rgb.map { |e| format('%<value>02x', value: e) }.join end
Converts RGB value array to hex string suitable for use with {fill_color} and {stroke_color}.
@example
Prawn::Graphics::Color.rgb2hex([255, 120, 8]) #=> "ff7808"
@param rgb [Array(Number, Number, Number)]
Each component has to be in the range from 0 to 255.
@return [String]
Source
# File lib/prawn/graphics/color.rb, line 67 def stroke_color(*color) return current_stroke_color if color.empty? color = process_color(*color) self.current_stroke_color = color set_stroke_color(color) end
Sets or returns the line stroking color.
@overload stroke_color
When called with no argument, it returns the current stroking color. @return [String, Array<Number>]
@overload stroke_color(color)
Sets the stroking color.
@param color [String, Array<Number>] new stroking color:
- In String form it should be a 6 digit HTML color code.
```ruby
pdf.stroke_color "f0ffc1"
```
- If 4 arguments are provided, the color is assumed to be a CMYK
value. Values range from 0 to 100.
```ruby
pdf.stroke_color 0, 99, 95, 0
```
@return [void]
Also aliased as: stroke_color=