DosTips.com

A Forum all about DOS Batch
It is currently 26 Sep 2017 14:04

All times are UTC-06:00




Post new topic  Reply to topic  [ 23 posts ]  Go to page Previous 1 2
Author Message
PostPosted: 09 Feb 2017 13:16 
Online
Expert

Joined: 06 Dec 2011 22:15
Posts: 1427
Location: México City, México
esuhl wrote:
So... a computer won't necessarily support all valid code pages...? Is the only reliable solution to stick to pure ASCII characters?

You may use Pixel Resolution Graphics and then draw in the screen any desired "character", as shown in this example:

Image

Just an idea... :wink:

Antonio


Top
   
PostPosted: 09 Feb 2017 14:09 
Offline
Expert

Joined: 22 Jan 2010 18:01
Posts: 2904
Location: Germany
Hmm. I'm afraid you didn't fully understand.

esuhl wrote:
and use the equivalent characters (accented E, etc.)

This isn't portable. See the difference between Antonio's and Saso's examples. Both are able to write box-drawing characters for their specific computer settings. As I wrote, as soon as you have characters in the code that exceed the ASCII range it won't be portable anymore.


esuhl wrote:
So... a computer won't necessarily support all valid code pages...?

Right. And fonts won't support all possible characters (I'm aware of only one project where developers try to achieve this).

It's important to understand the difference between files-charset vs. window-font.
A file consists of bits and bytes. You need a translation between the bytes read (or written) and the characters that shall be represented by these bytes. The charset (code page) is just the rule for this translation.
A window needs a font for graphically displaying these characters. Even if the translation of the bytes read succeed the characters can't be displayed if the font don't support them (that's what happened to Saso).

Steffen


Top
   
PostPosted: 10 Feb 2017 07:27 
Offline

Joined: 04 Feb 2017 22:03
Posts: 9
aGerman wrote:
Hmm. I'm afraid you didn't fully understand.

esuhl wrote:
and use the equivalent characters (accented E, etc.)

This isn't portable. See the difference between Antonio's and Saso's examples. Both are able to write box-drawing characters for their specific computer settings. As I wrote, as soon as you have characters in the code that exceed the ASCII range it won't be portable anymore.


Ah. Thanks for correcting me. I've re-read this thread several times, but I still don't quite understand why this wouldn't work.

Going back to your example, let's say I want to echo the õ character to screen. Notepad on your system uses a different encoding, so you enter the character as ä, but doing chcp 850 will (I thought) make sure the character appears correctly on all systems...?

So long as the batch file contains byte E4, and the console is set to chcp 850... I don't understand why this wouldn't work...? (Other than the console font not having such a character.)

aGerman wrote:
esuhl wrote:
So... a computer won't necessarily support all valid code pages...?

Right. And fonts won't support all possible characters (I'm aware of only one project were developers try to achieve this).

It's important to understand the difference between files-charset vs. window-font.
A file consists of bits and bytes. You need a translation between the bytes read (or written) and the characters that shall be represented by these bytes. The charset (code page) is just the rule for this translation.
A window needs a font for graphically displaying these characters. Even if the translation of the bytes read succeed the characters can't be displayed if the font don't support them (that's what happened to Saso).


Yes -- I understand that, at least. That sounds like the final word on this, then! So it is literally impossible to guarantee that anything other than 7-bit ASCII characters will appear on screen correctly?

I thought the solution in your first reply might work. But is sounds like this needs a known font to be specified. And it looks like you can't do this from within a batch file.

But... my solution of writing the batch file in UTF-8 without a BOM to echo UTF-8 characters to a text file is pretty reliable, right?

--------

It's a long-shot, but... Would there be any way to get a batch file to open a new console window with a specific font and code-page, and then re-direct commands to that window, thus guaranteeing that the first solution you posted would work every time...? :-/

I guess I might just have to make do with ASCII on screen!

Thanks again for everyone's really helpful replies. I feel like I've learned so much! :-)


Top
   
PostPosted: 10 Feb 2017 11:57 
Offline
Expert

Joined: 22 Jan 2010 18:01
Posts: 2904
Location: Germany
esuhl wrote:
Going back to your example, let's say I want to echo the õ character to screen. Notepad on your system uses a different encoding, so you enter the character as ä, but doing chcp 850 will (I thought) make sure the character appears correctly on all systems...?

So long as the batch file contains byte E4, and the console is set to chcp 850... I don't understand why this wouldn't work...? (Other than the console font not having such a character.)

This will work as long as the byte is E4. But whether or not letter ä results in the byte E4 depends on the code page used by the text editor :wink:

esuhl wrote:
Yes -- I understand that, at least. That sounds like the final word on this, then! So it is literally impossible to guarantee that anything other than 7-bit ASCII characters will appear on screen correctly?

If you have to make sure that everything will be displayed correctly the answer is yes. Every single-byte code page supports ASCII and every text font, too.
Althoug out of my experiences every OEM code page and every console font supports at least the single-frame characters.


esuhl wrote:
But... my solution of writing the batch file in UTF-8 without a BOM to echo UTF-8 characters to a text file is pretty reliable, right?

It should also let the characters appear on the screen if you change the code page to 65001 using CHCP.

esuhl wrote:
Would there be any way to get a batch file to open a new console window with a specific font and code-page, and then re-direct commands to that window, thus guaranteeing that the first solution you posted would work every time...? :-/

I should rather answer with a no. Third party tools may be able to change the font. Also changing the registry settings may work (but you have to make sure to reset them). But you never know if the font you need would be even installed. E.g. I remember that Consolas was missing on my XP machine.

Steffen


Top
   
PostPosted: 10 Feb 2017 16:21 
Offline
Expert

Joined: 23 Jun 2013 06:15
Posts: 1421
Location: Germany
If you know how to program in c, then you could load fonts temporarily for one windows session, just like carlos did it here:
http://consolesoft.com/p/bg/bg_src/pixelfnt.c.

The resulting application "pixelfnt.exe":
http://www.dostips.com/forum/viewtopic.php?f=3&t=6254.

It works from Win XP to Win 8.1; maybe it also works under win10, but i haven't tested the pixelfnt there.


penpen


Top
   
PostPosted: 02 Sep 2017 15:54 
Offline

Joined: 30 Oct 2016 09:48
Posts: 7
I made a script to change the font, it works here, it makes the change through the registry, I tested on windows 7 and 10 using chcp 865
my doubt is if it works in other languages

File name: Test.bat

Code: Select all
echo off
color f
reg Query HKCU\Console\%%SystemRoot%%_system32_cmd.exe /v FaceName>>temp.dat
for /f "usebackq skip=2 tokens=1,2,3* delims=" %%a in  (temp.dat) do set valuereg=%%a
set valuereg=%valuereg:~26,15%
Del /f /q /a temp.dat >nul 2>&1
Rem ########### changing font ###########
if not "%valuereg%"=="Lucida Console" (
reg add HKCU\Console\%%SystemRoot%%_system32_cmd.exe /V ScreenColors /t REG_DWORD /d "0x0000000f" /f
reg add HKCU\Console\%%SystemRoot%%_system32_cmd.exe /V ScreenBufferSize /t REG_DWORD /d "0x00190050" /f
reg add HKCU\Console\%%SystemRoot%%_system32_cmd.exe /V FaceName  /t REG_SZ /d "Lucida Console" /f
reg add HKCU\Console\%%SystemRoot%%_system32_cmd.exe /V FontSize  /t REG_DWORD /d "0x000c0000" /f
reg add HKCU\Console\%%SystemRoot%%_system32_cmd.exe /V FontFamily  /t REG_DWORD /d "0x00000036" /f
reg add HKCU\Console\%%SystemRoot%%_system32_cmd.exe /V FontWeight  /t REG_DWORD /d "0x00000190" /f
start Test.bat
exit
)
set valuereg=
chcp 865
cls
mode 80,25
echo.Draw boxes with single-frame characters.                                       
echo. ÚÄÂÄ¿                                                                         
echo. ³A³B³                                                                         
echo. ÃÄÅÄ´                                                                         
echo. ³C³D³                                                                         
echo. ÀÄÁÄÙ                                                                         
echo.Draw boxes with double-frame characters.                                       
echo. ÉÍËÍ»                                                                         
echo. ºAºBº                                                                         
echo. ÌÍÎ͹                                                                         
echo. ºCºDº                                                                         
echo. ÈÍÊͼ                                                                         
echo.1st combination (single vertical, double horizontal frames).                   
echo. ÕÍÑ͸                                                                         
echo. ³A³B³                                                                         
echo. ÆÍØ͵                                                                         
echo. ³C³D³                                                                         
echo. ÔÍÏ;                                                                         
echo.2nd combination (double vertical, single horizontal frames).                   
echo. ÖÄÒÄ·                                                                         
echo. ºAºBº                                                                         
echo. ÇÄ×Ķ                                                                         
echo. ºCºDº                                                                         
echo. ÓÄÐĽ                                         
pause >NUL


Attachments:
boxok1.PNG
boxok1.PNG [ 12.19 KiB | Viewed 119 times ]


Last edited by Aspidiske on 02 Sep 2017 17:33, edited 1 time in total.
Top
   
PostPosted: 02 Sep 2017 16:49 
Offline
Expert

Joined: 22 Jan 2010 18:01
Posts: 2904
Location: Germany
Some notes

1) You don't reset the registry updates which leads to permanent changes of the console settings.
2) The code doesn't display what it should because you don't use the right characters in the combinated single/double frames. (Compare it with my screenshot below, created with the code I provided in my first reply.)
3) It only works if the the ANSI codepage (used by your text editor) is set to Windows-1252.

Please read the whole thread to understand this behavior.

Steffen

Attachment:
box.png
box.png [ 14.89 KiB | Viewed 123 times ]


Top
   
PostPosted: 02 Sep 2017 17:47 
Offline

Joined: 30 Oct 2016 09:48
Posts: 7
aGerman wrote:
Some notes

1) You don't reset the registry updates which leads to permanent changes of the console settings.
2) The code doesn't display what it should because you don't use the right characters in the combinated single/double frames. (Compare it with my screenshot below, created with the code I provided in my first reply.)
3) It only works if the the ANSI codepage (used by your text editor) is set to Windows-1252.

Please read the whole thread to understand this behavior.

Steffen

Attachment:
box.png


You're right agerman the boxes code was wrong, I do not know how I did it
I already corrected the post! :roll:
OK I'll give a better view in the post


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 23 posts ]  Go to page Previous 1 2

All times are UTC-06:00


Who is online

Users browsing this forum: Aacini, Google [Bot] and 17 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Limited