Sha256: 1c479d0f1ef8afc9694cb66112d3e4ddd9b8dbe5ac98ccb934c3300219958e09

Contents?: true

Size: 1.16 KB

Versions: 9

Compression:

Stored size: 1.16 KB

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
  rescue ::Encoding::InvalidByteSequenceError
    raise Prawn::Errors::IncompatibleStringEncoding,
        'Your document includes text which is not compatible with the Windows-1252 character set.
If you need full UTF-8 support, use TTF fonts instead of the built-in PDF (AFM) fonts.'
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
asciidoctor-pdf-1.6.2 lib/asciidoctor/pdf/ext/prawn/font/afm.rb
asciidoctor-pdf-1.6.1 lib/asciidoctor/pdf/ext/prawn/font/afm.rb
asciidoctor-pdf-1.6.0 lib/asciidoctor/pdf/ext/prawn/font/afm.rb
asciidoctor-pdf-1.5.4 lib/asciidoctor/pdf/ext/prawn/font/afm.rb
asciidoctor-pdf-1.5.3 lib/asciidoctor/pdf/ext/prawn/font/afm.rb
asciidoctor-pdf-1.5.2 lib/asciidoctor/pdf/ext/prawn/font/afm.rb
asciidoctor-pdf-1.5.1 lib/asciidoctor/pdf/ext/prawn/font/afm.rb
asciidoctor-pdf-1.5.0 lib/asciidoctor/pdf/ext/prawn/font/afm.rb
asciidoctor-pdf-1.5.0.rc.3 lib/asciidoctor/pdf/ext/prawn/font/afm.rb