hidakatsuya / prawn-emoji Goto Github PK
View Code? Open in Web Editor NEWPrawn::Emoji is an extention that adds Emoji support to Prawn.
Home Page: https://rubygems.org/gems/prawn-emoji
License: MIT License
Prawn::Emoji is an extention that adds Emoji support to Prawn.
Home Page: https://rubygems.org/gems/prawn-emoji
License: MIT License
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
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:
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.
prawn-emoji/prawn-emoji.gemspec
Line 23 in 26f83a1
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
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) |
---|---|
![]() |
![]() |
See also
Fixed by 5ae4c5b but not released. The release works in progress.
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?
prawn-emoji/lib/prawn/emoji/drawer.rb
Lines 45 to 54 in 26f83a1
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
prawn-emojij v2.1 or older can't draw ZWJ Sequence and Combining Sequence emojis like π¨βπ¨βπ¦ or 1οΈβ£.
Fixed by d622e6f with #23 Switch to Twemoji. This will be released in v3.0.
master (will be v3.0) | v2.1 or older |
---|---|
![]() |
![]() |
See also
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.
So far so good.
And now here is screenshot from Safari browser:
I have also opened it on Mac's default pdf viewer:
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.
zombie π§ββοΈ doesn't render when I test out a few common emoji issues even though it looks to be available in EmojiOne (found here https://www.emojicopy.com/)
Perhaps need to update to the latest EmojiOne 3.1.1 w/ some more images?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. πππ
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google β€οΈ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.