Android Question Special chars and TextReader

GiovanniPolese

Well-Known Member
Licensed User
Longtime User
Hi to everybody here
I am using TextReader with files of which I don't know the encoding. As a matter of fact, it may be either "Windows-1252" or "UTF-8". The problem arises when these files contain special characters. Despite, in theory, the encoding is declared in the file itself, it is not respected, in practice. What I see is that some files are successfully read with TextReader when one encoding is used, while others, in same conditions, are not read correctly. In other words, while all files are normally declared as "Windows-1252", very often to read them correctly it is necessary to initialize the TextReader with UTF8. Besides the explicit (often false) declaration inside the file, I tried also an analysis on the very first characters of the file, with no success. The only way to have a sure answer is to read the raw bytes to discover when and if the special characters appear. This creates new problems, because the files are often huge (over one Gb) and cannot be entirely loaded in memory with File.ReadBytes. Alternatively maybe I must read byte by byte. I use TextReader because, due to file size, I read them line by line. Moreover the structure of these files is such to require a line by line processing. Is there any way to read raw bytes from a Text file, line by line, not using TextReader? thank in advance for any suggestion.
 
Solution
I post here the code resolving my problem. It reads a file using an external (global) defined InputStream. It is a sub reading a line of an Ascii file, byte by byte.
It returns a decoded line. It works for Portugues special chars written (sometimes improperly definition of coding inside) in dxf files. It first decodes the line with UTF8 and, if special chars are empirically detected, redoes the conversion using Windows-1252. Any eventual improvement is welcome. As a matter of fact I have doubts on my empirical detection with Asc(char)>256, despite for my cases it works.

B4X:
private Sub Txr_ReadLine As String
#if TEXTR    
    Return Txr.Readline ' if TEXTR is defined, it uses a global TextReader Txr. of course this is not the case...

emexes

Expert
Licensed User
What was the problem with using regular fonts to do the overlay text?

I realised later that it doesn't need to be a plotted font, if you're overlaying it on top of (or in to) a bitmap.

It would be nice if the accented characters etc were displayed.

The technique might be to draw the text black-on-white into a regular orthagonal rectangle, then rotate and scale, then copy into the overlay plane using the blackness of the pixel as the opacity. Or can add a subtle 1-pixel outline lightness around the characters to make them more visible against the underlying imagery.

Tracing to create a plotted font still seems feasible, from something like eg:

https://en.wikipedia.org/wiki/Windows-1252#/media/File:Windows-1252-infobox.svg

On the other hand, if it's working now, and is good enough, then maybe: if it ain't broke, don't fix it. 🍻
 
Upvote 0

emexes

Expert
Licensed User
Don't forget that rendering is done with OpenGL. No fonts available on version for B4A.
So fonts are hand defined, done not by me,

The hand defined font, what does that file look like? Is it rendered by OpenGL? If so, could it possibly be this:

https://learnopengl.com/In-Practice/Text-Rendering

Perhaps the hand defined font file that you have, when you pull back the cover, is actually an OpenGL texture something like this:

1738771449195.png
 
Upvote 0

GiovanniPolese

Well-Known Member
Licensed User
Longtime User
Thanks for suggestions, but my texts have to be scaled and rotated. Therefore I have some vectors representing the fonts with lines. At moment I don't see any alternative.
 
Upvote 0

GiovanniPolese

Well-Known Member
Licensed User
Longtime User
Great Grok... nice name .. in the picture: besides the idea, this mouse will die: the helmet is too small compared to the size of the trap.. see another post that I wrote some minutes ago, and you will understand .. thanks
 
Upvote 0
Top