News:

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

Problems with characters and fonts

Started by RuiLoureiro, May 24, 2005, 06:41:39 PM

Previous topic - Next topic

GregL

#15
Rui,

You could use the chr$ macro and the ASCII codes of the characters you want. Or just type the ASCII codes directly into the .data section.

Assuming ASCII has the characters you want, it's limited.

[later]
It looks like ASCII doesn't have all of the characters you need, most but not all. If ASCII won't do it, you will probably want to pursue MichaelW's suggestion of changing the console font to Lucida Console. To set the console font manually, open a command prompt, right-click on the title bar, select Properties, and then Font. I can't find an API function that will change the console font. Changing the Code-Page will not have any effect if a raster font is in use, which is the default.
[/later]


MichaelW

I corrected an error in my previous post.

I couldn't find an API function to change the console font directly, but you can change it for the currrent user in the registry:

In "HKEY_CURRENT_USER\Console" set the value named "FaceName" to "Lucida Console".
eschew obfuscation

RuiLoureiro

#17
Hi
   I will try to remake the problem.

    1. In the link that Greg gave us, we can see three tables: ASCII, ANSI and
       IBM extended (see the tables);

    2. The only one that serves me is the ASCII, because the others  haven't
       BoxDrawing chars or all BoxDrawing chars;

    3. When we compile the example with the string

        _String db "é já às íngremes acções"

       it is coded like astr:

        astr db 0E9h,' ','j',0E1h,' ',0E0h,'s',' ',0EDh,'n','g','r'
              db 'e','m','e','s',' ','a','c',0E7h,0F5h,'e','s',0

This is

char:          é     j  á     à  s     í  ...ç  õ  e  s
code:          E9 20 6A E1 20 E0 73 20 ED    E7 F5 65 73  [ hexa ]


      4. Then, if the computer uses ANSI char set, it is printed correctly;
               If it uses IBM extended or ASCII what we see are not that chars.
               [in GUI it is using ANSI, but in CONSOLE it is IBM extended ]

     5. So, i thk, the problem are two things:

                A – the string cannot be coded ( by MASM ) as

char:          é     j  á     à  s     í  ...ç  õ  e  s
code:          E9 20 6A E1 20 E0 73 20 ED    E7 F5 65 73  [ hexa ]

                It must be coded in ASCII.

               B – i want to use ASCII character set and not IBM font.

When i use the right mouse button in the title bar, i can change the font to Lucida Console and the string is correctly printed. But, this programming method i dont like. The mouse buttons should not work at all ( it is another problem ).

Greg, some days ago, Mark Jones said me the same: «... if the current font is a default raster font, SetConsoleOutputCP does not affect how extended characters are displayed». And if we haven't an API function to change the console font, then we should have one to change properties or something like that.
Can we not know what the font properties ?

Note 1. If i cannot know the basic starting point properties such as fonts, char tables etc. i thk i cannot program.

Note 2: Michael, i haven't msvcrt.inc/.lib to compile the example(i installed SP2 ). I thk you are refering to RegOpenKeyEx RegEnumValue when you refer "HKEY_CURRENT_USER \Console" (?).

MichaelW

#18
Rui,

Sorry, I had forgotten where I got msvcrt.inc and msvcrt.lib.

http://www.masmforum.com/simple/index.php?topic=1638.0

In my previous post I was assuming the change would be made with a registry editor, such as the REGEDIT.EXE that comes with Windows. Before you modify the registry, either manually or with the API, it's a good idea to create a backup. That way, if something goes wrong and you damage the registry you can undo the damage. This is a program that makes the change using the API:

EDIT: Added code to restart the console so the changes will take effect.


; ««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    .486                       ; create 32 bit code
    .model flat, stdcall       ; 32 bit memory model
    option casemap :none       ; case sensitive

    include \masm32\include\windows.inc
    include \masm32\include\masm32.inc
    include \masm32\include\user32.inc
    include \masm32\include\kernel32.inc
    include \masm32\include\advapi32.inc
    include \masm32\include\msvcrt.inc

    includelib \masm32\lib\masm32.lib
    includelib \masm32\lib\user32.lib
    includelib \masm32\lib\kernel32.lib
    includelib \masm32\lib\advapi32.lib
    includelib \masm32\lib\msvcrt.lib

    include \masm32\macros\macros.asm
    include \masm32\macros\ucmacros.asm

    NAME_SIZE EQU 1024

    SUBKEY EQU "Console"

; ««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    .data
      hKey          dd 0
      cbValueData   dd NAME_SIZE
      valueData     db NAME_SIZE dup(0)
      valent        VALENT <>
      subKey        db SUBKEY,0
    .code
; ««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
start:
; ««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    ; ----------------------------------
    ; Open the target registry subkey.
    ; ----------------------------------
    invoke RegOpenKeyEx,HKEY_CURRENT_USER,ADDR subKey,0,
                        KEY_ALL_ACCESS,ADDR hKey
    .IF eax != ERROR_SUCCESS
        print chr$("error opening key"),13,10
        jmp   fini
    .ENDIF

    ; -------------------------------------------
    ; Find and display the FaceName value data.
    ; -------------------------------------------
    mov   valent.ve_valuename, chr$("FaceName")
    mov   valent.ve_valuelen, NAME_SIZE
    mov   valent.ve_valueptr, OFFSET valueData
    mov   valent.ve_type, REG_SZ
    invoke RegQueryMultipleValues,hKey,ADDR valent,1,
      ADDR valueData,ADDR cbValueData
    .IF eax != ERROR_SUCCESS
        print chr$("error finding value/data"),13,10
        jmp   fini
    .ENDIF
    print chr$("FaceName = ")
    .IF valueData
      print ADDR valueData,13,10
    .ELSE
      print chr$("NULL"),13,10
    .ENDIF   
   
    ; --------------------------------------------------
    ; Set the FaceName value data to "Lucida Console".
    ; --------------------------------------------------
    invoke RegSetValueEx,hKey,chr$("FaceName"),NULL,
      REG_SZ,chr$("Lucida Console"),15  ; including null
    .IF eax != ERROR_SUCCESS
        print chr$("error setting value data"),13,10
        jmp   fini
    .ENDIF

    ; ----------------------------------------
    ; Pause and then restart the console so
    ; the changes will take effect.
    ; ----------------------------------------
    mov   eax, input(13,10,"Press enter to restart console...")
    invoke FreeConsole
    invoke AllocConsole

    ; -------------------------------------------
    ; Find and display the FaceName value data
    ; (cbValueData must be reset because the
    ; previous call could have set it to 1).
    ; -------------------------------------------
    mov   cbValueData, NAME_SIZE
    mov   valent.ve_valuename, chr$("FaceName")
    mov   valent.ve_valuelen, NAME_SIZE
    mov   valent.ve_valueptr, OFFSET valueData
    mov   valent.ve_type, REG_SZ
    invoke RegQueryMultipleValues,hKey,ADDR valent,1,
      ADDR valueData,ADDR cbValueData
    .IF eax != ERROR_SUCCESS
        print chr$("error finding value/data"),13,10
        jmp   fini
    .ENDIF
    print chr$("FaceName = ")
    .IF valueData
      print ADDR valueData,13,10
    .ELSE
      print chr$("NULL"),13,10
    .ENDIF

  fini:
    mov   eax, input(13,10,"Press enter to exit...")
    exit
; ««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
end start


REGEDIT is also a good tool for learning about the registry.
eschew obfuscation

GregL

Rui,

Like this for IBM ASCII:

  char:       é     j  á     à  s     í ... ç  õ  e  s
  code:      82 20 6A A0 20 85 73 20 A1    87 ?? 65 73

One small problem, there is no õ in IBM ASCII.

You can determine the current console font with GetCurrentConsoleFont.

The only way I know of to change the console font programatically, is how MichaelW showed above, via the registry. And that doesn't take effect immediately. At least it didn't for me.

The console supports Code Pages but changing the Code Page doesn't have any effect if a raster font is in use. The raster font is the default.

It seems they didn't make it easy to use languages other than English in the console. Why not use a GUI window?


Phoenix

Greg,

there is a way to change the console font programatically via the (undocumented!) function SetConsoleFont of Kernel32.dll.
But i guess this will not solve the problem.

Regards, Phoenix


[attachment deleted by admin]

GregL

Phoenix,

  Thanks. I'm reluctant to use undocumented functions, but that is good to know about.  :U
 

Phoenix

Greg,

here is a link to an example code in C by Jason Hood that displays or changes the sizes of the console buffer, window and font using 5 undocumented functions. I'm not familiar with C, but perhaps you find it useful.

http://www.geocities.com/jadoxa/misc/cs.c.txt


RuiLoureiro

Hi
   Many Thanks to Michael, Greg and Phoenix.

   I passed this time searching MSDN about stuff related with fonts, code pages, working with registry, and so on.

Phoenix,
         The exmple works. I got 13 ( to me, it seems to be blocks of 256 chars of the same font). But we dont know whether it is raster or not and if it is ASCII, ANSI or other (i can be wrong) and this is a problem.
We would know the type (if TrueType, Raster, etc)
         Thanks for the link to the C exmple. It helps.

Greg,
     About «õ», IIANW, that table is for CP 850. For CP 860 the «õ» should be
     there. In CP 860 «õ» = code 94h.
     About languages, i thk the problem is in MASM. This is the way i am seeing this.

     Phoenix gave us an exmple Console.zip (analogous one i used before from Jeremy ). In this exmple he uses SetConsoleFont,GetNumberOfConsoleFonts which are in kernel32.dll. It doesnt print strings with «é ç à í õ ...» chars correctly (the font is not ANSI).
.................................................................................................................................
The problem is in this stage: The strings are coded by MASM in ANSI

char:     é     j  á     à  s     í  ...ç  õ  e  s
code:     E9 20 6A E1 20 E0 73 20 ED    E7 F5 65 73  <=> ANSI code page ???

but WriteConsole prints it using IBM ext FONT(the installed font seems to be IBM ext ).
The same string coded with CodePage 860 is:

char:     é     j  á     à  s     í  ...ç  õ  e  s
code:     82 20 6A A0 20 85 73 20 A1    87 94 65 73  <=> ASCII code page 860

So, we have no solutions because MASM doesnt code my strings in CP 860. I cannot change the CP to 860 because the strings are in ANSI (not CP 860). 
..................................................................................................................................
When we change to Lucida Console, those ANSI chars above are printed correctly and it seems that Boxdrawing chars are there. Lucida seems to be a TrueType font.(I dont know exactly where is the difference.) It seems to be one solution (?).

The other solution, i think could be UNICODE, but i dont know how to use it correctly. The other solution can be GUI, but i dont know if i'll go to have the same type of problems with fonts.
.....................................................................................................................................
In the C exmple from the link, Jason Wood says: «It appears the TrueType fonts are only indexed after being used. To be able to select a different TrueType font, it is still necessary to go through the Properties once. The font (and its bold/normal counterpart) are then inserted into the list, potentially changing the order of the current fonts.». I thk it is important. But where did he see the type is TrueType ?

Stay well

GregL

Phoenix,

  Sorry I didn't reply sooner, I tried out the C program and then forgot to say thanks. Thanks.

RuiLoureiro,

  Wow, what a mess. If you ever figure it out, let me (us) know about it. It's beyond my experience at this point.


RuiLoureiro

#25
Quote from: Greg on June 12, 2005, 03:11:44 AM
If you ever figure it out, let me (us) know about it. It's beyond my experience at this point.

Greg, About what ? Let me know your opinion.

See this www.uwe-sieber.de/codepage_e.html  and  www.styopkin.com/
and  www.alanwood.net/unicode/fonts.html#wgl4
and say something.

RuiLoureiro

#26
Hi

This is an example with BoxDrawing UNICODE characters.
We can change Properties to chose other fonts like TrueType Lucida Console.
In both cases boxdrawing chars. are printed.

♠ ♥                          ; This was to test   &#Number;    form          where Number=9824 and 9829

The code sample was a bit long for a post so I attached it to the post in zip format -Donkey


[attachment deleted by admin]