Rev 5025 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 5025 | Rev 6865 | ||
---|---|---|---|
Line 4... | Line 4... | ||
4 | #include |
4 | #include |
5 | #include |
5 | #include |
6 | #include FT_FREETYPE_H |
6 | #include FT_FREETYPE_H |
7 | #include FT_GLYPH_H |
7 | #include FT_GLYPH_H |
8 | #include |
8 | #include |
9 | 9 | ||
10 | typedef struct |
- | |
11 | { |
- | |
12 | int l; |
- | |
13 | int t; |
- | |
14 | int r; |
- | |
15 | int b; |
- | |
16 | }rect_t; |
- | |
17 | - | ||
Line 18... | Line 10... | ||
18 | typedef struct |
10 | typedef struct |
19 | { |
11 | { |
20 | FT_Face face; |
12 | FT_Face face; |
- | 13 | int fontsize; |
|
21 | int height; |
14 | int height; |
22 | int base; |
15 | int base; |
Line 23... | Line 16... | ||
23 | 16 | ||
Line 24... | Line 17... | ||
24 | FT_Glyph glyph[256]; |
17 | FT_Glyph glyph[256]; |
Line 25... | Line 18... | ||
25 | 18 | ||
- | 19 | }font_t; |
|
- | 20 | ||
- | 21 | static FT_Face def_face; |
|
Line 26... | Line 22... | ||
26 | }font_t; |
22 | static FT_Face sym_face; |
Line 27... | Line 23... | ||
27 | 23 | ||
Line 28... | Line 24... | ||
28 | static FT_Face def_face; |
24 | font_t *sym_font; |
Line 29... | Line 25... | ||
29 | 25 | ||
30 | typedef unsigned int color_t; |
- | |
31 | - | ||
32 | unsigned int ansi2utf32(unsigned char ch); |
- | |
33 | - | ||
34 | font_t *create_font(FT_Face face, int size); |
- | |
35 | - | ||
36 | void my_draw_bitmap(bitmap_t *win, FT_Bitmap *bitmap, int dstx, int dsty, int col) |
- | |
37 | { |
- | |
38 | uint8_t *dst; |
- | |
39 | uint8_t *src, *tmpsrc; |
- | |
40 | - | ||
41 | uint32_t *tmpdst; |
- | |
Line 42... | Line -... | ||
42 | int i, j; |
- | |
43 | 26 | typedef unsigned int color_t; |
|
44 | dst = win->data + dsty * win->pitch + dstx*4; |
- | |
45 | src = bitmap->buffer; |
- | |
46 | - | ||
47 | // printf("buffer %x width %d rows %d\n", |
- | |
48 | // bitmap->buffer, bitmap->width, bitmap->rows); |
- | |
49 | - | ||
50 | - | ||
51 | for( i = 0; i < bitmap->rows; i++ ) |
- | |
52 | { |
27 | |
53 | tmpdst = (uint32_t*)dst; |
- | |
54 | tmpsrc = src; |
28 | unsigned int ansi2utf32(unsigned char ch); |
55 | 29 | ||
56 | dst+= win->pitch; |
- | |
57 | src+= bitmap->pitch; |
- | |
Line 58... | Line 30... | ||
58 | 30 | font_t *create_font(FT_Face face, int size); |
|
59 | for( j = 0; j < bitmap->width; j++) |
31 | |
60 | { |
- | |
Line 61... | Line 32... | ||
61 | int a = *tmpsrc++; |
32 | void draw_glyph(ctx_t *ctx, void *buffer, int pitch, rect_t *rc, color_t color); |
62 | int sr, sg, sb; |
- | |
63 | int dr, dg, db; |
33 | |
Line 64... | Line -... | ||
64 | - | ||
65 | if( a != 0) a++; |
34 | unsigned int ansi2utf32(unsigned char ch) |
66 | 35 | { |
|
Line -... | Line 36... | ||
- | 36 | if(ch < 0x80) |
|
67 | db = *tmpdst & 0xFF; |
37 | return ch; |
- | 38 | ||
68 | dg = (*tmpdst >> 8) & 0xFF; |
39 | if(ch < 0xB0) |
- | 40 | return 0x410-0x80 + ch; |
|
69 | dr = (*tmpdst >> 16) & 0xFF; |
41 | |
70 | - | ||
71 | sb = col & 0xFF; |
- | |
Line 72... | Line 42... | ||
72 | sg = (col >> 8) & 0xFF; |
42 | if(ch < 0xE0) |
73 | sr = (col >> 16) &0xFF; |
43 | return 0; |
74 | 44 | ||
75 | db = (a*sb + db*(256-a))/256; |
45 | if(ch < 0xF0) |
76 | dg = (a*sg + dg*(256-a))/256; |
46 | return 0x440-0xE0 + ch; |
77 | dr = (a*sr + dr*(256-a))/256; |
47 | |
Line 78... | Line 48... | ||
78 | 48 | if(ch == 0xF0) |
|
79 | *tmpdst++ = 0xFF000000|(dr<<16)|(dg<<8)|db; |
49 | return 0x401; |
80 | }; |
50 | else if(ch==0xF1) |
81 | } |
51 | return 0x451; |
Line 82... | Line 52... | ||
82 | }; |
52 | else return 0; |
83 | 53 | } |
|
84 | 54 | ||
Line 85... | Line 55... | ||
85 | int draw_text_ext(bitmap_t *winbitmap, font_t *font, char *text, int len, rect_t *rc, int color) |
55 | int draw_text_ext(ctx_t *ctx, font_t *font, char *text, int len, rect_t *rc, color_t color) |
86 | { |
56 | { |
87 | FT_UInt glyph_index; |
- | |
88 | FT_Bool use_kerning = 0; |
57 | FT_UInt glyph_index; |
Line 89... | Line 58... | ||
89 | FT_BitmapGlyph glyph; |
58 | FT_Bool use_kerning = 0; |
90 | FT_UInt previous; |
59 | FT_BitmapGlyph glyph; |
91 | 60 | FT_UInt previous; |
|
Line 92... | Line 61... | ||
92 | int x, y, w; |
61 | |
93 | int col, ncol; |
62 | int x, y, xend; |
Line 94... | Line 63... | ||
94 | unsigned char ch; |
63 | int col, ncol; |
95 | int err = 0; |
64 | unsigned char ch; |
96 | 65 | int err = 0; |
|
97 | use_kerning = FT_HAS_KERNING( font->face ); |
66 | |
98 | previous = 0; |
67 | use_kerning = FT_HAS_KERNING( font->face ); |
99 | col = 0; |
68 | previous = 0; |
Line 100... | Line 69... | ||
100 | 69 | col = 0; |
|
Line 125... | Line 94... | ||
125 | FT_Get_Kerning( font->face, previous, glyph_index, FT_KERNING_DEFAULT, &delta ); |
94 | FT_Get_Kerning( font->face, previous, glyph_index, FT_KERNING_DEFAULT, &delta ); |
126 | x += delta.x ; |
95 | x += delta.x ; |
127 | } |
96 | } |
128 | 97 | ||
Line 129... | Line 98... | ||
129 | if( x + (font->glyph[ch]->advance.x >> 10) > w) |
98 | if( x + (font->glyph[ch]->advance.x >> 10) >= xend) |
130 | break; |
99 | break; |
Line 131... | Line 100... | ||
131 | 100 | ||
132 | x += font->glyph[ch]->advance.x >> 10; |
101 | x += font->glyph[ch]->advance.x >> 10; |
133 | previous = glyph_index; |
102 | previous = glyph_index; |
Line 145... | Line 114... | ||
145 | FT_Get_Kerning( font->face, previous, glyph_index, FT_KERNING_DEFAULT, &delta ); |
114 | FT_Get_Kerning( font->face, previous, glyph_index, FT_KERNING_DEFAULT, &delta ); |
146 | x += delta.x ; |
115 | x += delta.x ; |
147 | } |
116 | } |
148 | 117 | ||
Line 149... | Line 118... | ||
149 | if( x + (font->glyph[ch]->advance.x >> 10) > w) |
118 | // if( x + (font->glyph[ch]->advance.x >> 10) >= xend) |
- | 119 | // break; |
|
- | 120 | ||
- | 121 | if( x >= xend) |
|
150 | break; |
122 | break; |
Line 151... | Line 123... | ||
151 | 123 | ||
Line -... | Line 124... | ||
- | 124 | glyph = (FT_BitmapGlyph)font->glyph[ch]; |
|
- | 125 | ||
- | 126 | if(glyph != NULL) |
|
- | 127 | { |
|
152 | glyph = (FT_BitmapGlyph)font->glyph[ch]; |
128 | rect_t rc_dst; |
153 | 129 | ||
- | 130 | rc_dst.l = (x >> 6) + glyph->left; |
|
- | 131 | rc_dst.t = y - glyph->top; |
|
- | 132 | rc_dst.r = rc_dst.l + glyph->bitmap.width; |
|
- | 133 | if(rc_dst.r > (xend >> 6)) |
|
- | 134 | rc_dst.r = xend >> 6; |
|
- | 135 | rc_dst.b = rc_dst.t + glyph->bitmap.rows; |
|
- | 136 | ||
Line 154... | Line 137... | ||
154 | my_draw_bitmap(winbitmap, &glyph->bitmap, (x >> 6) + glyph->left, |
137 | // printf("char: %c ", ch); |
- | 138 | px_draw_glyph(ctx, glyph->bitmap.buffer, glyph->bitmap.pitch, &rc_dst, color); |
|
155 | y - glyph->top, color); |
139 | |
156 | 140 | x += font->glyph[ch]->advance.x >> 10; |
|
Line 157... | Line 141... | ||
157 | x += font->glyph[ch]->advance.x >> 10; |
141 | }; |
158 | previous = glyph_index; |
142 | previous = glyph_index; |
Line 178... | Line 162... | ||
178 | // err = FT_New_Face( library, "/kolibrios/Fonts/IstokWeb.ttf", 0, &face ); |
162 | // err = FT_New_Face( library, "/kolibrios/Fonts/IstokWeb.ttf", 0, &face ); |
179 | // err = FT_New_Face( library, "/kolibrios/Fonts/lucon.ttf", 0, &face ); |
163 | // err = FT_New_Face( library, "/kolibrios/Fonts/lucon.ttf", 0, &face ); |
Line 180... | Line 164... | ||
180 | 164 | ||
181 | err = FT_New_Face( library, "/kolibrios/Fonts/DroidSansMono.ttf", 0, &face ); |
- | |
182 | 165 | err = FT_New_Face( library, "/kolibrios/Fonts/DroidSansMono.ttf", 0, &face ); |
|
183 | if ( err == FT_Err_Unknown_File_Format ) |
166 | if ( err == FT_Err_Unknown_File_Format ) |
184 | { |
167 | { |
185 | printf("font format is unsupported\n"); |
168 | printf("font format is unsupported\n"); |
Line 186... | Line 169... | ||
186 | goto done; |
169 | goto done; |
187 | 170 | ||
188 | } |
171 | } |
189 | else if ( err ) |
172 | else if ( err ) |
190 | { |
173 | { |
191 | printf("font file could not be read or broken\n"); |
- | |
192 | goto done; |
174 | printf("font file could not be read or broken\n"); |
Line 193... | Line 175... | ||
193 | 175 | goto done; |
|
Line -... | Line 176... | ||
- | 176 | } |
|
- | 177 | ||
194 | } |
178 | def_face = face; |
- | 179 | ||
- | 180 | err = FT_New_Face( library, "/kolibrios/Fonts/Symbols.ttf", 0, &face ); |
|
Line -... | Line 181... | ||
- | 181 | if ( err == FT_Err_Unknown_File_Format ) |
|
195 | 182 | { |
|
196 | def_face = face; |
183 | printf("font format is unsupported\n"); |
- | 184 | goto done; |
|
- | 185 | ||
- | 186 | } |
|
Line -... | Line 187... | ||
- | 187 | else if ( err ) |
|
Line 197... | Line 188... | ||
197 | 188 | { |
|
198 | done: |
- | |
199 | - | ||
200 | return err; |
- | |
Line 201... | Line 189... | ||
201 | }; |
189 | printf("font file could not be read or broken\n"); |
202 | - | ||
Line 203... | Line -... | ||
203 | - | ||
204 | unsigned int ansi2utf32(unsigned char ch) |
190 | goto done; |
- | 191 | } |
|
Line 205... | Line -... | ||
205 | { |
- | |
206 | if(ch < 0x80) |
- | |
Line 207... | Line -... | ||
207 | return ch; |
- | |
208 | - | ||
209 | if(ch < 0xB0) |
- | |
210 | return 0x410-0x80 + ch; |
- | |
211 | - | ||
212 | if(ch < 0xE0) |
- | |
Line 213... | Line 192... | ||
213 | return 0; |
192 | |
214 | 193 | sym_face = face; |
|
215 | if(ch < 0xF0) |
194 | |
Line 234... | Line 213... | ||
234 | 213 | ||
Line 235... | Line 214... | ||
235 | memset(font, 0, sizeof(*font)); |
214 | memset(font, 0, sizeof(*font)); |
Line 236... | Line 215... | ||
236 | 215 | ||
237 | font->face = (xface == NULL) ? def_face : xface; |
216 | font->face = (xface == NULL) ? def_face : xface; |
Line 238... | Line 217... | ||
238 | font->height = size+1; |
217 | font->height = size; |
Line 239... | Line 218... | ||
239 | 218 | ||
240 | err = FT_Set_Pixel_Sizes( font->face, 0, size ); |
219 | err = FT_Set_Pixel_Sizes( font->face, 0, size ); |
Line 274... | Line 253... | ||
274 | } |
253 | } |
275 | 254 | ||
Line 276... | Line 255... | ||
276 | return font; |
255 | return font; |
277 | }>>>>>>>><>><>8)|db; |
256 | } |
- | 257 | ||
- | 258 | int get_font_height(font_t *font) |
|
- | 259 | { |
|
- | 260 | return font->height; |
|
- | 261 | }>>>><>><>>>>> |
|
- | 262 |