hexapdf 0.6.0 → 0.7.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 (257) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +33 -0
  3. data/CONTRIBUTERS +1 -1
  4. data/LICENSE +1 -1
  5. data/Rakefile +1 -1
  6. data/VERSION +1 -1
  7. data/bin/hexapdf +1 -1
  8. data/examples/text_layouter_styling.rb +1 -2
  9. data/lib/hexapdf.rb +2 -2
  10. data/lib/hexapdf/cli.rb +3 -3
  11. data/lib/hexapdf/cli/batch.rb +5 -5
  12. data/lib/hexapdf/cli/command.rb +15 -17
  13. data/lib/hexapdf/cli/files.rb +3 -3
  14. data/lib/hexapdf/cli/images.rb +3 -4
  15. data/lib/hexapdf/cli/info.rb +5 -5
  16. data/lib/hexapdf/cli/inspect.rb +6 -6
  17. data/lib/hexapdf/cli/merge.rb +6 -6
  18. data/lib/hexapdf/cli/modify.rb +4 -4
  19. data/lib/hexapdf/cli/optimize.rb +3 -3
  20. data/lib/hexapdf/configuration.rb +4 -5
  21. data/lib/hexapdf/content.rb +2 -2
  22. data/lib/hexapdf/content/canvas.rb +35 -36
  23. data/lib/hexapdf/content/color_space.rb +9 -14
  24. data/lib/hexapdf/content/graphic_object.rb +2 -2
  25. data/lib/hexapdf/content/graphic_object/arc.rb +3 -3
  26. data/lib/hexapdf/content/graphic_object/endpoint_arc.rb +2 -2
  27. data/lib/hexapdf/content/graphic_object/solid_arc.rb +4 -8
  28. data/lib/hexapdf/content/graphics_state.rb +4 -13
  29. data/lib/hexapdf/content/operator.rb +33 -35
  30. data/lib/hexapdf/content/parser.rb +28 -18
  31. data/lib/hexapdf/content/processor.rb +4 -5
  32. data/lib/hexapdf/content/transformation_matrix.rb +2 -2
  33. data/lib/hexapdf/data_dir.rb +2 -2
  34. data/lib/hexapdf/dictionary.rb +8 -9
  35. data/lib/hexapdf/dictionary_fields.rb +7 -10
  36. data/lib/hexapdf/document.rb +18 -18
  37. data/lib/hexapdf/document/files.rb +12 -10
  38. data/lib/hexapdf/document/fonts.rb +2 -2
  39. data/lib/hexapdf/document/images.rb +3 -3
  40. data/lib/hexapdf/document/pages.rb +4 -4
  41. data/lib/hexapdf/encryption.rb +2 -2
  42. data/lib/hexapdf/encryption/aes.rb +2 -2
  43. data/lib/hexapdf/encryption/arc4.rb +4 -4
  44. data/lib/hexapdf/encryption/fast_aes.rb +2 -2
  45. data/lib/hexapdf/encryption/fast_arc4.rb +4 -4
  46. data/lib/hexapdf/encryption/identity.rb +5 -4
  47. data/lib/hexapdf/encryption/ruby_aes.rb +147 -139
  48. data/lib/hexapdf/encryption/ruby_arc4.rb +4 -4
  49. data/lib/hexapdf/encryption/security_handler.rb +11 -12
  50. data/lib/hexapdf/encryption/standard_security_handler.rb +6 -9
  51. data/lib/hexapdf/error.rb +7 -9
  52. data/lib/hexapdf/filter.rb +2 -3
  53. data/lib/hexapdf/filter/ascii85_decode.rb +3 -3
  54. data/lib/hexapdf/filter/ascii_hex_decode.rb +2 -2
  55. data/lib/hexapdf/filter/dct_decode.rb +2 -2
  56. data/lib/hexapdf/filter/encryption.rb +2 -2
  57. data/lib/hexapdf/filter/flate_decode.rb +16 -33
  58. data/lib/hexapdf/filter/jpx_decode.rb +2 -2
  59. data/lib/hexapdf/filter/lzw_decode.rb +4 -4
  60. data/lib/hexapdf/filter/predictor.rb +2 -6
  61. data/lib/hexapdf/filter/run_length_decode.rb +2 -2
  62. data/lib/hexapdf/font/cmap.rb +2 -3
  63. data/lib/hexapdf/font/cmap/parser.rb +11 -11
  64. data/lib/hexapdf/font/cmap/writer.rb +25 -25
  65. data/lib/hexapdf/font/encoding.rb +2 -2
  66. data/lib/hexapdf/font/encoding/base.rb +2 -2
  67. data/lib/hexapdf/font/encoding/difference_encoding.rb +2 -2
  68. data/lib/hexapdf/font/encoding/glyph_list.rb +6 -6
  69. data/lib/hexapdf/font/encoding/mac_expert_encoding.rb +2 -2
  70. data/lib/hexapdf/font/encoding/mac_roman_encoding.rb +2 -2
  71. data/lib/hexapdf/font/encoding/standard_encoding.rb +2 -2
  72. data/lib/hexapdf/font/encoding/symbol_encoding.rb +2 -2
  73. data/lib/hexapdf/font/encoding/win_ansi_encoding.rb +2 -2
  74. data/lib/hexapdf/font/encoding/zapf_dingbats_encoding.rb +2 -2
  75. data/lib/hexapdf/font/invalid_glyph.rb +7 -7
  76. data/lib/hexapdf/font/true_type.rb +2 -2
  77. data/lib/hexapdf/font/true_type/builder.rb +13 -7
  78. data/lib/hexapdf/font/true_type/font.rb +2 -3
  79. data/lib/hexapdf/font/true_type/optimizer.rb +2 -2
  80. data/lib/hexapdf/font/true_type/subsetter.rb +4 -4
  81. data/lib/hexapdf/font/true_type/table.rb +3 -5
  82. data/lib/hexapdf/font/true_type/table/cmap.rb +2 -2
  83. data/lib/hexapdf/font/true_type/table/cmap_subtable.rb +9 -16
  84. data/lib/hexapdf/font/true_type/table/directory.rb +4 -4
  85. data/lib/hexapdf/font/true_type/table/glyf.rb +2 -2
  86. data/lib/hexapdf/font/true_type/table/head.rb +3 -2
  87. data/lib/hexapdf/font/true_type/table/hhea.rb +2 -2
  88. data/lib/hexapdf/font/true_type/table/hmtx.rb +2 -2
  89. data/lib/hexapdf/font/true_type/table/kern.rb +3 -3
  90. data/lib/hexapdf/font/true_type/table/loca.rb +3 -3
  91. data/lib/hexapdf/font/true_type/table/maxp.rb +2 -2
  92. data/lib/hexapdf/font/true_type/table/name.rb +3 -5
  93. data/lib/hexapdf/font/true_type/table/os2.rb +4 -3
  94. data/lib/hexapdf/font/true_type/table/post.rb +3 -7
  95. data/lib/hexapdf/font/true_type_wrapper.rb +20 -22
  96. data/lib/hexapdf/font/type1.rb +2 -2
  97. data/lib/hexapdf/font/type1/afm_parser.rb +7 -7
  98. data/lib/hexapdf/font/type1/character_metrics.rb +2 -2
  99. data/lib/hexapdf/font/type1/font.rb +3 -3
  100. data/lib/hexapdf/font/type1/font_metrics.rb +2 -4
  101. data/lib/hexapdf/font/type1/pfb_parser.rb +2 -2
  102. data/lib/hexapdf/font/type1_wrapper.rb +8 -9
  103. data/lib/hexapdf/font_loader.rb +2 -2
  104. data/lib/hexapdf/font_loader/from_configuration.rb +2 -2
  105. data/lib/hexapdf/font_loader/from_file.rb +2 -2
  106. data/lib/hexapdf/font_loader/standard14.rb +2 -2
  107. data/lib/hexapdf/image_loader.rb +2 -2
  108. data/lib/hexapdf/image_loader/jpeg.rb +6 -4
  109. data/lib/hexapdf/image_loader/pdf.rb +2 -2
  110. data/lib/hexapdf/image_loader/png.rb +6 -6
  111. data/lib/hexapdf/importer.rb +6 -4
  112. data/lib/hexapdf/layout.rb +2 -2
  113. data/lib/hexapdf/layout/box.rb +4 -4
  114. data/lib/hexapdf/layout/inline_box.rb +2 -2
  115. data/lib/hexapdf/layout/line.rb +6 -6
  116. data/lib/hexapdf/layout/numeric_refinements.rb +2 -2
  117. data/lib/hexapdf/layout/style.rb +17 -8
  118. data/lib/hexapdf/layout/text_fragment.rb +86 -48
  119. data/lib/hexapdf/layout/text_layouter.rb +40 -21
  120. data/lib/hexapdf/layout/text_shaper.rb +2 -2
  121. data/lib/hexapdf/name_tree_node.rb +2 -2
  122. data/lib/hexapdf/number_tree_node.rb +2 -2
  123. data/lib/hexapdf/object.rb +6 -8
  124. data/lib/hexapdf/parser.rb +10 -10
  125. data/lib/hexapdf/rectangle.rb +4 -4
  126. data/lib/hexapdf/reference.rb +2 -2
  127. data/lib/hexapdf/revision.rb +4 -4
  128. data/lib/hexapdf/revisions.rb +5 -5
  129. data/lib/hexapdf/serializer.rb +27 -24
  130. data/lib/hexapdf/stream.rb +4 -4
  131. data/lib/hexapdf/task.rb +2 -2
  132. data/lib/hexapdf/task/dereference.rb +4 -4
  133. data/lib/hexapdf/task/optimize.rb +5 -4
  134. data/lib/hexapdf/tokenizer.rb +12 -14
  135. data/lib/hexapdf/type.rb +2 -2
  136. data/lib/hexapdf/type/action.rb +3 -3
  137. data/lib/hexapdf/type/actions.rb +2 -2
  138. data/lib/hexapdf/type/actions/go_to.rb +2 -2
  139. data/lib/hexapdf/type/actions/go_to_r.rb +2 -2
  140. data/lib/hexapdf/type/actions/launch.rb +2 -2
  141. data/lib/hexapdf/type/actions/uri.rb +3 -3
  142. data/lib/hexapdf/type/annotation.rb +3 -3
  143. data/lib/hexapdf/type/annotations.rb +2 -2
  144. data/lib/hexapdf/type/annotations/link.rb +2 -2
  145. data/lib/hexapdf/type/annotations/markup_annotation.rb +2 -2
  146. data/lib/hexapdf/type/annotations/text.rb +2 -2
  147. data/lib/hexapdf/type/catalog.rb +4 -4
  148. data/lib/hexapdf/type/cid_font.rb +4 -5
  149. data/lib/hexapdf/type/embedded_file.rb +3 -3
  150. data/lib/hexapdf/type/file_specification.rb +6 -7
  151. data/lib/hexapdf/type/font.rb +4 -4
  152. data/lib/hexapdf/type/font_descriptor.rb +3 -4
  153. data/lib/hexapdf/type/font_simple.rb +12 -16
  154. data/lib/hexapdf/type/font_true_type.rb +2 -2
  155. data/lib/hexapdf/type/font_type0.rb +5 -5
  156. data/lib/hexapdf/type/font_type1.rb +4 -4
  157. data/lib/hexapdf/type/form.rb +3 -3
  158. data/lib/hexapdf/type/graphics_state_parameter.rb +3 -3
  159. data/lib/hexapdf/type/image.rb +13 -14
  160. data/lib/hexapdf/type/info.rb +2 -2
  161. data/lib/hexapdf/type/names.rb +2 -2
  162. data/lib/hexapdf/type/object_stream.rb +5 -5
  163. data/lib/hexapdf/type/page.rb +9 -10
  164. data/lib/hexapdf/type/page_tree_node.rb +5 -6
  165. data/lib/hexapdf/type/resources.rb +11 -11
  166. data/lib/hexapdf/type/trailer.rb +3 -3
  167. data/lib/hexapdf/type/viewer_preferences.rb +2 -2
  168. data/lib/hexapdf/type/xref_stream.rb +8 -4
  169. data/lib/hexapdf/utils/bit_field.rb +4 -4
  170. data/lib/hexapdf/utils/bit_stream.rb +4 -4
  171. data/lib/hexapdf/utils/graphics_helpers.rb +2 -2
  172. data/lib/hexapdf/utils/lru_cache.rb +2 -2
  173. data/lib/hexapdf/utils/math_helpers.rb +2 -2
  174. data/lib/hexapdf/utils/object_hash.rb +3 -3
  175. data/lib/hexapdf/utils/pdf_doc_encoding.rb +3 -3
  176. data/lib/hexapdf/utils/sorted_tree_node.rb +12 -11
  177. data/lib/hexapdf/version.rb +3 -3
  178. data/lib/hexapdf/writer.rb +8 -8
  179. data/lib/hexapdf/xref_section.rb +3 -3
  180. data/test/hexapdf/common_tokenizer_tests.rb +6 -7
  181. data/test/hexapdf/content/graphic_object/test_endpoint_arc.rb +0 -1
  182. data/test/hexapdf/content/test_canvas.rb +28 -36
  183. data/test/hexapdf/content/test_color_space.rb +4 -0
  184. data/test/hexapdf/content/test_graphics_state.rb +2 -0
  185. data/test/hexapdf/content/test_operator.rb +6 -7
  186. data/test/hexapdf/content/test_parser.rb +2 -2
  187. data/test/hexapdf/content/test_processor.rb +1 -1
  188. data/test/hexapdf/document/test_files.rb +1 -0
  189. data/test/hexapdf/document/test_images.rb +1 -1
  190. data/test/hexapdf/encryption/common.rb +3 -3
  191. data/test/hexapdf/encryption/test_aes.rb +10 -4
  192. data/test/hexapdf/encryption/test_identity.rb +1 -1
  193. data/test/hexapdf/encryption/test_security_handler.rb +13 -17
  194. data/test/hexapdf/encryption/test_standard_security_handler.rb +12 -12
  195. data/test/hexapdf/filter/test_ascii85_decode.rb +2 -3
  196. data/test/hexapdf/filter/test_ascii_hex_decode.rb +6 -1
  197. data/test/hexapdf/filter/test_flate_decode.rb +2 -2
  198. data/test/hexapdf/filter/test_lzw_decode.rb +10 -10
  199. data/test/hexapdf/filter/test_predictor.rb +10 -2
  200. data/test/hexapdf/filter/test_run_length_decode.rb +1 -1
  201. data/test/hexapdf/font/cmap/test_parser.rb +40 -40
  202. data/test/hexapdf/font/cmap/test_writer.rb +29 -29
  203. data/test/hexapdf/font/test_true_type_wrapper.rb +3 -2
  204. data/test/hexapdf/font/true_type/common.rb +2 -0
  205. data/test/hexapdf/font/true_type/table/test_cmap.rb +1 -1
  206. data/test/hexapdf/font/true_type/table/test_cmap_subtable.rb +5 -4
  207. data/test/hexapdf/font/true_type/table/test_glyf.rb +2 -2
  208. data/test/hexapdf/font/true_type/table/test_head.rb +2 -2
  209. data/test/hexapdf/font/true_type/table/test_name.rb +9 -6
  210. data/test/hexapdf/font/true_type/test_builder.rb +8 -3
  211. data/test/hexapdf/font/true_type/test_optimizer.rb +1 -2
  212. data/test/hexapdf/font/type1/test_afm_parser.rb +2 -2
  213. data/test/hexapdf/image_loader/test_jpeg.rb +1 -1
  214. data/test/hexapdf/image_loader/test_pdf.rb +1 -1
  215. data/test/hexapdf/image_loader/test_png.rb +3 -3
  216. data/test/hexapdf/layout/test_inline_box.rb +10 -1
  217. data/test/hexapdf/layout/test_line.rb +4 -4
  218. data/test/hexapdf/layout/test_style.rb +19 -7
  219. data/test/hexapdf/layout/test_text_fragment.rb +73 -27
  220. data/test/hexapdf/layout/test_text_layouter.rb +84 -68
  221. data/test/hexapdf/layout/test_text_shaper.rb +4 -6
  222. data/test/hexapdf/task/test_dereference.rb +2 -2
  223. data/test/hexapdf/task/test_optimize.rb +16 -7
  224. data/test/hexapdf/test_configuration.rb +1 -1
  225. data/test/hexapdf/test_data_dir.rb +2 -2
  226. data/test/hexapdf/test_dictionary.rb +6 -3
  227. data/test/hexapdf/test_dictionary_fields.rb +15 -14
  228. data/test/hexapdf/test_document.rb +47 -48
  229. data/test/hexapdf/test_filter.rb +30 -26
  230. data/test/hexapdf/test_importer.rb +14 -0
  231. data/test/hexapdf/test_object.rb +16 -4
  232. data/test/hexapdf/test_parser.rb +36 -36
  233. data/test/hexapdf/test_reference.rb +7 -5
  234. data/test/hexapdf/test_revision.rb +1 -1
  235. data/test/hexapdf/test_revisions.rb +90 -90
  236. data/test/hexapdf/test_serializer.rb +3 -2
  237. data/test/hexapdf/test_stream.rb +2 -4
  238. data/test/hexapdf/test_tokenizer.rb +2 -2
  239. data/test/hexapdf/test_writer.rb +80 -80
  240. data/test/hexapdf/test_xref_section.rb +1 -1
  241. data/test/hexapdf/type/annotations/test_link.rb +1 -1
  242. data/test/hexapdf/type/annotations/test_text.rb +3 -3
  243. data/test/hexapdf/type/test_font_descriptor.rb +1 -1
  244. data/test/hexapdf/type/test_font_simple.rb +2 -2
  245. data/test/hexapdf/type/test_font_type0.rb +0 -1
  246. data/test/hexapdf/type/test_image.rb +0 -3
  247. data/test/hexapdf/type/test_object_stream.rb +2 -1
  248. data/test/hexapdf/type/test_page.rb +5 -1
  249. data/test/hexapdf/type/test_page_tree_node.rb +4 -4
  250. data/test/hexapdf/type/test_trailer.rb +1 -1
  251. data/test/hexapdf/type/test_xref_stream.rb +4 -0
  252. data/test/hexapdf/utils/test_bit_field.rb +2 -0
  253. data/test/hexapdf/utils/test_bit_stream.rb +1 -1
  254. data/test/hexapdf/utils/test_lru_cache.rb +1 -1
  255. data/test/hexapdf/utils/test_sorted_tree_node.rb +10 -4
  256. data/test/test_helper.rb +3 -6
  257. metadata +3 -3
@@ -1,10 +1,10 @@
1
- # -*- encoding: utf-8 -*-
1
+ # -*- encoding: utf-8; frozen_string_literal: true -*-
2
2
  #
3
3
  #--
4
4
  # This file is part of HexaPDF.
5
5
  #
6
6
  # HexaPDF - A Versatile PDF Creation and Manipulation Library For Ruby
7
- # Copyright (C) 2014-2017 Thomas Leitner
7
+ # Copyright (C) 2014-2018 Thomas Leitner
8
8
  #
9
9
  # HexaPDF is free software: you can redistribute it and/or modify it
10
10
  # under the terms of the GNU Affero General Public License version 3 as
@@ -1,10 +1,10 @@
1
- # -*- encoding: utf-8 -*-
1
+ # -*- encoding: utf-8; frozen_string_literal: true -*-
2
2
  #
3
3
  #--
4
4
  # This file is part of HexaPDF.
5
5
  #
6
6
  # HexaPDF - A Versatile PDF Creation and Manipulation Library For Ruby
7
- # Copyright (C) 2014-2017 Thomas Leitner
7
+ # Copyright (C) 2014-2018 Thomas Leitner
8
8
  #
9
9
  # HexaPDF is free software: you can redistribute it and/or modify it
10
10
  # under the terms of the GNU Affero General Public License version 3 as
@@ -1,10 +1,10 @@
1
- # -*- encoding: utf-8 -*-
1
+ # -*- encoding: utf-8; frozen_string_literal: true -*-
2
2
  #
3
3
  #--
4
4
  # This file is part of HexaPDF.
5
5
  #
6
6
  # HexaPDF - A Versatile PDF Creation and Manipulation Library For Ruby
7
- # Copyright (C) 2014-2017 Thomas Leitner
7
+ # Copyright (C) 2014-2018 Thomas Leitner
8
8
  #
9
9
  # HexaPDF is free software: you can redistribute it and/or modify it
10
10
  # under the terms of the GNU Affero General Public License version 3 as
@@ -1,10 +1,10 @@
1
- # -*- encoding: utf-8 -*-
1
+ # -*- encoding: utf-8; frozen_string_literal: true -*-
2
2
  #
3
3
  #--
4
4
  # This file is part of HexaPDF.
5
5
  #
6
6
  # HexaPDF - A Versatile PDF Creation and Manipulation Library For Ruby
7
- # Copyright (C) 2014-2017 Thomas Leitner
7
+ # Copyright (C) 2014-2018 Thomas Leitner
8
8
  #
9
9
  # HexaPDF is free software: you can redistribute it and/or modify it
10
10
  # under the terms of the GNU Affero General Public License version 3 as
@@ -1,10 +1,10 @@
1
- # -*- encoding: utf-8 -*-
1
+ # -*- encoding: utf-8; frozen_string_literal: true -*-
2
2
  #
3
3
  #--
4
4
  # This file is part of HexaPDF.
5
5
  #
6
6
  # HexaPDF - A Versatile PDF Creation and Manipulation Library For Ruby
7
- # Copyright (C) 2014-2017 Thomas Leitner
7
+ # Copyright (C) 2014-2018 Thomas Leitner
8
8
  #
9
9
  # HexaPDF is free software: you can redistribute it and/or modify it
10
10
  # under the terms of the GNU Affero General Public License version 3 as
@@ -48,7 +48,7 @@ module HexaPDF
48
48
 
49
49
  define_type :Catalog
50
50
 
51
- define_field :Type, type: Symbol, required: true, default: self.type
51
+ define_field :Type, type: Symbol, required: true, default: type
52
52
  define_field :Version, type: Symbol, version: '1.4'
53
53
  define_field :Extensions, type: Dictionary, version: '1.7'
54
54
  # Pages field is required but this is handled in #perform_validation
@@ -99,7 +99,7 @@ module HexaPDF
99
99
  unless key?(:Pages)
100
100
  yield("A PDF document needs a page tree", true)
101
101
  value[:Pages] = document.add(Type: :Pages)
102
- value[:Pages].validate {|msg, correctable| yield(msg, correctable)}
102
+ value[:Pages].validate {|msg, correctable| yield(msg, correctable) }
103
103
  end
104
104
  end
105
105
 
@@ -1,10 +1,10 @@
1
- # -*- encoding: utf-8 -*-
1
+ # -*- encoding: utf-8; frozen_string_literal: true -*-
2
2
  #
3
3
  #--
4
4
  # This file is part of HexaPDF.
5
5
  #
6
6
  # HexaPDF - A Versatile PDF Creation and Manipulation Library For Ruby
7
- # Copyright (C) 2014-2017 Thomas Leitner
7
+ # Copyright (C) 2014-2018 Thomas Leitner
8
8
  #
9
9
  # HexaPDF is free software: you can redistribute it and/or modify it
10
10
  # under the terms of the GNU Affero General Public License version 3 as
@@ -51,7 +51,6 @@ module HexaPDF
51
51
  define_field :DW2, type: Array, default: [880, -1100]
52
52
  define_field :W2, type: Array
53
53
 
54
-
55
54
  # Returns the unscaled width of the given CID in glyph units, or 0 if the width for the CID is
56
55
  # missing.
57
56
  #
@@ -101,11 +100,11 @@ module HexaPDF
101
100
  entry = array[index]
102
101
  value = array[index + 1]
103
102
  if value.kind_of?(Array)
104
- value.each_with_index {|width, i| result[entry + i] = width}
103
+ value.each_with_index {|width, i| result[entry + i] = width }
105
104
  index += 2
106
105
  else
107
106
  width = array[index + 2]
108
- entry.upto(value) {|cid| result[cid] = width}
107
+ entry.upto(value) {|cid| result[cid] = width }
109
108
  index += 3
110
109
  end
111
110
  end
@@ -1,10 +1,10 @@
1
- # -*- encoding: utf-8 -*-
1
+ # -*- encoding: utf-8; frozen_string_literal: true -*-
2
2
  #
3
3
  #--
4
4
  # This file is part of HexaPDF.
5
5
  #
6
6
  # HexaPDF - A Versatile PDF Creation and Manipulation Library For Ruby
7
- # Copyright (C) 2014-2017 Thomas Leitner
7
+ # Copyright (C) 2014-2018 Thomas Leitner
8
8
  #
9
9
  # HexaPDF is free software: you can redistribute it and/or modify it
10
10
  # under the terms of the GNU Affero General Public License version 3 as
@@ -72,7 +72,7 @@ module HexaPDF
72
72
 
73
73
  define_type :EmbeddedFile
74
74
 
75
- define_field :Type, type: Symbol, default: self.type, version: '1.3'
75
+ define_field :Type, type: Symbol, default: type, version: '1.3'
76
76
  define_field :Subtype, type: Symbol
77
77
  define_field :Params, type: :XXEmbeddedFileParameters
78
78
 
@@ -1,10 +1,10 @@
1
- # -*- encoding: utf-8 -*-
1
+ # -*- encoding: utf-8; frozen_string_literal: true -*-
2
2
  #
3
3
  #--
4
4
  # This file is part of HexaPDF.
5
5
  #
6
6
  # HexaPDF - A Versatile PDF Creation and Manipulation Library For Ruby
7
- # Copyright (C) 2014-2017 Thomas Leitner
7
+ # Copyright (C) 2014-2018 Thomas Leitner
8
8
  #
9
9
  # HexaPDF is free software: you can redistribute it and/or modify it
10
10
  # under the terms of the GNU Affero General Public License version 3 as
@@ -75,7 +75,7 @@ module HexaPDF
75
75
 
76
76
  define_type :Filespec
77
77
 
78
- define_field :Type, type: Symbol, default: self.type, required: true
78
+ define_field :Type, type: Symbol, default: type, required: true
79
79
  define_field :FS, type: Symbol
80
80
  define_field :F, type: PDFByteString
81
81
  define_field :UF, type: String, version: '1.7'
@@ -89,7 +89,6 @@ module HexaPDF
89
89
  define_field :Desc, type: String, version: '1.6'
90
90
  define_field :CI, type: Dictionary, version: '1.7'
91
91
 
92
-
93
92
  # Returns +true+ if this file specification references an URL and not a file.
94
93
  def url?
95
94
  self[:FS] == :URL
@@ -130,7 +129,7 @@ module HexaPDF
130
129
  begin
131
130
  URI(url)
132
131
  rescue URI::InvalidURIError => e
133
- raise HexaPDF::Error.new(e)
132
+ raise HexaPDF::Error, e
134
133
  end
135
134
  self.path = url
136
135
  self[:FS] = :URL
@@ -214,11 +213,11 @@ module HexaPDF
214
213
  # in the EmbeddedFiles name tree is also deleted.
215
214
  def unembed
216
215
  return unless key?(:EF)
217
- self[:EF].each {|_key, ef_stream| document.delete(ef_stream)}
216
+ self[:EF].each {|_, ef_stream| document.delete(ef_stream) }
218
217
 
219
218
  if document.catalog.key?(:Names) && document.catalog[:Names].key?(:EmbeddedFiles)
220
219
  tree = document.catalog[:Names][:EmbeddedFiles]
221
- tree.each_entry.find_all {|_, spec| document.deref(spec) == self}.each do |name, _|
220
+ tree.each_entry.find_all {|_, spec| document.deref(spec) == self }.each do |(name, _)|
222
221
  tree.delete_entry(name)
223
222
  end
224
223
  end
@@ -1,10 +1,10 @@
1
- # -*- encoding: utf-8 -*-
1
+ # -*- encoding: utf-8; frozen_string_literal: true -*-
2
2
  #
3
3
  #--
4
4
  # This file is part of HexaPDF.
5
5
  #
6
6
  # HexaPDF - A Versatile PDF Creation and Manipulation Library For Ruby
7
- # Copyright (C) 2014-2017 Thomas Leitner
7
+ # Copyright (C) 2014-2018 Thomas Leitner
8
8
  #
9
9
  # HexaPDF is free software: you can redistribute it and/or modify it
10
10
  # under the terms of the GNU Affero General Public License version 3 as
@@ -44,7 +44,7 @@ module HexaPDF
44
44
 
45
45
  define_type :Font
46
46
 
47
- define_field :Type, type: Symbol, required: true, default: self.type
47
+ define_field :Type, type: Symbol, required: true, default: type
48
48
  define_field :BaseFont, type: Symbol, required: true
49
49
  define_field :ToUnicode, type: Stream, version: '1.2'
50
50
 
@@ -56,7 +56,7 @@ module HexaPDF
56
56
  # Returns the UTF-8 string for the given character code, or calls the configuration option
57
57
  # 'font.on_missing_unicode_mapping' if no mapping was found.
58
58
  def to_utf8(code)
59
- to_unicode_cmap && to_unicode_cmap.to_unicode(code) || missing_unicode_mapping(code)
59
+ to_unicode_cmap&.to_unicode(code) || missing_unicode_mapping(code)
60
60
  end
61
61
 
62
62
  # Returns the bounding box of the font or +nil+ if it is not found.
@@ -1,10 +1,10 @@
1
- # -*- encoding: utf-8 -*-
1
+ # -*- encoding: utf-8; frozen_string_literal: true -*-
2
2
  #
3
3
  #--
4
4
  # This file is part of HexaPDF.
5
5
  #
6
6
  # HexaPDF - A Versatile PDF Creation and Manipulation Library For Ruby
7
- # Copyright (C) 2014-2017 Thomas Leitner
7
+ # Copyright (C) 2014-2018 Thomas Leitner
8
8
  #
9
9
  # HexaPDF is free software: you can redistribute it and/or modify it
10
10
  # under the terms of the GNU Affero General Public License version 3 as
@@ -48,7 +48,7 @@ module HexaPDF
48
48
 
49
49
  define_type :FontDescriptor
50
50
 
51
- define_field :Type, type: Symbol, required: true, default: self.type
51
+ define_field :Type, type: Symbol, required: true, default: type
52
52
  define_field :FontName, type: Symbol, required: true
53
53
  define_field :FontFamily, type: PDFByteString, version: '1.5'
54
54
  define_field :FontStretch, type: Symbol, version: '1.5'
@@ -76,7 +76,6 @@ module HexaPDF
76
76
  define_field :FD, type: Dictionary
77
77
  define_field :CIDSet, type: Stream
78
78
 
79
-
80
79
  bit_field(:raw_flags, {fixed_pitch: 0, serif: 1, symbolic: 2, script: 3, nonsymbolic: 5,
81
80
  italic: 6, all_cap: 16, small_cap: 17, force_bold: 18},
82
81
  lister: "flags", getter: "flagged?", setter: "flag")
@@ -1,10 +1,10 @@
1
- # -*- encoding: utf-8 -*-
1
+ # -*- encoding: utf-8; frozen_string_literal: true -*-
2
2
  #
3
3
  #--
4
4
  # This file is part of HexaPDF.
5
5
  #
6
6
  # HexaPDF - A Versatile PDF Creation and Manipulation Library For Ruby
7
- # Copyright (C) 2014-2017 Thomas Leitner
7
+ # Copyright (C) 2014-2018 Thomas Leitner
8
8
  #
9
9
  # HexaPDF is free software: you can redistribute it and/or modify it
10
10
  # under the terms of the GNU Affero General Public License version 3 as
@@ -61,15 +61,12 @@ module HexaPDF
61
61
  encoding = encoding_from_font if encoding.nil?
62
62
  encoding
63
63
  when HexaPDF::Dictionary, Hash
64
- encoding = val[:BaseEncoding]
65
- encoding = HexaPDF::Font::Encoding.for_name(encoding) if encoding
66
- unless encoding
67
- if embedded? || symbolic?
68
- encoding = encoding_from_font
69
- else
70
- encoding = HexaPDF::Font::Encoding.for_name(:StandardEncoding)
71
- end
72
- end
64
+ encoding = val[:BaseEncoding] && HexaPDF::Font::Encoding.for_name(val[:BaseEncoding])
65
+ encoding ||= if embedded? || symbolic?
66
+ encoding_from_font
67
+ else
68
+ HexaPDF::Font::Encoding.for_name(:StandardEncoding)
69
+ end
73
70
  encoding = difference_encoding(encoding, val[:Differences]) if val.key?(:Differences)
74
71
  encoding
75
72
  when nil
@@ -88,16 +85,15 @@ module HexaPDF
88
85
  # Returns the UTF-8 string for the given character code, or calls the configuration option
89
86
  # 'font.on_missing_unicode_mapping' if no mapping was found.
90
87
  def to_utf8(code)
91
- (to_unicode_cmap && to_unicode_cmap.to_unicode(code)) ||
92
- encoding.unicode(code) || missing_unicode_mapping(code)
88
+ to_unicode_cmap&.to_unicode(code) || encoding.unicode(code) || missing_unicode_mapping(code)
93
89
  end
94
90
 
95
91
  # Returns the unscaled width of the given code point in glyph units, or 0 if the width for
96
92
  # the code point is missing.
97
93
  def width(code)
98
94
  widths = self[:Widths]
99
- first_char = self[:FirstChar] || -1
100
- last_char = self[:LastChar] || -1
95
+ first_char = self[:FirstChar]
96
+ last_char = self[:LastChar]
101
97
 
102
98
  if widths && code >= first_char && code <= last_char
103
99
  widths[code - first_char]
@@ -116,7 +112,7 @@ module HexaPDF
116
112
  # Returns +true+ if the font is a symbolic font, +false+ if it is not, and +nil+ if it is
117
113
  # not known.
118
114
  def symbolic?
119
- self[:FontDescriptor] && self[:FontDescriptor].flagged?(:symbolic) || nil
115
+ self[:FontDescriptor]&.flagged?(:symbolic)
120
116
  end
121
117
 
122
118
  # Returns whether word spacing is applicable when using this font.
@@ -1,10 +1,10 @@
1
- # -*- encoding: utf-8 -*-
1
+ # -*- encoding: utf-8; frozen_string_literal: true -*-
2
2
  #
3
3
  #--
4
4
  # This file is part of HexaPDF.
5
5
  #
6
6
  # HexaPDF - A Versatile PDF Creation and Manipulation Library For Ruby
7
- # Copyright (C) 2014-2017 Thomas Leitner
7
+ # Copyright (C) 2014-2018 Thomas Leitner
8
8
  #
9
9
  # HexaPDF is free software: you can redistribute it and/or modify it
10
10
  # under the terms of the GNU Affero General Public License version 3 as
@@ -1,10 +1,10 @@
1
- # -*- encoding: utf-8 -*-
1
+ # -*- encoding: utf-8; frozen_string_literal: true -*-
2
2
  #
3
3
  #--
4
4
  # This file is part of HexaPDF.
5
5
  #
6
6
  # HexaPDF - A Versatile PDF Creation and Manipulation Library For Ruby
7
- # Copyright (C) 2014-2017 Thomas Leitner
7
+ # Copyright (C) 2014-2018 Thomas Leitner
8
8
  #
9
9
  # HexaPDF is free software: you can redistribute it and/or modify it
10
10
  # under the terms of the GNU Affero General Public License version 3 as
@@ -72,8 +72,8 @@ module HexaPDF
72
72
  # Returns the UTF-8 string for the given code, or calls the configuration option
73
73
  # 'font.on_missing_unicode_mapping' if no mapping was found.
74
74
  def to_utf8(code)
75
- (to_unicode_cmap && to_unicode_cmap.to_unicode(code)) ||
76
- (ucs2_cmap && ucs2_cmap.to_unicode(code)) || missing_unicode_mapping(code)
75
+ to_unicode_cmap&.to_unicode(code) || ucs2_cmap&.to_unicode(code) ||
76
+ missing_unicode_mapping(code)
77
77
  end
78
78
 
79
79
  # Returns the unscaled width of the given CID in glyph units, or 0 if the width for the code
@@ -103,7 +103,7 @@ module HexaPDF
103
103
  #
104
104
  # See: PDF1.7 s9.3.3
105
105
  def word_spacing_applicable?
106
- @word_spacing_applicable ||= ((cmap.read_codes("\x20".freeze) && true) rescue false)
106
+ @word_spacing_applicable ||= ((cmap.read_codes("\x20") && true) rescue false)
107
107
  end
108
108
 
109
109
  private
@@ -1,10 +1,10 @@
1
- # -*- encoding: utf-8 -*-
1
+ # -*- encoding: utf-8; frozen_string_literal: true -*-
2
2
  #
3
3
  #--
4
4
  # This file is part of HexaPDF.
5
5
  #
6
6
  # HexaPDF - A Versatile PDF Creation and Manipulation Library For Ruby
7
- # Copyright (C) 2014-2017 Thomas Leitner
7
+ # Copyright (C) 2014-2018 Thomas Leitner
8
8
  #
9
9
  # HexaPDF is free software: you can redistribute it and/or modify it
10
10
  # under the terms of the GNU Affero General Public License version 3 as
@@ -65,10 +65,10 @@ module HexaPDF
65
65
  %s(TimesNewRoman,Bold) => %s(Times-Bold),
66
66
  %s(TimesNewRoman,BoldItalic) => %s(Times-BoldItalic),
67
67
  }
68
- %i(Times-Roman Times-Bold Times-Italic Times-BoldItalic
68
+ %i[Times-Roman Times-Bold Times-Italic Times-BoldItalic
69
69
  Helvetica Helvetica-Bold Helvetica-Oblique Helvetica-BoldOblique
70
70
  Courier Courier-Bold Courier-Oblique Courier-BoldOblique
71
- Symbol ZapfDingbats).each {|name| @mapping[name] = name}
71
+ Symbol ZapfDingbats].each {|name| @mapping[name] = name }
72
72
 
73
73
  # Returns +true+ if the given name is the name of a standard font.
74
74
  def self.standard_font?(name)
@@ -1,10 +1,10 @@
1
- # -*- encoding: utf-8 -*-
1
+ # -*- encoding: utf-8; frozen_string_literal: true -*-
2
2
  #
3
3
  #--
4
4
  # This file is part of HexaPDF.
5
5
  #
6
6
  # HexaPDF - A Versatile PDF Creation and Manipulation Library For Ruby
7
- # Copyright (C) 2014-2017 Thomas Leitner
7
+ # Copyright (C) 2014-2018 Thomas Leitner
8
8
  #
9
9
  # HexaPDF is free software: you can redistribute it and/or modify it
10
10
  # under the terms of the GNU Affero General Public License version 3 as
@@ -44,7 +44,7 @@ module HexaPDF
44
44
 
45
45
  define_type :XObject
46
46
 
47
- define_field :Type, type: Symbol, default: self.type
47
+ define_field :Type, type: Symbol, default: type
48
48
  define_field :Subtype, type: Symbol, required: true, default: :Form
49
49
  define_field :FormType, type: Integer, default: 1
50
50
  define_field :BBox, type: Rectangle, required: true
@@ -1,10 +1,10 @@
1
- # -*- encoding: utf-8 -*-
1
+ # -*- encoding: utf-8; frozen_string_literal: true -*-
2
2
  #
3
3
  #--
4
4
  # This file is part of HexaPDF.
5
5
  #
6
6
  # HexaPDF - A Versatile PDF Creation and Manipulation Library For Ruby
7
- # Copyright (C) 2014-2017 Thomas Leitner
7
+ # Copyright (C) 2014-2018 Thomas Leitner
8
8
  #
9
9
  # HexaPDF is free software: you can redistribute it and/or modify it
10
10
  # under the terms of the GNU Affero General Public License version 3 as
@@ -47,7 +47,7 @@ module HexaPDF
47
47
 
48
48
  define_type :ExtGState
49
49
 
50
- define_field :Type, type: Symbol, required: true, default: self.type
50
+ define_field :Type, type: Symbol, required: true, default: type
51
51
  define_field :LW, type: Numeric, version: "1.3"
52
52
  define_field :LC, type: Integer, version: "1.3"
53
53
  define_field :LJ, type: Integer, version: "1.3"
@@ -1,10 +1,10 @@
1
- # -*- encoding: utf-8 -*-
1
+ # -*- encoding: utf-8; frozen_string_literal: true -*-
2
2
  #
3
3
  #--
4
4
  # This file is part of HexaPDF.
5
5
  #
6
6
  # HexaPDF - A Versatile PDF Creation and Manipulation Library For Ruby
7
- # Copyright (C) 2014-2017 Thomas Leitner
7
+ # Copyright (C) 2014-2018 Thomas Leitner
8
8
  #
9
9
  # HexaPDF is free software: you can redistribute it and/or modify it
10
10
  # under the terms of the GNU Affero General Public License version 3 as
@@ -50,7 +50,7 @@ module HexaPDF
50
50
 
51
51
  define_type :XObject
52
52
 
53
- define_field :Type, type: Symbol, default: self.type
53
+ define_field :Type, type: Symbol, default: type
54
54
  define_field :Subtype, type: Symbol, required: true, default: :Image
55
55
  define_field :Width, type: Integer, required: true
56
56
  define_field :Height, type: Integer, required: true
@@ -112,17 +112,17 @@ module HexaPDF
112
112
  case filter
113
113
  when :DCTDecode
114
114
  result.type = :jpeg
115
- result.extension = 'jpg'.freeze
115
+ result.extension = 'jpg'
116
116
  when :JPXDecode
117
117
  result.type = :jp2
118
- result.extension = 'jpx'.freeze
118
+ result.extension = 'jpx'
119
119
  when :JBIG2Decode
120
120
  result.type = :jbig2
121
121
  when :CCITTFaxDecode
122
122
  result.type = :ccitt
123
123
  else
124
124
  result.type = :png
125
- result.extension = 'png'.freeze
125
+ result.extension = 'png'
126
126
  end
127
127
 
128
128
  if rest || ![:FlateDecode, :DCTDecode, :JPXDecode, nil].include?(filter)
@@ -177,7 +177,7 @@ module HexaPDF
177
177
  end
178
178
 
179
179
  io = if name_or_io.kind_of?(String)
180
- File.open(name_or_io.sub(/\.#{info.extension}\z/, '') + "." + info.extension, "wb")
180
+ File.open(name_or_io.sub(/\.#{info.extension}\z/, '') << "." << info.extension, "wb")
181
181
  else
182
182
  name_or_io
183
183
  end
@@ -226,14 +226,14 @@ module HexaPDF
226
226
  if info.color_space == :rgb
227
227
  palette = palette_data[0, palette_data.length - palette_data.length % 3]
228
228
  else
229
- palette_data.each_byte {|byte| palette << byte << byte << byte}
229
+ palette_data.each_byte {|byte| palette << byte << byte << byte }
230
230
  end
231
231
  io << png_chunk('PLTE', palette)
232
232
  end
233
233
 
234
- if self[:Mask].kind_of?(Array) && self[:Mask].each_slice(2).all? {|a, b| a == b} &&
234
+ if self[:Mask].kind_of?(Array) && self[:Mask].each_slice(2).all? {|a, b| a == b } &&
235
235
  (color_type == ImageLoader::PNG::TRUECOLOR || color_type == ImageLoader::PNG::GREYSCALE)
236
- io << png_chunk('tRNS', self[:Mask].each_slice(2).map {|a, _| a}.pack('n*'))
236
+ io << png_chunk('tRNS', self[:Mask].each_slice(2).map {|a, _| a }.pack('n*'))
237
237
  end
238
238
 
239
239
  filter, = *self[:Filter]
@@ -246,13 +246,12 @@ module HexaPDF
246
246
  end
247
247
  io << png_chunk('IDAT', Filter.string_from_source(data))
248
248
 
249
- io << png_chunk('IEND', '')
249
+ io << png_chunk('IEND')
250
250
  end
251
251
 
252
252
  # Returns the binary representation of the PNG chunk for the given chunk type and data.
253
- def png_chunk(type, data = nil)
254
- [data.to_s.length].pack("N") << type << data.to_s <<
255
- [Zlib.crc32(data, Zlib.crc32(type))].pack("N")
253
+ def png_chunk(type, data = '')
254
+ [data.length].pack("N") << type << data << [Zlib.crc32(data, Zlib.crc32(type))].pack("N")
256
255
  end
257
256
 
258
257
  end