dragonfly_harfbuzz 1.1.3 → 1.1.4

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: 8770ccbb7bfdfe8b736a4e2074118fe6229161dff997af7d72eba97ae5c2bade
4
- data.tar.gz: 248e3e3d33af72f6362eb02fa733e3b97ee92c101f47d27323e0708b3ec40cb5
3
+ metadata.gz: d960dc318684ef2b9f4796075ee08722cd391bfee77584ef024afd79f259ff64
4
+ data.tar.gz: db194504f7e53563c1d97198cd07eb15dc863e9e5b416774facb6f1050df787b
5
5
  SHA512:
6
- metadata.gz: 936adfbd294352ec1f41301d948fe06ea1d7045a47c68a053bef53bea718b9d7953baac758070afb066c593a035b6f6642402956cfd8a8d31a8b81a6731de6c9
7
- data.tar.gz: 91a5e0d69b79347ecea40d1a8502ef4a56a2cb21a5b8ef19c90e4bc3786cbeeff8f3ffb202f3cbeedd465b621614ef3153e0288e4d2f75bedd47a458f394dd2f
6
+ metadata.gz: d10581a86c8f9f41e746a9ce5430b2960aa1bca6c52aad670a651cc9b665977703dedcabb0b3a01646906bd10d2787f3ecee7237336c9d55a35646b3c151b462
7
+ data.tar.gz: a990bb2433badf1f4a330d54c3f49a305f5feb5991a7340abf00f3c0cb2c66232acc939302a2aff76c8d74c600ebe6c1c35d42bc5892b49de3f240ecf10dbb73
@@ -9,8 +9,8 @@ rvm:
9
9
  before_install:
10
10
  - gem update bundler
11
11
  - sudo apt-get update
12
- - wget --no-check-certificate http://www.freedesktop.org/software/harfbuzz/release/harfbuzz-1.7.6.tar.bz2 && tar -xjf harfbuzz-1.7.6.tar.bz2 --no-same-owner
13
- - cd harfbuzz-1.7.6 && sudo ./configure && sudo make && sudo make install && rm -rf harfbuzz*
12
+ - wget --no-check-certificate http://www.freedesktop.org/software/harfbuzz/release/harfbuzz-2.3.0.tar.bz2 && tar -xjf harfbuzz-2.3.0.tar.bz2 --no-same-owner
13
+ - cd harfbuzz-2.3.0 && sudo ./configure && sudo make && sudo make install && rm -rf harfbuzz*
14
14
 
15
15
  notifications:
16
16
  email:
@@ -1,8 +1,12 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 1.1.4
4
+
5
+ * ADD: `translate` option that translates glyph positions by specified `x` and/or `y` offset
6
+
3
7
  ## 1.1.3
4
8
 
5
- * make sure that `str` argument to `hb_view` is properly escaped
9
+ * FIX: make sure that `str` argument to `hb_view` is properly escaped
6
10
 
7
11
  ## 1.1.2
8
12
 
@@ -10,7 +14,7 @@
10
14
 
11
15
  ## 1.1.1
12
16
 
13
- * minor fixes
17
+ * FIX: minor fixes
14
18
 
15
19
  ## 1.1.0
16
20
 
@@ -19,5 +23,5 @@
19
23
 
20
24
  ## 1.0.0
21
25
 
22
- * add `SUPPORTED_FORMATS` and `SUPPORTED_OUTPUT_FORMATS` and raise errors when formats are not matching
23
- * add more thorough tests for supported formats
26
+ * ADD: `SUPPORTED_FORMATS` and `SUPPORTED_OUTPUT_FORMATS` and raise errors when formats are not matching
27
+ * ADD: more thorough tests for supported formats
data/README.md CHANGED
@@ -56,7 +56,15 @@ DragonflyHarfbuzz::SUPPORTED_OUTPUT_FORMATS # => ["ansi", "png", "svg", "pdf", "
56
56
 
57
57
  ## Options
58
58
 
59
- 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.
59
+ Additionally (for `<svg>` only) you can pass the following options: `translate: Hash[x: 0, y: 0]`, `markup_svg: Boolean`, `split_paths: Boolean` and `flatten_svg: Boolean`.
60
+
61
+ `translate` translates glyph positions by specified `x` and/or `y` offset.
62
+
63
+ `markup_svg` returns an `<svg>` that is organized into word and characters and marked up with additional data attributes.
64
+
65
+ `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>`.
66
+
67
+ `split_paths` is a feature of the `markup_svg` and controls whether the paths of each character are split up into smaller components.
60
68
 
61
69
  ## Contributing
62
70
 
@@ -1,4 +1,3 @@
1
-
2
1
  lib = File.expand_path('lib', __dir__)
3
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
3
  require 'dragonfly_harfbuzz/version'
@@ -23,9 +22,9 @@ Gem::Specification.new do |spec|
23
22
  spec.add_dependency 'savage'
24
23
 
25
24
  spec.add_development_dependency 'bundler', '~> 1.9'
26
- spec.add_development_dependency 'rake', '~> 10.0'
27
25
  spec.add_development_dependency 'guard'
28
26
  spec.add_development_dependency 'guard-minitest'
29
27
  spec.add_development_dependency 'minitest'
30
28
  spec.add_development_dependency 'minitest-reporters'
29
+ spec.add_development_dependency 'rake', '~> 10.0'
31
30
  end
@@ -4,6 +4,7 @@ require 'active_support/core_ext/object/blank'
4
4
  require 'dragonfly_harfbuzz/dom_attrs_service'
5
5
  require 'dragonfly_harfbuzz/flatten_svg_service'
6
6
  require 'dragonfly_harfbuzz/markup_svg_service'
7
+ require 'dragonfly_harfbuzz/translate_service'
7
8
 
8
9
  require 'dragonfly_harfbuzz/plugin'
9
10
  require 'dragonfly_harfbuzz/version'
@@ -14,6 +14,10 @@ module DragonflyHarfbuzz
14
14
 
15
15
  raise UnsupportedOutputFormat unless SUPPORTED_OUTPUT_FORMATS.include?(format.downcase)
16
16
 
17
+ translate = options.fetch('translate', nil)
18
+ translate_hash = (translate || {}).each_with_object({}) { |(k, v), memo| memo[k.to_s] = v } # stringify keys
19
+ translate_x = translate_hash.fetch('x', nil)
20
+ translate_y = translate_hash.fetch('y', nil)
17
21
  flatten_svg = options.fetch('flatten_svg', false)
18
22
  markup_svg = options.fetch('markup_svg', flatten_svg)
19
23
  split_paths = options.fetch('split_paths', false)
@@ -27,7 +31,7 @@ module DragonflyHarfbuzz
27
31
 
28
32
  args << "--text=#{Shellwords.escape(str)}" unless options.key?('unicodes')
29
33
 
30
- options.reject { |k, _| %w[format markup_svg flatten_svg split_paths].include?(k.to_s) }.each do |k, v|
34
+ options.reject { |k, _| %w[translate format markup_svg flatten_svg split_paths].include?(k.to_s) }.each do |k, v|
31
35
  args << "--#{k.to_s.tr('_', '-')}=#{Shellwords.escape(v)}" if v.present?
32
36
  end
33
37
 
@@ -38,6 +42,7 @@ module DragonflyHarfbuzz
38
42
  content.ext = format
39
43
 
40
44
  if format =~ /svg/i
45
+ content.update(TranslateService.call(content.data, x: translate_x, y: translate_y), 'name' => "temp.#{format}") if translate
41
46
  content.update(MarkupSvgService.call((str || str_from_unicodes(unicodes)), content.data, split_paths: split_paths), 'name' => "temp.#{format}") if markup_svg
42
47
  content.update(FlattenSvgService.call(content.data), 'name' => "temp.#{format}") if flatten_svg
43
48
  content.update(DomAttrsService.call(content.data, options[:font_size], options[:margin]), 'name' => "temp.#{format}") if markup_svg
@@ -0,0 +1,36 @@
1
+ require 'ox'
2
+
3
+ module DragonflyHarfbuzz
4
+ class TranslateService
5
+ attr_accessor :ox_doc
6
+ attr_accessor :svg
7
+ attr_accessor :x
8
+ attr_accessor :y
9
+
10
+ def self.call(*args)
11
+ new(*args).call
12
+ end
13
+
14
+ def initialize(svg, x: 0, y: 0)
15
+ @svg = svg
16
+ @x = x.to_f
17
+ @y = y.to_f
18
+ @ox_doc = Ox.parse(svg)
19
+ end
20
+
21
+ def call
22
+ use_definitions.each do |use_definition|
23
+ use_definition[:x] = use_definition[:x].to_f + x
24
+ use_definition[:y] = use_definition[:y].to_f + y
25
+ end
26
+
27
+ Ox.dump(ox_doc)
28
+ end
29
+
30
+ private
31
+
32
+ def use_definitions
33
+ ox_doc.locate('svg/g/g/use[@xlink:href]')
34
+ end
35
+ end
36
+ end
@@ -1,3 +1,3 @@
1
1
  module DragonflyHarfbuzz
2
- VERSION = '1.1.3'.freeze
2
+ VERSION = '1.1.4'.freeze
3
3
  end
@@ -33,6 +33,18 @@ describe DragonflyHarfbuzz::Processors::HbView do
33
33
  it { content.data.must_include 'fill:rgb(100%,0%,100%);' }
34
34
  end
35
35
 
36
+ describe 'translate_x' do
37
+ let(:string) { 'A' }
38
+ before { processor.call(content, string, translate: { x: 100 }) }
39
+ it { content.data.must_include 'x="116.0"' }
40
+ end
41
+
42
+ describe 'translate_y' do
43
+ let(:string) { 'A' }
44
+ before { processor.call(content, string, translate: { y: 100 }) }
45
+ it { content.data.must_include 'y="329.5"' }
46
+ end
47
+
36
48
  describe 'markup_svg' do
37
49
  before { processor.call(content, string, markup_svg: true) }
38
50
  it { content.data.must_include "word=\"#{string}\"" }
@@ -0,0 +1,14 @@
1
+ require 'test_helper'
2
+
3
+ describe DragonflyHarfbuzz::TranslateService do
4
+ let(:app) { test_app.configure_with(:harfbuzz) }
5
+ let(:processor) { DragonflyHarfbuzz::Processors::HbView.new }
6
+ let(:content) { Dragonfly::Content.new(app, SAMPLES_DIR.join('sample.otf')) }
7
+ let(:string) { 'A' }
8
+ let(:svg) { processor.call(content, string).data }
9
+ let(:font_info) { analyser.call(content) }
10
+ let(:result) { DragonflyHarfbuzz::TranslateService.call(svg, x: 100, y: 100) }
11
+
12
+ it { result.must_include 'x="116.0"' }
13
+ it { result.must_include 'y="329.5"' }
14
+ 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: 1.1.3
4
+ version: 1.1.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: 2018-11-06 00:00:00.000000000 Z
11
+ date: 2019-01-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -81,21 +81,21 @@ dependencies:
81
81
  - !ruby/object:Gem::Version
82
82
  version: '1.9'
83
83
  - !ruby/object:Gem::Dependency
84
- name: rake
84
+ name: guard
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - "~>"
87
+ - - ">="
88
88
  - !ruby/object:Gem::Version
89
- version: '10.0'
89
+ version: '0'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - "~>"
94
+ - - ">="
95
95
  - !ruby/object:Gem::Version
96
- version: '10.0'
96
+ version: '0'
97
97
  - !ruby/object:Gem::Dependency
98
- name: guard
98
+ name: guard-minitest
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
101
  - - ">="
@@ -109,7 +109,7 @@ dependencies:
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
111
  - !ruby/object:Gem::Dependency
112
- name: guard-minitest
112
+ name: minitest
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
115
  - - ">="
@@ -123,7 +123,7 @@ dependencies:
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0'
125
125
  - !ruby/object:Gem::Dependency
126
- name: minitest
126
+ name: minitest-reporters
127
127
  requirement: !ruby/object:Gem::Requirement
128
128
  requirements:
129
129
  - - ">="
@@ -137,19 +137,19 @@ dependencies:
137
137
  - !ruby/object:Gem::Version
138
138
  version: '0'
139
139
  - !ruby/object:Gem::Dependency
140
- name: minitest-reporters
140
+ name: rake
141
141
  requirement: !ruby/object:Gem::Requirement
142
142
  requirements:
143
- - - ">="
143
+ - - "~>"
144
144
  - !ruby/object:Gem::Version
145
- version: '0'
145
+ version: '10.0'
146
146
  type: :development
147
147
  prerelease: false
148
148
  version_requirements: !ruby/object:Gem::Requirement
149
149
  requirements:
150
- - - ">="
150
+ - - "~>"
151
151
  - !ruby/object:Gem::Version
152
- version: '0'
152
+ version: '10.0'
153
153
  description:
154
154
  email:
155
155
  - tomas.celizna@gmail.com
@@ -172,6 +172,7 @@ files:
172
172
  - lib/dragonfly_harfbuzz/markup_svg_service.rb
173
173
  - lib/dragonfly_harfbuzz/plugin.rb
174
174
  - lib/dragonfly_harfbuzz/processors/hb_view.rb
175
+ - lib/dragonfly_harfbuzz/translate_service.rb
175
176
  - lib/dragonfly_harfbuzz/version.rb
176
177
  - samples/sample.otf
177
178
  - samples/sample.ttf
@@ -179,6 +180,7 @@ files:
179
180
  - test/dragonfly_harfbuzz/markup_svg_service_test.rb
180
181
  - test/dragonfly_harfbuzz/plugin_test.rb
181
182
  - test/dragonfly_harfbuzz/processors/hb_view_test.rb
183
+ - test/dragonfly_harfbuzz/translate_service_test.rb
182
184
  - test/test_helper.rb
183
185
  homepage: https://github.com/tomasc/dragonfly_harfbuzz
184
186
  licenses:
@@ -199,8 +201,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
199
201
  - !ruby/object:Gem::Version
200
202
  version: '0'
201
203
  requirements: []
202
- rubyforge_project:
203
- rubygems_version: 2.7.6
204
+ rubygems_version: 3.0.1
204
205
  signing_key:
205
206
  specification_version: 4
206
207
  summary: Harfbuzz renderer wrapped by Dragonfly processors.
@@ -209,4 +210,5 @@ test_files:
209
210
  - test/dragonfly_harfbuzz/markup_svg_service_test.rb
210
211
  - test/dragonfly_harfbuzz/plugin_test.rb
211
212
  - test/dragonfly_harfbuzz/processors/hb_view_test.rb
213
+ - test/dragonfly_harfbuzz/translate_service_test.rb
212
214
  - test/test_helper.rb