prawn 2.3.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 +223 -143
- data/lib/prawn/document/column_box.rb +61 -26
- data/lib/prawn/document/internals.rb +25 -16
- data/lib/prawn/document/span.rb +21 -18
- data/lib/prawn/document.rb +273 -182
- data/lib/prawn/encoding.rb +2 -5
- data/lib/prawn/errors.rb +23 -34
- data/lib/prawn/font.rb +254 -139
- data/lib/prawn/font_metric_cache.rb +18 -16
- data/lib/prawn/fonts/afm.rb +99 -57
- 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 +345 -107
- 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 +75 -50
- data/lib/prawn/graphics/dash.rb +45 -42
- data/lib/prawn/graphics/join_style.rb +18 -12
- data/lib/prawn/graphics/patterns.rb +239 -110
- data/lib/prawn/graphics/transformation.rb +51 -44
- data/lib/prawn/graphics/transparency.rb +16 -40
- data/lib/prawn/graphics.rb +370 -260
- data/lib/prawn/grid.rb +219 -57
- data/lib/prawn/image_handler.rb +27 -10
- data/lib/prawn/images/image.rb +8 -10
- data/lib/prawn/images/jpg.rb +46 -20
- data/lib/prawn/images/png.rb +94 -42
- data/lib/prawn/images.rb +70 -81
- data/lib/prawn/measurement_extensions.rb +39 -8
- data/lib/prawn/measurements.rb +60 -5
- data/lib/prawn/outline.rb +120 -113
- data/lib/prawn/repeater.rb +52 -36
- data/lib/prawn/security/arcfour.rb +4 -4
- data/lib/prawn/security.rb +106 -98
- data/lib/prawn/soft_mask.rb +42 -30
- data/lib/prawn/stamp.rb +38 -42
- data/lib/prawn/text/box.rb +156 -105
- data/lib/prawn/text/formatted/arranger.rb +121 -41
- data/lib/prawn/text/formatted/box.rb +239 -163
- data/lib/prawn/text/formatted/fragment.rb +130 -14
- data/lib/prawn/text/formatted/line_wrap.rb +49 -38
- data/lib/prawn/text/formatted/parser.rb +116 -74
- data/lib/prawn/text/formatted/wrap.rb +25 -26
- data/lib/prawn/text/formatted.rb +75 -0
- data/lib/prawn/text.rb +456 -211
- 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 +69 -54
- data/lib/prawn.rb +24 -18
- data.tar.gz.sig +0 -0
- metadata +55 -262
- metadata.gz.sig +3 -4
- data/.yardopts +0 -10
- data/Gemfile +0 -5
- data/Rakefile +0 -54
- 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 -25
- 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 -22
- 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 -37
- data/manual/graphics/gradients.rb +0 -43
- data/manual/graphics/graphics.rb +0 -64
- data/manual/graphics/helper.rb +0 -27
- 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 -28
- 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 -27
- 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 -41
- 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 -22
- data/manual/text/formatted_callbacks.rb +0 -65
- data/manual/text/formatted_text.rb +0 -58
- 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 -32
- 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 -47
- 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 -49
- data/manual/text/utf8.rb +0 -27
- data/manual/text/win_ansi_charset.rb +0 -62
- data/prawn.gemspec +0 -57
- data/spec/data/curves.pdf +0 -66
- data/spec/extensions/encoding_helpers.rb +0 -11
- data/spec/prawn/document/bounding_box_spec.rb +0 -546
- 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 -36
- data/spec/prawn/document_spec.rb +0 -802
- data/spec/prawn/font_metric_cache_spec.rb +0 -54
- data/spec/prawn/font_spec.rb +0 -542
- 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 -837
- 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 -224
- data/spec/prawn/measurements_extensions_spec.rb +0 -24
- data/spec/prawn/outline_spec.rb +0 -412
- data/spec/prawn/repeater_spec.rb +0 -165
- data/spec/prawn/soft_mask_spec.rb +0 -74
- data/spec/prawn/stamp_spec.rb +0 -172
- data/spec/prawn/text/box_spec.rb +0 -1112
- data/spec/prawn/text/formatted/arranger_spec.rb +0 -466
- data/spec/prawn/text/formatted/box_spec.rb +0 -846
- data/spec/prawn/text/formatted/fragment_spec.rb +0 -343
- data/spec/prawn/text/formatted/line_wrap_spec.rb +0 -494
- data/spec/prawn/text/formatted/parser_spec.rb +0 -697
- data/spec/prawn/text_draw_text_spec.rb +0 -149
- 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,41 +1,38 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# blend_mode.rb : Implements blend modes
|
4
|
-
#
|
5
|
-
# Contributed by John Ford. October, 2015
|
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
|
-
# The Prawn::BlendMode module is used to change the way
|
13
|
-
#
|
14
|
-
#
|
15
|
-
# Passing an array of blend modes is allowed. PDF viewers should
|
16
|
-
# blend layers based on the first recognized blend mode.
|
17
|
-
#
|
18
|
-
# Valid blend modes in v1.4 of the PDF spec include :Normal, :Multiply,
|
19
|
-
# :Screen, :Overlay, :Darken, :Lighten, :ColorDodge, :ColorBurn, :HardLight,
|
20
|
-
# :SoftLight, :Difference, :Exclusion, :Hue, :Saturation, :Color, and
|
21
|
-
# :Luminosity.
|
22
|
-
#
|
23
|
-
# Example:
|
24
|
-
# pdf.fill_color('0000ff')
|
25
|
-
# pdf.fill_rectangle([x, y+25], 50, 50)
|
26
|
-
# pdf.blend_mode(:Multiply) do
|
27
|
-
# pdf.fill_color('ff0000')
|
28
|
-
# pdf.fill_circle([x, y], 25)
|
29
|
-
# end
|
30
|
-
#
|
5
|
+
# The {Prawn::BlendMode} module is used to change the way two graphic
|
6
|
+
# objects are blended together.
|
31
7
|
module BlendMode
|
32
8
|
# @group Stable API
|
33
9
|
|
10
|
+
# Set blend mode. If a block is passed blend mode is restored afterwards.
|
11
|
+
#
|
12
|
+
# Passing an array of blend modes is allowed. PDF viewers should blend
|
13
|
+
# layers based on the first recognized blend mode.
|
14
|
+
#
|
15
|
+
# Valid blend modes since PDF 1.4 include `:Normal`, `:Multiply`, `:Screen`,
|
16
|
+
# `:Overlay`, `:Darken`, `:Lighten`, `:ColorDodge`, `:ColorBurn`,
|
17
|
+
# `:HardLight`, `:SoftLight`, `:Difference`, `:Exclusion`, `:Hue`,
|
18
|
+
# `:Saturation`, `:Color`, and `:Luminosity`.
|
19
|
+
#
|
20
|
+
# @example
|
21
|
+
# pdf.fill_color('0000ff')
|
22
|
+
# pdf.fill_rectangle([x, y + 25], 50, 50)
|
23
|
+
# pdf.blend_mode(:Multiply) do
|
24
|
+
# pdf.fill_color('ff0000')
|
25
|
+
# pdf.fill_circle([x, y], 25)
|
26
|
+
# end
|
27
|
+
#
|
28
|
+
# @param blend_mode [Symbol, Array<Symbol>]
|
29
|
+
# @yield
|
30
|
+
# @return [void]
|
34
31
|
def blend_mode(blend_mode = :Normal)
|
35
32
|
renderer.min_version(1.4)
|
36
33
|
|
37
34
|
save_graphics_state if block_given?
|
38
|
-
renderer.add_content
|
35
|
+
renderer.add_content("/#{blend_mode_dictionary_name(blend_mode)} gs")
|
39
36
|
if block_given?
|
40
37
|
yield
|
41
38
|
restore_graphics_state
|
@@ -54,7 +51,7 @@ module Prawn
|
|
54
51
|
|
55
52
|
dictionary = blend_mode_dictionary_registry[dictionary_name] ||= ref!(
|
56
53
|
Type: :ExtGState,
|
57
|
-
BM: blend_mode
|
54
|
+
BM: blend_mode,
|
58
55
|
)
|
59
56
|
|
60
57
|
page.ext_gstates[dictionary_name] = dictionary
|
@@ -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>]
|
17
15
|
#
|
18
|
-
#
|
19
|
-
#
|
16
|
+
# @overload fill_color(color)
|
17
|
+
# Sets the fill color.
|
20
18
|
#
|
19
|
+
# If a single argument is provided, it should be a 6 digit HTML color
|
20
|
+
# code.
|
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)
|
@@ -154,44 +177,46 @@ module Prawn
|
|
154
177
|
raise ArgumentError, "unknown color space: '#{color_space}'"
|
155
178
|
end
|
156
179
|
|
157
|
-
operator =
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
180
|
+
operator =
|
181
|
+
case type
|
182
|
+
when :fill
|
183
|
+
'cs'
|
184
|
+
when :stroke
|
185
|
+
'CS'
|
186
|
+
else
|
187
|
+
raise ArgumentError, "unknown type '#{type}'"
|
188
|
+
end
|
165
189
|
|
166
|
-
renderer.add_content
|
190
|
+
renderer.add_content("/#{color_space} #{operator}")
|
167
191
|
end
|
168
192
|
|
169
193
|
def set_color(type, color, options = {})
|
170
|
-
operator =
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
194
|
+
operator =
|
195
|
+
case type
|
196
|
+
when :fill
|
197
|
+
'scn'
|
198
|
+
when :stroke
|
199
|
+
'SCN'
|
200
|
+
else
|
201
|
+
raise ArgumentError, "unknown type '#{type}'"
|
202
|
+
end
|
178
203
|
|
179
204
|
if options[:pattern]
|
180
|
-
set_color_space
|
181
|
-
renderer.add_content
|
205
|
+
set_color_space(type, :Pattern)
|
206
|
+
renderer.add_content("/#{color} #{operator}")
|
182
207
|
else
|
183
|
-
set_color_space
|
208
|
+
set_color_space(type, color_space(color))
|
184
209
|
color = color_to_s(color)
|
185
210
|
write_color(color, operator)
|
186
211
|
end
|
187
212
|
end
|
188
213
|
|
189
214
|
def set_fill_color(color = nil)
|
190
|
-
set_color
|
215
|
+
set_color(:fill, color || current_fill_color)
|
191
216
|
end
|
192
217
|
|
193
218
|
def set_stroke_color(color = nil)
|
194
|
-
set_color
|
219
|
+
set_color(:stroke, color || current_stroke_color)
|
195
220
|
end
|
196
221
|
|
197
222
|
def update_colors
|
@@ -225,7 +250,7 @@ module Prawn
|
|
225
250
|
end
|
226
251
|
|
227
252
|
def write_color(color, operator)
|
228
|
-
renderer.add_content
|
253
|
+
renderer.add_content("#{color} #{operator}")
|
229
254
|
end
|
230
255
|
end
|
231
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?
|
@@ -28,7 +34,7 @@ module Prawn
|
|
28
34
|
unless JOIN_STYLES.key?(current_join_style)
|
29
35
|
raise Prawn::Errors::InvalidJoinStyle,
|
30
36
|
"#{style} is not a recognized join style. Valid styles are " +
|
31
|
-
|
37
|
+
JOIN_STYLES.keys.join(', ')
|
32
38
|
end
|
33
39
|
|
34
40
|
write_stroke_join_style
|
@@ -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
|