How to draw color emojis with love.graphics.print()

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
ki
Prole
Posts: 16
Joined: Tue Oct 09, 2012 10:23 am

How to draw color emojis with love.graphics.print()

Post by ki »

Hi! Is it possible to draw color emojis with love.graphics.print(), and if yes, how? I couldn't get this attempt to work.

main.lua:

Code: Select all

local mainFont = love.graphics.newFont("Helvetica.ttc", 10)
local mainFontHasGlyphs = mainFont:hasGlyphs("👋")
print("Helvetica has waving hand sign: ", mainFontHasGlyphs) -- prints "false", which is expected

local emojiFont = love.graphics.newFont("Apple Color Emoji.ttc", 10)
local emojiFontHasGlyphs = emojiFont:hasGlyphs("👋")
print("Apple Color Emoji has waving hand sign: ", emojiFontHasGlyphs) -- prints "true", which is expected

function love.draw() 
	love.graphics.setFont(mainFont)
	love.graphics.print("Hello world!", 100, 200)
	
	love.graphics.setFont(emojiFont)
	love.graphics.print("👋", 100, 300) -- this causes the error shown below.
end
The emoji is the waving hand sign (https://emojipedia.org/waving-hand/).

The files "Helvetica.ttc" and "Apple Color Emoji.ttc" are copied from "/System/Library/Fonts/" (macOS) into the same folder as main.lua (source: https://apple.stackexchange.com/a/214659).

The main.lua file is saved with the encoding UTF-8 without BOM.

Running the program results in the following error:

Code: Select all

Helvetica has waving hand sign: 	false
Apple Color Emoji has waving hand sign: 	true
Error: main.lua:15: TrueType Font glyph error: FT_Load_Glyph failed (0x7)
stack traceback:
	[string "boot.lua"]:777: in function <[string "boot.lua"]:773>
	[C]: in function 'print'
	main.lua:15: in function 'draw'
	[string "boot.lua"]:618: in function <[string "boot.lua"]:594>
	[C]: in function 'xpcall'
Trying with a different font (Google's Noto Color Emoji, from https://github.com/googlefonts/noto-emo ... ster/fonts) doesn't work either, though the error message is different:

Code: Select all

local notoFont = love.graphics.newFont("NotoColorEmoji.ttf", 10) -- results in an error with and without the size parameter 
Result:

Code: Select all

Error: TrueType Font loading error: FT_Set_Pixel_Sizes failed: 0x17 (invalid size?)
stack traceback:
	[string "boot.lua"]:777: in function <[string "boot.lua"]:773>
	[C]: at 0x010b587b60
	[C]: in function 'newFont'
	main.lua:2: in main chunk
	[C]: in function 'require'
	[string "boot.lua"]:570: in function <[string "boot.lua"]:380>
	[C]: in function 'xpcall'
	[string "boot.lua"]:787: in function <[string "boot.lua"]:780>
	[C]: in function 'xpcall'
However, it is possible to draw a black and white emoji with the font "NotoEmoji-Regular.ttf".
Attachments
TestEmoji.love.zip
Contains only the font "NotoEmoji-Regular.ttf"; the fonts "NotoColorEmoji.ttf", "Apple Color Emoji.ttc" and "Helvetica.ttc" are not included.
(288.29 KiB) Downloaded 238 times
ki
Prole
Posts: 16
Joined: Tue Oct 09, 2012 10:23 am

Re: How to draw color emojis with love.graphics.print()

Post by ki »

Update: color fonts are currently not supported in Löve. There's a (closed) change issue here: https://github.com/love2d/love/issues/1195

I guess it's possible to first convert emojis to images (with this tool for example: https://onlineunicodetools.com/convert-emoji-to-image) and then using these images in Löve -- if you have a small and fixed set of emojis you want to use.
User avatar
Sasha264
Party member
Posts: 131
Joined: Mon Sep 08, 2014 7:57 am

Re: How to draw color emojis with love.graphics.print()

Post by Sasha264 »

ki wrote: Tue Aug 04, 2020 10:54 am ...and then using these images in Löve -- if you have a small and fixed set of emojis you want to use.
But after you have images (colored) that is not so easy task to embed them inline with a regular text as that smile :o: for example. I tried to do that in my game: I want to print text like that: "You will get 100 <gold_icon_here> when you bring me <potion_icon_here> small potion.", and I did not find easy solution for this.
User avatar
dusoft
Party member
Posts: 482
Joined: Fri Nov 08, 2013 12:07 am
Location: Europe usually
Contact:

Re: How to draw color emojis with love.graphics.print()

Post by dusoft »

Bumping old thread - print / printf claims full support for UTF-8.
Emojis are part of UTF-8 now.
But I can not get them to print.

See: https://love2d.org/imgmirrur/qM41JUK.html
Heart should be shown instead of unknown character / box.
User avatar
dusoft
Party member
Posts: 482
Joined: Fri Nov 08, 2013 12:07 am
Location: Europe usually
Contact:

Re: How to draw color emojis with love.graphics.print()

Post by dusoft »

Actually, I tried an emoji font but to no avail, maybe it does not hint to sizes or something.
I went with saving emojis I need as images instead.
User avatar
pgimeno
Party member
Posts: 3541
Joined: Sun Oct 18, 2015 2:58 pm

Re: How to draw color emojis with love.graphics.print()

Post by pgimeno »

Fonts with colour emojis probably use features that Löve doesn't support. Try a using a font with B/W emoji support, like https://github.com/googlefonts/noto-emo ... egular.ttf
User avatar
dusoft
Party member
Posts: 482
Joined: Fri Nov 08, 2013 12:07 am
Location: Europe usually
Contact:

Re: How to draw color emojis with love.graphics.print()

Post by dusoft »

pgimeno wrote: Mon Jan 17, 2022 3:58 pm Fonts with colour emojis probably use features that Löve doesn't support. Try a using a font with B/W emoji support, like https://github.com/googlefonts/noto-emo ... egular.ttf
Thanks, tried that. Still no support for ZJW sequences, so images it is.
User avatar
ReFreezed
Party member
Posts: 612
Joined: Sun Oct 25, 2015 11:32 pm
Location: Sweden
Contact:

Re: How to draw color emojis with love.graphics.print()

Post by ReFreezed »

dusoft wrote: Mon Jan 17, 2022 1:29 pm Emojis are part of UTF-8 now.
Unicode, not UTF-8.

Also, a good thing about rendering emojis and other things using your own code is that you can go beyond what both LÖVE and Unicode provides, like animations, or interactable elements. Go nuts, to make your game as good as it can be, is what I'm saying! :)
Tools: Hot Particles, LuaPreprocess, InputField, (more) Games: Momento Temporis
"If each mistake being made is a new one, then progress is being made."
User avatar
dusoft
Party member
Posts: 482
Joined: Fri Nov 08, 2013 12:07 am
Location: Europe usually
Contact:

Re: How to draw color emojis with love.graphics.print()

Post by dusoft »

ReFreezed wrote: Tue Jan 18, 2022 2:56 am
dusoft wrote: Mon Jan 17, 2022 1:29 pm Emojis are part of UTF-8 now.
Unicode, not UTF-8.

Also, a good thing about rendering emojis and other things using your own code is that you can go beyond what both LÖVE and Unicode provides, like animations, or interactable elements. Go nuts, to make your game as good as it can be, is what I'm saying! :)
Thanks for the correction.

We could say this about any part of LÖVE :-) including basic stuff like drawing text on screen. But we all agree the engine should provide basic handling of text and images. I expected emojis to be part of that, but no big deal.
User avatar
slime
Solid Snayke
Posts: 3129
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: How to draw color emojis with love.graphics.print()

Post by slime »

At the time the original issue was created, there was almost no standardization in color emoji font formats, and libraries like FreeType barely had any support at all. It was not something love could reasonably support.

I believe the situation is a bit better now, but even so it seems like that Google font may still be using a nonstandard format (e.g. https://github.com/googlefonts/noto-emoji/issues/43 ).

Given the lack of solid standardization, lack of standardized color fonts with licenses that allow people to ship them, lack of interest in the feature from game developers using love in general, and a supply of alternative color font formats which do work with love (BMFont and ImageFont), there hasn't been a lot of reason to invest my personal time into this feature over the past few years.

That's not to say we shouldn't give this a second look now that a few years have passed since the original issue was created, or that we won't accept outside contribution. I'm just speaking to where I spend my own personal time, and the history of the feature in general.



As for the original topic, perhaps some BMFont exporter programs may recognize emoji font glyphs and export them to a BMFont image+definition file. If so you could do that, since love's font/text system supports color BMFont files.
Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 15 guests