dragonfly_harfbuzz 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +24 -0
- data/Gemfile +4 -0
- data/Guardfile +8 -0
- data/LICENSE.txt +22 -0
- data/README.md +56 -0
- data/Rakefile +9 -0
- data/dragonfly_harfbuzz.gemspec +29 -0
- data/lib/dragonfly_harfbuzz/dom_attrs_service.rb +26 -0
- data/lib/dragonfly_harfbuzz/flatten_svg_service.rb +79 -0
- data/lib/dragonfly_harfbuzz/markup_svg_service.rb +107 -0
- data/lib/dragonfly_harfbuzz/plugin.rb +13 -0
- data/lib/dragonfly_harfbuzz/processors/hb_view.rb +49 -0
- data/lib/dragonfly_harfbuzz/version.rb +3 -0
- data/lib/dragonfly_harfbuzz.rb +12 -0
- data/samples/Inconsolata.otf +0 -0
- data/samples/test.svg +24 -0
- data/test/dragonfly_harfbuzz/flatten_svg_service_test.rb +21 -0
- data/test/dragonfly_harfbuzz/plugin_test.rb +18 -0
- data/test/dragonfly_harfbuzz/processors/hb_view_test.rb +45 -0
- data/test/minitest_helper.rb +21 -0
- metadata +180 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 2dade1afe3d3e68118083ef3d1a8cb32f1a9d68c
|
4
|
+
data.tar.gz: 6272bd78b89d2a10a2af686be45da02eb3090f04
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 976761177bd268266e083738538b1a6535d2239e687439b26c51e5d33bde47b6bff699f7e707b2e3b8522f33d0ec4453fe984c979d794e7450e9d9cd1a7476b4
|
7
|
+
data.tar.gz: 8e767fb5807961d28beb87b5f3359f0d5282c53c87c510a79275083d0730a3ba92046f293247ed5457b2a17a989c5c44d6877a6dedd3014282103c89f9ad5f43
|
data/.gitignore
ADDED
@@ -0,0 +1,24 @@
|
|
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
|
24
|
+
.DS_Store
|
data/Gemfile
ADDED
data/Guardfile
ADDED
data/LICENSE.txt
ADDED
@@ -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.
|
data/README.md
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
# Dragonfly Harfbuzz
|
2
|
+
|
3
|
+
[Harfbuzz](http://fontforge.github.io) renderer wrapped by [Dragonfly](http://markevans.github.io/dragonfly) processors.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'dragonfly_harfbuzz'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install dragonfly_harfbuzz
|
18
|
+
|
19
|
+
You will also need Harfbuzz installed.
|
20
|
+
|
21
|
+
Using [Homebrew](http://brew.sh):
|
22
|
+
|
23
|
+
$ brew install harfbuzz
|
24
|
+
|
25
|
+
Or build from source. See [Harfbuzz](http://harfbuzz.org) website for instructions.
|
26
|
+
|
27
|
+
## Usage
|
28
|
+
|
29
|
+
Add the `:harfbuzz` plugin to your Dragonfly config block:
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
Dragonfly.app.configure do
|
33
|
+
plugin :harfbuzz
|
34
|
+
# ...
|
35
|
+
end
|
36
|
+
```
|
37
|
+
|
38
|
+
Then use as:
|
39
|
+
|
40
|
+
```ruby
|
41
|
+
font.hb_view('my text', :svg, { font_size: 36 })
|
42
|
+
```
|
43
|
+
|
44
|
+
See tests and `hb-view --help-all` for more details on options.
|
45
|
+
|
46
|
+
## Options
|
47
|
+
|
48
|
+
Additionally (for `<svg>` only) you can pass two options: `markup_svg: Boolean` and `flatten_svg: Boolean`. `markup_svg` returns an `<svg>` that is organized into word and characters and marked up with additional data attributes. `flatten_svg` uses the result of `markup_svg` and further cleans up the `<svg>`, replacing the `<symbol>`, `<use>` elements with nested `<svg>`s. This is handy if you want to do some more precise animation/manipulation of the resulting `<svg>`.
|
49
|
+
|
50
|
+
## Contributing
|
51
|
+
|
52
|
+
1. Fork it ( https://github.com/tomasc/dragonfly_harfbuzz/fork )
|
53
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
54
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
55
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
56
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'dragonfly_harfbuzz/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "dragonfly_harfbuzz"
|
8
|
+
spec.version = DragonflyHarfbuzz::VERSION
|
9
|
+
spec.authors = ["Tomas Celizna"]
|
10
|
+
spec.email = ["tomas.celizna@gmail.com"]
|
11
|
+
spec.summary = %q{Harfbuzz renderer wrapped by Dragonfly processors.}
|
12
|
+
spec.homepage = "https://github.com/tomasc/dragonfly_harfbuzz"
|
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
|
+
spec.add_dependency "ox"
|
22
|
+
spec.add_dependency "savage"
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.9"
|
25
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
26
|
+
spec.add_development_dependency "guard"
|
27
|
+
spec.add_development_dependency "guard-minitest"
|
28
|
+
spec.add_development_dependency "minitest"
|
29
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'ox'
|
2
|
+
|
3
|
+
module DragonflyHarfbuzz
|
4
|
+
class DomAttrsService < Struct.new :svg, :font_size, :margin
|
5
|
+
attr_accessor :ox_doc
|
6
|
+
|
7
|
+
# =====================================================================
|
8
|
+
|
9
|
+
def self.call *args
|
10
|
+
self.new(*args).call
|
11
|
+
end
|
12
|
+
|
13
|
+
def call
|
14
|
+
ox_doc[:'data-font-size'] = font_size unless font_size.nil?
|
15
|
+
ox_doc[:'data-margin'] = margin unless margin.nil?
|
16
|
+
|
17
|
+
Ox.dump(ox_doc)
|
18
|
+
end
|
19
|
+
|
20
|
+
private # =============================================================
|
21
|
+
|
22
|
+
def ox_doc
|
23
|
+
@ox_doc ||= Ox.parse(svg)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
require 'ox'
|
2
|
+
require 'savage'
|
3
|
+
|
4
|
+
module DragonflyHarfbuzz
|
5
|
+
class FlattenSvgService
|
6
|
+
|
7
|
+
def self.call *args
|
8
|
+
self.new(*args).call
|
9
|
+
end
|
10
|
+
|
11
|
+
def initialize svg
|
12
|
+
@svg = svg
|
13
|
+
@ox_doc = Ox.parse(@svg)
|
14
|
+
end
|
15
|
+
|
16
|
+
def call
|
17
|
+
get_words.each do |word|
|
18
|
+
characters_to_add = []
|
19
|
+
|
20
|
+
get_characters_from_word(word).each do |character|
|
21
|
+
symbol = get_symbol_for_character(character)
|
22
|
+
characters_to_add << build_character_svg(character, symbol)
|
23
|
+
end
|
24
|
+
|
25
|
+
word.nodes.clear
|
26
|
+
|
27
|
+
characters_to_add.each{ |char| word << char }
|
28
|
+
end
|
29
|
+
|
30
|
+
lines = @ox_doc.locate('g/g').select{ |g| g[:class] == 'line' }
|
31
|
+
|
32
|
+
add_lines_to_doc(lines)
|
33
|
+
|
34
|
+
Ox.dump(@ox_doc)
|
35
|
+
end
|
36
|
+
|
37
|
+
private # =============================================================
|
38
|
+
|
39
|
+
def add_lines_to_doc lines
|
40
|
+
@ox_doc.nodes.clear
|
41
|
+
|
42
|
+
lines.each{ |line| @ox_doc << line }
|
43
|
+
end
|
44
|
+
|
45
|
+
def get_symbols
|
46
|
+
@ox_doc.locate("defs/g/symbol")
|
47
|
+
end
|
48
|
+
|
49
|
+
def get_words
|
50
|
+
@ox_doc.locate("g/g/g")
|
51
|
+
end
|
52
|
+
|
53
|
+
def get_characters_from_word word
|
54
|
+
word.locate("use")
|
55
|
+
end
|
56
|
+
|
57
|
+
def get_symbol_for_character character
|
58
|
+
symbols = @ox_doc.locate("defs/g/symbol")
|
59
|
+
symbol_href = character.attributes[:"xlink:href"].gsub(/\#/, '')
|
60
|
+
|
61
|
+
symbols.select{ |s| s.attributes[:id] == symbol_href }.first
|
62
|
+
end
|
63
|
+
|
64
|
+
def build_character_svg character, symbol
|
65
|
+
character_svg = Ox::Element.new('svg').tap do |prop|
|
66
|
+
prop[:character] = character[:character]
|
67
|
+
prop[:class] = "character"
|
68
|
+
prop[:overflow] = "visible"
|
69
|
+
prop[:x] = character[:x]
|
70
|
+
prop[:y] = character[:y]
|
71
|
+
end
|
72
|
+
|
73
|
+
symbol.nodes.each{ |path| character_svg << path }
|
74
|
+
|
75
|
+
character_svg
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,107 @@
|
|
1
|
+
require 'ox'
|
2
|
+
require 'savage'
|
3
|
+
|
4
|
+
module DragonflyHarfbuzz
|
5
|
+
class MarkupSvgService
|
6
|
+
|
7
|
+
attr_accessor :ox_doc
|
8
|
+
attr_accessor :text
|
9
|
+
|
10
|
+
# =====================================================================
|
11
|
+
|
12
|
+
def self.call *args
|
13
|
+
self.new(*args).call
|
14
|
+
end
|
15
|
+
|
16
|
+
# =====================================================================
|
17
|
+
|
18
|
+
def initialize text, svg
|
19
|
+
@text = text
|
20
|
+
@svg = svg
|
21
|
+
@ox_doc = Ox.parse(@svg)
|
22
|
+
end
|
23
|
+
|
24
|
+
def call
|
25
|
+
split_paths
|
26
|
+
|
27
|
+
lines.each_with_index do |line, index|
|
28
|
+
line_group = ox_doc.locate("svg/g/g[#{index}]").first
|
29
|
+
line_group[:line] = line
|
30
|
+
line_group[:class] = "line"
|
31
|
+
|
32
|
+
word_groups = []
|
33
|
+
words_in_line(line).each_with_index do |word, word_index|
|
34
|
+
word_groups << marked_up_word(word, word_index, line, line_group)
|
35
|
+
end
|
36
|
+
|
37
|
+
line_group.nodes.clear
|
38
|
+
|
39
|
+
word_groups.each { |wg| line_group << wg }
|
40
|
+
end
|
41
|
+
|
42
|
+
Ox.dump(ox_doc)
|
43
|
+
end
|
44
|
+
|
45
|
+
private # =============================================================
|
46
|
+
|
47
|
+
def lines
|
48
|
+
text.split(/\n+/)
|
49
|
+
end
|
50
|
+
|
51
|
+
def words_in_line line
|
52
|
+
line.split(/\s+/)
|
53
|
+
end
|
54
|
+
|
55
|
+
# ---------------------------------------------------------------------
|
56
|
+
|
57
|
+
# FIXME: fix issues with negative paths ('O', 'd', etc.)
|
58
|
+
def split_paths
|
59
|
+
symbols = ox_doc.locate("svg/defs/g/symbol")
|
60
|
+
symbols.each do |symbol|
|
61
|
+
path = symbol.nodes.first
|
62
|
+
parsed_path = Savage::Parser.parse(path[:d])
|
63
|
+
subpath_elements = []
|
64
|
+
|
65
|
+
parsed_path.subpaths.each do |subpath|
|
66
|
+
path_element = Ox::Element.new('path').tap { |prop| prop[:d] = subpath.to_command }
|
67
|
+
subpath_elements.push path_element
|
68
|
+
end
|
69
|
+
|
70
|
+
symbol.nodes.clear
|
71
|
+
subpath_elements.each { |path| symbol << path }
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
# ---------------------------------------------------------------------
|
76
|
+
|
77
|
+
def marked_up_word word, word_index, line, line_group
|
78
|
+
word_group = Ox::Element.new('g').tap do |prop|
|
79
|
+
prop[:word] = word
|
80
|
+
prop[:class] = "word"
|
81
|
+
end
|
82
|
+
|
83
|
+
previous_words = words_in_line(line)[0...word_index]
|
84
|
+
index_offset = previous_words.join.length
|
85
|
+
|
86
|
+
index_of_first_character = index_offset + 0
|
87
|
+
index_of_last_character = index_offset + word.length - 1
|
88
|
+
|
89
|
+
characters = line_group.locate("use")[index_of_first_character..index_of_last_character]
|
90
|
+
|
91
|
+
marked_up_characters(characters, word).each do |char|
|
92
|
+
word_group << char
|
93
|
+
end
|
94
|
+
|
95
|
+
word_group
|
96
|
+
end
|
97
|
+
|
98
|
+
def marked_up_characters characters, word
|
99
|
+
characters.each do |character|
|
100
|
+
index = characters.index(character)
|
101
|
+
character[:character] = word[index]
|
102
|
+
character[:class] = "character"
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
end
|
107
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'dragonfly_harfbuzz/processors/hb_view'
|
2
|
+
|
3
|
+
module DragonflyHarfbuzz
|
4
|
+
class Plugin
|
5
|
+
|
6
|
+
def call app, opts={}
|
7
|
+
app.add_processor :hb_view, Processors::HbView.new
|
8
|
+
end
|
9
|
+
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
Dragonfly::App.register_plugin(:harfbuzz) { DragonflyHarfbuzz::Plugin.new }
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'shellwords'
|
2
|
+
|
3
|
+
module DragonflyHarfbuzz
|
4
|
+
module Processors
|
5
|
+
class HbView
|
6
|
+
|
7
|
+
def call content, str, opts={}
|
8
|
+
format = opts.fetch(:format, :svg)
|
9
|
+
flatten_svg = opts.fetch(:flatten_svg, false)
|
10
|
+
markup_svg = opts.fetch(:markup_svg, flatten_svg)
|
11
|
+
|
12
|
+
content.shell_update(ext: format) do |old_path, new_path|
|
13
|
+
args = %W(
|
14
|
+
--font-file=#{old_path}
|
15
|
+
--output-file=#{new_path}
|
16
|
+
--output-format=#{format}
|
17
|
+
)
|
18
|
+
|
19
|
+
opts.reject{ |k,v| %w(format markup_svg flatten_svg).include?(k.to_s) }.each do |k, v|
|
20
|
+
args << "--#{k.to_s.gsub('_', '-')}=#{Shellwords.escape(v)}"
|
21
|
+
end
|
22
|
+
|
23
|
+
"hb-view #{Shellwords.escape(str)} #{args.join(' ')}"
|
24
|
+
end
|
25
|
+
|
26
|
+
if format
|
27
|
+
content.meta['format'] = format.to_s
|
28
|
+
content.ext = format
|
29
|
+
end
|
30
|
+
|
31
|
+
if format.to_s =~ /svg/i
|
32
|
+
content.update( DragonflyHarfbuzz::MarkupSvgService.call(str, content.data) ) if markup_svg
|
33
|
+
content.update( DragonflyHarfbuzz::FlattenSvgService.call(content.data) ) if flatten_svg
|
34
|
+
content.update( DragonflyHarfbuzz::DomAttrsService.call(content.data, opts[:font_size], opts[:margin]) )
|
35
|
+
end
|
36
|
+
|
37
|
+
content
|
38
|
+
end
|
39
|
+
|
40
|
+
# ---------------------------------------------------------------------
|
41
|
+
|
42
|
+
def update_url(attrs, args='', opts={})
|
43
|
+
format = opts['format']
|
44
|
+
attrs.ext = format if format
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'dragonfly'
|
2
|
+
|
3
|
+
require "dragonfly_harfbuzz/dom_attrs_service"
|
4
|
+
require "dragonfly_harfbuzz/flatten_svg_service"
|
5
|
+
require "dragonfly_harfbuzz/markup_svg_service"
|
6
|
+
|
7
|
+
require "dragonfly_harfbuzz/plugin"
|
8
|
+
require "dragonfly_harfbuzz/version"
|
9
|
+
|
10
|
+
Dragonfly.app.configure do
|
11
|
+
plugin :harfbuzz
|
12
|
+
end
|
Binary file
|
data/samples/test.svg
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="416pt" height="313.6pt" viewBox="0 0 416 313.6" version="1.1">
|
3
|
+
<defs>
|
4
|
+
<g>
|
5
|
+
<symbol overflow="visible" id="glyph0-0">
|
6
|
+
<path style="stroke:none;" d=""/>
|
7
|
+
</symbol>
|
8
|
+
<symbol overflow="visible" id="glyph0-1">
|
9
|
+
<path style="stroke:none;" d="M 19.71875 -159.484375 L 19.71875 0 L 37.890625 0 L 37.890625 -78.34375 L 97.53125 -78.34375 L 97.53125 -93.703125 L 37.890625 -93.703125 L 37.890625 -143.875 L 111.609375 -143.875 L 111.609375 -159.484375 Z M 19.71875 -159.484375 "/>
|
10
|
+
</symbol>
|
11
|
+
<symbol overflow="visible" id="glyph0-2">
|
12
|
+
<path style="stroke:none;" d="M 120.578125 -79.359375 C 120.578125 -94.203125 119.546875 -113.921875 110.84375 -131.078125 C 100.359375 -151.546875 82.171875 -161.03125 64.765625 -161.03125 C 40.953125 -161.03125 7.421875 -142.59375 7.421875 -79.875 C 7.421875 -17.15625 40.453125 2.5625 65.03125 2.5625 C 82.171875 2.5625 100.609375 -7.171875 111.109375 -28.421875 C 119.546875 -45.5625 120.578125 -65.28125 120.578125 -79.359375 Z M 64 -144.390625 C 75.265625 -144.390625 89.09375 -137.734375 96.515625 -119.046875 C 101.890625 -105.734375 102.65625 -90.375 102.65625 -77.0625 C 102.65625 -66.5625 102.140625 -50.171875 95.484375 -36.609375 C 88.0625 -20.984375 75.78125 -14.84375 65.03125 -14.84375 C 47.109375 -14.84375 25.09375 -31.484375 25.09375 -82.171875 C 25.09375 -129.796875 47.359375 -144.390625 64 -144.390625 Z M 64 -144.390625 "/>
|
13
|
+
</symbol>
|
14
|
+
</g>
|
15
|
+
</defs>
|
16
|
+
<g id="surface1">
|
17
|
+
<rect x="0" y="0" width="416" height="313.6" style="fill:rgb(100%,100%,100%);fill-opacity:1;stroke:none;"/>
|
18
|
+
<g style="fill:rgb(0%,0%,0%);fill-opacity:1;">
|
19
|
+
<use xlink:href="#glyph0-1" x="16" y="229.504"/>
|
20
|
+
<use xlink:href="#glyph0-2" x="144" y="229.504"/>
|
21
|
+
<use xlink:href="#glyph0-2" x="272" y="229.504"/>
|
22
|
+
</g>
|
23
|
+
</g>
|
24
|
+
</svg>
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'minitest_helper'
|
2
|
+
|
3
|
+
module DragonflyHarfbuzz
|
4
|
+
describe FlattenSvgService do
|
5
|
+
|
6
|
+
let(:app) { test_app.configure_with(:harfbuzz) }
|
7
|
+
let(:processor) { DragonflyHarfbuzz::Processors::HbView.new }
|
8
|
+
let(:font) { Dragonfly::Content.new(app, SAMPLES_DIR.join('Inconsolata.otf')) }
|
9
|
+
let(:string) { 'foo foo' }
|
10
|
+
let(:svg) { processor.call(font, string) }
|
11
|
+
let(:call) { DragonflyHarfbuzz::FlattenSvgService.call(string, svg) }
|
12
|
+
|
13
|
+
let(:f_markup) { "<svg character=\"f\" class=\"character\" overflow=\"visible\" x=\"1552\" y=\"229.504\">" }
|
14
|
+
|
15
|
+
it 'supports :flatten_svg' do
|
16
|
+
processor.call(font, string, { flatten_svg: true })
|
17
|
+
font.data.sub(f_markup, '').wont_include f_markup
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'minitest_helper'
|
2
|
+
|
3
|
+
module DragonflyHarfbuzz
|
4
|
+
describe Plugin do
|
5
|
+
|
6
|
+
let(:app) { test_app.configure_with(:harfbuzz) }
|
7
|
+
let(:font) { app.fetch_file(SAMPLES_DIR.join('Inconsolata.otf')) }
|
8
|
+
|
9
|
+
# ---------------------------------------------------------------------
|
10
|
+
|
11
|
+
describe 'processors' do
|
12
|
+
it 'adds #hb_view' do
|
13
|
+
font.must_respond_to :hb_view
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'minitest_helper'
|
2
|
+
|
3
|
+
module DragonflyHarfbuzz
|
4
|
+
module Processors
|
5
|
+
describe HbView do
|
6
|
+
|
7
|
+
let(:app) { test_app.configure_with(:harfbuzz) }
|
8
|
+
let(:processor) { DragonflyHarfbuzz::Processors::HbView.new }
|
9
|
+
let(:font) { Dragonfly::Content.new(app, SAMPLES_DIR.join('Inconsolata.otf')) }
|
10
|
+
let(:string) { 'FOO' }
|
11
|
+
|
12
|
+
it 'renders SVG by default' do
|
13
|
+
processor.call(font, string)
|
14
|
+
font.meta['format'].must_equal 'svg'
|
15
|
+
end
|
16
|
+
|
17
|
+
describe 'options' do
|
18
|
+
it 'passes options to command line ' do
|
19
|
+
processor.call(font, string, { foreground: '#ff00ff' })
|
20
|
+
font.data.must_include 'fill:rgb(100%,0%,100%);'
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'supports :markup_svg' do
|
24
|
+
processor.call(font, string, { markup_svg: true })
|
25
|
+
|
26
|
+
font.data.must_include "word=\"#{string}\""
|
27
|
+
|
28
|
+
font.data.must_include 'character="F"'
|
29
|
+
font.data.must_include 'character="O"'
|
30
|
+
font.data.must_include 'character="O"'
|
31
|
+
|
32
|
+
font.data.must_include 'class="character"'
|
33
|
+
font.data.must_include 'class="word"'
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'supports :flatten_svg' do
|
37
|
+
processor.call(font, string, { flatten_svg: true })
|
38
|
+
|
39
|
+
font.data.wont_include "#glyph0-1"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
$LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
|
2
|
+
require "bundler/setup"
|
3
|
+
|
4
|
+
require "minitest"
|
5
|
+
require "minitest/autorun"
|
6
|
+
require "minitest/spec"
|
7
|
+
|
8
|
+
require "dragonfly_harfbuzz"
|
9
|
+
|
10
|
+
# ---------------------------------------------------------------------
|
11
|
+
|
12
|
+
SAMPLES_DIR = Pathname.new(File.expand_path('../../samples', __FILE__))
|
13
|
+
|
14
|
+
# ---------------------------------------------------------------------
|
15
|
+
|
16
|
+
def test_app name=nil
|
17
|
+
app = Dragonfly::App.instance(name)
|
18
|
+
app.datastore = Dragonfly::MemoryDataStore.new
|
19
|
+
app.secret = "test secret"
|
20
|
+
app
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,180 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dragonfly_harfbuzz
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tomas Celizna
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-11-04 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: dragonfly
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: ox
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: savage
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: bundler
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.9'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.9'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '10.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '10.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: guard
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: guard-minitest
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: minitest
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
description:
|
126
|
+
email:
|
127
|
+
- tomas.celizna@gmail.com
|
128
|
+
executables: []
|
129
|
+
extensions: []
|
130
|
+
extra_rdoc_files: []
|
131
|
+
files:
|
132
|
+
- ".gitignore"
|
133
|
+
- Gemfile
|
134
|
+
- Guardfile
|
135
|
+
- LICENSE.txt
|
136
|
+
- README.md
|
137
|
+
- Rakefile
|
138
|
+
- dragonfly_harfbuzz.gemspec
|
139
|
+
- lib/dragonfly_harfbuzz.rb
|
140
|
+
- lib/dragonfly_harfbuzz/dom_attrs_service.rb
|
141
|
+
- lib/dragonfly_harfbuzz/flatten_svg_service.rb
|
142
|
+
- lib/dragonfly_harfbuzz/markup_svg_service.rb
|
143
|
+
- lib/dragonfly_harfbuzz/plugin.rb
|
144
|
+
- lib/dragonfly_harfbuzz/processors/hb_view.rb
|
145
|
+
- lib/dragonfly_harfbuzz/version.rb
|
146
|
+
- samples/Inconsolata.otf
|
147
|
+
- samples/test.svg
|
148
|
+
- test/dragonfly_harfbuzz/flatten_svg_service_test.rb
|
149
|
+
- test/dragonfly_harfbuzz/plugin_test.rb
|
150
|
+
- test/dragonfly_harfbuzz/processors/hb_view_test.rb
|
151
|
+
- test/minitest_helper.rb
|
152
|
+
homepage: https://github.com/tomasc/dragonfly_harfbuzz
|
153
|
+
licenses:
|
154
|
+
- MIT
|
155
|
+
metadata: {}
|
156
|
+
post_install_message:
|
157
|
+
rdoc_options: []
|
158
|
+
require_paths:
|
159
|
+
- lib
|
160
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
161
|
+
requirements:
|
162
|
+
- - ">="
|
163
|
+
- !ruby/object:Gem::Version
|
164
|
+
version: '0'
|
165
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
166
|
+
requirements:
|
167
|
+
- - ">="
|
168
|
+
- !ruby/object:Gem::Version
|
169
|
+
version: '0'
|
170
|
+
requirements: []
|
171
|
+
rubyforge_project:
|
172
|
+
rubygems_version: 2.4.8
|
173
|
+
signing_key:
|
174
|
+
specification_version: 4
|
175
|
+
summary: Harfbuzz renderer wrapped by Dragonfly processors.
|
176
|
+
test_files:
|
177
|
+
- test/dragonfly_harfbuzz/flatten_svg_service_test.rb
|
178
|
+
- test/dragonfly_harfbuzz/plugin_test.rb
|
179
|
+
- test/dragonfly_harfbuzz/processors/hb_view_test.rb
|
180
|
+
- test/minitest_helper.rb
|