[WASTE-list] Retaining and inserting text

Marco Piovanelli marco.piovanelli at pobox.com
Sat Mar 24 07:15:58 EDT 2007


On Sat, 24 Mar 2007 16:08:09 +0700,
Brother Josef (thykeeper at nerdshack.com) wrote:



>I'm performing a simple operation which is supposed to make a

>temporary copy of text (raw text, objects, styles and attributes

>applied with WESetAttributes. basically a standard clipboard copy

>operation) and store it's contents into a embedded object so it may

>be "unarchived" later and inserted into the document.

>

>I first call WEStreamRange to obtain the kTypeStyleScrap (with

>weStreamIncludeObjects) and kTypeText data. This I "think" is

>supposed to return ALL the data I need. I will then call WEPut using

>the kTypeStyleScrap data and raw text.


First of all, when working with WASTE 3.0, prefer kTypeUnicodeText
('utxt') over kTypeText ('TEXT'), as the latter is provided mainly
for compatibility with old applications. Asking for kTypeText data
causes WASTE 3.0 to translate the native Unicode text buffer into
legacy WorldScript encodings, a potentially lossy conversion, since
there exist Unicode characters that cannot be represented in any
WorldScript encoding.

Secondly, kTypeStyleScrap must always be used in conjunction with
kTypeCharFormat: kTypeStyleScrap holds a table of unique styles,
while kTypeCharFormat is an array of <offset, index> pairs that
maps ranges in the raw text to styles referenced in the corresponding
kTypeStyleScrap. Either is useless without the other.

Thirdly, kTypeStyleScrap/kTypeCharFormat are enough to store all
character-level styles (font, size, color, etc.), but for
paragraph-level styles (alignment, indents, spacing, tabs, etc.)
you also need to retrieve (with WEStreamRange) and reapply (with
WEPut) a similar pairs of scraps: kTypeRulerScrap/kTypeParaFormat.

To sum up, faithfully preserving the contents of a WASTE document
involves saving and reapplying the following scraps:

kTypeUnicodeText
kTypeStyleScrap (with weStreamIncludeObjects)
kTypeCharFormat
kTypeRulerScrap
kTypeCharFormat

If this sounds complicated, it's because it is.

That's why in WASTE 3.0, the preferred format for round-tripping
rich text is RTF. If you use RTF, saving the text and a complete
set of attributes involves only one call to WEStreamRange:

SInt32 rangeStart, rangeEnd;
OSStatus err;
Handle rtfData = NewHandle(0);

err = WEStreamRange(rangeStart, rangeEnd, kTypeRTF, 0,
rtfData, myWASTEDocument);

and later reinsertion of the text involves only one call to WEPut:

err = WEPut(rangeStart, rangeEnd, *rtfData, GetHandleSize(rtfData),
0, wePutRTF, 0, 0, 0, myWASTEDocument);


Hope this helps,


-- marco

--
It's not the data universe only, it's human conversation.
They want to turn it into a one-way flow that they have entirely
monetized. I look at the collective human mind as a kind of
ecosystem. They want to clear cut it. They want to go into the
rainforest of human thought and mow the thing down.



More information about the WASTE-list mailing list