Calculate layout_char properly. Comment about the weird state of things.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@18861 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
alexm 2004-03-22 00:17:18 +00:00
parent 4933e54ded
commit b619ad5bb2
2 changed files with 49 additions and 36 deletions

View file

@ -1,3 +1,11 @@
2004-03-22 01:13 Alexander Malmberg <alexander@malmberg.org>
* Source/NSLayoutManager.m
(-textStorage:edited:range:changeInLength:invalidatedRange:): Update
layout_char, glyph_delta, and new_last_glyph only if it makes sense
to do so and we need the value. Clarify and correct layout_char
update. Add comments.
2004-03-14 19:42 Alexander Malmberg <alexander@malmberg.org> 2004-03-14 19:42 Alexander Malmberg <alexander@malmberg.org>
* Source/NSView.m (-hitTest:): Don't require that the point is * Source/NSView.m (-hitTest:): Don't require that the point is

View file

@ -1772,9 +1772,7 @@ this file describes this.
invalidatedRange: (NSRange)invalidatedRange invalidatedRange: (NSRange)invalidatedRange
{ {
NSRange r; NSRange r;
unsigned int original_last_glyph, new_last_glyph; unsigned int original_last_glyph;
int glyph_delta;
BOOL had_layout;
/* printf("\n*** invalidating\n"); /* printf("\n*** invalidating\n");
[self _dumpLayout];*/ [self _dumpLayout];*/
@ -1787,7 +1785,6 @@ this file describes this.
TODO: make sure last_glyph is set as expected TODO: make sure last_glyph is set as expected
*/ */
original_last_glyph = layout_glyph; original_last_glyph = layout_glyph;
had_layout = layout_char > 0;
if (!(mask & NSTextStorageEditedCharacters)) if (!(mask & NSTextStorageEditedCharacters))
lengthChange = 0; lengthChange = 0;
@ -1796,37 +1793,17 @@ this file describes this.
changeInLength: lengthChange changeInLength: lengthChange
actualCharacterRange: &r]; actualCharacterRange: &r];
if (layout_char > r.location) /*
{ If we had layout information and we had layout information for the range
if (layout_char >= r.location + r.length) of characters that was modified, we need to invalidate layout information.
layout_char += lengthChange;
else
{
/*
The last layout information we had is inside the range that
is being invalidated.
In this case, there'll be no soft-invalidated layout information TODO: This is broken. Even if we don't have layout for the modified
to save. However, we still have layout information that we need characters, we might have layout for the preceeding line, and we then need
to discard. to invalidate that line. Need to rework this a bit... I really really need
*/ to know the glyph length change here. :/
layout_char = r.location; (Alexander Malmberg 2004-03-22)
} */
} if (layout_char > 0 && layout_char >= r.location)
if (!layout_char)
new_last_glyph = 0;
else if (layout_char == [_textStorage length])
new_last_glyph = [self numberOfGlyphs];
else
new_last_glyph = [self glyphRangeForCharacterRange: NSMakeRange(layout_char, 1)
actualCharacterRange: NULL].location;
glyph_delta = new_last_glyph - original_last_glyph;
/* printf("original=%i, new=%i, delta %i\n",
original_last_glyph,new_last_glyph,glyph_delta);*/
if (had_layout && r.location <= layout_char)
{ {
unsigned int glyph_index, last_glyph; unsigned int glyph_index, last_glyph;
textcontainer_t *tc; textcontainer_t *tc;
@ -1834,10 +1811,38 @@ this file describes this.
int i, j, k; int i, j, k;
int new_num; int new_num;
NSRange char_range; NSRange char_range;
unsigned int new_last_glyph;
int glyph_delta;
/* /*
Note that r.location might equal layout_char, in which case If we had layout beyond the modified characters, update layout_char.
r.location might not actually have any text container or line frag. Otherwise, just pretend that we have layout up to the end of the range
after the change. This will give glyph_delta and last_glyph incorrect
values, strictly speaking, but glyph_delta is only used if we have
layout beyond the modified range, and last_glyph is used in a way that
makes it safe to overestimate it (as we do here).
When I can get exact information about the modified glyphs (TODO above),
all this will become much cleaner...
*/
if (layout_char >= r.location + r.length - lengthChange)
layout_char += lengthChange;
else
layout_char = r.location + r.length;
if (!layout_char)
new_last_glyph = 0;
else if (layout_char == [_textStorage length])
new_last_glyph = [self numberOfGlyphs];
else
new_last_glyph = [self glyphRangeForCharacterRange: NSMakeRange(layout_char, 1)
actualCharacterRange: NULL].location;
glyph_delta = new_last_glyph - original_last_glyph;
/*
Note that r.location might not actually have any text container or
line frag.
*/ */
if (!r.location) if (!r.location)
{ {