WPSGraphicShape.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
00002 
00003 /* libwps
00004  * Version: MPL 2.0 / LGPLv2.1+
00005  *
00006  * This Source Code Form is subject to the terms of the Mozilla Public
00007  * License, v. 2.0. If a copy of the MPL was not distributed with this
00008  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
00009  *
00010  * Major Contributor(s):
00011  * Copyright (C) 2002, 2005 William Lachance (william.lachance@sympatico.ca)
00012  * Copyright (C) 2002, 2004 Marc Maurer (uwog@uwog.net)
00013  *
00014  * For minor contributions see the git repository.
00015  *
00016  * Alternatively, the contents of this file may be used under the terms
00017  * of the GNU Lesser General Public License Version 2.1 or later
00018  * (LGPLv2.1+), in which case the provisions of the LGPLv2.1+ are
00019  * applicable instead of those above.
00020  *
00021  * For further information visit http://libwps.sourceforge.net
00022 */
00023 #ifndef WPS_GRAPHIC_SHAPE
00024 #  define WPS_GRAPHIC_SHAPE
00025 #  include <ostream>
00026 #  include <string>
00027 #  include <vector>
00028 
00029 #  include "librevenge/librevenge.h"
00030 
00031 #  include "libwps_internal.h"
00032 
00034 class WPSGraphicShape
00035 {
00036 public:
00038         enum Type { Arc, Circle, Line, Rectangle, Path, Pie, Polygon, ShapeUnknown };
00040         enum Command { C_Ellipse, C_Polyline, C_Rectangle, C_Path, C_Polygon, C_Bad };
00042         struct PathData
00043         {
00045                 PathData(char type, Vec2f const &x=Vec2f(), Vec2f const &x1=Vec2f(), Vec2f const &x2=Vec2f()):
00046                         m_type(type), m_x(x), m_x1(x1), m_x2(x2), m_r(), m_rotate(0), m_largeAngle(false), m_sweep(false)
00047                 {
00048                 }
00050                 void translate(Vec2f const &delta);
00052                 void scale(Vec2f const &factor);
00054                 void rotate(float angle, Vec2f const &delta);
00056                 bool get(librevenge::RVNGPropertyList &pList, Vec2f const &orig) const;
00058                 friend std::ostream &operator<<(std::ostream &o, PathData const &path);
00060                 int cmp(PathData const &a) const;
00062                 char m_type;
00064                 Vec2f m_x;
00066                 Vec2f m_x1;
00068                 Vec2f m_x2;
00070                 Vec2f m_r;
00072                 float m_rotate;
00074                 bool m_largeAngle;
00076                 bool m_sweep;
00077         };
00078 
00080         WPSGraphicShape() : m_type(ShapeUnknown), m_bdBox(), m_formBox(), m_cornerWidth(0,0), m_arcAngles(0,0),
00081                 m_vertices(), m_path(), m_extra("")
00082         {
00083         }
00085         virtual ~WPSGraphicShape() { }
00087         static WPSGraphicShape line(Vec2f const &orign, Vec2f const &dest);
00089         static WPSGraphicShape rectangle(Box2f const &box, Vec2f const &corners=Vec2f(0,0))
00090         {
00091                 WPSGraphicShape res;
00092                 res.m_type=Rectangle;
00093                 res.m_bdBox=res.m_formBox=box;
00094                 res.m_cornerWidth=corners;
00095                 return res;
00096         }
00098         static WPSGraphicShape circle(Box2f const &box)
00099         {
00100                 WPSGraphicShape res;
00101                 res.m_type=Circle;
00102                 res.m_bdBox=res.m_formBox=box;
00103                 return res;
00104         }
00106         static WPSGraphicShape arc(Box2f const &box, Box2f const &circleBox, Vec2f const &angles)
00107         {
00108                 WPSGraphicShape res;
00109                 res.m_type=Arc;
00110                 res.m_bdBox=box;
00111                 res.m_formBox=circleBox;
00112                 res.m_arcAngles=angles;
00113                 return res;
00114         }
00116         static WPSGraphicShape pie(Box2f const &box, Box2f const &circleBox, Vec2f const &angles)
00117         {
00118                 WPSGraphicShape res;
00119                 res.m_type=Pie;
00120                 res.m_bdBox=box;
00121                 res.m_formBox=circleBox;
00122                 res.m_arcAngles=angles;
00123                 return res;
00124         }
00126         static WPSGraphicShape polygon(Box2f const &box)
00127         {
00128                 WPSGraphicShape res;
00129                 res.m_type=Polygon;
00130                 res.m_bdBox=box;
00131                 return res;
00132         }
00134         static WPSGraphicShape path(Box2f const &box)
00135         {
00136                 WPSGraphicShape res;
00137                 res.m_type=Path;
00138                 res.m_bdBox=box;
00139                 return res;
00140         }
00141 
00143         void translate(Vec2f const &delta);
00145         void scale(Vec2f const &factor);
00149         WPSGraphicShape rotate(float angle, Vec2f const &center) const;
00151         Type getType() const
00152         {
00153                 return m_type;
00154         }
00156         Box2f getBdBox() const
00157         {
00158                 return m_bdBox;
00159         }
00161         Command addTo(Vec2f const &orig, bool asSurface, librevenge::RVNGPropertyList &propList) const;
00163         friend std::ostream &operator<<(std::ostream &o, WPSGraphicShape const &sh);
00165         int cmp(WPSGraphicShape const &a) const;
00166 protected:
00168         std::vector<PathData> getPath() const;
00169 public:
00171         Type m_type;
00173         Box2f m_bdBox;
00175         Box2f m_formBox;
00177         Vec2f m_cornerWidth;
00179         Vec2f m_arcAngles;
00181         std::vector<Vec2f> m_vertices;
00183         std::vector<PathData> m_path;
00185         std::string m_extra;
00186 };
00187 #endif
00188 /* vim:set shiftwidth=4 softtabstop=4 noexpandtab: */