COPASI API  4.16.103
CQFontRenderer.h
Go to the documentation of this file.
1 // Copyright (C) 2010 - 2015 by Pedro Mendes, Virginia Tech Intellectual
2 // Properties, Inc., University of Heidelberg, and The University
3 // of Manchester.
4 // All rights reserved.
5 
6 #ifndef CQFontRenderer_H__
7 #define CQFontRenderer_H__
8 
9 #include <QtGui/QFont>
10 #include <QtGui/QFontDatabase>
11 
12 #include <string>
13 #include <map>
14 #include <set>
15 #include <list>
16 #include <utility>
17 
18 #include "copasi/layout/CLText.h"
20 
21 struct CLTextTextureSpec;
22 
24 {
25 public:
27 
28  /**
29  * Destructor
30  */
31  virtual ~CQFontRenderer();
32 
33  /**
34  * Functor that returns a TextureSpec objct with a texture
35  * for the given font family, font size font weight, font style and text.
36  * The caller is responsible to free the memory of the TextureSpec object
37  * and of the pData in the TextureSpec.
38  */
39  virtual std::pair<CLTextTextureSpec*, GLubyte*> operator()(const std::string& family, double fontSize, const std::string& text, CLText::FONT_WEIGHT weight = CLText::WEIGHT_NORMAL, CLText::FONT_STYLE style = CLText::STYLE_NORMAL, double zoomFactor = 1.0);
40 
41  /**
42  * static method that creates a texture with a static FontRenderer
43  * object.
44  * This method can be used as a callback.
45  */
46  static std::pair<CLTextTextureSpec*, GLubyte*> createTexture(const std::string& family, double fontSize, const std::string& text, CLText::FONT_WEIGHT weight = CLText::WEIGHT_NORMAL, CLText::FONT_STYLE style = CLText::STYLE_NORMAL, double zoomFactor = 1.0);
47 
48  /**
49  * Returns the size for a font given a font, a text and a zoom factor.
50  */
51  virtual std::pair<double, double> getTextureSize(const CLFontSpec& spec, const std::string& text);
52 
53 protected:
54  /**
55  * Returns the size for a font given a font specification, a text and a zoom factor.
56  */
57  std::pair<double, double> getTextureSize(const QFont& font, const std::string& text);
58 
59  /**
60  * Returns the font that matches the given FontSpc.
61  */
62  QFont getFont(const CLFontSpec& spec);
63 
64  /**
65  * Creates a texture for the given text using the given font object.
66  * The caller has to free the memory for the TextureSpec object and the
67  * pData in the TextureSpec object.
68  */
69  std::pair<CLTextTextureSpec*, GLubyte*> getTexture(QFont& font, const std::string& text, double zoomFactor);
70 
71  /**
72  * Finds the font families that fit the given family name.
73  * A family fits if the name is exactly the same or if the name is
74  * contained in the family name.
75  * For generic names like sans, serif or monospaced the algorithm tries
76  * to find a suitable font family.
77  */
78  void findSimilarFamily(const std::string& name, std::set<std::string>& families) const;
79 
80  /**
81  * Given a certain name and a set of font family names, the algorithm
82  * tries to put them in an order from best match to worst match.
83  */
84  void orderFamilies(const std::string& name, const std::set<std::string>& familySet, std::list<std::string>& familyList) const;
85 
86  void getFamilyList(const std::string& family, std::list<std::string>& list) const;
87 
88 protected:
89  /**
90  * An instance of the font database.
91  * It has to be a pointer since there seems to be a problem under linux if an
92  * instance of QFontDatabase is created before some other things have been instanciated.
93  * At least the application crashed when I made this an object instead of a pointer.
94  */
95  QFontDatabase* mpFontDatabase;
96 
97  /**
98  * A map that stores the font that matches a given spec the best.
99  */
100  std::map<CLFontSpec, QFont> mFontMap;
101 
103 };
104 
105 #endif /* CQFontRenderer_H__ */
QFont getFont(const CLFontSpec &spec)
static std::pair< CLTextTextureSpec *, GLubyte * > createTexture(const std::string &family, double fontSize, const std::string &text, CLText::FONT_WEIGHT weight=CLText::WEIGHT_NORMAL, CLText::FONT_STYLE style=CLText::STYLE_NORMAL, double zoomFactor=1.0)
void findSimilarFamily(const std::string &name, std::set< std::string > &families) const
std::pair< CLTextTextureSpec *, GLubyte * > getTexture(QFont &font, const std::string &text, double zoomFactor)
FONT_STYLE
Definition: CLText.h:41
void getFamilyList(const std::string &family, std::list< std::string > &list) const
virtual std::pair< CLTextTextureSpec *, GLubyte * > operator()(const std::string &family, double fontSize, const std::string &text, CLText::FONT_WEIGHT weight=CLText::WEIGHT_NORMAL, CLText::FONT_STYLE style=CLText::STYLE_NORMAL, double zoomFactor=1.0)
virtual std::pair< double, double > getTextureSize(const CLFontSpec &spec, const std::string &text)
std::map< CLFontSpec, QFont > mFontMap
QFontDatabase * mpFontDatabase
FONT_WEIGHT
Definition: CLText.h:34
virtual ~CQFontRenderer()
static CQFontRenderer FONT_RENDERER
void orderFamilies(const std::string &name, const std::set< std::string > &familySet, std::list< std::string > &familyList) const