Module: Cooltrainer::DistorteD::Molecule::Text

Includes:
Technology::Pango, Technology::TTFunk, Technology::Vips::Save
Defined in:
lib/distorted/media_molecule/text.rb

Constant Summary collapse

FONT_FILENAME =

Track supported fonts by codepage. Avoid renaming these from the original archives / websites. Try not to go nuts here bloating the size of our Gem for a very niche feature, but I want to ensure good coverage too.

Treat codepage 8859 documents as codepage 1252 to avoid breaking smart- quotes and other printable chars in 1252 that are control chars in 8859. encoding.spec.whatwg.org/#names-and-labels

Numeric key for UTF-8 is codepage 65001 like Win32: docs.microsoft.com/en-us/windows/win32/intl/code-page-identifiers

{
  :anonpro => 'Anonymous Pro.ttf'.freeze,
  :anonpro_b => 'Anonymous Pro B.ttf'.freeze,
  :anonpro_bi => 'Anonymous Pro BI.ttf'.freeze,
  :anonpro_i => 'Anonymous Pro I.ttf'.freeze,
  :lessperfectdosvga => 'LessPerfectDOSVGA.ttf'.freeze,
  :moreperfectdisvga => 'MorePerfectDOSVGA.ttf'.freeze,
  :perfectdosvgawin => 'Perfect DOS VGA 437 Win.ttf'.freeze,
  :mona => 'mona.ttf'.freeze,
  :perfectdosvga => 'Perfect DOS VGA 437.ttf'.freeze,
  :profont => 'ProFontWindows.ttf'.freeze,
  :profont_b => 'ProFontWindows-Bold.ttf'.freeze,
}
CODEPAGE_FONT =

Certain fonts are more suitable for certain codepages, so track each codepage’s available fonts…

{
  65001 => [
    :anonpro,
    :anonpro_b,
    :anonpro_bi,
    :anonpro_i,
  ],
  1252 => [
    :lessperfectdosvga,
    :moreperfectdosvga,
    :perfectdosvgawin,
  ],
  932 => [
    :mona,
  ],
  850 => [
    :profont,
    :profont_b,
  ],
  437 => [
    :perfectdosvga,
  ],
}
FONT_CODEPAGE =

…as well as the inverse, the numeric codepage for each font:

self::CODEPAGE_FONT.reduce(Hash.new([])) { |memo, (key, values)|
  values.each { |value| memo[value] = key }
  memo
}
LOWER_WORLD =
CHECKING::YOU::IN(/^text\/(plain|x-nfo)/).to_hash.transform_values { |v| Hash[
  :encoding => Cooltrainer::Compound.new(:encoding, blurb: 'Character encoding used in this document.', default: 'UTF-8'.freeze),
]}
OUTER_LIMITS =
CHECKING::YOU::IN(/^text\/(plain|x-nfo)/).to_hash.merge(
  Cooltrainer::DistorteD::Technology::Vips::Save::OUTER_LIMITS.dup.transform_values{ |v| Hash[
    :spacing => Cooltrainer::Compound.new(:spacing, blurb: 'Document-wide character spacing style.', valid: Set[:monospace, :proportional]),
    :dpi => Cooltrainer::Compound.new(:dpi, blurb: 'Dots per inch for text rendering.', valid: Integer, default: 144),
    :font => Cooltrainer::Compound.new(:font, blurb: 'Font to use for text rendering.', valid: self::FONT_FILENAME.keys.to_set),
  ]}
)

Constants included from Technology::Vips::Save

Technology::Vips::Save::VIPS_SAVERS

Instance Method Summary collapse

Methods included from Technology::Pango

#cr, #crlf, #g_markup_escape_char, #g_markup_escape_text, #lf, #overlong_null

Methods included from Technology::TTFunk

#font_copyright, #font_description, #font_name, #font_spacing, #font_version, #to_ttfunk

Instance Method Details

#to_pangoObject

Return a Pango Markup escaped version of the document.



100
101
102
103
104
105
106
107
108
109
110
# File 'lib/distorted/media_molecule/text.rb', line 100

def to_pango
  # https://developer.gnome.org/glib/stable/glib-Simple-XML-Subset-Parser.html#g-markup-escape-text
  escaped = text_file_utf8_content.map{ |c|
    g_markup_escape_char(c)
  }
  if font_spacing == :monospace
    "<tt>" << escaped << "</tt>"
  else
    escaped
  end
end