bpp-core3  3.0.0
XFigGraphicDevice.h
Go to the documentation of this file.
1 //
2 // File: XFigGraphicDevice.h
3 // Authors:
4 // Julien Dutheil
5 // Created: 2008-03-03 00:00:00
6 //
7 
8 /*
9  Copyright or © or Copr. Bio++ Development Team, (November 17, 2004)
10 
11  This software is a computer program whose purpose is to provide utilitary
12  classes. This file belongs to the Bio++ Project.
13 
14  This software is governed by the CeCILL license under French law and
15  abiding by the rules of distribution of free software. You can use,
16  modify and/ or redistribute the software under the terms of the CeCILL
17  license as circulated by CEA, CNRS and INRIA at the following URL
18  "http://www.cecill.info".
19 
20  As a counterpart to the access to the source code and rights to copy,
21  modify and redistribute granted by the license, users are provided only
22  with a limited warranty and the software's author, the holder of the
23  economic rights, and the successive licensors have only limited
24  liability.
25 
26  In this respect, the user's attention is drawn to the risks associated
27  with loading, using, modifying and/or developing or reproducing the
28  software by the user in light of its specific status of free software,
29  that may mean that it is complicated to manipulate, and that also
30  therefore means that it is reserved for developers and experienced
31  professionals having in-depth computer knowledge. Users are therefore
32  encouraged to load and test the software's suitability as regards their
33  requirements in conditions enabling the security of their systems and/or
34  data to be ensured and, more generally, to use and operate it in the
35  same conditions as regards security.
36 
37  The fact that you are presently reading this means that you have had
38  knowledge of the CeCILL license and that you accept its terms.
39 */
40 
41 #ifndef BPP_GRAPHICS_FIG_XFIGGRAPHICDEVICE_H
42 #define BPP_GRAPHICS_FIG_XFIGGRAPHICDEVICE_H
43 
44 
45 #include "../AbstractGraphicDevice.h"
46 #include "../ColorManager.h"
47 #include "XFigLaTeXFontManager.h"
49 
50 // From the STL:
51 #include <map>
52 #include <iostream>
53 
54 namespace bpp
55 {
61 {
62 private:
63  std::ostream& out_;
64  std::vector<std::string> content_;
68  unsigned int fgColorCode_;
69  unsigned int bgColorCode_;
70  int fontCode_;
71  unsigned int fontSize_;
72  unsigned int fontFlag_;
74 
75 public:
76  XFigGraphicDevice(std::ostream& out) :
77  out_(out),
78  content_(),
79  colorManager_(),
82  fgColorCode_(0),
83  bgColorCode_(0),
84  fontCode_(-1),
85  fontSize_(12),
88  {
89  setCurrentLayer(0);
90  }
91 
92  virtual ~XFigGraphicDevice() {}
93 
94 public:
95  void begin();
96  void end();
97 
98  void setCurrentForegroundColor(const RGBColor& color);
99  void setCurrentBackgroundColor(const RGBColor& color);
100  void setCurrentFont(const Font& font);
101  void setCurrentLineType(short type)
102  {
103  if (type == LINE_SOLID) lineTypeCode_ = 0;
104  else if (type == LINE_DASHED) lineTypeCode_ = 1;
105  else if (type == LINE_DOTTED) lineTypeCode_ = 2;
106  else throw Exception("XFigGraphicDevice::setCurrentLineType. Unknown line type: " + TextTools::toString(type));
108  }
109  void drawLine(double x1, double y1, double x2, double y2);
110  void drawRect(double x, double y, double width, double height, short fill = FILL_EMPTY);
111  void drawCircle(double x, double y, double radius, short fill = FILL_EMPTY);
112  void drawText(double x, double y, const std::string& text, short hpos = TEXT_HORIZONTAL_LEFT, short vpos = TEXT_VERTICAL_BOTTOM, double angle = 0);
113  void comment(const std::string& text)
114  {
115  content_.push_back("#" + text);
116  }
117 
118  // Specific:
119  void setFontFlag(unsigned int flag) { fontFlag_ = flag; }
120 
121 protected:
122  int getFillCode(short fill);
123 
124 public:
125  static const unsigned int FONTFLAG_LATEX;
126  static const unsigned int FONTFLAG_POSTSCRIPT;
127 };
128 } // end of namespace bpp;
129 #endif // BPP_GRAPHICS_FIG_XFIGGRAPHICDEVICE_H
Partial implementation of the GraphicDevice interface.
void setCurrentLayer(int layerIndex)
Exception base class. Overload exception constructor (to control the exceptions mechanism)....
Definition: Exceptions.h:59
Data structure for fonts.
Definition: Font.h:59
static short LINE_DOTTED
static short TEXT_HORIZONTAL_LEFT
static short LINE_DASHED
static short FILL_EMPTY
static short TEXT_VERTICAL_BOTTOM
static short LINE_SOLID
Describe a color according to its red, green and blue componants.
Definition: RgbColor.h:60
Color manager for the XFig format.
Definition: ColorManager.h:105
XFig plotting format.
void drawLine(double x1, double y1, double x2, double y2)
Draw a line between two points.
static const unsigned int FONTFLAG_POSTSCRIPT
std::vector< std::string > content_
void comment(const std::string &text)
Add a comment in the output.
void setCurrentLineType(short type)
XFigGraphicDevice(std::ostream &out)
XFigColorManager colorManager_
void setFontFlag(unsigned int flag)
void setCurrentFont(const Font &font)
XFigPostscriptFontManager postscriptFontManager_
void drawRect(double x, double y, double width, double height, short fill=FILL_EMPTY)
Draw a rectangle.
void setCurrentForegroundColor(const RGBColor &color)
static const unsigned int FONTFLAG_LATEX
void drawText(double x, double y, const std::string &text, short hpos=TEXT_HORIZONTAL_LEFT, short vpos=TEXT_VERTICAL_BOTTOM, double angle=0)
Draw some characters.
void setCurrentBackgroundColor(const RGBColor &color)
XFigLaTeXFontManager latexFontManager_
void begin()
Start the painting.
void drawCircle(double x, double y, double radius, short fill=FILL_EMPTY)
Draw a circle.
void end()
End the painting.
LaTeX font manager for the XFig format.
Postscript font manager for the XFig format.
std::string toString(T t)
General template method to convert to a string.
Definition: TextTools.h:153