Graphviz 14.0.3~dev.20251029.0425
Loading...
Searching...
No Matches
gvdevice_quartz.c
Go to the documentation of this file.
1/*************************************************************************
2 * Copyright (c) 2011 AT&T Intellectual Property
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * https://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors: Details at https://graphviz.org
9 *************************************************************************/
10
11#include "config.h"
12
13#include <gvc/gvplugin_device.h>
14
15#include "gvplugin_quartz.h"
16#include <stdbool.h>
17#include <util/gv_math.h>
18
19#if __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ >= 1040 && defined(HAVE_PANGOCAIRO)
20
21static const void *memory_data_consumer_get_byte_pointer(void *info)
22{
23 return info;
24}
25
26CGDataProviderDirectCallbacks memory_data_provider_callbacks = {
27 0,
28 memory_data_consumer_get_byte_pointer,
29 NULL,
30 NULL,
31 NULL
32};
33
34static void quartz_format(GVJ_t *job)
35{
36 /* image destination -> data consumer -> job's gvdevice */
37 /* data provider <- job's imagedata */
38 CGDataConsumerRef data_consumer = CGDataConsumerCreate(job, &device_data_consumer_callbacks);
39 CGImageDestinationRef image_destination =
40 CGImageDestinationCreateWithDataConsumer(data_consumer,
41 format_to_uti((format_type)job->device.id), 1, NULL);
42 CGDataProviderRef data_provider = CGDataProviderCreateDirect(job->imagedata, BYTES_PER_PIXEL * job->width * job->height, &memory_data_provider_callbacks);
43
44 const void *keys[] = {kCGImagePropertyDPIWidth, kCGImagePropertyDPIHeight};
45 const void *values[] = {
46 CFNumberCreate(NULL, kCFNumberDoubleType, &job->dpi.x),
47 CFNumberCreate(NULL, kCFNumberDoubleType, &job->dpi.y)
48 };
49 CFDictionaryRef dpi = CFDictionaryCreate(NULL, keys, values,
50 sizeof(keys) / sizeof(keys[0]),
51 &kCFTypeDictionaryKeyCallBacks,
52 &kCFTypeDictionaryValueCallBacks);
53
54 /* add the bitmap image to the destination and save it */
55 CGColorSpaceRef color_space = CGColorSpaceCreateWithName(kCGColorSpaceSRGB);
56 CGImageRef image = CGImageCreate (
57 job->width, /* width in pixels */
58 job->height, /* height in pixels */
59 BITS_PER_COMPONENT, /* bits per component */
60 BYTES_PER_PIXEL * 8, /* bits per pixel */
61 BYTES_PER_PIXEL * job->width, /* bytes per row: exactly width # of pixels */
62 color_space, /* color space: sRGB */
63 kCGImageAlphaPremultipliedFirst|kCGBitmapByteOrder32Little, /* bitmap info: corresponds to CAIRO_FORMAT_ARGB32 */
64 data_provider, /* data provider: from imagedata */
65 NULL, /* decode: don't remap colors */
66 false, // don't interpolate
67 kCGRenderingIntentDefault /* rendering intent (what to do with out-of-gamut colors): default */
68 );
69 CGImageDestinationAddImage(image_destination, image, dpi);
70 CGImageDestinationFinalize(image_destination);
71
72 /* clean up */
73 CGImageRelease(image);
74 CGColorSpaceRelease(color_space);
75 CGDataProviderRelease(data_provider);
76 if (image_destination)
77 CFRelease(image_destination);
78 if (dpi != NULL)
79 CFRelease(dpi);
80 CGDataConsumerRelease(data_consumer);
81}
82
83static gvdevice_engine_t quartz_engine = {
84 NULL, /* quartz_initialize */
85 quartz_format,
86 NULL, /* quartz_finalize */
87};
88
89static gvdevice_features_t device_features_quartz = {
91 | GVDEVICE_DOES_TRUECOLOR,/* flags */
92 {0.,0.}, /* default margin - points */
93 {0.,0.}, /* default page width, height - points */
94 {96.,96.}, /* dpi */
95};
96
97gvplugin_installed_t gvdevice_quartz_types_for_cairo[] = {
98 {FORMAT_BMP, "bmp:cairo", 7, &quartz_engine, &device_features_quartz},
99 {FORMAT_GIF, "gif:cairo", 7, &quartz_engine, &device_features_quartz},
100 {FORMAT_EXR, "exr:cairo", 7, &quartz_engine, &device_features_quartz},
101 {FORMAT_ICNS, "icns:cairo", 7, &quartz_engine, &device_features_quartz},
102 {FORMAT_ICO, "ico:cairo", 7, &quartz_engine, &device_features_quartz},
103 {FORMAT_JPEG, "jpe:cairo", 7, &quartz_engine, &device_features_quartz},
104 {FORMAT_JPEG, "jpeg:cairo", 7, &quartz_engine, &device_features_quartz},
105 {FORMAT_JPEG, "jpg:cairo", 7, &quartz_engine, &device_features_quartz},
106 {FORMAT_JPEG2000, "jp2:cairo", 7, &quartz_engine, &device_features_quartz},
107 {FORMAT_PICT, "pct:cairo", 7, &quartz_engine, &device_features_quartz},
108 {FORMAT_PICT, "pict:cairo", 7, &quartz_engine, &device_features_quartz},
109 {FORMAT_PNG, "png:cairo", 7, &quartz_engine, &device_features_quartz},
110 {FORMAT_PSD, "psd:cairo", 7, &quartz_engine, &device_features_quartz},
111 {FORMAT_SGI, "sgi:cairo", 7, &quartz_engine, &device_features_quartz},
112 {FORMAT_TIFF, "tif:cairo", 7, &quartz_engine, &device_features_quartz},
113 {FORMAT_TIFF, "tiff:cairo", 7, &quartz_engine, &device_features_quartz},
114 {FORMAT_TGA, "tga:cairo", 7, &quartz_engine, &device_features_quartz},
115 {0, NULL, 0, NULL, NULL}
116};
117
118#endif
node NULL
Definition grammar.y:181
Arithmetic helper functions.
@ BYTES_PER_PIXEL
Definition gv_math.h:91
#define GVDEVICE_DOES_TRUECOLOR
Definition gvcjob.h:90
#define GVDEVICE_BINARY_FORMAT
Definition gvcjob.h:91
@ FORMAT_ICO
@ FORMAT_TIFF
@ FORMAT_BMP
CGDataConsumerCallbacks device_data_consumer_callbacks
static const int BITS_PER_COMPONENT
@ FORMAT_PICT
@ FORMAT_EXR
@ FORMAT_JPEG2000
@ FORMAT_TGA
@ FORMAT_ICNS
@ FORMAT_PSD
@ FORMAT_SGI
format_type
@ FORMAT_JPEG
Definition gvrender_gd.c:37
@ FORMAT_GIF
Definition gvrender_gd.c:36
@ FORMAT_PNG
Definition gvrender_gd.c:38
T_cell image
Definition htmlparse.y:334
pointf dpi
Definition gvcjob.h:325
gvplugin_active_device_t device
Definition gvcjob.h:286
unsigned char * imagedata
location of imagedata
Definition gvcjob.h:297
unsigned int width
Definition gvcjob.h:327
unsigned int height
Definition gvcjob.h:328
ingroup plugin_api
Definition gvplugin.h:35
double x
Definition geom.h:29
double y
Definition geom.h:29