00001
00010 #ifndef _BOARD_TRANSFORMS_H_
00011 #define _BOARD_TRANSFORMS_H_
00012
00013 #include <limits>
00014 #include <vector>
00015 #include <cmath>
00016
00017 namespace LibBoard {
00018
00019 struct Rect;
00020 struct Shape;
00021 struct ShapeList;
00022
00027 struct Transform {
00028 public:
00029 Transform() : _scale(1.0), _deltaX(0.0), _deltaY(0.0), _height(0.0) { }
00030 virtual ~Transform() { };
00031 virtual float mapX( float x ) const;
00032 virtual float mapY( float y ) const = 0;
00033 virtual void apply( float & x, float & y ) const;
00034 virtual float scale( float x ) const;
00035 virtual float rounded( float x ) const;
00036 virtual void setBoundingBox( const Rect & rect,
00037 const float pageWidth,
00038 const float pageHeight,
00039 const float margin ) = 0;
00040
00041 static inline float round( const float & x );
00042 static inline double round( const double & x );
00043
00044 protected:
00045 float _scale;
00046 float _deltaX;
00047 float _deltaY;
00048 float _height;
00049 };
00050
00056 struct TransformEPS : public Transform {
00057 public:
00058 float mapY( float y ) const;
00059 void setBoundingBox( const Rect & rect,
00060 const float pageWidth,
00061 const float pageHeight,
00062 const float margin );
00063 };
00064
00070 struct TransformFIG : public Transform {
00071 public:
00072 TransformFIG():_maxDepth(std::numeric_limits<int>::max()),_minDepth(0) { }
00073 float rounded( float x ) const;
00074 float mapY( float y ) const;
00075 int mapWidth( float width ) const;
00076 void setBoundingBox( const Rect & rect,
00077 const float pageWidth,
00078 const float pageHeight,
00079 const float margin );
00080 void setDepthRange( const ShapeList & shapes );
00081 int mapDepth( int depth ) const;
00082 private:
00083 int _maxDepth;
00084 int _minDepth;
00085 };
00086
00092 struct TransformSVG : public Transform {
00093 public:
00094 float rounded( float x ) const;
00095 float mapY( float y ) const;
00096 float mapWidth( float width ) const;
00097 void setBoundingBox( const Rect & rect,
00098 const float pageWidth,
00099 const float pageHeight,
00100 const float margin );
00101 };
00102
00103 inline float Transform::round( const float & x )
00104 {
00105 return static_cast<float>( std::floor( x + 0.5f ) );
00106 }
00107
00108 inline double Transform::round( const double & x )
00109 {
00110 return std::floor( x + 0.5 );
00111 }
00112
00113 }
00114
00115 #endif