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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: b927f3fa2dd24b6cdb4985d8b0d72f6b753cc3d1
4
- data.tar.gz: 51de8ad704088ef8738768969444443379b57bcc
2
+ SHA256:
3
+ metadata.gz: 429f3bfae75301dabdb339edccbdd816026f605dc84d1902f07d6494277d6360
4
+ data.tar.gz: 13fa187ef7307bc6de531a06d9d97272ff2ba0c2a9e21744b52efe1c387094d5
5
5
  SHA512:
6
- metadata.gz: 589610d88baa8f03bbe3b4532cef5d780e0264d021933622d816c7b87b34ae8df06b5cd4e4276a2b159bcf6bbb1ae2ff0710d2cbe8cf37e44ce4c12ab7e04007
7
- data.tar.gz: 525447dd1ed202a7880bbac27a7acc4cda730eae17b726c5ef2b3c46ec777dbdd8d794db8e36207d6a764b6e45caf007e628e76b139fc93d1f5c2ec8cb0f181d
6
+ metadata.gz: 76f74e81e59e382b4ab8c0bfe0cd58eb6b8624afd4b6b92fee6ed56da432205ad682cd3bd99b364d29be38747727a198f796975cb7718c7f62ad682f33f4953f
7
+ data.tar.gz: b0b08cdd020ba23a4b3aa135d795eb35089cf0c6fbe34dd5457a3302f78969062347952b2f0f532b9066578a81537059afed889edd7d102817f26439b7f0848e
checksums.yaml.gz.sig CHANGED
Binary file
data/Gemfile CHANGED
@@ -1,3 +1,5 @@
1
- source "https://rubygems.org"
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
2
4
 
3
5
  gemspec
data/Rakefile CHANGED
@@ -1,10 +1,9 @@
1
- require 'bundler'
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: [:spec, :rubocop]
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
@@ -1,4 +1,4 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  # annotations.rb : Implements low-level annotation support for PDF
4
4
  #
@@ -1,4 +1,5 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
+
2
3
  module PDF
3
4
  module Core
4
5
  # This is used to differentiate strings that must be encoded as
@@ -1,4 +1,4 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  # Implements destination support for PDF
4
4
  #
@@ -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
- :encrypt, :encryption_key, :skip_encoding,
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 = count.map do |index|
38
- orig_dict_id = @store.object_id_for_page(index)
39
- PDF::Core::Page.new(document, object_id: orig_dict_id)
40
- end
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)
@@ -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 "Can not interpret input as filter: #{filter.inspect}"
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 do |filter|
46
- yield(filter)
47
- end
58
+ def each(&block)
59
+ @list.each(&block)
48
60
  end
49
61
  end
50
62
  end
@@ -1,4 +1,4 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  # prawn/core/filters.rb : Implements stream filters
4
4
  #
@@ -1,4 +1,5 @@
1
- # encoding: utf-8
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 = if @dash[:dash].is_a?(Array)
67
- @dash[:dash]
68
- else
69
- [@dash[:dash], @dash[:space]]
70
- end
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"
@@ -1,4 +1,5 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
+
2
3
  module PDF
3
4
  module Core
4
5
  # This is used to differentiate strings that must be encoded as
@@ -1,4 +1,4 @@
1
- # encoding: utf-8
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.map(&:size).reduce(:+)
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.detect { |child| child >= value }
82
- fit = children.last unless 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
- # encoding: utf-8
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(k)
95
- k -= 1 if k > 0
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[k]
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]
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module PDF
2
4
  module Core
3
5
  class OutlineRoot #:nodoc:
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 = options[:margins] || { left: 36,
27
- right: 36,
28
- top: 36,
29
- bottom: 36 }
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 = options[:size] || 'LETTER'
36
- @layout = options[:layout] || :portrait
38
+ @size = options[:size] || 'LETTER'
39
+ @layout = options[:layout] || :portrait
37
40
 
38
- @stamp_stream = nil
39
- @stamp_dictionary = nil
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] = [:PDF, :Text, :ImageB, :ImageC, :ImageI]
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.send(:freeze_stamp_graphics)
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
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Describes PDF page geometries
2
4
  #
3
5
  # Copyright April 2008, Gregory Brown. All Rights Reserved.
@@ -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.to_f.round(4)
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.unpack('H*').first.force_encoding(::Encoding::US_ASCII)
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
- '[' << obj.map { |e| pdf_object(e, in_content_stream) }.join(' ') << ']'
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\(\)]/) { |m| "\\#{m}" }
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 + "'00'"
65
- obj = obj.gsub(/[\\\n\r\t\b\f\(\)]/) { |m| "\\#{m}" }
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
- '<' << obj.unpack('H*').first << '>'
75
+ "<#{obj.unpack1('H*')}>"
69
76
  when String
70
77
  obj = utf8_to_utf16(obj) unless in_content_stream
71
- '<' << string_to_hex(obj) << '>'
78
+ "<#{string_to_hex(obj)}>"
72
79
  when Symbol
73
- '/' + obj.to_s.unpack('C*').map do |n|
74
- if n < 33 || n > 126 || [35, 40, 41, 47, 60, 62].include?(n)
75
- '#' + n.to_s(16).upcase
76
- else
77
- [n].pack('C*')
78
- end
79
- end.join
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) + ' ' + pdf_object(obj.value)
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
@@ -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 'Cannot attach stream to non-dictionary object'
43
+ raise CannotAttachStream
36
44
  end
45
+
37
46
  (@stream ||= Stream.new) << io
38
47
  end
39
48
 
@@ -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(k)
133
- @page_number = k
134
- state.page = state.pages[k - 1]
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
- return str
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('%010d', ref.offset)
211
+ output.printf('%<offset>010d', offset: ref.offset)
212
212
  output << " 00000 n \n"
213
213
  end
214
214
  end
@@ -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
- "#<#{self.class.name}:0x#{format '%014x', object_id} "\
92
- "@stream=#{@stream.inspect}, @filters=#{@filters.inspect}>"
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 = [:kerning, :size, :style].freeze
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, stroke_clip: 5,
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 'Bad font family' unless font.family
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 "/#{font.identifier_for(subset)} #{font_size} Tf"
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) << ' ' << operation
304
+ add_content "#{PDF::Core.pdf_object(string, true)} #{operation}"
288
305
  end
289
306
 
290
307
  add_content "ET\n"
@@ -1,12 +1,13 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module PDF
2
4
  module Core
3
5
  module Utils
4
- # rubocop: disable Security/MarshalLoad
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
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'core/pdf_object'
2
4
  require_relative 'core/annotations'
3
5
  require_relative 'core/byte_string'
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.7.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 = Dir.glob('lib/**/**/*') +
7
- %w[COPYING GPLv2 GPLv3 LICENSE] +
8
- %w[Gemfile Rakefile] +
9
- ['pdf-core.gemspec']
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 = '>= 1.9.3'
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('~/.ssh/gem-private_key.pem')
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.46')
38
- spec.add_development_dependency('rubocop-rspec', '~> 1.9')
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://prawn.majesticseacreature.com'
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.7.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
- MIIDcDCCAligAwIBAgIBATANBgkqhkiG9w0BAQUFADA/MQ0wCwYDVQQDDARhbGV4
18
- MRkwFwYKCZImiZPyLGQBGRYJcG9pbnRsZXNzMRMwEQYKCZImiZPyLGQBGRYDb25l
19
- MB4XDTE3MDEwNDExNDAzM1oXDTE4MDEwNDExNDAzM1owPzENMAsGA1UEAwwEYWxl
20
- eDEZMBcGCgmSJomT8ixkARkWCXBvaW50bGVzczETMBEGCgmSJomT8ixkARkWA29u
21
- ZTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAM85Us8YQr55o/rM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END CERTIFICATE-----
37
- date: 2017-03-11 00:00:00.000000000 Z
36
+ date: 2020-10-24 00:00:00.000000000 Z
38
37
  dependencies:
39
38
  - !ruby/object:Gem::Dependency
40
- name: bundler
39
+ name: pdf-inspector
41
40
  requirement: !ruby/object:Gem::Requirement
42
41
  requirements:
43
- - - ">="
42
+ - - "~>"
44
43
  - !ruby/object:Gem::Version
45
- version: '0'
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: '0'
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: pdf-inspector
67
+ name: rake
69
68
  requirement: !ruby/object:Gem::Requirement
70
69
  requirements:
71
- - - "~>"
70
+ - - ">="
72
71
  - !ruby/object:Gem::Version
73
- version: 1.1.0
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: 1.1.0
79
+ version: '0'
81
80
  - !ruby/object:Gem::Dependency
82
- name: rake
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: rspec
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: '0.46'
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: '0.46'
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.9'
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.9'
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://prawn.majesticseacreature.com
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: 1.9.3
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
- rubyforge_project: prawn
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