News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

WriteConsoleW

Started by jj2007, March 29, 2010, 04:19:41 PM

Previous topic - Next topic

GregL

Another font you can use for the console is Consolas in Windows Vista and Seven. I have it set up for my consoles per KB 247815. It's monospace, has slashed zeroes and supports Unicode.

jj2007

Quote from: redskull on May 06, 2010, 12:14:41 PM
For Unicode, all you need is the right font.  These probably vary enormously between different versions sold in different countries.  I was completly incapable of generating JJ's results (the repaint bug), on either Vista or XP; all I ever got was blocks with the Lucida Console font.

I am still playing around with this problem, and to say the least, Windows misbehaves. Example output:

Same console window but after clicking up & down into the scrollbar:


Directly after the launch, items 802+1203 display boxes instead of text. Note these are the only lines that get wrapped. By clicking into the scrollbar, the text gets displayed properly.

You need MB version 23.06.2011 to assemble the attachment. Under the hood, when Recall detects a Unicode textfile, it launches a routine that sets the console environment using
- SetConsoleOutputCP, CP_UTF8
- GetCurrentConsoleFont
  .if the index is lower than 10 ; then it must be a raster font, so...
  - GetNumberOfConsoleFonts
  - SetConsoleFont to last index  ; ... use the last one, which is usually a Lucida Console example
  .endif
- SetConsoleTextAttribute to gray on black


The snippet below works fine, provided the languages are supported on one's PC, wrapped lines are avoided, and the user has at least once used a Lucida console in the current session. Overall, the handling of Unicode in consoles looks like amateur software, and it may be proof that Microsoft does not pay much attention to console mode users in China or Arabic countries...

Quoteinclude \masm32\MasmBasic\MasmBasic.inc   ; Download
   Init
   Recall "Unicode2Console.rc", L$()   ; that file is Unicode, as the name says ;-)
   
xchg eax, ebx   ; # of strings read into ebx
   ; ConsoleColor cGray   ; grey on black is the default
   For_ n=0 To ebx-1
      Print L$(n), CrLf$   ; print the strings
   Next

   ConsoleColor cYellow   ; yellow on black
   For_ n=0 To ebx-1
      Print L$(n), CrLf$   ; print the strings again
   Next

   Inkey CrLf$, "Check the wrapped text, and see what happens if you use the scrollbar"
   Exit
end start

redskull

Quote from: jj2007 on June 23, 2011, 10:46:56 AM
Note these are the only lines that get wrapped. By clicking into the scrollbar, the text gets displayed properly.

I don't think it's just Unicode, as I'm inclined to belive that it's strictly a unicode program (i.e. everything gets converted before it gets displayed.  Some cursory once-overs of the langauage "code page" files seems like they just map ASCII charcters to Unicode ones).  It's when a charcters doesn't fit into the fixed-size box that seems to have the console stumped.  As to why it works sometimes but not others, my only guess is that they put some "idiot proofing" into it to keep overhanging characters from painting pictures, but were not exactly consistent about where they tried to save you from yourself and where they left you to your own maddness.  An interesting test I would like to see is erasing some of those characters and seeing what gets left behind.

When I run the test on my machine, I just get the extended ASCII set without fancy letters, but rendering and scrolling works as it should.

What I find more interesting is the regular letters that got cut off (The "nese" in Chinese), especially the half-an-n that's left over.

-r
Strange women, lying in ponds, distributing swords, is no basis for a system of government

jj2007

Quote from: redskull on June 23, 2011, 11:23:44 PM
What I find more interesting is the regular letters that got cut off (The "nese" in Chinese), especially the half-an-n that's left over.

I couldn't find any solution for the missing 'nese but at least I solved the painting problem by inserting an InvalidateRect just before the Inkey. Now I am tempted to close the case for good, but still I would be curious to see what Windows 7 users with enabled Arabic & Chinese see when they run the test above.

Note the attachment above still lacks the InvalidateRect, for testing purposes. The current MasmBasic inserts it automatically if Unicode or UTF8 was detected and when it hits an Inkey statement.