### Home Classes Methods

### In Files

- lib/prawn/text/box.rb

### Parent

Object

### Methods

- #wrap_line

### Files

- COPYING
- HACKING
- LICENSE
- README

### Class/Module Index

Quicksearch

- Prawn
- Prawn::Core
- Prawn::Document
- Prawn::Document::Annotations
- Prawn::Document::BoundingBox
- Prawn::Document::ColumnBox
- Prawn::Document::Destinations
- Prawn::Document::GraphicsState
- Prawn::Document::Internals
- Prawn::Document::PageGeometry
- Prawn::Document::Snapshot
- Prawn::Encoding
- Prawn::Errors
- Prawn::Font
- Prawn::Font::AFM
- Prawn::Font::DFont
- Prawn::Font::TTF
- Prawn::Graphics
- Prawn::Graphics::CapStyle
- Prawn::Graphics::Color
- Prawn::Graphics::Dash
- Prawn::Graphics::JoinStyle
- Prawn::Graphics::Transformation
- Prawn::Graphics::Transparency
- Prawn::Images
- Prawn::Images::JPG
- Prawn::Images::PNG
- Prawn::Measurements
- Prawn::Outline
- Prawn::Stamp
- Prawn::Text
- Prawn::Text::Box
- Prawn::Text::LineWrap
- File
- Numeric

No matching classes.

# Prawn::Text::LineWrap

### Public Instance Methods

wrap_line(line, options) click to toggle source

    # File lib/prawn/text/box.rb, line 348
    def wrap_line(line, options)
      @document = options[:document]
      @size = options[:size]
      @kerning = options[:kerning]
      @width = options[:width]
      @accumulated_width = 0
      @output = ""

      scan_pattern = @document.font.unicode? ? /\S+|\s+/ : /\S+|\s+/
      space_scan_pattern = @document.font.unicode? ? /\s/ : /\s/

      line.scan(scan_pattern).each do |segment|
        # yes, this block could be split out into another method, but it is
        # called on every word printed, so I'm keeping it here for speed

        segment_width = @document.width_of(segment,
                                           :size => @size,
                                           :kerning => @kerning)

        if @accumulated_width + segment_width <= @width
          @accumulated_width += segment_width
          @output << segment
        else
          # if the line contains white space, don't split the
          # final word that doesn't fit, just return what fits nicely
          break if @output =~ space_scan_pattern
          wrap_by_char(segment)
          break
        end
      end
      @output
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.