rag
graphic 2d engine
BMPFont.h
1 #ifndef _TEXT_LINE_H_
2 #define _TEXT_LINE_H_
3 
4 #include <string>
5 #include <map>
6 #include <vector>
7 #include <glm/glm.hpp>
8 #include <rag/Image.h>
9 #include "ITextFont.h"
10 
11 typedef unsigned int u32;
12 typedef signed int s32;
13 typedef unsigned short u16;
14 typedef signed short s16;
15 typedef unsigned char u8;
16 typedef signed char s8;
17 
18 namespace rag
19 {
21 
25  class BMPFont: public ITextFont
26  {
27  public:
28 
34  BMPFont(const std::string& path, const std::string& name);
35  virtual ~BMPFont();
36 
37 
38 
39  virtual int getWidth(const std::string& text);
40  virtual void print(const std::string& text, const glm::mat4& matrix);
41 
42  private:
43 
44  struct Glyph
45  {
46  u32 id;
47  u16 x, y;
48  u16 width, height;
49  s16 xoffset, yoffset;
50  u16 xadvance;
51  u8 page;
52  u8 chnl;
53  };
54 
55  class FontBinDescriptorReader
56  {
57 
58  public:
59 
63  std::map<int, Glyph*> read(std::string fontDescriptorFile, int* outHeight, std::string& outTexturePath);
64 
65  private:
66 
67  std::map<int, Glyph*> mGlyphs;
68 
69  };
70 
71  void printGlyph(Glyph* glyph);
72 
74  int* decodeText(const char* text, int* size);
75 
77  int decodeUTF8(const char *encodedBuffer, unsigned int *outLength);
78 
80  int getDecodedStringWidth(int* decodedString, int size);
81 
82  std::map<int, Glyph*> mGlyphs;
83 
84  int mHeight;
85  int mDecodedText[1024];
86 
87  Image* image;
88 
89  };
90 
91 }
92 
93 #endif
Definition: Bitmap.h:8
virtual int getWidth(const std::string &text)
Returns the width of a text.
Definition: BMPFont.cpp:246
Interface for text fonts.
Definition: ITextFont.h:10
Font system based on bitmap fonts.
Definition: BMPFont.h:25
BMPFont(const std::string &path, const std::string &name)
Definition: BMPFont.cpp:99
virtual void print(const std::string &text, const glm::mat4 &matrix)
Renders text. Asumes ortho projection 1:1.
Definition: BMPFont.cpp:199
Image object.
Definition: Image.h:19