prawn 2.4.0 → 2.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/lib/prawn/document/bounding_box.rb +213 -141
- data/lib/prawn/document/column_box.rb +61 -26
- data/lib/prawn/document/internals.rb +25 -16
- data/lib/prawn/document/span.rb +20 -18
- data/lib/prawn/document.rb +257 -171
- data/lib/prawn/encoding.rb +2 -5
- data/lib/prawn/errors.rb +23 -34
- data/lib/prawn/font.rb +248 -135
- data/lib/prawn/font_metric_cache.rb +11 -10
- data/lib/prawn/fonts/afm.rb +85 -45
- data/lib/prawn/fonts/dfont.rb +7 -1
- data/lib/prawn/fonts/otf.rb +4 -1
- data/lib/prawn/fonts/to_unicode_cmap.rb +151 -0
- data/lib/prawn/fonts/ttc.rb +7 -2
- data/lib/prawn/fonts/ttf.rb +305 -93
- data/lib/prawn/fonts.rb +14 -0
- data/lib/prawn/graphics/blend_mode.rb +25 -28
- data/lib/prawn/graphics/cap_style.rb +9 -12
- data/lib/prawn/graphics/color.rb +57 -34
- data/lib/prawn/graphics/dash.rb +45 -42
- data/lib/prawn/graphics/join_style.rb +17 -11
- data/lib/prawn/graphics/patterns.rb +190 -69
- data/lib/prawn/graphics/transformation.rb +48 -41
- data/lib/prawn/graphics/transparency.rb +16 -40
- data/lib/prawn/graphics.rb +363 -253
- data/lib/prawn/grid.rb +184 -57
- data/lib/prawn/image_handler.rb +27 -10
- data/lib/prawn/images/image.rb +8 -10
- data/lib/prawn/images/jpg.rb +42 -19
- data/lib/prawn/images/png.rb +92 -41
- data/lib/prawn/images.rb +44 -57
- data/lib/prawn/measurement_extensions.rb +39 -8
- data/lib/prawn/measurements.rb +60 -5
- data/lib/prawn/outline.rb +114 -108
- data/lib/prawn/repeater.rb +51 -35
- data/lib/prawn/security/arcfour.rb +4 -4
- data/lib/prawn/security.rb +75 -70
- data/lib/prawn/soft_mask.rb +42 -30
- data/lib/prawn/stamp.rb +38 -42
- data/lib/prawn/text/box.rb +146 -96
- data/lib/prawn/text/formatted/arranger.rb +87 -26
- data/lib/prawn/text/formatted/box.rb +221 -150
- data/lib/prawn/text/formatted/fragment.rb +130 -14
- data/lib/prawn/text/formatted/line_wrap.rb +33 -24
- data/lib/prawn/text/formatted/parser.rb +112 -72
- data/lib/prawn/text/formatted/wrap.rb +12 -17
- data/lib/prawn/text/formatted.rb +75 -0
- data/lib/prawn/text.rb +441 -196
- data/lib/prawn/transformation_stack.rb +29 -10
- data/lib/prawn/utilities.rb +13 -13
- data/lib/prawn/version.rb +2 -1
- data/lib/prawn/view.rb +68 -53
- data/lib/prawn.rb +23 -18
- data.tar.gz.sig +0 -0
- metadata +54 -177
- metadata.gz.sig +0 -0
- data/.yardopts +0 -10
- data/Gemfile +0 -5
- data/Rakefile +0 -25
- data/manual/absolute_position.pdf +0 -0
- data/manual/basic_concepts/adding_pages.rb +0 -26
- data/manual/basic_concepts/basic_concepts.rb +0 -43
- data/manual/basic_concepts/creation.rb +0 -38
- data/manual/basic_concepts/cursor.rb +0 -32
- data/manual/basic_concepts/measurement.rb +0 -24
- data/manual/basic_concepts/origin.rb +0 -37
- data/manual/basic_concepts/other_cursor_helpers.rb +0 -39
- data/manual/basic_concepts/view.rb +0 -48
- data/manual/bounding_box/bounding_box.rb +0 -41
- data/manual/bounding_box/bounds.rb +0 -48
- data/manual/bounding_box/canvas.rb +0 -23
- data/manual/bounding_box/creation.rb +0 -22
- data/manual/bounding_box/indentation.rb +0 -45
- data/manual/bounding_box/nesting.rb +0 -52
- data/manual/bounding_box/russian_boxes.rb +0 -40
- data/manual/bounding_box/stretchy.rb +0 -29
- data/manual/contents.rb +0 -35
- data/manual/cover.rb +0 -43
- data/manual/document_and_page_options/background.rb +0 -29
- data/manual/document_and_page_options/document_and_page_options.rb +0 -34
- data/manual/document_and_page_options/metadata.rb +0 -25
- data/manual/document_and_page_options/page_margins.rb +0 -36
- data/manual/document_and_page_options/page_size.rb +0 -34
- data/manual/document_and_page_options/print_scaling.rb +0 -23
- data/manual/example_helper.rb +0 -8
- data/manual/graphics/blend_mode.rb +0 -52
- data/manual/graphics/circle_and_ellipse.rb +0 -21
- data/manual/graphics/color.rb +0 -22
- data/manual/graphics/common_lines.rb +0 -29
- data/manual/graphics/fill_and_stroke.rb +0 -41
- data/manual/graphics/fill_rules.rb +0 -38
- data/manual/graphics/gradients.rb +0 -43
- data/manual/graphics/graphics.rb +0 -64
- data/manual/graphics/helper.rb +0 -34
- data/manual/graphics/line_width.rb +0 -36
- data/manual/graphics/lines_and_curves.rb +0 -40
- data/manual/graphics/polygon.rb +0 -27
- data/manual/graphics/rectangle.rb +0 -20
- data/manual/graphics/rotate.rb +0 -25
- data/manual/graphics/scale.rb +0 -42
- data/manual/graphics/soft_masks.rb +0 -44
- data/manual/graphics/stroke_cap.rb +0 -30
- data/manual/graphics/stroke_dash.rb +0 -47
- data/manual/graphics/stroke_join.rb +0 -29
- data/manual/graphics/translate.rb +0 -29
- data/manual/graphics/transparency.rb +0 -33
- data/manual/how_to_read_this_manual.rb +0 -39
- data/manual/images/absolute_position.rb +0 -22
- data/manual/images/fit.rb +0 -20
- data/manual/images/horizontal.rb +0 -24
- data/manual/images/images.rb +0 -41
- data/manual/images/plain_image.rb +0 -17
- data/manual/images/scale.rb +0 -21
- data/manual/images/vertical.rb +0 -30
- data/manual/images/width_and_height.rb +0 -24
- data/manual/layout/boxes.rb +0 -26
- data/manual/layout/content.rb +0 -24
- data/manual/layout/layout.rb +0 -27
- data/manual/layout/simple_grid.rb +0 -22
- data/manual/outline/add_subsection_to.rb +0 -60
- data/manual/outline/insert_section_after.rb +0 -46
- data/manual/outline/outline.rb +0 -33
- data/manual/outline/sections_and_pages.rb +0 -66
- data/manual/repeatable_content/alternate_page_numbering.rb +0 -36
- data/manual/repeatable_content/page_numbering.rb +0 -55
- data/manual/repeatable_content/repeatable_content.rb +0 -35
- data/manual/repeatable_content/repeater.rb +0 -54
- data/manual/repeatable_content/stamp.rb +0 -40
- data/manual/security/encryption.rb +0 -28
- data/manual/security/permissions.rb +0 -43
- data/manual/security/security.rb +0 -28
- data/manual/table.rb +0 -16
- data/manual/text/alignment.rb +0 -43
- data/manual/text/color.rb +0 -24
- data/manual/text/column_box.rb +0 -30
- data/manual/text/fallback_fonts.rb +0 -41
- data/manual/text/font.rb +0 -40
- data/manual/text/font_size.rb +0 -44
- data/manual/text/font_style.rb +0 -25
- data/manual/text/formatted_callbacks.rb +0 -70
- data/manual/text/formatted_text.rb +0 -61
- data/manual/text/free_flowing_text.rb +0 -50
- data/manual/text/inline.rb +0 -40
- data/manual/text/kerning_and_character_spacing.rb +0 -38
- data/manual/text/leading.rb +0 -24
- data/manual/text/line_wrapping.rb +0 -60
- data/manual/text/paragraph_indentation.rb +0 -31
- data/manual/text/positioned_text.rb +0 -37
- data/manual/text/registering_families.rb +0 -51
- data/manual/text/rendering_and_color.rb +0 -36
- data/manual/text/right_to_left_text.rb +0 -54
- data/manual/text/rotation.rb +0 -52
- data/manual/text/single_usage.rb +0 -36
- data/manual/text/text.rb +0 -75
- data/manual/text/text_box_excess.rb +0 -35
- data/manual/text/text_box_extensions.rb +0 -48
- data/manual/text/text_box_overflow.rb +0 -51
- data/manual/text/utf8.rb +0 -27
- data/manual/text/win_ansi_charset.rb +0 -62
- data/prawn.gemspec +0 -51
- data/spec/data/curves.pdf +0 -66
- data/spec/extensions/encoding_helpers.rb +0 -11
- data/spec/prawn/document/bounding_box_spec.rb +0 -550
- data/spec/prawn/document/column_box_spec.rb +0 -75
- data/spec/prawn/document/security_spec.rb +0 -176
- data/spec/prawn/document_annotations_spec.rb +0 -76
- data/spec/prawn/document_destinations_spec.rb +0 -15
- data/spec/prawn/document_grid_spec.rb +0 -99
- data/spec/prawn/document_reference_spec.rb +0 -27
- data/spec/prawn/document_span_spec.rb +0 -44
- data/spec/prawn/document_spec.rb +0 -805
- data/spec/prawn/font_metric_cache_spec.rb +0 -54
- data/spec/prawn/font_spec.rb +0 -544
- data/spec/prawn/graphics/blend_mode_spec.rb +0 -63
- data/spec/prawn/graphics/transparency_spec.rb +0 -81
- data/spec/prawn/graphics_spec.rb +0 -872
- data/spec/prawn/graphics_stroke_styles_spec.rb +0 -229
- data/spec/prawn/image_handler_spec.rb +0 -53
- data/spec/prawn/images/jpg_spec.rb +0 -20
- data/spec/prawn/images/png_spec.rb +0 -283
- data/spec/prawn/images_spec.rb +0 -229
- data/spec/prawn/measurements_extensions_spec.rb +0 -24
- data/spec/prawn/outline_spec.rb +0 -512
- data/spec/prawn/repeater_spec.rb +0 -166
- data/spec/prawn/soft_mask_spec.rb +0 -74
- data/spec/prawn/stamp_spec.rb +0 -173
- data/spec/prawn/text/box_spec.rb +0 -1110
- data/spec/prawn/text/formatted/arranger_spec.rb +0 -466
- data/spec/prawn/text/formatted/box_spec.rb +0 -849
- data/spec/prawn/text/formatted/fragment_spec.rb +0 -343
- data/spec/prawn/text/formatted/line_wrap_spec.rb +0 -495
- data/spec/prawn/text/formatted/parser_spec.rb +0 -697
- data/spec/prawn/text_draw_text_spec.rb +0 -150
- data/spec/prawn/text_rendering_mode_spec.rb +0 -48
- data/spec/prawn/text_spacing_spec.rb +0 -95
- data/spec/prawn/text_spec.rb +0 -603
- data/spec/prawn/text_with_inline_formatting_spec.rb +0 -35
- data/spec/prawn/transformation_stack_spec.rb +0 -66
- data/spec/prawn/view_spec.rb +0 -63
- data/spec/prawn_manual_spec.rb +0 -35
- data/spec/spec_helper.rb +0 -48
@@ -2,76 +2,195 @@
|
|
2
2
|
|
3
3
|
require 'digest/sha1'
|
4
4
|
|
5
|
-
# patterns.rb : Implements axial & radial gradients
|
6
|
-
#
|
7
|
-
# Originally implemented by Wojciech Piekutowski. November, 2009
|
8
|
-
# Copyright September 2012, Alexander Mankuta. All Rights Reserved.
|
9
|
-
#
|
10
|
-
# This is free software. Please see the LICENSE and COPYING files for details.
|
11
|
-
#
|
12
5
|
module Prawn
|
13
6
|
module Graphics
|
7
|
+
# Implements axial & radial gradients.
|
14
8
|
module Patterns
|
9
|
+
# Gradient color stop.
|
10
|
+
# @private
|
15
11
|
GradientStop = Struct.new(:position, :color)
|
12
|
+
|
13
|
+
# @private
|
16
14
|
Gradient = Struct.new(
|
17
|
-
:type, :apply_transformations, :stops, :from, :to, :r1, :r2
|
15
|
+
:type, :apply_transformations, :stops, :from, :to, :r1, :r2,
|
18
16
|
)
|
19
17
|
|
20
18
|
# @group Stable API
|
21
19
|
|
22
20
|
# Sets the fill gradient.
|
23
|
-
# old arguments:
|
24
|
-
# from, to, color1, color2
|
25
|
-
# or
|
26
|
-
# from, r1, to, r2, color1, color2
|
27
|
-
# new arguments:
|
28
|
-
# from: [x, y]
|
29
|
-
# to: [x, y]
|
30
|
-
# r1: radius
|
31
|
-
# r2: radius
|
32
|
-
# stops: [color, color, ...] or
|
33
|
-
# { position => color, position => color, ... }
|
34
|
-
# apply_transformations: true
|
35
21
|
#
|
36
|
-
#
|
22
|
+
# @overload fill_gradient(from, to, color1, color2, apply_margin_options: false)
|
23
|
+
# Set an axial (linear) fill gradient.
|
37
24
|
#
|
38
|
-
#
|
39
|
-
#
|
40
|
-
#
|
25
|
+
# @param from [Array(Number, Number)]
|
26
|
+
# Starting point of the gradient.
|
27
|
+
# @param to [Array(Number, Number)] ending point of the gradient.
|
28
|
+
# @param color1 [Color] starting color of the gradient.
|
29
|
+
# @param color2 [Color] ending color of the gradient.
|
30
|
+
# @param apply_transformations [Boolean] (false)
|
31
|
+
# If set `true`, will transform the gradient's co-ordinate space so it
|
32
|
+
# matches the current co-ordinate space of the document. This option
|
33
|
+
# will be the default from Prawn v3, and is default `true` if you use
|
34
|
+
# the all-keyword version of this method. The default for the
|
35
|
+
# positional arguments version (this one), `false`, will mean if you
|
36
|
+
# (for example) scale your document by 2 and put a gradient inside,
|
37
|
+
# you will have to manually multiply your co-ordinates by 2 so the
|
38
|
+
# gradient is correctly positioned.
|
39
|
+
# @return [void]
|
41
40
|
#
|
42
|
-
#
|
43
|
-
#
|
44
|
-
# fill_gradient from: [0, 0], r1: 0, to: [100, 0], r2: 180,
|
45
|
-
# stops: { 0 => 'red', 0.8 => 'green', 1 => 'blue' }
|
41
|
+
# @overload fill_gradient(from, r1, to, r2, color1, color2, apply_margin_options: false)
|
42
|
+
# Set a radial fill gradient.
|
46
43
|
#
|
47
|
-
#
|
48
|
-
#
|
44
|
+
# @param from [Array(Number, Number)]
|
45
|
+
# Starting point of the gradient.
|
46
|
+
# @param r1 [Number]
|
47
|
+
# Radius of the starting circle of a radial gradient. The circle is
|
48
|
+
# centered at `from`.
|
49
|
+
# @param to [Array(Number, Number)]
|
50
|
+
# Ending point of the gradient.
|
51
|
+
# @param r2 [Number]
|
52
|
+
# Radius of the ending circle of a radial gradient. The circle is
|
53
|
+
# centered at `to`.
|
54
|
+
# @param color1 [Color]
|
55
|
+
# Starting color.
|
56
|
+
# @param color2 [Color]
|
57
|
+
# Ending color.
|
58
|
+
# @param apply_transformations [Boolean] (false)
|
59
|
+
# If set `true`, will transform the gradient's co-ordinate space so it
|
60
|
+
# matches the current co-ordinate space of the document. This option
|
61
|
+
# will be the default from Prawn v3, and is default `true` if you use
|
62
|
+
# the all-keyword version of this method. The default for the
|
63
|
+
# positional arguments version (this one), `false`, will mean if you
|
64
|
+
# (for example) scale your document by 2 and put a gradient inside,
|
65
|
+
# you will have to manually multiply your co-ordinates by 2 so the
|
66
|
+
# gradient is correctly positioned.
|
67
|
+
# @return [void]
|
49
68
|
#
|
50
|
-
#
|
51
|
-
# the
|
52
|
-
# and ending at a circle of radius <tt>r2</tt> centered at <tt>to</tt>.
|
53
|
-
# If <tt>r1</tt> is not specified, a axial gradient will be drawn.
|
69
|
+
# @overload fill_gradient(from:, to:, r1: nil, r2: nil, stops:, apply_margin_options: true)
|
70
|
+
# Set the fill gradient.
|
54
71
|
#
|
55
|
-
#
|
56
|
-
#
|
57
|
-
#
|
58
|
-
# a
|
59
|
-
#
|
72
|
+
# @example Draw a horizontal axial gradient that starts at red on the left and ends at blue on the right
|
73
|
+
# fill_gradient from: [0, 0], to: [100, 0], stops: ['ff0000', '0000ff']
|
74
|
+
#
|
75
|
+
# @example Draw a horizontal radial gradient that starts at red, is green 80% through, and finishes blue
|
76
|
+
# fill_gradient from: [0, 0], r1: 0, to: [100, 0], r2: 180,
|
77
|
+
# stops: { 0 => 'ff0000', 0.8 => '00ff00', 1 => '0000ff' }
|
60
78
|
#
|
61
|
-
#
|
62
|
-
#
|
63
|
-
#
|
64
|
-
#
|
65
|
-
#
|
66
|
-
# (
|
67
|
-
#
|
68
|
-
#
|
79
|
+
# @param from [Array(Number, Number)]
|
80
|
+
# Starting point of the gradient.
|
81
|
+
# @param r1 [Number, nil]
|
82
|
+
# Radius of the starting circle of a radial gradient. The circle is
|
83
|
+
# centered at `from`. If omitted a linear gradient will be produced.
|
84
|
+
# @param to [Array(Number, Number)]
|
85
|
+
# Ending point of the gradient.
|
86
|
+
# @param r2 [Number, nil]
|
87
|
+
# Radius of the ending circle of a radial gradient. The circle is
|
88
|
+
# centered at `to`.
|
89
|
+
# @param stops [Array<Color>, Hash{Number => Color}]
|
90
|
+
# Color stops. Each stop is either just a color, in which case the
|
91
|
+
# stops will be evenly distributed across the gradient, or a hash
|
92
|
+
# where the key is a position between 0 and 1 indicating what distance
|
93
|
+
# through the gradient the color should change, and the value is
|
94
|
+
# a color.
|
95
|
+
# @param apply_transformations [Boolean] (true)
|
96
|
+
# If set `true`, will transform the gradient's co-ordinate space so it
|
97
|
+
# matches the current co-ordinate space of the document. This option
|
98
|
+
# will be the default from Prawn v3, and is default `true` if you use
|
99
|
+
# the all-keyword version of this method (this one). The default for
|
100
|
+
# the old arguments format, `false`, will mean if you (for example)
|
101
|
+
# scale your document by 2 and put a gradient inside, you will have to
|
102
|
+
# manually multiply your co-ordinates by 2 so the gradient is
|
103
|
+
# correctly positioned.
|
104
|
+
# @return [void]
|
69
105
|
def fill_gradient(*args, **kwargs)
|
70
106
|
set_gradient(:fill, *args, **kwargs)
|
71
107
|
end
|
72
108
|
|
73
109
|
# Sets the stroke gradient.
|
74
|
-
#
|
110
|
+
#
|
111
|
+
# @overload fill_gradient(from, to, color1, color2, apply_margin_options: false)
|
112
|
+
# Set an axial (linear) stroke gradient.
|
113
|
+
#
|
114
|
+
# @param from [Array(Number, Number)]
|
115
|
+
# Starting point of the gradient.
|
116
|
+
# @param to [Array(Number, Number)] ending point of the gradient.
|
117
|
+
# @param color1 [Color] starting color of the gradient.
|
118
|
+
# @param color2 [Color] ending color of the gradient.
|
119
|
+
# @param apply_transformations [Boolean] (false)
|
120
|
+
# If set `true`, will transform the gradient's co-ordinate space so it
|
121
|
+
# matches the current co-ordinate space of the document. This option
|
122
|
+
# will be the default from Prawn v3, and is default `true` if you use
|
123
|
+
# the all-keyword version of this method. The default for the
|
124
|
+
# positional arguments version (this one), `false`, will mean if you
|
125
|
+
# (for example) scale your document by 2 and put a gradient inside,
|
126
|
+
# you will have to manually multiply your co-ordinates by 2 so the
|
127
|
+
# gradient is correctly positioned.
|
128
|
+
# @return [void]
|
129
|
+
#
|
130
|
+
# @overload fill_gradient(from, r1, to, r2, color1, color2, apply_margin_options: false)
|
131
|
+
# Set a radial stroke gradient.
|
132
|
+
#
|
133
|
+
# @param from [Array(Number, Number)]
|
134
|
+
# Starting point of the gradient.
|
135
|
+
# @param r1 [Number]
|
136
|
+
# Radius of the starting circle of a radial gradient. The circle is
|
137
|
+
# centered at `from`.
|
138
|
+
# @param to [Array(Number, Number)]
|
139
|
+
# Ending point of the gradient.
|
140
|
+
# @param r2 [Number]
|
141
|
+
# Radius of the ending circle of a radial gradient. The circle is
|
142
|
+
# centered at `to`.
|
143
|
+
# @param color1 [Color]
|
144
|
+
# Starting color.
|
145
|
+
# @param color2 [Color]
|
146
|
+
# Ending color.
|
147
|
+
# @param apply_transformations [Boolean] (false)
|
148
|
+
# If set `true`, will transform the gradient's co-ordinate space so it
|
149
|
+
# matches the current co-ordinate space of the document. This option
|
150
|
+
# will be the default from Prawn v3, and is default `true` if you use
|
151
|
+
# the all-keyword version of this method. The default for the
|
152
|
+
# positional arguments version (this one), `false`, will mean if you
|
153
|
+
# (for example) scale your document by 2 and put a gradient inside,
|
154
|
+
# you will have to manually multiply your co-ordinates by 2 so the
|
155
|
+
# gradient is correctly positioned.
|
156
|
+
# @return [void]
|
157
|
+
#
|
158
|
+
# @overload fill_gradient(from:, to:, r1: nil, r2: nil, stops:, apply_margin_options: true)
|
159
|
+
# Set the stroke gradient.
|
160
|
+
#
|
161
|
+
# @example Draw a horizontal axial gradient that starts at red on the left and ends at blue on the right
|
162
|
+
# stroke_gradient from: [0, 0], to: [100, 0], stops: ['ff0000', '0000ff']
|
163
|
+
#
|
164
|
+
# @example Draw a horizontal radial gradient that starts at red, is green 80% through, and finishes blue
|
165
|
+
# stroke_gradient from: [0, 0], r1: 0, to: [100, 0], r2: 180,
|
166
|
+
# stops: { 0 => 'ff0000', 0.8 => '00ff00', 1 => '0000ff' }
|
167
|
+
#
|
168
|
+
# @param from [Array(Number, Number)]
|
169
|
+
# Starting point of the gradient.
|
170
|
+
# @param r1 [Number, nil]
|
171
|
+
# Radius of the starting circle of a radial gradient. The circle is
|
172
|
+
# centered at `from`. If omitted a linear gradient will be produced.
|
173
|
+
# @param to [Array(Number, Number)]
|
174
|
+
# Ending point of the gradient.
|
175
|
+
# @param r2 [Number, nil]
|
176
|
+
# Radius of the ending circle of a radial gradient. The circle is
|
177
|
+
# centered at `to`.
|
178
|
+
# @param stops [Array<Color>, Hash{Number => Color}]
|
179
|
+
# Color stops. Each stop is either just a color, in which case the
|
180
|
+
# stops will be evenly distributed across the gradient, or a hash
|
181
|
+
# where the key is a position between 0 and 1 indicating what distance
|
182
|
+
# through the gradient the color should change, and the value is
|
183
|
+
# a color.
|
184
|
+
# @param apply_transformations [Boolean] (true)
|
185
|
+
# If set `true`, will transform the gradient's co-ordinate space so it
|
186
|
+
# matches the current co-ordinate space of the document. This option
|
187
|
+
# will be the default from Prawn v3, and is default `true` if you use
|
188
|
+
# the all-keyword version of this method (this one). The default for
|
189
|
+
# the old arguments format, `false`, will mean if you (for example)
|
190
|
+
# scale your document by 2 and put a gradient inside, you will have to
|
191
|
+
# manually multiply your co-ordinates by 2 so the gradient is
|
192
|
+
# correctly positioned.
|
193
|
+
# @return [void]
|
75
194
|
def stroke_gradient(*args, **kwargs)
|
76
195
|
set_gradient(:stroke, *args, **kwargs)
|
77
196
|
end
|
@@ -83,9 +202,9 @@ module Prawn
|
|
83
202
|
|
84
203
|
patterns = page.resources[:Pattern] ||= {}
|
85
204
|
|
86
|
-
registry_key = gradient_registry_key
|
205
|
+
registry_key = gradient_registry_key(gradient)
|
87
206
|
|
88
|
-
unless patterns.key?
|
207
|
+
unless patterns.key?("SP#{registry_key}")
|
89
208
|
shading = gradient_registry[registry_key]
|
90
209
|
unless shading
|
91
210
|
shading = create_gradient_pattern(gradient)
|
@@ -105,8 +224,8 @@ module Prawn
|
|
105
224
|
raise ArgumentError, "unknown type '#{type}'"
|
106
225
|
end
|
107
226
|
|
108
|
-
set_color_space
|
109
|
-
renderer.add_content
|
227
|
+
set_color_space(type, :Pattern)
|
228
|
+
renderer.add_content("/SP#{registry_key} #{operator}")
|
110
229
|
end
|
111
230
|
|
112
231
|
# rubocop: disable Metrics/ParameterLists
|
@@ -131,12 +250,12 @@ module Prawn
|
|
131
250
|
end
|
132
251
|
|
133
252
|
stops =
|
134
|
-
stops.map.with_index
|
253
|
+
stops.map.with_index { |stop, index|
|
135
254
|
case stop
|
136
255
|
when Array, Hash
|
137
256
|
position, color = stop
|
138
257
|
else
|
139
|
-
position = index / (stops.length
|
258
|
+
position = index / (Float(stops.length) - 1)
|
140
259
|
color = stop
|
141
260
|
end
|
142
261
|
|
@@ -145,7 +264,7 @@ module Prawn
|
|
145
264
|
end
|
146
265
|
|
147
266
|
GradientStop.new(position, normalize_color(color))
|
148
|
-
|
267
|
+
}
|
149
268
|
|
150
269
|
if stops.first.position != 0
|
151
270
|
raise ArgumentError, 'The first stop must have a position of 0'
|
@@ -165,7 +284,7 @@ module Prawn
|
|
165
284
|
from,
|
166
285
|
to,
|
167
286
|
r1,
|
168
|
-
r2
|
287
|
+
r2,
|
169
288
|
)
|
170
289
|
end
|
171
290
|
# rubocop: enable Metrics/ParameterLists
|
@@ -179,7 +298,7 @@ module Prawn
|
|
179
298
|
x2, y2,
|
180
299
|
gradient.r1 || -1, gradient.r2 || -1,
|
181
300
|
gradient.stops.length,
|
182
|
-
gradient.stops.map { |s| [s.position, s.color] }
|
301
|
+
gradient.stops.map { |s| [s.position, s.color] },
|
183
302
|
].flatten
|
184
303
|
Digest::SHA1.hexdigest(key.join(','))
|
185
304
|
end
|
@@ -192,24 +311,26 @@ module Prawn
|
|
192
311
|
if gradient.apply_transformations.nil? &&
|
193
312
|
current_transformation_matrix_with_translation(0, 0) !=
|
194
313
|
[1, 0, 0, 1, 0, 0]
|
195
|
-
warn
|
196
|
-
'
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
314
|
+
warn(
|
315
|
+
'Gradients in Prawn 2.x and lower are not correctly positioned ' \
|
316
|
+
'when a transformation has been made to the document. ' \
|
317
|
+
"Pass 'apply_transformations: true' to correctly transform the " \
|
318
|
+
'gradient, or see ' \
|
319
|
+
'https://github.com/prawnpdf/prawn/wiki/Gradient-Transformations ' \
|
320
|
+
'for more information.',
|
321
|
+
)
|
201
322
|
end
|
202
323
|
|
203
324
|
shader_stops =
|
204
|
-
gradient.stops.each_cons(2).map
|
325
|
+
gradient.stops.each_cons(2).map { |first, second|
|
205
326
|
ref!(
|
206
327
|
FunctionType: 2,
|
207
328
|
Domain: [0.0, 1.0],
|
208
329
|
C0: first.color,
|
209
330
|
C1: second.color,
|
210
|
-
N: 1.0
|
331
|
+
N: 1.0,
|
211
332
|
)
|
212
|
-
|
333
|
+
}
|
213
334
|
|
214
335
|
# If there's only two stops, we can use the single shader.
|
215
336
|
# Otherwise we stitch the multiple shaders together.
|
@@ -222,7 +343,7 @@ module Prawn
|
|
222
343
|
Domain: [0.0, 1.0],
|
223
344
|
Functions: shader_stops,
|
224
345
|
Bounds: gradient.stops[1..-2].map(&:position),
|
225
|
-
Encode: [0.0, 1.0] * shader_stops.length
|
346
|
+
Encode: [0.0, 1.0] * shader_stops.length,
|
226
347
|
)
|
227
348
|
end
|
228
349
|
|
@@ -240,13 +361,13 @@ module Prawn
|
|
240
361
|
ColorSpace: color_space(gradient.stops.first.color),
|
241
362
|
Coords: coords,
|
242
363
|
Function: shader,
|
243
|
-
Extend: [true, true]
|
364
|
+
Extend: [true, true],
|
244
365
|
)
|
245
366
|
|
246
367
|
ref!(
|
247
368
|
PatternType: 2, # shading pattern
|
248
369
|
Shading: shading,
|
249
|
-
Matrix: transformation
|
370
|
+
Matrix: transformation,
|
250
371
|
)
|
251
372
|
end
|
252
373
|
|
@@ -1,36 +1,21 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# transformation.rb: Implements rotate, translate, skew, scale and a generic
|
4
|
-
# transformation_matrix
|
5
|
-
#
|
6
|
-
# Copyright January 2010, Michael Witrant. All Rights Reserved.
|
7
|
-
#
|
8
|
-
# This is free software. Please see the LICENSE and COPYING files for details.
|
9
|
-
|
10
3
|
module Prawn
|
11
4
|
module Graphics
|
5
|
+
# Implements user-space coordinate transformation.
|
12
6
|
module Transformation
|
13
7
|
# @group Stable API
|
14
8
|
|
15
|
-
# Rotate the user space.
|
9
|
+
# Rotate the user space. If a block is not provided, then you must save
|
16
10
|
# and restore the graphics state yourself.
|
17
11
|
#
|
18
|
-
#
|
19
|
-
# <tt>:origin</tt>:: <tt>[number, number]</tt>. The point around which to
|
20
|
-
# rotate. A block must be provided if using the :origin
|
21
|
-
#
|
22
|
-
# raises <tt>Prawn::Errors::BlockRequired</tt> if an :origin option is
|
23
|
-
# provided, but no block is given
|
24
|
-
#
|
25
|
-
# Example without a block:
|
26
|
-
#
|
12
|
+
# @example
|
27
13
|
# save_graphics_state
|
28
14
|
# rotate 30
|
29
15
|
# text "rotated text"
|
30
16
|
# restore_graphics_state
|
31
17
|
#
|
32
|
-
#
|
33
|
-
#
|
18
|
+
# @example Rotating a rectangle around its upper-left corner
|
34
19
|
# x = 300
|
35
20
|
# y = 300
|
36
21
|
# width = 150
|
@@ -40,6 +25,14 @@ module Prawn
|
|
40
25
|
# pdf.stroke_rectangle([x, y], width, height)
|
41
26
|
# end
|
42
27
|
#
|
28
|
+
# @param angle [Number] Angle in degrees.
|
29
|
+
# @param options [Hash{Symbol => any}]
|
30
|
+
# @option options :origin [Array(Number, Number)] Rotation origin point.
|
31
|
+
# A block must be provided if specified.
|
32
|
+
# @yield
|
33
|
+
# @raise [Prawn::Errors::BlockRequired] if an `:origin` option is
|
34
|
+
# provided, but no block is given.
|
35
|
+
# @return [void]
|
43
36
|
def rotate(angle, options = {}, &block)
|
44
37
|
Prawn.verify_options(:origin, options)
|
45
38
|
rad = degree_to_rad(angle)
|
@@ -52,27 +45,24 @@ module Prawn
|
|
52
45
|
|
53
46
|
x = options[:origin][0] + bounds.absolute_left
|
54
47
|
y = options[:origin][1] + bounds.absolute_bottom
|
55
|
-
x_prime = x * cos - y * sin
|
56
|
-
y_prime = x * sin + y * cos
|
48
|
+
x_prime = (x * cos) - (y * sin)
|
49
|
+
y_prime = (x * sin) + (y * cos)
|
57
50
|
translate(x - x_prime, y - y_prime) do
|
58
51
|
transformation_matrix(cos, sin, -sin, cos, 0, 0, &block)
|
59
52
|
end
|
60
53
|
end
|
61
54
|
end
|
62
55
|
|
63
|
-
# Translate the user space.
|
56
|
+
# Translate the user space. If a block is not provided, then you must
|
64
57
|
# save and restore the graphics state yourself.
|
65
58
|
#
|
66
|
-
#
|
67
|
-
#
|
59
|
+
# @example Move the text up and over 10
|
68
60
|
# save_graphics_state
|
69
61
|
# translate(10, 10)
|
70
62
|
# text "scaled text"
|
71
63
|
# restore_graphics_state
|
72
64
|
#
|
73
|
-
#
|
74
|
-
# x + 10, y + 10
|
75
|
-
#
|
65
|
+
# @example draw a rectangle with its upper-left corner at x + 10, y + 10
|
76
66
|
# x = 300
|
77
67
|
# y = 300
|
78
68
|
# width = 150
|
@@ -81,29 +71,24 @@ module Prawn
|
|
81
71
|
# pdf.stroke_rectangle([x, y], width, height)
|
82
72
|
# end
|
83
73
|
#
|
74
|
+
# @param x [Number]
|
75
|
+
# @param y [Number]
|
76
|
+
# @yield
|
77
|
+
# @return [void]
|
84
78
|
def translate(x, y, &block)
|
85
79
|
transformation_matrix(1, 0, 0, 1, x, y, &block)
|
86
80
|
end
|
87
81
|
|
88
|
-
# Scale the user space.
|
82
|
+
# Scale the user space. If a block is not provided, then you must save
|
89
83
|
# and restore the graphics state yourself.
|
90
84
|
#
|
91
|
-
#
|
92
|
-
# <tt>:origin</tt>:: <tt>[number, number]</tt>. The point from which to
|
93
|
-
# scale. A block must be provided if using the :origin
|
94
|
-
#
|
95
|
-
# raises <tt>Prawn::Errors::BlockRequired</tt> if an :origin option is
|
96
|
-
# provided, but no block is given
|
97
|
-
#
|
98
|
-
# Example without a block:
|
99
|
-
#
|
85
|
+
# @example
|
100
86
|
# save_graphics_state
|
101
87
|
# scale 1.5
|
102
88
|
# text "scaled text"
|
103
89
|
# restore_graphics_state
|
104
90
|
#
|
105
|
-
#
|
106
|
-
#
|
91
|
+
# @example Scale a rectangle from its upper-left corner
|
107
92
|
# x = 300
|
108
93
|
# y = 300
|
109
94
|
# width = 150
|
@@ -113,6 +98,14 @@ module Prawn
|
|
113
98
|
# pdf.stroke_rectangle([x, y], width, height)
|
114
99
|
# end
|
115
100
|
#
|
101
|
+
# @param factor [Number] Scale factor.
|
102
|
+
# @param options [Hash{Symbol => any}]
|
103
|
+
# @option options :origin [Array(Number, Number)] The point from which to
|
104
|
+
# scale. A block must be provided if specified.
|
105
|
+
# @yield
|
106
|
+
# @raise [Prawn::Errors::BlockRequired] If an `:origin` option is
|
107
|
+
# provided, but no block is given.
|
108
|
+
# @return [void]
|
116
109
|
def scale(factor, options = {}, &block)
|
117
110
|
Prawn.verify_options(:origin, options)
|
118
111
|
if options[:origin].nil?
|
@@ -142,8 +135,22 @@ module Prawn
|
|
142
135
|
# end
|
143
136
|
|
144
137
|
# Transform the user space (see notes for rotate regarding graphics state)
|
145
|
-
# Generally, one would use the rotate, scale,
|
138
|
+
# Generally, one would use the {rotate}, {scale}, and {translate}
|
146
139
|
# convenience methods instead of calling transformation_matrix directly
|
140
|
+
#
|
141
|
+
# @param matrix [Array(Number, Number, Number, Number, Number, Number)]
|
142
|
+
# Transformation matrix.
|
143
|
+
#
|
144
|
+
# The six elements correspond to the following elements of the
|
145
|
+
# transformation matrix:
|
146
|
+
#
|
147
|
+
# ```plain
|
148
|
+
# a b 0
|
149
|
+
# c d 0
|
150
|
+
# e f 0
|
151
|
+
# ```
|
152
|
+
# @yield
|
153
|
+
# @return [void]
|
147
154
|
def transformation_matrix(*matrix)
|
148
155
|
if matrix.length != 6
|
149
156
|
raise ArgumentError,
|
@@ -154,7 +161,7 @@ module Prawn
|
|
154
161
|
add_to_transformation_stack(*matrix)
|
155
162
|
|
156
163
|
values = PDF::Core.real_params(matrix)
|
157
|
-
renderer.add_content
|
164
|
+
renderer.add_content("#{values} cm")
|
158
165
|
if block_given?
|
159
166
|
yield
|
160
167
|
restore_graphics_state
|
@@ -1,65 +1,41 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# transparency.rb : Implements transparency
|
4
|
-
#
|
5
|
-
# Copyright October 2009, Daniel Nelson. All Rights Reserved.
|
6
|
-
#
|
7
|
-
# This is free software. Please see the LICENSE and COPYING files for details.
|
8
|
-
#
|
9
|
-
|
10
3
|
module Prawn
|
11
4
|
module Graphics
|
12
|
-
#
|
13
|
-
#
|
14
|
-
#
|
15
|
-
#
|
16
|
-
# Example:
|
17
|
-
# # both the fill and stroke will be at 50% opacity
|
18
|
-
# pdf.transparent(0.5) do
|
19
|
-
# pdf.text("hello world")
|
20
|
-
# pdf.fill_and_stroke_circle([x, y], 25)
|
21
|
-
# end
|
22
|
-
#
|
23
|
-
# # the fill will be at 50% opacity, but the stroke will
|
24
|
-
# # be at 75% opacity
|
25
|
-
# pdf.transparent(0.5, 0.75) do
|
26
|
-
# pdf.text("hello world")
|
27
|
-
# pdf.fill_and_stroke_circle([x, y], 25)
|
28
|
-
# end
|
29
|
-
#
|
5
|
+
# This module is used to place transparent content on the page. It has the
|
6
|
+
# capacity for separate transparency values for stroked content and all
|
7
|
+
# other content.
|
30
8
|
module Transparency
|
31
9
|
# @group Stable API
|
32
10
|
|
33
|
-
#
|
34
|
-
# the content within the <tt>block</tt>
|
35
|
-
# If <tt>stroke_opacity</tt> is not provided, then it takes on
|
36
|
-
# the same value as <tt>opacity</tt>
|
37
|
-
#
|
38
|
-
# Valid ranges for both paramters are 0.0 to 1.0
|
11
|
+
# Set opacity.
|
39
12
|
#
|
40
|
-
#
|
41
|
-
# # both the fill and stroke will be at 50% opacity
|
13
|
+
# @example Both the fill and stroke will be at 50% opacity.
|
42
14
|
# pdf.transparent(0.5) do
|
43
15
|
# pdf.text("hello world")
|
44
16
|
# pdf.fill_and_stroke_circle([x, y], 25)
|
45
17
|
# end
|
46
18
|
#
|
47
|
-
#
|
48
|
-
# # be at 75% opacity
|
19
|
+
# @example The fill will be at 50% opacity, but the stroke will be at 75% opacity.
|
49
20
|
# pdf.transparent(0.5, 0.75) do
|
50
21
|
# pdf.text("hello world")
|
51
22
|
# pdf.fill_and_stroke_circle([x, y], 25)
|
52
23
|
# end
|
53
24
|
#
|
25
|
+
# @param opacity [Number] Fill opacity. Clipped to the 0.0 to 1.0 range.
|
26
|
+
# @param stroke_opacity [Number] Stroke opacity. Clipped to the
|
27
|
+
# 0.0 to 1.0 range.
|
28
|
+
# @yield
|
29
|
+
# @return [void]
|
54
30
|
def transparent(opacity, stroke_opacity = opacity)
|
55
31
|
renderer.min_version(1.4)
|
56
32
|
|
57
|
-
opacity =
|
58
|
-
stroke_opacity =
|
33
|
+
opacity = opacity.clamp(0.0, 1.0)
|
34
|
+
stroke_opacity = stroke_opacity.clamp(0.0, 1.0)
|
59
35
|
|
60
36
|
save_graphics_state
|
61
37
|
renderer.add_content(
|
62
|
-
"/#{opacity_dictionary_name(opacity, stroke_opacity)} gs"
|
38
|
+
"/#{opacity_dictionary_name(opacity, stroke_opacity)} gs",
|
63
39
|
)
|
64
40
|
yield
|
65
41
|
restore_graphics_state
|
@@ -85,13 +61,13 @@ module Prawn
|
|
85
61
|
dictionary = ref!(
|
86
62
|
Type: :ExtGState,
|
87
63
|
CA: stroke_opacity,
|
88
|
-
ca: opacity
|
64
|
+
ca: opacity,
|
89
65
|
)
|
90
66
|
|
91
67
|
dictionary_name = "Tr#{next_opacity_dictionary_id}"
|
92
68
|
opacity_dictionary_registry[key] = {
|
93
69
|
name: dictionary_name,
|
94
|
-
obj: dictionary
|
70
|
+
obj: dictionary,
|
95
71
|
}
|
96
72
|
end
|
97
73
|
|