1 /* 2 * Portable Agile C++ Classes (PACC) 3 * Copyright (C) 2001-2003 by Marc Parizeau 4 * http://manitou.gel.ulaval.ca/~parizeau/PACC 5 * 6 * This library is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU Lesser General Public 8 * License as published by the Free Software Foundation; either 9 * version 2.1 of the License, or (at your option) any later version. 10 * 11 * This library is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 * Lesser General Public License for more details. 15 * 16 * You should have received a copy of the GNU Lesser General Public 17 * License along with this library; if not, write to the Free Software 18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 * 20 * Contact: 21 * Laboratoire de Vision et Systemes Numeriques 22 * Departement de genie electrique et de genie informatique 23 * Universite Laval, Quebec, Canada, G1K 7P4 24 * http://vision.gel.ulaval.ca 25 * 26 */ 27 28 /*! 29 * \file PACC/SVG/Types.hpp 30 * \brief Class definition for the basic SVG types. 31 * \author Marc Parizeau and Michel Fortin, Laboratoire de vision et systèmes numériques, Université Laval 32 * $Revision: 1.6.2.1 $ 33 * $Date: 2007/09/10 18:24:09 $ 34 */ 35 36 #ifndef PACC_SVG_Types_hpp_ 37 #define PACC_SVG_Types_hpp_ 38 39 #include <cmath> 40 #include <vector> 41 #include <string> 42 43 namespace PACC { 44 45 namespace SVG { 46 47 using namespace std; 48 49 //! \brief Basic %SVG color string. 50 //! \ingroup SVG 51 class Color : public string { 52 public: 53 /*! 54 * \brief Constructor with color string. 55 * \param inColorString A string representing an" SVG color. 56 * 57 * Here are the valid" SVG colors formats: 58 * 59 * <table> 60 * <tr><th> Format </th><th> Description </th></tr> 61 * <tr><td> #rgb </td><td> Three-digit RGB notation</td></tr> 62 * <tr><td> #rrggbb </td><td> Six-digit RGB notation </td></tr> 63 * <tr><td> rgb(R, G, B) </td> 64 * <td> Functional notation (integer from 0 to 255) </td></tr> 65 * <tr><td> rgb(R%, G%, B%) </td> 66 * <td> Functional notation (percent) </td></tr> 67 * <tr><td> <colorname> </td><td> Keyword </td></tr> 68 * </table> 69 * 70 * If you want to use a color name keyword, you should use constants 71 * defined in this class instead. If you need to use direct numerical 72 * values, you should use the RGBColor or Gray subclass to construct 73 * the appropriate string. 74 * 75 * \note No string format validation is performed to ensure that it 76 * conform to SVG specifications. Make sure of what you write. 77 */ Color(const string & inColorString)78 explicit Color(const string &inColorString) : string(inColorString) {} 79 80 /*! 81 * \name Color Constants Keywords 82 * 83 * Borowed from 84 * <a href="http://www.w3.org/TR/SVG/types.html#ColorKeywords">SVG color 85 * keywords specifications</a>. Theses predefined colors should make 86 * your life easier. 87 */ 88 //@{ 89 static const Color cAliceBlue; //!< "aliceblue" SVG color 90 static const Color cAntiqueWhite; //!< "antiquewhite" SVG color 91 static const Color cAqua; //!< "aqua" SVG color 92 static const Color cAquaMarine; //!< "aquamarine" SVG color 93 static const Color cAzure; //!< "azure" SVG color 94 static const Color cBeige; //!< "beige" SVG color 95 static const Color cBisque; //!< "bisque" SVG color 96 static const Color cBlack; //!< "black" SVG color 97 static const Color cBlacheDalmond; //!< "blanchedalmond" SVG color 98 static const Color cBlue; //!< "blue" SVG color 99 static const Color cBlueViolet; //!< "blueviolet" SVG color 100 static const Color cBrown; //!< "brown" SVG color 101 static const Color cBurlyWood; //!< "burlywood" SVG color 102 static const Color cCadetBlue; //!< "cadetblue" SVG color 103 static const Color cChartreuse; //!< "chartreuse" SVG color 104 static const Color cChocolate; //!< "chocolate" SVG color 105 static const Color cCoral; //!< "coral" SVG color 106 static const Color cCornFlowerBlue; //!< "cornflowerblue" SVG color 107 static const Color cCornSilk; //!< "cornsilk" SVG color 108 static const Color cCrimson; //!< "crimson" SVG color 109 static const Color cCyan; //!< "cyan" SVG color 110 static const Color cDarkBlue; //!< "darkblue" SVG color 111 static const Color cDarkCyan; //!< "darkcyan" SVG color 112 static const Color cDarkGoldenRod; //!< "darkgoldenrod" SVG color 113 static const Color cDarkGray; //!< "darkgray" SVG color 114 static const Color cDarkGreen; //!< "darkgreen" SVG color 115 static const Color cDarkGrey; //!< "darkgrey" SVG color 116 static const Color cDarkKhaki; //!< "darkkhaki" SVG color 117 static const Color cDarkMagenta; //!< "darkmagenta" SVG color 118 static const Color cDarkOliveGreen; //!< "darkolivegreen" SVG color 119 static const Color cDarkOrange; //!< "darkorange" SVG color 120 static const Color cDarkOrchid; //!< "darkorchid" SVG color 121 static const Color cDarkRed; //!< "darkred" SVG color 122 static const Color cDarkSalmon; //!< "darksalmon" SVG color 123 static const Color cDarkSeaGreen; //!< "darkseagreen" SVG color 124 static const Color cDarkSlateBlue; //!< "darkslateblue" SVG color 125 static const Color cDarkSlateGray; //!< "darkslategray" SVG color 126 static const Color cDarkSlateGrey; //!< "darkslategrey" SVG color 127 static const Color cDarkTurquoise; //!< "darkturquoise" SVG color 128 static const Color cDarkViolet; //!< "darkviolet" SVG color 129 static const Color cDeepPink; //!< "deeppink" SVG color 130 static const Color cDeepSkyBlue; //!< "deepskyblue" SVG color 131 static const Color cDimGray; //!< "dimgray" SVG color 132 static const Color cDimGrey; //!< "dimgrey" SVG color 133 static const Color cDodgerBlue; //!< "dodgerblue" SVG color 134 static const Color cFireBrick; //!< "firebrick" SVG color 135 static const Color cFloralWhite; //!< "floralwhite" SVG color 136 static const Color cForestGreen; //!< "forestgreen" SVG color 137 static const Color cFuchsia; //!< "fuchsia" SVG color 138 static const Color cGainsboro; //!< "gainsboro" SVG color 139 static const Color cGostWhite; //!< "ghostwhite" SVG color 140 static const Color cGold; //!< "gold" SVG color 141 static const Color cGoldenRod; //!< "goldenrod" SVG color 142 static const Color cGray; //!< "gray" SVG color 143 static const Color cGrey; //!< "grey" SVG color 144 static const Color cGreen; //!< "green" SVG color 145 static const Color cGreenYellow; //!< "greenyellow" SVG color 146 static const Color cHoneyDew; //!< "honeydew" SVG color 147 static const Color cHotPink; //!< "hotpink" SVG color 148 static const Color cIndianRed; //!< "indianred" SVG color 149 static const Color cIndigo; //!< "indigo" SVG color 150 static const Color cIvory; //!< "ivory" SVG color 151 static const Color cKhaki; //!< "khaki" SVG color 152 static const Color cLavender; //!< "lavender" SVG color 153 static const Color cLavenderBlush; //!< "lavenderblush" SVG color 154 static const Color cLawnGreen; //!< "lawngreen" SVG color 155 static const Color cLemonChiffon; //!< "lemonchiffon" SVG color 156 static const Color cLightBlue; //!< "lightblue" SVG color 157 static const Color cLightCoral; //!< "lightcoral" SVG color 158 static const Color cLightCyan; //!< "lightcyan" SVG color 159 static const Color cLightGolderRodYellow; //!< "lightgoldenrodyellow" SVG color 160 static const Color cLightGray; //!< "lightgray" SVG color 161 static const Color cLightGreen; //!< "lightgreen" SVG color 162 static const Color cLightGrey; //!< "lightgrey" SVG color 163 static const Color cLigntPink; //!< "lightpink" SVG color 164 static const Color cLightSalmon; //!< "lightsalmon" SVG color 165 static const Color cLightSeaGreen; //!< "lightseagreen" SVG color 166 static const Color cLightSkyBlue; //!< "lightskyblue" SVG color 167 static const Color cLightSlateGray; //!< "lightslategray" SVG color 168 static const Color cLightSlateGrey; //!< "lightslategrey" SVG color 169 static const Color cLightSteelBlue; //!< "lightsteelblue" SVG color 170 static const Color cLightYellow; //!< "lightyellow" SVG color 171 static const Color cLime; //!< "lime" SVG color 172 static const Color cLimeGreen; //!< "limegreen" SVG color 173 static const Color cLinen; //!< "linen" SVG color 174 static const Color cMagenta; //!< "magenta" SVG color 175 static const Color cMaroon; //!< "maroon" SVG color 176 static const Color cMediumAquaMarine; //!< "mediumaquamarine" SVG color 177 static const Color cMediumBlue; //!< "mediumblue" SVG color 178 static const Color cMediumOrchid; //!< "mediumorchid" SVG color 179 static const Color cMediumPurple; //!< "mediumpurple" SVG color 180 static const Color cMeidumSeaGreen; //!< "mediumseagreen" SVG color 181 static const Color cMediumSlateBlue; //!< "mediumslateblue" SVG color 182 static const Color cMediumSpringGreen;//!< "mediumspringgreen" SVG color 183 static const Color cMediumTurquoise; //!< "mediumturquoise" SVG color 184 static const Color cMediumVioletRed; //!< "mediumvioletred" SVG color 185 static const Color cModNightBlue; //!< "midnightblue" SVG color 186 static const Color cMintCream; //!< "mintcream" SVG color 187 static const Color cMistyRose; //!< "mistyrose" SVG color 188 static const Color cMoccasin; //!< "moccasin" SVG color 189 static const Color cNavajoWhite; //!< "navajowhite" SVG color 190 static const Color cNavy; //!< "navy" SVG color 191 static const Color cOldLace; //!< "oldlace" SVG color 192 static const Color cOlive; //!< "olive" SVG color 193 static const Color cOliveDrab; //!< "olivedrab" SVG color 194 static const Color cOrange; //!< "orange" SVG color 195 static const Color cOrangered; //!< "orangered" SVG color 196 static const Color cOrchid; //!< "orchid" SVG color 197 static const Color cPaleGoldenRod; //!< "palegoldenrod" SVG color 198 static const Color cPaleGreen; //!< "palegreen" SVG color 199 static const Color cPaleTurquoise; //!< "paleturquoise" SVG color 200 static const Color cPaleVioletRed; //!< "palevioletred" SVG color 201 static const Color cPapayaWhip; //!< "papayawhip" SVG color 202 static const Color cPeachPuff; //!< "peachpuff" SVG color 203 static const Color cPeru; //!< "peru" SVG color 204 static const Color cPink; //!< "pink" SVG color 205 static const Color cPlum; //!< "plum" SVG color 206 static const Color cPowderBlue; //!< "powderblue" SVG color 207 static const Color cPurple; //!< "purple" SVG color 208 static const Color cRed; //!< "red" SVG color 209 static const Color cRosyBrown; //!< "rosybrown" SVG color 210 static const Color cRoyalBlue; //!< "royalblue" SVG color 211 static const Color cSaddleBrown; //!< "saddlebrown" SVG color 212 static const Color cSalmon; //!< "salmon" SVG color 213 static const Color cSandyBrown; //!< "sandybrown" SVG color 214 static const Color cSeaGreen; //!< "seagreen" SVG color 215 static const Color cSeaShell; //!< "seashell" SVG color 216 static const Color cSienna; //!< "sienna" SVG color 217 static const Color cSilver; //!< "silver" SVG color 218 static const Color cSkyBlue; //!< "skyblue" SVG color 219 static const Color cSlateBlue; //!< "slateblue" SVG color 220 static const Color cSlateGray; //!< "slategray" SVG color 221 static const Color cSlateGrey; //!< "slategrey" SVG color 222 static const Color cSnow; //!< "snow" SVG color 223 static const Color cSpringGreen; //!< "springgreen" SVG color 224 static const Color cSteelBlue; //!< "steelblue" SVG color 225 static const Color cTan; //!< "tan" SVG color 226 static const Color cTeal; //!< "teal" SVG color 227 static const Color cThistle; //!< "thistle" SVG color 228 static const Color cTomato; //!< "tomato" SVG color 229 static const Color cTurquoise; //!< "turquoise" SVG color 230 static const Color cViolet; //!< "violet" SVG color 231 static const Color cWheat; //!< "wheat" SVG color 232 static const Color cWhite; //!< "white" SVG color 233 static const Color cWhiteSmoke; //!< "whitesmoke" SVG color 234 static const Color cYellow; //!< "yellow" SVG color 235 static const Color cYellowGreen; //!< "yellowgreen" SVG color 236 //@} 237 }; 238 239 //! \brief Red, green, and blue color. 240 //! \ingroup SVG 241 class RGBColor : public Color { 242 public: 243 //! Construct with components \c inRed, \c inGreen, and \c inBlue. 244 RGBColor(float inRed, float inGreen, float inBlue); 245 }; 246 247 //! \brief %Color as a shade of gray. 248 //! \ingroup SVG 249 class Gray : public RGBColor { 250 public: 251 //! Construct gray color of intensity \c inLevel. Gray(float inLevel)252 Gray(float inLevel) : RGBColor(inLevel, inLevel, inLevel) {} 253 }; 254 255 class PointList; 256 257 //! \brief Position of graphic component. 258 //! \ingroup SVG 259 class Point { 260 public: 261 //! Default constructor. Point(void)262 Point(void) : x(0), y(0) {} 263 264 //! Construct with (\c inX,\c inY).. Point(double inX,double inY)265 Point(double inX, double inY) : x(inX), y(inY) {} 266 267 //! return the angle with the origin. getAngle(void) const268 double getAngle(void) const {return atan2(y,x);} 269 270 //! Return the distance from the origin. getDistance(void) const271 double getDistance(void) const {return sqrt(x*x+y*y);} 272 273 //! Rotate by \c inAngle degrees. rotate(double inAngle)274 void rotate(double inAngle) {*this = Point(x*cos(inAngle)-y*sin(inAngle), x*sin(inAngle)+y*cos(inAngle));} 275 276 //! Translate by offset (\c inDX,\c inDY). translateBy(double inDX,double inDY)277 void translateBy(double inDX, double inDY) {x += inDX; y += inDY;} 278 279 //! Scale by factor \c inFactor scaleBy(double inFactor)280 void scaleBy(double inFactor) {x *= inFactor; y *= inFactor;} 281 282 std::string getStringValue() const; 283 284 //! Concatenate with point \c inPoint, and return new point list. 285 PointList operator+(const Point &inPoint) const; 286 287 //! Concatenate with point list \c inList and return new point list. 288 PointList operator+(const PointList &inList) const; 289 290 double x; //!< Horizontal coordinate. 291 double y; //!< Vertical coordinate. 292 }; 293 294 /*!\brief List of points. 295 * \ingroup SVG 296 * 297 * This class is a standard vector of point (std::vector<Point>) with some 298 * utility functions and + and += operators to facilitate the concatenation 299 * of point lists. 300 */ 301 class PointList : public vector<Point> { 302 public: 303 //! Make an empty point list. PointList()304 PointList() {} 305 306 //! Make a point list out of a single point \c inPoint. PointList(const Point inPoint)307 PointList(const Point inPoint) : std::vector<Point>(1, inPoint) {} 308 309 //! Return the result of cancatenating this list with point list \c inList. operator +(const PointList & inList) const310 PointList operator+(const PointList &inList) const {return PointList(*this) += inList;} 311 312 //! Append point list \c inList to this list. operator +=(const PointList & inList)313 PointList &operator+=(const PointList &inList) { 314 for ( unsigned i = 0; i < inList.size(); i++ ) push_back(inList[i]); 315 return *this; 316 } 317 318 //! Return the result of cancatenating this list with single point \c inPoint. operator +(const Point & inPoint) const319 PointList operator+(const Point &inPoint) const {return PointList(*this) += inPoint;} 320 321 //! Append single point \c inPoint to this list. operator +=(const Point & inPoint)322 PointList &operator+=(const Point &inPoint) { 323 push_back(inPoint); 324 return *this; 325 } 326 327 //! Return a string representation of this list. 328 string getStringValue(void) const; 329 }; 330 331 //! \brief %Size of graphic component. 332 //! \ingroup SVG 333 class Size { 334 public: 335 //! Default constructor. Size()336 Size() : width(0), height(0) {} 337 338 //! Construct with width \c inWidth and height \c inHeight. Size(double inWidth,double inHeight)339 Size(double inWidth, double inHeight) : width(inWidth), height(inHeight) {} 340 341 //! Return length of diagonal. getDiagonal(void) const342 double getDiagonal(void) const {return sqrt(width*width + height*height);} 343 344 //! Scale by factor \c inFactor. scaleBy(float inFactor)345 void scaleBy(float inFactor) {width *= inFactor; height *= inFactor;} 346 347 string getStringValue(void) const; 348 349 double width; //!< Width of graphic component. 350 double height; //!< Height of graphic component. 351 }; 352 353 } // end of SVG namespace 354 355 } // end of PACC namespace 356 357 #endif //PACC_SVG_Types_hpp_ 358