[futurebasic] Re: [FB] styled Edit field to disk and printer

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : November 1999 : Group Archive : Group : All Groups

From: Rick Brown <rbrown@...>
Date: Sun, 14 Nov 1999 11:13:09 -0600

Mikearrony@... wrote:

>
>     Right now I have a Function that will save the file to disk as a text
> file but it needs to be modified and that is where I need some help.  The
> file may be opened with Simple text, word,etc.  but there is garbage at the
> top and bottom of the document.  That garbage is formating which I need to
> remove.  What is the best way to do this?
>     I would also like to save the entire field as is (windows calls it rich
> text format) too.  Staz said there was a PG function in Text ED. Fltr (FB3)
> that would do this.  I looked at it but didn't understand what parts I needed
> and what parts I didn't.
>     As far as printing it, I have a Function that I modified that will print
> 1 page.  This works perfectly but I need to modify it to print more than 1
> page and this is where I need some help too.

It sounds like you're using something like GET FIELD to get the data that you
write to disk.  GET FIELD creates a data structure called a "ZTXT block" which
is a thing invented by the designers of FB and is of no real use outside of FB.
However, its structure is simple enough that you can manipulate it a little to
make it more useful.

The ZTXT consists of text information and style information glued together into
a single block (plus a 2-byte header preceding the text information).  You need
to separate out this information in order to create a styled SimpleText file,
because in a SimpleText file the text and the style information are stored in
two separate locations (specifically, the text is stored in the data fork, and
the style information is stored as a "styl" resource).  The following demo
illustrates how this can be done:

LOCAL FN efToSimpleText(efID, filename$, wd)
  '(note: assumes the file doesn't already exist)
  GET FIELD ztxt&, efID
  OSErr = FN HLOCK(ztxt&)
  tlen = {[ztxt&]}
  hsize = FN GETHANDLESIZE(ztxt&)
  DEF OPEN "TEXTttxt"
  OPEN "O",1,filename$,,wd
  WRITE FILE #1, [ztxt&]+2, tlen
  CLOSE #1
  styleLen = hsize - (tlen + 2)
  LONG IF styleLen > 0
    CALL HCREATERESFILE(wd, 0, filename$)
    resrefnum = FN OPENRFPERM(filename$, wd, _fsWrPerm)
    stylH& = FN NEWHANDLE(styleLen)
    BLOCKMOVE [ztxt&] + 2 + tlen, [stylH&], styleLen
    CALL ADDRESOURCE(stylH&, _"styl", 128, "")
    CALL CLOSERESFILE(resrefnum)  'this releases stylH& too
  END IF
  DEF DISPOSEH(ztxt&)
END FN

WINDOW 1
EDIT FIELD -1,"Hello",(10,10)-(100,26), _framed
SETSELECT 100,100
EDIT TEXT ,,_ulineBit% + _italicBit%
TEKEY$ = " there"
f$ = FILES$(_fSave,,,wd)
LONG IF f$ <> ""
  FN efToSimpleText(1, f$, wd)
END IF
'============================

Now, you also wrote this:

> The file may be opened with Simple text, word,etc.

The problem here is that programs like Word store their style information in a
completely different (and usually proprietary) way than SimpleText does.
Generally no two word processors (and often no two versions of the same word
processor) will store style information in the same way.  Storing style
information for SimpleText is easy and predictable:  storing style information
for a WP program is messy and requires a lot of special knowledge.  If you open
a SimpleText file in a WP, the WP will just read the text part and ignore the
formatting.

"Rich Text Format" (RTF) is an attempt to get around this problem; it's supposed
to be a way to store text and formatting information in a way that is
sufficiently standardized that a number of different WP programs will be able to
interpret it.  Having said that:

* To create RTF output, you would have to write a pretty sophisticated program.
Maybe this Text ED. Fltr thing does a lot of that work for you.
* I don't think SimpleText can read nor write RTF.
* The last RTF spec I read from MicroSoft was pretty poorly written and
ambigous.  This may explain why I have never seen two WP programs that interpret
RTF in quite the same way.

Hope this helps.
- Rick