comparison src/graphics.cc @ 14257:5cc69bafe3b9

Add updating for figure paperorientation property. Bug # 35329. * graphics.h.in: Make paperorientation property as having an updater. * graphics.cc: Add paperorientation dependence to paperunits, papertype, and papersize. Add figure::properties::update_paperorientation. Add tests.
author Ben Abbott <bpabbott@mac.com>
date Tue, 24 Jan 2012 08:29:33 -0500
parents 72c96de7a403
children 08779abcb640
comparison
equal deleted inserted replaced
14254:73086d4b64fa 14257:5cc69bafe3b9
3462 void 3462 void
3463 figure::properties::update_paperunits (const caseless_str& old_paperunits) 3463 figure::properties::update_paperunits (const caseless_str& old_paperunits)
3464 { 3464 {
3465 Matrix pos = get_paperposition ().matrix_value (); 3465 Matrix pos = get_paperposition ().matrix_value ();
3466 Matrix sz = get_papersize ().matrix_value (); 3466 Matrix sz = get_papersize ().matrix_value ();
3467 caseless_str porient = get_paperorientation ();
3467 3468
3468 pos (0) = pos (0) / sz(0); 3469 pos (0) = pos (0) / sz(0);
3469 pos (1) = pos (1) / sz(1); 3470 pos (1) = pos (1) / sz(1);
3470 pos (2) = pos (2) / sz(0); 3471 pos (2) = pos (2) / sz(0);
3471 pos (3) = pos (3) / sz(1); 3472 pos (3) = pos (3) / sz(1);
3496 sz (0) = sz (0) * 72.0; 3497 sz (0) = sz (0) * 72.0;
3497 sz (1) = sz (1) * 72.0; 3498 sz (1) = sz (1) * 72.0;
3498 } 3499 }
3499 } 3500 }
3500 else 3501 else
3501 sz = papersize_from_type (punits, typ); 3502 {
3503 sz = papersize_from_type (punits, typ);
3504 if (porient.compare ("landscape"))
3505 {
3506 double tmp = sz (0);
3507 sz (0) = sz (1);
3508 sz (1) = tmp;
3509 }
3510 }
3502 3511
3503 pos (0) = pos (0) * sz(0); 3512 pos (0) = pos (0) * sz(0);
3504 pos (1) = pos (1) * sz(1); 3513 pos (1) = pos (1) * sz(1);
3505 pos (2) = pos (2) * sz(0); 3514 pos (2) = pos (2) * sz(0);
3506 pos (3) = pos (3) * sz(1); 3515 pos (3) = pos (3) * sz(1);
3511 3520
3512 void 3521 void
3513 figure::properties::update_papertype (void) 3522 figure::properties::update_papertype (void)
3514 { 3523 {
3515 caseless_str typ = get_papertype (); 3524 caseless_str typ = get_papertype ();
3516
3517 if (! typ.compare ("<custom>")) 3525 if (! typ.compare ("<custom>"))
3518 // Call papersize.set rather than set_papersize to avoid loops between 3526 {
3519 // update_papersize and update_papertype 3527 Matrix sz = papersize_from_type (get_paperunits (), typ);
3520 papersize.set (octave_value (papersize_from_type (get_paperunits (), typ))); 3528 caseless_str porient = get_paperorientation ();
3529 if (porient.compare ("landscape"))
3530 {
3531 double tmp = sz (0);
3532 sz (0) = sz (1);
3533 sz (1) = tmp;
3534 }
3535 // Call papersize.set rather than set_papersize to avoid loops between
3536 // update_papersize and update_papertype
3537 papersize.set (octave_value (sz));
3538 }
3521 } 3539 }
3522 3540
3523 void 3541 void
3524 figure::properties::update_papersize (void) 3542 figure::properties::update_papersize (void)
3525 { 3543 {
3526 papertype.set ("<custom>"); 3544 Matrix sz = get_papersize ().matrix_value ();
3527 } 3545 if (sz (0) > sz (1))
3546 {
3547 double tmp = sz (0);
3548 sz (0) = sz (1);
3549 sz (1) = tmp;
3550 papersize.set (octave_value (sz));
3551 caseless_str porient = "landscape";
3552 paperorientation.set (octave_value (porient));
3553 }
3554 else
3555 {
3556 caseless_str porient = "portrait";
3557 paperorientation.set (octave_value (porient));
3558 }
3559 caseless_str punits = get_paperunits ();
3560 if (punits.compare ("centimeters"))
3561 {
3562 sz (0) = sz (0) / 2.54;
3563 sz (1) = sz (1) / 2.54;
3564 }
3565 else if (punits.compare ("points"))
3566 {
3567 sz (0) = sz (0) / 72.0;
3568 sz (1) = sz (1) / 72.0;
3569 }
3570 if (punits.compare ("normalized"))
3571 {
3572 caseless_str typ = get_papertype ();
3573 if (typ.compare ("<custom>"))
3574 error ("set: can't set the papertype to <custom> when the paperunits is normalized");
3575 }
3576 else
3577 {
3578 // TODO - the papersizes info is also in papersize_from_type(). Both should be
3579 // rewritten to avoid the duplication.
3580 caseless_str typ = "<custom>";
3581 double mm2in = 1.0 / 25.4;
3582 double tol = 0.01;
3583 if (std::abs (sz (0) - 8.5) + std::abs (sz (1) - 11.0) < tol)
3584 typ = "usletter";
3585 else if (std::abs (sz (0) - 8.5) + std::abs (sz (1) - 14.0) < tol)
3586 typ = "uslegal";
3587 else if (std::abs (sz (0) - 11.0) + std::abs (sz (1) - 17.0) < tol)
3588 typ = "tabloid";
3589 else if (std::abs (sz (0) - 841.0 * mm2in) + std::abs (sz (1) - 1198.0 * mm2in) < tol)
3590 typ = "a0";
3591 else if (std::abs (sz (0) - 594.0 * mm2in) + std::abs (sz (1) - 841.0 * mm2in) < tol)
3592 typ = "a1";
3593 else if (std::abs (sz (0) - 420.0 * mm2in) + std::abs (sz (1) - 594.0 * mm2in) < tol)
3594 typ = "a2";
3595 else if (std::abs (sz (0) - 297.0 * mm2in) + std::abs (sz (1) - 420.0 * mm2in) < tol)
3596 typ = "a3";
3597 else if (std::abs (sz (0) - 210.0 * mm2in) + std::abs (sz (1) - 297.0 * mm2in) < tol)
3598 typ = "a4";
3599 else if (std::abs (sz (0) - 148.0 * mm2in) + std::abs (sz (1) - 210.0 * mm2in) < tol)
3600 typ = "a5";
3601 else if (std::abs (sz (0) - 1029.0 * mm2in) + std::abs (sz (1) - 1456.0 * mm2in) < tol)
3602 typ = "b0";
3603 else if (std::abs (sz (0) - 728.0 * mm2in) + std::abs (sz (1) - 1028.0 * mm2in) < tol)
3604 typ = "b1";
3605 else if (std::abs (sz (0) - 514.0 * mm2in) + std::abs (sz (1) - 728.0 * mm2in) < tol)
3606 typ = "b2";
3607 else if (std::abs (sz (0) - 364.0 * mm2in) + std::abs (sz (1) - 514.0 * mm2in) < tol)
3608 typ = "b3";
3609 else if (std::abs (sz (0) - 257.0 * mm2in) + std::abs (sz (1) - 364.0 * mm2in) < tol)
3610 typ = "b4";
3611 else if (std::abs (sz (0) - 182.0 * mm2in) + std::abs (sz (1) - 257.0 * mm2in) < tol)
3612 typ = "b5";
3613 else if (std::abs (sz (0) - 9.0) + std::abs (sz (1) - 12.0) < tol)
3614 typ = "arch-a";
3615 else if (std::abs (sz (0) - 12.0) + std::abs (sz (1) - 18.0) < tol)
3616 typ = "arch-b";
3617 else if (std::abs (sz (0) - 18.0) + std::abs (sz (1) - 24.0) < tol)
3618 typ = "arch-c";
3619 else if (std::abs (sz (0) - 24.0) + std::abs (sz (1) - 36.0) < tol)
3620 typ = "arch-d";
3621 else if (std::abs (sz (0) - 36.0) + std::abs (sz (1) - 48.0) < tol)
3622 typ = "arch-e";
3623 else if (std::abs (sz (0) - 8.5) + std::abs (sz (1) - 11.0) < tol)
3624 typ = "a";
3625 else if (std::abs (sz (0) - 11.0) + std::abs (sz (1) - 17.0) < tol)
3626 typ = "b";
3627 else if (std::abs (sz (0) - 17.0) + std::abs (sz (1) - 22.0) < tol)
3628 typ = "c";
3629 else if (std::abs (sz (0) - 22.0) + std::abs (sz (1) - 34.0) < tol)
3630 typ = "d";
3631 else if (std::abs (sz (0) - 34.0) + std::abs (sz (1) - 43.0) < tol)
3632 typ = "e";
3633 // Call papertype.set rather than set_papertype to avoid loops between
3634 // update_papersize and update_papertype
3635 papertype.set (typ);
3636 }
3637 }
3638
3639 void
3640 figure::properties::update_paperorientation (void)
3641 {
3642 caseless_str porient = get_paperorientation ();
3643 Matrix sz = get_papersize ().matrix_value ();
3644 Matrix pos = get_paperposition ().matrix_value ();
3645 if ((sz (0) > sz (1) && porient.compare ("portrait"))
3646 || (sz (0) < sz (1) && porient.compare ("landscape")))
3647 {
3648 double tmp = sz (0);
3649 sz (0) = sz (1);
3650 sz (1) = tmp;
3651 tmp = pos (0);
3652 pos (0) = pos (1);
3653 pos (1) = tmp;
3654 tmp = pos (2);
3655 pos (2) = pos (3);
3656 pos (3) = tmp;
3657 // Call papertype.set rather than set_papertype to avoid loops between
3658 // update_papersize and update_papertype
3659 papersize.set (octave_value (sz));
3660 paperposition.set (octave_value (pos));
3661 }
3662 }
3663
3664 /*
3665 %!test
3666 %! figure (1, "visible", false);
3667 %! tol = 100 * eps ();
3668 %! set (gcf (), "paperorientation", "portrait")
3669 %! set (gcf (), "paperunits", "inches")
3670 %! set (gcf (), "papertype", "usletter")
3671 %! assert (get (gcf (), "papersize"), [8.5, 11.0], tol)
3672 %! set (gcf (), "paperorientation", "landscape")
3673 %! assert (get (gcf (), "papersize"), [11.0, 8.5], tol)
3674 %! set (gcf (), "paperunits", "centimeters")
3675 %! assert (get (gcf (), "papersize"), [11.0, 8.5] * 2.54, tol)
3676 %! set (gcf (), "papertype", "a4");
3677 %! assert (get (gcf (), "papersize"), [29.7, 21.0], tol)
3678 %! set (gcf (), "paperunits", "inches", "papersize", [8.5, 11.0])
3679 %! assert (get (gcf (), "papertype"), "usletter")
3680 %! assert (get (gcf (), "paperorientation"), "portrait")
3681 %! set (gcf (), "papersize", [11.0, 8.5])
3682 %! assert (get (gcf (), "papertype"), "usletter")
3683 %! assert (get (gcf (), "paperorientation"), "landscape")
3684 */
3528 3685
3529 void 3686 void
3530 figure::properties::set_units (const octave_value& v) 3687 figure::properties::set_units (const octave_value& v)
3531 { 3688 {
3532 if (! error_state) 3689 if (! error_state)