35#include <pango/pangocairo.h>
44#if defined ( PLD_wincairo )
46#include <cairo-win32.h>
48#if defined ( PLD_xcairo )
49#include <cairo-xlib.h>
53#include <X11/cursorfont.h>
54#include <X11/keysym.h>
56#if defined ( PLD_pdfcairo )
59#if defined ( PLD_pscairo )
62#if defined ( PLD_svgcairo )
72#define PLCAIRO_DEFAULT_X 720
73#define PLCAIRO_DEFAULT_Y 540
75#define MAX_STRING_LEN 500
76#define MAX_MARKUP_LEN MAX_STRING_LEN * 10
88 {
"text_anti_aliasing",
DRV_INT, &
text_anti_aliasing,
"Set desired text anti-aliasing (text_anti_aliasing=0|1|2|3). The numbers are in the same order as the cairo_antialias_t enumeration documented at http://cairographics.org/manual/cairo-cairo-t.html#cairo-antialias-t)" },
89 {
"graphics_anti_aliasing",
DRV_INT, &
graphics_anti_aliasing,
"Set desired graphics anti-aliasing (graphics_anti_aliasing=0|1|2|3). The numbers are in the same order as the cairo_antialias_t enumeration documented at http://cairographics.org/manual/cairo-cairo-t.html#cairo-antialias-t" },
91 {
"rasterize_image",
DRV_INT, &
rasterize_image,
"Raster or vector image rendering (rasterize_image=0|1)" },
92 {
"set_background",
DRV_INT, &
set_background,
"Set the background for the extcairo device (set_background=0|1). If 1 then the plot background will set by PLplot" },
93 {
"image_buffering",
DRV_INT, &
image_buffering,
"Buffered offscreen rendering for the xcairo device (image_buffering=0|1)." },
94 { NULL,
DRV_INT, NULL, NULL } };
123#if defined ( PLD_xcairo )
124 cairo_surface_t *cairoSurface_X;
125 cairo_t *cairoContext_X;
126 short exit_event_loop;
129 unsigned int xdrawable_mode;
131#if defined ( PLD_memcairo )
132 unsigned char *memory;
133 unsigned char *cairo_format_memory;
136#if defined ( PLD_wincairo )
137 cairo_surface_t *cairoSurface_win;
138 cairo_t *cairoContext_win;
150#if defined ( PLD_xcairo )
151 "xcairo:Cairo X Windows Driver:1:cairo:100:xcairo\n"
153#if defined ( PLD_pdfcairo )
154 "pdfcairo:Cairo PDF Driver:0:cairo:101:pdfcairo\n"
156#if defined ( PLD_pscairo )
157 "pscairo:Cairo PS Driver:0:cairo:102:pscairo\n"
159#if defined ( PLD_epscairo )
160 "epscairo:Cairo EPS Driver:0:cairo:103:epscairo\n"
162#if defined ( PLD_svgcairo )
163 "svgcairo:Cairo SVG Driver:0:cairo:104:svgcairo\n"
165#if defined ( PLD_pngcairo )
166 "pngcairo:Cairo PNG Driver:0:cairo:105:pngcairo\n"
168#if defined ( PLD_memcairo )
169 "memcairo:Cairo Memory Driver:0:cairo:106:memcairo\n"
171#if defined ( PLD_extcairo )
172 "extcairo:Cairo External Context Driver:0:cairo:107:extcairo\n"
174#if defined ( PLD_wincairo )
175 "wincairo:Cairo Microscoft Windows Driver:0:cairo:108:wincairo\n"
183#if defined ( PLD_xcairo )
188} PLXcairoDrawableInfo;
196#define NPANGOLOOKUP 5
207 "PLPLOT_FREETYPE_SANS_FAMILY",
208 "PLPLOT_FREETYPE_SERIF_FAMILY",
209 "PLPLOT_FREETYPE_MONO_FAMILY",
210 "PLPLOT_FREETYPE_SCRIPT_FAMILY",
211 "PLPLOT_FREETYPE_SYMBOL_FAMILY"
214#define FAMILY_LOOKUP_LEN 1024
245cairo_status_t
write_to_stream(
void *,
unsigned char *,
unsigned int );
301 cairo_surface_t *tmp_sfc;
302 cairo_t *tmp_context;
317 cairo_image_surface_create( CAIRO_FORMAT_ARGB32,
345 cairo_surface_t *tmp_sfc;
346 cairo_t *tmp_context;
360 plexit(
"Can not plot to a Cairo device with no context" );
400 cairo_set_source_rgba( aStream->
cairoContext, 1.0, 1.0, 1.0, 1.0 );
597 cairo_set_operator( aStream->
cairoContext, CAIRO_OPERATOR_OVER );
600 cairo_set_operator( aStream->
cairoContext, CAIRO_OPERATOR_SOURCE );
603 cairo_set_operator( aStream->
cairoContext, CAIRO_OPERATOR_XOR );
625 case CAIRO_OPERATOR_OVER:
628 case CAIRO_OPERATOR_SOURCE:
631 case CAIRO_OPERATOR_XOR:
716 if ( aStream->
upDown < 0 )
732 if ( aStream->
upDown > 0 )
748 if ( aStream->
uline == 1 )
762 plwarn(
"'-', and 'b/B' text escape sequences not processed." );
775 int textXExtent, textYExtent, baseline;
776 PLFLT rotation, shear, stride, cos_rot, sin_rot, cos_shear, sin_shear;
777 cairo_matrix_t *cairoTransformMatrix;
778 cairo_font_options_t *cairoFontOptions;
779 PangoContext *context;
793 layout = pango_cairo_create_layout( aStream->
cairoContext );
795 pango_layout_get_pixel_size( layout, &textXExtent, &textYExtent );
796 baseline = pango_layout_get_baseline( layout );
806 context = pango_layout_get_context( layout );
807 cairoFontOptions = cairo_font_options_create();
809 pango_cairo_context_set_font_options( context, cairoFontOptions );
810 pango_layout_context_changed( layout );
811 cairo_font_options_destroy( cairoFontOptions );
826 cairoTransformMatrix = (cairo_matrix_t *) malloc(
sizeof ( cairo_matrix_t ) );
827 cairo_matrix_init( cairoTransformMatrix, 1.0, 0.0, 0.0, -1.0, 0.0, 0.0 );
828 cairo_transform( aStream->
cairoContext, cairoTransformMatrix );
834 cos_rot = cos( rotation );
835 sin_rot = sin( rotation );
836 cos_shear = cos( shear );
837 sin_shear = sin( shear );
840 cairo_matrix_init( cairoTransformMatrix,
843 cos_rot * sin_shear + sin_rot * cos_shear,
844 -sin_rot * sin_shear + cos_rot * cos_shear,
846 cairo_transform( aStream->
cairoContext, cairoTransformMatrix );
847 free( cairoTransformMatrix );
852 (
double) ( -1.0 * args->
just * (
double) textXExtent ),
853 (
double) 0.5 * aStream->
fontSize - baseline / 1024.0 );
856 pango_cairo_show_layout( aStream->
cairoContext, layout );
863 g_object_unref( layout );
876 int textXExtent, textYExtent, baseline;
877 char *textWithPangoMarkup;
878 PLFLT rotation, shear, stride, cos_rot, sin_rot, cos_shear, sin_shear;
879 cairo_matrix_t *cairoTransformMatrix;
880 cairo_font_options_t *cairoFontOptions;
881 PangoContext *context;
892 printf(
"Non unicode string passed to a cairo driver, ignoring\n" );
899 printf(
"Sorry, the cairo drivers only handles strings of length < %d\n",
MAX_STRING_LEN );
910 layout = pango_cairo_create_layout( aStream->
cairoContext );
911 pango_layout_set_markup( layout, textWithPangoMarkup, -1 );
912 pango_layout_get_pixel_size( layout, &textXExtent, &textYExtent );
913 baseline = pango_layout_get_baseline( layout );
923 context = pango_layout_get_context( layout );
924 cairoFontOptions = cairo_font_options_create();
926 pango_cairo_context_set_font_options( context, cairoFontOptions );
927 pango_layout_context_changed( layout );
928 cairo_font_options_destroy( cairoFontOptions );
943 cairoTransformMatrix = (cairo_matrix_t *) malloc(
sizeof ( cairo_matrix_t ) );
944 cairo_matrix_init( cairoTransformMatrix, 1.0, 0.0, 0.0, -1.0, 0.0, 0.0 );
945 cairo_transform( aStream->
cairoContext, cairoTransformMatrix );
951 cos_rot = cos( rotation );
952 sin_rot = sin( rotation );
953 cos_shear = cos( shear );
954 sin_shear = sin( shear );
957 cairo_matrix_init( cairoTransformMatrix,
960 cos_rot * sin_shear + sin_rot * cos_shear,
961 -sin_rot * sin_shear + cos_rot * cos_shear,
963 cairo_transform( aStream->
cairoContext, cairoTransformMatrix );
964 free( cairoTransformMatrix );
969 (
double) ( -1.0 * args->
just * (
double) textXExtent ),
970 (
double) 0.5 * fontSize - baseline / 1024.0 );
973 pango_cairo_show_layout( aStream->
cairoContext, layout );
979 g_object_unref( layout );
980 free( textWithPangoMarkup );
999 char *pangoMarkupString;
1000 PLFLT old_sscale, sscale, old_soffset, soffset;
1005 pangoMarkupString = (
char *) malloc(
sizeof (
char ) *
MAX_MARKUP_LEN );
1008 pangoMarkupString[i] = 0;
1020 while ( i < ucs4Len )
1034 strncat( pangoMarkupString,
"&",
MAX_MARKUP_LEN - 1 - strlen( pangoMarkupString ) );
1037 strncat( pangoMarkupString,
"<",
MAX_MARKUP_LEN - 1 - strlen( pangoMarkupString ) );
1040 strncat( pangoMarkupString,
">",
MAX_MARKUP_LEN - 1 - strlen( pangoMarkupString ) );
1044 strncat( pangoMarkupString, utf8,
MAX_MARKUP_LEN - 1 - strlen( pangoMarkupString ) );
1054 strncat( pangoMarkupString, utf8,
MAX_MARKUP_LEN - 1 - strlen( pangoMarkupString ) );
1064 strncat( pangoMarkupString,
"</span>",
MAX_MARKUP_LEN - 1 - strlen( pangoMarkupString ) );
1070 &old_sscale, &sscale, &old_soffset, &soffset );
1071 strncat( pangoMarkupString,
1081 strncat( pangoMarkupString,
"</span>",
MAX_MARKUP_LEN - 1 - strlen( pangoMarkupString ) );
1087 &old_sscale, &sscale, &old_soffset, &soffset );
1088 strncat( pangoMarkupString,
1098 strncat( pangoMarkupString,
"</span>",
MAX_MARKUP_LEN - 1 - strlen( pangoMarkupString ) );
1103 strncat( pangoMarkupString,
1104 "<span underline=\"single\">",
1115 open_span_tag( pangoMarkupString, ucs4[i], fontSize, upDown );
1125 return pangoMarkupString;
1139 unsigned char fontFamily, fontStyle, fontWeight;
1142 PLFLT old_sscale, sscale, old_soffset, soffset;
1152 if ( fontStyle >= 3 )
1154 plwarn(
"cairo: Unknown font style specified, forcing normal\n" );
1157 if ( fontWeight >= 2 )
1159 plwarn(
"cairo: Unknown font weight specified, forcing normal\n" );
1166 strncat( pangoMarkupString, openTag,
MAX_MARKUP_LEN - 1 - strlen( pangoMarkupString ) );
1169 strncat( pangoMarkupString, openTag,
MAX_MARKUP_LEN - 1 - strlen( pangoMarkupString ) );
1172 strncat( pangoMarkupString, openTag,
MAX_MARKUP_LEN - 1 - strlen( pangoMarkupString ) );
1175 for ( upDown_level = 0; upDown_level < upDown; upDown_level++ )
1178 &old_sscale, &sscale, &old_soffset, &soffset );
1179 strncat( pangoMarkupString,
1183 for ( upDown_level = 0; upDown_level > upDown; upDown_level-- )
1186 &old_sscale, &sscale, &old_soffset, &soffset );
1187 strncat( pangoMarkupString,
1203 while ( upDown > 0 )
1205 strncat( pangoMarkupString,
"</span>",
MAX_MARKUP_LEN - 1 - strlen( pangoMarkupString ) );
1211 while ( upDown < 0 )
1213 strncat( pangoMarkupString,
"</span>",
MAX_MARKUP_LEN - 1 - strlen( pangoMarkupString ) );
1218 strncat( pangoMarkupString,
"</span>",
MAX_MARKUP_LEN - 1 - strlen( pangoMarkupString ) );
1226# define RISE_FACTOR 0.8
1239char *
rise_span_tag(
int ifsuperscript,
float fontSize,
float multiplier,
float rise )
1242 static char tag[100];
1249 rise = 1024.f * fontSize * (float)
RISE_FACTOR * rise;
1254 offset = 1024.f * 0.5f * fontSize * ( 1.0f - multiplier );
1256 if ( ifsuperscript )
1258 sprintf( tag,
"<span rise=\"%d\" size=\"%d\">",
1259 (
int) ( rise + offset ), (
int) ( fontSize * 1024. * multiplier ) );
1263 sprintf( tag,
"<span rise=\"%d\" size=\"%d\">",
1264 (
int) -( rise - offset ), (
int) ( fontSize * 1024. * multiplier ) );
1277cairo_status_t
write_to_stream(
void *filePointer,
unsigned char *data,
unsigned int length )
1279 unsigned int bytes_written;
1281 bytes_written = (
unsigned int) fwrite( data, 1, (
size_t) length, (FILE *) filePointer );
1282 if ( bytes_written == length )
1284 return CAIRO_STATUS_SUCCESS;
1288 return CAIRO_STATUS_WRITE_ERROR;
1356 aStream = malloc(
sizeof (
PLCairo ) );
1357#if defined ( PLD_xcairo )
1358 aStream->XDisplay = NULL;
1359 aStream->XWindow = 0;
1440 for ( i = 1; i < npts; i++ )
1469 if ( cairo_get_antialias( aStream->
cairoContext ) != CAIRO_ANTIALIAS_NONE )
1503 cairo_pattern_t *linear_gradient;
1510 linear_gradient = cairo_pattern_create_linear(
1516 cairo_pattern_reference( linear_gradient );
1519 cairo_pattern_add_color_stop_rgba( linear_gradient,
1520 (
double) i / (
double) (
pls->
ncol1 - 1 ),
1530 cairo_set_source( aStream->
cairoContext, linear_gradient );
1532 cairo_pattern_destroy( linear_gradient );
1545 PLINT rcx[4], rcy[4];
1596 plwarn(
"All pages after the first skipped because family file output not specified.\n" );
1612 double angle1, angle2, rotate;
1639 cairo_arc( aStream->
cairoContext, 0.0, 0.0, 1.0, angle1, angle2 );
1640 if ( arc_info->
fill )
1649 if ( arc_info->
fill )
1668 cairo_matrix_t *matrix;
1673 matrix = (cairo_matrix_t *) malloc(
sizeof ( cairo_matrix_t ) );
1674 cairo_matrix_init( matrix, x11, x12, x21, x22, x0, y0 );
1675#if defined ( PLD_xcairo )
1678 cairo_transform( aStream->cairoContext_X, matrix );
1697#if defined ( PLD_pngcairo ) || defined ( PLD_svgcairo ) || defined ( PLD_epscairo )
1699void plD_bop_cairo_fam(
PLStream * );
1700void plD_eop_cairo_fam(
PLStream * );
1703void plD_tidy_cairo_fam(
PLStream * );
1704void plD_line_cairo_fam(
PLStream *,
short,
short,
short,
short );
1705void plD_polyline_cairo_fam(
PLStream *,
short *,
short *,
PLINT );
1807void plD_line_cairo_fam(
PLStream *
pls,
short x1a,
short y1a,
short x2a,
short y2a )
1823void plD_polyline_cairo_fam(
PLStream *
pls,
short *xa,
short *ya,
PLINT npts )
1842#if defined ( PLD_xcairo )
1845static Window rootWindow;
1864#ifndef ENABLE_DYNDRIVERS
1893static signed int xcairo_init_cairo(
PLStream *
pls )
1896 Visual *defaultVisual;
1901 defaultVisual = DefaultVisual( aStream->XDisplay, 0 );
1905 aStream->cairoSurface_X = cairo_xlib_surface_create(
1912 aStream->cairoContext_X = cairo_create( aStream->cairoSurface_X );
1918 aStream->cairoSurface_X,
1919 CAIRO_CONTENT_COLOR_ALPHA,
1929 cairo_image_surface_create(
1930 CAIRO_FORMAT_ARGB32,
1944 cairo_set_fill_rule( aStream->
cairoContext, CAIRO_FILL_RULE_EVEN_ODD );
1946 cairo_set_fill_rule( aStream->
cairoContext, CAIRO_FILL_RULE_WINDING );
1951 cairo_set_source_rgba( aStream->cairoContext_X,
1956 cairo_fill( aStream->cairoContext_X );
1958 XFlush( aStream->XDisplay );
1983 aStream->xdrawable_mode = 1;
1988 aStream->XDisplay = NULL;
1990 aStream->XDisplay = XOpenDisplay(
pls->
FileName );
1992 aStream->XDisplay = XOpenDisplay( NULL );
1993 if ( aStream->XDisplay == NULL )
1995 plexit(
"Failed to open X Windows display\n" );
1998 XScreen = DefaultScreen( aStream->XDisplay );
1999 rootWindow = RootWindow( aStream->XDisplay, XScreen );
2001 aStream->XWindow = XCreateSimpleWindow(
2007 BlackPixel( aStream->XDisplay, XScreen ),
2008 BlackPixel( aStream->XDisplay, XScreen ) );
2010 XStoreName( aStream->XDisplay, aStream->XWindow,
pls->
plwindow );
2011 XSelectInput( aStream->XDisplay, aStream->XWindow, NoEventMask );
2012 XMapWindow( aStream->XDisplay, aStream->XWindow );
2013 aStream->xdrawable_mode = 0;
2015 wmDelete = XInternAtom( aStream->XDisplay,
"WM_DELETE_WINDOW", True );
2016 XSetWMProtocols( aStream->XDisplay, aStream->XWindow, &wmDelete, 1 );
2018 xcairo_init_cairo(
pls );
2021 aStream->exit_event_loop = 0;
2041 cairo_set_operator( aStream->
cairoContext, CAIRO_OPERATOR_DEST_OVER );
2050 cairo_save( aStream->cairoContext_X );
2052 cairo_rectangle( aStream->cairoContext_X, x, y, w, h );
2053 cairo_set_operator( aStream->cairoContext_X, CAIRO_OPERATOR_SOURCE );
2054 cairo_set_source_surface( aStream->cairoContext_X,
2056 cairo_fill( aStream->cairoContext_X );
2057 cairo_restore( aStream->cairoContext_X );
2074 if ( aStream->xdrawable_mode )
2077 XFlush( aStream->XDisplay );
2111 cairo_destroy( aStream->cairoContext_X );
2112 cairo_surface_destroy( aStream->cairoSurface_X );
2114 if ( aStream->xdrawable_mode )
2118 XFlush( aStream->XDisplay );
2120 XDestroyWindow( aStream->XDisplay, aStream->XWindow );
2122 XCloseDisplay( aStream->XDisplay );
2135 char event_string[10];
2140 XExposeEvent *expose;
2144 if ( aStream->xdrawable_mode )
2147 aStream->exit_event_loop = 0;
2150 event_mask = ButtonPressMask | KeyPressMask | ExposureMask;
2151 XSelectInput( aStream->XDisplay, aStream->XWindow, event_mask );
2152 while ( !aStream->exit_event_loop )
2155 XNextEvent( aStream->XDisplay, &event );
2156 switch ( event.type )
2159 number_chars = XLookupString( (XKeyEvent *) &event, event_string, 10, &keysym, &cs );
2160 event_string[number_chars] =
'\0';
2161 if ( keysym == XK_Return )
2163 aStream->exit_event_loop = 1;
2167 if ( ( (XButtonEvent *) &event )->button == Button3 )
2168 aStream->exit_event_loop = 1;
2173 aStream->exit_event_loop = 1;
2178 expose = (XExposeEvent *) &event;
2179 if ( expose->count == 0 )
2182 expose->
width, expose->height );
2187 aStream->exit_event_loop = 0;
2206 XFlush( aStream->XDisplay );
2210 XFlush( aStream->XDisplay );
2215 PLXcairoDrawableInfo *xinfo = (PLXcairoDrawableInfo *) ptr;
2217 unsigned int w, h, b, d;
2218 if ( xinfo == NULL )
2220 printf(
"xcairo: PLESC_DEVINIT ignored, no drawable info provided\n" );
2223 if ( aStream->xdrawable_mode == 0 )
2225 printf(
"xcairo: PLESC_DEVINIT called with drawable but stream not in xdrawable mode\n" );
2228 aStream->XDisplay = xinfo->display;
2229 aStream->XWindow = xinfo->drawable;
2232 XGetGeometry( aStream->XDisplay, aStream->XWindow, &rootwin,
2233 &x, &y, &w, &h, &b, &d );
2246 xcairo_init_cairo(
pls );
2271 XButtonEvent *xButtonEvent;
2281 xHairCursor = XCreateFontCursor( aStream->XDisplay, XC_crosshair );
2282 XDefineCursor( aStream->XDisplay, aStream->XWindow, xHairCursor );
2285 XSelectInput( aStream->XDisplay, aStream->XWindow, ButtonPressMask | ButtonReleaseMask | KeyPressMask | KeyReleaseMask | ButtonMotionMask );
2286 XMaskEvent( aStream->XDisplay, ButtonPressMask | ButtonReleaseMask | KeyPressMask | KeyReleaseMask | ButtonMotionMask, &event );
2287 XSelectInput( aStream->XDisplay, aStream->XWindow, NoEventMask );
2290 xButtonEvent = (XButtonEvent *) &event;
2291 gin->
state = xButtonEvent->state;
2292 gin->
button = xButtonEvent->button;
2293 gin->
pX =
event.xbutton.x;
2299 if ( event.type == KeyPress || event.type == KeyRelease )
2301 XLookupString( (XKeyEvent *) &event, str, 100, &keysym, NULL );
2302 if ( keysym == NoSymbol )
2303 ksname =
"NoSymbol";
2304 else if ( !( ksname = XKeysymToString( keysym ) ) )
2305 ksname =
"(no name)";
2306 strcpy( gin->
string, ksname );
2316 gin->
keysym = 0xFF & keysym;
2319 gin->
keysym = (
unsigned int) keysym;
2329 XUndefineCursor( aStream->XDisplay, aStream->XWindow );
2330 XFlush( aStream->XDisplay );
2344#if defined ( PLD_pdfcairo )
2347void plD_init_pdfcairo(
PLStream * );
2358#ifndef ENABLE_DYNDRIVERS
2406 cairo_set_fill_rule( aStream->
cairoContext, CAIRO_FILL_RULE_EVEN_ODD );
2408 cairo_set_fill_rule( aStream->
cairoContext, CAIRO_FILL_RULE_WINDING );
2422#if defined ( PLD_pscairo )
2425void plD_init_pscairo(
PLStream * );
2436#ifndef ENABLE_DYNDRIVERS
2486 cairo_set_fill_rule( aStream->
cairoContext, CAIRO_FILL_RULE_EVEN_ODD );
2488 cairo_set_fill_rule( aStream->
cairoContext, CAIRO_FILL_RULE_WINDING );
2502#if defined ( PLD_epscairo )
2505void plD_init_epscairo(
PLStream * );
2516#ifndef ENABLE_DYNDRIVERS
2590 cairo_set_fill_rule( aStream->
cairoContext, CAIRO_FILL_RULE_EVEN_ODD );
2592 cairo_set_fill_rule( aStream->
cairoContext, CAIRO_FILL_RULE_WINDING );
2606#if defined ( PLD_svgcairo )
2609void plD_init_svgcairo(
PLStream * );
2620#ifndef ENABLE_DYNDRIVERS
2689 cairo_set_fill_rule( aStream->
cairoContext, CAIRO_FILL_RULE_EVEN_ODD );
2691 cairo_set_fill_rule( aStream->
cairoContext, CAIRO_FILL_RULE_WINDING );
2705#if defined ( PLD_pngcairo )
2708void plD_init_pngcairo(
PLStream * );
2709void plD_eop_pngcairo(
PLStream * );
2720#ifndef ENABLE_DYNDRIVERS
2789 cairo_set_fill_rule( aStream->
cairoContext, CAIRO_FILL_RULE_EVEN_ODD );
2791 cairo_set_fill_rule( aStream->
cairoContext, CAIRO_FILL_RULE_WINDING );
2824#if defined ( PLD_memcairo )
2827void plD_init_memcairo(
PLStream * );
2828void plD_eop_memcairo(
PLStream * );
2829void plD_bop_memcairo(
PLStream * );
2840#ifndef ENABLE_DYNDRIVERS
2877 unsigned char *cairo_mem;
2878 unsigned char *input_mem;
2884 char testByte[
sizeof ( int )];
2886 endianTest.testWord = 1;
2898 if ( endianTest.testByte[0] == 1 )
2899 aStream->bigendian = 0;
2901 aStream->bigendian = 1;
2906 plexit(
"Must call plsmem first to set user plotting area!" );
2910 aStream->memory =
pls->
dev;
2920 aStream->cairo_format_memory = (
unsigned char *) calloc( (
size_t) ( stride *
pls->
ylength ), 1 );
2923 cairo_mem = aStream->cairo_format_memory;
2924 input_mem = aStream->memory;
2930 if ( aStream->bigendian )
2934 cairo_mem[1] = input_mem[0];
2935 cairo_mem[2] = input_mem[1];
2936 cairo_mem[3] = input_mem[2];
2939 cairo_mem[0] = input_mem[3];
2953 cairo_mem[2] = input_mem[0];
2954 cairo_mem[1] = input_mem[1];
2955 cairo_mem[0] = input_mem[2];
2958 cairo_mem[3] = input_mem[3];
2973 cairo_image_surface_create_for_data( aStream->cairo_format_memory, CAIRO_FORMAT_RGB24,
pls->
xlength,
pls->
ylength, stride );
2988 cairo_set_fill_rule( aStream->
cairoContext, CAIRO_FILL_RULE_EVEN_ODD );
2990 cairo_set_fill_rule( aStream->
cairoContext, CAIRO_FILL_RULE_WINDING );
3003 unsigned char *memory;
3004 unsigned char *cairo_surface_data;
3008 memory = aStream->memory;
3009 cairo_surface_data = cairo_image_surface_get_data( aStream->
cairoSurface );
3013 if ( aStream->bigendian )
3017 memory[0] = cairo_surface_data[1];
3018 memory[1] = cairo_surface_data[2];
3019 memory[2] = cairo_surface_data[3];
3022 memory[3] = cairo_surface_data[0];
3029 cairo_surface_data += 4;
3036 memory[0] = cairo_surface_data[2];
3037 memory[1] = cairo_surface_data[1];
3038 memory[2] = cairo_surface_data[0];
3041 memory[3] = cairo_surface_data[3];
3048 cairo_surface_data += 4;
3053 free( aStream->cairo_format_memory );
3066#if defined ( PLD_extcairo )
3068void extcairo_setbackground(
PLStream * );
3070void plD_init_extcairo(
PLStream * );
3071void plD_bop_extcairo(
PLStream * );
3072void plD_eop_extcairo(
PLStream * );
3074void plD_tidy_extcairo(
PLStream * );
3110#ifndef ENABLE_DYNDRIVERS
3111 pdt->
pl_MenuStr =
"Cairo external context driver";
3158 extcairo_setbackground(
pls );
3203 extcairo_setbackground(
pls );
3208 cairo_set_fill_rule( aStream->
cairoContext, CAIRO_FILL_RULE_EVEN_ODD );
3210 cairo_set_fill_rule( aStream->
cairoContext, CAIRO_FILL_RULE_WINDING );
3243#if defined ( PLD_wincairo )
3245static char* szWndClass =
"PLplot WinCairo";
3248void plD_init_wincairo(
PLStream * );
3250void plD_eop_wincairo(
PLStream * );
3251void plD_wait_wincairo(
PLStream * );
3253void plD_tidy_wincairo(
PLStream * );
3261void blit_to_win(
PLCairo *aStream )
3263 cairo_set_source_surface( aStream->cairoContext_win, aStream->
cairoSurface, 0.0, 0.0 );
3264 cairo_paint( aStream->cairoContext_win );
3273LRESULT CALLBACK PlplotCairoWndProc( HWND hwnd, UINT nMsg, WPARAM wParam, LPARAM lParam )
3288 if ( nMsg == WM_CREATE )
3294 pls = (
PLStream *) GetWindowLongPtr( hwnd, GWLP_USERDATA );
3316 PostQuitMessage( 0 );
3326 GetClientRect( dev->hwnd, &dev->rect );
3330 case WM_ENTERSIZEMOVE:
3334 case WM_EXITSIZEMOVE:
3342 ExtTextOut( dev->hdc, 0, 0, ETO_OPAQUE, &dev->rect,
"", 0, 0 );
3343 SetBkColor( dev->hdc, dev->oldcolour );
3355 return DefWindowProc( hwnd, nMsg, wParam, lParam );
3373 while ( GetMessage( &aStream->msg, NULL, 0, 0 ) && !located )
3375 TranslateMessage( &aStream->msg );
3377 switch ( (
int) aStream->msg.message )
3380 case WM_LBUTTONDOWN:
3383 gin->
pX = LOWORD( aStream->msg.lParam );
3384 gin->
pY =
pls->
ylength - HIWORD( aStream->msg.lParam );
3389 gin->
keysym = aStream->msg.wParam;
3394 DispatchMessage( &aStream->msg );
3409#ifndef ENABLE_DYNDRIVERS
3410 pdt->
pl_MenuStr =
"Cairo Microsoft Windows driver";
3443 memset( &aStream->wndclass, 0, sizeof ( WNDCLASSEX ) );
3446 aStream->wndclass.lpszClassName = szWndClass;
3449 aStream->wndclass.cbSize =
sizeof ( WNDCLASSEX );
3452 aStream->wndclass.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS | CS_OWNDC | CS_PARENTDC;
3455 aStream->wndclass.lpfnWndProc = PlplotCairoWndProc;
3459 aStream->wndclass.hInstance = GetModuleHandle( NULL );
3462 aStream->wndclass.hIcon = LoadIcon( NULL, IDI_APPLICATION );
3463 aStream->wndclass.hIconSm = LoadIcon( NULL, IDI_APPLICATION );
3464 aStream->wndclass.hCursor = LoadCursor( NULL, IDC_ARROW );
3466 aStream->wndclass.hbrBackground = NULL;
3468 aStream->wndclass.cbWndExtra =
sizeof (
pls );
3475 RegisterClassEx( &aStream->wndclass );
3480 aStream->hwnd = CreateWindowEx( WS_EX_WINDOWEDGE + WS_EX_LEFT,
3483 WS_OVERLAPPEDWINDOW,
3491 aStream->wndclass.hInstance,
3502 SetWindowLongPtr( aStream->hwnd, GWLP_USERDATA, (LONG_PTR)
pls );
3503 aStream->SCRN_hdc = aStream->hdc = GetDC( aStream->hwnd );
3522 ShowWindow( aStream->hwnd, SW_SHOWDEFAULT );
3523 SetForegroundWindow( aStream->hwnd );
3543 aStream->cairoSurface_win = (cairo_surface_t *) cairo_win32_surface_create( aStream->hdc );
3544 aStream->cairoContext_win = cairo_create( aStream->cairoSurface_win );
3558 cairo_set_fill_rule( aStream->
cairoContext, CAIRO_FILL_RULE_EVEN_ODD );
3560 cairo_set_fill_rule( aStream->
cairoContext, CAIRO_FILL_RULE_WINDING );
3586 while ( GetMessage( &aStream->msg, NULL, 0, 0 ) )
3588 TranslateMessage( &aStream->msg );
3589 switch ( (
int) aStream->msg.message )
3592 if ( ( (TCHAR) ( aStream->msg.wParam ) == 13 ) ||
3593 ( (TCHAR) ( aStream->msg.wParam ) ==
'q' ) ||
3594 ( (TCHAR) ( aStream->msg.wParam ) ==
'Q' ) )
3596 PostQuitMessage( 0 );
3601 DispatchMessage( &aStream->msg );
3620 cairo_destroy( aStream->cairoContext_win );
3621 cairo_surface_destroy( aStream->cairoSurface_win );
3623 if ( aStream != NULL )
3625 if ( aStream->hdc != NULL )
3626 ReleaseDC( aStream->hwnd, aStream->hdc );
3646 InvalidateRect( aStream->hwnd, NULL,
TRUE );
const char * envFamilyLookup[NPANGOLOOKUP]
static void proc_str(PLStream *, EscText *)
void set_line_properties(PLCairo *aStream, cairo_line_join_t join, cairo_line_cap_t cap)
static void close_span_tag(char *, int)
static DrvOpt cairo_options[]
void set_clip(PLStream *pls)
void plD_state_cairo(PLStream *, PLINT)
static void text_esc_cairo(PLStream *pls, EscText *args)
static int graphics_anti_aliasing
static void gradient(PLStream *pls, short *xa, short *ya, PLINT npts)
static void poly_line(PLStream *, short *, short *, PLINT)
PLDLLIMPEXP_DRIVER const char * plD_DEVICE_INFO_cairo
static void end_raster(PLStream *)
void plD_tidy_cairo(PLStream *)
static void set_mode(PLStream *, PLINT *)
#define PLCAIRO_DEFAULT_Y
static void rotate_cairo_surface(PLStream *, float, float, float, float, float, float, PLBOOL)
static int text_anti_aliasing
void get_line_properties(PLCairo *aStream, cairo_line_join_t *join, cairo_line_cap_t *cap)
const char * defaultFamilyLookup[NPANGOLOOKUP]
static void set_current_context(PLStream *)
static void open_span_tag(char *, PLUNICODE, float, int)
const char * styleLookup[3]
const char * weightLookup[2]
static void start_raster(PLStream *)
static int already_warned
static int external_drawable
static void get_mode(PLStream *, PLINT *)
void plD_line_cairo(PLStream *, short, short, short, short)
static void text_begin_cairo(PLStream *pls, EscText *args)
static int set_background
#define PLCAIRO_DEFAULT_X
static void text_end_cairo(PLStream *pls, EscText *args)
#define FAMILY_LOOKUP_LEN
void plD_esc_cairo(PLStream *, PLINT, void *)
static char * rise_span_tag(int, float, float, float)
static int image_buffering
static void blit_to_x(PLStream *pls, double x, double y, double w, double h)
char familyLookup[NPANGOLOOKUP][FAMILY_LOOKUP_LEN]
static int rasterize_image
static char * ucs4_to_pango_markup_format(PLUNICODE *, int, float)
PLCairo * stream_and_font_setup(PLStream *, int)
cairo_status_t write_to_stream(void *, unsigned char *, unsigned int)
void plD_polyline_cairo(PLStream *, short *, short *, PLINT)
static void text_char_cairo(PLStream *pls, EscText *args)
static void arc(PLStream *, arc_struct *)
void plD_bop_cairo(PLStream *)
int cairo_family_check(PLStream *pls)
static void filled_polygon(PLStream *pls, short *xa, short *ya, PLINT npts)
void plD_eop_cairo(PLStream *)
void(* plD_line_fp)(struct PLStream_struct *, short, short, short, short)
void(* plD_tidy_fp)(struct PLStream_struct *)
void(* plD_bop_fp)(struct PLStream_struct *)
void(* plD_wait_fp)(struct PLStream_struct *)
void(* plD_state_fp)(struct PLStream_struct *, PLINT)
void(* plD_eop_fp)(struct PLStream_struct *)
void(* plD_init_fp)(struct PLStream_struct *)
void(* plD_esc_fp)(struct PLStream_struct *, PLINT, void *)
void(* plD_polyline_fp)(struct PLStream_struct *, short *, short *, PLINT)
PLDLLIMPEXP_DRIVER void plD_dispatch_init_xcairo(PLDispatchTable *pdt)
PLDLLIMPEXP_DRIVER void plD_dispatch_init_svgcairo(PLDispatchTable *pdt)
PLDLLIMPEXP_DRIVER void plD_dispatch_init_wincairo(PLDispatchTable *pdt)
PLDLLIMPEXP_DRIVER void plD_dispatch_init_memcairo(PLDispatchTable *pdt)
PLDLLIMPEXP_DRIVER void plD_dispatch_init_epscairo(PLDispatchTable *pdt)
PLDLLIMPEXP_DRIVER void plD_dispatch_init_extcairo(PLDispatchTable *pdt)
PLDLLIMPEXP_DRIVER void plD_dispatch_init_pdfcairo(PLDispatchTable *pdt)
PLDLLIMPEXP_DRIVER void plD_dispatch_init_pscairo(PLDispatchTable *pdt)
PLDLLIMPEXP_DRIVER void plD_dispatch_init_pngcairo(PLDispatchTable *pdt)
int plParseDrvOpts(DrvOpt *acc_opt)
void plP_fci2hex(PLUNICODE fci, unsigned char *phexdigit, unsigned char hexpower)
void difilt_clip(PLINT *x_coords, PLINT *y_coords)
void plP_setpxl(PLFLT xpmm, PLFLT ypmm)
int ucs4_to_utf8(PLUNICODE unichar, char *ptr)
void plP_setphy(PLINT xmin, PLINT xmax, PLINT ymin, PLINT ymax)
static PLStream * pls[PL_NSTREAMS]
void plFamInit(PLStream *pls)
void plwarn(PLCHAR_VECTOR errormsg)
void plCloseFile(PLStream *pls)
void plGinInit(PLGraphicsIn *gin)
void plOpenFile(PLStream *pls)
void plexit(PLCHAR_VECTOR errormsg)
void plGetFam(PLStream *pls)
#define PLDLLIMPEXP_DRIVER
void plRotationShear(PLFLT *xFormMatrix, PLFLT *rotation, PLFLT *shear, PLFLT *stride)
#define PLESC_CONTROL_CHAR
#define PLTEXT_SUPERSCRIPT
#define PLESC_START_RASTERIZE
#define PLTEXT_FONTCHANGE
#define PLESC_END_RASTERIZE
void plP_script_scale(PLBOOL ifupper, PLINT *level, PLFLT *old_scale, PLFLT *scale, PLFLT *old_offset, PLFLT *offset)
unsigned short unicode_array_len
PLUNICODE * unicode_array
cairo_surface_t * cairoSurface
cairo_surface_t * cairoSurface_raster
short graphics_anti_aliasing
cairo_t * cairoContext_raster
plD_polyline_fp pl_polyline
static const char * display