hexapdf 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +56 -0
- data/CONTRIBUTERS +1 -1
- data/Rakefile +3 -3
- data/VERSION +1 -1
- data/examples/arc.rb +1 -1
- data/examples/graphics.rb +1 -1
- data/examples/hello_world.rb +1 -1
- data/examples/merging.rb +1 -1
- data/examples/show_char_bboxes.rb +1 -1
- data/examples/standard_pdf_fonts.rb +1 -1
- data/examples/truetype.rb +1 -1
- data/lib/hexapdf/cli.rb +14 -7
- data/lib/hexapdf/cli/extract.rb +1 -1
- data/lib/hexapdf/cli/info.rb +2 -2
- data/lib/hexapdf/cli/inspect.rb +4 -4
- data/lib/hexapdf/cli/modify.rb +151 -51
- data/lib/hexapdf/configuration.rb +1 -1
- data/lib/hexapdf/content/canvas.rb +1 -1
- data/lib/hexapdf/content/processor.rb +1 -1
- data/lib/hexapdf/dictionary.rb +6 -19
- data/lib/hexapdf/dictionary_fields.rb +1 -1
- data/lib/hexapdf/document.rb +23 -16
- data/lib/hexapdf/document/files.rb +130 -0
- data/lib/hexapdf/{font_utils.rb → document/fonts.rb} +40 -38
- data/lib/hexapdf/document/images.rb +117 -0
- data/lib/hexapdf/document/pages.rb +125 -0
- data/lib/hexapdf/encryption/aes.rb +1 -1
- data/lib/hexapdf/encryption/ruby_aes.rb +10 -10
- data/lib/hexapdf/encryption/standard_security_handler.rb +11 -8
- data/lib/hexapdf/filter/ascii85_decode.rb +1 -1
- data/lib/hexapdf/filter/ascii_hex_decode.rb +1 -6
- data/lib/hexapdf/font/cmap/writer.rb +5 -7
- data/lib/hexapdf/font/true_type.rb +4 -1
- data/lib/hexapdf/font/true_type/font.rb +8 -16
- data/lib/hexapdf/font/true_type/table.rb +5 -16
- data/lib/hexapdf/font/true_type/table/cmap.rb +2 -7
- data/lib/hexapdf/font/true_type/table/cmap_subtable.rb +2 -6
- data/lib/hexapdf/font/true_type/table/directory.rb +0 -5
- data/lib/hexapdf/font/true_type/table/glyf.rb +3 -11
- data/lib/hexapdf/font/true_type/table/head.rb +0 -12
- data/lib/hexapdf/font/true_type/table/hhea.rb +0 -7
- data/lib/hexapdf/font/true_type/table/hmtx.rb +1 -5
- data/lib/hexapdf/font/true_type/table/loca.rb +0 -4
- data/lib/hexapdf/font/true_type/table/maxp.rb +0 -8
- data/lib/hexapdf/font/true_type/table/name.rb +3 -17
- data/lib/hexapdf/font/true_type/table/os2.rb +0 -14
- data/lib/hexapdf/font/true_type/table/post.rb +0 -8
- data/lib/hexapdf/font/true_type_wrapper.rb +1 -1
- data/lib/hexapdf/font/type1.rb +2 -2
- data/lib/hexapdf/font/type1/font.rb +2 -1
- data/lib/hexapdf/font/type1/font_metrics.rb +10 -1
- data/lib/hexapdf/font/type1_wrapper.rb +2 -1
- data/lib/hexapdf/font_loader/from_configuration.rb +1 -1
- data/lib/hexapdf/font_loader/standard14.rb +1 -1
- data/lib/hexapdf/image_loader/jpeg.rb +1 -1
- data/lib/hexapdf/image_loader/pdf.rb +1 -1
- data/lib/hexapdf/image_loader/png.rb +2 -2
- data/lib/hexapdf/object.rb +18 -5
- data/lib/hexapdf/rectangle.rb +8 -1
- data/lib/hexapdf/revisions.rb +4 -2
- data/lib/hexapdf/serializer.rb +3 -3
- data/lib/hexapdf/stream.rb +3 -2
- data/lib/hexapdf/task/dereference.rb +4 -5
- data/lib/hexapdf/task/optimize.rb +6 -3
- data/lib/hexapdf/tokenizer.rb +3 -3
- data/lib/hexapdf/type/file_specification.rb +2 -2
- data/lib/hexapdf/type/form.rb +19 -0
- data/lib/hexapdf/type/page.rb +21 -6
- data/lib/hexapdf/type/page_tree_node.rb +27 -34
- data/lib/hexapdf/utils/bit_stream.rb +1 -1
- data/lib/hexapdf/utils/pdf_doc_encoding.rb +1 -1
- data/lib/hexapdf/version.rb +1 -1
- data/man/man1/hexapdf.1 +259 -187
- data/test/hexapdf/content/graphic_object/test_arc.rb +1 -1
- data/test/hexapdf/content/graphic_object/test_endpoint_arc.rb +1 -1
- data/test/hexapdf/content/graphic_object/test_solid_arc.rb +1 -1
- data/test/hexapdf/content/test_canvas.rb +1 -1
- data/test/hexapdf/document/test_files.rb +71 -0
- data/test/hexapdf/{test_font_utils.rb → document/test_fonts.rb} +1 -2
- data/test/hexapdf/document/test_images.rb +78 -0
- data/test/hexapdf/document/test_pages.rb +114 -0
- data/test/hexapdf/encryption/test_standard_security_handler.rb +26 -5
- data/test/hexapdf/font/test_true_type_wrapper.rb +1 -1
- data/test/hexapdf/font/true_type/common.rb +0 -4
- data/test/hexapdf/font/true_type/table/test_cmap.rb +0 -6
- data/test/hexapdf/font/true_type/table/test_directory.rb +0 -5
- data/test/hexapdf/font/true_type/table/test_glyf.rb +5 -8
- data/test/hexapdf/font/true_type/table/test_head.rb +0 -20
- data/test/hexapdf/font/true_type/table/test_hhea.rb +0 -7
- data/test/hexapdf/font/true_type/table/test_hmtx.rb +2 -7
- data/test/hexapdf/font/true_type/table/test_loca.rb +4 -8
- data/test/hexapdf/font/true_type/table/test_maxp.rb +0 -7
- data/test/hexapdf/font/true_type/table/test_name.rb +0 -19
- data/test/hexapdf/font/true_type/table/test_os2.rb +0 -8
- data/test/hexapdf/font/true_type/table/test_post.rb +0 -13
- data/test/hexapdf/font/true_type/test_font.rb +14 -38
- data/test/hexapdf/font/true_type/test_table.rb +0 -9
- data/test/hexapdf/font/type1/test_font_metrics.rb +22 -0
- data/test/hexapdf/task/test_dereference.rb +5 -1
- data/test/hexapdf/task/test_optimize.rb +1 -1
- data/test/hexapdf/test_dictionary.rb +4 -0
- data/test/hexapdf/test_document.rb +0 -7
- data/test/hexapdf/test_importer.rb +4 -4
- data/test/hexapdf/test_object.rb +31 -9
- data/test/hexapdf/test_rectangle.rb +18 -0
- data/test/hexapdf/test_revisions.rb +7 -0
- data/test/hexapdf/test_serializer.rb +6 -0
- data/test/hexapdf/test_writer.rb +2 -2
- data/test/hexapdf/type/test_form.rb +12 -0
- data/test/hexapdf/type/test_page.rb +39 -20
- data/test/hexapdf/type/test_page_tree_node.rb +28 -21
- metadata +21 -9
- data/lib/hexapdf/document_utils.rb +0 -209
- data/test/hexapdf/test_document_utils.rb +0 -144
@@ -1,144 +0,0 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
|
-
|
3
|
-
require 'test_helper'
|
4
|
-
require 'stringio'
|
5
|
-
require 'tempfile'
|
6
|
-
require 'hexapdf/document'
|
7
|
-
|
8
|
-
describe HexaPDF::DocumentUtils::Images do
|
9
|
-
before do
|
10
|
-
@doc = HexaPDF::Document.new
|
11
|
-
end
|
12
|
-
|
13
|
-
describe "add_image" do
|
14
|
-
describe "using a custom image loader" do
|
15
|
-
before do
|
16
|
-
@loader = Object.new
|
17
|
-
@loader.define_singleton_method(:handles?) {|*| true}
|
18
|
-
@loader.define_singleton_method(:load) do |doc, s|
|
19
|
-
s = HexaPDF::StreamData.new(s) if s.kind_of?(IO)
|
20
|
-
doc.add({Subtype: :Image}, stream: s)
|
21
|
-
end
|
22
|
-
HexaPDF::GlobalConfiguration['image_loader'].unshift(@loader)
|
23
|
-
end
|
24
|
-
|
25
|
-
after do
|
26
|
-
HexaPDF::GlobalConfiguration['image_loader'].delete(@loader)
|
27
|
-
end
|
28
|
-
|
29
|
-
it "adds an image using a filename" do
|
30
|
-
data = 'test'
|
31
|
-
image = @doc.utils.add_image(data)
|
32
|
-
assert_equal(data, image.stream)
|
33
|
-
assert_equal(File.absolute_path(data), image.source_path)
|
34
|
-
end
|
35
|
-
|
36
|
-
it "adds an image using an IO" do
|
37
|
-
File.open(__FILE__, 'rb') do |file|
|
38
|
-
image = @doc.utils.add_image(file)
|
39
|
-
assert_equal(File.read(__FILE__), image.stream)
|
40
|
-
assert_equal(File.absolute_path(__FILE__), image.source_path)
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
it "doesn't add an image twice" do
|
45
|
-
data = 'test'
|
46
|
-
image = @doc.utils.add_image(data)
|
47
|
-
image1 = @doc.utils.add_image(data)
|
48
|
-
assert_same(image, image1)
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
it "fails if the needed image loader can't be resolved" do
|
53
|
-
begin
|
54
|
-
HexaPDF::GlobalConfiguration['image_loader'].unshift('SomeUnknownConstantHere')
|
55
|
-
exp = assert_raises(HexaPDF::Error) { @doc.utils.add_image(StringIO.new('test')) }
|
56
|
-
assert_match(/image loader from configuration/, exp.message)
|
57
|
-
ensure
|
58
|
-
HexaPDF::GlobalConfiguration['image_loader'].shift
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
it "fails if no image loader is found" do
|
63
|
-
exp = assert_raises(HexaPDF::Error) { @doc.utils.add_image(StringIO.new('test')) }
|
64
|
-
assert_match(/suitable image loader/, exp.message)
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
describe "each" do
|
69
|
-
it "iterates over all non-mask images" do
|
70
|
-
images = []
|
71
|
-
images << @doc.add(Subtype: :Image)
|
72
|
-
images << @doc.add(Subtype: :Image, Mask: [5, 6])
|
73
|
-
images << @doc.add(Subtype: :Image, Mask: @doc.add(Subtype: :Image))
|
74
|
-
images << @doc.add(Subtype: :Image, SMask: @doc.add(Subtype: :Image))
|
75
|
-
assert_equal(images.sort, @doc.utils.each_image.to_a.sort)
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
|
81
|
-
describe HexaPDF::DocumentUtils::Files do
|
82
|
-
before do
|
83
|
-
@doc = HexaPDF::Document.new
|
84
|
-
@data = "embed-test"
|
85
|
-
@file = Tempfile.new('file-embed-test')
|
86
|
-
@file.write(@data)
|
87
|
-
@file.close
|
88
|
-
end
|
89
|
-
|
90
|
-
after do
|
91
|
-
@file.unlink
|
92
|
-
end
|
93
|
-
|
94
|
-
describe "add_file" do
|
95
|
-
it "adds a file using a filename and embeds it" do
|
96
|
-
spec = @doc.utils.add_file(@file.path)
|
97
|
-
assert_equal(File.basename(@file.path), spec.path)
|
98
|
-
assert_equal(@data, spec.embedded_file_stream.stream)
|
99
|
-
end
|
100
|
-
|
101
|
-
it "adds a reference to a file" do
|
102
|
-
spec = @doc.utils.add_file(@file.path, embed: false)
|
103
|
-
assert_equal(File.basename(@file.path), spec.path)
|
104
|
-
refute(spec.embedded_file?)
|
105
|
-
end
|
106
|
-
|
107
|
-
it "adds a file using an IO" do
|
108
|
-
@file.open
|
109
|
-
spec = @doc.utils.add_file(@file, name: 'test', embed: false)
|
110
|
-
assert_equal('test', spec.path)
|
111
|
-
assert_equal(@data, spec.embedded_file_stream.stream)
|
112
|
-
end
|
113
|
-
|
114
|
-
it "optionally sets the description of the file" do
|
115
|
-
spec = @doc.utils.add_file(@file.path, description: 'Some file')
|
116
|
-
assert_equal('Some file', spec[:Desc])
|
117
|
-
end
|
118
|
-
|
119
|
-
it "requires the name argument when given an IO object" do
|
120
|
-
assert_raises(ArgumentError) { @doc.utils.add_file(StringIO.new) }
|
121
|
-
end
|
122
|
-
end
|
123
|
-
|
124
|
-
describe "each_file" do
|
125
|
-
it "iterates only over named embedded files and file annotations if search=false" do
|
126
|
-
@doc.add(Type: :Filespec)
|
127
|
-
spec1 = @doc.utils.add_file(__FILE__)
|
128
|
-
spec2 = @doc.add(Type: :Filespec)
|
129
|
-
@doc.pages.add_page[:Annots] = [
|
130
|
-
{Subtype: :FileAttachment, FS: HexaPDF::Reference.new(spec1.oid, spec1.gen)},
|
131
|
-
{Subtype: :FileAttachment, FS: spec2},
|
132
|
-
{},
|
133
|
-
]
|
134
|
-
assert_equal([spec1, spec2], @doc.utils.each_file.to_a)
|
135
|
-
end
|
136
|
-
|
137
|
-
it "iterates over all file specifications of the document if search=true" do
|
138
|
-
specs = []
|
139
|
-
specs << @doc.add(Type: :Filespec)
|
140
|
-
specs << @doc.add(Type: :Filespec)
|
141
|
-
assert_equal(specs, @doc.utils.each_file(search: true).to_a)
|
142
|
-
end
|
143
|
-
end
|
144
|
-
end
|