hexapdf 0.21.1 → 0.24.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +137 -0
- data/LICENSE +1 -1
- data/Rakefile +1 -1
- data/examples/016-frame_automatic_box_placement.rb +7 -2
- data/examples/017-frame_text_flow.rb +10 -18
- data/examples/020-column_box.rb +20 -37
- data/examples/021-list_box.rb +26 -0
- data/lib/hexapdf/cli/batch.rb +1 -1
- data/lib/hexapdf/cli/command.rb +1 -1
- data/lib/hexapdf/cli/files.rb +1 -1
- data/lib/hexapdf/cli/fonts.rb +1 -1
- data/lib/hexapdf/cli/form.rb +31 -4
- data/lib/hexapdf/cli/image2pdf.rb +1 -1
- data/lib/hexapdf/cli/images.rb +1 -1
- data/lib/hexapdf/cli/info.rb +2 -2
- data/lib/hexapdf/cli/inspect.rb +19 -6
- data/lib/hexapdf/cli/merge.rb +1 -1
- data/lib/hexapdf/cli/modify.rb +24 -4
- data/lib/hexapdf/cli/optimize.rb +1 -1
- data/lib/hexapdf/cli/split.rb +1 -1
- data/lib/hexapdf/cli/watermark.rb +1 -1
- data/lib/hexapdf/cli.rb +1 -1
- data/lib/hexapdf/composer.rb +66 -125
- data/lib/hexapdf/configuration.rb +17 -1
- data/lib/hexapdf/content/canvas.rb +1 -1
- data/lib/hexapdf/content/color_space.rb +1 -1
- data/lib/hexapdf/content/graphic_object/arc.rb +1 -1
- data/lib/hexapdf/content/graphic_object/endpoint_arc.rb +1 -1
- data/lib/hexapdf/content/graphic_object/geom2d.rb +2 -1
- data/lib/hexapdf/content/graphic_object/solid_arc.rb +1 -1
- data/lib/hexapdf/content/graphic_object.rb +1 -1
- data/lib/hexapdf/content/graphics_state.rb +1 -1
- data/lib/hexapdf/content/operator.rb +1 -1
- data/lib/hexapdf/content/parser.rb +1 -1
- data/lib/hexapdf/content/processor.rb +1 -1
- data/lib/hexapdf/content/transformation_matrix.rb +1 -1
- data/lib/hexapdf/content.rb +1 -1
- data/lib/hexapdf/data_dir.rb +1 -1
- data/lib/hexapdf/dictionary.rb +1 -1
- data/lib/hexapdf/dictionary_fields.rb +2 -2
- data/lib/hexapdf/document/destinations.rb +396 -0
- data/lib/hexapdf/document/files.rb +1 -1
- data/lib/hexapdf/document/fonts.rb +1 -1
- data/lib/hexapdf/document/images.rb +1 -1
- data/lib/hexapdf/document/layout.rb +397 -0
- data/lib/hexapdf/document/pages.rb +17 -1
- data/lib/hexapdf/document/signatures.rb +5 -4
- data/lib/hexapdf/document.rb +46 -90
- data/lib/hexapdf/encryption/aes.rb +1 -1
- data/lib/hexapdf/encryption/arc4.rb +1 -1
- data/lib/hexapdf/encryption/fast_aes.rb +1 -1
- data/lib/hexapdf/encryption/fast_arc4.rb +30 -21
- data/lib/hexapdf/encryption/identity.rb +1 -1
- data/lib/hexapdf/encryption/ruby_aes.rb +1 -1
- data/lib/hexapdf/encryption/ruby_arc4.rb +1 -1
- data/lib/hexapdf/encryption/security_handler.rb +1 -1
- data/lib/hexapdf/encryption/standard_security_handler.rb +1 -1
- data/lib/hexapdf/encryption.rb +1 -1
- data/lib/hexapdf/error.rb +1 -1
- data/lib/hexapdf/filter/ascii85_decode.rb +1 -1
- data/lib/hexapdf/filter/ascii_hex_decode.rb +1 -1
- data/lib/hexapdf/filter/crypt.rb +1 -1
- data/lib/hexapdf/filter/encryption.rb +1 -1
- data/lib/hexapdf/filter/flate_decode.rb +1 -1
- data/lib/hexapdf/filter/lzw_decode.rb +1 -1
- data/lib/hexapdf/filter/pass_through.rb +1 -1
- data/lib/hexapdf/filter/predictor.rb +1 -1
- data/lib/hexapdf/filter/run_length_decode.rb +1 -1
- data/lib/hexapdf/filter.rb +1 -1
- data/lib/hexapdf/font/cmap/parser.rb +1 -1
- data/lib/hexapdf/font/cmap/writer.rb +1 -1
- data/lib/hexapdf/font/cmap.rb +1 -1
- data/lib/hexapdf/font/encoding/base.rb +1 -1
- data/lib/hexapdf/font/encoding/difference_encoding.rb +1 -1
- data/lib/hexapdf/font/encoding/glyph_list.rb +2 -2
- data/lib/hexapdf/font/encoding/mac_expert_encoding.rb +1 -1
- data/lib/hexapdf/font/encoding/mac_roman_encoding.rb +1 -1
- data/lib/hexapdf/font/encoding/standard_encoding.rb +1 -1
- data/lib/hexapdf/font/encoding/symbol_encoding.rb +1 -1
- data/lib/hexapdf/font/encoding/win_ansi_encoding.rb +1 -1
- data/lib/hexapdf/font/encoding/zapf_dingbats_encoding.rb +1 -1
- data/lib/hexapdf/font/encoding.rb +1 -1
- data/lib/hexapdf/font/invalid_glyph.rb +1 -1
- data/lib/hexapdf/font/true_type/builder.rb +1 -1
- data/lib/hexapdf/font/true_type/font.rb +1 -1
- data/lib/hexapdf/font/true_type/optimizer.rb +1 -1
- data/lib/hexapdf/font/true_type/subsetter.rb +1 -1
- data/lib/hexapdf/font/true_type/table/cmap.rb +1 -1
- data/lib/hexapdf/font/true_type/table/cmap_subtable.rb +1 -1
- data/lib/hexapdf/font/true_type/table/directory.rb +1 -1
- data/lib/hexapdf/font/true_type/table/glyf.rb +1 -1
- data/lib/hexapdf/font/true_type/table/head.rb +1 -1
- data/lib/hexapdf/font/true_type/table/hhea.rb +1 -1
- data/lib/hexapdf/font/true_type/table/hmtx.rb +1 -1
- data/lib/hexapdf/font/true_type/table/kern.rb +1 -1
- data/lib/hexapdf/font/true_type/table/loca.rb +1 -1
- data/lib/hexapdf/font/true_type/table/maxp.rb +1 -1
- data/lib/hexapdf/font/true_type/table/name.rb +1 -1
- data/lib/hexapdf/font/true_type/table/os2.rb +1 -1
- data/lib/hexapdf/font/true_type/table/post.rb +1 -1
- data/lib/hexapdf/font/true_type/table.rb +1 -1
- data/lib/hexapdf/font/true_type.rb +1 -1
- data/lib/hexapdf/font/true_type_wrapper.rb +1 -1
- data/lib/hexapdf/font/type1/afm_parser.rb +1 -1
- data/lib/hexapdf/font/type1/character_metrics.rb +1 -1
- data/lib/hexapdf/font/type1/font.rb +1 -1
- data/lib/hexapdf/font/type1/font_metrics.rb +1 -1
- data/lib/hexapdf/font/type1/pfb_parser.rb +1 -1
- data/lib/hexapdf/font/type1.rb +1 -1
- data/lib/hexapdf/font/type1_wrapper.rb +1 -1
- data/lib/hexapdf/font_loader/from_configuration.rb +1 -1
- data/lib/hexapdf/font_loader/from_file.rb +1 -1
- data/lib/hexapdf/font_loader/standard14.rb +1 -1
- data/lib/hexapdf/font_loader.rb +1 -1
- data/lib/hexapdf/image_loader/jpeg.rb +1 -1
- data/lib/hexapdf/image_loader/pdf.rb +1 -1
- data/lib/hexapdf/image_loader/png.rb +1 -1
- data/lib/hexapdf/image_loader.rb +1 -1
- data/lib/hexapdf/importer.rb +1 -1
- data/lib/hexapdf/layout/box.rb +121 -22
- data/lib/hexapdf/layout/box_fitter.rb +136 -0
- data/lib/hexapdf/layout/column_box.rb +168 -89
- data/lib/hexapdf/layout/frame.rb +155 -140
- data/lib/hexapdf/layout/image_box.rb +19 -4
- data/lib/hexapdf/layout/inline_box.rb +1 -1
- data/lib/hexapdf/layout/line.rb +1 -1
- data/lib/hexapdf/layout/list_box.rb +355 -0
- data/lib/hexapdf/layout/numeric_refinements.rb +1 -1
- data/lib/hexapdf/layout/style.rb +285 -8
- data/lib/hexapdf/layout/text_box.rb +30 -11
- data/lib/hexapdf/layout/text_fragment.rb +3 -2
- data/lib/hexapdf/layout/text_layouter.rb +23 -3
- data/lib/hexapdf/layout/text_shaper.rb +1 -1
- data/lib/hexapdf/layout/width_from_polygon.rb +12 -7
- data/lib/hexapdf/layout.rb +4 -1
- data/lib/hexapdf/name_tree_node.rb +1 -1
- data/lib/hexapdf/number_tree_node.rb +1 -1
- data/lib/hexapdf/object.rb +1 -1
- data/lib/hexapdf/parser.rb +1 -8
- data/lib/hexapdf/pdf_array.rb +1 -1
- data/lib/hexapdf/rectangle.rb +1 -1
- data/lib/hexapdf/reference.rb +1 -1
- data/lib/hexapdf/revision.rb +9 -2
- data/lib/hexapdf/revisions.rb +152 -51
- data/lib/hexapdf/serializer.rb +1 -1
- data/lib/hexapdf/stream.rb +1 -1
- data/lib/hexapdf/task/dereference.rb +1 -1
- data/lib/hexapdf/task/optimize.rb +22 -12
- data/lib/hexapdf/task.rb +1 -1
- data/lib/hexapdf/tokenizer.rb +1 -1
- data/lib/hexapdf/type/acro_form/appearance_generator.rb +1 -1
- data/lib/hexapdf/type/acro_form/button_field.rb +1 -1
- data/lib/hexapdf/type/acro_form/choice_field.rb +1 -1
- data/lib/hexapdf/type/acro_form/field.rb +1 -1
- data/lib/hexapdf/type/acro_form/form.rb +12 -6
- data/lib/hexapdf/type/acro_form/signature_field.rb +1 -1
- data/lib/hexapdf/type/acro_form/text_field.rb +9 -1
- data/lib/hexapdf/type/acro_form/variable_text_field.rb +1 -1
- data/lib/hexapdf/type/acro_form.rb +1 -1
- data/lib/hexapdf/type/action.rb +1 -1
- data/lib/hexapdf/type/actions/go_to.rb +1 -1
- data/lib/hexapdf/type/actions/go_to_r.rb +1 -1
- data/lib/hexapdf/type/actions/launch.rb +1 -1
- data/lib/hexapdf/type/actions/uri.rb +1 -1
- data/lib/hexapdf/type/actions.rb +1 -1
- data/lib/hexapdf/type/annotation.rb +1 -1
- data/lib/hexapdf/type/annotations/link.rb +1 -1
- data/lib/hexapdf/type/annotations/markup_annotation.rb +1 -1
- data/lib/hexapdf/type/annotations/text.rb +1 -1
- data/lib/hexapdf/type/annotations/widget.rb +1 -1
- data/lib/hexapdf/type/annotations.rb +1 -1
- data/lib/hexapdf/type/catalog.rb +10 -2
- data/lib/hexapdf/type/cid_font.rb +1 -1
- data/lib/hexapdf/type/embedded_file.rb +1 -1
- data/lib/hexapdf/type/file_specification.rb +1 -1
- data/lib/hexapdf/type/font.rb +1 -1
- data/lib/hexapdf/type/font_descriptor.rb +1 -1
- data/lib/hexapdf/type/font_simple.rb +1 -1
- data/lib/hexapdf/type/font_true_type.rb +1 -1
- data/lib/hexapdf/type/font_type0.rb +1 -1
- data/lib/hexapdf/type/font_type1.rb +1 -1
- data/lib/hexapdf/type/font_type3.rb +1 -1
- data/lib/hexapdf/type/form.rb +1 -1
- data/lib/hexapdf/type/graphics_state_parameter.rb +1 -1
- data/lib/hexapdf/type/icon_fit.rb +1 -1
- data/lib/hexapdf/type/image.rb +48 -4
- data/lib/hexapdf/type/info.rb +1 -1
- data/lib/hexapdf/type/names.rb +14 -1
- data/lib/hexapdf/type/object_stream.rb +1 -1
- data/lib/hexapdf/type/page.rb +1 -1
- data/lib/hexapdf/type/page_tree_node.rb +19 -2
- data/lib/hexapdf/type/resources.rb +1 -1
- data/lib/hexapdf/type/signature/adbe_pkcs7_detached.rb +1 -1
- data/lib/hexapdf/type/signature/adbe_x509_rsa_sha1.rb +1 -1
- data/lib/hexapdf/type/signature/handler.rb +1 -1
- data/lib/hexapdf/type/signature/verification_result.rb +1 -1
- data/lib/hexapdf/type/signature.rb +1 -1
- data/lib/hexapdf/type/trailer.rb +2 -2
- data/lib/hexapdf/type/viewer_preferences.rb +1 -1
- data/lib/hexapdf/type/xref_stream.rb +3 -2
- data/lib/hexapdf/type.rb +1 -1
- data/lib/hexapdf/utils/bit_field.rb +1 -1
- data/lib/hexapdf/utils/bit_stream.rb +1 -1
- data/lib/hexapdf/utils/graphics_helpers.rb +1 -1
- data/lib/hexapdf/utils/lru_cache.rb +1 -1
- data/lib/hexapdf/utils/math_helpers.rb +1 -1
- data/lib/hexapdf/utils/object_hash.rb +1 -1
- data/lib/hexapdf/utils/pdf_doc_encoding.rb +1 -1
- data/lib/hexapdf/utils/sorted_tree_node.rb +4 -2
- data/lib/hexapdf/version.rb +2 -2
- data/lib/hexapdf/writer.rb +23 -8
- data/lib/hexapdf/xref_section.rb +1 -1
- data/lib/hexapdf.rb +1 -1
- data/test/hexapdf/content/graphic_object/test_geom2d.rb +1 -1
- data/test/hexapdf/document/test_destinations.rb +338 -0
- data/test/hexapdf/document/test_images.rb +1 -1
- data/test/hexapdf/document/test_layout.rb +264 -0
- data/test/hexapdf/document/test_pages.rb +9 -0
- data/test/hexapdf/document/test_signatures.rb +10 -3
- data/test/hexapdf/encryption/test_security_handler.rb +3 -3
- data/test/hexapdf/font/encoding/test_glyph_list.rb +4 -0
- data/test/hexapdf/layout/test_box.rb +53 -3
- data/test/hexapdf/layout/test_box_fitter.rb +62 -0
- data/test/hexapdf/layout/test_column_box.rb +159 -0
- data/test/hexapdf/layout/test_frame.rb +114 -39
- data/test/hexapdf/layout/test_image_box.rb +1 -1
- data/test/hexapdf/layout/test_list_box.rb +249 -0
- data/test/hexapdf/layout/test_text_box.rb +33 -2
- data/test/hexapdf/layout/test_text_fragment.rb +1 -1
- data/test/hexapdf/layout/test_text_layouter.rb +49 -17
- data/test/hexapdf/layout/test_width_from_polygon.rb +13 -0
- data/test/hexapdf/task/test_optimize.rb +17 -4
- data/test/hexapdf/test_composer.rb +35 -1
- data/test/hexapdf/test_dictionary_fields.rb +10 -10
- data/test/hexapdf/test_document.rb +33 -136
- data/test/hexapdf/test_filter.rb +1 -1
- data/test/hexapdf/test_parser.rb +1 -3
- data/test/hexapdf/test_revision.rb +14 -0
- data/test/hexapdf/test_revisions.rb +137 -29
- data/test/hexapdf/test_serializer.rb +1 -5
- data/test/hexapdf/test_writer.rb +99 -15
- data/test/hexapdf/type/acro_form/test_form.rb +2 -1
- data/test/hexapdf/type/acro_form/test_text_field.rb +17 -0
- data/test/hexapdf/type/test_catalog.rb +8 -0
- data/test/hexapdf/type/test_image.rb +45 -9
- data/test/hexapdf/type/test_names.rb +20 -0
- data/test/hexapdf/type/test_page_tree_node.rb +21 -1
- data/test/hexapdf/type/test_trailer.rb +3 -3
- data/test/hexapdf/type/test_xref_stream.rb +2 -1
- data/test/hexapdf/utils/test_sorted_tree_node.rb +11 -1
- data/test/test_helper.rb +5 -1
- metadata +29 -3
@@ -0,0 +1,396 @@
|
|
1
|
+
# -*- encoding: utf-8; frozen_string_literal: true -*-
|
2
|
+
#
|
3
|
+
#--
|
4
|
+
# This file is part of HexaPDF.
|
5
|
+
#
|
6
|
+
# HexaPDF - A Versatile PDF Creation and Manipulation Library For Ruby
|
7
|
+
# Copyright (C) 2014-2022 Thomas Leitner
|
8
|
+
#
|
9
|
+
# HexaPDF is free software: you can redistribute it and/or modify it
|
10
|
+
# under the terms of the GNU Affero General Public License version 3 as
|
11
|
+
# published by the Free Software Foundation with the addition of the
|
12
|
+
# following permission added to Section 15 as permitted in Section 7(a):
|
13
|
+
# FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY
|
14
|
+
# THOMAS LEITNER, THOMAS LEITNER DISCLAIMS THE WARRANTY OF NON
|
15
|
+
# INFRINGEMENT OF THIRD PARTY RIGHTS.
|
16
|
+
#
|
17
|
+
# HexaPDF is distributed in the hope that it will be useful, but WITHOUT
|
18
|
+
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
19
|
+
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
|
20
|
+
# License for more details.
|
21
|
+
#
|
22
|
+
# You should have received a copy of the GNU Affero General Public License
|
23
|
+
# along with HexaPDF. If not, see <http://www.gnu.org/licenses/>.
|
24
|
+
#
|
25
|
+
# The interactive user interfaces in modified source and object code
|
26
|
+
# versions of HexaPDF must display Appropriate Legal Notices, as required
|
27
|
+
# under Section 5 of the GNU Affero General Public License version 3.
|
28
|
+
#
|
29
|
+
# In accordance with Section 7(b) of the GNU Affero General Public
|
30
|
+
# License, a covered work must retain the producer line in every PDF that
|
31
|
+
# is created or manipulated using HexaPDF.
|
32
|
+
#
|
33
|
+
# If the GNU Affero General Public License doesn't fit your need,
|
34
|
+
# commercial licenses are available at <https://gettalong.at/hexapdf/>.
|
35
|
+
#++
|
36
|
+
|
37
|
+
require 'hexapdf/dictionary'
|
38
|
+
require 'hexapdf/error'
|
39
|
+
|
40
|
+
module HexaPDF
|
41
|
+
class Document
|
42
|
+
|
43
|
+
# This class provides methods for creating and managing the destinations of a PDF file.
|
44
|
+
#
|
45
|
+
# A destination describes a particular view of a PDF document, consisting of the page, the view
|
46
|
+
# location and a magnification factor. See Destination for details.
|
47
|
+
#
|
48
|
+
# Such destinations may be directly specified where needed, e.g. for link annotations, or they
|
49
|
+
# may be named and later referenced through the name. This class allows to create destinations
|
50
|
+
# with or without a name.
|
51
|
+
#
|
52
|
+
# See: PDF1.7 s12.3.2
|
53
|
+
class Destinations
|
54
|
+
|
55
|
+
# Wraps an explicit destination array to allow easy access to query its properties.
|
56
|
+
#
|
57
|
+
# A *destination array* has the form
|
58
|
+
#
|
59
|
+
# [page, type, *arguments]
|
60
|
+
#
|
61
|
+
# where +page+ is either a page object or a page number (in case of a destination to a page in
|
62
|
+
# a remote PDF document), +type+ is the destination type (see below) and +arguments+ are the
|
63
|
+
# required arguments for the specific type of destination.
|
64
|
+
#
|
65
|
+
# == Destination Types
|
66
|
+
#
|
67
|
+
# There are eight different types of destinations, each taking different arguments. The
|
68
|
+
# arguments are marked up in the list below and are in the correct order for use in the
|
69
|
+
# destination array. The first name in the list is the PDF internal name, the second one the
|
70
|
+
# explicit, more descriptive one used by HexaPDF:
|
71
|
+
#
|
72
|
+
# :XYZ, :xyz::
|
73
|
+
# Display the page with the given (+left+, +top+) coordinate at the upper-left corner of
|
74
|
+
# the window and the specified magnification (+zoom+) factor. A +nil+ value for any
|
75
|
+
# argument means not changing it from the current value.
|
76
|
+
#
|
77
|
+
# :Fit, :fit_page::
|
78
|
+
# Display the page so that it fits horizontally and vertically within the window.
|
79
|
+
#
|
80
|
+
# :FitH, :fit_page_horizontal::
|
81
|
+
# Display the page so that it fits horizontally within the window, with the given +top+
|
82
|
+
# coordinate being at the top of the window. A +nil+ value for +top+ means not changing it
|
83
|
+
# from the current value.
|
84
|
+
#
|
85
|
+
# :FitV, :fit_page_vertical::
|
86
|
+
# Display the page so that it fits vertically within the window, with the given +left+
|
87
|
+
# coordinate being at the left of the window. A +nil+ value for +left+ means not changing
|
88
|
+
# it from the current value.
|
89
|
+
#
|
90
|
+
# :FitR, :fit_rectangle::
|
91
|
+
# Display the page so that the rectangle specified by (+left+, +bottom+)-(+right+, +top+)
|
92
|
+
# fits horizontally and vertically within the window.
|
93
|
+
#
|
94
|
+
# :FitB, :fit_bounding_box::
|
95
|
+
# Display the page so that its bounding box fits horizontally and vertically within the
|
96
|
+
# window.
|
97
|
+
#
|
98
|
+
# :FitBH, :fit_bounding_box_horizontal::
|
99
|
+
# Display the page so that its bounding box fits horizontally within the window, with the
|
100
|
+
# given +top+ coordinate being at the top of the window. A +nil+ value for +top+ means not
|
101
|
+
# changing it from the current value.
|
102
|
+
#
|
103
|
+
# :FitBV, :fit_bounding_box_vertical::
|
104
|
+
# Display the page so that its bounding box fits vertically within the window, with the
|
105
|
+
# given +left+ coordinate being at the left of the window. A +nil+ value for +left+ means
|
106
|
+
# not changing it from the current value.
|
107
|
+
class Destination
|
108
|
+
|
109
|
+
# :nodoc:
|
110
|
+
TYPE_MAPPING = {
|
111
|
+
XYZ: :xyz,
|
112
|
+
Fit: :fit_page,
|
113
|
+
FitH: :fit_page_horizontal,
|
114
|
+
FitV: :fit_page_vertical,
|
115
|
+
FitR: :fit_rectangle,
|
116
|
+
FitB: :fit_bounding_box,
|
117
|
+
FitBH: :fit_bounding_box_horizontal,
|
118
|
+
FitBV: :fit_bounding_box_vertical,
|
119
|
+
}
|
120
|
+
|
121
|
+
# :nodoc:
|
122
|
+
REVERSE_TYPE_MAPPING = Hash[*TYPE_MAPPING.flatten.reverse]
|
123
|
+
|
124
|
+
# Creates a new Destination for the given +destination+ which may be an explicit destination
|
125
|
+
# array or a dictionary with a /D entry (as allowed for a named destination).
|
126
|
+
def initialize(destination)
|
127
|
+
@destination = (destination.kind_of?(HexaPDF::Dictionary) ? destination[:D] : destination)
|
128
|
+
end
|
129
|
+
|
130
|
+
# Returns +true+ if the destination references a destination in a remote document.
|
131
|
+
def remote?
|
132
|
+
@destination[0].kind_of?(Numeric)
|
133
|
+
end
|
134
|
+
|
135
|
+
# Returns the referenced page.
|
136
|
+
#
|
137
|
+
# The return value is either a page object or, in case of a destination to a remote
|
138
|
+
# document, a page number.
|
139
|
+
def page
|
140
|
+
@destination[0]
|
141
|
+
end
|
142
|
+
|
143
|
+
# Returns the type of destination.
|
144
|
+
def type
|
145
|
+
TYPE_MAPPING[@destination[1]]
|
146
|
+
end
|
147
|
+
|
148
|
+
# Returns the argument +left+ if used by the destination, raises an error otherwise.
|
149
|
+
def left
|
150
|
+
case type
|
151
|
+
when :xyz, :fit_page_vertical, :fit_rectangle, :fit_bounding_box_vertical
|
152
|
+
@destination[2]
|
153
|
+
else
|
154
|
+
raise HexaPDF::Error, "No such argument for destination type #{type}"
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
# Returns the argument +top+ if used by the destination, raises an error otherwise.
|
159
|
+
def top
|
160
|
+
case type
|
161
|
+
when :xyz
|
162
|
+
@destination[3]
|
163
|
+
when :fit_page_horizontal, :fit_bounding_box_horizontal
|
164
|
+
@destination[2]
|
165
|
+
when :fit_rectangle
|
166
|
+
@destination[5]
|
167
|
+
else
|
168
|
+
raise HexaPDF::Error, "No such argument for destination type #{type}"
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
# Returns the argument +right+ if used by the destination, raises an error otherwise.
|
173
|
+
def right
|
174
|
+
case type
|
175
|
+
when :fit_rectangle
|
176
|
+
@destination[4]
|
177
|
+
else
|
178
|
+
raise HexaPDF::Error, "No such argument for destination type #{type}"
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
# Returns the argument +bottom+ if used by the destination, raises an error otherwise.
|
183
|
+
def bottom
|
184
|
+
case type
|
185
|
+
when :fit_rectangle
|
186
|
+
@destination[3]
|
187
|
+
else
|
188
|
+
raise HexaPDF::Error, "No such argument for destination type #{type}"
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
# Returns the argument +zoom+ if used by the destination, raises an error otherwise.
|
193
|
+
def zoom
|
194
|
+
case type
|
195
|
+
when :xyz
|
196
|
+
@destination[4]
|
197
|
+
else
|
198
|
+
raise HexaPDF::Error, "No such argument for destination type #{type}"
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
202
|
+
end
|
203
|
+
|
204
|
+
include Enumerable
|
205
|
+
|
206
|
+
# Creates a new Destinations object for the given PDF document.
|
207
|
+
def initialize(document)
|
208
|
+
@document = document
|
209
|
+
end
|
210
|
+
|
211
|
+
# :call-seq:
|
212
|
+
# destinations.create_xyz(page, left: nil, top: nil, zoom: nil) -> dest
|
213
|
+
# destinations.create_xyz(page, name: nil, left: nil, top: nil, zoom: nil) -> name
|
214
|
+
#
|
215
|
+
# Creates a new xyz destination array for the given arguments and returns it or, in case
|
216
|
+
# a name is given, the name.
|
217
|
+
#
|
218
|
+
# The arguments +page+, +left+, +top+ and +zoom+ are described in detail in the Destination
|
219
|
+
# class description.
|
220
|
+
#
|
221
|
+
# If the argument +name+ is given, the created destination array is added to the destinations
|
222
|
+
# name tree under that name for reuse later, overwriting an existing entry if there is one.
|
223
|
+
def create_xyz(page, name: nil, left: nil, top: nil, zoom: nil)
|
224
|
+
destination = [page, Destination::REVERSE_TYPE_MAPPING.fetch(:xyz), left, top, zoom]
|
225
|
+
name ? (add(name, destination); name) : destination
|
226
|
+
end
|
227
|
+
|
228
|
+
# :call-seq:
|
229
|
+
# destinations.create_fit_page(page) -> dest
|
230
|
+
# destinations.create_fit_page(page, name: nil) -> name
|
231
|
+
#
|
232
|
+
# Creates a new fit to page destination array for the given arguments and returns it or, in
|
233
|
+
# case a name is given, the name.
|
234
|
+
#
|
235
|
+
# The argument +page+ is described in detail in the Destination class description.
|
236
|
+
#
|
237
|
+
# If the argument +name+ is given, the created destination array is added to the destinations
|
238
|
+
# name tree under that name for reuse later, overwriting an existing entry if there is one.
|
239
|
+
def create_fit_page(page, name: nil)
|
240
|
+
destination = [page, Destination::REVERSE_TYPE_MAPPING.fetch(:fit_page)]
|
241
|
+
name ? (add(name, destination); name) : destination
|
242
|
+
end
|
243
|
+
|
244
|
+
# :call-seq:
|
245
|
+
# destinations.create_fit_page_horizontal(page, top: nil) -> dest
|
246
|
+
# destinations.create_fit_page_horizontal(page, name: nil, top: nil) -> name
|
247
|
+
#
|
248
|
+
# Creates a new fit page horizontal destination array for the given arguments and returns it
|
249
|
+
# or, in case a name is given, the name.
|
250
|
+
#
|
251
|
+
# The arguments +page and +top+ are described in detail in the Destination class description.
|
252
|
+
#
|
253
|
+
# If the argument +name+ is given, the created destination array is added to the destinations
|
254
|
+
# name tree under that name for reuse later, overwriting an existing entry if there is one.
|
255
|
+
def create_fit_page_horizontal(page, name: nil, top: nil)
|
256
|
+
destination = [page, Destination::REVERSE_TYPE_MAPPING.fetch(:fit_page_horizontal), top]
|
257
|
+
name ? (add(name, destination); name) : destination
|
258
|
+
end
|
259
|
+
|
260
|
+
# :call-seq:
|
261
|
+
# destinations.create_fit_page_vertical(page, left: nil) -> dest
|
262
|
+
# destinations.create_fit_page_vertical(page, name: nil, left: nil) -> name
|
263
|
+
#
|
264
|
+
# Creates a new fit page vertical destination array for the given arguments and returns it or,
|
265
|
+
# in case a name is given, the name.
|
266
|
+
#
|
267
|
+
# The arguments +page and +left+ are described in detail in the Destination class description.
|
268
|
+
#
|
269
|
+
# If the argument +name+ is given, the created destination array is added to the destinations
|
270
|
+
# name tree under that name for reuse later, overwriting an existing entry if there is one.
|
271
|
+
def create_fit_page_vertical(page, name: nil, left: nil)
|
272
|
+
destination = [page, Destination::REVERSE_TYPE_MAPPING.fetch(:fit_page_vertical), left]
|
273
|
+
name ? (add(name, destination); name) : destination
|
274
|
+
end
|
275
|
+
|
276
|
+
# :call-seq:
|
277
|
+
# destinations.create_fit_rectangle(page, left:, bottom:, right:, top:) -> dest
|
278
|
+
# destinations.create_fit_rectangle(page, name: nil, left:, bottom:, right:, top:) -> name
|
279
|
+
#
|
280
|
+
# Creates a new fit to rectangle destination array for the given arguments and returns it or,
|
281
|
+
# in case a name is given, the name.
|
282
|
+
#
|
283
|
+
# The arguments +page+, +left+, +bottom+, +right+ and +top+ are described in detail in the
|
284
|
+
# Destination class description.
|
285
|
+
#
|
286
|
+
# If the argument +name+ is given, the created destination array is added to the destinations
|
287
|
+
# name tree under that name for reuse later, overwriting an existing entry if there is one.
|
288
|
+
def create_fit_rectangle(page, left:, bottom:, right:, top:, name: nil)
|
289
|
+
destination = [page, Destination::REVERSE_TYPE_MAPPING.fetch(:fit_rectangle),
|
290
|
+
left, bottom, right, top]
|
291
|
+
name ? (add(name, destination); name) : destination
|
292
|
+
end
|
293
|
+
|
294
|
+
# :call-seq:
|
295
|
+
# destinations.create_fit_bounding_box(page) -> dest
|
296
|
+
# destinations.create_fit_bounding_box(page, name: nil) -> name
|
297
|
+
#
|
298
|
+
# Creates a new fit to bounding box destination array for the given arguments and returns it
|
299
|
+
# or, in case a name is given, the name.
|
300
|
+
#
|
301
|
+
# The argument +page+ is described in detail in the Destination class description.
|
302
|
+
#
|
303
|
+
# If the argument +name+ is given, the created destination array is added to the destinations
|
304
|
+
# name tree under that name for reuse later, overwriting an existing entry if there is one.
|
305
|
+
def create_fit_bounding_box(page, name: nil)
|
306
|
+
destination = [page, Destination::REVERSE_TYPE_MAPPING.fetch(:fit_bounding_box)]
|
307
|
+
name ? (add(name, destination); name) : destination
|
308
|
+
end
|
309
|
+
|
310
|
+
# :call-seq:
|
311
|
+
# destinations.create_fit_bounding_box_horizontal(page, top: nil) -> dest
|
312
|
+
# destinations.create_fit_bounding_box_horizontal(page, name: nil, top: nil) -> name
|
313
|
+
#
|
314
|
+
# Creates a new fit bounding box horizontal destination array for the given arguments and
|
315
|
+
# returns it or, in case a name is given, the name.
|
316
|
+
#
|
317
|
+
# The arguments +page and +top+ are described in detail in the Destination class description.
|
318
|
+
#
|
319
|
+
# If the argument +name+ is given, the created destination array is added to the destinations
|
320
|
+
# name tree under that name for reuse later, overwriting an existing entry if there is one.
|
321
|
+
def create_fit_bounding_box_horizontal(page, name: nil, top: nil)
|
322
|
+
destination = [page, Destination::REVERSE_TYPE_MAPPING.fetch(:fit_bounding_box_horizontal), top]
|
323
|
+
name ? (add(name, destination); name) : destination
|
324
|
+
end
|
325
|
+
|
326
|
+
# :call-seq:
|
327
|
+
# destinations.create_fit_bounding_box_vertical(page, left: nil) -> dest
|
328
|
+
# destinations.create_fit_bounding_box_vertical(page, name: nil, left: nil) -> name
|
329
|
+
#
|
330
|
+
# Creates a new fit bounding box vertical destination array for the given arguments and
|
331
|
+
# returns it or, in case a name is given, the name.
|
332
|
+
#
|
333
|
+
# The arguments +page and +left+ are described in detail in the Destination class description.
|
334
|
+
#
|
335
|
+
# If the argument +name+ is given, the created destination array is added to the destinations
|
336
|
+
# name tree under that name for reuse later, overwriting an existing entry if there is one.
|
337
|
+
def create_fit_bounding_box_vertical(page, name: nil, left: nil)
|
338
|
+
destination = [page, Destination::REVERSE_TYPE_MAPPING.fetch(:fit_bounding_box_vertical), left]
|
339
|
+
name ? (add(name, destination); name) : destination
|
340
|
+
end
|
341
|
+
|
342
|
+
# :call-seq:
|
343
|
+
# destinations.add(name, destination)
|
344
|
+
#
|
345
|
+
# Adds the given +destination+ under +name+ to the destinations name tree.
|
346
|
+
#
|
347
|
+
# If the name does already exist, an error is raised.
|
348
|
+
def add(name, destination)
|
349
|
+
destinations.add_entry(name, destination)
|
350
|
+
end
|
351
|
+
|
352
|
+
# :call-seq:
|
353
|
+
# destinations.delete(name) -> destination
|
354
|
+
#
|
355
|
+
# Deletes the given destination from the destinations name tree and returns it or +nil+ if no
|
356
|
+
# destination was registered under that name.
|
357
|
+
def delete(name)
|
358
|
+
destinations.delete_entry(name)
|
359
|
+
end
|
360
|
+
|
361
|
+
# :call-seq:
|
362
|
+
# destinations[name] -> destination
|
363
|
+
#
|
364
|
+
# Returns the destination registered under the given +name+ or +nil+ if no destination was
|
365
|
+
# registered under that name.
|
366
|
+
def [](name)
|
367
|
+
destinations.find_entry(name)
|
368
|
+
end
|
369
|
+
|
370
|
+
# :call-seq:
|
371
|
+
# destinations.each {|name, dest| block } -> destinations
|
372
|
+
# destinations.each -> Enumerator
|
373
|
+
#
|
374
|
+
# Iterates over all named destinations of the PDF, yielding the name and the destination
|
375
|
+
# wrapped into a Destination object.
|
376
|
+
def each
|
377
|
+
return to_enum(__method__) unless block_given?
|
378
|
+
|
379
|
+
destinations.each_entry do |name, dest|
|
380
|
+
yield(name, Destination.new(dest))
|
381
|
+
end
|
382
|
+
|
383
|
+
self
|
384
|
+
end
|
385
|
+
|
386
|
+
private
|
387
|
+
|
388
|
+
# Returns the root of the destinations name tree.
|
389
|
+
def destinations
|
390
|
+
@document.catalog.names.destinations
|
391
|
+
end
|
392
|
+
|
393
|
+
end
|
394
|
+
|
395
|
+
end
|
396
|
+
end
|
@@ -4,7 +4,7 @@
|
|
4
4
|
# This file is part of HexaPDF.
|
5
5
|
#
|
6
6
|
# HexaPDF - A Versatile PDF Creation and Manipulation Library For Ruby
|
7
|
-
# Copyright (C) 2014-
|
7
|
+
# Copyright (C) 2014-2022 Thomas Leitner
|
8
8
|
#
|
9
9
|
# HexaPDF is free software: you can redistribute it and/or modify it
|
10
10
|
# under the terms of the GNU Affero General Public License version 3 as
|
@@ -4,7 +4,7 @@
|
|
4
4
|
# This file is part of HexaPDF.
|
5
5
|
#
|
6
6
|
# HexaPDF - A Versatile PDF Creation and Manipulation Library For Ruby
|
7
|
-
# Copyright (C) 2014-
|
7
|
+
# Copyright (C) 2014-2022 Thomas Leitner
|
8
8
|
#
|
9
9
|
# HexaPDF is free software: you can redistribute it and/or modify it
|
10
10
|
# under the terms of the GNU Affero General Public License version 3 as
|
@@ -4,7 +4,7 @@
|
|
4
4
|
# This file is part of HexaPDF.
|
5
5
|
#
|
6
6
|
# HexaPDF - A Versatile PDF Creation and Manipulation Library For Ruby
|
7
|
-
# Copyright (C) 2014-
|
7
|
+
# Copyright (C) 2014-2022 Thomas Leitner
|
8
8
|
#
|
9
9
|
# HexaPDF is free software: you can redistribute it and/or modify it
|
10
10
|
# under the terms of the GNU Affero General Public License version 3 as
|