prawn-emoji 2.1.0 → 2.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 +5 -5
- data/.travis.yml +7 -3
- data/CHANGELOG.md +6 -0
- data/README.md +1 -1
- data/lib/prawn/emoji/drawer.rb +21 -18
- data/lib/prawn/emoji/version.rb +1 -1
- data/test/prawn/emoji/drawer_test.rb +16 -9
- data/test/prawn/emoji/unicode_test.rb +12 -10
- metadata +3 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
|
-
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 7c7814b9fcdf6df957493097c0a5a82b8759e4102058afda188a3323f7a48ea2
|
|
4
|
+
data.tar.gz: 5759ef6fbdfdc30bb48dbf9a8c8e87c7ddf9aa65c7f7ea5ddf52aa643d4d3469
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 6ca4f75d9382b7a9df0be903b07761b7d924edbdb493516d48784664885e9fe775024273c0c049298b627d69770c74d6bed3c11415a0e4c5a4c42418576ec30d
|
|
7
|
+
data.tar.gz: d6040f8f133f46b844523836e10e4ec0f0bf3ab326e31a42349894a8f828e4ba66769538756384a0d58f0be581456760b420787443e2219e798c9acbf1fc5319
|
data/.travis.yml
CHANGED
|
@@ -4,12 +4,16 @@ sudo: false
|
|
|
4
4
|
|
|
5
5
|
rvm:
|
|
6
6
|
- 2.1.10
|
|
7
|
-
- 2.2.
|
|
8
|
-
- 2.3.
|
|
9
|
-
- 2.4.
|
|
7
|
+
- 2.2.9
|
|
8
|
+
- 2.3.6
|
|
9
|
+
- 2.4.3
|
|
10
|
+
- 2.5.0
|
|
10
11
|
|
|
11
12
|
gemfile:
|
|
12
13
|
- test/gemfiles/prawn-2.1
|
|
13
14
|
- test/gemfiles/prawn-2.2
|
|
14
15
|
|
|
16
|
+
before_install:
|
|
17
|
+
- travis_retry gem update --system
|
|
18
|
+
|
|
15
19
|
script: bundle exec rake test
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
data/lib/prawn/emoji/drawer.rb
CHANGED
|
@@ -25,35 +25,38 @@ module Prawn
|
|
|
25
25
|
def draw_emoji(text, text_options)
|
|
26
26
|
return text unless @emoji_index.to_regexp =~ text
|
|
27
27
|
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
result_texts = []
|
|
29
|
+
target_text = text
|
|
30
30
|
|
|
31
|
-
while
|
|
32
|
-
left_text, emoji_unicode, remaining_text = partition_emoji(
|
|
31
|
+
while target_text do
|
|
32
|
+
left_text, emoji_unicode, remaining_text = partition_emoji(target_text)
|
|
33
33
|
|
|
34
34
|
if emoji_unicode.nil?
|
|
35
|
-
|
|
35
|
+
result_texts << target_text
|
|
36
36
|
break
|
|
37
37
|
end
|
|
38
38
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
emoji_unicode.
|
|
42
|
-
|
|
43
|
-
|
|
39
|
+
current_result_texts = [left_text]
|
|
40
|
+
current_result_texts <<
|
|
41
|
+
if emoji_unicode.text?
|
|
42
|
+
emoji_unicode.to_s
|
|
43
|
+
else
|
|
44
|
+
emoji_image = Emoji::Image.new(emoji_unicode)
|
|
44
45
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
46
|
+
emoji_x, emoji_y = text_options[:at]
|
|
47
|
+
emoji_x += @document.width_of(result_texts.join + left_text, text_options)
|
|
48
|
+
emoji_y += @document.font_size
|
|
48
49
|
|
|
49
|
-
|
|
50
|
+
draw_emoji_image emoji_image, at: [emoji_x, emoji_y], width: @document.font_size
|
|
50
51
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
52
|
+
Emoji::Substitution.new(@document).to_s
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
result_texts += current_result_texts
|
|
56
|
+
target_text = remaining_text
|
|
54
57
|
end
|
|
55
58
|
|
|
56
|
-
|
|
59
|
+
result_texts.join
|
|
57
60
|
end
|
|
58
61
|
|
|
59
62
|
def draw_emoji_image(emoji_image, at:, width:)
|
data/lib/prawn/emoji/version.rb
CHANGED
|
@@ -38,7 +38,9 @@ describe Prawn::Emoji::Drawer do
|
|
|
38
38
|
|
|
39
39
|
describe '#draw_emoji' do
|
|
40
40
|
subject { drawer.send :draw_emoji, text, text_options }
|
|
41
|
-
|
|
41
|
+
|
|
42
|
+
let(:text_options) { { at: [100, 200], font_size: 12 } }
|
|
43
|
+
let(:sub_char) { Prawn::Emoji::Substitution.new(document) }
|
|
42
44
|
|
|
43
45
|
describe 'when not includes emoji' do
|
|
44
46
|
let(:text) { 'abc' }
|
|
@@ -49,18 +51,23 @@ describe Prawn::Emoji::Drawer do
|
|
|
49
51
|
end
|
|
50
52
|
|
|
51
53
|
describe 'when includes emoji' do
|
|
52
|
-
let(:text) { "aaa#{sushi}bbb" }
|
|
53
|
-
|
|
54
|
-
it 'draws
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
54
|
+
let(:text) { "aaa#{sushi}bbb#{sushi}#{sushi}ccc" }
|
|
55
|
+
|
|
56
|
+
it 'draws alternative images for each emoji included in the text' do
|
|
57
|
+
image_x_positions = [
|
|
58
|
+
100 + document.width_of('aaa', text_options),
|
|
59
|
+
100 + document.width_of("aaa#{sub_char}bbb", text_options),
|
|
60
|
+
100 + document.width_of("aaa#{sub_char}bbb#{sub_char}", text_options)
|
|
61
|
+
]
|
|
62
|
+
|
|
63
|
+
image_x_positions.each { |x|
|
|
64
|
+
mock(drawer).draw_emoji_image(sushi_image, at: [x, 200 + 12], width: 12).once
|
|
65
|
+
}
|
|
59
66
|
subject
|
|
60
67
|
end
|
|
61
68
|
|
|
62
69
|
it 'returns text that all emoji has substituted' do
|
|
63
|
-
subject.must_equal "aaa#{
|
|
70
|
+
subject.must_equal "aaa#{sub_char}bbb#{sub_char}#{sub_char}ccc"
|
|
64
71
|
end
|
|
65
72
|
end
|
|
66
73
|
end
|
|
@@ -3,34 +3,36 @@
|
|
|
3
3
|
require 'test_helper'
|
|
4
4
|
|
|
5
5
|
describe Prawn::Emoji::Unicode do
|
|
6
|
-
|
|
6
|
+
def unicode(emoji)
|
|
7
|
+
Prawn::Emoji::Unicode.new(emoji)
|
|
8
|
+
end
|
|
7
9
|
|
|
8
10
|
describe '#==' do
|
|
9
|
-
it {
|
|
10
|
-
it {
|
|
11
|
+
it { unicode('🐟').must_be :==, unicode('🐟') }
|
|
12
|
+
it { unicode('🐟').wont_be :==, unicode('🍣') }
|
|
11
13
|
end
|
|
12
14
|
|
|
13
15
|
describe '#codepoint' do
|
|
14
|
-
it {
|
|
15
|
-
it {
|
|
16
|
+
it { unicode('🍣').codepoint.must_equal '1f363' }
|
|
17
|
+
it { unicode('🇯🇵').codepoint.must_equal '1f1ef-1f1f5' }
|
|
16
18
|
end
|
|
17
19
|
|
|
18
20
|
describe '#to_s' do
|
|
19
|
-
it {
|
|
20
|
-
it {
|
|
21
|
+
it { unicode('🍣').to_s.must_equal '🍣' }
|
|
22
|
+
it { unicode('❤️').to_s.wont_match /[\ufe0e\ufe0f]/ }
|
|
21
23
|
end
|
|
22
24
|
|
|
23
25
|
describe '#text?' do
|
|
24
26
|
describe 'no selector' do
|
|
25
|
-
it {
|
|
27
|
+
it { unicode('☀').wont_be :text? }
|
|
26
28
|
end
|
|
27
29
|
|
|
28
30
|
describe 'with text presentation selector' do
|
|
29
|
-
it {
|
|
31
|
+
it { unicode('☀︎').must_be :text? }
|
|
30
32
|
end
|
|
31
33
|
|
|
32
34
|
describe 'with emoji presentation selector' do
|
|
33
|
-
it {
|
|
35
|
+
it { unicode('☀️').wont_be :text? }
|
|
34
36
|
end
|
|
35
37
|
end
|
|
36
38
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: prawn-emoji
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.1.
|
|
4
|
+
version: 2.1.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Katsuya HIDAKA
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2018-01-03 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: prawn
|
|
@@ -1983,7 +1983,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
1983
1983
|
version: '0'
|
|
1984
1984
|
requirements: []
|
|
1985
1985
|
rubyforge_project:
|
|
1986
|
-
rubygems_version: 2.
|
|
1986
|
+
rubygems_version: 2.7.4
|
|
1987
1987
|
signing_key:
|
|
1988
1988
|
specification_version: 4
|
|
1989
1989
|
summary: Provides support for Emoji in Prawn
|