]> granicus.if.org Git - graphviz/commitdiff
Quartz: format to UTI through function instead of array
authorGlen Low <glen.low@pixelglow.com>
Thu, 5 Dec 2013 14:33:19 +0000 (22:33 +0800)
committerGlen Low <glen.low@pixelglow.com>
Thu, 5 Dec 2013 15:00:05 +0000 (23:00 +0800)
* Function is safer: non-existent format won't crash

* Function is better encapsulated: strings not exposed in header

plugin/quartz/gvdevice_quartz.c
plugin/quartz/gvloadimage_quartz.c
plugin/quartz/gvplugin_quartz.c
plugin/quartz/gvplugin_quartz.h
plugin/quartz/gvrender_quartz.c

index 9b5d3daaa2dc52122cf2f7ec7b4592c5607cf685..9c7ee40db903d7848197087071884d97cdfd7a9f 100644 (file)
@@ -39,7 +39,7 @@ static void quartz_format(GVJ_t *job)
        /* image destination -> data consumer -> job's gvdevice */
        /* data provider <- job's imagedata */
        CGDataConsumerRef data_consumer = CGDataConsumerCreate(job, &device_data_consumer_callbacks);
-       CGImageDestinationRef image_destination = CGImageDestinationCreateWithDataConsumer(data_consumer, format_uti[job->device.id], 1, NULL);
+       CGImageDestinationRef image_destination = CGImageDestinationCreateWithDataConsumer(data_consumer, format_to_uti(job->device.id), 1, NULL);
        CGDataProviderRef data_provider = CGDataProviderCreateDirect(job->imagedata, BYTES_PER_PIXEL * job->width * job->height, &memory_data_provider_callbacks);
        
        /* add the bitmap image to the destination and save it */
index 11d95a7f92c5fffe3a16ee58d3bb31f15684ee82..28ddc6fbf794db5ac2b96e52ec50f999cce6cd4c 100644 (file)
@@ -122,7 +122,7 @@ static CGImageRef quartz_loadimage(GVJ_t * job, usershape_t *us)
                CFDictionaryRef options = hint_format_type == FORMAT_NONE ? NULL : CFDictionaryCreate(
                        kCFAllocatorDefault,
                        (const void **)&kCGImageSourceTypeIdentifierHint,
-                       (const void **)(format_uti + hint_format_type),
+                       (const void **)format_to_uti(hint_format_type),
                        1,
                        &kCFTypeDictionaryKeyCallBacks,
                        &kCFTypeDictionaryValueCallBacks);
index 52ed554a485178fc3ffd3640134d9604e1c823e7..947b0a7716a1f2126cf6ddc935fdad12f5bb0630 100644 (file)
@@ -27,25 +27,6 @@ extern gvplugin_installed_t gvdevice_quartz_types;
 
 #if __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ >= 1040
 extern gvplugin_installed_t gvdevice_quartz_types_for_cairo;
-
-/* Uniform Type Identifiers corresponding to each format_type */
-CFStringRef format_uti [] = {
-       NULL,
-       NULL,
-       CFSTR("com.microsoft.bmp"),
-       CFSTR("com.ilm.openexr-image"),
-       CFSTR("com.compuserve.gif"),
-       CFSTR("public.jpeg"),
-       CFSTR("public.jpeg-2000"),
-       CFSTR("com.adobe.pdf"),
-       CFSTR("com.apple.pict"),
-       CFSTR("public.png"),
-       CFSTR("com.adobe.photoshop-image"),
-       CFSTR("com.sgi.sgi-image"),
-       CFSTR("public.tiff"),
-       CFSTR("com.truevision.tga-image")
-};
-
 #endif
 /* data consumer backed by the gvdevice */
 
@@ -59,6 +40,40 @@ CGDataConsumerCallbacks device_data_consumer_callbacks = {
        NULL
 };
 
+#if __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ >= 1040
+
+CFStringRef format_to_uti(format_type format)
+{
+       switch (format) {
+               case FORMAT_BMP:
+                       return CFSTR("com.microsoft.bmp");
+               case FORMAT_EXR:
+                       return CFSTR("com.ilm.openexr-image");
+               case FORMAT_GIF:
+                       return CFSTR("com.compuserve.gif");
+               case FORMAT_JPEG:
+                       return CFSTR("public.jpeg");
+               case FORMAT_JPEG2000:
+                       return CFSTR("public.jpeg-2000");
+               case FORMAT_PICT:
+                       return CFSTR("com.apple.pict");
+               case FORMAT_PNG:
+                       return CFSTR("public.png");
+               case FORMAT_PSD:
+                       return CFSTR("com.adobe.photoshop-image");
+               case FORMAT_SGI:
+                       return CFSTR("com.sgi.sgi-image");
+               case FORMAT_TIFF:
+                       return CFSTR("public.tiff");
+               case FORMAT_TGA:
+                       return CFSTR("com.truevision.tga-image");
+               default:
+                       return NULL;
+       }
+}
+
+#endif
+
 static gvplugin_api_t apis[] = {
     {API_render, &gvrender_quartz_types},
        {API_textlayout, &gvtextlayout_quartz_types},
index 8716c4edd3a28fdda8ae0220949f31b241544811..7a1aa09d6f75f8400abc1802b35f8bf7e2423293 100644 (file)
@@ -48,7 +48,7 @@ static const int BITS_PER_COMPONENT = 8;      /* bits per color component */
 static const int BYTES_PER_PIXEL = 4;          /* bytes per pixel */
 
 #if __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ >= 1040
-extern CFStringRef format_uti [];
+CFStringRef format_to_uti(format_type format);
 #endif
 
 extern CGDataConsumerCallbacks device_data_consumer_callbacks;
index ddbf4fd813864f130f09889cbd69fde5c85715c7..cdf8c4cd1114439c0a1c7b4498da160c18a18090 100644 (file)
@@ -67,9 +67,8 @@ static void quartzgen_end_job(GVJ_t * job)
                                         &device_data_consumer_callbacks);
                CGImageDestinationRef image_destination =
                    CGImageDestinationCreateWithDataConsumer(data_consumer,
-                                                            format_uti
-                                                            [job->device.
-                                                             id], 1,
+                                                            format_to_uti(job->device.id),
+                                                                1,
                                                             NULL);
 
                /* add the bitmap image to the destination and save it */