ios - CTFrameDraw() causes app to crash -


i've been pulling hair trying sort problem out. i'm programatically creating pdf , drawing images , text every time try draw text ctframedraw() app breaks @ point. drawing image works fine. i've dumbed down function copy paste apple example still no luck.

at top of page have included , added framework project.

the function (disregard first 2 values type , entries):

int createpdf(int type, const char** entries, const char *filename) {     // create a4 pagerect     cgrect pagerect = cgrectmake(0, 0, 612, 792);      // code block sets our pdf context can draw     cgcontextref pdfcontext;     cfstringref path;     cfurlref url;     cfmutabledictionaryref mydictionary = null;      // create cfstring filename provide method when call     path = cfstringcreatewithcstring (null, filename,                                       kcfstringencodingutf8);      // create cfurl using cfstring defined     url = cfurlcreatewithfilesystempath (null, path,                                          kcfurlposixpathstyle, 0);     cfrelease (path);     // dictionary contains options 'signing' pdf     mydictionary = cfdictionarycreatemutable(null, 0,                                              &kcftypedictionarykeycallbacks,                                              &kcftypedictionaryvaluecallbacks);      cfdictionarysetvalue(mydictionary, kcgpdfcontexttitle, cfstr("myapp"));     cfdictionarysetvalue(mydictionary, kcgpdfcontextcreator, cfstr("fred"));     // create our pdf context cfurl, cgrect provide, , above defined dictionary     pdfcontext = cgpdfcontextcreatewithurl (url, &pagerect, mydictionary);     // cleanup our mess     cfrelease(mydictionary);     cfrelease(url);     // done creating our pdf context, it's time draw      // starts our first page     cgcontextbeginpage (pdfcontext, &pagerect);      // draws black rectangle around page inset 50 on sides     cgcontextstrokerect(pdfcontext, cgrectmake(25, 25, pagerect.size.width - 50, pagerect.size.height - 50));      // code block create logo image     const char *picture = "pdficon";     cgimageref image;     cgdataproviderref provider;     cfstringref picturepath;     cfurlref pictureurl;      picturepath = cfstringcreatewithcstring (null, picture,                                              kcfstringencodingutf8);     pictureurl = cfbundlecopyresourceurl(cfbundlegetmainbundle(), picturepath, cfstr("png"), null);     cfrelease(picturepath);     provider = cgdataprovidercreatewithurl (pictureurl);     cfrelease (pictureurl);     image = cgimagecreatewithpngdataprovider (provider, null, true, kcgrenderingintentdefault);     cgdataproviderrelease (provider);     cgcontextdrawimage (pdfcontext, cgrectmake(30, pagerect.size.height - 100, 70, 70),image);     cgimagerelease (image);     // end image code      // flip coordinate system     cgrect bounds = cgcontextgetclipboundingbox(pdfcontext);     cgcontextscalectm(pdfcontext, 1.0, -1.0);     cgcontexttranslatectm(pdfcontext, 0.0, -bounds.size.height);      // set text matrix.     cgcontextsettextmatrix(pdfcontext, cgaffinetransformidentity);      // create path bounds area drawing text.     // path need not rectangular.     cgmutablepathref mutpath = cgpathcreatemutable();      // in simple example, initialize rectangular path.     //cgrect bounds = cgrectmake(10.0, 10.0, 200.0, 200.0);     cgpathaddrect(mutpath, null, bounds );      // initialize string.     cfstringref textstring = cfstr("hello, world! know nothing in world has power word. write one, , @ it, until begins shine.");      // create mutable attributed string max length of 0.     // max length hint how internal storage reserve.     // 0 means no hint.     cfmutableattributedstringref attrstring =     cfattributedstringcreatemutable(kcfallocatordefault, 0);      // copy textstring newly created attrstring     cfattributedstringreplacestring (attrstring, cfrangemake(0, 0),                                      textstring);      // create color added attribute attrstring.     cgcolorspaceref rgbcolorspace = cgcolorspacecreatedevicergb();     cgfloat components[] = { 1.0, 0.0, 0.0, 0.8 };     cgcolorref red = cgcolorcreate(rgbcolorspace, components);     cgcolorspacerelease(rgbcolorspace);      // set color of first 12 chars red.     cfattributedstringsetattribute(attrstring, cfrangemake(0, 12),                                    kctforegroundcolorattributename, red);      // create framesetter attributed string.     ctframesetterref framesetter =     ctframesettercreatewithattributedstring(attrstring);     cfrelease(attrstring);      // create frame.     ctframeref frame = ctframesettercreateframe(framesetter,                                                 cfrangemake(0, 0), mutpath, null);      // draw specified frame in given context.     ctframedraw(frame, pdfcontext);      // release objects used.     cfrelease(frame);     cfrelease(path);     cfrelease(framesetter);      // done drawing page, let's end     // add many pages wanted using cgcontextbeginpage/cgcontextendpage     cgcontextendpage (pdfcontext);      // done our context now, release     cgcontextrelease (pdfcontext);      return 0; } 

any suggestions gladly appreciated. / frederik


Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -