Class: PDF::Reader::TextRun

### Home Classes Methods

### In Files

- lib/pdf/reader/text_run.rb

### Parent

Object

### Methods

- ::new
- #+
- #<=>
- #endx
- #inspect
- #mean_character_width
- #mergable?

### Included Modules

- Comparable

### Files

- MIT-LICENSE
- README.rdoc
- TODO
- mac_expert.txt
- mac_roman.txt
- pdf_doc.txt
- standard.txt
- symbol.txt
- win_ansi.txt
- zapf_dingbats.txt
- glyphlist.txt

### Class/Module Index

Quicksearch

- PDF
- PDF::Reader
- PDF::Reader::Buffer
- PDF::Reader::CidWidths
- PDF::Reader::EncryptedPDFError
- PDF::Reader::Filter
- PDF::Reader::Filter::Ascii85
- PDF::Reader::Filter::AsciiHex
- PDF::Reader::Filter::Depredict
- PDF::Reader::Filter::Flate
- PDF::Reader::Filter::Lzw
- PDF::Reader::Filter::Null
- PDF::Reader::Filter::RunLength
- PDF::Reader::Font
- PDF::Reader::FontDescriptor
- PDF::Reader::FormXObject
- PDF::Reader::InvalidObjectError
- PDF::Reader::MalformedPDFError
- PDF::Reader::ObjectCache
- PDF::Reader::ObjectHash
- PDF::Reader::PageLayout
- PDF::Reader::PageState
- PDF::Reader::PageTextReceiver
- PDF::Reader::Parser
- PDF::Reader::PrintReceiver
- PDF::Reader::Reference
- PDF::Reader::RegisterReceiver
- PDF::Reader::ResourceMethods
- PDF::Reader::StandardSecurityHandler
- PDF::Reader::Stream
- PDF::Reader::SynchronizedCache
- PDF::Reader::TextReceiver
- PDF::Reader::TextRun
- PDF::Reader::TransformationMatrix
- PDF::Reader::UnsupportedFeatureError
- PDF::Reader::WidthCalculator
- PDF::Reader::WidthCalculator::BuiltIn
- PDF::Reader::WidthCalculator::Composite
- PDF::Reader::WidthCalculator::TrueType
- PDF::Reader::WidthCalculator::TypeOneOrThree
- PDF::Reader::WidthCalculator::TypeZero
- PDF::Reader::XRef
- AFM
- AFM::Font

No matching classes.

# PDF::Reader::TextRun

A value object that represents one or more consecutive characters on a page.

### Attributes

font_size[R]
text[R]
to_s[R]
width[R]
x[R]
y[R]

### Public Class Methods

new(x, y, width, font_size, text) click to toggle source

    # File lib/pdf/reader/text_run.rb, line 11
    def initialize(x, y, width, font_size, text)
      @x = x
      @y = y
      @width = width
      @font_size = font_size.floor
      @text = text
    end

### Public Instance Methods

+(other) click to toggle source

    # File lib/pdf/reader/text_run.rb, line 47
    def +(other)
      raise ArgumentError, "#{other} cannot be merged with this run" unless mergable?(other)

      if (other.x - endx) <( font_size * 0.2)
        TextRun.new(x, y, other.endx - x, font_size, text + other.text)
      else
        TextRun.new(x, y, other.endx - x, font_size, "#{text} #{other.text}")
      end
    end

<=>(other) click to toggle source

Allows collections of TextRun objects to be sorted. They will be sorted in order of their position on a cartesian plain - Top Left to Bottom Right

    # File lib/pdf/reader/text_run.rb, line 21
    def <=>(other)
      if x == other.x && y == other.y
        0
      elsif y < other.y
        1
      elsif y > other.y
        -1
      elsif x < other.x
        -1
      elsif x > other.x
        1
      end
    end

endx() click to toggle source

    # File lib/pdf/reader/text_run.rb, line 35
    def endx
      @endx ||= x + width
    end

inspect() click to toggle source

    # File lib/pdf/reader/text_run.rb, line 57
    def inspect
      "#{text} w:#{width} f:#{font_size} @#{x},#{y}"
    end

mean_character_width() click to toggle source

    # File lib/pdf/reader/text_run.rb, line 39
    def mean_character_width
      @width / character_count
    end

mergable?(other) click to toggle source

    # File lib/pdf/reader/text_run.rb, line 43
    def mergable?(other)
      y.to_i == other.y.to_i && font_size == other.font_size && mergable_range.include?(other.x)
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.