Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100755 401 lines (361 sloc) 11.276 kb
ac480ef4 »
2012-07-08 0.1.5
1 #include <NoRSX/Font.h>
bc784bb1 »
2012-05-21 0.0.8 TTF support (sperimental)
2
3 #define COLOR_TO_ARGB(alpha, red, green, blue) (((alpha) << 24) | ((red) << 16) | ((green) << 8) | (blue))
4 #define COLOR_TO_RGB(red, green, blue) (((red) << 16) | ((green) << 8) | (blue))
5
6 #define VALUE_TO_ARGB(value) (((value) << 24) | ((value) << 16) | ((value) << 8) | (value))
7 #define VALUE_TO_RGB(value) (((value) << 16) | ((value) << 8) | (value))
8
9 #define A(argb) (((argb) >> 24) & 0xFF)
10 #define R(argb) (((argb) >> 16) & 0xFF)
11 #define G(argb) (((argb) >> 8) & 0xFF)
5e94efab »
2012-05-26 added a few options to Font.h/cpp
12 #define B(argb) ((argb) & 0xFF)
bc784bb1 »
2012-05-21 0.0.8 TTF support (sperimental)
13
14
231bddcd »
2012-06-27 0.1.1e - fixed font size
15
6d19c9cb »
2012-05-21 0.0.9 TTF font perfect now!
16 Font::Font(u32 Color, u32 Size,const void *MemFont, u32 MemFont_size, Minimum *min){
bc784bb1 »
2012-05-21 0.0.8 TTF support (sperimental)
17 FontColor = Color;
18 FontSize = Size;
19 Pointer = (FT_Byte*)MemFont;
20 Lenght = MemFont_size;
21 m = min;
22
23 FT_Init_FreeType(&library);
24 FT_New_Memory_Face(library,Pointer,Lenght,0,&face);
25 FT_Stroker_New(library,&stroker);
26 Kerning = FT_HAS_KERNING(face);
27 FT_Set_Pixel_Sizes(face,0,FontSize);
28
6d19c9cb »
2012-05-21 0.0.9 TTF font perfect now!
29 font=0;
bc784bb1 »
2012-05-21 0.0.8 TTF support (sperimental)
30 }
31
6d19c9cb »
2012-05-21 0.0.9 TTF font perfect now!
32 Font::Font(u32 Color, u32 Size, const char *Font_Path, Minimum *min){
33 FontColor = Color;
34 FontSize = Size;
35 Lenght = 0;
36 m = min;
37 FT_Init_FreeType(&library);
38 FT_New_Face(library,Font_Path,0,&face);
39 FT_Stroker_New(library,&stroker);
40 Kerning = FT_HAS_KERNING(face);
41 FT_Set_Pixel_Sizes(face,0,FontSize);
42 font=0;
43 }
5e94efab »
2012-05-26 added a few options to Font.h/cpp
44
45 Font::Font(u32 Size,const void *MemFont, u32 MemFont_size, Minimum *min){
46 FontColor = COLOR_BLACK;
47 FontSize = Size;
48 Pointer = (FT_Byte*)MemFont;
49 Lenght = MemFont_size;
50 m = min;
51
52 FT_Init_FreeType(&library);
53 FT_New_Memory_Face(library,Pointer,Lenght,0,&face);
54 FT_Stroker_New(library,&stroker);
55 Kerning = FT_HAS_KERNING(face);
56 FT_Set_Pixel_Sizes(face,0,FontSize);
57
58 font=0;
59 }
60
61 Font::Font(u32 Size, const char *Font_Path, Minimum *min){
62 FontColor = COLOR_BLACK;
63 FontSize = Size;
64 Lenght = 0;
65 m = min;
66 FT_Init_FreeType(&library);
67 FT_New_Face(library,Font_Path,0,&face);
68 FT_Stroker_New(library,&stroker);
69 Kerning = FT_HAS_KERNING(face);
70 FT_Set_Pixel_Sizes(face,0,FontSize);
71 font=0;
72 }
73
74 Font::Font(const void *MemFont, u32 MemFont_size, Minimum *min){
75 FontColor = COLOR_BLACK;
76 FontSize = DEFAULT_FONT_SIZE;
77 Pointer = (FT_Byte*)MemFont;
78 Lenght = MemFont_size;
79 m = min;
80
81 FT_Init_FreeType(&library);
82 FT_New_Memory_Face(library,Pointer,Lenght,0,&face);
83 FT_Stroker_New(library,&stroker);
84 Kerning = FT_HAS_KERNING(face);
85 FT_Set_Pixel_Sizes(face,0,FontSize);
86
87 font=0;
88 }
89
90 Font::Font(const char *Font_Path, Minimum *min){
91 FontColor = COLOR_BLACK;
92 FontSize = DEFAULT_FONT_SIZE;
93 Lenght = 0;
94 m = min;
95 FT_Init_FreeType(&library);
96 FT_New_Face(library,Font_Path,0,&face);
97 FT_Stroker_New(library,&stroker);
98 Kerning = FT_HAS_KERNING(face);
99 FT_Set_Pixel_Sizes(face,0,FontSize);
100 font=0;
101 }
102
231bddcd »
2012-06-27 0.1.1e - fixed font size
103 Font::Font(const int ID, Minimum *min){
104 const char *Font_Path;
105 if(ID==JPN)
106 Font_Path = "/dev_flash/data/font/SCE-PS3-NR-R-JPN.TTF";
107 else if(ID==KOR)
108 Font_Path = "/dev_flash/data/font/SCE-PS3-YG-R-KOR.TTF";
109 else if(ID==CGB)
110 Font_Path = "/dev_flash/data/font/SCE-PS3-DH-R-CGB.TTF";
111 else if(ID==KANA)
112 Font_Path = "/dev_flash/data/font/SCE-PS3-CP-R-KANA.TTF";
113 else
114 Font_Path = "/dev_flash/data/font/SCE-PS3-VR-R-LATIN2.TTF";
115
116 FontColor = COLOR_BLACK;
117 FontSize = DEFAULT_FONT_SIZE;
118 Lenght = 0;
119 m = min;
120 FT_Init_FreeType(&library);
121 FT_New_Face(library,Font_Path,0,&face);
122 FT_Stroker_New(library,&stroker);
123 Kerning = FT_HAS_KERNING(face);
124 FT_Set_Pixel_Sizes(face,0,FontSize);
125 font=0;
126 }
127
6d19c9cb »
2012-05-21 0.0.9 TTF font perfect now!
128 Font::~Font(){
129 if(font==0)
bc784bb1 »
2012-05-21 0.0.8 TTF support (sperimental)
130 Disable_Fonts();
131 }
132
47eeb7c4 »
2012-06-27 0.1.2 - Fixed Font ChromaKey
133 void Font::ChangeFontColor(u32 color){
134 FontColor = color;
135 }
136
137 void Font::ChangeFontSize(u32 size){
138 FontSize = size;
139 FT_Set_Pixel_Sizes(face,0,FontSize);
140 }
141
6d19c9cb »
2012-05-21 0.0.9 TTF font perfect now!
142 void Font::Disable_Fonts(){
143 FT_Done_Glyph(glyph);
144 FT_Stroker_Done(stroker);
145 FT_Done_Face(face);
146 FT_Done_FreeType(library);
147 font=1;
148 }
149
150 void Font::Printf(u32 x, u32 y,const char *a, ...){
151 char text[1024];
152 va_list va;
153 va_start(va, a);
154 vsnprintf(text, sizeof text, a, va);
bc784bb1 »
2012-05-21 0.0.8 TTF support (sperimental)
155 size_t len = strlen(a);
156 if(len>0){
6d19c9cb »
2012-05-21 0.0.9 TTF font perfect now!
157 len=strlen(text);
bc784bb1 »
2012-05-21 0.0.8 TTF support (sperimental)
158 vec.x = 0;
159 vec.y = FontSize;
160 FT_GlyphSlot slot = face->glyph;
161 FT_UInt glyph_index = 0;
162 FT_UInt previous_glyph = 0;
163 Kerning = FT_HAS_KERNING(face);
164
165 for(unsigned int i=0;i<len;i++){
166 glyph_index = FT_Get_Char_Index(face, text[i]);
167 if(Kerning && previous_glyph && glyph_index){
168 FT_Vector delta;
169 FT_Get_Kerning(face, previous_glyph, glyph_index, FT_KERNING_DEFAULT, &delta);
5e94efab »
2012-05-26 added a few options to Font.h/cpp
170 vec.x += delta.x >> 6;
bc784bb1 »
2012-05-21 0.0.8 TTF support (sperimental)
171 }
172 FT_Load_Glyph(face, glyph_index,FT_LOAD_RENDER);
173 FT_Get_Glyph(face->glyph, &glyph);
174 FT_Glyph_StrokeBorder(&glyph,stroker,0,0);
175 FontDrawBitmap(&slot->bitmap,vec.x + slot->bitmap_left + x, (vec.y - slot->bitmap_top + y -FontSize));
5e94efab »
2012-05-26 added a few options to Font.h/cpp
176 previous_glyph = glyph_index;
bc784bb1 »
2012-05-21 0.0.8 TTF support (sperimental)
177 vec.x += slot->advance.x >> 6;
178 vec.y += slot->advance.y >> 6;
179 }
180 }
181 }
182
5e94efab »
2012-05-26 added a few options to Font.h/cpp
183 void Font::Printf(u32 x, u32 y, u32 Color,const char *a, ...){
184 char text[1024];
185 va_list va;
186 va_start(va, a);
187 vsnprintf(text, sizeof text, a, va);
188 size_t len = strlen(a);
189 if(len>0){
190 u32 C_TMP = FontColor;
191 FontColor = Color;
192 len=strlen(text);
193 vec.x = 0;
194 vec.y = FontSize;
195 FT_GlyphSlot slot = face->glyph;
196 FT_UInt glyph_index = 0;
197 FT_UInt previous_glyph = 0;
198 Kerning = FT_HAS_KERNING(face);
199
200 for(unsigned int i=0;i<len;i++){
201 glyph_index = FT_Get_Char_Index(face, text[i]);
202 if(Kerning && previous_glyph && glyph_index){
203 FT_Vector delta;
204 FT_Get_Kerning(face, previous_glyph, glyph_index, FT_KERNING_DEFAULT, &delta);
205 vec.x += delta.x >> 6;
206 }
207 FT_Load_Glyph(face, glyph_index,FT_LOAD_RENDER);
208 FT_Get_Glyph(face->glyph, &glyph);
209 FT_Glyph_StrokeBorder(&glyph,stroker,0,0);
210 FontDrawBitmap(&slot->bitmap,vec.x + slot->bitmap_left + x, (vec.y - slot->bitmap_top + y -FontSize));
211 previous_glyph = glyph_index;
212 vec.x += slot->advance.x >> 6;
213 vec.y += slot->advance.y >> 6;
214 }
215 FontColor = C_TMP;
216 }
217 }
bc784bb1 »
2012-05-21 0.0.8 TTF support (sperimental)
218
5e94efab »
2012-05-26 added a few options to Font.h/cpp
219 void Font::Printf(u32 x, u32 y, u32 Color, u32 Size,const char *a, ...){
220 char text[1024];
221 va_list va;
222 va_start(va, a);
223 vsnprintf(text, sizeof text, a, va);
224 size_t len = strlen(a);
225 if(len>0){
47eeb7c4 »
2012-06-27 0.1.2 - Fixed Font ChromaKey
226 u32 C_TMP = FontColor;
5e94efab »
2012-05-26 added a few options to Font.h/cpp
227 FontColor = Color;
228 len=strlen(text);
47eeb7c4 »
2012-06-27 0.1.2 - Fixed Font ChromaKey
229 FT_Set_Pixel_Sizes(face,0,Size);
5e94efab »
2012-05-26 added a few options to Font.h/cpp
230 vec.x = 0;
47eeb7c4 »
2012-06-27 0.1.2 - Fixed Font ChromaKey
231 vec.y = Size;
5e94efab »
2012-05-26 added a few options to Font.h/cpp
232 FT_GlyphSlot slot = face->glyph;
233 FT_UInt glyph_index = 0;
234 FT_UInt previous_glyph = 0;
235 Kerning = FT_HAS_KERNING(face);
bc784bb1 »
2012-05-21 0.0.8 TTF support (sperimental)
236
5e94efab »
2012-05-26 added a few options to Font.h/cpp
237 for(unsigned int i=0;i<len;i++){
238 glyph_index = FT_Get_Char_Index(face, text[i]);
239 if(Kerning && previous_glyph && glyph_index){
240 FT_Vector delta;
241 FT_Get_Kerning(face, previous_glyph, glyph_index, FT_KERNING_DEFAULT, &delta);
242 vec.x += delta.x >> 6;
243 }
244 FT_Load_Glyph(face, glyph_index,FT_LOAD_RENDER);
245 FT_Get_Glyph(face->glyph, &glyph);
246 FT_Glyph_StrokeBorder(&glyph,stroker,0,0);
47eeb7c4 »
2012-06-27 0.1.2 - Fixed Font ChromaKey
247 FontDrawBitmap(&slot->bitmap,vec.x + slot->bitmap_left + x, (vec.y - slot->bitmap_top + y -Size));
5e94efab »
2012-05-26 added a few options to Font.h/cpp
248 previous_glyph = glyph_index;
249 vec.x += slot->advance.x >> 6;
250 vec.y += slot->advance.y >> 6;
251 }
252 FontColor = C_TMP;
231bddcd »
2012-06-27 0.1.1e - fixed font size
253 FT_Set_Pixel_Sizes(face,0,FontSize);
254
5e94efab »
2012-05-26 added a few options to Font.h/cpp
255 }
256 }
bc784bb1 »
2012-05-21 0.0.8 TTF support (sperimental)
257
5e94efab »
2012-05-26 added a few options to Font.h/cpp
258 void Font::FontDrawBitmap(FT_Bitmap *bitmap, s32 offset, s32 top){
259 static s32 color;
260 FT_Int x, y, i, j;
261 FT_Int x_max = offset + bitmap->width;
262 FT_Int y_max = top + bitmap->rows;
bc784bb1 »
2012-05-21 0.0.8 TTF support (sperimental)
263 u32 M_width = m->width;
264 u32 M_height = m->height;
5e94efab »
2012-05-26 added a few options to Font.h/cpp
265 for(x = offset, i = 0; x < x_max; x++, i++){
266 if(x >= (s32)M_width) break;
267 for(y = top, j = 0; y < y_max; y++, j++){
268 if(y >= (s32)M_height) break;
269 color = bitmap->buffer[bitmap->width * j + i];
47eeb7c4 »
2012-06-27 0.1.2 - Fixed Font ChromaKey
270 if(CHROMAKEY!=color)
5e94efab »
2012-05-26 added a few options to Font.h/cpp
271 *(m->buffers[m->currentBuffer].ptr + m->width * y + x) = FontColor;
bc784bb1 »
2012-05-21 0.0.8 TTF support (sperimental)
272 }
273 }
274 }
275
152090af »
2012-06-11 performance patches by Deroad/Wargio
276 void Font::PrintfToBitmap(u32 x, u32 y,NoRSX_Bitmap* bmap,const char *a, ...){
277 char text[1024];
278 va_list va;
279 va_start(va, a);
280 vsnprintf(text, sizeof text, a, va);
281 size_t len = strlen(a);
282 if(len>0){
283 len=strlen(text);
284 vec.x = 0;
285 vec.y = FontSize;
286 FT_GlyphSlot slot = face->glyph;
287 FT_UInt glyph_index = 0;
288 FT_UInt previous_glyph = 0;
289 Kerning = FT_HAS_KERNING(face);
bc784bb1 »
2012-05-21 0.0.8 TTF support (sperimental)
290
152090af »
2012-06-11 performance patches by Deroad/Wargio
291 for(unsigned int i=0;i<len;i++){
292 glyph_index = FT_Get_Char_Index(face, text[i]);
293 if(Kerning && previous_glyph && glyph_index){
294 FT_Vector delta;
295 FT_Get_Kerning(face, previous_glyph, glyph_index, FT_KERNING_DEFAULT, &delta);
296 vec.x += delta.x >> 6;
297 }
298 FT_Load_Glyph(face, glyph_index,FT_LOAD_RENDER);
299 FT_Get_Glyph(face->glyph, &glyph);
300 FT_Glyph_StrokeBorder(&glyph,stroker,0,0);
301 FontDrawBitmapToBitmap(&slot->bitmap,bmap,vec.x + slot->bitmap_left + x, (vec.y - slot->bitmap_top + y -FontSize));
302 previous_glyph = glyph_index;
303 vec.x += slot->advance.x >> 6;
304 vec.y += slot->advance.y >> 6;
305 }
306 }
307 }
308
309 void Font::PrintfToBitmap(u32 x, u32 y, NoRSX_Bitmap* bmap, u32 Color,const char *a, ...){
310 char text[1024];
311 va_list va;
312 va_start(va, a);
313 vsnprintf(text, sizeof text, a, va);
314 size_t len = strlen(a);
315 if(len>0){
316 u32 C_TMP = FontColor;
317 FontColor = Color;
318 len=strlen(text);
319 vec.x = 0;
320 vec.y = FontSize;
321 FT_GlyphSlot slot = face->glyph;
322 FT_UInt glyph_index = 0;
323 FT_UInt previous_glyph = 0;
324 Kerning = FT_HAS_KERNING(face);
325
326 for(unsigned int i=0;i<len;i++){
327 glyph_index = FT_Get_Char_Index(face, text[i]);
328 if(Kerning && previous_glyph && glyph_index){
329 FT_Vector delta;
330 FT_Get_Kerning(face, previous_glyph, glyph_index, FT_KERNING_DEFAULT, &delta);
331 vec.x += delta.x >> 6;
332 }
333 FT_Load_Glyph(face, glyph_index,FT_LOAD_RENDER);
334 FT_Get_Glyph(face->glyph, &glyph);
335 FT_Glyph_StrokeBorder(&glyph,stroker,0,0);
336 FontDrawBitmapToBitmap(&slot->bitmap,bmap,vec.x + slot->bitmap_left + x, (vec.y - slot->bitmap_top + y -FontSize));
337 previous_glyph = glyph_index;
338 vec.x += slot->advance.x >> 6;
339 vec.y += slot->advance.y >> 6;
340 }
341 FontColor = C_TMP;
342 }
343 }
344
345 void Font::PrintfToBitmap(u32 x, u32 y, NoRSX_Bitmap* bmap, u32 Color, u32 Size,const char *a, ...){
346 char text[1024];
347 va_list va;
348 va_start(va, a);
349 vsnprintf(text, sizeof text, a, va);
350 size_t len = strlen(a);
351 if(len>0){
47eeb7c4 »
2012-06-27 0.1.2 - Fixed Font ChromaKey
352 u32 C_TMP = FontColor;
152090af »
2012-06-11 performance patches by Deroad/Wargio
353 FontColor = Color;
354 len=strlen(text);
47eeb7c4 »
2012-06-27 0.1.2 - Fixed Font ChromaKey
355 FT_Set_Pixel_Sizes(face,0,Size);
152090af »
2012-06-11 performance patches by Deroad/Wargio
356 vec.x = 0;
47eeb7c4 »
2012-06-27 0.1.2 - Fixed Font ChromaKey
357 vec.y = Size;
152090af »
2012-06-11 performance patches by Deroad/Wargio
358 FT_GlyphSlot slot = face->glyph;
359 FT_UInt glyph_index = 0;
360 FT_UInt previous_glyph = 0;
361 Kerning = FT_HAS_KERNING(face);
362
363 for(unsigned int i=0;i<len;i++){
364 glyph_index = FT_Get_Char_Index(face, text[i]);
365 if(Kerning && previous_glyph && glyph_index){
366 FT_Vector delta;
367 FT_Get_Kerning(face, previous_glyph, glyph_index, FT_KERNING_DEFAULT, &delta);
368 vec.x += delta.x >> 6;
369 }
370 FT_Load_Glyph(face, glyph_index,FT_LOAD_RENDER);
371 FT_Get_Glyph(face->glyph, &glyph);
372 FT_Glyph_StrokeBorder(&glyph,stroker,0,0);
47eeb7c4 »
2012-06-27 0.1.2 - Fixed Font ChromaKey
373 FontDrawBitmapToBitmap(&slot->bitmap,bmap,vec.x + slot->bitmap_left + x, (vec.y - slot->bitmap_top + y -Size));
152090af »
2012-06-11 performance patches by Deroad/Wargio
374 previous_glyph = glyph_index;
375 vec.x += slot->advance.x >> 6;
376 vec.y += slot->advance.y >> 6;
377 }
378 FontColor = C_TMP;
231bddcd »
2012-06-27 0.1.1e - fixed font size
379 FT_Set_Pixel_Sizes(face,0,FontSize);
152090af »
2012-06-11 performance patches by Deroad/Wargio
380 }
381 }
382
383 void Font::FontDrawBitmapToBitmap(FT_Bitmap *bitmap, NoRSX_Bitmap* bmap, s32 offset, s32 top){
384 static s32 color;
385 FT_Int x, y, i, j;
386 FT_Int x_max = offset + bitmap->width;
387 FT_Int y_max = top + bitmap->rows;
388
389 u32 M_width = m->width;
390 u32 M_height = m->height;
391
392 for(x = offset, i = 0;x < x_max;x++, i++ ){
393 if(x >= (s32)M_width)break;
394 for(y = top, j = 0;y < y_max;y++, j++ ){
395 if(y >= (s32) M_height) break;
396 color = bitmap->buffer[bitmap->width * j + i];
47eeb7c4 »
2012-06-27 0.1.2 - Fixed Font ChromaKey
397 if(CHROMAKEY!=color)
152090af »
2012-06-11 performance patches by Deroad/Wargio
398 *(bmap->bitmap + m->width * y + x) = FontColor;
399 }
400 }
401 }
Something went wrong with that request. Please try again.