prawn 2.4.0 → 2.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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
@@ -1,24 +1,21 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# cap_style.rb : Implements stroke cap styling
|
4
|
-
#
|
5
|
-
# Contributed by Daniel Nelson. October, 2009
|
6
|
-
#
|
7
|
-
# This is free software. Please see the LICENSE and COPYING files for details.
|
8
|
-
#
|
9
3
|
module Prawn
|
10
4
|
module Graphics
|
5
|
+
# Implements stroke cap styling
|
11
6
|
module CapStyle
|
12
7
|
# @group Stable API
|
13
8
|
|
9
|
+
# @private
|
14
10
|
CAP_STYLES = { butt: 0, round: 1, projecting_square: 2 }.freeze
|
15
11
|
|
16
|
-
# Sets the cap style for stroked lines and curves
|
17
|
-
#
|
18
|
-
# style is one of :butt, :round, or :projecting_square
|
19
|
-
#
|
20
|
-
# NOTE: If this method is never called, :butt will be used by default.
|
12
|
+
# Sets the cap style for stroked lines and curves.
|
21
13
|
#
|
14
|
+
# @overload cap_style(style)
|
15
|
+
# @param style [:butt, :round, :projecting_square] (:butt)
|
16
|
+
# @return [void]
|
17
|
+
# @overload cap_style()
|
18
|
+
# @return [Symbol]
|
22
19
|
def cap_style(style = nil)
|
23
20
|
return current_cap_style || :butt if style.nil?
|
24
21
|
|
@@ -40,7 +37,7 @@ module Prawn
|
|
40
37
|
end
|
41
38
|
|
42
39
|
def write_stroke_cap_style
|
43
|
-
renderer.add_content
|
40
|
+
renderer.add_content("#{CAP_STYLES[current_cap_style]} J")
|
44
41
|
end
|
45
42
|
end
|
46
43
|
end
|
data/lib/prawn/graphics/color.rb
CHANGED
@@ -1,30 +1,37 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# color.rb : Implements color handling
|
4
|
-
#
|
5
|
-
# Copyright June 2008, Gregory Brown. All Rights Reserved.
|
6
|
-
#
|
7
|
-
# This is free software. Please see the LICENSE and COPYING files for details.
|
8
|
-
|
9
3
|
module Prawn
|
10
4
|
module Graphics
|
5
|
+
# Implements color handling.
|
11
6
|
module Color
|
12
7
|
# @group Stable API
|
13
8
|
|
14
9
|
# Sets or returns the fill color.
|
15
10
|
#
|
16
|
-
#
|
11
|
+
# @overload fill_color
|
12
|
+
# Returns the current fill color.
|
13
|
+
#
|
14
|
+
# @return [String, Array<Number>]
|
15
|
+
#
|
16
|
+
# @overload fill_color(color)
|
17
|
+
# Sets the fill color.
|
17
18
|
#
|
18
|
-
#
|
19
|
-
#
|
19
|
+
# If a single argument is provided, it should be a 6 digit HTML color
|
20
|
+
# code.
|
20
21
|
#
|
22
|
+
# ```ruby
|
21
23
|
# pdf.fill_color "f0ffc1"
|
24
|
+
# ```
|
22
25
|
#
|
23
|
-
#
|
24
|
-
#
|
26
|
+
# If 4 arguments are provided, the color is assumed to be a CMYK value.
|
27
|
+
# Values range is 0–100.
|
25
28
|
#
|
29
|
+
# ```ruby
|
26
30
|
# pdf.fill_color 0, 99, 95, 0
|
31
|
+
# ```
|
27
32
|
#
|
33
|
+
# @param color [String, Array<Number>]
|
34
|
+
# @return [void]
|
28
35
|
def fill_color(*color)
|
29
36
|
return current_fill_color if color.empty?
|
30
37
|
|
@@ -36,18 +43,27 @@ module Prawn
|
|
36
43
|
|
37
44
|
# Sets or returns the line stroking color.
|
38
45
|
#
|
39
|
-
#
|
46
|
+
# @overload stroke_color
|
47
|
+
# When called with no argument, it returns the current stroking color.
|
40
48
|
#
|
41
|
-
#
|
42
|
-
# code.
|
49
|
+
# @return [String, Array<Number>]
|
43
50
|
#
|
44
|
-
#
|
51
|
+
# @overload stroke_color(color)
|
52
|
+
# Sets the stroking color.
|
45
53
|
#
|
46
|
-
#
|
47
|
-
#
|
54
|
+
# @param color [String, Array<Number>] new stroking color:
|
55
|
+
# - In String form it should be a 6 digit HTML color code.
|
48
56
|
#
|
49
|
-
#
|
57
|
+
# ```ruby
|
58
|
+
# pdf.stroke_color "f0ffc1"
|
59
|
+
# ```
|
60
|
+
# - If 4 arguments are provided, the color is assumed to be a CMYK
|
61
|
+
# value. Values range from 0 to 100.
|
50
62
|
#
|
63
|
+
# ```ruby
|
64
|
+
# pdf.stroke_color 0, 99, 95, 0
|
65
|
+
# ```
|
66
|
+
# @return [void]
|
51
67
|
def stroke_color(*color)
|
52
68
|
return current_stroke_color if color.empty?
|
53
69
|
|
@@ -60,21 +76,28 @@ module Prawn
|
|
60
76
|
|
61
77
|
module_function
|
62
78
|
|
63
|
-
# Converts RGB value array to hex string suitable for use with
|
64
|
-
# and stroke_color
|
79
|
+
# Converts RGB value array to hex string suitable for use with
|
80
|
+
# {fill_color} and {stroke_color}.
|
65
81
|
#
|
66
|
-
#
|
67
|
-
#
|
82
|
+
# @example
|
83
|
+
# Prawn::Graphics::Color.rgb2hex([255, 120, 8])
|
84
|
+
# #=> "ff7808"
|
68
85
|
#
|
86
|
+
# @param rgb [Array(Number, Number, Number)]
|
87
|
+
# Each component has to be in the range from 0 to 255.
|
88
|
+
# @return [String]
|
69
89
|
def rgb2hex(rgb)
|
70
|
-
rgb.map { |e| format
|
90
|
+
rgb.map { |e| format('%<value>02x', value: e) }.join
|
71
91
|
end
|
72
92
|
|
73
|
-
# Converts hex string into RGB value array
|
93
|
+
# Converts hex string into RGB value array.
|
74
94
|
#
|
75
|
-
#
|
76
|
-
#
|
95
|
+
# @example
|
96
|
+
# Prawn::Graphics::Color.hex2rgb("ff7808")
|
97
|
+
# #=> [255, 120, 8]
|
77
98
|
#
|
99
|
+
# @param hex [String] must be 6-digits long.
|
100
|
+
# @return [Array(Integer, Integer, Integer)]
|
78
101
|
def hex2rgb(hex)
|
79
102
|
r = hex[0..1]
|
80
103
|
g = hex[2..3]
|
@@ -127,7 +150,7 @@ module Prawn
|
|
127
150
|
end
|
128
151
|
|
129
152
|
def color_to_s(color)
|
130
|
-
PDF::Core.real_params
|
153
|
+
PDF::Core.real_params(normalize_color(color))
|
131
154
|
end
|
132
155
|
|
133
156
|
def color_space(color)
|
@@ -164,7 +187,7 @@ module Prawn
|
|
164
187
|
raise ArgumentError, "unknown type '#{type}'"
|
165
188
|
end
|
166
189
|
|
167
|
-
renderer.add_content
|
190
|
+
renderer.add_content("/#{color_space} #{operator}")
|
168
191
|
end
|
169
192
|
|
170
193
|
def set_color(type, color, options = {})
|
@@ -179,21 +202,21 @@ module Prawn
|
|
179
202
|
end
|
180
203
|
|
181
204
|
if options[:pattern]
|
182
|
-
set_color_space
|
183
|
-
renderer.add_content
|
205
|
+
set_color_space(type, :Pattern)
|
206
|
+
renderer.add_content("/#{color} #{operator}")
|
184
207
|
else
|
185
|
-
set_color_space
|
208
|
+
set_color_space(type, color_space(color))
|
186
209
|
color = color_to_s(color)
|
187
210
|
write_color(color, operator)
|
188
211
|
end
|
189
212
|
end
|
190
213
|
|
191
214
|
def set_fill_color(color = nil)
|
192
|
-
set_color
|
215
|
+
set_color(:fill, color || current_fill_color)
|
193
216
|
end
|
194
217
|
|
195
218
|
def set_stroke_color(color = nil)
|
196
|
-
set_color
|
219
|
+
set_color(:stroke, color || current_stroke_color)
|
197
220
|
end
|
198
221
|
|
199
222
|
def update_colors
|
@@ -227,7 +250,7 @@ module Prawn
|
|
227
250
|
end
|
228
251
|
|
229
252
|
def write_color(color, operator)
|
230
|
-
renderer.add_content
|
253
|
+
renderer.add_content("#{color} #{operator}")
|
231
254
|
end
|
232
255
|
end
|
233
256
|
end
|
data/lib/prawn/graphics/dash.rb
CHANGED
@@ -1,60 +1,61 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# dash.rb : Implements stroke dashing
|
4
|
-
#
|
5
|
-
# Contributed by Daniel Nelson. October, 2009
|
6
|
-
#
|
7
|
-
# This is free software. Please see the LICENSE and COPYING files for details.
|
8
|
-
#
|
9
3
|
module Prawn
|
10
4
|
module Graphics
|
5
|
+
# Implements stroke dashing.
|
11
6
|
module Dash
|
12
7
|
# @group Stable API
|
13
8
|
|
14
|
-
#
|
15
|
-
# current dash pattern setting if +length+ is nil.
|
9
|
+
# Get or set stroke dash pattern.
|
16
10
|
#
|
17
|
-
#
|
11
|
+
# @overload dash()
|
12
|
+
# Returns the current dash pattern.
|
18
13
|
#
|
19
|
-
#
|
20
|
-
# the length of the dash and of the gap. The length of the gap
|
21
|
-
# can be customized by setting the :space option.
|
14
|
+
# @return [Hash{:dash => Number, Array<Number>, :space => Number, nil, :phase => Number}]
|
22
15
|
#
|
23
|
-
#
|
16
|
+
# @overload dash(length, options ={})
|
17
|
+
# Sets the dash pattern for stroked lines and curves.
|
24
18
|
#
|
25
|
-
#
|
26
|
-
#
|
27
|
-
# length = 3, :space =2
|
28
|
-
# 3 on, 2 off, 3 on, 2 off, ...
|
19
|
+
# Integers or Floats may be used for length and the option values.
|
20
|
+
# Dash units are in PDF points (1/72 inch).
|
29
21
|
#
|
30
|
-
#
|
31
|
-
#
|
32
|
-
#
|
33
|
-
#
|
22
|
+
# @param length [Number, Array<Number>]
|
23
|
+
# * If `length` is a Number (Integer or Float), it specifies the
|
24
|
+
# length of the dash and of the gap. The length of the gap can be
|
25
|
+
# customized by setting the `:space` option.
|
34
26
|
#
|
35
|
-
#
|
27
|
+
# Examples:
|
36
28
|
#
|
37
|
-
#
|
38
|
-
#
|
39
|
-
# length = [3, 1, 2, 3]
|
40
|
-
# 3 on, 1 off, 2 on, 3 off, 3 on, 1 off, ...
|
41
|
-
# length = [3, 0, 1]
|
42
|
-
# 3 on, 0 off, 1 on, 3 off, 0 on, 1 off, ...
|
29
|
+
# length = 3
|
30
|
+
# : 3 on, 3 off, 3 on, 3 off, ...
|
43
31
|
#
|
44
|
-
#
|
32
|
+
# length = 3, :space = 2
|
33
|
+
# : 3 on, 2 off, 3 on, 2 off, ...
|
45
34
|
#
|
46
|
-
#
|
47
|
-
#
|
35
|
+
# * If `length` is an array, it specifies the lengths of alternating
|
36
|
+
# dashes and gaps. The numbers must be non-negative and not all
|
37
|
+
# zero. The `:space` option is ignored in this case.
|
48
38
|
#
|
49
|
-
#
|
50
|
-
# the dash. For example, a phase of 0 starts at the
|
51
|
-
# beginning of the dash; whereas, if the phase is equal
|
52
|
-
# to the length of the dash, then stroking will begin at
|
53
|
-
# the beginning of the space. Default is 0.
|
39
|
+
# Examples:
|
54
40
|
#
|
55
|
-
#
|
56
|
-
#
|
41
|
+
# length = [2, 1]
|
42
|
+
# : 2 on, 1 off, 2 on, 1 off, ...
|
57
43
|
#
|
44
|
+
# length = [3, 1, 2, 3]
|
45
|
+
# : 3 on, 1 off, 2 on, 3 off, 3 on, 1 off, ...
|
46
|
+
#
|
47
|
+
# length = [3, 0, 1]
|
48
|
+
# : 3 on, 0 off, 1 on, 3 off, 0 on, 1 off, ...
|
49
|
+
# @param options [Hash{Symbol => any}]
|
50
|
+
# @option options :space [Number]
|
51
|
+
# The space between the dashes (only used when `length` is not an
|
52
|
+
# array).
|
53
|
+
# @option options :phase [Number] (0)
|
54
|
+
# The distance into the dash pattern at which to start the dash. For
|
55
|
+
# example, a phase of 0 starts at the beginning of the dash; whereas,
|
56
|
+
# if the phase is equal to the length of the dash, then stroking will
|
57
|
+
# begin at the beginning of the space.
|
58
|
+
# @return [void]
|
58
59
|
def dash(length = nil, options = {})
|
59
60
|
return current_dash_state if length.nil?
|
60
61
|
|
@@ -73,7 +74,7 @@ module Prawn
|
|
73
74
|
self.current_dash_state = {
|
74
75
|
dash: length,
|
75
76
|
space: length.is_a?(Array) ? nil : options[:space] || length,
|
76
|
-
phase: options[:phase] || 0
|
77
|
+
phase: options[:phase] || 0,
|
77
78
|
}
|
78
79
|
|
79
80
|
write_stroke_dash
|
@@ -81,15 +82,17 @@ module Prawn
|
|
81
82
|
|
82
83
|
alias dash= dash
|
83
84
|
|
84
|
-
# Stops dashing, restoring solid stroked lines and curves
|
85
|
+
# Stops dashing, restoring solid stroked lines and curves.
|
85
86
|
#
|
87
|
+
# @return [void]
|
86
88
|
def undash
|
87
89
|
self.current_dash_state = undashed_setting
|
88
90
|
write_stroke_dash
|
89
91
|
end
|
90
92
|
|
91
|
-
# Returns when stroke is dashed, false otherwise
|
93
|
+
# Returns `true` when stroke is dashed, `false` otherwise.
|
92
94
|
#
|
95
|
+
# @return [Boolean]
|
93
96
|
def dashed?
|
94
97
|
current_dash_state != undashed_setting
|
95
98
|
end
|
@@ -97,7 +100,7 @@ module Prawn
|
|
97
100
|
private
|
98
101
|
|
99
102
|
def write_stroke_dash
|
100
|
-
renderer.add_content
|
103
|
+
renderer.add_content(dash_setting)
|
101
104
|
end
|
102
105
|
|
103
106
|
def undashed_setting
|
@@ -1,24 +1,30 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# join_style.rb : Implements stroke join styling
|
4
|
-
#
|
5
|
-
# Contributed by Daniel Nelson. October, 2009
|
6
|
-
#
|
7
|
-
# This is free software. Please see the LICENSE and COPYING files for details.
|
8
|
-
#
|
9
3
|
module Prawn
|
10
4
|
module Graphics
|
5
|
+
# Implements stroke join styling.
|
11
6
|
module JoinStyle
|
7
|
+
# @private
|
12
8
|
JOIN_STYLES = { miter: 0, round: 1, bevel: 2 }.freeze
|
13
9
|
|
14
10
|
# @group Stable API
|
15
11
|
|
16
|
-
#
|
12
|
+
# Get or set the join style for stroked lines and curves.
|
17
13
|
#
|
18
|
-
#
|
14
|
+
# @overload join_style
|
15
|
+
# Get current join style.
|
16
|
+
#
|
17
|
+
# @return [:miter, :round, :bevel]
|
18
|
+
#
|
19
|
+
# @overload join_style(style)
|
20
|
+
# Set join style.
|
21
|
+
#
|
22
|
+
# @note If this method is never called, `:miter` will be used for join
|
23
|
+
# style throughout the document.
|
24
|
+
#
|
25
|
+
# @param style [:miter, :round, :bevel]
|
26
|
+
# @return [void]
|
19
27
|
#
|
20
|
-
# NOTE: if this method is never called, :miter will be used for join style
|
21
|
-
# throughout the document
|
22
28
|
#
|
23
29
|
def join_style(style = nil)
|
24
30
|
return current_join_style || :miter if style.nil?
|
@@ -47,7 +53,7 @@ module Prawn
|
|
47
53
|
end
|
48
54
|
|
49
55
|
def write_stroke_join_style
|
50
|
-
renderer.add_content
|
56
|
+
renderer.add_content("#{JOIN_STYLES[current_join_style]} j")
|
51
57
|
end
|
52
58
|
end
|
53
59
|
end
|