DosTips.com

A Forum all about DOS Batch
It is currently 22 Jul 2017 18:45

All times are UTC-06:00




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

Joined: 06 Dec 2011 22:15
Posts: 1384
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: 2714
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: 2714
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

Joined: 23 Jun 2013 06:15
Posts: 1352
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
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 20 posts ]  Go to page Previous 1 2

All times are UTC-06:00


Who is online

Users browsing this forum: Bing [Bot] and 10 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:  
Powered by phpBB® Forum Software © phpBB Limited