hexapdf 0.6.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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
|
@@ -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
|
|
@@ -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
|
|
@@ -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
|
|
@@ -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/type/catalog.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
|
|
@@ -48,7 +48,7 @@ module HexaPDF
|
|
|
48
48
|
|
|
49
49
|
define_type :Catalog
|
|
50
50
|
|
|
51
|
-
define_field :Type, type: Symbol, required: true, default:
|
|
51
|
+
define_field :Type, type: Symbol, required: true, default: type
|
|
52
52
|
define_field :Version, type: Symbol, version: '1.4'
|
|
53
53
|
define_field :Extensions, type: Dictionary, version: '1.7'
|
|
54
54
|
# Pages field is required but this is handled in #perform_validation
|
|
@@ -99,7 +99,7 @@ module HexaPDF
|
|
|
99
99
|
unless key?(:Pages)
|
|
100
100
|
yield("A PDF document needs a page tree", true)
|
|
101
101
|
value[:Pages] = document.add(Type: :Pages)
|
|
102
|
-
value[:Pages].validate {|msg, correctable| yield(msg, correctable)}
|
|
102
|
+
value[:Pages].validate {|msg, correctable| yield(msg, correctable) }
|
|
103
103
|
end
|
|
104
104
|
end
|
|
105
105
|
|
|
@@ -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
|
|
@@ -51,7 +51,6 @@ module HexaPDF
|
|
|
51
51
|
define_field :DW2, type: Array, default: [880, -1100]
|
|
52
52
|
define_field :W2, type: Array
|
|
53
53
|
|
|
54
|
-
|
|
55
54
|
# Returns the unscaled width of the given CID in glyph units, or 0 if the width for the CID is
|
|
56
55
|
# missing.
|
|
57
56
|
#
|
|
@@ -101,11 +100,11 @@ module HexaPDF
|
|
|
101
100
|
entry = array[index]
|
|
102
101
|
value = array[index + 1]
|
|
103
102
|
if value.kind_of?(Array)
|
|
104
|
-
value.each_with_index {|width, i| result[entry + i] = width}
|
|
103
|
+
value.each_with_index {|width, i| result[entry + i] = width }
|
|
105
104
|
index += 2
|
|
106
105
|
else
|
|
107
106
|
width = array[index + 2]
|
|
108
|
-
entry.upto(value) {|cid| result[cid] = width}
|
|
107
|
+
entry.upto(value) {|cid| result[cid] = width }
|
|
109
108
|
index += 3
|
|
110
109
|
end
|
|
111
110
|
end
|
|
@@ -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
|
|
@@ -72,7 +72,7 @@ module HexaPDF
|
|
|
72
72
|
|
|
73
73
|
define_type :EmbeddedFile
|
|
74
74
|
|
|
75
|
-
define_field :Type, type: Symbol, default:
|
|
75
|
+
define_field :Type, type: Symbol, default: type, version: '1.3'
|
|
76
76
|
define_field :Subtype, type: Symbol
|
|
77
77
|
define_field :Params, type: :XXEmbeddedFileParameters
|
|
78
78
|
|
|
@@ -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
|
|
@@ -75,7 +75,7 @@ module HexaPDF
|
|
|
75
75
|
|
|
76
76
|
define_type :Filespec
|
|
77
77
|
|
|
78
|
-
define_field :Type, type: Symbol, default:
|
|
78
|
+
define_field :Type, type: Symbol, default: type, required: true
|
|
79
79
|
define_field :FS, type: Symbol
|
|
80
80
|
define_field :F, type: PDFByteString
|
|
81
81
|
define_field :UF, type: String, version: '1.7'
|
|
@@ -89,7 +89,6 @@ module HexaPDF
|
|
|
89
89
|
define_field :Desc, type: String, version: '1.6'
|
|
90
90
|
define_field :CI, type: Dictionary, version: '1.7'
|
|
91
91
|
|
|
92
|
-
|
|
93
92
|
# Returns +true+ if this file specification references an URL and not a file.
|
|
94
93
|
def url?
|
|
95
94
|
self[:FS] == :URL
|
|
@@ -130,7 +129,7 @@ module HexaPDF
|
|
|
130
129
|
begin
|
|
131
130
|
URI(url)
|
|
132
131
|
rescue URI::InvalidURIError => e
|
|
133
|
-
raise HexaPDF::Error
|
|
132
|
+
raise HexaPDF::Error, e
|
|
134
133
|
end
|
|
135
134
|
self.path = url
|
|
136
135
|
self[:FS] = :URL
|
|
@@ -214,11 +213,11 @@ module HexaPDF
|
|
|
214
213
|
# in the EmbeddedFiles name tree is also deleted.
|
|
215
214
|
def unembed
|
|
216
215
|
return unless key?(:EF)
|
|
217
|
-
self[:EF].each {|
|
|
216
|
+
self[:EF].each {|_, ef_stream| document.delete(ef_stream) }
|
|
218
217
|
|
|
219
218
|
if document.catalog.key?(:Names) && document.catalog[:Names].key?(:EmbeddedFiles)
|
|
220
219
|
tree = document.catalog[:Names][:EmbeddedFiles]
|
|
221
|
-
tree.each_entry.find_all {|_, spec| document.deref(spec) == self}.each do |name, _|
|
|
220
|
+
tree.each_entry.find_all {|_, spec| document.deref(spec) == self }.each do |(name, _)|
|
|
222
221
|
tree.delete_entry(name)
|
|
223
222
|
end
|
|
224
223
|
end
|
data/lib/hexapdf/type/font.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
|
|
|
45
45
|
define_type :Font
|
|
46
46
|
|
|
47
|
-
define_field :Type, type: Symbol, required: true, default:
|
|
47
|
+
define_field :Type, type: Symbol, required: true, default: type
|
|
48
48
|
define_field :BaseFont, type: Symbol, required: true
|
|
49
49
|
define_field :ToUnicode, type: Stream, version: '1.2'
|
|
50
50
|
|
|
@@ -56,7 +56,7 @@ module HexaPDF
|
|
|
56
56
|
# Returns the UTF-8 string for the given character code, or calls the configuration option
|
|
57
57
|
# 'font.on_missing_unicode_mapping' if no mapping was found.
|
|
58
58
|
def to_utf8(code)
|
|
59
|
-
to_unicode_cmap
|
|
59
|
+
to_unicode_cmap&.to_unicode(code) || missing_unicode_mapping(code)
|
|
60
60
|
end
|
|
61
61
|
|
|
62
62
|
# Returns the bounding box of the font or +nil+ if it is not found.
|
|
@@ -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
|
|
@@ -48,7 +48,7 @@ module HexaPDF
|
|
|
48
48
|
|
|
49
49
|
define_type :FontDescriptor
|
|
50
50
|
|
|
51
|
-
define_field :Type, type: Symbol, required: true, default:
|
|
51
|
+
define_field :Type, type: Symbol, required: true, default: type
|
|
52
52
|
define_field :FontName, type: Symbol, required: true
|
|
53
53
|
define_field :FontFamily, type: PDFByteString, version: '1.5'
|
|
54
54
|
define_field :FontStretch, type: Symbol, version: '1.5'
|
|
@@ -76,7 +76,6 @@ module HexaPDF
|
|
|
76
76
|
define_field :FD, type: Dictionary
|
|
77
77
|
define_field :CIDSet, type: Stream
|
|
78
78
|
|
|
79
|
-
|
|
80
79
|
bit_field(:raw_flags, {fixed_pitch: 0, serif: 1, symbolic: 2, script: 3, nonsymbolic: 5,
|
|
81
80
|
italic: 6, all_cap: 16, small_cap: 17, force_bold: 18},
|
|
82
81
|
lister: "flags", getter: "flagged?", setter: "flag")
|
|
@@ -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
|
|
@@ -61,15 +61,12 @@ module HexaPDF
|
|
|
61
61
|
encoding = encoding_from_font if encoding.nil?
|
|
62
62
|
encoding
|
|
63
63
|
when HexaPDF::Dictionary, Hash
|
|
64
|
-
encoding = val[:BaseEncoding]
|
|
65
|
-
encoding
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
encoding = HexaPDF::Font::Encoding.for_name(:StandardEncoding)
|
|
71
|
-
end
|
|
72
|
-
end
|
|
64
|
+
encoding = val[:BaseEncoding] && HexaPDF::Font::Encoding.for_name(val[:BaseEncoding])
|
|
65
|
+
encoding ||= if embedded? || symbolic?
|
|
66
|
+
encoding_from_font
|
|
67
|
+
else
|
|
68
|
+
HexaPDF::Font::Encoding.for_name(:StandardEncoding)
|
|
69
|
+
end
|
|
73
70
|
encoding = difference_encoding(encoding, val[:Differences]) if val.key?(:Differences)
|
|
74
71
|
encoding
|
|
75
72
|
when nil
|
|
@@ -88,16 +85,15 @@ module HexaPDF
|
|
|
88
85
|
# Returns the UTF-8 string for the given character code, or calls the configuration option
|
|
89
86
|
# 'font.on_missing_unicode_mapping' if no mapping was found.
|
|
90
87
|
def to_utf8(code)
|
|
91
|
-
(
|
|
92
|
-
encoding.unicode(code) || missing_unicode_mapping(code)
|
|
88
|
+
to_unicode_cmap&.to_unicode(code) || encoding.unicode(code) || missing_unicode_mapping(code)
|
|
93
89
|
end
|
|
94
90
|
|
|
95
91
|
# Returns the unscaled width of the given code point in glyph units, or 0 if the width for
|
|
96
92
|
# the code point is missing.
|
|
97
93
|
def width(code)
|
|
98
94
|
widths = self[:Widths]
|
|
99
|
-
first_char = self[:FirstChar]
|
|
100
|
-
last_char = self[:LastChar]
|
|
95
|
+
first_char = self[:FirstChar]
|
|
96
|
+
last_char = self[:LastChar]
|
|
101
97
|
|
|
102
98
|
if widths && code >= first_char && code <= last_char
|
|
103
99
|
widths[code - first_char]
|
|
@@ -116,7 +112,7 @@ module HexaPDF
|
|
|
116
112
|
# Returns +true+ if the font is a symbolic font, +false+ if it is not, and +nil+ if it is
|
|
117
113
|
# not known.
|
|
118
114
|
def symbolic?
|
|
119
|
-
self[:FontDescriptor]
|
|
115
|
+
self[:FontDescriptor]&.flagged?(:symbolic)
|
|
120
116
|
end
|
|
121
117
|
|
|
122
118
|
# Returns whether word spacing is applicable when using this font.
|
|
@@ -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
|
|
@@ -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
|
|
@@ -72,8 +72,8 @@ module HexaPDF
|
|
|
72
72
|
# Returns the UTF-8 string for the given code, or calls the configuration option
|
|
73
73
|
# 'font.on_missing_unicode_mapping' if no mapping was found.
|
|
74
74
|
def to_utf8(code)
|
|
75
|
-
(
|
|
76
|
-
|
|
75
|
+
to_unicode_cmap&.to_unicode(code) || ucs2_cmap&.to_unicode(code) ||
|
|
76
|
+
missing_unicode_mapping(code)
|
|
77
77
|
end
|
|
78
78
|
|
|
79
79
|
# Returns the unscaled width of the given CID in glyph units, or 0 if the width for the code
|
|
@@ -103,7 +103,7 @@ module HexaPDF
|
|
|
103
103
|
#
|
|
104
104
|
# See: PDF1.7 s9.3.3
|
|
105
105
|
def word_spacing_applicable?
|
|
106
|
-
@word_spacing_applicable ||= ((cmap.read_codes("\x20"
|
|
106
|
+
@word_spacing_applicable ||= ((cmap.read_codes("\x20") && true) rescue false)
|
|
107
107
|
end
|
|
108
108
|
|
|
109
109
|
private
|
|
@@ -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
|
|
@@ -65,10 +65,10 @@ module HexaPDF
|
|
|
65
65
|
%s(TimesNewRoman,Bold) => %s(Times-Bold),
|
|
66
66
|
%s(TimesNewRoman,BoldItalic) => %s(Times-BoldItalic),
|
|
67
67
|
}
|
|
68
|
-
%i
|
|
68
|
+
%i[Times-Roman Times-Bold Times-Italic Times-BoldItalic
|
|
69
69
|
Helvetica Helvetica-Bold Helvetica-Oblique Helvetica-BoldOblique
|
|
70
70
|
Courier Courier-Bold Courier-Oblique Courier-BoldOblique
|
|
71
|
-
Symbol ZapfDingbats
|
|
71
|
+
Symbol ZapfDingbats].each {|name| @mapping[name] = name }
|
|
72
72
|
|
|
73
73
|
# Returns +true+ if the given name is the name of a standard font.
|
|
74
74
|
def self.standard_font?(name)
|
data/lib/hexapdf/type/form.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
|
|
|
45
45
|
define_type :XObject
|
|
46
46
|
|
|
47
|
-
define_field :Type, type: Symbol, default:
|
|
47
|
+
define_field :Type, type: Symbol, default: type
|
|
48
48
|
define_field :Subtype, type: Symbol, required: true, default: :Form
|
|
49
49
|
define_field :FormType, type: Integer, default: 1
|
|
50
50
|
define_field :BBox, type: Rectangle, required: true
|
|
@@ -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,7 +47,7 @@ module HexaPDF
|
|
|
47
47
|
|
|
48
48
|
define_type :ExtGState
|
|
49
49
|
|
|
50
|
-
define_field :Type, type: Symbol, required: true, default:
|
|
50
|
+
define_field :Type, type: Symbol, required: true, default: type
|
|
51
51
|
define_field :LW, type: Numeric, version: "1.3"
|
|
52
52
|
define_field :LC, type: Integer, version: "1.3"
|
|
53
53
|
define_field :LJ, type: Integer, version: "1.3"
|
data/lib/hexapdf/type/image.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
|
|
@@ -50,7 +50,7 @@ module HexaPDF
|
|
|
50
50
|
|
|
51
51
|
define_type :XObject
|
|
52
52
|
|
|
53
|
-
define_field :Type, type: Symbol, default:
|
|
53
|
+
define_field :Type, type: Symbol, default: type
|
|
54
54
|
define_field :Subtype, type: Symbol, required: true, default: :Image
|
|
55
55
|
define_field :Width, type: Integer, required: true
|
|
56
56
|
define_field :Height, type: Integer, required: true
|
|
@@ -112,17 +112,17 @@ module HexaPDF
|
|
|
112
112
|
case filter
|
|
113
113
|
when :DCTDecode
|
|
114
114
|
result.type = :jpeg
|
|
115
|
-
result.extension = 'jpg'
|
|
115
|
+
result.extension = 'jpg'
|
|
116
116
|
when :JPXDecode
|
|
117
117
|
result.type = :jp2
|
|
118
|
-
result.extension = 'jpx'
|
|
118
|
+
result.extension = 'jpx'
|
|
119
119
|
when :JBIG2Decode
|
|
120
120
|
result.type = :jbig2
|
|
121
121
|
when :CCITTFaxDecode
|
|
122
122
|
result.type = :ccitt
|
|
123
123
|
else
|
|
124
124
|
result.type = :png
|
|
125
|
-
result.extension = 'png'
|
|
125
|
+
result.extension = 'png'
|
|
126
126
|
end
|
|
127
127
|
|
|
128
128
|
if rest || ![:FlateDecode, :DCTDecode, :JPXDecode, nil].include?(filter)
|
|
@@ -177,7 +177,7 @@ module HexaPDF
|
|
|
177
177
|
end
|
|
178
178
|
|
|
179
179
|
io = if name_or_io.kind_of?(String)
|
|
180
|
-
File.open(name_or_io.sub(/\.#{info.extension}\z/, '')
|
|
180
|
+
File.open(name_or_io.sub(/\.#{info.extension}\z/, '') << "." << info.extension, "wb")
|
|
181
181
|
else
|
|
182
182
|
name_or_io
|
|
183
183
|
end
|
|
@@ -226,14 +226,14 @@ module HexaPDF
|
|
|
226
226
|
if info.color_space == :rgb
|
|
227
227
|
palette = palette_data[0, palette_data.length - palette_data.length % 3]
|
|
228
228
|
else
|
|
229
|
-
palette_data.each_byte {|byte| palette << byte << byte << byte}
|
|
229
|
+
palette_data.each_byte {|byte| palette << byte << byte << byte }
|
|
230
230
|
end
|
|
231
231
|
io << png_chunk('PLTE', palette)
|
|
232
232
|
end
|
|
233
233
|
|
|
234
|
-
if self[:Mask].kind_of?(Array) && self[:Mask].each_slice(2).all? {|a, b| a == b} &&
|
|
234
|
+
if self[:Mask].kind_of?(Array) && self[:Mask].each_slice(2).all? {|a, b| a == b } &&
|
|
235
235
|
(color_type == ImageLoader::PNG::TRUECOLOR || color_type == ImageLoader::PNG::GREYSCALE)
|
|
236
|
-
io << png_chunk('tRNS', self[:Mask].each_slice(2).map {|a, _| a}.pack('n*'))
|
|
236
|
+
io << png_chunk('tRNS', self[:Mask].each_slice(2).map {|a, _| a }.pack('n*'))
|
|
237
237
|
end
|
|
238
238
|
|
|
239
239
|
filter, = *self[:Filter]
|
|
@@ -246,13 +246,12 @@ module HexaPDF
|
|
|
246
246
|
end
|
|
247
247
|
io << png_chunk('IDAT', Filter.string_from_source(data))
|
|
248
248
|
|
|
249
|
-
io << png_chunk('IEND'
|
|
249
|
+
io << png_chunk('IEND')
|
|
250
250
|
end
|
|
251
251
|
|
|
252
252
|
# Returns the binary representation of the PNG chunk for the given chunk type and data.
|
|
253
|
-
def png_chunk(type, data =
|
|
254
|
-
[data.
|
|
255
|
-
[Zlib.crc32(data, Zlib.crc32(type))].pack("N")
|
|
253
|
+
def png_chunk(type, data = '')
|
|
254
|
+
[data.length].pack("N") << type << data << [Zlib.crc32(data, Zlib.crc32(type))].pack("N")
|
|
256
255
|
end
|
|
257
256
|
|
|
258
257
|
end
|