class Fontist::Import::Otf::FontFile

Constants

COLLECTION_ATTRIBUTES
REQUIREMENTS
STYLE_ATTRIBUTES

Attributes

info[R]
path[R]

Public Class Methods

new(path) click to toggle source
# File lib/fontist/import/otf/font_file.rb, line 24
def initialize(path)
  @path = path
  @info = read
  @extension = detect_extension
end

Public Instance Methods

description() click to toggle source
# File lib/fontist/import/otf/font_file.rb, line 68
def description
  info["Description"]
end
family_name() click to toggle source
# File lib/fontist/import/otf/font_file.rb, line 38
def family_name
  info["Family"]
end
font() click to toggle source
# File lib/fontist/import/otf/font_file.rb, line 72
def font
  File.basename(@path, ".*") + "." + @extension
end
full_name() click to toggle source
# File lib/fontist/import/otf/font_file.rb, line 54
def full_name
  info["Full name"]
end
homepage() click to toggle source
# File lib/fontist/import/otf/font_file.rb, line 84
def homepage
  info["Vendor URL"]
end
license_url() click to toggle source
# File lib/fontist/import/otf/font_file.rb, line 88
def license_url
  info["License URL"]
end
post_script_name() click to toggle source
# File lib/fontist/import/otf/font_file.rb, line 58
def post_script_name
  info["PostScript name"]
end
preferred_family_name() click to toggle source
# File lib/fontist/import/otf/font_file.rb, line 46
def preferred_family_name
  info["Preferred family"]
end
preferred_type() click to toggle source
# File lib/fontist/import/otf/font_file.rb, line 50
def preferred_type
  info["Preferred subfamily"]
end
source_font() click to toggle source
# File lib/fontist/import/otf/font_file.rb, line 76
def source_font
  File.basename(@path) unless font == File.basename(@path)
end
to_collection_style() click to toggle source
# File lib/fontist/import/otf/font_file.rb, line 34
def to_collection_style
  COLLECTION_ATTRIBUTES.map { |name| [name, send(name)] }.to_h.compact
end
to_style() click to toggle source
# File lib/fontist/import/otf/font_file.rb, line 30
def to_style
  STYLE_ATTRIBUTES.map { |name| [name, send(name)] }.to_h.compact
end
type() click to toggle source
# File lib/fontist/import/otf/font_file.rb, line 42
def type
  info["Subfamily"]
end
version() click to toggle source
# File lib/fontist/import/otf/font_file.rb, line 62
def version
  return unless info["Version"]

  info["Version"].gsub("Version ", "")
end

Private Instance Methods

detect_extension() click to toggle source
# File lib/fontist/import/otf/font_file.rb, line 108
def detect_extension
  detected = Files::FontDetector.standard_extension(@path)
  file_extension = File.extname(File.basename(@path)).sub(/^\./, "")
  return file_extension if file_extension.casecmp?(detected)

  detected
end
read() click to toggle source
# File lib/fontist/import/otf/font_file.rb, line 96
def read
  text = REQUIREMENTS[:otfinfo].call(@path)

  text
    .encode("UTF-8", invalid: :replace, replace: "")
    .split("\n")
    .select { |x| x.include?(":") }
    .map { |x| x.split(":", 2) }
    .map { |x| x.map { |y| Fontist::Import::TextHelper.cleanup(y) } }
    .to_h
end