[WASTE-list] calculating linebreaks

Alfred Van Hoek vanhoek at mac.com
Sat Oct 27 18:10:41 EDT 2007


First of all, Waste 3 automatically recalculates line-breaks when
necessary, while in Waste 2 we need to tell waste it by calling
WECalText. No problem.

However, recalculating line-breaks when the destination rectangle
changes leads to spurious mistakes. We claim that the mistake is in
the line break algorithm.

Here is the code that will be called during a life resize:

/* remember offset of first visible character */
WEGetViewRect(&lr, text); // the old view rect
topCharPosition = *(LongPt*)&lr; // old topChar offset

topCharOffset = WEGetOffset(&topCharPosition, &edge, text);
dprintf("rewrapping: topCharOffset = %i, edge = %i, view left = %i,
view top = %i", topCharOffset, edge, lr.left, lr.top);

/* reset destination rectangle and recalculate line breaks */
_SetDestinationRect(instance);
_SetViewRect(instance);

if ( (err = WECalText(text)) != noErr ) {
dprintf("error calculating line breaks...");
goto cleanup ;
}

lineWidth = WEGetMaxLineWidth(text);

/* scroll the destination rectangle to keep the previous */
/* first visible character at the top of the view rectangle */

WEGetPoint(topCharOffset, kHilite, &topCharPosition, &lineHeight,
text);
dprintf("rewrapping: topCharPosition = %i, %i, lineWidth = %i,
lineHeight = %i",
topCharPosition.h, topCharPosition.v, lineWidth, lineHeight);

// note that sometimes the topCharPosition is way off with respect
to topCharOffset
// and potentially is related to WECalText doing something wrong??

WEGetDestRect(&lr, text);

offsetX = controltop.h - topCharPosition.h;
offsetY = controltop.v - topCharPosition.v;

dprintf("offsetX %i, offsetY %i", offsetX, offsetY);
WEOffsetLongRect(&lr, offsetX, offsetY);
WESetDestRect(&lr, text);

cleanup: ;


A good pass through the above gives:

rewrapping: topCharOffset = 1728, edge = 0, view left = 8, view top = 37
rewrapping: topCharPosition = 8, 613, lineWidth = 312, lineHeight = 16
offsetX 0, offsetY -576


and the next pass gives:

rewrapping: topCharOffset = 1728, edge = 0, view left = 8, view top = 37
rewrapping: topCharPosition = 324, 485, lineWidth = 391, lineHeight = 16
offsetX -316, offsetY -448

and suddenly the field is scrolled to the left. This offsetX change
relates to the length of the word used in the field.

The example used was:

WEGetOffset WEGetOffset WEGetOffset WEGetOffset WEGetOffset
WEGetOffset WEGetOffset WEGetOffset WEGetOffset WEGetOffset
WEGetOffset WEGetOffset WEGetOffset WEGetOffset WEGetOffset
WEGetOffset WEGetOffset WEGetOffset WEGetOffset WEGetOffset
WEGetOffset WEGetOffset WEGetOffset WEGetOffset WEGetOffset
WEGetOffset WEGetOffset WEGetOffset WEGetOffset WEGetOffset
WEGetOffset WEGetOffset WEGetOffset WEGetOffset WEGetOffset
WEGetOffset WEGetOffset WEGetOffset WEGetOffset WEGetOffset
WEGetOffset WEGetOffset WEGetOffset WEGetOffset WEGetOffset
WEGetOffset WEGetOffset WEGetOffset etc

and the field width was less than 5 words.

When the field width is increased to 5 words, Waste is moving the
dest rectangle 4 words to the left if that would be of value here
(Waste 2) or 2 words to the left (Waste 3). Then moving to a width
that can contain 6 of the above words on a line, the field snaps back
to an offsetX of 0:

rewrapping: topCharOffset = 1728, edge = 0, view left = 8, view top = 37
rewrapping: topCharPosition = 8, 421, lineWidth = 470, lineHeight = 16
offsetX 0, offsetY -384

With Waste 2, but snaps further to the left as a function of the word
length.

Any thoughts, comments, workarounds etc?

Alfred

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://six.pairlist.net/pipermail/waste-list/attachments/20071027/844bf076/attachment.htm>


More information about the WASTE-list mailing list