-
Notifications
You must be signed in to change notification settings - Fork 0
/
ttf_font.h
executable file
·169 lines (141 loc) · 3.74 KB
/
ttf_font.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
#ifndef __TTF_FONT_H__
#define __TTF_FONT_H__
#include "codec.h"
#include "ft2build.h"
#include FT_FREETYPE_H
#include FT_OUTLINE_H
#include FT_SYNTHESIS_H
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
//#include <iconv.h>
#include <map>
#include "hulib.h"
#include "transcoding.h"
using namespace std;
#define FONT_NORMAL 0
#define FONT_ITALIC 1
#define FONT_BOLD 2
typedef unsigned short U16;
class text;
class FontDev: public Mutex
{ //FontDev字体绘制器 ,阻塞绘制元素,同BLT功能一般
public:
FontDev():face(NULL),ft_Lib(NULL)
{
}
~FontDev()
{
if (face != NULL)
FT_Done_Face(face);
if (ft_Lib != NULL)
FT_Done_FreeType(ft_Lib);
}
int TTF_Init(const char * path, unsigned char bitmap)
{
FT_UInt glyph_index;
int i;
ft_error = FT_Init_FreeType(&ft_Lib);
if (ft_error)
{
log_e("Error at init ft_Lib!\n");
FT_Done_FreeType(ft_Lib);
return -1;
}
ft_error = FT_New_Face(ft_Lib, path, 0, &face);
if (ft_error)
{
log_e("New face error!\n");
FT_Done_FreeType(ft_Lib);
return -1;
}
TTF_bitmap_type = bitmap;
matrix.xx = 1 << 16;
matrix.xy = 0x5800;
matrix.yx = 0;
matrix.yy = 1 << 16;
log_i("TTF_Init succssed!!!!!!!!!!!!!!!!!\n");
// logMsg("init ok.\n");
return 0;
}
int setPixelSize(int fontWidth, int fontHeight)
{
ft_error = FT_Set_Pixel_Sizes(face, fontWidth, fontHeight);
if (ft_error)
{
errexitf("Error at set fontSize %dx%d \n", fontWidth, fontHeight);
}
}
int setStyle(unsigned char bitmap)
{
TTF_bitmap_type = bitmap;
return 0;
}
// ssize_t convert(const char *tocode, const char *fromcode, char *inbufp, size_t inbytesleft, char *outbufp,
// size_t outbytesleft);
unsigned int drawText(text * ptext, char * showtxt,unsigned int txt_len);
unsigned int drawText(text * ptext, char * showtxt,unsigned int txt_len,int padding_left,int padding_top);
unsigned int displayUTF8(text * ptext, const char *text, int num,unsigned int color, unsigned char style);
unsigned int displayUTF8(text * ptext, const char *text, int num, unsigned int color, unsigned char style,
int padding_left,int padding_top);
FT_Library ft_Lib;
FT_Face face;
FT_UInt glyph_index;
FT_Vector pen;
FT_Matrix matrix;
FT_Error ft_error;
unsigned char TTF_bitmap_type;
};
class text: public image
{
private:
//void LCD_PutPixel(unsigned int x, unsigned int y, unsigned int color, unsigned char gray);
//void ft_draw_bitmap(FT_Bitmap *bitmap, int x, int y, unsigned int color);
public:
//以下几个变量需要外部赋值
FontDev * m_font;
unsigned int fontWidth;
unsigned int fontHeight;
unsigned int color;
unsigned char style;
//void *text_buffer;
text():
fontWidth(0),fontHeight(16),
color(0),style(0),
m_font(NULL)
{
}
~text()
{
destroy();
}
void destroy()
{
//printf("destroy ttf\n");
}
void LCD_PutPixel(unsigned int x, unsigned int y, unsigned long color,
unsigned char gray)
{
*((unsigned long *) pSrcBuffer + y * u32Width + x)=color;
((IMG_PIX *) pSrcBuffer + y * u32Width + x)->u8Alpha = gray;
}
void ft_draw_bitmap(FT_Bitmap *bitmap, int dst_x, int dst_y,unsigned int color);
unsigned int drawText( char * showtxt, unsigned int txt_len)
{
if (m_font != NULL)
{
return m_font->drawText(this, showtxt,txt_len);
}
return 0;
}
unsigned int drawText( char * showtxt, unsigned int txt_len,int padding_left,int padding_top)
{
if (m_font != NULL)
{
return m_font->drawText(this, showtxt,txt_len,padding_left,padding_top);
}
return 0;
}
};
extern map<hustr, FontDev> font_mp;
#endif /* __TTF_FUNC_H__ */