prawn 2.2.2 → 2.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/GPLv2 +20 -21
- data/Gemfile +2 -0
- data/Rakefile +10 -3
- data/lib/prawn.rb +9 -3
- data/lib/prawn/document.rb +40 -18
- data/lib/prawn/document/bounding_box.rb +9 -4
- data/lib/prawn/document/column_box.rb +2 -0
- data/lib/prawn/document/internals.rb +6 -4
- data/lib/prawn/document/span.rb +2 -0
- data/lib/prawn/encoding.rb +4 -1
- data/lib/prawn/errors.rb +2 -0
- data/lib/prawn/font.rb +34 -17
- data/lib/prawn/font_metric_cache.rb +8 -3
- data/lib/prawn/{font → fonts}/afm.rb +14 -7
- data/lib/prawn/{font → fonts}/dfont.rb +3 -1
- data/lib/prawn/fonts/otf.rb +11 -0
- data/lib/prawn/{font → fonts}/ttc.rb +3 -1
- data/lib/prawn/{font → fonts}/ttf.rb +23 -12
- data/lib/prawn/graphics.rb +24 -26
- data/lib/prawn/graphics/blend_mode.rb +2 -0
- data/lib/prawn/graphics/cap_style.rb +2 -0
- data/lib/prawn/graphics/color.rb +8 -3
- data/lib/prawn/graphics/dash.rb +3 -1
- data/lib/prawn/graphics/join_style.rb +2 -0
- data/lib/prawn/graphics/patterns.rb +7 -2
- data/lib/prawn/graphics/transformation.rb +5 -1
- data/lib/prawn/graphics/transparency.rb +2 -0
- data/lib/prawn/grid.rb +39 -38
- data/lib/prawn/image_handler.rb +2 -0
- data/lib/prawn/images.rb +21 -19
- data/lib/prawn/images/image.rb +2 -0
- data/lib/prawn/images/jpg.rb +2 -0
- data/lib/prawn/images/png.rb +9 -9
- data/lib/prawn/measurement_extensions.rb +2 -0
- data/lib/prawn/measurements.rb +5 -0
- data/lib/prawn/outline.rb +2 -0
- data/lib/prawn/repeater.rb +2 -0
- data/lib/prawn/security.rb +26 -24
- data/lib/prawn/security/arcfour.rb +2 -0
- data/lib/prawn/soft_mask.rb +3 -1
- data/lib/prawn/stamp.rb +4 -1
- data/lib/prawn/text.rb +14 -12
- data/lib/prawn/text/box.rb +3 -1
- data/lib/prawn/text/formatted.rb +2 -0
- data/lib/prawn/text/formatted/arranger.rb +12 -12
- data/lib/prawn/text/formatted/box.rb +23 -13
- data/lib/prawn/text/formatted/fragment.rb +2 -0
- data/lib/prawn/text/formatted/line_wrap.rb +10 -8
- data/lib/prawn/text/formatted/parser.rb +8 -10
- data/lib/prawn/text/formatted/wrap.rb +4 -2
- data/lib/prawn/transformation_stack.rb +5 -2
- data/lib/prawn/utilities.rb +2 -2
- data/lib/prawn/version.rb +3 -1
- data/lib/prawn/view.rb +15 -7
- data/manual/basic_concepts/adding_pages.rb +2 -0
- data/manual/basic_concepts/basic_concepts.rb +4 -2
- data/manual/basic_concepts/creation.rb +2 -0
- data/manual/basic_concepts/cursor.rb +2 -0
- data/manual/basic_concepts/measurement.rb +3 -1
- data/manual/basic_concepts/origin.rb +2 -0
- data/manual/basic_concepts/other_cursor_helpers.rb +2 -0
- data/manual/basic_concepts/view.rb +2 -0
- data/manual/bounding_box/bounding_box.rb +4 -2
- data/manual/bounding_box/bounds.rb +6 -4
- data/manual/bounding_box/canvas.rb +2 -0
- data/manual/bounding_box/creation.rb +2 -0
- data/manual/bounding_box/indentation.rb +2 -0
- data/manual/bounding_box/nesting.rb +2 -0
- data/manual/bounding_box/russian_boxes.rb +6 -4
- data/manual/bounding_box/stretchy.rb +2 -0
- data/manual/contents.rb +2 -0
- data/manual/cover.rb +10 -7
- data/manual/document_and_page_options/background.rb +2 -0
- data/manual/document_and_page_options/document_and_page_options.rb +4 -2
- data/manual/document_and_page_options/metadata.rb +2 -0
- data/manual/document_and_page_options/page_margins.rb +2 -0
- data/manual/document_and_page_options/page_size.rb +2 -0
- data/manual/document_and_page_options/print_scaling.rb +2 -0
- data/manual/example_helper.rb +5 -2
- data/manual/graphics/blend_mode.rb +6 -4
- data/manual/graphics/circle_and_ellipse.rb +2 -0
- data/manual/graphics/color.rb +2 -0
- data/manual/graphics/common_lines.rb +2 -0
- data/manual/graphics/fill_and_stroke.rb +2 -0
- data/manual/graphics/fill_rules.rb +2 -0
- data/manual/graphics/gradients.rb +2 -0
- data/manual/graphics/graphics.rb +4 -2
- data/manual/graphics/helper.rb +2 -0
- data/manual/graphics/line_width.rb +3 -0
- data/manual/graphics/lines_and_curves.rb +2 -0
- data/manual/graphics/polygon.rb +2 -0
- data/manual/graphics/rectangle.rb +2 -0
- data/manual/graphics/rotate.rb +2 -0
- data/manual/graphics/scale.rb +2 -0
- data/manual/graphics/soft_masks.rb +2 -0
- data/manual/graphics/stroke_cap.rb +3 -1
- data/manual/graphics/stroke_dash.rb +2 -0
- data/manual/graphics/stroke_join.rb +3 -1
- data/manual/graphics/translate.rb +2 -0
- data/manual/graphics/transparency.rb +2 -0
- data/manual/how_to_read_this_manual.rb +2 -0
- data/manual/images/absolute_position.rb +2 -0
- data/manual/images/fit.rb +2 -0
- data/manual/images/horizontal.rb +3 -1
- data/manual/images/images.rb +4 -2
- data/manual/images/plain_image.rb +2 -0
- data/manual/images/scale.rb +2 -0
- data/manual/images/vertical.rb +3 -1
- data/manual/images/width_and_height.rb +2 -0
- data/manual/layout/boxes.rb +2 -0
- data/manual/layout/content.rb +2 -0
- data/manual/layout/layout.rb +4 -2
- data/manual/layout/simple_grid.rb +2 -0
- data/manual/outline/add_subsection_to.rb +2 -0
- data/manual/outline/insert_section_after.rb +2 -0
- data/manual/outline/outline.rb +4 -2
- data/manual/outline/sections_and_pages.rb +2 -0
- data/manual/repeatable_content/alternate_page_numbering.rb +2 -0
- data/manual/repeatable_content/page_numbering.rb +2 -0
- data/manual/repeatable_content/repeatable_content.rb +4 -2
- data/manual/repeatable_content/repeater.rb +2 -0
- data/manual/repeatable_content/stamp.rb +2 -0
- data/manual/security/encryption.rb +2 -0
- data/manual/security/permissions.rb +2 -0
- data/manual/security/security.rb +4 -2
- data/manual/table.rb +2 -0
- data/manual/text/alignment.rb +2 -0
- data/manual/text/color.rb +2 -0
- data/manual/text/column_box.rb +4 -2
- data/manual/text/fallback_fonts.rb +4 -2
- data/manual/text/font.rb +2 -0
- data/manual/text/font_size.rb +2 -0
- data/manual/text/font_style.rb +4 -2
- data/manual/text/formatted_callbacks.rb +2 -0
- data/manual/text/formatted_text.rb +3 -1
- data/manual/text/free_flowing_text.rb +2 -0
- data/manual/text/inline.rb +2 -0
- data/manual/text/kerning_and_character_spacing.rb +2 -0
- data/manual/text/leading.rb +2 -0
- data/manual/text/line_wrapping.rb +4 -1
- data/manual/text/paragraph_indentation.rb +2 -0
- data/manual/text/positioned_text.rb +2 -0
- data/manual/text/registering_families.rb +4 -2
- data/manual/text/rendering_and_color.rb +2 -0
- data/manual/text/right_to_left_text.rb +2 -0
- data/manual/text/rotation.rb +3 -1
- data/manual/text/single_usage.rb +2 -0
- data/manual/text/text.rb +4 -3
- data/manual/text/text_box_excess.rb +2 -0
- data/manual/text/text_box_extensions.rb +2 -0
- data/manual/text/text_box_overflow.rb +3 -1
- data/manual/text/utf8.rb +3 -1
- data/manual/text/win_ansi_charset.rb +6 -3
- data/prawn.gemspec +14 -11
- data/spec/extensions/encoding_helpers.rb +4 -2
- data/spec/prawn/document/bounding_box_spec.rb +8 -8
- data/spec/prawn/document/column_box_spec.rb +2 -0
- data/spec/prawn/document/security_spec.rb +12 -9
- data/spec/prawn/document_annotations_spec.rb +2 -0
- data/spec/prawn/document_destinations_spec.rb +2 -0
- data/spec/prawn/document_grid_spec.rb +3 -0
- data/spec/prawn/document_reference_spec.rb +2 -0
- data/spec/prawn/document_span_spec.rb +2 -0
- data/spec/prawn/document_spec.rb +59 -14
- data/spec/prawn/font_metric_cache_spec.rb +2 -0
- data/spec/prawn/font_spec.rb +45 -16
- data/spec/prawn/graphics/blend_mode_spec.rb +4 -2
- data/spec/prawn/graphics/transparency_spec.rb +2 -0
- data/spec/prawn/graphics_spec.rb +40 -20
- data/spec/prawn/graphics_stroke_styles_spec.rb +2 -0
- data/spec/prawn/image_handler_spec.rb +2 -0
- data/spec/prawn/images/jpg_spec.rb +2 -0
- data/spec/prawn/images/png_spec.rb +2 -0
- data/spec/prawn/images_spec.rb +56 -2
- data/spec/prawn/measurements_extensions_spec.rb +2 -0
- data/spec/prawn/outline_spec.rb +6 -2
- data/spec/prawn/repeater_spec.rb +6 -4
- data/spec/prawn/soft_mask_spec.rb +2 -0
- data/spec/prawn/stamp_spec.rb +11 -7
- data/spec/prawn/text/box_spec.rb +26 -27
- data/spec/prawn/text/formatted/arranger_spec.rb +30 -28
- data/spec/prawn/text/formatted/box_spec.rb +78 -57
- data/spec/prawn/text/formatted/fragment_spec.rb +10 -8
- data/spec/prawn/text/formatted/line_wrap_spec.rb +8 -5
- data/spec/prawn/text/formatted/parser_spec.rb +32 -2
- data/spec/prawn/text_draw_text_spec.rb +5 -3
- data/spec/prawn/text_rendering_mode_spec.rb +7 -1
- data/spec/prawn/text_spacing_spec.rb +6 -4
- data/spec/prawn/text_spec.rb +9 -7
- data/spec/prawn/text_with_inline_formatting_spec.rb +3 -1
- data/spec/prawn/transformation_stack_spec.rb +2 -0
- data/spec/prawn/view_spec.rb +18 -0
- data/spec/{manual_spec.rb → prawn_manual_spec.rb} +6 -4
- data/spec/spec_helper.rb +9 -10
- metadata +86 -73
- metadata.gz.sig +4 -2
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# font_metric_cache.rb : The Prawn font class
|
2
4
|
#
|
3
5
|
# Copyright Dec 2012, Kenneth Kalmer. All Rights Reserved.
|
@@ -35,9 +37,12 @@ module Prawn
|
|
35
37
|
|
36
38
|
length = @cache[key]
|
37
39
|
|
38
|
-
|
39
|
-
|
40
|
-
|
40
|
+
character_count = @document.font.character_count(encoded_string)
|
41
|
+
if character_count.positive?
|
42
|
+
length += @document.character_spacing * (character_count - 1)
|
43
|
+
end
|
44
|
+
|
45
|
+
length
|
41
46
|
end
|
42
47
|
end
|
43
48
|
end
|
@@ -1,4 +1,6 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Implements AFM font support for Prawn
|
2
4
|
#
|
3
5
|
# Copyright May 2008, Gregory Brown / James Healy. All Rights Reserved.
|
4
6
|
#
|
@@ -7,7 +9,7 @@
|
|
7
9
|
require_relative '../encoding'
|
8
10
|
|
9
11
|
module Prawn
|
10
|
-
|
12
|
+
module Fonts
|
11
13
|
# @private
|
12
14
|
|
13
15
|
class AFM < Font
|
@@ -49,14 +51,16 @@ module Prawn
|
|
49
51
|
end
|
50
52
|
|
51
53
|
def initialize(document, name, options = {}) #:nodoc:
|
54
|
+
name ||= options[:family]
|
52
55
|
unless BUILT_INS.include?(name)
|
53
|
-
raise Prawn::Errors::UnknownFont,
|
56
|
+
raise Prawn::Errors::UnknownFont,
|
57
|
+
"#{name} (#{options[:style] || 'normal'}) is not a known font."
|
54
58
|
end
|
55
59
|
|
56
60
|
super
|
57
61
|
|
58
62
|
file_name = @name.dup
|
59
|
-
file_name << '.afm' unless
|
63
|
+
file_name << '.afm' unless /\.afm$/.match?(file_name)
|
60
64
|
file_name = file_name[0] == '/' ? file_name : find_font(file_name)
|
61
65
|
|
62
66
|
font_data = self.class.font_data[file_name] ||= parse_afm(file_name)
|
@@ -93,9 +97,11 @@ module Prawn
|
|
93
97
|
|
94
98
|
# Returns true if the font has kerning data, false otherwise
|
95
99
|
#
|
100
|
+
# rubocop: disable Naming/PredicateName
|
96
101
|
def has_kerning_data?
|
97
102
|
@kern_pairs.any?
|
98
103
|
end
|
104
|
+
# rubocop: enable Naming/PredicateName
|
99
105
|
|
100
106
|
# built-in fonts only work with winansi encoding, so translate the
|
101
107
|
# string. Changes the encoding in-place, so the argument itself
|
@@ -109,8 +115,8 @@ module Prawn
|
|
109
115
|
raise Prawn::Errors::IncompatibleStringEncoding,
|
110
116
|
"Your document includes text that's not compatible with the " \
|
111
117
|
"Windows-1252 character set.\n" \
|
112
|
-
|
113
|
-
"built-in fonts.\n"
|
118
|
+
'If you need full UTF-8 support, use external fonts instead of ' \
|
119
|
+
"PDF's built-in fonts.\n"
|
114
120
|
end
|
115
121
|
|
116
122
|
def to_utf8(text)
|
@@ -194,13 +200,14 @@ module Prawn
|
|
194
200
|
|
195
201
|
case section
|
196
202
|
when %w[FontMetrics CharMetrics]
|
197
|
-
next unless
|
203
|
+
next unless /^CH?\s/.match?(line)
|
198
204
|
|
199
205
|
name = line[/\bN\s+(\.?\w+)\s*;/, 1]
|
200
206
|
data[:glyph_widths][name] = line[/\bWX\s+(\d+)\s*;/, 1].to_i
|
201
207
|
data[:bounding_boxes][name] = line[/\bB\s+([^;]+);/, 1].to_s.rstrip
|
202
208
|
when %w[FontMetrics KernData KernPairs]
|
203
209
|
next unless line =~ /^KPX\s+(\.?\w+)\s+(\.?\w+)\s+(-?\d+)/
|
210
|
+
|
204
211
|
data[:kern_pairs][[Regexp.last_match(1), Regexp.last_match(2)]] =
|
205
212
|
Regexp.last_match(3).to_i
|
206
213
|
when %w[FontMetrics KernData TrackKern],
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# prawn/font/ttf.rb : Implements AFM font support for Prawn
|
2
4
|
#
|
3
5
|
# Copyright May 2008, Gregory Brown / James Healy / Jamis Buck
|
@@ -9,7 +11,7 @@ require 'ttfunk'
|
|
9
11
|
require 'ttfunk/subset_collection'
|
10
12
|
|
11
13
|
module Prawn
|
12
|
-
|
14
|
+
module Fonts
|
13
15
|
# @private
|
14
16
|
class TTF < Font
|
15
17
|
attr_reader :ttf, :subsets
|
@@ -23,6 +25,7 @@ module Prawn
|
|
23
25
|
|
24
26
|
@ttf = read_ttf_file
|
25
27
|
@subsets = TTFunk::SubsetCollection.new(@ttf)
|
28
|
+
@italic_angle = nil
|
26
29
|
|
27
30
|
@attributes = {}
|
28
31
|
@bounding_boxes = {}
|
@@ -59,9 +62,12 @@ module Prawn
|
|
59
62
|
end
|
60
63
|
|
61
64
|
# Returns true if the font has kerning data, false otherwise
|
65
|
+
#
|
66
|
+
# rubocop: disable Naming/PredicateName
|
62
67
|
def has_kerning_data?
|
63
68
|
@has_kerning_data
|
64
69
|
end
|
70
|
+
# rubocop: enable Naming/PredicateName
|
65
71
|
|
66
72
|
# Perform any changes to the string that need to happen
|
67
73
|
# before it is rendered to the canvas. Returns an array of
|
@@ -109,7 +115,7 @@ module Prawn
|
|
109
115
|
end
|
110
116
|
|
111
117
|
# not sure how to compute this for true-type fonts...
|
112
|
-
def
|
118
|
+
def stem_v
|
113
119
|
0
|
114
120
|
end
|
115
121
|
|
@@ -155,7 +161,7 @@ module Prawn
|
|
155
161
|
end
|
156
162
|
|
157
163
|
def pdf_flags
|
158
|
-
@
|
164
|
+
@pdf_flags ||= begin
|
159
165
|
flags = 0
|
160
166
|
flags |= 0x0001 if @ttf.postscript.fixed_pitch?
|
161
167
|
flags |= 0x0002 if serif?
|
@@ -168,7 +174,7 @@ module Prawn
|
|
168
174
|
|
169
175
|
def normalize_encoding(text)
|
170
176
|
text.encode(::Encoding::UTF_8)
|
171
|
-
rescue => e
|
177
|
+
rescue StandardError => e
|
172
178
|
puts e
|
173
179
|
raise Prawn::Errors::IncompatibleStringEncoding, 'Encoding ' \
|
174
180
|
"#{text.encoding} can not be transparently converted to UTF-8. " \
|
@@ -182,7 +188,7 @@ module Prawn
|
|
182
188
|
|
183
189
|
def glyph_present?(char)
|
184
190
|
code = char.codepoints.first
|
185
|
-
cmap[code]
|
191
|
+
cmap[code].positive?
|
186
192
|
end
|
187
193
|
|
188
194
|
# Returns the number of characters in +str+ (a UTF-8-encoded string).
|
@@ -220,7 +226,7 @@ module Prawn
|
|
220
226
|
end
|
221
227
|
|
222
228
|
def kern_pairs_table
|
223
|
-
@
|
229
|
+
@kern_pairs_table ||=
|
224
230
|
if has_kerning_data?
|
225
231
|
@ttf.kerning.tables.first.pairs
|
226
232
|
else
|
@@ -243,7 +249,7 @@ module Prawn
|
|
243
249
|
end
|
244
250
|
|
245
251
|
def scale_factor
|
246
|
-
@
|
252
|
+
@scale_factor ||= 1000.0 / @ttf.header.units_per_em
|
247
253
|
end
|
248
254
|
|
249
255
|
def register(subset)
|
@@ -281,7 +287,7 @@ module Prawn
|
|
281
287
|
FontFile2: fontfile,
|
282
288
|
FontBBox: bbox,
|
283
289
|
Flags: pdf_flags,
|
284
|
-
StemV:
|
290
|
+
StemV: stem_v,
|
285
291
|
ItalicAngle: italic_angle,
|
286
292
|
Ascent: @ascender,
|
287
293
|
Descent: @descender,
|
@@ -310,13 +316,18 @@ module Prawn
|
|
310
316
|
map.keys.sort.inject('') do |_s, code|
|
311
317
|
ranges << [] if ranges.last.length >= 100
|
312
318
|
unicode = map[code]
|
313
|
-
ranges.last << format(
|
319
|
+
ranges.last << format(
|
320
|
+
'<%<code>02x><%<unicode>04x>',
|
321
|
+
code: code,
|
322
|
+
unicode: unicode
|
323
|
+
)
|
314
324
|
end
|
315
325
|
|
316
|
-
range_blocks = ranges.inject('') do |s, list|
|
326
|
+
range_blocks = ranges.inject(+'') do |s, list|
|
317
327
|
s << format(
|
318
|
-
"
|
319
|
-
list.length,
|
328
|
+
"%<lenght>d beginbfchar\n%<list>s\nendbfchar\n",
|
329
|
+
lenght: list.length,
|
330
|
+
list: list.join("\n")
|
320
331
|
)
|
321
332
|
end
|
322
333
|
|
data/lib/prawn/graphics.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# graphics.rb : Implements PDF drawing primitives
|
2
4
|
#
|
3
5
|
# Copyright April 2008, Gregory Brown. All Rights Reserved.
|
@@ -148,11 +150,7 @@ module Prawn
|
|
148
150
|
# horizontal_line 25, 100, :at => 75
|
149
151
|
#
|
150
152
|
def horizontal_line(x1, x2, options = {})
|
151
|
-
y1 =
|
152
|
-
options[:at]
|
153
|
-
else
|
154
|
-
y - bounds.absolute_bottom
|
155
|
-
end
|
153
|
+
y1 = options[:at] || y - bounds.absolute_bottom
|
156
154
|
|
157
155
|
line(x1, y1, x2, y1)
|
158
156
|
end
|
@@ -198,36 +196,36 @@ module Prawn
|
|
198
196
|
ellipse(center, radius, radius)
|
199
197
|
end
|
200
198
|
|
201
|
-
# Draws an ellipse of +x+ radius <tt>
|
202
|
-
# with the centre-point at <tt>point</tt> as a complete
|
203
|
-
# drawing point will be moved to the centre-point upon
|
204
|
-
# 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.
|
205
203
|
#
|
206
204
|
# # draws an ellipse with x-radius 25 and y-radius 50
|
207
205
|
# pdf.ellipse [100,100], 25, 50
|
208
206
|
#
|
209
|
-
def ellipse(point,
|
207
|
+
def ellipse(point, radius1, radius2 = radius1)
|
210
208
|
x, y = point
|
211
|
-
l1 =
|
212
|
-
l2 =
|
209
|
+
l1 = radius1 * KAPPA
|
210
|
+
l2 = radius2 * KAPPA
|
213
211
|
|
214
|
-
move_to(x +
|
212
|
+
move_to(x + radius1, y)
|
215
213
|
|
216
214
|
# Upper right hand corner
|
217
|
-
curve_to [x, y +
|
218
|
-
bounds: [[x +
|
215
|
+
curve_to [x, y + radius2],
|
216
|
+
bounds: [[x + radius1, y + l2], [x + l1, y + radius2]]
|
219
217
|
|
220
218
|
# Upper left hand corner
|
221
|
-
curve_to [x -
|
222
|
-
bounds: [[x - l1, y +
|
219
|
+
curve_to [x - radius1, y],
|
220
|
+
bounds: [[x - l1, y + radius2], [x - radius1, y + l2]]
|
223
221
|
|
224
222
|
# Lower left hand corner
|
225
|
-
curve_to [x, y -
|
226
|
-
bounds: [[x -
|
223
|
+
curve_to [x, y - radius2],
|
224
|
+
bounds: [[x - radius1, y - l2], [x - l1, y - radius2]]
|
227
225
|
|
228
226
|
# Lower right hand corner
|
229
|
-
curve_to [x +
|
230
|
-
bounds: [[x + l1, y -
|
227
|
+
curve_to [x + radius1, y],
|
228
|
+
bounds: [[x + l1, y - radius2], [x + radius1, y - l2]]
|
231
229
|
|
232
230
|
move_to(x, y)
|
233
231
|
end
|
@@ -343,9 +341,9 @@ module Prawn
|
|
343
341
|
}.merge(options)
|
344
342
|
|
345
343
|
Prawn.verify_options(
|
346
|
-
[
|
347
|
-
|
348
|
-
|
344
|
+
%i[
|
345
|
+
at width height step_length
|
346
|
+
negative_axes_length color
|
349
347
|
], options
|
350
348
|
)
|
351
349
|
|
@@ -634,12 +632,12 @@ module Prawn
|
|
634
632
|
]
|
635
633
|
|
636
634
|
ops.product(shapes).each do |operation, shape|
|
637
|
-
class_eval <<-
|
635
|
+
class_eval <<-METHOD, __FILE__, __LINE__ + 1
|
638
636
|
def #{operation}_#{shape}(*args)
|
639
637
|
#{shape}(*args)
|
640
638
|
#{operation}
|
641
639
|
end
|
642
|
-
|
640
|
+
METHOD
|
643
641
|
end
|
644
642
|
|
645
643
|
private
|
data/lib/prawn/graphics/color.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# color.rb : Implements color handling
|
2
4
|
#
|
3
5
|
# Copyright June 2008, Gregory Brown. All Rights Reserved.
|
@@ -25,6 +27,7 @@ module Prawn
|
|
25
27
|
#
|
26
28
|
def fill_color(*color)
|
27
29
|
return current_fill_color if color.empty?
|
30
|
+
|
28
31
|
self.current_fill_color = process_color(*color)
|
29
32
|
set_fill_color
|
30
33
|
end
|
@@ -47,6 +50,7 @@ module Prawn
|
|
47
50
|
#
|
48
51
|
def stroke_color(*color)
|
49
52
|
return current_stroke_color if color.empty?
|
53
|
+
|
50
54
|
color = process_color(*color)
|
51
55
|
self.current_stroke_color = color
|
52
56
|
set_stroke_color(color)
|
@@ -63,7 +67,7 @@ module Prawn
|
|
63
67
|
# => "ff7808"
|
64
68
|
#
|
65
69
|
def rgb2hex(rgb)
|
66
|
-
rgb.map { |e| format '
|
70
|
+
rgb.map { |e| format '%<value>02x', value: e }.join
|
67
71
|
end
|
68
72
|
|
69
73
|
# Converts hex string into RGB value array:
|
@@ -94,7 +98,7 @@ module Prawn
|
|
94
98
|
def color_type(color)
|
95
99
|
case color
|
96
100
|
when String
|
97
|
-
if
|
101
|
+
if /\A\h{6}\z/.match?(color)
|
98
102
|
:RGB
|
99
103
|
else
|
100
104
|
raise ArgumentError, "Unknown type of color: #{color.inspect}"
|
@@ -135,7 +139,7 @@ module Prawn
|
|
135
139
|
end
|
136
140
|
end
|
137
141
|
|
138
|
-
COLOR_SPACES = [
|
142
|
+
COLOR_SPACES = %i[DeviceRGB DeviceCMYK Pattern].freeze
|
139
143
|
|
140
144
|
def set_color_space(type, color_space)
|
141
145
|
# don't set the same color space again
|
@@ -143,6 +147,7 @@ module Prawn
|
|
143
147
|
!state.page.in_stamp_stream?
|
144
148
|
return
|
145
149
|
end
|
150
|
+
|
146
151
|
set_current_color_space(color_space, type)
|
147
152
|
|
148
153
|
unless COLOR_SPACES.include?(color_space)
|
data/lib/prawn/graphics/dash.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# dash.rb : Implements stroke dashing
|
2
4
|
#
|
3
5
|
# Contributed by Daniel Nelson. October, 2009
|
@@ -61,7 +63,7 @@ module Prawn
|
|
61
63
|
if length.all?(&:zero?)
|
62
64
|
raise ArgumentError,
|
63
65
|
'Zero length dashes are invalid. Call #undash to disable dashes.'
|
64
|
-
elsif length.any?
|
66
|
+
elsif length.any?(&:negative?)
|
65
67
|
raise ArgumentError,
|
66
68
|
'Negative numbers are not allowed for dash lengths.'
|
67
69
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'digest/sha1'
|
2
4
|
|
3
5
|
# patterns.rb : Implements axial & radial gradients
|
@@ -106,7 +108,8 @@ module Prawn
|
|
106
108
|
renderer.add_content "/SP#{registry_key} #{operator}"
|
107
109
|
end
|
108
110
|
|
109
|
-
|
111
|
+
# rubocop: disable Metrics/ParameterLists
|
112
|
+
def parse_gradient_arguments(
|
110
113
|
*arguments, from: nil, to: nil, r1: nil, r2: nil, stops: nil,
|
111
114
|
apply_transformations: nil
|
112
115
|
)
|
@@ -137,6 +140,7 @@ module Prawn
|
|
137
140
|
unless (0..1).cover?(position)
|
138
141
|
raise ArgumentError, 'position must be between 0 and 1'
|
139
142
|
end
|
143
|
+
|
140
144
|
GradientStop.new(position, normalize_color(color))
|
141
145
|
end
|
142
146
|
|
@@ -159,6 +163,7 @@ module Prawn
|
|
159
163
|
r1, r2
|
160
164
|
)
|
161
165
|
end
|
166
|
+
# rubocop: enable Metrics/ParameterLists
|
162
167
|
|
163
168
|
def gradient_registry_key(gradient)
|
164
169
|
_x1, _y1, x2, y2, transformation = gradient_coordinates(gradient)
|
@@ -171,7 +176,7 @@ module Prawn
|
|
171
176
|
gradient.stops.length,
|
172
177
|
gradient.stops.map { |s| [s.position, s.color] }
|
173
178
|
].flatten
|
174
|
-
Digest::SHA1.hexdigest(key.
|
179
|
+
Digest::SHA1.hexdigest(key.join(','))
|
175
180
|
end
|
176
181
|
|
177
182
|
def gradient_registry
|