Sha256: 84b5e43b3c407cfc0d092b3443d5fe522ee0ba9a47c03745f4982a66ea5fe169

Contents?: true

Size: 931 Bytes

Versions: 10

Compression:

Stored size: 931 Bytes

Contents

# frozen_string_literal: true

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

  FALLBACK_CHARS = {
    ?\u200b => '',
    ?\u202f => ?\u00a0,
    ?\u2009 => ' ',
    ?\u2063 => ?\u00ad,
    ?\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

10 entries across 10 versions & 1 rubygems

Version Path
asciidoctor-pdf-2.3.19 lib/asciidoctor/pdf/ext/prawn/font/afm.rb
asciidoctor-pdf-2.3.18 lib/asciidoctor/pdf/ext/prawn/font/afm.rb
asciidoctor-pdf-2.3.17 lib/asciidoctor/pdf/ext/prawn/font/afm.rb
asciidoctor-pdf-2.3.16 lib/asciidoctor/pdf/ext/prawn/font/afm.rb
asciidoctor-pdf-2.3.15 lib/asciidoctor/pdf/ext/prawn/font/afm.rb
asciidoctor-pdf-2.3.14 lib/asciidoctor/pdf/ext/prawn/font/afm.rb
asciidoctor-pdf-2.3.13 lib/asciidoctor/pdf/ext/prawn/font/afm.rb
asciidoctor-pdf-2.3.12 lib/asciidoctor/pdf/ext/prawn/font/afm.rb
asciidoctor-pdf-2.3.11 lib/asciidoctor/pdf/ext/prawn/font/afm.rb
asciidoctor-pdf-2.3.10 lib/asciidoctor/pdf/ext/prawn/font/afm.rb