Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How can an emoji be displayed?
#1
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.
Of all the places on Earth, and all the planets in the Universe, I'd rather live here (Perth, W.A.) Big Grin
Please visit my Website at: http://oldendayskids.blogspot.com/
Reply
#2
(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
New to QB64pe? Visit the QB64 tutorial to get started.
QB64 Tutorial
Reply
#3
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?
Of all the places on Earth, and all the planets in the Universe, I'd rather live here (Perth, W.A.) Big Grin
Please visit my Website at: http://oldendayskids.blogspot.com/
Reply
#4
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
Reply
#5
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
Reply
#6
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.
Of all the places on Earth, and all the planets in the Universe, I'd rather live here (Perth, W.A.) Big Grin
Please visit my Website at: http://oldendayskids.blogspot.com/
Reply
#7
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).
grymmjack (gj!)
GitHubYouTube | Soundcloud | 16colo.rs
Reply
#8
(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.


Attached Files
.zip   NotoColorEmoji-Regular.zip (Size: 7.39 MB / Downloads: 14)
Reply
#9
curious if forum editor can display this
?

if so how?

guess not, looks fine in the edit window
   
b = b + ...
Reply




Users browsing this thread: 3 Guest(s)