Shapes.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* libmspub
00003  * Version: MPL 1.1 / GPLv2+ / LGPLv2+
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License or as specified alternatively below. You may obtain a copy of
00008  * the License at http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * Major Contributor(s):
00016  * Copyright (C) 2012 Brennan Vincent <brennanv@email.arizona.edu>
00017  *
00018  * All Rights Reserved.
00019  *
00020  * For minor contributions see the git repository.
00021  *
00022  * Alternatively, the contents of this file may be used under the terms of
00023  * either the GNU General Public License Version 2 or later (the "GPLv2+"), or
00024  * the GNU Lesser General Public License Version 2 or later (the "LGPLv2+"),
00025  * in which case the provisions of the GPLv2+ or the LGPLv2+ are applicable
00026  * instead of those above.
00027  */
00028 #ifndef __SHAPES_H__
00029 #define __SHAPES_H__
00030 
00031 #include <vector>
00032 #include <map>
00033 
00034 #include "Coordinate.h"
00035 #include "MSPUBConstants.h"
00036 #include "ShapeType.h"
00037 #include "VectorTransformation2D.h"
00038 
00039 namespace libmspub
00040 {
00041 class MSPUBCollector;
00042 struct CustomShape;
00043 struct Shape
00044 {
00045   Shape(MSPUBCollector *o) : props(), graphicsProps(), owner(o) { }
00046   virtual void output(libwpg::WPGPaintInterface *painter, Coordinate coord);
00047   virtual ~Shape()
00048   {
00049   }
00050   WPXPropertyList props;
00051   WPXPropertyList graphicsProps;
00052 protected:
00053   virtual void setCoordProps(Coordinate coord);
00054   virtual void write(libwpg::WPGPaintInterface *painter) = 0;
00055   MSPUBCollector *owner;
00056 
00057   virtual WPXPropertyListVector updateGraphicsProps();
00058 
00059   Shape();
00060 private:
00061   Shape(const Shape &);
00062   Shape &operator=(const Shape &);
00063 };
00064 struct FillableShape : public Shape
00065 {
00066   FillableShape(MSPUBCollector *o) : Shape(o), m_fill(NULL) { }
00067   Fill *m_fill;
00068   void setFill(Fill *fill);
00069 protected:
00070   virtual WPXPropertyListVector updateGraphicsProps();
00071 private:
00072   FillableShape(const FillableShape &);
00073   FillableShape &operator=(const FillableShape &);
00074 };
00075 struct GeometricShape : public FillableShape
00076 {
00077   void addLine(ColorReference color, unsigned widthInEmu, bool lineExists);
00078   void fillDefaultAdjustValues();
00079   void setAdjustValue(unsigned index, int adjustValue);
00080   void setText(std::vector<TextParagraph> str);
00081   double getCalculationValue(unsigned index, bool recursiveEntry = false) const;
00082   double getSpecialValue(const CustomShape &shape, int arg) const;
00083   void writeText(libwpg::WPGPaintInterface *painter);
00084   void setTransformation(VectorTransformation2D transform);
00085 
00086   std::vector<TextParagraph> m_str;
00087   bool m_hasText;
00088   unsigned m_pageSeqNum;
00089   unsigned m_imgIndex;
00090   ShapeType m_type;
00091   double m_x, m_y, m_width, m_height;
00092   VectorTransformation2D m_transform;
00093   std::vector<int> m_adjustValues;
00094   unsigned m_left, m_top, m_right, m_bottom; //emu
00095   GeometricShape(MSPUBCollector *o)
00096     : FillableShape(o), m_str(), m_hasText(false), m_pageSeqNum(0), m_imgIndex(0), m_type(RECTANGLE),
00097       m_x(0), m_y(0), m_width(0), m_height(0), m_transform(VectorTransformation2D()),
00098       m_adjustValues(),
00099       m_left(DEFAULT_MARGIN), m_top(DEFAULT_MARGIN), m_right(DEFAULT_MARGIN), m_bottom(DEFAULT_MARGIN),
00100       m_valuesSeen(), m_filledDefaultAdjustValues(false), m_textCoord(), m_closeEverything(false),
00101       m_lines(), m_drawStroke(false),
00102       m_borderPosition(HALF_INSIDE_SHAPE),
00103       m_coordinatesRotated90(false), m_foldedTransform(VectorTransformation2D()) { }
00104   GeometricShape(unsigned pageSeqNum, MSPUBCollector *o)
00105     : FillableShape(o), m_str(), m_hasText(false), m_pageSeqNum(pageSeqNum), m_imgIndex(0), m_type(RECTANGLE),
00106       m_x(0), m_y(0), m_width(0), m_height(0), m_transform(VectorTransformation2D()), m_adjustValues(),
00107       m_left(DEFAULT_MARGIN), m_top(DEFAULT_MARGIN), m_right(DEFAULT_MARGIN), m_bottom(DEFAULT_MARGIN),
00108       m_valuesSeen(), m_filledDefaultAdjustValues(false), m_textCoord(), m_closeEverything(false),
00109       m_lines(), m_drawStroke(false),
00110       m_borderPosition(HALF_INSIDE_SHAPE),
00111       m_coordinatesRotated90(false), m_foldedTransform(VectorTransformation2D()) { }
00112   std::vector<Color> getPaletteColors() const;
00113   void output(libwpg::WPGPaintInterface *painter, Coordinate coord);
00114 protected:
00115   virtual bool hasFill();
00116   void setCoordProps(Coordinate coord);
00117   virtual void write(libwpg::WPGPaintInterface *painter);
00118   WPXPropertyListVector updateGraphicsProps();
00119   GeometricShape();
00120 private:
00121   GeometricShape(const GeometricShape &);
00122   GeometricShape &operator=(const GeometricShape &);
00123   mutable std::vector<bool> m_valuesSeen;
00124   bool m_filledDefaultAdjustValues;
00125   Coordinate m_textCoord;
00126   bool m_closeEverything;
00127 public:
00128   std::vector<Line> m_lines;
00129   bool m_drawStroke;
00130   BorderPosition m_borderPosition;
00131   bool m_coordinatesRotated90;
00132   VectorTransformation2D m_foldedTransform;
00133 };
00134 } // namespace libmspub
00135 #endif // __SHAPES_H__
00136 /* vim:set shiftwidth=2 softtabstop=2 expandtab: */