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
@@ -82,7 +82,6 @@ module HexaPDF
82
82
  Writer.new.create_to_unicode_cmap(mapping)
83
83
  end
84
84
 
85
-
86
85
  # The registry part of the CMap version.
87
86
  attr_accessor :registry
88
87
 
@@ -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
@@ -49,20 +49,20 @@ module HexaPDF
49
49
  tokenizer = HexaPDF::Content::Tokenizer.new(string)
50
50
  cmap = CMap.new
51
51
 
52
- while (token = tokenizer.next_token) != HexaPDF::Tokenizer::NO_MORE_TOKENS
52
+ until (token = tokenizer.next_token) == HexaPDF::Tokenizer::NO_MORE_TOKENS
53
53
  if token.kind_of?(HexaPDF::Tokenizer::Token)
54
54
  case token
55
- when 'beginbfchar'.freeze then parse_bf_char(tokenizer, cmap)
56
- when 'beginbfrange'.freeze then parse_bf_range(tokenizer, cmap)
57
- when 'begincidchar'.freeze then parse_cid_char(tokenizer, cmap)
58
- when 'begincidrange'.freeze then parse_cid_range(tokenizer, cmap)
59
- when 'begincodespacerange'.freeze then parse_codespace_range(tokenizer, cmap)
55
+ when 'beginbfchar' then parse_bf_char(tokenizer, cmap)
56
+ when 'beginbfrange' then parse_bf_range(tokenizer, cmap)
57
+ when 'begincidchar' then parse_cid_char(tokenizer, cmap)
58
+ when 'begincidrange' then parse_cid_range(tokenizer, cmap)
59
+ when 'begincodespacerange' then parse_codespace_range(tokenizer, cmap)
60
60
  when 'endcmap' then break
61
61
  end
62
62
  elsif token.kind_of?(Symbol)
63
63
  value = tokenizer.next_token
64
64
  if value.kind_of?(HexaPDF::Tokenizer::Token)
65
- parse_cmap(cmap, token) if value == 'usecmap'.freeze
65
+ parse_cmap(cmap, token) if value == 'usecmap'
66
66
  else
67
67
  parse_dict_mapping(cmap, token, value)
68
68
  end
@@ -70,7 +70,7 @@ module HexaPDF
70
70
  end
71
71
 
72
72
  cmap
73
- rescue => e
73
+ rescue StandardError => e
74
74
  raise HexaPDF::Error, "Error parsing CMap: #{e.message}", e.backtrace
75
75
  end
76
76
 
@@ -162,7 +162,7 @@ module HexaPDF
162
162
  if dest.kind_of?(String)
163
163
  codepoint = dest.force_encoding(::Encoding::UTF_16BE).ord
164
164
  code1.upto(code2) do |code|
165
- cmap.add_unicode_mapping(code, '' << codepoint)
165
+ cmap.add_unicode_mapping(code, +'' << codepoint)
166
166
  codepoint += 1
167
167
  end
168
168
  elsif dest.kind_of?(Array)
@@ -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
@@ -57,14 +57,14 @@ module HexaPDF
57
57
  result = create_sections("bfchar", chars.size / 2) do |index|
58
58
  index *= 2
59
59
  sprintf("<%04X>", chars[index]) << "<" <<
60
- (''.force_encoding(::Encoding::UTF_16BE) << chars[index + 1]).unpack('H*').first <<
60
+ ((+'').force_encoding(::Encoding::UTF_16BE) << chars[index + 1]).unpack('H*').first <<
61
61
  ">\n"
62
62
  end
63
63
 
64
64
  result << create_sections("bfrange", ranges.size / 3) do |index|
65
65
  index *= 3
66
66
  sprintf("<%04X><%04X>", ranges[index], ranges[index + 1]) << "<" <<
67
- (''.force_encoding(::Encoding::UTF_16BE) << ranges[index + 2]).unpack('H*').first <<
67
+ ((+'').force_encoding(::Encoding::UTF_16BE) << ranges[index + 2]).unpack('H*').first <<
68
68
  ">\n"
69
69
  end
70
70
 
@@ -129,12 +129,12 @@ module HexaPDF
129
129
  def create_sections(type, size)
130
130
  return '' if size == 0
131
131
 
132
- result = ""
132
+ result = +""
133
133
  index = 0
134
134
  while size > 0
135
135
  count = [MAX_ENTRIES_IN_SECTION, size].min
136
136
  result << "#{count} begin#{type}\n"
137
- index.upto(index + count - 1) {|i| result << yield(i)}
137
+ index.upto(index + count - 1) {|i| result << yield(i) }
138
138
  result << "end#{type}\n"
139
139
  index += count
140
140
  size -= count
@@ -145,25 +145,25 @@ module HexaPDF
145
145
 
146
146
  # Returns the CMap file template for a ToUnicode CMap.
147
147
  def to_unicode_template
148
- <<-TEMPLATE
149
- /CIDInit /ProcSet findresource begin
150
- 12 dict begin
151
- begincmap
152
- /CIDSystemInfo
153
- << /Registry (Adobe)
154
- /Ordering (UCS)
155
- /Supplement 0
156
- >> def
157
- /CMapName /Adobe-Identity-UCS def
158
- /CMapType 2 def
159
- 1 begincodespacerange
160
- <0000> <FFFF>
161
- endcodespacerange
162
- %s
163
- endcmap
164
- CMapName currentdict /CMap defineresource pop
165
- end
166
- end
148
+ <<~TEMPLATE
149
+ /CIDInit /ProcSet findresource begin
150
+ 12 dict begin
151
+ begincmap
152
+ /CIDSystemInfo
153
+ << /Registry (Adobe)
154
+ /Ordering (UCS)
155
+ /Supplement 0
156
+ >> def
157
+ /CMapName /Adobe-Identity-UCS def
158
+ /CMapType 2 def
159
+ 1 begincodespacerange
160
+ <0000> <FFFF>
161
+ endcodespacerange
162
+ %s
163
+ endcmap
164
+ CMapName currentdict /CMap defineresource pop
165
+ end
166
+ end
167
167
  TEMPLATE
168
168
  end
169
169
 
@@ -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
@@ -87,7 +87,7 @@ module HexaPDF
87
87
  else
88
88
  name = name.to_s
89
89
  if name =~ /\Auni([0-9A-F]{4})\Z/ || name =~ /\Au([0-9A-f]{4,6})\Z/
90
- '' << $1.hex
90
+ +'' << $1.hex
91
91
  end
92
92
  end
93
93
  end
@@ -130,10 +130,10 @@ module HexaPDF
130
130
  uni2name = {}
131
131
  File.open(file, 'rb') do |f|
132
132
  while (line = f.gets)
133
- next if line.start_with?('#'.freeze)
134
- index = line.index(';'.freeze)
133
+ next if line.start_with?('#')
134
+ index = line.index(';')
135
135
  name = line[0, index].to_sym
136
- codes = line[index + 1, 50].split(" ".freeze).map(&:hex).pack('U*'.freeze)
136
+ codes = line[index + 1, 50].split(" ").map(&:hex).pack('U*')
137
137
  name2uni[name] = codes
138
138
  uni2name[codes] = name unless uni2name.key?(codes)
139
139
  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
@@ -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
@@ -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,16 +51,16 @@ module HexaPDF
51
51
  def id
52
52
  @font.missing_glyph_id
53
53
  end
54
- alias_method :name, :id
54
+ alias name id
55
55
 
56
56
  # Returns 0.
57
57
  def x_min
58
58
  0
59
59
  end
60
- alias_method :x_max, :x_min
61
- alias_method :y_min, :x_min
62
- alias_method :y_max, :x_min
63
- alias_method :width, :x_min
60
+ alias x_max x_min
61
+ alias y_min x_min
62
+ alias y_max x_min
63
+ alias width x_min
64
64
 
65
65
  # Word spacing is never applied for the invalid glyph, so +false+ is returned.
66
66
  def apply_word_spacing?
@@ -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
@@ -51,19 +51,25 @@ module HexaPDF
51
51
  offset = font_data.length + tables.length * 16
52
52
  checksum = Table.calculate_checksum(font_data)
53
53
 
54
- # prepare head table for checksumming
55
- tables['head'][8, 4] = "\0\0\0\0"
54
+ # Prepare head table for checksumming
55
+ head_table = tables['head']
56
+ head_table[8, 4] = "\0\0\0\0"
57
+
58
+ # The directory table needs to be sorted in ascending order by tag
59
+ tables = tables.sort
56
60
 
57
61
  tables.each do |tag, data|
62
+ original_data_length = data.length
58
63
  table_checksum = Table.calculate_checksum(data)
64
+ data << "\0" * (4 - original_data_length % 4) if original_data_length % 4 != 0
59
65
  # tag, offset, data.length are all 32bit uint, table_checksum for header and body
60
66
  checksum += tag.unpack('N').first + 2 * table_checksum + offset + data.length
61
- font_data << [tag, table_checksum, offset, data.length].pack('a4N3')
67
+ font_data << [tag, table_checksum, offset, original_data_length].pack('a4N3')
62
68
  offset += data.length
63
69
  end
64
70
 
65
- tables['head'][8, 4] = [0xB1B0AFBA - checksum].pack('N')
66
- tables.each_value {|data| font_data << data}
71
+ head_table[8, 4] = [0xB1B0AFBA - checksum].pack('N')
72
+ tables.each {|_, data| font_data << data }
67
73
 
68
74
  font_data
69
75
  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
@@ -66,7 +66,6 @@ module HexaPDF
66
66
  'font.true_type.unknown_format' => :ignore,
67
67
  }
68
68
 
69
-
70
69
  # The IO stream associated with this file.
71
70
  attr_reader :io
72
71