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