prawn 2.1.0 → 2.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/GPLv2 +20 -21
- data/Gemfile +3 -9
- data/Rakefile +20 -23
- data/lib/prawn.rb +36 -49
- data/lib/prawn/document.rb +180 -133
- data/lib/prawn/document/bounding_box.rb +41 -29
- data/lib/prawn/document/column_box.rb +7 -7
- data/lib/prawn/document/internals.rb +8 -6
- data/lib/prawn/document/span.rb +21 -16
- data/lib/prawn/encoding.rb +69 -68
- data/lib/prawn/errors.rb +12 -7
- data/lib/prawn/font.rb +102 -69
- data/lib/prawn/font_metric_cache.rb +14 -8
- data/lib/prawn/{font → fonts}/afm.rb +102 -68
- data/lib/prawn/{font → fonts}/dfont.rb +5 -11
- data/lib/prawn/fonts/otf.rb +11 -0
- data/lib/prawn/fonts/ttc.rb +36 -0
- data/lib/prawn/{font → fonts}/ttf.rb +87 -68
- data/lib/prawn/graphics.rb +119 -81
- data/lib/prawn/graphics/blend_mode.rb +9 -8
- data/lib/prawn/graphics/cap_style.rb +3 -3
- data/lib/prawn/graphics/color.rb +27 -25
- data/lib/prawn/graphics/dash.rb +23 -11
- data/lib/prawn/graphics/join_style.rb +9 -3
- data/lib/prawn/graphics/patterns.rb +190 -96
- data/lib/prawn/graphics/transformation.rb +15 -9
- data/lib/prawn/graphics/transparency.rb +17 -13
- data/lib/prawn/grid.rb +48 -47
- data/lib/prawn/image_handler.rb +5 -5
- data/lib/prawn/images.rb +39 -30
- data/lib/prawn/images/image.rb +2 -1
- data/lib/prawn/images/jpg.rb +28 -22
- data/lib/prawn/images/png.rb +65 -62
- data/lib/prawn/measurement_extensions.rb +10 -9
- data/lib/prawn/measurements.rb +19 -15
- data/lib/prawn/outline.rb +97 -77
- data/lib/prawn/repeater.rb +14 -10
- data/lib/prawn/security.rb +81 -61
- data/lib/prawn/security/arcfour.rb +2 -2
- data/lib/prawn/soft_mask.rb +26 -26
- data/lib/prawn/stamp.rb +20 -13
- data/lib/prawn/text.rb +68 -52
- data/lib/prawn/text/box.rb +11 -8
- data/lib/prawn/text/formatted.rb +5 -5
- data/lib/prawn/text/formatted/arranger.rb +53 -32
- data/lib/prawn/text/formatted/box.rb +134 -100
- data/lib/prawn/text/formatted/fragment.rb +11 -14
- data/lib/prawn/text/formatted/line_wrap.rb +122 -63
- data/lib/prawn/text/formatted/parser.rb +139 -117
- data/lib/prawn/text/formatted/wrap.rb +43 -31
- data/lib/prawn/transformation_stack.rb +7 -5
- data/lib/prawn/utilities.rb +7 -22
- data/lib/prawn/version.rb +2 -2
- data/lib/prawn/view.rb +17 -7
- data/manual/basic_concepts/adding_pages.rb +6 -7
- data/manual/basic_concepts/basic_concepts.rb +31 -22
- data/manual/basic_concepts/creation.rb +10 -11
- data/manual/basic_concepts/cursor.rb +4 -5
- data/manual/basic_concepts/measurement.rb +6 -7
- data/manual/basic_concepts/origin.rb +5 -6
- data/manual/basic_concepts/other_cursor_helpers.rb +11 -12
- data/manual/basic_concepts/view.rb +22 -16
- data/manual/bounding_box/bounding_box.rb +29 -24
- data/manual/bounding_box/bounds.rb +11 -12
- data/manual/bounding_box/canvas.rb +4 -5
- data/manual/bounding_box/creation.rb +6 -7
- data/manual/bounding_box/indentation.rb +14 -15
- data/manual/bounding_box/nesting.rb +24 -17
- data/manual/bounding_box/russian_boxes.rb +14 -13
- data/manual/bounding_box/stretchy.rb +12 -13
- data/manual/contents.rb +28 -22
- data/manual/cover.rb +33 -28
- data/manual/document_and_page_options/background.rb +11 -13
- data/manual/document_and_page_options/document_and_page_options.rb +25 -20
- data/manual/document_and_page_options/metadata.rb +18 -16
- data/manual/document_and_page_options/page_margins.rb +18 -20
- data/manual/document_and_page_options/page_size.rb +13 -12
- data/manual/document_and_page_options/print_scaling.rb +17 -15
- data/manual/example_helper.rb +5 -4
- data/manual/graphics/blend_mode.rb +12 -9
- data/manual/graphics/circle_and_ellipse.rb +4 -5
- data/manual/graphics/color.rb +7 -9
- data/manual/graphics/common_lines.rb +7 -8
- data/manual/graphics/fill_and_stroke.rb +4 -5
- data/manual/graphics/fill_rules.rb +9 -10
- data/manual/graphics/gradients.rb +27 -21
- data/manual/graphics/graphics.rb +48 -40
- data/manual/graphics/helper.rb +12 -9
- data/manual/graphics/line_width.rb +8 -7
- data/manual/graphics/lines_and_curves.rb +7 -8
- data/manual/graphics/polygon.rb +6 -8
- data/manual/graphics/rectangle.rb +4 -5
- data/manual/graphics/rotate.rb +6 -7
- data/manual/graphics/scale.rb +14 -15
- data/manual/graphics/soft_masks.rb +3 -4
- data/manual/graphics/stroke_cap.rb +6 -7
- data/manual/graphics/stroke_dash.rb +11 -12
- data/manual/graphics/stroke_join.rb +5 -6
- data/manual/graphics/translate.rb +9 -10
- data/manual/graphics/transparency.rb +7 -8
- data/manual/how_to_read_this_manual.rb +6 -6
- data/manual/images/absolute_position.rb +6 -7
- data/manual/images/fit.rb +7 -8
- data/manual/images/horizontal.rb +9 -10
- data/manual/images/images.rb +28 -24
- data/manual/images/plain_image.rb +5 -6
- data/manual/images/scale.rb +9 -10
- data/manual/images/vertical.rb +13 -14
- data/manual/images/width_and_height.rb +10 -11
- data/manual/layout/boxes.rb +5 -6
- data/manual/layout/content.rb +7 -8
- data/manual/layout/layout.rb +18 -16
- data/manual/layout/simple_grid.rb +6 -7
- data/manual/outline/add_subsection_to.rb +20 -21
- data/manual/outline/insert_section_after.rb +15 -16
- data/manual/outline/outline.rb +21 -17
- data/manual/outline/sections_and_pages.rb +17 -18
- data/manual/repeatable_content/alternate_page_numbering.rb +21 -17
- data/manual/repeatable_content/page_numbering.rb +17 -16
- data/manual/repeatable_content/repeatable_content.rb +25 -19
- data/manual/repeatable_content/repeater.rb +14 -15
- data/manual/repeatable_content/stamp.rb +14 -15
- data/manual/security/encryption.rb +9 -10
- data/manual/security/permissions.rb +19 -14
- data/manual/security/security.rb +19 -16
- data/manual/table.rb +3 -3
- data/manual/text/alignment.rb +16 -17
- data/manual/text/color.rb +12 -11
- data/manual/text/column_box.rb +9 -10
- data/manual/text/fallback_fonts.rb +25 -21
- data/manual/text/font.rb +11 -12
- data/manual/text/font_size.rb +13 -14
- data/manual/text/font_style.rb +7 -8
- data/manual/text/formatted_callbacks.rb +25 -21
- data/manual/text/formatted_text.rb +33 -25
- data/manual/text/free_flowing_text.rb +20 -21
- data/manual/text/inline.rb +18 -19
- data/manual/text/kerning_and_character_spacing.rb +14 -15
- data/manual/text/leading.rb +7 -8
- data/manual/text/line_wrapping.rb +37 -18
- data/manual/text/paragraph_indentation.rb +13 -14
- data/manual/text/positioned_text.rb +15 -16
- data/manual/text/registering_families.rb +20 -21
- data/manual/text/rendering_and_color.rb +9 -10
- data/manual/text/right_to_left_text.rb +26 -19
- data/manual/text/rotation.rb +28 -23
- data/manual/text/single_usage.rb +8 -9
- data/manual/text/text.rb +57 -52
- data/manual/text/text_box_excess.rb +20 -17
- data/manual/text/text_box_extensions.rb +18 -15
- data/manual/text/text_box_overflow.rb +18 -19
- data/manual/text/utf8.rb +11 -12
- data/manual/text/win_ansi_charset.rb +21 -19
- data/prawn.gemspec +44 -31
- data/spec/extensions/encoding_helpers.rb +3 -3
- data/spec/prawn/document/bounding_box_spec.rb +546 -0
- data/spec/prawn/document/column_box_spec.rb +75 -0
- data/spec/prawn/document/security_spec.rb +176 -0
- data/spec/prawn/document_annotations_spec.rb +76 -0
- data/spec/prawn/document_destinations_spec.rb +15 -0
- data/spec/prawn/document_grid_spec.rb +99 -0
- data/spec/prawn/document_reference_spec.rb +27 -0
- data/spec/prawn/document_span_spec.rb +36 -0
- data/spec/prawn/document_spec.rb +802 -0
- data/spec/prawn/font_metric_cache_spec.rb +54 -0
- data/spec/prawn/font_spec.rb +542 -0
- data/spec/prawn/graphics/blend_mode_spec.rb +63 -0
- data/spec/prawn/graphics/transparency_spec.rb +81 -0
- data/spec/prawn/graphics_spec.rb +837 -0
- data/spec/prawn/graphics_stroke_styles_spec.rb +229 -0
- data/spec/{image_handler_spec.rb → prawn/image_handler_spec.rb} +14 -14
- data/spec/prawn/images/jpg_spec.rb +20 -0
- data/spec/prawn/images/png_spec.rb +283 -0
- data/spec/prawn/images_spec.rb +224 -0
- data/spec/prawn/measurements_extensions_spec.rb +24 -0
- data/spec/prawn/outline_spec.rb +412 -0
- data/spec/prawn/repeater_spec.rb +165 -0
- data/spec/prawn/soft_mask_spec.rb +74 -0
- data/spec/prawn/stamp_spec.rb +172 -0
- data/spec/prawn/text/box_spec.rb +1112 -0
- data/spec/prawn/text/formatted/arranger_spec.rb +466 -0
- data/spec/prawn/text/formatted/box_spec.rb +846 -0
- data/spec/prawn/text/formatted/fragment_spec.rb +343 -0
- data/spec/prawn/text/formatted/line_wrap_spec.rb +494 -0
- data/spec/prawn/text/formatted/parser_spec.rb +697 -0
- data/spec/prawn/text_draw_text_spec.rb +149 -0
- data/spec/prawn/text_rendering_mode_spec.rb +48 -0
- data/spec/prawn/text_spacing_spec.rb +95 -0
- data/spec/prawn/text_spec.rb +603 -0
- data/spec/prawn/text_with_inline_formatting_spec.rb +35 -0
- data/spec/{transformation_stack_spec.rb → prawn/transformation_stack_spec.rb} +22 -19
- data/spec/prawn/view_spec.rb +63 -0
- data/spec/prawn_manual_spec.rb +35 -0
- data/spec/spec_helper.rb +18 -19
- metadata +144 -180
- metadata.gz.sig +4 -0
- data/data/images/16bit.alpha +0 -0
- data/data/images/16bit.color +0 -0
- data/data/images/16bit.png +0 -0
- data/data/images/arrow.png +0 -0
- data/data/images/arrow2.png +0 -0
- data/data/images/blend_modes_bottom_layer.jpg +0 -0
- data/data/images/blend_modes_top_layer.jpg +0 -0
- data/data/images/dice.alpha +0 -0
- data/data/images/dice.color +0 -0
- data/data/images/dice.png +0 -0
- data/data/images/dice_interlaced.png +0 -0
- data/data/images/fractal.jpg +0 -0
- data/data/images/indexed_color.dat +0 -0
- data/data/images/indexed_color.png +0 -0
- data/data/images/indexed_transparency.png +0 -0
- data/data/images/indexed_transparency_alpha.dat +0 -0
- data/data/images/indexed_transparency_color.dat +0 -0
- data/data/images/letterhead.jpg +0 -0
- data/data/images/license.md +0 -8
- data/data/images/page_white_text.alpha +0 -0
- data/data/images/page_white_text.color +0 -0
- data/data/images/page_white_text.png +0 -0
- data/data/images/pigs.jpg +0 -0
- data/data/images/prawn.png +0 -0
- data/data/images/ruport.png +0 -0
- data/data/images/ruport_data.dat +0 -0
- data/data/images/ruport_transparent.png +0 -0
- data/data/images/ruport_type0.png +0 -0
- data/data/images/stef.jpg +0 -0
- data/data/images/tru256.bmp +0 -0
- data/data/images/web-links.dat +0 -1
- data/data/images/web-links.png +0 -0
- data/data/pdfs/complex_template.pdf +0 -0
- data/data/pdfs/contains_ttf_font.pdf +0 -0
- data/data/pdfs/encrypted.pdf +0 -0
- data/data/pdfs/form.pdf +1 -819
- data/data/pdfs/hexagon.pdf +0 -61
- data/data/pdfs/indirect_reference.pdf +0 -86
- data/data/pdfs/multipage_template.pdf +0 -127
- data/data/pdfs/nested_pages.pdf +0 -118
- data/data/pdfs/page_without_mediabox.pdf +0 -193
- data/data/pdfs/resources_as_indirect_object.pdf +0 -83
- data/data/pdfs/two_hexagons.pdf +0 -90
- data/data/pdfs/version_1_6.pdf +0 -61
- data/data/shift_jis_text.txt +0 -1
- data/spec/acceptance/png_spec.rb +0 -35
- data/spec/annotations_spec.rb +0 -67
- data/spec/blend_mode_spec.rb +0 -71
- data/spec/bounding_box_spec.rb +0 -501
- data/spec/column_box_spec.rb +0 -59
- data/spec/destinations_spec.rb +0 -13
- data/spec/document_spec.rb +0 -738
- data/spec/font_metric_cache_spec.rb +0 -52
- data/spec/font_spec.rb +0 -475
- data/spec/formatted_text_arranger_spec.rb +0 -452
- data/spec/formatted_text_box_spec.rb +0 -716
- data/spec/formatted_text_fragment_spec.rb +0 -299
- data/spec/graphics_spec.rb +0 -705
- data/spec/grid_spec.rb +0 -95
- data/spec/images_spec.rb +0 -167
- data/spec/inline_formatted_text_parser_spec.rb +0 -568
- data/spec/jpg_spec.rb +0 -23
- data/spec/line_wrap_spec.rb +0 -366
- data/spec/measurement_units_spec.rb +0 -22
- data/spec/outline_spec.rb +0 -409
- data/spec/png_spec.rb +0 -257
- data/spec/reference_spec.rb +0 -25
- data/spec/repeater_spec.rb +0 -154
- data/spec/security_spec.rb +0 -151
- data/spec/soft_mask_spec.rb +0 -78
- data/spec/span_spec.rb +0 -43
- data/spec/stamp_spec.rb +0 -179
- data/spec/stroke_styles_spec.rb +0 -208
- data/spec/text_at_spec.rb +0 -142
- data/spec/text_box_spec.rb +0 -1042
- data/spec/text_rendering_mode_spec.rb +0 -45
- data/spec/text_spacing_spec.rb +0 -93
- data/spec/text_spec.rb +0 -543
- data/spec/text_with_inline_formatting_spec.rb +0 -35
- data/spec/transparency_spec.rb +0 -91
- data/spec/view_spec.rb +0 -42
data/lib/prawn/images/image.rb
CHANGED
data/lib/prawn/images/jpg.rb
CHANGED
@@ -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 = [
|
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(
|
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)
|
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
|
-
|
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(
|
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 =
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
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
|
-
:
|
69
|
-
:
|
70
|
-
:
|
71
|
-
:
|
72
|
-
:
|
73
|
-
:
|
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] = [
|
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
|
data/lib/prawn/images/png.rb
CHANGED
@@ -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(
|
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)
|
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
|
47
|
-
section
|
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(
|
52
|
+
values = data.read(chunk_size).unpack('NNCCCCC')
|
53
53
|
|
54
|
-
@width
|
55
|
-
@height
|
56
|
-
@bits
|
57
|
-
@color_type
|
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
|
60
|
-
@interlace_method
|
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).
|
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(
|
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)
|
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
|
98
|
+
case color_type
|
99
99
|
when 0, 3, 4
|
100
|
-
|
100
|
+
1
|
101
101
|
when 2, 6
|
102
|
-
|
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
|
-
|
132
|
-
|
131
|
+
raise Errors::UnsupportedImageType,
|
132
|
+
'PNG uses an unsupported compression method'
|
133
133
|
end
|
134
134
|
|
135
135
|
if filter_method != 0
|
136
|
-
|
137
|
-
|
136
|
+
raise Errors::UnsupportedImageType,
|
137
|
+
'PNG uses an unsupported filter method'
|
138
138
|
end
|
139
139
|
|
140
140
|
if interlace_method != 0
|
141
|
-
|
142
|
-
|
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
|
-
|
156
|
-
|
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
|
-
:
|
162
|
-
:
|
163
|
-
:
|
164
|
-
:
|
165
|
-
:
|
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
|
-
:
|
173
|
-
:
|
174
|
-
:
|
175
|
-
:
|
176
|
-
:
|
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] = [
|
190
|
-
|
191
|
-
|
192
|
-
|
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
|
217
|
-
# channel mixed in with the main image data. The PNG class
|
218
|
-
# it out for us and makes it available via the alpha_channel
|
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
|
-
:
|
222
|
-
:
|
223
|
-
:
|
224
|
-
:
|
225
|
-
:
|
226
|
-
:
|
227
|
-
:
|
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
|
-
:
|
233
|
-
:
|
234
|
-
:
|
235
|
-
:
|
236
|
-
:
|
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
|
267
|
+
scanline_length = (color_bytes + alpha_bytes) * width + 1
|
265
268
|
scanlines = @img_data.bytesize / scanline_length
|
266
|
-
pixels =
|
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
|
-
|
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).
|
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
|
-
#
|
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
|
-
|
21
|
+
mm2pt(self)
|
21
22
|
end
|
22
23
|
|
23
24
|
def cm
|
24
|
-
|
25
|
+
cm2pt(self)
|
25
26
|
end
|
26
27
|
|
27
28
|
def dm
|
28
|
-
|
29
|
+
dm2pt(self)
|
29
30
|
end
|
30
31
|
|
31
32
|
def m
|
32
|
-
|
33
|
+
m2pt(self)
|
33
34
|
end
|
34
35
|
|
35
36
|
def in
|
36
|
-
|
37
|
+
in2pt(self)
|
37
38
|
end
|
38
39
|
|
39
40
|
def yd
|
40
|
-
|
41
|
+
yd2pt(self)
|
41
42
|
end
|
42
43
|
|
43
44
|
def ft
|
44
|
-
|
45
|
+
ft2pt(self)
|
45
46
|
end
|
46
47
|
|
47
48
|
def pt
|
48
|
-
|
49
|
+
pt2pt(self)
|
49
50
|
end
|
50
51
|
end
|
data/lib/prawn/measurements.rb
CHANGED
@@ -1,70 +1,74 @@
|
|
1
|
-
#
|
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
|
-
|
15
|
+
cm * 10
|
13
16
|
end
|
14
17
|
|
15
18
|
def dm2mm(dm)
|
16
|
-
|
19
|
+
dm * 100
|
17
20
|
end
|
18
21
|
|
19
22
|
def m2mm(m)
|
20
|
-
|
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
|
-
|
29
|
+
ft * 12
|
27
30
|
end
|
28
31
|
|
29
32
|
def yd2in(yd)
|
30
|
-
|
33
|
+
yd * 36
|
31
34
|
end
|
32
35
|
|
33
36
|
# PostscriptPoint-converisons
|
34
37
|
def pt2pt(pt)
|
35
|
-
|
38
|
+
pt
|
36
39
|
end
|
37
40
|
|
38
41
|
def in2pt(inch)
|
39
|
-
|
42
|
+
inch * 72
|
40
43
|
end
|
41
44
|
|
42
45
|
def ft2pt(ft)
|
43
|
-
|
46
|
+
in2pt(ft2in(ft))
|
44
47
|
end
|
45
48
|
|
46
49
|
def yd2pt(yd)
|
47
|
-
|
50
|
+
in2pt(yd2in(yd))
|
48
51
|
end
|
49
52
|
|
50
53
|
def mm2pt(mm)
|
51
|
-
|
54
|
+
mm * (72 / 25.4)
|
52
55
|
end
|
53
56
|
|
54
57
|
def cm2pt(cm)
|
55
|
-
|
58
|
+
mm2pt(cm2mm(cm))
|
56
59
|
end
|
57
60
|
|
58
61
|
def dm2pt(dm)
|
59
|
-
|
62
|
+
mm2pt(dm2mm(dm))
|
60
63
|
end
|
61
64
|
|
62
65
|
def m2pt(m)
|
63
|
-
|
66
|
+
mm2pt(m2mm(m))
|
64
67
|
end
|
65
68
|
|
66
69
|
def pt2mm(pt)
|
67
|
-
|
70
|
+
pt * 1 / mm2pt(1) # (25.4 / 72)
|
68
71
|
end
|
69
72
|
end
|
70
73
|
end
|
74
|
+
# rubocop: enable Naming/MethodParameterName
|