1 //////////////////////////////////////////////////////////////////////////////
2 // Name:        SVGRect.cpp
3 // Purpose:
4 // Author:      Alex Thuering
5 // Created:     2005/09/27
6 // RCS-ID:      $Id: SVGRect.cpp,v 1.5 2006/02/26 14:50:01 ntalex Exp $
7 // Copyright:   (c) 2005 Alex Thuering
8 // Licence:     wxWindows licence
9 //////////////////////////////////////////////////////////////////////////////
10 
11 #include "SVGRect.h"
12 #include "SVGPoint.h"
13 #include <wx/tokenzr.h>
14 
GetValueAsString() const15 wxString wxSVGRect::GetValueAsString() const {
16   return wxString::Format(wxT("%g %g %g %g"), GetX(), GetY(), GetWidth(), GetHeight());
17 }
18 
SetValueAsString(const wxString & value)19 void wxSVGRect::SetValueAsString(const wxString& value)
20 {
21   double val;
22   wxStringTokenizer tkz(value, wxT(", \\t"));
23   int pi = 0;
24   while (tkz.HasMoreTokens() && pi<4)
25   {
26     wxString token = tkz.GetNextToken();
27     token.ToDouble(&val);
28     switch (pi)
29     {
30       case 0: SetX(val); break;
31       case 1: SetY(val); break;
32       case 2: SetWidth(val); break;
33       case 3: SetHeight(val); break;
34     }
35     pi++;
36   }
37 }
38 
MatrixTransform(const wxSVGMatrix & matrix) const39 wxSVGRect wxSVGRect::MatrixTransform(const wxSVGMatrix& matrix) const
40 {
41   wxSVGPoint point1(GetX(), GetY());
42   point1 = point1.MatrixTransform(matrix);
43   wxSVGPoint point2(GetX() + GetWidth(), GetY() + GetHeight());
44   point2 = point2.MatrixTransform(matrix);
45 
46   wxSVGRect rect;
47   rect.SetX(point1.GetX() < point2.GetX() ? point1.GetX() : point2.GetX());
48   rect.SetY(point1.GetY() < point2.GetY() ? point1.GetY() : point2.GetY());
49   rect.SetWidth(point1.GetX() < point2.GetX() ? point2.GetX() - rect.GetX() : point1.GetX() - rect.GetX());
50   rect.SetHeight(point1.GetY() < point2.GetY() ? point2.GetY() - rect.GetY() : point1.GetY() - rect.GetY());
51   return rect;
52 }
53