~mc-return/nux/nux.merge-fix-deprecated-warnings

« back to all changes in this revision

Viewing changes to NuxGraphics/FreetypeFont.h

  • Committer: Neil Jagdish Patel
  • Date: 2010-09-01 21:15:42 UTC
  • Revision ID: neil.patel@canonical.com-20100901211542-cw2ce3ak28unouwb
Add NuxGraphics with licensing

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright 2010 Inalogic Inc.
 
3
 *
 
4
 * This program is free software: you can redistribute it and/or modify it 
 
5
 * under the terms of the GNU Lesser General Public License version 3, as
 
6
 * published by the  Free Software Foundation.
 
7
 *
 
8
 * This program is distributed in the hope that it will be useful, but 
 
9
 * WITHOUT ANY WARRANTY; without even the implied warranties of 
 
10
 * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR 
 
11
 * PURPOSE.  See the applicable version of the GNU Lesser General Public 
 
12
 * License for more details.
 
13
 * 
 
14
 * You should have received a copy of both the GNU Lesser General Public 
 
15
 * License version 3 along with this program.  If not, see 
 
16
 * <http://www.gnu.org/licenses/>
 
17
 *
 
18
 * Authored by: Jay Taoko <jay.taoko_AT_gmail_DOT_com>
 
19
 *
 
20
 */
 
21
 
 
22
 
 
23
#ifndef DBM_FONTMGR
 
24
#define DBM_FONTMGR
 
25
 
 
26
#if defined WIN32
 
27
        #include <windows.h>    // Header File For Windows
 
28
        #include <vector>
 
29
        #include <list>
 
30
        #include <algorithm>    
 
31
//      #include <gl\gl.h>      // Header File For The OpenGL32 Library
 
32
//      #include <gl\glu.h>     // Header File For The GLu32 Library
 
33
//      #include <gl\glaux.h>
 
34
        using namespace std; 
 
35
#else   
 
36
        #include <vector.h>
 
37
        #include <algo.h>
 
38
//      #include <GL/gl.h>      
 
39
//      #include <GL/glx.h>
 
40
//      #include <GL/glu.h>     
 
41
#endif
 
42
 
 
43
 
 
44
 
 
45
/*#include "fmt_image.h"
 
46
#include "fmt_tga.h"
 
47
#include "fmt_bmp.h"
 
48
#include "dbm_texturemgr.h"*/
 
49
 
 
50
#include <ft2build.h>
 
51
#include <freetype/fttypes.h>
 
52
#include <freetype/freetype.h>
 
53
#include <freetype/ftglyph.h>
 
54
#include FT_FREETYPE_H
 
55
 
 
56
 
 
57
typedef int FontID;
 
58
 
 
59
typedef enum _TextAlignment
 
60
{
 
61
    eAlignTextNone       = 0,
 
62
    eAlignTextLeft       = 1,
 
63
    eAlignTextRight      = 2,
 
64
    eAlignTextCenter     = 3,
 
65
 
 
66
} TextAlignment;
 
67
 
 
68
class StringBBox
 
69
{
 
70
public:
 
71
    StringBBox() {
 
72
        x = 0;
 
73
        y = 0;
 
74
        width = 0;
 
75
        height = 0;
 
76
        ybearing = 0;
 
77
        downline = 0;
 
78
    };
 
79
    ~StringBBox(){};
 
80
 
 
81
    int x;
 
82
    int y;
 
83
    int width;
 
84
    int height;
 
85
    int ybearing; // max ybearing of the string
 
86
    int downline; // max downline of the string (max space below the baseline)
 
87
};
 
88
 
 
89
class PageBBox 
 
90
{
 
91
public:
 
92
    PageBBox() {
 
93
        xmin = 0;
 
94
        ymin = 0;
 
95
        xmax = 0;
 
96
        ymax = 0;
 
97
        x_margin = 0;    
 
98
        y_margin = 0;    
 
99
    };
 
100
    ~PageBBox(){};
 
101
    int xmin;
 
102
    int ymin;
 
103
    int xmax;
 
104
    int ymax;
 
105
    int x_margin;
 
106
    int y_margin;
 
107
};
 
108
 
 
109
typedef struct _CharData
 
110
{
 
111
                int hbearingX;
 
112
                int hbearingY;
 
113
                int vbearingX;
 
114
                int vbearingY;
 
115
                int vadvance;
 
116
                int hadvance;
 
117
                int gwidth;
 
118
                int gheight;
 
119
                
 
120
                struct 
 
121
                {
 
122
                        int xmin, xmax, ymin, ymax;
 
123
                } bbox;
 
124
 
 
125
                int bitmap_left_bearing;
 
126
                int bitmap_top_bearing;
 
127
                int bitmap_width;
 
128
                int bitmap_height;
 
129
 
 
130
        int glyph_index;
 
131
                int gltexid;
 
132
        int glTexWidth;
 
133
        int glTexHeight;
 
134
 
 
135
} CharData;
 
136
 
 
137
typedef struct _FontStyle
 
138
{
 
139
        char *style_name;
 
140
        CharData *charmap;
 
141
        int num_glyph;
 
142
        int ascent;
 
143
        int descent;
 
144
        int texture_width;
 
145
        int texture_height;
 
146
        int line_spacing;
 
147
} FontStyle;
 
148
 
 
149
typedef struct _FontFamily
 
150
{
 
151
        char *font_name;
 
152
    FT_Face m_face;
 
153
        //int num_glyph;
 
154
        list <FontStyle*> *style_list;
 
155
} FontFamily;
 
156
 
 
157
class FontMgr
 
158
{
 
159
private:
 
160
        char *current_font;
 
161
        char *current_style;
 
162
 
 
163
        FontMgr();
 
164
        static FontMgr *pinstance;
 
165
public:
 
166
  list <FontFamily*> *m_font_list;
 
167
 
 
168
  static FontMgr* Instance();
 
169
 
 
170
  int nombre;
 
171
 
 
172
  ~FontMgr();
 
173
  
 
174
  bool load_font(const char* font_name);
 
175
  int get_character_texture_id(const char *font_name, int encoding, CharData *cd);
 
176
  int get_character_texture_id(int encoding, CharData *cd);
 
177
  void get_style_texture_size(const char *font_name, int *width, int *height);
 
178
  void get_style_texture_size(int *width, int *height);
 
179
  void get_style_line_spacing(const char *font_name, int *line_spacing);
 
180
  void get_style_line_spacing(int *line_spacing);
 
181
  unsigned int get_null_character_texture_id(const char *font_name);
 
182
  unsigned int get_null_character_texture_id();
 
183
  bool find_font(const char *font_name, const char *style_name);
 
184
  
 
185
  FontFamily* get_font_family(const char *font_name);
 
186
  FontStyle* get_font_style(char *font_name, char *style_name);
 
187
  
 
188
  void set_current_font(char *font_name, char *style_name);
 
189
  void draw_text(int rect_xmin, int rect_ymin, int rect_xmax, int rect_ymax, const char *text, const char *sh_name);
 
190
 
 
191
  void ComputeGlyphString(int x, int y, const char* text);
 
192
  //unsigned int GetStringWidth(const char* text);
 
193
  //unsigned int GetStringHeight(const char* text);
 
194
  unsigned int GetStringWidth(const std::string& text);
 
195
  unsigned int GetStringHeight(const std::string& text);
 
196
  void ComputeStringBBox(StringBBox &stringBBox, const char* text);
 
197
  void PositionString(const PageBBox&, StringBBox&, TextAlignment align = eAlignTextCenter);
 
198
 
 
199
  //void RenderGlyph(int targer_width, int target_height);
 
200
  void RenderGlyph(const PageBBox& pageSize, const char* text, TextAlignment align = eAlignTextCenter);
 
201
  void RenderString(const PageBBox& pageSize, const std::string& Str, TextAlignment alignment,  unsigned int CursorPosition, int offset = 0);
 
202
  void RenderTextLineEdit(const PageBBox& pageSize, const std::string& Str, unsigned int CursorPosition, int offset = 0);
 
203
  void RenderTextLineStatic(const PageBBox& pageSize, const std::string& Str, TextAlignment alignment, char trailingchar = 0);
 
204
 
 
205
};
 
206
 
 
207
 
 
208
#endif