hexapdf 0.5.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (122) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +76 -2
  3. data/CONTRIBUTERS +1 -1
  4. data/Rakefile +1 -1
  5. data/VERSION +1 -1
  6. data/examples/boxes.rb +68 -0
  7. data/examples/graphics.rb +12 -12
  8. data/examples/{text_box_alignment.rb → text_layouter_alignment.rb} +14 -14
  9. data/examples/text_layouter_inline_boxes.rb +66 -0
  10. data/examples/{text_box_line_wrapping.rb → text_layouter_line_wrapping.rb} +9 -10
  11. data/examples/{text_box_shapes.rb → text_layouter_shapes.rb} +58 -54
  12. data/examples/text_layouter_styling.rb +125 -0
  13. data/examples/truetype.rb +5 -7
  14. data/lib/hexapdf/cli/command.rb +1 -0
  15. data/lib/hexapdf/configuration.rb +170 -106
  16. data/lib/hexapdf/content/canvas.rb +41 -36
  17. data/lib/hexapdf/content/graphics_state.rb +15 -0
  18. data/lib/hexapdf/content/operator.rb +1 -1
  19. data/lib/hexapdf/dictionary.rb +20 -8
  20. data/lib/hexapdf/dictionary_fields.rb +8 -6
  21. data/lib/hexapdf/document.rb +25 -26
  22. data/lib/hexapdf/document/fonts.rb +4 -4
  23. data/lib/hexapdf/document/images.rb +2 -2
  24. data/lib/hexapdf/document/pages.rb +16 -16
  25. data/lib/hexapdf/encryption/security_handler.rb +41 -9
  26. data/lib/hexapdf/filter/flate_decode.rb +1 -1
  27. data/lib/hexapdf/filter/lzw_decode.rb +1 -1
  28. data/lib/hexapdf/filter/predictor.rb +7 -1
  29. data/lib/hexapdf/font/true_type/font.rb +20 -0
  30. data/lib/hexapdf/font/type1/font.rb +23 -0
  31. data/lib/hexapdf/font_loader.rb +1 -0
  32. data/lib/hexapdf/font_loader/from_configuration.rb +2 -3
  33. data/lib/hexapdf/font_loader/from_file.rb +65 -0
  34. data/lib/hexapdf/image_loader/png.rb +2 -2
  35. data/lib/hexapdf/layout.rb +3 -2
  36. data/lib/hexapdf/layout/box.rb +146 -0
  37. data/lib/hexapdf/layout/inline_box.rb +40 -31
  38. data/lib/hexapdf/layout/{line_fragment.rb → line.rb} +12 -13
  39. data/lib/hexapdf/layout/style.rb +630 -41
  40. data/lib/hexapdf/layout/text_fragment.rb +80 -12
  41. data/lib/hexapdf/layout/{text_box.rb → text_layouter.rb} +164 -109
  42. data/lib/hexapdf/number_tree_node.rb +1 -1
  43. data/lib/hexapdf/parser.rb +4 -1
  44. data/lib/hexapdf/revisions.rb +11 -4
  45. data/lib/hexapdf/stream.rb +8 -9
  46. data/lib/hexapdf/tokenizer.rb +5 -3
  47. data/lib/hexapdf/type.rb +3 -0
  48. data/lib/hexapdf/type/action.rb +56 -0
  49. data/lib/hexapdf/type/actions.rb +52 -0
  50. data/lib/hexapdf/type/actions/go_to.rb +52 -0
  51. data/lib/hexapdf/type/actions/go_to_r.rb +54 -0
  52. data/lib/hexapdf/type/actions/launch.rb +73 -0
  53. data/lib/hexapdf/type/actions/uri.rb +65 -0
  54. data/lib/hexapdf/type/annotation.rb +85 -0
  55. data/lib/hexapdf/type/annotations.rb +51 -0
  56. data/lib/hexapdf/type/annotations/link.rb +70 -0
  57. data/lib/hexapdf/type/annotations/markup_annotation.rb +70 -0
  58. data/lib/hexapdf/type/annotations/text.rb +81 -0
  59. data/lib/hexapdf/type/catalog.rb +3 -1
  60. data/lib/hexapdf/type/embedded_file.rb +6 -11
  61. data/lib/hexapdf/type/file_specification.rb +4 -6
  62. data/lib/hexapdf/type/font.rb +3 -1
  63. data/lib/hexapdf/type/font_descriptor.rb +18 -16
  64. data/lib/hexapdf/type/form.rb +3 -1
  65. data/lib/hexapdf/type/graphics_state_parameter.rb +3 -1
  66. data/lib/hexapdf/type/image.rb +4 -2
  67. data/lib/hexapdf/type/info.rb +2 -5
  68. data/lib/hexapdf/type/names.rb +2 -5
  69. data/lib/hexapdf/type/object_stream.rb +2 -1
  70. data/lib/hexapdf/type/page.rb +14 -1
  71. data/lib/hexapdf/type/page_tree_node.rb +9 -6
  72. data/lib/hexapdf/type/resources.rb +2 -5
  73. data/lib/hexapdf/type/trailer.rb +2 -5
  74. data/lib/hexapdf/type/viewer_preferences.rb +2 -5
  75. data/lib/hexapdf/type/xref_stream.rb +3 -1
  76. data/lib/hexapdf/version.rb +1 -1
  77. data/test/hexapdf/common_tokenizer_tests.rb +3 -1
  78. data/test/hexapdf/content/test_canvas.rb +29 -3
  79. data/test/hexapdf/content/test_graphics_state.rb +11 -0
  80. data/test/hexapdf/content/test_operator.rb +3 -2
  81. data/test/hexapdf/document/test_fonts.rb +8 -8
  82. data/test/hexapdf/document/test_images.rb +4 -12
  83. data/test/hexapdf/document/test_pages.rb +7 -7
  84. data/test/hexapdf/encryption/test_security_handler.rb +1 -5
  85. data/test/hexapdf/filter/test_predictor.rb +40 -12
  86. data/test/hexapdf/font/true_type/test_font.rb +16 -0
  87. data/test/hexapdf/font/type1/test_font.rb +30 -0
  88. data/test/hexapdf/font_loader/test_from_file.rb +29 -0
  89. data/test/hexapdf/font_loader/test_standard14.rb +4 -3
  90. data/test/hexapdf/layout/test_box.rb +104 -0
  91. data/test/hexapdf/layout/test_inline_box.rb +24 -10
  92. data/test/hexapdf/layout/{test_line_fragment.rb → test_line.rb} +9 -9
  93. data/test/hexapdf/layout/test_style.rb +519 -31
  94. data/test/hexapdf/layout/test_text_fragment.rb +136 -15
  95. data/test/hexapdf/layout/{test_text_box.rb → test_text_layouter.rb} +224 -144
  96. data/test/hexapdf/layout/test_text_shaper.rb +1 -1
  97. data/test/hexapdf/test_configuration.rb +12 -6
  98. data/test/hexapdf/test_dictionary.rb +27 -2
  99. data/test/hexapdf/test_dictionary_fields.rb +10 -1
  100. data/test/hexapdf/test_document.rb +14 -13
  101. data/test/hexapdf/test_parser.rb +12 -0
  102. data/test/hexapdf/test_revisions.rb +34 -0
  103. data/test/hexapdf/test_stream.rb +1 -1
  104. data/test/hexapdf/test_type.rb +18 -0
  105. data/test/hexapdf/test_writer.rb +2 -2
  106. data/test/hexapdf/type/actions/test_launch.rb +24 -0
  107. data/test/hexapdf/type/actions/test_uri.rb +23 -0
  108. data/test/hexapdf/type/annotations/test_link.rb +19 -0
  109. data/test/hexapdf/type/annotations/test_markup_annotation.rb +22 -0
  110. data/test/hexapdf/type/annotations/test_text.rb +38 -0
  111. data/test/hexapdf/type/test_annotation.rb +38 -0
  112. data/test/hexapdf/type/test_file_specification.rb +0 -7
  113. data/test/hexapdf/type/test_info.rb +0 -5
  114. data/test/hexapdf/type/test_page.rb +14 -0
  115. data/test/hexapdf/type/test_page_tree_node.rb +4 -1
  116. data/test/hexapdf/type/test_trailer.rb +0 -4
  117. data/test/test_helper.rb +6 -3
  118. metadata +36 -15
  119. data/examples/text_box_inline_boxes.rb +0 -56
  120. data/examples/text_box_styling.rb +0 -72
  121. data/test/hexapdf/type/test_embedded_file.rb +0 -16
  122. data/test/hexapdf/type/test_names.rb +0 -9
@@ -0,0 +1,85 @@
1
+ # -*- encoding: utf-8 -*-
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-2017 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
+
34
+ require 'hexapdf/dictionary'
35
+ require 'hexapdf/utils/bit_field'
36
+
37
+ module HexaPDF
38
+ module Type
39
+
40
+ # Annotations are used to associate objects like notes, sounds or movies with a location on a
41
+ # PDF page or allow the user to interact with a PDF document using a keyboard or mouse.
42
+ #
43
+ # See: PDF1.7 s12.5
44
+ class Annotation < Dictionary
45
+
46
+ extend Utils::BitField
47
+
48
+ define_type :Annot
49
+
50
+ define_field :Type, type: Symbol, default: self.type
51
+ define_field :Subtype, type: Symbol, required: true
52
+ define_field :Rect, type: Rectangle, required: true
53
+ define_field :Contents, type: String
54
+ define_field :P, type: Dictionary, version: '1.3'
55
+ define_field :NM, type: String, version: '1.4'
56
+ define_field :M, type: PDFDate, version: '1.1'
57
+ define_field :F, type: Integer, default: 0, version: '1.1'
58
+ define_field :AP, type: Dictionary, version: '1.2'
59
+ define_field :AS, type: Symbol, version: '1.2'
60
+ define_field :Border, type: Array, default: [0, 0, 1]
61
+ define_field :C, type: Array, version: '1.1'
62
+ define_field :StructParent, type: Integer, version: '1.3'
63
+ define_field :OC, type: Dictionary, version: '1.5'
64
+
65
+ bit_field(:raw_flags, {invisible: 0, hidden: 1, print: 2, no_zoom: 3, no_rotate: 4,
66
+ no_view: 5, read_only: 6, locked: 7, toggle_no_view: 8,
67
+ locked_contents: 9},
68
+ lister: "flags", getter: "flagged?", setter: "flag")
69
+
70
+ private
71
+
72
+ # Helper method for bit field getter access.
73
+ def raw_flags
74
+ self[:F]
75
+ end
76
+
77
+ # Helper method for bit field setter access.
78
+ def raw_flags=(value)
79
+ self[:F] = value
80
+ end
81
+
82
+ end
83
+
84
+ end
85
+ end
@@ -0,0 +1,51 @@
1
+ # -*- encoding: utf-8 -*-
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-2017 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
+
34
+ module HexaPDF
35
+ module Type
36
+
37
+ autoload(:Annotation, 'hexapdf/type/annotation')
38
+
39
+ # Namespace module for all PDF annotation dictionary types.
40
+ #
41
+ # See: PDF1.7 s12.5.6, Annotation
42
+ module Annotations
43
+
44
+ autoload(:MarkupAnnotation, 'hexapdf/type/annotations/markup_annotation')
45
+ autoload(:Text, 'hexapdf/type/annotations/text')
46
+ autoload(:Link, 'hexapdf/type/annotations/link')
47
+
48
+ end
49
+
50
+ end
51
+ end
@@ -0,0 +1,70 @@
1
+ # -*- encoding: utf-8 -*-
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-2017 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
+
34
+ require 'hexapdf/type/annotation'
35
+
36
+ module HexaPDF
37
+ module Type
38
+ module Annotations
39
+
40
+ # Link annotations represent a link to a destination elsewhere in the PDF document or an
41
+ # action to be performed.
42
+ #
43
+ # See: PDF1.7 s12.5.6.5, HexaPDF::Type::Annotation
44
+ class Link < Annotation
45
+
46
+ define_field :Subtype, type: Symbol, required: true, default: :Link
47
+ define_field :A, type: Dictionary, version: '1.1'
48
+ define_field :Dest, type: [Symbol, PDFByteString, Array]
49
+ define_field :H, type: Symbol, default: :I, version: '1.2'
50
+ define_field :PA, type: Dictionary, version: '1.3'
51
+ define_field :QuadPoints, type: Array, version: '1.6'
52
+ define_field :BS, type: Dictionary, version: '1.6'
53
+
54
+ private
55
+
56
+ HIGHLIGHTING_MODES = [:N, :I, :O, :P].freeze # :nodoc:
57
+
58
+ def perform_validation #:nodoc:
59
+ super
60
+
61
+ if key?(:H) && !HIGHLIGHTING_MODES.include?(self[:H])
62
+ yield("/H contains invalid value #{self[:H]}")
63
+ end
64
+ end
65
+
66
+ end
67
+
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,70 @@
1
+ # -*- encoding: utf-8 -*-
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-2017 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
+
34
+ require 'hexapdf/type/annotation'
35
+
36
+ module HexaPDF
37
+ module Type
38
+ module Annotations
39
+
40
+ # Markup annotations are used to "mark up" a PDF document, most of the available PDF
41
+ # annotations are actually markup annotations.
42
+ #
43
+ # See: PDF1.7 s12.5.6.2, HexaPDF::Type::Annotation
44
+ class MarkupAnnotation < Annotation
45
+
46
+ define_field :T, type: String, version: '1.1'
47
+ define_field :Popup, type: :Annotation, version: '1.3'
48
+ define_field :CA, type: Numeric, default: 1.0, version: '1.4'
49
+ define_field :RC, type: [String, Stream], version: '1.5'
50
+ define_field :CreationDate, type: PDFDate, version: '1.5'
51
+ define_field :IRT, type: Dictionary, version: '1.5'
52
+ define_field :Subj, type: String, version: '1.5'
53
+ define_field :RT, type: Symbol, default: :R, version: '1.6'
54
+ define_field :IT, type: Symbol, version: '1.6'
55
+ define_field :ExData, type: Dictionary, version: '1.7'
56
+
57
+ private
58
+
59
+ def perform_validation #:nodoc:
60
+ super
61
+ if key?(:RT) && !key?(:IRT)
62
+ yield("/IRT required if /RT field is set")
63
+ end
64
+ end
65
+
66
+ end
67
+
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,81 @@
1
+ # -*- encoding: utf-8 -*-
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-2017 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
+
34
+ require 'hexapdf/type/annotations/markup_annotation'
35
+
36
+ module HexaPDF
37
+ module Type
38
+ module Annotations
39
+
40
+ # Text annotations are "sticky notes" attached to a point in a PDF document. They act as if
41
+ # the NoZoom and NoRotate flags were always set.
42
+ #
43
+ # See: PDF1.7 s12.5.6.4, HexaPDF::Type::MarkupAnnotation
44
+ class Text < MarkupAnnotation
45
+
46
+ define_field :Subtype, type: Symbol, required: true, default: :Text
47
+ define_field :Open, type: Boolean, default: false
48
+ define_field :Name, type: Symbol, default: :Note
49
+ define_field :State, type: String, version: '1.5'
50
+ define_field :StateModel, type: String, version: '1.5'
51
+
52
+ private
53
+
54
+ # :nodoc:
55
+ STATE_TO_STATE_MODEL = {
56
+ "Marked" => "Marked", "Unmarked" => "Marked",
57
+ "Accepted" => "Review", "Rejected" => "Review", "Cancelled" => "Review",
58
+ "Completed" => "Review", "None" => "Review"
59
+ }
60
+
61
+ def perform_validation #:nodoc:
62
+ super
63
+
64
+ if key?(:StateModel) && self[:StateModel] != "Review" && self[:StateModel] != "Marked"
65
+ yield("/StateModel contains invalid value #{self[:StateModel]}")
66
+ end
67
+
68
+ if key?(:State) && !key?(:StateModel)
69
+ state_model = STATE_TO_STATE_MODEL[self[:State]]
70
+ yield("/StateModel required if /State set", !state_model.nil?)
71
+ self[:StateModel] = state_model
72
+ elsif key?(:State) && STATE_TO_STATE_MODEL[self[:State]] != self[:StateModel]
73
+ yield("/State and /StateModel don't agree", false)
74
+ end
75
+ end
76
+
77
+ end
78
+
79
+ end
80
+ end
81
+ end
@@ -46,7 +46,9 @@ module HexaPDF
46
46
  # See: PDF1.7 s7.7.2, Trailer
47
47
  class Catalog < Dictionary
48
48
 
49
- define_field :Type, type: Symbol, required: true, default: :Catalog
49
+ define_type :Catalog
50
+
51
+ define_field :Type, type: Symbol, required: true, default: self.type
50
52
  define_field :Version, type: Symbol, version: '1.4'
51
53
  define_field :Extensions, type: Dictionary, version: '1.7'
52
54
  # Pages field is required but this is handled in #perform_validation
@@ -49,35 +49,30 @@ module HexaPDF
49
49
  # The type used for the /Mac field of an EmbeddedFile::Parameters dictionary.
50
50
  class MacInfo < Dictionary
51
51
 
52
+ define_type :XXEmbeddedFileParametersMacInfo
53
+
52
54
  define_field :Subtype, type: Integer
53
55
  define_field :Creator, type: Integer
54
56
  define_field :ResFork, type: Stream
55
57
 
56
- # Returns +:XXEmbeddedFileParametersMacInfo+
57
- def type
58
- :XXEmbeddedFileParametersMacInfo
59
- end
60
-
61
58
  end
62
59
 
63
60
  # The type used for the /Params field of an EmbeddedFileStream.
64
61
  class Parameters < Dictionary
65
62
 
63
+ define_type :XXEmbeddedFileParameters
64
+
66
65
  define_field :Size, type: Integer
67
66
  define_field :CreationDate, type: PDFDate
68
67
  define_field :ModDate, type: PDFDate
69
68
  define_field :Mac, type: :XXEmbeddedFileParametersMacInfo
70
69
  define_field :CheckSum, type: PDFByteString
71
70
 
72
- # Returns +:XXEmbeddedFileParameters+
73
- def type
74
- :XXEmbeddedFileParameters
75
- end
76
-
77
71
  end
78
72
 
73
+ define_type :EmbeddedFile
79
74
 
80
- define_field :Type, type: Symbol, default: :EmbeddedFile, version: '1.3'
75
+ define_field :Type, type: Symbol, default: self.type, version: '1.3'
81
76
  define_field :Subtype, type: Symbol
82
77
  define_field :Params, type: :XXEmbeddedFileParameters
83
78
 
@@ -63,21 +63,19 @@ module HexaPDF
63
63
  # The type used for the /EF field of a FileSpecification
64
64
  class EFDictionary < Dictionary
65
65
 
66
+ define_type :XXFilespecEFDictionary
67
+
66
68
  define_field :F, type: :EmbeddedFile
67
69
  define_field :UF, type: :EmbeddedFile
68
70
  define_field :DOS, type: :EmbeddedFile
69
71
  define_field :Mac, type: :EmbeddedFile
70
72
  define_field :Unix, type: :EmbeddedFile
71
73
 
72
- # Returns +:XXFilespecEFDictionary+
73
- def type
74
- :XXFilespecEFDictionary
75
- end
76
-
77
74
  end
78
75
 
76
+ define_type :Filespec
79
77
 
80
- define_field :Type, type: Symbol, default: :Filespec, required: true
78
+ define_field :Type, type: Symbol, default: self.type, required: true
81
79
  define_field :FS, type: Symbol
82
80
  define_field :F, type: PDFByteString
83
81
  define_field :UF, type: String, version: '1.7'
@@ -42,7 +42,9 @@ module HexaPDF
42
42
  # This class is the base class for all font objects, be it simple fonts or composite fonts.
43
43
  class Font < Dictionary
44
44
 
45
- define_field :Type, type: Symbol, required: true, default: :Font
45
+ define_type :Font
46
+
47
+ define_field :Type, type: Symbol, required: true, default: self.type
46
48
  define_field :BaseFont, type: Symbol, required: true
47
49
  define_field :ToUnicode, type: Stream, version: '1.2'
48
50