bpp-core3  3.0.0
XFigGraphicDevice.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: The Bio++ Development Group
2 //
3 // SPDX-License-Identifier: CECILL-2.1
4 
5 #ifndef BPP_GRAPHICS_FIG_XFIGGRAPHICDEVICE_H
6 #define BPP_GRAPHICS_FIG_XFIGGRAPHICDEVICE_H
7 
8 
9 #include "../AbstractGraphicDevice.h"
10 #include "../ColorManager.h"
11 #include "XFigLaTeXFontManager.h"
13 
14 // From the STL:
15 #include <map>
16 #include <iostream>
17 
18 namespace bpp
19 {
25 {
26 private:
27  std::ostream& out_;
28  std::vector<std::string> content_;
32  unsigned int fgColorCode_;
33  unsigned int bgColorCode_;
34  int fontCode_;
35  unsigned int fontSize_;
36  unsigned int fontFlag_;
38 
39 public:
40  XFigGraphicDevice(std::ostream& out) :
41  out_(out),
42  content_(),
43  colorManager_(),
44  latexFontManager_(),
45  postscriptFontManager_(),
46  fgColorCode_(0),
47  bgColorCode_(0),
48  fontCode_(-1),
49  fontSize_(12),
50  fontFlag_(FONTFLAG_POSTSCRIPT),
51  lineTypeCode_(LINE_SOLID)
52  {
53  setCurrentLayer(0);
54  }
55 
56  virtual ~XFigGraphicDevice() {}
57 
58 public:
59  void begin();
60  void end();
61 
62  void setCurrentForegroundColor(const RGBColor& color);
63  void setCurrentBackgroundColor(const RGBColor& color);
64  void setCurrentFont(const Font& font);
65  void setCurrentLineType(short type)
66  {
67  if (type == LINE_SOLID) lineTypeCode_ = 0;
68  else if (type == LINE_DASHED) lineTypeCode_ = 1;
69  else if (type == LINE_DOTTED) lineTypeCode_ = 2;
70  else throw Exception("XFigGraphicDevice::setCurrentLineType. Unknown line type: " + TextTools::toString(type));
72  }
73  void drawLine(double x1, double y1, double x2, double y2);
74  void drawRect(double x, double y, double width, double height, short fill = FILL_EMPTY);
75  void drawCircle(double x, double y, double radius, short fill = FILL_EMPTY);
76  void drawText(double x, double y, const std::string& text, short hpos = TEXT_HORIZONTAL_LEFT, short vpos = TEXT_VERTICAL_BOTTOM, double angle = 0);
77  void comment(const std::string& text)
78  {
79  content_.push_back("#" + text);
80  }
81 
82  // Specific:
83  void setFontFlag(unsigned int flag) { fontFlag_ = flag; }
84 
85 protected:
86  int getFillCode(short fill);
87 
88 public:
89  static const unsigned int FONTFLAG_LATEX;
90  static const unsigned int FONTFLAG_POSTSCRIPT;
91 };
92 } // end of namespace bpp;
93 #endif // BPP_GRAPHICS_FIG_XFIGGRAPHICDEVICE_H
void end()
End the painting.
void comment(const std::string &text)
Add a comment in the output.
void setCurrentLineType(short type)
Data structure for fonts.
Definition: Font.h:21
void setCurrentBackgroundColor(const RGBColor &color)
static short LINE_SOLID
Describe a color according to its red, green and blue componants.
Definition: RgbColor.h:21
static short LINE_DOTTED
static const unsigned int FONTFLAG_LATEX
void drawCircle(double x, double y, double radius, short fill=FILL_EMPTY)
Draw a circle.
static const unsigned int FONTFLAG_POSTSCRIPT
LaTeX font manager for the XFig format.
static short LINE_DASHED
Color manager for the XFig format.
Definition: ColorManager.h:67
XFigGraphicDevice(std::ostream &out)
void drawLine(double x1, double y1, double x2, double y2)
Draw a line between two points.
void setCurrentForegroundColor(const RGBColor &color)
Partial implementation of the GraphicDevice interface.
void setFontFlag(unsigned int flag)
void setCurrentFont(const Font &font)
static short FILL_EMPTY
void begin()
Start the painting.
void setCurrentLayer(int layerIndex)
Postscript font manager for the XFig format.
Exception base class. Overload exception constructor (to control the exceptions mechanism). Destructor is already virtual (from std::exception)
Definition: Exceptions.h:20
XFigLaTeXFontManager latexFontManager_
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.
static short TEXT_VERTICAL_BOTTOM
XFigColorManager colorManager_
XFigPostscriptFontManager postscriptFontManager_
std::string toString(T t)
General template method to convert to a string.
Definition: TextTools.h:115
std::vector< std::string > content_
void drawRect(double x, double y, double width, double height, short fill=FILL_EMPTY)
Draw a rectangle.
XFig plotting format.
static short TEXT_HORIZONTAL_LEFT