I get the bounding rect for all glyphs in my TextView subclass and display them.
Looks perfect: the boxes snugly fit the characters.

But when a line contains any Thai character (similar for Laos, Burma, Khmer) 
then the boxes are strangly wide.

Why? Is there some good reason for this? Or am I doing something wrong?

Example: font = Thonburi 48pt. One line of "Wim" prints:
2011-09-13 12:01:36.072 NSFontAttributeExplorer[5156:707] -[FontView 
setFont:andString:] 3 glyps - self {{0, 0}, {205, 231}}
2011-09-13 12:01:36.075 NSFontAttributeExplorer[5156:707] -[FontView 
setFont:andString:] textContainer {205, 10000000}
2011-09-13 12:01:36.075 NSFontAttributeExplorer[5156:707] -[FontView 
setFont:andString:] glyphs[0] =  172           rect {{5, 0}, 
{45.450000000000003, 66}}
2011-09-13 12:01:36.077 NSFontAttributeExplorer[5156:707] -[FontView 
setFont:andString:] glyphs[1] =  190           rect {{50.450000000000003, 0}, 
{11.268749999999997, 66}}
2011-09-13 12:01:36.077 NSFontAttributeExplorer[5156:707] -[FontView 
setFont:andString:] glyphs[2] =  194           rect {{61.71875, 0}, 
{42.918746948242188, 66}}

but the line "Wimม" (last char is Thai character mo ma = U+0E21) prints:
2011-09-13 12:03:55.684 NSFontAttributeExplorer[5156:707] -[FontView 
setFont:andString:] 4 glyps - self {{0, 0}, {205, 231}}
2011-09-13 12:03:55.685 NSFontAttributeExplorer[5156:707] -[FontView 
setFont:andString:] textContainer {205, 10000000}
2011-09-13 12:03:55.686 NSFontAttributeExplorer[5156:707] -[FontView 
setFont:andString:] glyphs[0] =  172           rect {{-28, 
-5.5250000000000057}, {99.318749999999994, 78.918750000000003}}
2011-09-13 12:03:55.687 NSFontAttributeExplorer[5156:707] -[FontView 
setFont:andString:] glyphs[1] =  190           rect {{17.450000000000003, 
-5.5250000000000057}, {99.318749999999994, 78.918750000000003}}
2011-09-13 12:03:55.688 NSFontAttributeExplorer[5156:707] -[FontView 
setFont:andString:] glyphs[2] =  194           rect {{28.71875, 
-5.5250000000000057}, {99.318749999999994, 78.918750000000003}}
2011-09-13 12:03:55.689 NSFontAttributeExplorer[5156:707] -[FontView 
setFont:andString:] glyphs[3] =   61           rect {{71.637500000000003, 
-5.5250000000000057}, {99.318750000000009, 78.918750000000003}}


Code fragment:
        NSUInteger numberOfGlyphs = [ layoutManager numberOfGlyphs ];
        #ifdef LOG_BOXES
                NSLog(@"%s %lu glyps - self %@", __FUNCTION__, numberOfGlyphs, 
NSStringFromRect([self bounds]) );
        #endif
        for( NSUInteger glyphIndex = 0; glyphIndex < numberOfGlyphs; )
        {
                NSRange effectiveGlyphRange;
                NSTextContainer *container =    [ layoutManager 
textContainerForGlyphAtIndex:   glyphIndex 
                                                                                
                                effectiveRange:                                 
&effectiveGlyphRange
                                                                                
];
                #ifdef LOG_BOXES
                        NSLog(@"%s textContainer %@", __FUNCTION__, 
NSStringFromSize([container containerSize]) );
                #endif
                NSUInteger max = NSMaxRange(effectiveGlyphRange);
                NSRange sux; sux.length = 1;
                for( NSUInteger i = effectiveGlyphRange.location; i < max; i++)
                {
                        sux.location = i;
                        NSRect r = [ layoutManager boundingRectForGlyphRange: 
sux inTextContainer: container ];
                        NSGlyph g = [ layoutManager glyphAtIndex: i ];
                        if              ( g == NSControlGlyph )
                        {
                                #ifdef LOG_BOXES
                                        NSLog(@"%s glyphs[%lu] = NSControlGlyph 
rect %@", __FUNCTION__, i, NSStringFromRect(r) );
                                #endif
                        }
                        else if ( g == NSNullGlyph )
                        {
                                #ifdef LOG_BOXES
                                        NSLog(@"%s glyphs[%lu] = NSNullGlyph    
rect %@", __FUNCTION__, i, NSStringFromRect(r) );
                                #endif
                        }
                        else
                        {
                                #ifdef LOG_BOXES
                                        NSLog(@"%s glyphs[%lu] = %4u           
rect %@", __FUNCTION__, i, g, NSStringFromRect(r) );
                                #endif
                        };
                };
                
                glyphIndex = max;
        };


Kind regards,

Gerriet.

_______________________________________________

Cocoa-dev mailing list ([email protected])

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to