hexapdf 0.10.0 → 0.11.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (139) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +33 -0
  3. data/CONTRIBUTERS +1 -1
  4. data/Rakefile +35 -50
  5. data/VERSION +1 -1
  6. data/lib/hexapdf/cli.rb +4 -0
  7. data/lib/hexapdf/cli/command.rb +6 -2
  8. data/lib/hexapdf/cli/image2pdf.rb +141 -0
  9. data/lib/hexapdf/cli/info.rb +1 -1
  10. data/lib/hexapdf/cli/inspect.rb +32 -2
  11. data/lib/hexapdf/cli/modify.rb +1 -1
  12. data/lib/hexapdf/cli/optimize.rb +1 -1
  13. data/lib/hexapdf/cli/watermark.rb +130 -0
  14. data/lib/hexapdf/composer.rb +2 -2
  15. data/lib/hexapdf/configuration.rb +7 -1
  16. data/lib/hexapdf/content/canvas.rb +2 -2
  17. data/lib/hexapdf/content/graphic_object/arc.rb +2 -2
  18. data/lib/hexapdf/content/graphic_object/endpoint_arc.rb +2 -2
  19. data/lib/hexapdf/content/graphic_object/geom2d.rb +1 -1
  20. data/lib/hexapdf/content/graphic_object/solid_arc.rb +1 -1
  21. data/lib/hexapdf/dictionary.rb +11 -3
  22. data/lib/hexapdf/dictionary_fields.rb +32 -3
  23. data/lib/hexapdf/document.rb +7 -3
  24. data/lib/hexapdf/document/files.rb +1 -1
  25. data/lib/hexapdf/document/fonts.rb +21 -1
  26. data/lib/hexapdf/document/pages.rb +2 -2
  27. data/lib/hexapdf/encryption/standard_security_handler.rb +2 -2
  28. data/lib/hexapdf/font/cmap/parser.rb +1 -1
  29. data/lib/hexapdf/font/true_type/table/head.rb +2 -2
  30. data/lib/hexapdf/font/true_type/table/os2.rb +4 -4
  31. data/lib/hexapdf/font/true_type_wrapper.rb +16 -16
  32. data/lib/hexapdf/font/type1_wrapper.rb +16 -16
  33. data/lib/hexapdf/font_loader.rb +2 -0
  34. data/lib/hexapdf/font_loader/from_configuration.rb +5 -0
  35. data/lib/hexapdf/font_loader/standard14.rb +5 -0
  36. data/lib/hexapdf/image_loader/png.rb +1 -1
  37. data/lib/hexapdf/layout/box.rb +2 -2
  38. data/lib/hexapdf/layout/image_box.rb +1 -1
  39. data/lib/hexapdf/layout/style.rb +50 -24
  40. data/lib/hexapdf/layout/text_box.rb +1 -1
  41. data/lib/hexapdf/layout/text_fragment.rb +2 -2
  42. data/lib/hexapdf/layout/text_layouter.rb +14 -10
  43. data/lib/hexapdf/name_tree_node.rb +3 -3
  44. data/lib/hexapdf/number_tree_node.rb +3 -3
  45. data/lib/hexapdf/pdf_array.rb +207 -0
  46. data/lib/hexapdf/rectangle.rb +12 -12
  47. data/lib/hexapdf/serializer.rb +1 -1
  48. data/lib/hexapdf/stream.rb +6 -4
  49. data/lib/hexapdf/task/optimize.rb +3 -3
  50. data/lib/hexapdf/type.rb +2 -0
  51. data/lib/hexapdf/type/acro_form.rb +51 -0
  52. data/lib/hexapdf/type/acro_form/field.rb +129 -0
  53. data/lib/hexapdf/type/acro_form/form.rb +124 -0
  54. data/lib/hexapdf/type/action.rb +1 -1
  55. data/lib/hexapdf/type/actions/go_to.rb +1 -1
  56. data/lib/hexapdf/type/actions/go_to_r.rb +1 -1
  57. data/lib/hexapdf/type/actions/launch.rb +1 -1
  58. data/lib/hexapdf/type/annotation.rb +2 -2
  59. data/lib/hexapdf/type/annotations.rb +1 -0
  60. data/lib/hexapdf/type/annotations/link.rb +4 -15
  61. data/lib/hexapdf/type/annotations/markup_annotation.rb +2 -1
  62. data/lib/hexapdf/type/annotations/text.rb +3 -6
  63. data/lib/hexapdf/type/annotations/widget.rb +90 -0
  64. data/lib/hexapdf/type/catalog.rb +12 -9
  65. data/lib/hexapdf/type/cid_font.rb +3 -3
  66. data/lib/hexapdf/type/file_specification.rb +2 -2
  67. data/lib/hexapdf/type/font_descriptor.rb +5 -2
  68. data/lib/hexapdf/type/font_simple.rb +1 -1
  69. data/lib/hexapdf/type/font_type0.rb +1 -1
  70. data/lib/hexapdf/type/font_type3.rb +1 -1
  71. data/lib/hexapdf/type/form.rb +2 -2
  72. data/lib/hexapdf/type/graphics_state_parameter.rb +11 -6
  73. data/lib/hexapdf/type/icon_fit.rb +58 -0
  74. data/lib/hexapdf/type/image.rb +14 -8
  75. data/lib/hexapdf/type/info.rb +2 -1
  76. data/lib/hexapdf/type/page.rb +4 -4
  77. data/lib/hexapdf/type/page_tree_node.rb +3 -7
  78. data/lib/hexapdf/type/resources.rb +1 -1
  79. data/lib/hexapdf/type/trailer.rb +4 -4
  80. data/lib/hexapdf/type/viewer_preferences.rb +7 -4
  81. data/lib/hexapdf/type/xref_stream.rb +2 -2
  82. data/lib/hexapdf/utils/sorted_tree_node.rb +1 -1
  83. data/lib/hexapdf/version.rb +1 -1
  84. data/man/man1/hexapdf.1 +77 -8
  85. data/test/hexapdf/content/test_canvas.rb +2 -2
  86. data/test/hexapdf/content/test_processor.rb +3 -3
  87. data/test/hexapdf/document/test_files.rb +4 -4
  88. data/test/hexapdf/document/test_fonts.rb +13 -1
  89. data/test/hexapdf/document/test_images.rb +6 -6
  90. data/test/hexapdf/document/test_pages.rb +8 -8
  91. data/test/hexapdf/encryption/test_security_handler.rb +7 -7
  92. data/test/hexapdf/encryption/test_standard_security_handler.rb +5 -5
  93. data/test/hexapdf/font/test_true_type_wrapper.rb +2 -2
  94. data/test/hexapdf/font_loader/test_from_configuration.rb +4 -0
  95. data/test/hexapdf/font_loader/test_standard14.rb +10 -0
  96. data/test/hexapdf/image_loader/test_jpeg.rb +1 -1
  97. data/test/hexapdf/image_loader/test_png.rb +3 -3
  98. data/test/hexapdf/layout/test_box.rb +2 -2
  99. data/test/hexapdf/layout/test_frame.rb +1 -1
  100. data/test/hexapdf/layout/test_image_box.rb +1 -1
  101. data/test/hexapdf/layout/test_style.rb +18 -13
  102. data/test/hexapdf/layout/test_text_box.rb +1 -1
  103. data/test/hexapdf/layout/test_text_layouter.rb +11 -6
  104. data/test/hexapdf/task/test_dereference.rb +2 -2
  105. data/test/hexapdf/task/test_optimize.rb +11 -11
  106. data/test/hexapdf/test_composer.rb +1 -1
  107. data/test/hexapdf/test_dictionary.rb +10 -2
  108. data/test/hexapdf/test_dictionary_fields.rb +27 -3
  109. data/test/hexapdf/test_document.rb +16 -15
  110. data/test/hexapdf/test_importer.rb +4 -4
  111. data/test/hexapdf/test_object.rb +1 -1
  112. data/test/hexapdf/test_pdf_array.rb +162 -0
  113. data/test/hexapdf/test_rectangle.rb +3 -5
  114. data/test/hexapdf/test_serializer.rb +1 -1
  115. data/test/hexapdf/test_stream.rb +1 -0
  116. data/test/hexapdf/test_writer.rb +3 -3
  117. data/test/hexapdf/type/acro_form/test_field.rb +85 -0
  118. data/test/hexapdf/type/acro_form/test_form.rb +69 -0
  119. data/test/hexapdf/type/annotations/test_text.rb +2 -6
  120. data/test/hexapdf/type/annotations/test_widget.rb +24 -0
  121. data/test/hexapdf/type/test_annotation.rb +1 -1
  122. data/test/hexapdf/type/test_catalog.rb +1 -1
  123. data/test/hexapdf/type/test_cid_font.rb +3 -3
  124. data/test/hexapdf/type/test_font.rb +2 -2
  125. data/test/hexapdf/type/test_font_descriptor.rb +2 -1
  126. data/test/hexapdf/type/test_font_simple.rb +3 -3
  127. data/test/hexapdf/type/test_font_true_type.rb +6 -6
  128. data/test/hexapdf/type/test_font_type0.rb +5 -5
  129. data/test/hexapdf/type/test_font_type1.rb +8 -8
  130. data/test/hexapdf/type/test_font_type3.rb +4 -4
  131. data/test/hexapdf/type/test_image.rb +16 -12
  132. data/test/hexapdf/type/test_page.rb +11 -11
  133. data/test/hexapdf/type/test_page_tree_node.rb +20 -20
  134. data/test/hexapdf/type/test_resources.rb +6 -6
  135. data/test/hexapdf/type/test_trailer.rb +5 -2
  136. data/test/hexapdf/type/test_xref_stream.rb +1 -0
  137. data/test/hexapdf/utils/test_sorted_tree_node.rb +35 -35
  138. metadata +23 -7
  139. data/test/hexapdf/type/annotations/test_link.rb +0 -19
@@ -0,0 +1,124 @@
1
+ # -*- encoding: utf-8; frozen_string_literal: true -*-
2
+ #
3
+ #--
4
+ # This file is part of HexaPDF.
5
+ #
6
+ # HexaPDF - A Versatile PDF Creation and Manipulation Library For Ruby
7
+ # Copyright (C) 2014-2019 Thomas Leitner
8
+ #
9
+ # HexaPDF is free software: you can redistribute it and/or modify it
10
+ # under the terms of the GNU Affero General Public License version 3 as
11
+ # published by the Free Software Foundation with the addition of the
12
+ # following permission added to Section 15 as permitted in Section 7(a):
13
+ # FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY
14
+ # THOMAS LEITNER, THOMAS LEITNER DISCLAIMS THE WARRANTY OF NON
15
+ # INFRINGEMENT OF THIRD PARTY RIGHTS.
16
+ #
17
+ # HexaPDF is distributed in the hope that it will be useful, but WITHOUT
18
+ # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
19
+ # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
20
+ # License for more details.
21
+ #
22
+ # You should have received a copy of the GNU Affero General Public License
23
+ # along with HexaPDF. If not, see <http://www.gnu.org/licenses/>.
24
+ #
25
+ # The interactive user interfaces in modified source and object code
26
+ # versions of HexaPDF must display Appropriate Legal Notices, as required
27
+ # under Section 5 of the GNU Affero General Public License version 3.
28
+ #
29
+ # In accordance with Section 7(b) of the GNU Affero General Public
30
+ # License, a covered work must retain the producer line in every PDF that
31
+ # is created or manipulated using HexaPDF.
32
+ #
33
+ # If the GNU Affero General Public License doesn't fit your need,
34
+ # commercial licenses are available at <https://gettalong.at/hexapdf/>.
35
+ #++
36
+
37
+ require 'hexapdf/dictionary'
38
+ require 'hexapdf/stream'
39
+ require 'hexapdf/utils/bit_field'
40
+
41
+ module HexaPDF
42
+ module Type
43
+ module AcroForm
44
+
45
+ # Represents the PDF's interactive form dictionary. It is linked from the catalog dictionary
46
+ # via the /AcroForm entry.
47
+ #
48
+ # See: PDF1.7 s12.7.2
49
+ class Form < Dictionary
50
+
51
+ extend Utils::BitField
52
+
53
+ define_type :XXAcroForm
54
+
55
+ define_field :Fields, type: PDFArray, required: true, version: '1.2'
56
+ define_field :NeedAppearances, type: Boolean, default: false
57
+ define_field :SigFlags, type: Integer, version: '1.3'
58
+ define_field :CO, type: PDFArray, version: '1.3'
59
+ define_field :DR, type: :Ressources
60
+ define_field :DA, type: String
61
+ define_field :XFA, type: [Stream, PDFArray], version: '1.5'
62
+
63
+ bit_field(:raw_signature_flags, {signatures_exist: 0, append_only: 1},
64
+ lister: "signature_flags", getter: "signature_flag?", setter: "signature_flag")
65
+
66
+ # Returns an array with all root fields that were found in the PDF document.
67
+ def find_root_fields
68
+ result = []
69
+ document.pages.each do |page|
70
+ page[:Annots].each do |annot|
71
+ if !annot.key?(:Parent) && annot.key?(:FT)
72
+ result << document.wrap(annot, type: :XXAcroFormField)
73
+ elsif annot.key?(:Parent)
74
+ field = annot[:Parent]
75
+ field = field[:Parent] while field[:Parent]
76
+ result << document.wrap(field, type: :XXAcroFormField)
77
+ end
78
+ end
79
+ end
80
+ result
81
+ end
82
+
83
+ # Finds all root fields and sets /Fields appropriately.
84
+ #
85
+ # See: #find_root_fields
86
+ def find_root_fields!
87
+ self[:Fields] = find_root_fields
88
+ end
89
+
90
+ # :call-seq:
91
+ # acroform.each_field(terminal_only: true) {|field| block} -> acroform
92
+ # acroform.each_field(terminal_only: true) -> Enumerator
93
+ #
94
+ # Yields all terminal fields or all fields, depending on the +terminal_only+ argument.
95
+ def each_field(terminal_only: true)
96
+ return to_enum(__method__, terminal_only: terminal_only) unless block_given?
97
+
98
+ process_field = lambda do |field|
99
+ field = document.wrap(field, type: :XXAcroFormField)
100
+ yield(field) if field.terminal_field? || !terminal_only
101
+ field[:Kids].each(&process_field) unless field.terminal_field?
102
+ end
103
+
104
+ self[:Fields]&.each(&process_field)
105
+ self
106
+ end
107
+
108
+ private
109
+
110
+ # Helper method for bit field getter access.
111
+ def raw_signature_flags
112
+ self[:SigFlags]
113
+ end
114
+
115
+ # Helper method for bit field setter access.
116
+ def raw_signature_flags=(value)
117
+ self[:SigFlags] = value
118
+ end
119
+
120
+ end
121
+
122
+ end
123
+ end
124
+ end
@@ -51,7 +51,7 @@ module HexaPDF
51
51
 
52
52
  define_field :Type, type: Symbol, default: type
53
53
  define_field :S, type: Symbol, required: true
54
- define_field :Next, type: [Dictionary, Array], version: '1.2'
54
+ define_field :Next, type: [Dictionary, PDFArray], version: '1.2'
55
55
 
56
56
  end
57
57
 
@@ -46,7 +46,7 @@ module HexaPDF
46
46
  class GoTo < Action
47
47
 
48
48
  define_field :S, type: Symbol, required: true, default: :GoTo
49
- define_field :D, type: [Symbol, PDFByteString, Array], required: true
49
+ define_field :D, type: [Symbol, PDFByteString, PDFArray], required: true
50
50
 
51
51
  end
52
52
 
@@ -47,7 +47,7 @@ module HexaPDF
47
47
 
48
48
  define_field :S, type: Symbol, required: true, default: :GoToR
49
49
  define_field :F, type: :Filespec, required: true
50
- define_field :D, type: [Symbol, PDFByteString, Array], required: true
50
+ define_field :D, type: [Symbol, PDFByteString, PDFArray], required: true
51
51
  define_field :NewWindow, type: Boolean, version: '1.2'
52
52
 
53
53
  end
@@ -52,7 +52,7 @@ module HexaPDF
52
52
 
53
53
  define_field :F, type: PDFByteString, required: true
54
54
  define_field :D, type: PDFByteString
55
- define_field :O, type: String
55
+ define_field :O, type: String, default: 'open', allowed_values: ['open', 'print']
56
56
  define_field :P, type: PDFByteString
57
57
 
58
58
  end
@@ -60,8 +60,8 @@ module HexaPDF
60
60
  define_field :F, type: Integer, default: 0, version: '1.1'
61
61
  define_field :AP, type: Dictionary, version: '1.2'
62
62
  define_field :AS, type: Symbol, version: '1.2'
63
- define_field :Border, type: Array, default: [0, 0, 1]
64
- define_field :C, type: Array, version: '1.1'
63
+ define_field :Border, type: PDFArray, default: [0, 0, 1]
64
+ define_field :C, type: PDFArray, version: '1.1'
65
65
  define_field :StructParent, type: Integer, version: '1.3'
66
66
  define_field :OC, type: Dictionary, version: '1.5'
67
67
 
@@ -47,6 +47,7 @@ module HexaPDF
47
47
  autoload(:MarkupAnnotation, 'hexapdf/type/annotations/markup_annotation')
48
48
  autoload(:Text, 'hexapdf/type/annotations/text')
49
49
  autoload(:Link, 'hexapdf/type/annotations/link')
50
+ autoload(:Widget, 'hexapdf/type/annotations/widget')
50
51
 
51
52
  end
52
53
 
@@ -48,24 +48,13 @@ module HexaPDF
48
48
 
49
49
  define_field :Subtype, type: Symbol, required: true, default: :Link
50
50
  define_field :A, type: Dictionary, version: '1.1'
51
- define_field :Dest, type: [Symbol, PDFByteString, Array]
52
- define_field :H, type: Symbol, default: :I, version: '1.2'
51
+ define_field :Dest, type: [Symbol, PDFByteString, PDFArray]
52
+ define_field :H, type: Symbol, default: :I, allowed_values: [:N, :I, :O, :P],
53
+ version: '1.2'
53
54
  define_field :PA, type: Dictionary, version: '1.3'
54
- define_field :QuadPoints, type: Array, version: '1.6'
55
+ define_field :QuadPoints, type: PDFArray, version: '1.6'
55
56
  define_field :BS, type: Dictionary, version: '1.6'
56
57
 
57
- private
58
-
59
- HIGHLIGHTING_MODES = [:N, :I, :O, :P].freeze # :nodoc:
60
-
61
- def perform_validation #:nodoc:
62
- super
63
-
64
- if key?(:H) && !HIGHLIGHTING_MODES.include?(self[:H])
65
- yield("/H contains invalid value #{self[:H]}")
66
- end
67
- end
68
-
69
58
  end
70
59
 
71
60
  end
@@ -53,7 +53,8 @@ module HexaPDF
53
53
  define_field :CreationDate, type: PDFDate, version: '1.5'
54
54
  define_field :IRT, type: Dictionary, version: '1.5'
55
55
  define_field :Subj, type: String, version: '1.5'
56
- define_field :RT, type: Symbol, default: :R, version: '1.6'
56
+ define_field :RT, type: Symbol, default: :R, allowed_values: [:R, :Group],
57
+ version: '1.6'
57
58
  define_field :IT, type: Symbol, version: '1.6'
58
59
  define_field :ExData, type: Dictionary, version: '1.7'
59
60
 
@@ -49,8 +49,9 @@ module HexaPDF
49
49
  define_field :Subtype, type: Symbol, required: true, default: :Text
50
50
  define_field :Open, type: Boolean, default: false
51
51
  define_field :Name, type: Symbol, default: :Note
52
- define_field :State, type: String, version: '1.5'
53
- define_field :StateModel, type: String, version: '1.5'
52
+ define_field :State, type: String, version: '1.5',
53
+ allowed_values: %w[Marked Unmarked Accepted Rejected Cancelled Completed None]
54
+ define_field :StateModel, type: String, allowed_values: ['Review', 'Marked'], version: '1.5'
54
55
 
55
56
  private
56
57
 
@@ -64,10 +65,6 @@ module HexaPDF
64
65
  def perform_validation #:nodoc:
65
66
  super
66
67
 
67
- if key?(:StateModel) && self[:StateModel] != "Review" && self[:StateModel] != "Marked"
68
- yield("/StateModel contains invalid value #{self[:StateModel]}")
69
- end
70
-
71
68
  if key?(:State) && !key?(:StateModel)
72
69
  state_model = STATE_TO_STATE_MODEL[self[:State]]
73
70
  yield("/StateModel required if /State set", !state_model.nil?)
@@ -0,0 +1,90 @@
1
+ # -*- encoding: utf-8; frozen_string_literal: true -*-
2
+ #
3
+ #--
4
+ # This file is part of HexaPDF.
5
+ #
6
+ # HexaPDF - A Versatile PDF Creation and Manipulation Library For Ruby
7
+ # Copyright (C) 2014-2019 Thomas Leitner
8
+ #
9
+ # HexaPDF is free software: you can redistribute it and/or modify it
10
+ # under the terms of the GNU Affero General Public License version 3 as
11
+ # published by the Free Software Foundation with the addition of the
12
+ # following permission added to Section 15 as permitted in Section 7(a):
13
+ # FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY
14
+ # THOMAS LEITNER, THOMAS LEITNER DISCLAIMS THE WARRANTY OF NON
15
+ # INFRINGEMENT OF THIRD PARTY RIGHTS.
16
+ #
17
+ # HexaPDF is distributed in the hope that it will be useful, but WITHOUT
18
+ # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
19
+ # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
20
+ # License for more details.
21
+ #
22
+ # You should have received a copy of the GNU Affero General Public License
23
+ # along with HexaPDF. If not, see <http://www.gnu.org/licenses/>.
24
+ #
25
+ # The interactive user interfaces in modified source and object code
26
+ # versions of HexaPDF must display Appropriate Legal Notices, as required
27
+ # under Section 5 of the GNU Affero General Public License version 3.
28
+ #
29
+ # In accordance with Section 7(b) of the GNU Affero General Public
30
+ # License, a covered work must retain the producer line in every PDF that
31
+ # is created or manipulated using HexaPDF.
32
+ #
33
+ # If the GNU Affero General Public License doesn't fit your need,
34
+ # commercial licenses are available at <https://gettalong.at/hexapdf/>.
35
+ #++
36
+
37
+ require 'hexapdf/type/annotation'
38
+
39
+ module HexaPDF
40
+ module Type
41
+ module Annotations
42
+
43
+ # Widget annotations are used by interactive forms to represent the appearance of fields and
44
+ # to manage user interactions.
45
+ #
46
+ # See: PDF1.7 s12.5.6.19, HexaPDF::Type::Annotation
47
+ class Widget < Annotation
48
+
49
+ # The dictionary used by the /MK key of the widget annotation.
50
+ class AppearanceCharacteristics < Dictionary
51
+
52
+ define_type :XXAppearanceCharacteristics
53
+
54
+ define_field :R, type: Integer, default: 0
55
+ define_field :BC, type: PDFArray
56
+ define_field :BG, type: PDFArray
57
+ define_field :CA, type: String
58
+ define_field :RC, type: String
59
+ define_field :AC, type: String
60
+ define_field :I, type: Stream
61
+ define_field :RI, type: Stream
62
+ define_field :IX, type: Stream
63
+ define_field :IF, type: :XXIconFit
64
+ define_field :TP, type: Integer, default: 0, allowed_values: [0, 1, 2, 3, 4, 5, 6]
65
+
66
+ private
67
+
68
+ def perform_validation #:nodoc:
69
+ super
70
+
71
+ if key?(:R) && self[:R] % 90 != 0
72
+ yield("Value of field R needs to be a multiple of 90")
73
+ end
74
+ end
75
+
76
+ end
77
+
78
+ define_field :Subtype, type: Symbol, required: true, default: :Widget
79
+ define_field :H, type: Symbol, allowed_values: [:N, :I, :O, :P, :T]
80
+ define_field :MK, type: :XXAppearanceCharacteristics
81
+ define_field :A, type: Dictionary, version: '1.1'
82
+ define_field :AA, type: Dictionary, version: '1.2'
83
+ define_field :BS, type: Dictionary, version: '1.2'
84
+ define_field :Parent, type: Dictionary
85
+
86
+ end
87
+
88
+ end
89
+ end
90
+ end
@@ -60,25 +60,28 @@ module HexaPDF
60
60
  define_field :Names, type: :XXNames, version: '1.2'
61
61
  define_field :Dests, type: Dictionary, version: '1.1'
62
62
  define_field :ViewerPreferences, type: :XXViewerPreferences, version: '1.2'
63
- define_field :PageLayout, type: Symbol, default: :SinglePage
64
- define_field :PageMode, type: Symbol, default: :UseNone
63
+ define_field :PageLayout, type: Symbol, default: :SinglePage,
64
+ allowed_values: [:SinglePage, :OneColumn, :TwoColumnLeft, :TwoColumnRight,
65
+ :TwoPageLeft, :TwoPageRight]
66
+ define_field :PageMode, type: Symbol, default: :UseNone,
67
+ allowed_values: [:UseNone, :UseOutlines, :UseThumbs, :FullScreen, :UseOC, :UseAttachments]
65
68
  define_field :Outlines, type: Dictionary, indirect: true
66
- define_field :Threads, type: Array, version: '1.1'
67
- define_field :OpenAction, type: [Dictionary, Array], version: '1.1'
69
+ define_field :Threads, type: PDFArray, version: '1.1'
70
+ define_field :OpenAction, type: [Dictionary, PDFArray], version: '1.1'
68
71
  define_field :AA, type: Dictionary, version: '1.4'
69
72
  define_field :URI, type: Dictionary, version: '1.1'
70
- define_field :AcroForm, type: Dictionary, version: '1.2'
73
+ define_field :AcroForm, type: :XXAcroForm, version: '1.2'
71
74
  define_field :Metadata, type: Stream, indirect: true, version: '1.4'
72
75
  define_field :StructTreeRoot, type: Dictionary, version: '1.3'
73
76
  define_field :MarkInfo, type: Dictionary, version: '1.4'
74
77
  define_field :Lang, type: String, version: '1.4'
75
78
  define_field :SpiderInfo, type: Dictionary, version: '1.3'
76
- define_field :OutputIntents, type: Array, version: '1.4'
79
+ define_field :OutputIntents, type: PDFArray, version: '1.4'
77
80
  define_field :PieceInfo, type: Dictionary, version: '1.4'
78
81
  define_field :OCProperties, type: Dictionary, version: '1.5'
79
82
  define_field :Perms, type: Dictionary, version: '1.5'
80
83
  define_field :Legal, type: Dictionary, version: '1.5'
81
- define_field :Requirements, type: Array, version: '1.7'
84
+ define_field :Requirements, type: PDFArray, version: '1.7'
82
85
  define_field :Collection, type: Dictionary, version: '1.7'
83
86
  define_field :NeedsRendering, type: Boolean, version: '1.7'
84
87
 
@@ -91,7 +94,7 @@ module HexaPDF
91
94
  #
92
95
  # See: PageTreeNode
93
96
  def pages
94
- self[:Pages] ||= document.add(Type: :Pages)
97
+ self[:Pages] ||= document.add({Type: :Pages})
95
98
  end
96
99
 
97
100
  private
@@ -101,7 +104,7 @@ module HexaPDF
101
104
  super
102
105
  unless key?(:Pages)
103
106
  yield("A PDF document needs a page tree", true)
104
- value[:Pages] = document.add(Type: :Pages)
107
+ value[:Pages] = document.add({Type: :Pages})
105
108
  value[:Pages].validate {|msg, correctable| yield(msg, correctable) }
106
109
  end
107
110
  end
@@ -51,9 +51,9 @@ module HexaPDF
51
51
  define_field :CIDSystemInfo, type: Dictionary, required: true
52
52
  define_field :FontDescriptor, type: :FontDescriptor, indirect: true, required: true
53
53
  define_field :DW, type: Integer, default: DEFAULT_WIDTH
54
- define_field :W, type: Array
55
- define_field :DW2, type: Array, default: [880, -1100]
56
- define_field :W2, type: Array
54
+ define_field :W, type: PDFArray
55
+ define_field :DW2, type: PDFArray, default: [880, -1100]
56
+ define_field :W2, type: PDFArray
57
57
 
58
58
  # Returns the unscaled width of the given CID in glyph units, or 0 if the width for the CID is
59
59
  # missing.
@@ -85,7 +85,7 @@ module HexaPDF
85
85
  define_field :DOS, type: PDFByteString
86
86
  define_field :Mac, type: PDFByteString
87
87
  define_field :Unix, type: PDFByteString
88
- define_field :ID, type: Array
88
+ define_field :ID, type: PDFArray
89
89
  define_field :V, type: Boolean, version: '1.2'
90
90
  define_field :EF, type: :XXFilespecEFDictionary, version: '1.7'
91
91
  define_field :RF, type: Dictionary, version: '1.3'
@@ -192,7 +192,7 @@ module HexaPDF
192
192
  self.path = name
193
193
 
194
194
  self[:EF] ||= {}
195
- ef_stream = self[:EF][:UF] = self[:EF][:F] = document.add(Type: :EmbeddedFile)
195
+ ef_stream = self[:EF][:UF] = self[:EF][:F] = document.add({Type: :EmbeddedFile})
196
196
  stat = if file_or_io.kind_of?(String)
197
197
  File.stat(file_or_io)
198
198
  elsif file_or_io.respond_to?(:stat)
@@ -54,8 +54,11 @@ module HexaPDF
54
54
  define_field :Type, type: Symbol, required: true, default: type
55
55
  define_field :FontName, type: Symbol, required: true
56
56
  define_field :FontFamily, type: PDFByteString, version: '1.5'
57
- define_field :FontStretch, type: Symbol, version: '1.5'
58
- define_field :FontWeight, type: Numeric, version: '1.5'
57
+ define_field :FontStretch, type: Symbol, version: '1.5',
58
+ allowed_values: [:UltraCondensed, :ExtraCondensed, :Condensed, :SemiCondensed,
59
+ :Normal, :SemiExpanded, :Expanded, :ExtraExpanded, :UltraExpanded]
60
+ define_field :FontWeight, type: Numeric, version: '1.5',
61
+ allowed_values: [100, 200, 300, 400, 500, 600, 700, 800, 900]
59
62
  define_field :Flags, type: Integer, required: true
60
63
  define_field :FontBBox, type: Rectangle
61
64
  define_field :ItalicAngle, type: Numeric, required: true
@@ -49,7 +49,7 @@ module HexaPDF
49
49
 
50
50
  define_field :FirstChar, type: Integer
51
51
  define_field :LastChar, type: Integer
52
- define_field :Widths, type: Array
52
+ define_field :Widths, type: PDFArray
53
53
  define_field :FontDescriptor, type: :FontDescriptor, indirect: true
54
54
  define_field :Encoding, type: [Dictionary, Symbol]
55
55