Sha256: 640e9799002fc84ea83a818cc063f488892078b4140d412e0d0761b3629ab09a

Contents?: true

Size: 1.89 KB

Versions: 2

Compression:

Stored size: 1.89 KB

Contents

require_relative "../otfinfo/otfinfo_requirement"
require_relative "../text_helper"

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 }

        attr_reader :path

        def initialize(path)
          @path = path
          @info = read
        end

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

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

        def family_name
          info["Preferred family"] || info["Family"]
        end

        def type
          info["Preferred subfamily"] || info["Subfamily"]
        end

        def full_name
          info["Full name"]
        end

        def post_script_name
          info["PostScript name"]
        end

        def version
          return unless info["Version"]

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

        def description
          info["Description"]
        end

        def font
          File.basename(@path)
        end

        def copyright
          info["Copyright"]
        end

        def homepage
          info["Vendor URL"]
        end

        def license_url
          info["License URL"]
        end

        private

        attr_reader :info

        def read
          text = REQUIREMENTS[:otfinfo].call(@path)

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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
fontist-1.5.0 lib/fontist/import/otf/font_file.rb
fontist-1.4.0 lib/fontist/import/otf/font_file.rb