![]() |
|
display unicode text(by windows api) - 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: Programs (https://qb64phoenix.com/forum/forumdisplay.php?fid=7) +---- Thread: display unicode text(by windows api) (/showthread.php?tid=4193) Pages:
1
2
|
display unicode text(by windows api) - qbfans - 12-06-2025 Hello everyone, I'm a beginner, and QBasic was the first programming language I learned during my student days, although my knowledge of it was quite basic. I'm delighted to see how powerful it has become today. In this forum, I've learned a lot, but I've noticed that most discussions are quite advanced, with relatively few resources suitable for beginners—especially regarding localization, which is rarely addressed. Through my own exploration, I’ve managed to create a program that displays Chinese text in graphics mode. The core mechanism involves calling the Windows API to convert GBK to UTF-16. Please don’t laugh at my amateurish code—I’m still learning, and I welcome any feedback or corrections on its shortcomings. ![]() Code: (Select All) '$Console![]() RE: display unicode text(by windows api) - bplus - 12-06-2025 Hi @qbfans, your code looks pretty advanced to me, welcome to the forum! Well I tried your code it doesn't work, I suspect the fonts aren't loading and maybe more... I am wondering about the line that starts fn = ... because fn is old QB command word so the IDE editor is highlighting fn like a command word. I am going to try a font load test function that will alert me if a font doesn't load. RE: display unicode text(by windows api) - bplus - 12-06-2025 Well yes the fonts aren't loading except first? Didn't get anywhere with Chinese Text. Code: (Select All) $ConsoleAt least it runs without error for me. Actually the font looks unchanged so maybe even the first font, fn = OKFont&(FONT_PATH + "simsun.ttc", 20, "automono"), didn't load right either??? RE: display unicode text(by windows api) - qbfans - 12-06-2025 Thank you, bplus, for pointing that out. You're absolutely right — I made a serious mistake by not providing any error handling when the font fails to load.I have already updated the original post with corrections. Let me clarify a few points: The purpose of this program is to demonstrate a method for correctly displaying local/national characters (rather than garbled text) in QB64 applications. English users typically don't encounter this issue. On Chinese Windows systems where I've tested it, the display works correctly. Variables like fn, fn1, etc., are simply font handles used by the _LoadFont function. I'm not sure why fn appears highlighted, but pressing F1 doesn't bring up help information. The multiple fonts are loaded only for demonstration purposes. Since my testing was done on Chinese Windows systems, I didn't initially include Chinese font files, as they wouldn't be meaningful for most users and might affect testing results. However, I did leave comments in the code indicating that users should replace the font paths with their own local fonts and directories. The LINE INPUT section addresses a quirk in QB64's graphical mode where typed characters appear garbled on screen (though stored correctly in memory), making it hard for users to review or edit their input. Console mode provides a more user-friendly input experience. The dual INPUT sections are merely for comparison and are optional — they're included for anyone interested in testing the difference. Note that using the console requires the $CONSOLE metacommand. Following bplus's suggestion, I've revised the code by removing unnecessary portions and have now uploaded the STHUPO.TTF font file. If you place it in your Windows\Fonts directory, you should see it render correctly. I hope this approach helps non-English speakers display their native characters properly in QB64. Thank you all again for your feedback and corrections. RE: display unicode text(by windows api) - bplus - 12-06-2025 Ok here is translation of edited post: Thats Russian? Anyway I tested edited post that qbfans did, see attached zip as I didn't want to load the font file into Windows Fonts Folder, see attached. Here is result: Dang lost the Chinese Text but ran without error. @qbfans notice the screen is not in the middle. I recommend before using _ScreenMove _Middle to put a: _Delay [fraction of second], to allow time for the screen to load before it is moved. This is usually the problem with that particular command, oddly _ScreenMove with actual numbers works faster, for me anyway and no _Delay is needed. +1 @qbfans thanks for sharing and fixing. Edit: oops forgot to save the edited filed before zipping, new zip file now.
Test qbfans code.zip (Size: 2.39 MB / Downloads: 24)
RE: display unicode text(by windows api) - SMcNeill - 12-06-2025 I haven't had a chance to look closely over this, and from what I see just scrolling above, there appears to be as much code remarked out as there is code active, so I can't really follow it much on my browser. Let me give a quick demo of displaying chinese characters for you. I'm not fluent in the language so have no idea if I'm missing something here, but here's how to get a simplified chinese to display: Code: (Select All)
The font used is the one packaged for windows and should be readily available for most systems (I think). The file with the chinese is below. Feel free to grab and test it. RE: display unicode text(by windows api) - Pete - 12-06-2025 AI generated? It appears that way to me. Pete RE: display unicode text(by windows api) - bplus - 12-06-2025 Well Steves version is way simpler than qbfans. As Pete commented I had same suspecions, if qbfans was testing his AI code with us? But he did originally post all that code with only very few commented lines and his original graphic of his successful result remains in OP. I have no experience in Unicode so don't know squat but qbfans mentioned extra wide character handling in his code so it didn't look like just a straight font load and print thing to me in the middle of the night, last. RE: display unicode text(by windows api) - qbfans - 12-06-2025 My English is quite basic, so all the program descriptions and code comments I posted were translated into English using Deepseek. Actually, the core issue is that most members on this forum are from Latin language backgrounds, and they don't face the same Chinese character display problems that I do. There were no existing posts on this topic in the forum, so I had to explore and test everything myself. I studied lots of documentation and Unicode articles, and only posted after successfully getting it to work. Some experts might even think this simple code isn't worth mentioning. The code itself doesn't contain any advanced technical concepts for forum experts—it's just that no one had posted about this before. Steven's solution is excellent—he saves text as UTF-8 files, reads UTF-8 formatted text, and displays it using _UPrintString with parameter 8. However, as I mentioned earlier, my problem is that I need to display Chinese character strings that are assigned within my code and entered by users in graphics mode. Clearly, Steven's high-quality code can't solve this, because strings assigned in QB or obtained via INPUT use ANSI encoding by default. These need to be converted to Unicode16 or UTF-8 encoding before they can be displayed using _UPrintString with parameter 8 or 16. That's why I even wrote a UTF-16 → UTF-8 conversion function in QB for testing, to confirm this approach would work. Of course, this explanation is also translated by Deepseek. I'm not even sure if the translation accurately conveys what I mean. This code is just meant to provide a reference for others who have similar needs and are at a similar skill level as me. RE: display unicode text(by windows api) - bplus - 12-06-2025 Hi qbfans, The Deepseek translations seem excellent to me, very clear, hopefully they are doing as well with your meaning as they do with the English. And though I am fortunate to have QB64pe in my primary language I do appreciate the efforts made by folks who don't use English as their primary to help others with what they learn while overcoming word representations and symbols. Thats what forums are about, good efforts @qbfans! |