Class: Fontist::Import::Otf::FontFile

Inherits:
Object
  • Object
show all
Defined in:
lib/fontist/import/otf/font_file.rb

Constant Summary collapse

REQUIREMENTS =
{
  otfinfo: Otfinfo::OtfinfoRequirement.new,
}.freeze
STYLE_ATTRIBUTES =
i[family_name type preferred_family_name
preferred_type full_name post_script_name
version description copyright font
source_font].freeze
COLLECTION_ATTRIBUTES =
STYLE_ATTRIBUTES.reject do |a|
  i[font source_font].include?(a)
end

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, name_prefix: nil) ⇒ FontFile

Returns a new instance of FontFile.



24
25
26
27
28
29
# File 'lib/fontist/import/otf/font_file.rb', line 24

def initialize(path, name_prefix: nil)
  @path = path
  @name_prefix = name_prefix
  @info = read
  @extension = detect_extension
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



22
23
24
# File 'lib/fontist/import/otf/font_file.rb', line 22

def path
  @path
end

Instance Method Details



87
88
89
# File 'lib/fontist/import/otf/font_file.rb', line 87

def copyright
  info["Copyright"]
end

#descriptionObject



73
74
75
# File 'lib/fontist/import/otf/font_file.rb', line 73

def description
  info["Description"]
end

#family_nameObject



39
40
41
42
# File 'lib/fontist/import/otf/font_file.rb', line 39

def family_name
  name = info["Family"]
  @name_prefix ? "#{@name_prefix}#{name}" : name
end

#fontObject



77
78
79
80
81
# File 'lib/fontist/import/otf/font_file.rb', line 77

def font
  basename = File.basename(@path, ".*").chomp(".#{@extension}")

  "#{basename}.#{@extension}"
end

#full_nameObject



59
60
61
# File 'lib/fontist/import/otf/font_file.rb', line 59

def full_name
  info["Full name"]
end

#homepageObject



91
92
93
# File 'lib/fontist/import/otf/font_file.rb', line 91

def homepage
  info["Vendor URL"]
end

#license_urlObject



95
96
97
# File 'lib/fontist/import/otf/font_file.rb', line 95

def license_url
  info["License URL"]
end

#post_script_nameObject



63
64
65
# File 'lib/fontist/import/otf/font_file.rb', line 63

def post_script_name
  info["PostScript name"]
end

#preferred_family_nameObject



48
49
50
51
52
53
# File 'lib/fontist/import/otf/font_file.rb', line 48

def preferred_family_name
  name = info["Preferred family"]
  return unless name

  @name_prefix ? "#{@name_prefix}#{name}" : name
end

#preferred_typeObject



55
56
57
# File 'lib/fontist/import/otf/font_file.rb', line 55

def preferred_type
  info["Preferred subfamily"]
end

#source_fontObject



83
84
85
# File 'lib/fontist/import/otf/font_file.rb', line 83

def source_font
  File.basename(@path) unless font == File.basename(@path)
end

#to_collection_styleObject



35
36
37
# File 'lib/fontist/import/otf/font_file.rb', line 35

def to_collection_style
  COLLECTION_ATTRIBUTES.map { |name| [name, send(name)] }.to_h.compact
end

#to_styleObject



31
32
33
# File 'lib/fontist/import/otf/font_file.rb', line 31

def to_style
  STYLE_ATTRIBUTES.map { |name| [name, send(name)] }.to_h.compact
end

#typeObject



44
45
46
# File 'lib/fontist/import/otf/font_file.rb', line 44

def type
  info["Subfamily"]
end

#versionObject



67
68
69
70
71
# File 'lib/fontist/import/otf/font_file.rb', line 67

def version
  return unless info["Version"]

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