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
data/lib/hexapdf/type/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
|
data/lib/hexapdf/type/names.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
|
@@ -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
|
@@ -97,7 +97,7 @@ module HexaPDF
|
|
97
97
|
|
98
98
|
define_type :ObjStm
|
99
99
|
|
100
|
-
define_field :Type, type: Symbol, required: true, default:
|
100
|
+
define_field :Type, type: Symbol, required: true, default: type, version: '1.5'
|
101
101
|
define_field :N, type: Integer # not required, will be auto-filled on #write_objects
|
102
102
|
define_field :First, type: Integer # not required, will be auto-filled on #write_objects
|
103
103
|
define_field :Extends, type: Stream
|
@@ -110,7 +110,7 @@ module HexaPDF
|
|
110
110
|
def parse_stream
|
111
111
|
data = stream
|
112
112
|
oids, offsets = parse_oids_and_offsets(data)
|
113
|
-
oids.each {|oid| add_object(Reference.new(oid, 0))}
|
113
|
+
oids.each {|oid| add_object(Reference.new(oid, 0)) }
|
114
114
|
Data.new(data, oids, offsets)
|
115
115
|
end
|
116
116
|
|
@@ -200,7 +200,7 @@ module HexaPDF
|
|
200
200
|
first = value[:First].to_i
|
201
201
|
|
202
202
|
stream_tokenizer = Tokenizer.new(StringIO.new(data))
|
203
|
-
data.
|
203
|
+
!data.empty? && value[:N].to_i.times do
|
204
204
|
oids << stream_tokenizer.next_object
|
205
205
|
offsets << first + stream_tokenizer.next_object
|
206
206
|
end
|
data/lib/hexapdf/type/page.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
|
@@ -119,7 +119,7 @@ module HexaPDF
|
|
119
119
|
|
120
120
|
define_type :Page
|
121
121
|
|
122
|
-
define_field :Type, type: Symbol, required: true, default:
|
122
|
+
define_field :Type, type: Symbol, required: true, default: type
|
123
123
|
define_field :Parent, type: :Pages, required: true, indirect: true
|
124
124
|
define_field :LastModified, type: PDFDate, version: '1.3'
|
125
125
|
define_field :Resources, type: :XXResources
|
@@ -227,7 +227,7 @@ module HexaPDF
|
|
227
227
|
# streams' data!
|
228
228
|
def contents
|
229
229
|
Array(self[:Contents]).each_with_object("".b) do |content_stream, content|
|
230
|
-
content << " "
|
230
|
+
content << " " unless content.empty?
|
231
231
|
content << document.deref(content_stream).stream
|
232
232
|
end
|
233
233
|
end
|
@@ -238,7 +238,7 @@ module HexaPDF
|
|
238
238
|
# or by creating a new one if no content stream exists.
|
239
239
|
def contents=(data)
|
240
240
|
first, *rest = self[:Contents]
|
241
|
-
rest.each {|stream| document.delete(stream)}
|
241
|
+
rest.each {|stream| document.delete(stream) }
|
242
242
|
if first
|
243
243
|
self[:Contents] = first
|
244
244
|
document.deref(first).stream = data
|
@@ -370,11 +370,10 @@ module HexaPDF
|
|
370
370
|
def perform_validation(&block)
|
371
371
|
super
|
372
372
|
REQUIRED_INHERITABLE_FIELDS.each do |name|
|
373
|
-
if self[name]
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
end
|
373
|
+
next if self[name]
|
374
|
+
yield("Inheritable page field #{name} not set", name == :Resources)
|
375
|
+
self[:Resources] = {}
|
376
|
+
self[:Resources].validate(&block)
|
378
377
|
end
|
379
378
|
end
|
380
379
|
|
@@ -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,7 +61,7 @@ module HexaPDF
|
|
61
61
|
|
62
62
|
define_type :Pages
|
63
63
|
|
64
|
-
define_field :Type, type: Symbol, required: true, default:
|
64
|
+
define_field :Type, type: Symbol, required: true, default: type
|
65
65
|
define_field :Parent, type: Dictionary, indirect: true
|
66
66
|
define_field :Kids, type: Array, required: true, default: []
|
67
67
|
define_field :Count, type: Integer, required: true, default: 0
|
@@ -72,7 +72,6 @@ module HexaPDF
|
|
72
72
|
define_field :CropBox, type: Rectangle
|
73
73
|
define_field :Rotate, type: Integer
|
74
74
|
|
75
|
-
|
76
75
|
# Returns +true+ since page tree objects must always be indirect.
|
77
76
|
def must_be_indirect?
|
78
77
|
true
|
@@ -175,7 +174,7 @@ module HexaPDF
|
|
175
174
|
return nil unless page && page[:Parent]
|
176
175
|
|
177
176
|
parent = page[:Parent]
|
178
|
-
index = parent[:Kids].index {|kid| document.deref(kid).data == page.data}
|
177
|
+
index = parent[:Kids].index {|kid| document.deref(kid).data == page.data }
|
179
178
|
|
180
179
|
if index
|
181
180
|
ancestors = [parent]
|
@@ -260,7 +259,7 @@ module HexaPDF
|
|
260
259
|
|
261
260
|
if self[:Count] == 0
|
262
261
|
yield("A PDF document needs at least one page", true)
|
263
|
-
add_page.validate {|msg, correctable| yield(msg, correctable)}
|
262
|
+
add_page.validate {|msg, correctable| yield(msg, correctable) }
|
264
263
|
end
|
265
264
|
end
|
266
265
|
|
@@ -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
|
@@ -64,20 +64,20 @@ module HexaPDF
|
|
64
64
|
def color_space(name)
|
65
65
|
case name
|
66
66
|
when :DeviceRGB, :DeviceGray, :DeviceCMYK
|
67
|
-
GlobalConfiguration.constantize('color_space.map'
|
67
|
+
GlobalConfiguration.constantize('color_space.map', name).new
|
68
68
|
else
|
69
69
|
space_definition = self[:ColorSpace] && self[:ColorSpace][name]
|
70
70
|
if space_definition.nil?
|
71
71
|
raise HexaPDF::Error, "Color space '#{name}' not found in the resources"
|
72
72
|
elsif space_definition.kind_of?(Array)
|
73
|
-
space_definition.map! {|item| document.deref(item)}
|
73
|
+
space_definition.map! {|item| document.deref(item) }
|
74
74
|
space_family = space_definition[0]
|
75
75
|
else
|
76
76
|
space_family = space_definition
|
77
77
|
space_definition = [space_definition]
|
78
78
|
end
|
79
79
|
|
80
|
-
GlobalConfiguration.constantize('color_space.map'
|
80
|
+
GlobalConfiguration.constantize('color_space.map', space_family) do
|
81
81
|
HexaPDF::Content::ColorSpace::Universal
|
82
82
|
end.new(space_definition)
|
83
83
|
end
|
@@ -97,7 +97,7 @@ module HexaPDF
|
|
97
97
|
color_space_dict = self[:ColorSpace]
|
98
98
|
|
99
99
|
name, _value = color_space_dict.value.find do |_k, v|
|
100
|
-
v.map! {|item| document.deref(item)}
|
100
|
+
v.map! {|item| document.deref(item) }
|
101
101
|
v == definition
|
102
102
|
end
|
103
103
|
unless name
|
@@ -118,7 +118,7 @@ module HexaPDF
|
|
118
118
|
#
|
119
119
|
# If there already exists a name for the given XObject, it is just returned.
|
120
120
|
def add_xobject(object)
|
121
|
-
object_setter(:XObject, 'XO'
|
121
|
+
object_setter(:XObject, 'XO', object)
|
122
122
|
end
|
123
123
|
|
124
124
|
# Returns the graphics state parameter dictionary (see Type::GraphicsStateParameter) stored
|
@@ -134,7 +134,7 @@ module HexaPDF
|
|
134
134
|
#
|
135
135
|
# If there already exists a name for the given dictionary, it is just returned.
|
136
136
|
def add_ext_gstate(object)
|
137
|
-
object_setter(:ExtGState, 'GS'
|
137
|
+
object_setter(:ExtGState, 'GS', object)
|
138
138
|
end
|
139
139
|
|
140
140
|
# Returns the font dictionary stored under the given name.
|
@@ -148,7 +148,7 @@ module HexaPDF
|
|
148
148
|
#
|
149
149
|
# If there already exists a name for the given dictionary, it is just returned.
|
150
150
|
def add_font(object)
|
151
|
-
object_setter(:Font, 'F'
|
151
|
+
object_setter(:Font, 'F', object)
|
152
152
|
end
|
153
153
|
|
154
154
|
# Returns the property list stored under the given name.
|
@@ -162,7 +162,7 @@ module HexaPDF
|
|
162
162
|
#
|
163
163
|
# If there already exists a name for the given property list, it is just returned.
|
164
164
|
def add_property_list(dict)
|
165
|
-
object_setter(:Properties, 'P'
|
165
|
+
object_setter(:Properties, 'P', dict)
|
166
166
|
end
|
167
167
|
|
168
168
|
private
|
@@ -180,7 +180,7 @@ module HexaPDF
|
|
180
180
|
def object_setter(dict_name, prefix, object)
|
181
181
|
self[dict_name] = {} unless key?(dict_name)
|
182
182
|
dict = self[dict_name]
|
183
|
-
name, _value = dict.each.find {|_, dict_obj| dict_obj == object}
|
183
|
+
name, _value = dict.each.find {|_, dict_obj| dict_obj == object }
|
184
184
|
unless name
|
185
185
|
name = create_resource_name(dict.value, prefix)
|
186
186
|
dict[name] = object
|
data/lib/hexapdf/type/trailer.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
|
@@ -110,7 +110,7 @@ module HexaPDF
|
|
110
110
|
unless value[:Root]
|
111
111
|
yield("A PDF document must have a Catalog dictionary", true)
|
112
112
|
value[:Root] = document.add(Type: :Catalog)
|
113
|
-
value[:Root].validate {|message, correctable| yield(message, correctable)}
|
113
|
+
value[:Root].validate {|message, correctable| yield(message, correctable) }
|
114
114
|
end
|
115
115
|
|
116
116
|
if value[:Encrypt] && (!document.security_handler ||
|
@@ -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
|
@@ -67,7 +67,8 @@ module HexaPDF
|
|
67
67
|
|
68
68
|
define_type :XRef
|
69
69
|
|
70
|
-
define_field :Type, type: Symbol, default:
|
70
|
+
define_field :Type, type: Symbol, default: type, required: true, indirect: false,
|
71
|
+
version: '1.5'
|
71
72
|
# Size is not required because it will be auto-filled before the object is written
|
72
73
|
define_field :Size, type: Integer, indirect: false
|
73
74
|
define_field :Index, type: Array, indirect: false
|
@@ -75,7 +76,6 @@ module HexaPDF
|
|
75
76
|
# W is not required because it will be auto-filled on #update_with_xref_section_and_trailer
|
76
77
|
define_field :W, type: Array, indirect: false
|
77
78
|
|
78
|
-
|
79
79
|
# Returns an XRefSection that represents the content of this cross-reference stream.
|
80
80
|
#
|
81
81
|
# Each invocation returns a new XRefSection object based on the current data in the
|
@@ -98,6 +98,10 @@ module HexaPDF
|
|
98
98
|
# Makes this cross-reference stream represent the data in the given HexaPDF::XRefSection and
|
99
99
|
# Type::Trailer.
|
100
100
|
#
|
101
|
+
# The +xref_section+ needs to contain an entry for this cross-reference stream and it is
|
102
|
+
# necessary that this entry is the one with the highest byte position (for calculating the
|
103
|
+
# correct /W entry).
|
104
|
+
#
|
101
105
|
# The given cross-reference section is *not* stored but only used to rewrite the associated
|
102
106
|
# stream to reflect the cross-reference section. The dictionary is updated with the
|
103
107
|
# information from the trailer and the needed entries for the cross-reference section.
|
@@ -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
|
@@ -68,7 +68,7 @@ module HexaPDF
|
|
68
68
|
value_setter = "#{name}="
|
69
69
|
|
70
70
|
define_method(lister) do
|
71
|
-
bit_names.map {|n| send(getter, n) ? n : nil}.compact
|
71
|
+
bit_names.map {|n| send(getter, n) ? n : nil }.compact
|
72
72
|
end
|
73
73
|
define_method(getter) do |bit|
|
74
74
|
(send(value_getter) || 0)[mapping[bit]] == 1
|
@@ -76,7 +76,7 @@ module HexaPDF
|
|
76
76
|
define_method(setter) do |*bits, clear_existing: false|
|
77
77
|
send(value_setter, 0) if clear_existing || send(value_getter).nil?
|
78
78
|
result = send(value_getter)
|
79
|
-
bits.each {|bit| result |= 1 << mapping[bit]}
|
79
|
+
bits.each {|bit| result |= 1 << mapping[bit] }
|
80
80
|
send(value_setter, result)
|
81
81
|
end
|
82
82
|
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
|
@@ -44,7 +44,7 @@ module HexaPDF
|
|
44
44
|
class BitStreamReader
|
45
45
|
|
46
46
|
# Creates a new object, optionally providing the string from where the bits should be read.
|
47
|
-
def initialize(data = '')
|
47
|
+
def initialize(data = +'')
|
48
48
|
@data = data.force_encoding(Encoding::BINARY)
|
49
49
|
@pos = 0
|
50
50
|
@bit_cache = 0
|
@@ -58,7 +58,7 @@ module HexaPDF
|
|
58
58
|
@pos = 0
|
59
59
|
self
|
60
60
|
end
|
61
|
-
alias
|
61
|
+
alias << append_data
|
62
62
|
|
63
63
|
# Returns the number of remaining bits that can be read.
|
64
64
|
def remaining_bits
|
@@ -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
|
@@ -114,7 +114,7 @@ module HexaPDF
|
|
114
114
|
# generation number and the associated data as arguments.
|
115
115
|
def each
|
116
116
|
return to_enum(__method__) unless block_given?
|
117
|
-
@oids.keys.each {|oid| yield(oid, @oids[oid], @table[oid]) if @table.key?(oid)}
|
117
|
+
@oids.keys.each {|oid| yield(oid, @oids[oid], @table[oid]) if @table.key?(oid) }
|
118
118
|
self
|
119
119
|
end
|
120
120
|
|