origami-docspring 2.2.0 → 2.3.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.
Files changed (118) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +18 -0
  3. data/examples/attachments/attachment.rb +7 -8
  4. data/examples/attachments/nested_document.rb +6 -5
  5. data/examples/encryption/encryption.rb +5 -4
  6. data/examples/events/events.rb +7 -6
  7. data/examples/flash/flash.rb +10 -9
  8. data/examples/forms/javascript.rb +14 -13
  9. data/examples/forms/xfa.rb +67 -66
  10. data/examples/javascript/hello_world.rb +6 -5
  11. data/examples/javascript/js_emulation.rb +26 -26
  12. data/examples/loop/goto.rb +12 -11
  13. data/examples/loop/named.rb +17 -16
  14. data/examples/signature/signature.rb +11 -11
  15. data/examples/uri/javascript.rb +25 -24
  16. data/examples/uri/open-uri.rb +5 -4
  17. data/examples/uri/submitform.rb +11 -10
  18. data/lib/origami/3d.rb +330 -334
  19. data/lib/origami/acroform.rb +267 -268
  20. data/lib/origami/actions.rb +266 -278
  21. data/lib/origami/annotations.rb +659 -670
  22. data/lib/origami/array.rb +192 -196
  23. data/lib/origami/boolean.rb +66 -70
  24. data/lib/origami/catalog.rb +360 -363
  25. data/lib/origami/collections.rb +132 -133
  26. data/lib/origami/compound.rb +125 -129
  27. data/lib/origami/destinations.rb +226 -237
  28. data/lib/origami/dictionary.rb +155 -154
  29. data/lib/origami/encryption.rb +967 -923
  30. data/lib/origami/extensions/fdf.rb +270 -275
  31. data/lib/origami/extensions/ppklite.rb +323 -328
  32. data/lib/origami/filespec.rb +170 -173
  33. data/lib/origami/filters/ascii.rb +162 -167
  34. data/lib/origami/filters/ccitt/tables.rb +248 -252
  35. data/lib/origami/filters/ccitt.rb +309 -312
  36. data/lib/origami/filters/crypt.rb +31 -34
  37. data/lib/origami/filters/dct.rb +47 -50
  38. data/lib/origami/filters/flate.rb +57 -60
  39. data/lib/origami/filters/jbig2.rb +50 -53
  40. data/lib/origami/filters/jpx.rb +40 -43
  41. data/lib/origami/filters/lzw.rb +151 -155
  42. data/lib/origami/filters/predictors.rb +250 -255
  43. data/lib/origami/filters/runlength.rb +111 -115
  44. data/lib/origami/filters.rb +319 -325
  45. data/lib/origami/font.rb +173 -177
  46. data/lib/origami/functions.rb +62 -66
  47. data/lib/origami/graphics/colors.rb +203 -208
  48. data/lib/origami/graphics/instruction.rb +79 -81
  49. data/lib/origami/graphics/path.rb +141 -144
  50. data/lib/origami/graphics/patterns.rb +156 -160
  51. data/lib/origami/graphics/render.rb +51 -47
  52. data/lib/origami/graphics/state.rb +144 -142
  53. data/lib/origami/graphics/text.rb +185 -188
  54. data/lib/origami/graphics/xobject.rb +818 -804
  55. data/lib/origami/graphics.rb +25 -26
  56. data/lib/origami/header.rb +63 -65
  57. data/lib/origami/javascript.rb +718 -651
  58. data/lib/origami/linearization.rb +284 -285
  59. data/lib/origami/metadata.rb +156 -135
  60. data/lib/origami/name.rb +98 -100
  61. data/lib/origami/null.rb +49 -51
  62. data/lib/origami/numeric.rb +133 -135
  63. data/lib/origami/obfuscation.rb +180 -182
  64. data/lib/origami/object.rb +634 -631
  65. data/lib/origami/optionalcontent.rb +147 -149
  66. data/lib/origami/outline.rb +46 -48
  67. data/lib/origami/outputintents.rb +76 -77
  68. data/lib/origami/page.rb +637 -596
  69. data/lib/origami/parser.rb +214 -221
  70. data/lib/origami/parsers/fdf.rb +44 -45
  71. data/lib/origami/parsers/pdf/lazy.rb +147 -154
  72. data/lib/origami/parsers/pdf/linear.rb +104 -109
  73. data/lib/origami/parsers/pdf.rb +109 -107
  74. data/lib/origami/parsers/ppklite.rb +44 -46
  75. data/lib/origami/pdf.rb +886 -896
  76. data/lib/origami/reference.rb +116 -120
  77. data/lib/origami/signature.rb +617 -625
  78. data/lib/origami/stream.rb +560 -558
  79. data/lib/origami/string.rb +366 -368
  80. data/lib/origami/template/patterns.rb +50 -52
  81. data/lib/origami/template/widgets.rb +111 -114
  82. data/lib/origami/trailer.rb +153 -157
  83. data/lib/origami/tree.rb +55 -57
  84. data/lib/origami/version.rb +19 -19
  85. data/lib/origami/webcapture.rb +87 -90
  86. data/lib/origami/xfa/config.rb +409 -414
  87. data/lib/origami/xfa/connectionset.rb +113 -117
  88. data/lib/origami/xfa/datasets.rb +38 -42
  89. data/lib/origami/xfa/localeset.rb +33 -37
  90. data/lib/origami/xfa/package.rb +49 -52
  91. data/lib/origami/xfa/pdf.rb +54 -59
  92. data/lib/origami/xfa/signature.rb +33 -37
  93. data/lib/origami/xfa/sourceset.rb +34 -38
  94. data/lib/origami/xfa/stylesheet.rb +35 -39
  95. data/lib/origami/xfa/template.rb +1630 -1634
  96. data/lib/origami/xfa/xdc.rb +33 -37
  97. data/lib/origami/xfa/xfa.rb +132 -123
  98. data/lib/origami/xfa/xfdf.rb +34 -38
  99. data/lib/origami/xfa/xmpmeta.rb +34 -38
  100. data/lib/origami/xfa.rb +50 -53
  101. data/lib/origami/xreftable.rb +462 -462
  102. data/lib/origami.rb +37 -38
  103. data/test/test_actions.rb +22 -20
  104. data/test/test_annotations.rb +54 -52
  105. data/test/test_forms.rb +23 -21
  106. data/test/test_native_types.rb +82 -78
  107. data/test/test_object_tree.rb +25 -24
  108. data/test/test_pages.rb +43 -41
  109. data/test/test_pdf.rb +2 -0
  110. data/test/test_pdf_attachment.rb +23 -21
  111. data/test/test_pdf_create.rb +16 -15
  112. data/test/test_pdf_encrypt.rb +69 -66
  113. data/test/test_pdf_parse.rb +131 -129
  114. data/test/test_pdf_parse_lazy.rb +53 -53
  115. data/test/test_pdf_sign.rb +67 -67
  116. data/test/test_streams.rb +145 -143
  117. data/test/test_xrefs.rb +46 -45
  118. metadata +64 -8
data/lib/origami.rb CHANGED
@@ -1,46 +1,45 @@
1
- =begin
2
-
3
- This file is part of Origami, PDF manipulation framework for Ruby
4
- Copyright (C) 2016 Guillaume Delugré.
5
-
6
- Origami is free software: you can redistribute it and/or modify
7
- it under the terms of the GNU Lesser General Public License as published by
8
- the Free Software Foundation, either version 3 of the License, or
9
- (at your option) any later version.
10
-
11
- Origami is distributed in the hope that it will be useful,
12
- but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
- GNU Lesser General Public License for more details.
15
-
16
- You should have received a copy of the GNU Lesser General Public License
17
- along with Origami. If not, see <http://www.gnu.org/licenses/>.
18
-
19
- =end
1
+ # frozen_string_literal: true
2
+
3
+ #
4
+ # This file is part of Origami, PDF manipulation framework for Ruby
5
+ # Copyright (C) 2016 Guillaume Delugré.
6
+ #
7
+ # Origami is free software: you can redistribute it and/or modify
8
+ # it under the terms of the GNU Lesser General Public License as published by
9
+ # the Free Software Foundation, either version 3 of the License, or
10
+ # (at your option) any later version.
11
+ #
12
+ # Origami is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ # GNU Lesser General Public License for more details.
16
+ #
17
+ # You should have received a copy of the GNU Lesser General Public License
18
+ # along with Origami. If not, see <http://www.gnu.org/licenses/>.
19
+ #
20
20
 
21
21
  module Origami
22
-
23
- #
24
- # Common Exception class for Origami errors.
25
- #
26
- class Error < StandardError
27
- end
28
-
29
- #
30
- # Global options for Origami.
31
- #
32
- OPTIONS =
22
+ #
23
+ # Common Exception class for Origami errors.
24
+ #
25
+ class Error < StandardError
26
+ end
27
+
28
+ #
29
+ # Global options for Origami.
30
+ #
31
+ OPTIONS =
33
32
  {
34
- enable_type_checking: true, # set to false to disable type consistency checks during compilation.
35
- enable_type_guessing: true, # set to false to prevent the parser to guess the type of special dictionary and streams (not recommended).
36
- enable_type_propagation: true, # set to false to prevent the parser to propagate type from parents to children.
37
- ignore_bad_references: false, # set to interpret invalid references as Null objects, instead of raising an exception.
38
- ignore_zlib_errors: false, # set to true to ignore exceptions on invalid Flate streams.
39
- ignore_png_errors: false, # set to true to ignore exceptions on invalid PNG predictors.
33
+ enable_type_checking: true, # set to false to disable type consistency checks during compilation.
34
+ enable_type_guessing: true, # set to false to prevent the parser to guess the type of special dictionary and streams (not recommended).
35
+ enable_type_propagation: true, # set to false to prevent the parser to propagate type from parents to children.
36
+ ignore_bad_references: false, # set to interpret invalid references as Null objects, instead of raising an exception.
37
+ ignore_zlib_errors: false, # set to true to ignore exceptions on invalid Flate streams.
38
+ ignore_png_errors: false, # set to true to ignore exceptions on invalid PNG predictors.
40
39
  }
41
40
 
42
- autoload :FDF, 'origami/extensions/fdf'
43
- autoload :PPKLite, 'origami/extensions/ppklite'
41
+ autoload :FDF, 'origami/extensions/fdf'
42
+ autoload :PPKLite, 'origami/extensions/ppklite'
44
43
  end
45
44
 
46
45
  require 'origami/version'
data/test/test_actions.rb CHANGED
@@ -1,27 +1,29 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'minitest/autorun'
2
4
 
3
- class TestActions < MiniTest::Test
4
- def setup
5
- @target = PDF.new
6
- @page = Page.new
7
- @action = Action::JavaScript "app.alert(null);"
8
- end
5
+ class TestActions < Minitest::Test
6
+ def setup
7
+ @target = PDF.new
8
+ @page = Page.new
9
+ @action = Action::JavaScript "app.alert(null);"
10
+ end
9
11
 
10
- def test_pdf_actions
11
- @target.onDocumentOpen @action
12
- @target.onDocumentClose @action
13
- @target.onDocumentPrint @action
12
+ def test_pdf_actions
13
+ @target.onDocumentOpen @action
14
+ @target.onDocumentClose @action
15
+ @target.onDocumentPrint @action
14
16
 
15
- assert_equal @target.Catalog.OpenAction, @action
16
- assert_equal @target.Catalog.AA.WC, @action
17
- assert_equal @target.Catalog.AA.WP, @action
18
- end
17
+ assert_equal @target.Catalog.OpenAction, @action
18
+ assert_equal @target.Catalog.AA.WC, @action
19
+ assert_equal @target.Catalog.AA.WP, @action
20
+ end
19
21
 
20
- def test_page_actions
21
- @page.onOpen @action
22
- @page.onClose @action
22
+ def test_page_actions
23
+ @page.onOpen @action
24
+ @page.onClose @action
23
25
 
24
- assert_equal @page.AA.O, @action
25
- assert_equal @page.AA.C, @action
26
- end
26
+ assert_equal @page.AA.O, @action
27
+ assert_equal @page.AA.C, @action
28
+ end
27
29
  end
@@ -1,68 +1,70 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'minitest/autorun'
2
4
  require 'stringio'
3
5
 
4
6
  class TestAnnotations < Minitest::Test
5
- def setup
6
- @target = PDF.new
7
- @page = Page.new
8
- @action = Action::JavaScript["app.alert(null);"]
9
- @output = StringIO.new
7
+ def setup
8
+ @target = PDF.new
9
+ @page = Page.new
10
+ @action = Action::JavaScript["app.alert(null);"]
11
+ @output = StringIO.new
10
12
 
11
- @types = [
12
- Annotation::Circle, Annotation::Square,
13
- Annotation::Text, Annotation::Link,
14
- Annotation::FileAttachment, Annotation::Screen,
15
- Annotation::Sound, Annotation::Widget::CheckBox,
16
- Annotation::Widget::Radio, Annotation::Widget::Text,
17
- Annotation::Widget::ComboBox, Annotation::Widget::ListBox,
18
- Annotation::Widget::Signature
19
- ]
20
- end
13
+ @types = [
14
+ Annotation::Circle, Annotation::Square,
15
+ Annotation::Text, Annotation::Link,
16
+ Annotation::FileAttachment, Annotation::Screen,
17
+ Annotation::Sound, Annotation::Widget::CheckBox,
18
+ Annotation::Widget::Radio, Annotation::Widget::Text,
19
+ Annotation::Widget::ComboBox, Annotation::Widget::ListBox,
20
+ Annotation::Widget::Signature
21
+ ]
22
+ end
21
23
 
22
- def test_annotations
23
- @target.append_page @page
24
+ def test_annotations
25
+ @target.append_page @page
24
26
 
25
- annotations = @types.map(&:new)
26
- annotations.each do |annotation|
27
- @page.add_annotation(annotation)
28
- end
27
+ annotations = @types.map(&:new)
28
+ annotations.each do |annotation|
29
+ @page.add_annotation(annotation)
30
+ end
29
31
 
30
- @page.each_annotation do |annotation|
31
- assert_kind_of Annotation, annotation
32
+ @page.each_annotation do |annotation|
33
+ assert_kind_of Annotation, annotation
32
34
 
33
- assert annotations.include?(annotation)
34
- end
35
+ assert annotations.include?(annotation)
36
+ end
35
37
 
36
- assert_equal @page.annotations.size, annotations.size
38
+ assert_equal @page.annotations.size, annotations.size
37
39
 
38
- @target.save(@output)
39
- end
40
+ @target.save(@output)
41
+ end
40
42
 
41
- def test_annotation_actions
42
- screen = Annotation::Screen.new
43
+ def test_annotation_actions
44
+ screen = Annotation::Screen.new
43
45
 
44
- @page.add_annotation screen
46
+ @page.add_annotation screen
45
47
 
46
- screen.onMouseOver @action
47
- screen.onMouseOut @action
48
- screen.onMouseDown @action
49
- screen.onMouseUp @action
50
- screen.onFocus @action
51
- screen.onBlur @action
52
- screen.onPageOpen @action
53
- screen.onPageClose @action
54
- screen.onPageVisible @action
55
- screen.onPageInvisible @action
48
+ screen.onMouseOver @action
49
+ screen.onMouseOut @action
50
+ screen.onMouseDown @action
51
+ screen.onMouseUp @action
52
+ screen.onFocus @action
53
+ screen.onBlur @action
54
+ screen.onPageOpen @action
55
+ screen.onPageClose @action
56
+ screen.onPageVisible @action
57
+ screen.onPageInvisible @action
56
58
 
57
- assert_equal screen.AA.E, @action
58
- assert_equal screen.AA.X, @action
59
- assert_equal screen.AA.D, @action
60
- assert_equal screen.AA.U, @action
61
- assert_equal screen.AA.Fo, @action
62
- assert_equal screen.AA.Bl, @action
63
- assert_equal screen.AA.PO, @action
64
- assert_equal screen.AA.PC, @action
65
- assert_equal screen.AA.PV, @action
66
- assert_equal screen.AA.PI, @action
67
- end
59
+ assert_equal screen.AA.E, @action
60
+ assert_equal screen.AA.X, @action
61
+ assert_equal screen.AA.D, @action
62
+ assert_equal screen.AA.U, @action
63
+ assert_equal screen.AA.Fo, @action
64
+ assert_equal screen.AA.Bl, @action
65
+ assert_equal screen.AA.PO, @action
66
+ assert_equal screen.AA.PC, @action
67
+ assert_equal screen.AA.PV, @action
68
+ assert_equal screen.AA.PI, @action
69
+ end
68
70
  end
data/test/test_forms.rb CHANGED
@@ -1,30 +1,32 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'minitest/autorun'
2
4
 
3
5
  class TestForms < Minitest::Test
4
- def setup
5
- @target = PDF.new
6
- @target.append_page
7
- end
6
+ def setup
7
+ @target = PDF.new
8
+ @target.append_page
9
+ end
8
10
 
9
- def test_create_acroform
10
- fields = [
11
- Annotation::Widget::Text.new.set_name('text'),
12
- Annotation::Widget::PushButton.new.set_name('button')
13
- ]
11
+ def test_create_acroform
12
+ fields = [
13
+ Annotation::Widget::Text.new.set_name('text'),
14
+ Annotation::Widget::PushButton.new.set_name('button')
15
+ ]
14
16
 
15
- @target.create_form(*fields)
17
+ @target.create_form(*fields)
16
18
 
17
- assert @target.form?
18
- assert_kind_of InteractiveForm, @target.Catalog.AcroForm
19
- assert_equal @target.fields.length, fields.length
19
+ assert @target.form?
20
+ assert_kind_of InteractiveForm, @target.Catalog.AcroForm
21
+ assert_equal @target.fields.length, fields.length
20
22
 
21
- @target.each_field do |field|
22
- assert_kind_of Field, field
23
- assert %w{text button}.include?(field.name)
24
- end
25
-
26
- assert_nil @target.get_field('not_existent_field')
27
- assert_kind_of Field, @target.get_field('button')
28
- assert_kind_of Field, @target.get_field('text')
23
+ @target.each_field do |field|
24
+ assert_kind_of Field, field
25
+ assert %w[text button].include?(field.name)
29
26
  end
27
+
28
+ assert_nil @target.get_field('not_existent_field')
29
+ assert_kind_of Field, @target.get_field('button')
30
+ assert_kind_of Field, @target.get_field('text')
31
+ end
30
32
  end
@@ -1,83 +1,87 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'minitest/autorun'
2
4
  require 'strscan'
5
+ require 'origami'
3
6
 
4
7
  class TestPDFCreate < Minitest::Test
5
- using Origami::TypeConversion
6
-
7
- def test_type_string
8
- assert_kind_of Origami::String, "".to_o
9
- assert_kind_of ::String, "".to_o.value
10
-
11
- assert_equal "<616263>", HexaString.new("abc").to_s
12
- assert_equal "(test)", LiteralString.new("test").to_s
13
- assert_equal '(\(\(\(\)\)\)\))', LiteralString.new("((())))").to_s
14
- assert_equal "abc", "abc".to_s.to_o
15
- end
16
-
17
- def test_string_encoding
18
- str = LiteralString.new("test")
19
-
20
- assert_equal Origami::String::Encoding::PDFDocEncoding, str.encoding
21
- assert_equal "UTF-8", str.to_utf8.encoding.to_s
22
-
23
- assert_equal "\xFE\xFF\x00t\x00e\x00s\x00t".b, str.to_utf16be
24
- assert_equal Origami::String::Encoding::UTF16BE, str.to_utf16be.to_o.encoding
25
- assert_equal str, str.to_utf16be.to_o.to_pdfdoc
26
- end
27
-
28
- def test_type_null
29
- assert_instance_of Null, nil.to_o
30
- assert_nil Null.new.value
31
- assert_equal Null.new.to_s, "null"
32
- end
33
-
34
- def test_type_name
35
- assert_instance_of Name, :test.to_o
36
- assert_instance_of Symbol, :test.to_o.value
37
-
38
- assert_equal "/test", Name.new(:test).to_s
39
- assert_equal "/#20#23#09#0d#0a#00#5b#5d#3c#3e#28#29#25#2f", Name.new(" #\t\r\n\0[]<>()%/").to_s
40
- assert_equal " #\t\r\n\0[]<>()%/", Name.new(" #\t\r\n\0[]<>()%/").value.to_s
41
- end
42
-
43
- def test_type_boolean
44
- assert_instance_of Boolean, true.to_o
45
- assert_instance_of Boolean, false.to_o
46
- assert Boolean.new(true).value
47
- refute Boolean.new(false).value
48
- assert_equal "true", true.to_o.to_s
49
- assert_equal "false", false.to_o.to_s
50
- end
51
-
52
- def test_type_numeric
53
- assert_instance_of Origami::Real, Math::PI.to_o
54
- assert_instance_of Origami::Integer, 1.to_o
55
-
56
- assert_equal "1.8", Origami::Real.new(1.8).to_s
57
- assert_equal "100", Origami::Integer.new(100).to_s
58
- assert_equal 1.8, 1.8.to_o.value
59
- assert_equal 100, 100.to_o.value
60
- end
61
-
62
- def test_type_array
63
- array = [1, "a", [], {}, :test, nil, true, 3.14]
64
-
65
- assert_instance_of Origami::Array, [].to_o
66
- assert_instance_of ::Array, [].to_o.value
67
-
68
- assert_equal array, array.to_o.value
69
- assert_equal "[1 (a) [] <<>> /test null true 3.14]", array.to_o.to_s
70
- assert array.to_o.all? {|o| o.is_a? Origami::Object}
71
- end
72
-
73
- def test_type_dictionary
74
- assert_instance_of Origami::Dictionary, {}.to_o
75
- assert_instance_of Hash, {}.to_o.value
76
-
77
- dict = {a: 1, b: false, c: nil, d: "abc", e: :abc, f: []}
78
-
79
- assert_equal "<</a 1/b false/c null/d (abc)/e /abc/f []>>", dict.to_o.to_s(indent: 0)
80
- assert_equal dict, dict.to_o.value
81
- assert dict.to_o.all?{|k,v| k.is_a?(Name) and v.is_a?(Origami::Object)}
82
- end
8
+ include Origami
9
+ using Origami::TypeConversion
10
+
11
+ def test_type_string
12
+ assert_kind_of Origami::String, "".to_o
13
+ assert_kind_of ::String, "".to_o.value
14
+
15
+ assert_equal "<616263>", HexaString.new("abc").to_s
16
+ assert_equal "(test)", LiteralString.new("test").to_s
17
+ assert_equal '(\(\(\(\)\)\)\))', LiteralString.new("((())))").to_s
18
+ assert_equal "abc", "abc".to_o
19
+ end
20
+
21
+ def test_string_encoding
22
+ str = LiteralString.new("test")
23
+
24
+ assert_equal Origami::String::Encoding::PDFDocEncoding, str.encoding
25
+ assert_equal "UTF-8", str.to_utf8.encoding.to_s
26
+
27
+ assert_equal "\xFE\xFF\x00t\x00e\x00s\x00t".b, str.to_utf16be
28
+ assert_equal Origami::String::Encoding::UTF16BE, str.to_utf16be.to_o.encoding
29
+ assert_equal str, str.to_utf16be.to_o.to_pdfdoc
30
+ end
31
+
32
+ def test_type_null
33
+ assert_instance_of Null, nil.to_o
34
+ assert_nil Null.new.value
35
+ assert_equal Null.new.to_s, "null"
36
+ end
37
+
38
+ def test_type_name
39
+ assert_instance_of Name, :test.to_o
40
+ assert_instance_of Symbol, :test.to_o.value
41
+
42
+ assert_equal "/test", Name.new(:test).to_s
43
+ assert_equal "/#20#23#09#0d#0a#00#5b#5d#3c#3e#28#29#25#2f", Name.new(" #\t\r\n\0[]<>()%/").to_s
44
+ assert_equal " #\t\r\n\0[]<>()%/", Name.new(" #\t\r\n\0[]<>()%/").value.to_s
45
+ end
46
+
47
+ def test_type_boolean
48
+ assert_instance_of Boolean, true.to_o
49
+ assert_instance_of Boolean, false.to_o
50
+ assert Boolean.new(true).value
51
+ refute Boolean.new(false).value
52
+ assert_equal "true", true.to_o.to_s
53
+ assert_equal "false", false.to_o.to_s
54
+ end
55
+
56
+ def test_type_numeric
57
+ assert_instance_of Origami::Real, Math::PI.to_o
58
+ assert_instance_of Origami::Integer, 1.to_o
59
+
60
+ assert_equal "1.8", Origami::Real.new(1.8).to_s
61
+ assert_equal "100", Origami::Integer.new(100).to_s
62
+ assert_equal 1.8, 1.8.to_o.value
63
+ assert_equal 100, 100.to_o.value
64
+ end
65
+
66
+ def test_type_array
67
+ array = [1, "a", [], {}, :test, nil, true, 3.14]
68
+
69
+ assert_instance_of Origami::Array, [].to_o
70
+ assert_instance_of ::Array, [].to_o.value
71
+
72
+ assert_equal array, array.to_o.value
73
+ assert_equal "[1 (a) [] <<>> /test null true 3.14]", array.to_o.to_s
74
+ assert array.to_o.all? { |o| o.is_a? Origami::Object }
75
+ end
76
+
77
+ def test_type_dictionary
78
+ assert_instance_of Origami::Dictionary, {}.to_o
79
+ assert_instance_of Hash, {}.to_o.value
80
+
81
+ dict = {a: 1, b: false, c: nil, d: "abc", e: :abc, f: []}
82
+
83
+ assert_equal "<</a 1/b false/c null/d (abc)/e /abc/f []>>", dict.to_o.to_s(indent: 0)
84
+ assert_equal dict, dict.to_o.value
85
+ assert dict.to_o.all? { |k, v| k.is_a?(Name) and v.is_a?(Origami::Object) }
86
+ end
83
87
  end
@@ -1,33 +1,34 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'minitest/autorun'
2
4
  require 'stringio'
3
5
 
4
6
  class TestPDFObjectTree < Minitest::Test
7
+ def setup
8
+ @pdf = PDF.new.append_page
9
+ @contents = ContentStream.new("abc")
10
+ @pdf.pages.first.Contents = @contents
11
+ @pdf.Catalog.Loop = @pdf.Catalog
12
+ @pdf.save StringIO.new
13
+ end
5
14
 
6
- def setup
7
- @pdf = PDF.new.append_page
8
- @contents = ContentStream.new("abc")
9
- @pdf.pages.first.Contents = @contents
10
- @pdf.Catalog.Loop = @pdf.Catalog
11
- @pdf.save StringIO.new
12
- end
13
-
14
- def test_pdf_object_tree
15
- assert_instance_of Catalog, @pdf.Catalog
16
- assert_nil @pdf.Catalog.parent
15
+ def test_pdf_object_tree
16
+ assert_instance_of Catalog, @pdf.Catalog
17
+ assert_nil @pdf.Catalog.parent
17
18
 
18
- @pdf.each_object(recursive: true) do |obj|
19
- assert_kind_of Origami::Object, obj
20
- assert_equal obj.document, @pdf
19
+ @pdf.each_object(recursive: true) do |obj|
20
+ assert_kind_of Origami::Object, obj
21
+ assert_equal obj.document, @pdf
21
22
 
22
- unless obj.indirect?
23
- assert_kind_of Origami::Object, obj.parent
24
- assert_equal obj.parent.document, @pdf
25
- end
26
- end
27
-
28
- enum = @pdf.each_object(recursive: true)
29
- assert_kind_of Enumerator, enum
30
- assert enum.include?(@pdf.Catalog.Pages)
31
- assert enum.include?(@contents.dictionary)
23
+ unless obj.indirect?
24
+ assert_kind_of Origami::Object, obj.parent
25
+ assert_equal obj.parent.document, @pdf
26
+ end
32
27
  end
28
+
29
+ enum = @pdf.each_object(recursive: true)
30
+ assert_kind_of Enumerator, enum
31
+ assert enum.include?(@pdf.Catalog.Pages)
32
+ assert enum.include?(@contents.dictionary)
33
+ end
33
34
  end
data/test/test_pages.rb CHANGED
@@ -1,60 +1,62 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'minitest/autorun'
2
4
  require 'stringio'
3
5
 
4
6
  class TestPages < Minitest::Test
5
- def setup
6
- @target = PDF.new
7
- @output = StringIO.new
8
- end
7
+ def setup
8
+ @target = PDF.new
9
+ @output = StringIO.new
10
+ end
9
11
 
10
- def test_append_page
11
- p1, p2, p3 = Page.new, Page.new, Page.new
12
+ def test_append_page
13
+ p1, p2, p3 = Page.new, Page.new, Page.new
12
14
 
13
- @target.append_page p1
14
- @target.append_page p2
15
- @target.append_page p3
15
+ @target.append_page p1
16
+ @target.append_page p2
17
+ @target.append_page p3
16
18
 
17
- assert_equal @target.pages.count, 3
19
+ assert_equal @target.pages.count, 3
18
20
 
19
- assert_equal @target.get_page(1), p1
20
- assert_equal @target.get_page(2), p2
21
- assert_equal @target.get_page(3), p3
21
+ assert_equal @target.get_page(1), p1
22
+ assert_equal @target.get_page(2), p2
23
+ assert_equal @target.get_page(3), p3
22
24
 
23
- assert_raises(IndexError) { @target.get_page(0) }
24
- assert_raises(IndexError) { @target.get_page(4) }
25
+ assert_raises(IndexError) { @target.get_page(0) }
26
+ assert_raises(IndexError) { @target.get_page(4) }
25
27
 
26
- assert_equal @target.Catalog.Pages, p1.Parent
27
- assert_equal @target.Catalog.Pages, p2.Parent
28
- assert_equal @target.Catalog.Pages, p3.Parent
28
+ assert_equal @target.Catalog.Pages, p1.Parent
29
+ assert_equal @target.Catalog.Pages, p2.Parent
30
+ assert_equal @target.Catalog.Pages, p3.Parent
29
31
 
30
- @target.save(@output)
32
+ @target.save(@output)
31
33
 
32
- assert_equal @target.Catalog.Pages.Count, 3
33
- assert_equal @target.pages, [p1, p2, p3]
34
- assert_equal @target.each_page.to_a, [p1, p2, p3]
35
- end
34
+ assert_equal @target.Catalog.Pages.Count, 3
35
+ assert_equal @target.pages, [p1, p2, p3]
36
+ assert_equal @target.each_page.to_a, [p1, p2, p3]
37
+ end
36
38
 
37
- def test_insert_page
38
- pages = Array.new(10) { Page.new }
39
+ def test_insert_page
40
+ pages = Array.new(10) { Page.new }
39
41
 
40
- pages.each_with_index do |page, index|
41
- @target.insert_page(index + 1, page)
42
- end
42
+ pages.each_with_index do |page, index|
43
+ @target.insert_page(index + 1, page)
44
+ end
43
45
 
44
- assert_equal @target.pages, pages
46
+ assert_equal @target.pages, pages
45
47
 
46
- new_page = Page.new
47
- @target.insert_page(1, new_page)
48
- assert_equal @target.get_page(1), new_page
48
+ new_page = Page.new
49
+ @target.insert_page(1, new_page)
50
+ assert_equal @target.get_page(1), new_page
49
51
 
50
- assert_raises(IndexError) { @target.insert_page(0, Page.new) }
51
- assert_raises(IndexError) { @target.insert_page(1000, Page.new) }
52
- end
52
+ assert_raises(IndexError) { @target.insert_page(0, Page.new) }
53
+ assert_raises(IndexError) { @target.insert_page(1000, Page.new) }
54
+ end
53
55
 
54
- def test_example_write_page
55
- @target.append_page
56
- @target.pages.first.write 'Hello, world!', size: 30
57
- @target.save(@output)
58
- assert_equal @target.Catalog.Pages.Count, 1
59
- end
56
+ def test_example_write_page
57
+ @target.append_page
58
+ @target.pages.first.write 'Hello, world!', size: 30
59
+ @target.save(@output)
60
+ assert_equal @target.Catalog.Pages.Count, 1
61
+ end
60
62
  end
data/test/test_pdf.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'minitest/autorun'
2
4
 
3
5
  $:.unshift File.join(__dir__, "..", "lib")