35 #include <pango/pangocairo.h>
44 #if defined ( PLD_wincairo )
47 #if defined ( PLD_xcairo )
48 #include <cairo-xlib.h>
51 #include <X11/Xutil.h>
52 #include <X11/cursorfont.h>
53 #include <X11/keysym.h>
55 #if defined ( PLD_pdfcairo )
56 #include <cairo-pdf.h>
58 #if defined ( PLD_pscairo )
61 #if defined ( PLD_svgcairo )
62 #include <cairo-svg.h>
71 #define PLCAIRO_DEFAULT_X 720
72 #define PLCAIRO_DEFAULT_Y 540
74 #define MAX_STRING_LEN 500
75 #define MAX_MARKUP_LEN MAX_STRING_LEN * 10
87 {
"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)" },
88 {
"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" },
90 {
"rasterize_image",
DRV_INT, &
rasterize_image,
"Raster or vector image rendering (rasterize_image=0|1)" },
91 {
"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" },
92 {
"image_buffering",
DRV_INT, &
image_buffering,
"Buffered offscreen rendering for the xcairo device (image_buffering=0|1)." },
93 { NULL,
DRV_INT, NULL, NULL } };
122 #if defined ( PLD_xcairo )
123 cairo_surface_t *cairoSurface_X;
124 cairo_t *cairoContext_X;
125 short exit_event_loop;
128 unsigned int xdrawable_mode;
130 #if defined ( PLD_memcairo )
131 unsigned char *memory;
132 unsigned char *cairo_format_memory;
135 #if defined ( PLD_wincairo )
136 cairo_surface_t *cairoSurface_win;
137 cairo_t *cairoContext_win;
149 #if defined ( PLD_xcairo )
150 "xcairo:Cairo X Windows Driver:1:cairo:100:xcairo\n"
152 #if defined ( PLD_pdfcairo )
153 "pdfcairo:Cairo PDF Driver:0:cairo:101:pdfcairo\n"
155 #if defined ( PLD_pscairo )
156 "pscairo:Cairo PS Driver:0:cairo:102:pscairo\n"
158 #if defined ( PLD_epscairo )
159 "epscairo:Cairo EPS Driver:0:cairo:103:epscairo\n"
161 #if defined ( PLD_svgcairo )
162 "svgcairo:Cairo SVG Driver:0:cairo:104:svgcairo\n"
164 #if defined ( PLD_pngcairo )
165 "pngcairo:Cairo PNG Driver:0:cairo:105:pngcairo\n"
167 #if defined ( PLD_memcairo )
168 "memcairo:Cairo Memory Driver:0:cairo:106:memcairo\n"
170 #if defined ( PLD_extcairo )
171 "extcairo:Cairo External Context Driver:0:cairo:107:extcairo\n"
173 #if defined ( PLD_wincairo )
174 "wincairo:Cairo Microscoft Windows Driver:0:cairo:108:wincairo\n"
182 #if defined ( PLD_xcairo )
187 } PLXcairoDrawableInfo;
195 #define NPANGOLOOKUP 5
206 "PLPLOT_FREETYPE_SANS_FAMILY",
207 "PLPLOT_FREETYPE_SERIF_FAMILY",
208 "PLPLOT_FREETYPE_MONO_FAMILY",
209 "PLPLOT_FREETYPE_SCRIPT_FAMILY",
210 "PLPLOT_FREETYPE_SYMBOL_FAMILY"
213 #define FAMILY_LOOKUP_LEN 1024
244 cairo_status_t
write_to_stream(
void *,
unsigned char *,
unsigned int );
300 cairo_surface_t *tmp_sfc;
301 cairo_t *tmp_context;
316 cairo_image_surface_create( CAIRO_FORMAT_ARGB32,
344 cairo_surface_t *tmp_sfc;
345 cairo_t *tmp_context;
359 plexit(
"Can not plot to a Cairo device with no context" );
397 if ( (
double) pls->
cmap0[0].
a < 1.0 )
399 cairo_set_source_rgba( aStream->
cairoContext, 1.0, 1.0, 1.0, 1.0 );
403 (
double) pls->
cmap0[0].
r / 255.0,
404 (
double) pls->
cmap0[0].
g / 255.0,
405 (
double) pls->
cmap0[0].
b / 255.0,
406 (
double) pls->
cmap0[0].
a );
596 cairo_set_operator( aStream->
cairoContext, CAIRO_OPERATOR_OVER );
599 cairo_set_operator( aStream->
cairoContext, CAIRO_OPERATOR_SOURCE );
602 cairo_set_operator( aStream->
cairoContext, CAIRO_OPERATOR_XOR );
624 case CAIRO_OPERATOR_OVER:
627 case CAIRO_OPERATOR_SOURCE:
630 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;
1154 strncat( pangoMarkupString, openTag,
MAX_MARKUP_LEN - 1 - strlen( pangoMarkupString ) );
1157 strncat( pangoMarkupString, openTag,
MAX_MARKUP_LEN - 1 - strlen( pangoMarkupString ) );
1160 strncat( pangoMarkupString, openTag,
MAX_MARKUP_LEN - 1 - strlen( pangoMarkupString ) );
1163 for ( upDown_level = 0; upDown_level < upDown; upDown_level++ )
1166 &old_sscale, &sscale, &old_soffset, &soffset );
1167 strncat( pangoMarkupString,
1171 for ( upDown_level = 0; upDown_level > upDown; upDown_level-- )
1174 &old_sscale, &sscale, &old_soffset, &soffset );
1175 strncat( pangoMarkupString,
1191 while ( upDown > 0 )
1193 strncat( pangoMarkupString,
"</span>",
MAX_MARKUP_LEN - 1 - strlen( pangoMarkupString ) );
1199 while ( upDown < 0 )
1201 strncat( pangoMarkupString,
"</span>",
MAX_MARKUP_LEN - 1 - strlen( pangoMarkupString ) );
1206 strncat( pangoMarkupString,
"</span>",
MAX_MARKUP_LEN - 1 - strlen( pangoMarkupString ) );
1214 # define RISE_FACTOR 0.8
1227 char *
rise_span_tag(
int ifsuperscript,
float fontSize,
float multiplier,
float rise )
1230 static char tag[100];
1237 rise = 1024.f * fontSize * (float)
RISE_FACTOR * rise;
1242 offset = 1024.f * 0.5f * fontSize * ( 1.0f - multiplier );
1244 if ( ifsuperscript )
1246 sprintf( tag,
"<span rise=\"%d\" size=\"%d\">",
1247 (
int) ( rise + offset ), (
int) ( fontSize * 1024. * multiplier ) );
1251 sprintf( tag,
"<span rise=\"%d\" size=\"%d\">",
1252 (
int) -( rise - offset ), (
int) ( fontSize * 1024. * multiplier ) );
1265 cairo_status_t
write_to_stream(
void *filePointer,
unsigned char *data,
unsigned int length )
1267 unsigned int bytes_written;
1269 bytes_written = (
unsigned int) fwrite( data, 1, (
size_t) length, (FILE *) filePointer );
1270 if ( bytes_written == length )
1272 return CAIRO_STATUS_SUCCESS;
1276 return CAIRO_STATUS_WRITE_ERROR;
1298 pls->
termin = interactive;
1344 aStream = malloc(
sizeof (
PLCairo ) );
1345 #if defined ( PLD_xcairo )
1346 aStream->XDisplay = NULL;
1347 aStream->XWindow = 0;
1400 if ( pls->
width <= 0. )
1428 for ( i = 1; i < npts; i++ )
1457 if ( cairo_get_antialias( aStream->
cairoContext ) != CAIRO_ANTIALIAS_NONE )
1491 cairo_pattern_t *linear_gradient;
1498 linear_gradient = cairo_pattern_create_linear(
1504 cairo_pattern_reference( linear_gradient );
1505 for ( i = 0; i < pls->
ncol1; i++ )
1507 cairo_pattern_add_color_stop_rgba( linear_gradient,
1508 (
double) i / (
double) ( pls->
ncol1 - 1 ),
1509 (
double) pls->
cmap1[i].
r / 255.,
1510 (
double) pls->
cmap1[i].
g / 255.,
1511 (
double) pls->
cmap1[i].
b / 255.,
1512 (
double) pls->
cmap1[i].
a );
1518 cairo_set_source( aStream->
cairoContext, linear_gradient );
1520 cairo_pattern_destroy( linear_gradient );
1533 PLINT rcx[4], rcy[4];
1584 plwarn(
"All pages after the first skipped because family file output not specified.\n" );
1600 double angle1, angle2, rotate;
1627 cairo_arc( aStream->
cairoContext, 0.0, 0.0, 1.0, angle1, angle2 );
1628 if ( arc_info->
fill )
1637 if ( arc_info->
fill )
1656 cairo_matrix_t *matrix;
1661 matrix = (cairo_matrix_t *) malloc(
sizeof ( cairo_matrix_t ) );
1662 cairo_matrix_init( matrix, x11, x12, x21, x22, x0, y0 );
1663 #if defined ( PLD_xcairo )
1666 cairo_transform( aStream->cairoContext_X, matrix );
1685 #if defined ( PLD_pngcairo ) || defined ( PLD_svgcairo ) || defined ( PLD_epscairo )
1687 void plD_bop_cairo_fam(
PLStream * );
1688 void plD_eop_cairo_fam(
PLStream * );
1691 void plD_tidy_cairo_fam(
PLStream * );
1692 void plD_line_cairo_fam(
PLStream *,
short,
short,
short,
short );
1693 void plD_polyline_cairo_fam(
PLStream *,
short *,
short *,
PLINT );
1701 void plD_bop_cairo_fam(
PLStream *pls )
1723 (
double) pls->
cmap0[0].
r / 255.0,
1724 (
double) pls->
cmap0[0].
g / 255.0,
1725 (
double) pls->
cmap0[0].
b / 255.0,
1726 (
double) pls->
cmap0[0].
a );
1736 void plD_eop_cairo_fam(
PLStream *pls )
1768 void plD_esc_cairo_fam(
PLStream *pls,
PLINT op,
void *ptr )
1784 void plD_tidy_cairo_fam(
PLStream *pls )
1795 void plD_line_cairo_fam(
PLStream *pls,
short x1a,
short y1a,
short x2a,
short y2a )
1811 void plD_polyline_cairo_fam(
PLStream *pls,
short *xa,
short *ya,
PLINT npts )
1830 #if defined ( PLD_xcairo )
1833 static Window rootWindow;
1836 void plD_init_xcairo(
PLStream * );
1839 void plD_tidy_xcairo(
PLStream * );
1851 #ifndef ENABLE_DYNDRIVERS
1879 static signed int xcairo_init_cairo(
PLStream *pls )
1882 Visual *defaultVisual;
1887 defaultVisual = DefaultVisual( aStream->XDisplay, 0 );
1890 aStream->cairoSurface_X = cairo_xlib_surface_create( aStream->XDisplay, aStream->XWindow, defaultVisual, pls->
xlength, pls->
ylength );
1891 aStream->cairoContext_X = cairo_create( aStream->cairoSurface_X );
1895 aStream->
cairoSurface = cairo_surface_create_similar( aStream->cairoSurface_X, CAIRO_CONTENT_COLOR_ALPHA, pls->
xlength, pls->
ylength );
1902 cairo_image_surface_create( CAIRO_FORMAT_ARGB32,
1915 cairo_set_fill_rule( aStream->
cairoContext, CAIRO_FILL_RULE_EVEN_ODD );
1917 cairo_set_fill_rule( aStream->
cairoContext, CAIRO_FILL_RULE_WINDING );
1921 cairo_rectangle( aStream->cairoContext_X, 0.0, 0.0, pls->
xlength, pls->
ylength );
1922 cairo_set_source_rgba( aStream->cairoContext_X,
1923 (
double) pls->
cmap0[0].
r / 255.0,
1924 (
double) pls->
cmap0[0].
g / 255.0,
1925 (
double) pls->
cmap0[0].
b / 255.0,
1926 (
double) pls->
cmap0[0].
a );
1927 cairo_fill( aStream->cairoContext_X );
1929 XFlush( aStream->XDisplay );
1940 void plD_init_xcairo(
PLStream *pls )
1954 aStream->xdrawable_mode = 1;
1959 aStream->XDisplay = NULL;
1961 aStream->XDisplay = XOpenDisplay( pls->
FileName );
1963 aStream->XDisplay = XOpenDisplay( NULL );
1964 if ( aStream->XDisplay == NULL )
1966 plexit(
"Failed to open X Windows display\n" );
1969 XScreen = DefaultScreen( aStream->XDisplay );
1970 rootWindow = RootWindow( aStream->XDisplay, XScreen );
1972 aStream->XWindow = XCreateSimpleWindow( aStream->XDisplay, rootWindow, 0, 0, (
unsigned int) pls->
xlength, (
unsigned int) pls->
ylength,
1973 1, BlackPixel( aStream->XDisplay, XScreen ), BlackPixel( aStream->XDisplay, XScreen ) );
1974 XStoreName( aStream->XDisplay, aStream->XWindow, pls->
plwindow );
1975 XSelectInput( aStream->XDisplay, aStream->XWindow, NoEventMask );
1976 XMapWindow( aStream->XDisplay, aStream->XWindow );
1977 aStream->xdrawable_mode = 0;
1979 wmDelete = XInternAtom( aStream->XDisplay,
"WM_DELETE_WINDOW", True );
1980 XSetWMProtocols( aStream->XDisplay, aStream->XWindow, &wmDelete, 1 );
1982 xcairo_init_cairo( pls );
1985 aStream->exit_event_loop = 0;
2005 cairo_set_operator( aStream->
cairoContext, CAIRO_OPERATOR_DEST_OVER );
2007 (
double) pls->
cmap0[0].
r / 255.0,
2008 (
double) pls->
cmap0[0].
g / 255.0,
2009 (
double) pls->
cmap0[0].
b / 255.0,
2010 (
double) pls->
cmap0[0].
a );
2014 cairo_save( aStream->cairoContext_X );
2016 cairo_rectangle( aStream->cairoContext_X, x, y, w, h );
2017 cairo_set_operator( aStream->cairoContext_X, CAIRO_OPERATOR_SOURCE );
2018 cairo_set_source_surface( aStream->cairoContext_X,
2020 cairo_fill( aStream->cairoContext_X );
2021 cairo_restore( aStream->cairoContext_X );
2030 void plD_bop_xcairo(
PLStream *pls )
2038 if ( aStream->xdrawable_mode )
2041 XFlush( aStream->XDisplay );
2050 void plD_eop_xcairo(
PLStream *pls )
2054 char event_string[10];
2058 XExposeEvent *expose;
2066 if ( aStream->xdrawable_mode )
2071 aStream->exit_event_loop = 1;
2074 event_mask = ButtonPressMask | KeyPressMask | ExposureMask;
2075 XSelectInput( aStream->XDisplay, aStream->XWindow, event_mask );
2076 while ( !aStream->exit_event_loop )
2079 XNextEvent( aStream->XDisplay, &event );
2080 switch ( event.type )
2083 number_chars = XLookupString( (XKeyEvent *) &event, event_string, 10, &keysym, &cs );
2084 event_string[number_chars] =
'\0';
2085 if ( keysym == XK_Return )
2087 aStream->exit_event_loop = 1;
2091 if ( ( (XButtonEvent *) &event )->button == Button3 )
2092 aStream->exit_event_loop = 1;
2097 aStream->exit_event_loop = 1;
2102 expose = (XExposeEvent *) &event;
2103 if ( expose->count == 0 )
2106 expose->
width, expose->height );
2111 aStream->exit_event_loop = 0;
2120 void plD_tidy_xcairo(
PLStream *pls )
2129 cairo_destroy( aStream->cairoContext_X );
2130 cairo_surface_destroy( aStream->cairoSurface_X );
2132 if ( aStream->xdrawable_mode )
2136 XFlush( aStream->XDisplay );
2138 XDestroyWindow( aStream->XDisplay, aStream->XWindow );
2140 XCloseDisplay( aStream->XDisplay );
2159 XFlush( aStream->XDisplay );
2163 XFlush( aStream->XDisplay );
2168 PLXcairoDrawableInfo *xinfo = (PLXcairoDrawableInfo *) ptr;
2170 unsigned int w, h, b, d;
2171 if ( xinfo == NULL )
2173 printf(
"xcairo: PLESC_DEVINIT ignored, no drawable info provided\n" );
2176 if ( aStream->xdrawable_mode == 0 )
2178 printf(
"xcairo: PLESC_DEVINIT called with drawable but stream not in xdrawable mode\n" );
2181 aStream->XDisplay = xinfo->display;
2182 aStream->XWindow = xinfo->drawable;
2185 XGetGeometry( aStream->XDisplay, aStream->XWindow, &rootwin,
2186 &x, &y, &w, &h, &b, &d );
2193 xcairo_init_cairo( pls );
2218 XButtonEvent *xButtonEvent;
2228 xHairCursor = XCreateFontCursor( aStream->XDisplay, XC_crosshair );
2229 XDefineCursor( aStream->XDisplay, aStream->XWindow, xHairCursor );
2232 XSelectInput( aStream->XDisplay, aStream->XWindow, ButtonPressMask | ButtonReleaseMask | KeyPressMask | KeyReleaseMask | ButtonMotionMask );
2233 XMaskEvent( aStream->XDisplay, ButtonPressMask | ButtonReleaseMask | KeyPressMask | KeyReleaseMask | ButtonMotionMask, &event );
2234 XSelectInput( aStream->XDisplay, aStream->XWindow, NoEventMask );
2237 xButtonEvent = (XButtonEvent *) &event;
2238 gin->
state = xButtonEvent->state;
2239 gin->
button = xButtonEvent->button;
2240 gin->
pX =
event.xbutton.x;
2241 gin->
pY = pls->
ylength -
event.xbutton.y;
2246 if ( event.type == KeyPress || event.type == KeyRelease )
2248 XLookupString( (XKeyEvent *) &event, str, 100, &keysym, NULL );
2249 if ( keysym == NoSymbol )
2250 ksname =
"NoSymbol";
2251 else if ( !( ksname = XKeysymToString( keysym ) ) )
2252 ksname =
"(no name)";
2253 strcpy( gin->
string, ksname );
2263 gin->
keysym = 0xFF & keysym;
2266 gin->
keysym = (
unsigned int) keysym;
2276 XUndefineCursor( aStream->XDisplay, aStream->XWindow );
2277 XFlush( aStream->XDisplay );
2291 #if defined ( PLD_pdfcairo )
2294 void plD_init_pdfcairo(
PLStream * );
2305 #ifndef ENABLE_DYNDRIVERS
2327 void plD_init_pdfcairo(
PLStream *pls )
2353 cairo_set_fill_rule( aStream->
cairoContext, CAIRO_FILL_RULE_EVEN_ODD );
2355 cairo_set_fill_rule( aStream->
cairoContext, CAIRO_FILL_RULE_WINDING );
2369 #if defined ( PLD_pscairo )
2372 void plD_init_pscairo(
PLStream * );
2383 #ifndef ENABLE_DYNDRIVERS
2405 void plD_init_pscairo(
PLStream *pls )
2433 cairo_set_fill_rule( aStream->
cairoContext, CAIRO_FILL_RULE_EVEN_ODD );
2435 cairo_set_fill_rule( aStream->
cairoContext, CAIRO_FILL_RULE_WINDING );
2449 #if defined ( PLD_epscairo )
2452 void plD_init_epscairo(
PLStream * );
2463 #ifndef ENABLE_DYNDRIVERS
2485 void plD_init_epscairo(
PLStream *pls )
2500 if ( pls->
dev == NULL )
2537 cairo_set_fill_rule( aStream->
cairoContext, CAIRO_FILL_RULE_EVEN_ODD );
2539 cairo_set_fill_rule( aStream->
cairoContext, CAIRO_FILL_RULE_WINDING );
2553 #if defined ( PLD_svgcairo )
2556 void plD_init_svgcairo(
PLStream * );
2567 #ifndef ENABLE_DYNDRIVERS
2589 void plD_init_svgcairo(
PLStream *pls )
2604 if ( pls->
dev == NULL )
2636 cairo_set_fill_rule( aStream->
cairoContext, CAIRO_FILL_RULE_EVEN_ODD );
2638 cairo_set_fill_rule( aStream->
cairoContext, CAIRO_FILL_RULE_WINDING );
2652 #if defined ( PLD_pngcairo )
2655 void plD_init_pngcairo(
PLStream * );
2656 void plD_eop_pngcairo(
PLStream * );
2667 #ifndef ENABLE_DYNDRIVERS
2689 void plD_init_pngcairo(
PLStream *pls )
2704 if ( pls->
dev == NULL )
2736 cairo_set_fill_rule( aStream->
cairoContext, CAIRO_FILL_RULE_EVEN_ODD );
2738 cairo_set_fill_rule( aStream->
cairoContext, CAIRO_FILL_RULE_WINDING );
2747 void plD_eop_pngcairo(
PLStream *pls )
2771 #if defined ( PLD_memcairo )
2774 void plD_init_memcairo(
PLStream * );
2775 void plD_eop_memcairo(
PLStream * );
2776 void plD_bop_memcairo(
PLStream * );
2787 #ifndef ENABLE_DYNDRIVERS
2820 void plD_init_memcairo(
PLStream *pls )
2824 unsigned char *cairo_mem;
2825 unsigned char *input_mem;
2831 char testByte[
sizeof ( int )];
2833 endianTest.testWord = 1;
2845 if ( endianTest.testByte[0] == 1 )
2846 aStream->bigendian = 0;
2848 aStream->bigendian = 1;
2851 if ( pls->
dev == NULL )
2853 plexit(
"Must call plsmem first to set user plotting area!" );
2857 aStream->memory = pls->
dev;
2867 aStream->cairo_format_memory = (
unsigned char *) calloc( (
size_t) ( stride * pls->
ylength ), 1 );
2870 cairo_mem = aStream->cairo_format_memory;
2871 input_mem = aStream->memory;
2877 if ( aStream->bigendian )
2881 cairo_mem[1] = input_mem[0];
2882 cairo_mem[2] = input_mem[1];
2883 cairo_mem[3] = input_mem[2];
2886 cairo_mem[0] = input_mem[3];
2900 cairo_mem[2] = input_mem[0];
2901 cairo_mem[1] = input_mem[1];
2902 cairo_mem[0] = input_mem[2];
2905 cairo_mem[3] = input_mem[3];
2920 cairo_image_surface_create_for_data( aStream->cairo_format_memory, CAIRO_FORMAT_RGB24, pls->
xlength, pls->
ylength, stride );
2935 cairo_set_fill_rule( aStream->
cairoContext, CAIRO_FILL_RULE_EVEN_ODD );
2937 cairo_set_fill_rule( aStream->
cairoContext, CAIRO_FILL_RULE_WINDING );
2947 void plD_eop_memcairo(
PLStream *pls )
2950 unsigned char *memory;
2951 unsigned char *cairo_surface_data;
2955 memory = aStream->memory;
2956 cairo_surface_data = cairo_image_surface_get_data( aStream->
cairoSurface );
2960 if ( aStream->bigendian )
2964 memory[0] = cairo_surface_data[1];
2965 memory[1] = cairo_surface_data[2];
2966 memory[2] = cairo_surface_data[3];
2969 memory[3] = cairo_surface_data[0];
2976 cairo_surface_data += 4;
2983 memory[0] = cairo_surface_data[2];
2984 memory[1] = cairo_surface_data[1];
2985 memory[2] = cairo_surface_data[0];
2988 memory[3] = cairo_surface_data[3];
2995 cairo_surface_data += 4;
3000 free( aStream->cairo_format_memory );
3013 #if defined ( PLD_extcairo )
3015 void extcairo_setbackground(
PLStream * );
3017 void plD_init_extcairo(
PLStream * );
3018 void plD_bop_extcairo(
PLStream * );
3019 void plD_eop_extcairo(
PLStream * );
3021 void plD_tidy_extcairo(
PLStream * );
3029 void extcairo_setbackground(
PLStream *pls )
3040 (
double) pls->
cmap0[0].
r / 255.0,
3041 (
double) pls->
cmap0[0].
g / 255.0,
3042 (
double) pls->
cmap0[0].
b / 255.0,
3043 (
double) pls->
cmap0[0].
a );
3057 #ifndef ENABLE_DYNDRIVERS
3058 pdt->
pl_MenuStr =
"Cairo external context driver";
3079 void plD_init_extcairo(
PLStream *pls )
3096 void plD_bop_extcairo(
PLStream *pls )
3105 extcairo_setbackground( pls );
3150 extcairo_setbackground( pls );
3155 cairo_set_fill_rule( aStream->
cairoContext, CAIRO_FILL_RULE_EVEN_ODD );
3157 cairo_set_fill_rule( aStream->
cairoContext, CAIRO_FILL_RULE_WINDING );
3190 #if defined ( PLD_wincairo )
3192 static char* szWndClass =
"PLplot WinCairo";
3195 void plD_init_wincairo(
PLStream * );
3197 void plD_eop_wincairo(
PLStream * );
3199 void plD_tidy_wincairo(
PLStream * );
3207 void blit_to_win(
PLCairo *aStream )
3209 cairo_set_source_surface( aStream->cairoContext_win, aStream->
cairoSurface, 0.0, 0.0 );
3210 cairo_paint( aStream->cairoContext_win );
3219 LRESULT CALLBACK PlplotCairoWndProc( HWND hwnd, UINT nMsg, WPARAM wParam, LPARAM lParam )
3234 if ( nMsg == WM_CREATE )
3240 pls = (
PLStream *) GetWindowLong( hwnd, GWL_USERDATA );
3262 PostQuitMessage( 0 );
3272 GetClientRect( dev->hwnd, &dev->rect );
3276 case WM_ENTERSIZEMOVE:
3280 case WM_EXITSIZEMOVE:
3287 dev->oldcolour = SetBkColor( dev->hdc, RGB( pls->
cmap0[0].
r, pls->
cmap0[0].
g, pls->
cmap0[0].
b ) );
3288 ExtTextOut( dev->hdc, 0, 0, ETO_OPAQUE, &dev->rect,
"", 0, 0 );
3289 SetBkColor( dev->hdc, dev->oldcolour );
3301 return DefWindowProc( hwnd, nMsg, wParam, lParam );
3319 while ( GetMessage( &aStream->msg, NULL, 0, 0 ) && !located )
3321 TranslateMessage( &aStream->msg );
3323 switch ( (
int) aStream->msg.message )
3326 case WM_LBUTTONDOWN:
3329 gin->
pX = LOWORD( aStream->msg.lParam );
3330 gin->
pY = pls->
ylength - HIWORD( aStream->msg.lParam );
3335 gin->
keysym = aStream->msg.wParam;
3340 DispatchMessage( &aStream->msg );
3355 #ifndef ENABLE_DYNDRIVERS
3356 pdt->
pl_MenuStr =
"Cairo Microsoft Windows driver";
3377 void plD_init_wincairo(
PLStream *pls )
3388 memset( &aStream->wndclass, 0, sizeof ( WNDCLASSEX ) );
3391 aStream->wndclass.lpszClassName = szWndClass;
3394 aStream->wndclass.cbSize =
sizeof ( WNDCLASSEX );
3397 aStream->wndclass.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS | CS_OWNDC | CS_PARENTDC;
3400 aStream->wndclass.lpfnWndProc = PlplotCairoWndProc;
3404 aStream->wndclass.hInstance = GetModuleHandle( NULL );
3407 aStream->wndclass.hIcon = LoadIcon( NULL, IDI_APPLICATION );
3408 aStream->wndclass.hIconSm = LoadIcon( NULL, IDI_APPLICATION );
3409 aStream->wndclass.hCursor = LoadCursor( NULL, IDC_ARROW );
3411 aStream->wndclass.hbrBackground = NULL;
3413 aStream->wndclass.cbWndExtra =
sizeof ( pls );
3420 RegisterClassEx( &aStream->wndclass );
3425 aStream->hwnd = CreateWindowEx( WS_EX_WINDOWEDGE + WS_EX_LEFT,
3428 WS_OVERLAPPEDWINDOW,
3436 aStream->wndclass.hInstance,
3447 SetWindowLong( aStream->hwnd, GWL_USERDATA, (
long) pls );
3448 aStream->SCRN_hdc = aStream->hdc = GetDC( aStream->hwnd );
3467 ShowWindow( aStream->hwnd, SW_SHOWDEFAULT );
3468 SetForegroundWindow( aStream->hwnd );
3488 aStream->cairoSurface_win = (cairo_surface_t *) cairo_win32_surface_create( aStream->hdc );
3489 aStream->cairoContext_win = cairo_create( aStream->cairoSurface_win );
3503 cairo_set_fill_rule( aStream->
cairoContext, CAIRO_FILL_RULE_EVEN_ODD );
3505 cairo_set_fill_rule( aStream->
cairoContext, CAIRO_FILL_RULE_WINDING );
3521 while ( GetMessage( &aStream->msg, NULL, 0, 0 ) )
3523 TranslateMessage( &aStream->msg );
3524 switch ( (
int) aStream->msg.message )
3527 if ( ( (TCHAR) ( aStream->msg.wParam ) == 13 ) ||
3528 ( (TCHAR) ( aStream->msg.wParam ) ==
'q' ) ||
3529 ( (TCHAR) ( aStream->msg.wParam ) ==
'Q' ) )
3531 PostQuitMessage( 0 );
3536 DispatchMessage( &aStream->msg );
3549 void plD_tidy_wincairo(
PLStream *pls )
3556 cairo_destroy( aStream->cairoContext_win );
3557 cairo_surface_destroy( aStream->cairoSurface_win );
3559 if ( aStream != NULL )
3561 if ( aStream->hdc != NULL )
3562 ReleaseDC( aStream->hwnd, aStream->hdc );
3582 InvalidateRect( aStream->hwnd, NULL,
TRUE );