hexapdf 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (115) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +56 -0
  3. data/CONTRIBUTERS +1 -1
  4. data/Rakefile +3 -3
  5. data/VERSION +1 -1
  6. data/examples/arc.rb +1 -1
  7. data/examples/graphics.rb +1 -1
  8. data/examples/hello_world.rb +1 -1
  9. data/examples/merging.rb +1 -1
  10. data/examples/show_char_bboxes.rb +1 -1
  11. data/examples/standard_pdf_fonts.rb +1 -1
  12. data/examples/truetype.rb +1 -1
  13. data/lib/hexapdf/cli.rb +14 -7
  14. data/lib/hexapdf/cli/extract.rb +1 -1
  15. data/lib/hexapdf/cli/info.rb +2 -2
  16. data/lib/hexapdf/cli/inspect.rb +4 -4
  17. data/lib/hexapdf/cli/modify.rb +151 -51
  18. data/lib/hexapdf/configuration.rb +1 -1
  19. data/lib/hexapdf/content/canvas.rb +1 -1
  20. data/lib/hexapdf/content/processor.rb +1 -1
  21. data/lib/hexapdf/dictionary.rb +6 -19
  22. data/lib/hexapdf/dictionary_fields.rb +1 -1
  23. data/lib/hexapdf/document.rb +23 -16
  24. data/lib/hexapdf/document/files.rb +130 -0
  25. data/lib/hexapdf/{font_utils.rb → document/fonts.rb} +40 -38
  26. data/lib/hexapdf/document/images.rb +117 -0
  27. data/lib/hexapdf/document/pages.rb +125 -0
  28. data/lib/hexapdf/encryption/aes.rb +1 -1
  29. data/lib/hexapdf/encryption/ruby_aes.rb +10 -10
  30. data/lib/hexapdf/encryption/standard_security_handler.rb +11 -8
  31. data/lib/hexapdf/filter/ascii85_decode.rb +1 -1
  32. data/lib/hexapdf/filter/ascii_hex_decode.rb +1 -6
  33. data/lib/hexapdf/font/cmap/writer.rb +5 -7
  34. data/lib/hexapdf/font/true_type.rb +4 -1
  35. data/lib/hexapdf/font/true_type/font.rb +8 -16
  36. data/lib/hexapdf/font/true_type/table.rb +5 -16
  37. data/lib/hexapdf/font/true_type/table/cmap.rb +2 -7
  38. data/lib/hexapdf/font/true_type/table/cmap_subtable.rb +2 -6
  39. data/lib/hexapdf/font/true_type/table/directory.rb +0 -5
  40. data/lib/hexapdf/font/true_type/table/glyf.rb +3 -11
  41. data/lib/hexapdf/font/true_type/table/head.rb +0 -12
  42. data/lib/hexapdf/font/true_type/table/hhea.rb +0 -7
  43. data/lib/hexapdf/font/true_type/table/hmtx.rb +1 -5
  44. data/lib/hexapdf/font/true_type/table/loca.rb +0 -4
  45. data/lib/hexapdf/font/true_type/table/maxp.rb +0 -8
  46. data/lib/hexapdf/font/true_type/table/name.rb +3 -17
  47. data/lib/hexapdf/font/true_type/table/os2.rb +0 -14
  48. data/lib/hexapdf/font/true_type/table/post.rb +0 -8
  49. data/lib/hexapdf/font/true_type_wrapper.rb +1 -1
  50. data/lib/hexapdf/font/type1.rb +2 -2
  51. data/lib/hexapdf/font/type1/font.rb +2 -1
  52. data/lib/hexapdf/font/type1/font_metrics.rb +10 -1
  53. data/lib/hexapdf/font/type1_wrapper.rb +2 -1
  54. data/lib/hexapdf/font_loader/from_configuration.rb +1 -1
  55. data/lib/hexapdf/font_loader/standard14.rb +1 -1
  56. data/lib/hexapdf/image_loader/jpeg.rb +1 -1
  57. data/lib/hexapdf/image_loader/pdf.rb +1 -1
  58. data/lib/hexapdf/image_loader/png.rb +2 -2
  59. data/lib/hexapdf/object.rb +18 -5
  60. data/lib/hexapdf/rectangle.rb +8 -1
  61. data/lib/hexapdf/revisions.rb +4 -2
  62. data/lib/hexapdf/serializer.rb +3 -3
  63. data/lib/hexapdf/stream.rb +3 -2
  64. data/lib/hexapdf/task/dereference.rb +4 -5
  65. data/lib/hexapdf/task/optimize.rb +6 -3
  66. data/lib/hexapdf/tokenizer.rb +3 -3
  67. data/lib/hexapdf/type/file_specification.rb +2 -2
  68. data/lib/hexapdf/type/form.rb +19 -0
  69. data/lib/hexapdf/type/page.rb +21 -6
  70. data/lib/hexapdf/type/page_tree_node.rb +27 -34
  71. data/lib/hexapdf/utils/bit_stream.rb +1 -1
  72. data/lib/hexapdf/utils/pdf_doc_encoding.rb +1 -1
  73. data/lib/hexapdf/version.rb +1 -1
  74. data/man/man1/hexapdf.1 +259 -187
  75. data/test/hexapdf/content/graphic_object/test_arc.rb +1 -1
  76. data/test/hexapdf/content/graphic_object/test_endpoint_arc.rb +1 -1
  77. data/test/hexapdf/content/graphic_object/test_solid_arc.rb +1 -1
  78. data/test/hexapdf/content/test_canvas.rb +1 -1
  79. data/test/hexapdf/document/test_files.rb +71 -0
  80. data/test/hexapdf/{test_font_utils.rb → document/test_fonts.rb} +1 -2
  81. data/test/hexapdf/document/test_images.rb +78 -0
  82. data/test/hexapdf/document/test_pages.rb +114 -0
  83. data/test/hexapdf/encryption/test_standard_security_handler.rb +26 -5
  84. data/test/hexapdf/font/test_true_type_wrapper.rb +1 -1
  85. data/test/hexapdf/font/true_type/common.rb +0 -4
  86. data/test/hexapdf/font/true_type/table/test_cmap.rb +0 -6
  87. data/test/hexapdf/font/true_type/table/test_directory.rb +0 -5
  88. data/test/hexapdf/font/true_type/table/test_glyf.rb +5 -8
  89. data/test/hexapdf/font/true_type/table/test_head.rb +0 -20
  90. data/test/hexapdf/font/true_type/table/test_hhea.rb +0 -7
  91. data/test/hexapdf/font/true_type/table/test_hmtx.rb +2 -7
  92. data/test/hexapdf/font/true_type/table/test_loca.rb +4 -8
  93. data/test/hexapdf/font/true_type/table/test_maxp.rb +0 -7
  94. data/test/hexapdf/font/true_type/table/test_name.rb +0 -19
  95. data/test/hexapdf/font/true_type/table/test_os2.rb +0 -8
  96. data/test/hexapdf/font/true_type/table/test_post.rb +0 -13
  97. data/test/hexapdf/font/true_type/test_font.rb +14 -38
  98. data/test/hexapdf/font/true_type/test_table.rb +0 -9
  99. data/test/hexapdf/font/type1/test_font_metrics.rb +22 -0
  100. data/test/hexapdf/task/test_dereference.rb +5 -1
  101. data/test/hexapdf/task/test_optimize.rb +1 -1
  102. data/test/hexapdf/test_dictionary.rb +4 -0
  103. data/test/hexapdf/test_document.rb +0 -7
  104. data/test/hexapdf/test_importer.rb +4 -4
  105. data/test/hexapdf/test_object.rb +31 -9
  106. data/test/hexapdf/test_rectangle.rb +18 -0
  107. data/test/hexapdf/test_revisions.rb +7 -0
  108. data/test/hexapdf/test_serializer.rb +6 -0
  109. data/test/hexapdf/test_writer.rb +2 -2
  110. data/test/hexapdf/type/test_form.rb +12 -0
  111. data/test/hexapdf/type/test_page.rb +39 -20
  112. data/test/hexapdf/type/test_page_tree_node.rb +28 -21
  113. metadata +21 -9
  114. data/lib/hexapdf/document_utils.rb +0 -209
  115. 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