1 // renderimpl.h 2 // this file is part of Context Free 3 // --------------------- 4 // Copyright (C) 2006-2008 Mark Lentczner - markl@glyphic.com 5 // Copyright (C) 2006-2013 John Horigan - john@glyphic.com 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 9 // as published by the Free Software Foundation; either version 2 10 // of the License, or (at your option) any later version. 11 // 12 // This program is distributed in the hope that it will be useful, 13 // but 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, write to the Free Software 19 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 20 // 21 // John Horigan can be contacted at john@glyphic.com or at 22 // John Horigan, 1209 Villa St., Mountain View, CA 94041-1123, USA 23 // 24 // Mark Lentczner can be contacted at markl@glyphic.com or at 25 // Mark Lentczner, 1209 Villa St., Mountain View, CA 94041-1123, USA 26 // 27 // 28 29 30 #ifndef INCLUDE_RENDERIMPL_H 31 #define INCLUDE_RENDERIMPL_H 32 33 #ifdef _WIN32 34 #pragma warning( disable : 4786 ) 35 #endif 36 37 #include <deque> 38 #include <set> 39 #include <array> 40 #include <type_traits> 41 42 #include "agg2/agg_trans_affine.h" 43 #include "agg_trans_affine_time.h" 44 #include "bounds.h" 45 #include "rendererAST.h" 46 #include "cfdgimpl.h" 47 #include "shape.h" 48 #include "tempfile.h" 49 #include "shape.h" 50 #include "CmdInfo.h" 51 #include "pathIterator.h" 52 #include "chunk_vector.h" 53 54 class ShapeOp; 55 namespace AST { 56 class ASTbodyContainer; 57 class ASTrule; 58 class ASTpathCommand; 59 class ASTcompiledPath; 60 } 61 62 class RendererImpl final : public RendererAST { 63 public: 64 RendererImpl(const cfdg_ptr& cfdg, 65 int width, int height, double minSize, 66 int variation, double border); 67 ~RendererImpl(); 68 69 void setMaxShapes(int n) final; 70 void resetBounds() final; 71 void resetSize(int x, int y) final; 72 void initBounds(); 73 74 double run(Canvas* canvas, bool partialDraw) final; 75 void draw(Canvas* canvas) final; 76 void animate(Canvas* canvas, int frames, int frame, bool zoom) final; 77 void processPathCommand(const Shape& s, const AST::CommandInfo* attr) final; 78 void processShape(Shape& s) final; 79 void processPrimShape(Shape& s, const AST::ASTrule* attr = nullptr) final; 80 void processSubpath(const Shape& s, bool tr, int) final; 81 82 private: 83 void outputPrep(Canvas*); 84 void rescaleOutput(int& curr_width, int& curr_height, bool final); 85 void forEachShape(bool final, ShapeFunction op); 86 void processPrimShapeSiblings(Shape&& s, const AST::ASTrule* attr); 87 void drawShape(const FinishedShape& s); 88 89 void output(bool final); outputPartial()90 void outputPartial() { output(false); } outputFinal()91 void outputFinal() { output(true); } 92 void outputStats(); 93 94 friend class OutputDraw; 95 friend class OutputMerge; 96 friend class OutputBounds; 97 98 bool isDone(); 99 void fileIfNecessary(); 100 void moveFinishedToFile(); 101 void moveUnfinishedToTwoFiles(); 102 void getUnfinishedFromFile(); system()103 AbstractSystem* system() { return m_cfdg->system(); } 104 void fixupHeap(); 105 106 void init(); 107 void cleanup(); 108 109 private: 110 cfdgi_ptr m_cfdg; 111 Canvas* m_canvas; 112 pathIterator m_pathIter; 113 114 bool mColorConflict; 115 116 int m_maxShapes; 117 bool m_tiled; 118 bool m_sized; 119 bool m_timed; 120 CFDG::frieze_t m_frieze; 121 double m_frieze_size; 122 bool m_drawingMode; 123 bool mFinal; 124 125 using FinishedContainer = chunk_vector<FinishedShape, 10>; 126 FinishedContainer mFinishedShapes; 127 using UnfinishedContainer = chunk_vector<Shape, 10>; 128 UnfinishedContainer mUnfinishedShapes; 129 130 std::deque<TempFile> m_finishedFiles; 131 std::deque<TempFile> m_unfinishedFiles; 132 int mFinishedFileCount; 133 int mUnfinishedFileCount; 134 135 int mVariation; 136 double m_border; 137 138 double mScaleArea; 139 double mScale; 140 double mFixedBorderX; 141 double mFixedBorderY; 142 double mShapeBorder; 143 double mTotalArea; 144 145 double mCurrentArea; 146 Bounds mPathBounds; 147 148 double m_currScale; 149 double m_currArea; 150 double m_minArea; 151 double m_minSize; 152 Bounds mBounds; 153 agg::trans_affine_time mTimeBounds; 154 agg::trans_affine_time mFrameTimeBounds; 155 agg::trans_affine m_currTrans; 156 unsigned int m_outputSoFar; 157 158 std::vector<agg::trans_affine> mSymmetryOps; 159 160 AbstractSystem::Stats m_stats; 161 int m_unfinishedInFilesCount; 162 163 primShape::primShapes_t shapeCopies; 164 std::array<AST::CommandInfo, primShape::numTypes> shapeMap; 165 166 static unsigned int MoveFinishedAt; // when this many, move to file 167 static unsigned int MoveUnfinishedAt; // when this many, move to files 168 static unsigned int MaxMergeFiles; // maximum number of files to merge at once 169 170 protected: 171 void colorConflict(const yy::location& w) final; 172 }; 173 174 175 #endif // INCLUDE_RENDERIMPL_H 176