Class: Fontist::SystemIndex

Inherits:
Object
  • Object
show all
Includes:
Utils::Locking
Defined in:
lib/fontist/system_index.rb

Defined Under Namespace

Classes: DefaultFamily, PreferredFamily

Constant Summary collapse

PLATFORM_MACINTOSH =
1
PLATFORM_MICROSOFT =
3
ENCODING_MAC_ROMAN =
0
ENCODING_MS_UNICODE_BMP =
1
LANGUAGE_MAC_ENGLISH =
0
LANGUAGE_MS_ENGLISH_AMERICAN =
0x409

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Utils::Locking

#lock

Constructor Details

#initialize(index_path, font_paths_fetcher, family) ⇒ SystemIndex

Returns a new instance of SystemIndex.



70
71
72
73
74
# File 'lib/fontist/system_index.rb', line 70

def initialize(index_path, font_paths_fetcher, family)
  @index_path = index_path
  @font_paths_fetcher = font_paths_fetcher
  @family = family
end

Class Method Details

.familyObject



66
67
68
# File 'lib/fontist/system_index.rb', line 66

def self.family
  Fontist.preferred_family? ? PreferredFamily.new : DefaultFamily.new
end

.fontist_indexObject



53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/fontist/system_index.rb', line 53

def self.fontist_index
  path = if Fontist.preferred_family?
           Fontist.fontist_preferred_family_index_path
         else
           Fontist.fontist_index_path
         end

  @fontist_index ||= {}
  @fontist_index[Fontist.preferred_family?] ||= {}
  @fontist_index[Fontist.preferred_family?][path] ||=
    new(path, -> { SystemFont.fontist_font_paths }, family)
end

.system_indexObject



40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/fontist/system_index.rb', line 40

def self.system_index
  path = if Fontist.preferred_family?
           Fontist.system_preferred_family_index_path
         else
           Fontist.system_index_path
         end

  @system_index ||= {}
  @system_index[Fontist.preferred_family?] ||= {}
  @system_index[Fontist.preferred_family?][path] ||=
    new(path, -> { SystemFont.font_paths }, family)
end

Instance Method Details

#find(font, style) ⇒ Object



76
77
78
79
80
81
82
83
# File 'lib/fontist/system_index.rb', line 76

def find(font, style)
  fonts = index.select do |file|
    file[:family_name].casecmp?(font) &&
      (style.nil? || file[:type].casecmp?(style))
  end

  fonts.empty? ? nil : fonts
end

#rebuildObject



85
86
87
# File 'lib/fontist/system_index.rb', line 85

def rebuild
  build_index
end