prawn 2.1.0 → 2.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (280) hide show
  1. checksums.yaml +5 -5
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/GPLv2 +20 -21
  5. data/Gemfile +3 -9
  6. data/Rakefile +20 -23
  7. data/lib/prawn.rb +36 -49
  8. data/lib/prawn/document.rb +180 -133
  9. data/lib/prawn/document/bounding_box.rb +41 -29
  10. data/lib/prawn/document/column_box.rb +7 -7
  11. data/lib/prawn/document/internals.rb +8 -6
  12. data/lib/prawn/document/span.rb +21 -16
  13. data/lib/prawn/encoding.rb +69 -68
  14. data/lib/prawn/errors.rb +12 -7
  15. data/lib/prawn/font.rb +102 -69
  16. data/lib/prawn/font_metric_cache.rb +14 -8
  17. data/lib/prawn/{font → fonts}/afm.rb +102 -68
  18. data/lib/prawn/{font → fonts}/dfont.rb +5 -11
  19. data/lib/prawn/fonts/otf.rb +11 -0
  20. data/lib/prawn/fonts/ttc.rb +36 -0
  21. data/lib/prawn/{font → fonts}/ttf.rb +87 -68
  22. data/lib/prawn/graphics.rb +119 -81
  23. data/lib/prawn/graphics/blend_mode.rb +9 -8
  24. data/lib/prawn/graphics/cap_style.rb +3 -3
  25. data/lib/prawn/graphics/color.rb +27 -25
  26. data/lib/prawn/graphics/dash.rb +23 -11
  27. data/lib/prawn/graphics/join_style.rb +9 -3
  28. data/lib/prawn/graphics/patterns.rb +190 -96
  29. data/lib/prawn/graphics/transformation.rb +15 -9
  30. data/lib/prawn/graphics/transparency.rb +17 -13
  31. data/lib/prawn/grid.rb +48 -47
  32. data/lib/prawn/image_handler.rb +5 -5
  33. data/lib/prawn/images.rb +39 -30
  34. data/lib/prawn/images/image.rb +2 -1
  35. data/lib/prawn/images/jpg.rb +28 -22
  36. data/lib/prawn/images/png.rb +65 -62
  37. data/lib/prawn/measurement_extensions.rb +10 -9
  38. data/lib/prawn/measurements.rb +19 -15
  39. data/lib/prawn/outline.rb +97 -77
  40. data/lib/prawn/repeater.rb +14 -10
  41. data/lib/prawn/security.rb +81 -61
  42. data/lib/prawn/security/arcfour.rb +2 -2
  43. data/lib/prawn/soft_mask.rb +26 -26
  44. data/lib/prawn/stamp.rb +20 -13
  45. data/lib/prawn/text.rb +68 -52
  46. data/lib/prawn/text/box.rb +11 -8
  47. data/lib/prawn/text/formatted.rb +5 -5
  48. data/lib/prawn/text/formatted/arranger.rb +53 -32
  49. data/lib/prawn/text/formatted/box.rb +134 -100
  50. data/lib/prawn/text/formatted/fragment.rb +11 -14
  51. data/lib/prawn/text/formatted/line_wrap.rb +122 -63
  52. data/lib/prawn/text/formatted/parser.rb +139 -117
  53. data/lib/prawn/text/formatted/wrap.rb +43 -31
  54. data/lib/prawn/transformation_stack.rb +7 -5
  55. data/lib/prawn/utilities.rb +7 -22
  56. data/lib/prawn/version.rb +2 -2
  57. data/lib/prawn/view.rb +17 -7
  58. data/manual/basic_concepts/adding_pages.rb +6 -7
  59. data/manual/basic_concepts/basic_concepts.rb +31 -22
  60. data/manual/basic_concepts/creation.rb +10 -11
  61. data/manual/basic_concepts/cursor.rb +4 -5
  62. data/manual/basic_concepts/measurement.rb +6 -7
  63. data/manual/basic_concepts/origin.rb +5 -6
  64. data/manual/basic_concepts/other_cursor_helpers.rb +11 -12
  65. data/manual/basic_concepts/view.rb +22 -16
  66. data/manual/bounding_box/bounding_box.rb +29 -24
  67. data/manual/bounding_box/bounds.rb +11 -12
  68. data/manual/bounding_box/canvas.rb +4 -5
  69. data/manual/bounding_box/creation.rb +6 -7
  70. data/manual/bounding_box/indentation.rb +14 -15
  71. data/manual/bounding_box/nesting.rb +24 -17
  72. data/manual/bounding_box/russian_boxes.rb +14 -13
  73. data/manual/bounding_box/stretchy.rb +12 -13
  74. data/manual/contents.rb +28 -22
  75. data/manual/cover.rb +33 -28
  76. data/manual/document_and_page_options/background.rb +11 -13
  77. data/manual/document_and_page_options/document_and_page_options.rb +25 -20
  78. data/manual/document_and_page_options/metadata.rb +18 -16
  79. data/manual/document_and_page_options/page_margins.rb +18 -20
  80. data/manual/document_and_page_options/page_size.rb +13 -12
  81. data/manual/document_and_page_options/print_scaling.rb +17 -15
  82. data/manual/example_helper.rb +5 -4
  83. data/manual/graphics/blend_mode.rb +12 -9
  84. data/manual/graphics/circle_and_ellipse.rb +4 -5
  85. data/manual/graphics/color.rb +7 -9
  86. data/manual/graphics/common_lines.rb +7 -8
  87. data/manual/graphics/fill_and_stroke.rb +4 -5
  88. data/manual/graphics/fill_rules.rb +9 -10
  89. data/manual/graphics/gradients.rb +27 -21
  90. data/manual/graphics/graphics.rb +48 -40
  91. data/manual/graphics/helper.rb +12 -9
  92. data/manual/graphics/line_width.rb +8 -7
  93. data/manual/graphics/lines_and_curves.rb +7 -8
  94. data/manual/graphics/polygon.rb +6 -8
  95. data/manual/graphics/rectangle.rb +4 -5
  96. data/manual/graphics/rotate.rb +6 -7
  97. data/manual/graphics/scale.rb +14 -15
  98. data/manual/graphics/soft_masks.rb +3 -4
  99. data/manual/graphics/stroke_cap.rb +6 -7
  100. data/manual/graphics/stroke_dash.rb +11 -12
  101. data/manual/graphics/stroke_join.rb +5 -6
  102. data/manual/graphics/translate.rb +9 -10
  103. data/manual/graphics/transparency.rb +7 -8
  104. data/manual/how_to_read_this_manual.rb +6 -6
  105. data/manual/images/absolute_position.rb +6 -7
  106. data/manual/images/fit.rb +7 -8
  107. data/manual/images/horizontal.rb +9 -10
  108. data/manual/images/images.rb +28 -24
  109. data/manual/images/plain_image.rb +5 -6
  110. data/manual/images/scale.rb +9 -10
  111. data/manual/images/vertical.rb +13 -14
  112. data/manual/images/width_and_height.rb +10 -11
  113. data/manual/layout/boxes.rb +5 -6
  114. data/manual/layout/content.rb +7 -8
  115. data/manual/layout/layout.rb +18 -16
  116. data/manual/layout/simple_grid.rb +6 -7
  117. data/manual/outline/add_subsection_to.rb +20 -21
  118. data/manual/outline/insert_section_after.rb +15 -16
  119. data/manual/outline/outline.rb +21 -17
  120. data/manual/outline/sections_and_pages.rb +17 -18
  121. data/manual/repeatable_content/alternate_page_numbering.rb +21 -17
  122. data/manual/repeatable_content/page_numbering.rb +17 -16
  123. data/manual/repeatable_content/repeatable_content.rb +25 -19
  124. data/manual/repeatable_content/repeater.rb +14 -15
  125. data/manual/repeatable_content/stamp.rb +14 -15
  126. data/manual/security/encryption.rb +9 -10
  127. data/manual/security/permissions.rb +19 -14
  128. data/manual/security/security.rb +19 -16
  129. data/manual/table.rb +3 -3
  130. data/manual/text/alignment.rb +16 -17
  131. data/manual/text/color.rb +12 -11
  132. data/manual/text/column_box.rb +9 -10
  133. data/manual/text/fallback_fonts.rb +25 -21
  134. data/manual/text/font.rb +11 -12
  135. data/manual/text/font_size.rb +13 -14
  136. data/manual/text/font_style.rb +7 -8
  137. data/manual/text/formatted_callbacks.rb +25 -21
  138. data/manual/text/formatted_text.rb +33 -25
  139. data/manual/text/free_flowing_text.rb +20 -21
  140. data/manual/text/inline.rb +18 -19
  141. data/manual/text/kerning_and_character_spacing.rb +14 -15
  142. data/manual/text/leading.rb +7 -8
  143. data/manual/text/line_wrapping.rb +37 -18
  144. data/manual/text/paragraph_indentation.rb +13 -14
  145. data/manual/text/positioned_text.rb +15 -16
  146. data/manual/text/registering_families.rb +20 -21
  147. data/manual/text/rendering_and_color.rb +9 -10
  148. data/manual/text/right_to_left_text.rb +26 -19
  149. data/manual/text/rotation.rb +28 -23
  150. data/manual/text/single_usage.rb +8 -9
  151. data/manual/text/text.rb +57 -52
  152. data/manual/text/text_box_excess.rb +20 -17
  153. data/manual/text/text_box_extensions.rb +18 -15
  154. data/manual/text/text_box_overflow.rb +18 -19
  155. data/manual/text/utf8.rb +11 -12
  156. data/manual/text/win_ansi_charset.rb +21 -19
  157. data/prawn.gemspec +44 -31
  158. data/spec/extensions/encoding_helpers.rb +3 -3
  159. data/spec/prawn/document/bounding_box_spec.rb +546 -0
  160. data/spec/prawn/document/column_box_spec.rb +75 -0
  161. data/spec/prawn/document/security_spec.rb +176 -0
  162. data/spec/prawn/document_annotations_spec.rb +76 -0
  163. data/spec/prawn/document_destinations_spec.rb +15 -0
  164. data/spec/prawn/document_grid_spec.rb +99 -0
  165. data/spec/prawn/document_reference_spec.rb +27 -0
  166. data/spec/prawn/document_span_spec.rb +36 -0
  167. data/spec/prawn/document_spec.rb +802 -0
  168. data/spec/prawn/font_metric_cache_spec.rb +54 -0
  169. data/spec/prawn/font_spec.rb +542 -0
  170. data/spec/prawn/graphics/blend_mode_spec.rb +63 -0
  171. data/spec/prawn/graphics/transparency_spec.rb +81 -0
  172. data/spec/prawn/graphics_spec.rb +837 -0
  173. data/spec/prawn/graphics_stroke_styles_spec.rb +229 -0
  174. data/spec/{image_handler_spec.rb → prawn/image_handler_spec.rb} +14 -14
  175. data/spec/prawn/images/jpg_spec.rb +20 -0
  176. data/spec/prawn/images/png_spec.rb +283 -0
  177. data/spec/prawn/images_spec.rb +224 -0
  178. data/spec/prawn/measurements_extensions_spec.rb +24 -0
  179. data/spec/prawn/outline_spec.rb +412 -0
  180. data/spec/prawn/repeater_spec.rb +165 -0
  181. data/spec/prawn/soft_mask_spec.rb +74 -0
  182. data/spec/prawn/stamp_spec.rb +172 -0
  183. data/spec/prawn/text/box_spec.rb +1112 -0
  184. data/spec/prawn/text/formatted/arranger_spec.rb +466 -0
  185. data/spec/prawn/text/formatted/box_spec.rb +846 -0
  186. data/spec/prawn/text/formatted/fragment_spec.rb +343 -0
  187. data/spec/prawn/text/formatted/line_wrap_spec.rb +494 -0
  188. data/spec/prawn/text/formatted/parser_spec.rb +697 -0
  189. data/spec/prawn/text_draw_text_spec.rb +149 -0
  190. data/spec/prawn/text_rendering_mode_spec.rb +48 -0
  191. data/spec/prawn/text_spacing_spec.rb +95 -0
  192. data/spec/prawn/text_spec.rb +603 -0
  193. data/spec/prawn/text_with_inline_formatting_spec.rb +35 -0
  194. data/spec/{transformation_stack_spec.rb → prawn/transformation_stack_spec.rb} +22 -19
  195. data/spec/prawn/view_spec.rb +63 -0
  196. data/spec/prawn_manual_spec.rb +35 -0
  197. data/spec/spec_helper.rb +18 -19
  198. metadata +144 -180
  199. metadata.gz.sig +4 -0
  200. data/data/images/16bit.alpha +0 -0
  201. data/data/images/16bit.color +0 -0
  202. data/data/images/16bit.png +0 -0
  203. data/data/images/arrow.png +0 -0
  204. data/data/images/arrow2.png +0 -0
  205. data/data/images/blend_modes_bottom_layer.jpg +0 -0
  206. data/data/images/blend_modes_top_layer.jpg +0 -0
  207. data/data/images/dice.alpha +0 -0
  208. data/data/images/dice.color +0 -0
  209. data/data/images/dice.png +0 -0
  210. data/data/images/dice_interlaced.png +0 -0
  211. data/data/images/fractal.jpg +0 -0
  212. data/data/images/indexed_color.dat +0 -0
  213. data/data/images/indexed_color.png +0 -0
  214. data/data/images/indexed_transparency.png +0 -0
  215. data/data/images/indexed_transparency_alpha.dat +0 -0
  216. data/data/images/indexed_transparency_color.dat +0 -0
  217. data/data/images/letterhead.jpg +0 -0
  218. data/data/images/license.md +0 -8
  219. data/data/images/page_white_text.alpha +0 -0
  220. data/data/images/page_white_text.color +0 -0
  221. data/data/images/page_white_text.png +0 -0
  222. data/data/images/pigs.jpg +0 -0
  223. data/data/images/prawn.png +0 -0
  224. data/data/images/ruport.png +0 -0
  225. data/data/images/ruport_data.dat +0 -0
  226. data/data/images/ruport_transparent.png +0 -0
  227. data/data/images/ruport_type0.png +0 -0
  228. data/data/images/stef.jpg +0 -0
  229. data/data/images/tru256.bmp +0 -0
  230. data/data/images/web-links.dat +0 -1
  231. data/data/images/web-links.png +0 -0
  232. data/data/pdfs/complex_template.pdf +0 -0
  233. data/data/pdfs/contains_ttf_font.pdf +0 -0
  234. data/data/pdfs/encrypted.pdf +0 -0
  235. data/data/pdfs/form.pdf +1 -819
  236. data/data/pdfs/hexagon.pdf +0 -61
  237. data/data/pdfs/indirect_reference.pdf +0 -86
  238. data/data/pdfs/multipage_template.pdf +0 -127
  239. data/data/pdfs/nested_pages.pdf +0 -118
  240. data/data/pdfs/page_without_mediabox.pdf +0 -193
  241. data/data/pdfs/resources_as_indirect_object.pdf +0 -83
  242. data/data/pdfs/two_hexagons.pdf +0 -90
  243. data/data/pdfs/version_1_6.pdf +0 -61
  244. data/data/shift_jis_text.txt +0 -1
  245. data/spec/acceptance/png_spec.rb +0 -35
  246. data/spec/annotations_spec.rb +0 -67
  247. data/spec/blend_mode_spec.rb +0 -71
  248. data/spec/bounding_box_spec.rb +0 -501
  249. data/spec/column_box_spec.rb +0 -59
  250. data/spec/destinations_spec.rb +0 -13
  251. data/spec/document_spec.rb +0 -738
  252. data/spec/font_metric_cache_spec.rb +0 -52
  253. data/spec/font_spec.rb +0 -475
  254. data/spec/formatted_text_arranger_spec.rb +0 -452
  255. data/spec/formatted_text_box_spec.rb +0 -716
  256. data/spec/formatted_text_fragment_spec.rb +0 -299
  257. data/spec/graphics_spec.rb +0 -705
  258. data/spec/grid_spec.rb +0 -95
  259. data/spec/images_spec.rb +0 -167
  260. data/spec/inline_formatted_text_parser_spec.rb +0 -568
  261. data/spec/jpg_spec.rb +0 -23
  262. data/spec/line_wrap_spec.rb +0 -366
  263. data/spec/measurement_units_spec.rb +0 -22
  264. data/spec/outline_spec.rb +0 -409
  265. data/spec/png_spec.rb +0 -257
  266. data/spec/reference_spec.rb +0 -25
  267. data/spec/repeater_spec.rb +0 -154
  268. data/spec/security_spec.rb +0 -151
  269. data/spec/soft_mask_spec.rb +0 -78
  270. data/spec/span_spec.rb +0 -43
  271. data/spec/stamp_spec.rb +0 -179
  272. data/spec/stroke_styles_spec.rb +0 -208
  273. data/spec/text_at_spec.rb +0 -142
  274. data/spec/text_box_spec.rb +0 -1042
  275. data/spec/text_rendering_mode_spec.rb +0 -45
  276. data/spec/text_spacing_spec.rb +0 -93
  277. data/spec/text_spec.rb +0 -543
  278. data/spec/text_with_inline_formatting_spec.rb +0 -35
  279. data/spec/transparency_spec.rb +0 -91
  280. data/spec/view_spec.rb +0 -42
@@ -1,4 +1,5 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
+
2
3
  # image.rb : Base class for image info objects
3
4
  #
4
5
  # Copyright September 2011, Brad Ediger. All rights reserved.
@@ -1,5 +1,7 @@
1
1
  # encoding: ASCII-8BIT
2
2
 
3
+ # frozen_string_literal: true
4
+
3
5
  # jpg.rb : Extracts the data from a JPG that is needed for embedding
4
6
  #
5
7
  # Copyright April 2008, James Healy. All Rights Reserved.
@@ -19,10 +21,13 @@ module Prawn
19
21
  attr_reader :width, :height, :bits, :channels
20
22
  attr_accessor :scaled_width, :scaled_height
21
23
 
22
- JPEG_SOF_BLOCKS = [0xC0, 0xC1, 0xC2, 0xC3, 0xC5, 0xC6, 0xC7, 0xC9, 0xCA, 0xCB, 0xCD, 0xCE, 0xCF]
24
+ JPEG_SOF_BLOCKS = [
25
+ 0xC0, 0xC1, 0xC2, 0xC3, 0xC5, 0xC6, 0xC7, 0xC9, 0xCA, 0xCB, 0xCD, 0xCE,
26
+ 0xCF
27
+ ].freeze
23
28
 
24
29
  def self.can_render?(image_blob)
25
- image_blob[0, 3].unpack("C*") == [255, 216, 255]
30
+ image_blob[0, 3].unpack('C*') == [255, 216, 255]
26
31
  end
27
32
 
28
33
  # Process a new JPG image
@@ -35,13 +40,13 @@ module Prawn
35
40
  d.binmode
36
41
 
37
42
  c_marker = 0xff # Section marker.
38
- d.seek(2) # Skip the first two bytes of JPEG identifier.
43
+ d.seek(2) # Skip the first two bytes of JPEG identifier.
39
44
  loop do
40
45
  marker, code, length = d.read(4).unpack('CCn')
41
- fail "JPEG marker not found!" if marker != c_marker
46
+ raise 'JPEG marker not found!' if marker != c_marker
42
47
 
43
48
  if JPEG_SOF_BLOCKS.include?(code)
44
- @bits, @height, @width, @channels = d.read(6).unpack("CnnC")
49
+ @bits, @height, @width, @channels = d.read(6).unpack('CnnC')
45
50
  break
46
51
  end
47
52
 
@@ -53,31 +58,32 @@ module Prawn
53
58
  # a Reference to it.
54
59
  #
55
60
  def build_pdf_object(document)
56
- color_space = case channels
57
- when 1
58
- :DeviceGray
59
- when 3
60
- :DeviceRGB
61
- when 4
62
- :DeviceCMYK
63
- else
64
- fail ArgumentError, 'JPG uses an unsupported number of channels'
65
- end
61
+ color_space =
62
+ case channels
63
+ when 1
64
+ :DeviceGray
65
+ when 3
66
+ :DeviceRGB
67
+ when 4
68
+ :DeviceCMYK
69
+ else
70
+ raise ArgumentError, 'JPG uses an unsupported number of channels'
71
+ end
66
72
 
67
73
  obj = document.ref!(
68
- :Type => :XObject,
69
- :Subtype => :Image,
70
- :ColorSpace => color_space,
71
- :BitsPerComponent => bits,
72
- :Width => width,
73
- :Height => height
74
+ Type: :XObject,
75
+ Subtype: :Image,
76
+ ColorSpace: color_space,
77
+ BitsPerComponent: bits,
78
+ Width: width,
79
+ Height: height
74
80
  )
75
81
 
76
82
  # add extra decode params for CMYK images. By swapping the
77
83
  # min and max values from the default, we invert the colours. See
78
84
  # section 4.8.4 of the spec.
79
85
  if color_space == :DeviceCMYK
80
- obj.data[:Decode] = [ 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0 ]
86
+ obj.data[:Decode] = [1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0]
81
87
  end
82
88
 
83
89
  obj.stream << @data
@@ -1,5 +1,7 @@
1
1
  # encoding: ASCII-8BIT
2
2
 
3
+ # frozen_string_literal: true
4
+
3
5
  # png.rb : Extracts the data from a PNG that is needed for embedding
4
6
  #
5
7
  # Based on some similar code in PDF::Writer by Austin Ziegler
@@ -9,8 +11,6 @@
9
11
  # This is free software. Please see the LICENSE and COPYING files for details.
10
12
 
11
13
  require 'stringio'
12
- require 'enumerator'
13
-
14
14
  module Prawn
15
15
  module Images
16
16
  # A convenience class that wraps the logic for extracting the parts
@@ -26,7 +26,7 @@ module Prawn
26
26
  attr_accessor :scaled_width, :scaled_height
27
27
 
28
28
  def self.can_render?(image_blob)
29
- image_blob[0, 8].unpack("C*") == [137, 80, 78, 71, 13, 10, 26, 10]
29
+ image_blob[0, 8].unpack('C*') == [137, 80, 78, 71, 13, 10, 26, 10]
30
30
  end
31
31
 
32
32
  # Process a new PNG image
@@ -36,28 +36,28 @@ module Prawn
36
36
  def initialize(data)
37
37
  data = StringIO.new(data.dup)
38
38
 
39
- data.read(8) # Skip the default header
39
+ data.read(8) # Skip the default header
40
40
 
41
- @palette = ""
42
- @img_data = ""
41
+ @palette = +''
42
+ @img_data = +''
43
43
  @transparency = {}
44
44
 
45
45
  loop do
46
- chunk_size = data.read(4).unpack("N")[0]
47
- section = data.read(4)
46
+ chunk_size = data.read(4).unpack1('N')
47
+ section = data.read(4)
48
48
  case section
49
49
  when 'IHDR'
50
50
  # we can grab other interesting values from here (like width,
51
51
  # height, etc)
52
- values = data.read(chunk_size).unpack("NNCCCCC")
52
+ values = data.read(chunk_size).unpack('NNCCCCC')
53
53
 
54
- @width = values[0]
55
- @height = values[1]
56
- @bits = values[2]
57
- @color_type = values[3]
54
+ @width = values[0]
55
+ @height = values[1]
56
+ @bits = values[2]
57
+ @color_type = values[3]
58
58
  @compression_method = values[4]
59
- @filter_method = values[5]
60
- @interlace_method = values[6]
59
+ @filter_method = values[5]
60
+ @interlace_method = values[6]
61
61
  when 'PLTE'
62
62
  @palette << data.read(chunk_size)
63
63
  when 'IDAT'
@@ -72,11 +72,11 @@ module Prawn
72
72
  when 0
73
73
  # Greyscale. Corresponding to entries in the PLTE chunk.
74
74
  # Grey is two bytes, range 0 .. (2 ^ bit-depth) - 1
75
- grayval = data.read(chunk_size).unpack("n").first
75
+ grayval = data.read(chunk_size).unpack1('n')
76
76
  @transparency[:grayscale] = grayval
77
77
  when 2
78
78
  # True colour with proper alpha channel.
79
- @transparency[:rgb] = data.read(chunk_size).unpack("nnn")
79
+ @transparency[:rgb] = data.read(chunk_size).unpack('nnn')
80
80
  end
81
81
  when 'IEND'
82
82
  # we've got everything we need, exit the loop
@@ -86,7 +86,7 @@ module Prawn
86
86
  data.seek(data.pos + chunk_size)
87
87
  end
88
88
 
89
- data.read(4) # Skip the CRC
89
+ data.read(4) # Skip the CRC
90
90
  end
91
91
 
92
92
  @img_data = Zlib::Inflate.inflate(@img_data)
@@ -95,11 +95,11 @@ module Prawn
95
95
  # number of color components to each pixel
96
96
  #
97
97
  def colors
98
- case self.color_type
98
+ case color_type
99
99
  when 0, 3, 4
100
- return 1
100
+ 1
101
101
  when 2, 6
102
- return 3
102
+ 3
103
103
  end
104
104
  end
105
105
 
@@ -128,18 +128,18 @@ module Prawn
128
128
  #
129
129
  def build_pdf_object(document)
130
130
  if compression_method != 0
131
- fail Errors::UnsupportedImageType,
132
- 'PNG uses an unsupported compression method'
131
+ raise Errors::UnsupportedImageType,
132
+ 'PNG uses an unsupported compression method'
133
133
  end
134
134
 
135
135
  if filter_method != 0
136
- fail Errors::UnsupportedImageType,
137
- 'PNG uses an unsupported filter method'
136
+ raise Errors::UnsupportedImageType,
137
+ 'PNG uses an unsupported filter method'
138
138
  end
139
139
 
140
140
  if interlace_method != 0
141
- fail Errors::UnsupportedImageType,
142
- 'PNG uses unsupported interlace method'
141
+ raise Errors::UnsupportedImageType,
142
+ 'PNG uses unsupported interlace method'
143
143
  end
144
144
 
145
145
  # some PNG types store the colour and alpha channel data together,
@@ -152,28 +152,28 @@ module Prawn
152
152
  when 3
153
153
  color = :DeviceRGB
154
154
  else
155
- fail Errors::UnsupportedImageType,
156
- "PNG uses an unsupported number of colors (#{png.colors})"
155
+ raise Errors::UnsupportedImageType,
156
+ "PNG uses an unsupported number of colors (#{png.colors})"
157
157
  end
158
158
 
159
159
  # build the image dict
160
160
  obj = document.ref!(
161
- :Type => :XObject,
162
- :Subtype => :Image,
163
- :Height => height,
164
- :Width => width,
165
- :BitsPerComponent => bits
161
+ Type: :XObject,
162
+ Subtype: :Image,
163
+ Height: height,
164
+ Width: width,
165
+ BitsPerComponent: bits
166
166
  )
167
167
 
168
168
  # append the actual image data to the object as a stream
169
169
  obj << img_data
170
170
 
171
171
  obj.stream.filters << {
172
- :FlateDecode => {
173
- :Predictor => 15,
174
- :Colors => colors,
175
- :BitsPerComponent => bits,
176
- :Columns => width
172
+ FlateDecode: {
173
+ Predictor: 15,
174
+ Colors: colors,
175
+ BitsPerComponent: bits,
176
+ Columns: width
177
177
  }
178
178
  }
179
179
 
@@ -186,10 +186,12 @@ module Prawn
186
186
  palette_obj << palette
187
187
 
188
188
  # build the color space array for the image
189
- obj.data[:ColorSpace] = [:Indexed,
190
- :DeviceRGB,
191
- (palette.size / 3) - 1,
192
- palette_obj]
189
+ obj.data[:ColorSpace] = [
190
+ :Indexed,
191
+ :DeviceRGB,
192
+ (palette.size / 3) - 1,
193
+ palette_obj
194
+ ]
193
195
  end
194
196
 
195
197
  # *************************************
@@ -213,27 +215,28 @@ module Prawn
213
215
  obj.data[:Mask] = rgb.collect { |x| [x, x] }.flatten
214
216
  end
215
217
 
216
- # For PNG color types 4 and 6, the transparency data is stored as a alpha
217
- # channel mixed in with the main image data. The PNG class seperates
218
- # it out for us and makes it available via the alpha_channel attribute
218
+ # For PNG color types 4 and 6, the transparency data is stored as
219
+ # a alpha channel mixed in with the main image data. The PNG class
220
+ # seperates it out for us and makes it available via the alpha_channel
221
+ # attribute
219
222
  if alpha_channel?
220
223
  smask_obj = document.ref!(
221
- :Type => :XObject,
222
- :Subtype => :Image,
223
- :Height => height,
224
- :Width => width,
225
- :BitsPerComponent => bits,
226
- :ColorSpace => :DeviceGray,
227
- :Decode => [0, 1]
224
+ Type: :XObject,
225
+ Subtype: :Image,
226
+ Height: height,
227
+ Width: width,
228
+ BitsPerComponent: bits,
229
+ ColorSpace: :DeviceGray,
230
+ Decode: [0, 1]
228
231
  )
229
232
  smask_obj.stream << alpha_channel
230
233
 
231
234
  smask_obj.stream.filters << {
232
- :FlateDecode => {
233
- :Predictor => 15,
234
- :Colors => 1,
235
- :BitsPerComponent => bits,
236
- :Columns => width
235
+ FlateDecode: {
236
+ Predictor: 15,
237
+ Colors: 1,
238
+ BitsPerComponent: bits,
239
+ Columns: width
237
240
  }
238
241
  }
239
242
  obj.data[:SMask] = smask_obj
@@ -261,9 +264,9 @@ module Prawn
261
264
  alpha_bytes = bits / 8
262
265
  color_bytes = colors * bits / 8
263
266
 
264
- scanline_length = (color_bytes + alpha_bytes) * self.width + 1
267
+ scanline_length = (color_bytes + alpha_bytes) * width + 1
265
268
  scanlines = @img_data.bytesize / scanline_length
266
- pixels = self.width * self.height
269
+ pixels = width * height
267
270
 
268
271
  data = StringIO.new(@img_data)
269
272
  data.binmode
@@ -284,7 +287,7 @@ module Prawn
284
287
  color.putc filter
285
288
  alpha.putc filter
286
289
 
287
- self.width.times do
290
+ width.times do
288
291
  color.write data.read(color_bytes)
289
292
  alpha.write data.read(alpha_bytes)
290
293
  end
@@ -318,7 +321,7 @@ module Prawn
318
321
  alpha.putc filter
319
322
 
320
323
  width.times do
321
- color = data.read(1).unpack('C').first
324
+ color = data.read(1).unpack1('C')
322
325
  alpha.putc alpha_palette[color]
323
326
  end
324
327
  end
@@ -1,4 +1,5 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
+
2
3
  # measurement_extensions.rb: Core extensions for Prawn::Measurements
3
4
  #
4
5
  # Copyright December 2008, Florian Witteler. All Rights Reserved.
@@ -17,34 +18,34 @@ class Numeric
17
18
  # @group Experimental API
18
19
 
19
20
  def mm
20
- return mm2pt(self)
21
+ mm2pt(self)
21
22
  end
22
23
 
23
24
  def cm
24
- return cm2pt(self)
25
+ cm2pt(self)
25
26
  end
26
27
 
27
28
  def dm
28
- return dm2pt(self)
29
+ dm2pt(self)
29
30
  end
30
31
 
31
32
  def m
32
- return m2pt(self)
33
+ m2pt(self)
33
34
  end
34
35
 
35
36
  def in
36
- return in2pt(self)
37
+ in2pt(self)
37
38
  end
38
39
 
39
40
  def yd
40
- return yd2pt(self)
41
+ yd2pt(self)
41
42
  end
42
43
 
43
44
  def ft
44
- return ft2pt(self)
45
+ ft2pt(self)
45
46
  end
46
47
 
47
48
  def pt
48
- return pt2pt(self)
49
+ pt2pt(self)
49
50
  end
50
51
  end
@@ -1,70 +1,74 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
+
2
3
  # measurements.rb: Conversions from other measurements to PDF points
3
4
  #
4
5
  # Copyright December 2008, Florian Witteler. All Rights Reserved.
5
6
  #
7
+
8
+ # rubocop: disable Naming/MethodParameterName
6
9
  module Prawn
7
10
  # @group Stable API
8
11
 
9
12
  module Measurements
10
13
  # metric conversions
11
14
  def cm2mm(cm)
12
- return cm * 10
15
+ cm * 10
13
16
  end
14
17
 
15
18
  def dm2mm(dm)
16
- return dm * 100
19
+ dm * 100
17
20
  end
18
21
 
19
22
  def m2mm(m)
20
- return m * 1000
23
+ m * 1000
21
24
  end
22
25
 
23
26
  # imperial conversions
24
27
  # from http://en.wikipedia.org/wiki/Imperial_units
25
28
  def ft2in(ft)
26
- return ft * 12
29
+ ft * 12
27
30
  end
28
31
 
29
32
  def yd2in(yd)
30
- return yd * 36
33
+ yd * 36
31
34
  end
32
35
 
33
36
  # PostscriptPoint-converisons
34
37
  def pt2pt(pt)
35
- return pt
38
+ pt
36
39
  end
37
40
 
38
41
  def in2pt(inch)
39
- return inch * 72
42
+ inch * 72
40
43
  end
41
44
 
42
45
  def ft2pt(ft)
43
- return in2pt(ft2in(ft))
46
+ in2pt(ft2in(ft))
44
47
  end
45
48
 
46
49
  def yd2pt(yd)
47
- return in2pt(yd2in(yd))
50
+ in2pt(yd2in(yd))
48
51
  end
49
52
 
50
53
  def mm2pt(mm)
51
- return mm * (72 / 25.4)
54
+ mm * (72 / 25.4)
52
55
  end
53
56
 
54
57
  def cm2pt(cm)
55
- return mm2pt(cm2mm(cm))
58
+ mm2pt(cm2mm(cm))
56
59
  end
57
60
 
58
61
  def dm2pt(dm)
59
- return mm2pt(dm2mm(dm))
62
+ mm2pt(dm2mm(dm))
60
63
  end
61
64
 
62
65
  def m2pt(m)
63
- return mm2pt(m2mm(m))
66
+ mm2pt(m2mm(m))
64
67
  end
65
68
 
66
69
  def pt2mm(pt)
67
- return pt * 1 / mm2pt(1) # (25.4 / 72)
70
+ pt * 1 / mm2pt(1) # (25.4 / 72)
68
71
  end
69
72
  end
70
73
  end
74
+ # rubocop: enable Naming/MethodParameterName