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 box 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].



97
98
99
100
101
102
103
104
105
106
107
# File 'lib/hexapdf/content/processor.rb', line 97

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.



89
90
91
# File 'lib/hexapdf/content/processor.rb', line 89

def code_point
  @code_point
end

#stringObject (readonly)

The Unicode value of the code point.



92
93
94
# File 'lib/hexapdf/content/processor.rb', line 92

def string
  @string
end

Instance Method Details

#lower_leftObject

:call-seq:

glyph_box.lower_left    -> [llx, lly]

Returns the lower left coordinate



113
114
115
# File 'lib/hexapdf/content/processor.rb', line 113

def lower_left
  [@llx, @lly]
end

#lower_rightObject

:call-seq:

glyph_box.lower_right   -> [lrx, lry]

Returns the lower right coordinate



121
122
123
# File 'lib/hexapdf/content/processor.rb', line 121

def lower_right
  [@lrx, @lry]
end

#pointsObject

:call-seq:

glyph_box.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.



147
148
149
# File 'lib/hexapdf/content/processor.rb', line 147

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

#upper_leftObject

:call-seq:

glyph_box.upper_left    -> [ulx, uly]

Returns the upper left coordinate



129
130
131
# File 'lib/hexapdf/content/processor.rb', line 129

def upper_left
  [@ulx, @uly]
end

#upper_rightObject

:call-seq:

glyph_box.upper_right    -> [urx, ury]

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



138
139
140
# File 'lib/hexapdf/content/processor.rb', line 138

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