mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-04-23 20:01:11 +00:00
Fix for glyph index immediately beyond glyph range
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@8812 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
35a0b834f8
commit
5f2d75b783
2 changed files with 49 additions and 43 deletions
|
@ -1,3 +1,9 @@
|
|||
2001-01-26 Richard Frith-Macdonald <rfm@gnu.org>
|
||||
|
||||
* Source/NSLayoutManager.m: when doing conversions between glyph
|
||||
and character indices, support the index immediately beyond the
|
||||
end of the glyphs/characters without raising an exception.
|
||||
|
||||
2001-01-22 Richard Frith-Macdonald <rfm@gnu.org>
|
||||
|
||||
* Source/NSLayoutManager.m: loads of glyph changes - added some
|
||||
|
|
|
@ -1904,7 +1904,23 @@ _Sane(self);
|
|||
#if USE_GLYPHS
|
||||
if (_JumpToGlyph(self, glyphIndex) == NO)
|
||||
{
|
||||
[self glyphAtIndex: glyphIndex];
|
||||
BOOL exists;
|
||||
|
||||
[self glyphAtIndex: glyphIndex isValidIndex: &exists];
|
||||
if (exists == NO)
|
||||
{
|
||||
/*
|
||||
* As a special case, the glyph index just beyond the end of
|
||||
* the glyph stream is known to map to the character index just
|
||||
* beyond the end of the text.
|
||||
*/
|
||||
if (glyphIndex == _numberOfGlyphs)
|
||||
{
|
||||
return [_textStorage length];
|
||||
}
|
||||
[NSException raise: NSRangeException
|
||||
format: @"glyph index out of range"];
|
||||
}
|
||||
_JumpToGlyph(self, glyphIndex);
|
||||
}
|
||||
return _CharIndex(self);
|
||||
|
@ -1926,11 +1942,34 @@ _Sane(self);
|
|||
actualGlyphRange: (NSRange*)actualGlyphRange
|
||||
{
|
||||
#if USE_GLYPHS
|
||||
unsigned pos;
|
||||
NSRange cRange;
|
||||
NSRange gRange = glyphRange;
|
||||
unsigned cEnd;
|
||||
BOOL exists;
|
||||
|
||||
[self glyphAtIndex: glyphRange.location]; // Force generation of glyphs.
|
||||
/*
|
||||
* Force generation of glyphs to fill gaps.
|
||||
*/
|
||||
[self glyphAtIndex: NSMaxRange(glyphRange)
|
||||
isValidIndex: &exists];
|
||||
|
||||
/*
|
||||
* Locate character index of location immediately beyond last glyph in range.
|
||||
*/
|
||||
if (exists == NO)
|
||||
{
|
||||
if (NSMaxRange(glyphRange) > _numberOfGlyphs)
|
||||
{
|
||||
[NSException raise: NSRangeException
|
||||
format: @"glyph range too large"];
|
||||
}
|
||||
cEnd = [_textStorage length];
|
||||
}
|
||||
else
|
||||
{
|
||||
_JumpToGlyph(self, NSMaxRange(glyphRange));
|
||||
cEnd = _CharIndex(self);
|
||||
}
|
||||
|
||||
/*
|
||||
* Locate the first glyph and step backwards to the earliest glyph with
|
||||
|
@ -1938,52 +1977,13 @@ _Sane(self);
|
|||
*/
|
||||
_JumpToGlyph(self, glyphRange.location);
|
||||
cRange.location = _CharIndex(self);
|
||||
cRange.length = cEnd - cRange.location;
|
||||
while (_Back(self) == YES && _CharIndex(self) == cRange.location)
|
||||
{
|
||||
gRange.location--;
|
||||
gRange.length++;
|
||||
}
|
||||
|
||||
if (glyphRange.length == 0)
|
||||
{
|
||||
/*
|
||||
* For a zero length range, we don't need to locate an end glyph.
|
||||
*/
|
||||
cRange.length = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
BOOL exists;
|
||||
|
||||
/*
|
||||
* Make sure that the last glyph in the range exists.
|
||||
*/
|
||||
[self glyphAtIndex: NSMaxRange(glyphRange)
|
||||
isValidIndex: &exists];
|
||||
if (exists == YES)
|
||||
{
|
||||
_JumpToGlyph(self, NSMaxRange(glyphRange));
|
||||
gRange.length = _GlyphIndex(self) - gRange.location;
|
||||
pos = _CharIndex(self);
|
||||
}
|
||||
else if (_numberOfGlyphs == NSMaxRange(glyphRange)-1)
|
||||
{
|
||||
_JumpToGlyph(self, NSMaxRange(glyphRange)-1);
|
||||
gRange.length = _numberOfGlyphs - gRange.location;
|
||||
pos = [_textStorage length];
|
||||
}
|
||||
else
|
||||
{
|
||||
[NSException raise: NSRangeException
|
||||
format: @"glyph index out of range"];
|
||||
}
|
||||
while (_Back(self) == YES && _CharIndex(self) == pos)
|
||||
{
|
||||
gRange.length--;
|
||||
}
|
||||
|
||||
cRange.length = pos - cRange.location;
|
||||
}
|
||||
if (actualGlyphRange != 0)
|
||||
{
|
||||
*actualGlyphRange = gRange;
|
||||
|
|
Loading…
Reference in a new issue