Module: Fontina::Windows::MetaPackage

Defined in:
lib/fontina/windows/meta_package.rb

Constant Summary

Constants included from Marshal

Fontina::Windows::Marshal::BYTE, Fontina::Windows::Marshal::WCHAR

Instance Method Summary collapse

Instance Method Details

#install(force: false) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/fontina/windows/meta_package.rb', line 29

def install(force: false)
  return if installed? unless force

  add_times = 1
  path = Windows.font_registered? registered_name

  Dir.chdir(Windows.fonts_directory) do
    add_times = Windows.remove_font_resource path if path and File.exist? path
    path, = FileUtils.safe_write file.filename, file.content
  end

  Windows.add_font_resource(path, times: add_times).tap do |count|
    unless count == package.fonts.length
      fail "Windows reported #{count} fonts added (expected: #{package.fonts.length})"
    end
  end

  Windows.register_font registered_name, path
  Windows.notify_fonts_changed
end

#installed?Boolean

Returns:

  • (Boolean)


22
23
24
25
26
27
# File 'lib/fontina/windows/meta_package.rb', line 22

def installed?
  !!(path = Windows.font_registered? registered_name) and
  path = File.expand_path(path, Windows.fonts_directory) and
  File.file?(path) and
  File.open(path) { |io| FileUtils.compare_stream io.binmode, StringIO.new(file.content) }
end

#registered_nameObject



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/fontina/windows/meta_package.rb', line 10

def registered_name
  @registered_name ||= begin
    name = package.preferred_name \
      ? wstr(package.preferred_name.name)
      : package.fonts.map { |f| wstr(f.preferred_name.name) }.join(wstr(' & '))

    [Formats::OpenType].include?(format) \
      ? name + wstr(' (TrueType)')
      : name
  end
end