ecfb4d4fa258ac16eba8c73f90784ba9e60a219d
[blender.git] / source / blender / freestyle / intern / stroke / TextStrokeRenderer.cpp
1 /*
2  * ***** BEGIN GPL LICENSE BLOCK *****
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software Foundation,
16  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  *
18  * ***** END GPL LICENSE BLOCK *****
19  */
20
21 # include "TextStrokeRenderer.h"
22 # include "Canvas.h"
23 # include "StrokeIterators.h"
24
25 namespace Freestyle {
26
27 TextStrokeRenderer::TextStrokeRenderer(const char *iFileName)
28 :StrokeRenderer()
29 {
30         if (!iFileName)
31                 iFileName = "freestyle.txt";
32         // open the stream:
33         _ofstream.open(iFileName, ios::out);
34         if (!_ofstream.is_open()) {
35                 cerr << "couldn't open the output file " << iFileName << endl;
36         }
37         _ofstream << "%!FREESTYLE" << endl;
38         _ofstream << "%Creator: Freestyle (http://artis.imag.fr/Software/Freestyle)" << endl;
39         // Bounding box
40         _ofstream << 0 << " "<< 0 << " " << Canvas::getInstance()->width() << " " << Canvas::getInstance()->height() <<
41                      endl;
42         _ofstream << "%u x y z tleft tright r g b ..." << endl;
43 }
44
45 TextStrokeRenderer::~TextStrokeRenderer()
46 {
47         Close();
48 }
49
50 void TextStrokeRenderer::RenderStrokeRep(StrokeRep *iStrokeRep) const
51 {
52         RenderStrokeRepBasic(iStrokeRep);
53 }
54
55 void TextStrokeRenderer::RenderStrokeRepBasic(StrokeRep *iStrokeRep) const
56 {
57         Stroke *stroke = iStrokeRep->getStroke();
58         if (!stroke) {
59                 cerr << "no stroke associated with Rep" << endl;
60                 return;
61         }
62
63         StrokeInternal::StrokeVertexIterator v = stroke->strokeVerticesBegin();
64         StrokeAttribute att;
65         while (!v.isEnd()) {
66                 att = v->attribute();
67                 _ofstream << v->u() << " " << v->getProjectedX() << " " << v->getProjectedY() << " " << v->getProjectedZ() <<
68                              " " << att.getThicknessL() << " " << att.getThicknessR() << " " <<
69                              att.getColorR() << " " << att.getColorG() << " " << att.getColorB() << " ";
70                 ++v;
71         }
72         _ofstream << endl;
73 }
74
75 void TextStrokeRenderer::Close()
76 {
77         if (_ofstream.is_open())
78                 _ofstream.close();
79 }
80
81 } /* namespace Freestyle */