Sha256: 7982bc558458f2a1ea3c04eb291d916e8e3faa6230be9a285c35ba6d07ef365a

Contents?: true

Size: 907 Bytes

Versions: 33

Compression:

Stored size: 907 Bytes

Contents

# frozen_string_literal: true

class Prawn::Font::AFM
  include ::Asciidoctor::Logging

  FALLBACK_CHARS = {
    ?\u200b => '',
    ?\u202f => ?\u00a0,
    ?\u2009 => ' ',
    ?\u25e6 => '-',
    ?\u25aa => ?\u00b7,
  }

  remove_method :normalize_encoding

  # Patch normalize_encoding method to handle conversion more gracefully.
  #
  # Any valid utf-8 characters that cannot be encoded to windows-1252 are
  # replaced with the logic "not" symbol and a warning is issued identifying
  # the text that cannot be converted.
  def normalize_encoding text
    text.encode 'windows-1252', fallback: FALLBACK_CHARS
  rescue ::Encoding::UndefinedConversionError
    logger.warn %(The following text could not be fully converted to the Windows-1252 character set:
#{text.gsub(/^/, '| ').rstrip}) if logger.info? && !@document.scratch?
    text.encode 'windows-1252', undef: :replace, replace: ?\u00ac
  end
end

Version data entries

33 entries across 33 versions & 1 rubygems

Version Path
asciidoctor-pdf-2.3.9 lib/asciidoctor/pdf/ext/prawn/font/afm.rb
asciidoctor-pdf-2.3.8 lib/asciidoctor/pdf/ext/prawn/font/afm.rb
asciidoctor-pdf-2.3.7 lib/asciidoctor/pdf/ext/prawn/font/afm.rb
asciidoctor-pdf-2.3.6 lib/asciidoctor/pdf/ext/prawn/font/afm.rb
asciidoctor-pdf-2.3.5 lib/asciidoctor/pdf/ext/prawn/font/afm.rb
asciidoctor-pdf-2.3.4 lib/asciidoctor/pdf/ext/prawn/font/afm.rb
asciidoctor-pdf-2.3.3 lib/asciidoctor/pdf/ext/prawn/font/afm.rb
asciidoctor-pdf-2.3.2 lib/asciidoctor/pdf/ext/prawn/font/afm.rb
asciidoctor-pdf-2.3.1 lib/asciidoctor/pdf/ext/prawn/font/afm.rb
asciidoctor-pdf-2.3.0 lib/asciidoctor/pdf/ext/prawn/font/afm.rb
asciidoctor-pdf-2.2.0 lib/asciidoctor/pdf/ext/prawn/font/afm.rb
asciidoctor-pdf-2.1.6 lib/asciidoctor/pdf/ext/prawn/font/afm.rb
asciidoctor-pdf-2.1.5 lib/asciidoctor/pdf/ext/prawn/font/afm.rb
asciidoctor-pdf-2.1.4 lib/asciidoctor/pdf/ext/prawn/font/afm.rb
asciidoctor-pdf-2.1.3 lib/asciidoctor/pdf/ext/prawn/font/afm.rb
asciidoctor-pdf-2.1.2 lib/asciidoctor/pdf/ext/prawn/font/afm.rb
asciidoctor-pdf-2.1.1 lib/asciidoctor/pdf/ext/prawn/font/afm.rb
asciidoctor-pdf-2.1.0 lib/asciidoctor/pdf/ext/prawn/font/afm.rb
asciidoctor-pdf-2.0.8 lib/asciidoctor/pdf/ext/prawn/font/afm.rb
asciidoctor-pdf-2.0.7 lib/asciidoctor/pdf/ext/prawn/font/afm.rb