VTK-m  2.0
BitmapFont.h
Go to the documentation of this file.
1 //============================================================================
2 // Copyright (c) Kitware, Inc.
3 // All rights reserved.
4 // See LICENSE.txt for details.
5 //
6 // This software is distributed WITHOUT ANY WARRANTY; without even
7 // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
8 // PURPOSE. See the above copyright notice for more information.
9 //============================================================================
10 #ifndef vtk_m_BitmapFont_h
11 #define vtk_m_BitmapFont_h
12 
13 #include <vtkm/rendering/vtkm_rendering_export.h>
14 
15 #include <vtkm/Types.h>
16 
17 #include <string>
18 #include <vector>
19 
20 namespace vtkm
21 {
22 namespace rendering
23 {
24 
25 class VTKM_RENDERING_EXPORT BitmapFont
26 {
27 public:
28  struct Character
29  {
30  std::string id;
31  char c;
32  int offx, offy;
33  int x, y, w, h;
34  int adv;
35  int kern[256];
36  Character() { ResetKerning(); }
37  Character(const std::string& id_,
38  char c_,
39  int offx_,
40  int offy_,
41  int x_,
42  int y_,
43  int w_,
44  int h_,
45  int adv_)
46  : id(id_)
47  , c(c_)
48  , offx(offx_)
49  , offy(offy_)
50  , x(x_)
51  , y(y_)
52  , w(w_)
53  , h(h_)
54  , adv(adv_)
55  {
56  ResetKerning();
57  }
58  Character(const std::string& id_, const int metrics[])
59  : id(id_)
60  , c((char)metrics[0])
61  , offx(metrics[1])
62  , offy(metrics[2])
63  , x(metrics[3])
64  , y(metrics[4])
65  , w(metrics[5])
66  , h(metrics[6])
67  , adv(metrics[7])
68  {
69  ResetKerning();
70  }
71  void ResetKerning()
72  {
73  for (int i = 0; i < 256; i++)
74  {
75  kern[i] = 0;
76  }
77  }
78  };
79 
80  std::string Name;
81  std::string ImageFile;
82  int Height;
83  int Ascender;
84  int Descender;
85  int ImgW, ImgH;
86  int PadL, PadR, PadT, PadB;
87  int ShortMap[256];
88  std::vector<Character> Chars;
89 
90  std::vector<unsigned char> RawImageFileData;
91 
92 public:
93  BitmapFont();
94 
95  const Character& GetChar(char c) const;
96 
97  VTKM_CONT
98  const std::vector<unsigned char>& GetRawImageData() const { return this->RawImageFileData; }
99 
100  vtkm::Float32 GetTextWidth(const std::string& text) const;
101 
102  void GetCharPolygon(char character,
103  vtkm::Float32& x,
104  vtkm::Float32& y,
105  vtkm::Float32& vl,
106  vtkm::Float32& vr,
107  vtkm::Float32& vt,
108  vtkm::Float32& vb,
109  vtkm::Float32& tl,
110  vtkm::Float32& tr,
111  vtkm::Float32& tt,
112  vtkm::Float32& tb,
113  char nextchar = 0) const;
114 };
115 }
116 } //namespace vtkm::rendering
117 
118 #endif
vtkm::rendering::BitmapFont::Character::Character
Character(const std::string &id_, const int metrics[])
Definition: BitmapFont.h:58
vtkm
Groups connected points that have the same field value.
Definition: Atomic.h:19
vtkm::rendering::BitmapFont
Definition: BitmapFont.h:25
Types.h
vtkm::rendering::BitmapFont::Chars
std::vector< Character > Chars
Definition: BitmapFont.h:88
vtkm::rendering::BitmapFont::Descender
int Descender
Definition: BitmapFont.h:84
vtkm::rendering::BitmapFont::Character::Character
Character()
Definition: BitmapFont.h:36
vtkm::rendering::BitmapFont::Character::adv
int adv
Definition: BitmapFont.h:34
vtkm::rendering::BitmapFont::Character::c
char c
Definition: BitmapFont.h:31
vtkm::rendering::BitmapFont::GetRawImageData
const VTKM_CONT std::vector< unsigned char > & GetRawImageData() const
Definition: BitmapFont.h:98
vtkm::rendering::BitmapFont::Character::Character
Character(const std::string &id_, char c_, int offx_, int offy_, int x_, int y_, int w_, int h_, int adv_)
Definition: BitmapFont.h:37
vtkm::rendering::BitmapFont::Character::ResetKerning
void ResetKerning()
Definition: BitmapFont.h:71
vtkm::rendering::BitmapFont::ImgW
int ImgW
Definition: BitmapFont.h:85
vtkm::rendering::BitmapFont::Height
int Height
Definition: BitmapFont.h:82
vtkm::rendering::BitmapFont::Name
std::string Name
Definition: BitmapFont.h:80
vtkm::rendering::BitmapFont::RawImageFileData
std::vector< unsigned char > RawImageFileData
Definition: BitmapFont.h:90
VTKM_CONT
#define VTKM_CONT
Definition: ExportMacros.h:57
vtkm::rendering::BitmapFont::Character::id
std::string id
Definition: BitmapFont.h:30
vtkm::rendering::BitmapFont::Character
Definition: BitmapFont.h:28
vtkm::Float32
float Float32
Definition: Types.h:154
vtkm::rendering::BitmapFont::Ascender
int Ascender
Definition: BitmapFont.h:83
vtkm::rendering::BitmapFont::Character::offy
int offy
Definition: BitmapFont.h:32
vtkm::rendering::BitmapFont::Character::y
int y
Definition: BitmapFont.h:33
vtkm::rendering::BitmapFont::PadT
int PadT
Definition: BitmapFont.h:86
vtkm::rendering::BitmapFont::ImageFile
std::string ImageFile
Definition: BitmapFont.h:81