Posts: 652
Threads: 96
Joined: Apr 2022
Reputation:
22
I think I asked this once before, but I can't find the post now, or the programme where I used it, so apologies to those who helped.
How can I display a Unicode character in PE?
I can use _MapUnicode for Unicode characters up to 127, (as in _MapUnicode 127 to 97) but not beyond. I don't want to access all of Unicode, just one character so I just want a simple way to map this to my character set.
Posts: 2,696
Threads: 327
Joined: Apr 2022
Reputation:
217
10-04-2024, 06:42 AM
(This post was last modified: 10-04-2024, 06:44 AM by SMcNeill.)
_MapUnicode (unicode value) TO (ascii value)
So if you want CHR$(255) to be a unicode symbol, use:
_MapUnicode 9648 TO 255 (For unicode symbol 9648, which is the black parallelogram symbol)
NOTE:
1) You have to have an unicode capable font loaded.
2) That font has to have the symbol in it. (Not all symbols are packed in all unicode fonts.)
3) You probably want to be in a graphic screen when printing an unicode character. If you're in SCREEN 0, that character will swap back as soon as you restore that _MapUnicode point back to whatever it was before.
Get your unicode character values from any list like this one: https://symbl.cc/en/unicode-table/
Posts: 476
Threads: 25
Joined: Nov 2022
Reputation:
45
@PhilofPerth I made a PETSCII translator (sorta) using unicode font to QB64PE if you are interested it is here:
https://github.com/grymmjack/qb64/blob/8...76C1-L83C7
In my case I wanted to translate the entire PETSCII range:
Code: (Select All)
FONT_FILE$ = "ASSETS/C64_Pro-STYLE.ttf"
FONT_STYLE$ = "MONOSPACE"
F& = _LOADFONT(FONT_FILE$, 16, FONT_STYLE$)
_FONT F&
PETSCII_UPPER_PUA = 60928 '&HEE00
FOR I = 0 TO 255
_MAPUNICODE PETSCII_UPPER_PUA + I TO I
NEXT I
This was stored int the font in the unicode Private Use Area, contiguously. So it was a matter of finding the character I wanted in the font, using charmap, then noting the hex code, (I could have just used &HEE00 I guess - but for some reason my brain wanted decimals since I was mapping to decimal range 0-255). Anyway, the end result worked exactly as intended.
I also had to have the font loaded of course, first.
Good luck!
Posts: 208
Threads: 13
Joined: Apr 2022
Reputation:
52
The easiest solution is using _UPRINTSTRING
Code: (Select All)
SCREEN _NEWIMAGE(640, 320, 32)
f& = _LOADFONT("arial.ttf", 20)
IF f& > 0 THEN _FONT f&
'a single char is easy with Utf-16 or Utf-32,
'if you know the exact unicode codepoint
_UPRINTSTRING (10, 10), MKI$(1046), , 16 'use MKI$() for Utf-16 encoding
_UPRINTSTRING (10, 30), MKL$(1046), , 32 'use MKL$() for Utf-32 encoding
'if you otherwise have a Utf-8 multibyte sequence,
'then you can assemble it
_UPRINTSTRING (10, 50), CHR$(208) + CHR$(150), , 8 'use CHR$() for multibyte Utf-8 encoding
'to write complete text, just concatenate the values
_UPRINTSTRING (10, 80), MKI$(1046) + MKI$(1046), , 16 'use MKI$() for Utf-16 encoding
_UPRINTSTRING (10, 100), MKL$(1046) + MKL$(1046), , 32 'use MKL$() for Utf-32 encoding
_UPRINTSTRING (10, 120), CHR$(208) + CHR$(150) + CHR$(208) + CHR$(150), , 8 'use CHR$() for multibyte Utf-8 encoding
_UPRINTSTRING (10, 160), "press any key...": SLEEP 'or write ASCII as is with _UPRINTSTRING
_FONT 16
SCREEN 0
SYSTEM
Posts: 476
Threads: 25
Joined: Nov 2022
Reputation:
45
10-04-2024, 11:13 AM
(This post was last modified: 10-04-2024, 11:15 AM by grymmjack.
Edit Reason: UPRINTSTRING in 3.7.0
)
(10-04-2024, 10:54 AM)RhoSigma Wrote: The easiest solution is using _UPRINTSTRING
Code: (Select All)
SCREEN _NEWIMAGE(640, 320, 32)
f& = _LOADFONT("arial.ttf", 20)
IF f& > 0 THEN _FONT f&
'a single char is easy with Utf-16 or Utf-32,
'if you know the exact unicode codepoint
_UPRINTSTRING (10, 10), MKI$(1046), , 16 'use MKI$() for Utf-16 encoding
_UPRINTSTRING (10, 30), MKL$(1046), , 32 'use MKL$() for Utf-32 encoding
'if you otherwise have a Utf-8 multibyte sequence,
'then you can assemble it
_UPRINTSTRING (10, 50), CHR$(208) + CHR$(150), , 8 'use CHR$() for multibyte Utf-8 encoding
'to write complete text, just concatenate the values
_UPRINTSTRING (10, 80), MKI$(1046) + MKI$(1046), , 16 'use MKI$() for Utf-16 encoding
_UPRINTSTRING (10, 100), MKL$(1046) + MKL$(1046), , 32 'use MKL$() for Utf-32 encoding
_UPRINTSTRING (10, 120), CHR$(208) + CHR$(150) + CHR$(208) + CHR$(150), , 8 'use CHR$() for multibyte Utf-8 encoding
_UPRINTSTRING (10, 160), "press any key...": SLEEP 'or write ASCII as is with _UPRINTSTRING
_FONT 16
SCREEN 0
SYSTEM
Sweet! Has that always been a thing? Ah, nevermind only since 3.7.0 - this is why I didn't use it It wasn't there! But awesome that it is now!
Also, can we print emojis in QB64PE with those joiners and stuff?
Posts: 652
Threads: 96
Joined: Apr 2022
Reputation:
22
Thanks all. I got most of that. It seems I need to find a font with my character glyph in it.
The _UPRINTSTRING method seems like the way to go; it gave me the Unicode character 1046 ok, but the character I want (2022) is apparently not in that font. Is there a way to find a common font that has this character in it?
Posts: 208
Threads: 13
Joined: Apr 2022
Reputation:
52
(10-05-2024, 12:43 AM)PhilOfPerth Wrote: Thanks all. I got most of that. It seems I need to find a font with my character glyph in it.
The _UPRINTSTRING method seems like the way to go; it gave me the Unicode character 1046 ok, but the character I want (2022) is apparently not in that font. Is there a way to find a common font that has this character in it?
Ah, a list bullet. Why unicode, I see at least two, with _CONTROLCHR OFF even five alternatives in the QB64 inbuilt font:
Code: (Select All)
_CONTROLCHR OFF
PRINT CHR$(4); CHR$(7); CHR$(9)
_CONTROLCHR ON
PRINT CHR$(249); CHR$(254)
Otherwise it could be hard to find a suitable font, my best guess was "Arial Unicode MS", the most complete unicode font I've found so far, but when I checked even that font doesn't have the U2022 in it.
Posts: 1,002
Threads: 50
Joined: May 2022
Reputation:
27
10-05-2024, 11:46 AM
(This post was last modified: 10-05-2024, 11:48 AM by Kernelpanic.)
Searching for this character? U2022 is decimal 8226.
Code: (Select All)
Screen _NewImage(640, 320, 32)
f& = _LoadFont("arial.ttf", 20)
If f& > 0 Then _Font f&
_UPrintString (10, 100), MKL$(8226), , 32
Posts: 208
Threads: 13
Joined: Apr 2022
Reputation:
52
(10-05-2024, 11:46 AM)Kernelpanic Wrote: Searching for this character? U2022 is decimal 8226.
Code: (Select All)
Screen _NewImage(640, 320, 32)
f& = _LoadFont("arial.ttf", 20)
If f& > 0 Then _Font f&
_UPrintString (10, 100), MKL$(8226), , 32
Oh, now you see how important it is to know the base of a number, especially if there are no letters in it which would immediatly identify it as a hex number.
Posts: 652
Threads: 96
Joined: Apr 2022
Reputation:
22
(10-05-2024, 11:52 AM)RhoSigma Wrote: (10-05-2024, 11:46 AM)Kernelpanic Wrote: Searching for this character? U2022 is decimal 8226.
Code: (Select All)
Screen _NewImage(640, 320, 32)
f& = _LoadFont("arial.ttf", 20)
If f& > 0 Then _Font f&
_UPrintString (10, 100), MKL$(8226), , 32
Oh, now you see how important it is to know the base of a number, especially if there are no letters in it which would immediatly identify it as a hex number.
Good grief!!!!
I can't believe I never thunk of that! I must be seniler than I thought! Thanks RhoSigma.
|