35 #include <pango/pangocairo.h>
44 #if defined ( PLD_xcairo )
45 #include <cairo-xlib.h>
48 #include <X11/Xutil.h>
49 #include <X11/cursorfont.h>
50 #include <X11/keysym.h>
52 #if defined ( PLD_pdfcairo )
53 #include <cairo-pdf.h>
55 #if defined ( PLD_pscairo )
58 #if defined ( PLD_svgcairo )
59 #include <cairo-svg.h>
61 #if defined ( PLD_wincairo )
70 #define PLCAIRO_DEFAULT_X 720
71 #define PLCAIRO_DEFAULT_Y 540
73 #define MAX_STRING_LEN 500
74 #define MAX_MARKUP_LEN MAX_STRING_LEN * 10
86 {
"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)" },
87 {
"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" },
89 {
"rasterize_image",
DRV_INT, &
rasterize_image,
"Raster or vector image rendering (rasterize_image=0|1)" },
90 {
"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" },
91 {
"image_buffering",
DRV_INT, &
image_buffering,
"Buffered offscreen rendering for the xcairo device (image_buffering=0|1)." },
92 { NULL,
DRV_INT, NULL, NULL } };
120 #if defined ( PLD_xcairo )
121 cairo_surface_t *cairoSurface_X;
122 cairo_t *cairoContext_X;
123 short exit_event_loop;
126 unsigned int xdrawable_mode;
128 #if defined ( PLD_memcairo )
129 unsigned char *memory;
130 unsigned char *cairo_format_memory;
133 #if defined ( PLD_wincairo )
134 cairo_surface_t *cairoSurface_win;
135 cairo_t *cairoContext_win;
147 #if defined ( PLD_xcairo )
148 "xcairo:Cairo X Windows Driver:1:cairo:100:xcairo\n"
150 #if defined ( PLD_pdfcairo )
151 "pdfcairo:Cairo PDF Driver:0:cairo:101:pdfcairo\n"
153 #if defined ( PLD_pscairo )
154 "pscairo:Cairo PS Driver:0:cairo:102:pscairo\n"
156 #if defined ( PLD_epscairo )
157 "epscairo:Cairo EPS Driver:0:cairo:103:epscairo\n"
159 #if defined ( PLD_svgcairo )
160 "svgcairo:Cairo SVG Driver:0:cairo:104:svgcairo\n"
162 #if defined ( PLD_pngcairo )
163 "pngcairo:Cairo PNG Driver:0:cairo:105:pngcairo\n"
165 #if defined ( PLD_memcairo )
166 "memcairo:Cairo Memory Driver:0:cairo:106:memcairo\n"
168 #if defined ( PLD_extcairo )
169 "extcairo:Cairo External Context Driver:0:cairo:107:extcairo\n"
171 #if defined ( PLD_wincairo )
172 "wincairo:Cairo Microscoft Windows Driver:0:cairo:108:wincairo\n"
180 #if defined ( PLD_xcairo )
185 } PLXcairoDrawableInfo;
193 #define NPANGOLOOKUP 5
204 "PLPLOT_FREETYPE_SANS_FAMILY",
205 "PLPLOT_FREETYPE_SERIF_FAMILY",
206 "PLPLOT_FREETYPE_MONO_FAMILY",
207 "PLPLOT_FREETYPE_SCRIPT_FAMILY",
208 "PLPLOT_FREETYPE_SYMBOL_FAMILY"
211 #define FAMILY_LOOKUP_LEN 1024
242 cairo_status_t
write_to_stream(
void *,
unsigned char *,
unsigned int );
298 cairo_surface_t *tmp_sfc;
299 cairo_t *tmp_context;
314 cairo_image_surface_create( CAIRO_FORMAT_ARGB32,
342 cairo_surface_t *tmp_sfc;
343 cairo_t *tmp_context;
357 plexit(
"Can not plot to a Cairo device with no context" );
395 if ( (
double) pls->
cmap0[0].
a < 1.0 )
397 cairo_set_source_rgba( aStream->
cairoContext, 1.0, 1.0, 1.0, 1.0 );
401 (
double) pls->
cmap0[0].
r / 255.0,
402 (
double) pls->
cmap0[0].
g / 255.0,
403 (
double) pls->
cmap0[0].
b / 255.0,
404 (
double) pls->
cmap0[0].
a );
594 cairo_set_operator( aStream->
cairoContext, CAIRO_OPERATOR_OVER );
597 cairo_set_operator( aStream->
cairoContext, CAIRO_OPERATOR_SOURCE );
600 cairo_set_operator( aStream->
cairoContext, CAIRO_OPERATOR_XOR );
622 case CAIRO_OPERATOR_OVER:
625 case CAIRO_OPERATOR_SOURCE:
628 case CAIRO_OPERATOR_XOR:
713 if ( aStream->
upDown < 0 )
729 if ( aStream->
upDown > 0 )
755 int textXExtent, textYExtent, baseline;
756 PLFLT rotation, shear, stride, cos_rot, sin_rot, cos_shear, sin_shear;
757 cairo_matrix_t *cairoTransformMatrix;
758 cairo_font_options_t *cairoFontOptions;
759 PangoContext *context;
773 layout = pango_cairo_create_layout( aStream->
cairoContext );
775 pango_layout_get_pixel_size( layout, &textXExtent, &textYExtent );
776 baseline = pango_layout_get_baseline( layout );
786 context = pango_layout_get_context( layout );
787 cairoFontOptions = cairo_font_options_create();
789 pango_cairo_context_set_font_options( context, cairoFontOptions );
790 pango_layout_context_changed( layout );
791 cairo_font_options_destroy( cairoFontOptions );
806 cairoTransformMatrix = (cairo_matrix_t *) malloc(
sizeof ( cairo_matrix_t ) );
807 cairo_matrix_init( cairoTransformMatrix, 1.0, 0.0, 0.0, -1.0, 0.0, 0.0 );
808 cairo_transform( aStream->
cairoContext, cairoTransformMatrix );
814 cos_rot = cos( rotation );
815 sin_rot = sin( rotation );
816 cos_shear = cos( shear );
817 sin_shear = sin( shear );
820 cairo_matrix_init( cairoTransformMatrix,
823 cos_rot * sin_shear + sin_rot * cos_shear,
824 -sin_rot * sin_shear + cos_rot * cos_shear,
826 cairo_transform( aStream->
cairoContext, cairoTransformMatrix );
827 free( cairoTransformMatrix );
832 (
double) ( -1.0 * args->
just * (
double) textXExtent ),
833 (
double) 0.5 * aStream->
fontSize - baseline / 1024.0 );
836 pango_cairo_show_layout( aStream->
cairoContext, layout );
843 g_object_unref( layout );
856 int textXExtent, textYExtent, baseline;
857 char *textWithPangoMarkup;
858 PLFLT rotation, shear, stride, cos_rot, sin_rot, cos_shear, sin_shear;
859 cairo_matrix_t *cairoTransformMatrix;
860 cairo_font_options_t *cairoFontOptions;
861 PangoContext *context;
872 printf(
"Non unicode string passed to a cairo driver, ignoring\n" );
879 printf(
"Sorry, the cairo drivers only handles strings of length < %d\n",
MAX_STRING_LEN );
884 fontSize = (float) ( pls->
chrht *
DPI / 25.4 );
890 layout = pango_cairo_create_layout( aStream->
cairoContext );
891 pango_layout_set_markup( layout, textWithPangoMarkup, -1 );
892 pango_layout_get_pixel_size( layout, &textXExtent, &textYExtent );
893 baseline = pango_layout_get_baseline( layout );
903 context = pango_layout_get_context( layout );
904 cairoFontOptions = cairo_font_options_create();
906 pango_cairo_context_set_font_options( context, cairoFontOptions );
907 pango_layout_context_changed( layout );
908 cairo_font_options_destroy( cairoFontOptions );
923 cairoTransformMatrix = (cairo_matrix_t *) malloc(
sizeof ( cairo_matrix_t ) );
924 cairo_matrix_init( cairoTransformMatrix, 1.0, 0.0, 0.0, -1.0, 0.0, 0.0 );
925 cairo_transform( aStream->
cairoContext, cairoTransformMatrix );
931 cos_rot = cos( rotation );
932 sin_rot = sin( rotation );
933 cos_shear = cos( shear );
934 sin_shear = sin( shear );
937 cairo_matrix_init( cairoTransformMatrix,
940 cos_rot * sin_shear + sin_rot * cos_shear,
941 -sin_rot * sin_shear + cos_rot * cos_shear,
943 cairo_transform( aStream->
cairoContext, cairoTransformMatrix );
944 free( cairoTransformMatrix );
949 (
double) ( -1.0 * args->
just * (
double) textXExtent ),
950 (
double) 0.5 * fontSize - baseline / 1024.0 );
953 pango_cairo_show_layout( aStream->
cairoContext, layout );
959 g_object_unref( layout );
960 free( textWithPangoMarkup );
979 char *pangoMarkupString;
980 PLFLT old_sscale, sscale, old_soffset, soffset;
984 pangoMarkupString = (
char *) malloc(
sizeof (
char ) *
MAX_MARKUP_LEN );
987 pangoMarkupString[i] = 0;
999 while ( i < ucs4Len )
1002 if ( strlen( pangoMarkupString ) > ( MAX_MARKUP_LEN - 50 ) )
1013 strncat( pangoMarkupString,
"&", MAX_MARKUP_LEN - 1 - strlen( pangoMarkupString ) );
1016 strncat( pangoMarkupString,
"<", MAX_MARKUP_LEN - 1 - strlen( pangoMarkupString ) );
1019 strncat( pangoMarkupString,
">", MAX_MARKUP_LEN - 1 - strlen( pangoMarkupString ) );
1023 strncat( pangoMarkupString, utf8, MAX_MARKUP_LEN - 1 - strlen( pangoMarkupString ) );
1033 strncat( pangoMarkupString, utf8, MAX_MARKUP_LEN - 1 - strlen( pangoMarkupString ) );
1043 strncat( pangoMarkupString,
"</span>", MAX_MARKUP_LEN - 1 - strlen( pangoMarkupString ) );
1049 &old_sscale, &sscale, &old_soffset, &soffset );
1050 strncat( pangoMarkupString,
1052 MAX_MARKUP_LEN - 1 - strlen( pangoMarkupString ) );
1060 strncat( pangoMarkupString,
"</span>", MAX_MARKUP_LEN - 1 - strlen( pangoMarkupString ) );
1066 &old_sscale, &sscale, &old_soffset, &soffset );
1067 strncat( pangoMarkupString,
1069 MAX_MARKUP_LEN - 1 - strlen( pangoMarkupString ) );
1079 open_span_tag( pangoMarkupString, ucs4[i], fontSize, upDown );
1089 return pangoMarkupString;
1103 unsigned char fontFamily, fontStyle, fontWeight;
1106 PLFLT old_sscale, sscale, old_soffset, soffset;
1118 strncat( pangoMarkupString, openTag,
MAX_MARKUP_LEN - 1 - strlen( pangoMarkupString ) );
1121 strncat( pangoMarkupString, openTag,
MAX_MARKUP_LEN - 1 - strlen( pangoMarkupString ) );
1124 strncat( pangoMarkupString, openTag,
MAX_MARKUP_LEN - 1 - strlen( pangoMarkupString ) );
1127 for ( upDown_level = 0; upDown_level < upDown; upDown_level++ )
1130 &old_sscale, &sscale, &old_soffset, &soffset );
1131 strncat( pangoMarkupString,
1135 for ( upDown_level = 0; upDown_level > upDown; upDown_level-- )
1138 &old_sscale, &sscale, &old_soffset, &soffset );
1139 strncat( pangoMarkupString,
1155 while ( upDown > 0 )
1157 strncat( pangoMarkupString,
"</span>",
MAX_MARKUP_LEN - 1 - strlen( pangoMarkupString ) );
1163 while ( upDown < 0 )
1165 strncat( pangoMarkupString,
"</span>",
MAX_MARKUP_LEN - 1 - strlen( pangoMarkupString ) );
1170 strncat( pangoMarkupString,
"</span>",
MAX_MARKUP_LEN - 1 - strlen( pangoMarkupString ) );
1178 # define RISE_FACTOR 0.8
1191 char *
rise_span_tag(
int ifsuperscript,
float fontSize,
float multiplier,
float rise )
1194 static char tag[100];
1201 rise = 1024.f * fontSize * (float)
RISE_FACTOR * rise;
1206 offset = 1024.f * 0.5f * fontSize * ( 1.0f - multiplier );
1208 if ( ifsuperscript )
1210 sprintf( tag,
"<span rise=\"%d\" size=\"%d\">",
1211 (
int) ( rise + offset ), (
int) ( fontSize * 1024. * multiplier ) );
1215 sprintf( tag,
"<span rise=\"%d\" size=\"%d\">",
1216 (
int) -( rise - offset ), (
int) ( fontSize * 1024. * multiplier ) );
1229 cairo_status_t
write_to_stream(
void *filePointer,
unsigned char *data,
unsigned int length )
1231 unsigned int bytes_written;
1233 bytes_written = (
unsigned int) fwrite( data, 1, (
size_t) length, (FILE *) filePointer );
1234 if ( bytes_written == length )
1236 return CAIRO_STATUS_SUCCESS;
1240 return CAIRO_STATUS_WRITE_ERROR;
1262 pls->
termin = interactive;
1308 aStream = malloc(
sizeof (
PLCairo ) );
1309 #if defined ( PLD_xcairo )
1310 aStream->XDisplay = NULL;
1311 aStream->XWindow = 0;
1364 if ( pls->
width <= 0. )
1392 for ( i = 1; i < npts; i++ )
1421 if ( cairo_get_antialias( aStream->
cairoContext ) != CAIRO_ANTIALIAS_NONE )
1455 cairo_pattern_t *linear_gradient;
1462 linear_gradient = cairo_pattern_create_linear(
1468 cairo_pattern_reference( linear_gradient );
1469 for ( i = 0; i < pls->
ncol1; i++ )
1471 cairo_pattern_add_color_stop_rgba( linear_gradient,
1472 (
double) i / (
double) ( pls->
ncol1 - 1 ),
1473 (
double) pls->
cmap1[i].
r / 255.,
1474 (
double) pls->
cmap1[i].
g / 255.,
1475 (
double) pls->
cmap1[i].
b / 255.,
1476 (
double) pls->
cmap1[i].
a );
1482 cairo_set_source( aStream->
cairoContext, linear_gradient );
1484 cairo_pattern_destroy( linear_gradient );
1497 PLINT rcx[4], rcy[4];
1548 plwarn(
"All pages after the first skipped because family file output not specified.\n" );
1564 double angle1, angle2, rotate;
1591 cairo_arc( aStream->
cairoContext, 0.0, 0.0, 1.0, angle1, angle2 );
1592 if ( arc_info->
fill )
1601 if ( arc_info->
fill )
1620 cairo_matrix_t *matrix;
1625 matrix = (cairo_matrix_t *) malloc(
sizeof ( cairo_matrix_t ) );
1626 cairo_matrix_init( matrix, x11, x12, x21, x22, x0, y0 );
1627 #if defined ( PLD_xcairo )
1630 cairo_transform( aStream->cairoContext_X, matrix );
1649 #if defined ( PLD_pngcairo ) || defined ( PLD_svgcairo ) || defined ( PLD_epscairo )
1651 void plD_bop_cairo_fam(
PLStream * );
1652 void plD_eop_cairo_fam(
PLStream * );
1655 void plD_tidy_cairo_fam(
PLStream * );
1656 void plD_line_cairo_fam(
PLStream *,
short,
short,
short,
short );
1657 void plD_polyline_cairo_fam(
PLStream *,
short *,
short *,
PLINT );
1665 void plD_bop_cairo_fam(
PLStream *pls )
1687 (
double) pls->
cmap0[0].
r / 255.0,
1688 (
double) pls->
cmap0[0].
g / 255.0,
1689 (
double) pls->
cmap0[0].
b / 255.0,
1690 (
double) pls->
cmap0[0].
a );
1700 void plD_eop_cairo_fam(
PLStream *pls )
1732 void plD_esc_cairo_fam(
PLStream *pls,
PLINT op,
void *ptr )
1748 void plD_tidy_cairo_fam(
PLStream *pls )
1759 void plD_line_cairo_fam(
PLStream *pls,
short x1a,
short y1a,
short x2a,
short y2a )
1775 void plD_polyline_cairo_fam(
PLStream *pls,
short *xa,
short *ya,
PLINT npts )
1794 #if defined ( PLD_xcairo )
1797 static Window rootWindow;
1800 void plD_init_xcairo(
PLStream * );
1803 void plD_tidy_xcairo(
PLStream * );
1815 #ifndef ENABLE_DYNDRIVERS
1843 static signed int xcairo_init_cairo(
PLStream *pls )
1846 Visual *defaultVisual;
1851 defaultVisual = DefaultVisual( aStream->XDisplay, 0 );
1854 aStream->cairoSurface_X = cairo_xlib_surface_create( aStream->XDisplay, aStream->XWindow, defaultVisual, pls->
xlength, pls->
ylength );
1855 aStream->cairoContext_X = cairo_create( aStream->cairoSurface_X );
1859 aStream->
cairoSurface = cairo_surface_create_similar( aStream->cairoSurface_X, CAIRO_CONTENT_COLOR_ALPHA, pls->
xlength, pls->
ylength );
1866 cairo_image_surface_create( CAIRO_FORMAT_ARGB32,
1879 cairo_set_fill_rule( aStream->
cairoContext, CAIRO_FILL_RULE_EVEN_ODD );
1881 cairo_set_fill_rule( aStream->
cairoContext, CAIRO_FILL_RULE_WINDING );
1885 cairo_rectangle( aStream->cairoContext_X, 0.0, 0.0, pls->
xlength, pls->
ylength );
1886 cairo_set_source_rgba( aStream->cairoContext_X,
1887 (
double) pls->
cmap0[0].
r / 255.0,
1888 (
double) pls->
cmap0[0].
g / 255.0,
1889 (
double) pls->
cmap0[0].
b / 255.0,
1890 (
double) pls->
cmap0[0].
a );
1891 cairo_fill( aStream->cairoContext_X );
1893 XFlush( aStream->XDisplay );
1904 void plD_init_xcairo(
PLStream *pls )
1918 aStream->xdrawable_mode = 1;
1923 aStream->XDisplay = NULL;
1924 aStream->XDisplay = XOpenDisplay( NULL );
1925 if ( aStream->XDisplay == NULL )
1927 printf(
"Failed to open X Windows display\n" );
1930 XScreen = DefaultScreen( aStream->XDisplay );
1931 rootWindow = RootWindow( aStream->XDisplay, XScreen );
1933 aStream->XWindow = XCreateSimpleWindow( aStream->XDisplay, rootWindow, 0, 0, (
unsigned int) pls->
xlength, (
unsigned int) pls->
ylength,
1934 1, BlackPixel( aStream->XDisplay, XScreen ), BlackPixel( aStream->XDisplay, XScreen ) );
1935 XStoreName( aStream->XDisplay, aStream->XWindow, pls->
plwindow );
1936 XSelectInput( aStream->XDisplay, aStream->XWindow, NoEventMask );
1937 XMapWindow( aStream->XDisplay, aStream->XWindow );
1938 aStream->xdrawable_mode = 0;
1940 wmDelete = XInternAtom( aStream->XDisplay,
"WM_DELETE_WINDOW", True );
1941 XSetWMProtocols( aStream->XDisplay, aStream->XWindow, &wmDelete, 1 );
1943 xcairo_init_cairo( pls );
1946 aStream->exit_event_loop = 0;
1966 cairo_set_operator( aStream->
cairoContext, CAIRO_OPERATOR_DEST_OVER );
1968 (
double) pls->
cmap0[0].
r / 255.0,
1969 (
double) pls->
cmap0[0].
g / 255.0,
1970 (
double) pls->
cmap0[0].
b / 255.0,
1971 (
double) pls->
cmap0[0].
a );
1975 cairo_save( aStream->cairoContext_X );
1977 cairo_rectangle( aStream->cairoContext_X, x, y, w, h );
1978 cairo_set_operator( aStream->cairoContext_X, CAIRO_OPERATOR_SOURCE );
1979 cairo_set_source_surface( aStream->cairoContext_X,
1981 cairo_fill( aStream->cairoContext_X );
1982 cairo_restore( aStream->cairoContext_X );
1991 void plD_bop_xcairo(
PLStream *pls )
1999 if ( aStream->xdrawable_mode )
2002 XFlush( aStream->XDisplay );
2011 void plD_eop_xcairo(
PLStream *pls )
2015 char event_string[10];
2019 XExposeEvent *expose;
2027 if ( aStream->xdrawable_mode )
2032 aStream->exit_event_loop = 1;
2035 event_mask = ButtonPressMask | KeyPressMask | ExposureMask;
2036 XSelectInput( aStream->XDisplay, aStream->XWindow, event_mask );
2037 while ( !aStream->exit_event_loop )
2040 XNextEvent( aStream->XDisplay, &event );
2041 switch ( event.type )
2044 number_chars = XLookupString( (XKeyEvent *) &event, event_string, 10, &keysym, &cs );
2045 event_string[number_chars] =
'\0';
2046 if ( keysym == XK_Return )
2048 aStream->exit_event_loop = 1;
2052 if ( ( (XButtonEvent *) &event )->button == Button3 )
2053 aStream->exit_event_loop = 1;
2058 aStream->exit_event_loop = 1;
2063 expose = (XExposeEvent *) &event;
2064 if ( expose->count == 0 )
2067 expose->
width, expose->height );
2072 aStream->exit_event_loop = 0;
2081 void plD_tidy_xcairo(
PLStream *pls )
2090 cairo_destroy( aStream->cairoContext_X );
2091 cairo_surface_destroy( aStream->cairoSurface_X );
2093 if ( aStream->xdrawable_mode )
2097 XFlush( aStream->XDisplay );
2099 XDestroyWindow( aStream->XDisplay, aStream->XWindow );
2101 XCloseDisplay( aStream->XDisplay );
2120 XFlush( aStream->XDisplay );
2124 XFlush( aStream->XDisplay );
2129 PLXcairoDrawableInfo *xinfo = (PLXcairoDrawableInfo *) ptr;
2131 unsigned int w, h, b, d;
2132 if ( xinfo == NULL )
2134 printf(
"xcairo: PLESC_DEVINIT ignored, no drawable info provided\n" );
2137 if ( aStream->xdrawable_mode == 0 )
2139 printf(
"xcairo: PLESC_DEVINIT called with drawable but stream not in xdrawable mode\n" );
2142 aStream->XDisplay = xinfo->display;
2143 aStream->XWindow = xinfo->drawable;
2146 XGetGeometry( aStream->XDisplay, aStream->XWindow, &rootwin,
2147 &x, &y, &w, &h, &b, &d );
2154 xcairo_init_cairo( pls );
2179 XButtonEvent *xButtonEvent;
2189 xHairCursor = XCreateFontCursor( aStream->XDisplay, XC_crosshair );
2190 XDefineCursor( aStream->XDisplay, aStream->XWindow, xHairCursor );
2193 XSelectInput( aStream->XDisplay, aStream->XWindow, ButtonPressMask | ButtonReleaseMask | KeyPressMask | KeyReleaseMask | ButtonMotionMask );
2194 XMaskEvent( aStream->XDisplay, ButtonPressMask | ButtonReleaseMask | KeyPressMask | KeyReleaseMask | ButtonMotionMask, &event );
2195 XSelectInput( aStream->XDisplay, aStream->XWindow, NoEventMask );
2198 xButtonEvent = (XButtonEvent *) &event;
2199 gin->
state = xButtonEvent->state;
2200 gin->
button = xButtonEvent->button;
2201 gin->
pX =
event.xbutton.x;
2202 gin->
pY = pls->
ylength -
event.xbutton.y;
2207 if ( event.type == KeyPress || event.type == KeyRelease )
2209 XLookupString( (XKeyEvent *) &event, str, 100, &keysym, NULL );
2210 if ( keysym == NoSymbol )
2211 ksname =
"NoSymbol";
2212 else if ( !( ksname = XKeysymToString( keysym ) ) )
2213 ksname =
"(no name)";
2214 strcpy( gin->
string, ksname );
2224 gin->
keysym = 0xFF & keysym;
2227 gin->
keysym = (
unsigned int) keysym;
2237 XUndefineCursor( aStream->XDisplay, aStream->XWindow );
2238 XFlush( aStream->XDisplay );
2252 #if defined ( PLD_pdfcairo )
2255 void plD_init_pdfcairo(
PLStream * );
2266 #ifndef ENABLE_DYNDRIVERS
2288 void plD_init_pdfcairo(
PLStream *pls )
2314 cairo_set_fill_rule( aStream->
cairoContext, CAIRO_FILL_RULE_EVEN_ODD );
2316 cairo_set_fill_rule( aStream->
cairoContext, CAIRO_FILL_RULE_WINDING );
2330 #if defined ( PLD_pscairo )
2333 void plD_init_pscairo(
PLStream * );
2344 #ifndef ENABLE_DYNDRIVERS
2366 void plD_init_pscairo(
PLStream *pls )
2394 cairo_set_fill_rule( aStream->
cairoContext, CAIRO_FILL_RULE_EVEN_ODD );
2396 cairo_set_fill_rule( aStream->
cairoContext, CAIRO_FILL_RULE_WINDING );
2410 #if defined ( PLD_epscairo )
2413 void plD_init_epscairo(
PLStream * );
2424 #ifndef ENABLE_DYNDRIVERS
2446 void plD_init_epscairo(
PLStream *pls )
2461 if ( pls->
dev == NULL )
2498 cairo_set_fill_rule( aStream->
cairoContext, CAIRO_FILL_RULE_EVEN_ODD );
2500 cairo_set_fill_rule( aStream->
cairoContext, CAIRO_FILL_RULE_WINDING );
2514 #if defined ( PLD_svgcairo )
2517 void plD_init_svgcairo(
PLStream * );
2528 #ifndef ENABLE_DYNDRIVERS
2550 void plD_init_svgcairo(
PLStream *pls )
2565 if ( pls->
dev == NULL )
2597 cairo_set_fill_rule( aStream->
cairoContext, CAIRO_FILL_RULE_EVEN_ODD );
2599 cairo_set_fill_rule( aStream->
cairoContext, CAIRO_FILL_RULE_WINDING );
2613 #if defined ( PLD_pngcairo )
2616 void plD_init_pngcairo(
PLStream * );
2617 void plD_eop_pngcairo(
PLStream * );
2628 #ifndef ENABLE_DYNDRIVERS
2650 void plD_init_pngcairo(
PLStream *pls )
2665 if ( pls->
dev == NULL )
2697 cairo_set_fill_rule( aStream->
cairoContext, CAIRO_FILL_RULE_EVEN_ODD );
2699 cairo_set_fill_rule( aStream->
cairoContext, CAIRO_FILL_RULE_WINDING );
2708 void plD_eop_pngcairo(
PLStream *pls )
2732 #if defined ( PLD_memcairo )
2735 void plD_init_memcairo(
PLStream * );
2736 void plD_eop_memcairo(
PLStream * );
2737 void plD_bop_memcairo(
PLStream * );
2748 #ifndef ENABLE_DYNDRIVERS
2781 void plD_init_memcairo(
PLStream *pls )
2785 unsigned char *cairo_mem;
2786 unsigned char *input_mem;
2792 char testByte[
sizeof ( int )];
2794 endianTest.testWord = 1;
2806 if ( endianTest.testByte[0] == 1 )
2807 aStream->bigendian = 0;
2809 aStream->bigendian = 1;
2812 if ( pls->
dev == NULL )
2814 plexit(
"Must call plsmem first to set user plotting area!" );
2818 aStream->memory = pls->
dev;
2828 aStream->cairo_format_memory = (
unsigned char *) calloc( (
size_t) ( stride * pls->
ylength ), 1 );
2831 cairo_mem = aStream->cairo_format_memory;
2832 input_mem = aStream->memory;
2838 if ( aStream->bigendian )
2842 cairo_mem[1] = input_mem[0];
2843 cairo_mem[2] = input_mem[1];
2844 cairo_mem[3] = input_mem[2];
2847 cairo_mem[0] = input_mem[3];
2861 cairo_mem[2] = input_mem[0];
2862 cairo_mem[1] = input_mem[1];
2863 cairo_mem[0] = input_mem[2];
2866 cairo_mem[3] = input_mem[3];
2881 cairo_image_surface_create_for_data( aStream->cairo_format_memory, CAIRO_FORMAT_RGB24, pls->
xlength, pls->
ylength, stride );
2896 cairo_set_fill_rule( aStream->
cairoContext, CAIRO_FILL_RULE_EVEN_ODD );
2898 cairo_set_fill_rule( aStream->
cairoContext, CAIRO_FILL_RULE_WINDING );
2908 void plD_eop_memcairo(
PLStream *pls )
2911 unsigned char *memory;
2912 unsigned char *cairo_surface_data;
2916 memory = aStream->memory;
2917 cairo_surface_data = cairo_image_surface_get_data( aStream->
cairoSurface );
2921 if ( aStream->bigendian )
2925 memory[0] = cairo_surface_data[1];
2926 memory[1] = cairo_surface_data[2];
2927 memory[2] = cairo_surface_data[3];
2930 memory[3] = cairo_surface_data[0];
2937 cairo_surface_data += 4;
2944 memory[0] = cairo_surface_data[2];
2945 memory[1] = cairo_surface_data[1];
2946 memory[2] = cairo_surface_data[0];
2949 memory[3] = cairo_surface_data[3];
2956 cairo_surface_data += 4;
2961 free( aStream->cairo_format_memory );
2974 #if defined ( PLD_extcairo )
2976 void extcairo_setbackground(
PLStream * );
2978 void plD_init_extcairo(
PLStream * );
2979 void plD_bop_extcairo(
PLStream * );
2980 void plD_eop_extcairo(
PLStream * );
2982 void plD_tidy_extcairo(
PLStream * );
2990 void extcairo_setbackground(
PLStream *pls )
3001 (
double) pls->
cmap0[0].
r / 255.0,
3002 (
double) pls->
cmap0[0].
g / 255.0,
3003 (
double) pls->
cmap0[0].
b / 255.0,
3004 (
double) pls->
cmap0[0].
a );
3018 #ifndef ENABLE_DYNDRIVERS
3019 pdt->
pl_MenuStr =
"Cairo external context driver";
3040 void plD_init_extcairo(
PLStream *pls )
3057 void plD_bop_extcairo(
PLStream *pls )
3066 extcairo_setbackground( pls );
3111 extcairo_setbackground( pls );
3116 cairo_set_fill_rule( aStream->
cairoContext, CAIRO_FILL_RULE_EVEN_ODD );
3118 cairo_set_fill_rule( aStream->
cairoContext, CAIRO_FILL_RULE_WINDING );
3151 #if defined ( PLD_wincairo )
3153 static char* szWndClass =
"PLplot WinCairo";
3156 void plD_init_wincairo(
PLStream * );
3158 void plD_eop_wincairo(
PLStream * );
3160 void plD_tidy_wincairo(
PLStream * );
3168 void blit_to_win(
PLCairo *aStream )
3170 cairo_set_source_surface( aStream->cairoContext_win, aStream->
cairoSurface, 0.0, 0.0 );
3171 cairo_paint( aStream->cairoContext_win );
3180 LRESULT CALLBACK PlplotCairoWndProc( HWND hwnd, UINT nMsg, WPARAM wParam, LPARAM lParam )
3195 if ( nMsg == WM_CREATE )
3201 pls = (
PLStream *) GetWindowLong( hwnd, GWL_USERDATA );
3223 PostQuitMessage( 0 );
3233 GetClientRect( dev->hwnd, &dev->rect );
3237 case WM_ENTERSIZEMOVE:
3241 case WM_EXITSIZEMOVE:
3248 dev->oldcolour = SetBkColor( dev->hdc, RGB( pls->
cmap0[0].
r, pls->
cmap0[0].
g, pls->
cmap0[0].
b ) );
3249 ExtTextOut( dev->hdc, 0, 0, ETO_OPAQUE, &dev->rect,
"", 0, 0 );
3250 SetBkColor( dev->hdc, dev->oldcolour );
3262 return DefWindowProc( hwnd, nMsg, wParam, lParam );
3280 while ( GetMessage( &aStream->msg, NULL, 0, 0 ) && !located )
3282 TranslateMessage( &aStream->msg );
3284 switch ( (
int) aStream->msg.message )
3287 case WM_LBUTTONDOWN:
3290 gin->
pX = LOWORD( aStream->msg.lParam );
3291 gin->
pY = pls->
ylength - HIWORD( aStream->msg.lParam );
3296 gin->
keysym = aStream->msg.wParam;
3301 DispatchMessage( &aStream->msg );
3316 #ifndef ENABLE_DYNDRIVERS
3317 pdt->
pl_MenuStr =
"Cairo Microsoft Windows driver";
3338 void plD_init_wincairo(
PLStream *pls )
3349 memset( &aStream->wndclass, 0, sizeof ( WNDCLASSEX ) );
3352 aStream->wndclass.lpszClassName = szWndClass;
3355 aStream->wndclass.cbSize =
sizeof ( WNDCLASSEX );
3358 aStream->wndclass.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS | CS_OWNDC | CS_PARENTDC;
3361 aStream->wndclass.lpfnWndProc = PlplotCairoWndProc;
3365 aStream->wndclass.hInstance = GetModuleHandle( NULL );
3368 aStream->wndclass.hIcon = LoadIcon( NULL, IDI_APPLICATION );
3369 aStream->wndclass.hIconSm = LoadIcon( NULL, IDI_APPLICATION );
3370 aStream->wndclass.hCursor = LoadCursor( NULL, IDC_ARROW );
3372 aStream->wndclass.hbrBackground = NULL;
3374 aStream->wndclass.cbWndExtra =
sizeof ( pls );
3381 RegisterClassEx( &aStream->wndclass );
3386 aStream->hwnd = CreateWindowEx( WS_EX_WINDOWEDGE + WS_EX_LEFT,
3389 WS_OVERLAPPEDWINDOW,
3397 aStream->wndclass.hInstance,
3408 SetWindowLong( aStream->hwnd, GWL_USERDATA, (
long) pls );
3409 aStream->SCRN_hdc = aStream->hdc = GetDC( aStream->hwnd );
3428 ShowWindow( aStream->hwnd, SW_SHOWDEFAULT );
3429 SetForegroundWindow( aStream->hwnd );
3449 aStream->cairoSurface_win = (cairo_surface_t *) cairo_win32_surface_create( aStream->hdc );
3450 aStream->cairoContext_win = cairo_create( aStream->cairoSurface_win );
3464 cairo_set_fill_rule( aStream->
cairoContext, CAIRO_FILL_RULE_EVEN_ODD );
3466 cairo_set_fill_rule( aStream->
cairoContext, CAIRO_FILL_RULE_WINDING );
3482 while ( GetMessage( &aStream->msg, NULL, 0, 0 ) )
3484 TranslateMessage( &aStream->msg );
3485 switch ( (
int) aStream->msg.message )
3488 if ( ( (TCHAR) ( aStream->msg.wParam ) == 13 ) ||
3489 ( (TCHAR) ( aStream->msg.wParam ) ==
'q' ) ||
3490 ( (TCHAR) ( aStream->msg.wParam ) ==
'Q' ) )
3492 PostQuitMessage( 0 );
3497 DispatchMessage( &aStream->msg );
3510 void plD_tidy_wincairo(
PLStream *pls )
3517 cairo_destroy( aStream->cairoContext_win );
3518 cairo_surface_destroy( aStream->cairoSurface_win );
3520 if ( aStream != NULL )
3522 if ( aStream->hdc != NULL )
3523 ReleaseDC( aStream->hwnd, aStream->hdc );
3543 InvalidateRect( aStream->hwnd, NULL,
TRUE );