# HG changeset patch # User Ben Abbott # Date 1233058858 18000 # Node ID b4fb0a52b15e3f08f33c396f035b064ed0f9766d # Parent 11cf7bc4a871922900b1b95aa17da92a6b213d8d Improve default property compatibility. diff -r 11cf7bc4a871 -r b4fb0a52b15e src/ChangeLog --- a/src/ChangeLog Tue Jan 27 12:40:31 2009 +0100 +++ b/src/ChangeLog Tue Jan 27 07:20:58 2009 -0500 @@ -1,3 +1,12 @@ +2009-01-27 Ben Abbott + + * graphics.cc (convert_position): Handle character units. + (default_axes_tick, default_figure_papersize, + default_figure_paperposition): New functions. + * graphics.h.in (class figure::properties): Use them to + initialize papersize, paperposition, xtick, ytick, and ztick + properties. + 2009-01-27 Jaroslav Hajek * DLD-FUNCTIONS/qr.cc (Fqr): Treat empty matrices correctly. diff -r 11cf7bc4a871 -r b4fb0a52b15e src/graphics.cc --- a/src/graphics.cc Tue Jan 27 12:40:31 2009 +0100 +++ b/src/graphics.cc Tue Jan 27 07:20:58 2009 -0500 @@ -188,6 +188,19 @@ } static Matrix +default_axes_tick (void) +{ + Matrix m (1, 6, 0.0); + m(0) = 0.0; + m(1) = 0.2; + m(2) = 0.4; + m(3) = 0.6; + m(4) = 0.8; + m(5) = 1.0; + return m; +} + +static Matrix default_figure_position (void) { Matrix m (1, 4, 0.0); @@ -199,6 +212,26 @@ } static Matrix +default_figure_papersize (void) +{ + Matrix m (1, 2, 0.0); + m(0) = 8.5; + m(1) = 11.5; + return m; +} + +static Matrix +default_figure_paperposition (void) +{ + Matrix m (1, 4, 0.0); + m(0) = 0.25; + m(1) = 2.50; + m(2) = 8.00; + m(3) = 6.00; + return m; +} + +static Matrix convert_position (const Matrix& pos, const caseless_str& from_units, const caseless_str& to_units, const Matrix& parent_dim = Matrix (1, 2, 0.0), @@ -218,7 +251,21 @@ } else if (from_units.compare ("characters")) { - // FIXME -- implement this. + res = backend.get_screen_resolution (); + + double f = 0.0; + + // FIXME -- this assumes the system font is Helvetica 10pt + // (for which "x" requires 6x12 pixels at 74.951 pixels/inch) + f = 12.0 * res / 74.951; + + if (f > 0) + { + retval(0) = 0.5 * pos(0) * f; + retval(1) = pos(1) * f; + retval(2) = 0.5 * pos(2) * f; + retval(3) = pos(3) * f; + } } else { @@ -253,7 +300,19 @@ } else if (to_units.compare ("characters")) { - // FIXME -- implement this. + res = backend.get_screen_resolution (); + + double f = 0.0; + + f = 12.0 * res / 74.951; + + if (f > 0) + { + retval(0) = 2 * retval(0) / f; + retval(1) = retval(1) / f; + retval(2) = 2 * retval(2) / f; + retval(3) = retval(3) / f; + } } else { diff -r 11cf7bc4a871 -r b4fb0a52b15e src/graphics.h.in --- a/src/graphics.h.in Tue Jan 27 12:40:31 2009 +0100 +++ b/src/graphics.h.in Tue Jan 27 07:20:58 2009 -0500 @@ -2353,9 +2353,9 @@ string_property name , "" bool_property numbertitle , "on" radio_property paperunits , "{inches}|centimeters|normalized|points" - array_property paperposition , Matrix (1, 4 , 0) + array_property paperposition , default_figure_paperposition () radio_property paperpositionmode , "auto|{manual}" - array_property papersize , Matrix (1, 2, 0) + array_property papersize , default_figure_papersize () radio_property papertype , "{usletter}|uslegal|a0|a1|a2|a3|a4|a5|b0|b1|b2|b3|b4|b5|arch-a|arch-b|arch-c|arch-d|arch-e|a|b|c|d|e|tabloid|" radio_property pointer , "crosshair|fullcrosshair|{arrow}|ibeam|watch|topl|topr|botl|botr|left|top|right|bottom|circle|cross|fleur|custom|hand" array_property pointershapecdata , Matrix (16, 16, 0) @@ -2641,9 +2641,9 @@ bool_property xminorgrid , "off" bool_property yminorgrid , "off" bool_property zminorgrid , "off" - row_vector_property xtick m , Matrix () - row_vector_property ytick m , Matrix () - row_vector_property ztick m , Matrix () + row_vector_property xtick m , default_axes_tick () + row_vector_property ytick m , default_axes_tick () + row_vector_property ztick m , default_axes_tick () radio_property xtickmode , "{auto}|manual" radio_property ytickmode , "{auto}|manual" radio_property ztickmode , "{auto}|manual"