Extracting All Text from a ProtoTXView Object

One of the Newton 2.x OS Q&As
Copyright © 1997 Newton, Inc. All Rights Reserved. Newton, Newton Technology, Newton Works, the Newton, Inc. logo, the Newton Technology logo, the Light Bulb logo and MessagePad are trademarks of Newton, Inc. and may be registered in the U.S.A. and other countries. Windows is a registered trademark of Microsoft Corp. All other trademarks and company names are the intellectual property of their respective owners.


For the most recent version of the Q&As on the World Wide Web, check the URL: http://www.newton-inc.com/dev/techinfo/qa/qa.htm
If you've copied this file locally, click here to go to the main Newton Q&A page.
This document was exported on 7/23/97.


Extracting All Text from a ProtoTXView Object (4/3/97)

Q: How can I get all the text out of the protoTXView data stored in a soup entry, for example to get the text for sending in email?

A: First, instantiate a dummy view with the data from the soup, as described in the Q&A "How to Get Data From a ProtoTXView Externalized Data". The protoTXView method GetRangeData always allocates its storage from the NewtonScript heap, so you will need to copy the data into a destination VBO in chunks. Here's some code to do that. (This code uses a 4K block size, you may wish to adjust that as necessary, add error checking, etc.) StringFilter is used to remove the protoTXView graphic indicator.

    constant kChunkSize := 0x1000; // 4K chunks
    local start := 0;
    local theText := GetDefaultStore():NewVBO('string, length(""));

    // make VBO into a proper string
    BinaryMunger(theText,0,nil, "", 0, nil);    

    while numChars-start > kChunkSize do
        // strip out graphics characters
        StrMunger(theText,start, nil,
                    StringFilter(
                        textView:GetRangeData(
                            {
                            first: start, 
                            last: start := start + kChunkSize
                            }, 'text),
                        "\u2206\u", 'rejectAll),
                    0, nil);
    // copy remainder
    if start < numChars then
        StrMunger(theText,start,nil,
                    StringFilter(
                        textView:GetRangeData(
                            {first: start, last: numChars}, 'text),
                        "\u2206\u", 'rejectAll),
            0, nil);
    // theText now holds plain text from the protoTXView

For clarity, the code above does not use ClearVBOCache as mentioned in the Q&A, "How to Avoid Resets When Using VBOs". If you are having problems with large VBOs during code like that mentioned above, see that Q&A for more information.