Question

m_LayoutManager = [[NSLayoutManager alloc] init];
m_TextContainer = [[NSTextContainer alloc] init];
m_TextStorage = [[NSTextStorage alloc] initWithString: @"Here's to the crazy ones, the misfits, the rebels, the troublemakers, the round pegs in the square holes, the ones who see things differently."];  
[m_LayoutManager addTextContainer: m_TextContainer];
[m_TextStorage addLayoutManager: m_LayoutManager];
[m_TextContainer release];
[m_LayoutManager release];
[m_TextStorage replaceCharactersInRange:NSMakeRange(0, [m_TextStorage length]) withString: XMajor];
[m_TextContainer setContainerSize: NSMakeSize(75,50)];

NSRange glyphRange = [m_LayoutManager glyphRangeForTextContainer: m_TextContainer];
NSRect usedRect = [m_LayoutManager usedRectForTextContainer: m_TextContainer];

[[NSColor brownColor] setFill];
//NSRectFill( NSMakeRect(j - usedRect.size.width/2,y0 - 50 - 5,50,50));

[m_LayoutManager drawGlyphsForGlyphRange:glyphRange 
                                 atPoint: NSMakePoint(j - usedRect.size.width/2,y0 - 50 - 5)];  

What I end up seeing is the text starting from the bottom of the rectangle and going up. It looks like this when I draw it in view:

ferently.
the ones who see things dif
nd pegs in the square holes, 
the troublemakers, the rou
 the misfits, the rebels,
Here's to the crazy ones,

I want the text to start from top and go down and I also want the text to word wrap, right now it will start the middle of a word on a new line. I read about NSLayoutManager, NSParagraphStyle, and NSTypeSetter, but I cannot figure out how to fix this problem.

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top