Coder Social home page Coder Social logo

hidakatsuya / prawn-emoji Goto Github PK

View Code? Open in Web Editor NEW
25.0 25.0 13.0 12.38 MB

Prawn::Emoji is an extention that adds Emoji support to Prawn.

Home Page: https://rubygems.org/gems/prawn-emoji

License: MIT License

Ruby 100.00%
emoji pdf prawn ruby twemoji

prawn-emoji's People

Contributors

aried3r avatar dependabot[bot] avatar hidakatsuya avatar ryo-kitamura avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

prawn-emoji's Issues

ttf corruption when requiring emoji

Just after updating to last ruby 2.4 (brew), my projects using emoji are drawing the normal .ttf fonts numbers as circled emoji numbers. Total disaster. The only solution is banning emoji and rewrite it all

Some emoji are not printed

Hey! Thanks for this gem!

I was just playing around with this with different emoji and fonts and found some behavior which I don't know if it is a bug or I'm missing a configuration option.

Prawn::Document.generate 'sushi.pdf' do
  font 'DejaVuSans.ttf'
  text 'πŸ‘πŸ€·β€β™€οΈπŸ¦„'
end

produces:

Screenshot 2020-02-20 at 11 10 44

The eye is part of Unicode 7.

I tested with unicode-emoji and maybe it's because it has a text representation?

Β» "πŸ‘πŸ€·β€β™€οΈπŸ¦„".scan(Unicode::Emoji::REGEX_INCLUDE_TEXT)XT)
=> [
  [0] "πŸ‘",
  [1] "πŸ€·β€β™€οΈ",
  [2] "πŸ¦„"
]

Β» "πŸ‘πŸ€·β€β™€οΈπŸ¦„".scan(Unicode::Emoji::REGEX)
=> [
  [0] "πŸ€·β€β™€οΈ",
  [1] "πŸ¦„"
]

Regarding unicode-emoji, is there a reason why the version constraint even contains the patch version? That way updates from 2.3 to 2.4 depend on a new release of this gem.

spec.add_runtime_dependency 'unicode-emoji', '~> 2.3.1'

Leading not taken into account

When an emoji is rendered, the leading for the current text box isn't subtracted from the y coordinate for the image so it ends up rendering above the baseline for a line of text with leading set.

I looked into trying to fix this, but I wasn't able to find a way to access the current leading.

Example:

@document.text '…', leading: 8

screen shot 2016-02-01 at 2 16 11 pm

Switch to Twemoji

Overview

Twemoji is

Twitter’s open source emoji has you covered for all your project's emoji needs. With support for the latest Unicode emoji specification, featuring 3,071 emojis, and all for free.
https://twemoji.twitter.com/

prawn-emoji will use the Twemoji's emoji since v3.0.

v3.0 (Twemoji 12.04) v2.1 or older (EmojiOne 2.0)
image image

See also

Status

Fixed by 5ae4c5b but not released. The release works in progress.

Consequences

  • More emojis supported
  • Emoji expression changes

Related Issue/PR

#20 #21

Should `draw_image` close the file descriptor?

Hey!

I was wondering if draw_image shouldn't maybe close the file descriptor of image. In our usage of prawn the tend to close the file descriptor when printing images, but I'm not sure if that would somehow affect prawn-emoji in any way or if we should trust the GC with that?

def draw_emoji(text, text_options:, base_text:)
image = Emoji::Image.new(text.emoji, @document.font_size)
base_x, base_y = text_options[:at]
x = image.adjust_x(base_x + @document.width_of(base_text + text.left, text_options))
y = image.adjust_y(base_y)
@document.image image.path, at: [x, y], width: image.width
end

After rendering a PDF I get the following output from ObjectSpace:

require 'prawn/emoji'

Prawn::Document.generate 'sushi.pdf' do
  font '/Users/kakazza/Library/Fonts/DejaVuSans.ttf'
  text '🐟 / πŸ”ͺ + 🍚 / 🍾 = 🍣'
end

ObjectSpace.each_object(File) do |f|
  puts "%s: %d" % [f.path, f.fileno] unless f.closed?
end

DejaVuSans.ttf: 26
prawn-emoji-3.1.0/emoji/images/1f35a.png: 29
prawn-emoji-3.1.0/emoji/images/1f37e.png: 30
prawn-emoji-3.1.0/emoji/images/1f363.png: 31
prawn-emoji-3.1.0/emoji/images/1f41f.png: 27
prawn-emoji-3.1.0/emoji/images/1f52a.png: 28

Joined emojis like πŸ‘¨β€πŸ‘¨β€πŸ‘¦ or 1️⃣ are not drawn

Overview

prawn-emojij v2.1 or older can't draw ZWJ Sequence and Combining Sequence emojis like πŸ‘¨β€πŸ‘¨β€πŸ‘¦ or 1️⃣.

Status

Fixed by d622e6f with #23 Switch to Twemoji. This will be released in v3.0.

master (will be v3.0) v2.1 or older
image image

See also

Related Issue/PR

#23 #20

Some emojis are not displayed.

First of all, thanks for this great gem. It works really great. But I have faced a problem when it comes to display some emojis.

When I render the pdf on Firefox all emojis are displayed nicely.

Here is a screenshot from firefox.
image

So far so good.

And now here is screenshot from Safari browser:

image

I have also opened it on Mac's default pdf viewer:

image

Safari & Mac's Preview behave the same and they show only smiley face. Other emojis are rendered but they have problem.
I have debuged the code and realize that prawn splits the text here if it find unicode such as any kind of emoji.

My prawn configuration:

Prawn version: 2.2.2
Prawn-emoji: 3.3.0

    font_families.update(
      'SFProDisplay' => {
        normal: Rails.root.join('app', 'assets', 'fonts', 'SFProDisplay-Regular.ttf'),
        bold: Rails.root.join('app', 'assets', 'fonts', 'SFProDisplay-Bold.ttf'),
        semi_bold: Rails.root.join('app', 'assets', 'fonts', 'SFProDisplay-Semibold.ttf'),
      },
      'DejaVuSans' => {
        normal: Rails.root.join('app', 'assets', 'fonts', 'DejaVuSans.ttf'),
        bold: Rails.root.join('app', 'assets', 'fonts', 'DejaVuSans-Bold.ttf'),
        semi_bold: Rails.root.join('app', 'assets', 'fonts', 'DejaVuSans-Bold.ttf')
      }
    )

    fill_color DEFAULT_COLOR
    font 'SFProDisplay'
    fallback_fonts ['DejaVuSans']

NOTE: If I set default font as DejaVuSans instead of SFProDisplay then all emojis are displayed.

I could not understand the problem otherwise I could open a PR. If you guide me if there is some sort of a bug I can send a PR.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.