Starshatter_Open
Open source Starshatter engine
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Font.h
Go to the documentation of this file.
1 /* Project nGenEx
2  Destroyer Studios LLC
3  Copyright © 1997-2004. All Rights Reserved.
4 
5  SUBSYSTEM: nGenEx.lib
6  FILE: Font.h
7  AUTHOR: John DiCamillo
8 
9 
10  OVERVIEW
11  ========
12  Font Resource class
13 */
14 
15 #ifndef Font_h
16 #define Font_h
17 
18 #include "Types.h"
19 #include "Bitmap.h"
20 #include "Color.h"
21 #include "Geometry.h"
22 
23 // +--------------------------------------------------------------------+
24 
25 struct Poly;
26 struct Material;
27 struct VertexSet;
28 class Video;
29 
30 // +--------------------------------------------------------------------+
31 
32 struct FontChar
33 {
34  short offset;
35  short width;
36 };
37 
38 // +--------------------------------------------------------------------+
39 
40 class Font
41 {
42 public:
43  static const char* TYPENAME() { return "Font"; }
44 
45  enum FLAGS { FONT_FIXED_PITCH = 1,
48  };
49 
50  enum CHARS { PIPE_NBSP = 16,
51  PIPE_VERT = 17,
52  PIPE_LT = 18,
53  PIPE_TEE = 19,
54  PIPE_UL = 20,
55  PIPE_LL = 21,
56  PIPE_HORZ = 22,
57  PIPE_PLUS = 23,
58  PIPE_MINUS = 24,
59  ARROW_UP = 25,
60  ARROW_DOWN = 26,
61  ARROW_LEFT = 27,
63  };
64 
65  // default constructor:
66  Font();
67  Font(const char* name);
68  ~Font();
69 
70  bool Load(const char* name);
71 
72  int CharWidth(char c) const;
73  int SpaceWidth() const;
74  int KernWidth(char left, char right) const;
75  int StringWidth(const char* str, int len=0) const;
76 
77  void DrawText(const char* txt, int count, Rect& txt_rect, DWORD flags, Bitmap* tgt_bitmap=0);
78  int DrawString( const char* txt, int len, int x1, int y1, const Rect& clip, Bitmap* tgt_bitmap=0);
79 
80  int Height() const { return height; }
81  int Baseline() const { return baseline; }
82  WORD GetFlags() const { return flags; }
83  void SetFlags(WORD s) { flags = s; }
84  Color GetColor() const { return color; }
85  void SetColor(const Color& c) { color = c; }
86  double GetExpansion() const { return expansion; }
87  void SetExpansion(double e) { expansion = (float) e; }
88  double GetAlpha() const { return alpha; }
89  void SetAlpha(double a) { alpha = (float) a; }
90  int GetBlend() const { return blend; }
91  void SetBlend(int b) { blend = b; }
92 
93  void SetKern(char left, char right, int k=0);
94 
95  int GetCaretIndex() const { return caret_index; }
96  void SetCaretIndex(int n) { caret_index = n; }
97 
98 private:
99  void AutoKern();
100  void FindEdges(BYTE c, double* l, double* r);
101  int CalcWidth(BYTE c) const;
102  int GlyphOffset(BYTE c) const;
103  int GlyphLocationX(BYTE c) const;
104  int GlyphLocationY(BYTE c) const;
105 
106  void DrawTextSingle(const char* txt, int count, const Rect& txt_rect, Rect& clip_rect, DWORD flags);
107  void DrawTextWrap(const char* txt, int count, const Rect& txt_rect, Rect& clip_rect, DWORD flags);
108  void DrawTextMulti(const char* txt, int count, const Rect& txt_rect, Rect& clip_rect, DWORD flags);
109 
110  void LoadDef(char* defname, char* imgname);
111 
112  char name[64];
113  WORD flags;
114  BYTE height;
115  BYTE baseline;
116  BYTE interspace;
117  BYTE spacewidth;
118  float expansion;
119  float alpha;
120  int blend;
121  int scale;
122 
123  int caret_index;
124  int caret_x;
125  int caret_y;
126 
127  int imagewidth;
128  BYTE* image;
129  Bitmap bitmap;
130  Bitmap* tgt_bitmap;
131  Material* material;
132  VertexSet* vset;
133  Poly* polys;
134  int npolys;
135 
136  FontChar glyph[256];
137  Color color;
138 
139  char kern[256][256];
140 };
141 
142 #endif Font_h
143