Added simple glyph cahracter mapping methods

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@7996 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
FredKiefer 2000-11-03 00:21:29 +00:00
parent 1f8de305ac
commit 3692dce9fe

View file

@ -30,24 +30,6 @@
#include <AppKit/NSLayoutManager.h> #include <AppKit/NSLayoutManager.h>
#include "GSSimpleLayoutManager.h" #include "GSSimpleLayoutManager.h"
/*
* A little utility function to determine the range of characters in a scanner
* that are present in a specified character set.
*/
static inline NSRange
scanRange(NSScanner *scanner, NSCharacterSet* aSet)
{
unsigned start = [scanner scanLocation];
unsigned end = start;
if ([scanner scanCharactersFromSet: aSet intoString: 0] == YES)
{
end = [scanner scanLocation];
}
return NSMakeRange(start, end - start);
}
// _GSRunSearchKey is an internal class which serves as the foundation for // _GSRunSearchKey is an internal class which serves as the foundation for
// all our searching. This may not be an elegant way to go about this, so // all our searching. This may not be an elegant way to go about this, so
// if someone wants to optimize this out, please do. // if someone wants to optimize this out, please do.
@ -114,7 +96,6 @@ scanRange(NSScanner *scanner, NSCharacterSet* aSet)
{ {
@public @public
NSTextContainer *textContainer; NSTextContainer *textContainer;
NSString *testString;
} }
@end @end
@ -154,6 +135,7 @@ static NSComparisonResult aSort(GSIArrayItem i0, GSIArrayItem i1)
unsigned int _count; unsigned int _count;
void *_runs; void *_runs;
} }
- (void) insertObject: (id)anObject; - (void) insertObject: (id)anObject;
- (void) insertObject: (id)anObject atIndex: (unsigned)theIndex; - (void) insertObject: (id)anObject atIndex: (unsigned)theIndex;
- (id) objectAtIndex: (unsigned)theIndex; - (id) objectAtIndex: (unsigned)theIndex;
@ -218,6 +200,7 @@ static NSComparisonResult aSort(GSIArrayItem i0, GSIArrayItem i1)
NSLog(@"dead. VERY DEAD DEAD DEAD DEAD."); NSLog(@"dead. VERY DEAD DEAD DEAD DEAD.");
// NSLog(@"==> %d item(s)", GSIArrayCount(_runs)); // NSLog(@"==> %d item(s)", GSIArrayCount(_runs));
RELEASE(aKey);
} }
- (void) insertObject: (id)anObject - (void) insertObject: (id)anObject
@ -259,10 +242,12 @@ static NSComparisonResult aSort(GSIArrayItem i0, GSIArrayItem i1)
if (NSLocationInRange(aLocation, aKey->glyphRange)) if (NSLocationInRange(aLocation, aKey->glyphRange))
{ {
RELEASE(aKey);
return (position - 1); return (position - 1);
} }
} }
RELEASE(aKey);
return -1; return -1;
} }
@ -274,6 +259,7 @@ static NSComparisonResult aSort(GSIArrayItem i0, GSIArrayItem i1)
aKey->glyphRange.location = aLocation; aKey->glyphRange.location = aLocation;
position = GSIArrayInsertionPosition(_runs, (GSIArrayItem)aKey, aSort); position = GSIArrayInsertionPosition(_runs, (GSIArrayItem)aKey, aSort);
RELEASE(aKey);
if (position >= 0 && position - 1 >= 0) if (position >= 0 && position - 1 >= 0)
{ {
@ -310,7 +296,6 @@ static NSComparisonResult aSort(GSIArrayItem i0, GSIArrayItem i1)
@end @end
@implementation NSLayoutManager @implementation NSLayoutManager
+ (id) allocWithZone: (NSZone*)z + (id) allocWithZone: (NSZone*)z
@ -326,9 +311,9 @@ static NSComparisonResult aSort(GSIArrayItem i0, GSIArrayItem i1)
} }
} }
// Designated Initializer. Sets up this instance. Finds the shared NSGlyphGenerator // Designated Initializer. Sets up this instance. Finds the shared
// and the shared default NSTypesetter. The NSLayoutManager starts off without a // NSGlyphGenerator and the shared default NSTypesetter.
// NSTextStorage // The NSLayoutManager starts off without a NSTextStorage
- (id) init - (id) init
{ {
[super init]; [super init];
@ -380,11 +365,12 @@ static NSComparisonResult aSort(GSIArrayItem i0, GSIArrayItem i1)
return _textStorage; return _textStorage;
} }
// This method should be used instead of the primitive -setTextStorage: if you need to // This method should be used instead of the primitive -setTextStorage:
// replace a NSLayoutManager's NSTextStorage with a new one leaving the rest of the // if you need to replace a NSLayoutManager's NSTextStorage with a new
// web intact. This method deals with all the work of making sure the NSLayoutManager // one leaving the rest of the web intact. This method deals with all
// doesn't get deallocated and transferring all the NSLayoutManager s on the old // the work of making sure the NSLayoutManager doesn't get deallocated
// NSTextStorage to the new one. // and transferring all the NSLayoutManager s on the old NSTextStorage
// to the new one.
- (void) replaceTextStorage: (NSTextStorage*)newTextStorage - (void) replaceTextStorage: (NSTextStorage*)newTextStorage
{ {
NSArray *layoutManagers = [_textStorage layoutManagers]; NSArray *layoutManagers = [_textStorage layoutManagers];
@ -422,9 +408,9 @@ static NSComparisonResult aSort(GSIArrayItem i0, GSIArrayItem i1)
} }
} }
// Insert a container into the array before the container at index. Must invalidate // Insert a container into the array before the container at index.
// layout of all glyphs in the containers from the one previously at index to the // Must invalidate layout of all glyphs in the containers from the one
// last container. // previously at index to the last container.
- (void) insertTextContainer: (NSTextContainer*)aTextContainer - (void) insertTextContainer: (NSTextContainer*)aTextContainer
atIndex: (unsigned)index atIndex: (unsigned)index
{ {
@ -451,7 +437,6 @@ static NSComparisonResult aSort(GSIArrayItem i0, GSIArrayItem i1)
actualCharacterRange: (NSRange*)actualRange actualCharacterRange: (NSRange*)actualRange
{ {
// FIXME // FIXME
// Currently we don't have context information // Currently we don't have context information
if (actualRange) if (actualRange)
{ {
@ -472,7 +457,6 @@ static NSComparisonResult aSort(GSIArrayItem i0, GSIArrayItem i1)
isSoft: (BOOL)flag isSoft: (BOOL)flag
actualCharacterRange: (NSRange*)actualRange actualCharacterRange: (NSRange*)actualRange
{ {
[self _doLayout]; [self _doLayout];
} }
@ -492,9 +476,9 @@ static NSComparisonResult aSort(GSIArrayItem i0, GSIArrayItem i1)
// Invalidates layout of all glyphs in container and all subsequent containers. // Invalidates layout of all glyphs in container and all subsequent containers.
- (void) textContainerChangedGeometry: (NSTextContainer*)aContainer - (void) textContainerChangedGeometry: (NSTextContainer*)aContainer
{ {
unsigned first = 0;
// find the first character in that text container // find the first character in that text container
NSRange aRange = [self glyphRangeForTextContainer: aContainer];
unsigned first = aRange.location;
// invalidate the layout from here on // invalidate the layout from here on
[self invalidateLayoutForCharacterRange: [self invalidateLayoutForCharacterRange:
@ -645,7 +629,8 @@ invalidatedRange.length);
// for all holes sequentially encountered until the desired index is available. // for all holes sequentially encountered until the desired index is available.
- (unsigned) characterIndexForGlyphAtIndex: (unsigned)glyphIndex - (unsigned) characterIndexForGlyphAtIndex: (unsigned)glyphIndex
{ {
return 0; // Currently gyphIndex is the same as character index
return glyphIndex;
} }
// These two methods can cause glyph generation. // These two methods can cause glyph generation.
@ -660,7 +645,11 @@ invalidatedRange.length);
- (NSRange) characterRangeForGlyphRange: (NSRange)glyphRange - (NSRange) characterRangeForGlyphRange: (NSRange)glyphRange
actualGlyphRange: (NSRange*)actualGlyphRange actualGlyphRange: (NSRange*)actualGlyphRange
{ {
return NSMakeRange(0, 0); // Currently gyphIndex is the same as character index
if (actualGlyphRange != NULL)
*actualGlyphRange = glyphRange;
return glyphRange;
} }
// Returns the range of glyphs that are generated from the unichars in // Returns the range of glyphs that are generated from the unichars in
@ -674,7 +663,11 @@ invalidatedRange.length);
- (NSRange) glyphRangeForCharacterRange: (NSRange)charRange - (NSRange) glyphRangeForCharacterRange: (NSRange)charRange
actualCharacterRange: (NSRange*)actualCharRange actualCharacterRange: (NSRange*)actualCharRange
{ {
return NSMakeRange(0, 0); // Currently gyphIndex is the same as character index
if (actualCharRange != NULL)
*actualCharRange = charRange;
return charRange;
} }
// //
@ -1398,6 +1391,23 @@ aLine->lineFragmentRect.size.height);
contain for the most part is. Therefore, my country and a handsome gift of contain for the most part is. Therefore, my country and a handsome gift of
Ghiradelli chocolate to he who puts all the pieces together : ) */ Ghiradelli chocolate to he who puts all the pieces together : ) */
/*
* A little utility function to determine the range of characters in a scanner
* that are present in a specified character set.
*/
static inline NSRange
scanRange(NSScanner *scanner, NSCharacterSet* aSet)
{
unsigned start = [scanner scanLocation];
unsigned end = start;
if ([scanner scanCharactersFromSet: aSet intoString: 0] == YES)
{
end = [scanner scanLocation];
}
return NSMakeRange(start, end - start);
}
@implementation NSLayoutManager (Private) @implementation NSLayoutManager (Private)
- (int) _rebuildLayoutForTextContainer: (NSTextContainer*)aContainer - (int) _rebuildLayoutForTextContainer: (NSTextContainer*)aContainer
startingAtGlyphIndex: (int)glyphIndex startingAtGlyphIndex: (int)glyphIndex