Class: Fontist::SystemFont

Inherits:
Lutaml::Model::Serializable
  • Object
show all
Defined in:
lib/fontist/system_font.rb

Overview

TODO: This is actually a SystemIndex font entry

Class Method Summary collapse

Class Method Details

.expand_paths(paths) ⇒ Object



33
34
35
36
37
38
39
40
41
# File 'lib/fontist/system_font.rb', line 33

def self.expand_paths(paths)
  paths.map do |path|
    require "etc"
    passwd = Etc.getpwuid
    username = passwd ? passwd.name : Etc.getlogin

    username ? path.gsub("{username}", username) : path
  end
end

.find(font) ⇒ Object



47
48
49
50
51
52
# File 'lib/fontist/system_font.rb', line 47

def self.find(font)
  styles = find_styles(font)
  return unless styles

  styles.map(&:path)
end

.find_styles(font, style = nil) ⇒ Object

This returns a SystemIndexEntry



55
56
57
# File 'lib/fontist/system_font.rb', line 55

def self.find_styles(font, style = nil)
  SystemIndex.system_index.find(font, style)
end

.font_pathsObject



6
7
8
# File 'lib/fontist/system_font.rb', line 6

def self.font_paths
  system_font_paths + fontist_font_paths
end

.fontist_font_pathsObject



43
44
45
# File 'lib/fontist/system_font.rb', line 43

def self.fontist_font_paths
  Dir.glob(Fontist.fonts_path.join("**"))
end

.load_system_font_pathsObject

This detects all fonts on the system from the configuration file.



15
16
17
18
19
20
21
22
23
# File 'lib/fontist/system_font.rb', line 15

def self.load_system_font_paths
  os = Fontist::Utils::System.user_os.to_s
  templates = system_config["system"][os]["paths"]
  patterns = expand_paths(templates)

  Dir.glob(patterns)
  # File::FNM_CASEFOLD is officially ignored -- see https://ruby-doc.org/core-3.1.1/Dir.html#method-c-glob
  # "Case sensitivity depends on your system"
end

.reset_system_font_paths_cacheObject



29
30
31
# File 'lib/fontist/system_font.rb', line 29

def self.reset_system_font_paths_cache
  @system_font_paths = nil
end

.system_configObject



25
26
27
# File 'lib/fontist/system_font.rb', line 25

def self.system_config
  YAML.load_file(Fontist.system_file_path)
end

.system_font_pathsObject



10
11
12
# File 'lib/fontist/system_font.rb', line 10

def self.system_font_paths
  @system_font_paths ||= load_system_font_paths
end