From: <hba...@us...> - 2010-10-10 21:17:18
|
Revision: 11255 http://plplot.svn.sourceforge.net/plplot/?rev=11255&view=rev Author: hbabcock Date: 2010-10-10 21:17:11 +0000 (Sun, 10 Oct 2010) Log Message: ----------- Add a string length calculation option to PLplot core and the cairo driver. If a driver can calculate the length of a string it should set pls->has_string_length. Then, when asked to render a string it should check pls->get_string_length. If pls->get_string_length is set then it should return the length of the string instead of rendering it. Currently set to return the length in pixels. Modified Paths: -------------- trunk/drivers/cairo.c trunk/include/plstrm.h Modified: trunk/drivers/cairo.c =================================================================== --- trunk/drivers/cairo.c 2010-10-10 18:12:08 UTC (rev 11254) +++ trunk/drivers/cairo.c 2010-10-10 21:17:11 UTC (rev 11255) @@ -694,6 +694,13 @@ 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 (pls->get_string_length) + { + pls->string_length = textXExtent; + return; + } + /* Set font aliasing */ context = pango_layout_get_context( layout ); cairoFontOptions = cairo_font_options_create(); @@ -1139,8 +1146,8 @@ pls->dev_gradient = 1; /* driver renders gradient */ 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 */ - if ( pls->xlength <= 0 || pls->ylength <= 0 ) { pls->xlength = PLCAIRO_DEFAULT_X; Modified: trunk/include/plstrm.h =================================================================== --- trunk/include/plstrm.h 2010-10-10 18:12:08 UTC (rev 11254) +++ trunk/include/plstrm.h 2010-10-10 21:17:11 UTC (rev 11255) @@ -187,7 +187,11 @@ * page PLINT Page count for output stream * linepos PLINT Line count for output stream * pdfs PDFstrm* PDF stream pointer - * dev_mem_alpha PLINT The user supplied memory buffer supports alpha values + * dev_mem_alpha PLINT The user supplied memory buffer supports alpha values + * has_string_length PLINT The driver can calculate the lengths of strings + * string_length PLINT Set to the length of the current string by the driver + * get_string_length PLINT Tells the driver to calculate the length of the string + * but not to render it. * * These are used by the escape function (for area fill, etc). * @@ -777,6 +781,9 @@ PLBOOL stream_closed; PLINT line_style; PLINT dev_mem_alpha; + PLINT has_string_length; + PLINT string_length; + PLINT get_string_length; } PLStream; /*--------------------------------------------------------------------------*\ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |