dragonfly_harfbuzz 0.0.3 → 0.0.4
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/README.md +2 -2
- data/lib/dragonfly_harfbuzz/flatten_svg_service.rb +21 -24
- data/lib/dragonfly_harfbuzz/markup_svg_service.rb +20 -17
- data/lib/dragonfly_harfbuzz/processors/hb_view.rb +8 -9
- data/lib/dragonfly_harfbuzz/version.rb +1 -1
- data/test/dragonfly_harfbuzz/flatten_svg_service_test.rb +2 -4
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 12a1a1d9e43896d972f04db0af8fba629ff01c9a
|
4
|
+
data.tar.gz: 57713f254cdf739f93cd407d6662aaef451df471
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 24c63ab26bbced5fb03be3071c8f0be576573852e2c95780e30068087dfead89dd74c57a1afa4b453cc3f3ddb44b2c2b4cd9e841fd1ebf1ae4aeef3131af668a
|
7
|
+
data.tar.gz: e37a54bb7666077687d6f2bb2e0b9e9ead42f6af984a5c62f4c57c453f3f809711d1af2d4869705786460e9e2799a6950727d608e665e562c8440fc2e18080a4
|
data/README.md
CHANGED
@@ -16,7 +16,7 @@ Or install it yourself as:
|
|
16
16
|
|
17
17
|
$ gem install dragonfly_harfbuzz
|
18
18
|
|
19
|
-
You will also need Harfbuzz installed.
|
19
|
+
You will also need Harfbuzz installed.
|
20
20
|
|
21
21
|
Using [Homebrew](http://brew.sh):
|
22
22
|
|
@@ -45,7 +45,7 @@ See tests and `hb-view --help-all` for more details on options.
|
|
45
45
|
|
46
46
|
## Options
|
47
47
|
|
48
|
-
Additionally (for `<svg>` only) you can pass
|
48
|
+
Additionally (for `<svg>` only) you can pass the following options: `markup_svg: Boolean`, `split_paths: 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>`. `split_paths` is a feature of the `markup_svg` and controls whether the paths of each character are split up into smaller components.
|
49
49
|
|
50
50
|
## Contributing
|
51
51
|
|
@@ -1,14 +1,12 @@
|
|
1
1
|
require 'ox'
|
2
|
-
require 'savage'
|
3
2
|
|
4
3
|
module DragonflyHarfbuzz
|
5
4
|
class FlattenSvgService
|
6
|
-
|
7
|
-
|
8
|
-
self.new(*args).call
|
5
|
+
def self.call(*args)
|
6
|
+
new(*args).call
|
9
7
|
end
|
10
8
|
|
11
|
-
def initialize
|
9
|
+
def initialize(svg)
|
12
10
|
@svg = svg
|
13
11
|
@ox_doc = Ox.parse(@svg)
|
14
12
|
end
|
@@ -24,10 +22,10 @@ module DragonflyHarfbuzz
|
|
24
22
|
|
25
23
|
word.nodes.clear
|
26
24
|
|
27
|
-
characters_to_add.each{ |char| word << char }
|
25
|
+
characters_to_add.each { |char| word << char }
|
28
26
|
end
|
29
27
|
|
30
|
-
lines = @ox_doc.locate('g/g').select{ |g| g[:class] == 'line' }
|
28
|
+
lines = @ox_doc.locate('g/g').select { |g| g[:class] == 'line' }
|
31
29
|
|
32
30
|
add_lines_to_doc(lines)
|
33
31
|
|
@@ -36,44 +34,43 @@ module DragonflyHarfbuzz
|
|
36
34
|
|
37
35
|
private # =============================================================
|
38
36
|
|
39
|
-
def add_lines_to_doc
|
37
|
+
def add_lines_to_doc(lines)
|
40
38
|
@ox_doc.nodes.clear
|
41
|
-
|
42
|
-
lines.each{ |line| @ox_doc << line }
|
39
|
+
lines.each { |line| @ox_doc << line }
|
43
40
|
end
|
44
41
|
|
45
42
|
def get_symbols
|
46
|
-
@ox_doc.locate(
|
43
|
+
@ox_doc.locate('defs/g/symbol')
|
47
44
|
end
|
48
45
|
|
49
46
|
def get_words
|
50
|
-
@ox_doc.locate(
|
47
|
+
@ox_doc.locate('g/g/g')
|
51
48
|
end
|
52
49
|
|
53
|
-
def get_characters_from_word
|
54
|
-
word.locate(
|
50
|
+
def get_characters_from_word(word)
|
51
|
+
word.locate('use')
|
55
52
|
end
|
56
53
|
|
57
|
-
def get_symbol_for_character
|
58
|
-
symbols = @ox_doc.locate(
|
59
|
-
symbol_href = character.attributes[:"xlink:href"].
|
60
|
-
|
61
|
-
symbols.select{ |s| s.attributes[:id] == symbol_href }.first
|
54
|
+
def get_symbol_for_character(character)
|
55
|
+
symbols = @ox_doc.locate('defs/g/symbol')
|
56
|
+
symbol_href = character.attributes[:"xlink:href"].delete('#')
|
57
|
+
symbols.select { |s| s.attributes[:id] == symbol_href }.first
|
62
58
|
end
|
63
59
|
|
64
|
-
def build_character_svg
|
60
|
+
def build_character_svg(character, symbol)
|
65
61
|
character_svg = Ox::Element.new('svg').tap do |prop|
|
66
62
|
prop[:character] = character[:character]
|
67
|
-
prop[:class] =
|
68
|
-
prop[:overflow] =
|
63
|
+
prop[:class] = 'character'
|
64
|
+
prop[:overflow] = 'visible'
|
69
65
|
prop[:x] = character[:x]
|
70
66
|
prop[:y] = character[:y]
|
71
67
|
end
|
72
68
|
|
73
|
-
symbol.nodes.each
|
69
|
+
symbol.nodes.each do |path|
|
70
|
+
character_svg << path
|
71
|
+
end
|
74
72
|
|
75
73
|
character_svg
|
76
74
|
end
|
77
|
-
|
78
75
|
end
|
79
76
|
end
|
@@ -3,31 +3,31 @@ require 'savage'
|
|
3
3
|
|
4
4
|
module DragonflyHarfbuzz
|
5
5
|
class MarkupSvgService
|
6
|
-
|
7
6
|
attr_accessor :ox_doc
|
8
7
|
attr_accessor :text
|
9
8
|
|
10
9
|
# =====================================================================
|
11
10
|
|
12
|
-
def self.call
|
13
|
-
|
11
|
+
def self.call(*args)
|
12
|
+
new(*args).call
|
14
13
|
end
|
15
14
|
|
16
15
|
# =====================================================================
|
17
16
|
|
18
|
-
def initialize
|
17
|
+
def initialize(text, svg, options = {})
|
19
18
|
@text = text
|
20
19
|
@svg = svg
|
21
20
|
@ox_doc = Ox.parse(@svg)
|
21
|
+
@options = options
|
22
22
|
end
|
23
23
|
|
24
24
|
def call
|
25
|
-
split_paths
|
25
|
+
split_paths if split_paths?
|
26
26
|
|
27
27
|
lines.each_with_index do |line, index|
|
28
28
|
line_group = ox_doc.locate("svg/g/g[#{index}]").first
|
29
29
|
line_group[:line] = line
|
30
|
-
line_group[:class] =
|
30
|
+
line_group[:class] = 'line'
|
31
31
|
|
32
32
|
word_groups = []
|
33
33
|
words_in_line(line).each_with_index do |word, word_index|
|
@@ -46,18 +46,22 @@ module DragonflyHarfbuzz
|
|
46
46
|
private # =============================================================
|
47
47
|
|
48
48
|
def lines
|
49
|
-
text.split
|
49
|
+
text.split(/\n+/)
|
50
|
+
end
|
51
|
+
|
52
|
+
def words_in_line(line)
|
53
|
+
line.split(/(\s+)/)
|
50
54
|
end
|
51
55
|
|
52
|
-
def
|
53
|
-
|
56
|
+
def split_paths?
|
57
|
+
@options.fetch(:split_paths, true)
|
54
58
|
end
|
55
59
|
|
56
60
|
# ---------------------------------------------------------------------
|
57
61
|
|
58
62
|
# FIXME: fix issues with negative paths ('O', 'd', etc.)
|
59
63
|
def split_paths
|
60
|
-
symbols = ox_doc.locate(
|
64
|
+
symbols = ox_doc.locate('svg/defs/g/symbol')
|
61
65
|
symbols.each do |symbol|
|
62
66
|
path = symbol.nodes.first
|
63
67
|
parsed_path = Savage::Parser.parse(path[:d])
|
@@ -69,16 +73,16 @@ module DragonflyHarfbuzz
|
|
69
73
|
end
|
70
74
|
|
71
75
|
symbol.nodes.clear
|
72
|
-
subpath_elements.each { |
|
76
|
+
subpath_elements.each { |pth| symbol << pth }
|
73
77
|
end
|
74
78
|
end
|
75
79
|
|
76
80
|
# ---------------------------------------------------------------------
|
77
81
|
|
78
|
-
def marked_up_word
|
82
|
+
def marked_up_word(word, word_index, line, line_group)
|
79
83
|
word_group = Ox::Element.new('g').tap do |prop|
|
80
84
|
prop[:word] = word
|
81
|
-
prop[:class] =
|
85
|
+
prop[:class] = 'word'
|
82
86
|
end
|
83
87
|
|
84
88
|
previous_words = words_in_line(line)[0...word_index]
|
@@ -87,7 +91,7 @@ module DragonflyHarfbuzz
|
|
87
91
|
index_of_first_character = index_offset + 0
|
88
92
|
index_of_last_character = index_offset + word.length - 1
|
89
93
|
|
90
|
-
characters = line_group.locate(
|
94
|
+
characters = line_group.locate('use')[index_of_first_character..index_of_last_character]
|
91
95
|
|
92
96
|
marked_up_characters(characters, word).each do |char|
|
93
97
|
word_group << char
|
@@ -96,13 +100,12 @@ module DragonflyHarfbuzz
|
|
96
100
|
word_group
|
97
101
|
end
|
98
102
|
|
99
|
-
def marked_up_characters
|
103
|
+
def marked_up_characters(characters, word)
|
100
104
|
characters.each do |character|
|
101
105
|
index = characters.index(character)
|
102
106
|
character[:character] = word[index]
|
103
|
-
character[:class] =
|
107
|
+
character[:class] = 'character'
|
104
108
|
end
|
105
109
|
end
|
106
|
-
|
107
110
|
end
|
108
111
|
end
|
@@ -3,11 +3,11 @@ require 'shellwords'
|
|
3
3
|
module DragonflyHarfbuzz
|
4
4
|
module Processors
|
5
5
|
class HbView
|
6
|
-
|
7
|
-
def call content, str, opts={}
|
6
|
+
def call(content, str, opts = {})
|
8
7
|
format = opts.fetch(:format, :svg)
|
9
8
|
flatten_svg = opts.fetch(:flatten_svg, false)
|
10
9
|
markup_svg = opts.fetch(:markup_svg, flatten_svg)
|
10
|
+
split_paths = opts.fetch(:split_paths, true)
|
11
11
|
|
12
12
|
content.shell_update(ext: format) do |old_path, new_path|
|
13
13
|
args = %W(
|
@@ -16,8 +16,8 @@ module DragonflyHarfbuzz
|
|
16
16
|
--output-format=#{format}
|
17
17
|
)
|
18
18
|
|
19
|
-
opts.reject{ |k,
|
20
|
-
args << "--#{k.to_s.
|
19
|
+
opts.reject { |k, _v| %w(format markup_svg flatten_svg split_paths).include?(k.to_s) }.each do |k, v|
|
20
|
+
args << "--#{k.to_s.tr('_', '-')}=#{Shellwords.escape(v)}"
|
21
21
|
end
|
22
22
|
|
23
23
|
"hb-view #{Shellwords.escape(str)} #{args.join(' ')}"
|
@@ -29,9 +29,9 @@ module DragonflyHarfbuzz
|
|
29
29
|
end
|
30
30
|
|
31
31
|
if format.to_s =~ /svg/i
|
32
|
-
content.update(
|
33
|
-
content.update(
|
34
|
-
content.update(
|
32
|
+
content.update(DragonflyHarfbuzz::MarkupSvgService.call(str, content.data, split_paths: split_paths)) 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
35
|
end
|
36
36
|
|
37
37
|
content
|
@@ -39,11 +39,10 @@ module DragonflyHarfbuzz
|
|
39
39
|
|
40
40
|
# ---------------------------------------------------------------------
|
41
41
|
|
42
|
-
def update_url(attrs,
|
42
|
+
def update_url(attrs, _args = '', opts = {})
|
43
43
|
format = opts['format']
|
44
44
|
attrs.ext = format if format
|
45
45
|
end
|
46
|
-
|
47
46
|
end
|
48
47
|
end
|
49
48
|
end
|
@@ -2,7 +2,6 @@ require 'minitest_helper'
|
|
2
2
|
|
3
3
|
module DragonflyHarfbuzz
|
4
4
|
describe FlattenSvgService do
|
5
|
-
|
6
5
|
let(:app) { test_app.configure_with(:harfbuzz) }
|
7
6
|
let(:processor) { DragonflyHarfbuzz::Processors::HbView.new }
|
8
7
|
let(:font) { Dragonfly::Content.new(app, SAMPLES_DIR.join('Inconsolata.otf')) }
|
@@ -10,12 +9,11 @@ module DragonflyHarfbuzz
|
|
10
9
|
let(:svg) { processor.call(font, string) }
|
11
10
|
let(:call) { DragonflyHarfbuzz::FlattenSvgService.call(string, svg) }
|
12
11
|
|
13
|
-
let(:f_markup) {
|
12
|
+
let(:f_markup) { '<svg character="f" class="character" overflow="visible" x="1552" y="229.504">' }
|
14
13
|
|
15
14
|
it 'supports :flatten_svg' do
|
16
|
-
processor.call(font, string,
|
15
|
+
processor.call(font, string, flatten_svg: true)
|
17
16
|
font.data.sub(f_markup, '').wont_include f_markup
|
18
17
|
end
|
19
|
-
|
20
18
|
end
|
21
19
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dragonfly_harfbuzz
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tomas Celizna
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-08-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dragonfly
|
@@ -168,7 +168,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
168
168
|
version: '0'
|
169
169
|
requirements: []
|
170
170
|
rubyforge_project:
|
171
|
-
rubygems_version: 2.4.
|
171
|
+
rubygems_version: 2.4.5.1
|
172
172
|
signing_key:
|
173
173
|
specification_version: 4
|
174
174
|
summary: Harfbuzz renderer wrapped by Dragonfly processors.
|