Skip to content

Commit

Permalink
Added support for specifying fill colors with cmyk.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon Gilbraith committed Oct 17, 2008
1 parent 522070b commit a00fc97
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
16 changes: 12 additions & 4 deletions lib/core/rfpdf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ module RFPDF
# * <tt>:border_width</tt> - Default value is <tt>0.5</tt>.
# * <tt>:fill</tt> - Fill the box, 0 = no, 1 = yes? Default value is <tt>1</tt>.
# * <tt>:fill_color</tt> - Default value is nothing or <tt>COLOR_PALETTE[:white]</tt>.
# * <tt>:fill_colorspace</tt> - Default value is :rgb or <tt>''</tt>.
#
# Example:
#
Expand All @@ -23,9 +24,10 @@ def draw_circle(mid_x, mid_y, radius, options = {})
options[:border_width] ||= 0.5
options[:fill] ||= 1
options[:fill_color] ||= RFPDF::COLOR_PALETTE[:white]
options[:fill_colorspace] ||= :rgb
SetLineWidth(options[:border_width])
set_draw_color_a(options[:border_color])
set_fill_color_a(options[:fill_color])
set_fill_color_a(options[:fill_color], :options[:colorspace])
fd = ""
fd = "D" if options[:border] == 1
fd += "F" if options[:fill] == 1
Expand Down Expand Up @@ -111,6 +113,7 @@ def draw_text_block(x, y, text, left_margin, right_margin_from_right_edge, optio
# * <tt>:border_width</tt> - Default value is <tt>0.5</tt>.
# * <tt>:fill</tt> - Fill the box, 0 = no, 1 = yes? Default value is <tt>1</tt>.
# * <tt>:fill_color</tt> - Default value is nothing or <tt>COLOR_PALETTE[:white]</tt>.
# * <tt>:fill_colorspace</tt> - Default value is :rgb or <tt>''</tt>.
#
# Example:
#
Expand All @@ -122,9 +125,10 @@ def draw_box(x, y, w, h, options = {})
options[:border_width] ||= 0.5
options[:fill] ||= 1
options[:fill_color] ||= RFPDF::COLOR_PALETTE[:white]
options[:fill_colorspace] ||= :rgb
SetLineWidth(options[:border_width])
set_draw_color_a(options[:border_color])
set_fill_color_a(options[:fill_color])
set_fill_color_a(options[:fill_color], options[:fill_colorspace])
fd = ""
fd = "D" if options[:border] == 1
fd += "F" if options[:fill] == 1
Expand Down Expand Up @@ -252,8 +256,12 @@ def set_draw_color_a(color = RFPDF::COLOR_PALETTE[:black])
#
# set_fill_color_a(ReportHelper::COLOR_PALETTE[:dark_blue])
#
def set_fill_color_a(color = RFPDF::COLOR_PALETTE[:white])
SetFillColor(color[0], color[1], color[2])
def set_fill_color_a(color = RFPDF::COLOR_PALETTE[:white], colorspace = :rgb)
if colorspace == :cmyk
SetCmykFillColor(color[0], color[1], color[2], color[3])
else
SetFillColor(color[0], color[1], color[2])
end
end

# Set the text color. Default value is <tt>COLOR_PALETTE[:white]</tt>.
Expand Down
15 changes: 15 additions & 0 deletions lib/tcpdf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1087,6 +1087,21 @@ def SetFillColor(r, g=-1, b=-1, storeprev=false)
end
alias_method :set_fill_color, :SetFillColor

# This hasn't been ported from tcpdf, it's a variation on SetTextColor for setting cmyk colors
def SetCmykFillColor(c, m, y, k, storeprev=false)
#Set color for all filling operations
@fill_color=sprintf('%.3f %.3f %.3f %.3f k', c, m, y, k);
@color_flag=(@fill_color!=@text_color);
if (storeprev)
# store color as previous value
@prevtext_color = [c, m, y, k]
end
if (@page>0)
out(@fill_color);
end
end
alias_method :set_cmyk_fill_color, :SetCmykFillColor

#
# Defines the color used for text. It can be expressed in RGB components or gray scale. The method can be called before the first page is created and the value is retained from page to page.
# @param int :r If g et b are given, red component; if not, indicates the gray level. Value between 0 and 255
Expand Down

0 comments on commit a00fc97

Please sign in to comment.