JuliaGraphics / Cairo.jl

Bindings to the Cairo graphics library.
Other
87 stars 56 forks source link

Emoji support #311

Open cormullion opened 4 years ago

cormullion commented 4 years ago

I believe Cairo now supports emoji (https://www.phoronix.com/scan.php?page=news_item&px=Cairo-1.15.8-Colored-Emoji) as of 1.15.8. I think Cairo.jl is now based on 1.16.0. So I thought it should be possible to display emoji...

Changing sample_text.jl to contain this:

select_font_face(cr, "AppleColorEmoji", Cairo.FONT_SLANT_NORMAL,
                Cairo.FONT_WEIGHT_BOLD)
set_font_size(cr, 90.0)

move_to(cr, 10.0, 135.0)
show_text(cr, "๐Ÿ™ฉ๐Ÿ™ช๐Ÿ™ซ๐Ÿ™ฌ๐Ÿ™ญ๐Ÿ™ฎ๐Ÿ™ฏ๐Ÿ™ฐ๐Ÿ™ฑ๐Ÿ™ฒ๐Ÿ™ณ๐Ÿ™ด๐Ÿ™ต๐Ÿ™ถ๐Ÿ™ท๐Ÿ™ธ๐Ÿ™น๐Ÿ™บ๐Ÿ™ป๐Ÿ™ผ๐Ÿ™ฝ๐Ÿ™พ๐Ÿ™ฟ๐Ÿš€๐Ÿš") 

just produces empty boxes. Is there a trick to getting them showing? Perhaps it's a FontConfig/FreeType thing?

Edit: I see that on some devices Github canโ€™t display some of the emojis in that string either... But theyโ€™re rendered correctly in Julia (n the REPL and in my editor (Atom)).

lobingera commented 4 years ago

Glyph boxes are usually a sign of not defined. Have you ensured, that this font is actually opened and does display any glyph?

cormullion commented 4 years ago

Actually, the boxes are the second string, "void"... so it looks like there aren't any boxes...

select_font_face(cr, "AppleColorEmoji", Cairo.FONT_SLANT_NORMAL, Cairo.FONT_WEIGHT_NORMAL)
set_font_size(cr, 10.0)

move_to(cr, 10.0, 135.0)
show_text(cr, "123๐ŸŒ€๐ŸŒ๐ŸŒ‚๐ŸŒƒ๐ŸŒ„๐ŸŒ…๐ŸŒ†๐ŸŒ‡๐ŸŒˆ๐ŸŒ‰๐ŸŒŠ")

move_to(cr, 70.0, 165.0)
text_path(cr, "void")
set_source_rgb(cr, 0.5, 0.5, 1)
fill_preserve(cr)
set_source_rgb(cr, 0, 0, 0)
set_line_width(cr, 2.56)
stroke(cr)

# draw helping lines
set_source_rgba(cr, 1, 0.2, 0.2, 0.6)
arc(cr, 10.0, 135.0, 5.12, 0, 2*pi)
close_path(cr)
arc(cr, 70.0, 165.0, 5.12, 0, 2*pi)
fill(cr)

displays

sample_text

so the digits (they're also in the font) appear, but the emoji characters don't.

curio-sitas commented 2 years ago

I there. Is there a package that does draw emojis ?

cormullion commented 2 years ago

Perhaps a plotting package like Plots.jl or Makie.jl might be able to do it. Or work with the terminal with Term.jl etc...

Using Cairo.jl and FreeType will get you only black and white images, although I'd love to be proved wrong...

using FreeTypeAbstraction
using FixedPointNumbers
using Luxor
using Colors

face = FTFont("/Library/FontLibrary/S/Segoe UI Emoji/seguiemj_0.ttf")
img, metric = renderface(face, Char(0x1F608), 256)
imgg = reinterpret(N0f8, permutedims(img, (2, 1)))
@draw begin
    placeimage(convert.(Colors.RGB, imgg), centered=true)
end
Screenshot 2022-10-02 at 17 15 45
curio-sitas commented 2 years ago

Perhaps a plotting package like Plots.jl or Makie.jl might be able to do it. Or work with the terminal with Term.jl etc...

Using Cairo.jl and FreeType will get you only black and white images, although I'd love to be proved wrong...

using FreeTypeAbstraction
using FixedPointNumbers
using Luxor
using Colors

face = FTFont("/Library/FontLibrary/S/Segoe UI Emoji/seguiemj_0.ttf")
img, metric = renderface(face, Char(0x1F608), 256)
imgg = reinterpret(N0f8, permutedims(img, (2, 1)))
@draw begin
    placeimage(convert.(Colors.RGB, imgg), centered=true)
end
Screenshot 2022-10-02 at 17 15 45

Thank's. I was wondering if there was a way to draw a text containing a native emoji but that does not seem to be possible without drawing an emoji alone and not correctly. Is the package abandonned ?, there have been no update in the last two years.

cormullion commented 2 years ago

Cairo.jl? No it's stable, as far as I know. (See also the library.)

In general, Julia support for fonts and typography is quite limited and spread piecemeal across various packages. Plotting package developers often write their own stuff as needed rather than develop a full-featured typography package. Cross-platform typography support is quite a tough problem...