prawn 1.1.0 → 2.4.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 +5 -5
- checksums.yaml.gz.sig +0 -0
- data/.yardopts +1 -0
- data/GPLv2 +20 -21
- data/Gemfile +3 -9
- data/Rakefile +9 -40
- data/lib/prawn/document/bounding_box.rb +54 -40
- data/lib/prawn/document/column_box.rb +8 -10
- data/lib/prawn/document/internals.rb +39 -146
- data/lib/prawn/document/span.rb +23 -17
- data/lib/prawn/document.rb +217 -182
- data/lib/prawn/encoding.rb +69 -101
- data/lib/prawn/errors.rb +47 -43
- data/lib/prawn/font.rb +124 -104
- data/lib/prawn/font_metric_cache.rb +23 -21
- data/lib/prawn/fonts/afm.rb +292 -0
- data/lib/prawn/{font → fonts}/dfont.rb +5 -12
- data/lib/prawn/fonts/otf.rb +11 -0
- data/lib/prawn/fonts/ttc.rb +36 -0
- data/lib/prawn/{font → fonts}/ttf.rb +140 -88
- data/lib/prawn/graphics/blend_mode.rb +65 -0
- data/lib/prawn/graphics/cap_style.rb +5 -5
- data/lib/prawn/graphics/color.rb +46 -44
- data/lib/prawn/graphics/dash.rb +27 -11
- data/lib/prawn/graphics/join_style.rb +11 -6
- data/lib/prawn/graphics/patterns.rb +220 -78
- data/lib/prawn/graphics/transformation.rb +20 -12
- data/lib/prawn/graphics/transparency.rb +20 -18
- data/lib/prawn/graphics.rb +153 -115
- data/lib/prawn/grid.rb +93 -50
- data/lib/prawn/image_handler.rb +4 -4
- data/lib/prawn/images/image.rb +3 -2
- data/lib/prawn/images/jpg.rb +31 -24
- data/lib/prawn/images/png.rb +101 -68
- data/lib/prawn/images.rb +64 -56
- data/lib/prawn/measurement_extensions.rb +10 -9
- data/lib/prawn/measurements.rb +20 -23
- data/lib/prawn/outline.rb +96 -75
- data/lib/prawn/repeater.rb +16 -16
- data/lib/prawn/security/arcfour.rb +2 -2
- data/lib/prawn/security.rb +100 -85
- data/lib/prawn/soft_mask.rb +37 -38
- data/lib/prawn/stamp.rb +28 -13
- data/lib/prawn/text/box.rb +24 -29
- data/lib/prawn/text/formatted/arranger.rb +108 -63
- data/lib/prawn/text/formatted/box.rb +187 -124
- data/lib/prawn/text/formatted/fragment.rb +24 -20
- data/lib/prawn/text/formatted/line_wrap.rb +133 -73
- data/lib/prawn/text/formatted/parser.rb +147 -127
- data/lib/prawn/text/formatted/wrap.rb +48 -35
- data/lib/prawn/text/formatted.rb +5 -5
- data/lib/prawn/text.rb +103 -68
- data/lib/prawn/transformation_stack.rb +44 -0
- data/lib/prawn/utilities.rb +10 -22
- data/lib/prawn/version.rb +5 -0
- data/lib/prawn/view.rb +101 -0
- data/lib/prawn.rb +39 -54
- data/manual/basic_concepts/adding_pages.rb +6 -7
- data/manual/basic_concepts/basic_concepts.rb +34 -25
- data/manual/basic_concepts/creation.rb +10 -11
- data/manual/basic_concepts/cursor.rb +4 -5
- data/manual/basic_concepts/measurement.rb +8 -9
- data/manual/basic_concepts/origin.rb +5 -6
- data/manual/basic_concepts/other_cursor_helpers.rb +11 -12
- data/manual/basic_concepts/view.rb +48 -0
- data/manual/bounding_box/bounding_box.rb +30 -28
- data/manual/bounding_box/bounds.rb +12 -13
- data/manual/bounding_box/canvas.rb +7 -8
- data/manual/bounding_box/creation.rb +6 -7
- data/manual/bounding_box/indentation.rb +14 -15
- data/manual/bounding_box/nesting.rb +25 -18
- data/manual/bounding_box/russian_boxes.rb +18 -18
- data/manual/bounding_box/stretchy.rb +12 -14
- data/manual/contents.rb +28 -22
- data/manual/cover.rb +33 -32
- data/manual/document_and_page_options/background.rb +15 -13
- data/manual/document_and_page_options/document_and_page_options.rb +24 -22
- data/manual/document_and_page_options/metadata.rb +20 -18
- data/manual/document_and_page_options/page_margins.rb +18 -20
- data/manual/document_and_page_options/page_size.rb +13 -13
- data/manual/document_and_page_options/print_scaling.rb +18 -15
- data/manual/example_helper.rb +5 -4
- data/manual/graphics/blend_mode.rb +52 -0
- data/manual/graphics/circle_and_ellipse.rb +4 -5
- data/manual/graphics/color.rb +7 -9
- data/manual/graphics/common_lines.rb +7 -8
- data/manual/graphics/fill_and_stroke.rb +5 -6
- data/manual/graphics/fill_rules.rb +12 -11
- data/manual/graphics/gradients.rb +27 -21
- data/manual/graphics/graphics.rb +46 -40
- data/manual/graphics/helper.rb +19 -9
- data/manual/graphics/line_width.rb +8 -7
- data/manual/graphics/lines_and_curves.rb +8 -9
- data/manual/graphics/polygon.rb +6 -8
- data/manual/graphics/rectangle.rb +4 -5
- data/manual/graphics/rotate.rb +6 -9
- data/manual/graphics/scale.rb +14 -13
- data/manual/graphics/soft_masks.rb +4 -6
- data/manual/graphics/stroke_cap.rb +7 -8
- data/manual/graphics/stroke_dash.rb +15 -16
- data/manual/graphics/stroke_join.rb +6 -7
- data/manual/graphics/translate.rb +10 -10
- data/manual/graphics/transparency.rb +7 -9
- data/manual/how_to_read_this_manual.rb +8 -9
- data/manual/images/absolute_position.rb +6 -7
- data/manual/images/fit.rb +7 -8
- data/manual/images/horizontal.rb +10 -11
- data/manual/images/images.rb +28 -27
- data/manual/images/plain_image.rb +5 -6
- data/manual/images/scale.rb +9 -10
- data/manual/images/vertical.rb +16 -14
- data/manual/images/width_and_height.rb +10 -11
- data/manual/layout/boxes.rb +10 -11
- data/manual/layout/content.rb +9 -10
- data/manual/layout/layout.rb +17 -18
- data/manual/layout/simple_grid.rb +6 -7
- data/manual/outline/add_subsection_to.rb +20 -21
- data/manual/outline/insert_section_after.rb +15 -16
- data/manual/outline/outline.rb +22 -21
- data/manual/outline/sections_and_pages.rb +17 -18
- data/manual/repeatable_content/alternate_page_numbering.rb +36 -0
- data/manual/repeatable_content/page_numbering.rb +17 -16
- data/manual/repeatable_content/repeatable_content.rb +27 -23
- data/manual/repeatable_content/repeater.rb +15 -16
- data/manual/repeatable_content/stamp.rb +14 -15
- data/manual/security/encryption.rb +8 -11
- data/manual/security/permissions.rb +20 -15
- data/manual/security/security.rb +18 -18
- data/manual/table.rb +16 -0
- data/manual/text/alignment.rb +16 -17
- data/manual/text/color.rb +12 -12
- data/manual/text/column_box.rb +9 -11
- data/manual/text/fallback_fonts.rb +25 -21
- data/manual/text/font.rb +11 -12
- data/manual/text/font_size.rb +13 -14
- data/manual/text/font_style.rb +10 -8
- data/manual/text/formatted_callbacks.rb +33 -23
- data/manual/text/formatted_text.rb +36 -25
- data/manual/text/free_flowing_text.rb +22 -23
- data/manual/text/inline.rb +18 -19
- data/manual/text/kerning_and_character_spacing.rb +14 -15
- data/manual/text/leading.rb +7 -8
- data/manual/text/line_wrapping.rb +37 -18
- data/manual/text/paragraph_indentation.rb +15 -10
- data/manual/text/positioned_text.rb +16 -17
- data/manual/text/registering_families.rb +27 -24
- data/manual/text/rendering_and_color.rb +9 -10
- data/manual/text/right_to_left_text.rb +30 -19
- data/manual/text/rotation.rb +33 -24
- data/manual/text/single_usage.rb +8 -9
- data/manual/text/text.rb +56 -54
- data/manual/text/text_box_excess.rb +20 -17
- data/manual/text/text_box_extensions.rb +18 -15
- data/manual/text/text_box_overflow.rb +24 -17
- data/manual/text/utf8.rb +12 -13
- data/manual/text/win_ansi_charset.rb +28 -25
- data/prawn.gemspec +45 -50
- data/spec/extensions/encoding_helpers.rb +3 -3
- data/spec/prawn/document/bounding_box_spec.rb +550 -0
- data/spec/prawn/document/column_box_spec.rb +75 -0
- data/spec/prawn/document/security_spec.rb +176 -0
- data/spec/prawn/document_annotations_spec.rb +76 -0
- data/spec/prawn/document_destinations_spec.rb +15 -0
- data/spec/prawn/document_grid_spec.rb +99 -0
- data/spec/prawn/document_reference_spec.rb +27 -0
- data/spec/prawn/document_span_spec.rb +44 -0
- data/spec/prawn/document_spec.rb +805 -0
- data/spec/prawn/font_metric_cache_spec.rb +54 -0
- data/spec/prawn/font_spec.rb +544 -0
- data/spec/prawn/graphics/blend_mode_spec.rb +63 -0
- data/spec/prawn/graphics/transparency_spec.rb +81 -0
- data/spec/prawn/graphics_spec.rb +872 -0
- data/spec/prawn/graphics_stroke_styles_spec.rb +229 -0
- data/spec/prawn/image_handler_spec.rb +53 -0
- data/spec/prawn/images/jpg_spec.rb +20 -0
- data/spec/prawn/images/png_spec.rb +283 -0
- data/spec/prawn/images_spec.rb +229 -0
- data/spec/prawn/measurements_extensions_spec.rb +24 -0
- data/spec/prawn/outline_spec.rb +512 -0
- data/spec/prawn/repeater_spec.rb +166 -0
- data/spec/prawn/soft_mask_spec.rb +74 -0
- data/spec/prawn/stamp_spec.rb +173 -0
- data/spec/prawn/text/box_spec.rb +1110 -0
- data/spec/prawn/text/formatted/arranger_spec.rb +466 -0
- data/spec/prawn/text/formatted/box_spec.rb +849 -0
- data/spec/prawn/text/formatted/fragment_spec.rb +343 -0
- data/spec/prawn/text/formatted/line_wrap_spec.rb +495 -0
- data/spec/prawn/text/formatted/parser_spec.rb +697 -0
- data/spec/prawn/text_draw_text_spec.rb +150 -0
- data/spec/prawn/text_rendering_mode_spec.rb +48 -0
- data/spec/prawn/text_spacing_spec.rb +95 -0
- data/spec/prawn/text_spec.rb +603 -0
- data/spec/prawn/text_with_inline_formatting_spec.rb +35 -0
- data/spec/prawn/transformation_stack_spec.rb +66 -0
- data/spec/prawn/view_spec.rb +63 -0
- data/spec/prawn_manual_spec.rb +35 -0
- data/spec/spec_helper.rb +19 -25
- data.tar.gz.sig +0 -0
- metadata +113 -276
- metadata.gz.sig +0 -0
- data/data/encodings/win_ansi.txt +0 -29
- data/data/images/16bit.alpha +0 -0
- data/data/images/16bit.color +0 -0
- data/data/images/16bit.png +0 -0
- data/data/images/arrow.png +0 -0
- data/data/images/arrow2.png +0 -0
- data/data/images/dice.alpha +0 -0
- data/data/images/dice.color +0 -0
- data/data/images/dice.png +0 -0
- data/data/images/dice_interlaced.png +0 -0
- data/data/images/fractal.jpg +0 -0
- data/data/images/indexed_color.dat +0 -0
- data/data/images/indexed_color.png +0 -0
- data/data/images/letterhead.jpg +0 -0
- data/data/images/license.md +0 -8
- data/data/images/page_white_text.alpha +0 -0
- data/data/images/page_white_text.color +0 -0
- data/data/images/page_white_text.png +0 -0
- data/data/images/pigs.jpg +0 -0
- data/data/images/prawn.png +0 -0
- data/data/images/ruport.png +0 -0
- data/data/images/ruport_data.dat +0 -0
- data/data/images/ruport_transparent.png +0 -0
- data/data/images/ruport_type0.png +0 -0
- data/data/images/stef.jpg +0 -0
- data/data/images/tru256.bmp +0 -0
- data/data/images/web-links.dat +0 -1
- data/data/images/web-links.png +0 -0
- data/data/pdfs/complex_template.pdf +0 -0
- data/data/pdfs/contains_ttf_font.pdf +0 -0
- data/data/pdfs/encrypted.pdf +0 -0
- data/data/pdfs/form.pdf +1 -819
- data/data/pdfs/hexagon.pdf +0 -61
- data/data/pdfs/indirect_reference.pdf +0 -86
- data/data/pdfs/multipage_template.pdf +0 -127
- data/data/pdfs/nested_pages.pdf +0 -118
- data/data/pdfs/page_without_mediabox.pdf +0 -193
- data/data/pdfs/resources_as_indirect_object.pdf +0 -83
- data/data/pdfs/two_hexagons.pdf +0 -90
- data/data/pdfs/version_1_6.pdf +0 -61
- data/data/shift_jis_text.txt +0 -1
- data/lib/prawn/document/graphics_state.rb +0 -73
- data/lib/prawn/font/afm.rb +0 -247
- data/lib/prawn/table/cell/image.rb +0 -69
- data/lib/prawn/table/cell/in_table.rb +0 -33
- data/lib/prawn/table/cell/span_dummy.rb +0 -93
- data/lib/prawn/table/cell/subtable.rb +0 -66
- data/lib/prawn/table/cell/text.rb +0 -154
- data/lib/prawn/table/cell.rb +0 -772
- data/lib/prawn/table/cells.rb +0 -255
- data/lib/prawn/table/column_width_calculator.rb +0 -182
- data/lib/prawn/table.rb +0 -644
- data/manual/table/basic_block.rb +0 -53
- data/manual/table/before_rendering_page.rb +0 -26
- data/manual/table/cell_border_lines.rb +0 -24
- data/manual/table/cell_borders_and_bg.rb +0 -31
- data/manual/table/cell_dimensions.rb +0 -30
- data/manual/table/cell_text.rb +0 -38
- data/manual/table/column_widths.rb +0 -30
- data/manual/table/content_and_subtables.rb +0 -39
- data/manual/table/creation.rb +0 -27
- data/manual/table/filtering.rb +0 -36
- data/manual/table/flow_and_header.rb +0 -17
- data/manual/table/image_cells.rb +0 -33
- data/manual/table/position.rb +0 -29
- data/manual/table/row_colors.rb +0 -20
- data/manual/table/span.rb +0 -30
- data/manual/table/style.rb +0 -22
- data/manual/table/table.rb +0 -52
- data/manual/table/width.rb +0 -27
- data/spec/acceptance/png.rb +0 -25
- data/spec/annotations_spec.rb +0 -74
- data/spec/bounding_box_spec.rb +0 -510
- data/spec/cell_spec.rb +0 -629
- data/spec/column_box_spec.rb +0 -65
- data/spec/destinations_spec.rb +0 -15
- data/spec/document_spec.rb +0 -730
- data/spec/extensions/mocha.rb +0 -46
- data/spec/font_metric_cache_spec.rb +0 -52
- data/spec/font_spec.rb +0 -449
- data/spec/formatted_text_arranger_spec.rb +0 -421
- data/spec/formatted_text_box_spec.rb +0 -639
- data/spec/formatted_text_fragment_spec.rb +0 -298
- data/spec/graphics_spec.rb +0 -669
- data/spec/grid_spec.rb +0 -96
- data/spec/image_handler_spec.rb +0 -54
- data/spec/images_spec.rb +0 -153
- data/spec/inline_formatted_text_parser_spec.rb +0 -564
- data/spec/jpg_spec.rb +0 -25
- data/spec/line_wrap_spec.rb +0 -344
- data/spec/measurement_units_spec.rb +0 -25
- data/spec/outline_spec.rb +0 -430
- data/spec/png_spec.rb +0 -237
- data/spec/reference_spec.rb +0 -25
- data/spec/repeater_spec.rb +0 -160
- data/spec/security_spec.rb +0 -158
- data/spec/soft_mask_spec.rb +0 -79
- data/spec/span_spec.rb +0 -44
- data/spec/stamp_spec.rb +0 -160
- data/spec/stroke_styles_spec.rb +0 -211
- data/spec/table/span_dummy_spec.rb +0 -17
- data/spec/table_spec.rb +0 -1527
- data/spec/text_at_spec.rb +0 -115
- data/spec/text_box_spec.rb +0 -1034
- data/spec/text_rendering_mode_spec.rb +0 -45
- data/spec/text_spacing_spec.rb +0 -93
- data/spec/text_spec.rb +0 -437
- data/spec/text_with_inline_formatting_spec.rb +0 -35
- data/spec/transparency_spec.rb +0 -91
data/lib/prawn/graphics.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
# graphics.rb : Implements PDF drawing primitives
|
4
4
|
#
|
@@ -6,17 +6,16 @@
|
|
6
6
|
#
|
7
7
|
# This is free software. Please see the LICENSE and COPYING files for details.
|
8
8
|
|
9
|
-
|
10
|
-
require_relative
|
11
|
-
require_relative
|
12
|
-
require_relative
|
13
|
-
require_relative
|
14
|
-
require_relative
|
15
|
-
require_relative
|
16
|
-
require_relative
|
9
|
+
require_relative 'graphics/blend_mode'
|
10
|
+
require_relative 'graphics/color'
|
11
|
+
require_relative 'graphics/dash'
|
12
|
+
require_relative 'graphics/cap_style'
|
13
|
+
require_relative 'graphics/join_style'
|
14
|
+
require_relative 'graphics/transparency'
|
15
|
+
require_relative 'graphics/transformation'
|
16
|
+
require_relative 'graphics/patterns'
|
17
17
|
|
18
18
|
module Prawn
|
19
|
-
|
20
19
|
# Implements the drawing facilities for Prawn::Document.
|
21
20
|
# Use this to draw the most beautiful imaginable things.
|
22
21
|
#
|
@@ -24,7 +23,7 @@ module Prawn
|
|
24
23
|
# ruby-pdf.rubyforge.org
|
25
24
|
#
|
26
25
|
module Graphics
|
27
|
-
|
26
|
+
include BlendMode
|
28
27
|
include Color
|
29
28
|
include Dash
|
30
29
|
include CapStyle
|
@@ -46,8 +45,8 @@ module Prawn
|
|
46
45
|
# pdf.move_to(100,50)
|
47
46
|
#
|
48
47
|
def move_to(*point)
|
49
|
-
|
50
|
-
add_content("
|
48
|
+
xy = PDF::Core.real_params(map_to_absolute(point))
|
49
|
+
renderer.add_content("#{xy} m")
|
51
50
|
end
|
52
51
|
|
53
52
|
# Draws a line from the current drawing position to the specified point.
|
@@ -57,8 +56,8 @@ module Prawn
|
|
57
56
|
# pdf.line_to(50,50)
|
58
57
|
#
|
59
58
|
def line_to(*point)
|
60
|
-
|
61
|
-
add_content("
|
59
|
+
xy = PDF::Core.real_params(map_to_absolute(point))
|
60
|
+
renderer.add_content("#{xy} l")
|
62
61
|
end
|
63
62
|
|
64
63
|
# Draws a Bezier curve from the current drawing position to the
|
@@ -66,14 +65,18 @@ module Prawn
|
|
66
65
|
#
|
67
66
|
# pdf.curve_to [100,100], :bounds => [[90,90],[75,75]]
|
68
67
|
#
|
69
|
-
def curve_to(dest,options={})
|
70
|
-
|
71
|
-
|
72
|
-
|
68
|
+
def curve_to(dest, options = {})
|
69
|
+
options[:bounds] || raise(
|
70
|
+
Prawn::Errors::InvalidGraphicsPath,
|
71
|
+
'Bounding points for bezier curve must be specified ' \
|
72
|
+
'as :bounds => [[x1,y1],[x2,y2]]'
|
73
|
+
)
|
73
74
|
|
74
|
-
|
75
|
-
|
76
|
-
|
75
|
+
curve_points = PDF::Core.real_params(
|
76
|
+
(options[:bounds] << dest).flat_map { |e| map_to_absolute(e) }
|
77
|
+
)
|
78
|
+
|
79
|
+
renderer.add_content("#{curve_points} c")
|
77
80
|
end
|
78
81
|
|
79
82
|
# Draws a rectangle given <tt>point</tt>, <tt>width</tt> and
|
@@ -81,9 +84,11 @@ module Prawn
|
|
81
84
|
#
|
82
85
|
# pdf.rectangle [300,300], 100, 200
|
83
86
|
#
|
84
|
-
def rectangle(point,width,height)
|
85
|
-
x,y = map_to_absolute(point)
|
86
|
-
|
87
|
+
def rectangle(point, width, height)
|
88
|
+
x, y = map_to_absolute(point)
|
89
|
+
box = PDF::Core.real_params([x, y - height, width, height])
|
90
|
+
|
91
|
+
renderer.add_content("#{box} re")
|
87
92
|
end
|
88
93
|
|
89
94
|
# Draws a rounded rectangle given <tt>point</tt>, <tt>width</tt> and
|
@@ -92,12 +97,13 @@ module Prawn
|
|
92
97
|
#
|
93
98
|
# pdf.rounded_rectangle [300,300], 100, 200, 10
|
94
99
|
#
|
95
|
-
def rounded_rectangle(point,width,height,radius)
|
100
|
+
def rounded_rectangle(point, width, height, radius)
|
96
101
|
x, y = point
|
97
|
-
rounded_polygon(
|
102
|
+
rounded_polygon(
|
103
|
+
radius, point, [x + width, y], [x + width, y - height], [x, y - height]
|
104
|
+
)
|
98
105
|
end
|
99
106
|
|
100
|
-
|
101
107
|
###########################################################
|
102
108
|
# Higher level functions: May use relative coords #
|
103
109
|
###########################################################
|
@@ -117,7 +123,7 @@ module Prawn
|
|
117
123
|
# pdf.line_width(5)
|
118
124
|
# pdf.line_width #=> 5
|
119
125
|
#
|
120
|
-
def line_width(width=nil)
|
126
|
+
def line_width(width = nil)
|
121
127
|
if width
|
122
128
|
self.line_width = width
|
123
129
|
else
|
@@ -132,7 +138,7 @@ module Prawn
|
|
132
138
|
# pdf.line(100,100,200,250)
|
133
139
|
#
|
134
140
|
def line(*points)
|
135
|
-
x0,y0,x1,y1 = points.flatten
|
141
|
+
x0, y0, x1, y1 = points.flatten
|
136
142
|
move_to(x0, y0)
|
137
143
|
line_to(x1, y1)
|
138
144
|
end
|
@@ -143,14 +149,10 @@ module Prawn
|
|
143
149
|
# # draw a line from [25, 75] to [100, 75]
|
144
150
|
# horizontal_line 25, 100, :at => 75
|
145
151
|
#
|
146
|
-
def horizontal_line(x1,x2,options={})
|
147
|
-
|
148
|
-
y1 = options[:at]
|
149
|
-
else
|
150
|
-
y1 = y - bounds.absolute_bottom
|
151
|
-
end
|
152
|
+
def horizontal_line(x1, x2, options = {})
|
153
|
+
y1 = options[:at] || y - bounds.absolute_bottom
|
152
154
|
|
153
|
-
line(x1,y1,x2,y1)
|
155
|
+
line(x1, y1, x2, y1)
|
154
156
|
end
|
155
157
|
|
156
158
|
# Draws a horizontal line from the left border to the right border of the
|
@@ -165,8 +167,8 @@ module Prawn
|
|
165
167
|
# # draw a line from [25, 100] to [25, 300]
|
166
168
|
# vertical_line 100, 300, :at => 25
|
167
169
|
#
|
168
|
-
def vertical_line(y1,y2,params)
|
169
|
-
line(params[:at],y1,params[:at],y2)
|
170
|
+
def vertical_line(y1, y2, params)
|
171
|
+
line(params[:at], y1, params[:at], y2)
|
170
172
|
end
|
171
173
|
|
172
174
|
# Draws a Bezier curve between two points, bounded by two additional
|
@@ -174,9 +176,9 @@ module Prawn
|
|
174
176
|
#
|
175
177
|
# pdf.curve [50,100], [100,100], :bounds => [[90,90],[75,75]]
|
176
178
|
#
|
177
|
-
def curve(origin,dest, options={})
|
179
|
+
def curve(origin, dest, options = {})
|
178
180
|
move_to(*origin)
|
179
|
-
curve_to(dest,options)
|
181
|
+
curve_to(dest, options)
|
180
182
|
end
|
181
183
|
|
182
184
|
# This constant is used to approximate a symmetrical arc using a cubic
|
@@ -184,9 +186,9 @@ module Prawn
|
|
184
186
|
#
|
185
187
|
KAPPA = 4.0 * ((Math.sqrt(2) - 1.0) / 3.0)
|
186
188
|
|
187
|
-
# Draws a circle of radius <tt>radius</tt> with the centre-point at
|
188
|
-
# as a complete subpath. The drawing point will be moved to
|
189
|
-
# centre-point upon completion of the drawing the circle.
|
189
|
+
# Draws a circle of radius <tt>radius</tt> with the centre-point at
|
190
|
+
# <tt>point</tt> as a complete subpath. The drawing point will be moved to
|
191
|
+
# the centre-point upon completion of the drawing the circle.
|
190
192
|
#
|
191
193
|
# pdf.circle [100,100], 25
|
192
194
|
#
|
@@ -194,36 +196,36 @@ module Prawn
|
|
194
196
|
ellipse(center, radius, radius)
|
195
197
|
end
|
196
198
|
|
197
|
-
# Draws an ellipse of +x+ radius <tt>
|
198
|
-
# with the centre-point at <tt>point</tt> as a complete
|
199
|
-
# drawing point will be moved to the centre-point upon
|
200
|
-
# drawing the ellipse.
|
199
|
+
# Draws an ellipse of +x+ radius <tt>radius1</tt> and +y+ radius
|
200
|
+
# <tt>radius2</tt> with the centre-point at <tt>point</tt> as a complete
|
201
|
+
# subpath. The drawing point will be moved to the centre-point upon
|
202
|
+
# completion of the drawing the ellipse.
|
201
203
|
#
|
202
204
|
# # draws an ellipse with x-radius 25 and y-radius 50
|
203
205
|
# pdf.ellipse [100,100], 25, 50
|
204
206
|
#
|
205
|
-
def ellipse(point,
|
207
|
+
def ellipse(point, radius1, radius2 = radius1)
|
206
208
|
x, y = point
|
207
|
-
l1 =
|
208
|
-
l2 =
|
209
|
+
l1 = radius1 * KAPPA
|
210
|
+
l2 = radius2 * KAPPA
|
209
211
|
|
210
|
-
move_to(x +
|
212
|
+
move_to(x + radius1, y)
|
211
213
|
|
212
214
|
# Upper right hand corner
|
213
|
-
curve_to [x,
|
214
|
-
:
|
215
|
+
curve_to [x, y + radius2],
|
216
|
+
bounds: [[x + radius1, y + l2], [x + l1, y + radius2]]
|
215
217
|
|
216
218
|
# Upper left hand corner
|
217
|
-
curve_to [x -
|
218
|
-
:
|
219
|
+
curve_to [x - radius1, y],
|
220
|
+
bounds: [[x - l1, y + radius2], [x - radius1, y + l2]]
|
219
221
|
|
220
222
|
# Lower left hand corner
|
221
|
-
curve_to [x, y -
|
222
|
-
:
|
223
|
+
curve_to [x, y - radius2],
|
224
|
+
bounds: [[x - radius1, y - l2], [x - l1, y - radius2]]
|
223
225
|
|
224
226
|
# Lower right hand corner
|
225
|
-
curve_to [x +
|
226
|
-
:
|
227
|
+
curve_to [x + radius1, y],
|
228
|
+
bounds: [[x + l1, y - radius2], [x + radius1, y - l2]]
|
227
229
|
|
228
230
|
move_to(x, y)
|
229
231
|
end
|
@@ -239,36 +241,47 @@ module Prawn
|
|
239
241
|
line_to(*point)
|
240
242
|
end
|
241
243
|
# close the path
|
242
|
-
add_content
|
244
|
+
renderer.add_content 'h'
|
243
245
|
end
|
244
246
|
|
245
|
-
# Draws a rounded polygon from specified points using the radius to define
|
247
|
+
# Draws a rounded polygon from specified points using the radius to define
|
248
|
+
# bezier curves
|
246
249
|
#
|
247
|
-
#
|
248
|
-
# pdf.fill_and_stroke_rounded_polygon(
|
249
|
-
#
|
250
|
+
# # draws a rounded filled in polygon
|
251
|
+
# pdf.fill_and_stroke_rounded_polygon(
|
252
|
+
# 10, [100, 250], [200, 300], [300, 250], [300, 150], [200, 100],
|
253
|
+
# [100, 150]
|
254
|
+
# )
|
250
255
|
def rounded_polygon(radius, *points)
|
251
256
|
move_to point_on_line(radius, points[1], points[0])
|
252
257
|
sides = points.size
|
253
258
|
points << points[0] << points[1]
|
254
|
-
|
259
|
+
sides.times do |i|
|
255
260
|
rounded_vertex(radius, points[i], points[i + 1], points[i + 2])
|
256
261
|
end
|
257
262
|
# close the path
|
258
|
-
add_content
|
263
|
+
renderer.add_content 'h'
|
259
264
|
end
|
260
265
|
|
261
|
-
|
262
|
-
#
|
263
|
-
#
|
264
|
-
# the
|
266
|
+
# Creates a rounded vertex for a line segment used for building a rounded
|
267
|
+
# polygon requires a radius to define bezier curve and three points. The
|
268
|
+
# first two points define the line segment and the third point helps define
|
269
|
+
# the curve for the vertex.
|
265
270
|
def rounded_vertex(radius, *points)
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
271
|
+
radial_point1 = point_on_line(radius, points[0], points[1])
|
272
|
+
bezier_point1 = point_on_line(
|
273
|
+
(radius - radius * KAPPA),
|
274
|
+
points[0],
|
275
|
+
points[1]
|
276
|
+
)
|
277
|
+
radial_point2 = point_on_line(radius, points[2], points[1])
|
278
|
+
bezier_point2 = point_on_line(
|
279
|
+
(radius - radius * KAPPA),
|
280
|
+
points[2],
|
281
|
+
points[1]
|
282
|
+
)
|
283
|
+
line_to(radial_point1)
|
284
|
+
curve_to(radial_point2, bounds: [bezier_point1, bezier_point2])
|
272
285
|
end
|
273
286
|
|
274
287
|
# Strokes the current path. If a block is provided, yields to the block
|
@@ -276,7 +289,7 @@ module Prawn
|
|
276
289
|
#
|
277
290
|
def stroke
|
278
291
|
yield if block_given?
|
279
|
-
add_content
|
292
|
+
renderer.add_content 'S'
|
280
293
|
end
|
281
294
|
|
282
295
|
# Closes and strokes the current path. If a block is provided, yields to
|
@@ -284,7 +297,7 @@ module Prawn
|
|
284
297
|
#
|
285
298
|
def close_and_stroke
|
286
299
|
yield if block_given?
|
287
|
-
add_content
|
300
|
+
renderer.add_content 's'
|
288
301
|
end
|
289
302
|
|
290
303
|
# Draws and strokes a rectangle represented by the current bounding box
|
@@ -319,38 +332,56 @@ module Prawn
|
|
319
332
|
#
|
320
333
|
def stroke_axis(options = {})
|
321
334
|
options = {
|
322
|
-
:
|
323
|
-
:
|
324
|
-
:
|
325
|
-
:
|
326
|
-
:
|
327
|
-
:
|
335
|
+
at: [0, 0],
|
336
|
+
height: bounds.height.to_i - (options[:at] || [0, 0])[1],
|
337
|
+
width: bounds.width.to_i - (options[:at] || [0, 0])[0],
|
338
|
+
step_length: 100,
|
339
|
+
negative_axes_length: 20,
|
340
|
+
color: '000000'
|
328
341
|
}.merge(options)
|
329
342
|
|
330
|
-
Prawn.verify_options(
|
331
|
-
|
343
|
+
Prawn.verify_options(
|
344
|
+
%i[at width height step_length negative_axes_length color],
|
345
|
+
options
|
346
|
+
)
|
332
347
|
|
333
348
|
save_graphics_state do
|
334
349
|
fill_color(options[:color])
|
335
350
|
stroke_color(options[:color])
|
336
351
|
|
337
|
-
dash(1, :
|
338
|
-
stroke_horizontal_line(
|
339
|
-
|
340
|
-
|
341
|
-
|
352
|
+
dash(1, space: 4)
|
353
|
+
stroke_horizontal_line(
|
354
|
+
options[:at][0] - options[:negative_axes_length],
|
355
|
+
options[:at][0] + options[:width],
|
356
|
+
at: options[:at][1]
|
357
|
+
)
|
358
|
+
stroke_vertical_line(
|
359
|
+
options[:at][1] - options[:negative_axes_length],
|
360
|
+
options[:at][1] + options[:height],
|
361
|
+
at: options[:at][0]
|
362
|
+
)
|
342
363
|
undash
|
343
364
|
|
344
365
|
fill_circle(options[:at], 1)
|
345
366
|
|
346
|
-
(options[:step_length]..options[:width])
|
367
|
+
(options[:step_length]..options[:width])
|
368
|
+
.step(options[:step_length]) do |point|
|
347
369
|
fill_circle([options[:at][0] + point, options[:at][1]], 1)
|
348
|
-
draw_text(
|
370
|
+
draw_text(
|
371
|
+
point,
|
372
|
+
at: [options[:at][0] + point - 5, options[:at][1] - 10],
|
373
|
+
size: 7
|
374
|
+
)
|
349
375
|
end
|
350
376
|
|
351
|
-
(options[:step_length]..options[:height])
|
377
|
+
(options[:step_length]..options[:height])
|
378
|
+
.step(options[:step_length]) do |point|
|
352
379
|
fill_circle([options[:at][0], options[:at][1] + point], 1)
|
353
|
-
draw_text(
|
380
|
+
draw_text(
|
381
|
+
point,
|
382
|
+
at: [options[:at][0] - 17, options[:at][1] + point - 2],
|
383
|
+
size: 7
|
384
|
+
)
|
354
385
|
end
|
355
386
|
end
|
356
387
|
end
|
@@ -362,9 +393,9 @@ module Prawn
|
|
362
393
|
# will be used. See the PDF reference, "Graphics -> Path Construction and
|
363
394
|
# Painting -> Clipping Path Operators" for details on the difference.
|
364
395
|
#
|
365
|
-
def fill(options={})
|
396
|
+
def fill(options = {})
|
366
397
|
yield if block_given?
|
367
|
-
add_content(options[:fill_rule] == :even_odd ?
|
398
|
+
renderer.add_content(options[:fill_rule] == :even_odd ? 'f*' : 'f')
|
368
399
|
end
|
369
400
|
|
370
401
|
# Closes, fills, and strokes the current path. If a block is provided,
|
@@ -376,15 +407,15 @@ module Prawn
|
|
376
407
|
# will be used. See the PDF reference, "Graphics -> Path Construction and
|
377
408
|
# Painting -> Clipping Path Operators" for details on the difference.
|
378
409
|
#
|
379
|
-
def fill_and_stroke(options={})
|
410
|
+
def fill_and_stroke(options = {})
|
380
411
|
yield if block_given?
|
381
|
-
add_content(options[:fill_rule] == :even_odd ?
|
412
|
+
renderer.add_content(options[:fill_rule] == :even_odd ? 'b*' : 'b')
|
382
413
|
end
|
383
414
|
|
384
415
|
# Closes the current path.
|
385
416
|
#
|
386
417
|
def close_path
|
387
|
-
add_content
|
418
|
+
renderer.add_content 'h'
|
388
419
|
end
|
389
420
|
|
390
421
|
##
|
@@ -593,12 +624,20 @@ module Prawn
|
|
593
624
|
# :call-seq:
|
594
625
|
# fill_and_stroke_rounded_polygon(radius, *points)
|
595
626
|
|
596
|
-
ops
|
597
|
-
shapes = %w
|
598
|
-
|
627
|
+
ops = %w[fill stroke fill_and_stroke]
|
628
|
+
shapes = %w[
|
629
|
+
line_to curve_to rectangle rounded_rectangle line horizontal_line
|
630
|
+
horizontal_rule vertical_line curve circle_at circle ellipse_at ellipse
|
631
|
+
polygon rounded_polygon rounded_vertex
|
632
|
+
]
|
599
633
|
|
600
|
-
ops.product(shapes).each do |operation,shape|
|
601
|
-
class_eval
|
634
|
+
ops.product(shapes).each do |operation, shape|
|
635
|
+
class_eval <<-METHOD, __FILE__, __LINE__ + 1
|
636
|
+
def #{operation}_#{shape}(*args) # def fill_polygon(*args)
|
637
|
+
#{shape}(*args) # polygon(*args)
|
638
|
+
#{operation} # fill
|
639
|
+
end # end
|
640
|
+
METHOD
|
602
641
|
end
|
603
642
|
|
604
643
|
private
|
@@ -612,11 +651,11 @@ module Prawn
|
|
612
651
|
end
|
613
652
|
|
614
653
|
def write_line_width
|
615
|
-
add_content("#{current_line_width} w")
|
654
|
+
renderer.add_content("#{current_line_width} w")
|
616
655
|
end
|
617
656
|
|
618
657
|
def map_to_absolute(*point)
|
619
|
-
x,y = point.flatten
|
658
|
+
x, y = point.flatten
|
620
659
|
[@bounding_box.absolute_left + x, @bounding_box.absolute_bottom + y]
|
621
660
|
end
|
622
661
|
|
@@ -625,19 +664,18 @@ module Prawn
|
|
625
664
|
end
|
626
665
|
|
627
666
|
def degree_to_rad(angle)
|
628
|
-
|
667
|
+
angle * Math::PI / 180
|
629
668
|
end
|
630
669
|
|
631
|
-
# Returns the coordinates for a point on a line that is a given distance
|
632
|
-
# point defining the line segement
|
670
|
+
# Returns the coordinates for a point on a line that is a given distance
|
671
|
+
# away from the second point defining the line segement
|
633
672
|
def point_on_line(distance_from_end, *points)
|
634
|
-
x0,y0,x1,y1 = points.flatten
|
673
|
+
x0, y0, x1, y1 = points.flatten
|
635
674
|
length = Math.sqrt((x1 - x0)**2 + (y1 - y0)**2)
|
636
675
|
p = (length - distance_from_end) / length
|
637
|
-
xr = x0 + p*(x1 - x0)
|
638
|
-
yr = y0 + p*(y1 - y0)
|
676
|
+
xr = x0 + p * (x1 - x0)
|
677
|
+
yr = y0 + p * (y1 - y0)
|
639
678
|
[xr, yr]
|
640
679
|
end
|
641
|
-
|
642
680
|
end
|
643
681
|
end
|