[texworks] Script: Assertion Failed - any limits to array size or anything?

Paul A Norman paul.a.norman at gmail.com
Sun Jun 13 04:50:06 CEST 2010


Thanks Jonathan and Stefan,

I believe that is it Jonathan. I was looking at the routine's earlier
array() space issue, but it appears to be at the end of the routine
during string rebuilding from the message.

Can Qt handle compression/decompression of .ui ? One .ui was getting
quite big - they are after all just ginormous loose xml trees.

So not finding any built in compression/decompression in Qt for .ui so
far, I wanted to handle it in script - especially as I abosolutely
need access to the .ui's xml tree in script any way.

So I was using some LZW algorithm' as it is now public domain.

On trials with various very large text portions it went quite well.
Compressed and decompressed very nicely and the disk space savings are
fantastic. A couple of minor UTF type issues, but nothing relevant to
what I actually needed to do.

But when I hit a 500k .ui that's when the fun started.

So, yes there c/would be a very long string during the re-compoistion
of "a" (one) string from array().join()

Here is my test script. I've put it here in full for perusal / and any
recommendations please.

(A small other matter should TW.target.text be settable? You'll see
what I am doing here.)

//TeXworksScript
//Title: LZW Compress / Decompress experiment
//Description: Testing
//Author: Paul A. Norman
//Version: 0.3
//Date: 2010-06-12
//Script-Type: standalone
//Context: TeXDocument


// http://stackoverflow.com/questions/294297/javascript-implementation-of-gzip
// http://jsolait.net/changeset/44/trunk
//http://en.wikipedia.org/wiki/LZW

// LZW-compress / decompress a string

  switch( TW.question( null, "Compress / Decompress", "Compress?" ,(
0x00004000 | 0x00010000 ) ,0x00004000  ))
     {
      case 0x00004000:

      TW.target.selectAll();
      text = TW.target.text;
      compressed = lzw_encode(text);
      TW.target.insertText(compressed);

      break

      case 0x00010000:
      TW.target.selectAll();
      compressed = TW.target.text;
      text = lzw_decode(compressed);
      TW.target.insertText(text);
      break;

      default:
      break;
     }

function lzw_encode(s) {
    var dict = {};
    var data = (s + "").split("");
    var out = [];
    var currChar;
    var phrase = data[0];
    var code = 256;
    for (var i=1; i<data.length; i++) {
        currChar=data[i];
        if (dict[phrase + currChar] != null) {
            phrase += currChar;
        }
        else {
            out.push(phrase.length > 1 ? dict[phrase] : phrase.charCodeAt(0));
            dict[phrase + currChar] = code;
            code++;
            phrase=currChar;
        }
    }
    out.push(phrase.length > 1 ? dict[phrase] : phrase.charCodeAt(0));
    for (var i=0; i<out.length; i++) {
        out[i] = String.fromCharCode(out[i]);
    }
    return out.join("");
}

// Decompress an LZW-encoded string
function lzw_decode(s) {
    var dict = {};
    var data = (s + "").split("");
    var currChar = data[0];
    var oldPhrase = currChar;
    var out = [currChar];
    var code = 256;
    var phrase;
    for (var i=1; i<data.length; i++) {
        var currCode = data[i].charCodeAt(0);
        if (currCode < 256) {
            phrase = data[i];
        }
        else {
           phrase = dict[currCode] ? dict[currCode] : (oldPhrase + currChar);
        }
        out.push(phrase);
        currChar = phrase.charAt(0);
        dict[code] = oldPhrase + currChar;
        code++;
        oldPhrase = phrase;
    }
    return out.join("");
}

On 13 June 2010 01:50, Jonathan Kew <jfkthame at googlemail.com> wrote:
>
> On 12 Jun 2010, at 12:36, Paul A Norman wrote:
>
>> Hi,
>>
>> Just checking, is there any limit to array size or anything  when
>> using QtScript?
>>
>> I am getting the attached error message thrown up occasionally when
>> using a lot of array space.
>>
>> Paul
>> <assertionFailed.png>
>
> The error message is coming from inside the Qt libraries (from KDE, apparently), and relates to text rendering; my guess is that you've constructed an extremely long string (perhaps with no spaces/linebreaks?) and are trying to put it into the document where it'll get displayed. Perhaps you need to be adding line-breaks in between items in a list, or something like that.
>
> JK
>
>
>



More information about the texworks mailing list