Class: HexaPDF::Rectangle

Inherits:
PDFArray show all
Defined in:
lib/hexapdf/rectangle.rb

Overview

Implementation of the PDF rectangle data structure.

Rectangles are used for describing page and bounding boxes. They are represented by arrays of four numbers specifying the (x,y) coordinates of any diagonally opposite corners.

This class simplifies the usage of rectangles by automatically normalizing the coordinates so that they are in the order:

[left, bottom, right, top]

where left is the bottom-left x-coordinate, bottom is the bottom-left y-coordinate, right is the top-right x-coordinate and top is the top-right y-coordinate.

See: PDF2.0 s7.9.5

Instance Attribute Summary

Attributes inherited from Object

#data, #document, #must_be_indirect

Instance Method Summary collapse

Methods inherited from PDFArray

#<<, #[], #[]=, #delete, #delete_at, #each, #empty?, #index, #insert, #length, #reject!, #slice!, #to_ary, #values_at

Methods inherited from Object

#<=>, #==, #cache, #cached?, #clear_cache, deep_copy, #deep_copy, #document?, #eql?, field, #gen, #gen=, #hash, #indirect?, #initialize, #inspect, make_direct, #must_be_indirect?, #null?, #oid, #oid=, #type, #validate, #value, #value=

Constructor Details

This class inherits a constructor from HexaPDF::Object

Instance Method Details

#bottomObject

Returns the y-coordinate of the bottom-left corner.



78
79
80
# File 'lib/hexapdf/rectangle.rb', line 78

def bottom
  self[1]
end

#bottom=(y) ⇒ Object

Sets the y-coordinate of the bottom-left corner to the given value.



83
84
85
# File 'lib/hexapdf/rectangle.rb', line 83

def bottom=(y)
  value[1] = y
end

#heightObject

Returns the height of the rectangle.



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

def height
  self[3] - self[1]
end

#height=(val) ⇒ Object

Sets the height of the rectangle to the given value.



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

def height=(val)
  self[3] = self[1] + val
end

#leftObject

Returns the x-coordinate of the bottom-left corner.



58
59
60
# File 'lib/hexapdf/rectangle.rb', line 58

def left
  self[0]
end

#left=(x) ⇒ Object

Sets the x-coordinate of the bottom-left corner to the given value.



63
64
65
# File 'lib/hexapdf/rectangle.rb', line 63

def left=(x)
  value[0] = x
end

#rightObject

Returns the x-coordinate of the top-right corner.



68
69
70
# File 'lib/hexapdf/rectangle.rb', line 68

def right
  self[2]
end

#right=(x) ⇒ Object

Sets the x-coordinate of the top-right corner to the given value.



73
74
75
# File 'lib/hexapdf/rectangle.rb', line 73

def right=(x)
  value[2] = x
end

#topObject

Returns the y-coordinate of the top-right corner.



88
89
90
# File 'lib/hexapdf/rectangle.rb', line 88

def top
  self[3]
end

#top=(y) ⇒ Object

Sets the y-coordinate of the top-right corner to the given value.



93
94
95
# File 'lib/hexapdf/rectangle.rb', line 93

def top=(y)
  value[3] = y
end

#widthObject

Returns the width of the rectangle.



98
99
100
# File 'lib/hexapdf/rectangle.rb', line 98

def width
  self[2] - self[0]
end

#width=(val) ⇒ Object

Sets the width of the rectangle to the given value.



103
104
105
# File 'lib/hexapdf/rectangle.rb', line 103

def width=(val)
  self[2] = self[0] + val
end