fontist 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4e446487ef01cae5da6b38d363e22e6a4210880f88a4741762a234598db88940
4
- data.tar.gz: 8d622e34e2a80ae41018238d99b7be5781dbd785d8505d8a69e63aa48a70706f
3
+ metadata.gz: 4a5ce61ee68294a97524ff87c5e618bea5d1e29ab9df3387e8dee8012c424ac1
4
+ data.tar.gz: 478d00a93ca6a5e3ef247f1d9d3b4a925b281d50400f161bdd4ff86d3060fe1f
5
5
  SHA512:
6
- metadata.gz: 106f4f4c64991ad9301eb2315e4b98bab19973d393a3daed060ca0d2014c4d8236ebb7de4cf6dceee7e9e4fed849111238d3d2231c83e5c3aeb6f8c3a385a4eb
7
- data.tar.gz: 5fb219fb32f6d8616924abaabe4451fba80e0be2f2986ac0b7aa574511884dec670a33635c3edad1eec817f6126f0017b995a7aa876f8711a87be8570efc6c48
6
+ metadata.gz: acf8df0ad6831f6e10602e854fb32042c3d1bece526c2293e8a6a71c76d65d2092f69a4a3d161e2eef863de74f5380253b7a1a02ad7ec9e718b5c4676796ec69
7
+ data.tar.gz: a2c9485dc91adee02a8926a0c0ac52a223d26e16f37396adb914e902851453486c9be84ec3d7ae6a1220ba5a0af51751d4c5fd9840692ca15de7079b9830c9a9
data/.gitignore CHANGED
@@ -8,7 +8,6 @@
8
8
  /tmp/
9
9
  Gemfile.lock
10
10
  /assets/*
11
- !/assets/source.yml
12
11
  !/assets/fonts/.keep
13
12
 
14
13
  # rspec failure tracking
data/fontist.gemspec CHANGED
@@ -23,6 +23,7 @@ Gem::Specification.new do |spec|
23
23
 
24
24
  spec.add_runtime_dependency "down", "~> 5.0"
25
25
  spec.add_runtime_dependency "libmspack", "~> 0.1.0"
26
+ spec.add_runtime_dependency "rubyzip", "~> 2.3.0"
26
27
 
27
28
  spec.add_development_dependency "pry"
28
29
  spec.add_development_dependency "bundler", "~> 2.0"
data/lib/fontist.rb CHANGED
@@ -5,7 +5,7 @@ require "fontist/finder"
5
5
  require "fontist/source"
6
6
  require "fontist/installer"
7
7
  require "fontist/system_font"
8
- require "fontist/ms_vista_font"
8
+ require "fontist/formulas"
9
9
 
10
10
  module Fontist
11
11
  def self.lib_path
@@ -20,6 +20,10 @@ module Fontist
20
20
  Fontist.root_path.join("assets")
21
21
  end
22
22
 
23
+ def self.data_path
24
+ Fontist.lib_path.join("fontist", "data")
25
+ end
26
+
23
27
  def self.fontist_path
24
28
  Pathname.new(Dir.home).join(".fontist")
25
29
  end
@@ -0,0 +1,39 @@
1
+ msvista:
2
+ agreement: "yes"
3
+
4
+ fonts:
5
+ - CALIBRI.TTF
6
+ - CALIBRII.TTF
7
+ - CAMBRIA.TTC
8
+ - CAMBRIAI.TTF
9
+ - CANDARA.TTF
10
+ - CANDARAI.TTF
11
+ - CONSOLA.TTF
12
+ - CONSOLAI.TTF
13
+ - CONSTAN.TTF
14
+ - CONSTANI.TTF
15
+ - CORBEL.TTF
16
+ - CORBELI.TTF
17
+ - MEIRYO.TTC
18
+ - CALIBRIB.TTF
19
+ - CALIBRIZ.TTF
20
+ - CAMBRIAB.TTF
21
+ - CAMBRIAZ.TTF
22
+ - CANDARAB.TTF
23
+ - CANDARAZ.TTF
24
+ - CONSOLAB.TTF
25
+ - CONSOLAZ.TTF
26
+ - CONSTANB.TTF
27
+ - CONSTANZ.TTF
28
+ - CORBELB.TTF
29
+ - CORBELZ.TTF
30
+ - MEIRYOB.TTC
31
+
32
+ file_size: "62914560"
33
+ sha: "249473568eba7a1e4f95498acba594e0f42e6581add4dead70c1dfb908a09423"
34
+ urls:
35
+ - "https://www.dropbox.com/s/dl/6lclhxpydwgkjzh/PowerPointViewer.exe?dl=1"
36
+ - "https://web.archive.org/web/20171225132744/http://download.microsoft.com/download/E/6/7/E675FFFC-2A6D-4AB0-B3EB-27C9F8C8F696/PowerPointViewer.exe"
37
+
38
+ license: |
39
+ Complete MS licence;
@@ -0,0 +1,51 @@
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
@@ -0,0 +1,21 @@
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
+ formulas:
20
+ - ./formulas/ms_vista.yml
21
+ - ./formulas/source_font.yml
@@ -3,9 +3,10 @@ require "digest"
3
3
 
4
4
  module Fontist
5
5
  class Downloader
6
- def initialize(file, file_size: nil, sha: nil)
6
+ def initialize(file, file_size: nil, sha: nil, progress: nil)
7
7
  @sha = sha
8
8
  @file = file
9
+ @progress = progress
9
10
  @file_size = file_size || default_file_size
10
11
  end
11
12
 
@@ -19,7 +20,7 @@ module Fontist
19
20
  end
20
21
 
21
22
  def raise_invalid_file
22
- raise(Fontist::Error, "Invalid / Tempared file")
23
+ raise(Fontist::Errors::TemparedFileError)
23
24
  end
24
25
 
25
26
  def self.download(file, options = {})
@@ -48,7 +49,7 @@ module Fontist
48
49
  Down.download(
49
50
  @file,
50
51
  progress_proc: -> (progress) {
51
- bar.increment(progress / byte_to_megabyte)
52
+ bar.increment(progress / byte_to_megabyte) if @progress === true
52
53
  }
53
54
  )
54
55
  end
@@ -3,5 +3,6 @@ module Fontist
3
3
  class LicensingError < StandardError; end
4
4
  class MissingFontError < StandardError; end
5
5
  class NonSupportedFontError < StandardError; end
6
+ class TemparedFileError < StandardError; end
6
7
  end
7
8
  end
@@ -21,7 +21,7 @@ module Fontist
21
21
  end
22
22
 
23
23
  def remote_source
24
- Fontist::Source.all.remote.to_h.select do |key, value|
24
+ Fontist::Source.formulas.to_h.select do |key, value|
25
25
  !value.fonts.grep(/#{name}/i).empty?
26
26
  end
27
27
  end
@@ -0,0 +1,8 @@
1
+ require "fontist/formulas/base"
2
+ require "fontist/formulas/ms_vista"
3
+ require "fontist/formulas/source_font"
4
+
5
+ module Fontist
6
+ module Formulas
7
+ end
8
+ end
@@ -0,0 +1,25 @@
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
@@ -0,0 +1,74 @@
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
@@ -0,0 +1,48 @@
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
@@ -21,7 +21,10 @@ module Fontist
21
21
  attr_reader :font_name, :confirmation, :options
22
22
 
23
23
  def downloaders
24
- { msvista: Fontist::MsVistaFont }
24
+ {
25
+ msvista: Fontist::Formulas::MsVista,
26
+ source_front: Fontist::Formulas::SourceFont,
27
+ }
25
28
  end
26
29
 
27
30
  def find_system_font
@@ -29,16 +32,16 @@ module Fontist
29
32
  end
30
33
 
31
34
  def download_font
32
- if font_source
33
- downloader = downloaders[font_source.first]
35
+ if !font_sources.empty?
36
+ downloader = downloaders[font_sources.first]
34
37
  downloader.fetch_font(font_name, confirmation: confirmation)
35
38
  end
36
39
  end
37
40
 
38
- def font_source
39
- @font_source ||= Fontist::Source.all.remote.to_h.select do |key, value|
41
+ def font_sources
42
+ @font_sources ||= Fontist::Source.formulas.to_h.select do |key, value|
40
43
  !value.fonts.grep(/#{font_name}/i).empty?
41
- end.first
44
+ end.keys
42
45
  end
43
46
  end
44
47
  end
@@ -8,24 +8,51 @@ module Fontist
8
8
  new.all
9
9
  end
10
10
 
11
+ def self.formulas
12
+ new.formulas
13
+ end
14
+
11
15
  def all
12
16
  source_data
13
17
  end
14
18
 
19
+ def formulas
20
+ formulas_data
21
+ end
22
+
15
23
  private
16
24
 
17
25
  def source_data
18
- @source_data ||= JSON.parse(
19
- yaml_data.to_json, object_class: OpenStruct
20
- )
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
21
48
  end
22
49
 
23
- def yaml_data
24
- YAML.load(File.open(yaml_file))
50
+ def yaml_file(file)
51
+ Fontist.data_path.join(file)
25
52
  end
26
53
 
27
- def yaml_file
28
- Fontist.assets_path.join("source.yml")
54
+ def yaml_data(file_name = "source.yml")
55
+ YAML.load(File.open(yaml_file(file_name)))
29
56
  end
30
57
  end
31
58
  end
@@ -1,3 +1,3 @@
1
1
  module Fontist
2
- VERSION = "0.2.0".freeze
2
+ VERSION = "0.3.0".freeze
3
3
  end
@@ -1,7 +1,6 @@
1
1
  require "spec_helper"
2
-
3
2
  RSpec.describe Fontist::Downloader do
4
- describe ".download", api_call: true do
3
+ describe ".download", file_download: true do
5
4
  it "return the valid downloaded file" do
6
5
  tempfile = Fontist::Downloader.download(
7
6
  sample_file[:file],
@@ -20,15 +19,15 @@ RSpec.describe Fontist::Downloader do
20
19
  sha: sample_file[:sha] + "mm",
21
20
  file_size: sample_file[:file_size]
22
21
  )
23
- }.to raise_error(Fontist::Error, "Invalid / Tempared file")
22
+ }.to raise_error(Fontist::Errors::TemparedFileError)
24
23
  end
25
24
  end
26
25
 
27
26
  def sample_file
28
27
  @sample_file ||= {
29
- file_size: 10132625,
30
- file: "https://unsplash.com/photos/ZXHgEIWELYA/download?force=true",
31
- sha: "b701889c51802f6f382206e6d0aa3509c8f98e10f26bd0725ae91d93e148fe7a"
28
+ file_size: 150899,
29
+ file: "https://drive.google.com/u/0/uc?id=1Kk-rpLyQk98ubgxhTRKD2ZkMoY9KqKXk&export=download",
30
+ sha: "5e513e4bfdada0ff10dd5b96414fcaeade84e235ce043865416ad7673cb6f3d8"
32
31
  }
33
32
  end
34
33
  end
@@ -1,11 +1,11 @@
1
1
  require "spec_helper"
2
2
 
3
- RSpec.describe Fontist::MsVistaFont do
3
+ RSpec.describe Fontist::Formulas::MsVista do
4
4
  describe ".fetch_font" do
5
- context "with valid licence", api_call: true do
5
+ context "with valid licence", file_download: true do
6
6
  it "downloads and returns font paths" do
7
7
  name = "CANDARAI.TTF"
8
- fonts = Fontist::MsVistaFont.fetch_font(
8
+ fonts = Fontist::Formulas::MsVista.fetch_font(
9
9
  name, confirmation: "yes", force_download: true
10
10
  )
11
11
 
@@ -19,7 +19,7 @@ RSpec.describe Fontist::MsVistaFont do
19
19
  font_name = "CANDARAI.TTF"
20
20
 
21
21
  expect {
22
- Fontist::MsVistaFont.fetch_font(font_name, confirmation: "no")
22
+ Fontist::Formulas::MsVista.fetch_font(font_name, confirmation: "no")
23
23
  }.to raise_error(Fontist::Errors::LicensingError)
24
24
  end
25
25
  end
@@ -0,0 +1,18 @@
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
@@ -5,9 +5,9 @@ RSpec.describe Fontist::Installer do
5
5
  context "with already downloaded fonts", skip_in_windows: true do
6
6
  it "returns the font path" do
7
7
  name = "CALIBRI.TTF"
8
- Fontist::MsVistaFont.fetch_font(name, confirmation: "yes")
8
+ Fontist::Formulas::MsVista.fetch_font(name, confirmation: "yes")
9
9
 
10
- allow(Fontist::MsVistaFont).to receive(:fetch_font).and_return(nil)
10
+ allow(Fontist::Formulas::MsVista).to receive(:fetch_font).and_return(nil)
11
11
  paths = Fontist::Installer.download(name, confirmation: "yes")
12
12
 
13
13
  expect(paths.first).to include("fonts/#{name}")
@@ -6,8 +6,19 @@ RSpec.describe Fontist::Source do
6
6
  sources = Fontist::Source.all
7
7
 
8
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")
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).to include("CALIBRI.TTF")
11
22
  end
12
23
  end
13
24
  end
data/spec/spec_helper.rb CHANGED
@@ -1,15 +1,18 @@
1
1
  require "bundler/setup"
2
2
  require "fontist"
3
3
 
4
+ Dir["./spec/support/**/*.rb"].sort.each { |file| require file }
5
+
4
6
  RSpec.configure do |config|
5
7
  # Enable flags like --only-failures and --next-failure
6
8
  config.example_status_persistence_file_path = ".rspec_status"
9
+ config.include Fontist::Helper
7
10
 
8
11
  # Disable RSpec exposing methods globally on `Module` and `main`
9
12
  config.disable_monkey_patching!
10
13
 
11
- # Skip the actual API calls by default
12
- config.filter_run_excluding api_call: true
14
+ # Skip the actual file_download by default
15
+ config.filter_run_excluding file_download: true
13
16
 
14
17
  config.expect_with :rspec do |c|
15
18
  c.syntax = :expect
@@ -0,0 +1,8 @@
1
+ module Fontist
2
+ module Helper
3
+ def stub_fontist_path_to_assets
4
+ allow(Fontist).to receive(:fontist_path).and_return(Fontist.assets_path)
5
+ end
6
+ end
7
+ end
8
+
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.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2020-05-03 00:00:00.000000000 Z
12
+ date: 2020-05-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: down
@@ -39,6 +39,20 @@ dependencies:
39
39
  - - "~>"
40
40
  - !ruby/object:Gem::Version
41
41
  version: 0.1.0
42
+ - !ruby/object:Gem::Dependency
43
+ name: rubyzip
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: 2.3.0
49
+ type: :runtime
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: 2.3.0
42
56
  - !ruby/object:Gem::Dependency
43
57
  name: pry
44
58
  requirement: !ruby/object:Gem::Requirement
@@ -113,29 +127,36 @@ files:
113
127
  - README.md
114
128
  - Rakefile
115
129
  - assets/fonts/.keep
116
- - assets/source.yml
117
130
  - bin/console
118
131
  - bin/rspec
119
132
  - bin/setup
120
133
  - fontist.gemspec
121
134
  - lib/fontist.rb
135
+ - lib/fontist/data/formulas/ms_vista.yml
136
+ - lib/fontist/data/formulas/source_font.yml
137
+ - lib/fontist/data/source.yml
122
138
  - lib/fontist/downloader.rb
123
139
  - lib/fontist/errors.rb
124
140
  - lib/fontist/finder.rb
141
+ - lib/fontist/formulas.rb
142
+ - lib/fontist/formulas/base.rb
143
+ - lib/fontist/formulas/ms_vista.rb
144
+ - lib/fontist/formulas/source_font.rb
125
145
  - lib/fontist/installer.rb
126
- - lib/fontist/ms_vista_font.rb
127
146
  - lib/fontist/source.rb
128
147
  - lib/fontist/system_font.rb
129
148
  - lib/fontist/version.rb
130
149
  - spec/fixtures/fonts/DejaVuSerif.ttf
131
150
  - spec/fontist/downloader_spec.rb
132
151
  - spec/fontist/finder_spec.rb
152
+ - spec/fontist/formulas/ms_vista_spec.rb
153
+ - spec/fontist/formulas/source_font_spec.rb
133
154
  - spec/fontist/installer_spec.rb
134
- - spec/fontist/ms_vista_font_spec.rb
135
155
  - spec/fontist/source_spec.rb
136
156
  - spec/fontist/system_font_spec.rb
137
157
  - spec/fontist_spec.rb
138
158
  - spec/spec_helper.rb
159
+ - spec/support/fontist_helper.rb
139
160
  homepage: https://github.com/fontist/fontist
140
161
  licenses:
141
162
  - BSD-2-Clause
data/assets/source.yml DELETED
@@ -1,54 +0,0 @@
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"
@@ -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