pdf-core 0.7.0 → 0.9.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/Gemfile +3 -1
- data/Rakefile +17 -3
- data/lib/pdf/core/annotations.rb +1 -1
- data/lib/pdf/core/byte_string.rb +2 -1
- data/lib/pdf/core/destinations.rb +1 -1
- data/lib/pdf/core/document_state.rb +9 -7
- data/lib/pdf/core/filter_list.rb +17 -5
- data/lib/pdf/core/filters.rb +1 -1
- data/lib/pdf/core/graphics_state.rb +9 -8
- data/lib/pdf/core/literal_string.rb +2 -1
- data/lib/pdf/core/name_tree.rb +5 -6
- data/lib/pdf/core/object_store.rb +4 -4
- data/lib/pdf/core/outline_item.rb +3 -2
- data/lib/pdf/core/outline_root.rb +2 -0
- data/lib/pdf/core/page.rb +16 -15
- data/lib/pdf/core/page_geometry.rb +2 -0
- data/lib/pdf/core/pdf_object.rb +28 -19
- data/lib/pdf/core/reference.rb +11 -2
- data/lib/pdf/core/renderer.rb +7 -7
- data/lib/pdf/core/stream.rb +11 -3
- data/lib/pdf/core/text.rb +24 -7
- data/lib/pdf/core/utils.rb +4 -3
- data/lib/pdf/core.rb +2 -0
- data/pdf-core.gemspec +15 -13
- data.tar.gz.sig +0 -0
- metadata +44 -46
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 429f3bfae75301dabdb339edccbdd816026f605dc84d1902f07d6494277d6360
|
4
|
+
data.tar.gz: 13fa187ef7307bc6de531a06d9d97272ff2ba0c2a9e21744b52efe1c387094d5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 76f74e81e59e382b4ab8c0bfe0cd58eb6b8624afd4b6b92fee6ed56da432205ad682cd3bd99b364d29be38747727a198f796975cb7718c7f62ad682f33f4953f
|
7
|
+
data.tar.gz: b0b08cdd020ba23a4b3aa135d795eb35089cf0c6fbe34dd5457a3302f78969062347952b2f0f532b9066578a81537059afed889edd7d102817f26439b7f0848e
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/Gemfile
CHANGED
data/Rakefile
CHANGED
@@ -1,10 +1,9 @@
|
|
1
|
-
|
2
|
-
Bundler.setup
|
1
|
+
# frozen_string_literal: true
|
3
2
|
|
4
3
|
require 'rake'
|
5
4
|
require 'rspec/core/rake_task'
|
6
5
|
|
7
|
-
task default: [
|
6
|
+
task default: %i[spec rubocop]
|
8
7
|
|
9
8
|
desc 'Run all rspec files'
|
10
9
|
RSpec::Core::RakeTask.new('spec') do |c|
|
@@ -13,3 +12,18 @@ end
|
|
13
12
|
|
14
13
|
require 'rubocop/rake_task'
|
15
14
|
RuboCop::RakeTask.new
|
15
|
+
|
16
|
+
require 'rubygems/package_task'
|
17
|
+
spec = Gem::Specification.load 'pdf-core.gemspec'
|
18
|
+
Gem::PackageTask.new(spec) do |pkg|
|
19
|
+
pkg.need_zip = true
|
20
|
+
pkg.need_tar = true
|
21
|
+
end
|
22
|
+
|
23
|
+
task :checksum do
|
24
|
+
require 'digest/sha2'
|
25
|
+
built_gem_path = "pkg/pdf-core-#{Prawn::VERSION}.gem"
|
26
|
+
checksum = Digest::SHA512.new.hexdigest(File.read(built_gem_path))
|
27
|
+
checksum_path = "checksums/#{built_gem_path}.sha512"
|
28
|
+
File.write(checksum_path, checksum)
|
29
|
+
end
|
data/lib/pdf/core/annotations.rb
CHANGED
data/lib/pdf/core/byte_string.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module PDF
|
2
4
|
module Core
|
3
5
|
class DocumentState #:nodoc:
|
@@ -26,18 +28,18 @@ module PDF
|
|
26
28
|
@on_page_create_callback = nil
|
27
29
|
end
|
28
30
|
|
29
|
-
attr_accessor :store, :version, :pages, :page, :trailer, :compress,
|
30
|
-
|
31
|
-
:before_render_callbacks, :on_page_create_callback
|
31
|
+
attr_accessor :store, :version, :pages, :page, :trailer, :compress, :encrypt, :encryption_key, :skip_encoding
|
32
|
+
attr_accessor :before_render_callbacks, :on_page_create_callback
|
32
33
|
|
33
34
|
def populate_pages_from_store(document)
|
34
35
|
return 0 if @store.page_count <= 0 || !@pages.empty?
|
35
36
|
|
36
37
|
count = (1..@store.page_count)
|
37
|
-
@pages =
|
38
|
-
|
39
|
-
|
40
|
-
|
38
|
+
@pages =
|
39
|
+
count.map do |index|
|
40
|
+
orig_dict_id = @store.object_id_for_page(index)
|
41
|
+
PDF::Core::Page.new(document, object_id: orig_dict_id)
|
42
|
+
end
|
41
43
|
end
|
42
44
|
|
43
45
|
def normalize_metadata(options)
|
data/lib/pdf/core/filter_list.rb
CHANGED
@@ -1,6 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module PDF
|
2
4
|
module Core
|
3
5
|
class FilterList
|
6
|
+
class NotFilter < StandardError
|
7
|
+
DEFAULT_MESSAGE = 'Can not interpret input as a filter'
|
8
|
+
MESSAGE_WITH_FILTER = 'Can not interpret input as a filter: %<filter>s'
|
9
|
+
|
10
|
+
def initialize(message = DEFAULT_MESSAGE, filter: nil)
|
11
|
+
if filter
|
12
|
+
super format(MESSAGE_WITH_FILTER, filter: filter)
|
13
|
+
else
|
14
|
+
super(message)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
4
18
|
def initialize
|
5
19
|
@list = []
|
6
20
|
end
|
@@ -14,7 +28,7 @@ module PDF
|
|
14
28
|
@list << [name, params]
|
15
29
|
end
|
16
30
|
else
|
17
|
-
raise
|
31
|
+
raise NotFilter.new(filter: filter)
|
18
32
|
end
|
19
33
|
|
20
34
|
self
|
@@ -41,10 +55,8 @@ module PDF
|
|
41
55
|
@list.inspect
|
42
56
|
end
|
43
57
|
|
44
|
-
def each
|
45
|
-
@list.each
|
46
|
-
yield(filter)
|
47
|
-
end
|
58
|
+
def each(&block)
|
59
|
+
@list.each(&block)
|
48
60
|
end
|
49
61
|
end
|
50
62
|
end
|
data/lib/pdf/core/filters.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
2
3
|
#
|
3
4
|
# Implements graphics state saving and restoring
|
4
5
|
#
|
@@ -43,8 +44,7 @@ module PDF
|
|
43
44
|
|
44
45
|
# NOTE: This class may be a good candidate for a copy-on-write hash.
|
45
46
|
class GraphicState
|
46
|
-
attr_accessor :color_space, :dash, :cap_style, :join_style, :line_width,
|
47
|
-
:fill_color, :stroke_color
|
47
|
+
attr_accessor :color_space, :dash, :cap_style, :join_style, :line_width, :fill_color, :stroke_color
|
48
48
|
|
49
49
|
def initialize(previous_state = nil)
|
50
50
|
if previous_state
|
@@ -63,11 +63,12 @@ module PDF
|
|
63
63
|
def dash_setting
|
64
64
|
return '[] 0 d' unless @dash[:dash]
|
65
65
|
|
66
|
-
array =
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
66
|
+
array =
|
67
|
+
if @dash[:dash].is_a?(Array)
|
68
|
+
@dash[:dash]
|
69
|
+
else
|
70
|
+
[@dash[:dash], @dash[:space]]
|
71
|
+
end
|
71
72
|
|
72
73
|
"[#{PDF::Core.real_params(array)}] "\
|
73
74
|
"#{PDF::Core.real(@dash[:phase])} d"
|
data/lib/pdf/core/name_tree.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'pdf/core/utils'
|
4
4
|
|
@@ -31,7 +31,7 @@ module PDF
|
|
31
31
|
end
|
32
32
|
|
33
33
|
def size
|
34
|
-
leaf? ? children.size : children.
|
34
|
+
leaf? ? children.size : children.sum(&:size)
|
35
35
|
end
|
36
36
|
|
37
37
|
def leaf?
|
@@ -78,8 +78,8 @@ module PDF
|
|
78
78
|
children.insert(insertion_point(value), value)
|
79
79
|
split! if children.length > limit
|
80
80
|
else
|
81
|
-
fit = children.
|
82
|
-
fit
|
81
|
+
fit = children.find { |child| child >= value }
|
82
|
+
fit ||= children.last
|
83
83
|
fit << value
|
84
84
|
end
|
85
85
|
|
@@ -107,8 +107,7 @@ module PDF
|
|
107
107
|
def deep_copy
|
108
108
|
node = dup
|
109
109
|
node.instance_variable_set('@children', Utils.deep_clone(children))
|
110
|
-
node.instance_variable_set('@ref',
|
111
|
-
node.ref ? node.ref.deep_copy : nil)
|
110
|
+
node.instance_variable_set('@ref', node.ref ? node.ref.deep_copy : nil)
|
112
111
|
node
|
113
112
|
end
|
114
113
|
|
@@ -1,4 +1,4 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
# Implements PDF object repository
|
4
4
|
#
|
@@ -91,10 +91,10 @@ module PDF
|
|
91
91
|
# object_id_for_page(-11)
|
92
92
|
# => 17
|
93
93
|
#
|
94
|
-
def object_id_for_page(
|
95
|
-
|
94
|
+
def object_id_for_page(page)
|
95
|
+
page -= 1 if page.positive?
|
96
96
|
flat_page_ids = get_page_objects(pages).flatten
|
97
|
-
flat_page_ids[
|
97
|
+
flat_page_ids[page]
|
98
98
|
end
|
99
99
|
end
|
100
100
|
end
|
@@ -1,8 +1,9 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module PDF
|
2
4
|
module Core
|
3
5
|
class OutlineItem #:nodoc:
|
4
|
-
attr_accessor :count, :first, :last, :next, :prev, :parent, :title, :dest,
|
5
|
-
:closed
|
6
|
+
attr_accessor :count, :first, :last, :next, :prev, :parent, :title, :dest, :closed
|
6
7
|
|
7
8
|
def initialize(title, parent, options)
|
8
9
|
@closed = options[:closed]
|
data/lib/pdf/core/page.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# prawn/core/page.rb : Implements low-level representation of a PDF page
|
2
4
|
#
|
3
5
|
# Copyright February 2010, Gregory Brown. All Rights Reserved.
|
@@ -10,8 +12,7 @@ require_relative 'graphics_state'
|
|
10
12
|
module PDF
|
11
13
|
module Core
|
12
14
|
class Page #:nodoc:
|
13
|
-
attr_accessor :art_indents, :bleeds, :crops, :document, :margins, :stack,
|
14
|
-
:trims
|
15
|
+
attr_accessor :art_indents, :bleeds, :crops, :document, :margins, :stack, :trims
|
15
16
|
attr_writer :content, :dictionary
|
16
17
|
|
17
18
|
ZERO_INDENTS = {
|
@@ -23,20 +24,22 @@ module PDF
|
|
23
24
|
|
24
25
|
def initialize(document, options = {})
|
25
26
|
@document = document
|
26
|
-
@margins
|
27
|
-
|
28
|
-
|
29
|
-
|
27
|
+
@margins = options[:margins] || {
|
28
|
+
left: 36,
|
29
|
+
right: 36,
|
30
|
+
top: 36,
|
31
|
+
bottom: 36
|
32
|
+
}
|
30
33
|
@crops = options[:crops] || ZERO_INDENTS
|
31
34
|
@bleeds = options[:bleeds] || ZERO_INDENTS
|
32
35
|
@trims = options[:trims] || ZERO_INDENTS
|
33
36
|
@art_indents = options[:art_indents] || ZERO_INDENTS
|
34
37
|
@stack = GraphicStateStack.new(options[:graphic_state])
|
35
|
-
@size
|
36
|
-
@layout
|
38
|
+
@size = options[:size] || 'LETTER'
|
39
|
+
@layout = options[:layout] || :portrait
|
37
40
|
|
38
|
-
@stamp_stream
|
39
|
-
@stamp_dictionary
|
41
|
+
@stamp_stream = nil
|
42
|
+
@stamp_dictionary = nil
|
40
43
|
|
41
44
|
@content = document.ref({})
|
42
45
|
content << 'q' << "\n"
|
@@ -51,7 +54,7 @@ module PDF
|
|
51
54
|
Contents: content
|
52
55
|
)
|
53
56
|
|
54
|
-
resources[:ProcSet] = [
|
57
|
+
resources[:ProcSet] = %i[PDF Text ImageB ImageC ImageI]
|
55
58
|
end
|
56
59
|
|
57
60
|
def graphic_state
|
@@ -78,20 +81,18 @@ module PDF
|
|
78
81
|
end
|
79
82
|
|
80
83
|
def stamp_stream(dictionary)
|
81
|
-
@stamp_stream = ''
|
82
84
|
@stamp_dictionary = dictionary
|
85
|
+
@stamp_stream = @stamp_dictionary.stream
|
83
86
|
graphic_stack_size = stack.stack.size
|
84
87
|
|
85
88
|
document.save_graphics_state
|
86
|
-
document.
|
89
|
+
document.__send__(:freeze_stamp_graphics)
|
87
90
|
yield if block_given?
|
88
91
|
|
89
92
|
until graphic_stack_size == stack.stack.size
|
90
93
|
document.restore_graphics_state
|
91
94
|
end
|
92
95
|
|
93
|
-
@stamp_dictionary << @stamp_stream
|
94
|
-
|
95
96
|
@stamp_stream = nil
|
96
97
|
@stamp_dictionary = nil
|
97
98
|
end
|
data/lib/pdf/core/pdf_object.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# pdf_object.rb : Handles Ruby to PDF object serialization
|
2
4
|
#
|
3
5
|
# Copyright April 2008, Gregory Brown. All Rights Reserved.
|
@@ -11,7 +13,7 @@ module PDF
|
|
11
13
|
module_function
|
12
14
|
|
13
15
|
def real(num)
|
14
|
-
num.
|
16
|
+
format('%<number>.5f', number: num).sub(/((?<!\.)0)+\z/, '')
|
15
17
|
end
|
16
18
|
|
17
19
|
def real_params(array)
|
@@ -19,7 +21,7 @@ module PDF
|
|
19
21
|
end
|
20
22
|
|
21
23
|
def utf8_to_utf16(str)
|
22
|
-
"\xFE\xFF".force_encoding(::Encoding::UTF_16BE) +
|
24
|
+
(+"\xFE\xFF").force_encoding(::Encoding::UTF_16BE) +
|
23
25
|
str.encode(::Encoding::UTF_16BE)
|
24
26
|
end
|
25
27
|
|
@@ -27,9 +29,11 @@ module PDF
|
|
27
29
|
# with only 0-9 and a-f characters. That result is valid ASCII so tag
|
28
30
|
# it as such to account for behaviour of different ruby VMs
|
29
31
|
def string_to_hex(str)
|
30
|
-
str.
|
32
|
+
str.unpack1('H*').force_encoding(::Encoding::US_ASCII)
|
31
33
|
end
|
32
34
|
|
35
|
+
ESCAPED_NAME_CHARACTERS = (1..32).to_a + [35, 40, 41, 47, 60, 62] + (127..255).to_a
|
36
|
+
|
33
37
|
# Serializes Ruby objects to their PDF equivalents. Most primitive objects
|
34
38
|
# will work as expected, but please note that Name objects are represented
|
35
39
|
# by Ruby Symbol objects and Dictionary objects are represented by Ruby
|
@@ -54,31 +58,36 @@ module PDF
|
|
54
58
|
|
55
59
|
# NOTE: this can fail on huge floating point numbers, but it seems
|
56
60
|
# unlikely to ever happen in practice.
|
57
|
-
String(obj)
|
61
|
+
num_string = String(obj)
|
62
|
+
|
63
|
+
# Truncate trailing fraction zeroes
|
64
|
+
num_string.sub(/(\d*)((\.0*$)|(\.0*[1-9]*)0*$)/, '\1\4')
|
58
65
|
when Array
|
59
|
-
|
66
|
+
"[#{obj.map { |e| pdf_object(e, in_content_stream) }.join(' ')}]"
|
60
67
|
when PDF::Core::LiteralString
|
61
|
-
obj = obj.gsub(/[\\\n\r\t\b\f
|
68
|
+
obj = obj.gsub(/[\\\n\r\t\b\f()]/) { |m| "\\#{m}" }
|
62
69
|
"(#{obj})"
|
63
70
|
when Time
|
64
|
-
obj = obj.strftime('D:%Y%m%d%H%M%S%z').chop.chop
|
65
|
-
obj = obj.gsub(/[\\\n\r\t\b\f
|
71
|
+
obj = "#{obj.strftime('D:%Y%m%d%H%M%S%z').chop.chop}'00'"
|
72
|
+
obj = obj.gsub(/[\\\n\r\t\b\f()]/) { |m| "\\#{m}" }
|
66
73
|
"(#{obj})"
|
67
74
|
when PDF::Core::ByteString
|
68
|
-
|
75
|
+
"<#{obj.unpack1('H*')}>"
|
69
76
|
when String
|
70
77
|
obj = utf8_to_utf16(obj) unless in_content_stream
|
71
|
-
|
78
|
+
"<#{string_to_hex(obj)}>"
|
72
79
|
when Symbol
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
+
name_string =
|
81
|
+
obj.to_s.unpack('C*').map do |n|
|
82
|
+
if ESCAPED_NAME_CHARACTERS.include?(n)
|
83
|
+
"##{n.to_s(16).upcase}"
|
84
|
+
else
|
85
|
+
[n].pack('C*')
|
86
|
+
end
|
87
|
+
end.join
|
88
|
+
"/#{name_string}"
|
80
89
|
when ::Hash
|
81
|
-
output = '<< '
|
90
|
+
output = +'<< '
|
82
91
|
obj.each do |k, v|
|
83
92
|
unless k.is_a?(String) || k.is_a?(Symbol)
|
84
93
|
raise PDF::Core::Errors::FailedObjectConversion,
|
@@ -93,7 +102,7 @@ module PDF
|
|
93
102
|
when PDF::Core::NameTree::Node
|
94
103
|
pdf_object(obj.to_hash)
|
95
104
|
when PDF::Core::NameTree::Value
|
96
|
-
pdf_object(obj.name)
|
105
|
+
"#{pdf_object(obj.name)} #{pdf_object(obj.value)}"
|
97
106
|
when PDF::Core::OutlineRoot, PDF::Core::OutlineItem
|
98
107
|
pdf_object(obj.to_hash)
|
99
108
|
else
|
data/lib/pdf/core/reference.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# reference.rb : Implementation of PDF indirect objects
|
2
4
|
#
|
3
5
|
# Copyright April 2008, Gregory Brown. All Rights Reserved.
|
@@ -11,6 +13,12 @@ module PDF
|
|
11
13
|
class Reference #:nodoc:
|
12
14
|
attr_accessor :gen, :data, :offset, :stream, :identifier
|
13
15
|
|
16
|
+
class CannotAttachStream < StandardError
|
17
|
+
def initialize(message = 'Cannot attach stream to a non-dictionary object')
|
18
|
+
super
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
14
22
|
def initialize(id, data)
|
15
23
|
@identifier = id
|
16
24
|
@gen = 0
|
@@ -19,7 +27,7 @@ module PDF
|
|
19
27
|
end
|
20
28
|
|
21
29
|
def object
|
22
|
-
output = "#{@identifier} #{gen} obj\n"
|
30
|
+
output = +"#{@identifier} #{gen} obj\n"
|
23
31
|
if @stream.empty?
|
24
32
|
output << PDF::Core.pdf_object(data) << "\n"
|
25
33
|
else
|
@@ -32,8 +40,9 @@ module PDF
|
|
32
40
|
|
33
41
|
def <<(io)
|
34
42
|
unless @data.is_a?(::Hash)
|
35
|
-
raise
|
43
|
+
raise CannotAttachStream
|
36
44
|
end
|
45
|
+
|
37
46
|
(@stream ||= Stream.new) << io
|
38
47
|
end
|
39
48
|
|
data/lib/pdf/core/renderer.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'stringio'
|
2
4
|
|
3
5
|
module PDF
|
@@ -129,9 +131,9 @@ module PDF
|
|
129
131
|
#
|
130
132
|
# See Prawn::Document#number_pages for a sample usage of this capability.
|
131
133
|
|
132
|
-
def go_to_page(
|
133
|
-
@page_number =
|
134
|
-
state.page = state.pages[
|
134
|
+
def go_to_page(page_number)
|
135
|
+
@page_number = page_number
|
136
|
+
state.page = state.pages[page_number - 1]
|
135
137
|
end
|
136
138
|
|
137
139
|
def finalize_all_page_contents
|
@@ -168,9 +170,7 @@ module PDF
|
|
168
170
|
if output.instance_of?(StringIO)
|
169
171
|
str = output.string
|
170
172
|
str.force_encoding(::Encoding::ASCII_8BIT)
|
171
|
-
|
172
|
-
else
|
173
|
-
return nil
|
173
|
+
str
|
174
174
|
end
|
175
175
|
end
|
176
176
|
|
@@ -208,7 +208,7 @@ module PDF
|
|
208
208
|
output << "0 #{state.store.size + 1}\n"
|
209
209
|
output << "0000000000 65535 f \n"
|
210
210
|
state.store.each do |ref|
|
211
|
-
output.printf('
|
211
|
+
output.printf('%<offset>010d', offset: ref.offset)
|
212
212
|
output << " 00000 n \n"
|
213
213
|
end
|
214
214
|
end
|
data/lib/pdf/core/stream.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# prawn/core/stream.rb : Implements Stream objects
|
2
4
|
#
|
3
5
|
# Copyright February 2013, Alexander Mankuta. All Rights Reserved.
|
@@ -16,7 +18,7 @@ module PDF
|
|
16
18
|
end
|
17
19
|
|
18
20
|
def <<(io)
|
19
|
-
(@stream ||= '') << io
|
21
|
+
(@stream ||= +'') << io
|
20
22
|
@filtered_stream = nil
|
21
23
|
self
|
22
24
|
end
|
@@ -88,8 +90,14 @@ module PDF
|
|
88
90
|
end
|
89
91
|
|
90
92
|
def inspect
|
91
|
-
|
92
|
-
|
93
|
+
format(
|
94
|
+
'#<%<class>s:0x%<object_id>014x '\
|
95
|
+
'@stream=%<stream>s, @filters=%<filters>s>',
|
96
|
+
class: self.class.name,
|
97
|
+
object_id: object_id,
|
98
|
+
stream: @stream.inspect,
|
99
|
+
filters: @filters.inspect
|
100
|
+
)
|
93
101
|
end
|
94
102
|
end
|
95
103
|
end
|
data/lib/pdf/core/text.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# prawn/core/text.rb : Implements low level text helpers for Prawn
|
2
4
|
#
|
3
5
|
# Copyright January 2010, Daniel Nelson. All Rights Reserved.
|
@@ -9,17 +11,24 @@ module PDF
|
|
9
11
|
module Text #:nodoc:
|
10
12
|
# These should be used as a base. Extensions may build on this list
|
11
13
|
#
|
12
|
-
VALID_OPTIONS = [
|
14
|
+
VALID_OPTIONS = %i[kerning size style].freeze
|
13
15
|
MODES = {
|
14
16
|
fill: 0,
|
15
17
|
stroke: 1,
|
16
18
|
fill_stroke: 2,
|
17
19
|
invisible: 3,
|
18
|
-
fill_clip: 4,
|
20
|
+
fill_clip: 4,
|
21
|
+
stroke_clip: 5,
|
19
22
|
fill_stroke_clip: 6,
|
20
23
|
clip: 7
|
21
24
|
}.freeze
|
22
25
|
|
26
|
+
class BadFontFamily < StandardError
|
27
|
+
def initialize(message = 'Bad font family')
|
28
|
+
super
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
23
32
|
attr_reader :skip_encoding
|
24
33
|
|
25
34
|
# Low level call to set the current font style and extract text options
|
@@ -27,7 +36,8 @@ module PDF
|
|
27
36
|
#
|
28
37
|
def process_text_options(options)
|
29
38
|
if options[:style]
|
30
|
-
raise
|
39
|
+
raise BadFontFamily unless font.family
|
40
|
+
|
31
41
|
font(font.family, style: options[:style])
|
32
42
|
end
|
33
43
|
|
@@ -45,6 +55,7 @@ module PDF
|
|
45
55
|
#
|
46
56
|
def default_kerning?
|
47
57
|
return true unless defined?(@default_kerning)
|
58
|
+
|
48
59
|
@default_kerning
|
49
60
|
end
|
50
61
|
|
@@ -180,6 +191,7 @@ module PDF
|
|
180
191
|
if mode.nil?
|
181
192
|
return defined?(@text_rendering_mode) && @text_rendering_mode || :fill
|
182
193
|
end
|
194
|
+
|
183
195
|
unless MODES.key?(mode)
|
184
196
|
raise ArgumentError,
|
185
197
|
"mode must be between one of #{MODES.keys.join(', ')} (#{mode})"
|
@@ -209,6 +221,7 @@ module PDF
|
|
209
221
|
if amount.nil?
|
210
222
|
return defined?(@character_spacing) && @character_spacing || 0
|
211
223
|
end
|
224
|
+
|
212
225
|
original_character_spacing = character_spacing
|
213
226
|
if original_character_spacing == amount
|
214
227
|
yield
|
@@ -227,6 +240,7 @@ module PDF
|
|
227
240
|
#
|
228
241
|
def word_spacing(amount = nil)
|
229
242
|
return defined?(@word_spacing) && @word_spacing || 0 if amount.nil?
|
243
|
+
|
230
244
|
original_word_spacing = word_spacing
|
231
245
|
if original_word_spacing == amount
|
232
246
|
yield
|
@@ -244,8 +258,7 @@ module PDF
|
|
244
258
|
# percentage of the normal width.
|
245
259
|
def horizontal_text_scaling(amount = nil)
|
246
260
|
if amount.nil?
|
247
|
-
return defined?(@horizontal_text_scaling) &&
|
248
|
-
@horizontal_text_scaling || 100
|
261
|
+
return defined?(@horizontal_text_scaling) && @horizontal_text_scaling || 100
|
249
262
|
end
|
250
263
|
|
251
264
|
original_horizontal_text_scaling = horizontal_text_scaling
|
@@ -281,10 +294,14 @@ module PDF
|
|
281
294
|
|
282
295
|
chunks.each do |(subset, string)|
|
283
296
|
font.add_to_current_page(subset)
|
284
|
-
add_content
|
297
|
+
add_content [
|
298
|
+
PDF::Core.pdf_object(font.identifier_for(subset), true),
|
299
|
+
PDF::Core.pdf_object(font_size, true),
|
300
|
+
'Tf'
|
301
|
+
].join(' ')
|
285
302
|
|
286
303
|
operation = options[:kerning] && string.is_a?(Array) ? 'TJ' : 'Tj'
|
287
|
-
add_content PDF::Core.pdf_object(string, true)
|
304
|
+
add_content "#{PDF::Core.pdf_object(string, true)} #{operation}"
|
288
305
|
end
|
289
306
|
|
290
307
|
add_content "ET\n"
|
data/lib/pdf/core/utils.rb
CHANGED
@@ -1,12 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module PDF
|
2
4
|
module Core
|
3
5
|
module Utils
|
4
|
-
|
6
|
+
module_function
|
7
|
+
|
5
8
|
def deep_clone(object)
|
6
9
|
Marshal.load(Marshal.dump(object))
|
7
10
|
end
|
8
|
-
# rubocop: enable Security/MarshalLoad
|
9
|
-
module_function :deep_clone
|
10
11
|
end
|
11
12
|
end
|
12
13
|
end
|
data/lib/pdf/core.rb
CHANGED
data/pdf-core.gemspec
CHANGED
@@ -1,19 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
Gem::Specification.new do |spec|
|
2
4
|
spec.name = 'pdf-core'
|
3
|
-
spec.version = '0.
|
5
|
+
spec.version = '0.9.0'
|
4
6
|
spec.platform = Gem::Platform::RUBY
|
5
7
|
spec.summary = 'PDF::Core is used by Prawn to render PDF documents'
|
6
|
-
spec.files =
|
7
|
-
|
8
|
-
|
9
|
-
|
8
|
+
spec.files =
|
9
|
+
Dir.glob('lib/**/**/*') +
|
10
|
+
%w[COPYING GPLv2 GPLv3 LICENSE] +
|
11
|
+
%w[Gemfile Rakefile] +
|
12
|
+
['pdf-core.gemspec']
|
10
13
|
spec.require_path = 'lib'
|
11
|
-
spec.required_ruby_version = '>=
|
14
|
+
spec.required_ruby_version = '>= 2.5'
|
12
15
|
spec.required_rubygems_version = '>= 1.3.6'
|
13
16
|
|
14
17
|
spec.cert_chain = ['certs/pointlessone.pem']
|
15
18
|
if $PROGRAM_NAME.end_with? 'gem'
|
16
|
-
spec.signing_key = File.expand_path('~/.
|
19
|
+
spec.signing_key = File.expand_path('~/.gem/gem-private_key.pem')
|
17
20
|
end
|
18
21
|
|
19
22
|
# spec.extra_rdoc_files = %w{README.md LICENSE COPYING GPLv2 GPLv3}
|
@@ -27,16 +30,15 @@ Gem::Specification.new do |spec|
|
|
27
30
|
'gregory.t.brown@gmail.com', 'brad@bradediger.com', 'dnelson@bluejade.com',
|
28
31
|
'greenberg@entryway.net', 'jimmy@deefa.com'
|
29
32
|
]
|
30
|
-
spec.rubyforge_project = 'prawn'
|
31
33
|
spec.licenses = %w[PRAWN GPL-2.0 GPL-3.0]
|
32
|
-
spec.add_development_dependency('bundler')
|
33
|
-
spec.add_development_dependency('pdf-reader', '~>1.2')
|
34
34
|
spec.add_development_dependency('pdf-inspector', '~> 1.1.0')
|
35
|
+
spec.add_development_dependency('pdf-reader', '~>1.2')
|
35
36
|
spec.add_development_dependency('rake')
|
36
37
|
spec.add_development_dependency('rspec')
|
37
|
-
spec.add_development_dependency('rubocop', '~> 0.
|
38
|
-
spec.add_development_dependency('rubocop-
|
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')
|
39
41
|
spec.add_development_dependency('simplecov')
|
40
|
-
spec.homepage = 'http://
|
42
|
+
spec.homepage = 'http://prawnpdf.org'
|
41
43
|
spec.description = 'PDF::Core is used by Prawn to render PDF documents'
|
42
44
|
end
|
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pdf-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gregory Brown
|
@@ -14,42 +14,41 @@ bindir: bin
|
|
14
14
|
cert_chain:
|
15
15
|
- |
|
16
16
|
-----BEGIN CERTIFICATE-----
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
5u3JK+T0toNEYkMuV6W8NU+gVyo=
|
17
|
+
MIIDODCCAiCgAwIBAgIBATANBgkqhkiG9w0BAQsFADAjMSEwHwYDVQQDDBhhbGV4
|
18
|
+
L0RDPXBvaW50bGVzcy9EQz1vbmUwHhcNMjAwODAxMTQxMjE1WhcNMjEwODAxMTQx
|
19
|
+
MjE1WjAjMSEwHwYDVQQDDBhhbGV4L0RDPXBvaW50bGVzcy9EQz1vbmUwggEiMA0G
|
20
|
+
CSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDPOVLPGEK+eaP6zJfifrpWvPTg4qo3
|
21
|
+
XNJJPom80SwqX2hVCVsRDK4RYgKUQqKRQzHhlx14wZHwWLETBVbNDGX3uqyCnTWU
|
22
|
+
JUKh3ydiZShXpNHoV/NW7hhEYvNsDcBAjYTmbvXOhuYCo0Tz/0N2Oiun/0wIICtP
|
23
|
+
vytY9TY0/lklWjAbsqJjNOu3o8IYkJBAN/rU96E/6WhFwjnxLcTnV9RfFRXdjG5j
|
24
|
+
CughoB2xSwKX8gwbQ8fsnaZRmdyDGYNpz6sGF0zycfiLkTttbLA2nYATCALy98CH
|
25
|
+
nsyZNsTjb4WINCuY2yEDjwesw9f/ROkNC68EgQ5M+aMjp+D0WcYGfzojAgMBAAGj
|
26
|
+
dzB1MAkGA1UdEwQCMAAwCwYDVR0PBAQDAgSwMB0GA1UdDgQWBBRPgIwSVbeonua/
|
27
|
+
Ny/8576oxdUbrjAdBgNVHREEFjAUgRJhbGV4QHBvaW50bGVzcy5vbmUwHQYDVR0S
|
28
|
+
BBYwFIESYWxleEBwb2ludGxlc3Mub25lMA0GCSqGSIb3DQEBCwUAA4IBAQAzhGxF
|
29
|
+
M0bXJ9GWD9vdVHOyzBQBJcJAvnsz2yV3+r4eJBsQynFIscsea8lHFL/d1eHYP0mN
|
30
|
+
k0fhK+WDcPlrj0Sn/Ezhk2qogTIekwDOK6pZkGRQzD45leJqQMnYd+/TXK3ri485
|
31
|
+
Gi4oJ6NitnnUT59SQnjD5JcENfc0EcRzclmVRFE8W4O+ORgo4Dypq1rwYUzxeyUk
|
32
|
+
mP5jNBWtH+hGUph28GQb0Hph6YnQb8zEFB88Xq80PK1SzkIPHpbTBk9mwPf6ypeX
|
33
|
+
Un1TJEahAlgENVml6CyDXSwk0H8N1V3gm1mb9Fe1T2Z/kAzvjo0qTDEtMVLU7Bxh
|
34
|
+
uqMUrdETjTnRYCVq
|
36
35
|
-----END CERTIFICATE-----
|
37
|
-
date:
|
36
|
+
date: 2020-10-24 00:00:00.000000000 Z
|
38
37
|
dependencies:
|
39
38
|
- !ruby/object:Gem::Dependency
|
40
|
-
name:
|
39
|
+
name: pdf-inspector
|
41
40
|
requirement: !ruby/object:Gem::Requirement
|
42
41
|
requirements:
|
43
|
-
- - "
|
42
|
+
- - "~>"
|
44
43
|
- !ruby/object:Gem::Version
|
45
|
-
version:
|
44
|
+
version: 1.1.0
|
46
45
|
type: :development
|
47
46
|
prerelease: false
|
48
47
|
version_requirements: !ruby/object:Gem::Requirement
|
49
48
|
requirements:
|
50
|
-
- - "
|
49
|
+
- - "~>"
|
51
50
|
- !ruby/object:Gem::Version
|
52
|
-
version:
|
51
|
+
version: 1.1.0
|
53
52
|
- !ruby/object:Gem::Dependency
|
54
53
|
name: pdf-reader
|
55
54
|
requirement: !ruby/object:Gem::Requirement
|
@@ -65,21 +64,21 @@ dependencies:
|
|
65
64
|
- !ruby/object:Gem::Version
|
66
65
|
version: '1.2'
|
67
66
|
- !ruby/object:Gem::Dependency
|
68
|
-
name:
|
67
|
+
name: rake
|
69
68
|
requirement: !ruby/object:Gem::Requirement
|
70
69
|
requirements:
|
71
|
-
- - "
|
70
|
+
- - ">="
|
72
71
|
- !ruby/object:Gem::Version
|
73
|
-
version:
|
72
|
+
version: '0'
|
74
73
|
type: :development
|
75
74
|
prerelease: false
|
76
75
|
version_requirements: !ruby/object:Gem::Requirement
|
77
76
|
requirements:
|
78
|
-
- - "
|
77
|
+
- - ">="
|
79
78
|
- !ruby/object:Gem::Version
|
80
|
-
version:
|
79
|
+
version: '0'
|
81
80
|
- !ruby/object:Gem::Dependency
|
82
|
-
name:
|
81
|
+
name: rspec
|
83
82
|
requirement: !ruby/object:Gem::Requirement
|
84
83
|
requirements:
|
85
84
|
- - ">="
|
@@ -93,47 +92,47 @@ dependencies:
|
|
93
92
|
- !ruby/object:Gem::Version
|
94
93
|
version: '0'
|
95
94
|
- !ruby/object:Gem::Dependency
|
96
|
-
name:
|
95
|
+
name: rubocop
|
97
96
|
requirement: !ruby/object:Gem::Requirement
|
98
97
|
requirements:
|
99
|
-
- - "
|
98
|
+
- - "~>"
|
100
99
|
- !ruby/object:Gem::Version
|
101
|
-
version: '0'
|
100
|
+
version: '0.93'
|
102
101
|
type: :development
|
103
102
|
prerelease: false
|
104
103
|
version_requirements: !ruby/object:Gem::Requirement
|
105
104
|
requirements:
|
106
|
-
- - "
|
105
|
+
- - "~>"
|
107
106
|
- !ruby/object:Gem::Version
|
108
|
-
version: '0'
|
107
|
+
version: '0.93'
|
109
108
|
- !ruby/object:Gem::Dependency
|
110
|
-
name: rubocop
|
109
|
+
name: rubocop-performance
|
111
110
|
requirement: !ruby/object:Gem::Requirement
|
112
111
|
requirements:
|
113
112
|
- - "~>"
|
114
113
|
- !ruby/object:Gem::Version
|
115
|
-
version: '
|
114
|
+
version: '1.8'
|
116
115
|
type: :development
|
117
116
|
prerelease: false
|
118
117
|
version_requirements: !ruby/object:Gem::Requirement
|
119
118
|
requirements:
|
120
119
|
- - "~>"
|
121
120
|
- !ruby/object:Gem::Version
|
122
|
-
version: '
|
121
|
+
version: '1.8'
|
123
122
|
- !ruby/object:Gem::Dependency
|
124
123
|
name: rubocop-rspec
|
125
124
|
requirement: !ruby/object:Gem::Requirement
|
126
125
|
requirements:
|
127
126
|
- - "~>"
|
128
127
|
- !ruby/object:Gem::Version
|
129
|
-
version: '1.
|
128
|
+
version: '1.44'
|
130
129
|
type: :development
|
131
130
|
prerelease: false
|
132
131
|
version_requirements: !ruby/object:Gem::Requirement
|
133
132
|
requirements:
|
134
133
|
- - "~>"
|
135
134
|
- !ruby/object:Gem::Version
|
136
|
-
version: '1.
|
135
|
+
version: '1.44'
|
137
136
|
- !ruby/object:Gem::Dependency
|
138
137
|
name: simplecov
|
139
138
|
requirement: !ruby/object:Gem::Requirement
|
@@ -187,7 +186,7 @@ files:
|
|
187
186
|
- lib/pdf/core/text.rb
|
188
187
|
- lib/pdf/core/utils.rb
|
189
188
|
- pdf-core.gemspec
|
190
|
-
homepage: http://
|
189
|
+
homepage: http://prawnpdf.org
|
191
190
|
licenses:
|
192
191
|
- PRAWN
|
193
192
|
- GPL-2.0
|
@@ -201,15 +200,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
201
200
|
requirements:
|
202
201
|
- - ">="
|
203
202
|
- !ruby/object:Gem::Version
|
204
|
-
version:
|
203
|
+
version: '2.5'
|
205
204
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
206
205
|
requirements:
|
207
206
|
- - ">="
|
208
207
|
- !ruby/object:Gem::Version
|
209
208
|
version: 1.3.6
|
210
209
|
requirements: []
|
211
|
-
|
212
|
-
rubygems_version: 2.6.10
|
210
|
+
rubygems_version: 3.0.3
|
213
211
|
signing_key:
|
214
212
|
specification_version: 4
|
215
213
|
summary: PDF::Core is used by Prawn to render PDF documents
|
metadata.gz.sig
CHANGED
Binary file
|