fontist 0.2.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (72) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/macosx.yml +1 -1
  3. data/.github/workflows/ubuntu.yml +1 -1
  4. data/.gitignore +4 -3
  5. data/README.md +91 -5
  6. data/fontist.gemspec +1 -0
  7. data/lib/fontist.rb +26 -8
  8. data/lib/fontist/errors.rb +3 -0
  9. data/lib/fontist/font.rb +78 -0
  10. data/lib/fontist/font_formula.rb +123 -0
  11. data/lib/fontist/formula.rb +90 -0
  12. data/lib/fontist/formulas.rb +15 -0
  13. data/lib/fontist/formulas/andale_font.rb +79 -0
  14. data/lib/fontist/formulas/arial_black_font.rb +78 -0
  15. data/lib/fontist/formulas/cleartype_fonts.rb +226 -0
  16. data/lib/fontist/formulas/comic_font.rb +77 -0
  17. data/lib/fontist/formulas/courier_font.rb +80 -0
  18. data/lib/fontist/formulas/euphemia_font.rb +85 -0
  19. data/lib/fontist/formulas/georgia_font.rb +79 -0
  20. data/lib/fontist/formulas/impact_font.rb +77 -0
  21. data/lib/fontist/formulas/montserrat_font.rb +132 -0
  22. data/lib/fontist/formulas/ms_truetype_fonts.rb +124 -0
  23. data/lib/fontist/formulas/open_sans_fonts.rb +263 -0
  24. data/lib/fontist/formulas/overpass_font.rb +73 -0
  25. data/lib/fontist/formulas/source_fonts.rb +109 -0
  26. data/lib/fontist/formulas/stix_fonts.rb +108 -0
  27. data/lib/fontist/formulas/tahoma_font.rb +146 -0
  28. data/lib/fontist/formulas/webding_font.rb +77 -0
  29. data/lib/fontist/registry.rb +42 -0
  30. data/lib/fontist/system.yml +17 -0
  31. data/lib/fontist/system_font.rb +19 -12
  32. data/lib/fontist/utils.rb +9 -0
  33. data/lib/fontist/utils/downloader.rb +74 -0
  34. data/lib/fontist/utils/dsl.rb +77 -0
  35. data/lib/fontist/utils/exe_extractor.rb +72 -0
  36. data/lib/fontist/utils/zip_extractor.rb +38 -0
  37. data/lib/fontist/version.rb +1 -1
  38. data/spec/fontist/font_formula_spec.rb +67 -0
  39. data/spec/fontist/font_spec.rb +87 -0
  40. data/spec/fontist/formula_spec.rb +67 -0
  41. data/spec/fontist/formulas/andale_font_spec.rb +29 -0
  42. data/spec/fontist/formulas/arial_black_font_spec.rb +29 -0
  43. data/spec/fontist/formulas/cleartype_fonts_spec.rb +38 -0
  44. data/spec/fontist/formulas/comic_font_spec.rb +29 -0
  45. data/spec/fontist/formulas/courier_font_spec.rb +29 -0
  46. data/spec/fontist/formulas/euphemia_font_spec.rb +29 -0
  47. data/spec/fontist/formulas/georgia_font_spec.rb +29 -0
  48. data/spec/fontist/formulas/impact_font_spec.rb +29 -0
  49. data/spec/fontist/formulas/montserrat_font_spec.rb +29 -0
  50. data/spec/fontist/formulas/ms_truetype_fonts_spec.rb +29 -0
  51. data/spec/fontist/formulas/open_sans_fonts_spec.rb +29 -0
  52. data/spec/fontist/formulas/overpass_font_spec.rb +29 -0
  53. data/spec/fontist/formulas/source_fonts_spec.rb +31 -0
  54. data/spec/fontist/formulas/stix_fonts_spec.rb +29 -0
  55. data/spec/fontist/formulas/tahoma_font_spec.rb +29 -0
  56. data/spec/fontist/formulas/webding_font_spec.rb +29 -0
  57. data/spec/fontist/registry_spec.rb +47 -0
  58. data/spec/fontist/system_font_spec.rb +16 -0
  59. data/spec/fontist/{downloader_spec.rb → utils/downloader_spec.rb} +8 -8
  60. data/spec/spec_helper.rb +7 -2
  61. data/spec/support/fontist_helper.rb +10 -0
  62. metadata +65 -14
  63. data/assets/source.yml +0 -54
  64. data/lib/fontist/downloader.rb +0 -69
  65. data/lib/fontist/finder.rb +0 -47
  66. data/lib/fontist/installer.rb +0 -44
  67. data/lib/fontist/ms_vista_font.rb +0 -83
  68. data/lib/fontist/source.rb +0 -31
  69. data/spec/fontist/finder_spec.rb +0 -41
  70. data/spec/fontist/installer_spec.rb +0 -48
  71. data/spec/fontist/ms_vista_font_spec.rb +0 -27
  72. data/spec/fontist/source_spec.rb +0 -13
@@ -1,47 +0,0 @@
1
- module Fontist
2
- class Finder
3
- def initialize(name)
4
- @name = name
5
- end
6
-
7
- def self.find(name)
8
- new(name).find
9
- end
10
-
11
- def find
12
- find_system_font || downloadable_font || raise_invalid_error
13
- end
14
-
15
- private
16
-
17
- attr_reader :name
18
-
19
- def find_system_font
20
- Fontist::SystemFont.find(name)
21
- end
22
-
23
- def remote_source
24
- Fontist::Source.all.remote.to_h.select do |key, value|
25
- !value.fonts.grep(/#{name}/i).empty?
26
- end
27
- end
28
-
29
- def downloadable_font
30
- unless remote_source.empty?
31
- raise(
32
- Fontist::Errors::MissingFontError,
33
- "Fonts are missing, please run" \
34
- "Fontist::Installer.download(name, confirmation: 'yes') to " \
35
- "download these fonts"
36
- )
37
- end
38
- end
39
-
40
- def raise_invalid_error
41
- raise(
42
- Fontist::Errors::NonSupportedFontError,
43
- "Could not find the #{name} font in any of the supported downlodable"
44
- )
45
- end
46
- end
47
- end
@@ -1,44 +0,0 @@
1
- module Fontist
2
- class Installer
3
- def initialize(font_name:, confirmation:, **options)
4
- @font_name = font_name
5
- @confirmation = confirmation.downcase
6
- @options = options
7
- end
8
-
9
- def download
10
- find_system_font || download_font || raise(
11
- Fontist::Errors::NonSupportedFontError
12
- )
13
- end
14
-
15
- def self.download(font_name, confirmation:)
16
- new(font_name: font_name, confirmation: confirmation).download
17
- end
18
-
19
- private
20
-
21
- attr_reader :font_name, :confirmation, :options
22
-
23
- def downloaders
24
- { msvista: Fontist::MsVistaFont }
25
- end
26
-
27
- def find_system_font
28
- Fontist::SystemFont.find(font_name)
29
- end
30
-
31
- def download_font
32
- if font_source
33
- downloader = downloaders[font_source.first]
34
- downloader.fetch_font(font_name, confirmation: confirmation)
35
- end
36
- end
37
-
38
- def font_source
39
- @font_source ||= Fontist::Source.all.remote.to_h.select do |key, value|
40
- !value.fonts.grep(/#{font_name}/i).empty?
41
- end.first
42
- end
43
- end
44
- end
@@ -1,83 +0,0 @@
1
- require "fontist/downloader"
2
-
3
- module Fontist
4
- class MsVistaFont
5
- def initialize(font_name, confirmation:, fonts_path: nil, **options)
6
- @font_name = font_name
7
- @confirmation = confirmation || "no"
8
- @fonts_path = fonts_path || Fontist.fonts_path
9
- @force_download = options.fetch(:force_download, false)
10
-
11
- unless source.agreement === confirmation
12
- raise(Fontist::Errors::LicensingError)
13
- end
14
- end
15
-
16
- def self.fetch_font(font_name, confirmation:, **options)
17
- new(font_name, options.merge(confirmation: confirmation)).fetch
18
- end
19
-
20
- def fetch
21
- fonts = extract_ppviewer_fonts
22
- paths = fonts.grep(/#{font_name}/i)
23
- paths.empty? ? nil : paths
24
- end
25
-
26
- private
27
-
28
- attr_reader :font_name, :fonts_path, :force_download
29
-
30
- def decompressor
31
- @decompressor ||= (
32
- require "libmspack"
33
- LibMsPack::CabDecompressor.new
34
- )
35
- end
36
-
37
- def extract_ppviewer_fonts
38
- Array.new.tap do |fonts|
39
- cabbed_fonts.each do |font|
40
- font_path = fonts_path.join(font.filename).to_s
41
- decompressor.extract(font, font_path)
42
-
43
- fonts.push(font_path)
44
- end
45
- end
46
- end
47
-
48
- def extract_ppviewer_cab_file
49
- if !File.exists?(ppviewer_cab) || force_download
50
- exe_file = decompressor.search(download_exe_file.path)
51
- decompressor.extract(exe_file.files.next, ppviewer_cab)
52
- end
53
- end
54
-
55
- def cabbed_fonts
56
- extract_ppviewer_cab_file
57
- grep_cabbed_fonts(decompressor.search(ppviewer_cab).files) || []
58
- end
59
-
60
- def grep_cabbed_fonts(file)
61
- Array.new.tap do |fonts|
62
- while file
63
- fonts.push(file) if file.filename.match(/.tt|.TT/)
64
- file = file.next
65
- end
66
- end
67
- end
68
-
69
- def source
70
- @source ||= Fontist::Source.all.remote.msvista
71
- end
72
-
73
- def download_exe_file
74
- Fontist::Downloader.download(
75
- source.urls.first, file_size: source.file_size.to_i, sha: source.sha
76
- )
77
- end
78
-
79
- def ppviewer_cab
80
- @ppviewer_cab ||= Fontist.assets_path.join("ppviewer.cab").to_s
81
- end
82
- end
83
- end
@@ -1,31 +0,0 @@
1
- require "yaml"
2
- require "json"
3
- require "ostruct"
4
-
5
- module Fontist
6
- class Source
7
- def self.all
8
- new.all
9
- end
10
-
11
- def all
12
- source_data
13
- end
14
-
15
- private
16
-
17
- def source_data
18
- @source_data ||= JSON.parse(
19
- yaml_data.to_json, object_class: OpenStruct
20
- )
21
- end
22
-
23
- def yaml_data
24
- YAML.load(File.open(yaml_file))
25
- end
26
-
27
- def yaml_file
28
- Fontist.assets_path.join("source.yml")
29
- end
30
- end
31
- end
@@ -1,41 +0,0 @@
1
- require "spec_helper"
2
-
3
- RSpec.describe Fontist::Finder do
4
- describe ".find" do
5
- context "with valid font name" do
6
- it "returns the fonts path" do
7
- name = "DejaVuSerif.ttf"
8
- stub_system_font_finder_to_fixture(name)
9
- dejavu_ttf = Fontist::Finder.find(name)
10
-
11
- expect(dejavu_ttf.first).to include(name)
12
- end
13
- end
14
-
15
- context "with downloadable ms vista font" do
16
- it "returns missing font error" do
17
- name = "CALIBRI.TTF"
18
- allow(Fontist::SystemFont).to receive(:find).and_return(nil)
19
-
20
- expect {
21
- Fontist::Finder.find(name)
22
- }.to raise_error(Fontist::Errors::MissingFontError)
23
- end
24
- end
25
-
26
- context "with invalid font name" do
27
- it "raise an missing font error" do
28
- font_name = "InvalidFont.ttf"
29
-
30
- expect {
31
- Fontist::Finder.find(font_name)
32
- }.to raise_error(Fontist::Errors::NonSupportedFontError)
33
- end
34
- end
35
- end
36
-
37
- def stub_system_font_finder_to_fixture(name)
38
- allow(Fontist::SystemFont).to receive(:find).
39
- and_return(["spec/fixtures/fonts/#{name}"])
40
- end
41
- end
@@ -1,48 +0,0 @@
1
- require "spec_helper"
2
-
3
- RSpec.describe Fontist::Installer do
4
- describe ".download" do
5
- context "with already downloaded fonts", skip_in_windows: true do
6
- it "returns the font path" do
7
- name = "CALIBRI.TTF"
8
- Fontist::MsVistaFont.fetch_font(name, confirmation: "yes")
9
-
10
- allow(Fontist::MsVistaFont).to receive(:fetch_font).and_return(nil)
11
- paths = Fontist::Installer.download(name, confirmation: "yes")
12
-
13
- expect(paths.first).to include("fonts/#{name}")
14
- end
15
- end
16
-
17
- context "with missing but downloadable fonts" do
18
- it "downloads and install the fonts", skip_in_windows: true do
19
- name = "CALIBRI.TTF"
20
- confirmation = "yes"
21
- allow(Fontist::SystemFont).to receive(:find).and_return(nil)
22
-
23
- paths = Fontist::Installer.download(name, confirmation: confirmation)
24
-
25
- expect(paths.first).to include("fonts/#{name}")
26
- end
27
-
28
- it "do not download if user didn't agree" do
29
- name = "CALIBRI.TTF"
30
- allow(Fontist::SystemFont).to receive(:find).and_return(nil)
31
-
32
- expect {
33
- Fontist::Installer.download(name, confirmation: "no")
34
- }.to raise_error(Fontist::Errors::LicensingError)
35
- end
36
- end
37
-
38
- context "with unsupported fonts" do
39
- it "raise an unsupported error" do
40
- name = "InvalidFont.ttf"
41
-
42
- expect {
43
- Fontist::Installer.download(name, confirmation: "yes")
44
- }.to raise_error(Fontist::Errors::NonSupportedFontError)
45
- end
46
- end
47
- end
48
- end
@@ -1,27 +0,0 @@
1
- require "spec_helper"
2
-
3
- RSpec.describe Fontist::MsVistaFont do
4
- describe ".fetch_font" do
5
- context "with valid licence", api_call: true do
6
- it "downloads and returns font paths" do
7
- name = "CANDARAI.TTF"
8
- fonts = Fontist::MsVistaFont.fetch_font(
9
- name, confirmation: "yes", force_download: true
10
- )
11
-
12
- expect(fonts.count).to eq(1)
13
- expect(fonts.first).to include("CANDARAI.TTF")
14
- end
15
- end
16
-
17
- context "with invalid licence agreement" do
18
- it "raise an licensing error" do
19
- font_name = "CANDARAI.TTF"
20
-
21
- expect {
22
- Fontist::MsVistaFont.fetch_font(font_name, confirmation: "no")
23
- }.to raise_error(Fontist::Errors::LicensingError)
24
- end
25
- end
26
- end
27
- end
@@ -1,13 +0,0 @@
1
- require "spec_helper"
2
-
3
- RSpec.describe Fontist::Source do
4
- describe ".all" do
5
- it "returns all of the dataset" do
6
- sources = Fontist::Source.all
7
-
8
- expect(sources.system.linux.paths).not_to be_nil
9
- expect(sources.remote.msvista.file_size).to eq("62914560")
10
- expect(sources.remote.msvista.fonts).to include("CALIBRI.TTF")
11
- end
12
- end
13
- end