Rev 3068 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 3068 | Rev 3248 | ||
---|---|---|---|
Line 2... | Line 2... | ||
2 | #include |
2 | #include |
3 | #include |
3 | #include |
4 | #include |
4 | #include |
5 | #include |
5 | #include |
6 | #include "font_droid.h" |
6 | //#include "font_droid.h" |
7 | #include |
7 | #include |
8 | #include FT_FREETYPE_H |
8 | #include FT_FREETYPE_H |
9 | 9 | #include |
|
- | 10 | ||
Line 10... | Line 11... | ||
10 | typedef unsigned int color_t; |
11 | extern char res_def_font[]; |
Line 11... | Line 12... | ||
11 | 12 | ||
12 | typedef struct |
13 | typedef struct |
13 | { |
14 | { |
14 | uint32_t width; |
- | |
15 | uint32_t height; |
15 | int l; |
16 | uint32_t pitch; |
16 | int t; |
17 | uint32_t handle; |
17 | int r; |
18 | uint8_t *data; |
18 | int b; |
- | 19 | }rect_t; |
|
- | 20 | ||
Line -... | Line 21... | ||
- | 21 | typedef unsigned int color_t; |
|
Line 19... | Line 22... | ||
19 | }bitmap_t; |
22 | |
20 | 23 | unsigned int ansi2utf32(unsigned char ch); |
|
21 | 24 | ||
22 | void my_draw_bitmap(bitmap_t *win, FT_Bitmap *bitmap, int dstx, int dsty, int col) |
25 | void my_draw_bitmap(bitmap_t *win, FT_Bitmap *bitmap, int dstx, int dsty, int col) |
Line 63... | Line 66... | ||
63 | } |
66 | } |
64 | }; |
67 | }; |
65 | 68 | ||
Line 66... | Line 69... | ||
66 | 69 | ||
67 | int draw_text(bitmap_t * winbitmap, FT_Face face, char *text, int x, int y, int color) |
70 | int draw_text_ext(bitmap_t *winbitmap, FT_Face face, char *text, rect_t *rc, int color) |
68 | { |
71 | { |
69 | FT_UInt glyph_index; |
72 | FT_UInt glyph_index; |
70 | FT_Bool use_kerning = 0; |
73 | FT_Bool use_kerning = 0; |
71 | FT_UInt previous; |
- | |
- | 74 | FT_UInt previous; |
|
72 | 75 | int x, y, w; |
|
73 | char ch; |
76 | char ch; |
Line 74... | Line 77... | ||
74 | int err = 0; |
77 | int err = 0; |
75 | 78 | ||
Line 76... | Line 79... | ||
76 | use_kerning = FT_HAS_KERNING( face ); |
79 | use_kerning = FT_HAS_KERNING( face ); |
- | 80 | previous = 0; |
|
- | 81 | ||
- | 82 | x = rc->l << 6; |
|
Line 77... | Line 83... | ||
77 | previous = 0; |
83 | y = rc->b; |
78 | 84 | ||
79 | x <<= 6; |
85 | w = (rc->r - rc->l) << 6; |
Line 80... | Line 86... | ||
80 | 86 | ||
81 | while( ch = *text++ ) |
87 | while( ch = *text++ ) |
82 | { |
88 | { |
83 | glyph_index = FT_Get_Char_Index( face, ch ); |
89 | glyph_index = FT_Get_Char_Index( face, ansi2utf32(ch) ); |
84 | 90 | ||
85 | if ( use_kerning && previous && glyph_index ) |
91 | if ( use_kerning && previous && glyph_index ) |
Line -... | Line 92... | ||
- | 92 | { |
|
- | 93 | FT_Vector delta; |
|
- | 94 | FT_Get_Kerning( face, previous, glyph_index, FT_KERNING_DEFAULT, &delta ); |
|
86 | { |
95 | x += delta.x ; |
87 | FT_Vector delta; |
96 | } |
88 | FT_Get_Kerning( face, previous, glyph_index, FT_KERNING_DEFAULT, &delta ); |
97 | |
Line 89... | Line 98... | ||
89 | x += delta.x ; |
98 | if( x + face->glyph->advance.x > w) |
Line 106... | Line 115... | ||
106 | 115 | ||
Line 107... | Line 116... | ||
107 | return err; |
116 | return err; |
108 | }; |
117 | }; |
Line -... | Line 118... | ||
- | 118 | ||
109 | 119 | ||
110 | int init_fontlib() |
120 | int init_fontlib() |
111 | { |
121 | { |
Line 112... | Line 122... | ||
112 | int err; |
122 | int err; |
Line 120... | Line 130... | ||
120 | printf("an error occurred during FreeType initialization\n"); |
130 | printf("an error occurred during FreeType initialization\n"); |
121 | goto done; |
131 | goto done; |
122 | } |
132 | } |
123 | 133 | ||
Line 124... | Line 134... | ||
124 | err = FT_New_Face( library, "/hd0/1/istokweb.ttf", 0, &face ); |
134 | // err = FT_New_Face( library, "/hd0/1/IstokWeb.ttf", 0, &face ); |
Line 125... | Line 135... | ||
125 | 135 | ||
126 | // err = FT_New_Memory_Face( library, pdf_font_DroidSans, 139280, 0, &face ); |
136 | err = FT_New_Memory_Face( library, res_def_font, 277996, 0, &face ); |
127 | if ( err == FT_Err_Unknown_File_Format ) |
137 | if ( err == FT_Err_Unknown_File_Format ) |
128 | { |
138 | { |
129 | printf("font format is unsupported\n"); |
139 | printf("font format is unsupported\n"); |
Line 136... | Line 146... | ||
136 | goto done; |
146 | goto done; |
137 | 147 | ||
Line 138... | Line 148... | ||
138 | } |
148 | } |
Line 139... | Line 149... | ||
139 | 149 | ||
140 | err = FT_Set_Char_Size( face, 0, 12*64, 96, 96 ); |
150 | err = FT_Set_Char_Size( face, 0, 11*64, 96, 96 ); |
Line 141... | Line 151... | ||
141 | // err = FT_Set_Pixel_Sizes( face, 0, 100 ); |
151 | // err = FT_Set_Pixel_Sizes( face, 0, 100 ); |
Line 142... | Line 152... | ||
142 | 152 | ||
143 | done: |
153 | done: |
Line 144... | Line 154... | ||
144 | 154 | ||
Line -... | Line 155... | ||
- | 155 | return (int)face; |
|
- | 156 | }; |
|
- | 157 | ||
- | 158 | // draw_text(face,"/hd0/1/demo", 10, 80, 0x00000000); |
|
- | 159 | ||
- | 160 | ||
- | 161 | unsigned int ansi2utf32(unsigned char ch) |
|
- | 162 | { |
|
- | 163 | if(ch < 0x80) |
|
- | 164 | return ch; |
|
- | 165 | ||
- | 166 | if(ch < 0xB0) |
|
- | 167 | return 0x410-0x80 + ch; |
|
- | 168 | ||
- | 169 | if(ch < 0xE0) |
|
- | 170 | return 0; |
|
- | 171 | ||
- | 172 | if(ch < 0xF0) |
|
- | 173 | return 0x440-0xE0 + ch; |
|
- | 174 | ||
- | 175 | if(ch == 0xF0) |
|
- | 176 | return 0x401; |
|
- | 177 | else if(ch==0xF1) |