fontprocessor 27.1.3
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 +7 -0
- data/.gitignore +12 -0
- data/.rbenv-version +1 -0
- data/.rspec +0 -0
- data/.travis.yml +17 -0
- data/CHANGELOG.md +64 -0
- data/CHANGELOG_FPV14.md +20 -0
- data/Dockerfile +3 -0
- data/Gemfile +14 -0
- data/Gemfile.lock +156 -0
- data/Guardfile +5 -0
- data/README.md +6 -0
- data/Rakefile +53 -0
- data/Rakefile.base +57 -0
- data/bin/process-file +41 -0
- data/config/development.yml +5 -0
- data/config/production.yml +3 -0
- data/config/staging.yml +3 -0
- data/config/test.yml +5 -0
- data/fontprocessor.gemspec +37 -0
- data/lib/fontprocessor/config.rb +85 -0
- data/lib/fontprocessor/external/batik/batik-ttf2svg.jar +0 -0
- data/lib/fontprocessor/external/batik/lib/batik-svggen.jar +0 -0
- data/lib/fontprocessor/external/batik/lib/batik-util.jar +0 -0
- data/lib/fontprocessor/external/fontforge/subset.py +30 -0
- data/lib/fontprocessor/external/fontforge/utils.py +66 -0
- data/lib/fontprocessor/external_execution.rb +117 -0
- data/lib/fontprocessor/font_file.rb +149 -0
- data/lib/fontprocessor/font_file_naming_strategy.rb +63 -0
- data/lib/fontprocessor/font_format.rb +29 -0
- data/lib/fontprocessor/process_font_job.rb +227 -0
- data/lib/fontprocessor/processed_font_iterator.rb +89 -0
- data/lib/fontprocessor/processor.rb +790 -0
- data/lib/fontprocessor/version.rb +3 -0
- data/lib/fontprocessor.rb +16 -0
- data/scripts/build_and_test.sh +15 -0
- data/scripts/get_production_source_map.rb +53 -0
- data/spec/fixtures/bad_os2_width_class.otf +0 -0
- data/spec/fixtures/extra_language_names.otf +0 -0
- data/spec/fixtures/fixtures.rb +35 -0
- data/spec/fixtures/locked.otf +0 -0
- data/spec/fixtures/op_size.otf +0 -0
- data/spec/fixtures/ots_failure_font.otf +0 -0
- data/spec/fixtures/postscript.otf +0 -0
- data/spec/fixtures/stat_font.otf +0 -0
- data/spec/fixtures/truetype.otf +0 -0
- data/spec/lib/fontprocessor/config_spec.rb +38 -0
- data/spec/lib/fontprocessor/external_execution_spec.rb +33 -0
- data/spec/lib/fontprocessor/font_file_naming_strategy_spec.rb +13 -0
- data/spec/lib/fontprocessor/font_file_spec.rb +110 -0
- data/spec/lib/fontprocessor/process_font_job_spec.rb +317 -0
- data/spec/lib/fontprocessor/processed_font_iterator_spec.rb +128 -0
- data/spec/lib/fontprocessor/processor_spec.rb +466 -0
- data/spec/spec_helper.rb +4 -0
- data/tasks/fonts.rake +30 -0
- data/worker.rb +23 -0
- metadata +312 -0
@@ -0,0 +1,89 @@
|
|
1
|
+
module FontProcessor
|
2
|
+
MissingFilesException = Class.new(Exception)
|
3
|
+
|
4
|
+
class ProcessedFontIterator
|
5
|
+
|
6
|
+
# fontbase_id - The unique fontbase id of the desired font.
|
7
|
+
# charset_id - The integer representing the character set contained within
|
8
|
+
# this font. 1 is all, 2 is default and 3 is upper-and-lower.
|
9
|
+
# fpv - The integer representing the fontprocessing version.
|
10
|
+
# directory - Local directory of files to iterate over.
|
11
|
+
def initialize(fontbase_id, charset_id, fpv, directory, convert)
|
12
|
+
@fontbase_id = fontbase_id
|
13
|
+
@charset_id = charset_id
|
14
|
+
@fpv = fpv
|
15
|
+
@directory = directory
|
16
|
+
@convert = convert
|
17
|
+
end
|
18
|
+
|
19
|
+
# Public: Iterates over the directory, ensures all of the expected files
|
20
|
+
# are present and maps each file into a proper S3 key.
|
21
|
+
#
|
22
|
+
# Examples
|
23
|
+
#
|
24
|
+
# p = ProcessedFileIterator.new(...)
|
25
|
+
# begin
|
26
|
+
# p.each do |file, s3_key|
|
27
|
+
# puts s3
|
28
|
+
# end
|
29
|
+
# rescue MissingFilesException => e
|
30
|
+
# puts "The processed file directory is missing some expected files."
|
31
|
+
# end
|
32
|
+
#
|
33
|
+
# Returns nothing.
|
34
|
+
# Raises MissingFilesException if an expected files is missing
|
35
|
+
def each
|
36
|
+
raise MissingFilesException unless valid?
|
37
|
+
Dir.glob(File.join(@directory, "*")) do |file|
|
38
|
+
next unless file =~ /charset-\d+-(.*?)\.(.*)/
|
39
|
+
container = $1
|
40
|
+
outline = $2
|
41
|
+
|
42
|
+
s3_key = s3_key(container, outline)
|
43
|
+
yield file, s3_key
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
# Checks whether all expected files are present.
|
48
|
+
#
|
49
|
+
# Returns true if all expected files are present and false otherwise.
|
50
|
+
def valid?
|
51
|
+
files = Dir.glob(File.join(@directory, "*")).map { |f| File.basename(f) }
|
52
|
+
only_truetype = files.select { |f| f.include?(".cff") || f.include?(".otf") }.empty?
|
53
|
+
|
54
|
+
expected_truetype_files = ["dyna_base.ttf", "otf.ttf", "inst.ttf", "woff.ttf", "woff2.ttf", "woff_raw.ttf"]
|
55
|
+
expected_postscript_files = files.select { |f| f.include?("cff") }.empty? ? ["dyna_base.otf", "otf.otf", "inst.otf", "woff.otf", "woff2.otf", "woff_raw.otf"] : ["dyna_base.cff", "otf.cff", "inst.cff", "woff.cff", "woff2.cff", "woff_raw.cff"]
|
56
|
+
|
57
|
+
if only_truetype
|
58
|
+
expected_files = expected_truetype_files
|
59
|
+
else
|
60
|
+
expected_files = expected_postscript_files
|
61
|
+
if @convert
|
62
|
+
expected_files += expected_truetype_files
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
expected_files = expected_files.map { |f| "charset-#{@charset_id}-#{f}" }
|
67
|
+
missing_files = expected_files.reject { |f| files.include?(f) }
|
68
|
+
|
69
|
+
if missing_files.empty?
|
70
|
+
true
|
71
|
+
else
|
72
|
+
false
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
# Generates a fully defined S3 key which incorporates all variables used to
|
77
|
+
# process a font.
|
78
|
+
#
|
79
|
+
# container - One of "dyna_base", woff", "woff2", "otf", "inst", "svg", "woff_raw"
|
80
|
+
# outline - One of "ttf", "otf"
|
81
|
+
#
|
82
|
+
# Returns a string containing an S3 object key of the object described by
|
83
|
+
# the given attributes.
|
84
|
+
def s3_key(container, outline)
|
85
|
+
outline = outline == 'otf' ? 'cff' : outline
|
86
|
+
"#{@fontbase_id}/#{@fpv}/#{@charset_id}/#{container}.#{outline}"
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|