Class: HexaPDF::Document::Destinations::Destination
- Inherits:
-
Object
- Object
- HexaPDF::Document::Destinations::Destination
- Defined in:
- lib/hexapdf/document/destinations.rb
Overview
Wraps an explicit destination array to allow easy access to query its properties.
A *destination array* has the form
[page, type, *arguments]
where page
is either a page object or a page number (in case of a destination to a page in a remote PDF document), type
is the destination type (see below) and arguments
are the required arguments for the specific type of destination.
Destination Types
There are eight different types of destinations, each taking different arguments. The arguments are marked up in the list below and are in the correct order for use in the destination array. The first name in the list is the PDF internal name, the second one the explicit, more descriptive one used by HexaPDF (though the PDF internal name can also be used):
- :XYZ, :xyz
-
Display the page with the given (
left
,top
) coordinate at the upper-left corner of the window and the specified magnification (zoom
) factor. Anil
value for any argument means not changing it from the current value. - :Fit, :fit_page
-
Display the page so that it fits horizontally and vertically within the window.
- :FitH, :fit_page_horizontal
-
Display the page so that it fits horizontally within the window, with the given
top
coordinate being at the top of the window. Anil
value fortop
means not changing it from the current value. - :FitV, :fit_page_vertical
-
Display the page so that it fits vertically within the window, with the given
left
coordinate being at the left of the window. Anil
value forleft
means not changing it from the current value. - :FitR, :fit_rectangle
-
Display the page so that the rectangle specified by (
left
,bottom
)-(right
,top
) fits horizontally and vertically within the window. - :FitB, :fit_bounding_box
-
Display the page so that its bounding box fits horizontally and vertically within the window.
- :FitBH, :fit_bounding_box_horizontal
-
Display the page so that its bounding box fits horizontally within the window, with the given
top
coordinate being at the top of the window. Anil
value fortop
means not changing it from the current value. - :FitBV, :fit_bounding_box_vertical
-
Display the page so that its bounding box fits vertically within the window, with the given
left
coordinate being at the left of the window. Anil
value forleft
means not changing it from the current value.
Constant Summary collapse
- TYPE_MAPPING =
:nodoc:
{ #:nodoc: XYZ: :xyz, Fit: :fit_page, FitH: :fit_page_horizontal, FitV: :fit_page_vertical, FitR: :fit_rectangle, FitB: :fit_bounding_box, FitBH: :fit_bounding_box_horizontal, FitBV: :fit_bounding_box_vertical, }
- REVERSE_TYPE_MAPPING =
:nodoc:
Hash[*TYPE_MAPPING.flatten.reverse]
Class Method Summary collapse
-
.valid?(destination) ⇒ Boolean
Returns
true
if the destination is valid.
Instance Method Summary collapse
-
#bottom ⇒ Object
Returns the argument
bottom
if used by the destination, raises an error otherwise. -
#initialize(destination) ⇒ Destination
constructor
Creates a new Destination for the given
destination
specification which may be an explicit destination array or a dictionary with a /D entry (as allowed for a named destination). -
#left ⇒ Object
Returns the argument
left
if used by the destination, raises an error otherwise. -
#page ⇒ Object
Returns the referenced page.
-
#remote? ⇒ Boolean
Returns
true
if the destination references a destination in a remote document. -
#right ⇒ Object
Returns the argument
right
if used by the destination, raises an error otherwise. -
#top ⇒ Object
Returns the argument
top
if used by the destination, raises an error otherwise. -
#type ⇒ Object
Returns the type of destination.
-
#valid? ⇒ Boolean
Returns
true
if the destination is valid. -
#value ⇒ Object
Returns the wrapped destination array.
-
#zoom ⇒ Object
Returns the argument
zoom
if used by the destination, raises an error otherwise.
Constructor Details
#initialize(destination) ⇒ Destination
Creates a new Destination for the given destination
specification which may be an explicit destination array or a dictionary with a /D entry (as allowed for a named destination).
133 134 135 136 137 138 139 |
# File 'lib/hexapdf/document/destinations.rb', line 133 def initialize(destination) @destination = if destination.kind_of?(HexaPDF::Dictionary) || destination.kind_of?(Hash) destination[:D] else destination end end |
Class Method Details
.valid?(destination) ⇒ Boolean
Returns true
if the destination is valid.
124 125 126 127 128 |
# File 'lib/hexapdf/document/destinations.rb', line 124 def self.valid?(destination) TYPE_MAPPING.key?(destination[1]) && (destination[0].kind_of?(Integer) || destination[0]&.type == :Page) && destination[2..-1].all? {|item| item.nil? || item.kind_of?(Numeric) } end |
Instance Method Details
#bottom ⇒ Object
Returns the argument bottom
if used by the destination, raises an error otherwise.
194 195 196 197 198 199 200 201 |
# File 'lib/hexapdf/document/destinations.rb', line 194 def bottom case type when :fit_rectangle @destination[3] else raise HexaPDF::Error, "No such argument for destination type #{type}" end end |
#left ⇒ Object
Returns the argument left
if used by the destination, raises an error otherwise.
160 161 162 163 164 165 166 167 |
# File 'lib/hexapdf/document/destinations.rb', line 160 def left case type when :xyz, :fit_page_vertical, :fit_rectangle, :fit_bounding_box_vertical @destination[2] else raise HexaPDF::Error, "No such argument for destination type #{type}" end end |
#page ⇒ Object
Returns the referenced page.
The return value is either a page object or, in case of a destination to a remote document, a page number.
150 151 152 |
# File 'lib/hexapdf/document/destinations.rb', line 150 def page @destination[0] end |
#remote? ⇒ Boolean
Returns true
if the destination references a destination in a remote document.
142 143 144 |
# File 'lib/hexapdf/document/destinations.rb', line 142 def remote? @destination[0].kind_of?(Numeric) end |
#right ⇒ Object
Returns the argument right
if used by the destination, raises an error otherwise.
184 185 186 187 188 189 190 191 |
# File 'lib/hexapdf/document/destinations.rb', line 184 def right case type when :fit_rectangle @destination[4] else raise HexaPDF::Error, "No such argument for destination type #{type}" end end |
#top ⇒ Object
Returns the argument top
if used by the destination, raises an error otherwise.
170 171 172 173 174 175 176 177 178 179 180 181 |
# File 'lib/hexapdf/document/destinations.rb', line 170 def top case type when :xyz @destination[3] when :fit_page_horizontal, :fit_bounding_box_horizontal @destination[2] when :fit_rectangle @destination[5] else raise HexaPDF::Error, "No such argument for destination type #{type}" end end |
#type ⇒ Object
Returns the type of destination.
155 156 157 |
# File 'lib/hexapdf/document/destinations.rb', line 155 def type TYPE_MAPPING[@destination[1]] end |
#valid? ⇒ Boolean
Returns true
if the destination is valid.
214 215 216 |
# File 'lib/hexapdf/document/destinations.rb', line 214 def valid? self.class.valid?(@destination) end |
#value ⇒ Object
Returns the wrapped destination array.
219 220 221 |
# File 'lib/hexapdf/document/destinations.rb', line 219 def value @destination end |
#zoom ⇒ Object
Returns the argument zoom
if used by the destination, raises an error otherwise.
204 205 206 207 208 209 210 211 |
# File 'lib/hexapdf/document/destinations.rb', line 204 def zoom case type when :xyz @destination[4] else raise HexaPDF::Error, "No such argument for destination type #{type}" end end |