DAY 017: _MAPUNICODE - Printable Version +- QB64 Phoenix Edition (https://qb64phoenix.com/forum) +-- Forum: Official Links (https://qb64phoenix.com/forum/forumdisplay.php?fid=16) +--- Forum: Learning Resources and Archives (https://qb64phoenix.com/forum/forumdisplay.php?fid=13) +---- Forum: Keyword of the Day! (https://qb64phoenix.com/forum/forumdisplay.php?fid=49) +---- Thread: DAY 017: _MAPUNICODE (/showthread.php?tid=1169) |
DAY 017: _MAPUNICODE - SMcNeill - 11-22-2022 As there's been several people asking about how to display extended characters (such as greek characters) onto the screen, I thought _MAPUNICODE would be a nice word for today. First: Download the attached unicode font file and extract it into your qb64pe root directory (the same one with the qb64pe executable). Then copy and paste the code below into qb64pe, and run it: Code: (Select All) Screen _NewImage(1280, 720, 32) Running the above, we start out with a burst of characters across the screen that everyone should be familiar with -- the 255 ASCII characters that we see and use all the time in QB64! Hit any key, and then you can see what the unicode characters from 1 to 255 look like. A large portion of the first half maps directly over from our current ASCII set to the UNICODE set of characters (everything from 32 to 128), but, as you can see, there's no symbols defined in our font for unicode characters 1 to 31. Those are/were control codes back in the day, and the vast majority of them were non-printing, so many unicode fonts don't have those characters in them. Our ASCII code actually maps unicode symbols from other values, and puts it in those spots, to make the character set that we're used to seeing. Now from 128 to 255, there's not a single character which matches up between the unicode values and our ASCII values. We tend to, by default, map the character codes from codepage 437 into those spots, so that our codes will match the same ones QB45 and all other basics used to use by default. Now, one problem with this is that we aren't offering a lot of the specialized characters (such as those with various accents and such), as we're offering the old character sets that were used to build boxes and such in old terminal screens. So, how would one fix that, if they wanted to display other symbols besides the ones we currently offer?? Hit any key in the demo, and you can see that there's a whole bunch of other characters inside the font we loaded! Even though QB64 only makes use of 256 of those characters, that doesn't mean our font doesn't have a whole lot more than 256 that we can choose from! (After all, if we couldn't use other characters, I'd never be able to create the demo that you're now viewing, now would I??) To pick and choose our display set, we simply make use of the _MAPUNICODE command. To easily get the most out of this command, I recommend the following steps: 1) Go to ✔️ ❤️ ★ Unicode Character Table (unicode-table.com) -- There's a ton of unicode symbols available out there. Find which code corresponds to the character you want. 2) Find a current ASCII character that you're not using. For my demo, I chose CHR$(0) for all my needs -- you can choose any of the 0 to 255 characters to replace that you want. 3) _MAPUNICDE unicode_number TO ascii_number It's that simple!! Now, whenever you need to display that character upon the screen, you can call upon it as needed. PRINT "Hello World " + CHR$(150) '150 for whatever symbol/character you decided to map to 150. Note that not every unicode font has every unicode character in it. When you run my demo, you'll see several square boxes -- that's default for "Nope! No symbol here!" If the font you have doesn't support the language/symbols you need, then you'll just have to swap to a different font. After all, you can't print characters that don't exist in your font set! RE: DAY 017: _MAPUNICODE - Pete - 11-22-2022 Ewwww I hates _MAP-UNEE-CODE! Cant's even gets a menu symbol to the title bar with the carnsarn idgit. - Sam from Sam-Clip. Well settle down there, cowboy. the title bar may have certain restrictions placed in it by Windows. Since the title needs to be used in things like Task Manager, maybe the developers didn't want odd characters present. Now you can display a blank box, as Steve described. Try... Code: (Select All) title$ = CHR$(4) + " FOO" The Windows system simply displays the empty box symbol, instead of the solid diamond character, which is CHR$(4). Now in Task manager, what do we see? We see just FOO.exe. The empty box symbol is ignored. Other windows symbols given to characters that won't show in the title bar are the = sign and the ? mark. Honestly I don't know for certain that we cannot start a title for the title bar with non-numeric and non-alphabetical Unicode characters, but so far no luck in finding a method to make it so. Pete RE: DAY 017: _MAPUNICODE - PhilOfPerth - 11-23-2022 @SMcNeill Wow, it worked! I have my Copyright symbol as chr$(0)! Very 'citing! RE: DAY 017: _MAPUNICODE - PhilOfPerth - 11-23-2022 Next question is: Can I still continue to use the rest of my "normal" symbols as well, or would I have to map those back? RE: DAY 017: _MAPUNICODE - SMcNeill - 11-23-2022 (11-23-2022, 05:06 AM)PhilOfPerth Wrote: Next question is: Can I still continue to use the rest of my "normal" symbols as well, or would I have to map those back? You have the normal character set that you're used to using and seeing all the time. _MAPCUNICODE only overwrites the characters that you tell it to -- nothing more. So, in your case where you mapped the copyright symbol to chr$(0), *ONLY* chr$(0) changed. All the rest of your ASCII codes are exactly the same as they've always been. If you just need a quick "swap out" for a brief moment to display one particular character, let me suggest this style trick: old_code = _MAPUNICODE(ASCII_position) 'get the unicode value of your old ascii position _MAPUNICODE new_unicode_value TO ASCII_position 'swap it out with the new unicode value you need 'do stuff with it _MAPUNICODE(ASCII_position) = old_code 'swap it back to the old value For example: old_code = _MAPUNICODE(1) 'store whatever the ASCII character is for that cute little smiley face _MAPUNICODE 169 TO 1 'your copyright symbol is now chr$(1), and our smiley face is gone... PRINT CHR$(1) 'print that copyright symbol _MAPUNICODE old_code TO 1 'map that old code value back, so CHR$(1) is our heroic smiley face once more! RE: DAY 017: _MAPUNICODE - gaslouk - 11-23-2022 (11-23-2022, 05:19 AM)SMcNeill Wrote: You have the normal character set that you're used to using and seeing all the time. _MAPCUNICODE only overwrites the characters that you tell it to -- nothing more. thank you very much for this small but necessary help all of you. Gaslouk. RE: DAY 017: _MAPUNICODE - bplus - 11-23-2022 Thanks for this, I got stuck right on this word in Wiki looking into Phil's question after I printed a 'c' and drew a circle around it. Too much work, so little payoff. I was thinking of pulling out my character editor code and app. Nah! We don't need that just for a CR, Spriggsy has THE SOLUTION for quick CR symbol. Good luck to @Gaslouk I admire those who take on coding in English. |