lib/prawn/table/cell/text.rb in prawn-0.11.1.pre vs lib/prawn/table/cell/text.rb in prawn-0.11.1
- old
+ new
@@ -12,13 +12,13 @@
# A Cell that contains text. Has some limited options to set font family,
# size, and style.
#
class Text < Cell
- TextOptions = [:inline_format, :kerning, :size, :style,
- :align, :valign, :rotate, :rotate_around, :leading, :single_line,
- :skip_encoding, :overflow, :min_font_size]
+ TextOptions = [:inline_format, :kerning, :size, :align, :valign,
+ :rotate, :rotate_around, :leading, :single_line, :skip_encoding,
+ :overflow, :min_font_size]
TextOptions.each do |option|
define_method("#{option}=") { |v| @text_options[option] = v }
define_method(option) { @text_options[option] }
end
@@ -26,24 +26,25 @@
attr_writer :font, :text_color
def initialize(pdf, point, options={})
@text_options = {}
super
-
- # Sets a reasonable minimum width. If the cell has any content, make
- # sure we have enough width to be at least one character wide. This is
- # a bit of a hack, but it should work well enough.
- min_content_width = [natural_content_width, styled_width_of("M")].min
- @min_width = padding_left + padding_right + min_content_width
end
# Returns the font that will be used to draw this cell.
#
def font
with_font { @pdf.font }
end
+ # Sets the style of the font in use. Equivalent to the Text::Box
+ # +style+ option, but we already have a style method.
+ #
+ def font_style=(style)
+ @text_options[:style] = style
+ end
+
# Returns the width of this text with no wrapping. This will be far off
# from the final width if the text is long.
#
def natural_content_width
[styled_width_of(@content), @pdf.bounds.width].min
@@ -54,11 +55,11 @@
#
def natural_content_height
with_font do
b = text_box(:width => content_width + FPTolerance)
b.render(:dry_run => true)
- b.height
+ b.height + b.line_gap
end
end
# Draws the text content into its bounding box.
#
@@ -72,9 +73,18 @@
end
end
end
protected
+
+ def set_width_constraints
+ # Sets a reasonable minimum width. If the cell has any content, make
+ # sure we have enough width to be at least one character wide. This is
+ # a bit of a hack, but it should work well enough.
+ min_content_width = [natural_content_width, styled_width_of("M")].min
+ @min_width ||= padding_left + padding_right + min_content_width
+ super
+ end
def with_font
@pdf.save_font do
options = {}
options[:style] = @text_options[:style] if @text_options[:style]