Module: Cooltrainer::DistorteD::Text

Constant Summary collapse

LOWER_WORLD =
CHECKING::YOU::IN(/^text\/(plain|x-nfo)/)
OUTER_LIMITS =
CHECKING::YOU::IN(/^text\/(plain|x-nfo)/)
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
}
ATTRIBUTES =
ATTRIBUTES_VALUES =
{
  :spacing => Set[:monospace, :proportional],
  :font => self::FONT_FILENAME.keys.to_set,
}
ATTRIBUTES_DEFAULT =
{
  :crop => :none,
  :dpi => 144,
  :encoding => 'UTF-8'.freeze
}

Constants included from InjectionOfLove

InjectionOfLove::AFTERPARTY, InjectionOfLove::ATTRIBUTE_CONSTANTS, InjectionOfLove::DISTORTED_CONSTANTS, InjectionOfLove::Injection_Of_Love, InjectionOfLove::TYPE_CONSTANTS

Instance Method Summary collapse

Methods included from InjectionOfLove

#abstract, included, so_deep, trip_machine, #trip_machine

Methods included from Cooltrainer::DistorteD::Technology::Pango

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

Methods included from Cooltrainer::DistorteD::Technology::TTFunk

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

Instance Method Details

#codepageObject

Using a numeric key for things for simplicity. TODO: Replace this with Ruby’s built-in Encoding class after I have a better idea what I want to do.



110
111
112
113
114
115
116
117
# File 'lib/distorted/molecule/text.rb', line 110

def codepage
  case text_file_encoding
    when 'UTF-8'.freeze then 65001
    when 'Shift_JIS'.freeze then 932
    when 'IBM437'.freeze then 437
    else 1252
  end
end

#to_pangoObject

Return a Pango Markup escaped version of the document.



120
121
122
123
124
125
126
127
128
129
130
# File 'lib/distorted/molecule/text.rb', line 120

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