lib/prawn/table/cell.rb in prawn-layout-0.1.0 vs lib/prawn/table/cell.rb in prawn-layout-0.2.0.1
- old
+ new
@@ -50,10 +50,11 @@
# <tt>:borders</tt>:: An array of sides which should have a border. Any of <tt>:top</tt>, <tt>:left</tt>, <tt>:right</tt>, <tt>:bottom</tt>
# <tt>:border_width</tt>:: The border line width. Defaults to 1.
# <tt>:border_style</tt>:: One of <tt>:all</tt>, <tt>:no_top</tt>, <tt>:no_bottom</tt>, <tt>:sides</tt>, <tt>:none</tt>, <tt>:bottom_only</tt>. Defaults to :all.
# <tt>:border_color</tt>:: The color of the cell border.
# <tt>:font_size</tt>:: The font size for the cell text.
+ # <tt>:font_style</tt>:: The font style for the cell text.
#
def initialize(options={})
@point = options[:point]
@document = options[:document]
@text = options[:text].to_s
@@ -65,10 +66,11 @@
@border_style = options[:border_style] || :all
@border_color = options[:border_color]
@background_color = options[:background_color]
@align = options[:align] || :left
@font_size = options[:font_size]
+ @font_style = options[:font_style]
@horizontal_padding = options[:horizontal_padding] || 0
@vertical_padding = options[:vertical_padding] || 0
if options[:padding]
@@ -76,11 +78,11 @@
end
end
attr_accessor :point, :border_style, :border_width, :background_color,
:document, :horizontal_padding, :vertical_padding, :align,
- :borders, :text_color, :border_color
+ :borders, :text_color, :border_color, :font_size, :font_style
attr_writer :height, :width #:nodoc:
# Returns the cell's text as a string.
#
@@ -95,11 +97,11 @@
end
# The width of the cell in PDF points
#
def width
- @width || (@document.font.width_of(@text, :size => @font_size)) + 2*@horizontal_padding
+ @width || (@document.width_of(@text, :size => @font_size)) + 2*@horizontal_padding
end
# The height of the cell in PDF points
#
def height
@@ -107,11 +109,19 @@
end
# The height of the text area excluding the vertical padding
#
def text_area_height
- @document.height_of(@text, text_area_width)
+ text_height = 0
+ if @font_size
+ @document.font_size(@font_size) do
+ text_height = @document.height_of(@text, text_area_width)
+ end
+ else
+ text_height = @document.height_of(@text, text_area_width)
+ end
+ text_height
end
# Draws the cell onto the PDF document
#
def draw
@@ -171,9 +181,10 @@
@document.move_down((@document.font.line_gap - @document.font.descender)/2)
options = {:align => @align, :final_gap => false}
options[:size] = @font_size if @font_size
+ options[:style] = @font_style if @font_style
@document.mask(:fill_color) do
@document.fill_color @text_color if @text_color
@document.text @text, options
end