Class: Prawn::Font::AFM

Inherits:
Object show all
Includes:
Asciidoctor::Logging
Defined in:
lib/asciidoctor/pdf/ext/prawn/font/afm.rb

Constant Summary collapse

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

Instance Method Summary collapse

Instance Method Details

#normalize_encoding(text) ⇒ Object

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.



21
22
23
24
25
26
27
# File 'lib/asciidoctor/pdf/ext/prawn/font/afm.rb', line 21

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