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/serializer.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
|
@@ -162,7 +162,7 @@ module HexaPDF
|
|
162
162
|
#
|
163
163
|
# See: PDF1.7 s7.3.3
|
164
164
|
def serialize_float(obj)
|
165
|
-
|
165
|
+
-0.0001 < obj && obj < 0.0001 && obj != 0 ? sprintf("%.6f", obj) : obj.round(6).to_s
|
166
166
|
end
|
167
167
|
|
168
168
|
# The regexp matches all characters that need to be escaped and the substs hash contains the
|
@@ -171,7 +171,7 @@ module HexaPDF
|
|
171
171
|
# See PDF1.7 s7.3.5
|
172
172
|
NAME_SUBSTS = {} # :nodoc:
|
173
173
|
[0..32, 127..255, Tokenizer::DELIMITER.bytes, Tokenizer::WHITESPACE.bytes, [35]].each do |a|
|
174
|
-
a.each {|c| NAME_SUBSTS[c.chr] = "##{c.to_s(16).rjust(2,
|
174
|
+
a.each {|c| NAME_SUBSTS[c.chr] = "##{c.to_s(16).rjust(2, '0')}" }
|
175
175
|
end
|
176
176
|
NAME_REGEXP = /[^!-~&&[^##{Regexp.escape(Tokenizer::DELIMITER)}#{Regexp.escape(Tokenizer::WHITESPACE)}]]/ # :nodoc:
|
177
177
|
NAME_CACHE = Utils::LRUCache.new(1000) # :nodoc:
|
@@ -183,7 +183,7 @@ module HexaPDF
|
|
183
183
|
NAME_CACHE[obj] ||=
|
184
184
|
begin
|
185
185
|
str = obj.to_s.force_encoding(Encoding::BINARY)
|
186
|
-
str.gsub!(NAME_REGEXP) {|m| NAME_SUBSTS[m]}
|
186
|
+
str.gsub!(NAME_REGEXP) {|m| NAME_SUBSTS[m] }
|
187
187
|
"/#{str}"
|
188
188
|
end
|
189
189
|
end
|
@@ -195,32 +195,32 @@ module HexaPDF
|
|
195
195
|
#
|
196
196
|
# See: PDF1.7 s7.3.6
|
197
197
|
def serialize_array(obj)
|
198
|
-
str = "["
|
198
|
+
str = +"["
|
199
199
|
index = 0
|
200
200
|
while index < obj.size
|
201
201
|
tmp = __serialize(obj[index])
|
202
|
-
str << " "
|
203
|
-
|
202
|
+
str << " " unless BYTE_IS_DELIMITER[tmp.getbyte(0)] ||
|
203
|
+
BYTE_IS_DELIMITER[str.getbyte(-1)]
|
204
204
|
str << tmp
|
205
205
|
index += 1
|
206
206
|
end
|
207
|
-
str << "]"
|
207
|
+
str << "]"
|
208
208
|
end
|
209
209
|
|
210
210
|
# Serializes a Hash object (i.e. a PDF dictionary object).
|
211
211
|
#
|
212
212
|
# See: PDF1.7 s7.3.7
|
213
213
|
def serialize_hash(obj)
|
214
|
-
str = "<<"
|
214
|
+
str = +"<<"
|
215
215
|
obj.each do |k, v|
|
216
216
|
next if v.nil? || (v.respond_to?(:null?) && v.null?)
|
217
217
|
str << __serialize(k)
|
218
218
|
tmp = __serialize(v)
|
219
|
-
str << " "
|
220
|
-
|
219
|
+
str << " " unless BYTE_IS_DELIMITER[tmp.getbyte(0)] ||
|
220
|
+
BYTE_IS_DELIMITER[str.getbyte(-1)]
|
221
221
|
str << tmp
|
222
222
|
end
|
223
|
-
str << ">>"
|
223
|
+
str << ">>"
|
224
224
|
end
|
225
225
|
|
226
226
|
STRING_ESCAPE_MAP = {"(" => "\\(", ")" => "\\)", "\\" => "\\\\", "\r" => "\\r"}.freeze # :nodoc:
|
@@ -229,16 +229,19 @@ module HexaPDF
|
|
229
229
|
#
|
230
230
|
# See: PDF1.7 s7.3.4
|
231
231
|
def serialize_string(obj)
|
232
|
-
if @encrypter && @object.kind_of?(HexaPDF::Object) && @object.indirect?
|
233
|
-
|
234
|
-
|
235
|
-
|
232
|
+
obj = if @encrypter && @object.kind_of?(HexaPDF::Object) && @object.indirect?
|
233
|
+
encrypter.encrypt_string(obj, @object)
|
234
|
+
elsif obj.encoding != Encoding::BINARY
|
235
|
+
if obj.match?(/[^ -~\t\r\n]/)
|
236
236
|
"\xFE\xFF".b << obj.encode(Encoding::UTF_16BE).force_encoding(Encoding::BINARY)
|
237
237
|
else
|
238
238
|
obj.b
|
239
239
|
end
|
240
|
-
|
241
|
-
|
240
|
+
else
|
241
|
+
obj.dup
|
242
|
+
end
|
243
|
+
obj.gsub!(/[\(\)\\\r]/n, STRING_ESCAPE_MAP)
|
244
|
+
"(#{obj})"
|
242
245
|
end
|
243
246
|
|
244
247
|
# The ISO PDF specification differs in respect to the supported date format. When converting
|
@@ -282,7 +285,7 @@ module HexaPDF
|
|
282
285
|
|
283
286
|
# See: PDF1.7 s7.3.10
|
284
287
|
def serialize_hexapdf_reference(obj)
|
285
|
-
"#{obj.oid} #{obj.gen} R"
|
288
|
+
"#{obj.oid} #{obj.gen} R"
|
286
289
|
end
|
287
290
|
|
288
291
|
# Serializes the streams dictionary and its stream.
|
@@ -304,11 +307,11 @@ module HexaPDF
|
|
304
307
|
if @io && fiber.respond_to?(:length) && fiber.length >= 0
|
305
308
|
obj.value[:Length] = fiber.length
|
306
309
|
@io << __serialize(obj.value)
|
307
|
-
@io << "stream\n"
|
310
|
+
@io << "stream\n"
|
308
311
|
while fiber.alive? && (data = fiber.resume)
|
309
312
|
@io << data.freeze
|
310
313
|
end
|
311
|
-
@io << "\nendstream"
|
314
|
+
@io << "\nendstream"
|
312
315
|
|
313
316
|
nil
|
314
317
|
else
|
@@ -316,9 +319,9 @@ module HexaPDF
|
|
316
319
|
obj.value[:Length] = data.size
|
317
320
|
|
318
321
|
str = __serialize(obj.value)
|
319
|
-
str << "stream\n"
|
322
|
+
str << "stream\n"
|
320
323
|
str << data
|
321
|
-
str << "\nendstream"
|
324
|
+
str << "\nendstream"
|
322
325
|
end
|
323
326
|
end
|
324
327
|
|
data/lib/hexapdf/stream.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
|
@@ -162,7 +162,7 @@ module HexaPDF
|
|
162
162
|
if data.stream.kind_of?(String)
|
163
163
|
HexaPDF::Filter.source_from_string(data.stream)
|
164
164
|
else
|
165
|
-
data.stream.fiber(config['io.chunk_size'
|
165
|
+
data.stream.fiber(config['io.chunk_size'])
|
166
166
|
end
|
167
167
|
end
|
168
168
|
|
@@ -190,7 +190,7 @@ module HexaPDF
|
|
190
190
|
def stream_encoder(source = stream_source)
|
191
191
|
encoder_data = [document.unwrap(self[:Filter])].flatten.
|
192
192
|
zip([document.unwrap(self[:DecodeParms])].flatten).
|
193
|
-
delete_if {|f, _| f.nil?}
|
193
|
+
delete_if {|f, _| f.nil? }
|
194
194
|
|
195
195
|
if data.stream.kind_of?(StreamData)
|
196
196
|
decoder_data = data.stream.filter.zip(data.stream.decode_parms)
|
data/lib/hexapdf/task.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
|
@@ -90,9 +90,9 @@ module HexaPDF
|
|
90
90
|
def recurse(val) #:nodoc:
|
91
91
|
case val
|
92
92
|
when Hash
|
93
|
-
val.each {|k, v| val[k] = recurse(v)}
|
93
|
+
val.each {|k, v| val[k] = recurse(v) }
|
94
94
|
when Array
|
95
|
-
val.map! {|v| recurse(v)}
|
95
|
+
val.map! {|v| recurse(v) }
|
96
96
|
when HexaPDF::Reference
|
97
97
|
dereference(@doc.object(val))
|
98
98
|
when HexaPDF::Object
|
@@ -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
|
@@ -157,7 +157,7 @@ module HexaPDF
|
|
157
157
|
count = 0
|
158
158
|
end
|
159
159
|
end
|
160
|
-
objstms.each {|objstm| doc.add(objstm, revision: rev_index)}
|
160
|
+
objstms.each {|objstm| doc.add(objstm, revision: rev_index) }
|
161
161
|
doc.add({Type: :XRef}, revision: rev_index) unless xref_stream
|
162
162
|
end
|
163
163
|
end
|
@@ -222,7 +222,8 @@ module HexaPDF
|
|
222
222
|
end
|
223
223
|
|
224
224
|
def process(op, operands) #:nodoc:
|
225
|
-
@result << HexaPDF::Content::Operator::DEFAULT_OPERATORS[op
|
225
|
+
@result << HexaPDF::Content::Operator::DEFAULT_OPERATORS[op].
|
226
|
+
serialize(@serializer, *operands)
|
226
227
|
end
|
227
228
|
|
228
229
|
end
|
data/lib/hexapdf/tokenizer.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
|
@@ -56,17 +56,16 @@ module HexaPDF
|
|
56
56
|
# Characters defined as whitespace.
|
57
57
|
#
|
58
58
|
# See: PDF1.7 s7.2.2
|
59
|
-
WHITESPACE = "\0\t\
|
59
|
+
WHITESPACE = " \n\r\0\t\f"
|
60
60
|
|
61
61
|
# Characters defined as delimiters.
|
62
62
|
#
|
63
63
|
# See: PDF1.7 s7.2.2
|
64
|
-
DELIMITER = "()<>{}/[]%"
|
64
|
+
DELIMITER = "()<>{}/[]%"
|
65
65
|
|
66
66
|
WHITESPACE_MULTI_RE = /[#{WHITESPACE}]+/ # :nodoc:
|
67
67
|
|
68
|
-
WHITESPACE_OR_DELIMITER_RE = /(?=[#{Regexp.escape(WHITESPACE
|
69
|
-
|
68
|
+
WHITESPACE_OR_DELIMITER_RE = /(?=[#{Regexp.escape(WHITESPACE + DELIMITER)}])/ # :nodoc:
|
70
69
|
|
71
70
|
# The IO object from the tokens are read.
|
72
71
|
attr_reader :io
|
@@ -228,7 +227,7 @@ module HexaPDF
|
|
228
227
|
|
229
228
|
private
|
230
229
|
|
231
|
-
TOKEN_CACHE = Hash.new {|h, k| h[k] = Token.new(k)} # :nodoc:
|
230
|
+
TOKEN_CACHE = Hash.new {|h, k| h[k] = Token.new(k) } # :nodoc:
|
232
231
|
TOKEN_CACHE['true'] = true
|
233
232
|
TOKEN_CACHE['false'] = false
|
234
233
|
TOKEN_CACHE['null'] = nil
|
@@ -237,11 +236,11 @@ module HexaPDF
|
|
237
236
|
#
|
238
237
|
# See: PDF1.7 s7.2
|
239
238
|
def parse_keyword
|
240
|
-
str = scan_until(WHITESPACE_OR_DELIMITER_RE) || @ss.scan(/.*/)
|
241
|
-
TOKEN_CACHE[str
|
239
|
+
str = scan_until(WHITESPACE_OR_DELIMITER_RE) || @ss.scan(/.*/)
|
240
|
+
TOKEN_CACHE[str]
|
242
241
|
end
|
243
242
|
|
244
|
-
REFERENCE_RE = /[#{WHITESPACE}]+([+-]?\d+)[#{WHITESPACE}]+R
|
243
|
+
REFERENCE_RE = /[#{WHITESPACE}]+([+-]?\d+)[#{WHITESPACE}]+R#{WHITESPACE_OR_DELIMITER_RE}/ # :nodoc:
|
245
244
|
|
246
245
|
# Parses the number (integer or real) at the current position.
|
247
246
|
#
|
@@ -254,7 +253,7 @@ module HexaPDF
|
|
254
253
|
tmp = Reference.new(tmp, @ss[1].to_i) if @ss.scan(REFERENCE_RE)
|
255
254
|
tmp
|
256
255
|
elsif (val = @ss.scan(/[+-]?(?:\d+\.\d*|\.\d+)/))
|
257
|
-
val << '0'
|
256
|
+
val << '0' if val.getbyte(-1) == 46 # dot '.'
|
258
257
|
Float(val)
|
259
258
|
else
|
260
259
|
parse_keyword
|
@@ -326,8 +325,8 @@ module HexaPDF
|
|
326
325
|
end
|
327
326
|
|
328
327
|
@ss.pos += 1
|
329
|
-
data.tr!(WHITESPACE, ""
|
330
|
-
[data].pack('H*'
|
328
|
+
data.tr!(WHITESPACE, "")
|
329
|
+
[data].pack('H*')
|
331
330
|
end
|
332
331
|
|
333
332
|
# Parses the name at the current position.
|
@@ -383,7 +382,6 @@ module HexaPDF
|
|
383
382
|
result
|
384
383
|
end
|
385
384
|
|
386
|
-
|
387
385
|
# Prepares the StringScanner by filling its string instance with enough bytes.
|
388
386
|
#
|
389
387
|
# The number of needed bytes can be specified via the optional +needed_bytes+ argument.
|
data/lib/hexapdf/type.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/action.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
|
@@ -46,7 +46,7 @@ module HexaPDF
|
|
46
46
|
|
47
47
|
define_type :Action
|
48
48
|
|
49
|
-
define_field :Type, type: Symbol, default:
|
49
|
+
define_field :Type, type: Symbol, default: type
|
50
50
|
define_field :S, type: Symbol, required: true
|
51
51
|
define_field :Next, type: [Dictionary, Hash, Array], version: '1.2'
|
52
52
|
|
data/lib/hexapdf/type/actions.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
|
@@ -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
|
@@ -53,7 +53,7 @@ module HexaPDF
|
|
53
53
|
unless self[:URI].ascii_only?
|
54
54
|
yield("URIs have to contain ASCII characters only", true)
|
55
55
|
uri = self[:URI].dup.force_encoding(Encoding::BINARY)
|
56
|
-
uri.encode!(Encoding::US_ASCII, fallback:
|
56
|
+
uri.encode!(Encoding::US_ASCII, fallback: lambda {|c| "%#{c.ord.to_s(16).upcase}" })
|
57
57
|
self[:URI] = uri
|
58
58
|
end
|
59
59
|
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
|
@@ -47,7 +47,7 @@ module HexaPDF
|
|
47
47
|
|
48
48
|
define_type :Annot
|
49
49
|
|
50
|
-
define_field :Type, type: Symbol, default:
|
50
|
+
define_field :Type, type: Symbol, default: type
|
51
51
|
define_field :Subtype, type: Symbol, required: true
|
52
52
|
define_field :Rect, type: Rectangle, required: true
|
53
53
|
define_field :Contents, type: String
|