lib/fontist/import/otf/font_file.rb in fontist-1.6.0 vs lib/fontist/import/otf/font_file.rb in fontist-1.7.0
- old
+ new
@@ -1,25 +1,31 @@
require_relative "../otfinfo/otfinfo_requirement"
require_relative "../text_helper"
+require_relative "../files/font_detector"
module Fontist
module Import
module Otf
class FontFile
REQUIREMENTS = {
otfinfo: Otfinfo::OtfinfoRequirement.new,
}.freeze
STYLE_ATTRIBUTES = %i[family_name type full_name post_script_name
- version description copyright font].freeze
- COLLECTION_ATTRIBUTES = STYLE_ATTRIBUTES.reject { |a| a == :font }
+ version description copyright font
+ source_font].freeze
+ COLLECTION_ATTRIBUTES = STYLE_ATTRIBUTES.reject do |a|
+ %i[font source_font].include?(a)
+ end
+
attr_reader :path
def initialize(path)
@path = path
@info = read
+ @extension = detect_extension
end
def to_style
STYLE_ATTRIBUTES.map { |name| [name, send(name)] }.to_h.compact
end
@@ -53,13 +59,17 @@
def description
info["Description"]
end
def font
- File.basename(@path)
+ File.basename(@path, ".*") + "." + @extension
end
+ def source_font
+ File.basename(@path) unless font == File.basename(@path)
+ end
+
def copyright
info["Copyright"]
end
def homepage
@@ -82,9 +92,13 @@
.split("\n")
.select { |x| x.include?(":") }
.map { |x| x.split(":", 2) }
.map { |x| x.map { |y| Fontist::Import::TextHelper.cleanup(y) } }
.to_h
+ end
+
+ def detect_extension
+ Files::FontDetector.standard_extension(@path)
end
end
end
end
end