PolygonUtils.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 
00029 #ifndef __POLYGONUTILS_H__
00030 #define __POLYGONUTILS_H__
00031 
00032 #include <vector>
00033 
00034 #include <libwpg/libwpg.h>
00035 #include <boost/function.hpp>
00036 #include <boost/shared_ptr.hpp>
00037 
00038 #include "ShapeType.h"
00039 #include "VectorTransformation2D.h"
00040 #include "Coordinate.h"
00041 #include "Line.h"
00042 
00043 namespace libmspub
00044 {
00045 const int PROP_ADJUST_VAL_FIRST = 327;
00046 const int PROP_ADJUST_VAL_LAST  = 336;
00047 const int PROP_GEO_LEFT         = 320;
00048 const int PROP_GEO_TOP          = 321;
00049 const int PROP_GEO_RIGHT        = 322;
00050 const int PROP_GEO_BOTTOM       = 323;
00051 
00052 const int OTHER_CALC_VAL        = 0x400;
00053 const int ASPECT_RATIO          = 0x600;
00054 
00055 class MSPUBCollector;
00056 
00057 typedef struct
00058 {
00059   int m_x;
00060   int m_y;
00061 }  Vertex;
00062 
00063 typedef struct
00064 {
00065   int m_flags;
00066   int m_argOne;
00067   int m_argTwo;
00068   int m_argThree;
00069 } Calculation;
00070 
00071 typedef struct
00072 {
00073   Vertex first;
00074   Vertex second;
00075 } TextRectangle;
00076 
00077 struct CustomShape
00078 {
00079   const Vertex *mp_vertices;
00080   unsigned m_numVertices;
00081   const unsigned short *mp_elements;
00082   unsigned m_numElements;
00083   const Calculation *mp_calculations;
00084   unsigned m_numCalculations;
00085   const int *mp_defaultAdjustValues;
00086   unsigned m_numDefaultAdjustValues;
00087   const TextRectangle *mp_textRectangles;
00088   unsigned m_numTextRectangles;
00089   unsigned m_coordWidth;
00090   unsigned m_coordHeight;
00091   const Vertex *mp_gluePoints;
00092   unsigned m_numGluePoints;
00093   unsigned char m_adjustShiftMask;
00094 
00095   Coordinate getTextRectangle(double x, double y, double width, double height, boost::function<double (unsigned index)> calculator) const;
00096 
00097   CustomShape(const Vertex *p_vertices, unsigned numVertices, const unsigned short *p_elements, unsigned numElements, const Calculation *p_calculations, unsigned numCalculations, const int *p_defaultAdjustValues, unsigned numDefaultAdjustValues, const TextRectangle *p_textRectangles, unsigned numTextRectangles, unsigned coordWidth, unsigned coordHeight, const Vertex *p_gluePoints, unsigned numGluePoints, unsigned char adjustShiftMask = 0) :
00098     mp_vertices(p_vertices), m_numVertices(numVertices),
00099     mp_elements(p_elements), m_numElements(numElements),
00100     mp_calculations(p_calculations), m_numCalculations(numCalculations),
00101     mp_defaultAdjustValues(p_defaultAdjustValues), m_numDefaultAdjustValues(numDefaultAdjustValues),
00102     mp_textRectangles(p_textRectangles), m_numTextRectangles(numTextRectangles),
00103     m_coordWidth(coordWidth), m_coordHeight(coordHeight),
00104     mp_gluePoints(p_gluePoints), m_numGluePoints(numGluePoints),
00105     m_adjustShiftMask(adjustShiftMask)
00106   {
00107   }
00108 };
00109 
00110 struct DynamicCustomShape
00111 {
00112   std::vector<Vertex> m_vertices;
00113   std::vector<unsigned short> m_elements;
00114   std::vector<Calculation> m_calculations;
00115   std::vector<int> m_defaultAdjustValues;
00116   std::vector<TextRectangle> m_textRectangles;
00117   std::vector<Vertex> m_gluePoints;
00118   unsigned m_coordWidth;
00119   unsigned m_coordHeight;
00120   unsigned char m_adjustShiftMask;
00121 
00122   DynamicCustomShape(unsigned coordWidth, unsigned coordHeight)
00123     : m_vertices(), m_elements(),
00124       m_calculations(), m_defaultAdjustValues(),
00125       m_textRectangles(), m_gluePoints(),
00126       m_coordWidth(coordWidth), m_coordHeight(coordHeight),
00127       m_adjustShiftMask(0)
00128   {
00129   }
00130 };
00131 
00132 boost::shared_ptr<const CustomShape> getFromDynamicCustomShape(const DynamicCustomShape &dcs);
00133 
00134 const CustomShape *getCustomShape(ShapeType type);
00135 bool isShapeTypeRectangle(ShapeType type);
00136 WPXPropertyList calcClipPath(const std::vector<libmspub::Vertex> &verts, double x, double y, double height, double width, VectorTransformation2D transform, boost::shared_ptr<const CustomShape> shape);
00137 void writeCustomShape(ShapeType shapeType, WPXPropertyList &graphicsProps, libwpg::WPGPaintInterface *painter, double x, double y, double height, double width, bool closeEverything, VectorTransformation2D transform, std::vector<Line> lines, boost::function<double(unsigned index)> calculator, const std::vector<Color> &palette, boost::shared_ptr<const CustomShape> shape);
00138 
00139 } // libmspub
00140 #endif /* __POLYGONUTILS_H__ */
00141 /* vim:set shiftwidth=2 softtabstop=2 expandtab: */