dragonfly_fonts 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +23 -0
  3. data/Dockerfile +15 -0
  4. data/Gemfile +4 -0
  5. data/Guardfile +8 -0
  6. data/LICENSE.txt +22 -0
  7. data/README.md +196 -0
  8. data/Rakefile +9 -0
  9. data/circle.yml +23 -0
  10. data/docker-compose.yml +15 -0
  11. data/dragonfly_fonts.gemspec +28 -0
  12. data/lib/dragonfly_fonts.rb +8 -0
  13. data/lib/dragonfly_fonts/analysers/bbox.rb +35 -0
  14. data/lib/dragonfly_fonts/analysers/font_info.rb +15 -0
  15. data/lib/dragonfly_fonts/analysers/glyphs.rb +14 -0
  16. data/lib/dragonfly_fonts/analysers/gsub_tables.rb +14 -0
  17. data/lib/dragonfly_fonts/plugin.rb +43 -0
  18. data/lib/dragonfly_fonts/processors/correct_metrics.rb +21 -0
  19. data/lib/dragonfly_fonts/processors/encode.rb +57 -0
  20. data/lib/dragonfly_fonts/processors/extract_glyph.rb +19 -0
  21. data/lib/dragonfly_fonts/processors/normalize_names.rb +17 -0
  22. data/lib/dragonfly_fonts/processors/set_dimensions.rb +24 -0
  23. data/lib/dragonfly_fonts/processors/set_ttf_names.rb +52 -0
  24. data/lib/dragonfly_fonts/processors/set_underline.rb +26 -0
  25. data/lib/dragonfly_fonts/processors/set_width.rb +25 -0
  26. data/lib/dragonfly_fonts/processors/set_woff_metadata.rb +23 -0
  27. data/lib/dragonfly_fonts/processors/ttf_autohint.rb +21 -0
  28. data/lib/dragonfly_fonts/processors/web_friendly.rb +17 -0
  29. data/lib/dragonfly_fonts/unicode_ranges.rb +89 -0
  30. data/lib/dragonfly_fonts/version.rb +3 -0
  31. data/samples/Arial.ttf +0 -0
  32. data/samples/Inconsolata.otf +0 -0
  33. data/script/dimensions.py +28 -0
  34. data/script/font_info.py +49 -0
  35. data/script/glyphs.py +25 -0
  36. data/script/gsub_tables.py +43 -0
  37. data/script/normalize_names.sh +13 -0
  38. data/script/underline.py +20 -0
  39. data/script/webfonts.pe +49 -0
  40. data/script/woff_meta.py +81 -0
  41. data/test/dragonfly_fonts/analysers/bbox_test.rb +48 -0
  42. data/test/dragonfly_fonts/analysers/font_info_test.rb +65 -0
  43. data/test/dragonfly_fonts/analysers/glyphs_test.rb +27 -0
  44. data/test/dragonfly_fonts/analysers/gsub_tables_test.rb +42 -0
  45. data/test/dragonfly_fonts/plugin_test.rb +76 -0
  46. data/test/dragonfly_fonts/processors/correct_metrics_test.rb +22 -0
  47. data/test/dragonfly_fonts/processors/encode_test.rb +36 -0
  48. data/test/dragonfly_fonts/processors/extract_glyph_test.rb +22 -0
  49. data/test/dragonfly_fonts/processors/normalize_names_test.rb +18 -0
  50. data/test/dragonfly_fonts/processors/set_dimensions_test.rb +26 -0
  51. data/test/dragonfly_fonts/processors/set_ttf_names_test.rb +23 -0
  52. data/test/dragonfly_fonts/processors/set_underline_test.rb +22 -0
  53. data/test/dragonfly_fonts/processors/set_width_test.rb +48 -0
  54. data/test/dragonfly_fonts/processors/set_woff_metadata_test.rb +28 -0
  55. data/test/dragonfly_fonts/processors/ttf_autohint_test.rb +18 -0
  56. data/test/dragonfly_fonts/processors/web_friendly_test.rb +18 -0
  57. data/test/test_helper.rb +21 -0
  58. metadata +215 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e8295884fc4ed5f5a1211ca7451663442b95c58b
4
+ data.tar.gz: 363818977f8bb82904d0a78e585ace9514cc9984
5
+ SHA512:
6
+ metadata.gz: cdee62f76a8b86bd25611308185c272ee092d46c1127e7f6fe33671d5f49a06f3c9e5ae3dc171f7eb7a33c298df968816ef1591c5b0e0a3ed9d596a8852802af
7
+ data.tar.gz: 9f268f9eb280eff1b46b2da18d9b8c498030bbd24e913cf503c922a20bfca0547d76221f3fb43fb15c968e6915e0162669c1c651a5f53211c2a8ed13b3ffead5
@@ -0,0 +1,23 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
23
+ dragonfly.log
@@ -0,0 +1,15 @@
1
+ FROM tomasce/modulor-base:latest
2
+ MAINTAINER Tomas Celizna <tomas.celizna@gmail.com>
3
+
4
+ RUN mkdir /app
5
+ WORKDIR /app
6
+
7
+ RUN mkdir lib
8
+ RUN mkdir lib/dragonfly_fonts
9
+
10
+ ADD Gemfile Gemfile
11
+ ADD dragonfly_fonts.gemspec dragonfly_fonts.gemspec
12
+ ADD lib/dragonfly_fonts/version.rb lib/dragonfly_fonts/version.rb
13
+
14
+ RUN bundle install
15
+ ADD . /app
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in dragonfly_fonts.gemspec
4
+ gemspec
@@ -0,0 +1,8 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ guard :minitest do
5
+ watch(%r{^lib/(.+)\.rb$}) { |m| "test/#{m[1]}_test.rb" }
6
+ watch(%r{^test/.+_test\.rb$})
7
+ watch(%r{^test/test_helper\.rb$}) { 'test' }
8
+ end
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Tomas Celizna
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,196 @@
1
+ # Dragonfly Fonts
2
+
3
+ [![Circle CI](https://circleci.com/gh/tomasc/dragonfly_fonts.svg?style=svg&circle-token=3b836116bd1aaa6b76103b45ab0caef112b3df94)](https://circleci.com/gh/tomasc/dragonfly_fonts)
4
+
5
+ Wraps common font-related tasks into [Dragonfly](http://markevans.github.io/dragonfly) analysers and processors.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'dragonfly_fonts'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install dragonfly_fonts
20
+
21
+ ## Dependencies
22
+
23
+ ### FontForge
24
+
25
+ You will need [FontForge](http://fontforge.github.io) with Python extensions installed.
26
+
27
+ Using [Homebrew](http://brew.sh):
28
+
29
+ $ brew install fontforge --enable-pyextension
30
+
31
+ Using debian/ubuntu packages:
32
+
33
+ $ sudo apt-get install fontforge python-fontforge
34
+
35
+ ### ttf2eot
36
+
37
+ See [ttf2eot](http://code.google.com/p/ttf2eot).
38
+
39
+ ### ttfautohint
40
+
41
+ See [ttfautohint](http://www.freetype.org/ttfautohint/doc/ttfautohint.html).
42
+
43
+ ### woff2
44
+
45
+ See [woff2](https://github.com/google/woff2).
46
+
47
+ ## Usage
48
+
49
+ Add the `:fonts` plugin to your Dragonfly config block:
50
+
51
+ ```ruby
52
+ Dragonfly.app.configure do
53
+ plugin :fonts
54
+ end
55
+ ```
56
+
57
+ ## Analysers
58
+
59
+ ### Bbox
60
+
61
+ Returns `Struct.new("Bbox", :glyph, :min_x, :min_y, :max_x, :max_y, :width, :height)` representing the glyph's bounding box.
62
+
63
+ ```ruby
64
+ DragonflyFonts::Analysers::Bbox.new.call(font, glyph)
65
+ ```
66
+
67
+ ### Font Info
68
+
69
+ Returns information about the font as a Hash with the following keys: `:ascent`, `:cap_height`, `:comment`, `:copyright`, `:default_base_filename`, `:descent`, `:descriptor`, `:designer`, `:designer_url`, `:em`, `:embedding_restrictions`, `:encoding`, `:familyname`, `:fontlog`, `:fontname`, `:fullname`, `:license`, `:license_url`, `:path`, `:sfnt_revision`, `:trademark`, `:upos`, `:uwidth`, `:vendor_url`, `:version`, `:weight`, `:woff_metadata`, `:woff_revision`, `:x_height`.
70
+
71
+ ```ruby
72
+ font.font_info
73
+ ```
74
+
75
+ ### Glyphs
76
+
77
+ Returns `Array` of all glyphs contained in the font, each glyph represented by a Hash with the following keys: `:glyphclass`, `:glyphname`, `:encoding`, `:script`, `:width`, `:unicode`.
78
+
79
+ ```ruby
80
+ font.glyphs
81
+ ```
82
+
83
+ ### GSUB Tables
84
+
85
+ Returns `Array` of gsub tables in the font.
86
+
87
+ ```ruby
88
+ font.gsub_tables
89
+ ```
90
+
91
+ ## Processors
92
+
93
+ ### Correct Metrics
94
+
95
+ Normalizes ascent and descent values.
96
+
97
+ ```ruby
98
+ font.correct_metrics
99
+ ```
100
+
101
+ ### Encode
102
+
103
+ Allows for conversion to EOT, OTF, SVG, TTF, WOFF, WOFF2.
104
+
105
+ ```ruby
106
+ font.encode(:woff)
107
+ ```
108
+
109
+ * OTF, SVG, TTF, WOFF conversion is handled by `FontForge`.
110
+ * EOT conversion is handled by `ttf2eot`. The input font needs to be in TTF format. Due to bug in IE, font FullName MUST begin with FamilyName. For example, if FamilyName is fontello, then FullName should be fontello regular and so on. In this condition is not satisfyed, then font will not be shown in IE.
111
+ * WOFF2 conversion is handled by `woff2`.
112
+
113
+ ### Extract Glyph
114
+
115
+ Extracts specified glyph in SVG format.
116
+
117
+ ```ruby
118
+ font.extract_glyph('A')
119
+ ```
120
+
121
+ ### Normalize Names
122
+
123
+ Fix for rejected EOT's in IE8.
124
+
125
+ ```ruby
126
+ font.normalize_names
127
+ ```
128
+
129
+ ### Set Dimensions
130
+
131
+ Adjust ascent & descent by an increment of.
132
+
133
+ ```ruby
134
+ font.set_dimensions(ascent: 10, descent: -10)
135
+ ```
136
+
137
+ ### Set TTF Names
138
+
139
+ Allows to set the following TTF properties: `:compatible_full`, `:copyright`, `:description`, `:designer`, `:designer_url`, `:fontname`, `:fullname`, `:license`, `:license_url`, `:manufacturer`, `:postscript_cid`, `:postscript_name`, `:preferred_family`, `:preferred_subfamily`, `:sample_text`, `:trademark`, `:uid`, `:vendor_url`, `:version`, `:weight`. See [docs at Adobe](http://partners.adobe.com/public/developer/opentype/index_name.html#enc4) for more details.
140
+
141
+ ```ruby
142
+ ttf_names = { designer: 'John Doe' }
143
+ font.set_ttf_names(ttf_names)
144
+ ```
145
+
146
+ ### Set Underline
147
+
148
+ Allows to set underline properties: position and width.
149
+
150
+ ```ruby
151
+ font.set_underline({ upos: 1, uwidth: 1 })
152
+ ```
153
+
154
+ ### Set Width
155
+
156
+ Sets width of each character. The relative parameter can have the following values:
157
+
158
+ * when 0 the vertical width will be set exactly to `width` value
159
+ * when 1 then the vertical width will be incremented by `width` value
160
+ * when 2 then the vertical width will be scaled by `width` value/100.0.
161
+
162
+ ```ruby
163
+ font.set_width(width, relative=1)
164
+ ```
165
+
166
+ ### Set WOFF Metadata
167
+
168
+ Converts font to WOFF and sets license-related values of embedded XML metadata. The rest of the metadata is automatically inferred from font properties (see `#set_ttf_names`).
169
+
170
+ ```ruby
171
+ font.set_woff_metadata(uniqueid, licensee_name)
172
+ ```
173
+
174
+ ### TTF autohint
175
+
176
+ Generates FreeType auto hints. See [ttfautohint](http://www.freetype.org/ttfautohint/doc/ttfautohint.html).
177
+
178
+ ```ruby
179
+ font.ttf_autohint
180
+ ```
181
+
182
+ ### Web Friendly
183
+
184
+ Make web friendly.
185
+
186
+ ```ruby
187
+ font.web_friendly
188
+ ```
189
+
190
+ ## Contributing
191
+
192
+ 1. Fork it ( https://github.com/tomasc/dragonfly_fonts/fork )
193
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
194
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
195
+ 4. Push to the branch (`git push origin my-new-feature`)
196
+ 5. Create a new Pull Request
@@ -0,0 +1,9 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.libs << 'test'
6
+ t.pattern = 'test/**/*_test.rb'
7
+ end
8
+
9
+ task :default => :test
@@ -0,0 +1,23 @@
1
+ machine:
2
+ environment:
3
+ IMAGE: dragonfly_fonts_$CIRCLE_BRANCH
4
+ TAG: $CIRCLE_SHA1
5
+
6
+ services:
7
+ - docker
8
+
9
+ dependencies:
10
+ cache_directories:
11
+ - "~/docker"
12
+
13
+ override:
14
+ - if [[ -e ~/docker/image_$CIRCLE_BRANCH.tar ]]; then docker load -i ~/docker/image_$CIRCLE_BRANCH.tar; fi
15
+
16
+ - docker build -t $IMAGE:$TAG .
17
+ - docker tag $IMAGE:$TAG $IMAGE:latest
18
+
19
+ - mkdir -p ~/docker; docker save $DOCKER_USER/$IMAGE:$TAG > ~/docker/image_$CIRCLE_BRANCH.tar
20
+
21
+ test:
22
+ override:
23
+ - docker run -e "RAILS_ENV=test" $IMAGE:$TAG bundle exec rake
@@ -0,0 +1,15 @@
1
+ version: '2'
2
+
3
+ services:
4
+ test:
5
+ build:
6
+ context: .
7
+ dockerfile: 'Dockerfile'
8
+ command: 'bundle exec guard'
9
+ environment:
10
+ RAILS_ENV: test
11
+ privileged: true
12
+ tty: true
13
+ working_dir: /app
14
+ volumes:
15
+ - .:/app
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'dragonfly_fonts/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "dragonfly_fonts"
8
+ spec.version = DragonflyFonts::VERSION
9
+ spec.authors = ["Tomas Celizna"]
10
+ spec.email = ["tomas.celizna@gmail.com"]
11
+ spec.summary = %q{Wraps common font-related tasks into Dragonfly analysers and processors.}
12
+ spec.homepage = "https://github.com/tomasc/dragonfly_fonts"
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_dependency "dragonfly", "~> 1.0"
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.6"
23
+ spec.add_development_dependency "rake"
24
+ spec.add_development_dependency "nokogiri"
25
+ spec.add_development_dependency "guard"
26
+ spec.add_development_dependency "guard-minitest"
27
+ spec.add_development_dependency "minitest"
28
+ end
@@ -0,0 +1,8 @@
1
+ require 'dragonfly'
2
+ require 'dragonfly_fonts/plugin'
3
+ require 'dragonfly_fonts/unicode_ranges'
4
+ require 'dragonfly_fonts/version'
5
+
6
+ module DragonflyFonts
7
+ SCRIPT_DIR = Pathname.new(File.expand_path('../../script', __FILE__))
8
+ end
@@ -0,0 +1,35 @@
1
+ require 'json'
2
+
3
+ module DragonflyFonts
4
+ module Analysers
5
+ class Bbox
6
+ def call(font, glyph)
7
+ res = font.shell_eval do |path|
8
+ "#{fontforge_command} -lang=ff -c 'Open($1); Select(\"#{glyph}\"); Print(GlyphInfo(\"BBox\"));' #{path}"
9
+ end
10
+
11
+ dimensions = JSON.parse(res)
12
+
13
+ Struct::Bbox.new(
14
+ glyph,
15
+
16
+ dimensions[0],
17
+ dimensions[1],
18
+ dimensions[2],
19
+ dimensions[3],
20
+
21
+ (dimensions[2] - dimensions[0]),
22
+ (dimensions[3] - dimensions[1])
23
+ )
24
+ end
25
+
26
+ private # =============================================================
27
+
28
+ def fontforge_command
29
+ 'fontforge'
30
+ end
31
+ end
32
+
33
+ Struct.new('Bbox', :glyph, :min_x, :min_y, :max_x, :max_y, :width, :height)
34
+ end
35
+ end
@@ -0,0 +1,15 @@
1
+ require 'json'
2
+
3
+ module DragonflyFonts
4
+ module Analysers
5
+ class FontInfo
6
+ # see http://dmtr.org/ff.php#Font
7
+ def call(font)
8
+ details = font.shell_eval do |path|
9
+ "#{DragonflyFonts::SCRIPT_DIR.join('font_info.py')} #{path}"
10
+ end
11
+ JSON.parse(details)
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,14 @@
1
+ require 'json'
2
+
3
+ module DragonflyFonts
4
+ module Analysers
5
+ class Glyphs
6
+ def call(font)
7
+ details = font.shell_eval do |path|
8
+ "#{DragonflyFonts::SCRIPT_DIR.join('glyphs.py')} #{path}"
9
+ end
10
+ JSON.parse(details)
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,14 @@
1
+ require 'json'
2
+
3
+ module DragonflyFonts
4
+ module Analysers
5
+ class GsubTables
6
+ def call(font)
7
+ details = font.shell_eval do |path|
8
+ "#{DragonflyFonts::SCRIPT_DIR.join('gsub_tables.py')} #{path}"
9
+ end
10
+ JSON.parse(details)
11
+ end
12
+ end
13
+ end
14
+ end