comparison src/graphics.cc @ 14266:37ca58f9a887

When root_figure units = normalized, screensize = [0 0 1 1]. * graphics.cc: Set correct value for screensize when units are normalized. Add tests.
author Ben Abbott <bpabbott@mac.com>
date Tue, 24 Jan 2012 20:52:12 -0500
parents 08779abcb640
children 7a7ce92cff56
comparison
equal deleted inserted replaced
14264:284656167c25 14266:37ca58f9a887
3027 ss(3) *= 2.54 / dpi; 3027 ss(3) *= 2.54 / dpi;
3028 } 3028 }
3029 else if (xunits.compare ("normalized")) 3029 else if (xunits.compare ("normalized"))
3030 { 3030 {
3031 ss = Matrix (1, 4, 1.0); 3031 ss = Matrix (1, 4, 1.0);
3032 ss(0) = 0;
3033 ss(1) = 0;
3032 } 3034 }
3033 else if (xunits.compare ("points")) 3035 else if (xunits.compare ("points"))
3034 { 3036 {
3035 ss(0) = 0; 3037 ss(0) = 0;
3036 ss(1) = 0; 3038 ss(1) = 0;
3038 ss(3) *= 72 / dpi; 3040 ss(3) *= 72 / dpi;
3039 } 3041 }
3040 3042
3041 set_screensize (ss); 3043 set_screensize (ss);
3042 } 3044 }
3045
3046 /*
3047 %!test
3048 %! set (0, "units", "pixels")
3049 %! sz = get (0, "screensize") - [1, 1, 0, 0];
3050 %! dpi = get (0, "screenpixelsperinch");
3051 %! set (0, "units", "inches")
3052 %! assert (get (0, "screensize"), sz / dpi, 0.5 / dpi)
3053 %! set (0, "units", "centimeters")
3054 %! assert (get (0, "screensize"), sz / dpi * 2.54, 0.5 / dpi * 2.54)
3055 %! set (0, "units", "points")
3056 %! assert (get (0, "screensize"), sz / dpi * 72, 0.5 / dpi * 72)
3057 %! set (0, "units", "normalized")
3058 %! assert (get (0, "screensize"), [0.0, 0.0, 1.0, 1.0])
3059 %! set (0, "units", "pixels")
3060 %! assert (get (0, "screensize"), sz + [1, 1, 0, 0])
3061 */
3043 3062
3044 void 3063 void
3045 root_figure::properties::remove_child (const graphics_handle& gh) 3064 root_figure::properties::remove_child (const graphics_handle& gh)
3046 { 3065 {
3047 gh_manager::pop_figure (gh); 3066 gh_manager::pop_figure (gh);
3683 figure::properties::update_units (const caseless_str& old_units) 3702 figure::properties::update_units (const caseless_str& old_units)
3684 { 3703 {
3685 set_position (convert_position (get_position ().matrix_value (), old_units, 3704 set_position (convert_position (get_position ().matrix_value (), old_units,
3686 get_units (), screen_size_pixels ())); 3705 get_units (), screen_size_pixels ()));
3687 } 3706 }
3707
3708 /*
3709 %!test
3710 %! figure (1, "visible", false)
3711 %! set (0, "units", "pixels")
3712 %! rsz = get (0, "screensize");
3713 %! set (gcf (), "units", "pixels")
3714 %! fsz = get (gcf (), "position");
3715 %! set (gcf (), "units", "normalized")
3716 %! assert (get (gcf (), "position"), (fsz - [1, 1, 0, 0]) ./ rsz([3, 4, 3, 4]))
3717 */
3688 3718
3689 std::string 3719 std::string
3690 figure::properties::get_title (void) const 3720 figure::properties::get_title (void) const
3691 { 3721 {
3692 if (is_numbertitle ()) 3722 if (is_numbertitle ())