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,163 +0,0 @@
1
- source_font:
2
- agreement: ""
3
-
4
- fonts:
5
- - name: Source Code Pro
6
- styles:
7
- - type: Black
8
- font: SourceCodePro-Black.ttf
9
-
10
- - type: Black Italic
11
- font: SourceCodePro-BlackIt.ttf
12
-
13
- - type: Bold
14
- font: SourceCodePro-Bold.ttf
15
-
16
- - type: Bold Italic
17
- font: SourceCodePro-BoldIt.ttf
18
-
19
- - type: Extra Light
20
- font: SourceCodePro-ExtraLight.ttf
21
-
22
- - type: ExtraLightIt
23
- font: SourceCodePro-ExtraLightIt.ttf
24
-
25
- - type: Italic
26
- font: SourceCodePro-It.ttf
27
-
28
- - type: Light
29
- font: SourceCodePro-Light.ttf
30
-
31
- - type: Light Italic
32
- font: SourceCodePro-LightIt.ttf
33
-
34
- - type: Medium
35
- font: SourceCodePro-Medium.ttf
36
-
37
- - type: Medium Italic
38
- font: SourceCodePro-MediumIt.ttf
39
-
40
- - type: Regular
41
- font: SourceCodePro-Regular.ttf
42
-
43
- - type: Semibold
44
- font: SourceCodePro-Semibold.ttf
45
-
46
- - type: Semibold Italic
47
- font: SourceCodePro-SemiboldIt.ttf
48
-
49
- - name: Source Sans Pro
50
- styles:
51
- - type: Black
52
- font: SourceSansPro-Black.ttf
53
-
54
- - type: Black Italic
55
- font: SourceSansPro-BlackIt.ttf
56
-
57
- - type: Bold
58
- font: SourceSansPro-Bold.ttf
59
-
60
- - type: Bold Italic
61
- font: SourceSansPro-BoldIt.ttf
62
-
63
- - type: Extra Light
64
- font: SourceSansPro-ExtraLight.ttf
65
-
66
- - type: ExtraLightIt
67
- font: SourceSansPro-ExtraLightIt.ttf
68
-
69
- - type: Italic
70
- font: SourceSansPro-It.ttf
71
-
72
- - type: Light
73
- font: SourceSansPro-Light.ttf
74
-
75
- - type: Light Italic
76
- font: SourceSansPro-LightIt.ttf
77
-
78
- - type: Medium
79
- font: SourceSansPro-Medium.ttf
80
-
81
- - type: Medium Italic
82
- font: SourceSansPro-MediumIt.ttf
83
-
84
- - type: Regular
85
- font: SourceSansPro-Regular.ttf
86
-
87
- - type: Semibold
88
- font: SourceSansPro-Semibold.ttf
89
-
90
- - type: Semibold Italic
91
- font: SourceSansPro-SemiboldIt.ttf
92
-
93
- - name: Source Serif Pro
94
- styles:
95
- - type: Black
96
- font: SourceSerifPro-Black.ttf
97
-
98
- - type: Black Italic
99
- font: SourceSerifPro-BlackIt.ttf
100
-
101
- - type: Bold
102
- font: SourceSerifPro-Bold.ttf
103
-
104
- - type: Bold Italic
105
- font: SourceSerifPro-BoldIt.ttf
106
-
107
- - type: Extra Light
108
- font: SourceSerifPro-ExtraLight.ttf
109
-
110
- - type: ExtraLightIt
111
- font: SourceSerifPro-ExtraLightIt.ttf
112
-
113
- - type: Italic
114
- font: SourceSerifPro-It.ttf
115
-
116
- - type: Light
117
- font: SourceSerifPro-Light.ttf
118
-
119
- - type: Light Italic
120
- font: SourceSerifPro-LightIt.ttf
121
-
122
- - type: Medium
123
- font: SourceSerifPro-Medium.ttf
124
-
125
- - type: Medium Italic
126
- font: SourceSerifPro-MediumIt.ttf
127
-
128
- - type: Regular
129
- font: SourceSerifPro-Regular.ttf
130
-
131
- - type: Semibold
132
- font: SourceSerifPro-Semibold.ttf
133
-
134
- - type: Semibold Italic
135
- font: SourceSerifPro-SemiboldIt.ttf
136
-
137
- - name: Source Han Sans
138
- styles:
139
- - type: Regular
140
- font: SourceHanSans-Regular.ttc
141
-
142
- - type: Normal
143
- font: SourceHanSans-Normal.ttc
144
-
145
- - type: Bold
146
- font: SourceHanSans-Bold.ttc
147
-
148
- - type: ExtraLight
149
- font: SourceHanSans-ExtraLight.ttc
150
-
151
- - type: Heavy
152
- font: SourceHanSans-Heavy.ttc
153
-
154
- - type: Light
155
- font: SourceHanSans-Light.ttc
156
-
157
- - type: Medium
158
- font: SourceHanSans-Medium.ttc
159
-
160
- file_size: "101440249"
161
- sha: "0107b5d4ba305cb4dff2ba19138407aa2153632a2c41592f74d20cd0d0261bfd"
162
- urls:
163
- - https://github.com/fontist/source-fonts/releases/download/v1.0/source-fonts-1.0.zip
@@ -1,45 +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::FormulaFinder.find(name)
25
- end
26
-
27
- def downloadable_font
28
- unless remote_source.nil?
29
- raise(
30
- Fontist::Errors::MissingFontError,
31
- "Fonts are missing, please run" \
32
- "Fontist::Installer.download(name, confirmation: 'yes') to " \
33
- "download these fonts"
34
- )
35
- end
36
- end
37
-
38
- def raise_invalid_error
39
- raise(
40
- Fontist::Errors::NonSupportedFontError,
41
- "Could not find the #{name} font in any of the supported downlodable"
42
- )
43
- end
44
- end
45
- end
@@ -1,94 +0,0 @@
1
- module Fontist
2
- class FormulaFinder
3
- def initialize(font_name)
4
- @font_name = font_name
5
- end
6
-
7
- def self.find(font_name)
8
- new(font_name).find
9
- end
10
-
11
- def self.find_fonts(name)
12
- new(name).find_fonts
13
- end
14
-
15
- def find
16
- formulas = find_formula
17
- build_formulas_array(formulas)
18
- end
19
-
20
- def find_fonts
21
- matched_fonts = find_formula.map do |key, _value|
22
- formulas[key].fonts.select do |font|
23
- font.name == font_name
24
- end
25
- end
26
-
27
- matched_fonts.empty? ? nil : matched_fonts.flatten
28
- end
29
-
30
- private
31
-
32
- attr_reader :font_name
33
-
34
- def build_formulas_array(formulas)
35
- unless formulas.empty?
36
- Array.new.tap do |formula_array|
37
- formulas.each do |key|
38
- formula_array.push(
39
- key: key.to_s,
40
- installer: formula_installers[key]
41
- )
42
- end
43
- end
44
- end
45
- end
46
-
47
- def find_formula
48
- find_by_font_name || find_by_font || []
49
- end
50
-
51
- def formulas
52
- @formulas ||= Fontist::Source.formulas.to_h
53
- end
54
-
55
- def formula_installers
56
- {
57
- msvista: Fontist::Formulas::MsVista,
58
- ms_system: Fontist::Formulas::MsSystem,
59
- courier: Fontist::Formulas::CourierFont,
60
- source_front: Fontist::Formulas::SourceFont,
61
- }
62
- end
63
-
64
- def find_by_font_name
65
- formula_names = formulas.select do |key, value|
66
- !value.fonts.map(&:name).grep(/#{font_name}/i).empty?
67
- end.keys
68
-
69
- formula_names.empty? ? nil : formula_names
70
- end
71
-
72
- # Note
73
- #
74
- # These interface recursively look into every single font styles,
75
- # so ideally try to avoid using it when possible, and that's why
76
- # we've added it as last option in formula finder.
77
- #
78
- def find_by_font
79
- formula_names = formulas.select do |key, value|
80
- match_in_font_styles?(value.fonts)
81
- end.keys
82
-
83
- formula_names.empty? ? nil : formula_names
84
- end
85
-
86
- def match_in_font_styles?(fonts)
87
- styles = fonts.select do |font|
88
- !font.styles.map(&:font).grep(/#{font_name}/i).empty?
89
- end
90
-
91
- styles.empty? ? false : true
92
- end
93
- end
94
- end
@@ -1,72 +0,0 @@
1
- require "fontist/downloader"
2
- require "fontist/formulas/helpers/exe_extractor"
3
- require "fontist/formulas/helpers/zip_extractor"
4
-
5
- module Fontist
6
- module Formulas
7
- class Base
8
- def initialize(font_name, confirmation:, **options)
9
- @matched_fonts = []
10
- @font_name = font_name
11
- @confirmation = confirmation || "no"
12
- @force_download = options.fetch(:force_download, false)
13
- @fonts_path = options.fetch(:fonts_path, Fontist.fonts_path)
14
-
15
- check_user_license_agreement
16
- end
17
-
18
- def self.fetch_font(font_name, confirmation: nil, **options)
19
- new(font_name, options.merge(confirmation: confirmation)).fetch
20
- end
21
-
22
- def fetch
23
- extract_fonts(map_names_to_fonts(font_name))
24
-
25
- matched_fonts_uniq = matched_fonts.flatten.uniq
26
- matched_fonts_uniq.empty? ? nil : matched_fonts_uniq
27
- end
28
-
29
- private
30
-
31
- attr_reader(
32
- :font_name,
33
- :fonts_path,
34
- :confirmation,
35
- :matched_fonts,
36
- :force_download,
37
- )
38
-
39
- def check_user_license_agreement
40
- end
41
-
42
- def resources(name, &block)
43
- source = formulas[name]
44
- block_given? ? yield(source) : source
45
- end
46
-
47
- def formulas
48
- @formulas ||= Fontist::Source.formulas
49
- end
50
-
51
- def match_fonts(fonts_dir, font_name)
52
- font = fonts_dir.grep(/#{font_name}/i)
53
- @matched_fonts.push(font) if font
54
-
55
- font
56
- end
57
-
58
- def map_names_to_fonts(font_name)
59
- fonts = FormulaFinder.find_fonts(font_name)
60
- fonts = fonts.map { |font| font.styles.map(&:font) }.flatten if fonts
61
-
62
- fonts || []
63
- end
64
-
65
- def download_file(source)
66
- Fontist::Downloader.download(
67
- source.urls.first, sha: source.sha, file_size: source.file_size,
68
- )
69
- end
70
- end
71
- end
72
- end
@@ -1,45 +0,0 @@
1
- module Fontist
2
- module Formulas
3
- module Helpers
4
- module ExeExtractor
5
- def cab_extract(exe_file, download: true, font_ext: /.tt|.ttc/i)
6
- exe_file = download_file(exe_file).path if download
7
- cab_file = decompressor.search(exe_file)
8
- cabbed_fonts = grep_fonts(cab_file.files, font_ext) || []
9
- fonts_paths = extract_cabbed_fonts_to_assets(cabbed_fonts)
10
-
11
- yield(fonts_paths) if block_given?
12
- end
13
-
14
- private
15
-
16
- def decompressor
17
- @decompressor ||= (
18
- require "libmspack"
19
- LibMsPack::CabDecompressor.new
20
- )
21
- end
22
-
23
- def grep_fonts(file, font_ext)
24
- Array.new.tap do |fonts|
25
- while file
26
- fonts.push(file) if file.filename.match(font_ext)
27
- file = file.next
28
- end
29
- end
30
- end
31
-
32
- def extract_cabbed_fonts_to_assets(cabbed_fonts)
33
- Array.new.tap do |fonts|
34
- cabbed_fonts.each do |font|
35
- font_path = fonts_path.join(font.filename).to_s
36
- decompressor.extract(font, font_path)
37
-
38
- fonts.push(font_path)
39
- end
40
- end
41
- end
42
- end
43
- end
44
- end
45
- end
@@ -1,36 +0,0 @@
1
- module Fontist
2
- module Formulas
3
- module Helpers
4
- module ZipExtractor
5
- def zip_extract(resource, download: true, fonts_sub_dir: "/")
6
- zip_file = download_file(resource) if download
7
- zip_file ||= resource.urls.first
8
-
9
- fonts_paths = unzip_fonts(zip_file, fonts_sub_dir)
10
- block_given? ? yield(fonts_paths) : fonts_paths
11
- end
12
-
13
- private
14
-
15
- def unzip_fonts(file, fonts_sub_dir = "/")
16
- Zip.on_exists_proc = true
17
-
18
- Array.new.tap do |fonts|
19
- Zip::File.open(file) do |zip_file|
20
- zip_file.glob("#{fonts_sub_dir}*.{ttf,ttc}").each do |entry|
21
- filename = entry.name.gsub("#{fonts_sub_dir}", "")
22
-
23
- if filename
24
- font_path = fonts_path.join(filename)
25
- fonts.push(font_path.to_s)
26
-
27
- entry.extract(font_path)
28
- end
29
- end
30
- end
31
- end
32
- end
33
- end
34
- end
35
- end
36
- end