MeVisLab Toolbox Reference
View2DFont.h
Go to the documentation of this file.
1 /*************************************************************************************
2 **
3 ** Copyright 2007, MeVis Medical Solutions AG
4 **
5 ** The user may use this file in accordance with the license agreement provided with
6 ** the Software or, alternatively, in accordance with the terms contained in a
7 ** written agreement between the user and MeVis Medical Solutions AG.
8 **
9 ** For further information use the contact form at https://www.mevislab.de/contact
10 **
11 **************************************************************************************/
12 
13 
15 
16 #pragma once
17 
18 #include "SoView2DSystem.h"
19 
23 
30 {
31 public:
33  virtual ~View2DFont();
34 
36  enum AlignXMode { ALIGN_LEFT, ALIGN_RIGHT, ALIGN_CENTER };
37 
40  virtual bool init(const char* fontname = nullptr) = 0;
41 
43  virtual int getFontHeight(float fontSize) const = 0;
44 
46  virtual int getFontAscender(float fontSize) const = 0;
47 
49  virtual int getFontDescender(float fontSize) const = 0;
50 
52  virtual int getStringWidth(float fontSize, const char* string, int len = -1) const = 0;
53 
59  virtual void drawString(float dx, float dy, float fontSize, const float* color, const char* string, int length,
60  bool shadow = true, const float* shadowColor = nullptr, bool flipped = false) = 0;
61 
63  void drawStringFlipped(float dx, float dy, float fontSize, const float* color, const char* string, int length,
64  bool shadow = true, const float* shadowColor = nullptr)
65  {
66  drawString(dx, dy, fontSize, color, string, length, shadow, shadowColor, true);
67  }
68 
70  virtual void getTextSize(float fontSize, const char* text, int& width, int& height, float lineSpacing = 0.0f) const;
71 
75  virtual void drawText(float dx, float dy, float fontSize, const float* color, const char* text, AlignXMode mode,
76  bool shadow = true, float lineSpacing = 0.0f, const float* shadowColor = nullptr);
77 
78 
81 
86  static View2DFont* createFont(const char* fontname = nullptr);
87 
88 private:
90  static View2DFont* _globalFont;
91 };
#define SOVIEW2D_API
File to resolve system dependencies in View2D library.
Abstract GL font drawing using FTGL.
Definition: View2DFont.h:30
virtual ~View2DFont()
static View2DFont * createFont(const char *fontname=nullptr)
create a new font object with the given font name (/see init).
virtual int getFontDescender(float fontSize) const =0
get descender of font
virtual void getTextSize(float fontSize, const char *text, int &width, int &height, float lineSpacing=0.0f) const
returns size of the box spanned by text box
virtual int getFontAscender(float fontSize) const =0
get ascender of font
static View2DFont * globalFont()
get the global font used for annotations etc. (only call this within a valid GL context!...
virtual void drawText(float dx, float dy, float fontSize, const float *color, const char *text, AlignXMode mode, bool shadow=true, float lineSpacing=0.0f, const float *shadowColor=nullptr)
draws a multi-line text, lines are separated by , the drawing starts in the top-left corner.
virtual bool init(const char *fontname=nullptr)=0
init with given font (either just a font name without .ttf or an absolute path) requires a valid GL c...
virtual int getFontHeight(float fontSize) const =0
get height of font (ascender + descender)
void drawStringFlipped(float dx, float dy, float fontSize, const float *color, const char *string, int length, bool shadow=true, const float *shadowColor=nullptr)
as above for drawing a string up-side down where you don't need to specify all parameters
Definition: View2DFont.h:63
virtual int getStringWidth(float fontSize, const char *string, int len=-1) const =0
get width of simple string
AlignXMode
align mode of multi-line text
Definition: View2DFont.h:36
virtual void drawString(float dx, float dy, float fontSize, const float *color, const char *string, int length, bool shadow=true, const float *shadowColor=nullptr, bool flipped=false)=0
draws a simple string with no linefeeds, the drawing starts in the top-left corner color needs to poi...