1 /************************************************************************* 2 ** ShadingPatch.h ** 3 ** ** 4 ** This file is part of dvisvgm -- the DVI to SVG converter ** 5 ** Copyright (C) 2005-2015 Martin Gieseking <martin.gieseking@uos.de> ** 6 ** ** 7 ** This program is free software; you can redistribute it and/or ** 8 ** modify it under the terms of the GNU General Public License as ** 9 ** published by the Free Software Foundation; either version 3 of ** 10 ** the License, or (at your option) any later version. ** 11 ** ** 12 ** This program is distributed in the hope that it will be useful, but ** 13 ** WITHOUT ANY WARRANTY; without even the implied warranty of ** 14 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** 15 ** GNU General Public License for more details. ** 16 ** ** 17 ** You should have received a copy of the GNU General Public License ** 18 ** along with this program; if not, see <http://www.gnu.org/licenses/>. ** 19 *************************************************************************/ 20 21 #ifndef DVISVGM_SHADINGPATCH_H 22 #define DVISVGM_SHADINGPATCH_H 23 24 #include "Color.h" 25 #include "GraphicPath.h" 26 #include "MessageException.h" 27 28 29 class ShadingPatch 30 { 31 public: 32 struct Callback { ~CallbackCallback33 virtual ~Callback () {} 34 virtual void patchSegment (GraphicPath<double> &path, const Color &color) =0; 35 }; 36 37 typedef std::vector<DPair> PointVec; 38 typedef std::vector<Color> ColorVec; 39 40 public: ShadingPatch(Color::ColorSpace colorSpace)41 ShadingPatch (Color::ColorSpace colorSpace) : _colorspace(colorSpace) {} ~ShadingPatch()42 virtual ~ShadingPatch () {} 43 virtual int psShadingType () const =0; 44 virtual void approximate (int gridsize, bool overlap, double delta, Callback &callback) const =0; 45 virtual void getBBox (BoundingBox &bbox) const =0; 46 virtual void getBoundaryPath (GraphicPath<double> &path) const =0; 47 virtual void setPoints (const PointVec &points, int edgeflag, ShadingPatch *patch) =0; 48 virtual void setColors (const ColorVec &colors, int edgeflag, ShadingPatch *patch) =0; 49 virtual int numPoints (int edgeflag) const =0; 50 virtual int numColors (int edgeflag) const =0; 51 virtual Color averageColor() const =0; colorSpace()52 Color::ColorSpace colorSpace () const {return _colorspace;} 53 static ShadingPatch* create (int psShadingType, Color::ColorSpace cspace); 54 55 protected: 56 typedef void (Color::*ColorGetter)(std::valarray<double> &va) const; 57 typedef void (Color::*ColorSetter)(const std::valarray<double> &va); 58 void colorQueryFuncs (ColorGetter &getter, ColorSetter &setter) const; 59 60 private: 61 Color::ColorSpace _colorspace; ///< color space used to compute the shading values 62 }; 63 64 65 struct ShadingException : public MessageException 66 { ShadingExceptionShadingException67 ShadingException (const std::string &msg) : MessageException(msg) {} 68 }; 69 70 #endif 71 72