From: <hba...@us...> - 2010-03-23 19:53:04
|
Revision: 10880 http://plplot.svn.sourceforge.net/plplot/?rev=10880&view=rev Author: hbabcock Date: 2010-03-23 19:52:58 +0000 (Tue, 23 Mar 2010) Log Message: ----------- Tweak xcairo driver so that button and keypress handling more exactly matched that of xev. Modified Paths: -------------- trunk/drivers/cairo.c Modified: trunk/drivers/cairo.c =================================================================== --- trunk/drivers/cairo.c 2010-03-23 19:29:55 UTC (rev 10879) +++ trunk/drivers/cairo.c 2010-03-23 19:52:58 UTC (rev 10880) @@ -1926,12 +1926,21 @@ XDefineCursor( aStream->XDisplay, aStream->XWindow, xHairCursor ); /* Get the next mouse button release or key press event */ - XSelectInput( aStream->XDisplay, aStream->XWindow, ButtonReleaseMask | KeyPressMask ); - XMaskEvent( aStream->XDisplay, ButtonReleaseMask | KeyPressMask, &event ); + XSelectInput( aStream->XDisplay, aStream->XWindow, ButtonPressMask | ButtonReleaseMask | KeyPressMask | KeyReleaseMask ); + XMaskEvent( aStream->XDisplay, ButtonPressMask | ButtonReleaseMask | KeyPressMask | KeyReleaseMask, &event ); XSelectInput( aStream->XDisplay, aStream->XWindow, NoEventMask ); + /* Update PLplot's mouse event structure */ + xButtonEvent = (XButtonEvent *) &event; + gin->state = xButtonEvent->state; + gin->button = xButtonEvent->button; + gin->pX = event.xbutton.x; + gin->pY = pls->ylength - event.xbutton.y; + gin->dX = (PLFLT) event.xbutton.x / ( (PLFLT) ( pls->xlength ) ); + gin->dY = (PLFLT) ( pls->ylength - event.xbutton.y ) / ( (PLFLT) ( pls->ylength ) ); + /* Get key pressed (if any) */ - if ( event.type == KeyPress ) + if ( event.type == KeyPress || event.type == KeyRelease ) { number_chars = XLookupString( (XKeyEvent *) &event, str, 100, &keysym, NULL ); if (keysym == NoSymbol) @@ -1954,21 +1963,12 @@ gin->keysym = keysym; } } - else + else // button press { - gin->string[0] = '\0'; - gin->keysym = 0x20; + sprintf(gin->string, "button %u", gin->button); + gin->keysym = 0x20; } - /* Update PLplot's mouse event structure */ - xButtonEvent = (XButtonEvent *) &event; - gin->state = xButtonEvent->state; - gin->button = xButtonEvent->button; - gin->pX = event.xbutton.x; - gin->pY = pls->ylength - event.xbutton.y; - gin->dX = (PLFLT) event.xbutton.x / ( (PLFLT) ( pls->xlength ) ); - gin->dY = (PLFLT) ( pls->ylength - event.xbutton.y ) / ( (PLFLT) ( pls->ylength ) ); - /* Switch back to normal cursor */ XUndefineCursor( aStream->XDisplay, aStream->XWindow ); XFlush( aStream->XDisplay ); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <and...@us...> - 2010-05-11 14:18:44
|
Revision: 10987 http://plplot.svn.sourceforge.net/plplot/?rev=10987&view=rev Author: andrewross Date: 2010-05-11 14:18:39 +0000 (Tue, 11 May 2010) Log Message: ----------- Update xcairo driver to return mouse move (drag) events in calls to plGetCursor. Modified Paths: -------------- trunk/drivers/cairo.c Modified: trunk/drivers/cairo.c =================================================================== --- trunk/drivers/cairo.c 2010-05-11 14:18:00 UTC (rev 10986) +++ trunk/drivers/cairo.c 2010-05-11 14:18:39 UTC (rev 10987) @@ -1926,8 +1926,8 @@ XDefineCursor( aStream->XDisplay, aStream->XWindow, xHairCursor ); /* Get the next mouse button release or key press event */ - XSelectInput( aStream->XDisplay, aStream->XWindow, ButtonPressMask | ButtonReleaseMask | KeyPressMask | KeyReleaseMask ); - XMaskEvent( aStream->XDisplay, ButtonPressMask | ButtonReleaseMask | KeyPressMask | KeyReleaseMask, &event ); + XSelectInput( aStream->XDisplay, aStream->XWindow, ButtonPressMask | ButtonReleaseMask | KeyPressMask | KeyReleaseMask | ButtonMotionMask ); + XMaskEvent( aStream->XDisplay, ButtonPressMask | ButtonReleaseMask | KeyPressMask | KeyReleaseMask | ButtonMotionMask, &event ); XSelectInput( aStream->XDisplay, aStream->XWindow, NoEventMask ); /* Update PLplot's mouse event structure */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <hba...@us...> - 2010-05-22 19:55:33
|
Revision: 11019 http://plplot.svn.sourceforge.net/plplot/?rev=11019&view=rev Author: hbabcock Date: 2010-05-22 19:55:27 +0000 (Sat, 22 May 2010) Log Message: ----------- Add code to the xcairo driver to detect and handle WM_DELETE_WINDOW client messages (i.e. pressing the window close button), consistent with xwin and qtwidget drivers. Modified Paths: -------------- trunk/drivers/cairo.c Modified: trunk/drivers/cairo.c =================================================================== --- trunk/drivers/cairo.c 2010-05-22 17:33:13 UTC (rev 11018) +++ trunk/drivers/cairo.c 2010-05-22 19:55:27 UTC (rev 11019) @@ -1654,6 +1654,7 @@ void plD_init_xcairo( PLStream *pls ) { PLCairo *aStream; + Atom wmDelete; /* Setup the PLStream and the font lookup table. */ aStream = stream_and_font_setup( pls, 1 ); @@ -1686,6 +1687,9 @@ XMapWindow( aStream->XDisplay, aStream->XWindow ); aStream->xdrawable_mode = 0; + wmDelete = XInternAtom( aStream->XDisplay, "WM_DELETE_WINDOW", True ); + XSetWMProtocols( aStream->XDisplay, aStream->XWindow, &wmDelete, 1 ); + xcairo_init_cairo( pls ); } @@ -1772,7 +1776,8 @@ XSelectInput( aStream->XDisplay, aStream->XWindow, event_mask ); while ( !aStream->exit_event_loop ) { - XWindowEvent( aStream->XDisplay, aStream->XWindow, event_mask, &event ); + //XWindowEvent( aStream->XDisplay, aStream->XWindow, event_mask, &event ); + XNextEvent( aStream->XDisplay, &event ); switch ( event.type ) { case KeyPress: @@ -1787,6 +1792,9 @@ if ( ( (XButtonEvent *) &event )->button == Button3 ) aStream->exit_event_loop = 1; break; + case ClientMessage: + aStream->exit_event_loop = 1; + break; case Expose: /* Blit the image again after an expose event, but only for the last * available event. Otherwise multiple redraws occur needlessly. */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <hba...@us...> - 2010-05-30 15:50:01
|
Revision: 11035 http://plplot.svn.sourceforge.net/plplot/?rev=11035&view=rev Author: hbabcock Date: 2010-05-30 15:49:54 +0000 (Sun, 30 May 2010) Log Message: ----------- Change xcairo driver so that its behavior matches that of the qtwidget driver when the window close box is clicked. Modified Paths: -------------- trunk/drivers/cairo.c Modified: trunk/drivers/cairo.c =================================================================== --- trunk/drivers/cairo.c 2010-05-30 15:35:50 UTC (rev 11034) +++ trunk/drivers/cairo.c 2010-05-30 15:49:54 UTC (rev 11035) @@ -119,6 +119,7 @@ Display *XDisplay; Window XWindow; unsigned int xdrawable_mode; + short window_closed; #endif #if defined ( PLD_memcairo ) unsigned char *memory; @@ -1642,6 +1643,9 @@ XFlush( aStream->XDisplay ); + /* set window as not closed. */ + aStream->window_closed = 0; + return 0; } @@ -1734,6 +1738,9 @@ plD_bop_cairo( pls ); + if ( aStream->window_closed ) + return; + if ( aStream->xdrawable_mode ) return; @@ -1761,6 +1768,9 @@ aStream = (PLCairo *) pls->dev; + if ( aStream->window_closed ) + return; + /* Blit the offscreen image to the X window. */ blit_to_x( aStream, 0.0, 0.0, pls->xlength, pls->ylength ); @@ -1793,7 +1803,9 @@ aStream->exit_event_loop = 1; break; case ClientMessage: - aStream->exit_event_loop = 1; + // plexit("X Window closed"); + aStream->window_closed = 1; + aStream->exit_event_loop = 1; break; case Expose: /* Blit the image again after an expose event, but only for the last This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <hba...@us...> - 2010-05-30 16:02:37
|
Revision: 11036 http://plplot.svn.sourceforge.net/plplot/?rev=11036&view=rev Author: hbabcock Date: 2010-05-30 16:02:31 +0000 (Sun, 30 May 2010) Log Message: ----------- Add a closed flag to the stream for the cairo driver. If the stream is closed then we don't do any plotting. Modified Paths: -------------- trunk/drivers/cairo.c Modified: trunk/drivers/cairo.c =================================================================== --- trunk/drivers/cairo.c 2010-05-30 15:49:54 UTC (rev 11035) +++ trunk/drivers/cairo.c 2010-05-30 16:02:31 UTC (rev 11036) @@ -107,6 +107,7 @@ char *pangoMarkupString; short upDown; float fontSize; + short closed; /* Keep track of the bounding box of the modified portion of the surface */ double dirty_x1; double dirty_y1; @@ -119,7 +120,6 @@ Display *XDisplay; Window XWindow; unsigned int xdrawable_mode; - short window_closed; #endif #if defined ( PLD_memcairo ) unsigned char *memory; @@ -285,6 +285,9 @@ aStream = (PLCairo *) pls->dev; + if ( aStream->closed ) + return; + /* Do not use the external surface if the user says not to */ if ( !aStream->rasterize_image ) return; @@ -329,6 +332,9 @@ aStream = (PLCairo *) pls->dev; + if ( aStream->closed ) + return; + /* TODO FIXME: This should really only copy the used portion of the * offscreen pixmap. */ @@ -370,6 +376,9 @@ aStream = (PLCairo *) pls->dev; + if ( aStream->closed ) + return; + /* Some Cairo devices support delayed device setup (eg: xcairo with * external drawable and extcairo with an external context). */ if ( aStream->cairoContext == NULL ) @@ -448,6 +457,9 @@ aStream = (PLCairo *) pls->dev; + if ( aStream->closed ) + return; + set_current_context( pls ); get_line_properties( aStream, &old_join, &old_cap ); @@ -477,6 +489,9 @@ aStream = (PLCairo *) pls->dev; + if ( aStream->closed ) + return; + get_line_properties( aStream, &old_join, &old_cap ); set_line_properties( aStream, CAIRO_LINE_JOIN_BEVEL, CAIRO_LINE_CAP_BUTT ); @@ -498,6 +513,10 @@ PLCairo *aStream; aStream = (PLCairo *) pls->dev; + + if ( aStream->closed ) + return; + cairo_show_page( aStream->cairoContext ); } @@ -546,6 +565,9 @@ aStream = (PLCairo *) pls->dev; + if ( aStream->closed ) + return; + switch ( op ) { case PLESC_FILL: /* filled polygon */ @@ -1230,6 +1252,9 @@ aStream->rasterize_image = rasterize_image; aStream->set_background = set_background; + /* set stream as not closed. */ + aStream->closed = 0; + return aStream; } @@ -1643,9 +1668,6 @@ XFlush( aStream->XDisplay ); - /* set window as not closed. */ - aStream->window_closed = 0; - return 0; } @@ -1738,7 +1760,7 @@ plD_bop_cairo( pls ); - if ( aStream->window_closed ) + if ( aStream->closed ) return; if ( aStream->xdrawable_mode ) @@ -1768,7 +1790,7 @@ aStream = (PLCairo *) pls->dev; - if ( aStream->window_closed ) + if ( aStream->closed ) return; /* Blit the offscreen image to the X window. */ @@ -1804,7 +1826,7 @@ break; case ClientMessage: // plexit("X Window closed"); - aStream->window_closed = 1; + aStream->closed = 1; aStream->exit_event_loop = 1; break; case Expose: @@ -1863,6 +1885,9 @@ aStream = (PLCairo *) pls->dev; + if ( aStream->closed ) + return; + switch ( op ) { case PLESC_FLUSH: /* forced update of the window */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <hez...@us...> - 2010-06-20 05:28:50
|
Revision: 11080 http://plplot.svn.sourceforge.net/plplot/?rev=11080&view=rev Author: hezekiahcarty Date: 2010-06-20 05:28:43 +0000 (Sun, 20 Jun 2010) Log Message: ----------- Replace xcairo dirty rectangles with optional offscreen (image) buffering Adds a new drvopt, image_buffering, which is on (= 1) by default. This also does a bit of minor cleanup in the way drawing properties are handled. Disabling image_buffering causes all plot drawing to occur directly on an X surface (still buffered off-screen). This should maintain a similar or better speed increase for example 17 as provided by the dirty rectangle approach, while avoiding the negative performance impact the dirty rectangle code had on some routines, such as plimage (example 20). The cleanup in this patch consists of: 1. Using cairo_save and cairo_restore to save/restore the state of various Cairo drawing settings when they are changed within a drawing function. 2. Using the CAIRO_OPERATOR_OVER operator to avoid seams between adjacent polygons, thanks to a suggestion on the Cairo mailing list. Modified Paths: -------------- trunk/drivers/cairo.c Modified: trunk/drivers/cairo.c =================================================================== --- trunk/drivers/cairo.c 2010-06-17 07:21:29 UTC (rev 11079) +++ trunk/drivers/cairo.c 2010-06-20 05:28:43 UTC (rev 11080) @@ -73,16 +73,13 @@ #define MAX_STRING_LEN 500 #define MAX_MARKUP_LEN MAX_STRING_LEN * 10 -/* Values to reset the dirty rectangle regions */ -#define DIRTY_MIN ( 1.0e50 ) -#define DIRTY_MAX ( -1.0e50 ) - static int text_clipping; static int text_anti_aliasing; static int graphics_anti_aliasing; static int external_drawable; static int rasterize_image; static int set_background; +static int image_buffering; static DrvOpt cairo_options[] = { { "text_clipping", DRV_INT, &text_clipping, "Use text clipping (text_clipping=0|1)" }, { "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)" }, @@ -90,6 +87,7 @@ { "external_drawable", DRV_INT, &external_drawable, "Plot to external X drawable" }, { "rasterize_image", DRV_INT, &rasterize_image, "Raster or vector image rendering (rasterize_image=0|1)" }, { "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" }, + { "image_buffering", DRV_INT, &image_buffering, "Buffered offscreen rendering for the xcairo device (image_buffering=0|1)." }, { NULL, DRV_INT, NULL, NULL } }; typedef struct @@ -103,16 +101,12 @@ short graphics_anti_aliasing; short rasterize_image; short set_background; + short image_buffering; double downscale; char *pangoMarkupString; short upDown; float fontSize; short closed; - /* Keep track of the bounding box of the modified portion of the surface */ - double dirty_x1; - double dirty_y1; - double dirty_x2; - double dirty_y2; #if defined ( PLD_xcairo ) cairo_surface_t *cairoSurface_X; cairo_t *cairoContext_X; @@ -422,38 +416,9 @@ cairo_set_line_cap( aStream->cairoContext, cap ); } -/* Call this after rendering paths have been defined and before they have - * been cleared. It will update the dirty rectangle information for the - * current stream for the new flush/end of page. */ - -void update_dirty_rectangle( PLCairo *aStream ) -{ - double x1, y1, x2, y2; - cairo_stroke_extents( aStream->cairoContext, &x1, &y1, &x2, &y2 ); - - /* Expand the rectangle slightly to account for thick lines and other - * effects which may extend beyond the defined Cairo path. */ - aStream->dirty_x1 = MAX( 0.0, MIN( x1 * 0.9, aStream->dirty_x1 ) ); - aStream->dirty_y1 = MAX( 0.0, MIN( y1 * 0.9, aStream->dirty_y1 ) ); - aStream->dirty_x2 = MAX( x2 * 1.1, aStream->dirty_x2 ); - aStream->dirty_y2 = MAX( y2 * 1.1, aStream->dirty_y2 ); -} - -/* Reset the dirty triangle extents */ - -void reset_dirty_rectangle( PLCairo *aStream ) -{ - aStream->dirty_x1 = DIRTY_MIN; - aStream->dirty_y1 = DIRTY_MIN; - aStream->dirty_x2 = DIRTY_MAX; - aStream->dirty_y2 = DIRTY_MAX; -} - void plD_line_cairo( PLStream *pls, short x1a, short y1a, short x2a, short y2a ) { PLCairo *aStream; - cairo_line_join_t old_join; - cairo_line_cap_t old_cap; aStream = (PLCairo *) pls->dev; @@ -462,17 +427,16 @@ set_current_context( pls ); - get_line_properties( aStream, &old_join, &old_cap ); - set_line_properties( aStream, old_join, CAIRO_LINE_CAP_ROUND ); + cairo_save( aStream->cairoContext ); + set_line_properties( aStream, CAIRO_LINE_JOIN_BEVEL, CAIRO_LINE_CAP_ROUND ); + cairo_move_to( aStream->cairoContext, aStream->downscale * (double) x1a, aStream->downscale * (double) y1a ); cairo_line_to( aStream->cairoContext, aStream->downscale * (double) x2a, aStream->downscale * (double) y2a ); - update_dirty_rectangle( aStream ); - cairo_stroke( aStream->cairoContext ); - set_line_properties( aStream, old_join, old_cap ); + cairo_restore( aStream->cairoContext ); } /*--------------------------------------------------------------------- @@ -484,22 +448,21 @@ void plD_polyline_cairo( PLStream *pls, short *xa, short *ya, PLINT npts ) { PLCairo *aStream; - cairo_line_join_t old_join; - cairo_line_cap_t old_cap; aStream = (PLCairo *) pls->dev; if ( aStream->closed ) return; - get_line_properties( aStream, &old_join, &old_cap ); + cairo_save( aStream->cairoContext ); + set_line_properties( aStream, CAIRO_LINE_JOIN_BEVEL, CAIRO_LINE_CAP_BUTT ); poly_line( pls, xa, ya, npts ); cairo_stroke( aStream->cairoContext ); - set_line_properties( aStream, old_join, old_cap ); + cairo_restore( aStream->cairoContext ); } /*--------------------------------------------------------------------- @@ -625,13 +588,6 @@ aStream->pangoMarkupString[i] = 0; } open_span_tag( aStream->pangoMarkupString, args->n_fci, aStream->fontSize, 0 ); - - /* TODO FIXME: Set the entire plot surface as dirty until the logic - * is added to properly calculate the actual text extents. */ - aStream->dirty_x1 = 0.0; - aStream->dirty_y1 = 0.0; - aStream->dirty_x2 = pls->xlength; - aStream->dirty_y2 = pls->ylength; } /*--------------------------------------------------------------------- @@ -1225,8 +1181,6 @@ aStream->cairoContext = NULL; aStream->downscale = downscale; - reset_dirty_rectangle( aStream ); - /* Set text clipping on by default since it makes little difference in * speed for a modern cairo stack.*/ aStream->text_clipping = 1; @@ -1235,6 +1189,7 @@ graphics_anti_aliasing = 0; /* use 'default' graphics aliasing by default */ rasterize_image = 1; /* Enable rasterization by default */ set_background = 0; /* Default for extcairo is that PLplot not change the background */ + image_buffering = 1; /* Default to image-based buffered rendering */ /* Check for cairo specific options */ plParseDrvOpts( cairo_options ); @@ -1250,6 +1205,7 @@ aStream->graphics_anti_aliasing = graphics_anti_aliasing; aStream->rasterize_image = rasterize_image; aStream->set_background = set_background; + aStream->image_buffering = image_buffering; /* set stream as not closed. */ aStream->closed = 0; @@ -1307,8 +1263,6 @@ { cairo_line_to( aStream->cairoContext, aStream->downscale * (double) xa[i], aStream->downscale * (double) ya[i] ); } - - update_dirty_rectangle( aStream ); } /*--------------------------------------------------------------------- @@ -1321,40 +1275,37 @@ { int i; PLCairo *aStream; - cairo_line_join_t old_line_join; - cairo_line_cap_t old_line_cap; - cairo_antialias_t aa_state; aStream = (PLCairo *) pls->dev; - /* Save the previous line drawing style */ - get_line_properties( aStream, &old_line_join, &old_line_cap ); + cairo_save( aStream->cairoContext ); - /* These line properties make for a nicer looking polygon mesh */ - set_line_properties( aStream, CAIRO_LINE_JOIN_BEVEL, CAIRO_LINE_CAP_BUTT ); - /* Draw the polygons */ poly_line( pls, xa, ya, npts ); + cairo_set_operator( aStream->cairoContext, CAIRO_OPERATOR_OVER ); + cairo_set_source_rgba( aStream->cairoContext, (double) pls->curcolor.r / 255.0, (double) pls->curcolor.g / 255.0, (double) pls->curcolor.b / 255.0, (double) pls->curcolor.a ); - aa_state = cairo_get_antialias( aStream->cairoContext ); - /* Add an extra outline stroke to the polygon unless the plotting color is - * not opaque or antialiasing is disabled. */ - if ( ( pls->curcolor.a > 0.99 ) && ( aa_state != CAIRO_ANTIALIAS_NONE ) ) + + if ( cairo_get_antialias( aStream->cairoContext ) != CAIRO_ANTIALIAS_NONE ) { cairo_fill_preserve( aStream->cairoContext ); + + // These line properties make for a nicer looking polygon mesh + set_line_properties( aStream, CAIRO_LINE_JOIN_BEVEL, CAIRO_LINE_CAP_BUTT ); cairo_set_line_width( aStream->cairoContext, 1.0 ); cairo_stroke( aStream->cairoContext ); } else + { cairo_fill( aStream->cairoContext ); + } - /* Restore the previous line drawing style */ - set_line_properties( aStream, old_line_join, old_line_cap ); + cairo_restore( aStream->cairoContext ); } /*--------------------------------------------------------------------- @@ -1482,8 +1433,6 @@ cairo_line_to( aStream->cairoContext, 0.0, 0.0 ); cairo_restore( aStream->cairoContext ); - update_dirty_rectangle( aStream ); - cairo_set_source_rgba( aStream->cairoContext, (double) pls->curcolor.r / 255.0, (double) pls->curcolor.g / 255.0, @@ -1639,15 +1588,19 @@ aStream->cairoSurface_X = cairo_xlib_surface_create( aStream->XDisplay, aStream->XWindow, defaultVisual, pls->xlength, pls->ylength ); aStream->cairoContext_X = cairo_create( aStream->cairoSurface_X ); /* This is the Cairo surface PLplot will actually plot to. */ - aStream->cairoSurface = - /* - * cairo_surface_create_similar( aStream->cairoSurface_X, - * CAIRO_CONTENT_COLOR, - * pls->xlength, pls->ylength ); - */ - cairo_image_surface_create( CAIRO_FORMAT_RGB24, - pls->xlength, pls->ylength ); - aStream->cairoContext = cairo_create( aStream->cairoSurface ); + if ( aStream->image_buffering == 0 ) + { + aStream->cairoSurface = cairo_surface_create_similar( aStream->cairoSurface_X, CAIRO_CONTENT_COLOR, pls->xlength, pls->ylength ); + aStream->cairoContext = cairo_create( aStream->cairoSurface ); + } + else + { + // Plot to an off-screen image + aStream->cairoSurface = + cairo_image_surface_create( CAIRO_FORMAT_RGB24, + pls->xlength, pls->ylength ); + aStream->cairoContext = cairo_create( aStream->cairoSurface ); + } /* Invert the surface so that the graphs are drawn right side up. */ rotate_cairo_surface( pls, 1.0, 0.0, 0.0, -1.0, 0.0, pls->ylength, TRUE ); @@ -1733,16 +1686,10 @@ cairo_save( aStream->cairoContext_X ); cairo_rectangle( aStream->cairoContext_X, x, y, w, h ); cairo_set_operator( aStream->cairoContext_X, CAIRO_OPERATOR_SOURCE ); - cairo_set_source_surface( aStream->cairoContext_X, aStream->cairoSurface, - 0.0, 0.0 ); + cairo_set_source_surface( aStream->cairoContext_X, + aStream->cairoSurface, 0.0, 0.0 ); cairo_fill( aStream->cairoContext_X ); cairo_restore( aStream->cairoContext_X ); - - /* Reset the drawn-on region */ - reset_dirty_rectangle( aStream ); - - /* Flush the X display */ - /* XFlush( aStream->XDisplay ); */ } /*---------------------------------------------------------------------- @@ -1890,15 +1837,11 @@ switch ( op ) { case PLESC_FLUSH: /* forced update of the window */ - blit_to_x( aStream, aStream->dirty_x1, aStream->dirty_y1, - aStream->dirty_x2 - aStream->dirty_x1, - aStream->dirty_y2 - aStream->dirty_y1 ); + blit_to_x( aStream, 0.0, 0.0, pls->xlength, pls->ylength ); XFlush( aStream->XDisplay ); break; case PLESC_GETC: /* get cursor position */ - blit_to_x( aStream, aStream->dirty_x1, aStream->dirty_y1, - aStream->dirty_x2 - aStream->dirty_x1, - aStream->dirty_y2 - aStream->dirty_y1 ); + blit_to_x( aStream, 0.0, 0.0, pls->xlength, pls->ylength ); XFlush( aStream->XDisplay ); xcairo_get_cursor( pls, (PLGraphicsIn*) ptr ); break; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <hba...@us...> - 2010-10-13 14:07:43
|
Revision: 11260 http://plplot.svn.sourceforge.net/plplot/?rev=11260&view=rev Author: hbabcock Date: 2010-10-13 14:07:32 +0000 (Wed, 13 Oct 2010) Log Message: ----------- Change cairo device to return the string length in millimeters. Modified Paths: -------------- trunk/drivers/cairo.c Modified: trunk/drivers/cairo.c =================================================================== --- trunk/drivers/cairo.c 2010-10-11 22:56:04 UTC (rev 11259) +++ trunk/drivers/cairo.c 2010-10-13 14:07:32 UTC (rev 11260) @@ -694,10 +694,10 @@ pango_layout_set_markup( layout, aStream->pangoMarkupString, -1 ); pango_layout_get_pixel_size( layout, &textXExtent, &textYExtent ); - /* If asked, set the string length and return */ + /* If asked, set the string length (in mm) and return */ if (pls->get_string_length) { - pls->string_length = textXExtent; + pls->string_length = (PLFLT)textXExtent * 25.4 / DPI; return; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ai...@us...> - 2011-03-02 20:47:18
|
Revision: 11588 http://plplot.svn.sourceforge.net/plplot/?rev=11588&view=rev Author: airwin Date: 2011-03-02 20:47:12 +0000 (Wed, 02 Mar 2011) Log Message: ----------- Make cairo devices honor the -eofill option. Implemented and tested (using example 27) for xcairo, pdfcairo, pscairo, svgcairo, and raster devices (e.g., pngcairo and jpgcairo). Implemented for memcairo, extcairo, and wincairo. N.B. those latter devices need testing with fills for self-intersecting boundaries. Modified Paths: -------------- trunk/drivers/cairo.c Modified: trunk/drivers/cairo.c =================================================================== --- trunk/drivers/cairo.c 2011-03-02 18:58:17 UTC (rev 11587) +++ trunk/drivers/cairo.c 2011-03-02 20:47:12 UTC (rev 11588) @@ -1615,6 +1615,12 @@ // Set graphics aliasing cairo_set_antialias( aStream->cairoContext, aStream->graphics_anti_aliasing ); + // Set fill rule for the case of self-intersecting boundaries. + if ( pls->dev_eofill) + cairo_set_fill_rule( aStream->cairoContext, CAIRO_FILL_RULE_EVEN_ODD); + else + cairo_set_fill_rule( aStream->cairoContext, CAIRO_FILL_RULE_WINDING); + // Fill in the X window with the background color to avoid starting out // with a blank window of an unexpected color. cairo_rectangle( aStream->cairoContext_X, 0.0, 0.0, pls->xlength, pls->ylength ); @@ -2038,6 +2044,13 @@ // Set graphics aliasing cairo_set_antialias( aStream->cairoContext, aStream->graphics_anti_aliasing ); + + // Set fill rule for the case of self-intersecting boundaries. + if ( pls->dev_eofill) + cairo_set_fill_rule( aStream->cairoContext, CAIRO_FILL_RULE_EVEN_ODD); + else + cairo_set_fill_rule( aStream->cairoContext, CAIRO_FILL_RULE_WINDING); + } #endif @@ -2112,9 +2125,15 @@ pls->freeaspect = 1; } rotate_cairo_surface( pls, 0.0, -1.0, -1.0, 0.0, pls->ylength, pls->xlength, FALSE ); + + // Set fill rule for the case of self-intersecting boundaries. + if ( pls->dev_eofill) + cairo_set_fill_rule( aStream->cairoContext, CAIRO_FILL_RULE_EVEN_ODD); + else + cairo_set_fill_rule( aStream->cairoContext, CAIRO_FILL_RULE_WINDING); + } - #endif @@ -2206,6 +2225,13 @@ // Set graphics aliasing cairo_set_antialias( aStream->cairoContext, aStream->graphics_anti_aliasing ); + + // Set fill rule for the case of self-intersecting boundaries. + if ( pls->dev_eofill) + cairo_set_fill_rule( aStream->cairoContext, CAIRO_FILL_RULE_EVEN_ODD); + else + cairo_set_fill_rule( aStream->cairoContext, CAIRO_FILL_RULE_WINDING); + } #endif @@ -2300,6 +2326,13 @@ // Set graphics aliasing cairo_set_antialias( aStream->cairoContext, aStream->graphics_anti_aliasing ); + + // Set fill rule for the case of self-intersecting boundaries. + if ( pls->dev_eofill) + cairo_set_fill_rule( aStream->cairoContext, CAIRO_FILL_RULE_EVEN_ODD); + else + cairo_set_fill_rule( aStream->cairoContext, CAIRO_FILL_RULE_WINDING); + } //-------------------------------------------------------------------------- @@ -2488,6 +2521,13 @@ // Set graphics aliasing cairo_set_antialias( aStream->cairoContext, aStream->graphics_anti_aliasing ); + + // Set fill rule for the case of self-intersecting boundaries. + if ( pls->dev_eofill) + cairo_set_fill_rule( aStream->cairoContext, CAIRO_FILL_RULE_EVEN_ODD); + else + cairo_set_fill_rule( aStream->cairoContext, CAIRO_FILL_RULE_WINDING); + } //-------------------------------------------------------------------------- @@ -2702,6 +2742,12 @@ { extcairo_setbackground( pls ); } + + // Set fill rule for the case of self-intersecting boundaries. + if ( pls->dev_eofill) + cairo_set_fill_rule( aStream->cairoContext, CAIRO_FILL_RULE_EVEN_ODD); + else + cairo_set_fill_rule( aStream->cairoContext, CAIRO_FILL_RULE_WINDING); break; default: // Fall back on default Cairo actions plD_esc_cairo( pls, op, ptr ); @@ -3044,6 +3090,13 @@ // Set graphics aliasing cairo_set_antialias( aStream->cairoContext, aStream->graphics_anti_aliasing ); + + // Set fill rule for the case of self-intersecting boundaries. + if ( pls->dev_eofill) + cairo_set_fill_rule( aStream->cairoContext, CAIRO_FILL_RULE_EVEN_ODD); + else + cairo_set_fill_rule( aStream->cairoContext, CAIRO_FILL_RULE_WINDING); + } //-------------------------------------------------------------------------- This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <hez...@us...> - 2011-05-17 22:16:42
|
Revision: 11752 http://plplot.svn.sourceforge.net/plplot/?rev=11752&view=rev Author: hezekiahcarty Date: 2011-05-17 22:16:36 +0000 (Tue, 17 May 2011) Log Message: ----------- Add drawing mode setting/getting support for Cairo output devices There are a few changes in how transparent colors are handled by the xcairo device in order to keep output consistent with the other Cairo devices. This should not affect any of the existing examples, and it may fix/avoid some potential rendering bugs which could come up with the xcairo device. Modified Paths: -------------- trunk/drivers/cairo.c Modified: trunk/drivers/cairo.c =================================================================== --- trunk/drivers/cairo.c 2011-05-17 22:16:30 UTC (rev 11751) +++ trunk/drivers/cairo.c 2011-05-17 22:16:36 UTC (rev 11752) @@ -253,6 +253,9 @@ // Rasterization of plotted material static void start_raster( PLStream* ); static void end_raster( PLStream* ); +// Get/set drawing mode +static void set_mode( PLStream*, PLINT* ); +static void get_mode( PLStream*, PLINT* ); // PLplot interface functions @@ -565,10 +568,76 @@ case PLESC_ARC: // Draw an arc, either filled or outline arc( pls, (arc_struct *) ptr ); break; + case PLESC_MODESET: // Set drawing mode + set_mode( pls, (int *) ptr ); + break; + case PLESC_MODEGET: // Get drawing mode + get_mode( pls, (int *) ptr ); + break; } } + //-------------------------------------------------------------------------- +// set_mode +// +// Set drawing mode. +//-------------------------------------------------------------------------- +void set_mode( PLStream *pls, PLINT *mode ) +{ + PLCairo *aStream; + + aStream = (PLCairo *) pls->dev; + + switch ( *mode ) + { + case PL_MODE_UNKNOWN: // Invalid - do nothing + break; + case PL_MODE_DEFAULT: + cairo_set_operator( aStream->cairoContext, CAIRO_OPERATOR_OVER ); + break; + case PL_MODE_REPLACE: + cairo_set_operator( aStream->cairoContext, CAIRO_OPERATOR_SOURCE ); + break; + case PL_MODE_XOR: + cairo_set_operator( aStream->cairoContext, CAIRO_OPERATOR_XOR ); + break; + } + return; +} + +//-------------------------------------------------------------------------- +// get_mode +// +// Get drawing mode. +//-------------------------------------------------------------------------- +void get_mode( PLStream *pls, PLINT *mode ) +{ + PLCairo *aStream; + cairo_operator_t op; + + aStream = (PLCairo *) pls->dev; + + op = cairo_get_operator( aStream->cairoContext ); + + switch ( op ) + { + case CAIRO_OPERATOR_OVER: + *mode = PL_MODE_DEFAULT; + break; + case CAIRO_OPERATOR_SOURCE: + *mode = PL_MODE_REPLACE; + break; + case CAIRO_OPERATOR_XOR: + *mode = PL_MODE_XOR; + break; + default: + *mode = PL_MODE_UNKNOWN; + } + return; +} + +//-------------------------------------------------------------------------- // text_begin_cairo() // // Begin text. @@ -1147,6 +1216,7 @@ pls->dev_arc = 1; // Supports driver-level arcs pls->plbuf_write = interactive; // Activate plot buffer pls->has_string_length = 1; // Driver supports string length calculations + pls->dev_modeset = 1; // Driver supports drawing mode setting if ( pls->xlength <= 0 || pls->ylength <= 0 ) { @@ -1290,8 +1360,6 @@ // Draw the polygons poly_line( pls, xa, ya, npts ); - cairo_set_operator( aStream->cairoContext, CAIRO_OPERATOR_OVER ); - cairo_set_source_rgba( aStream->cairoContext, (double) pls->curcolor.r / 255.0, (double) pls->curcolor.g / 255.0, @@ -1597,14 +1665,14 @@ // This is the Cairo surface PLplot will actually plot to. if ( aStream->image_buffering == 0 ) { - aStream->cairoSurface = cairo_surface_create_similar( aStream->cairoSurface_X, CAIRO_CONTENT_COLOR, pls->xlength, pls->ylength ); + aStream->cairoSurface = cairo_surface_create_similar( aStream->cairoSurface_X, CAIRO_CONTENT_COLOR_ALPHA, pls->xlength, pls->ylength ); aStream->cairoContext = cairo_create( aStream->cairoSurface ); } else { // Plot to an off-screen image aStream->cairoSurface = - cairo_image_surface_create( CAIRO_FORMAT_RGB24, + cairo_image_surface_create( CAIRO_FORMAT_ARGB32, pls->xlength, pls->ylength ); aStream->cairoContext = cairo_create( aStream->cairoSurface ); } @@ -1690,13 +1758,31 @@ //-------------------------------------------------------------------------- // blit_to_x() // +// // Blit the offscreen image to the X window. //-------------------------------------------------------------------------- -void blit_to_x( PLCairo *aStream, double x, double y, double w, double h ) +void blit_to_x( PLStream *pls, double x, double y, double w, double h ) { + PLCairo *aStream; + + aStream = pls->dev; + + cairo_save( aStream->cairoContext ); + // "Flatten" any transparent regions to look like they were drawn over the + // correct background color + cairo_rectangle( aStream->cairoContext, x, y, w, h ); + cairo_set_operator( aStream->cairoContext, CAIRO_OPERATOR_DEST_OVER ); + cairo_set_source_rgba( aStream->cairoContext, + (double) pls->cmap0[0].r / 255.0, + (double) pls->cmap0[0].g / 255.0, + (double) pls->cmap0[0].b / 255.0, + (double) pls->cmap0[0].a ); + cairo_fill( aStream->cairoContext ); + cairo_restore( aStream->cairoContext ); + + cairo_save( aStream->cairoContext_X ); // Copy a portion of the surface - cairo_save( aStream->cairoContext_X ); cairo_rectangle( aStream->cairoContext_X, x, y, w, h ); cairo_set_operator( aStream->cairoContext_X, CAIRO_OPERATOR_SOURCE ); cairo_set_source_surface( aStream->cairoContext_X, @@ -1753,7 +1839,7 @@ return; // Blit the offscreen image to the X window. - blit_to_x( aStream, 0.0, 0.0, pls->xlength, pls->ylength ); + blit_to_x( pls, 0.0, 0.0, pls->xlength, pls->ylength ); if ( aStream->xdrawable_mode ) return; @@ -1794,7 +1880,7 @@ expose = (XExposeEvent *) &event; if ( expose->count == 0 ) { - blit_to_x( aStream, expose->x, expose->y, + blit_to_x( pls, expose->x, expose->y, expose->width, expose->height ); } break; @@ -1850,11 +1936,11 @@ switch ( op ) { case PLESC_FLUSH: // forced update of the window - blit_to_x( aStream, 0.0, 0.0, pls->xlength, pls->ylength ); + blit_to_x( pls, 0.0, 0.0, pls->xlength, pls->ylength ); XFlush( aStream->XDisplay ); break; case PLESC_GETC: // get cursor position - blit_to_x( aStream, 0.0, 0.0, pls->xlength, pls->ylength ); + blit_to_x( pls, 0.0, 0.0, pls->xlength, pls->ylength ); XFlush( aStream->XDisplay ); xcairo_get_cursor( pls, (PLGraphicsIn*) ptr ); break; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ai...@us...> - 2011-06-22 00:47:04
|
Revision: 11778 http://plplot.svn.sourceforge.net/plplot/?rev=11778&view=rev Author: airwin Date: 2011-06-22 00:46:58 +0000 (Wed, 22 Jun 2011) Log Message: ----------- Better tuning of superscript/subscript offsets to match algorithm used for plstr code in plsym.c that is used for Hershey fonts (e.g., -dev xwin). However, there are still at least two superscript/subscript bugs for the cairo devices. 1. test_superscript_subscript.py results show that the vertical offsets for superscripts with -dev xcairo largely match those from -dev xwin. This is expected because it was those offsets I used to tune the cairo device driver. However, the subscript vertical offsets are slightly too large in magnitude, i.e., the subscript is placed too low compared to the corresponding superscript. Off by 1 error for subscripts? 2. The plbox axis exponents that occur for badly scaled axis coordinates are written using plmtex. I mimic those plmtex calls with test_superscript_subscript.py. As expected, the exponent strings from plbox and test_superscript_subscript.py with -dev xwin have the same vertical offsets. However, the -dev xcairo results for the two cases are quite different with the plbox result having much too large a vertical offset for the superscript. Starting superscript offset level is off by 1 for plbox? Modified Paths: -------------- trunk/drivers/cairo.c Modified: trunk/drivers/cairo.c =================================================================== --- trunk/drivers/cairo.c 2011-06-22 00:26:12 UTC (rev 11777) +++ trunk/drivers/cairo.c 2011-06-22 00:46:58 UTC (rev 11778) @@ -1137,7 +1137,7 @@ // Create a rise span tag w/ appropriate font size & baseline offset //-------------------------------------------------------------------------- -#define STEPSIZE 7500.0 +#define STEPSIZE 15000.0 char *rise_span_tag( int level, int direction ) { @@ -1148,7 +1148,7 @@ for ( i = 0; i < abs( level ); i++ ) { - multiplier = multiplier * 0.9; + multiplier = multiplier * 0.75; rise += STEPSIZE * multiplier; } if ( direction > 0 ) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ai...@us...> - 2011-06-22 20:45:46
|
Revision: 11781 http://plplot.svn.sourceforge.net/plplot/?rev=11781&view=rev Author: airwin Date: 2011-06-22 20:45:39 +0000 (Wed, 22 Jun 2011) Log Message: ----------- I have discovered experimentally that contrary to the documentation at http://developer.gnome.org/pango/unstable/PangoMarkupFormat.html, rise is in units of 1024th of a point (i.e., a real distance unit) rather than in units of the (variable) font size. Implement a correction the accounts properly for the real units of rise. The result is the actual superscript/subscript vertical offsets that are rendered by cairo devices now is (correctly) proportional to the font size (as opposed to being fixed in size before). This correction solves the second issue noted in the previous commit. The cairo and PLplot character coordinate system have vertical zero points of respectively the baseline of the fonts and the middle of the vertical dimension of the fonts. This mismatch in coordinate systems means the superscript/subscript offsets appear asymmetrical for cairo devices compared to -dev xwin (i.e., issue 1 noted in the previous commit message). An approximation for this coordinate shift has been implemented, and the asymmetry appears to be greatly reduced as a result. Modified Paths: -------------- trunk/drivers/cairo.c Modified: trunk/drivers/cairo.c =================================================================== --- trunk/drivers/cairo.c 2011-06-22 19:40:38 UTC (rev 11780) +++ trunk/drivers/cairo.c 2011-06-22 20:45:39 UTC (rev 11781) @@ -240,7 +240,7 @@ static char *ucs4_to_pango_markup_format( PLUNICODE *, int, float ); static void open_span_tag( char *, PLUNICODE, float, int ); static void close_span_tag( char *, int ); -static char *rise_span_tag( int, int ); +static char *rise_span_tag( int, int, float ); // Graphics @@ -651,7 +651,8 @@ aStream = (PLCairo *) pls->dev; aStream->upDown = 0; aStream->pangoMarkupString = (char *) malloc( sizeof ( char ) * MAX_MARKUP_LEN ); - aStream->fontSize = pls->chrht * DPI / 25.4; + // Calculate the font size (in points since DPI = 72). + aStream->fontSize = pls->chrht * DPI / 25.4; for ( i = 0; i < MAX_MARKUP_LEN; i++ ) { aStream->pangoMarkupString[i] = 0; @@ -717,7 +718,7 @@ } else { - strncat( aStream->pangoMarkupString, rise_span_tag( aStream->upDown, 1 ), MAX_MARKUP_LEN - 1 - strlen( aStream->pangoMarkupString ) ); + strncat( aStream->pangoMarkupString, rise_span_tag( aStream->upDown, 1, aStream->fontSize ), MAX_MARKUP_LEN - 1 - strlen( aStream->pangoMarkupString ) ); } aStream->upDown++; break; @@ -728,7 +729,7 @@ } else { - strncat( aStream->pangoMarkupString, rise_span_tag( aStream->upDown, -1 ), MAX_MARKUP_LEN - 1 - strlen( aStream->pangoMarkupString ) ); + strncat( aStream->pangoMarkupString, rise_span_tag( aStream->upDown, -1, aStream->fontSize ), MAX_MARKUP_LEN - 1 - strlen( aStream->pangoMarkupString ) ); } aStream->upDown--; break; @@ -866,7 +867,7 @@ return; } - // Calculate the font size (in pixels) + // Calculate the font size (in points since DPI = 72). fontSize = pls->chrht * DPI / 25.4; // Convert the escape characters into the appropriate Pango markup @@ -1019,7 +1020,7 @@ } else { - strncat( pangoMarkupString, rise_span_tag( upDown, 1 ), MAX_MARKUP_LEN - 1 - strlen( pangoMarkupString ) ); + strncat( pangoMarkupString, rise_span_tag( upDown, 1, fontSize ), MAX_MARKUP_LEN - 1 - strlen( pangoMarkupString ) ); } upDown++; } @@ -1031,7 +1032,7 @@ } else { - strncat( pangoMarkupString, rise_span_tag( upDown, -1 ), MAX_MARKUP_LEN - 1 - strlen( pangoMarkupString ) ); + strncat( pangoMarkupString, rise_span_tag( upDown, -1, fontSize ), MAX_MARKUP_LEN - 1 - strlen( pangoMarkupString ) ); } upDown--; } @@ -1090,7 +1091,7 @@ while ( upDown > 0 ) { upDown--; - strncat( pangoMarkupString, rise_span_tag( upDown, 1 ), MAX_MARKUP_LEN - 1 - strlen( pangoMarkupString ) ); + strncat( pangoMarkupString, rise_span_tag( upDown, 1, fontSize ), MAX_MARKUP_LEN - 1 - strlen( pangoMarkupString ) ); } } if ( upDown < 0 ) @@ -1098,7 +1099,7 @@ while ( upDown < 0 ) { upDown++; - strncat( pangoMarkupString, rise_span_tag( upDown, -1 ), MAX_MARKUP_LEN - 1 - strlen( pangoMarkupString ) ); + strncat( pangoMarkupString, rise_span_tag( upDown, -1, fontSize ), MAX_MARKUP_LEN - 1 - strlen( pangoMarkupString ) ); } } } @@ -1131,33 +1132,59 @@ strncat( pangoMarkupString, "</span>", MAX_MARKUP_LEN - 1 - strlen( pangoMarkupString ) ); } +// Use 16/20ths to mimic what plstr in plsym.c does for first level +// of superscripts/subscripts. +# define RISE_FACTOR 0.8 + +// Experimental correction to help account for difference between +// cairo and PLplot character coordinate systems. +# define OFFSET_FACTOR 1.0 + //-------------------------------------------------------------------------- // rise_span_tag // // Create a rise span tag w/ appropriate font size & baseline offset //-------------------------------------------------------------------------- -#define STEPSIZE 15000.0 - -char *rise_span_tag( int level, int direction ) +char *rise_span_tag( int level, int direction, float fontSize ) { int i; float multiplier = 1.0; - float rise = STEPSIZE; + float rise = RISE_FACTOR; + float offset; static char tag[100]; for ( i = 0; i < abs( level ); i++ ) { multiplier = multiplier * 0.75; - rise += STEPSIZE * multiplier; + rise += RISE_FACTOR * multiplier; } + // http://developer.gnome.org/pango/unstable/PangoMarkupFormat.html says + // rise should be in units of 10000 em's, but empricial evidence shows + // it is in units of 1024th of a point. Therefore, since FontSize + // is in points, a rise of 1024. * fontSize corresponds a rise of + // a full character height. + rise = 1024. * fontSize * rise; + + // This is the correction for the difference between baseline and + // middle coordinate systems. Theoretically this offset should be + // 0.5*(fontSize - superscript/subscript fontSize). We make the + // assumption that the "smaller" fonts below are close to 0.75* + // multiplier * fontSize in size, where the "extra" factor of 0.75 + // corrects for an off-by-one issue in the termination of + // the multiplier calculation in the above loop. OFFSET_FACTOR + // is an empirical correction. + offset = 1024. * 0.5 * fontSize * ( 1.0 - 0.75 * multiplier * OFFSET_FACTOR ); + if ( direction > 0 ) { - sprintf( tag, "<span rise=\"%d\" size=\"smaller\">", (int) rise ); + sprintf( tag, "<span rise=\"%d\" size=\"smaller\">", + (int) ( rise + offset ) ); } else { - sprintf( tag, "<span rise=\"%d\" size=\"smaller\">", (int) -rise ); + sprintf( tag, "<span rise=\"%d\" size=\"smaller\">", + (int) -( rise - offset ) ); } return ( tag ); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ai...@us...> - 2011-07-05 17:36:30
|
Revision: 11790 http://plplot.svn.sourceforge.net/plplot/?rev=11790&view=rev Author: airwin Date: 2011-07-05 17:36:24 +0000 (Tue, 05 Jul 2011) Log Message: ----------- Replace generic "smaller" sizes for each superscript/subscript level by exact calculated font sizes appropriate for that level. Some code cleanup and improved commentary. Modified Paths: -------------- trunk/drivers/cairo.c Modified: trunk/drivers/cairo.c =================================================================== --- trunk/drivers/cairo.c 2011-07-05 17:18:50 UTC (rev 11789) +++ trunk/drivers/cairo.c 2011-07-05 17:36:24 UTC (rev 11790) @@ -1125,14 +1125,13 @@ strncat( pangoMarkupString, "</span>", MAX_MARKUP_LEN - 1 - strlen( pangoMarkupString ) ); } -// Use 16/20ths to mimic what plstr in plsym.c does for first level -// of superscripts/subscripts. +// 0.8 mimics the offset of first superscript/subscript level implemented +// in plstr (plsym.c) for Hershey fonts. Indeed when comparing with +// -dev xwin results this factor appears to offset the centers of the +// letters appropriately (but not their edges since different font sizes +// are involved). # define RISE_FACTOR 0.8 -// Experimental correction to help account for difference between -// cairo and PLplot character coordinate systems. -# define OFFSET_FACTOR 1.0 - //-------------------------------------------------------------------------- // rise_span_tag // @@ -1143,41 +1142,38 @@ { int i; float multiplier = 1.0; - float rise = RISE_FACTOR; + float rise = 1.0; float offset; static char tag[100]; for ( i = 0; i < abs( level ); i++ ) { multiplier = multiplier * 0.75; - rise += RISE_FACTOR * multiplier; + rise += multiplier; } + // Adjust multiplier to correspond to font scale for level. + multiplier = multiplier * 0.75; // http://developer.gnome.org/pango/unstable/PangoMarkupFormat.html says // rise should be in units of 10000 em's, but empricial evidence shows // it is in units of 1024th of a point. Therefore, since FontSize // is in points, a rise of 1024. * fontSize corresponds a rise of // a full character height. - rise = 1024. * fontSize * rise; + rise = 1024. * fontSize * RISE_FACTOR * rise; // This is the correction for the difference between baseline and - // middle coordinate systems. Theoretically this offset should be - // 0.5*(fontSize - superscript/subscript fontSize). We make the - // assumption that the "smaller" fonts below are close to 0.75* - // multiplier * fontSize in size, where the "extra" factor of 0.75 - // corrects for an off-by-one issue in the termination of - // the multiplier calculation in the above loop. OFFSET_FACTOR - // is an empirical correction. - offset = 1024. * 0.5 * fontSize * ( 1.0 - 0.75 * multiplier * OFFSET_FACTOR ); + // middle coordinate systems. This offset should be + // 0.5*(fontSize - superscript/subscript fontSize). + offset = 1024. * 0.5 * fontSize * ( 1.0 - multiplier ); if ( direction > 0 ) { - sprintf( tag, "<span rise=\"%d\" size=\"smaller\">", - (int) ( rise + offset ) ); + sprintf( tag, "<span rise=\"%d\" size=\"%d\">", + (int) ( rise + offset ), (int) ( fontSize * 1024. * multiplier ) ); } else { - sprintf( tag, "<span rise=\"%d\" size=\"smaller\">", - (int) -( rise - offset ) ); + sprintf( tag, "<span rise=\"%d\" size=\"%d\">", + (int) -( rise - offset ), (int) ( fontSize * 1024. * multiplier ) ); } return ( tag ); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <hba...@us...> - 2011-07-06 02:21:04
|
Revision: 11793 http://plplot.svn.sourceforge.net/plplot/?rev=11793&view=rev Author: hbabcock Date: 2011-07-06 02:20:57 +0000 (Wed, 06 Jul 2011) Log Message: ----------- Attempt to fix vertical offset problems with strings that contain sub/superscripts. Add string length functionality to the -classic- text rendering path so that it again renders text properly. However the -classic- path is still not completely fixed as there still seems to a offset problem. Modified Paths: -------------- trunk/drivers/cairo.c Modified: trunk/drivers/cairo.c =================================================================== --- trunk/drivers/cairo.c 2011-07-06 02:14:40 UTC (rev 11792) +++ trunk/drivers/cairo.c 2011-07-06 02:20:57 UTC (rev 11793) @@ -744,7 +744,7 @@ void text_end_cairo( PLStream *pls, EscText *args ) { - int textXExtent, textYExtent; + int textXExtent, textYExtent, baseline; PLFLT rotation, shear, stride, cos_rot, sin_rot, cos_shear, sin_shear; cairo_matrix_t *cairoTransformMatrix; cairo_font_options_t *cairoFontOptions; @@ -759,10 +759,13 @@ // Close the last span tag. close_span_tag( aStream->pangoMarkupString, aStream->upDown ); + // printf("%s\n", aStream->pangoMarkupString); + // Create the Pango text layout so we can figure out how big it is layout = pango_cairo_create_layout( aStream->cairoContext ); pango_layout_set_markup( layout, aStream->pangoMarkupString, -1 ); pango_layout_get_pixel_size( layout, &textXExtent, &textYExtent ); + baseline = pango_layout_get_baseline( layout ); // If asked, set the string length (in mm) and return if ( pls->get_string_length ) @@ -816,9 +819,10 @@ free( cairoTransformMatrix ); // Move to the text starting point + // printf("baseline %d %d\n", baseline, textYExtent); cairo_rel_move_to( aStream->cairoContext, (double) ( -1.0 * args->just * (double) textXExtent ), - (double) ( -0.5 * textYExtent ) ); + (double) 0.5 * aStream->fontSize - baseline / 1024.0); // Render the text pango_cairo_show_layout( aStream->cairoContext, layout ); @@ -840,7 +844,7 @@ void proc_str( PLStream *pls, EscText *args ) { float fontSize; - int textXExtent, textYExtent; + int textXExtent, textYExtent, baseline; char *textWithPangoMarkup; PLFLT rotation, shear, stride, cos_rot, sin_rot, cos_shear, sin_shear; cairo_matrix_t *cairoTransformMatrix; @@ -877,7 +881,15 @@ layout = pango_cairo_create_layout( aStream->cairoContext ); pango_layout_set_markup( layout, textWithPangoMarkup, -1 ); pango_layout_get_pixel_size( layout, &textXExtent, &textYExtent ); + baseline = pango_layout_get_baseline( layout ); + // If asked, set the string length (in mm) and return + if ( pls->get_string_length ) + { + pls->string_length = (PLFLT) textXExtent * 25.4 / DPI; + return; + } + // Set font aliasing context = pango_layout_get_context( layout ); cairoFontOptions = cairo_font_options_create(); @@ -922,10 +934,11 @@ cairo_transform( aStream->cairoContext, cairoTransformMatrix ); free( cairoTransformMatrix ); + // printf("baseline (ps) %d %d\n", baseline, textYExtent); // Move to the text starting point cairo_rel_move_to( aStream->cairoContext, - (double) ( -1.0 * args->just * (double) textXExtent ), - (double) ( -0.5 * textYExtent ) ); + (double) ( -1.0 * args->just * (double) textXExtent ), + (double) 0.5 * aStream->fontSize - baseline / 1024.0); // Render the text pango_cairo_show_layout( aStream->cairoContext, layout ); @@ -1075,6 +1088,7 @@ plP_fci2hex( fci, &fontFamily, PL_FCI_FAMILY ); plP_fci2hex( fci, &fontStyle, PL_FCI_STYLE ); plP_fci2hex( fci, &fontWeight, PL_FCI_WEIGHT ); + // From http://library.gnome.org/devel/pango/unstable/PangoMarkupFormat.html // size = font size in 1024ths of a point. snprintf( openTag, TAG_LEN, "<span font_desc=\"%s\" size=\"%d\" ", familyLookup[fontFamily], (int) ( fontSize * 1024. ) ); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <hba...@us...> - 2012-12-19 17:11:08
|
Revision: 12282 http://plplot.svn.sourceforge.net/plplot/?rev=12282&view=rev Author: hbabcock Date: 2012-12-19 17:11:01 +0000 (Wed, 19 Dec 2012) Log Message: ----------- Attempt to fix family issues for the cairo family devices (epscairo, pngcairo, svgcairo). Modified Paths: -------------- trunk/drivers/cairo.c Modified: trunk/drivers/cairo.c =================================================================== --- trunk/drivers/cairo.c 2012-11-23 21:27:51 UTC (rev 12281) +++ trunk/drivers/cairo.c 2012-12-19 17:11:01 UTC (rev 12282) @@ -80,6 +80,7 @@ static int rasterize_image; static int set_background; static int image_buffering; +static int already_warned = 0; static DrvOpt cairo_options[] = { { "text_clipping", DRV_INT, &text_clipping, "Use text clipping (text_clipping=0|1)" }, { "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)" }, @@ -223,7 +224,6 @@ "oblique" }; - //-------------------------------------------------------------------------- //-------------------------------------------------------------------------- // @@ -241,6 +241,7 @@ PLCairo *stream_and_font_setup( PLStream *, int ); cairo_status_t write_to_stream( void *, unsigned char *, unsigned int ); void set_clip( PLStream *pls ); +int cairo_family_check( PLStream *pls); // String processing @@ -525,6 +526,10 @@ void plD_esc_cairo( PLStream *pls, PLINT op, void *ptr ) { + PLCairo *aStream; + + aStream = (PLCairo *) pls->dev; + switch ( op ) { case PLESC_FILL: // filled polygon @@ -1516,6 +1521,30 @@ } //-------------------------------------------------------------------------- +// cairo_family_check () +// +// support function to help supress more than one page if family file +// output not specified by the user (e.g., with the -fam command-line option). +//-------------------------------------------------------------------------- + +int cairo_family_check( PLStream *pls ) +{ + if ( pls->family || pls->page == 1 ) + { + return 0; + } + else + { + if ( !already_warned ) + { + already_warned = 1; + plwarn( "All pages after the first skipped because family file output not specified.\n" ); + } + return 1; + } +} + +//-------------------------------------------------------------------------- // arc() // // Draws an arc, possibly filled. @@ -1610,26 +1639,41 @@ // //-------------------------------------------------------------------------- //-------------------------------------------------------------------------- -#if defined ( PLD_pngcairo ) || defined ( PLD_svgcairo ) +#if defined ( PLD_pngcairo ) || defined ( PLD_svgcairo ) || defined ( PLD_epscairo ) -void plD_bop_famcairo( PLStream * ); +void plD_bop_cairo_fam( PLStream *); +void plD_eop_cairo_fam( PLStream *); +void plD_state_cairo_fam( PLStream *, PLINT ); +void plD_esc_cairo_fam( PLStream *, PLINT, void *); +void plD_tidy_cairo_fam( PLStream *); +void plD_line_cairo_fam( PLStream *, short, short, short, short); +void plD_polyline_cairo_fam( PLStream *, short *, short *, PLINT); + //-------------------------------------------------------------------------- -// plD_bop_famcairo() +// plD_bop_cairo_fam() // // Familying Devices: Set up for the next page. //-------------------------------------------------------------------------- -void plD_bop_famcairo( PLStream *pls ) +void plD_bop_cairo_fam( PLStream *pls ) { PLCairo *aStream; + // Plot familying stuff. Not really understood, just copying gd.c + plGetFam( pls ); + aStream = (PLCairo *) pls->dev; - // Plot familying stuff. Not really understood, just copying gd.c - plGetFam( pls ); pls->famadv = 1; pls->page++; + // Suppress multi-page output if family file output is not + // specified by the user. + if ( cairo_family_check( pls) ) + { + return; + } + // Fill in the window with the background color. cairo_rectangle( aStream->cairoContext, 0.0, 0.0, pls->xlength, pls->ylength ); cairo_set_source_rgba( aStream->cairoContext, @@ -1640,6 +1684,97 @@ cairo_fill( aStream->cairoContext ); } +//-------------------------------------------------------------------------- +// plD_eop_cairo() +// +// End of page. +//-------------------------------------------------------------------------- + +void plD_eop_cairo_fam( PLStream *pls ) +{ + if ( cairo_family_check( pls) ) + { + return; + } + + plD_eop_cairo(pls); +} + +//-------------------------------------------------------------------------- +// plD_state_cairo_fam() +// +// Handle change in PLStream state (color, pen width, fill attribute, etc). +//-------------------------------------------------------------------------- + +void plD_state_cairo_fam( PLStream *pls, PLINT op ) +{ + if ( cairo_family_check( pls) ) + { + return; + } + + plD_state_cairo(pls, op); +} + +//-------------------------------------------------------------------------- +// plD_esc_cairo_fam() +// +// Generic escape function. +//-------------------------------------------------------------------------- + +void plD_esc_cairo_fam( PLStream *pls, PLINT op , void *ptr ) +{ + if ( cairo_family_check( pls) ) + { + return; + } + + plD_esc_cairo(pls, op, ptr); +} + +//-------------------------------------------------------------------------- +// plD_tidy_cairo_fam() +// +// Close graphics file or otherwise clean up. +//-------------------------------------------------------------------------- + +void plD_tidy_cairo_fam( PLStream *pls ) +{ + plD_tidy_cairo( pls ); +} + +//-------------------------------------------------------------------------- +// plD_line_cairo_fam() +// +// Draw a line. +//-------------------------------------------------------------------------- + +void plD_line_cairo_fam( PLStream *pls, short x1a, short y1a, short x2a, short y2a ) +{ + if ( cairo_family_check( pls) ) + { + return; + } + + plD_line_cairo(pls, x1a, y1a, x2a, y2a); +} + +//-------------------------------------------------------------------------- +// plD_polyline_cairo_fam() +// +// Draw a polyline in the current color. +//-------------------------------------------------------------------------- + +void plD_polyline_cairo_fam( PLStream *pls, short *xa, short *ya, PLINT npts ) +{ + if ( cairo_family_check( pls) ) + { + return; + } + + plD_polyline_cairo(pls, xa, ya, npts); +} + #endif //-------------------------------------------------------------------------- //-------------------------------------------------------------------------- @@ -2286,13 +2421,13 @@ pdt->pl_type = plDevType_FileOriented; pdt->pl_seq = 102; pdt->pl_init = (plD_init_fp) plD_init_epscairo; - pdt->pl_line = (plD_line_fp) plD_line_cairo; - pdt->pl_polyline = (plD_polyline_fp) plD_polyline_cairo; - pdt->pl_eop = (plD_eop_fp) plD_eop_cairo; - pdt->pl_bop = (plD_bop_fp) plD_bop_famcairo; - pdt->pl_tidy = (plD_tidy_fp) plD_tidy_cairo; - pdt->pl_state = (plD_state_fp) plD_state_cairo; - pdt->pl_esc = (plD_esc_fp) plD_esc_cairo; + pdt->pl_line = (plD_line_fp) plD_line_cairo_fam; + pdt->pl_polyline = (plD_polyline_fp) plD_polyline_cairo_fam; + pdt->pl_eop = (plD_eop_fp) plD_eop_cairo_fam; + pdt->pl_bop = (plD_bop_fp) plD_bop_cairo_fam; + pdt->pl_tidy = (plD_tidy_fp) plD_tidy_cairo_fam; + pdt->pl_state = (plD_state_fp) plD_state_cairo_fam; + pdt->pl_esc = (plD_esc_fp) plD_esc_cairo_fam; } //-------------------------------------------------------------------------- @@ -2390,13 +2525,13 @@ pdt->pl_type = plDevType_FileOriented; pdt->pl_seq = 103; pdt->pl_init = (plD_init_fp) plD_init_svgcairo; - pdt->pl_line = (plD_line_fp) plD_line_cairo; - pdt->pl_polyline = (plD_polyline_fp) plD_polyline_cairo; - pdt->pl_eop = (plD_eop_fp) plD_eop_cairo; - pdt->pl_bop = (plD_bop_fp) plD_bop_famcairo; - pdt->pl_tidy = (plD_tidy_fp) plD_tidy_cairo; - pdt->pl_state = (plD_state_fp) plD_state_cairo; - pdt->pl_esc = (plD_esc_fp) plD_esc_cairo; + pdt->pl_line = (plD_line_fp) plD_line_cairo_fam; + pdt->pl_polyline = (plD_polyline_fp) plD_polyline_cairo_fam; + pdt->pl_eop = (plD_eop_fp) plD_eop_cairo_fam; + pdt->pl_bop = (plD_bop_fp) plD_bop_cairo_fam; + pdt->pl_tidy = (plD_tidy_fp) plD_tidy_cairo_fam; + pdt->pl_state = (plD_state_fp) plD_state_cairo_fam; + pdt->pl_esc = (plD_esc_fp) plD_esc_cairo_fam; } //-------------------------------------------------------------------------- @@ -2490,13 +2625,13 @@ pdt->pl_type = plDevType_FileOriented; pdt->pl_seq = 104; pdt->pl_init = (plD_init_fp) plD_init_pngcairo; - pdt->pl_line = (plD_line_fp) plD_line_cairo; - pdt->pl_polyline = (plD_polyline_fp) plD_polyline_cairo; + pdt->pl_line = (plD_line_fp) plD_line_cairo_fam; + pdt->pl_polyline = (plD_polyline_fp) plD_polyline_cairo_fam; pdt->pl_eop = (plD_eop_fp) plD_eop_pngcairo; - pdt->pl_bop = (plD_bop_fp) plD_bop_famcairo; - pdt->pl_tidy = (plD_tidy_fp) plD_tidy_cairo; - pdt->pl_state = (plD_state_fp) plD_state_cairo; - pdt->pl_esc = (plD_esc_fp) plD_esc_cairo; + pdt->pl_bop = (plD_bop_fp) plD_bop_cairo_fam; + pdt->pl_tidy = (plD_tidy_fp) plD_tidy_cairo_fam; + pdt->pl_state = (plD_state_fp) plD_state_cairo_fam; + pdt->pl_esc = (plD_esc_fp) plD_esc_cairo_fam; } //-------------------------------------------------------------------------- @@ -2567,6 +2702,11 @@ { PLCairo *aStream; + if ( cairo_family_check( pls) ) + { + return; + } + aStream = (PLCairo *) pls->dev; cairo_surface_write_to_png_stream( aStream->cairoSurface, (cairo_write_func_t) write_to_stream, pls->OutFile ); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ai...@us...> - 2013-04-30 04:53:00
|
Revision: 12311 http://sourceforge.net/p/plplot/code/12311 Author: airwin Date: 2013-04-30 04:52:56 +0000 (Tue, 30 Apr 2013) Log Message: ----------- Follow suggestion from H?\199?\142ili?\195?\160ng Wang <hwa...@gm...> to use the user-specified line width for fills rather than the hard-coded width value of 1.0 that was used previously. Modified Paths: -------------- trunk/drivers/cairo.c Modified: trunk/drivers/cairo.c =================================================================== --- trunk/drivers/cairo.c 2013-04-28 17:37:01 UTC (rev 12310) +++ trunk/drivers/cairo.c 2013-04-30 04:52:56 UTC (rev 12311) @@ -1424,7 +1424,14 @@ // These line properties make for a nicer looking polygon mesh set_line_properties( aStream, CAIRO_LINE_JOIN_BEVEL, CAIRO_LINE_CAP_BUTT ); - cairo_set_line_width( aStream->cairoContext, 1.0 ); + // Comment out the following call to cairo_set_line width + // since the hard-coded width value of 1.0 is not appropriate + // for fills of small areas. Instead, use the line width that + // has already been set by the user via the above call of + // poly_line which in turn calls set_current_context which in + // turn calls cairo_set_line_width for the user-specified + // width. + // cairo_set_line_width( aStream->cairoContext, 1.0 ); cairo_stroke( aStream->cairoContext ); } else This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <and...@us...> - 2013-09-09 22:32:39
|
Revision: 12504 http://sourceforge.net/p/plplot/code/12504 Author: andrewross Date: 2013-09-09 22:32:36 +0000 (Mon, 09 Sep 2013) Log Message: ----------- Modify xcairo driver to honour the -display option to set the display. Also exit if opening the display fails since continuing will lead to a crash anyway. Modified Paths: -------------- trunk/drivers/cairo.c Modified: trunk/drivers/cairo.c =================================================================== --- trunk/drivers/cairo.c 2013-09-09 14:41:12 UTC (rev 12503) +++ trunk/drivers/cairo.c 2013-09-09 22:32:36 UTC (rev 12504) @@ -1922,10 +1922,13 @@ { // X Windows setup aStream->XDisplay = NULL; - aStream->XDisplay = XOpenDisplay( NULL ); + if (pls->FileName != NULL) + aStream->XDisplay = XOpenDisplay( pls->FileName ); + else + aStream->XDisplay = XOpenDisplay( NULL ); if ( aStream->XDisplay == NULL ) { - printf( "Failed to open X Windows display\n" ); + plexit( "Failed to open X Windows display\n" ); // some sort of error here } XScreen = DefaultScreen( aStream->XDisplay ); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ai...@us...> - 2014-03-06 00:05:32
|
Revision: 13044 http://sourceforge.net/p/plplot/code/13044 Author: airwin Date: 2014-03-06 00:05:26 +0000 (Thu, 06 Mar 2014) Log Message: ----------- Solve scaling issue (https://sourceforge.net/p/plplot/bugs/143/) demonstrated by the extXdrawable_demo application. Thanks to Jens (https://sourceforge.net/u/jensplplot/profile/) for reporting this issue which I was able to confirm by attempting to resize the extXdrawable_demo GUI. I have applied the fix suggested by Jens which in retrospect is obvious; when you change the geometry by resizing the window, the result is reported back by the call to XGetGeometry, and the scale factor must be adjusted to compensate for that changed geometry right after that call. After this fix, resizing the extXdrawable_demo GUI produced no strange line artifacts (presumably caused by short overflows) that were present before the fix. Modified Paths: -------------- trunk/drivers/cairo.c Modified: trunk/drivers/cairo.c =================================================================== --- trunk/drivers/cairo.c 2014-03-05 20:19:04 UTC (rev 13043) +++ trunk/drivers/cairo.c 2014-03-06 00:05:26 UTC (rev 13044) @@ -2186,6 +2186,12 @@ &x, &y, &w, &h, &b, &d ); pls->xlength = (PLINT) w; pls->ylength = (PLINT) h; + // Calculate ratio of (smaller) external coordinates used for cairo + // devices to (larger) internal PLplot coordinates. + if ( pls->xlength > pls->ylength ) + aStream->downscale = (double) pls->xlength / (double) ( PIXELS_X - 1 ); + else + aStream->downscale = (double) pls->ylength / (double) PIXELS_Y; plP_setphy( (PLINT) 0, (PLINT) ( pls->xlength / aStream->downscale ), (PLINT) 0, (PLINT) ( pls->ylength / aStream->downscale ) ); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |