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:
- :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. Anilvalue 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
topcoordinate being at the top of the window. Anilvalue fortopmeans 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
leftcoordinate being at the left of the window. Anilvalue forleftmeans 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
topcoordinate being at the top of the window. Anilvalue fortopmeans 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
leftcoordinate being at the left of the window. Anilvalue forleftmeans not changing it from the current value.
Constant Summary collapse
- TYPE_MAPPING =
: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]
Instance Method Summary collapse
-
#bottom ⇒ Object
Returns the argument
bottomif used by the destination, raises an error otherwise. -
#initialize(destination) ⇒ Destination
constructor
Creates a new Destination for the given
destinationwhich may be an explicit destination array or a dictionary with a /D entry (as allowed for a named destination). -
#left ⇒ Object
Returns the argument
leftif used by the destination, raises an error otherwise. -
#page ⇒ Object
Returns the referenced page.
-
#remote? ⇒ Boolean
Returns
trueif the destination references a destination in a remote document. -
#right ⇒ Object
Returns the argument
rightif used by the destination, raises an error otherwise. -
#top ⇒ Object
Returns the argument
topif used by the destination, raises an error otherwise. -
#type ⇒ Object
Returns the type of destination.
-
#zoom ⇒ Object
Returns the argument
zoomif used by the destination, raises an error otherwise.
Constructor Details
#initialize(destination) ⇒ Destination
Creates a new Destination for the given destination which may be an explicit destination array or a dictionary with a /D entry (as allowed for a named destination).
126 127 128 |
# File 'lib/hexapdf/document/destinations.rb', line 126 def initialize(destination) @destination = (destination.kind_of?(HexaPDF::Dictionary) ? destination[:D] : destination) end |
Instance Method Details
#bottom ⇒ Object
Returns the argument bottom if used by the destination, raises an error otherwise.
183 184 185 186 187 188 189 190 |
# File 'lib/hexapdf/document/destinations.rb', line 183 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.
149 150 151 152 153 154 155 156 |
# File 'lib/hexapdf/document/destinations.rb', line 149 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.
139 140 141 |
# File 'lib/hexapdf/document/destinations.rb', line 139 def page @destination[0] end |
#remote? ⇒ Boolean
Returns true if the destination references a destination in a remote document.
131 132 133 |
# File 'lib/hexapdf/document/destinations.rb', line 131 def remote? @destination[0].kind_of?(Numeric) end |
#right ⇒ Object
Returns the argument right if used by the destination, raises an error otherwise.
173 174 175 176 177 178 179 180 |
# File 'lib/hexapdf/document/destinations.rb', line 173 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.
159 160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/hexapdf/document/destinations.rb', line 159 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.
144 145 146 |
# File 'lib/hexapdf/document/destinations.rb', line 144 def type TYPE_MAPPING[@destination[1]] end |
#zoom ⇒ Object
Returns the argument zoom if used by the destination, raises an error otherwise.
193 194 195 196 197 198 199 200 |
# File 'lib/hexapdf/document/destinations.rb', line 193 def zoom case type when :xyz @destination[4] else raise HexaPDF::Error, "No such argument for destination type #{type}" end end |