Class: HexaPDF::Content::Processor::GlyphBox

Inherits:
Object
  • Object
show all
Defined in:
lib/hexapdf/content/processor.rb

Overview

Represents an (immutable) glyph box with positioning information.

Since the glyph may have been transformed by an affine matrix, the bounding may not be a rectangle in all cases but it is always a parallelogram.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(code_point, string, llx, lly, lrx, lry, ulx, uly) ⇒ GlyphBox

Creates a new glyph box for the given code point/Unicode value pair with the lower left coordinate [llx, lly], the lower right coordinate [lrx, lry], and the upper left coordinate [ulx, uly].



92
93
94
95
96
97
98
99
100
101
102
# File 'lib/hexapdf/content/processor.rb', line 92

def initialize(code_point, string, llx, lly, lrx, lry, ulx, uly)
  @code_point = code_point
  @string = string.freeze
  @llx = llx
  @lly = lly
  @lrx = lrx
  @lry = lry
  @ulx = ulx
  @uly = uly
  freeze
end

Instance Attribute Details

#code_pointObject (readonly)

The code point representing the glyph.



84
85
86
# File 'lib/hexapdf/content/processor.rb', line 84

def code_point
  @code_point
end

#stringObject (readonly)

The Unicode value of the code point.



87
88
89
# File 'lib/hexapdf/content/processor.rb', line 87

def string
  @string
end

Instance Method Details

#lower_leftObject

:call-seq:

fragment.lower_left    -> [llx, lly]

Returns the lower left coordinate



108
109
110
# File 'lib/hexapdf/content/processor.rb', line 108

def lower_left
  [@llx, @lly]
end

#lower_rightObject

:call-seq:

fragment.lower_right   -> [lrx, lry]

Returns the lower right coordinate



116
117
118
# File 'lib/hexapdf/content/processor.rb', line 116

def lower_right
  [@lrx, @lry]
end

#pointsObject

:call-seq:

fragment.points         -> [llx, lly, lrx, lry, urx, ury, ulx, uly]

Returns the four corners of the box as an array of coordinates, starting with the lower left corner and going counterclockwise.



142
143
144
# File 'lib/hexapdf/content/processor.rb', line 142

def points
  [@llx, @lly, @lrx, @lry, @ulx + (@lrx - @llx), @uly + (@lry - @lly), @ulx, @uly]
end

#upper_leftObject

:call-seq:

fragment.upper_left    -> [ulx, uly]

Returns the upper left coordinate



124
125
126
# File 'lib/hexapdf/content/processor.rb', line 124

def upper_left
  [@ulx, @uly]
end

#upper_rightObject

:call-seq:

fragment.upper_right    -> [urx, ury]

Returns the upper right coordinate which is computed by using the other three points of the parallelogram.



133
134
135
# File 'lib/hexapdf/content/processor.rb', line 133

def upper_right
  [@ulx + (@lrx - @llx), @uly + (@lry - @lly)]
end