Class: Fontist::Import::Otf::FontFile
- Inherits:
-
Object
- Object
- Fontist::Import::Otf::FontFile
- Defined in:
- lib/fontist/import/otf/font_file.rb
Constant Summary collapse
- 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
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #copyright ⇒ Object
- #description ⇒ Object
- #family_name ⇒ Object
-
#font ⇒ Object
rubocop:disable Layout/LineLength Use the exact filename from the archive - do NOT modify or standardize it rubocop:enable Layout/LineLength.
- #full_name ⇒ Object
- #homepage ⇒ Object
-
#initialize(path_or_metadata, name_prefix: nil, metadata: nil) ⇒ FontFile
constructor
A new instance of FontFile.
- #license_url ⇒ Object
- #post_script_name ⇒ Object
- #preferred_family_name ⇒ Object
- #preferred_type ⇒ Object
- #source_font ⇒ Object
- #to_collection_style ⇒ Object
- #to_style ⇒ Object
- #type ⇒ Object
- #version ⇒ Object
Constructor Details
#initialize(path_or_metadata, name_prefix: nil, metadata: nil) ⇒ FontFile
Returns a new instance of FontFile.
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/fontist/import/otf/font_file.rb', line 16 def initialize(, name_prefix: nil, metadata: nil) if # Use pre-built metadata (for collection fonts without tempfiles) @path = .to_s @metadata = else # Extract metadata from file path (backward compatibility) @path = @metadata = end @name_prefix = name_prefix end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
14 15 16 |
# File 'lib/fontist/import/otf/font_file.rb', line 14 def path @path end |
Instance Method Details
#copyright ⇒ Object
86 87 88 |
# File 'lib/fontist/import/otf/font_file.rb', line 86 def copyright @metadata.copyright end |
#description ⇒ Object
69 70 71 |
# File 'lib/fontist/import/otf/font_file.rb', line 69 def description @metadata.description end |
#family_name ⇒ Object
37 38 39 40 |
# File 'lib/fontist/import/otf/font_file.rb', line 37 def family_name name = @metadata.family_name || "Unknown" @name_prefix ? "#{@name_prefix}#{name}" : name end |
#font ⇒ Object
rubocop:disable Layout/LineLength Use the exact filename from the archive - do NOT modify or standardize it rubocop:enable Layout/LineLength
76 77 78 |
# File 'lib/fontist/import/otf/font_file.rb', line 76 def font File.basename(@path) end |
#full_name ⇒ Object
57 58 59 |
# File 'lib/fontist/import/otf/font_file.rb', line 57 def full_name @metadata.full_name end |
#homepage ⇒ Object
90 91 92 |
# File 'lib/fontist/import/otf/font_file.rb', line 90 def homepage @metadata.vendor_url end |
#license_url ⇒ Object
94 95 96 |
# File 'lib/fontist/import/otf/font_file.rb', line 94 def license_url @metadata.license_url end |
#post_script_name ⇒ Object
61 62 63 |
# File 'lib/fontist/import/otf/font_file.rb', line 61 def post_script_name @metadata.postscript_name end |
#preferred_family_name ⇒ Object
46 47 48 49 50 51 |
# File 'lib/fontist/import/otf/font_file.rb', line 46 def preferred_family_name name = @metadata.preferred_family_name return unless name @name_prefix ? "#{@name_prefix}#{name}" : name end |
#preferred_type ⇒ Object
53 54 55 |
# File 'lib/fontist/import/otf/font_file.rb', line 53 def preferred_type @metadata.preferred_subfamily_name end |
#source_font ⇒ Object
80 81 82 83 84 |
# File 'lib/fontist/import/otf/font_file.rb', line 80 def source_font # source_font is only used when font != original filename # Since we now use exact filename, this should always be nil nil end |
#to_collection_style ⇒ Object
33 34 35 |
# File 'lib/fontist/import/otf/font_file.rb', line 33 def to_collection_style COLLECTION_ATTRIBUTES.to_h { |name| [name, send(name)] }.compact end |
#to_style ⇒ Object
29 30 31 |
# File 'lib/fontist/import/otf/font_file.rb', line 29 def to_style STYLE_ATTRIBUTES.to_h { |name| [name, send(name)] }.compact end |
#type ⇒ Object
42 43 44 |
# File 'lib/fontist/import/otf/font_file.rb', line 42 def type @metadata.subfamily_name || "Regular" end |
#version ⇒ Object
65 66 67 |
# File 'lib/fontist/import/otf/font_file.rb', line 65 def version @metadata.version end |