prawn-emoji 3.3.0 → 4.0.0.beta.1

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: da5130c4ae6b64826ec888c2eae4e859f9ebe98656b3367b9b2a3ef33657d5cc
4
- data.tar.gz: 0336be5198d8f4869e291f8b2d73ac1bd1c0bbf3a2394e9ff9eac1b1f8e98ca3
3
+ metadata.gz: df6049f973c509b992f095c4e0ba9350d60c3c4aa9a400e2d2ad8ed0e3a5770c
4
+ data.tar.gz: e8dc6fad7e6dfa7c77160462d46f93d5544d6de0b483507fc904cd1ab5cb0d1a
5
5
  SHA512:
6
- metadata.gz: 8f4fbdd4c9288065b02adfe14f49f3fc160fc47a2defa0b996ee2781eb2e4bc1ebfe99da6d9bc3b46a8b261aeb757c10349592527b295a862acd35d46cf39edf
7
- data.tar.gz: 4c9b700b7b0d647ca8e9cf5b7df17f7619959d6c7700576d6aa5d24d5e14fb8829fa1d3eefd9697d0b9f7bdd810341e03e2e6fa5e2a0741d40a043922b17d781
6
+ metadata.gz: dcc0640b6ee339682aec4a53dd65d620f370c93f7c19e011754b8493f66a710af911f8441fdf61e389695321aa661de20897bac39e78e6fa3236eef6fdf61168
7
+ data.tar.gz: '087003d57a544f7f6538d555f2cdb392c6b17eef2edf83e3fd94d73e11c0e50db369787334738fb22c4b805d23e9a2531454a33e935abf0b197f4834dde27a4c'
@@ -9,7 +9,6 @@ jobs:
9
9
  strategy:
10
10
  matrix:
11
11
  ruby_version:
12
- - 2.4.x
13
12
  - 2.5.x
14
13
  - 2.6.x
15
14
  - 2.7.x
@@ -19,7 +18,7 @@ jobs:
19
18
  run: |
20
19
  sudo apt-get update
21
20
  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
21
+ git clone https://github.com/vslavik/diff-pdf.git -b v0.4.1 --depth 1 /tmp/diff-pdf-src
23
22
  cd /tmp/diff-pdf-src
24
23
  ./bootstrap && ./configure && make && sudo make install
25
24
  - name: Set up Ruby ${{ matrix.ruby_version }}
@@ -1,5 +1,14 @@
1
1
  ## Master (Unreleased)
2
2
 
3
+ ## 4.0.0.beta.1
4
+
5
+ ### Breaking Changes
6
+
7
+ * Changes how to draw text including emoji:
8
+ * The result of drawing emoji will changes slightly
9
+ * prawn-emoji no longer requires Japanese fonts because it stopped replacing an emoji with the substitution char such as full-width space
10
+ * Drop ruby 2.4 support
11
+
3
12
  ## 3.3.0
4
13
 
5
14
  ### Minor Enhancements
data/Dockerfile CHANGED
@@ -6,7 +6,7 @@ RUN apt-get update -qq && apt-get install -y build-essential xvfb
6
6
  WORKDIR /tmp
7
7
  RUN apt-get install -y libpoppler-glib-dev poppler-utils libwxgtk3.0-dev && curl -L https://github.com/vslavik/diff-pdf/archive/master.tar.gz -o diff-pdf-master.tar.gz && tar zxf diff-pdf-master.tar.gz && cd diff-pdf-master && ./bootstrap && ./configure && make && make install
8
8
 
9
- RUN mkdir /prawn-emoji
9
+ RUN mkdir /src
10
10
 
11
- WORKDIR /prawn-emoji
12
- VOLUME /prawn-emoji
11
+ WORKDIR /src
12
+ VOLUME /src
data/README.md CHANGED
@@ -65,7 +65,7 @@ require 'prawn/emoji'
65
65
 
66
66
  ### True Type Font Required
67
67
 
68
- In order to draw Emoji, you must use a True Type Font. I recommend you use a Japanese font.
68
+ In order to draw Emoji, you must use a True Type Font.
69
69
 
70
70
  ## Configuring Emoji Regex
71
71
 
@@ -86,7 +86,7 @@ Prawn::Emoji.config.regex = ::Unicode::Emoji::REGEX_INCLUDE_TEXT
86
86
 
87
87
  ### Ruby
88
88
 
89
- 2.4, 2.5, 2.6, 2.7
89
+ 2.5, 2.6, 2.7
90
90
 
91
91
  ### Prawn
92
92
 
@@ -98,7 +98,7 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/hidaka
98
98
 
99
99
  ## Development
100
100
 
101
- ### How to test
101
+ ### Running tests
102
102
 
103
103
  Run all tests:
104
104
 
@@ -120,26 +120,25 @@ $ bundle exec rake test:pdf
120
120
 
121
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.
122
122
 
123
- ### How to develop in Docker container
123
+ ### Running tests in the docker container for development
124
124
 
125
- You can use the Docker container for development. This container contains the libraries required for testing, such as diff-pdf.
125
+ You can use the docker container for development. This container contains the libraries required for testing, such as diff-pdf.
126
126
 
127
127
  ```
128
- $ docker build -t prawn-emoji-dev .
128
+ $ docker build -t prawn-emoji:latest .
129
+ $ docker run -v $PWD:/src:cached -it prawn-emoji bash
129
130
 
130
- $ docker run -v $PWD:/prawn-emoji -it prawn-emoji-dev bash
131
-
132
- > /prawn-emoji#
131
+ > src#
133
132
  ```
134
133
 
135
134
  You can run test:
136
135
 
137
136
  ```
138
- > /prawn-emoji# bundle install
139
- > /prawn-emoji# bundle exec rake test
137
+ > src# bundle install
138
+ > src# bundle exec rake test
140
139
  ```
141
140
 
142
- ### How to update bundled emojis
141
+ ### Updating the bundled emojis
143
142
 
144
143
  ```
145
144
  $ bundle exec rake emoji:update VERSION=<Twemoji version>
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Prawn
4
+ module Emoji
5
+ class Char
6
+ VARIATION_SELECTORS = %w(fe0e fe0f).freeze
7
+
8
+ class << self
9
+ def format_codepoint(codepoints)
10
+ (codepoints - VARIATION_SELECTORS).map { |c| c.rjust(4, '0') }.join('-').downcase
11
+ end
12
+ end
13
+
14
+ attr_reader :font_size, :char
15
+ alias_method :to_s, :char
16
+
17
+ def initialize(char, font_size)
18
+ @char = char
19
+ @font_size = font_size
20
+ end
21
+
22
+ def ==(other)
23
+ char == other.to_s
24
+ end
25
+
26
+ def codepoint
27
+ @codepoint ||= self.class.format_codepoint(char.codepoints.map { |c| c.to_s(16) })
28
+ end
29
+
30
+ def width
31
+ @width ||= font_size * 0.85
32
+ end
33
+
34
+ def height
35
+ @height ||= font_size * 0.8
36
+ end
37
+ end
38
+ end
39
+ end
@@ -5,9 +5,16 @@ require_relative 'drawer'
5
5
  module Prawn
6
6
  module Emoji
7
7
  module Drawable
8
+ # == Additional Options
9
+ # <tt>:emoji</tt>:: <tt>boolean</tt>. Whether or not to draw an emoji [true]
8
10
  def draw_text!(text, options)
9
- text_without_emoji = emoji_drawer.draw(text.to_s, options)
10
- super text_without_emoji, options
11
+ draw_emoji = options.fetch(:emoji, true)
12
+
13
+ if draw_emoji && text.encoding == ::Encoding::UTF_8 && Emoji.regex.match?(text)
14
+ emoji_drawer.draw(text.to_s, options)
15
+ else
16
+ super(text, options)
17
+ end
11
18
  end
12
19
 
13
20
  private
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative 'substitution'
4
3
  require_relative 'index'
5
4
  require_relative 'image'
6
5
  require_relative 'text'
@@ -14,41 +13,40 @@ module Prawn
14
13
  end
15
14
 
16
15
  def draw(text, text_options)
17
- return text unless text.encoding == ::Encoding::UTF_8
18
- return text unless Emoji.regex.match?(text)
16
+ cursor_x, cursor_y = text_options[:at]
19
17
 
20
- result = []
21
- target = Emoji::Text.new(text)
18
+ emoji_text = Emoji::Text.new(text, document.font_size)
22
19
 
23
- while target.contains_emoji? do
24
- if emoji_index.include?(target.emoji.codepoint)
25
- draw_emoji(
26
- target,
27
- text_options: text_options,
28
- base_text: result.join
29
- )
30
- result << target.left + Emoji::Substitution.new(@document).to_s
20
+ while emoji_text.contains_emoji? do
21
+ if emoji_index.include?(emoji_text.emoji.codepoint)
22
+ cursor_x += draw_text(emoji_text.left, at: [cursor_x, cursor_y], text_options: text_options)
23
+ cursor_x += draw_emoji(emoji_text.emoji, at: [cursor_x, cursor_y])
31
24
  else
32
- result << target.left_with_emoji
25
+ cursor_x += draw_text(emoji_text.left_with_emoji, at: [cursor_x, cursor_y], text_options: text_options)
33
26
  end
34
-
35
- target = Emoji::Text.new(target.remaining)
27
+ emoji_text = Emoji::Text.new(emoji_text.remaining, document.font_size)
36
28
  end
37
29
 
38
- result.join + target.to_s
30
+ draw_text!(emoji_text.to_s, at: [cursor_x, cursor_y], text_options: text_options)
39
31
  end
40
32
 
41
33
  private
42
34
 
43
- attr_reader :emoji_index
35
+ attr_reader :emoji_index, :document
44
36
 
45
- def draw_emoji(text, text_options:, base_text:)
46
- image = Emoji::Image.new(text.emoji, @document.font_size)
37
+ def draw_text!(text, at:, text_options:)
38
+ document.draw_text!(text, text_options.merge(emoji: false, at: at))
39
+ end
47
40
 
48
- base_x, base_y = text_options[:at]
41
+ def draw_text(text, at:, text_options:)
42
+ draw_text!(text, at: at, text_options: text_options)
43
+ document.width_of(text, text_options)
44
+ end
49
45
 
50
- x = image.adjust_x(base_x + @document.width_of(base_text + text.left, text_options))
51
- y = image.adjust_y(base_y)
46
+ def draw_emoji(emoji_char, at:)
47
+ emoji_image = Emoji::Image.new(emoji_char)
48
+
49
+ x, y = at
52
50
 
53
51
  # Prawn 2.2 does not close the image file when Pathname is passed to Document#image method.
54
52
  #
@@ -57,9 +55,11 @@ module Prawn
57
55
  #
58
56
  # @document.image(image_file.path, at: [x, y], width: image.width)
59
57
  #
60
- File.open(image.path, 'rb') do |image_file|
61
- @document.image(image_file, at: [x, y], width: image.width)
58
+ File.open(emoji_image.path, 'rb') do |image_file|
59
+ @document.image(image_file, at: [x, y + emoji_char.height], width: emoji_char.width)
62
60
  end
61
+
62
+ emoji_char.width + document.character_spacing
63
63
  end
64
64
  end
65
65
  end
@@ -1,35 +1,21 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'yaml'
4
- require_relative 'unicode'
5
-
6
3
  module Prawn
7
4
  module Emoji
8
5
  class Image
9
6
  STORE = Emoji.root.join 'emoji', 'images'
10
7
 
11
- attr_reader :unicode, :font_size
12
-
13
- def initialize(unicode, font_size)
14
- @unicode = unicode
15
- @font_size = font_size
8
+ def initialize(emoji_char)
9
+ @emoji_char = emoji_char
16
10
  end
17
11
 
18
12
  def path
19
- STORE.join("#{unicode.codepoint}.png").to_s
20
- end
21
-
22
- def adjust_x(base_x)
23
- base_x + (font_size - width) / 2
13
+ STORE.join("#{emoji_char.codepoint}.png").to_s
24
14
  end
25
15
 
26
- def adjust_y(base_y)
27
- base_y + font_size * 0.8
28
- end
16
+ private
29
17
 
30
- def width
31
- font_size * 0.85
32
- end
18
+ attr_reader :emoji_char
33
19
  end
34
20
  end
35
21
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative 'unicode'
3
+ require 'yaml'
4
4
 
5
5
  module Prawn
6
6
  module Emoji
@@ -1,15 +1,16 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative 'unicode'
3
+ require_relative 'char'
4
4
 
5
5
  module Prawn
6
6
  module Emoji
7
7
  class Text
8
8
  attr_reader :left, :emoji, :remaining
9
9
 
10
- def initialize(text)
10
+ def initialize(text, font_size)
11
+ @text = text
11
12
  @left, emoji_char, @remaining = partition_by_emoji(text)
12
- @emoji = Emoji::Unicode.new(emoji_char) unless emoji_char.empty?
13
+ @emoji = Emoji::Char.new(emoji_char, font_size) unless emoji_char.empty?
13
14
  end
14
15
 
15
16
  def contains_emoji?
@@ -21,7 +22,7 @@ module Prawn
21
22
  end
22
23
 
23
24
  def to_s
24
- left_with_emoji + remaining
25
+ @text
25
26
  end
26
27
 
27
28
  private
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Prawn
4
4
  module Emoji
5
- VERSION = '3.3.0'
5
+ VERSION = '4.0.0.beta.1'
6
6
  end
7
7
  end
@@ -11,7 +11,7 @@ Gem::Specification.new do |spec|
11
11
  spec.homepage = 'https://github.com/hidakatsuya/prawn-emoji'
12
12
  spec.license = 'MIT'
13
13
 
14
- spec.required_ruby_version = '>= 2.4'
14
+ spec.required_ruby_version = '>= 2.5'
15
15
 
16
16
  spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
17
17
  `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^test/}) }
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.3.0
4
+ version: 4.0.0.beta.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: 2020-05-30 00:00:00.000000000 Z
11
+ date: 2020-07-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: prawn
@@ -3486,13 +3486,12 @@ files:
3486
3486
  - emoji/images/e50a.png
3487
3487
  - emoji/index.yml
3488
3488
  - lib/prawn/emoji.rb
3489
+ - lib/prawn/emoji/char.rb
3489
3490
  - lib/prawn/emoji/drawable.rb
3490
3491
  - lib/prawn/emoji/drawer.rb
3491
3492
  - lib/prawn/emoji/image.rb
3492
3493
  - lib/prawn/emoji/index.rb
3493
- - lib/prawn/emoji/substitution.rb
3494
3494
  - lib/prawn/emoji/text.rb
3495
- - lib/prawn/emoji/unicode.rb
3496
3495
  - lib/prawn/emoji/version.rb
3497
3496
  - prawn-emoji.gemspec
3498
3497
  homepage: https://github.com/hidakatsuya/prawn-emoji
@@ -3507,12 +3506,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
3507
3506
  requirements:
3508
3507
  - - ">="
3509
3508
  - !ruby/object:Gem::Version
3510
- version: '2.4'
3509
+ version: '2.5'
3511
3510
  required_rubygems_version: !ruby/object:Gem::Requirement
3512
3511
  requirements:
3513
- - - ">="
3512
+ - - ">"
3514
3513
  - !ruby/object:Gem::Version
3515
- version: '0'
3514
+ version: 1.3.1
3516
3515
  requirements: []
3517
3516
  rubygems_version: 3.1.2
3518
3517
  signing_key:
@@ -1,40 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'forwardable'
4
-
5
- module Prawn
6
- module Emoji
7
- class Substitution
8
- extend Forwardable
9
-
10
- FULL_SIZE_SPACE = ' '
11
- HALF_SIZE_SPACE = Prawn::Text::NBSP
12
-
13
- def_delegator :@document, :width_of
14
-
15
- def initialize(document)
16
- @document = document
17
- @font = document.font
18
- @font_size = document.font_size
19
- end
20
-
21
- def to_s
22
- emoji_width == full_size_space_width ? FULL_SIZE_SPACE : half_size_spaces
23
- end
24
-
25
- private
26
-
27
- def emoji_width
28
- @emoji_width ||= @font_size + @document.character_spacing
29
- end
30
-
31
- def full_size_space_width
32
- width_of @font.normalize_encoding(FULL_SIZE_SPACE)
33
- end
34
-
35
- def half_size_spaces
36
- HALF_SIZE_SPACE * (emoji_width.to_f / width_of(HALF_SIZE_SPACE)).round
37
- end
38
- end
39
- end
40
- end
@@ -1,31 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Prawn
4
- module Emoji
5
- class Unicode
6
- VARIATION_SELECTORS = %w(fe0e fe0f).freeze
7
-
8
- class << self
9
- def format_codepoint(codepoints)
10
- (codepoints - VARIATION_SELECTORS).map { |c| c.rjust(4, '0') }.join('-').downcase
11
- end
12
- end
13
-
14
- def initialize(char)
15
- @unicode = char
16
- end
17
-
18
- def ==(other)
19
- to_s == other.to_s
20
- end
21
-
22
- def codepoint
23
- @codepoint ||= self.class.format_codepoint(@unicode.codepoints.map { |c| c.to_s(16) })
24
- end
25
-
26
- def to_s
27
- @unicode
28
- end
29
- end
30
- end
31
- end