prawn 2.0.1 → 2.0.2
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
- data/Rakefile +7 -5
- data/lib/prawn.rb +4 -4
- data/lib/prawn/document.rb +47 -46
- data/lib/prawn/document/bounding_box.rb +13 -19
- data/lib/prawn/document/column_box.rb +3 -5
- data/lib/prawn/document/internals.rb +0 -1
- data/lib/prawn/document/span.rb +12 -12
- data/lib/prawn/errors.rb +32 -33
- data/lib/prawn/font.rb +29 -36
- data/lib/prawn/font/afm.rb +20 -20
- data/lib/prawn/font/dfont.rb +0 -1
- data/lib/prawn/font/ttf.rb +30 -27
- data/lib/prawn/font_metric_cache.rb +4 -8
- data/lib/prawn/graphics.rb +37 -42
- data/lib/prawn/graphics/cap_style.rb +1 -1
- data/lib/prawn/graphics/color.rb +21 -23
- data/lib/prawn/graphics/dash.rb +5 -6
- data/lib/prawn/graphics/join_style.rb +1 -2
- data/lib/prawn/graphics/patterns.rb +25 -21
- data/lib/prawn/graphics/transformation.rb +4 -5
- data/lib/prawn/graphics/transparency.rb +6 -8
- data/lib/prawn/grid.rb +21 -14
- data/lib/prawn/image_handler.rb +2 -2
- data/lib/prawn/images.rb +29 -31
- data/lib/prawn/images/image.rb +1 -1
- data/lib/prawn/images/jpg.rb +10 -12
- data/lib/prawn/images/png.rb +13 -13
- data/lib/prawn/measurements.rb +7 -14
- data/lib/prawn/outline.rb +6 -6
- data/lib/prawn/repeater.rb +1 -5
- data/lib/prawn/security.rb +17 -25
- data/lib/prawn/security/arcfour.rb +1 -1
- data/lib/prawn/soft_mask.rb +11 -12
- data/lib/prawn/stamp.rb +16 -8
- data/lib/prawn/text.rb +23 -20
- data/lib/prawn/text/box.rb +3 -6
- data/lib/prawn/text/formatted/arranger.rb +9 -12
- data/lib/prawn/text/formatted/box.rb +23 -22
- data/lib/prawn/text/formatted/fragment.rb +0 -4
- data/lib/prawn/text/formatted/line_wrap.rb +13 -24
- data/lib/prawn/text/formatted/parser.rb +16 -20
- data/lib/prawn/text/formatted/wrap.rb +2 -7
- data/lib/prawn/utilities.rb +6 -3
- data/lib/prawn/version.rb +1 -1
- data/manual/basic_concepts/basic_concepts.rb +0 -2
- data/manual/basic_concepts/view.rb +1 -1
- data/manual/bounding_box/bounding_box.rb +0 -3
- data/manual/bounding_box/russian_boxes.rb +7 -8
- data/manual/bounding_box/stretchy.rb +0 -1
- data/manual/contents.rb +2 -2
- data/manual/cover.rb +11 -12
- data/manual/document_and_page_options/document_and_page_options.rb +2 -5
- data/manual/document_and_page_options/metadata.rb +10 -10
- data/manual/document_and_page_options/page_size.rb +0 -1
- data/manual/graphics/fill_rules.rb +5 -4
- data/manual/graphics/graphics.rb +0 -3
- data/manual/graphics/lines_and_curves.rb +1 -1
- data/manual/graphics/rotate.rb +0 -2
- data/manual/graphics/scale.rb +4 -2
- data/manual/graphics/soft_masks.rb +0 -1
- data/manual/graphics/stroke_cap.rb +1 -1
- data/manual/graphics/stroke_join.rb +1 -1
- data/manual/graphics/translate.rb +3 -3
- data/manual/graphics/transparency.rb +0 -1
- data/manual/how_to_read_this_manual.rb +0 -1
- data/manual/images/images.rb +0 -3
- data/manual/layout/boxes.rb +5 -5
- data/manual/layout/content.rb +2 -2
- data/manual/layout/layout.rb +0 -3
- data/manual/outline/outline.rb +0 -3
- data/manual/repeatable_content/page_numbering.rb +1 -1
- data/manual/repeatable_content/repeatable_content.rb +0 -3
- data/manual/repeatable_content/repeater.rb +6 -6
- data/manual/security/encryption.rb +0 -2
- data/manual/security/permissions.rb +0 -2
- data/manual/security/security.rb +0 -3
- data/manual/text/alignment.rb +3 -3
- data/manual/text/color.rb +0 -1
- data/manual/text/column_box.rb +0 -1
- data/manual/text/fallback_fonts.rb +2 -2
- data/manual/text/formatted_callbacks.rb +3 -2
- data/manual/text/paragraph_indentation.rb +2 -3
- data/manual/text/registering_families.rb +13 -9
- data/manual/text/rotation.rb +0 -1
- data/manual/text/text.rb +0 -3
- data/manual/text/text_box_overflow.rb +7 -5
- data/manual/text/utf8.rb +1 -1
- data/manual/text/win_ansi_charset.rb +2 -2
- data/prawn.gemspec +4 -4
- data/spec/acceptance/png.rb +6 -7
- data/spec/annotations_spec.rb +21 -28
- data/spec/bounding_box_spec.rb +100 -109
- data/spec/column_box_spec.rb +26 -32
- data/spec/destinations_spec.rb +2 -4
- data/spec/document_spec.rb +145 -151
- data/spec/extensions/mocha.rb +0 -1
- data/spec/font_metric_cache_spec.rb +7 -7
- data/spec/font_spec.rb +103 -102
- data/spec/formatted_text_arranger_spec.rb +76 -74
- data/spec/formatted_text_box_spec.rb +170 -159
- data/spec/formatted_text_fragment_spec.rb +57 -56
- data/spec/graphics_spec.rb +158 -175
- data/spec/grid_spec.rb +28 -29
- data/spec/image_handler_spec.rb +4 -5
- data/spec/images_spec.rb +50 -36
- data/spec/inline_formatted_text_parser_spec.rb +397 -393
- data/spec/jpg_spec.rb +4 -6
- data/spec/line_wrap_spec.rb +54 -55
- data/spec/measurement_units_spec.rb +12 -15
- data/spec/outline_spec.rb +77 -98
- data/spec/png_spec.rb +55 -65
- data/spec/reference_spec.rb +3 -3
- data/spec/repeater_spec.rb +20 -26
- data/spec/security_spec.rb +42 -49
- data/spec/soft_mask_spec.rb +4 -5
- data/spec/span_spec.rb +5 -6
- data/spec/spec_helper.rb +2 -4
- data/spec/stamp_spec.rb +41 -22
- data/spec/stroke_styles_spec.rb +36 -39
- data/spec/text_at_spec.rb +28 -29
- data/spec/text_box_spec.rb +160 -165
- data/spec/text_rendering_mode_spec.rb +9 -9
- data/spec/text_spacing_spec.rb +13 -13
- data/spec/text_spec.rb +116 -124
- data/spec/text_with_inline_formatting_spec.rb +5 -5
- data/spec/transparency_spec.rb +20 -20
- data/spec/view_spec.rb +0 -1
- metadata +7 -7
@@ -8,22 +8,20 @@
|
|
8
8
|
#
|
9
9
|
|
10
10
|
module Prawn
|
11
|
-
|
12
11
|
# Cache used internally by Prawn::Document instances to calculate the width
|
13
12
|
# of various strings for layout purposes.
|
14
13
|
#
|
15
14
|
# @private
|
16
15
|
class FontMetricCache
|
16
|
+
CacheEntry = Struct.new(:font, :options, :string)
|
17
17
|
|
18
|
-
|
19
|
-
|
20
|
-
def initialize( document )
|
18
|
+
def initialize(document)
|
21
19
|
@document = document
|
22
20
|
|
23
21
|
@cache = {}
|
24
22
|
end
|
25
23
|
|
26
|
-
def width_of(
|
24
|
+
def width_of(string, options)
|
27
25
|
f = if options[:style]
|
28
26
|
# override style with :style => :bold
|
29
27
|
@document.find_font(@document.font.family, :style => options[:style])
|
@@ -31,7 +29,7 @@ module Prawn
|
|
31
29
|
@document.font
|
32
30
|
end
|
33
31
|
|
34
|
-
key = CacheEntry.new(
|
32
|
+
key = CacheEntry.new(f, options, string)
|
35
33
|
|
36
34
|
unless length = @cache[ key ]
|
37
35
|
length = @cache[ key ] = f.compute_width_of(string, options)
|
@@ -40,7 +38,5 @@ module Prawn
|
|
40
38
|
length +
|
41
39
|
(@document.character_spacing * @document.font.character_count(string))
|
42
40
|
end
|
43
|
-
|
44
41
|
end
|
45
|
-
|
46
42
|
end
|
data/lib/prawn/graphics.rb
CHANGED
@@ -6,7 +6,6 @@
|
|
6
6
|
#
|
7
7
|
# This is free software. Please see the LICENSE and COPYING files for details.
|
8
8
|
|
9
|
-
|
10
9
|
require_relative "graphics/color"
|
11
10
|
require_relative "graphics/dash"
|
12
11
|
require_relative "graphics/cap_style"
|
@@ -16,7 +15,6 @@ require_relative "graphics/transformation"
|
|
16
15
|
require_relative "graphics/patterns"
|
17
16
|
|
18
17
|
module Prawn
|
19
|
-
|
20
18
|
# Implements the drawing facilities for Prawn::Document.
|
21
19
|
# Use this to draw the most beautiful imaginable things.
|
22
20
|
#
|
@@ -24,7 +22,6 @@ module Prawn
|
|
24
22
|
# ruby-pdf.rubyforge.org
|
25
23
|
#
|
26
24
|
module Graphics
|
27
|
-
|
28
25
|
include Color
|
29
26
|
include Dash
|
30
27
|
include CapStyle
|
@@ -66,15 +63,16 @@ module Prawn
|
|
66
63
|
#
|
67
64
|
# pdf.curve_to [100,100], :bounds => [[90,90],[75,75]]
|
68
65
|
#
|
69
|
-
def curve_to(dest,options={})
|
70
|
-
|
71
|
-
|
72
|
-
|
66
|
+
def curve_to(dest, options = {})
|
67
|
+
options[:bounds] or fail Prawn::Errors::InvalidGraphicsPath,
|
68
|
+
"Bounding points for bezier curve must be specified " \
|
69
|
+
"as :bounds => [[x1,y1],[x2,y2]]"
|
73
70
|
|
74
|
-
|
75
|
-
(options[:bounds] << dest).flat_map { |e| map_to_absolute(e) }
|
71
|
+
curve_points = PDF::Core.real_params(
|
72
|
+
(options[:bounds] << dest).flat_map { |e| map_to_absolute(e) }
|
73
|
+
)
|
76
74
|
|
77
|
-
|
75
|
+
renderer.add_content("#{curve_points} c")
|
78
76
|
end
|
79
77
|
|
80
78
|
# Draws a rectangle given <tt>point</tt>, <tt>width</tt> and
|
@@ -82,8 +80,8 @@ module Prawn
|
|
82
80
|
#
|
83
81
|
# pdf.rectangle [300,300], 100, 200
|
84
82
|
#
|
85
|
-
def rectangle(point,width,height)
|
86
|
-
x,y = map_to_absolute(point)
|
83
|
+
def rectangle(point, width, height)
|
84
|
+
x, y = map_to_absolute(point)
|
87
85
|
box = PDF::Core.real_params([x, y - height, width, height])
|
88
86
|
|
89
87
|
renderer.add_content("#{box} re")
|
@@ -95,12 +93,11 @@ module Prawn
|
|
95
93
|
#
|
96
94
|
# pdf.rounded_rectangle [300,300], 100, 200, 10
|
97
95
|
#
|
98
|
-
def rounded_rectangle(point,width,height,radius)
|
96
|
+
def rounded_rectangle(point, width, height, radius)
|
99
97
|
x, y = point
|
100
98
|
rounded_polygon(radius, point, [x + width, y], [x + width, y - height], [x, y - height])
|
101
99
|
end
|
102
100
|
|
103
|
-
|
104
101
|
###########################################################
|
105
102
|
# Higher level functions: May use relative coords #
|
106
103
|
###########################################################
|
@@ -120,7 +117,7 @@ module Prawn
|
|
120
117
|
# pdf.line_width(5)
|
121
118
|
# pdf.line_width #=> 5
|
122
119
|
#
|
123
|
-
def line_width(width=nil)
|
120
|
+
def line_width(width = nil)
|
124
121
|
if width
|
125
122
|
self.line_width = width
|
126
123
|
else
|
@@ -135,7 +132,7 @@ module Prawn
|
|
135
132
|
# pdf.line(100,100,200,250)
|
136
133
|
#
|
137
134
|
def line(*points)
|
138
|
-
x0,y0,x1,y1 = points.flatten
|
135
|
+
x0, y0, x1, y1 = points.flatten
|
139
136
|
move_to(x0, y0)
|
140
137
|
line_to(x1, y1)
|
141
138
|
end
|
@@ -146,14 +143,14 @@ module Prawn
|
|
146
143
|
# # draw a line from [25, 75] to [100, 75]
|
147
144
|
# horizontal_line 25, 100, :at => 75
|
148
145
|
#
|
149
|
-
def horizontal_line(x1,x2,options={})
|
146
|
+
def horizontal_line(x1, x2, options = {})
|
150
147
|
if options[:at]
|
151
148
|
y1 = options[:at]
|
152
149
|
else
|
153
150
|
y1 = y - bounds.absolute_bottom
|
154
151
|
end
|
155
152
|
|
156
|
-
line(x1,y1,x2,y1)
|
153
|
+
line(x1, y1, x2, y1)
|
157
154
|
end
|
158
155
|
|
159
156
|
# Draws a horizontal line from the left border to the right border of the
|
@@ -168,8 +165,8 @@ module Prawn
|
|
168
165
|
# # draw a line from [25, 100] to [25, 300]
|
169
166
|
# vertical_line 100, 300, :at => 25
|
170
167
|
#
|
171
|
-
def vertical_line(y1,y2,params)
|
172
|
-
line(params[:at],y1,params[:at],y2)
|
168
|
+
def vertical_line(y1, y2, params)
|
169
|
+
line(params[:at], y1, params[:at], y2)
|
173
170
|
end
|
174
171
|
|
175
172
|
# Draws a Bezier curve between two points, bounded by two additional
|
@@ -177,9 +174,9 @@ module Prawn
|
|
177
174
|
#
|
178
175
|
# pdf.curve [50,100], [100,100], :bounds => [[90,90],[75,75]]
|
179
176
|
#
|
180
|
-
def curve(origin,dest, options={})
|
177
|
+
def curve(origin, dest, options = {})
|
181
178
|
move_to(*origin)
|
182
|
-
curve_to(dest,options)
|
179
|
+
curve_to(dest, options)
|
183
180
|
end
|
184
181
|
|
185
182
|
# This constant is used to approximate a symmetrical arc using a cubic
|
@@ -214,19 +211,19 @@ module Prawn
|
|
214
211
|
|
215
212
|
# Upper right hand corner
|
216
213
|
curve_to [x, y + r2],
|
217
|
-
|
214
|
+
:bounds => [[x + r1, y + l2], [x + l1, y + r2]]
|
218
215
|
|
219
216
|
# Upper left hand corner
|
220
217
|
curve_to [x - r1, y],
|
221
|
-
|
218
|
+
:bounds => [[x - l1, y + r2], [x - r1, y + l2]]
|
222
219
|
|
223
220
|
# Lower left hand corner
|
224
221
|
curve_to [x, y - r2],
|
225
|
-
|
222
|
+
:bounds => [[x - r1, y - l2], [x - l1, y - r2]]
|
226
223
|
|
227
224
|
# Lower right hand corner
|
228
225
|
curve_to [x + r1, y],
|
229
|
-
|
226
|
+
:bounds => [[x + l1, y - r2], [x + r1, y - l2]]
|
230
227
|
|
231
228
|
move_to(x, y)
|
232
229
|
end
|
@@ -261,15 +258,14 @@ module Prawn
|
|
261
258
|
renderer.add_content "h"
|
262
259
|
end
|
263
260
|
|
264
|
-
|
265
261
|
# Creates a rounded vertex for a line segment used for building a rounded polygon
|
266
262
|
# requires a radius to define bezier curve and three points. The first two points define
|
267
263
|
# the line segment and the third point helps define the curve for the vertex.
|
268
264
|
def rounded_vertex(radius, *points)
|
269
265
|
radial_point_1 = point_on_line(radius, points[0], points[1])
|
270
|
-
bezier_point_1 = point_on_line((radius - radius*KAPPA), points[0], points[1]
|
266
|
+
bezier_point_1 = point_on_line((radius - radius * KAPPA), points[0], points[1])
|
271
267
|
radial_point_2 = point_on_line(radius, points[2], points[1])
|
272
|
-
bezier_point_2 = point_on_line((radius - radius*KAPPA), points[2], points[1])
|
268
|
+
bezier_point_2 = point_on_line((radius - radius * KAPPA), points[2], points[1])
|
273
269
|
line_to(radial_point_1)
|
274
270
|
curve_to(radial_point_2, :bounds => [bezier_point_1, bezier_point_2])
|
275
271
|
end
|
@@ -322,12 +318,12 @@ module Prawn
|
|
322
318
|
#
|
323
319
|
def stroke_axis(options = {})
|
324
320
|
options = {
|
325
|
-
:at => [0,0],
|
326
|
-
:height => bounds.height.to_i - (options[:at] || [0,0])[1],
|
327
|
-
:width => bounds.width.to_i - (options[:at] || [0,0])[0],
|
321
|
+
:at => [0, 0],
|
322
|
+
:height => bounds.height.to_i - (options[:at] || [0, 0])[1],
|
323
|
+
:width => bounds.width.to_i - (options[:at] || [0, 0])[0],
|
328
324
|
:step_length => 100,
|
329
325
|
:negative_axes_length => 20,
|
330
|
-
:color => "000000"
|
326
|
+
:color => "000000"
|
331
327
|
}.merge(options)
|
332
328
|
|
333
329
|
Prawn.verify_options([:at, :width, :height, :step_length,
|
@@ -365,7 +361,7 @@ module Prawn
|
|
365
361
|
# will be used. See the PDF reference, "Graphics -> Path Construction and
|
366
362
|
# Painting -> Clipping Path Operators" for details on the difference.
|
367
363
|
#
|
368
|
-
def fill(options={})
|
364
|
+
def fill(options = {})
|
369
365
|
yield if block_given?
|
370
366
|
renderer.add_content(options[:fill_rule] == :even_odd ? "f*" : "f")
|
371
367
|
end
|
@@ -379,7 +375,7 @@ module Prawn
|
|
379
375
|
# will be used. See the PDF reference, "Graphics -> Path Construction and
|
380
376
|
# Painting -> Clipping Path Operators" for details on the difference.
|
381
377
|
#
|
382
|
-
def fill_and_stroke(options={})
|
378
|
+
def fill_and_stroke(options = {})
|
383
379
|
yield if block_given?
|
384
380
|
renderer.add_content(options[:fill_rule] == :even_odd ? "b*" : "b")
|
385
381
|
end
|
@@ -600,7 +596,7 @@ module Prawn
|
|
600
596
|
shapes = %w{line_to curve_to rectangle rounded_rectangle line horizontal_line horizontal_rule vertical_line
|
601
597
|
curve circle_at circle ellipse_at ellipse polygon rounded_polygon rounded_vertex}
|
602
598
|
|
603
|
-
ops.product(shapes).each do |operation,shape|
|
599
|
+
ops.product(shapes).each do |operation, shape|
|
604
600
|
class_eval "def #{operation}_#{shape}(*args); #{shape}(*args); #{operation}; end"
|
605
601
|
end
|
606
602
|
|
@@ -619,7 +615,7 @@ module Prawn
|
|
619
615
|
end
|
620
616
|
|
621
617
|
def map_to_absolute(*point)
|
622
|
-
x,y = point.flatten
|
618
|
+
x, y = point.flatten
|
623
619
|
[@bounding_box.absolute_left + x, @bounding_box.absolute_bottom + y]
|
624
620
|
end
|
625
621
|
|
@@ -628,19 +624,18 @@ module Prawn
|
|
628
624
|
end
|
629
625
|
|
630
626
|
def degree_to_rad(angle)
|
631
|
-
|
627
|
+
angle * Math::PI / 180
|
632
628
|
end
|
633
629
|
|
634
630
|
# Returns the coordinates for a point on a line that is a given distance away from the second
|
635
631
|
# point defining the line segement
|
636
632
|
def point_on_line(distance_from_end, *points)
|
637
|
-
x0,y0,x1,y1 = points.flatten
|
633
|
+
x0, y0, x1, y1 = points.flatten
|
638
634
|
length = Math.sqrt((x1 - x0)**2 + (y1 - y0)**2)
|
639
635
|
p = (length - distance_from_end) / length
|
640
|
-
xr = x0 + p*(x1 - x0)
|
641
|
-
yr = y0 + p*(y1 - y0)
|
636
|
+
xr = x0 + p * (x1 - x0)
|
637
|
+
yr = y0 + p * (y1 - y0)
|
642
638
|
[xr, yr]
|
643
639
|
end
|
644
|
-
|
645
640
|
end
|
646
641
|
end
|
data/lib/prawn/graphics/color.rb
CHANGED
@@ -74,8 +74,8 @@ module Prawn
|
|
74
74
|
# => [255, 120, 8]
|
75
75
|
#
|
76
76
|
def hex2rgb(hex)
|
77
|
-
r,g,b = hex[0..1], hex[2..3], hex[4..5]
|
78
|
-
[r,g,b].map { |e| e.to_i(16) }
|
77
|
+
r, g, b = hex[0..1], hex[2..3], hex[4..5]
|
78
|
+
[r, g, b].map { |e| e.to_i(16) }
|
79
79
|
end
|
80
80
|
|
81
81
|
private
|
@@ -87,7 +87,7 @@ module Prawn
|
|
87
87
|
when 4
|
88
88
|
color
|
89
89
|
else
|
90
|
-
|
90
|
+
fail ArgumentError, 'wrong number of arguments supplied'
|
91
91
|
end
|
92
92
|
end
|
93
93
|
|
@@ -102,7 +102,7 @@ module Prawn
|
|
102
102
|
when 4
|
103
103
|
:CMYK
|
104
104
|
else
|
105
|
-
|
105
|
+
fail ArgumentError, "Unknown type of color: #{color.inspect}"
|
106
106
|
end
|
107
107
|
end
|
108
108
|
end
|
@@ -110,10 +110,10 @@ module Prawn
|
|
110
110
|
def normalize_color(color)
|
111
111
|
case color_type(color)
|
112
112
|
when :RGB
|
113
|
-
r,g,b = hex2rgb(color)
|
113
|
+
r, g, b = hex2rgb(color)
|
114
114
|
[r / 255.0, g / 255.0, b / 255.0]
|
115
115
|
when :CMYK
|
116
|
-
c,m,y,k = *color
|
116
|
+
c, m, y, k = *color
|
117
117
|
[c / 100.0, m / 100.0, y / 100.0, k / 100.0]
|
118
118
|
end
|
119
119
|
end
|
@@ -139,30 +139,30 @@ module Prawn
|
|
139
139
|
set_current_color_space(color_space, type)
|
140
140
|
|
141
141
|
unless COLOR_SPACES.include?(color_space)
|
142
|
-
|
142
|
+
fail ArgumentError, "unknown color space: '#{color_space}'"
|
143
143
|
end
|
144
144
|
|
145
145
|
operator = case type
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
146
|
+
when :fill
|
147
|
+
'cs'
|
148
|
+
when :stroke
|
149
|
+
'CS'
|
150
|
+
else
|
151
|
+
fail ArgumentError, "unknown type '#{type}'"
|
152
|
+
end
|
153
153
|
|
154
154
|
renderer.add_content "/#{color_space} #{operator}"
|
155
155
|
end
|
156
156
|
|
157
157
|
def set_color(type, color, options = {})
|
158
158
|
operator = case type
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
159
|
+
when :fill
|
160
|
+
'scn'
|
161
|
+
when :stroke
|
162
|
+
'SCN'
|
163
|
+
else
|
164
|
+
fail ArgumentError, "unknown type '#{type}'"
|
165
|
+
end
|
166
166
|
|
167
167
|
if options[:pattern]
|
168
168
|
set_color_space type, :Pattern
|
@@ -225,8 +225,6 @@ module Prawn
|
|
225
225
|
def write_color(color, operator)
|
226
226
|
renderer.add_content "#{color} #{operator}"
|
227
227
|
end
|
228
|
-
|
229
228
|
end
|
230
229
|
end
|
231
230
|
end
|
232
|
-
|
data/lib/prawn/graphics/dash.rb
CHANGED
@@ -52,17 +52,17 @@ module Prawn
|
|
52
52
|
# Integers or Floats may be used for length and the option values.
|
53
53
|
# Dash units are in PDF points (1/72 inch).
|
54
54
|
#
|
55
|
-
def dash(length=nil, options={})
|
55
|
+
def dash(length = nil, options = {})
|
56
56
|
return current_dash_state if length.nil?
|
57
57
|
|
58
58
|
if length == 0 || length.kind_of?(Array) && length.any? { |e| e == 0 }
|
59
|
-
|
60
|
-
|
59
|
+
fail ArgumentError,
|
60
|
+
"Zero length dashes are invalid. Call #undash to disable dashes."
|
61
61
|
end
|
62
62
|
|
63
63
|
self.current_dash_state = { :dash => length,
|
64
|
-
|
65
|
-
|
64
|
+
:space => length.kind_of?(Array) ? nil : options[:space] || length,
|
65
|
+
:phase => options[:phase] || 0 }
|
66
66
|
|
67
67
|
write_stroke_dash
|
68
68
|
end
|
@@ -103,7 +103,6 @@ module Prawn
|
|
103
103
|
def dash_setting
|
104
104
|
graphic_state.dash_setting
|
105
105
|
end
|
106
|
-
|
107
106
|
end
|
108
107
|
end
|
109
108
|
end
|
@@ -20,7 +20,7 @@ module Prawn
|
|
20
20
|
# NOTE: if this method is never called, :miter will be used for join style
|
21
21
|
# throughout the document
|
22
22
|
#
|
23
|
-
def join_style(style=nil)
|
23
|
+
def join_style(style = nil)
|
24
24
|
return current_join_style || :miter if style.nil?
|
25
25
|
|
26
26
|
self.current_join_style = style
|
@@ -40,7 +40,6 @@ module Prawn
|
|
40
40
|
graphic_state.join_style = style
|
41
41
|
end
|
42
42
|
|
43
|
-
|
44
43
|
def write_stroke_join_style
|
45
44
|
renderer.add_content "#{JOIN_STYLES[current_join_style]} j"
|
46
45
|
end
|
@@ -47,13 +47,13 @@ module Prawn
|
|
47
47
|
end
|
48
48
|
|
49
49
|
operator = case type
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
50
|
+
when :fill
|
51
|
+
'scn'
|
52
|
+
when :stroke
|
53
|
+
'SCN'
|
54
|
+
else
|
55
|
+
fail ArgumentError, "unknown type '#{type}'"
|
56
|
+
end
|
57
57
|
|
58
58
|
set_color_space type, :Pattern
|
59
59
|
renderer.add_content "/SP#{registry_key} #{operator}"
|
@@ -83,43 +83,47 @@ module Prawn
|
|
83
83
|
|
84
84
|
def gradient(*args)
|
85
85
|
if args.length != 4 && args.length != 6
|
86
|
-
|
86
|
+
fail ArgumentError, "Unknown type of gradient: #{args.inspect}"
|
87
87
|
end
|
88
88
|
|
89
89
|
color1 = normalize_color(args[-2]).dup.freeze
|
90
90
|
color2 = normalize_color(args[-1]).dup.freeze
|
91
91
|
|
92
92
|
if color_type(color1) != color_type(color2)
|
93
|
-
|
93
|
+
fail ArgumentError, "Both colors must be of the same color space: #{color1.inspect} and #{color2.inspect}"
|
94
94
|
end
|
95
95
|
|
96
96
|
process_color color1
|
97
97
|
process_color color2
|
98
98
|
|
99
|
-
shader = ref!(
|
99
|
+
shader = ref!(
|
100
100
|
:FunctionType => 2,
|
101
101
|
:Domain => [0.0, 1.0],
|
102
102
|
:C0 => color1,
|
103
103
|
:C1 => color2,
|
104
|
-
:N => 1.0
|
105
|
-
|
104
|
+
:N => 1.0
|
105
|
+
)
|
106
|
+
|
107
|
+
if args.length == 4
|
108
|
+
coords = [0, 0, args[1].first - args[0].first, args[1].last - args[0].last]
|
109
|
+
else
|
110
|
+
coords = [0, 0, args[1], args[2].first - args[0].first, args[2].last - args[0].last, args[3]]
|
111
|
+
end
|
106
112
|
|
107
|
-
shading = ref!(
|
113
|
+
shading = ref!(
|
108
114
|
:ShadingType => args.length == 4 ? 2 : 3, # axial : radial shading
|
109
115
|
:ColorSpace => color_space(color1),
|
110
|
-
:Coords =>
|
111
|
-
[0, 0, args[1].first - args[0].first, args[1].last - args[0].last] :
|
112
|
-
[0, 0, args[1], args[2].first - args[0].first, args[2].last - args[0].last, args[3]],
|
116
|
+
:Coords => coords,
|
113
117
|
:Function => shader,
|
114
|
-
:Extend => [true, true]
|
115
|
-
|
118
|
+
:Extend => [true, true]
|
119
|
+
)
|
116
120
|
|
117
|
-
ref!(
|
121
|
+
ref!(
|
118
122
|
:PatternType => 2, # shading pattern
|
119
123
|
:Shading => shading,
|
120
124
|
:Matrix => [1, 0,
|
121
|
-
0, 1] + map_to_absolute(args[0])
|
122
|
-
|
125
|
+
0, 1] + map_to_absolute(args[0])
|
126
|
+
)
|
123
127
|
end
|
124
128
|
end
|
125
129
|
end
|