### Home Classes Methods

### In Files

- lib/prawn/graphics/color.rb

### Methods

- #fill_color
- #fill_color=
- #hex2rgb
- #rgb2hex
- #stroke_color
- #stroke_color=

### Class/Module Index

Quicksearch

- Prawn
- Prawn::Configurable
- Prawn::Document
- Prawn::Document::BoundingBox
- Prawn::Document::ColumnBox
- Prawn::Document::GraphicsState
- Prawn::Document::Grid
- Prawn::Document::GridBox
- Prawn::Document::Internals
- Prawn::Document::Security
- Prawn::Document::Snapshot
- Prawn::Encoding
- Prawn::Errors
- Prawn::Font
- Prawn::Font::AFM
- Prawn::Font::DFont
- Prawn::Font::TTF
- Prawn::FontMetricCache
- Prawn::Graphics
- Prawn::Graphics::CapStyle
- Prawn::Graphics::Color
- Prawn::Graphics::Dash
- Prawn::Graphics::JoinStyle
- Prawn::Graphics::Patterns
- Prawn::Graphics::Transformation
- Prawn::Graphics::Transparency
- Prawn::ImageHandler
- Prawn::Images
- Prawn::Images::Image
- Prawn::Images::JPG
- Prawn::Images::PNG
- Prawn::Measurements
- Prawn::SoftMask
- Prawn::Stamp
- Prawn::SynchronizedCache
- Prawn::Table
- Prawn::Table::Cell
- Prawn::Table::Cell::Image
- Prawn::Table::Cell::InTable
- Prawn::Table::Cell::SpanDummy
- Prawn::Table::Cell::Subtable
- Prawn::Table::Cell::Text
- Prawn::Table::Cells
- Prawn::Table::ColumnWidthCalculator
- Prawn::Text
- Prawn::Text::Box
- Prawn::Text::Formatted
- Prawn::Text::Formatted::Box
- Prawn::Text::Formatted::Fragment
- Prawn::Text::Formatted::Parser
- Prawn::ThreadLocalCache
- PDF
- PDF::Core
- PDF::Core::Reference
- PDF::Core::Stream
- Arcfour
- Numeric

No matching classes.

# Prawn::Graphics::Color

### Constants

COLOR_SPACES

### Public Instance Methods

fill_color(*color) click to toggle source

Sets or returns the fill color.

When called with no argument, it returns the current fill color.

If a single argument is provided, it should be a 6 digit HTML color code.

    pdf.fill_color "f0ffc1"

If 4 arguments are provided, the color is assumed to be a CMYK value Values range from 0 - 100.

    pdf.fill_color 0, 99, 95, 0

    # File lib/prawn/graphics/color.rb, line 27
    def fill_color(*color)
      return current_fill_color if color.empty?
      self.current_fill_color = process_color(*color)
      set_fill_color
    end

Also aliased as: fill_color=
fill_color=(*color) click to toggle source
Alias for: fill_color
hex2rgb(hex) click to toggle source

Converts hex string into RGB value array:

    >> Prawn::Graphics::Color.hex2rgb("ff7808")
    => [255, 120, 8]

    # File lib/prawn/graphics/color.rb, line 75
    def hex2rgb(hex)
      r,g,b = hex[0..1], hex[2..3], hex[4..5]
      [r,g,b].map { |e| e.to_i(16) }
    end

rgb2hex(rgb) click to toggle source

Converts RGB value array to hex string suitable for use with fill_color and stroke_color

    >> Prawn::Graphics::Color.rgb2hex([255,120,8])
    => "ff7808"

    # File lib/prawn/graphics/color.rb, line 66
    def rgb2hex(rgb)
      rgb.map { |e| "%02x" % e }.join
    end

stroke_color(*color) click to toggle source

Sets or returns the line stroking color.

When called with no argument, it returns the current stroking color.

If a single argument is provided, it should be a 6 digit HTML color code.

    pdf.stroke_color "f0ffc1"

If 4 arguments are provided, the color is assumed to be a CMYK value Values range from 0 - 100.

    pdf.stroke_color 0, 99, 95, 0

    # File lib/prawn/graphics/color.rb, line 49
    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

Also aliased as: stroke_color=
stroke_color=(*color) click to toggle source
Alias for: stroke_color

[Validate]

Generated with the Darkfish Rdoc Generator 2.