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



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

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.



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

def code_point
  @code_point
end

#stringObject (readonly)

The Unicode value of the code point.



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

def string
  @string
end

Instance Method Details

#lower_leftObject

:call-seq:

glyph_box.lower_left    -> [llx, lly]

Returns the lower left coordinate



111
112
113
# File 'lib/hexapdf/content/processor.rb', line 111

def lower_left
  [@llx, @lly]
end

#lower_rightObject

:call-seq:

glyph_box.lower_right   -> [lrx, lry]

Returns the lower right coordinate



119
120
121
# File 'lib/hexapdf/content/processor.rb', line 119

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.



145
146
147
# File 'lib/hexapdf/content/processor.rb', line 145

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



127
128
129
# File 'lib/hexapdf/content/processor.rb', line 127

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.



136
137
138
# File 'lib/hexapdf/content/processor.rb', line 136

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