annotate gui/skin/font.c @ 32790:5c23e57bb0a4

Remove desultory parameter checks. These functions will only be called with parameters already checked or the checked parameters don't harm.
author ib
date Thu, 10 Feb 2011 13:24:00 +0000
parents 236a95445ebb
children ece4313fbf15
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
26458
b0a7b35b78d2 Add standard GPL header to individual files.
diego
parents: 26382
diff changeset
1 /*
b0a7b35b78d2 Add standard GPL header to individual files.
diego
parents: 26382
diff changeset
2 * This file is part of MPlayer.
b0a7b35b78d2 Add standard GPL header to individual files.
diego
parents: 26382
diff changeset
3 *
b0a7b35b78d2 Add standard GPL header to individual files.
diego
parents: 26382
diff changeset
4 * MPlayer is free software; you can redistribute it and/or modify
b0a7b35b78d2 Add standard GPL header to individual files.
diego
parents: 26382
diff changeset
5 * it under the terms of the GNU General Public License as published by
b0a7b35b78d2 Add standard GPL header to individual files.
diego
parents: 26382
diff changeset
6 * the Free Software Foundation; either version 2 of the License, or
b0a7b35b78d2 Add standard GPL header to individual files.
diego
parents: 26382
diff changeset
7 * (at your option) any later version.
b0a7b35b78d2 Add standard GPL header to individual files.
diego
parents: 26382
diff changeset
8 *
b0a7b35b78d2 Add standard GPL header to individual files.
diego
parents: 26382
diff changeset
9 * MPlayer is distributed in the hope that it will be useful,
b0a7b35b78d2 Add standard GPL header to individual files.
diego
parents: 26382
diff changeset
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
b0a7b35b78d2 Add standard GPL header to individual files.
diego
parents: 26382
diff changeset
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
b0a7b35b78d2 Add standard GPL header to individual files.
diego
parents: 26382
diff changeset
12 * GNU General Public License for more details.
b0a7b35b78d2 Add standard GPL header to individual files.
diego
parents: 26382
diff changeset
13 *
b0a7b35b78d2 Add standard GPL header to individual files.
diego
parents: 26382
diff changeset
14 * You should have received a copy of the GNU General Public License along
b0a7b35b78d2 Add standard GPL header to individual files.
diego
parents: 26382
diff changeset
15 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
b0a7b35b78d2 Add standard GPL header to individual files.
diego
parents: 26382
diff changeset
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
b0a7b35b78d2 Add standard GPL header to individual files.
diego
parents: 26382
diff changeset
17 */
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
18
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
19 #include <stdlib.h>
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
20 #include <string.h>
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
21 #include <inttypes.h>
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
22
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
23 #include "skin.h"
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
24 #include "font.h"
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
25 #include "cut.h"
26382
b2f4abcf20ed Make include paths consistent; do not use ../ in them.
diego
parents: 26365
diff changeset
26 #include "mp_msg.h"
b2f4abcf20ed Make include paths consistent; do not use ../ in them.
diego
parents: 26365
diff changeset
27 #include "libavutil/avstring.h"
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
28
32787
d55d0bb7d00f Reduce Fonts array to required size.
ib
parents: 32786
diff changeset
29 bmpFont * Fonts[MAX_FONTS] = { NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL };
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
30
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
31 int fntAddNewFont( char * name )
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
32 {
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
33 int id;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
34 int i;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
35
32787
d55d0bb7d00f Reduce Fonts array to required size.
ib
parents: 32786
diff changeset
36 for( id=0;id<MAX_FONTS;id++ )
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
37 if ( !Fonts[id] ) break;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
38
32786
31f88a1387ad Define constants in a single place.
ib
parents: 32784
diff changeset
39 if ( id == MAX_FONTS ) return -2;
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
40
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
41 if ( ( Fonts[id]=calloc( 1,sizeof( bmpFont ) ) ) == NULL ) return -1;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
42
32786
31f88a1387ad Define constants in a single place.
ib
parents: 32784
diff changeset
43 av_strlcpy( Fonts[id]->name,name,MAX_FONT_NAME );
32734
cc58a1e919d9 Allow character in the font description file to be in UTF-8.
ib
parents: 32712
diff changeset
44 for ( i=0;i<ASCII_CHRS+EXTRA_CHRS;i++ )
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
45 Fonts[id]->Fnt[i].x=Fonts[id]->Fnt[i].y=Fonts[id]->Fnt[i].sx=Fonts[id]->Fnt[i].sy=-1;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
46
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
47 return id;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
48 }
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
49
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
50 void fntFreeFont( void )
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
51 {
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
52 int i;
32786
31f88a1387ad Define constants in a single place.
ib
parents: 32784
diff changeset
53 for( i=0;i < MAX_FONTS;i++ )
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
54 {
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
55 if ( Fonts[i] )
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
56 {
32537
8fa2f43cb760 Remove most of the NULL pointer check before free all over the code
cboesch
parents: 30405
diff changeset
57 free( Fonts[i]->Bitmap.Image );
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
58 free( Fonts[i] );
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
59 Fonts[i]=NULL;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
60 }
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
61 }
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
62 }
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
63
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
64 int fntRead( char * path,char * fname )
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
65 {
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
66 FILE * f;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
67 unsigned char tmp[512];
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
68 unsigned char * ptmp;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
69 unsigned char command[32];
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
70 unsigned char param[256];
32784
0a9481b9ce00 Remove needless includes and declarations.
ib
parents: 32759
diff changeset
71 int c;
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
72 int id = fntAddNewFont( fname );
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 26458
diff changeset
73
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
74 if ( id < 0 ) return id;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
75
23703
9fb716ab06a3 Avoid code duplication and ugly config.h hack by using av_strlcat/av_strlcpy
reimar
parents: 23077
diff changeset
76 av_strlcpy( tmp,path,sizeof( tmp ) );
9fb716ab06a3 Avoid code duplication and ugly config.h hack by using av_strlcat/av_strlcpy
reimar
parents: 23077
diff changeset
77 av_strlcat( tmp,fname,sizeof( tmp ) ); av_strlcat( tmp,".fnt",sizeof( tmp ) );
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 26458
diff changeset
78 if ( ( f=fopen( tmp,"rt" ) ) == NULL )
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
79 { free( Fonts[id] ); return -3; }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 26458
diff changeset
80
30405
d39acea63f2e Simplify and correct loop condition, also avoids a compiler warning for unused result.
reimar
parents: 30404
diff changeset
81 while ( fgets( tmp,255,f ) )
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
82 {
30404
5fbb30fa62cc Fix newline removal code that might read and write out of bounds.
reimar
parents: 29263
diff changeset
83 // remove any kind of newline, if any
5fbb30fa62cc Fix newline removal code that might read and write out of bounds.
reimar
parents: 29263
diff changeset
84 tmp[strcspn(tmp, "\n\r")] = 0;
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
85 for ( c=0;c < (int)strlen( tmp );c++ )
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
86 if ( tmp[c] == ';' ) { tmp[c]=0; break; }
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
87 if ( !tmp[0] ) continue;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
88 ptmp=trimleft( tmp );
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
89 if ( !tmp[0] ) continue;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
90 ptmp=strswap( ptmp,'\t',' ' );
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
91 ptmp=trim( ptmp );
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
92 cutItem( ptmp,command,'=',0 ); cutItem( ptmp,param,'=',1 );
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
93 if ( command[0] == '"' )
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
94 {
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
95 int i;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
96 cutItem( command,command,'"',1 );
32789
236a95445ebb Always access font characters in the same way
ib
parents: 32787
diff changeset
97 if ( !command[0] ) i='"';
32734
cc58a1e919d9 Allow character in the font description file to be in UTF-8.
ib
parents: 32712
diff changeset
98 else if ( command[0] & 0x80 )
cc58a1e919d9 Allow character in the font description file to be in UTF-8.
ib
parents: 32712
diff changeset
99 {
cc58a1e919d9 Allow character in the font description file to be in UTF-8.
ib
parents: 32712
diff changeset
100 for ( i = 0; i < EXTRA_CHRS; i++ )
cc58a1e919d9 Allow character in the font description file to be in UTF-8.
ib
parents: 32712
diff changeset
101 {
cc58a1e919d9 Allow character in the font description file to be in UTF-8.
ib
parents: 32712
diff changeset
102 if ( !Fonts[id]->nonASCIIidx[i][0] )
cc58a1e919d9 Allow character in the font description file to be in UTF-8.
ib
parents: 32712
diff changeset
103 {
cc58a1e919d9 Allow character in the font description file to be in UTF-8.
ib
parents: 32712
diff changeset
104 strncpy( Fonts[id]->nonASCIIidx[i], command, 4 );
cc58a1e919d9 Allow character in the font description file to be in UTF-8.
ib
parents: 32712
diff changeset
105 break;
cc58a1e919d9 Allow character in the font description file to be in UTF-8.
ib
parents: 32712
diff changeset
106 }
cc58a1e919d9 Allow character in the font description file to be in UTF-8.
ib
parents: 32712
diff changeset
107 }
cc58a1e919d9 Allow character in the font description file to be in UTF-8.
ib
parents: 32712
diff changeset
108 if ( i == EXTRA_CHRS ) continue;
cc58a1e919d9 Allow character in the font description file to be in UTF-8.
ib
parents: 32712
diff changeset
109 i += ASCII_CHRS;
cc58a1e919d9 Allow character in the font description file to be in UTF-8.
ib
parents: 32712
diff changeset
110 }
32789
236a95445ebb Always access font characters in the same way
ib
parents: 32787
diff changeset
111 else i=command[0];
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
112 cutItem( param,tmp,',',0 ); Fonts[id]->Fnt[i].x=atoi( tmp );
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
113 cutItem( param,tmp,',',1 ); Fonts[id]->Fnt[i].y=atoi( tmp );
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
114 cutItem( param,tmp,',',2 ); Fonts[id]->Fnt[i].sx=atoi( tmp );
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
115 cutItem( param,tmp,',',3 ); Fonts[id]->Fnt[i].sy=atoi( tmp );
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
116 mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"[font] char: '%s' params: %d,%d %dx%d\n",command,Fonts[id]->Fnt[i].x,Fonts[id]->Fnt[i].y,Fonts[id]->Fnt[i].sx,Fonts[id]->Fnt[i].sy );
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
117 }
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
118 else
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
119 {
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
120 if ( !strcmp( command,"image" ) )
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
121 {
23703
9fb716ab06a3 Avoid code duplication and ugly config.h hack by using av_strlcat/av_strlcpy
reimar
parents: 23077
diff changeset
122 av_strlcpy( tmp,path,sizeof( tmp ) ); av_strlcat( tmp,param,sizeof( tmp ) );
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
123 mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"[font] font imagefile: %s\n",tmp );
32712
6ff3cc81d602 Fix resource leaks and check for realloc failures
ib
parents: 32707
diff changeset
124 if ( skinBPRead( tmp,&Fonts[id]->Bitmap ) )
6ff3cc81d602 Fix resource leaks and check for realloc failures
ib
parents: 32707
diff changeset
125 {
6ff3cc81d602 Fix resource leaks and check for realloc failures
ib
parents: 32707
diff changeset
126 fclose(f);
6ff3cc81d602 Fix resource leaks and check for realloc failures
ib
parents: 32707
diff changeset
127 return -4;
6ff3cc81d602 Fix resource leaks and check for realloc failures
ib
parents: 32707
diff changeset
128 }
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
129 }
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
130 }
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
131 }
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
132
32712
6ff3cc81d602 Fix resource leaks and check for realloc failures
ib
parents: 32707
diff changeset
133 fclose(f);
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
134 return 0;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
135 }
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
136
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
137 int fntFindID( char * name )
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
138 {
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
139 int i;
32786
31f88a1387ad Define constants in a single place.
ib
parents: 32784
diff changeset
140 for ( i=0;i < MAX_FONTS;i++ )
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
141 if ( Fonts[i] )
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
142 if ( !strcmp( name,Fonts[i]->name ) ) return i;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
143 return -1;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
144 }
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
145
32734
cc58a1e919d9 Allow character in the font description file to be in UTF-8.
ib
parents: 32712
diff changeset
146 // get Fnt index of character (utf8 or normal one) *str points to,
cc58a1e919d9 Allow character in the font description file to be in UTF-8.
ib
parents: 32712
diff changeset
147 // then move pointer to next/previous character
cc58a1e919d9 Allow character in the font description file to be in UTF-8.
ib
parents: 32712
diff changeset
148 int fntGetCharIndex( int id, unsigned char **str, gboolean utf8, int direction )
cc58a1e919d9 Allow character in the font description file to be in UTF-8.
ib
parents: 32712
diff changeset
149 {
cc58a1e919d9 Allow character in the font description file to be in UTF-8.
ib
parents: 32712
diff changeset
150 unsigned char *p, uchar[4] = { 0, 0, 0, 0 };
cc58a1e919d9 Allow character in the font description file to be in UTF-8.
ib
parents: 32712
diff changeset
151 int i, c = -1;
cc58a1e919d9 Allow character in the font description file to be in UTF-8.
ib
parents: 32712
diff changeset
152
cc58a1e919d9 Allow character in the font description file to be in UTF-8.
ib
parents: 32712
diff changeset
153 if ( **str & 0x80 )
cc58a1e919d9 Allow character in the font description file to be in UTF-8.
ib
parents: 32712
diff changeset
154 {
cc58a1e919d9 Allow character in the font description file to be in UTF-8.
ib
parents: 32712
diff changeset
155 if ( utf8 )
cc58a1e919d9 Allow character in the font description file to be in UTF-8.
ib
parents: 32712
diff changeset
156 {
cc58a1e919d9 Allow character in the font description file to be in UTF-8.
ib
parents: 32712
diff changeset
157 p = *str;
cc58a1e919d9 Allow character in the font description file to be in UTF-8.
ib
parents: 32712
diff changeset
158 *str = g_utf8_next_char( *str );
cc58a1e919d9 Allow character in the font description file to be in UTF-8.
ib
parents: 32712
diff changeset
159 strncpy( uchar, p, *str - p );
cc58a1e919d9 Allow character in the font description file to be in UTF-8.
ib
parents: 32712
diff changeset
160
cc58a1e919d9 Allow character in the font description file to be in UTF-8.
ib
parents: 32712
diff changeset
161 if ( direction < 0 ) *str = g_utf8_prev_char( p );
cc58a1e919d9 Allow character in the font description file to be in UTF-8.
ib
parents: 32712
diff changeset
162 }
cc58a1e919d9 Allow character in the font description file to be in UTF-8.
ib
parents: 32712
diff changeset
163 else
cc58a1e919d9 Allow character in the font description file to be in UTF-8.
ib
parents: 32712
diff changeset
164 {
cc58a1e919d9 Allow character in the font description file to be in UTF-8.
ib
parents: 32712
diff changeset
165 uchar[0] = **str;
cc58a1e919d9 Allow character in the font description file to be in UTF-8.
ib
parents: 32712
diff changeset
166 *str += direction;
cc58a1e919d9 Allow character in the font description file to be in UTF-8.
ib
parents: 32712
diff changeset
167 }
cc58a1e919d9 Allow character in the font description file to be in UTF-8.
ib
parents: 32712
diff changeset
168
cc58a1e919d9 Allow character in the font description file to be in UTF-8.
ib
parents: 32712
diff changeset
169 for ( i = 0; ( i < EXTRA_CHRS ) && Fonts[id]->nonASCIIidx[i][0]; i++ )
cc58a1e919d9 Allow character in the font description file to be in UTF-8.
ib
parents: 32712
diff changeset
170 {
cc58a1e919d9 Allow character in the font description file to be in UTF-8.
ib
parents: 32712
diff changeset
171 if ( strncmp( Fonts[id]->nonASCIIidx[i], uchar, 4 ) == 0 ) return i + ASCII_CHRS;
cc58a1e919d9 Allow character in the font description file to be in UTF-8.
ib
parents: 32712
diff changeset
172 if ( !utf8 && ( Fonts[id]->nonASCIIidx[i][0] == (*uchar >> 6 | 0xc0) && Fonts[id]->nonASCIIidx[i][1] == (*uchar & 0x3f | 0x80) && Fonts[id]->nonASCIIidx[i][2] == 0 ) ) c = i + ASCII_CHRS;
cc58a1e919d9 Allow character in the font description file to be in UTF-8.
ib
parents: 32712
diff changeset
173 }
cc58a1e919d9 Allow character in the font description file to be in UTF-8.
ib
parents: 32712
diff changeset
174 }
cc58a1e919d9 Allow character in the font description file to be in UTF-8.
ib
parents: 32712
diff changeset
175 else
cc58a1e919d9 Allow character in the font description file to be in UTF-8.
ib
parents: 32712
diff changeset
176 {
cc58a1e919d9 Allow character in the font description file to be in UTF-8.
ib
parents: 32712
diff changeset
177 c = **str;
cc58a1e919d9 Allow character in the font description file to be in UTF-8.
ib
parents: 32712
diff changeset
178
cc58a1e919d9 Allow character in the font description file to be in UTF-8.
ib
parents: 32712
diff changeset
179 if ( utf8 && ( direction < 0 ) ) *str = g_utf8_prev_char( *str );
cc58a1e919d9 Allow character in the font description file to be in UTF-8.
ib
parents: 32712
diff changeset
180 else *str += direction;
cc58a1e919d9 Allow character in the font description file to be in UTF-8.
ib
parents: 32712
diff changeset
181 }
cc58a1e919d9 Allow character in the font description file to be in UTF-8.
ib
parents: 32712
diff changeset
182
cc58a1e919d9 Allow character in the font description file to be in UTF-8.
ib
parents: 32712
diff changeset
183 return c;
cc58a1e919d9 Allow character in the font description file to be in UTF-8.
ib
parents: 32712
diff changeset
184 }
cc58a1e919d9 Allow character in the font description file to be in UTF-8.
ib
parents: 32712
diff changeset
185
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
186 int fntTextWidth( int id,char * str )
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
187 {
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
188 int size = 0;
32734
cc58a1e919d9 Allow character in the font description file to be in UTF-8.
ib
parents: 32712
diff changeset
189 gboolean utf8;
cc58a1e919d9 Allow character in the font description file to be in UTF-8.
ib
parents: 32712
diff changeset
190 unsigned char *p;
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
191
32734
cc58a1e919d9 Allow character in the font description file to be in UTF-8.
ib
parents: 32712
diff changeset
192 utf8 = g_utf8_validate( str, -1, NULL);
cc58a1e919d9 Allow character in the font description file to be in UTF-8.
ib
parents: 32712
diff changeset
193 p = (unsigned char *) str;
cc58a1e919d9 Allow character in the font description file to be in UTF-8.
ib
parents: 32712
diff changeset
194
cc58a1e919d9 Allow character in the font description file to be in UTF-8.
ib
parents: 32712
diff changeset
195 while ( *p )
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
196 {
32734
cc58a1e919d9 Allow character in the font description file to be in UTF-8.
ib
parents: 32712
diff changeset
197 int c = fntGetCharIndex( id, &p, utf8, 1 );
cc58a1e919d9 Allow character in the font description file to be in UTF-8.
ib
parents: 32712
diff changeset
198 if ( c == -1 || Fonts[id]->Fnt[c].sx == -1 ) c = ' ';
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
199 size+= Fonts[id]->Fnt[ c ].sx;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
200 }
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
201 return size;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
202 }
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
203
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
204 int fntTextHeight( int id,char * str )
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
205 {
32734
cc58a1e919d9 Allow character in the font description file to be in UTF-8.
ib
parents: 32712
diff changeset
206 int max = 0;
cc58a1e919d9 Allow character in the font description file to be in UTF-8.
ib
parents: 32712
diff changeset
207 gboolean utf8;
cc58a1e919d9 Allow character in the font description file to be in UTF-8.
ib
parents: 32712
diff changeset
208 unsigned char *p;
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
209
32734
cc58a1e919d9 Allow character in the font description file to be in UTF-8.
ib
parents: 32712
diff changeset
210 utf8 = g_utf8_validate( str, -1, NULL);
cc58a1e919d9 Allow character in the font description file to be in UTF-8.
ib
parents: 32712
diff changeset
211 p = (unsigned char *) str;
cc58a1e919d9 Allow character in the font description file to be in UTF-8.
ib
parents: 32712
diff changeset
212
cc58a1e919d9 Allow character in the font description file to be in UTF-8.
ib
parents: 32712
diff changeset
213 while ( *p )
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
214 {
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
215 int h;
32734
cc58a1e919d9 Allow character in the font description file to be in UTF-8.
ib
parents: 32712
diff changeset
216 int c = fntGetCharIndex( id, &p, utf8, 1 );
cc58a1e919d9 Allow character in the font description file to be in UTF-8.
ib
parents: 32712
diff changeset
217 if ( c == -1 || Fonts[id]->Fnt[c].sx == -1 ) c = ' ';
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
218 h = Fonts[id]->Fnt[c].sy;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
219 if ( h > max ) max=h;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
220 }
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
221 return max;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
222 }
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
223
32759
63844ef43932 Remove useless format argument.
ib
parents: 32734
diff changeset
224 txSample * fntRender( wItem * item,int px,char * txt )
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
225 {
32759
63844ef43932 Remove useless format argument.
ib
parents: 32734
diff changeset
226 unsigned char * u;
32734
cc58a1e919d9 Allow character in the font description file to be in UTF-8.
ib
parents: 32712
diff changeset
227 int c, i, dx = 0, tw, fbw, iw, id, ofs;
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
228 int x,y,fh,fw,fyc,yc;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
229 uint32_t * ibuf;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
230 uint32_t * obuf;
32734
cc58a1e919d9 Allow character in the font description file to be in UTF-8.
ib
parents: 32712
diff changeset
231 gboolean utf8;
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
232
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
233 id=item->fontid;
32790
5c23e57bb0a4 Remove desultory parameter checks.
ib
parents: 32789
diff changeset
234 tw=fntTextWidth( id,txt );
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
235
32790
5c23e57bb0a4 Remove desultory parameter checks.
ib
parents: 32789
diff changeset
236 if ( !tw ) return NULL;
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
237
32790
5c23e57bb0a4 Remove desultory parameter checks.
ib
parents: 32789
diff changeset
238 iw=item->width;
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
239 fbw=Fonts[id]->Bitmap.Width;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
240
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 26458
diff changeset
241 if ( item->Bitmap.Image == NULL )
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
242 {
32759
63844ef43932 Remove useless format argument.
ib
parents: 32734
diff changeset
243 item->Bitmap.Height=item->height=fntTextHeight( id,txt );
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
244 item->Bitmap.Width=item->width=iw;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
245 item->Bitmap.ImageSize=item->height * iw * 4;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
246 if ( !item->Bitmap.ImageSize ) return NULL;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
247 item->Bitmap.BPP=32;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
248 item->Bitmap.Image=malloc( item->Bitmap.ImageSize );
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
249 }
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
250
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
251 obuf=(uint32_t *)item->Bitmap.Image;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
252 ibuf=(uint32_t *)Fonts[id]->Bitmap.Image;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
253
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
254 for ( i=0;i < item->Bitmap.ImageSize / 4;i++ ) obuf[i]=0xff00ff;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 26458
diff changeset
255
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 26458
diff changeset
256 if ( tw <= iw )
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
257 {
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
258 switch ( item->align )
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
259 {
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
260 default:
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
261 case fntAlignLeft: dx=0; break;
32759
63844ef43932 Remove useless format argument.
ib
parents: 32734
diff changeset
262 case fntAlignCenter: dx=( iw - fntTextWidth( id,txt ) ) / 2; break;
63844ef43932 Remove useless format argument.
ib
parents: 32734
diff changeset
263 case fntAlignRight: dx=iw - fntTextWidth( id,txt ); break;
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
264 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 26458
diff changeset
265
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
266 } else dx+=px;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
267
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
268 ofs=dx;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 26458
diff changeset
269
32759
63844ef43932 Remove useless format argument.
ib
parents: 32734
diff changeset
270 utf8 = g_utf8_validate( txt, -1, NULL);
63844ef43932 Remove useless format argument.
ib
parents: 32734
diff changeset
271 u = txt;
32734
cc58a1e919d9 Allow character in the font description file to be in UTF-8.
ib
parents: 32712
diff changeset
272
cc58a1e919d9 Allow character in the font description file to be in UTF-8.
ib
parents: 32712
diff changeset
273 while ( *u )
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
274 {
32734
cc58a1e919d9 Allow character in the font description file to be in UTF-8.
ib
parents: 32712
diff changeset
275 c = fntGetCharIndex( id, &u, utf8, 1 );
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 26458
diff changeset
276
32734
cc58a1e919d9 Allow character in the font description file to be in UTF-8.
ib
parents: 32712
diff changeset
277 if ( c != -1 ) fw=Fonts[id]->Fnt[c].sx;
cc58a1e919d9 Allow character in the font description file to be in UTF-8.
ib
parents: 32712
diff changeset
278
32789
236a95445ebb Always access font characters in the same way
ib
parents: 32787
diff changeset
279 if ( c == -1 || fw == -1 ) { c=' '; fw=Fonts[id]->Fnt[c].sx; }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 26458
diff changeset
280
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
281 fh=Fonts[id]->Fnt[c].sy;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
282 fyc=Fonts[id]->Fnt[c].y * fbw + Fonts[id]->Fnt[c].x;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
283 yc=dx;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 26458
diff changeset
284
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 26458
diff changeset
285 if ( dx >= 0 )
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
286 for ( y=0;y < fh;y++ )
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
287 {
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
288 for ( x=0; x < fw;x++ )
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
289 if ( dx + x >= 0 && dx + x < iw ) obuf[yc + x]=ibuf[ fyc + x ];
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
290 fyc+=fbw;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
291 yc+=iw;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
292 }
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
293 dx+=fw;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
294 }
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
295
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
296 if ( ofs > 0 && tw > item->width )
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
297 {
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
298 dx=ofs;
32759
63844ef43932 Remove useless format argument.
ib
parents: 32734
diff changeset
299 u = txt + strlen( txt );
32734
cc58a1e919d9 Allow character in the font description file to be in UTF-8.
ib
parents: 32712
diff changeset
300
32759
63844ef43932 Remove useless format argument.
ib
parents: 32734
diff changeset
301 while ( u > (unsigned char *) txt )
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
302 {
32734
cc58a1e919d9 Allow character in the font description file to be in UTF-8.
ib
parents: 32712
diff changeset
303 c = fntGetCharIndex( id, &u, utf8, -1 );
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 26458
diff changeset
304
32734
cc58a1e919d9 Allow character in the font description file to be in UTF-8.
ib
parents: 32712
diff changeset
305 if ( c != -1) fw=Fonts[id]->Fnt[c].sx;
cc58a1e919d9 Allow character in the font description file to be in UTF-8.
ib
parents: 32712
diff changeset
306
32789
236a95445ebb Always access font characters in the same way
ib
parents: 32787
diff changeset
307 if ( c == -1 || fw == -1 ) { c=' '; fw=Fonts[id]->Fnt[c].sx; }
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
308
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
309 fh=Fonts[id]->Fnt[c].sy;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
310 fyc=Fonts[id]->Fnt[c].y * fbw + Fonts[id]->Fnt[c].x;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
311
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
312 dx-=fw; yc=dx;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 26458
diff changeset
313 if ( dx >= 0 )
23077
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
314 for ( y=0;y < fh;y++ )
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
315 {
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
316 for ( x=fw - 1;x >= 0;x-- )
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
317 if ( dx + x >= 0 && dx + x < iw ) obuf[yc + x]=ibuf[fyc + x];
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
318 fyc+=fbw;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
319 yc+=iw;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
320 }
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
321 }
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
322 }
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
323
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
324 return &item->Bitmap;
17bf4f4b0715 Gui --> gui
diego
parents:
diff changeset
325 }