QB64 Phoenix Edition
How can an emoji be displayed? - Printable Version

+- QB64 Phoenix Edition (https://qb64phoenix.com/forum)
+-- Forum: QB64 Rising (https://qb64phoenix.com/forum/forumdisplay.php?fid=1)
+--- Forum: Code and Stuff (https://qb64phoenix.com/forum/forumdisplay.php?fid=3)
+---- Forum: Help Me! (https://qb64phoenix.com/forum/forumdisplay.php?fid=10)
+---- Thread: How can an emoji be displayed? (/showthread.php?tid=2609)



How can an emoji be displayed? - PhilOfPerth - 04-21-2024

I would like to use an "emoji" (or similar) in my programme. Is there a (simple) way to do this? I don't see any appropriate symbols in the ASCII code.


RE: How can an emoji be displayed? - TerryRitchie - 04-21-2024

(04-21-2024, 01:18 AM)PhilOfPerth Wrote: I would like to use an "emoji" (or similar) in my programme. Is there a (simple) way to do this? I don't see any appropriate symbols in the ASCII code.
You'll need to either do this with an image (_LOADIMAGE then _PUTIMAGE) or find a font that contains the images you're looking for.

Fonts can contain small images, often referred to as dingbats: https://www.dafont.com/mtheme.php?id=7


RE: How can an emoji be displayed? - PhilOfPerth - 04-21-2024

Thanks Terry.
I found what I wanted in Wingding (a font I never expected to use).
I found I can change fonts mid-stream, but the new font seems to place the print position as 1,1.
I can fix this by using Locate r,c but wondered if there's a setting when using the new font that bypasses this?
Also, I only want to use one character, then revert to my old font. Is there a shorter way than re-re-setting my font?


RE: How can an emoji be displayed? - SMcNeill - 04-21-2024

Code: (Select All)
Sub SafeLoadFont (font#)
'Safely loads a font without destroying our current print location and making it revert to the top left corner.

down = CsrLin: right = Pos(0)
down = (down - 1) * _FontHeight
If _FontWidth <> 0 Then 'weed start with a monospace font
right = (right - 1) * _PrintWidth(" ") 'convert the monospace LOC to a graphic X coordinate
End If
_Font font#
If _FontWidth <> 0 Then 'we swapped to a monospace font
right = (right / _PrintWidth(" ")) + 1 'convert the graphic X coordinate back to a monospace LOC column
End If
down = (down / _FontHeight) + 1
If right < 1 Then right = 1
Locate down, right
End Sub


Instead of using _FONT to swap to the new font, use _SafeLoadFont instead. It's been a standard part of my extended toolbox of routines which I make use of for years now. Smile


RE: How can an emoji be displayed? - SMcNeill - 04-21-2024

For a quick print of a single character, like your emoji, just use the above with a little helper code:

SUB PrintSmiley
f& = _FONT 'get the current font so we can restore it.
SafeLoadFont <whatever the handle is for the wingding font you loaded earlier in your code>
Print Chr$(<whatever the value is for the character>);
SafeLoadFont f& 'restore the current font back.
END SUB


RE: How can an emoji be displayed? - PhilOfPerth - 04-21-2024

Thanks Steve.
I'll have a fiddle with that; 
I don't really see much difference between that and just re-declaring my original font though.
Maybe the difference will become more obvious when I use it.


RE: How can an emoji be displayed? - grymmjack - 04-21-2024

Since we display unicode we should be able to display emojis? I know that we should be able to do this in terminals that support UTF-8. Just print out the unicode code point code to the terminal and it will display the emoji configured in the system? Or is this wrong?

Is it that when using a graphics screen mode the emojis will not render properly?

TBH I haven't tried to render an emoji in terminal yet. (the terminal must support it - windows terminal, xterm, mac terminal, etc. all do).


RE: How can an emoji be displayed? - a740g - 04-21-2024

(04-21-2024, 03:04 PM)grymmjack Wrote: Since we display unicode we should be able to display emojis? I know that we should be able to do this in terminals that support UTF-8. Just print out the unicode code point code to the terminal and it will display the emoji configured in the system? Or is this wrong?
Is it that when using a graphics screen mode the emojis will not render properly?
TBH I haven't tried to render an emoji in terminal yet. (the terminal must support it - windows terminal, xterm, mac terminal, etc. all do).
Yeah. I too am not sure if printing emojis to the terminal will work with QB64's PRINT. I'll need to play with that.

However, printing to a graphics screen with _UPRINTSTRING should work. Note that we do not have color font support yet. So, the below will print in monochrome (you can pick a single color of your choice).

Code: (Select All)
SCREEN_NEWIMAGE(800, 600, 32)

DIM fnt AS LONG: fnt = _LOADFONT("Seguiemj.ttf", 22)

COLOR _RGB32(255, 0, 255)

_UPRINTSTRING (100, 100), MKL$(&H1F638&), , 32, fnt

[Image: Screenshot-2024-04-21-235755.png]

Update:

Added sample font with emojis.


RE: How can an emoji be displayed? - bplus - 04-21-2024

curious if forum editor can display this
?

if so how?

guess not, looks fine in the edit window