fontist 0.3.0 → 1.2.1

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 (75) 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 +91 -5
  6. data/lib/fontist.rb +26 -12
  7. data/lib/fontist/errors.rb +3 -1
  8. data/lib/fontist/font.rb +78 -0
  9. data/lib/fontist/font_formula.rb +123 -0
  10. data/lib/fontist/formula.rb +90 -0
  11. data/lib/fontist/formulas.rb +10 -3
  12. data/lib/fontist/formulas/andale_font.rb +80 -0
  13. data/lib/fontist/formulas/arial_black_font.rb +79 -0
  14. data/lib/fontist/formulas/cleartype_fonts.rb +227 -0
  15. data/lib/fontist/formulas/comic_font.rb +78 -0
  16. data/lib/fontist/formulas/courier_font.rb +81 -0
  17. data/lib/fontist/formulas/euphemia_font.rb +85 -0
  18. data/lib/fontist/formulas/georgia_font.rb +80 -0
  19. data/lib/fontist/formulas/impact_font.rb +78 -0
  20. data/lib/fontist/formulas/montserrat_font.rb +132 -0
  21. data/lib/fontist/formulas/ms_truetype_fonts.rb +125 -0
  22. data/lib/fontist/formulas/open_sans_fonts.rb +263 -0
  23. data/lib/fontist/formulas/overpass_font.rb +73 -0
  24. data/lib/fontist/formulas/source_fonts.rb +109 -0
  25. data/lib/fontist/formulas/stix_fonts.rb +108 -0
  26. data/lib/fontist/formulas/tahoma_font.rb +147 -0
  27. data/lib/fontist/formulas/webding_font.rb +78 -0
  28. data/lib/fontist/registry.rb +42 -0
  29. data/lib/fontist/{data/source.yml → system.yml} +5 -6
  30. data/lib/fontist/system_font.rb +27 -11
  31. data/lib/fontist/utils.rb +9 -0
  32. data/lib/fontist/utils/downloader.rb +75 -0
  33. data/lib/fontist/utils/dsl.rb +77 -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/font_formula_spec.rb +67 -0
  38. data/spec/fontist/font_spec.rb +87 -0
  39. data/spec/fontist/formula_spec.rb +67 -0
  40. data/spec/fontist/formulas/andale_font_spec.rb +29 -0
  41. data/spec/fontist/formulas/arial_black_font_spec.rb +29 -0
  42. data/spec/fontist/formulas/cleartype_fonts_spec.rb +38 -0
  43. data/spec/fontist/formulas/comic_font_spec.rb +29 -0
  44. data/spec/fontist/formulas/courier_font_spec.rb +29 -0
  45. data/spec/fontist/formulas/euphemia_font_spec.rb +29 -0
  46. data/spec/fontist/formulas/georgia_font_spec.rb +29 -0
  47. data/spec/fontist/formulas/impact_font_spec.rb +29 -0
  48. data/spec/fontist/formulas/montserrat_font_spec.rb +29 -0
  49. data/spec/fontist/formulas/ms_truetype_fonts_spec.rb +29 -0
  50. data/spec/fontist/formulas/open_sans_fonts_spec.rb +29 -0
  51. data/spec/fontist/formulas/overpass_font_spec.rb +29 -0
  52. data/spec/fontist/formulas/source_fonts_spec.rb +31 -0
  53. data/spec/fontist/formulas/stix_fonts_spec.rb +29 -0
  54. data/spec/fontist/formulas/tahoma_font_spec.rb +29 -0
  55. data/spec/fontist/formulas/webding_font_spec.rb +29 -0
  56. data/spec/fontist/registry_spec.rb +47 -0
  57. data/spec/fontist/system_font_spec.rb +17 -1
  58. data/spec/fontist/{downloader_spec.rb → utils/downloader_spec.rb} +6 -5
  59. data/spec/spec_helper.rb +4 -2
  60. data/spec/support/fontist_helper.rb +4 -2
  61. metadata +50 -20
  62. data/lib/fontist/data/formulas/ms_vista.yml +0 -39
  63. data/lib/fontist/data/formulas/source_font.yml +0 -51
  64. data/lib/fontist/downloader.rb +0 -70
  65. data/lib/fontist/finder.rb +0 -47
  66. data/lib/fontist/formulas/base.rb +0 -25
  67. data/lib/fontist/formulas/ms_vista.rb +0 -74
  68. data/lib/fontist/formulas/source_font.rb +0 -48
  69. data/lib/fontist/installer.rb +0 -47
  70. data/lib/fontist/source.rb +0 -58
  71. data/spec/fontist/finder_spec.rb +0 -41
  72. data/spec/fontist/formulas/ms_vista_spec.rb +0 -27
  73. data/spec/fontist/formulas/source_font_spec.rb +0 -18
  74. data/spec/fontist/installer_spec.rb +0 -48
  75. data/spec/fontist/source_spec.rb +0 -24
@@ -1,51 +0,0 @@
1
- source_font:
2
- agreement: ""
3
-
4
- fonts:
5
- - SourceCodePro-Black.ttf
6
- - SourceCodePro-BlackIt.ttf
7
- - SourceCodePro-Bold.ttf
8
- - SourceCodePro-BoldIt.ttf
9
- - SourceCodePro-ExtraLight.ttf
10
- - SourceCodePro-ExtraLightIt.ttf
11
- - SourceCodePro-It.ttf
12
- - SourceCodePro-Light.ttf
13
- - SourceCodePro-LightIt.ttf
14
- - SourceCodePro-Medium.ttf
15
- - SourceCodePro-MediumIt.ttf
16
- - SourceCodePro-Regular.ttf
17
- - SourceCodePro-Semibold
18
- - SourceCodePro-SemiboldIt.ttf
19
- - SourceSansPro-Black.ttf
20
- - SourceSansPro-BlackIt.ttf
21
- - SourceSansPro-Bold.ttf
22
- - SourceSansPro-BoldIt.ttf
23
- - SourceSansPro-ExtraLight.ttf
24
- - SourceSansPro-ExtraLightIt.ttf
25
- - SourceSansPro-It.ttf
26
- - SourceSansPro-Light.ttf
27
- - SourceSansPro-LightIt.ttf
28
- - SourceSansPro-Medium.ttf
29
- - SourceSansPro-MediumIt.ttf
30
- - SourceSansPro-Regular.ttf
31
- - SourceSansPro-Semibold.ttf
32
- - SourceSansPro-SemiboldIt.ttf
33
- - SourceSerifPro-Black.ttf
34
- - SourceSerifPro-BlackIt.ttf
35
- - SourceSerifPro-Bold.ttf
36
- - SourceSerifPro-BoldIt.ttf
37
- - SourceSerifPro-ExtraLight.ttf
38
- - SourceSerifPro-ExtraLightIt.ttf
39
- - SourceSerifPro-It.ttf
40
- - SourceSerifPro-Light.ttf
41
- - SourceSerifPro-LightIt.ttf
42
- - SourceSerifPro-Medium.ttf
43
- - SourceSerifPro-MediumIt.ttf
44
- - SourceSerifPro-Regular.ttf
45
- - SourceSerifPro-Semibold.ttf
46
- - SourceSerifPro-SemiboldIt.ttf
47
-
48
- file_size: "101440249"
49
- sha: "0107b5d4ba305cb4dff2ba19138407aa2153632a2c41592f74d20cd0d0261bfd"
50
- urls:
51
- - https://github.com/fontist/source-fonts/releases/download/v1.0/source-fonts-1.0.zip
@@ -1,70 +0,0 @@
1
- require "down"
2
- require "digest"
3
-
4
- module Fontist
5
- class Downloader
6
- def initialize(file, file_size: nil, sha: nil, progress: nil)
7
- @sha = sha
8
- @file = file
9
- @progress = progress
10
- @file_size = file_size || default_file_size
11
- end
12
-
13
- def download
14
- file = download_file
15
- verify_file_checksum(file) || raise_invalid_file
16
- end
17
-
18
- def verify_file_checksum(file)
19
- file if Digest::SHA256.file(file) === sha
20
- end
21
-
22
- def raise_invalid_file
23
- raise(Fontist::Errors::TemparedFileError)
24
- end
25
-
26
- def self.download(file, options = {})
27
- new(file, options).download
28
- end
29
-
30
- private
31
-
32
- attr_reader :file, :sha, :file_size
33
-
34
- def default_file_size
35
- 5 * byte_to_megabyte
36
- end
37
-
38
- def byte_to_megabyte
39
- @byte_to_megabyte ||= 1024 * 1024
40
- end
41
-
42
- def download_path
43
- options[:download_path] || Fontist.root_path.join("tmp")
44
- end
45
-
46
- def download_file
47
- bar = ProgressBar.new(file_size / byte_to_megabyte)
48
-
49
- Down.download(
50
- @file,
51
- progress_proc: -> (progress) {
52
- bar.increment(progress / byte_to_megabyte) if @progress === true
53
- }
54
- )
55
- end
56
- end
57
-
58
- class ProgressBar
59
- def initialize(total)
60
- @counter = 1
61
- @total = total
62
- end
63
-
64
- def increment(progress)
65
- complete = sprintf("%#.2f%%", ((@counter.to_f / @total.to_f) * 100))
66
- print "\r\e[0KDownloads: #{@counter}MB/#{@total}MB (#{complete})"
67
- @counter = progress
68
- end
69
- end
70
- end
@@ -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.formulas.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,25 +0,0 @@
1
- module Fontist
2
- module Formulas
3
- class Base
4
- def initialize(font_name, confirmation:, **options)
5
- @font_name = font_name
6
- @confirmation = confirmation || "no"
7
- @force_download = options.fetch(:force_download, false)
8
- @fonts_path = options.fetch(:fonts_path, Fontist.fonts_path)
9
-
10
- check_user_license_agreement
11
- end
12
-
13
- def self.fetch_font(font_name, confirmation: nil, **options)
14
- new(font_name, options.merge(confirmation: confirmation)).fetch
15
- end
16
-
17
- private
18
-
19
- attr_reader :font_name, :confirmation, :fonts_path, :force_download
20
-
21
- def check_user_license_agreement
22
- end
23
- end
24
- end
25
- end
@@ -1,74 +0,0 @@
1
- require "fontist/downloader"
2
-
3
- module Fontist
4
- module Formulas
5
- class MsVista < Base
6
- def fetch
7
- fonts = extract_ppviewer_fonts
8
- paths = fonts.grep(/#{font_name}/i)
9
- paths.empty? ? nil : paths
10
- end
11
-
12
- private
13
-
14
- def check_user_license_agreement
15
- unless source.agreement === confirmation
16
- raise(Fontist::Errors::LicensingError)
17
- end
18
- end
19
-
20
- def decompressor
21
- @decompressor ||= (
22
- require "libmspack"
23
- LibMsPack::CabDecompressor.new
24
- )
25
- end
26
-
27
- def extract_ppviewer_fonts
28
- Array.new.tap do |fonts|
29
- cabbed_fonts.each do |font|
30
- font_path = fonts_path.join(font.filename).to_s
31
- decompressor.extract(font, font_path)
32
-
33
- fonts.push(font_path)
34
- end
35
- end
36
- end
37
-
38
- def extract_ppviewer_cab_file
39
- if !File.exists?(ppviewer_cab) || force_download
40
- exe_file = decompressor.search(download_exe_file.path)
41
- decompressor.extract(exe_file.files.next, ppviewer_cab)
42
- end
43
- end
44
-
45
- def cabbed_fonts
46
- extract_ppviewer_cab_file
47
- grep_cabbed_fonts(decompressor.search(ppviewer_cab).files) || []
48
- end
49
-
50
- def grep_cabbed_fonts(file)
51
- Array.new.tap do |fonts|
52
- while file
53
- fonts.push(file) if file.filename.match(/.tt|.TT/)
54
- file = file.next
55
- end
56
- end
57
- end
58
-
59
- def source
60
- @source ||= Fontist::Source.formulas.msvista
61
- end
62
-
63
- def download_exe_file
64
- Fontist::Downloader.download(
65
- source.urls.first, file_size: source.file_size.to_i, sha: source.sha
66
- )
67
- end
68
-
69
- def ppviewer_cab
70
- @ppviewer_cab ||= Fontist.assets_path.join("ppviewer.cab").to_s
71
- end
72
- end
73
- end
74
- end
@@ -1,48 +0,0 @@
1
- require "zip"
2
-
3
- module Fontist
4
- module Formulas
5
- class SourceFont < Formulas::Base
6
- def fetch
7
- paths = extract_fonts.grep(/#{font_name}/i)
8
- paths.empty? ? nil : paths
9
- end
10
-
11
- private
12
-
13
- def source
14
- @source ||= Fontist::Source.formulas.source_font
15
- end
16
-
17
- def extract_fonts
18
- zip_file = download_file
19
- unzip_fonts(zip_file)
20
- end
21
-
22
- def unzip_fonts(file)
23
- Zip.on_exists_proc = true
24
-
25
- Array.new.tap do |fonts|
26
- Zip::File.open(file) do |zip_file|
27
- zip_file.glob("fonts/*.ttf").each do |entry|
28
- filename = entry.name.gsub("fonts/", "")
29
-
30
- if filename
31
- font_path = fonts_path.join(filename)
32
- fonts.push(font_path.to_s)
33
-
34
- entry.extract(font_path)
35
- end
36
- end
37
- end
38
- end
39
- end
40
-
41
- def download_file
42
- Fontist::Downloader.download(
43
- source.urls.first, file_size: source.file_size.to_i, sha: source.sha
44
- )
45
- end
46
- end
47
- end
48
- end
@@ -1,47 +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
- {
25
- msvista: Fontist::Formulas::MsVista,
26
- source_front: Fontist::Formulas::SourceFont,
27
- }
28
- end
29
-
30
- def find_system_font
31
- Fontist::SystemFont.find(font_name)
32
- end
33
-
34
- def download_font
35
- if !font_sources.empty?
36
- downloader = downloaders[font_sources.first]
37
- downloader.fetch_font(font_name, confirmation: confirmation)
38
- end
39
- end
40
-
41
- def font_sources
42
- @font_sources ||= Fontist::Source.formulas.to_h.select do |key, value|
43
- !value.fonts.grep(/#{font_name}/i).empty?
44
- end.keys
45
- end
46
- end
47
- 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.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