Sha256: 641b62c245720ed240461fc19d6d4709cc0dc185556a323293ee4a683d2198d6

Contents?: true

Size: 740 Bytes

Versions: 6

Compression:

Stored size: 740 Bytes

Contents

# frozen_string_literal: true
class String
  def pred
    begin
      # integers
      %(#{(Integer self) - 1})
    rescue ::ArgumentError
      # chars (upper alpha, lower alpha, lower greek)
      ([65, 97, 945].include? ord) ? '0' : ([ord - 1].pack 'U1')
    end
  end unless method_defined? :pred

  # If the string is ASCII only, convert it to a PDF LiteralString object. Otherwise, return self.
  def as_pdf
    if ascii_only?
      ::PDF::Core::LiteralString.new(encode ::Encoding::ASCII_8BIT)
    else
      self
    end
  end

  # Convert the string to a serialized PDF object. If the string can be encoded as ASCII-8BIT, first convert it to a PDF
  # LiteralString object.
  def to_pdf
    ::PDF::Core.pdf_object as_pdf
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
asciidoctor-pdf-1.5.0.beta.7 lib/asciidoctor/pdf/ext/core/string.rb
asciidoctor-pdf-1.5.0.beta.6 lib/asciidoctor/pdf/ext/core/string.rb
asciidoctor-pdf-1.5.0.beta.5 lib/asciidoctor-pdf/core_ext/string.rb
asciidoctor-pdf-1.5.0.beta.4 lib/asciidoctor-pdf/core_ext/string.rb
asciidoctor-pdf-1.5.0.beta.3 lib/asciidoctor-pdf/core_ext/string.rb
asciidoctor-pdf-1.5.0.beta.2 lib/asciidoctor-pdf/core_ext/string.rb