qwert

Questions related to RTF file encoding

5 posts in this topic

#1 ·  Posted

I've worked quite a bit with rich text, but I've run into a problem that I can't get past.

When I write rich text from AutoIt, I can read back my content with no problem. But when I try to read an RTF file written by WordPad, I get a null buffer from the Open/Read/Close sequence.  (My files work fine with the same calls.)  I've tried various options on the file encoding parameter on FileOpen().

So I resorted to the GetFileEncoding() function in order to unravel the mystery.  But WordPad's file returns "1024", which isn't a published choice.

Quote

Success: the file encoding using similar values to the FileOpen() function:
    $FO_UTF16_LE (32) = UTF16 Little Endian.
    $FO_UTF16_BE (64) = UTF16 Big Endian.
    $FO_UTF8 (128) = UTF8 (with BOM).
    $FO_UTF8_NOBOM (256) = UTF8 (without BOM).
    $FO_ANSI (512) = ANSI (containing char > 127 and < 255)

To make matters more confusing, the files I write return encoding = 16 ... also not a listed choice.

Can anyone shed light on this?  Is there a common denominator encoding that WordPad uses that AutoIt can also write.

BTW, I'm working with the raw rich text syntax ("\par" and so on), so StreamToVar won't help in this instance.

Thanks in advance for any help.

Encoding.PNG

 

Share this post


Link to post
Share on other sites



#2 ·  Posted

You seem to be using or refering to an old AutoIt version or helpfile.


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

$FO_UTF16_LE_NOBOM (1024)
$FO_BINARY = 16 ;  binary 
 $FO_UNICODE or $FO_UTF16_LE = 32 ; Unicode UTF16 Little Endian
 $FO_UTF16_BE = 64 ; Unicode UTF16 Big Endian
 $FO_UTF8 = 128 ; Unicode UTF8 = with BOM
 $FO_UTF8_NOBOM = 256 ; Unicode UTF8 = without BOM
 $FO_ANSI = 512 ; ANSI
 $FO_UTF16_LE_NOBOM = 1024 ; Unicode UTF16 Little Endian = without BOM
 $FO_UTF16_BE_NOBOM = 2048 ; Unicode UTF16 Big Endian = without BOM

 

Edited by Trong

Regards,
 

Share this post


Link to post
Share on other sites

#4 ·  Posted

1 hour ago, jchd said:

You seem to be using or refering to an old AutoIt version or helpfile.

Good point.  It's true that my transfer of AutoIt (this year) to a new PC had some bobbles.  It looks like the help file was among them.

Thanks for the fresh list of the indicators.  Now that I see that WordPad is writing UTF-16, I'll see if it can be changed to UTF-8.  I think that's the common denominator I need.

 

 

Share this post


Link to post
Share on other sites

#5 ·  Posted

My preliminary testing has revealed that, apparently, WordPad is encoding the file according to the font's character set.  Tahoma, for example, results in a file where encoding=16, while Calibri results in encoding=1024.  I can't follow the rhyme or reasoning behind these results.  It seems that Tahoma should result in either 256 or 512.

Regardless, I can now build RTF files with WordPad (using Arial or Tahoma) that are equivalent to the files I write from the script, itself.  Both report encoding=16 and both read properly with FileRead(), when using a FileOpen($buffer, 256).

For now, my issue is resolved.  Thanks for the help.

 

TahomaTest.PNG

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now