### Home Classes Methods

### In Files

- lib/prawn/table/cell/text.rb

### Parent

Prawn::Table::Cell

### Methods

- ::new
- #draw_content
- #font
- #font_style=
- #natural_content_height
- #natural_content_width
- #set_width_constraints
- #styled_width_of
- #text_box
- #with_font
- #with_text_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::Table::Cell::Text

A Cell that contains text. Has some limited options to set font family, size, and style.

### Constants

TextOptions

### Attributes

font[W]
text_color[W]

### Public Class Methods

new(pdf, point, options={}) click to toggle source

    # File lib/prawn/table/cell/text.rb, line 27
    def initialize(pdf, point, options={})
      @text_options = {}
      super
    end

### Public Instance Methods

draw_content() click to toggle source

Draws the text content into its bounding box.

    # File lib/prawn/table/cell/text.rb, line 65
    def draw_content
      with_font do
        @pdf.move_down((@pdf.font.line_gap + @pdf.font.descender)/2)
        with_text_color do
          text_box(:width => spanned_content_width + FPTolerance,
                   :height => spanned_content_height + FPTolerance,
                   :at => [0, @pdf.cursor]).render
        end
      end
    end

font() click to toggle source

Returns the font that will be used to draw this cell.

    # File lib/prawn/table/cell/text.rb, line 34
    def font
      with_font { @pdf.font }
    end

font_style=(style) click to toggle source

Sets the style of the font in use. Equivalent to the Text::Box `style` option, but we already have a style method.

    # File lib/prawn/table/cell/text.rb, line 41
    def font_style=(style)
      @text_options[:style] = style
    end

natural_content_height() click to toggle source

Returns the natural height of this block of text, wrapped to the preset width.

    # File lib/prawn/table/cell/text.rb, line 55
    def natural_content_height
      with_font do
        b = text_box(:width => spanned_content_width + FPTolerance)
        b.render(:dry_run => true)
        b.height + b.line_gap
      end
    end

natural_content_width() click to toggle source

Returns the width of this text with no wrapping. This will be far off from the final width if the text is long.

    # File lib/prawn/table/cell/text.rb, line 48
    def natural_content_width
      @natural_content_width ||= [styled_width_of(@content), @pdf.bounds.width].min
    end

set_width_constraints() click to toggle source

    # File lib/prawn/table/cell/text.rb, line 76
    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.
      unless defined?(@min_width) && @min_width
        min_content_width = [natural_content_width, styled_width_of_single_character].min
        @min_width = padding_left + padding_right + min_content_width
        super
      end
    end

### Protected Instance Methods

styled_width_of(text) click to toggle source

Returns the width of `text` under the given text options.

    # File lib/prawn/table/cell/text.rb, line 134
    def styled_width_of(text)
      @pdf.width_of(text, @text_options)
    end

text_box(extra_options={}) click to toggle source

    # File lib/prawn/table/cell/text.rb, line 115
    def text_box(extra_options={})
      if p = @text_options[:inline_format]
        p = [] unless p.is_a?(Array)
        options = @text_options.dup
        options.delete(:inline_format)
        options.merge!(extra_options)
        options[:document] = @pdf

        array = @pdf.text_formatter.format(@content, *p)
        ::Prawn::Text::Formatted::Box.new(array,
          options.merge(extra_options).merge(:document => @pdf))
      else
        ::Prawn::Text::Box.new(@content, @text_options.merge(extra_options).
           merge(:document => @pdf))
      end
    end

with_font() click to toggle source

    # File lib/prawn/table/cell/text.rb, line 89
    def with_font
      @pdf.save_font do
        options = {}
        options[:style] = @text_options[:style] if @text_options[:style]
        options[:style] ||= @pdf.font.options[:style] if @pdf.font.options[:style]

        @pdf.font(defined?(@font) && @font || @pdf.font.family, options)

        yield
      end
    end

with_text_color() click to toggle source

    # File lib/prawn/table/cell/text.rb, line 101
    def with_text_color
      if defined?(@text_color) && @text_color
        begin
          old_color = @pdf.fill_color || '000000'
          @pdf.fill_color(@text_color)
          yield
        ensure
          @pdf.fill_color(old_color)
        end
      else
        yield
      end
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.