From: Glen Low Date: Thu, 5 Dec 2013 15:39:19 +0000 (+0800) Subject: Quartz: correctly handle other bitmap formats in iOS X-Git-Tag: 2.38.0~132^2~2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=11f399bf2033520a14493d3667fd8792e45b828c;p=graphviz Quartz: correctly handle other bitmap formats in iOS * On iOS, temp scratch files were memory mapped for all bitmap formats but only cleaned up for FORMAT_CGIMAGE. This fixes that and cleans up the surrounding code flow. * Don't use job external context to determine whether to render FORMAT_CGIMAGE. The format + job context is sufficient for rendition. * This also fixes export PDF warnings: bitmap context functions had been called on PDF context. --- diff --git a/plugin/quartz/gvrender_quartz.c b/plugin/quartz/gvrender_quartz.c index 8ae44c3a4..a12f3a3b0 100644 --- a/plugin/quartz/gvrender_quartz.c +++ b/plugin/quartz/gvrender_quartz.c @@ -34,20 +34,38 @@ static CGFloat dotted[] = { 2.0, 6.0 }; static void quartzgen_begin_job(GVJ_t * job) { - if (!job->external_context) - job->context = NULL; - else if (job->device.id == FORMAT_CGIMAGE) { - /* save the passed-in context in the window field, so we can create a CGContext in the context field later on */ - job->window = job->context; - *((CGImageRef *) job->window) = NULL; + switch (job->device.id) { + case FORMAT_CGIMAGE: + /* save the passed-in context in the window field, so we can create a CGContext in the context field later on */ + job->window = job->context; + *((CGImageRef *) job->window) = NULL; + } + job->context = NULL; - } } static void quartzgen_end_job(GVJ_t * job) { CGContextRef context = (CGContextRef) job->context; - if (!job->external_context) { + +#if __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ >= 20000 + void* context_data; + size_t context_datalen; + + switch (job->device.id) { + + case FORMAT_PDF: + context_data = NULL; + context_datalen = 0; + break; + + default: + context_data = CGBitmapContextGetData(context); + context_datalen = CGBitmapContextGetBytesPerRow(context) * CGBitmapContextGetHeight(context); + break; + } +#endif + switch (job->device.id) { case FORMAT_PDF: @@ -56,6 +74,8 @@ static void quartzgen_end_job(GVJ_t * job) break; case FORMAT_CGIMAGE: + /* create an image and save it where the window field is, which was set to the passed-in context at begin job */ + *((CGImageRef *) job->window) = CGBitmapContextCreateImage(context); break; #if __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ >= 1040 @@ -85,22 +105,13 @@ static void quartzgen_end_job(GVJ_t * job) break; #endif } + CGContextRelease(context); - } else if (job->device.id == FORMAT_CGIMAGE) { - /* create an image and save it where the window field is, which was set to the passed-in context at begin job */ - *((CGImageRef *) job->window) = - CGBitmapContextCreateImage(context); -#if __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ >= 20000 - void *context_data = CGBitmapContextGetData(context); - size_t context_datalen = - CGBitmapContextGetBytesPerRow(context) * - CGBitmapContextGetHeight(context); -#endif - CGContextRelease(context); + #if __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ >= 20000 - munmap(context_data, context_datalen); + if (context_data && context_datalen) + munmap(context_data, context_datalen); #endif - } } static void quartzgen_begin_page(GVJ_t * job)