fontist 0.1.0 → 0.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.
- checksums.yaml +4 -4
- data/.github/workflows/macosx.yml +30 -0
- data/.github/workflows/ubuntu.yml +1 -1
- data/.github/workflows/windows.yml +32 -0
- data/.gitignore +3 -0
- data/README.md +11 -1
- data/assets/fonts/.keep +0 -0
- data/assets/source.yml +54 -0
- data/bin/console +2 -5
- data/fontist.gemspec +4 -0
- data/lib/fontist/downloader.rb +69 -0
- data/lib/fontist/errors.rb +7 -0
- data/lib/fontist/finder.rb +47 -0
- data/lib/fontist/installer.rb +44 -0
- data/lib/fontist/ms_vista_font.rb +83 -0
- data/lib/fontist/source.rb +31 -0
- data/lib/fontist/system_font.rb +65 -0
- data/lib/fontist/version.rb +1 -1
- data/lib/fontist.rb +26 -2
- data/spec/fixtures/fonts/DejaVuSerif.ttf +0 -0
- data/spec/fontist/downloader_spec.rb +35 -0
- data/spec/fontist/finder_spec.rb +41 -0
- data/spec/fontist/installer_spec.rb +48 -0
- data/spec/fontist/ms_vista_font_spec.rb +27 -0
- data/spec/fontist/source_spec.rb +13 -0
- data/spec/fontist/system_font_spec.rb +28 -0
- data/spec/spec_helper.rb +3 -0
- metadata +62 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4e446487ef01cae5da6b38d363e22e6a4210880f88a4741762a234598db88940
|
4
|
+
data.tar.gz: 8d622e34e2a80ae41018238d99b7be5781dbd785d8505d8a69e63aa48a70706f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 106f4f4c64991ad9301eb2315e4b98bab19973d393a3daed060ca0d2014c4d8236ebb7de4cf6dceee7e9e4fed849111238d3d2231c83e5c3aeb6f8c3a385a4eb
|
7
|
+
data.tar.gz: 5fb219fb32f6d8616924abaabe4451fba80e0be2f2986ac0b7aa574511884dec670a33635c3edad1eec817f6126f0017b995a7aa876f8711a87be8570efc6c48
|
@@ -0,0 +1,30 @@
|
|
1
|
+
name: macos
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches:
|
6
|
+
- master
|
7
|
+
|
8
|
+
pull_request:
|
9
|
+
branches:
|
10
|
+
- master
|
11
|
+
|
12
|
+
jobs:
|
13
|
+
build:
|
14
|
+
runs-on: macos-latest
|
15
|
+
|
16
|
+
steps:
|
17
|
+
- uses: actions/checkout@v2
|
18
|
+
|
19
|
+
- uses: actions/setup-ruby@v1
|
20
|
+
with:
|
21
|
+
ruby-version: 2.6
|
22
|
+
|
23
|
+
- name: Install bundler
|
24
|
+
run: gem install bundler
|
25
|
+
|
26
|
+
- name: Setup
|
27
|
+
run: bin/setup
|
28
|
+
|
29
|
+
- name: Run tests
|
30
|
+
run: bin/rspec
|
@@ -0,0 +1,32 @@
|
|
1
|
+
name: windows
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches:
|
6
|
+
- master
|
7
|
+
|
8
|
+
pull_request:
|
9
|
+
branches:
|
10
|
+
- master
|
11
|
+
|
12
|
+
jobs:
|
13
|
+
build:
|
14
|
+
runs-on: windows-latest
|
15
|
+
|
16
|
+
steps:
|
17
|
+
- uses: actions/checkout@v2
|
18
|
+
|
19
|
+
- uses: actions/setup-ruby@v1
|
20
|
+
with:
|
21
|
+
ruby-version: 2.6
|
22
|
+
architecture: "x64"
|
23
|
+
|
24
|
+
- name: Setup
|
25
|
+
shell: pwsh
|
26
|
+
run: |
|
27
|
+
gem install bundler
|
28
|
+
bundle config --local path vendor/bundle
|
29
|
+
bundle install --jobs 4 --retry 3
|
30
|
+
|
31
|
+
- name: Run tests
|
32
|
+
run: bundle exec rspec --tag ~skip_in_windows
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# Fontist
|
2
2
|
|
3
|
+

|
4
|
+

|
3
5
|

|
4
6
|
|
5
7
|
A simple library to find and download fonts for Windows, Linux and Mac.
|
@@ -26,7 +28,15 @@ gem install fontist
|
|
26
28
|
|
27
29
|
## Usage
|
28
30
|
|
29
|
-
|
31
|
+
### Find a font
|
32
|
+
|
33
|
+
The fontist library allows us to easily locate or download a any of the supported
|
34
|
+
fonts and then it returns the complete path for the path. To find any font in a
|
35
|
+
user's system we can use the following interface.
|
36
|
+
|
37
|
+
```ruby
|
38
|
+
Fontist::Finder.find("CALIBRI.TTF")
|
39
|
+
```
|
30
40
|
|
31
41
|
## Development
|
32
42
|
|
data/assets/fonts/.keep
ADDED
File without changes
|
data/assets/source.yml
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
system:
|
2
|
+
linux:
|
3
|
+
paths:
|
4
|
+
- /usr/share/fonts/**/**.{ttf,ttc}
|
5
|
+
|
6
|
+
windows:
|
7
|
+
paths:
|
8
|
+
- C:/Windows/Fonts/**/**.{ttc,ttf}
|
9
|
+
|
10
|
+
macosx:
|
11
|
+
paths:
|
12
|
+
- /System/Library/Fonts/**/**.{ttf,ttc}
|
13
|
+
|
14
|
+
unix:
|
15
|
+
paths:
|
16
|
+
- /usr/share/fonts/**/**.{ttf,ttc}
|
17
|
+
|
18
|
+
remote:
|
19
|
+
msvista:
|
20
|
+
agreement: "yes"
|
21
|
+
|
22
|
+
fonts:
|
23
|
+
- CALIBRI.TTF
|
24
|
+
- CALIBRII.TTF
|
25
|
+
- CAMBRIA.TTC
|
26
|
+
- CAMBRIAI.TTF
|
27
|
+
- CANDARA.TTF
|
28
|
+
- CANDARAI.TTF
|
29
|
+
- CONSOLA.TTF
|
30
|
+
- CONSOLAI.TTF
|
31
|
+
- CONSTAN.TTF
|
32
|
+
- CONSTANI.TTF
|
33
|
+
- CORBEL.TTF
|
34
|
+
- CORBELI.TTF
|
35
|
+
- MEIRYO.TTC
|
36
|
+
- CALIBRIB.TTF
|
37
|
+
- CALIBRIZ.TTF
|
38
|
+
- CAMBRIAB.TTF
|
39
|
+
- CAMBRIAZ.TTF
|
40
|
+
- CANDARAB.TTF
|
41
|
+
- CANDARAZ.TTF
|
42
|
+
- CONSOLAB.TTF
|
43
|
+
- CONSOLAZ.TTF
|
44
|
+
- CONSTANB.TTF
|
45
|
+
- CONSTANZ.TTF
|
46
|
+
- CORBELB.TTF
|
47
|
+
- CORBELZ.TTF
|
48
|
+
- MEIRYOB.TTC
|
49
|
+
|
50
|
+
file_size: "62914560"
|
51
|
+
sha: "249473568eba7a1e4f95498acba594e0f42e6581add4dead70c1dfb908a09423"
|
52
|
+
urls:
|
53
|
+
- "https://www.dropbox.com/s/dl/6lclhxpydwgkjzh/PowerPointViewer.exe?dl=1"
|
54
|
+
- "https://web.archive.org/web/20171225132744/http://download.microsoft.com/download/E/6/7/E675FFFC-2A6D-4AB0-B3EB-27C9F8C8F696/PowerPointViewer.exe"
|
data/bin/console
CHANGED
@@ -7,8 +7,5 @@ require "fontist"
|
|
7
7
|
# with your gem easier. You can also use a different console, if you like.
|
8
8
|
|
9
9
|
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
require "irb"
|
14
|
-
IRB.start(__FILE__)
|
10
|
+
require "pry"
|
11
|
+
Pry.start
|
data/fontist.gemspec
CHANGED
@@ -21,6 +21,10 @@ Gem::Specification.new do |spec|
|
|
21
21
|
spec.files = `git ls-files`.split("\n")
|
22
22
|
spec.test_files = `git ls-files -- {spec}/*`.split("\n")
|
23
23
|
|
24
|
+
spec.add_runtime_dependency "down", "~> 5.0"
|
25
|
+
spec.add_runtime_dependency "libmspack", "~> 0.1.0"
|
26
|
+
|
27
|
+
spec.add_development_dependency "pry"
|
24
28
|
spec.add_development_dependency "bundler", "~> 2.0"
|
25
29
|
spec.add_development_dependency "rake", "~> 12.3.3"
|
26
30
|
spec.add_development_dependency "rspec", "~> 3.0"
|
@@ -0,0 +1,69 @@
|
|
1
|
+
require "down"
|
2
|
+
require "digest"
|
3
|
+
|
4
|
+
module Fontist
|
5
|
+
class Downloader
|
6
|
+
def initialize(file, file_size: nil, sha: nil)
|
7
|
+
@sha = sha
|
8
|
+
@file = file
|
9
|
+
@file_size = file_size || default_file_size
|
10
|
+
end
|
11
|
+
|
12
|
+
def download
|
13
|
+
file = download_file
|
14
|
+
verify_file_checksum(file) || raise_invalid_file
|
15
|
+
end
|
16
|
+
|
17
|
+
def verify_file_checksum(file)
|
18
|
+
file if Digest::SHA256.file(file) === sha
|
19
|
+
end
|
20
|
+
|
21
|
+
def raise_invalid_file
|
22
|
+
raise(Fontist::Error, "Invalid / Tempared file")
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.download(file, options = {})
|
26
|
+
new(file, options).download
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
attr_reader :file, :sha, :file_size
|
32
|
+
|
33
|
+
def default_file_size
|
34
|
+
5 * byte_to_megabyte
|
35
|
+
end
|
36
|
+
|
37
|
+
def byte_to_megabyte
|
38
|
+
@byte_to_megabyte ||= 1024 * 1024
|
39
|
+
end
|
40
|
+
|
41
|
+
def download_path
|
42
|
+
options[:download_path] || Fontist.root_path.join("tmp")
|
43
|
+
end
|
44
|
+
|
45
|
+
def download_file
|
46
|
+
bar = ProgressBar.new(file_size / byte_to_megabyte)
|
47
|
+
|
48
|
+
Down.download(
|
49
|
+
@file,
|
50
|
+
progress_proc: -> (progress) {
|
51
|
+
bar.increment(progress / byte_to_megabyte)
|
52
|
+
}
|
53
|
+
)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
class ProgressBar
|
58
|
+
def initialize(total)
|
59
|
+
@counter = 1
|
60
|
+
@total = total
|
61
|
+
end
|
62
|
+
|
63
|
+
def increment(progress)
|
64
|
+
complete = sprintf("%#.2f%%", ((@counter.to_f / @total.to_f) * 100))
|
65
|
+
print "\r\e[0KDownloads: #{@counter}MB/#{@total}MB (#{complete})"
|
66
|
+
@counter = progress
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,47 @@
|
|
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
|
@@ -0,0 +1,44 @@
|
|
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
|
@@ -0,0 +1,83 @@
|
|
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
|
@@ -0,0 +1,31 @@
|
|
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
|
@@ -0,0 +1,65 @@
|
|
1
|
+
module Fontist
|
2
|
+
class SystemFont
|
3
|
+
def initialize(font:, sources: nil)
|
4
|
+
@font = font
|
5
|
+
@user_sources = sources || []
|
6
|
+
|
7
|
+
check_or_create_fontist_path
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.find(font, sources: [])
|
11
|
+
new(font: font, sources: sources).find
|
12
|
+
end
|
13
|
+
|
14
|
+
def find
|
15
|
+
paths = font_paths.grep(/#{font}/i)
|
16
|
+
paths.empty? ? nil : paths
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
attr_reader :font, :user_sources
|
22
|
+
|
23
|
+
def check_or_create_fontist_path
|
24
|
+
unless fontist_fonts_path.exist?
|
25
|
+
require "fileutils"
|
26
|
+
FileUtils.mkdir_p(fontist_fonts_path)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def font_paths
|
31
|
+
Dir.glob((
|
32
|
+
user_sources +
|
33
|
+
default_sources["paths"] +
|
34
|
+
[fontist_fonts_path.join("**")]
|
35
|
+
).flatten.uniq)
|
36
|
+
end
|
37
|
+
|
38
|
+
def fontist_fonts_path
|
39
|
+
@fontist_fonts_path ||= Fontist.fonts_path
|
40
|
+
end
|
41
|
+
|
42
|
+
def default_sources
|
43
|
+
@default_sources ||= Source.all.system[user_os.to_s]
|
44
|
+
end
|
45
|
+
|
46
|
+
def user_os
|
47
|
+
@user_os ||= (
|
48
|
+
host_os = RbConfig::CONFIG["host_os"]
|
49
|
+
case host_os
|
50
|
+
when /mswin|msys|mingw|cygwin|bccwin|wince|emc/
|
51
|
+
:windows
|
52
|
+
when /darwin|mac os/
|
53
|
+
:macosx
|
54
|
+
when /linux/
|
55
|
+
:linux
|
56
|
+
when /solaris|bsd/
|
57
|
+
:unix
|
58
|
+
else
|
59
|
+
raise Fontist::Error, "unknown os: #{host_os.inspect}"
|
60
|
+
end
|
61
|
+
)
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
65
|
+
end
|
data/lib/fontist/version.rb
CHANGED
data/lib/fontist.rb
CHANGED
@@ -1,6 +1,30 @@
|
|
1
|
+
require "fontist/errors"
|
1
2
|
require "fontist/version"
|
2
3
|
|
4
|
+
require "fontist/finder"
|
5
|
+
require "fontist/source"
|
6
|
+
require "fontist/installer"
|
7
|
+
require "fontist/system_font"
|
8
|
+
require "fontist/ms_vista_font"
|
9
|
+
|
3
10
|
module Fontist
|
4
|
-
|
5
|
-
|
11
|
+
def self.lib_path
|
12
|
+
Fontist.root_path.join("lib")
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.root_path
|
16
|
+
Pathname.new(File.dirname(__dir__))
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.assets_path
|
20
|
+
Fontist.root_path.join("assets")
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.fontist_path
|
24
|
+
Pathname.new(Dir.home).join(".fontist")
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.fonts_path
|
28
|
+
Fontist.fontist_path.join("fonts")
|
29
|
+
end
|
6
30
|
end
|
Binary file
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
RSpec.describe Fontist::Downloader do
|
4
|
+
describe ".download", api_call: true do
|
5
|
+
it "return the valid downloaded file" do
|
6
|
+
tempfile = Fontist::Downloader.download(
|
7
|
+
sample_file[:file],
|
8
|
+
sha: sample_file[:sha],
|
9
|
+
file_size: sample_file[:file_size],
|
10
|
+
)
|
11
|
+
|
12
|
+
expect(tempfile).not_to be_nil
|
13
|
+
expect(tempfile.size).to eq(sample_file[:file_size])
|
14
|
+
end
|
15
|
+
|
16
|
+
it "raises an error for tempared file" do
|
17
|
+
expect{
|
18
|
+
Fontist::Downloader.download(
|
19
|
+
sample_file[:file],
|
20
|
+
sha: sample_file[:sha] + "mm",
|
21
|
+
file_size: sample_file[:file_size]
|
22
|
+
)
|
23
|
+
}.to raise_error(Fontist::Error, "Invalid / Tempared file")
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def sample_file
|
28
|
+
@sample_file ||= {
|
29
|
+
file_size: 10132625,
|
30
|
+
file: "https://unsplash.com/photos/ZXHgEIWELYA/download?force=true",
|
31
|
+
sha: "b701889c51802f6f382206e6d0aa3509c8f98e10f26bd0725ae91d93e148fe7a"
|
32
|
+
}
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
@@ -0,0 +1,41 @@
|
|
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
|
@@ -0,0 +1,48 @@
|
|
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
|
@@ -0,0 +1,27 @@
|
|
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
|
@@ -0,0 +1,13 @@
|
|
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
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
RSpec.describe Fontist::SystemFont do
|
4
|
+
describe ".find" do
|
5
|
+
context "with a vlaid existing font" do
|
6
|
+
it "returns the complete font path" do
|
7
|
+
name = "DejaVuSerif.ttf"
|
8
|
+
dejavu_ttf = Fontist::SystemFont.find(name, sources: [font_sources])
|
9
|
+
|
10
|
+
expect(dejavu_ttf).not_to be_nil
|
11
|
+
expect(dejavu_ttf.first).to include("spec/fixtures/fonts/")
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
context "with invalid font" do
|
16
|
+
it "returns nill to the caller" do
|
17
|
+
name = "invalid-font.ttf"
|
18
|
+
invalid_font = Fontist::SystemFont.find(name, sources: [font_sources])
|
19
|
+
|
20
|
+
expect(invalid_font).to be_nil
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def font_sources
|
26
|
+
@font_sources ||= Fontist.root_path.join("spec/fixtures/fonts/*")
|
27
|
+
end
|
28
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -8,6 +8,9 @@ RSpec.configure do |config|
|
|
8
8
|
# Disable RSpec exposing methods globally on `Module` and `main`
|
9
9
|
config.disable_monkey_patching!
|
10
10
|
|
11
|
+
# Skip the actual API calls by default
|
12
|
+
config.filter_run_excluding api_call: true
|
13
|
+
|
11
14
|
config.expect_with :rspec do |c|
|
12
15
|
c.syntax = :expect
|
13
16
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fontist
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ribose Inc.
|
@@ -9,8 +9,50 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2020-03
|
12
|
+
date: 2020-05-03 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: down
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - "~>"
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '5.0'
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - "~>"
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '5.0'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: libmspack
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - "~>"
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: 0.1.0
|
35
|
+
type: :runtime
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - "~>"
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: 0.1.0
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: pry
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
14
56
|
- !ruby/object:Gem::Dependency
|
15
57
|
name: bundler
|
16
58
|
requirement: !ruby/object:Gem::Requirement
|
@@ -61,19 +103,37 @@ executables: []
|
|
61
103
|
extensions: []
|
62
104
|
extra_rdoc_files: []
|
63
105
|
files:
|
106
|
+
- ".github/workflows/macosx.yml"
|
64
107
|
- ".github/workflows/ubuntu.yml"
|
108
|
+
- ".github/workflows/windows.yml"
|
65
109
|
- ".gitignore"
|
66
110
|
- ".rspec"
|
67
111
|
- Gemfile
|
68
112
|
- LICENSE.txt
|
69
113
|
- README.md
|
70
114
|
- Rakefile
|
115
|
+
- assets/fonts/.keep
|
116
|
+
- assets/source.yml
|
71
117
|
- bin/console
|
72
118
|
- bin/rspec
|
73
119
|
- bin/setup
|
74
120
|
- fontist.gemspec
|
75
121
|
- lib/fontist.rb
|
122
|
+
- lib/fontist/downloader.rb
|
123
|
+
- lib/fontist/errors.rb
|
124
|
+
- lib/fontist/finder.rb
|
125
|
+
- lib/fontist/installer.rb
|
126
|
+
- lib/fontist/ms_vista_font.rb
|
127
|
+
- lib/fontist/source.rb
|
128
|
+
- lib/fontist/system_font.rb
|
76
129
|
- lib/fontist/version.rb
|
130
|
+
- spec/fixtures/fonts/DejaVuSerif.ttf
|
131
|
+
- spec/fontist/downloader_spec.rb
|
132
|
+
- spec/fontist/finder_spec.rb
|
133
|
+
- spec/fontist/installer_spec.rb
|
134
|
+
- spec/fontist/ms_vista_font_spec.rb
|
135
|
+
- spec/fontist/source_spec.rb
|
136
|
+
- spec/fontist/system_font_spec.rb
|
77
137
|
- spec/fontist_spec.rb
|
78
138
|
- spec/spec_helper.rb
|
79
139
|
homepage: https://github.com/fontist/fontist
|