dragonfly_harfbuzz 1.1.0 → 1.1.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0bf9f016957a6112b6780a98641577c56fb5332ed5fb8a4928c17219f57fe8b2
4
- data.tar.gz: 4afcd3a4330851dc40b09d52d4e6cf5e77679fde8b56a8cda3c664d62ae5f283
3
+ metadata.gz: 1980ad4ccc7ad9114e7c1bf7dcedac662c745ca8e6c2b572f224accbd34f26e2
4
+ data.tar.gz: ce232fa77f208f0a94caed4e019aa5a3d1f5dadc0801b2d26c8d07b38140f447
5
5
  SHA512:
6
- metadata.gz: 337964e96d448279649158b151b72002bd7a27466bd7e31bab4db88a981d49478fd91be5454a3e8378fc1fade11329be2a62c937dfdaae965937925d8bf75fc7
7
- data.tar.gz: bda1125020e0e7d74427b0ee09a954e0606ba1640f9c4dcbd6b79368107ca3e69cd36298647c0caa4bc0a409c2c2da4808ce51630917b20fa91faed104390db5
6
+ metadata.gz: f7a80f5f1fed5e05abdeb0902ec1e922cf31981ef3b440b68c53e8e46c3d7a7d5ba506d378ae79eb59d26bfbb1d327a4585eebf90b1ae02fbf351f89dd1b68a7
7
+ data.tar.gz: 3e57c32feba7772d6478e9ea2f6a3e8036f04cc8fb51822169b7762080779f7658e297c7c391c9a942d825fade17b2bad8ac3cd1443d8241b9fe6561aa9eecb3
@@ -1,5 +1,9 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 1.1.1
4
+
5
+ * minor fixes
6
+
3
7
  ## 1.1.0
4
8
 
5
9
  * support `unicodes` option for `markup_svg: true`
@@ -2,13 +2,16 @@ require 'ox'
2
2
 
3
3
  module DragonflyHarfbuzz
4
4
  class FlattenSvgService
5
+ attr_accessor :ox_doc
6
+ attr_accessor :svg
7
+
5
8
  def self.call(*args)
6
9
  new(*args).call
7
10
  end
8
11
 
9
12
  def initialize(svg)
10
13
  @svg = svg
11
- @ox_doc = Ox.parse(@svg)
14
+ @ox_doc = Ox.parse(svg)
12
15
  end
13
16
 
14
17
  def call
@@ -25,26 +28,26 @@ module DragonflyHarfbuzz
25
28
  characters_to_add.each { |char| word << char }
26
29
  end
27
30
 
28
- lines = @ox_doc.locate('g/g').select { |g| g[:class] == 'line' }
31
+ lines = ox_doc.locate('g/g').select { |g| g[:class] == 'line' }
29
32
 
30
33
  add_lines_to_doc(lines)
31
34
 
32
- Ox.dump(@ox_doc)
35
+ Ox.dump(ox_doc)
33
36
  end
34
37
 
35
38
  private
36
39
 
37
40
  def add_lines_to_doc(lines)
38
- @ox_doc.nodes.clear
39
- lines.each { |line| @ox_doc << line }
41
+ ox_doc.nodes.clear
42
+ lines.each { |line| ox_doc << line }
40
43
  end
41
44
 
42
45
  def get_symbols
43
- @ox_doc.locate('defs/g/symbol')
46
+ ox_doc.locate('defs/g/symbol')
44
47
  end
45
48
 
46
49
  def get_words
47
- @ox_doc.locate('g/g/g')
50
+ ox_doc.locate('g/g/g')
48
51
  end
49
52
 
50
53
  def get_characters_from_word(word)
@@ -52,7 +55,7 @@ module DragonflyHarfbuzz
52
55
  end
53
56
 
54
57
  def get_symbol_for_character(character)
55
- symbols = @ox_doc.locate('defs/g/symbol')
58
+ symbols = ox_doc.locate('defs/g/symbol')
56
59
  symbol_href = character.attributes[:"xlink:href"].delete('#')
57
60
  symbols.select { |s| s.attributes[:id] == symbol_href }.first
58
61
  end
@@ -5,6 +5,9 @@ module DragonflyHarfbuzz
5
5
  class MarkupSvgService
6
6
  attr_accessor :ox_doc
7
7
  attr_accessor :text
8
+ attr_accessor :unicodes
9
+ attr_accessor :options
10
+ attr_accessor :svg
8
11
 
9
12
  def self.call(*args)
10
13
  new(*args).call
@@ -13,7 +16,7 @@ module DragonflyHarfbuzz
13
16
  def initialize(text, svg, options = {})
14
17
  @text = text
15
18
  @svg = svg
16
- @ox_doc = Ox.parse(@svg)
19
+ @ox_doc = Ox.parse(svg)
17
20
  @options = options
18
21
  end
19
22
 
@@ -50,7 +53,7 @@ module DragonflyHarfbuzz
50
53
  end
51
54
 
52
55
  def split_paths?
53
- @options.fetch(:split_paths, true)
56
+ options.fetch(:split_paths, true)
54
57
  end
55
58
 
56
59
  # FIXME: fix issues with negative paths ('O', 'd', etc.)
@@ -39,8 +39,10 @@ module DragonflyHarfbuzz
39
39
  if format =~ /svg/i
40
40
  content.update(MarkupSvgService.call((str || str_from_unicodes(unicodes)), content.data, split_paths: split_paths), 'name' => "temp.#{format}") if markup_svg
41
41
  content.update(FlattenSvgService.call(content.data), 'name' => "temp.#{format}") if flatten_svg
42
- content.update(DomAttrsService.call(content.data, options[:font_size], options[:margin]), 'name' => "temp.#{format}")
42
+ content.update(DomAttrsService.call(content.data, options[:font_size], options[:margin]), 'name' => "temp.#{format}") if markup_svg
43
43
  end
44
+
45
+ content
44
46
  end
45
47
 
46
48
  def update_url(attrs, str = '', options = {})
@@ -52,7 +54,11 @@ module DragonflyHarfbuzz
52
54
 
53
55
  def str_from_unicodes(unicodes)
54
56
  unicodes.split(",").map do |hexstring|
55
- Array(hexstring).pack("H*").force_encoding('utf-16be').encode('utf-8')
57
+ begin
58
+ Array(hexstring).pack("H*").force_encoding('utf-16be').encode('utf-8')
59
+ rescue
60
+ " "
61
+ end
56
62
  end.join
57
63
  end
58
64
 
@@ -1,3 +1,3 @@
1
1
  module DragonflyHarfbuzz
2
- VERSION = '1.1.0'.freeze
2
+ VERSION = '1.1.1'.freeze
3
3
  end
@@ -1,32 +1,28 @@
1
1
  require 'test_helper'
2
2
 
3
- module DragonflyHarfbuzz
4
- describe FlattenSvgService do
5
- let(:app) { test_app.configure_with(:harfbuzz) }
6
- let(:processor) { DragonflyHarfbuzz::Processors::HbView.new }
7
- let(:content) { Dragonfly::Content.new(app, SAMPLES_DIR.join('sample.otf')) }
8
- let(:string) { 'ABC def' }
9
- let(:svg) { processor.call(content, string) }
10
- let(:call) { DragonflyHarfbuzz::FlattenSvgService.call(string, svg) }
3
+ describe DragonflyHarfbuzz::FlattenSvgService 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) { 'ABC def' }
8
+ let(:svg) { processor.call(content, string, markup_svg: true, flatten_svg: false).data }
9
+ let(:result) { DragonflyHarfbuzz::FlattenSvgService.call(svg) }
11
10
 
12
- before { processor.call(content, string, flatten_svg: true) }
13
-
14
- describe 'lines' do
15
- it { content.data.must_include "line=\"#{string}\" class=\"line\"" }
16
- end
11
+ describe 'lines' do
12
+ it { result.must_include "line=\"#{string}\" class=\"line\"" }
13
+ end
17
14
 
18
- describe 'words' do
19
- it { content.data.must_include '<g word="ABC" class="word">' }
20
- it { content.data.must_include '<g word="def" class="word">' }
21
- end
15
+ describe 'words' do
16
+ it { result.must_include '<g word="ABC" class="word">' }
17
+ it { result.must_include '<g word="def" class="word">' }
18
+ end
22
19
 
23
- describe 'characters' do
24
- it { content.data.must_include '<svg character="A" class="character"' }
25
- it { content.data.must_include '<svg character="B" class="character"' }
26
- it { content.data.must_include '<svg character="C" class="character"' }
27
- it { content.data.must_include '<svg character="d" class="character"' }
28
- it { content.data.must_include '<svg character="e" class="character"' }
29
- it { content.data.must_include '<svg character="f" class="character"' }
30
- end
20
+ describe 'characters' do
21
+ it { result.must_include '<svg character="A" class="character"' }
22
+ it { result.must_include '<svg character="B" class="character"' }
23
+ it { result.must_include '<svg character="C" class="character"' }
24
+ it { result.must_include '<svg character="d" class="character"' }
25
+ it { result.must_include '<svg character="e" class="character"' }
26
+ it { result.must_include '<svg character="f" class="character"' }
31
27
  end
32
28
  end
@@ -0,0 +1,28 @@
1
+ require 'test_helper'
2
+
3
+ describe DragonflyHarfbuzz::MarkupSvgService 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) { 'ABC def' }
8
+ let(:svg) { processor.call(content, string).data }
9
+ let(:result) { DragonflyHarfbuzz::MarkupSvgService.call(string, svg) }
10
+
11
+ describe 'lines' do
12
+ it { result.must_include "line=\"#{string}\" class=\"line\"" }
13
+ end
14
+
15
+ describe 'words' do
16
+ it { result.must_include "word=\"ABC\" class=\"word\"" }
17
+ it { result.must_include "word=\"def\" class=\"word\"" }
18
+ end
19
+
20
+ describe 'characters' do
21
+ it { result.must_include "character=\"A\" class=\"character\"" }
22
+ it { result.must_include "character=\"B\" class=\"character\"" }
23
+ it { result.must_include "character=\"C\" class=\"character\"" }
24
+ it { result.must_include "character=\"d\" class=\"character\"" }
25
+ it { result.must_include "character=\"e\" class=\"character\"" }
26
+ it { result.must_include "character=\"f\" class=\"character\"" }
27
+ end
28
+ end
@@ -47,4 +47,10 @@ describe DragonflyHarfbuzz::Processors::HbView do
47
47
  before { processor.call(content, string, flatten_svg: true) }
48
48
  it { content.data.wont_include '#glyph0-1' }
49
49
  end
50
+
51
+ describe 'str as unicodes' do
52
+ before { processor.call(content, nil, unicodes: "0042,0043", flatten_svg: true) }
53
+ it { content.data.must_include "<svg character=\"B\" class=\"character\"" }
54
+ it { content.data.must_include "<svg character=\"C\" class=\"character\"" }
55
+ end
50
56
  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.0
4
+ version: 1.1.1
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-08-03 00:00:00.000000000 Z
11
+ date: 2018-08-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -176,6 +176,7 @@ files:
176
176
  - samples/sample.otf
177
177
  - samples/sample.ttf
178
178
  - test/dragonfly_harfbuzz/flatten_svg_service_test.rb
179
+ - test/dragonfly_harfbuzz/markup_svg_service_test.rb
179
180
  - test/dragonfly_harfbuzz/plugin_test.rb
180
181
  - test/dragonfly_harfbuzz/processors/hb_view_test.rb
181
182
  - test/test_helper.rb
@@ -205,6 +206,7 @@ specification_version: 4
205
206
  summary: Harfbuzz renderer wrapped by Dragonfly processors.
206
207
  test_files:
207
208
  - test/dragonfly_harfbuzz/flatten_svg_service_test.rb
209
+ - test/dragonfly_harfbuzz/markup_svg_service_test.rb
208
210
  - test/dragonfly_harfbuzz/plugin_test.rb
209
211
  - test/dragonfly_harfbuzz/processors/hb_view_test.rb
210
212
  - test/test_helper.rb