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
@@ -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
|
data/lib/hexapdf/cli.rb
CHANGED
@@ -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
|
data/lib/hexapdf/composer.rb
CHANGED
@@ -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
|
@@ -58,24 +58,6 @@ module HexaPDF
|
|
58
58
|
# page. Behind the scenes HexaPDF::Layout::Box (and subclass) objects are created and drawn on the
|
59
59
|
# page via the frame.
|
60
60
|
#
|
61
|
-
# All drawing methods accept HexaPDF::Layout::Style objects or names for style objects (defined
|
62
|
-
# via #style). The HexaPDF::Layout::Style#font is handled specially:
|
63
|
-
#
|
64
|
-
# * If no font is set on a style, the font "Times" is automatically set because otherwise there
|
65
|
-
# would be problems with text drawing operations (font is the only style property that has no
|
66
|
-
# valid default value).
|
67
|
-
#
|
68
|
-
# * Standard style objects only allow font wrapper objects to be set via the
|
69
|
-
# HexaPDF::Layout::Style#font method. Composer makes usage easier by allowing strings or an
|
70
|
-
# array [name, options_hash] to be used, like with e.g Content::Canvas. So using Helvetica as
|
71
|
-
# font, one could just do this by saying
|
72
|
-
#
|
73
|
-
# style.font = 'Helvetica'
|
74
|
-
#
|
75
|
-
# And if Helvetica bold should be used it would be
|
76
|
-
#
|
77
|
-
# style.font = ['Helvetica', variant: :bold]
|
78
|
-
#
|
79
61
|
# If the frame of a page is full and a box doesn't fit anymore, a new page is automatically
|
80
62
|
# created. The box is either split into two boxes where one fits on the first page and the other
|
81
63
|
# on the new page, or it is drawn completely on the new page. A new page can also be created by
|
@@ -146,7 +128,6 @@ module HexaPDF
|
|
146
128
|
@page_size = page_size
|
147
129
|
@page_orientation = page_orientation
|
148
130
|
@margin = Layout::Style::Quad.new(margin)
|
149
|
-
@styles = {base: Layout::Style.new}
|
150
131
|
|
151
132
|
new_page
|
152
133
|
yield(self) if block_given?
|
@@ -189,24 +170,14 @@ module HexaPDF
|
|
189
170
|
end
|
190
171
|
|
191
172
|
# :call-seq:
|
192
|
-
# composer.style(
|
193
|
-
# composer.style(
|
173
|
+
# composer.style(name) -> style
|
174
|
+
# composer.style(name, base: :base, **properties) -> style
|
194
175
|
#
|
195
176
|
# Creates or updates the HexaPDF::Layout::Style object called +name+ with the given property
|
196
|
-
# values and returns it.
|
197
|
-
# methods, e.g. #text or #image.
|
177
|
+
# values and returns it.
|
198
178
|
#
|
199
|
-
#
|
200
|
-
#
|
201
|
-
# If the style +name+ does not exist yet and the argument +base+ specifies the name of another
|
202
|
-
# style, that style is duplicated and used as basis for the style.
|
203
|
-
#
|
204
|
-
# The special name :base should be used for setting the base style which is used when no
|
205
|
-
# specific style is set. It is best to fully initialize the base style before creating any
|
206
|
-
# other styles.
|
207
|
-
#
|
208
|
-
# Note that the style property 'font' is handled specially by Composer, see the class
|
209
|
-
# documentation for details.
|
179
|
+
# See HexaPDF::Document::Layout#style for details; this method is just a thin wrapper around
|
180
|
+
# that method.
|
210
181
|
#
|
211
182
|
# Example:
|
212
183
|
#
|
@@ -216,35 +187,20 @@ module HexaPDF
|
|
216
187
|
#
|
217
188
|
# See: HexaPDF::Layout::Style
|
218
189
|
def style(name, base: :base, **properties)
|
219
|
-
style
|
220
|
-
style.update(**properties) unless properties.empty?
|
221
|
-
style
|
190
|
+
@document.layout.style(name, base: base, **properties)
|
222
191
|
end
|
223
192
|
|
224
193
|
# Draws the given text at the current position into the current frame.
|
225
194
|
#
|
226
|
-
# This method is the main method for displaying text on a PDF page. It uses a
|
227
|
-
# HexaPDF::Layout::TextBox behind the scenes to do the actual work.
|
228
|
-
#
|
229
195
|
# The text will be positioned at the current position if possible. Otherwise the next best
|
230
196
|
# position is used. If the text doesn't fit onto the current page or only partially, new pages
|
231
197
|
# are created automatically.
|
232
198
|
#
|
233
|
-
#
|
234
|
-
#
|
235
|
-
#
|
236
|
-
#
|
237
|
-
# +style+, +style_properties+::
|
238
|
-
# The box and the text are styled using the given +style+. This can either be a style name
|
239
|
-
# set via #style or anything HexaPDF::Layout::Style::create accepts. If any additional
|
240
|
-
# +style_properties+ are specified, the style is duplicated and the additional styles are
|
241
|
-
# applied.
|
199
|
+
# This method is of the two main methods for creating text boxes, the other being
|
200
|
+
# #formatted_text. It uses HexaPDF::Document::Layout#text_box behind the scenes to create the
|
201
|
+
# HexaPDF::Layout::TextBox that does the actual work.
|
242
202
|
#
|
243
|
-
#
|
244
|
-
# Sometimes it is necessary for the box to have a different style than the text, e.g. when
|
245
|
-
# using overlays. In such a case use +box_style+ for specifiying the style of the box (a
|
246
|
-
# style name set via #style or anything HexaPDF::Layout::Style::create accepts). The +style+
|
247
|
-
# together with the +style_properties+ will be used for the text style.
|
203
|
+
# See HexaPDF::Document::Layout#text_box for details on the arguments.
|
248
204
|
#
|
249
205
|
# Examples:
|
250
206
|
#
|
@@ -255,35 +211,16 @@ module HexaPDF
|
|
255
211
|
# composer.text("Different box style", fill_color: 'white', box_style: {
|
256
212
|
# underlays: [->(c, b) { c.rectangle(0, 0, b.content_width, b.content_height).fill }]
|
257
213
|
# })
|
258
|
-
#
|
259
|
-
# See HexaPDF::HexaPDF::Layout::TextBox for details.
|
260
214
|
def text(str, width: 0, height: 0, style: nil, box_style: nil, **style_properties)
|
261
|
-
|
262
|
-
|
263
|
-
draw_box(Layout::TextBox.new([Layout::TextFragment.create(str, style)],
|
264
|
-
width: width, height: height, style: box_style))
|
215
|
+
draw_box(@document.layout.text_box(str, width: width, height: height, style: style,
|
216
|
+
box_style: box_style, **style_properties))
|
265
217
|
end
|
266
218
|
|
267
219
|
# Draws text like #text but allows parts of the text to be formatted differently.
|
268
220
|
#
|
269
|
-
#
|
270
|
-
#
|
271
|
-
#
|
272
|
-
#
|
273
|
-
# * Hashes can contain any style properties and the following special keys:
|
274
|
-
#
|
275
|
-
# text:: The text to be formatted.
|
276
|
-
#
|
277
|
-
# link:: A URL that should be linked to. If no text is provided but a link, the link is used
|
278
|
-
# as text.
|
279
|
-
#
|
280
|
-
# style:: The style to be use as basis instead of the style created from the +style+ and
|
281
|
-
# +style_properties+ arguments. See HexaPDF::Layout::Style::create for allowed values.
|
282
|
-
#
|
283
|
-
# If any style properties are set, the used style is copied and the additional properties
|
284
|
-
# applied.
|
285
|
-
#
|
286
|
-
# See #text for details on +width+, +height+, +style+, +style_properties+ and +box_style+.
|
221
|
+
# It uses HexaPDF::Document::Layout#formatted_text_box behind the scenes to create the
|
222
|
+
# HexaPDF::Layout::TextBox that does the actual work. See that method for details on the
|
223
|
+
# arguments.
|
287
224
|
#
|
288
225
|
# Examples:
|
289
226
|
#
|
@@ -296,36 +233,41 @@ module HexaPDF
|
|
296
233
|
#
|
297
234
|
# See: #text, HexaPDF::Layout::TextBox, HexaPDF::Layout::TextFragment
|
298
235
|
def formatted_text(data, width: 0, height: 0, style: nil, box_style: nil, **style_properties)
|
299
|
-
|
300
|
-
|
301
|
-
data.map! do |hash|
|
302
|
-
if hash.kind_of?(String)
|
303
|
-
Layout::TextFragment.create(hash, style)
|
304
|
-
else
|
305
|
-
link = hash.delete(:link)
|
306
|
-
(hash[:overlays] ||= []) << [:link, {uri: link}] if link
|
307
|
-
text = hash.delete(:text) || link || ""
|
308
|
-
Layout::TextFragment.create(text, retrieve_style(hash.delete(:style) || style, hash))
|
309
|
-
end
|
310
|
-
end
|
311
|
-
draw_box(Layout::TextBox.new(data, width: width, height: height, style: box_style))
|
236
|
+
draw_box(@document.layout.formatted_text_box(data, width: width, height: height, style: style,
|
237
|
+
box_style: box_style, **style_properties))
|
312
238
|
end
|
313
239
|
|
314
240
|
# Draws the given image at the current position.
|
315
241
|
#
|
316
|
-
#
|
317
|
-
#
|
318
|
-
#
|
242
|
+
# It uses HexaPDF::Document::Layout#image_box behind the scenes to create the
|
243
|
+
# HexaPDF::Layout::ImageBox that does the actual work. See that method for details on the
|
244
|
+
# arguments.
|
319
245
|
#
|
320
246
|
# Examples:
|
321
247
|
#
|
322
248
|
# #>pdf-composer
|
323
249
|
# composer.image(machu_picchu, border: {width: 3})
|
324
250
|
# composer.image(machu_picchu, height: 30)
|
251
|
+
#
|
252
|
+
# See: HexaPDF::Layout::ImageBox
|
325
253
|
def image(file, width: 0, height: 0, style: nil, **style_properties)
|
326
|
-
|
327
|
-
|
328
|
-
|
254
|
+
draw_box(@document.layout.image_box(file, width: width, height: height,
|
255
|
+
style: style, **style_properties))
|
256
|
+
end
|
257
|
+
|
258
|
+
# Draws the named box at the current position.
|
259
|
+
#
|
260
|
+
# It uses HexaPDF::Document::Layout#box behind the scenes to create the named box. See that
|
261
|
+
# method for details on the arguments.
|
262
|
+
#
|
263
|
+
# Examples:
|
264
|
+
#
|
265
|
+
# #>pdf-composer
|
266
|
+
# composer.box(:image, image: composer.document.images.add(machu_picchu))
|
267
|
+
#
|
268
|
+
# See: HexaPDF::Document::Layout#box
|
269
|
+
def box(name, width: 0, height: 0, style: nil, **box_options, &block)
|
270
|
+
draw_box(@document.layout.box(name, width: width, height: height, style: style, **box_options, &block))
|
329
271
|
end
|
330
272
|
|
331
273
|
# Draws the given HexaPDF::Layout::Box.
|
@@ -339,16 +281,17 @@ module HexaPDF
|
|
339
281
|
def draw_box(box)
|
340
282
|
drawn_on_page = true
|
341
283
|
while true
|
342
|
-
|
343
|
-
|
284
|
+
result = @frame.fit(box)
|
285
|
+
if result.success?
|
286
|
+
@frame.draw(@canvas, result)
|
344
287
|
break
|
345
288
|
elsif @frame.full?
|
346
289
|
new_page
|
347
290
|
drawn_on_page = false
|
348
291
|
else
|
349
|
-
draw_box, box = @frame.split(
|
292
|
+
draw_box, box = @frame.split(result)
|
350
293
|
if draw_box
|
351
|
-
@frame.draw(@canvas,
|
294
|
+
@frame.draw(@canvas, result)
|
352
295
|
drawn_on_page = true
|
353
296
|
elsif !@frame.find_next_region
|
354
297
|
unless drawn_on_page
|
@@ -361,6 +304,27 @@ module HexaPDF
|
|
361
304
|
end
|
362
305
|
end
|
363
306
|
|
307
|
+
# Creates a stamp (Form XObject) which can be used like an image multiple times on a single page
|
308
|
+
# or on multiple pages.
|
309
|
+
#
|
310
|
+
# The width and the height of the stamp need to be set (frame.width/height or
|
311
|
+
# page.box.width/height might be good choices).
|
312
|
+
#
|
313
|
+
# Examples:
|
314
|
+
#
|
315
|
+
# #>pdf-composer
|
316
|
+
# stamp = composer.create_stamp(50, 50) do |canvas|
|
317
|
+
# canvas.fill_color("red").line_width(5).
|
318
|
+
# rectangle(10, 10, 30, 30).fill_stroke
|
319
|
+
# end
|
320
|
+
# composer.image(stamp, width: 20, height: 20)
|
321
|
+
# composer.image(stamp, width: 50)
|
322
|
+
def create_stamp(width, height) # :yield: canvas
|
323
|
+
stamp = @document.add({Type: :XObject, Subtype: :Form, BBox: [0, 0, width, height]})
|
324
|
+
yield(stamp.canvas) if block_given?
|
325
|
+
stamp
|
326
|
+
end
|
327
|
+
|
364
328
|
private
|
365
329
|
|
366
330
|
# Creates the frame into which boxes are layed out when a new page is created.
|
@@ -372,29 +336,6 @@ module HexaPDF
|
|
372
336
|
media_box.height - @margin.bottom - @margin.top)
|
373
337
|
end
|
374
338
|
|
375
|
-
# Retrieves the appropriate HexaPDF::Layout::Style object based on the +style+ and +properties+
|
376
|
-
# arguments.
|
377
|
-
#
|
378
|
-
# The +style+ argument specifies the style to retrieve. It can either be a registered style name
|
379
|
-
# (see #style), a hash with style properties or +nil+. In the latter case the registered style
|
380
|
-
# :base is used
|
381
|
-
#
|
382
|
-
# If the +properties+ hash is not empty, the retrieved style is duplicated and the properties
|
383
|
-
# hash is applied to it.
|
384
|
-
#
|
385
|
-
# Finally, a default font is set if necessary to ensure that the style object works in all
|
386
|
-
# cases.
|
387
|
-
def retrieve_style(style, properties = nil)
|
388
|
-
style = Layout::Style.create(@styles[style] || style || @styles[:base])
|
389
|
-
style = style.dup.update(**properties) unless properties.nil? || properties.empty?
|
390
|
-
style.font('Times') unless style.font?
|
391
|
-
unless style.font.respond_to?(:pdf_object)
|
392
|
-
name, options = *style.font
|
393
|
-
style.font(@document.fonts.add(name, **(options || {})))
|
394
|
-
end
|
395
|
-
style
|
396
|
-
end
|
397
|
-
|
398
339
|
end
|
399
340
|
|
400
341
|
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
|
@@ -193,6 +193,9 @@ module HexaPDF
|
|
193
193
|
# acro_form.text_field.default_width::
|
194
194
|
# A number specifying the default width of AcroForm text fields which should be auto-sized.
|
195
195
|
#
|
196
|
+
# debug::
|
197
|
+
# If set to +true+, enables debug output.
|
198
|
+
#
|
196
199
|
# document.auto_decrypt::
|
197
200
|
# A boolean determining whether the document should be decrypted automatically when parsed.
|
198
201
|
#
|
@@ -337,6 +340,12 @@ module HexaPDF
|
|
337
340
|
# This can be used to limit the memory needed for reading or writing PDF files with huge
|
338
341
|
# stream objects.
|
339
342
|
#
|
343
|
+
# layout.boxes.map::
|
344
|
+
# A mapping from layout box names to box classes. If the value is a String, it should contain
|
345
|
+
# the name of a constant to such a class.
|
346
|
+
#
|
347
|
+
# See HexaPDF::Layout::Box for more information.
|
348
|
+
#
|
340
349
|
# page.default_media_box::
|
341
350
|
# The media box that is used for new pages that don't define a media box. Default value is
|
342
351
|
# A4. See HexaPDF::Type::Page::PAPER_SIZE for a list of predefined paper sizes.
|
@@ -403,6 +412,7 @@ module HexaPDF
|
|
403
412
|
"#{field.concrete_field_type} field #{field.full_field_name}"
|
404
413
|
end,
|
405
414
|
'acro_form.text_field.default_width' => 100,
|
415
|
+
'debug' => false,
|
406
416
|
'document.auto_decrypt' => true,
|
407
417
|
'document.on_invalid_string' => proc do |str|
|
408
418
|
str.encode(Encoding::UTF_8, invalid: :replace, replace: '')
|
@@ -461,6 +471,12 @@ module HexaPDF
|
|
461
471
|
],
|
462
472
|
'image_loader.pdf.use_stringio' => true,
|
463
473
|
'io.chunk_size' => 2**16,
|
474
|
+
'layout.boxes.map' => {
|
475
|
+
text: 'HexaPDF::Layout::TextBox',
|
476
|
+
image: 'HexaPDF::Layout::ImageBox',
|
477
|
+
column: 'HexaPDF::Layout::ColumnBox',
|
478
|
+
list: 'HexaPDF::Layout::ListBox',
|
479
|
+
},
|
464
480
|
'page.default_media_box' => :A4,
|
465
481
|
'page.default_media_orientation' => :portrait,
|
466
482
|
'parser.on_correctable_error' => proc { false },
|
@@ -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
|
@@ -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
|
@@ -128,6 +128,7 @@ module HexaPDF
|
|
128
128
|
return unless @object.nr_of_vertices > 1
|
129
129
|
canvas.move_to(@object[0].x, @object[0].y)
|
130
130
|
1.upto(@object.nr_of_vertices - 1) {|i| canvas.line_to(@object[i].x, @object[i].y) }
|
131
|
+
canvas.close_subpath
|
131
132
|
canvas.stroke unless @path_only
|
132
133
|
end
|
133
134
|
|
@@ -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
|
@@ -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
|
@@ -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
|
data/lib/hexapdf/content.rb
CHANGED
@@ -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
|
data/lib/hexapdf/data_dir.rb
CHANGED
@@ -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
|
data/lib/hexapdf/dictionary.rb
CHANGED
@@ -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
|
@@ -241,7 +241,7 @@ module HexaPDF
|
|
241
241
|
if str.valid_encoding?
|
242
242
|
str.encode!(Encoding::UTF_8)
|
243
243
|
else
|
244
|
-
document.
|
244
|
+
document.config['document.on_invalid_string'].call(str)
|
245
245
|
end
|
246
246
|
else
|
247
247
|
Utils::PDFDocEncoding.convert_to_utf8(str)
|