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.
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/fontist/import/otf/font_file.rb', line 18 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.
16 17 18 |
# File 'lib/fontist/import/otf/font_file.rb', line 16 def path @path end |
Instance Method Details
#copyright ⇒ Object
88 89 90 |
# File 'lib/fontist/import/otf/font_file.rb', line 88 def copyright @metadata.copyright end |
#description ⇒ Object
71 72 73 |
# File 'lib/fontist/import/otf/font_file.rb', line 71 def description @metadata.description end |
#family_name ⇒ Object
39 40 41 42 |
# File 'lib/fontist/import/otf/font_file.rb', line 39 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
78 79 80 |
# File 'lib/fontist/import/otf/font_file.rb', line 78 def font File.basename(@path) end |
#full_name ⇒ Object
59 60 61 |
# File 'lib/fontist/import/otf/font_file.rb', line 59 def full_name @metadata.full_name end |
#homepage ⇒ Object
92 93 94 |
# File 'lib/fontist/import/otf/font_file.rb', line 92 def homepage @metadata.vendor_url end |
#license_url ⇒ Object
96 97 98 |
# File 'lib/fontist/import/otf/font_file.rb', line 96 def license_url @metadata.license_url end |
#post_script_name ⇒ Object
63 64 65 |
# File 'lib/fontist/import/otf/font_file.rb', line 63 def post_script_name @metadata.postscript_name end |
#preferred_family_name ⇒ Object
48 49 50 51 52 53 |
# File 'lib/fontist/import/otf/font_file.rb', line 48 def preferred_family_name name = @metadata.preferred_family_name return unless name @name_prefix ? "#{@name_prefix}#{name}" : name end |
#preferred_type ⇒ Object
55 56 57 |
# File 'lib/fontist/import/otf/font_file.rb', line 55 def preferred_type @metadata.preferred_subfamily_name end |
#source_font ⇒ Object
82 83 84 85 86 |
# File 'lib/fontist/import/otf/font_file.rb', line 82 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
35 36 37 |
# File 'lib/fontist/import/otf/font_file.rb', line 35 def to_collection_style COLLECTION_ATTRIBUTES.to_h { |name| [name, send(name)] }.compact end |
#to_style ⇒ Object
31 32 33 |
# File 'lib/fontist/import/otf/font_file.rb', line 31 def to_style STYLE_ATTRIBUTES.to_h { |name| [name, send(name)] }.compact end |
#type ⇒ Object
44 45 46 |
# File 'lib/fontist/import/otf/font_file.rb', line 44 def type @metadata.subfamily_name || "Regular" end |
#version ⇒ Object
67 68 69 |
# File 'lib/fontist/import/otf/font_file.rb', line 67 def version @metadata.version end |