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
data/lib/prawn/graphics.rb
CHANGED
@@ -16,12 +16,8 @@ require_relative 'graphics/transformation'
|
|
16
16
|
require_relative 'graphics/patterns'
|
17
17
|
|
18
18
|
module Prawn
|
19
|
-
# Implements the drawing facilities for Prawn::Document.
|
19
|
+
# Implements the drawing facilities for {Prawn::Document}.
|
20
20
|
# Use this to draw the most beautiful imaginable things.
|
21
|
-
#
|
22
|
-
# This file lifts and modifies several of PDF::Writer's graphics functions
|
23
|
-
# ruby-pdf.rubyforge.org
|
24
|
-
#
|
25
21
|
module Graphics
|
26
22
|
include BlendMode
|
27
23
|
include Color
|
@@ -38,12 +34,20 @@ module Prawn
|
|
38
34
|
# Low level drawing operations must map the point to absolute coords! #
|
39
35
|
#######################################################################
|
40
36
|
|
41
|
-
# Moves the drawing position to a given point.
|
42
|
-
#
|
37
|
+
# Moves the drawing position to a given point. The point can be specified as
|
38
|
+
# a tuple or a flattened argument list.
|
43
39
|
#
|
44
|
-
#
|
45
|
-
# pdf.move_to
|
40
|
+
# @example
|
41
|
+
# pdf.move_to [100, 50]
|
42
|
+
# pdf.move_to(100, 50)
|
46
43
|
#
|
44
|
+
# @overload move_to(point)
|
45
|
+
# @param point [Array(Number, Number)]
|
46
|
+
# @return [void]
|
47
|
+
# @overload move_to(x, y)
|
48
|
+
# @param x [Number]
|
49
|
+
# @param y [Number]
|
50
|
+
# @return [void]
|
47
51
|
def move_to(*point)
|
48
52
|
xy = PDF::Core.real_params(map_to_absolute(point))
|
49
53
|
renderer.add_content("#{xy} m")
|
@@ -52,9 +56,17 @@ module Prawn
|
|
52
56
|
# Draws a line from the current drawing position to the specified point.
|
53
57
|
# The destination may be described as a tuple or a flattened list:
|
54
58
|
#
|
55
|
-
#
|
56
|
-
# pdf.line_to
|
57
|
-
#
|
59
|
+
# @example
|
60
|
+
# pdf.line_to [50, 50]
|
61
|
+
# pdf.line_to(50, 50)
|
62
|
+
#
|
63
|
+
# @overload line_to(point)
|
64
|
+
# @param point [Array(Number, Number)]
|
65
|
+
# @return [void]
|
66
|
+
# @overload line_to(x, y)
|
67
|
+
# @param x [Number]
|
68
|
+
# @param y [Number]
|
69
|
+
# @return [void]
|
58
70
|
def line_to(*point)
|
59
71
|
xy = PDF::Core.real_params(map_to_absolute(point))
|
60
72
|
renderer.add_content("#{xy} l")
|
@@ -63,27 +75,36 @@ module Prawn
|
|
63
75
|
# Draws a Bezier curve from the current drawing position to the
|
64
76
|
# specified point, bounded by two additional points.
|
65
77
|
#
|
66
|
-
#
|
78
|
+
# @example
|
79
|
+
# pdf.curve_to [100, 100], bounds: [[90, 90], [75, 75]]
|
67
80
|
#
|
81
|
+
# @param dest [Array(Number, Number)]
|
82
|
+
# @param options [Hash]
|
83
|
+
# @option options :bounds [Array(Array(Number, Number), Array(Number, Number))]
|
84
|
+
# @return [void]
|
68
85
|
def curve_to(dest, options = {})
|
69
86
|
options[:bounds] || raise(
|
70
87
|
Prawn::Errors::InvalidGraphicsPath,
|
71
|
-
'Bounding points for bezier curve must be specified '
|
72
|
-
'as :bounds => [[x1,y1],[x2,y2]]'
|
88
|
+
'Bounding points for bezier curve must be specified as :bounds => [[x1,y1],[x2,y2]]',
|
73
89
|
)
|
74
90
|
|
75
91
|
curve_points = PDF::Core.real_params(
|
76
|
-
(options[:bounds] << dest).flat_map { |e| map_to_absolute(e) }
|
92
|
+
(options[:bounds] << dest).flat_map { |e| map_to_absolute(e) },
|
77
93
|
)
|
78
94
|
|
79
95
|
renderer.add_content("#{curve_points} c")
|
80
96
|
end
|
81
97
|
|
82
|
-
# Draws a rectangle given
|
83
|
-
#
|
98
|
+
# Draws a rectangle given `point`, `width and `height`. The rectangle is
|
99
|
+
# bounded by its upper-left corner.
|
84
100
|
#
|
85
|
-
#
|
101
|
+
# @example
|
102
|
+
# pdf.rectangle [300, 300], 100, 200
|
86
103
|
#
|
104
|
+
# @param point [Array(Number, Number)]
|
105
|
+
# @param width [Number]
|
106
|
+
# @param height [Number]
|
107
|
+
# @return [void]
|
87
108
|
def rectangle(point, width, height)
|
88
109
|
x, y = map_to_absolute(point)
|
89
110
|
box = PDF::Core.real_params([x, y - height, width, height])
|
@@ -91,16 +112,21 @@ module Prawn
|
|
91
112
|
renderer.add_content("#{box} re")
|
92
113
|
end
|
93
114
|
|
94
|
-
# Draws a rounded rectangle given
|
95
|
-
#
|
96
|
-
# is bounded by its upper-left corner.
|
115
|
+
# Draws a rounded rectangle given `point`, `width`, `height`, and `radius`
|
116
|
+
# for the rounded corner. The rectangle is bounded by its upper-left corner.
|
97
117
|
#
|
98
|
-
#
|
118
|
+
# @example
|
119
|
+
# pdf.rounded_rectangle [300, 300], 100, 200, 10
|
99
120
|
#
|
121
|
+
# @param point [Array(Number, Number)]
|
122
|
+
# @param width [Number]
|
123
|
+
# @param height [Number]
|
124
|
+
# @param radius [Number]
|
125
|
+
# @return [void]
|
100
126
|
def rounded_rectangle(point, width, height, radius)
|
101
127
|
x, y = point
|
102
128
|
rounded_polygon(
|
103
|
-
radius, point, [x + width, y], [x + width, y - height], [x, y - height]
|
129
|
+
radius, point, [x + width, y], [x + width, y - height], [x, y - height],
|
104
130
|
)
|
105
131
|
end
|
106
132
|
|
@@ -108,8 +134,10 @@ module Prawn
|
|
108
134
|
# Higher level functions: May use relative coords #
|
109
135
|
###########################################################
|
110
136
|
|
111
|
-
# Sets line thickness to the
|
137
|
+
# Sets line thickness to the `width` specified.
|
112
138
|
#
|
139
|
+
# @param width [Number]
|
140
|
+
# @return [void]
|
113
141
|
def line_width=(width)
|
114
142
|
self.current_line_width = width
|
115
143
|
write_line_width
|
@@ -117,12 +145,18 @@ module Prawn
|
|
117
145
|
|
118
146
|
# When called without an argument, returns the current line thickness.
|
119
147
|
# When called with an argument, sets the line thickness to the specified
|
120
|
-
# value (in PDF points)
|
148
|
+
# value (in PDF points).
|
121
149
|
#
|
150
|
+
# @example
|
122
151
|
# pdf.line_width #=> 1
|
123
152
|
# pdf.line_width(5)
|
124
153
|
# pdf.line_width #=> 5
|
125
154
|
#
|
155
|
+
# @overload line_width()
|
156
|
+
# @return [Number]
|
157
|
+
# @overload line_width(width)
|
158
|
+
# @param width [Number]
|
159
|
+
# @return [void]
|
126
160
|
def line_width(width = nil)
|
127
161
|
if width
|
128
162
|
self.line_width = width
|
@@ -132,41 +166,64 @@ module Prawn
|
|
132
166
|
end
|
133
167
|
|
134
168
|
# Draws a line from one point to another. Points may be specified as
|
135
|
-
# tuples or flattened argument list
|
136
|
-
#
|
137
|
-
# pdf.line [100,100], [200,250]
|
138
|
-
# pdf.line(100,100,200,250)
|
169
|
+
# tuples or flattened argument list.
|
139
170
|
#
|
171
|
+
# @example
|
172
|
+
# pdf.line [100, 100], [200, 250]
|
173
|
+
# pdf.line(100, 100, 200, 250)
|
174
|
+
#
|
175
|
+
# @overload line(point1, point2)
|
176
|
+
# @param point1 [Array(Number, Number)]
|
177
|
+
# @param point2 [Array(Number, Number)]
|
178
|
+
# @return [void]
|
179
|
+
# @overload line(x1, y1, x2, y2)
|
180
|
+
# @param x1 [Number]
|
181
|
+
# @param y1 [Number]
|
182
|
+
# @param x2 [Number]
|
183
|
+
# @param y2 [Number]
|
184
|
+
# @return [void]
|
140
185
|
def line(*points)
|
141
186
|
x0, y0, x1, y1 = points.flatten
|
142
187
|
move_to(x0, y0)
|
143
188
|
line_to(x1, y1)
|
144
189
|
end
|
145
190
|
|
146
|
-
# Draws a horizontal line from
|
147
|
-
#
|
191
|
+
# Draws a horizontal line from `x1` to `x2` at the current {Document#y}
|
192
|
+
# position, or the position specified by the `:at` option.
|
148
193
|
#
|
149
|
-
#
|
150
|
-
# horizontal_line 25, 100, :
|
194
|
+
# @example Draw a line from `[25, 75]` to `[100, 75]`
|
195
|
+
# horizontal_line 25, 100, at: 75
|
151
196
|
#
|
197
|
+
# @param x1 [Number]
|
198
|
+
# @param x2 [Number]
|
199
|
+
# @param options [Hash]
|
200
|
+
# @option options :at [Number]
|
201
|
+
# @return [void]
|
152
202
|
def horizontal_line(x1, x2, options = {})
|
153
|
-
y1 = options[:at] || y - bounds.absolute_bottom
|
203
|
+
y1 = options[:at] || (y - bounds.absolute_bottom)
|
154
204
|
|
155
205
|
line(x1, y1, x2, y1)
|
156
206
|
end
|
157
207
|
|
158
208
|
# Draws a horizontal line from the left border to the right border of the
|
159
|
-
# bounding box at the current
|
209
|
+
# bounding box at the current {Document#y} position.
|
160
210
|
#
|
211
|
+
# @return [void]
|
161
212
|
def horizontal_rule
|
162
213
|
horizontal_line(bounds.left, bounds.right)
|
163
214
|
end
|
164
215
|
|
165
|
-
# Draws a vertical line at the x
|
216
|
+
# Draws a vertical line at the x coordinate given by `:at` from `y1` to
|
217
|
+
# `y2`.
|
166
218
|
#
|
167
|
-
#
|
168
|
-
# vertical_line 100, 300, :
|
219
|
+
# @example Draw a line from `[25, 100]` to `[25, 300]`
|
220
|
+
# vertical_line 100, 300, at: 25
|
169
221
|
#
|
222
|
+
# @param y1 [Number]
|
223
|
+
# @param y2 [Number]
|
224
|
+
# @param params [Hash]
|
225
|
+
# @option params :at [Number]
|
226
|
+
# @return [void]
|
170
227
|
def vertical_line(y1, y2, params)
|
171
228
|
line(params[:at], y1, params[:at], y2)
|
172
229
|
end
|
@@ -174,8 +231,14 @@ module Prawn
|
|
174
231
|
# Draws a Bezier curve between two points, bounded by two additional
|
175
232
|
# points
|
176
233
|
#
|
177
|
-
#
|
234
|
+
# @example
|
235
|
+
# pdf.curve [50, 100], [100, 100], bounds: [[90, 90], [75, 75]]
|
178
236
|
#
|
237
|
+
# @param origin [Array(Number, Number)]
|
238
|
+
# @param dest [Array(Number, Number)]
|
239
|
+
# @param options [Hash]
|
240
|
+
# @option options :bounds [Array(Array(Number, Number), Array(Number, Number))]
|
241
|
+
# @return [void]
|
179
242
|
def curve(origin, dest, options = {})
|
180
243
|
move_to(*origin)
|
181
244
|
curve_to(dest, options)
|
@@ -183,27 +246,33 @@ module Prawn
|
|
183
246
|
|
184
247
|
# This constant is used to approximate a symmetrical arc using a cubic
|
185
248
|
# Bezier curve.
|
186
|
-
#
|
187
249
|
KAPPA = 4.0 * ((Math.sqrt(2) - 1.0) / 3.0)
|
188
250
|
|
189
|
-
# Draws a circle of radius
|
190
|
-
#
|
251
|
+
# Draws a circle of radius `radius` with the centre-point at
|
252
|
+
# `point` as a complete subpath. The drawing point will be moved to
|
191
253
|
# the centre-point upon completion of the drawing the circle.
|
192
254
|
#
|
193
|
-
#
|
255
|
+
# @example
|
256
|
+
# pdf.circle [100, 100], 25
|
194
257
|
#
|
258
|
+
# @param center [Array(Number, Number)]
|
259
|
+
# @param radius [Number]
|
260
|
+
# @return [void]
|
195
261
|
def circle(center, radius)
|
196
262
|
ellipse(center, radius, radius)
|
197
263
|
end
|
198
264
|
|
199
|
-
# Draws an ellipse of
|
200
|
-
#
|
201
|
-
#
|
202
|
-
# completion of the drawing the ellipse.
|
265
|
+
# Draws an ellipse of `x` radius `radius1` and `y` radius `radius2` with the
|
266
|
+
# centre-point at `point` as a complete subpath. The drawing point will be
|
267
|
+
# moved to the centre-point upon completion of the drawing the ellipse.
|
203
268
|
#
|
204
|
-
#
|
205
|
-
# pdf.ellipse [100,100], 25, 50
|
269
|
+
# @example Draws an ellipse with x-radius 25 and y-radius 50
|
270
|
+
# pdf.ellipse [100, 100], 25, 50
|
206
271
|
#
|
272
|
+
# @param point [Array(Number, Number)]
|
273
|
+
# @param radius1 [Number]
|
274
|
+
# @param radius2 [Number]
|
275
|
+
# @return [void]
|
207
276
|
def ellipse(point, radius1, radius2 = radius1)
|
208
277
|
x, y = point
|
209
278
|
l1 = radius1 * KAPPA
|
@@ -212,137 +281,153 @@ module Prawn
|
|
212
281
|
move_to(x + radius1, y)
|
213
282
|
|
214
283
|
# Upper right hand corner
|
215
|
-
curve_to
|
216
|
-
|
284
|
+
curve_to(
|
285
|
+
[x, y + radius2],
|
286
|
+
bounds: [[x + radius1, y + l2], [x + l1, y + radius2]],
|
287
|
+
)
|
217
288
|
|
218
289
|
# Upper left hand corner
|
219
|
-
curve_to
|
220
|
-
|
290
|
+
curve_to(
|
291
|
+
[x - radius1, y],
|
292
|
+
bounds: [[x - l1, y + radius2], [x - radius1, y + l2]],
|
293
|
+
)
|
221
294
|
|
222
295
|
# Lower left hand corner
|
223
|
-
curve_to
|
224
|
-
|
296
|
+
curve_to(
|
297
|
+
[x, y - radius2],
|
298
|
+
bounds: [[x - radius1, y - l2], [x - l1, y - radius2]],
|
299
|
+
)
|
225
300
|
|
226
301
|
# Lower right hand corner
|
227
|
-
curve_to
|
228
|
-
|
302
|
+
curve_to(
|
303
|
+
[x + radius1, y],
|
304
|
+
bounds: [[x + l1, y - radius2], [x + radius1, y - l2]],
|
305
|
+
)
|
229
306
|
|
230
307
|
move_to(x, y)
|
231
308
|
end
|
232
309
|
|
233
310
|
# Draws a polygon from the specified points.
|
234
311
|
#
|
235
|
-
#
|
312
|
+
# @example Draws a snazzy triangle
|
236
313
|
# pdf.polygon [100,100], [100,200], [200,200]
|
237
314
|
#
|
315
|
+
# @param points [Array<Array(Number, Number)>]
|
316
|
+
# @return [void]
|
238
317
|
def polygon(*points)
|
239
|
-
move_to
|
240
|
-
(points[1
|
318
|
+
move_to(points[0])
|
319
|
+
(points[1..] << points[0]).each do |point|
|
241
320
|
line_to(*point)
|
242
321
|
end
|
243
322
|
# close the path
|
244
|
-
renderer.add_content
|
323
|
+
renderer.add_content('h')
|
245
324
|
end
|
246
325
|
|
247
326
|
# Draws a rounded polygon from specified points using the radius to define
|
248
|
-
# bezier curves
|
327
|
+
# bezier curves.
|
249
328
|
#
|
250
|
-
#
|
329
|
+
# @example Draws a rounded filled in polygon
|
251
330
|
# pdf.fill_and_stroke_rounded_polygon(
|
252
331
|
# 10, [100, 250], [200, 300], [300, 250], [300, 150], [200, 100],
|
253
332
|
# [100, 150]
|
254
333
|
# )
|
334
|
+
#
|
335
|
+
# @param radius [Number]
|
336
|
+
# @param points [Array<Array(Number, Number)>]
|
337
|
+
# @return [void]
|
255
338
|
def rounded_polygon(radius, *points)
|
256
|
-
move_to
|
339
|
+
move_to(point_on_line(radius, points[1], points[0]))
|
257
340
|
sides = points.size
|
258
341
|
points << points[0] << points[1]
|
259
342
|
sides.times do |i|
|
260
343
|
rounded_vertex(radius, points[i], points[i + 1], points[i + 2])
|
261
344
|
end
|
262
345
|
# close the path
|
263
|
-
renderer.add_content
|
346
|
+
renderer.add_content('h')
|
264
347
|
end
|
265
348
|
|
266
349
|
# Creates a rounded vertex for a line segment used for building a rounded
|
267
350
|
# polygon requires a radius to define bezier curve and three points. The
|
268
351
|
# first two points define the line segment and the third point helps define
|
269
352
|
# the curve for the vertex.
|
353
|
+
#
|
354
|
+
# @param radius [Number]
|
355
|
+
# @param points [Array(Array(Number, Number), Array(Number, Number), Array(Number, Number))]
|
356
|
+
# @return [void]
|
270
357
|
def rounded_vertex(radius, *points)
|
271
358
|
radial_point1 = point_on_line(radius, points[0], points[1])
|
272
359
|
bezier_point1 = point_on_line(
|
273
|
-
(radius - radius * KAPPA),
|
360
|
+
(radius - (radius * KAPPA)),
|
274
361
|
points[0],
|
275
|
-
points[1]
|
362
|
+
points[1],
|
276
363
|
)
|
277
364
|
radial_point2 = point_on_line(radius, points[2], points[1])
|
278
365
|
bezier_point2 = point_on_line(
|
279
|
-
(radius - radius * KAPPA),
|
366
|
+
(radius - (radius * KAPPA)),
|
280
367
|
points[2],
|
281
|
-
points[1]
|
368
|
+
points[1],
|
282
369
|
)
|
283
370
|
line_to(radial_point1)
|
284
371
|
curve_to(radial_point2, bounds: [bezier_point1, bezier_point2])
|
285
372
|
end
|
286
373
|
|
287
374
|
# Strokes the current path. If a block is provided, yields to the block
|
288
|
-
# before closing the path. See Graphics::Color for color details.
|
375
|
+
# before closing the path. See {Graphics::Color} for color details.
|
289
376
|
#
|
377
|
+
# @yield
|
378
|
+
# @return [void]
|
290
379
|
def stroke
|
291
380
|
yield if block_given?
|
292
|
-
renderer.add_content
|
381
|
+
renderer.add_content('S')
|
293
382
|
end
|
294
383
|
|
295
|
-
# Closes and strokes the current path. If a block is provided, yields to
|
296
|
-
#
|
384
|
+
# Closes and strokes the current path. If a block is provided, yields to the
|
385
|
+
# block before closing the path. See {Graphics::Color} for color details.
|
297
386
|
#
|
387
|
+
# @yield
|
388
|
+
# @return [void]
|
298
389
|
def close_and_stroke
|
299
390
|
yield if block_given?
|
300
|
-
renderer.add_content
|
391
|
+
renderer.add_content('s')
|
301
392
|
end
|
302
393
|
|
303
|
-
# Draws and strokes a rectangle represented by the current bounding box
|
394
|
+
# Draws and strokes a rectangle represented by the current bounding box.
|
304
395
|
#
|
396
|
+
# @return [void]
|
305
397
|
def stroke_bounds
|
306
|
-
stroke_rectangle
|
398
|
+
stroke_rectangle(bounds.top_left, bounds.width, bounds.height)
|
307
399
|
end
|
308
400
|
|
309
401
|
# Draws and strokes X and Y axes rulers beginning at the current bounding
|
310
402
|
# box origin (or at a custom location).
|
311
403
|
#
|
312
|
-
#
|
313
|
-
#
|
314
|
-
#
|
315
|
-
#
|
316
|
-
#
|
317
|
-
#
|
318
|
-
#
|
319
|
-
#
|
320
|
-
#
|
321
|
-
#
|
322
|
-
# Length of the
|
323
|
-
#
|
324
|
-
# +:step_length+::
|
325
|
-
# Length of the step between markers (default: 100)
|
326
|
-
#
|
327
|
-
# +:negative_axes_length+::
|
328
|
-
# Length of the negative parts of the axes (default: 20)
|
329
|
-
#
|
330
|
-
# +:color+:
|
404
|
+
# @param options [Hash]
|
405
|
+
# @option options :at [Array(Number, Number)] ([0, 0], origin of the bounding box)
|
406
|
+
# Origin of the X and Y axes.
|
407
|
+
# @option options :width [Number] (width of the bounding box)
|
408
|
+
# Length of the X axis.
|
409
|
+
# @option options :height [Number] (height of the bounding box)
|
410
|
+
# Length of the Y axis.
|
411
|
+
# @option options :step_length [Number] (100)
|
412
|
+
# Length of the step between markers.
|
413
|
+
# @option options :negative_axes_length [Number] (20)
|
414
|
+
# Length of the negative parts of the axes.
|
415
|
+
# @option options :color [String, Array<Number>]
|
331
416
|
# The color of the axes and the text.
|
332
|
-
#
|
417
|
+
# @return [void]
|
333
418
|
def stroke_axis(options = {})
|
334
419
|
options = {
|
335
420
|
at: [0, 0],
|
336
|
-
height: bounds.height
|
337
|
-
width: bounds.width
|
421
|
+
height: bounds.height - (options[:at] || [0, 0])[1],
|
422
|
+
width: bounds.width - (options[:at] || [0, 0])[0],
|
338
423
|
step_length: 100,
|
339
424
|
negative_axes_length: 20,
|
340
|
-
color: '000000'
|
425
|
+
color: '000000',
|
341
426
|
}.merge(options)
|
342
427
|
|
343
428
|
Prawn.verify_options(
|
344
429
|
%i[at width height step_length negative_axes_length color],
|
345
|
-
options
|
430
|
+
options,
|
346
431
|
)
|
347
432
|
|
348
433
|
save_graphics_state do
|
@@ -353,12 +438,12 @@ module Prawn
|
|
353
438
|
stroke_horizontal_line(
|
354
439
|
options[:at][0] - options[:negative_axes_length],
|
355
440
|
options[:at][0] + options[:width],
|
356
|
-
at: options[:at][1]
|
441
|
+
at: options[:at][1],
|
357
442
|
)
|
358
443
|
stroke_vertical_line(
|
359
444
|
options[:at][1] - options[:negative_axes_length],
|
360
445
|
options[:at][1] + options[:height],
|
361
|
-
at: options[:at][0]
|
446
|
+
at: options[:at][0],
|
362
447
|
)
|
363
448
|
undash
|
364
449
|
|
@@ -370,7 +455,7 @@ module Prawn
|
|
370
455
|
draw_text(
|
371
456
|
point,
|
372
457
|
at: [options[:at][0] + point - 5, options[:at][1] - 10],
|
373
|
-
size: 7
|
458
|
+
size: 7,
|
374
459
|
)
|
375
460
|
end
|
376
461
|
|
@@ -380,33 +465,41 @@ module Prawn
|
|
380
465
|
draw_text(
|
381
466
|
point,
|
382
467
|
at: [options[:at][0] - 17, options[:at][1] + point - 2],
|
383
|
-
size: 7
|
468
|
+
size: 7,
|
384
469
|
)
|
385
470
|
end
|
386
471
|
end
|
387
472
|
end
|
388
473
|
|
389
|
-
# Closes and fills the current path. See Graphics::Color for color details.
|
474
|
+
# Closes and fills the current path. See {Graphics::Color} for color details.
|
390
475
|
#
|
391
|
-
# If the option :
|
476
|
+
# If the option `fill_rule: :even_odd` is specified, Prawn will use the
|
392
477
|
# even-odd rule to fill the path. Otherwise, the nonzero winding number rule
|
393
478
|
# will be used. See the PDF reference, "Graphics -> Path Construction and
|
394
479
|
# Painting -> Clipping Path Operators" for details on the difference.
|
395
480
|
#
|
481
|
+
# @param options [Hash]
|
482
|
+
# @option options :fill_rule [Symbol]
|
483
|
+
# @yield
|
484
|
+
# @return [void]
|
396
485
|
def fill(options = {})
|
397
486
|
yield if block_given?
|
398
487
|
renderer.add_content(options[:fill_rule] == :even_odd ? 'f*' : 'f')
|
399
488
|
end
|
400
489
|
|
401
490
|
# Closes, fills, and strokes the current path. If a block is provided,
|
402
|
-
# yields to the block before closing the path. See Graphics::Color for
|
491
|
+
# yields to the block before closing the path. See {Graphics::Color} for
|
403
492
|
# color details.
|
404
493
|
#
|
405
|
-
# If the option :
|
494
|
+
# If the option `fill_rule: :even_odd` is specified, Prawn will use the
|
406
495
|
# even-odd rule to fill the path. Otherwise, the nonzero winding number rule
|
407
496
|
# will be used. See the PDF reference, "Graphics -> Path Construction and
|
408
497
|
# Painting -> Clipping Path Operators" for details on the difference.
|
409
498
|
#
|
499
|
+
# @param options [Hash]
|
500
|
+
# @option options :fill_rule [Symbol]
|
501
|
+
# @yield
|
502
|
+
# @return [void]
|
410
503
|
def fill_and_stroke(options = {})
|
411
504
|
yield if block_given?
|
412
505
|
renderer.add_content(options[:fill_rule] == :even_odd ? 'b*' : 'b')
|
@@ -415,214 +508,231 @@ module Prawn
|
|
415
508
|
# Closes the current path.
|
416
509
|
#
|
417
510
|
def close_path
|
418
|
-
renderer.add_content
|
511
|
+
renderer.add_content('h')
|
419
512
|
end
|
420
513
|
|
421
|
-
|
422
|
-
#
|
514
|
+
# @!method fill_rectangle(point, width, height)
|
515
|
+
# Draws and fills a rectangle given `point`, `width`, and `height`. The
|
516
|
+
# rectangle is bounded by its upper-left corner.
|
423
517
|
#
|
424
|
-
#
|
425
|
-
#
|
426
|
-
#
|
427
|
-
#
|
428
|
-
# stroke_rectangle(point,width,height)
|
518
|
+
# @param point [Array(Number, Number)]
|
519
|
+
# @param width [Number]
|
520
|
+
# @param height [Number]
|
521
|
+
# @return [void]
|
429
522
|
|
430
|
-
|
431
|
-
#
|
432
|
-
#
|
433
|
-
# Draws and fills ills a rectangle given +point+, +width+ and +height+. The
|
434
|
-
# rectangle is bounded by its upper-left corner.
|
523
|
+
# @!method stroke_rectangle(point, width, height)
|
524
|
+
# Draws and strokes a rectangle given `point`, `width`, and `height`. The
|
525
|
+
# rectangle is bounded by its upper-left corner.
|
435
526
|
#
|
436
|
-
#
|
437
|
-
#
|
527
|
+
# @param point [Array(Number, Number)]
|
528
|
+
# @param width [Number]
|
529
|
+
# @param height [Number]
|
530
|
+
# @return [void]
|
438
531
|
|
439
|
-
|
440
|
-
#
|
441
|
-
#
|
442
|
-
# Draws, fills, and strokes a rectangle given +point+, +width+ and +height+.
|
443
|
-
# The rectangle is bounded by its upper-left corner.
|
532
|
+
# @!method fill_and_stroke_rectangle(point, width, height)
|
533
|
+
# Draws, fills, and strokes a rectangle given `point`, `width`, and
|
534
|
+
# `height`. The rectangle is bounded by its upper-left corner.
|
444
535
|
#
|
445
|
-
#
|
446
|
-
#
|
536
|
+
# @param point [Array(Number, Number)]
|
537
|
+
# @param width [Number]
|
538
|
+
# @param height [Number]
|
539
|
+
# @return [void]
|
447
540
|
|
448
|
-
|
449
|
-
# :method: stroke_rounded_rectangle
|
541
|
+
# @!method fill_rounded_rectangle(point, width, height, radius)
|
450
542
|
#
|
451
|
-
#
|
452
|
-
#
|
453
|
-
#
|
543
|
+
# Draws and fills a rounded rectangle given `point`, `width` and `height`,
|
544
|
+
# and `radius` for the rounded corner. The rectangle is bounded by its
|
545
|
+
# upper-left corner.
|
454
546
|
#
|
455
|
-
#
|
456
|
-
#
|
547
|
+
# @param point [Array(Number, Number)]
|
548
|
+
# @param width [Number]
|
549
|
+
# @param height [Number]
|
550
|
+
# @param radius [Number]
|
551
|
+
# @return [void]
|
457
552
|
|
458
|
-
|
459
|
-
#
|
553
|
+
# @!method stroke_rounded_rectangle(point, width, height, radius)
|
554
|
+
# Draws and strokes a rounded rectangle given `point`, `width` and
|
555
|
+
# `height`, and `radius` for the rounded corner. The rectangle is bounded
|
556
|
+
# by its upper-left corner.
|
460
557
|
#
|
461
|
-
#
|
462
|
-
#
|
463
|
-
#
|
464
|
-
#
|
465
|
-
#
|
466
|
-
# fill_rounded_rectangle(point,width,height,radius)
|
558
|
+
# @param point [Array(Number, Number)]
|
559
|
+
# @param width [Number]
|
560
|
+
# @param height [Number]
|
561
|
+
# @param radius [Number]
|
562
|
+
# @return [void]
|
467
563
|
|
468
|
-
|
469
|
-
# :method: stroke_and_fill_rounded_rectangle
|
564
|
+
# @!method fill_and_stroke_rounded_rectangle(point, width, height, radius)
|
470
565
|
#
|
471
|
-
#
|
472
|
-
#
|
473
|
-
# its upper-left corner.
|
566
|
+
# Draws, fills, and strokes a rounded rectangle given `point`, `width`,
|
567
|
+
# and `height` and `radius` for the rounded corner. The rectangle is
|
568
|
+
# bounded by its upper-left corner.
|
474
569
|
#
|
475
|
-
#
|
476
|
-
#
|
570
|
+
# @param point [Array(Number, Number)]
|
571
|
+
# @param width [Number]
|
572
|
+
# @param height [Number]
|
573
|
+
# @param radius [Number]
|
574
|
+
# @return [void]
|
477
575
|
|
478
|
-
|
479
|
-
# :method: stroke_line
|
576
|
+
# @!method stroke_line(*points)
|
480
577
|
#
|
481
|
-
#
|
482
|
-
#
|
578
|
+
# Strokes a line from one point to another. Points may be specified as
|
579
|
+
# tuples or flattened argument list.
|
483
580
|
#
|
484
|
-
#
|
485
|
-
#
|
581
|
+
# @overload line(point1, point2)
|
582
|
+
# @param point1 [Array(Number, Number)]
|
583
|
+
# @param point2 [Array(Number, Number)]
|
584
|
+
# @return [void]
|
585
|
+
# @overload line(x1, y1, x2, y2)
|
586
|
+
# @param x1 [Number]
|
587
|
+
# @param y1 [Number]
|
588
|
+
# @param x2 [Number]
|
589
|
+
# @param y2 [Number]
|
590
|
+
# @return [void]
|
486
591
|
|
487
|
-
|
488
|
-
# :method: stroke_horizontal_line
|
592
|
+
# @!method stroke_horizontal_line(x1, x2, options = {})
|
489
593
|
#
|
490
|
-
#
|
491
|
-
# the position specified by the :at option.
|
594
|
+
# Strokes a horizontal line from `x1` to `x2` at the current y position,
|
595
|
+
# or the position specified by the :at option.
|
492
596
|
#
|
493
|
-
#
|
494
|
-
#
|
597
|
+
# @param x1 [Number]
|
598
|
+
# @param x2 [Number]
|
599
|
+
# @param options [Hash]
|
600
|
+
# @option options :at [Number]
|
601
|
+
# @return [void]
|
495
602
|
|
496
|
-
|
497
|
-
# :method: stroke_horizontal_rule
|
603
|
+
# @!method stroke_horizontal_rule
|
498
604
|
#
|
499
|
-
#
|
500
|
-
# bounding box at the current y position.
|
605
|
+
# Strokes a horizontal line from the left border to the right border of
|
606
|
+
# the bounding box at the current y position.
|
501
607
|
#
|
502
|
-
#
|
503
|
-
# stroke_horizontal_rule
|
608
|
+
# @return [void]
|
504
609
|
|
505
|
-
|
506
|
-
# :method: stroke_vertical_line
|
610
|
+
# @!method stroke_vertical_line(y1, y2, params)
|
507
611
|
#
|
508
|
-
#
|
612
|
+
# Strokes a vertical line at the x coordinate given by `:at` from `y1` to
|
613
|
+
# `y2`.
|
509
614
|
#
|
510
|
-
#
|
511
|
-
#
|
615
|
+
# @param y1 [Number]
|
616
|
+
# @param y2 [Number]
|
617
|
+
# @param params [Hash]
|
618
|
+
# @option params :at [Number]
|
619
|
+
# @return [void]
|
512
620
|
|
513
|
-
|
514
|
-
# :method: stroke_curve
|
621
|
+
# @!method stroke_curve(origin, dest, options = {})
|
515
622
|
#
|
516
|
-
#
|
517
|
-
#
|
623
|
+
# Strokes a Bezier curve between two points, bounded by two additional
|
624
|
+
# points.
|
518
625
|
#
|
519
|
-
#
|
520
|
-
#
|
626
|
+
# @param origin [Array(Number, Number)]
|
627
|
+
# @param dest [Array(Number, Number)]
|
628
|
+
# @param options [Hash]
|
629
|
+
# @option options :bounds [Array(Array(Number, Number), Array(Number, Number))]
|
630
|
+
# @return [void]
|
521
631
|
|
522
|
-
|
523
|
-
# :method: stroke_circle
|
632
|
+
# @!method: stroke_circle(center, radius)
|
524
633
|
#
|
525
|
-
#
|
526
|
-
#
|
634
|
+
# Draws and strokes a circle of radius `radius` with the centre-point at
|
635
|
+
# `point`.
|
527
636
|
#
|
528
|
-
#
|
529
|
-
#
|
637
|
+
# @param center [Array(Number, Number)]
|
638
|
+
# @param radius [Number]
|
639
|
+
# @return [void]
|
530
640
|
|
531
|
-
|
532
|
-
# :method: fill_circle
|
641
|
+
# @!method fill_circle(center, radius)
|
533
642
|
#
|
534
|
-
#
|
535
|
-
#
|
643
|
+
# Draws and fills a circle of radius `radius` with the centre-point at
|
644
|
+
# `point`.
|
536
645
|
#
|
537
|
-
#
|
538
|
-
#
|
646
|
+
# @param center [Array(Number, Number)]
|
647
|
+
# @param radius [Number]
|
648
|
+
# @return [void]
|
539
649
|
|
540
|
-
|
541
|
-
# :method: fill_and_stroke_circle
|
650
|
+
# @!method fill_and_stroke_circle(center, radius)
|
542
651
|
#
|
543
|
-
#
|
544
|
-
#
|
652
|
+
# Draws, strokes, and fills a circle of radius `radius` with the
|
653
|
+
# centre-point at `point`.
|
545
654
|
#
|
546
|
-
#
|
547
|
-
#
|
655
|
+
# @param center [Array(Number, Number)]
|
656
|
+
# @param radius [Number]
|
657
|
+
# @return [void]
|
548
658
|
|
549
|
-
|
550
|
-
# :method: stroke_ellipse
|
659
|
+
# @!method stroke_ellipse(point, radius1, radius2 = radius1)
|
551
660
|
#
|
552
|
-
#
|
553
|
-
#
|
661
|
+
# Draws and strokes an ellipse of x radius `r1` and y radius `r2` with the
|
662
|
+
# centre-point at `point`.
|
554
663
|
#
|
555
|
-
#
|
556
|
-
#
|
664
|
+
# @param point [Array(Number, Number)]
|
665
|
+
# @param radius1 [Number]
|
666
|
+
# @param radius2 [Number]
|
667
|
+
# @return [void]
|
557
668
|
|
558
|
-
|
559
|
-
# :method: fill_ellipse
|
669
|
+
# @!method fill_ellipse(point, radius1, radius2 = radius1)
|
560
670
|
#
|
561
|
-
#
|
562
|
-
#
|
671
|
+
# Draws and fills an ellipse of x radius `r1` and y radius `r2` with the
|
672
|
+
# centre-point at `point`.
|
563
673
|
#
|
564
|
-
#
|
565
|
-
#
|
674
|
+
# @param point [Array(Number, Number)]
|
675
|
+
# @param radius1 [Number]
|
676
|
+
# @param radius2 [Number]
|
677
|
+
# @return [void]
|
566
678
|
|
567
|
-
|
568
|
-
# :method: fill_and_stroke_ellipse
|
679
|
+
# @!method fill_and_stroke_ellipse(point, radius1, radius2 = radius1)
|
569
680
|
#
|
570
|
-
#
|
571
|
-
#
|
681
|
+
# Draws, strokes, and fills an ellipse of x radius `r1` and y radius `r2`
|
682
|
+
# with the centre-point at `point`.
|
572
683
|
#
|
573
|
-
#
|
574
|
-
#
|
684
|
+
# @param point [Array(Number, Number)]
|
685
|
+
# @param radius1 [Number]
|
686
|
+
# @param radius2 [Number]
|
687
|
+
# @return [void]
|
575
688
|
|
576
|
-
|
577
|
-
# :method: stroke_polygon
|
689
|
+
# @!method stroke_polygon(*points)
|
578
690
|
#
|
579
691
|
# Draws and strokes a polygon from the specified points.
|
580
692
|
#
|
581
|
-
#
|
582
|
-
#
|
693
|
+
# @param points [Array<Array(Number, Number)>]
|
694
|
+
# @return [void]
|
583
695
|
|
584
|
-
|
585
|
-
# :method: fill_polygon
|
696
|
+
# @!method fill_polygon(*points)
|
586
697
|
#
|
587
|
-
#
|
698
|
+
# Draws and fills a polygon from the specified points.
|
588
699
|
#
|
589
|
-
#
|
590
|
-
#
|
700
|
+
# @param points [Array<Array(Number, Number)>]
|
701
|
+
# @return [void]
|
591
702
|
|
592
|
-
|
593
|
-
# :method: fill_and_stroke_polygon
|
703
|
+
# @!method fill_and_stroke_polygon(*points)
|
594
704
|
#
|
595
|
-
#
|
705
|
+
# Draws, strokes, and fills a polygon from the specified points.
|
596
706
|
#
|
597
|
-
#
|
598
|
-
#
|
707
|
+
# @param points [Array<Array(Number, Number)>]
|
708
|
+
# @return [void]
|
599
709
|
|
600
|
-
|
601
|
-
# :method: stroke_rounded_polygon
|
710
|
+
# @!method stroke_rounded_polygon(radius, *points)
|
602
711
|
#
|
603
|
-
#
|
604
|
-
# to define Bezier curves.
|
712
|
+
# Draws and strokes a rounded polygon from specified points, using
|
713
|
+
# `radius` to define Bezier curves.
|
605
714
|
#
|
606
|
-
#
|
607
|
-
#
|
715
|
+
# @param radius [Number]
|
716
|
+
# @param points [Array<Array(Number, Number)>]
|
717
|
+
# @return [void]
|
608
718
|
|
609
|
-
|
610
|
-
# :method: fill_rounded_polygon
|
719
|
+
# @!method fill_rounded_polygon(radius, *points)
|
611
720
|
#
|
612
|
-
#
|
613
|
-
# define Bezier curves.
|
721
|
+
# Draws and fills a rounded polygon from specified points, using `radius`
|
722
|
+
# to define Bezier curves.
|
614
723
|
#
|
615
|
-
#
|
616
|
-
#
|
724
|
+
# @param radius [Number]
|
725
|
+
# @param points [Array<Array(Number, Number)>]
|
726
|
+
# @return [void]
|
617
727
|
|
618
|
-
|
619
|
-
# :method: fill_and_stroke_rounded_polygon
|
728
|
+
# @!method fill_and_stroke_rounded_polygon(radius, *points)
|
620
729
|
#
|
621
|
-
#
|
622
|
-
#
|
730
|
+
# Draws, strokes, and fills a rounded polygon from specified points, using
|
731
|
+
# `radius` to define Bezier curves.
|
623
732
|
#
|
624
|
-
#
|
625
|
-
#
|
733
|
+
# @param radius [Number]
|
734
|
+
# @param points [Array<Array(Number, Number)>]
|
735
|
+
# @return [void]
|
626
736
|
|
627
737
|
ops = %w[fill stroke fill_and_stroke]
|
628
738
|
shapes = %w[
|
@@ -671,10 +781,10 @@ module Prawn
|
|
671
781
|
# away from the second point defining the line segement
|
672
782
|
def point_on_line(distance_from_end, *points)
|
673
783
|
x0, y0, x1, y1 = points.flatten
|
674
|
-
length = Math.sqrt((x1 - x0)**2 + (y1 - y0)**2)
|
784
|
+
length = Math.sqrt(((x1 - x0)**2) + ((y1 - y0)**2))
|
675
785
|
p = (length - distance_from_end) / length
|
676
|
-
xr = x0 + p * (x1 - x0)
|
677
|
-
yr = y0 + p * (y1 - y0)
|
786
|
+
xr = x0 + (p * (x1 - x0))
|
787
|
+
yr = y0 + (p * (y1 - y0))
|
678
788
|
[xr, yr]
|
679
789
|
end
|
680
790
|
end
|