fontist 0.4.0 → 1.0.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 (82) 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 -2
  5. data/README.md +87 -25
  6. data/lib/fontist.rb +28 -13
  7. data/lib/fontist/downloader.rb +11 -11
  8. data/lib/fontist/errors.rb +1 -0
  9. data/lib/fontist/font.rb +78 -0
  10. data/lib/fontist/font_formula.rb +116 -0
  11. data/lib/fontist/formula.rb +90 -0
  12. data/lib/fontist/formulas.rb +10 -5
  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 +225 -0
  16. data/lib/fontist/formulas/comic_font.rb +77 -0
  17. data/lib/fontist/formulas/courier_font.rb +67 -12
  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 +147 -0
  28. data/lib/fontist/formulas/webding_font.rb +77 -0
  29. data/lib/fontist/registry.rb +42 -0
  30. data/lib/fontist/{data/source.yml → system.yml} +0 -7
  31. data/lib/fontist/system_font.rb +9 -13
  32. data/lib/fontist/utils.rb +8 -0
  33. data/lib/fontist/utils/dsl.rb +73 -0
  34. data/lib/fontist/utils/exe_extractor.rb +72 -0
  35. data/lib/fontist/utils/zip_extractor.rb +38 -0
  36. data/lib/fontist/version.rb +1 -1
  37. data/spec/fontist/downloader_spec.rb +2 -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 +18 -19
  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 +6 -6
  59. data/spec/spec_helper.rb +4 -2
  60. data/spec/support/fontist_helper.rb +4 -2
  61. metadata +45 -25
  62. data/lib/fontist/data/formulas/courier.yml +0 -26
  63. data/lib/fontist/data/formulas/ms_system.yml +0 -68
  64. data/lib/fontist/data/formulas/ms_vista.yml +0 -118
  65. data/lib/fontist/data/formulas/source_font.yml +0 -163
  66. data/lib/fontist/finder.rb +0 -45
  67. data/lib/fontist/formula_finder.rb +0 -94
  68. data/lib/fontist/formulas/base.rb +0 -72
  69. data/lib/fontist/formulas/helpers/exe_extractor.rb +0 -45
  70. data/lib/fontist/formulas/helpers/zip_extractor.rb +0 -36
  71. data/lib/fontist/formulas/ms_system.rb +0 -29
  72. data/lib/fontist/formulas/ms_vista.rb +0 -42
  73. data/lib/fontist/formulas/source_font.rb +0 -25
  74. data/lib/fontist/installer.rb +0 -42
  75. data/lib/fontist/source.rb +0 -58
  76. data/spec/fontist/finder_spec.rb +0 -41
  77. data/spec/fontist/formula_finder_spec.rb +0 -54
  78. data/spec/fontist/formulas/ms_system_spec.rb +0 -31
  79. data/spec/fontist/formulas/ms_vista_spec.rb +0 -27
  80. data/spec/fontist/formulas/source_font_spec.rb +0 -18
  81. data/spec/fontist/installer_spec.rb +0 -48
  82. data/spec/fontist/source_spec.rb +0 -24
@@ -1,29 +0,0 @@
1
- module Fontist
2
- module Formulas
3
- class MsSystem < Base
4
- include Formulas::Helpers::ExeExtractor
5
-
6
- private
7
-
8
- def data_node
9
- @data_node ||= "ms_system"
10
- end
11
-
12
- def check_user_license_agreement
13
- unless resources(data_node).agreement === confirmation
14
- raise(Fontist::Errors::LicensingError)
15
- end
16
- end
17
-
18
- def extract_fonts(font_names)
19
- resources(data_node) do |resource|
20
- cab_extract(resource) do |fonts_dir|
21
- font_names.each do |font_name|
22
- match_fonts(fonts_dir, font_name)
23
- end
24
- end
25
- end
26
- end
27
- end
28
- end
29
- end
@@ -1,42 +0,0 @@
1
- module Fontist
2
- module Formulas
3
- class MsVista < Base
4
- include Formulas::Helpers::ExeExtractor
5
-
6
- private
7
-
8
- def data_node
9
- @data_node ||= "msvista"
10
- end
11
-
12
- def check_user_license_agreement
13
- unless resources(data_node).agreement === confirmation
14
- raise(Fontist::Errors::LicensingError)
15
- end
16
- end
17
-
18
- def extract_fonts(font_names)
19
- resources(data_node) do |resource|
20
- exe_extract(resource) do |cab_file|
21
- cab_extract(cab_file, download: false) do |fonts_dir|
22
- font_names.each do |font_name|
23
- match_fonts(fonts_dir, font_name)
24
- end
25
- end
26
- end
27
- end
28
- end
29
-
30
- def exe_extract(source)
31
- cab_files = decompressor.search(download_file(source).path)
32
- decompressor.extract(cab_files.files.next, ppviewer_cab)
33
-
34
- yield(ppviewer_cab) if block_given?
35
- end
36
-
37
- def ppviewer_cab
38
- @ppviewer_cab ||= Fontist.assets_path.join("ppviewer.cab").to_s
39
- end
40
- end
41
- end
42
- end
@@ -1,25 +0,0 @@
1
- require "zip"
2
-
3
- module Fontist
4
- module Formulas
5
- class SourceFont < Formulas::Base
6
- include Formulas::Helpers::ZipExtractor
7
-
8
- private
9
-
10
- def data_node
11
- @data_node ||= "source_font"
12
- end
13
-
14
- def extract_fonts(font_names)
15
- resources(data_node) do |resource|
16
- zip_extract(resource, fonts_sub_dir: "fonts/") do |fonts_paths|
17
- font_names.each do |font_name|
18
- match_fonts(fonts_paths, font_name)
19
- end
20
- end
21
- end
22
- end
23
- end
24
- end
25
- end
@@ -1,42 +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 find_system_font
24
- Fontist::SystemFont.find(font_name)
25
- end
26
-
27
- def font_formulas
28
- Fontist::FormulaFinder.find(font_name)
29
- end
30
-
31
- def download_font
32
- if font_formulas
33
- font_formulas.map do |formula|
34
- formula[:installer].fetch_font(
35
- font_name,
36
- confirmation: confirmation,
37
- )
38
- end.flatten
39
- end
40
- end
41
- end
42
- end
@@ -1,58 +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 self.formulas
12
- new.formulas
13
- end
14
-
15
- def all
16
- source_data
17
- end
18
-
19
- def formulas
20
- formulas_data
21
- end
22
-
23
- private
24
-
25
- def source_data
26
- @source_data ||= parse_to_object(yaml_data)
27
- end
28
-
29
- def parse_to_object(data)
30
- JSON.parse(data.to_json, object_class: OpenStruct)
31
- end
32
-
33
- def formulas_data
34
- @formulas_data ||= parse_to_object(load_formulas)
35
- end
36
-
37
- def load_formulas
38
- Hash.new.tap do |formulas|
39
- source_data.remote.formulas.map do |formula_file|
40
- formula_data = yaml_data(formula_file)
41
-
42
- if formula_data
43
- key = formula_data.keys.first
44
- formulas[key] = formula_data[key]
45
- end
46
- end
47
- end
48
- end
49
-
50
- def yaml_file(file)
51
- Fontist.data_path.join(file)
52
- end
53
-
54
- def yaml_data(file_name = "source.yml")
55
- YAML.load(File.open(yaml_file(file_name)))
56
- end
57
- end
58
- 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"
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,54 +0,0 @@
1
- require "spec_helper"
2
-
3
- RSpec.describe Fontist::FormulaFinder do
4
- describe ".find" do
5
- context "by font name" do
6
- it "returns the font formulas" do
7
- name = "Calibri"
8
- formulas = Fontist::FormulaFinder.find(name)
9
-
10
- expect(formulas.count).to eq(1)
11
- expect(formulas.first[:key]).to eq("msvista")
12
- expect(formulas.first[:installer]).to eq(Fontist::Formulas::MsVista)
13
- end
14
- end
15
-
16
- context "by exact font" do
17
- it "returns the font formulas" do
18
- name = "CAMBRIAI.TTF"
19
- formulas = Fontist::FormulaFinder.find(name)
20
-
21
- expect(formulas.count).to eq(1)
22
- expect(formulas.first[:key]).to eq("msvista")
23
- expect(formulas.first[:installer]).to eq(Fontist::Formulas::MsVista)
24
- end
25
- end
26
-
27
- context "for invalid font" do
28
- it "returns nil to the caller" do
29
- name = "Calibri Made Up Name"
30
- formulas = Fontist::FormulaFinder.find(name)
31
-
32
- expect(formulas).to be_nil
33
- end
34
- end
35
- end
36
-
37
- describe ".find_fonts" do
38
- it "returns the exact font font names" do
39
- name = "Calibri"
40
- font = Fontist::FormulaFinder.find_fonts(name).first
41
-
42
- expect(font.styles.map(&:font)).to include("CALIBRI.TTF")
43
- expect(font.styles.map(&:font)).to include("CALIBRIB.TTF")
44
- expect(font.styles.map(&:font)).to include("CALIBRII.TTF")
45
- end
46
-
47
- it "returns nil if invalid name provided" do
48
- name = "Calibri Invlaid"
49
- fonts = Fontist::FormulaFinder.find_fonts(name)
50
-
51
- expect(fonts).to be_nil
52
- end
53
- end
54
- end
@@ -1,31 +0,0 @@
1
- require "spec_helper"
2
-
3
- RSpec.describe Fontist::Formulas::MsSystem do
4
- describe ".fetch_font" do
5
- context "with valid licence", skip_in_windows: false do
6
- it "downloads and returns font paths", file_download: true do
7
- name = "Times"
8
- stub_fontist_path_to_assets
9
-
10
- fonts = Fontist::Formulas::MsSystem.fetch_font(
11
- name, confirmation: "yes"
12
- )
13
-
14
- expect(fonts).not_to be_empty
15
- expect(fonts.first).to include(name)
16
- expect(Fontist::Finder.find(name)).not_to be_empty
17
- end
18
- end
19
-
20
- context "with invalid licence agreement" do
21
- it "raise an licensing error" do
22
- font_name = "Times"
23
- stub_fontist_path_to_assets
24
-
25
- expect {
26
- Fontist::Formulas::MsSystem.fetch_font(font_name, confirmation: "no")
27
- }.to raise_error(Fontist::Errors::LicensingError)
28
- end
29
- end
30
- end
31
- end
@@ -1,27 +0,0 @@
1
- require "spec_helper"
2
-
3
- RSpec.describe Fontist::Formulas::MsVista do
4
- describe ".fetch_font" do
5
- context "with valid licence" do
6
- it "downloads and returns font paths", file_download: true do
7
- name = "CANDARAI.TTF"
8
- fonts = Fontist::Formulas::MsVista.fetch_font(
9
- name, confirmation: "yes"
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::Formulas::MsVista.fetch_font(font_name, confirmation: "no")
23
- }.to raise_error(Fontist::Errors::LicensingError)
24
- end
25
- end
26
- end
27
- end
@@ -1,18 +0,0 @@
1
- require "spec_helper"
2
-
3
- RSpec.describe Fontist::Formulas::SourceFont do
4
- describe ".fetch_font" do
5
- it "downloads and extract out fonts", file_download: true do
6
- name = "SourceCodePro"
7
- stub_fontist_path_to_assets
8
-
9
- fonts = Fontist::Formulas::SourceFont.fetch_font(
10
- name, confirmation: "yes", force_download: true,
11
- )
12
-
13
- expect(fonts).not_to be_empty
14
- expect(fonts.first).to include(name)
15
- expect(Fontist::Finder.find(name)).not_to be_empty
16
- end
17
- end
18
- 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", file_download: true do
7
- name = "Arial"
8
- Fontist::Formulas::MsVista.fetch_font(name, confirmation: "yes")
9
-
10
- allow(Fontist::Formulas::MsVista).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 = "Arial"
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"
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,24 +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.system.macosx.paths).not_to be_nil
10
- expect(sources.system.windows.paths).not_to be_nil
11
- expect(sources.remote.formulas.first).to include("./formulas")
12
- end
13
- end
14
-
15
- describe ".formulas" do
16
- it "returns all available dataset" do
17
- formulas = Fontist::Source.formulas
18
-
19
- expect(formulas.msvista.license).not_to be_nil
20
- expect(formulas.msvista.file_size).to eq("62914560")
21
- expect(formulas.msvista.fonts.map(&:name)).to include("Calibri")
22
- end
23
- end
24
- end