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>
52 #include <X11/Xutil.h>
53 #include <X11/cursorfont.h>
54 #include <X11/keysym.h>
56 #if defined ( PLD_pdfcairo )
57 #include <cairo-pdf.h>
59 #if defined ( PLD_pscairo )
62 #if defined ( PLD_svgcairo )
63 #include <cairo-svg.h>
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
245 cairo_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" );
398 if ( (
double) pls->
cmap0[0].
a < 1.0 )
400 cairo_set_source_rgba( aStream->
cairoContext, 1.0, 1.0, 1.0, 1.0 );
404 (
double) pls->
cmap0[0].
r / 255.0,
405 (
double) pls->
cmap0[0].
g / 255.0,
406 (
double) pls->
cmap0[0].
b / 255.0,
407 (
double) pls->
cmap0[0].
a );
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 );
904 fontSize = (float) ( pls->
chrht *
DPI / 25.4 );
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 )
1023 if ( strlen( pangoMarkupString ) > ( MAX_MARKUP_LEN - 50 ) )
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,
1073 MAX_MARKUP_LEN - 1 - strlen( pangoMarkupString ) );
1081 strncat( pangoMarkupString,
"</span>", MAX_MARKUP_LEN - 1 - strlen( pangoMarkupString ) );
1087 &old_sscale, &sscale, &old_soffset, &soffset );
1088 strncat( pangoMarkupString,
1090 MAX_MARKUP_LEN - 1 - strlen( pangoMarkupString ) );
1098 strncat( pangoMarkupString,
"</span>", MAX_MARKUP_LEN - 1 - strlen( pangoMarkupString ) );
1103 strncat( pangoMarkupString,
1104 "<span underline=\"single\">",
1105 MAX_MARKUP_LEN - 1 - strlen( pangoMarkupString ) );
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
1239 char *
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 ) );
1277 cairo_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;
1310 pls->
termin = interactive;
1356 aStream = malloc(
sizeof (
PLCairo ) );
1357 #if defined ( PLD_xcairo )
1358 aStream->XDisplay = NULL;
1359 aStream->XWindow = 0;
1412 if ( pls->
width <= 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 );
1517 for ( i = 0; i < pls->
ncol1; i++ )
1519 cairo_pattern_add_color_stop_rgba( linear_gradient,
1520 (
double) i / (
double) ( pls->
ncol1 - 1 ),
1521 (
double) pls->
cmap1[i].
r / 255.,
1522 (
double) pls->
cmap1[i].
g / 255.,
1523 (
double) pls->
cmap1[i].
b / 255.,
1524 (
double) pls->
cmap1[i].
a );
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 )
1699 void plD_bop_cairo_fam(
PLStream * );
1700 void plD_eop_cairo_fam(
PLStream * );
1703 void plD_tidy_cairo_fam(
PLStream * );
1704 void plD_line_cairo_fam(
PLStream *,
short,
short,
short,
short );
1705 void plD_polyline_cairo_fam(
PLStream *,
short *,
short *,
PLINT );
1735 (
double) pls->
cmap0[0].
r / 255.0,
1736 (
double) pls->
cmap0[0].
g / 255.0,
1737 (
double) pls->
cmap0[0].
b / 255.0,
1738 (
double) pls->
cmap0[0].
a );
1748 void plD_eop_cairo_fam(
PLStream *pls )
1780 void plD_esc_cairo_fam(
PLStream *pls,
PLINT op,
void *ptr )
1796 void plD_tidy_cairo_fam(
PLStream *pls )
1807 void plD_line_cairo_fam(
PLStream *pls,
short x1a,
short y1a,
short x2a,
short y2a )
1823 void plD_polyline_cairo_fam(
PLStream *pls,
short *xa,
short *ya,
PLINT npts )
1842 #if defined ( PLD_xcairo )
1845 static Window rootWindow;
1848 void plD_init_xcairo(
PLStream * );
1851 void plD_tidy_xcairo(
PLStream * );
1863 #ifndef ENABLE_DYNDRIVERS
1891 static signed int xcairo_init_cairo(
PLStream *pls )
1894 Visual *defaultVisual;
1899 defaultVisual = DefaultVisual( aStream->XDisplay, 0 );
1903 aStream->cairoSurface_X = cairo_xlib_surface_create(
1910 aStream->cairoContext_X = cairo_create( aStream->cairoSurface_X );
1916 aStream->cairoSurface_X,
1917 CAIRO_CONTENT_COLOR_ALPHA,
1927 cairo_image_surface_create(
1928 CAIRO_FORMAT_ARGB32,
1942 cairo_set_fill_rule( aStream->
cairoContext, CAIRO_FILL_RULE_EVEN_ODD );
1944 cairo_set_fill_rule( aStream->
cairoContext, CAIRO_FILL_RULE_WINDING );
1948 cairo_rectangle( aStream->cairoContext_X, 0.0, 0.0, pls->
xlength, pls->
ylength );
1949 cairo_set_source_rgba( aStream->cairoContext_X,
1950 (
double) pls->
cmap0[0].
r / 255.0,
1951 (
double) pls->
cmap0[0].
g / 255.0,
1952 (
double) pls->
cmap0[0].
b / 255.0,
1953 (
double) pls->
cmap0[0].
a );
1954 cairo_fill( aStream->cairoContext_X );
1956 XFlush( aStream->XDisplay );
1967 void plD_init_xcairo(
PLStream *pls )
1981 aStream->xdrawable_mode = 1;
1986 aStream->XDisplay = NULL;
1988 aStream->XDisplay = XOpenDisplay( pls->
FileName );
1990 aStream->XDisplay = XOpenDisplay( NULL );
1991 if ( aStream->XDisplay == NULL )
1993 plexit(
"Failed to open X Windows display\n" );
1996 XScreen = DefaultScreen( aStream->XDisplay );
1997 rootWindow = RootWindow( aStream->XDisplay, XScreen );
1999 aStream->XWindow = XCreateSimpleWindow(
2005 BlackPixel( aStream->XDisplay, XScreen ),
2006 BlackPixel( aStream->XDisplay, XScreen ) );
2008 XStoreName( aStream->XDisplay, aStream->XWindow, pls->
plwindow );
2009 XSelectInput( aStream->XDisplay, aStream->XWindow, NoEventMask );
2010 XMapWindow( aStream->XDisplay, aStream->XWindow );
2011 aStream->xdrawable_mode = 0;
2013 wmDelete = XInternAtom( aStream->XDisplay,
"WM_DELETE_WINDOW", True );
2014 XSetWMProtocols( aStream->XDisplay, aStream->XWindow, &wmDelete, 1 );
2016 xcairo_init_cairo( pls );
2019 aStream->exit_event_loop = 0;
2039 cairo_set_operator( aStream->
cairoContext, CAIRO_OPERATOR_DEST_OVER );
2041 (
double) pls->
cmap0[0].
r / 255.0,
2042 (
double) pls->
cmap0[0].
g / 255.0,
2043 (
double) pls->
cmap0[0].
b / 255.0,
2044 (
double) pls->
cmap0[0].
a );
2048 cairo_save( aStream->cairoContext_X );
2050 cairo_rectangle( aStream->cairoContext_X, x, y, w, h );
2051 cairo_set_operator( aStream->cairoContext_X, CAIRO_OPERATOR_SOURCE );
2052 cairo_set_source_surface( aStream->cairoContext_X,
2054 cairo_fill( aStream->cairoContext_X );
2055 cairo_restore( aStream->cairoContext_X );
2064 void plD_bop_xcairo(
PLStream *pls )
2072 if ( aStream->xdrawable_mode )
2075 XFlush( aStream->XDisplay );
2084 void plD_eop_xcairo(
PLStream *pls )
2088 char event_string[10];
2092 XExposeEvent *expose;
2100 if ( aStream->xdrawable_mode )
2105 aStream->exit_event_loop = 1;
2108 event_mask = ButtonPressMask | KeyPressMask | ExposureMask;
2109 XSelectInput( aStream->XDisplay, aStream->XWindow, event_mask );
2110 while ( !aStream->exit_event_loop )
2113 XNextEvent( aStream->XDisplay, &event );
2114 switch ( event.type )
2117 number_chars = XLookupString( (XKeyEvent *) &event, event_string, 10, &keysym, &cs );
2118 event_string[number_chars] =
'\0';
2119 if ( keysym == XK_Return )
2121 aStream->exit_event_loop = 1;
2125 if ( ( (XButtonEvent *) &event )->button == Button3 )
2126 aStream->exit_event_loop = 1;
2131 aStream->exit_event_loop = 1;
2136 expose = (XExposeEvent *) &event;
2137 if ( expose->count == 0 )
2140 expose->
width, expose->height );
2145 aStream->exit_event_loop = 0;
2154 void plD_tidy_xcairo(
PLStream *pls )
2163 cairo_destroy( aStream->cairoContext_X );
2164 cairo_surface_destroy( aStream->cairoSurface_X );
2166 if ( aStream->xdrawable_mode )
2170 XFlush( aStream->XDisplay );
2172 XDestroyWindow( aStream->XDisplay, aStream->XWindow );
2174 XCloseDisplay( aStream->XDisplay );
2193 XFlush( aStream->XDisplay );
2197 XFlush( aStream->XDisplay );
2202 PLXcairoDrawableInfo *xinfo = (PLXcairoDrawableInfo *) ptr;
2204 unsigned int w, h, b, d;
2205 if ( xinfo == NULL )
2207 printf(
"xcairo: PLESC_DEVINIT ignored, no drawable info provided\n" );
2210 if ( aStream->xdrawable_mode == 0 )
2212 printf(
"xcairo: PLESC_DEVINIT called with drawable but stream not in xdrawable mode\n" );
2215 aStream->XDisplay = xinfo->display;
2216 aStream->XWindow = xinfo->drawable;
2219 XGetGeometry( aStream->XDisplay, aStream->XWindow, &rootwin,
2220 &x, &y, &w, &h, &b, &d );
2233 xcairo_init_cairo( pls );
2258 XButtonEvent *xButtonEvent;
2268 xHairCursor = XCreateFontCursor( aStream->XDisplay, XC_crosshair );
2269 XDefineCursor( aStream->XDisplay, aStream->XWindow, xHairCursor );
2272 XSelectInput( aStream->XDisplay, aStream->XWindow, ButtonPressMask | ButtonReleaseMask | KeyPressMask | KeyReleaseMask | ButtonMotionMask );
2273 XMaskEvent( aStream->XDisplay, ButtonPressMask | ButtonReleaseMask | KeyPressMask | KeyReleaseMask | ButtonMotionMask, &event );
2274 XSelectInput( aStream->XDisplay, aStream->XWindow, NoEventMask );
2277 xButtonEvent = (XButtonEvent *) &event;
2278 gin->
state = xButtonEvent->state;
2279 gin->
button = xButtonEvent->button;
2280 gin->
pX =
event.xbutton.x;
2281 gin->
pY = pls->
ylength -
event.xbutton.y;
2286 if ( event.type == KeyPress || event.type == KeyRelease )
2288 XLookupString( (XKeyEvent *) &event, str, 100, &keysym, NULL );
2289 if ( keysym == NoSymbol )
2290 ksname =
"NoSymbol";
2291 else if ( !( ksname = XKeysymToString( keysym ) ) )
2292 ksname =
"(no name)";
2293 strcpy( gin->
string, ksname );
2303 gin->
keysym = 0xFF & keysym;
2306 gin->
keysym = (
unsigned int) keysym;
2316 XUndefineCursor( aStream->XDisplay, aStream->XWindow );
2317 XFlush( aStream->XDisplay );
2331 #if defined ( PLD_pdfcairo )
2334 void plD_init_pdfcairo(
PLStream * );
2345 #ifndef ENABLE_DYNDRIVERS
2367 void plD_init_pdfcairo(
PLStream *pls )
2393 cairo_set_fill_rule( aStream->
cairoContext, CAIRO_FILL_RULE_EVEN_ODD );
2395 cairo_set_fill_rule( aStream->
cairoContext, CAIRO_FILL_RULE_WINDING );
2409 #if defined ( PLD_pscairo )
2412 void plD_init_pscairo(
PLStream * );
2423 #ifndef ENABLE_DYNDRIVERS
2445 void plD_init_pscairo(
PLStream *pls )
2473 cairo_set_fill_rule( aStream->
cairoContext, CAIRO_FILL_RULE_EVEN_ODD );
2475 cairo_set_fill_rule( aStream->
cairoContext, CAIRO_FILL_RULE_WINDING );
2489 #if defined ( PLD_epscairo )
2492 void plD_init_epscairo(
PLStream * );
2503 #ifndef ENABLE_DYNDRIVERS
2525 void plD_init_epscairo(
PLStream *pls )
2540 if ( pls->
dev == NULL )
2577 cairo_set_fill_rule( aStream->
cairoContext, CAIRO_FILL_RULE_EVEN_ODD );
2579 cairo_set_fill_rule( aStream->
cairoContext, CAIRO_FILL_RULE_WINDING );
2593 #if defined ( PLD_svgcairo )
2596 void plD_init_svgcairo(
PLStream * );
2607 #ifndef ENABLE_DYNDRIVERS
2629 void plD_init_svgcairo(
PLStream *pls )
2644 if ( pls->
dev == NULL )
2676 cairo_set_fill_rule( aStream->
cairoContext, CAIRO_FILL_RULE_EVEN_ODD );
2678 cairo_set_fill_rule( aStream->
cairoContext, CAIRO_FILL_RULE_WINDING );
2692 #if defined ( PLD_pngcairo )
2695 void plD_init_pngcairo(
PLStream * );
2696 void plD_eop_pngcairo(
PLStream * );
2707 #ifndef ENABLE_DYNDRIVERS
2729 void plD_init_pngcairo(
PLStream *pls )
2744 if ( pls->
dev == NULL )
2776 cairo_set_fill_rule( aStream->
cairoContext, CAIRO_FILL_RULE_EVEN_ODD );
2778 cairo_set_fill_rule( aStream->
cairoContext, CAIRO_FILL_RULE_WINDING );
2787 void plD_eop_pngcairo(
PLStream *pls )
2811 #if defined ( PLD_memcairo )
2814 void plD_init_memcairo(
PLStream * );
2815 void plD_eop_memcairo(
PLStream * );
2816 void plD_bop_memcairo(
PLStream * );
2827 #ifndef ENABLE_DYNDRIVERS
2860 void plD_init_memcairo(
PLStream *pls )
2864 unsigned char *cairo_mem;
2865 unsigned char *input_mem;
2871 char testByte[
sizeof ( int )];
2873 endianTest.testWord = 1;
2885 if ( endianTest.testByte[0] == 1 )
2886 aStream->bigendian = 0;
2888 aStream->bigendian = 1;
2891 if ( pls->
dev == NULL )
2893 plexit(
"Must call plsmem first to set user plotting area!" );
2897 aStream->memory = pls->
dev;
2907 aStream->cairo_format_memory = (
unsigned char *) calloc( (
size_t) ( stride * pls->
ylength ), 1 );
2910 cairo_mem = aStream->cairo_format_memory;
2911 input_mem = aStream->memory;
2917 if ( aStream->bigendian )
2921 cairo_mem[1] = input_mem[0];
2922 cairo_mem[2] = input_mem[1];
2923 cairo_mem[3] = input_mem[2];
2926 cairo_mem[0] = input_mem[3];
2940 cairo_mem[2] = input_mem[0];
2941 cairo_mem[1] = input_mem[1];
2942 cairo_mem[0] = input_mem[2];
2945 cairo_mem[3] = input_mem[3];
2960 cairo_image_surface_create_for_data( aStream->cairo_format_memory, CAIRO_FORMAT_RGB24, pls->
xlength, pls->
ylength, stride );
2975 cairo_set_fill_rule( aStream->
cairoContext, CAIRO_FILL_RULE_EVEN_ODD );
2977 cairo_set_fill_rule( aStream->
cairoContext, CAIRO_FILL_RULE_WINDING );
2987 void plD_eop_memcairo(
PLStream *pls )
2990 unsigned char *memory;
2991 unsigned char *cairo_surface_data;
2995 memory = aStream->memory;
2996 cairo_surface_data = cairo_image_surface_get_data( aStream->
cairoSurface );
3000 if ( aStream->bigendian )
3004 memory[0] = cairo_surface_data[1];
3005 memory[1] = cairo_surface_data[2];
3006 memory[2] = cairo_surface_data[3];
3009 memory[3] = cairo_surface_data[0];
3016 cairo_surface_data += 4;
3023 memory[0] = cairo_surface_data[2];
3024 memory[1] = cairo_surface_data[1];
3025 memory[2] = cairo_surface_data[0];
3028 memory[3] = cairo_surface_data[3];
3035 cairo_surface_data += 4;
3040 free( aStream->cairo_format_memory );
3053 #if defined ( PLD_extcairo )
3055 void extcairo_setbackground(
PLStream * );
3057 void plD_init_extcairo(
PLStream * );
3058 void plD_bop_extcairo(
PLStream * );
3059 void plD_eop_extcairo(
PLStream * );
3061 void plD_tidy_extcairo(
PLStream * );
3069 void extcairo_setbackground(
PLStream *pls )
3080 (
double) pls->
cmap0[0].
r / 255.0,
3081 (
double) pls->
cmap0[0].
g / 255.0,
3082 (
double) pls->
cmap0[0].
b / 255.0,
3083 (
double) pls->
cmap0[0].
a );
3097 #ifndef ENABLE_DYNDRIVERS
3098 pdt->
pl_MenuStr =
"Cairo external context driver";
3119 void plD_init_extcairo(
PLStream *pls )
3136 void plD_bop_extcairo(
PLStream *pls )
3145 extcairo_setbackground( pls );
3190 extcairo_setbackground( pls );
3195 cairo_set_fill_rule( aStream->
cairoContext, CAIRO_FILL_RULE_EVEN_ODD );
3197 cairo_set_fill_rule( aStream->
cairoContext, CAIRO_FILL_RULE_WINDING );
3230 #if defined ( PLD_wincairo )
3232 static char* szWndClass =
"PLplot WinCairo";
3235 void plD_init_wincairo(
PLStream * );
3237 void plD_eop_wincairo(
PLStream * );
3239 void plD_tidy_wincairo(
PLStream * );
3247 void blit_to_win(
PLCairo *aStream )
3249 cairo_set_source_surface( aStream->cairoContext_win, aStream->
cairoSurface, 0.0, 0.0 );
3250 cairo_paint( aStream->cairoContext_win );
3259 LRESULT CALLBACK PlplotCairoWndProc( HWND hwnd, UINT nMsg, WPARAM wParam, LPARAM lParam )
3274 if ( nMsg == WM_CREATE )
3280 pls = (
PLStream *) GetWindowLongPtr( hwnd, GWLP_USERDATA );
3302 PostQuitMessage( 0 );
3312 GetClientRect( dev->hwnd, &dev->rect );
3316 case WM_ENTERSIZEMOVE:
3320 case WM_EXITSIZEMOVE:
3327 dev->oldcolour = SetBkColor( dev->hdc, RGB( pls->
cmap0[0].
r, pls->
cmap0[0].
g, pls->
cmap0[0].
b ) );
3328 ExtTextOut( dev->hdc, 0, 0, ETO_OPAQUE, &dev->rect,
"", 0, 0 );
3329 SetBkColor( dev->hdc, dev->oldcolour );
3341 return DefWindowProc( hwnd, nMsg, wParam, lParam );
3359 while ( GetMessage( &aStream->msg, NULL, 0, 0 ) && !located )
3361 TranslateMessage( &aStream->msg );
3363 switch ( (
int) aStream->msg.message )
3366 case WM_LBUTTONDOWN:
3369 gin->
pX = LOWORD( aStream->msg.lParam );
3370 gin->
pY = pls->
ylength - HIWORD( aStream->msg.lParam );
3375 gin->
keysym = aStream->msg.wParam;
3380 DispatchMessage( &aStream->msg );
3395 #ifndef ENABLE_DYNDRIVERS
3396 pdt->
pl_MenuStr =
"Cairo Microsoft Windows driver";
3417 void plD_init_wincairo(
PLStream *pls )
3428 memset( &aStream->wndclass, 0, sizeof ( WNDCLASSEX ) );
3431 aStream->wndclass.lpszClassName = szWndClass;
3434 aStream->wndclass.cbSize =
sizeof ( WNDCLASSEX );
3437 aStream->wndclass.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS | CS_OWNDC | CS_PARENTDC;
3440 aStream->wndclass.lpfnWndProc = PlplotCairoWndProc;
3444 aStream->wndclass.hInstance = GetModuleHandle( NULL );
3447 aStream->wndclass.hIcon = LoadIcon( NULL, IDI_APPLICATION );
3448 aStream->wndclass.hIconSm = LoadIcon( NULL, IDI_APPLICATION );
3449 aStream->wndclass.hCursor = LoadCursor( NULL, IDC_ARROW );
3451 aStream->wndclass.hbrBackground = NULL;
3453 aStream->wndclass.cbWndExtra =
sizeof (
pls );
3460 RegisterClassEx( &aStream->wndclass );
3465 aStream->hwnd = CreateWindowEx( WS_EX_WINDOWEDGE + WS_EX_LEFT,
3468 WS_OVERLAPPEDWINDOW,
3476 aStream->wndclass.hInstance,
3487 SetWindowLongPtr( aStream->hwnd, GWLP_USERDATA, (LONG_PTR) pls );
3488 aStream->SCRN_hdc = aStream->hdc = GetDC( aStream->hwnd );
3507 ShowWindow( aStream->hwnd, SW_SHOWDEFAULT );
3508 SetForegroundWindow( aStream->hwnd );
3528 aStream->cairoSurface_win = (cairo_surface_t *) cairo_win32_surface_create( aStream->hdc );
3529 aStream->cairoContext_win = cairo_create( aStream->cairoSurface_win );
3543 cairo_set_fill_rule( aStream->
cairoContext, CAIRO_FILL_RULE_EVEN_ODD );
3545 cairo_set_fill_rule( aStream->
cairoContext, CAIRO_FILL_RULE_WINDING );
3561 while ( GetMessage( &aStream->msg, NULL, 0, 0 ) )
3563 TranslateMessage( &aStream->msg );
3564 switch ( (
int) aStream->msg.message )
3567 if ( ( (TCHAR) ( aStream->msg.wParam ) == 13 ) ||
3568 ( (TCHAR) ( aStream->msg.wParam ) ==
'q' ) ||
3569 ( (TCHAR) ( aStream->msg.wParam ) ==
'Q' ) )
3571 PostQuitMessage( 0 );
3576 DispatchMessage( &aStream->msg );
3589 void plD_tidy_wincairo(
PLStream *pls )
3596 cairo_destroy( aStream->cairoContext_win );
3597 cairo_surface_destroy( aStream->cairoSurface_win );
3599 if ( aStream != NULL )
3601 if ( aStream->hdc != NULL )
3602 ReleaseDC( aStream->hwnd, aStream->hdc );
3622 InvalidateRect( aStream->hwnd, NULL,
TRUE );
int plParseDrvOpts(DrvOpt *acc_opt)
PLDLLIMPEXP_DRIVER void plD_dispatch_init_pscairo(PLDispatchTable *pdt)
void plP_script_scale(PLBOOL ifupper, PLINT *level, PLFLT *old_scale, PLFLT *scale, PLFLT *old_offset, PLFLT *offset)
void plD_tidy_cairo(PLStream *)
static void start_raster(PLStream *)
void(* plD_line_fp)(struct PLStream_struct *, short, short, short, short)
void plexit(PLCHAR_VECTOR errormsg)
static void rotate_cairo_surface(PLStream *, float, float, float, float, float, float, PLBOOL)
static void proc_str(PLStream *, EscText *)
PLDLLIMPEXP_DRIVER void plD_dispatch_init_wincairo(PLDispatchTable *pdt)
#define PLESC_CONTROL_CHAR
void(* plD_eop_fp)(struct PLStream_struct *)
static char * ucs4_to_pango_markup_format(PLUNICODE *, int, float)
static void arc(PLStream *, arc_struct *)
void plP_fci2hex(PLUNICODE fci, unsigned char *phexdigit, unsigned char hexpower)
const char * envFamilyLookup[NPANGOLOOKUP]
void(* plD_state_fp)(struct PLStream_struct *, PLINT)
static void get_mode(PLStream *, PLINT *)
void(* plD_tidy_fp)(struct PLStream_struct *)
void get_line_properties(PLCairo *aStream, cairo_line_join_t *join, cairo_line_cap_t *cap)
void plOpenFile(PLStream *pls)
void plCloseFile(PLStream *pls)
void plGetFam(PLStream *pls)
static DrvOpt cairo_options[]
int ucs4_to_utf8(PLUNICODE unichar, char *ptr)
void plGinInit(PLGraphicsIn *gin)
#define FAMILY_LOOKUP_LEN
static void text_esc_cairo(PLStream *pls, EscText *args)
static int already_warned
#define PLTEXT_SUPERSCRIPT
static void open_span_tag(char *, PLUNICODE, float, int)
PLDLLIMPEXP_DRIVER void plD_dispatch_init_pngcairo(PLDispatchTable *pdt)
PLDLLIMPEXP_DRIVER void plD_dispatch_init_extcairo(PLDispatchTable *pdt)
void plFamInit(PLStream *pls)
short graphics_anti_aliasing
void(* plD_polyline_fp)(struct PLStream_struct *, short *, short *, PLINT)
#define PLTEXT_FONTCHANGE
static void text_char_cairo(PLStream *pls, EscText *args)
void plD_eop_cairo(PLStream *)
cairo_surface_t * cairoSurface_raster
void(* plD_esc_fp)(struct PLStream_struct *, PLINT, void *)
cairo_surface_t * cairoSurface
void(* plD_bop_fp)(struct PLStream_struct *)
static char * rise_span_tag(int, float, float, float)
PLDLLIMPEXP_DRIVER void plD_dispatch_init_svgcairo(PLDispatchTable *pdt)
static int image_buffering
const char * weightLookup[2]
void set_line_properties(PLCairo *aStream, cairo_line_join_t join, cairo_line_cap_t cap)
int cairo_family_check(PLStream *pls)
static void end_raster(PLStream *)
void set_clip(PLStream *pls)
static int rasterize_image
void plD_bop_cairo(PLStream *)
void difilt_clip(PLINT *x_coords, PLINT *y_coords)
static void poly_line(PLStream *, short *, short *, PLINT)
#define PL_DRAWMODE_UNKNOWN
#define PLESC_END_RASTERIZE
static void gradient(PLStream *pls, short *xa, short *ya, PLINT npts)
void plD_polyline_cairo(PLStream *, short *, short *, PLINT)
static int text_anti_aliasing
void plP_setpxl(PLFLT xpmm, PLFLT ypmm)
static void set_mode(PLStream *, PLINT *)
static void close_span_tag(char *, int)
PLDLLIMPEXP_DRIVER void plD_dispatch_init_pdfcairo(PLDispatchTable *pdt)
static int graphics_anti_aliasing
void plD_esc_cairo(PLStream *, PLINT, void *)
#define PLDLLIMPEXP_DRIVER
static PLStream * pls[PL_NSTREAMS]
void plP_setphy(PLINT xmin, PLINT xmax, PLINT ymin, PLINT ymax)
void plRotationShear(PLFLT *xFormMatrix, PLFLT *rotation, PLFLT *shear, PLFLT *stride)
const char * styleLookup[3]
unsigned short unicode_array_len
static void text_begin_cairo(PLStream *pls, EscText *args)
#define PL_DRAWMODE_REPLACE
PLDLLIMPEXP_DRIVER void plD_dispatch_init_xcairo(PLDispatchTable *pdt)
char familyLookup[NPANGOLOOKUP][FAMILY_LOOKUP_LEN]
static int external_drawable
PLDLLIMPEXP_DRIVER void plD_dispatch_init_epscairo(PLDispatchTable *pdt)
cairo_t * cairoContext_raster
#define PLESC_START_RASTERIZE
static int set_background
PLDLLIMPEXP_DRIVER void plD_dispatch_init_memcairo(PLDispatchTable *pdt)
cairo_status_t write_to_stream(void *, unsigned char *, unsigned int)
#define PLCAIRO_DEFAULT_Y
void plD_line_cairo(PLStream *, short, short, short, short)
static void set_current_context(PLStream *)
void plwarn(PLCHAR_VECTOR errormsg)
static void text_end_cairo(PLStream *pls, EscText *args)
#define PLCAIRO_DEFAULT_X
static const char * display
static void filled_polygon(PLStream *pls, short *xa, short *ya, PLINT npts)
const char * defaultFamilyLookup[NPANGOLOOKUP]
static void blit_to_x(PLStream *pls, double x, double y, double w, double h)
#define PL_DRAWMODE_DEFAULT
plD_polyline_fp pl_polyline
PLUNICODE * unicode_array
PLDLLIMPEXP_DRIVER const char * plD_DEVICE_INFO_cairo
PLCairo * stream_and_font_setup(PLStream *, int)
void plD_state_cairo(PLStream *, PLINT)
void(* plD_init_fp)(struct PLStream_struct *)