MWAWGraphicShape.hxx
Go to the documentation of this file.
00001 /* -*- Mode: C++; c-default-style: "k&r"; indent-tabs-mode: nil; tab-width: 2; c-basic-offset: 2 -*- */
00002 
00003 /* libmwaw
00004 * Version: MPL 2.0 / LGPLv2+
00005 *
00006 * The contents of this file are subject to the Mozilla Public License Version
00007 * 2.0 (the "License"); you may not use this file except in compliance with
00008 * the License or as specified alternatively below. You may obtain a copy of
00009 * the License at http://www.mozilla.org/MPL/
00010 *
00011 * Software distributed under the License is distributed on an "AS IS" basis,
00012 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00013 * for the specific language governing rights and limitations under the
00014 * License.
00015 *
00016 * Major Contributor(s):
00017 * Copyright (C) 2002 William Lachance (wrlach@gmail.com)
00018 * Copyright (C) 2002,2004 Marc Maurer (uwog@uwog.net)
00019 * Copyright (C) 2004-2006 Fridrich Strba (fridrich.strba@bluewin.ch)
00020 * Copyright (C) 2006, 2007 Andrew Ziem
00021 * Copyright (C) 2011, 2012 Alonso Laurent (alonso@loria.fr)
00022 *
00023 *
00024 * All Rights Reserved.
00025 *
00026 * For minor contributions see the git repository.
00027 *
00028 * Alternatively, the contents of this file may be used under the terms of
00029 * the GNU Lesser General Public License Version 2 or later (the "LGPLv2+"),
00030 * in which case the provisions of the LGPLv2+ are applicable
00031 * instead of those above.
00032 */
00033 #ifndef MWAW_GRAPHIC_SHAPE
00034 #  define MWAW_GRAPHIC_SHAPE
00035 #  include <ostream>
00036 #  include <string>
00037 #  include <vector>
00038 
00039 #  include "librevenge/librevenge.h"
00040 #  include "libmwaw_internal.hxx"
00041 
00042 class MWAWGraphicStyle;
00043 
00045 class MWAWGraphicShape
00046 {
00047 public:
00049   enum Type { Arc, Circle, Line, Rectangle, Path, Pie, Polygon, ShapeUnknown };
00051   enum Command { C_Ellipse, C_Polyline, C_Rectangle, C_Path, C_Polygon, C_Bad };
00053   struct PathData {
00055     PathData(char type, MWAWVec2f const &x=MWAWVec2f(), MWAWVec2f const &x1=MWAWVec2f(), MWAWVec2f const &x2=MWAWVec2f()):
00056       m_type(type), m_x(x), m_x1(x1), m_x2(x2), m_r(), m_rotate(0), m_largeAngle(false), m_sweep(false)
00057     {
00058     }
00060     void translate(MWAWVec2f const &delta);
00062     void scale(MWAWVec2f const &factor);
00064     void rotate(float angle, MWAWVec2f const &delta);
00066     bool get(librevenge::RVNGPropertyList &pList, MWAWVec2f const &orig) const;
00068     friend std::ostream &operator<<(std::ostream &o, PathData const &path);
00070     int cmp(PathData const &a) const;
00072     char m_type;
00074     MWAWVec2f m_x;
00076     MWAWVec2f m_x1;
00078     MWAWVec2f m_x2;
00080     MWAWVec2f m_r;
00082     float m_rotate;
00084     bool m_largeAngle;
00086     bool m_sweep;
00087   };
00088 
00090   MWAWGraphicShape() : m_type(ShapeUnknown), m_bdBox(), m_formBox(), m_cornerWidth(0,0), m_arcAngles(0,0),
00091     m_vertices(), m_path(), m_extra("")
00092   {
00093   }
00095   virtual ~MWAWGraphicShape() { }
00097   static MWAWGraphicShape line(MWAWVec2f const &orign, MWAWVec2f const &dest);
00099   static MWAWGraphicShape rectangle(MWAWBox2f const &box, MWAWVec2f const &corners=MWAWVec2f(0,0))
00100   {
00101     MWAWGraphicShape res;
00102     res.m_type=Rectangle;
00103     res.m_bdBox=res.m_formBox=box;
00104     res.m_cornerWidth=corners;
00105     return res;
00106   }
00108   static MWAWGraphicShape circle(MWAWBox2f const &box)
00109   {
00110     MWAWGraphicShape res;
00111     res.m_type=Circle;
00112     res.m_bdBox=res.m_formBox=box;
00113     return res;
00114   }
00116   static MWAWGraphicShape arc(MWAWBox2f const &box, MWAWBox2f const &circleBox, MWAWVec2f const &angles)
00117   {
00118     MWAWGraphicShape res;
00119     res.m_type=Arc;
00120     res.m_bdBox=box;
00121     res.m_formBox=circleBox;
00122     res.m_arcAngles=angles;
00123     return res;
00124   }
00126   static MWAWGraphicShape pie(MWAWBox2f const &box, MWAWBox2f const &circleBox, MWAWVec2f const &angles)
00127   {
00128     MWAWGraphicShape res;
00129     res.m_type=Pie;
00130     res.m_bdBox=box;
00131     res.m_formBox=circleBox;
00132     res.m_arcAngles=angles;
00133     return res;
00134   }
00136   static MWAWGraphicShape polygon(MWAWBox2f const &box)
00137   {
00138     MWAWGraphicShape res;
00139     res.m_type=Polygon;
00140     res.m_bdBox=box;
00141     return res;
00142   }
00144   static MWAWGraphicShape path(MWAWBox2f const &box)
00145   {
00146     MWAWGraphicShape res;
00147     res.m_type=Path;
00148     res.m_bdBox=box;
00149     return res;
00150   }
00151 
00153   void translate(MWAWVec2f const &delta);
00155   void scale(MWAWVec2f const &factor);
00159   MWAWGraphicShape rotate(float angle, MWAWVec2f const &center) const;
00161   Type getType() const
00162   {
00163     return m_type;
00164   }
00166   MWAWBox2f getBdBox() const
00167   {
00168     return m_bdBox;
00169   }
00171   MWAWBox2f getBdBox(MWAWGraphicStyle const &style, bool moveToO=false) const;
00173   Command addTo(MWAWVec2f const &orig, bool asSurface, librevenge::RVNGPropertyList &propList) const;
00175   friend std::ostream &operator<<(std::ostream &o, MWAWGraphicShape const &sh);
00177   int cmp(MWAWGraphicShape const &a) const;
00178 protected:
00180   std::vector<PathData> getPath() const;
00181 public:
00183   Type m_type;
00185   MWAWBox2f m_bdBox;
00187   MWAWBox2f m_formBox;
00189   MWAWVec2f m_cornerWidth;
00191   MWAWVec2f m_arcAngles;
00193   std::vector<MWAWVec2f> m_vertices;
00195   std::vector<PathData> m_path;
00197   std::string m_extra;
00198 };
00199 #endif
00200 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab: