prawn-emoji 3.1.0 → 3.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/test.yml +33 -0
- data/CHANGELOG.md +17 -0
- data/Dockerfile +2 -8
- data/README.md +28 -11
- data/lib/prawn/emoji.rb +15 -2
- data/lib/prawn/emoji/drawer.rb +11 -2
- data/lib/prawn/emoji/substitution.rb +1 -1
- data/lib/prawn/emoji/text.rb +1 -1
- data/lib/prawn/emoji/version.rb +1 -1
- data/test/units/prawn/emoji/drawer_test.rb +30 -1
- data/test/units/prawn/emoji_test.rb +9 -56
- metadata +4 -4
- data/.travis.yml +0 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f1a48927e147cd633cc847c169b4f333b65e8317871fd5779a6eb2dd092952d6
|
4
|
+
data.tar.gz: 4d801491bbc68dfe274fb86a8f2537e8f2b0833a0304a4c9c0ffd3955de610d2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ca9c35d3e86f5d0425ac553a81c7fac39a618541736cfa0399444ffdbbb1d53e29c365fa47a6209edc6ab5331dcba76ac4a90c912c5ee285e5ff72f91f6bcbc2
|
7
|
+
data.tar.gz: bea7ba7dcfa9db8b208252b81afcad78afeaa29e5b541acf46745e6fc94fedf4a1ba7669a85c6e94ce90faa523f9cead703dfa7817852f6e1bd33e0497e66cfa
|
@@ -0,0 +1,33 @@
|
|
1
|
+
name: Test
|
2
|
+
|
3
|
+
on: [push, pull_request]
|
4
|
+
|
5
|
+
jobs:
|
6
|
+
test:
|
7
|
+
name: Test on ruby ${{ matrix.ruby_version }}
|
8
|
+
runs-on: ubuntu-latest
|
9
|
+
strategy:
|
10
|
+
matrix:
|
11
|
+
ruby_version:
|
12
|
+
- 2.4.x
|
13
|
+
- 2.5.x
|
14
|
+
- 2.6.x
|
15
|
+
- 2.7.x
|
16
|
+
steps:
|
17
|
+
- uses: actions/checkout@v1
|
18
|
+
- name: Set up diff-pdf
|
19
|
+
run: |
|
20
|
+
sudo apt-get update
|
21
|
+
sudo apt-get install make automake g++ libpoppler-glib-dev poppler-utils libwxgtk3.0-dev
|
22
|
+
git clone https://github.com/vslavik/diff-pdf.git -b v0.3 --depth 1 /tmp/diff-pdf-src
|
23
|
+
cd /tmp/diff-pdf-src
|
24
|
+
./bootstrap && ./configure && make && sudo make install
|
25
|
+
- name: Set up Ruby ${{ matrix.ruby_version }}
|
26
|
+
uses: actions/setup-ruby@v1
|
27
|
+
with:
|
28
|
+
ruby-version: ${{ matrix.ruby_version }}
|
29
|
+
- name: Build and test with Rake
|
30
|
+
run: |
|
31
|
+
gem install bundler
|
32
|
+
bundle install --jobs 4 --retry 3
|
33
|
+
bundle exec rake test
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,20 @@
|
|
1
|
+
## Master (Unreleased)
|
2
|
+
|
3
|
+
## 3.2.0
|
4
|
+
|
5
|
+
### Minor Enhancements
|
6
|
+
|
7
|
+
* Ruby 2.7.0 support
|
8
|
+
* Emoji Regex is now configurable using `Prawn::Emoji.config.regex` #30
|
9
|
+
```
|
10
|
+
Prawn::Emoji.config.regex # => ::Unicode::Emoji::REGEX_VALID by default
|
11
|
+
Prawn::Emoji.config.regex = ::Unicode::Emoji::REGEX_INCLUDE_TEXT
|
12
|
+
```
|
13
|
+
|
14
|
+
### Bug Fixes
|
15
|
+
|
16
|
+
* Fixed: Emoji Drawer does not close the file descriptor of emoji image #31
|
17
|
+
|
1
18
|
## 3.1.0
|
2
19
|
|
3
20
|
### Minor Enhancements
|
data/Dockerfile
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
FROM ruby:2.6.
|
1
|
+
FROM ruby:2.6.5
|
2
2
|
|
3
3
|
RUN apt-get update -qq && apt-get install -y build-essential xvfb
|
4
4
|
|
@@ -8,11 +8,5 @@ RUN apt-get install -y libpoppler-glib-dev poppler-utils libwxgtk3.0-dev && curl
|
|
8
8
|
|
9
9
|
RUN mkdir /prawn-emoji
|
10
10
|
|
11
|
-
ADD . /prawn-emoji
|
12
|
-
|
13
11
|
WORKDIR /prawn-emoji
|
14
|
-
|
15
|
-
RUN bundle install
|
16
|
-
|
17
|
-
ENTRYPOINT [ "bundle", "exec", "rake" ]
|
18
|
-
CMD [ "test:pdf" ]
|
12
|
+
VOLUME /prawn-emoji
|
data/README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# Prawn::Emoji
|
2
2
|
|
3
|
+
[![Test](https://github.com/hidakatsuya/prawn-emoji/workflows/Test/badge.svg?branch=master)](https://github.com/hidakatsuya/prawn-emoji/actions)
|
3
4
|
[![Gem Version](https://badge.fury.io/rb/prawn-emoji.svg)](https://badge.fury.io/rb/prawn-emoji)
|
4
|
-
[![Build Status](https://travis-ci.org/hidakatsuya/prawn-emoji.svg)](https://travis-ci.org/hidakatsuya/prawn-emoji)
|
5
5
|
[![Maintainability](https://api.codeclimate.com/v1/badges/edcd23ef38c2e393513b/maintainability)](https://codeclimate.com/github/hidakatsuya/prawn-emoji/maintainability)
|
6
6
|
|
7
7
|
Prawn::Emoji is an extention that adds Emoji support to [Prawn](https://github.com/prawnpdf/prawn).
|
@@ -67,11 +67,26 @@ require 'prawn/emoji'
|
|
67
67
|
|
68
68
|
In order to draw Emoji, you must use a True Type Font. I recommend you use a Japanese font.
|
69
69
|
|
70
|
+
## Configuring Emoji Regex
|
71
|
+
|
72
|
+
Emoji Regex is a regular expression used to determine which emoji to draw.
|
73
|
+
|
74
|
+
```ruby
|
75
|
+
Prawn::Emoji.config.regex # => ::Unicode::Emoji::REGEX_VALID by default
|
76
|
+
```
|
77
|
+
|
78
|
+
You can override it with [unicode-emoji's Regex](https://github.com/janlelis/unicode-emoji#regex):
|
79
|
+
|
80
|
+
```ruby
|
81
|
+
Prawn::Emoji.config.regex = ::Unicode::Emoji::REGEX_INCLUDE_TEXT
|
82
|
+
```
|
83
|
+
|
84
|
+
|
70
85
|
## Supported Versions
|
71
86
|
|
72
87
|
### Ruby
|
73
88
|
|
74
|
-
2.4, 2.5, 2.6
|
89
|
+
2.4, 2.5, 2.6, 2.7
|
75
90
|
|
76
91
|
### Prawn
|
77
92
|
|
@@ -105,21 +120,23 @@ $ bundle exec rake test:pdf
|
|
105
120
|
|
106
121
|
In order to run `test:pdf`, you need to install [diff-pdf](https://github.com/vslavik/diff-pdf) in your environment, or you can run test in the docker container as below.
|
107
122
|
|
108
|
-
###
|
123
|
+
### How to develop in Docker container
|
109
124
|
|
110
|
-
|
125
|
+
You can use the Docker container for development. This container contains the libraries required for testing, such as diff-pdf.
|
111
126
|
|
112
127
|
```
|
113
|
-
$ docker build -t prawn-emoji-
|
128
|
+
$ docker build -t prawn-emoji-dev .
|
114
129
|
|
115
|
-
|
116
|
-
$ docker run --rm prawn-emoji-test
|
130
|
+
$ docker run -v $PWD:/prawn-emoji -it prawn-emoji-dev bash
|
117
131
|
|
118
|
-
#
|
119
|
-
|
132
|
+
> /prawn-emoji#
|
133
|
+
```
|
134
|
+
|
135
|
+
You can run test:
|
120
136
|
|
121
|
-
|
122
|
-
|
137
|
+
```
|
138
|
+
> /prawn-emoji# bundle install
|
139
|
+
> /prawn-emoji# bundle exec rake test
|
123
140
|
```
|
124
141
|
|
125
142
|
### How to update bundled emojis
|
data/lib/prawn/emoji.rb
CHANGED
@@ -1,12 +1,25 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'prawn'
|
4
|
-
require 'pathname'
|
5
4
|
require 'unicode/emoji'
|
5
|
+
require 'pathname'
|
6
6
|
|
7
7
|
module Prawn
|
8
8
|
module Emoji
|
9
|
-
|
9
|
+
Config = Struct.new(
|
10
|
+
# Emoji Regex
|
11
|
+
#
|
12
|
+
# The following values are available (Default is `Unicode::Emoji::REGEX_VALID`):
|
13
|
+
# https://github.com/janlelis/unicode-emoji#regex.
|
14
|
+
:regex
|
15
|
+
)
|
16
|
+
def self.config
|
17
|
+
@config ||= Config.new(::Unicode::Emoji::REGEX_VALID)
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.regex
|
21
|
+
config.regex
|
22
|
+
end
|
10
23
|
|
11
24
|
def self.root
|
12
25
|
@root ||= Pathname.new File.expand_path('../..', File.dirname(__FILE__))
|
data/lib/prawn/emoji/drawer.rb
CHANGED
@@ -15,7 +15,7 @@ module Prawn
|
|
15
15
|
|
16
16
|
def draw(text, text_options)
|
17
17
|
return text unless text.encoding == ::Encoding::UTF_8
|
18
|
-
return text unless Emoji
|
18
|
+
return text unless Emoji.regex.match?(text)
|
19
19
|
|
20
20
|
result = []
|
21
21
|
target = Emoji::Text.new(text)
|
@@ -50,7 +50,16 @@ module Prawn
|
|
50
50
|
x = image.adjust_x(base_x + @document.width_of(base_text + text.left, text_options))
|
51
51
|
y = image.adjust_y(base_y)
|
52
52
|
|
53
|
-
|
53
|
+
# Prawn 2.2 does not close the image file when Pathname is passed to Document#image method.
|
54
|
+
#
|
55
|
+
# FIXME: This issue has been fixed by https://github.com/prawnpdf/prawn/pull/1090 but not released.
|
56
|
+
# Fix as follows after the PR released.
|
57
|
+
#
|
58
|
+
# @document.image(image_file.path, at: [x, y], width: image.width)
|
59
|
+
#
|
60
|
+
File.open(image.path, 'rb') do |image_file|
|
61
|
+
@document.image(image_file, at: [x, y], width: image.width)
|
62
|
+
end
|
54
63
|
end
|
55
64
|
end
|
56
65
|
end
|
data/lib/prawn/emoji/text.rb
CHANGED
data/lib/prawn/emoji/version.rb
CHANGED
@@ -47,7 +47,7 @@ describe Prawn::Emoji::Drawer do
|
|
47
47
|
sushi_image.adjust_x(x),
|
48
48
|
sushi_image.adjust_y(200)
|
49
49
|
]
|
50
|
-
mock(document).image(
|
50
|
+
mock(document).image(is_a(File), at: position, width: sushi_image.width).once
|
51
51
|
end
|
52
52
|
subject
|
53
53
|
end
|
@@ -117,4 +117,33 @@ describe Prawn::Emoji::Drawer do
|
|
117
117
|
it { _(subject).must_equal [sub_char * 2, japanese, sub_char * 2, japanese, sub_char * 2].join }
|
118
118
|
end
|
119
119
|
end
|
120
|
+
|
121
|
+
describe 'Closing opened image files' do
|
122
|
+
let(:text) { '🍣' }
|
123
|
+
let(:text_options) { { at: [100, 200], font_size: 12 } }
|
124
|
+
|
125
|
+
it do
|
126
|
+
opened_files = { before: count_opened_files, after: nil }
|
127
|
+
|
128
|
+
disable_gc {
|
129
|
+
subject
|
130
|
+
opened_files[:after] = count_opened_files
|
131
|
+
}
|
132
|
+
|
133
|
+
_(opened_files[:after]).must_equal opened_files[:before]
|
134
|
+
end
|
135
|
+
|
136
|
+
def count_opened_files
|
137
|
+
ObjectSpace.each_object(File).reject(&:closed?).count
|
138
|
+
end
|
139
|
+
|
140
|
+
def disable_gc
|
141
|
+
was_disabled = GC.disable
|
142
|
+
begin
|
143
|
+
yield
|
144
|
+
ensure
|
145
|
+
GC.enable unless was_disabled
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
120
149
|
end
|
@@ -2,67 +2,20 @@
|
|
2
2
|
|
3
3
|
require 'units/test_helper'
|
4
4
|
|
5
|
-
describe
|
6
|
-
describe '
|
7
|
-
|
8
|
-
pdf = Prawn::Document.new do |doc|
|
9
|
-
doc.font font_path('DejaVuSans.ttf')
|
10
|
-
doc.text 'sushi🍣teacup🍵'
|
5
|
+
describe Prawn::Emoji do
|
6
|
+
describe '.regex' do
|
7
|
+
subject { Prawn::Emoji.regex }
|
11
8
|
|
12
|
-
|
13
|
-
|
14
|
-
doc.font font_path('ipag.ttf')
|
15
|
-
doc.text '寿司🍣お茶🍵'
|
16
|
-
end
|
17
|
-
|
18
|
-
assert_properly_render_text(pdf)
|
9
|
+
describe 'Default' do
|
10
|
+
it { _(subject).must_equal ::Unicode::Emoji::REGEX_VALID }
|
19
11
|
end
|
20
|
-
end
|
21
12
|
|
22
|
-
|
23
|
-
|
24
|
-
pdf = Prawn::Document.new do |doc|
|
25
|
-
doc.font font_path('DejaVuSans.ttf')
|
26
|
-
doc.text_box 'sushi🍣teacup🍵', at: [100, 100], width: 500
|
13
|
+
describe 'Custom' do
|
14
|
+
let(:custom_regex) { ::Unicode::Emoji::REGEX_INCLUDE_TEXT }
|
27
15
|
|
28
|
-
|
29
|
-
doc.text_box '寿司🍣お茶🍵', at: [100, 300], width: 500
|
30
|
-
end
|
16
|
+
before { stub(Prawn::Emoji.config).regex { custom_regex } }
|
31
17
|
|
32
|
-
|
18
|
+
it { _(subject).must_equal custom_regex }
|
33
19
|
end
|
34
20
|
end
|
35
|
-
|
36
|
-
describe 'Prawn::Document#draw_text' do
|
37
|
-
it 'properly render text' do
|
38
|
-
pdf = Prawn::Document.new do |doc|
|
39
|
-
doc.font font_path('DejaVuSans.ttf')
|
40
|
-
doc.draw_text 'sushi🍣teacup🍵', at: [100, 100]
|
41
|
-
|
42
|
-
doc.font font_path('ipag.ttf')
|
43
|
-
doc.draw_text '寿司🍣お茶🍵', at: [100, 300]
|
44
|
-
end
|
45
|
-
|
46
|
-
assert_properly_render_text(pdf)
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
def assert_properly_render_text(pdf)
|
51
|
-
pdf_strings = extract_strings(pdf.render)
|
52
|
-
|
53
|
-
_(pdf_strings).must_include "sushi#{nbsp * 3}teacup#{nbsp * 3}"
|
54
|
-
_(pdf_strings).must_include "寿司 お茶 "
|
55
|
-
end
|
56
|
-
|
57
|
-
def font_path(name)
|
58
|
-
Prawn::Emoji.root.join 'test', 'fonts', name
|
59
|
-
end
|
60
|
-
|
61
|
-
def extract_strings(pdf)
|
62
|
-
PDF::Inspector::Text.analyze(pdf).strings
|
63
|
-
end
|
64
|
-
|
65
|
-
def nbsp
|
66
|
-
Prawn::Text::NBSP
|
67
|
-
end
|
68
21
|
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: 3.
|
4
|
+
version: 3.2.0
|
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: 2020-03-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: prawn
|
@@ -128,8 +128,8 @@ executables: []
|
|
128
128
|
extensions: []
|
129
129
|
extra_rdoc_files: []
|
130
130
|
files:
|
131
|
+
- ".github/workflows/test.yml"
|
131
132
|
- ".gitignore"
|
132
|
-
- ".travis.yml"
|
133
133
|
- CHANGELOG.md
|
134
134
|
- Dockerfile
|
135
135
|
- Gemfile
|
@@ -3261,7 +3261,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
3261
3261
|
- !ruby/object:Gem::Version
|
3262
3262
|
version: '0'
|
3263
3263
|
requirements: []
|
3264
|
-
rubygems_version: 3.
|
3264
|
+
rubygems_version: 3.1.2
|
3265
3265
|
signing_key:
|
3266
3266
|
specification_version: 4
|
3267
3267
|
summary: Adds Emoji support to Prawn
|
data/.travis.yml
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
language: ruby
|
2
|
-
|
3
|
-
sudo: false
|
4
|
-
|
5
|
-
rvm:
|
6
|
-
- 2.4.9
|
7
|
-
- 2.5.7
|
8
|
-
- 2.6.5
|
9
|
-
|
10
|
-
before_install:
|
11
|
-
- sudo apt-get install make automake g++ libpoppler-glib-dev poppler-utils libwxgtk3.0-dev
|
12
|
-
- git clone https://github.com/vslavik/diff-pdf.git /tmp/diff-pdf-src
|
13
|
-
- cd /tmp/diff-pdf-src
|
14
|
-
- ./bootstrap && ./configure && make && sudo make install
|
15
|
-
- diff-pdf --help
|
16
|
-
- cd $TRAVIS_BUILD_DIR
|
17
|
-
|
18
|
-
script: bundle exec rake test
|