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 "libwpd/libwpd.h"
00040 #  include "libmwaw_internal.hxx"
00041 
00042 class WPXPropertyList;
00043 class MWAWGraphicStyle;
00044 
00046 class MWAWGraphicShape
00047 {
00048 public:
00050   enum Type { Arc, Circle, Line, Rectangle, Path, Pie, Polygon, ShapeUnknown };
00052   struct PathData {
00054     PathData(char type, Vec2f const &x=Vec2f(), Vec2f const &x1=Vec2f(), Vec2f const &x2=Vec2f()):
00055       m_type(type), m_x(x), m_x1(x1), m_x2(x2), m_r(), m_rotate(0), m_largeAngle(false), m_sweep(false) {
00056     }
00058     void translate(Vec2f const &delta);
00060     void rotate(float angle, Vec2f const &delta);
00062     bool get(WPXPropertyList &pList, Vec2f const &orig) const;
00064     friend std::ostream &operator<<(std::ostream &o, PathData const &path);
00066     int cmp(PathData const &a) const;
00068     char m_type;
00070     Vec2f m_x;
00072     Vec2f m_x1;
00074     Vec2f m_x2;
00076     Vec2f m_r;
00078     float m_rotate;
00080     bool m_largeAngle;
00082     bool m_sweep;
00083   };
00084 
00086   MWAWGraphicShape() : m_type(ShapeUnknown), m_bdBox(), m_formBox(), m_cornerWidth(0,0), m_arcAngles(0,0),
00087     m_vertices(), m_path(), m_extra("") {
00088   }
00090   virtual ~MWAWGraphicShape() { }
00092   static MWAWGraphicShape line(Vec2f const &orign, Vec2f const &dest);
00094   static MWAWGraphicShape rectangle(Box2f const &box, Vec2f const &corners=Vec2f(0,0)) {
00095     MWAWGraphicShape res;
00096     res.m_type=Rectangle;
00097     res.m_bdBox=res.m_formBox=box;
00098     res.m_cornerWidth=corners;
00099     return res;
00100   }
00102   static MWAWGraphicShape circle(Box2f const &box) {
00103     MWAWGraphicShape res;
00104     res.m_type=Circle;
00105     res.m_bdBox=res.m_formBox=box;
00106     return res;
00107   }
00109   static MWAWGraphicShape arc(Box2f const &box, Box2f const &circleBox, Vec2f const &angles) {
00110     MWAWGraphicShape res;
00111     res.m_type=Arc;
00112     res.m_bdBox=box;
00113     res.m_formBox=circleBox;
00114     res.m_arcAngles=angles;
00115     return res;
00116   }
00118   static MWAWGraphicShape pie(Box2f const &box, Box2f const &circleBox, Vec2f const &angles) {
00119     MWAWGraphicShape res;
00120     res.m_type=Pie;
00121     res.m_bdBox=box;
00122     res.m_formBox=circleBox;
00123     res.m_arcAngles=angles;
00124     return res;
00125   }
00127   static MWAWGraphicShape polygon(Box2f const &box) {
00128     MWAWGraphicShape res;
00129     res.m_type=Polygon;
00130     res.m_bdBox=box;
00131     return res;
00132   }
00134   static MWAWGraphicShape path(Box2f const &box) {
00135     MWAWGraphicShape res;
00136     res.m_type=Path;
00137     res.m_bdBox=box;
00138     return res;
00139   }
00140 
00142   void translate(Vec2f const &delta);
00146   MWAWGraphicShape rotate(float angle, Vec2f const &center) const;
00148   Box2f getBdBox(MWAWGraphicStyle const &style, bool moveToO=false) const;
00150   bool send(MWAWGraphicInterface &interface, MWAWGraphicStyle const &style, Vec2f const &orig) const;
00152   friend std::ostream &operator<<(std::ostream &o, MWAWGraphicShape const &sh);
00154   int cmp(MWAWGraphicShape const &a) const;
00155 protected:
00157   std::vector<PathData> getPath() const;
00158 public:
00160   Type m_type;
00162   Box2f m_bdBox;
00164   Box2f m_formBox;
00166   Vec2f m_cornerWidth;
00168   Vec2f m_arcAngles;
00170   std::vector<Vec2f> m_vertices;
00172   std::vector<PathData> m_path;
00174   std::string m_extra;
00175 };
00176 #endif
00177 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab: