Sha256: f1d0074d7cf08c84fc8018180c2506e0e044d54a172fc23acc1bbe889ea317d4
Contents?: true
Size: 1.35 KB
Versions: 10
Compression:
Stored size: 1.35 KB
Contents
require "extract_ttc" require "fontist/import/helpers/system_helper" require_relative "../otf/font_file" module Fontist module Import module Files class CollectionFile attr_reader :fonts def initialize(path) @path = path @fonts = read @extension = detect_extension end def filename File.basename(@path, ".*") + "." + @extension end def source_filename File.basename(@path) unless filename == File.basename(@path) end private def read switch_to_temp_dir do |tmp_dir| extract_ttfs(tmp_dir).map do |path| Otf::FontFile.new(path) end end end def switch_to_temp_dir Dir.mktmpdir do |tmp_dir| Dir.chdir(tmp_dir) do yield tmp_dir end end end def extract_ttfs(tmp_dir) filenames = ExtractTtc.extract(@path) filenames.map do |filename| File.join(tmp_dir, filename) end end def detect_extension base_extension = "ttc" file_extension = File.extname(File.basename(@path)).sub(/^\./, "") return file_extension if file_extension.casecmp?(base_extension) base_extension end end end end end
Version data entries
10 entries across 10 versions & 1 rubygems