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.



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

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



88
89
90
# File 'lib/fontist/import/otf/font_file.rb', line 88

def copyright
  @metadata.copyright
end

#descriptionObject



71
72
73
# File 'lib/fontist/import/otf/font_file.rb', line 71

def description
  @metadata.description
end

#family_nameObject



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

#fontObject

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_nameObject



59
60
61
# File 'lib/fontist/import/otf/font_file.rb', line 59

def full_name
  @metadata.full_name
end

#homepageObject



92
93
94
# File 'lib/fontist/import/otf/font_file.rb', line 92

def homepage
  @metadata.vendor_url
end

#license_urlObject



96
97
98
# File 'lib/fontist/import/otf/font_file.rb', line 96

def license_url
  @metadata.license_url
end

#post_script_nameObject



63
64
65
# File 'lib/fontist/import/otf/font_file.rb', line 63

def post_script_name
  @metadata.postscript_name
end

#preferred_family_nameObject



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_typeObject



55
56
57
# File 'lib/fontist/import/otf/font_file.rb', line 55

def preferred_type
  @metadata.preferred_subfamily_name
end

#source_fontObject



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_styleObject



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_styleObject



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

#typeObject



44
45
46
# File 'lib/fontist/import/otf/font_file.rb', line 44

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

#versionObject



67
68
69
# File 'lib/fontist/import/otf/font_file.rb', line 67

def version
  @metadata.version
end