prawn 0.14.0 → 0.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.yardopts +2 -1
- data/Rakefile +12 -0
- data/lib/prawn.rb +9 -21
- data/lib/prawn/document.rb +95 -68
- data/lib/prawn/document/bounding_box.rb +22 -4
- data/lib/prawn/document/column_box.rb +2 -0
- data/lib/prawn/document/graphics_state.rb +1 -1
- data/lib/prawn/document/internals.rb +2 -2
- data/lib/prawn/document/snapshot.rb +2 -1
- data/lib/prawn/document/span.rb +2 -0
- data/lib/prawn/encoding.rb +1 -1
- data/lib/prawn/font.rb +89 -75
- data/lib/prawn/font/afm.rb +3 -0
- data/lib/prawn/font/dfont.rb +1 -0
- data/lib/prawn/font/ttf.rb +2 -0
- data/lib/prawn/font_metric_cache.rb +3 -1
- data/lib/prawn/graphics.rb +2 -14
- data/lib/prawn/graphics/cap_style.rb +1 -0
- data/lib/prawn/graphics/color.rb +1 -0
- data/lib/prawn/graphics/dash.rb +3 -2
- data/lib/prawn/graphics/join_style.rb +2 -0
- data/lib/prawn/graphics/patterns.rb +1 -0
- data/lib/prawn/graphics/transformation.rb +1 -0
- data/lib/prawn/graphics/transparency.rb +2 -0
- data/lib/prawn/image_handler.rb +2 -0
- data/lib/prawn/images.rb +5 -0
- data/lib/prawn/images/image.rb +1 -0
- data/lib/prawn/images/jpg.rb +3 -0
- data/lib/prawn/images/png.rb +2 -0
- data/lib/prawn/layout.rb +8 -13
- data/lib/prawn/layout/grid.rb +15 -3
- data/lib/prawn/measurement_extensions.rb +4 -0
- data/lib/prawn/measurements.rb +2 -0
- data/lib/prawn/outline.rb +3 -1
- data/lib/prawn/repeater.rb +3 -1
- data/lib/prawn/security.rb +15 -7
- data/lib/prawn/security/arcfour.rb +52 -0
- data/lib/prawn/soft_mask.rb +3 -1
- data/lib/prawn/stamp.rb +2 -0
- data/lib/prawn/table.rb +2 -0
- data/lib/prawn/table/cell.rb +4 -1
- data/lib/prawn/table/cell/image.rb +1 -2
- data/lib/prawn/table/cell/in_table.rb +2 -0
- data/lib/prawn/table/cell/span_dummy.rb +1 -0
- data/lib/prawn/table/cells.rb +7 -2
- data/lib/prawn/table/column_width_calculator.rb +8 -2
- data/lib/prawn/text.rb +4 -2
- data/lib/prawn/text/box.rb +3 -0
- data/lib/prawn/text/formatted/arranger.rb +2 -0
- data/lib/prawn/text/formatted/box.rb +55 -50
- data/lib/prawn/text/formatted/fragment.rb +2 -0
- data/lib/prawn/text/formatted/line_wrap.rb +1 -0
- data/lib/prawn/text/formatted/parser.rb +2 -0
- data/lib/prawn/text/formatted/wrap.rb +2 -0
- data/lib/prawn/utilities.rb +5 -3
- data/manual/graphics/common_lines.rb +2 -0
- data/manual/text/group.rb +2 -0
- data/manual/text/text.rb +1 -1
- data/prawn.gemspec +4 -3
- data/spec/grid_spec.rb +11 -0
- data/spec/object_store_spec.rb +1 -96
- data/spec/reference_spec.rb +0 -57
- data/spec/spec_helper.rb +7 -0
- data/spec/table_spec.rb +26 -0
- metadata +172 -185
- data/lib/pdf/core.rb +0 -35
- data/lib/pdf/core/annotations.rb +0 -60
- data/lib/pdf/core/byte_string.rb +0 -9
- data/lib/pdf/core/destinations.rb +0 -90
- data/lib/pdf/core/document_state.rb +0 -79
- data/lib/pdf/core/filter_list.rb +0 -51
- data/lib/pdf/core/filters.rb +0 -36
- data/lib/pdf/core/graphics_state.rb +0 -89
- data/lib/pdf/core/literal_string.rb +0 -16
- data/lib/pdf/core/name_tree.rb +0 -177
- data/lib/pdf/core/object_store.rb +0 -311
- data/lib/pdf/core/outline.rb +0 -315
- data/lib/pdf/core/page.rb +0 -212
- data/lib/pdf/core/page_geometry.rb +0 -126
- data/lib/pdf/core/pdf_object.rb +0 -99
- data/lib/pdf/core/reference.rb +0 -103
- data/lib/pdf/core/stream.rb +0 -98
- data/lib/pdf/core/text.rb +0 -275
- data/lib/prawn/templates.rb +0 -75
- data/spec/filters_spec.rb +0 -34
- data/spec/name_tree_spec.rb +0 -112
- data/spec/pdf_object_spec.rb +0 -172
- data/spec/stream_spec.rb +0 -58
- data/spec/template_spec_obsolete.rb +0 -352
@@ -9,6 +9,8 @@ require_relative "bounding_box"
|
|
9
9
|
module Prawn
|
10
10
|
class Document
|
11
11
|
|
12
|
+
# @group Experimental API
|
13
|
+
|
12
14
|
# A column box is a bounding box with the additional property that when
|
13
15
|
# text flows past the bottom, it will wrap first to another column on the
|
14
16
|
# same page, and only flow to the next page when all the columns are
|
@@ -14,8 +14,8 @@ module Prawn
|
|
14
14
|
# low level PDF functionality as defined by Adobe's specification, chances
|
15
15
|
# are you won't need anything you find here.
|
16
16
|
#
|
17
|
-
|
18
|
-
|
17
|
+
# @private
|
18
|
+
module Internals
|
19
19
|
# Creates a new Prawn::Reference and adds it to the Document's object
|
20
20
|
# list. The +data+ argument is anything that Prawn::PdfObject() can convert.
|
21
21
|
#
|
data/lib/prawn/document/span.rb
CHANGED
data/lib/prawn/encoding.rb
CHANGED
data/lib/prawn/font.rb
CHANGED
@@ -14,6 +14,8 @@ require_relative "font_metric_cache"
|
|
14
14
|
module Prawn
|
15
15
|
|
16
16
|
class Document
|
17
|
+
# @group Stable API
|
18
|
+
|
17
19
|
# Without arguments, this returns the currently selected font. Otherwise,
|
18
20
|
# it sets the current font. When a block is used, the font is applied
|
19
21
|
# transactionally and is rolled back when the block exits.
|
@@ -67,7 +69,10 @@ module Prawn
|
|
67
69
|
@font
|
68
70
|
end
|
69
71
|
|
72
|
+
# @method font_size(points=nil)
|
73
|
+
#
|
70
74
|
# When called with no argument, returns the current font size.
|
75
|
+
#
|
71
76
|
# When called with a single argument but no block, sets the current font
|
72
77
|
# size. When a block is used, the font size is applied transactionally and
|
73
78
|
# is rolled back when the block exits. You may still change the font size
|
@@ -98,59 +103,44 @@ module Prawn
|
|
98
103
|
@font_size = size_before_yield
|
99
104
|
end
|
100
105
|
|
101
|
-
# Sets the font
|
102
|
-
|
103
|
-
|
104
|
-
def set_font(font, size=nil) # :nodoc:
|
105
|
-
@font = font
|
106
|
-
@font_size = size if size
|
106
|
+
# Sets the font size
|
107
|
+
def font_size=(size)
|
108
|
+
font_size(size)
|
107
109
|
end
|
108
110
|
|
109
|
-
#
|
110
|
-
#
|
111
|
+
# Returns the width of the given string using the given font. If :size is not
|
112
|
+
# specified as one of the options, the string is measured using the current
|
113
|
+
# font size. You can also pass :kerning as an option to indicate whether
|
114
|
+
# kerning should be used when measuring the width (defaults to +false+).
|
111
115
|
#
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
yield
|
118
|
-
ensure
|
119
|
-
set_font(original_font, original_size) if original_font
|
120
|
-
end
|
121
|
-
|
122
|
-
# Looks up the given font using the given criteria. Once a font has been
|
123
|
-
# found by that matches the criteria, it will be cached to subsequent lookups
|
124
|
-
# for that font will return the same object.
|
116
|
+
# Note that the string _must_ be encoded properly for the font being used.
|
117
|
+
# For AFM fonts, this is WinAnsi. For TTF, make sure the font is encoded as
|
118
|
+
# UTF-8. You can use the Font#normalize_encoding method to make sure strings
|
119
|
+
# are in an encoding appropriate for the current font.
|
125
120
|
#--
|
126
|
-
#
|
127
|
-
#
|
128
|
-
#
|
121
|
+
# For the record, this method used to be a method of Font (and still delegates
|
122
|
+
# to width computations on Font). However, having the primary interface for
|
123
|
+
# calculating string widths exist on Font made it tricky to write extensions
|
124
|
+
# for Prawn in which widths are computed differently (e.g., taking formatting
|
125
|
+
# tags into account, or the like).
|
129
126
|
#
|
130
|
-
#
|
131
|
-
#
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
# embedding won't be catastrophic, just annoying.
|
137
|
-
# ++
|
138
|
-
def find_font(name, options={}) #:nodoc:
|
139
|
-
if font_families.key?(name)
|
140
|
-
family, name = name, font_families[name][options[:style] || :normal]
|
141
|
-
if name.is_a?(::Hash)
|
142
|
-
options = options.merge(name)
|
143
|
-
name = options[:file]
|
144
|
-
end
|
145
|
-
end
|
146
|
-
key = "#{name}:#{options[:font] || 0}"
|
147
|
-
font_registry[key] ||= Font.load(self, name, options.merge(:family => family))
|
148
|
-
end
|
127
|
+
# By putting width_of here, on Document itself, extensions may easily override
|
128
|
+
# it and redefine the width calculation behavior.
|
129
|
+
#++
|
130
|
+
def width_of(string, options={})
|
131
|
+
if p = options[:inline_format]
|
132
|
+
p = [] unless p.is_a?(Array)
|
149
133
|
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
134
|
+
# Build up an Arranger with the entire string on one line, finalize it,
|
135
|
+
# and find its width.
|
136
|
+
arranger = Prawn::Text::Formatted::Arranger.new(self, options)
|
137
|
+
arranger.consumed = self.text_formatter.format(string, *p)
|
138
|
+
arranger.finalize_line
|
139
|
+
|
140
|
+
arranger.line_width
|
141
|
+
else
|
142
|
+
width_of_string(string, options)
|
143
|
+
end
|
154
144
|
end
|
155
145
|
|
156
146
|
# Hash that maps font family names to their styled individual font names.
|
@@ -197,39 +187,63 @@ module Prawn
|
|
197
187
|
})
|
198
188
|
end
|
199
189
|
|
200
|
-
#
|
201
|
-
|
202
|
-
#
|
203
|
-
#
|
190
|
+
# @group Experimental API
|
191
|
+
|
192
|
+
# Sets the font directly, given an actual Font object
|
193
|
+
# and size.
|
204
194
|
#
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
#
|
211
|
-
#
|
212
|
-
# calculating string widths exist on Font made it tricky to write extensions
|
213
|
-
# for Prawn in which widths are computed differently (e.g., taking formatting
|
214
|
-
# tags into account, or the like).
|
195
|
+
def set_font(font, size=nil) # :nodoc:
|
196
|
+
@font = font
|
197
|
+
@font_size = size if size
|
198
|
+
end
|
199
|
+
|
200
|
+
# Saves the current font, and then yields. When the block
|
201
|
+
# finishes, the original font is restored.
|
215
202
|
#
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
if p = options[:inline_format]
|
221
|
-
p = [] unless p.is_a?(Array)
|
203
|
+
def save_font
|
204
|
+
@font ||= find_font("Helvetica")
|
205
|
+
original_font = @font
|
206
|
+
original_size = @font_size
|
222
207
|
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
arranger.finalize_line
|
208
|
+
yield
|
209
|
+
ensure
|
210
|
+
set_font(original_font, original_size) if original_font
|
211
|
+
end
|
228
212
|
|
229
|
-
|
230
|
-
|
231
|
-
|
213
|
+
# Looks up the given font using the given criteria. Once a font has been
|
214
|
+
# found by that matches the criteria, it will be cached to subsequent lookups
|
215
|
+
# for that font will return the same object.
|
216
|
+
#--
|
217
|
+
# Challenges involved: the name alone is not sufficient to uniquely identify
|
218
|
+
# a font (think dfont suitcases that can hold multiple different fonts in a
|
219
|
+
# single file). Thus, the :name key is included in the cache key.
|
220
|
+
#
|
221
|
+
# It is further complicated, however, since fonts in some formats (like the
|
222
|
+
# dfont suitcases) can be identified either by numeric index, OR by their
|
223
|
+
# name within the suitcase, and both should hash to the same font object
|
224
|
+
# (to avoid the font being embedded multiple times). This is not yet implemented,
|
225
|
+
# which means if someone selects a font both by name, and by index, the
|
226
|
+
# font will be embedded twice. Since we do font subsetting, this double
|
227
|
+
# embedding won't be catastrophic, just annoying.
|
228
|
+
# ++
|
229
|
+
#
|
230
|
+
# @private
|
231
|
+
def find_font(name, options={}) #:nodoc:
|
232
|
+
if font_families.key?(name)
|
233
|
+
family, name = name, font_families[name][options[:style] || :normal]
|
234
|
+
if name.is_a?(::Hash)
|
235
|
+
options = options.merge(name)
|
236
|
+
name = options[:file]
|
237
|
+
end
|
232
238
|
end
|
239
|
+
key = "#{name}:#{options[:font] || 0}"
|
240
|
+
font_registry[key] ||= Font.load(self, name, options.merge(:family => family))
|
241
|
+
end
|
242
|
+
|
243
|
+
# Hash of Font objects keyed by names
|
244
|
+
#
|
245
|
+
def font_registry #:nodoc:
|
246
|
+
@font_registry ||= {}
|
233
247
|
end
|
234
248
|
|
235
249
|
private
|
data/lib/prawn/font/afm.rb
CHANGED
data/lib/prawn/font/dfont.rb
CHANGED
data/lib/prawn/font/ttf.rb
CHANGED
@@ -11,7 +11,9 @@ module Prawn
|
|
11
11
|
|
12
12
|
# Cache used internally by Prawn::Document instances to calculate the width
|
13
13
|
# of various strings for layout purposes.
|
14
|
-
|
14
|
+
#
|
15
|
+
# @private
|
16
|
+
class FontMetricCache
|
15
17
|
|
16
18
|
CacheEntry = Struct.new( :font, :options, :string )
|
17
19
|
|
data/lib/prawn/graphics.rb
CHANGED
@@ -33,6 +33,8 @@ module Prawn
|
|
33
33
|
include Transformation
|
34
34
|
include Patterns
|
35
35
|
|
36
|
+
# @group Stable API
|
37
|
+
|
36
38
|
#######################################################################
|
37
39
|
# Low level drawing operations must map the point to absolute coords! #
|
38
40
|
#######################################################################
|
@@ -182,13 +184,6 @@ module Prawn
|
|
182
184
|
#
|
183
185
|
KAPPA = 4.0 * ((Math.sqrt(2) - 1.0) / 3.0)
|
184
186
|
|
185
|
-
# <b>DEPRECATED:</b> Please use <tt>circle</tt> instead.
|
186
|
-
def circle_at(point, options)
|
187
|
-
warn "[DEPRECATION] 'circle_at' is deprecated in favor of 'circle'. " +
|
188
|
-
"'circle_at' will be removed in release 1.1"
|
189
|
-
circle(point, options[:radius])
|
190
|
-
end
|
191
|
-
|
192
187
|
# Draws a circle of radius <tt>radius</tt> with the centre-point at <tt>point</tt>
|
193
188
|
# as a complete subpath. The drawing point will be moved to the
|
194
189
|
# centre-point upon completion of the drawing the circle.
|
@@ -199,13 +194,6 @@ module Prawn
|
|
199
194
|
ellipse(center, radius, radius)
|
200
195
|
end
|
201
196
|
|
202
|
-
# <b>DEPRECATED:</b> Please use <tt>ellipse</tt> instead.
|
203
|
-
def ellipse_at(point, r1, r2=r1)
|
204
|
-
warn "[DEPRECATION] 'ellipse_at' is deprecated in favor of 'ellipse'. " +
|
205
|
-
"'ellipse_at' will be removed in release 1.1"
|
206
|
-
ellipse(point, r1, r2)
|
207
|
-
end
|
208
|
-
|
209
197
|
# Draws an ellipse of +x+ radius <tt>r1</tt> and +y+ radius <tt>r2</tt>
|
210
198
|
# with the centre-point at <tt>point</tt> as a complete subpath. The
|
211
199
|
# drawing point will be moved to the centre-point upon completion of the
|
data/lib/prawn/graphics/color.rb
CHANGED
data/lib/prawn/graphics/dash.rb
CHANGED
@@ -9,6 +9,7 @@
|
|
9
9
|
module Prawn
|
10
10
|
module Graphics
|
11
11
|
module Dash
|
12
|
+
# @group Stable API
|
12
13
|
|
13
14
|
# Sets the dash pattern for stroked lines and curves or return the
|
14
15
|
# current dash pattern setting if +length+ is nil.
|
@@ -76,12 +77,12 @@ module Prawn
|
|
76
77
|
current_dash_state != undashed_setting
|
77
78
|
end
|
78
79
|
|
80
|
+
private
|
81
|
+
|
79
82
|
def write_stroke_dash
|
80
83
|
add_content dash_setting
|
81
84
|
end
|
82
85
|
|
83
|
-
private
|
84
|
-
|
85
86
|
def undashed_setting
|
86
87
|
{ :dash => nil, :space => nil, :phase => 0 }
|
87
88
|
end
|
data/lib/prawn/image_handler.rb
CHANGED
data/lib/prawn/images.rb
CHANGED
@@ -11,6 +11,8 @@ require 'pathname'
|
|
11
11
|
module Prawn
|
12
12
|
|
13
13
|
module Images
|
14
|
+
# @group Stable API
|
15
|
+
|
14
16
|
# Add the image at filename to the current page. Currently only
|
15
17
|
# JPG and PNG files are supported. (Note that processing PNG
|
16
18
|
# images with alpha channels can be processor and memory intensive.)
|
@@ -68,9 +70,11 @@ module Prawn
|
|
68
70
|
info
|
69
71
|
end
|
70
72
|
|
73
|
+
|
71
74
|
# Builds an info object (Prawn::Images::*) and a PDF reference representing
|
72
75
|
# the given image. Return a pair: [pdf_obj, info].
|
73
76
|
#
|
77
|
+
# @private
|
74
78
|
def build_image_object(file)
|
75
79
|
io = verify_and_open_image(file)
|
76
80
|
image_content = io.read
|
@@ -100,6 +104,7 @@ module Prawn
|
|
100
104
|
# build_image_object), embed the image according to the <tt>options</tt>
|
101
105
|
# given.
|
102
106
|
#
|
107
|
+
# @private
|
103
108
|
def embed_image(pdf_obj, info, options)
|
104
109
|
# find where the image will be placed and how big it will be
|
105
110
|
w,h = info.calc_image_dimensions(options)
|