pdf-core 0.9.0 → 0.10.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
- checksums.yaml.gz.sig +0 -0
- data/lib/pdf/core/annotations.rb +51 -13
- data/lib/pdf/core/byte_string.rb +3 -1
- data/lib/pdf/core/destinations.rb +64 -24
- data/lib/pdf/core/document_state.rb +97 -14
- data/lib/pdf/core/filter_list.rb +30 -1
- data/lib/pdf/core/filters.rb +26 -7
- data/lib/pdf/core/graphics_state.rb +68 -23
- data/lib/pdf/core/literal_string.rb +9 -9
- data/lib/pdf/core/name_tree.rb +74 -13
- data/lib/pdf/core/object_store.rb +69 -19
- data/lib/pdf/core/outline_item.rb +53 -4
- data/lib/pdf/core/outline_root.rb +18 -2
- data/lib/pdf/core/page.rb +148 -23
- data/lib/pdf/core/page_geometry.rb +4 -58
- data/lib/pdf/core/pdf_object.rb +57 -36
- data/lib/pdf/core/reference.rb +50 -14
- data/lib/pdf/core/renderer.rb +115 -44
- data/lib/pdf/core/stream.rb +38 -8
- data/lib/pdf/core/text.rb +242 -102
- data/lib/pdf/core/utils.rb +8 -0
- data/lib/pdf/core.rb +26 -16
- data/pdf-core.gemspec +27 -23
- data.tar.gz.sig +0 -0
- metadata +44 -107
- metadata.gz.sig +2 -2
- data/Gemfile +0 -5
- data/Rakefile +0 -29
data/lib/pdf/core/text.rb
CHANGED
@@ -8,10 +8,13 @@
|
|
8
8
|
|
9
9
|
module PDF
|
10
10
|
module Core
|
11
|
-
|
11
|
+
# Low-level text rendering.
|
12
|
+
module Text
|
13
|
+
# Valid options of text drawing.
|
12
14
|
# These should be used as a base. Extensions may build on this list
|
13
|
-
#
|
14
15
|
VALID_OPTIONS = %i[kerning size style].freeze
|
16
|
+
|
17
|
+
# text rendering modes
|
15
18
|
MODES = {
|
16
19
|
fill: 0,
|
17
20
|
stroke: 1,
|
@@ -20,20 +23,27 @@ module PDF
|
|
20
23
|
fill_clip: 4,
|
21
24
|
stroke_clip: 5,
|
22
25
|
fill_stroke_clip: 6,
|
23
|
-
clip: 7
|
26
|
+
clip: 7,
|
24
27
|
}.freeze
|
25
28
|
|
29
|
+
# Sygnals that a font doesn't have a name.
|
26
30
|
class BadFontFamily < StandardError
|
27
31
|
def initialize(message = 'Bad font family')
|
28
32
|
super
|
29
33
|
end
|
30
34
|
end
|
31
35
|
|
36
|
+
# @deprecated
|
32
37
|
attr_reader :skip_encoding
|
33
38
|
|
34
39
|
# Low level call to set the current font style and extract text options
|
35
40
|
# from an options hash. Should be called from within a save_font block
|
36
41
|
#
|
42
|
+
# @param options [Hash]
|
43
|
+
# @option options :style [Symbol, String]
|
44
|
+
# @option options :kerning [Boolean]
|
45
|
+
# @option options :size [Numeric]
|
46
|
+
# @return [void]
|
37
47
|
def process_text_options(options)
|
38
48
|
if options[:style]
|
39
49
|
raise BadFontFamily unless font.family
|
@@ -51,8 +61,9 @@ module PDF
|
|
51
61
|
|
52
62
|
# Retrieve the current default kerning setting.
|
53
63
|
#
|
54
|
-
# Defaults to true
|
64
|
+
# Defaults to `true`.
|
55
65
|
#
|
66
|
+
# @return [Boolean]
|
56
67
|
def default_kerning?
|
57
68
|
return true unless defined?(@default_kerning)
|
58
69
|
|
@@ -63,12 +74,15 @@ module PDF
|
|
63
74
|
# be overridden using the :kerning text option when drawing text or a text
|
64
75
|
# box.
|
65
76
|
#
|
77
|
+
# @example
|
66
78
|
# pdf.default_kerning = false
|
67
|
-
# pdf.text('hello world')
|
68
|
-
# pdf.text('hello world', :
|
79
|
+
# pdf.text('hello world') # text is not kerned
|
80
|
+
# pdf.text('hello world', kerning: true) # text is kerned
|
69
81
|
#
|
70
|
-
|
71
|
-
|
82
|
+
# @param value [Boolean]
|
83
|
+
# @return [void]
|
84
|
+
def default_kerning(value)
|
85
|
+
@default_kerning = value
|
72
86
|
end
|
73
87
|
|
74
88
|
alias default_kerning= default_kerning
|
@@ -79,15 +93,18 @@ module PDF
|
|
79
93
|
# overridden using the :leading text option when drawing text or a text
|
80
94
|
# box.
|
81
95
|
#
|
96
|
+
# @example
|
82
97
|
# pdf.default_leading = 7
|
83
|
-
# pdf.text('hello world')
|
84
|
-
# pdf.text('hello world', :
|
98
|
+
# pdf.text('hello world') # a leading of 7 is used
|
99
|
+
# pdf.text('hello world', leading: 0) # a leading of 0 is used
|
85
100
|
#
|
86
|
-
# Defaults to 0
|
101
|
+
# Defaults to 0.
|
87
102
|
#
|
103
|
+
# @param number [Numeric]
|
104
|
+
# @return [Numeric]
|
88
105
|
def default_leading(number = nil)
|
89
106
|
if number.nil?
|
90
|
-
defined?(@default_leading) && @default_leading || 0
|
107
|
+
(defined?(@default_leading) && @default_leading) || 0
|
91
108
|
else
|
92
109
|
@default_leading = number
|
93
110
|
end
|
@@ -101,23 +118,27 @@ module PDF
|
|
101
118
|
# overridden using the :direction text option when drawing text or a text
|
102
119
|
# box.
|
103
120
|
#
|
121
|
+
# @example
|
104
122
|
# pdf.text_direction = :rtl
|
105
|
-
# pdf.text('hello world')
|
106
|
-
# pdf.text('hello world', :
|
123
|
+
# pdf.text('hello world') # prints 'dlrow olleh'
|
124
|
+
# pdf.text('hello world', direction: :ltr) # prints 'hello world'
|
107
125
|
#
|
108
126
|
# Valid directions are:
|
109
127
|
#
|
110
|
-
# *
|
111
|
-
# *
|
128
|
+
# * `:ltr` -- left-to-right (default)
|
129
|
+
# * `:rtl` -- right-to-left
|
112
130
|
#
|
113
131
|
# Side effects:
|
114
132
|
#
|
115
|
-
# * When printing left-to-right, the default text alignment is
|
116
|
-
# * When printing right-to-left, the default text alignment is
|
133
|
+
# * When printing left-to-right, the default text alignment is `:left`
|
134
|
+
# * When printing right-to-left, the default text alignment is `:right`
|
117
135
|
#
|
136
|
+
# @param direction [:ltr, :rtl]
|
137
|
+
# @return [:ltr]
|
138
|
+
# @return [:rtl]
|
118
139
|
def text_direction(direction = nil)
|
119
140
|
if direction.nil?
|
120
|
-
defined?(@text_direction) && @text_direction || :ltr
|
141
|
+
(defined?(@text_direction) && @text_direction) || :ltr
|
121
142
|
else
|
122
143
|
@text_direction = direction
|
123
144
|
end
|
@@ -133,33 +154,36 @@ module PDF
|
|
133
154
|
# rendered using the first font that includes the glyph, starting with the
|
134
155
|
# current font and then moving through :fallback_fonts from left to right.
|
135
156
|
#
|
136
|
-
# Call with an empty array to turn off fallback fonts
|
137
|
-
#
|
138
|
-
#
|
139
|
-
#
|
140
|
-
#
|
141
|
-
# }
|
142
|
-
#
|
143
|
-
#
|
144
|
-
#
|
145
|
-
# }
|
146
|
-
#
|
147
|
-
#
|
148
|
-
#
|
149
|
-
#
|
150
|
-
#
|
151
|
-
#
|
152
|
-
#
|
153
|
-
#
|
157
|
+
# Call with an empty array to turn off fallback fonts.
|
158
|
+
#
|
159
|
+
# @example
|
160
|
+
# file = "#{Prawn::DATADIR}/fonts/gkai00mp.ttf"
|
161
|
+
# font_families['Kai'] = {
|
162
|
+
# normal: { file: file, font: 'Kai' }
|
163
|
+
# }
|
164
|
+
# file = "#{Prawn::DATADIR}/fonts/Action Man.dfont"
|
165
|
+
# font_families['Action Man'] = {
|
166
|
+
# normal: { file: file, font: 'ActionMan' },
|
167
|
+
# }
|
168
|
+
# fallback_fonts ['Times-Roman', 'Kai']
|
169
|
+
# font 'Action Man'
|
170
|
+
# text 'hello ƒ 你好'
|
171
|
+
# # hello prints in Action Man
|
172
|
+
# # ƒ prints in Times-Roman
|
173
|
+
# # 你好 prints in Kai
|
174
|
+
#
|
175
|
+
# fallback_fonts [] # clears document-wide fallback fonts
|
154
176
|
#
|
155
177
|
# Side effects:
|
156
178
|
#
|
157
179
|
# * Increased overhead when fallback fonts are declared as each glyph is
|
158
180
|
# checked to see whether it exists in the current font
|
159
181
|
#
|
182
|
+
# @param fallback_fonts [Array<String>]
|
183
|
+
# @return [Array<String>]
|
160
184
|
def fallback_fonts(fallback_fonts = nil)
|
161
185
|
if fallback_fonts.nil?
|
162
|
-
defined?(@fallback_fonts) && @fallback_fonts || []
|
186
|
+
(defined?(@fallback_fonts) && @fallback_fonts) || []
|
163
187
|
else
|
164
188
|
@fallback_fonts = fallback_fonts
|
165
189
|
end
|
@@ -172,139 +196,255 @@ module PDF
|
|
172
196
|
# Call with a symbol and block to temporarily change the current
|
173
197
|
# text rendering mode.
|
174
198
|
#
|
199
|
+
# Valid modes are:
|
200
|
+
#
|
201
|
+
# * `:fill` - fill text (default)
|
202
|
+
# * `:stroke` - stroke text
|
203
|
+
# * `:fill_stroke` - fill, then stroke text
|
204
|
+
# * `:invisible` - invisible text
|
205
|
+
# * `:fill_clip` - fill text then add to path for clipping
|
206
|
+
# * `:stroke_clip` - stroke text then add to path for clipping
|
207
|
+
# * `:fill_stroke_clip` - fill then stroke text, then add to path for
|
208
|
+
# clipping
|
209
|
+
# * `:clip` - add text to path for clipping
|
210
|
+
#
|
211
|
+
# @example
|
175
212
|
# pdf.text_rendering_mode(:stroke) do
|
176
213
|
# pdf.text('Outlined Text')
|
177
214
|
# end
|
178
215
|
#
|
179
|
-
#
|
180
|
-
#
|
181
|
-
#
|
182
|
-
#
|
183
|
-
|
184
|
-
# * :invisible - invisible text
|
185
|
-
# * :fill_clip - fill text then add to path for clipping
|
186
|
-
# * :stroke_clip - stroke text then add to path for clipping
|
187
|
-
# * :fill_stroke_clip - fill then stroke text, then add to path for
|
188
|
-
# clipping
|
189
|
-
# * :clip - add text to path for clipping
|
190
|
-
def text_rendering_mode(mode = nil)
|
216
|
+
# @param mode [Symbol]
|
217
|
+
# @yield Temporariliy set text rendering mode
|
218
|
+
# @return [Symbol] if called withouth mode
|
219
|
+
# @return [void] otherwise
|
220
|
+
def text_rendering_mode(mode = nil, &block)
|
191
221
|
if mode.nil?
|
192
|
-
return defined?(@text_rendering_mode) && @text_rendering_mode || :fill
|
222
|
+
return (defined?(@text_rendering_mode) && @text_rendering_mode) || :fill
|
193
223
|
end
|
194
224
|
|
195
225
|
unless MODES.key?(mode)
|
196
226
|
raise ArgumentError,
|
197
227
|
"mode must be between one of #{MODES.keys.join(', ')} (#{mode})"
|
198
228
|
end
|
199
|
-
original_mode = text_rendering_mode
|
200
229
|
|
201
|
-
if
|
230
|
+
if text_rendering_mode == mode
|
202
231
|
yield
|
203
232
|
else
|
204
|
-
|
205
|
-
add_content "\n#{MODES[mode]} Tr"
|
206
|
-
yield
|
207
|
-
add_content "\n#{MODES[original_mode]} Tr"
|
208
|
-
@text_rendering_mode = original_mode
|
233
|
+
wrap_and_restore_text_rendering_mode(mode, &block)
|
209
234
|
end
|
210
235
|
end
|
211
236
|
|
237
|
+
# Forget previously set text rendering mode.
|
238
|
+
#
|
239
|
+
# @return [void]
|
212
240
|
def forget_text_rendering_mode!
|
213
241
|
@text_rendering_mode = :unknown
|
214
242
|
end
|
215
243
|
|
216
244
|
# Increases or decreases the space between characters.
|
217
245
|
# For horizontal text, a positive value will increase the space.
|
218
|
-
# For
|
246
|
+
# For vertical text, a positive value will decrease the space.
|
247
|
+
#
|
248
|
+
# Call with no arguments to retrieve current character spacing.
|
219
249
|
#
|
220
|
-
|
250
|
+
# @param amount [Numeric]
|
251
|
+
# @yield Temporarily set character spacing
|
252
|
+
# @return [Numeric] if called without amount
|
253
|
+
# @return [void] otherwise
|
254
|
+
def character_spacing(amount = nil, &block)
|
221
255
|
if amount.nil?
|
222
|
-
return defined?(@character_spacing) && @character_spacing || 0
|
256
|
+
return (defined?(@character_spacing) && @character_spacing) || 0
|
223
257
|
end
|
224
258
|
|
225
|
-
|
226
|
-
if original_character_spacing == amount
|
259
|
+
if character_spacing == amount
|
227
260
|
yield
|
228
261
|
else
|
229
|
-
|
230
|
-
add_content "\n#{PDF::Core.real(amount)} Tc"
|
231
|
-
yield
|
232
|
-
add_content "\n#{PDF::Core.real(original_character_spacing)} Tc"
|
233
|
-
@character_spacing = original_character_spacing
|
262
|
+
wrap_and_restore_character_spacing(amount, &block)
|
234
263
|
end
|
235
264
|
end
|
236
265
|
|
237
266
|
# Increases or decreases the space between words.
|
238
267
|
# For horizontal text, a positive value will increase the space.
|
239
|
-
# For
|
268
|
+
# For vertical text, a positive value will decrease the space.
|
240
269
|
#
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
270
|
+
# Call with no arguments to retrieve current word spacing.
|
271
|
+
#
|
272
|
+
# @param amount [Numeric]
|
273
|
+
# @yield Temporarily set word spacing
|
274
|
+
# @return [Numeric] if called without amount
|
275
|
+
# @return [void] otherwise
|
276
|
+
def word_spacing(amount = nil, &block)
|
277
|
+
return (defined?(@word_spacing) && @word_spacing) || 0 if amount.nil?
|
278
|
+
|
279
|
+
if word_spacing == amount
|
246
280
|
yield
|
247
281
|
else
|
248
|
-
|
249
|
-
add_content "\n#{PDF::Core.real(amount)} Tw"
|
250
|
-
yield
|
251
|
-
add_content "\n#{PDF::Core.real(original_word_spacing)} Tw"
|
252
|
-
|
253
|
-
@word_spacing = original_word_spacing
|
282
|
+
wrap_and_restore_word_spacing(amount, &block)
|
254
283
|
end
|
255
284
|
end
|
256
285
|
|
257
|
-
# Set the horizontal scaling.
|
258
|
-
#
|
259
|
-
|
286
|
+
# Set the horizontal scaling.
|
287
|
+
#
|
288
|
+
# @param amount [Numeric] the percentage of the normal width.
|
289
|
+
# @yield Temporarili set text scaling
|
290
|
+
# @return [Numeric] if called with no arguments
|
291
|
+
# @return [void] otherwise
|
292
|
+
def horizontal_text_scaling(amount = nil, &block)
|
260
293
|
if amount.nil?
|
261
|
-
return defined?(@horizontal_text_scaling) && @horizontal_text_scaling || 100
|
294
|
+
return (defined?(@horizontal_text_scaling) && @horizontal_text_scaling) || 100
|
262
295
|
end
|
263
296
|
|
264
|
-
|
265
|
-
if original_horizontal_text_scaling == amount
|
297
|
+
if horizontal_text_scaling == amount
|
266
298
|
yield
|
267
299
|
else
|
268
|
-
|
269
|
-
|
300
|
+
wrap_and_restore_horizontal_text_scaling(amount, &block)
|
301
|
+
end
|
302
|
+
end
|
303
|
+
|
304
|
+
# Move the baseline up or down from its default location.
|
305
|
+
# Positive values move the baseline up, negative values move it down, and
|
306
|
+
# a zero value resets the baseline to its default location.
|
307
|
+
#
|
308
|
+
# @param amount [Numeric]
|
309
|
+
# @yield Temporarily set text rise
|
310
|
+
# @return [Numeric] if called with no arguments
|
311
|
+
# @return [void] otherwise
|
312
|
+
def rise(amount = nil, &block)
|
313
|
+
if amount.nil?
|
314
|
+
return (defined?(@rise) && @rise) || 0
|
315
|
+
end
|
316
|
+
|
317
|
+
if rise == amount
|
270
318
|
yield
|
271
|
-
|
272
|
-
|
319
|
+
else
|
320
|
+
wrap_and_restore_rise(amount, &block)
|
273
321
|
end
|
274
322
|
end
|
275
323
|
|
324
|
+
# Add a text object to content stream.
|
325
|
+
#
|
326
|
+
# @param text [String]
|
327
|
+
# @param x [Numeric] horizontal position of the text origin on the page
|
328
|
+
# @param y [Numeric] vertical position of the text origin on the page
|
329
|
+
# @param options [Hash]
|
330
|
+
# @option options :rotate [Numeric] text rotation angle in degrees
|
331
|
+
# @option options :kerning [Boolean]
|
276
332
|
def add_text_content(text, x, y, options)
|
277
333
|
chunks = font.encode_text(text, options)
|
278
334
|
|
279
|
-
add_content
|
335
|
+
add_content("\nBT")
|
280
336
|
|
281
337
|
if options[:rotate]
|
282
|
-
rad = options[:rotate]
|
338
|
+
rad = Float(options[:rotate]) * Math::PI / 180
|
283
339
|
array = [
|
284
340
|
Math.cos(rad),
|
285
341
|
Math.sin(rad),
|
286
342
|
-Math.sin(rad),
|
287
343
|
Math.cos(rad),
|
288
|
-
x, y
|
344
|
+
x, y,
|
289
345
|
]
|
290
|
-
add_content
|
346
|
+
add_content("#{PDF::Core.real_params(array)} Tm")
|
291
347
|
else
|
292
|
-
add_content
|
348
|
+
add_content("#{PDF::Core.real(x)} #{PDF::Core.real(y)} Td")
|
293
349
|
end
|
294
350
|
|
295
351
|
chunks.each do |(subset, string)|
|
296
352
|
font.add_to_current_page(subset)
|
297
|
-
add_content
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
353
|
+
add_content(
|
354
|
+
[
|
355
|
+
PDF::Core.pdf_object(font.identifier_for(subset), true),
|
356
|
+
PDF::Core.pdf_object(font_size, true),
|
357
|
+
'Tf',
|
358
|
+
].join(' '),
|
359
|
+
)
|
302
360
|
|
303
361
|
operation = options[:kerning] && string.is_a?(Array) ? 'TJ' : 'Tj'
|
304
|
-
add_content
|
362
|
+
add_content("#{PDF::Core.pdf_object(string, true)} #{operation}")
|
363
|
+
end
|
364
|
+
|
365
|
+
add_content("ET\n")
|
366
|
+
end
|
367
|
+
|
368
|
+
private
|
369
|
+
|
370
|
+
def wrap_and_restore_text_rendering_mode(block_value)
|
371
|
+
original_value = text_rendering_mode
|
372
|
+
@text_rendering_mode = block_value
|
373
|
+
update_text_rendering_mode_state
|
374
|
+
begin
|
375
|
+
yield
|
376
|
+
ensure
|
377
|
+
@text_rendering_mode = original_value
|
378
|
+
update_text_rendering_mode_state
|
305
379
|
end
|
380
|
+
end
|
381
|
+
|
382
|
+
def update_text_rendering_mode_state
|
383
|
+
add_content("\n#{MODES[text_rendering_mode]} Tr")
|
384
|
+
end
|
385
|
+
|
386
|
+
def wrap_and_restore_character_spacing(block_value)
|
387
|
+
original_value = character_spacing
|
388
|
+
@character_spacing = block_value
|
389
|
+
update_character_spacing_state
|
390
|
+
begin
|
391
|
+
yield
|
392
|
+
ensure
|
393
|
+
@character_spacing = original_value
|
394
|
+
update_character_spacing_state
|
395
|
+
end
|
396
|
+
end
|
397
|
+
|
398
|
+
def update_character_spacing_state
|
399
|
+
add_content("\n#{PDF::Core.real(character_spacing)} Tc")
|
400
|
+
end
|
401
|
+
|
402
|
+
def wrap_and_restore_word_spacing(block_value)
|
403
|
+
original_value = word_spacing
|
404
|
+
@word_spacing = block_value
|
405
|
+
update_word_spacing_state
|
406
|
+
begin
|
407
|
+
yield
|
408
|
+
ensure
|
409
|
+
@word_spacing = original_value
|
410
|
+
update_word_spacing_state
|
411
|
+
end
|
412
|
+
end
|
413
|
+
|
414
|
+
def update_word_spacing_state
|
415
|
+
add_content("\n#{PDF::Core.real(word_spacing)} Tw")
|
416
|
+
end
|
417
|
+
|
418
|
+
def wrap_and_restore_horizontal_text_scaling(block_value)
|
419
|
+
original_value = horizontal_text_scaling
|
420
|
+
@horizontal_text_scaling = block_value
|
421
|
+
update_horizontal_text_scaling_state
|
422
|
+
begin
|
423
|
+
yield
|
424
|
+
ensure
|
425
|
+
@horizontal_text_scaling = original_value
|
426
|
+
update_horizontal_text_scaling_state
|
427
|
+
end
|
428
|
+
end
|
429
|
+
|
430
|
+
def update_horizontal_text_scaling_state
|
431
|
+
add_content("\n#{PDF::Core.real(horizontal_text_scaling)} Tz")
|
432
|
+
end
|
433
|
+
|
434
|
+
def wrap_and_restore_rise(block_value)
|
435
|
+
original_value = rise
|
436
|
+
@rise = block_value
|
437
|
+
update_rise_state
|
438
|
+
begin
|
439
|
+
yield
|
440
|
+
ensure
|
441
|
+
@rise = original_value
|
442
|
+
update_rise_state
|
443
|
+
end
|
444
|
+
end
|
306
445
|
|
307
|
-
|
446
|
+
def update_rise_state
|
447
|
+
add_content("\n#{PDF::Core.real(rise)} Ts")
|
308
448
|
end
|
309
449
|
end
|
310
450
|
end
|
data/lib/pdf/core/utils.rb
CHANGED
@@ -2,9 +2,17 @@
|
|
2
2
|
|
3
3
|
module PDF
|
4
4
|
module Core
|
5
|
+
# Utility methods
|
5
6
|
module Utils
|
6
7
|
module_function
|
7
8
|
|
9
|
+
# Deep clone an object.
|
10
|
+
# It uses marshal-demarshal trick. Since it's supposed to be use only on
|
11
|
+
# objects that can be serialized into PDF it shouldn't have any issues
|
12
|
+
# with objects that can not be marshaled.
|
13
|
+
#
|
14
|
+
# @param object [any]
|
15
|
+
# @return [any]
|
8
16
|
def deep_clone(object)
|
9
17
|
Marshal.load(Marshal.dump(object))
|
10
18
|
end
|
data/lib/pdf/core.rb
CHANGED
@@ -1,5 +1,31 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
# Top level Module
|
4
|
+
module PDF
|
5
|
+
# PDF::Core is concerned with low-level PDF functions such as serialization,
|
6
|
+
# content streams and such.
|
7
|
+
#
|
8
|
+
# It's extracted from Prawn but at the moment is not entirely independent.
|
9
|
+
module Core
|
10
|
+
# PDF::Core-specific errors
|
11
|
+
module Errors
|
12
|
+
# This error indicates failure of {PDF::Core.pdf_object}
|
13
|
+
class FailedObjectConversion < StandardError
|
14
|
+
end
|
15
|
+
|
16
|
+
# This error occurs when a graphic state is being restored but the graphic
|
17
|
+
# state stack is empty.
|
18
|
+
class EmptyGraphicStateStack < StandardError
|
19
|
+
end
|
20
|
+
|
21
|
+
# This error is raised when page layout is set to anything other than
|
22
|
+
# `:portrait` or `:landscape`
|
23
|
+
class InvalidPageLayout < StandardError
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
3
29
|
require_relative 'core/pdf_object'
|
4
30
|
require_relative 'core/annotations'
|
5
31
|
require_relative 'core/byte_string'
|
@@ -19,19 +45,3 @@ require_relative 'core/outline_root'
|
|
19
45
|
require_relative 'core/outline_item'
|
20
46
|
require_relative 'core/renderer'
|
21
47
|
require_relative 'core/text'
|
22
|
-
|
23
|
-
module PDF
|
24
|
-
module Core
|
25
|
-
module Errors
|
26
|
-
# This error is raised when pdf_object() fails
|
27
|
-
FailedObjectConversion = Class.new(StandardError)
|
28
|
-
|
29
|
-
# This error is raise when trying to restore a graphic state that
|
30
|
-
EmptyGraphicStateStack = Class.new(StandardError)
|
31
|
-
|
32
|
-
# This error is raised when Document#page_layout is set to anything
|
33
|
-
# other than :portrait or :landscape
|
34
|
-
InvalidPageLayout = Class.new(StandardError)
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
data/pdf-core.gemspec
CHANGED
@@ -2,43 +2,47 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |spec|
|
4
4
|
spec.name = 'pdf-core'
|
5
|
-
spec.version = '0.
|
5
|
+
spec.version = '0.10.0'
|
6
6
|
spec.platform = Gem::Platform::RUBY
|
7
|
-
spec.summary = '
|
7
|
+
spec.summary = 'Low level PDF generator.'
|
8
|
+
spec.description = 'PDF::Core is used by Prawn to render PDF documents. It provides low-level format support.'
|
8
9
|
spec.files =
|
9
10
|
Dir.glob('lib/**/**/*') +
|
10
11
|
%w[COPYING GPLv2 GPLv3 LICENSE] +
|
11
|
-
%w[Gemfile Rakefile] +
|
12
12
|
['pdf-core.gemspec']
|
13
13
|
spec.require_path = 'lib'
|
14
|
-
spec.required_ruby_version = '>= 2.
|
14
|
+
spec.required_ruby_version = '>= 2.7'
|
15
15
|
spec.required_rubygems_version = '>= 1.3.6'
|
16
16
|
|
17
|
-
|
18
|
-
|
19
|
-
|
17
|
+
if File.basename($PROGRAM_NAME) == 'gem' && ARGV.include?('build')
|
18
|
+
signing_key = File.expand_path('~/.gem/gem-private_key.pem')
|
19
|
+
if File.exist?(signing_key)
|
20
|
+
spec.cert_chain = ['certs/pointlessone.pem']
|
21
|
+
spec.signing_key = signing_key
|
22
|
+
else
|
23
|
+
warn 'WARNING: Signing key is missing. The gem is not signed and its authenticity can not be verified.'
|
24
|
+
end
|
20
25
|
end
|
21
26
|
|
22
|
-
# spec.extra_rdoc_files = %w{README.md LICENSE COPYING GPLv2 GPLv3}
|
23
|
-
# spec.rdoc_options << '--title' << 'Prawn Documentation' <<
|
24
|
-
# '--main' << 'README.md' << '-q'
|
25
27
|
spec.authors = [
|
26
|
-
'Gregory Brown', 'Brad Ediger', 'Daniel Nelson',
|
27
|
-
'James Healy'
|
28
|
+
'Alexander Mankuta', 'Gregory Brown', 'Brad Ediger', 'Daniel Nelson',
|
29
|
+
'Jonathan Greenberg', 'James Healy',
|
28
30
|
]
|
29
31
|
spec.email = [
|
30
|
-
'gregory.t.brown@gmail.com', 'brad@bradediger.com',
|
31
|
-
'greenberg@entryway.net', 'jimmy@deefa.com'
|
32
|
+
'alex@pointless.one', 'gregory.t.brown@gmail.com', 'brad@bradediger.com',
|
33
|
+
'dnelson@bluejade.com', 'greenberg@entryway.net', 'jimmy@deefa.com',
|
32
34
|
]
|
33
|
-
spec.licenses = %w[
|
35
|
+
spec.licenses = %w[Nonstandard GPL-2.0-only GPL-3.0-only]
|
36
|
+
spec.homepage = 'http://prawnpdf.org/'
|
37
|
+
spec.metadata = {
|
38
|
+
'rubygems_mfa_required' => 'true',
|
39
|
+
'homepage_uri' => spec.homepage,
|
40
|
+
'changelog_uri' => "https://github.com/prawnpdf/pdf-core/blob/#{spec.version}/CHANGELOG.md",
|
41
|
+
'source_code_uri' => 'https://github.com/prawnpdf/pdf-core',
|
42
|
+
'documentation_uri' => "https://prawnpdf.org/docs/pdf-core/#{spec.version}/",
|
43
|
+
'bug_tracker_uri' => 'https://github.com/prawnpdf/pdf-core/issues',
|
44
|
+
}
|
34
45
|
spec.add_development_dependency('pdf-inspector', '~> 1.1.0')
|
35
46
|
spec.add_development_dependency('pdf-reader', '~>1.2')
|
36
|
-
spec.add_development_dependency('
|
37
|
-
spec.add_development_dependency('rspec')
|
38
|
-
spec.add_development_dependency('rubocop', '~> 0.93')
|
39
|
-
spec.add_development_dependency('rubocop-performance', '~> 1.8')
|
40
|
-
spec.add_development_dependency('rubocop-rspec', '~> 1.44')
|
41
|
-
spec.add_development_dependency('simplecov')
|
42
|
-
spec.homepage = 'http://prawnpdf.org'
|
43
|
-
spec.description = 'PDF::Core is used by Prawn to render PDF documents'
|
47
|
+
spec.add_development_dependency('prawn-dev', '~> 0.4.0')
|
44
48
|
end
|
data.tar.gz.sig
CHANGED
Binary file
|