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. 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]
Class Method Summary collapse
-
.valid?(destination) ⇒ Boolean
Returns
trueif the destination is valid.
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.
-
#valid? ⇒ Boolean
Returns
trueif the destination is valid. -
#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).
134 135 136 |
# File 'lib/hexapdf/document/destinations.rb', line 134 def initialize(destination) @destination = (destination.kind_of?(HexaPDF::Dictionary) ? destination[:D] : destination) end |
Class Method Details
.valid?(destination) ⇒ Boolean
Returns true if the destination is valid.
126 127 128 129 130 |
# File 'lib/hexapdf/document/destinations.rb', line 126 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.
191 192 193 194 195 196 197 198 |
# File 'lib/hexapdf/document/destinations.rb', line 191 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.
157 158 159 160 161 162 163 164 |
# File 'lib/hexapdf/document/destinations.rb', line 157 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.
147 148 149 |
# File 'lib/hexapdf/document/destinations.rb', line 147 def page @destination[0] end |
#remote? ⇒ Boolean
Returns true if the destination references a destination in a remote document.
139 140 141 |
# File 'lib/hexapdf/document/destinations.rb', line 139 def remote? @destination[0].kind_of?(Numeric) end |
#right ⇒ Object
Returns the argument right if used by the destination, raises an error otherwise.
181 182 183 184 185 186 187 188 |
# File 'lib/hexapdf/document/destinations.rb', line 181 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.
167 168 169 170 171 172 173 174 175 176 177 178 |
# File 'lib/hexapdf/document/destinations.rb', line 167 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.
152 153 154 |
# File 'lib/hexapdf/document/destinations.rb', line 152 def type TYPE_MAPPING[@destination[1]] end |
#valid? ⇒ Boolean
Returns true if the destination is valid.
211 212 213 |
# File 'lib/hexapdf/document/destinations.rb', line 211 def valid? self.class.valid?(@destination) end |
#zoom ⇒ Object
Returns the argument zoom if used by the destination, raises an error otherwise.
201 202 203 204 205 206 207 208 |
# File 'lib/hexapdf/document/destinations.rb', line 201 def zoom case type when :xyz @destination[4] else raise HexaPDF::Error, "No such argument for destination type #{type}" end end |