hexapdf 0.6.0 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +33 -0
- data/CONTRIBUTERS +1 -1
- data/LICENSE +1 -1
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/bin/hexapdf +1 -1
- data/examples/text_layouter_styling.rb +1 -2
- data/lib/hexapdf.rb +2 -2
- data/lib/hexapdf/cli.rb +3 -3
- data/lib/hexapdf/cli/batch.rb +5 -5
- data/lib/hexapdf/cli/command.rb +15 -17
- data/lib/hexapdf/cli/files.rb +3 -3
- data/lib/hexapdf/cli/images.rb +3 -4
- data/lib/hexapdf/cli/info.rb +5 -5
- data/lib/hexapdf/cli/inspect.rb +6 -6
- data/lib/hexapdf/cli/merge.rb +6 -6
- data/lib/hexapdf/cli/modify.rb +4 -4
- data/lib/hexapdf/cli/optimize.rb +3 -3
- data/lib/hexapdf/configuration.rb +4 -5
- data/lib/hexapdf/content.rb +2 -2
- data/lib/hexapdf/content/canvas.rb +35 -36
- data/lib/hexapdf/content/color_space.rb +9 -14
- data/lib/hexapdf/content/graphic_object.rb +2 -2
- data/lib/hexapdf/content/graphic_object/arc.rb +3 -3
- data/lib/hexapdf/content/graphic_object/endpoint_arc.rb +2 -2
- data/lib/hexapdf/content/graphic_object/solid_arc.rb +4 -8
- data/lib/hexapdf/content/graphics_state.rb +4 -13
- data/lib/hexapdf/content/operator.rb +33 -35
- data/lib/hexapdf/content/parser.rb +28 -18
- data/lib/hexapdf/content/processor.rb +4 -5
- data/lib/hexapdf/content/transformation_matrix.rb +2 -2
- data/lib/hexapdf/data_dir.rb +2 -2
- data/lib/hexapdf/dictionary.rb +8 -9
- data/lib/hexapdf/dictionary_fields.rb +7 -10
- data/lib/hexapdf/document.rb +18 -18
- data/lib/hexapdf/document/files.rb +12 -10
- data/lib/hexapdf/document/fonts.rb +2 -2
- data/lib/hexapdf/document/images.rb +3 -3
- data/lib/hexapdf/document/pages.rb +4 -4
- data/lib/hexapdf/encryption.rb +2 -2
- data/lib/hexapdf/encryption/aes.rb +2 -2
- data/lib/hexapdf/encryption/arc4.rb +4 -4
- data/lib/hexapdf/encryption/fast_aes.rb +2 -2
- data/lib/hexapdf/encryption/fast_arc4.rb +4 -4
- data/lib/hexapdf/encryption/identity.rb +5 -4
- data/lib/hexapdf/encryption/ruby_aes.rb +147 -139
- data/lib/hexapdf/encryption/ruby_arc4.rb +4 -4
- data/lib/hexapdf/encryption/security_handler.rb +11 -12
- data/lib/hexapdf/encryption/standard_security_handler.rb +6 -9
- data/lib/hexapdf/error.rb +7 -9
- data/lib/hexapdf/filter.rb +2 -3
- data/lib/hexapdf/filter/ascii85_decode.rb +3 -3
- data/lib/hexapdf/filter/ascii_hex_decode.rb +2 -2
- data/lib/hexapdf/filter/dct_decode.rb +2 -2
- data/lib/hexapdf/filter/encryption.rb +2 -2
- data/lib/hexapdf/filter/flate_decode.rb +16 -33
- data/lib/hexapdf/filter/jpx_decode.rb +2 -2
- data/lib/hexapdf/filter/lzw_decode.rb +4 -4
- data/lib/hexapdf/filter/predictor.rb +2 -6
- data/lib/hexapdf/filter/run_length_decode.rb +2 -2
- data/lib/hexapdf/font/cmap.rb +2 -3
- data/lib/hexapdf/font/cmap/parser.rb +11 -11
- data/lib/hexapdf/font/cmap/writer.rb +25 -25
- data/lib/hexapdf/font/encoding.rb +2 -2
- data/lib/hexapdf/font/encoding/base.rb +2 -2
- data/lib/hexapdf/font/encoding/difference_encoding.rb +2 -2
- data/lib/hexapdf/font/encoding/glyph_list.rb +6 -6
- data/lib/hexapdf/font/encoding/mac_expert_encoding.rb +2 -2
- data/lib/hexapdf/font/encoding/mac_roman_encoding.rb +2 -2
- data/lib/hexapdf/font/encoding/standard_encoding.rb +2 -2
- data/lib/hexapdf/font/encoding/symbol_encoding.rb +2 -2
- data/lib/hexapdf/font/encoding/win_ansi_encoding.rb +2 -2
- data/lib/hexapdf/font/encoding/zapf_dingbats_encoding.rb +2 -2
- data/lib/hexapdf/font/invalid_glyph.rb +7 -7
- data/lib/hexapdf/font/true_type.rb +2 -2
- data/lib/hexapdf/font/true_type/builder.rb +13 -7
- data/lib/hexapdf/font/true_type/font.rb +2 -3
- data/lib/hexapdf/font/true_type/optimizer.rb +2 -2
- data/lib/hexapdf/font/true_type/subsetter.rb +4 -4
- data/lib/hexapdf/font/true_type/table.rb +3 -5
- data/lib/hexapdf/font/true_type/table/cmap.rb +2 -2
- data/lib/hexapdf/font/true_type/table/cmap_subtable.rb +9 -16
- data/lib/hexapdf/font/true_type/table/directory.rb +4 -4
- data/lib/hexapdf/font/true_type/table/glyf.rb +2 -2
- data/lib/hexapdf/font/true_type/table/head.rb +3 -2
- data/lib/hexapdf/font/true_type/table/hhea.rb +2 -2
- data/lib/hexapdf/font/true_type/table/hmtx.rb +2 -2
- data/lib/hexapdf/font/true_type/table/kern.rb +3 -3
- data/lib/hexapdf/font/true_type/table/loca.rb +3 -3
- data/lib/hexapdf/font/true_type/table/maxp.rb +2 -2
- data/lib/hexapdf/font/true_type/table/name.rb +3 -5
- data/lib/hexapdf/font/true_type/table/os2.rb +4 -3
- data/lib/hexapdf/font/true_type/table/post.rb +3 -7
- data/lib/hexapdf/font/true_type_wrapper.rb +20 -22
- data/lib/hexapdf/font/type1.rb +2 -2
- data/lib/hexapdf/font/type1/afm_parser.rb +7 -7
- data/lib/hexapdf/font/type1/character_metrics.rb +2 -2
- data/lib/hexapdf/font/type1/font.rb +3 -3
- data/lib/hexapdf/font/type1/font_metrics.rb +2 -4
- data/lib/hexapdf/font/type1/pfb_parser.rb +2 -2
- data/lib/hexapdf/font/type1_wrapper.rb +8 -9
- data/lib/hexapdf/font_loader.rb +2 -2
- data/lib/hexapdf/font_loader/from_configuration.rb +2 -2
- data/lib/hexapdf/font_loader/from_file.rb +2 -2
- data/lib/hexapdf/font_loader/standard14.rb +2 -2
- data/lib/hexapdf/image_loader.rb +2 -2
- data/lib/hexapdf/image_loader/jpeg.rb +6 -4
- data/lib/hexapdf/image_loader/pdf.rb +2 -2
- data/lib/hexapdf/image_loader/png.rb +6 -6
- data/lib/hexapdf/importer.rb +6 -4
- data/lib/hexapdf/layout.rb +2 -2
- data/lib/hexapdf/layout/box.rb +4 -4
- data/lib/hexapdf/layout/inline_box.rb +2 -2
- data/lib/hexapdf/layout/line.rb +6 -6
- data/lib/hexapdf/layout/numeric_refinements.rb +2 -2
- data/lib/hexapdf/layout/style.rb +17 -8
- data/lib/hexapdf/layout/text_fragment.rb +86 -48
- data/lib/hexapdf/layout/text_layouter.rb +40 -21
- data/lib/hexapdf/layout/text_shaper.rb +2 -2
- data/lib/hexapdf/name_tree_node.rb +2 -2
- data/lib/hexapdf/number_tree_node.rb +2 -2
- data/lib/hexapdf/object.rb +6 -8
- data/lib/hexapdf/parser.rb +10 -10
- data/lib/hexapdf/rectangle.rb +4 -4
- data/lib/hexapdf/reference.rb +2 -2
- data/lib/hexapdf/revision.rb +4 -4
- data/lib/hexapdf/revisions.rb +5 -5
- data/lib/hexapdf/serializer.rb +27 -24
- data/lib/hexapdf/stream.rb +4 -4
- data/lib/hexapdf/task.rb +2 -2
- data/lib/hexapdf/task/dereference.rb +4 -4
- data/lib/hexapdf/task/optimize.rb +5 -4
- data/lib/hexapdf/tokenizer.rb +12 -14
- data/lib/hexapdf/type.rb +2 -2
- data/lib/hexapdf/type/action.rb +3 -3
- data/lib/hexapdf/type/actions.rb +2 -2
- data/lib/hexapdf/type/actions/go_to.rb +2 -2
- data/lib/hexapdf/type/actions/go_to_r.rb +2 -2
- data/lib/hexapdf/type/actions/launch.rb +2 -2
- data/lib/hexapdf/type/actions/uri.rb +3 -3
- data/lib/hexapdf/type/annotation.rb +3 -3
- data/lib/hexapdf/type/annotations.rb +2 -2
- data/lib/hexapdf/type/annotations/link.rb +2 -2
- data/lib/hexapdf/type/annotations/markup_annotation.rb +2 -2
- data/lib/hexapdf/type/annotations/text.rb +2 -2
- data/lib/hexapdf/type/catalog.rb +4 -4
- data/lib/hexapdf/type/cid_font.rb +4 -5
- data/lib/hexapdf/type/embedded_file.rb +3 -3
- data/lib/hexapdf/type/file_specification.rb +6 -7
- data/lib/hexapdf/type/font.rb +4 -4
- data/lib/hexapdf/type/font_descriptor.rb +3 -4
- data/lib/hexapdf/type/font_simple.rb +12 -16
- data/lib/hexapdf/type/font_true_type.rb +2 -2
- data/lib/hexapdf/type/font_type0.rb +5 -5
- data/lib/hexapdf/type/font_type1.rb +4 -4
- data/lib/hexapdf/type/form.rb +3 -3
- data/lib/hexapdf/type/graphics_state_parameter.rb +3 -3
- data/lib/hexapdf/type/image.rb +13 -14
- data/lib/hexapdf/type/info.rb +2 -2
- data/lib/hexapdf/type/names.rb +2 -2
- data/lib/hexapdf/type/object_stream.rb +5 -5
- data/lib/hexapdf/type/page.rb +9 -10
- data/lib/hexapdf/type/page_tree_node.rb +5 -6
- data/lib/hexapdf/type/resources.rb +11 -11
- data/lib/hexapdf/type/trailer.rb +3 -3
- data/lib/hexapdf/type/viewer_preferences.rb +2 -2
- data/lib/hexapdf/type/xref_stream.rb +8 -4
- data/lib/hexapdf/utils/bit_field.rb +4 -4
- data/lib/hexapdf/utils/bit_stream.rb +4 -4
- data/lib/hexapdf/utils/graphics_helpers.rb +2 -2
- data/lib/hexapdf/utils/lru_cache.rb +2 -2
- data/lib/hexapdf/utils/math_helpers.rb +2 -2
- data/lib/hexapdf/utils/object_hash.rb +3 -3
- data/lib/hexapdf/utils/pdf_doc_encoding.rb +3 -3
- data/lib/hexapdf/utils/sorted_tree_node.rb +12 -11
- data/lib/hexapdf/version.rb +3 -3
- data/lib/hexapdf/writer.rb +8 -8
- data/lib/hexapdf/xref_section.rb +3 -3
- data/test/hexapdf/common_tokenizer_tests.rb +6 -7
- data/test/hexapdf/content/graphic_object/test_endpoint_arc.rb +0 -1
- data/test/hexapdf/content/test_canvas.rb +28 -36
- data/test/hexapdf/content/test_color_space.rb +4 -0
- data/test/hexapdf/content/test_graphics_state.rb +2 -0
- data/test/hexapdf/content/test_operator.rb +6 -7
- data/test/hexapdf/content/test_parser.rb +2 -2
- data/test/hexapdf/content/test_processor.rb +1 -1
- data/test/hexapdf/document/test_files.rb +1 -0
- data/test/hexapdf/document/test_images.rb +1 -1
- data/test/hexapdf/encryption/common.rb +3 -3
- data/test/hexapdf/encryption/test_aes.rb +10 -4
- data/test/hexapdf/encryption/test_identity.rb +1 -1
- data/test/hexapdf/encryption/test_security_handler.rb +13 -17
- data/test/hexapdf/encryption/test_standard_security_handler.rb +12 -12
- data/test/hexapdf/filter/test_ascii85_decode.rb +2 -3
- data/test/hexapdf/filter/test_ascii_hex_decode.rb +6 -1
- data/test/hexapdf/filter/test_flate_decode.rb +2 -2
- data/test/hexapdf/filter/test_lzw_decode.rb +10 -10
- data/test/hexapdf/filter/test_predictor.rb +10 -2
- data/test/hexapdf/filter/test_run_length_decode.rb +1 -1
- data/test/hexapdf/font/cmap/test_parser.rb +40 -40
- data/test/hexapdf/font/cmap/test_writer.rb +29 -29
- data/test/hexapdf/font/test_true_type_wrapper.rb +3 -2
- data/test/hexapdf/font/true_type/common.rb +2 -0
- data/test/hexapdf/font/true_type/table/test_cmap.rb +1 -1
- data/test/hexapdf/font/true_type/table/test_cmap_subtable.rb +5 -4
- data/test/hexapdf/font/true_type/table/test_glyf.rb +2 -2
- data/test/hexapdf/font/true_type/table/test_head.rb +2 -2
- data/test/hexapdf/font/true_type/table/test_name.rb +9 -6
- data/test/hexapdf/font/true_type/test_builder.rb +8 -3
- data/test/hexapdf/font/true_type/test_optimizer.rb +1 -2
- data/test/hexapdf/font/type1/test_afm_parser.rb +2 -2
- data/test/hexapdf/image_loader/test_jpeg.rb +1 -1
- data/test/hexapdf/image_loader/test_pdf.rb +1 -1
- data/test/hexapdf/image_loader/test_png.rb +3 -3
- data/test/hexapdf/layout/test_inline_box.rb +10 -1
- data/test/hexapdf/layout/test_line.rb +4 -4
- data/test/hexapdf/layout/test_style.rb +19 -7
- data/test/hexapdf/layout/test_text_fragment.rb +73 -27
- data/test/hexapdf/layout/test_text_layouter.rb +84 -68
- data/test/hexapdf/layout/test_text_shaper.rb +4 -6
- data/test/hexapdf/task/test_dereference.rb +2 -2
- data/test/hexapdf/task/test_optimize.rb +16 -7
- data/test/hexapdf/test_configuration.rb +1 -1
- data/test/hexapdf/test_data_dir.rb +2 -2
- data/test/hexapdf/test_dictionary.rb +6 -3
- data/test/hexapdf/test_dictionary_fields.rb +15 -14
- data/test/hexapdf/test_document.rb +47 -48
- data/test/hexapdf/test_filter.rb +30 -26
- data/test/hexapdf/test_importer.rb +14 -0
- data/test/hexapdf/test_object.rb +16 -4
- data/test/hexapdf/test_parser.rb +36 -36
- data/test/hexapdf/test_reference.rb +7 -5
- data/test/hexapdf/test_revision.rb +1 -1
- data/test/hexapdf/test_revisions.rb +90 -90
- data/test/hexapdf/test_serializer.rb +3 -2
- data/test/hexapdf/test_stream.rb +2 -4
- data/test/hexapdf/test_tokenizer.rb +2 -2
- data/test/hexapdf/test_writer.rb +80 -80
- data/test/hexapdf/test_xref_section.rb +1 -1
- data/test/hexapdf/type/annotations/test_link.rb +1 -1
- data/test/hexapdf/type/annotations/test_text.rb +3 -3
- data/test/hexapdf/type/test_font_descriptor.rb +1 -1
- data/test/hexapdf/type/test_font_simple.rb +2 -2
- data/test/hexapdf/type/test_font_type0.rb +0 -1
- data/test/hexapdf/type/test_image.rb +0 -3
- data/test/hexapdf/type/test_object_stream.rb +2 -1
- data/test/hexapdf/type/test_page.rb +5 -1
- data/test/hexapdf/type/test_page_tree_node.rb +4 -4
- data/test/hexapdf/type/test_trailer.rb +1 -1
- data/test/hexapdf/type/test_xref_stream.rb +4 -0
- data/test/hexapdf/utils/test_bit_field.rb +2 -0
- data/test/hexapdf/utils/test_bit_stream.rb +1 -1
- data/test/hexapdf/utils/test_lru_cache.rb +1 -1
- data/test/hexapdf/utils/test_sorted_tree_node.rb +10 -4
- data/test/test_helper.rb +3 -6
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: ffd1dd41128f1ef75e1caf26f415e908509f881bfdf1595da9b45c633c26bb59
|
4
|
+
data.tar.gz: ef1ae7147fa94bcf361beae3a340acdd1f6f2a72cc3fdbad0d5e46766957c9b7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dc5242710665cf697db8085fcaf0e5096fce0179308a427e4dccbba3a9067db7713a22f1e83a6732ba943b4aa120eb1df69472b32fdcbae7f430c2cfc7364250
|
7
|
+
data.tar.gz: b700fb5ce735aa6ff38cb33b88f37cb4a7eece29979f0be5abaab884f8aef2f1fcf23336b47e9218ea237d04d27012a46df3fd5154f92b33b6a635d31139a180
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,36 @@
|
|
1
|
+
## 0.7.0 - 2018-06-19
|
2
|
+
|
3
|
+
### Changed
|
4
|
+
|
5
|
+
* All Ruby source files use frozen string literal pragma
|
6
|
+
* [HexaPDF::MalformedPDFError::new] method signature
|
7
|
+
* [HexaPDF::Layout::TextFragment::new] and
|
8
|
+
[HexaPDF::Layout::TextFragment::create] method signatures
|
9
|
+
* [HexaPDF::Encryption::SecurityHandler#set_up_encryption] argument `force_V4`
|
10
|
+
to `force_v4`
|
11
|
+
* [HexaPDF::Layout::TextLayouter#draw] to return result of #fit if possible
|
12
|
+
|
13
|
+
### Removed
|
14
|
+
|
15
|
+
* Optional `leading` argument to HexaPDF::Content::Canvas#font_size method
|
16
|
+
|
17
|
+
### Fixed
|
18
|
+
|
19
|
+
* Misspelt variable name in [HexaPDF::Layout::TextLayouter::SimpleLineWrapping]
|
20
|
+
* [HexaPDF::Layout::TextLayouter::SimpleTextSegmentation] to work if the last
|
21
|
+
character in a text fragment is \r
|
22
|
+
* [HexaPDF::Layout::TextLayouter] to work if an optional break point (think
|
23
|
+
soft-hyphen) is followed by whitespace
|
24
|
+
* [HexaPDF::Font::TrueType::Builder] to correctly order the entries in the
|
25
|
+
table directory
|
26
|
+
* [HexaPDF::Font::TrueType::Builder] to pad the table data to achieve the
|
27
|
+
correct alignment
|
28
|
+
* [HexaPDF::Filter::FlateDecode] by removing the Zlib pools since ther were
|
29
|
+
not thread safe
|
30
|
+
* All color space classes to accept the color space definition as argument to
|
31
|
+
`::new`
|
32
|
+
|
33
|
+
|
1
34
|
## 0.6.0 - 2017-10-27
|
2
35
|
|
3
36
|
### Added
|
data/CONTRIBUTERS
CHANGED
data/LICENSE
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
HexaPDF - A Versatile PDF Creation and Manipulation Library For Ruby
|
2
|
-
Copyright (C) 2014-
|
2
|
+
Copyright (C) 2014-2018 Thomas Leitner
|
3
3
|
|
4
4
|
HexaPDF is free software: you can redistribute it and/or modify it
|
5
5
|
under the terms of the GNU Affero General Public License version 3 as
|
data/Rakefile
CHANGED
@@ -94,7 +94,7 @@ namespace :dev do
|
|
94
94
|
File.open("hexapdf.gemspec", 'w+') {|f| f.puts(contents)}
|
95
95
|
end
|
96
96
|
|
97
|
-
CODING_LINE = "# -*- encoding: utf-8 -*-\n"
|
97
|
+
CODING_LINE = "# -*- encoding: utf-8; frozen_string_literal: true -*-\n"
|
98
98
|
|
99
99
|
desc "Insert/Update copyright notice"
|
100
100
|
task :update_copyright do
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.7.0
|
data/bin/hexapdf
CHANGED
@@ -25,8 +25,7 @@ in voluptate velit esse cillum dolore eu fugiat nulla pariatur.".tr("\n", ' ')
|
|
25
25
|
|
26
26
|
# Wraps the text in a TextFragment using the given style.
|
27
27
|
def fragment(text, style)
|
28
|
-
|
29
|
-
TextFragment.new(items: style.font.decode_utf8(text), style: style)
|
28
|
+
TextFragment.create(text, style)
|
30
29
|
end
|
31
30
|
|
32
31
|
# Draws the text at the given [x, y] position onto the canvas and returns the
|
data/lib/hexapdf.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
1
|
+
# -*- encoding: utf-8; frozen_string_literal: true -*-
|
2
2
|
#
|
3
3
|
#--
|
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-2018 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
@@ -1,10 +1,10 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
1
|
+
# -*- encoding: utf-8; frozen_string_literal: true -*-
|
2
2
|
#
|
3
3
|
#--
|
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-2018 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
|
@@ -52,7 +52,7 @@ module HexaPDF
|
|
52
52
|
# Runs the CLI application.
|
53
53
|
def self.run(args = ARGV)
|
54
54
|
Application.new.parse(args)
|
55
|
-
rescue => e
|
55
|
+
rescue StandardError => e
|
56
56
|
$stderr.puts "Problem encountered: #{e.message}"
|
57
57
|
exit(1)
|
58
58
|
end
|
data/lib/hexapdf/cli/batch.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
1
|
+
# -*- encoding: utf-8; frozen_string_literal: true -*-
|
2
2
|
#
|
3
3
|
#--
|
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-2018 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
|
@@ -43,7 +43,7 @@ module HexaPDF
|
|
43
43
|
def initialize #:nodoc:
|
44
44
|
super('batch', takes_commands: false)
|
45
45
|
short_desc("Execute a single command on multiple files")
|
46
|
-
long_desc(
|
46
|
+
long_desc(<<~EOF)
|
47
47
|
This command allows executing a single command for multiple input files, thereby reducing
|
48
48
|
the overall execution time.
|
49
49
|
|
@@ -57,8 +57,8 @@ module HexaPDF
|
|
57
57
|
args = Shellwords.split(command)
|
58
58
|
files.each do |file|
|
59
59
|
begin
|
60
|
-
HexaPDF::CLI::Application.new.parse(args.map {|a| a.gsub(/{}/, file)})
|
61
|
-
rescue
|
60
|
+
HexaPDF::CLI::Application.new.parse(args.map {|a| a.gsub(/{}/, file) })
|
61
|
+
rescue StandardError
|
62
62
|
if command_parser.verbosity_warning?
|
63
63
|
$stderr.puts "Error processing '#{file}': #{$!.message}"
|
64
64
|
end
|
data/lib/hexapdf/cli/command.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
1
|
+
# -*- encoding: utf-8; frozen_string_literal: true -*-
|
2
2
|
#
|
3
3
|
#--
|
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-2018 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
|
@@ -47,8 +47,8 @@ module HexaPDF
|
|
47
47
|
module Extensions #:nodoc:
|
48
48
|
def help_banner #:nodoc:
|
49
49
|
"hexapdf #{HexaPDF::VERSION} - Versatile PDF Manipulation Tool\n" \
|
50
|
-
"Copyright (c) 2014-2017 Thomas Leitner; licensed under the AGPLv3\n\n"
|
51
|
-
format(usage, indent: 7)
|
50
|
+
"Copyright (c) 2014-2017 Thomas Leitner; licensed under the AGPLv3\n\n" \
|
51
|
+
"#{format(usage, indent: 7)}\n\n"
|
52
52
|
end
|
53
53
|
end
|
54
54
|
|
@@ -243,7 +243,7 @@ module HexaPDF
|
|
243
243
|
# Applies the chosen stream mode to the given object.
|
244
244
|
def optimize_stream(obj)
|
245
245
|
return if @out_options.streams == :preserve || !obj.respond_to?(:set_filter) ||
|
246
|
-
|
246
|
+
Array(obj[:Filter]).any? {|f| IGNORED_FILTERS[f] }
|
247
247
|
|
248
248
|
obj.set_filter(@out_options.streams == :compress ? :FlateDecode : nil)
|
249
249
|
end
|
@@ -251,9 +251,9 @@ module HexaPDF
|
|
251
251
|
# Optimize the object if it is a font object.
|
252
252
|
def optimize_font(obj)
|
253
253
|
return unless @out_options.optimize_fonts && obj.kind_of?(HexaPDF::Type::Font) &&
|
254
|
-
|
255
|
-
|
256
|
-
|
254
|
+
(obj[:Subtype] == :TrueType ||
|
255
|
+
(obj[:Subtype] == :Type0 && obj.descendant_font[:Subtype] == :CIDFontType2)) &&
|
256
|
+
obj.embedded?
|
257
257
|
|
258
258
|
font = HexaPDF::Font::TrueType::Font.new(StringIO.new(obj.font_file.stream))
|
259
259
|
data = HexaPDF::Font::TrueType::Optimizer.build_for_pdf(font)
|
@@ -268,7 +268,7 @@ module HexaPDF
|
|
268
268
|
if @out_options.encryption == :add
|
269
269
|
doc.encrypt(algorithm: @out_options.enc_algorithm,
|
270
270
|
key_length: @out_options.enc_key_length,
|
271
|
-
|
271
|
+
force_v4: @out_options.enc_force_v4,
|
272
272
|
permissions: @out_options.enc_permissions,
|
273
273
|
owner_password: @out_options.enc_owner_pwd,
|
274
274
|
user_password: @out_options.enc_user_pwd)
|
@@ -277,7 +277,7 @@ module HexaPDF
|
|
277
277
|
end
|
278
278
|
end
|
279
279
|
|
280
|
-
PAGE_NUMBER_SPEC = "([1-9]\\d*|e)"
|
280
|
+
PAGE_NUMBER_SPEC = "([1-9]\\d*|e)" #:nodoc:
|
281
281
|
ROTATE_MAP = {'l' => -90, 'r' => 90, 'd' => 180, 'n' => :none}.freeze #:nodoc:
|
282
282
|
|
283
283
|
# Parses the pages specification string and returns an array of tuples containing a page
|
@@ -295,12 +295,12 @@ module HexaPDF
|
|
295
295
|
page_num = ($1 == 'e' ? count : str.to_i)
|
296
296
|
next if page_num > count
|
297
297
|
arr << [page_num - 1, ROTATE_MAP[$2]]
|
298
|
-
when /\A#{PAGE_NUMBER_SPEC}-#{PAGE_NUMBER_SPEC}(?:\/([1-9]\d*))?(l|r|d|n)?\z/
|
298
|
+
when /\A#{PAGE_NUMBER_SPEC}-#{PAGE_NUMBER_SPEC}(?:\/([1-9]\d*))?(l|r|d|n)?\z/o
|
299
299
|
start_nr = ($1 == 'e' ? count : [$1.to_i, count].min) - 1
|
300
300
|
end_nr = ($2 == 'e' ? count : [$2.to_i, count].min) - 1
|
301
301
|
step = ($3 ? $3.to_i : 1) * (start_nr > end_nr ? -1 : 1)
|
302
302
|
rotation = ROTATE_MAP[$4]
|
303
|
-
start_nr.step(to: end_nr, by: step) {|n| arr << [n, rotation]}
|
303
|
+
start_nr.step(to: end_nr, by: step) {|n| arr << [n, rotation] }
|
304
304
|
else
|
305
305
|
raise OptionParser::InvalidArgument, "invalid page range format: #{str}"
|
306
306
|
end
|
@@ -315,15 +315,13 @@ module HexaPDF
|
|
315
315
|
if $stdin.tty?
|
316
316
|
read_from_console(prompt)
|
317
317
|
else
|
318
|
-
|
319
|
-
pwd = read_from_console(prompt) unless pwd
|
320
|
-
pwd.chomp
|
318
|
+
($stdin.gets || read_from_console(prompt)).chomp
|
321
319
|
end
|
322
320
|
end
|
323
321
|
|
324
322
|
# Removes unused pages and page tree nodes from the document.
|
325
323
|
def remove_unused_pages(doc)
|
326
|
-
retained = doc.pages.each_with_object({}) {|page, h| h[page.data] = true}
|
324
|
+
retained = doc.pages.each_with_object({}) {|page, h| h[page.data] = true }
|
327
325
|
retained[doc.pages.root.data] = true
|
328
326
|
doc.each(current: false) do |obj|
|
329
327
|
next unless obj.kind_of?(HexaPDF::Dictionary)
|
@@ -338,7 +336,7 @@ module HexaPDF
|
|
338
336
|
# Displays the given prompt, reads from the console without echo and returns the read string.
|
339
337
|
def read_from_console(prompt)
|
340
338
|
IO.console.write("#{prompt}: ")
|
341
|
-
str = IO.console.noecho {|io| io.gets.chomp}
|
339
|
+
str = IO.console.noecho {|io| io.gets.chomp }
|
342
340
|
puts
|
343
341
|
str
|
344
342
|
end
|
data/lib/hexapdf/cli/files.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
1
|
+
# -*- encoding: utf-8; frozen_string_literal: true -*-
|
2
2
|
#
|
3
3
|
#--
|
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-2018 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
|
@@ -44,7 +44,7 @@ module HexaPDF
|
|
44
44
|
def initialize #:nodoc:
|
45
45
|
super('files', takes_commands: false)
|
46
46
|
short_desc("List or extract embedded files from a PDF file")
|
47
|
-
long_desc(
|
47
|
+
long_desc(<<~EOF)
|
48
48
|
If the option --extract is not given, the available files are listed with their names and
|
49
49
|
indices. The --extract option can then be used to extract one or more files.
|
50
50
|
EOF
|
data/lib/hexapdf/cli/images.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
1
|
+
# -*- encoding: utf-8; frozen_string_literal: true -*-
|
2
2
|
#
|
3
3
|
#--
|
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-2018 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
|
@@ -45,7 +45,7 @@ module HexaPDF
|
|
45
45
|
def initialize #:nodoc:
|
46
46
|
super('images', takes_commands: false)
|
47
47
|
short_desc("List or extract images from a PDF file")
|
48
|
-
long_desc(
|
48
|
+
long_desc(<<~EOF)
|
49
49
|
If the option --extract is not given, the available images are listed with their index and
|
50
50
|
additional information, sorted by page number. The --extract option can then be used to
|
51
51
|
extract one or more images, saving them to files called `prefix-n.ext` where the prefix
|
@@ -104,7 +104,6 @@ module HexaPDF
|
|
104
104
|
end
|
105
105
|
end
|
106
106
|
|
107
|
-
|
108
107
|
# Extracts the images with the given indices.
|
109
108
|
def extract_images(doc)
|
110
109
|
done = Set.new
|
data/lib/hexapdf/cli/info.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
1
|
+
# -*- encoding: utf-8; frozen_string_literal: true -*-
|
2
2
|
#
|
3
3
|
#--
|
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-2018 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
|
@@ -49,7 +49,7 @@ module HexaPDF
|
|
49
49
|
def initialize #:nodoc:
|
50
50
|
super('info', takes_commands: false)
|
51
51
|
short_desc("Show document information")
|
52
|
-
long_desc(
|
52
|
+
long_desc(<<~EOF)
|
53
53
|
This command extracts information from the Info dictionary of a PDF file as well
|
54
54
|
as some other useful information like the used PDF version and encryption information.
|
55
55
|
EOF
|
@@ -78,10 +78,10 @@ module HexaPDF
|
|
78
78
|
HexaPDF::Document.open(file, options) do |doc|
|
79
79
|
output_line("File name", file)
|
80
80
|
output_line("File size", File.stat(file).size.to_s + " bytes")
|
81
|
-
INFO_KEYS.each do |name|
|
81
|
+
@auto_decrypt && INFO_KEYS.each do |name|
|
82
82
|
next unless doc.trailer.info.key?(name)
|
83
83
|
output_line(name.to_s, doc.trailer.info[name].to_s)
|
84
|
-
end
|
84
|
+
end
|
85
85
|
|
86
86
|
if doc.encrypted? && @auto_decrypt
|
87
87
|
details = doc.security_handler.encryption_details
|
data/lib/hexapdf/cli/inspect.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
1
|
+
# -*- encoding: utf-8; frozen_string_literal: true -*-
|
2
2
|
#
|
3
3
|
#--
|
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-2018 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
|
@@ -42,7 +42,7 @@ module HexaPDF
|
|
42
42
|
def initialize #:nodoc:
|
43
43
|
super('inspect', takes_commands: false)
|
44
44
|
short_desc("Dig into the internal structure of a PDF file")
|
45
|
-
long_desc(
|
45
|
+
long_desc(<<~EOF)
|
46
46
|
Inspects a PDF file for debugging or testing purposes. This command is useful when one
|
47
47
|
needs to inspect the internal object structure or a stream of a PDF file. A PDF object is
|
48
48
|
always shown in the PDF syntax.
|
@@ -94,7 +94,7 @@ module HexaPDF
|
|
94
94
|
end
|
95
95
|
|
96
96
|
def execute(file) #:nodoc:
|
97
|
-
with_document(file, password: @password) {|doc| send("do_#{@exec}", doc)}
|
97
|
+
with_document(file, password: @password) {|doc| send("do_#{@exec}", doc) }
|
98
98
|
end
|
99
99
|
|
100
100
|
private
|
@@ -116,8 +116,8 @@ module HexaPDF
|
|
116
116
|
page_list = doc.pages.to_a
|
117
117
|
pages.each do |index, _|
|
118
118
|
page = page_list[index]
|
119
|
-
str = "page #{index + 1} (#{page.oid},#{page.gen}): "
|
120
|
-
str << Array(page[:Contents]).map {|c| "#{c.oid},#{c.gen}"}.join(" ")
|
119
|
+
str = +"page #{index + 1} (#{page.oid},#{page.gen}): "
|
120
|
+
str << Array(page[:Contents]).map {|c| "#{c.oid},#{c.gen}" }.join(" ")
|
121
121
|
puts str
|
122
122
|
end
|
123
123
|
end
|
data/lib/hexapdf/cli/merge.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
1
|
+
# -*- encoding: utf-8; frozen_string_literal: true -*-
|
2
2
|
#
|
3
3
|
#--
|
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-2018 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
|
@@ -44,7 +44,7 @@ module HexaPDF
|
|
44
44
|
def initialize #:nodoc:
|
45
45
|
super('merge', takes_commands: false)
|
46
46
|
short_desc("Merge multiple PDF files")
|
47
|
-
long_desc(
|
47
|
+
long_desc(<<~EOF)
|
48
48
|
This command merges pages from multiple PDFs into one output file which can optionally be
|
49
49
|
encrypted/decrypted and optimized in various ways.
|
50
50
|
|
@@ -144,14 +144,14 @@ module HexaPDF
|
|
144
144
|
@files.each do |s|
|
145
145
|
page_list = s.file.pages.to_a
|
146
146
|
s.pages = parse_pages_specification(s.pages, s.file.pages.count)
|
147
|
-
s.pages.each {|arr| arr[0] = page_list[arr[0]]}
|
147
|
+
s.pages.each {|arr| arr[0] = page_list[arr[0]] }
|
148
148
|
end
|
149
149
|
|
150
150
|
if @interleave
|
151
151
|
max_pages_per_file = 0
|
152
152
|
all = @files.each_with_index.map do |spec, findex|
|
153
153
|
list = []
|
154
|
-
spec.pages.each {|index, rotation| list << [spec.file, findex, index, rotation]}
|
154
|
+
spec.pages.each {|index, rotation| list << [spec.file, findex, index, rotation] }
|
155
155
|
max_pages_per_file = list.size if list.size > max_pages_per_file
|
156
156
|
list
|
157
157
|
end
|
@@ -165,7 +165,7 @@ module HexaPDF
|
|
165
165
|
end
|
166
166
|
else
|
167
167
|
@files.each_with_index do |s, findex|
|
168
|
-
s.pages.each {|page, rotation| import_page(page_tree, findex, page, rotation)}
|
168
|
+
s.pages.each {|page, rotation| import_page(page_tree, findex, page, rotation) }
|
169
169
|
end
|
170
170
|
end
|
171
171
|
end
|