objective c - Redraw NSBezierPath multiple times, with scaling? -
i writing many chunks of text on nsview using nsstring helper method ... slow write large amount of in many cases repeated text. trying re-write code text converted nsbezierpath's generated once, drawn many times. following draw text @ bottom of screen.
i still trying read through apple documentation understand how works, in mean time wonder if there easy way alter code re-draw path in multiple locations?
// write path view nsbezierpath* path = [self bezierpathfromtext: @"hello world!" maxwidth: width]; [[nscolor graycolor] setfill]; [path fill]; here method writes text path:
-(nsbezierpath*) bezierpathfromtext: (nsstring*) text maxwidth: (float) maxwidth { // create container describing shape of text area, // testing done use whole width of nsview. nstextcontainer* container = [[nstextcontainer alloc] initwithcontainersize:nsmakesize(maxwidth - maxwidth/4, 60)]; // create storage object hold attributed version of string display nsfont* font = [nsfont fontwithname:@"helvetica" size: 26]; nsdictionary* attr = [nsdictionary dictionarywithobjectsandkeys: font, nsfontattributename, nil]; nstextstorage* storage = [[nstextstorage alloc] initwithstring: text attributes: attr]; // create layout manager responsible writing text nsview nslayoutmanager* layoutmanger = [[nslayoutmanager alloc] init]; [layoutmanger addtextcontainer: container]; [layoutmanger settextstorage: storage]; nsrange glyphrange = [layoutmanger glyphrangefortextcontainer: container]; nsglyph glypharray[glyphrange.length]; nsuinteger glyphcount = [layoutmanger getglyphs:glypharray range:glyphrange]; nsbezierpath* path = [[nsbezierpath alloc] init]; //nsbezierpath *path = [nsbezierpath bezierpathwithrect:nsmakerect(0, 0, 30, 30)]; [path movetopoint: nsmakepoint(0, 7)]; [path appendbezierpathwithglyphs:glypharray count: glyphcount infont:font]; // deallocate unused objects [layoutmanger release]; [storage release]; [container release]; return [path autorelease]; } edit: attempting optimise application outputs screen, sequence of large amounts text such sequence of 10,000 numbers. each number has markings around and/or differing amounts of space between them, , numbers have dots and/or lines above, below or between them. example @ top of page 2 of document much more output.
you start removing line:
[path movetopoint: nsmakepoint(0, 7)]; so path isn't tied particular location in view. done, can call method path, move point, stroke path, move point, stroke path, , on. if want move starting point within path description, use -relativemovetopoint:.
Comments
Post a Comment