Class: Fontist::Import::Otf::FontFile

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#pathObject (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



86
87
88
# File 'lib/fontist/import/otf/font_file.rb', line 86

def copyright
  @metadata.copyright
end

#descriptionObject



69
70
71
# File 'lib/fontist/import/otf/font_file.rb', line 69

def description
  @metadata.description
end

#family_nameObject



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

#fontObject

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_nameObject



57
58
59
# File 'lib/fontist/import/otf/font_file.rb', line 57

def full_name
  @metadata.full_name
end

#homepageObject



90
91
92
# File 'lib/fontist/import/otf/font_file.rb', line 90

def homepage
  @metadata.vendor_url
end

#license_urlObject



94
95
96
# File 'lib/fontist/import/otf/font_file.rb', line 94

def license_url
  @metadata.license_url
end

#post_script_nameObject



61
62
63
# File 'lib/fontist/import/otf/font_file.rb', line 61

def post_script_name
  @metadata.postscript_name
end

#preferred_family_nameObject



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_typeObject



53
54
55
# File 'lib/fontist/import/otf/font_file.rb', line 53

def preferred_type
  @metadata.preferred_subfamily_name
end

#source_fontObject



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_styleObject



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_styleObject



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

#typeObject



42
43
44
# File 'lib/fontist/import/otf/font_file.rb', line 42

def type
  @metadata.subfamily_name || "Regular"
end

#versionObject



65
66
67
# File 'lib/fontist/import/otf/font_file.rb', line 65

def version
  @metadata.version
end