Mercurial > mplayer.hg
annotate Gui/skin/font.c @ 15205:19243f85e164
nico partially fixed the bug i reported; here's the rest of the fix.
basically demux_audio was mixing data in its header buffer in a bogus
manner, whereby it could sometimes "make up" valid mpeg headers where
no such header actually occurred in the file. it should be correct now.
btw these changes also fix the bug where mplayer reports huge initial
cpu usage for sound when playing mp3 files.
author | rfelker |
---|---|
date | Sun, 17 Apr 2005 17:17:52 +0000 |
parents | 9a495bdc3a1e |
children | 0e1471d9da74 |
rev | line source |
---|---|
1693 | 1 |
2 #include <stdlib.h> | |
3 #include <stdio.h> | |
4 #include <stdarg.h> | |
5 #include <string.h> | |
6166
82f770634c5b
inttypes gui patch from Bjrn Sandell <biorn@dce.chalmers.se>
pontscho
parents:
6159
diff
changeset
|
6 #include <inttypes.h> |
1693 | 7 |
8864 | 8 #include "../app.h" |
1693 | 9 #include "skin.h" |
10 #include "font.h" | |
11 #include "cut.h" | |
4818
3473ca9ef158
new gui interface, and gtk moved into mplayer process. fork ... bleh :)
pontscho
parents:
1907
diff
changeset
|
12 #include "../../mp_msg.h" |
1693 | 13 |
14 int items; | |
15 | |
6218 | 16 bmpFont * Fonts[26] = { 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 }; |
1693 | 17 |
18 int fntAddNewFont( char * name ) | |
19 { | |
20 int id; | |
6218 | 21 int i; |
22 | |
23 for( id=0;id<26;id++ ) | |
24 if ( !Fonts[id] ) break; | |
25 | |
26 if ( id == 25 ) return -2; | |
27 | |
28 if ( ( Fonts[id]=calloc( 1,sizeof( bmpFont ) ) ) == NULL ) return -1; | |
29 | |
12646 | 30 strlcpy( Fonts[id]->name,name,128 ); // FIXME: as defined in font.h |
6218 | 31 for ( i=0;i<256;i++ ) |
32 Fonts[id]->Fnt[i].x=Fonts[id]->Fnt[i].y=Fonts[id]->Fnt[i].sx=Fonts[id]->Fnt[i].sy=-1; | |
33 | |
1693 | 34 return id; |
35 } | |
36 | |
1829 | 37 void fntFreeFont( void ) |
1693 | 38 { |
1829 | 39 int i; |
6218 | 40 for( i=0;i < 25;i++ ) |
1829 | 41 { |
42 if ( Fonts[i] ) | |
43 { | |
44 if ( Fonts[i]->Bitmap.Image ) free( Fonts[i]->Bitmap.Image ); | |
45 free( Fonts[i] ); | |
46 Fonts[i]=NULL; | |
47 } | |
48 } | |
1693 | 49 } |
50 | |
6218 | 51 int fntRead( char * path,char * fname ) |
1693 | 52 { |
53 FILE * f; | |
54 unsigned char tmp[512]; | |
55 unsigned char * ptmp; | |
56 unsigned char command[32]; | |
57 unsigned char param[256]; | |
4818
3473ca9ef158
new gui interface, and gtk moved into mplayer process. fork ... bleh :)
pontscho
parents:
1907
diff
changeset
|
58 int c,linenumber = 0; |
6218 | 59 int id = fntAddNewFont( fname ); |
60 | |
61 if ( id < 0 ) return id; | |
1693 | 62 |
12646 | 63 strlcpy( tmp,path,sizeof( tmp ) ); |
64 strlcat( tmp,fname,sizeof( tmp ) ); strlcat( tmp,".fnt",sizeof( tmp ) ); | |
6218 | 65 if ( ( f=fopen( tmp,"rt" ) ) == NULL ) |
66 { free( Fonts[id] ); return -3; } | |
67 | |
1693 | 68 while ( !feof( f ) ) |
69 { | |
70 fgets( tmp,255,f ); linenumber++; | |
71 | |
72 c=tmp[ strlen( tmp ) - 1 ]; if ( ( c == '\n' )||( c == '\r' ) ) tmp[ strlen( tmp ) - 1 ]=0; | |
73 c=tmp[ strlen( tmp ) - 1 ]; if ( ( c == '\n' )||( c == '\r' ) ) tmp[ strlen( tmp ) - 1 ]=0; | |
4818
3473ca9ef158
new gui interface, and gtk moved into mplayer process. fork ... bleh :)
pontscho
parents:
1907
diff
changeset
|
74 for ( c=0;c < (int)strlen( tmp );c++ ) |
6218 | 75 if ( tmp[c] == ';' ) { tmp[c]=0; break; } |
76 if ( !tmp[0] ) continue; | |
8973 | 77 ptmp=trimleft( tmp ); |
6218 | 78 if ( !tmp[0] ) continue; |
1693 | 79 ptmp=strswap( ptmp,'\t',' ' ); |
8973 | 80 ptmp=trim( ptmp ); |
1693 | 81 cutItem( ptmp,command,'=',0 ); cutItem( ptmp,param,'=',1 ); |
82 if ( command[0] == '"' ) | |
83 { | |
84 int i; | |
85 cutItem( command,command,'"',1 ); | |
86 i=(int)command[0]; | |
87 cutItem( param,tmp,',',0 ); Fonts[id]->Fnt[i].x=atoi( tmp ); | |
88 cutItem( param,tmp,',',1 ); Fonts[id]->Fnt[i].y=atoi( tmp ); | |
89 cutItem( param,tmp,',',2 ); Fonts[id]->Fnt[i].sx=atoi( tmp ); | |
90 cutItem( param,tmp,',',3 ); Fonts[id]->Fnt[i].sy=atoi( tmp ); | |
4818
3473ca9ef158
new gui interface, and gtk moved into mplayer process. fork ... bleh :)
pontscho
parents:
1907
diff
changeset
|
91 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 ); |
1693 | 92 } |
93 else | |
94 { | |
95 if ( !strcmp( command,"image" ) ) | |
96 { | |
12646 | 97 strlcpy( tmp,path,sizeof( tmp ) ); strlcat( tmp,param,sizeof( tmp ) ); |
4818
3473ca9ef158
new gui interface, and gtk moved into mplayer process. fork ... bleh :)
pontscho
parents:
1907
diff
changeset
|
98 mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"[font] font imagefile: %s\n",tmp ); |
6218 | 99 if ( skinBPRead( tmp,&Fonts[id]->Bitmap ) ) return -4; |
1693 | 100 } |
101 } | |
6218 | 102 } |
103 | |
1693 | 104 return 0; |
105 } | |
106 | |
107 int fntFindID( char * name ) | |
108 { | |
109 int i; | |
110 for ( i=0;i < 25;i++ ) | |
6218 | 111 if ( Fonts[i] ) |
112 if ( !strcmp( name,Fonts[i]->name ) ) return i; | |
1693 | 113 return -1; |
114 } | |
115 | |
116 int fntTextWidth( int id,char * str ) | |
117 { | |
118 int size = 0; | |
119 int i; | |
6218 | 120 |
121 if ( ( !Fonts[id] )||( !str[0] ) ) return 0; | |
122 | |
8864 | 123 for ( i=0;i < (int)strlen( str );i++ ) |
7353
0cb951ac0133
Use the character substitution code from fntRender() / fntTextWidth()
jkeil
parents:
6218
diff
changeset
|
124 { |
0cb951ac0133
Use the character substitution code from fntRender() / fntTextWidth()
jkeil
parents:
6218
diff
changeset
|
125 unsigned char c = (unsigned char)str[i]; |
0cb951ac0133
Use the character substitution code from fntRender() / fntTextWidth()
jkeil
parents:
6218
diff
changeset
|
126 if ( Fonts[id]->Fnt[c].sx == -1 ) c = ' '; |
0cb951ac0133
Use the character substitution code from fntRender() / fntTextWidth()
jkeil
parents:
6218
diff
changeset
|
127 size+= Fonts[id]->Fnt[ c ].sx; |
0cb951ac0133
Use the character substitution code from fntRender() / fntTextWidth()
jkeil
parents:
6218
diff
changeset
|
128 } |
1693 | 129 return size; |
130 } | |
131 | |
132 int fntTextHeight( int id,char * str ) | |
133 { | |
134 int max = 0,i; | |
6218 | 135 |
136 if ( ( !Fonts[id] )||( !str[0] ) ) return 0; | |
137 | |
4818
3473ca9ef158
new gui interface, and gtk moved into mplayer process. fork ... bleh :)
pontscho
parents:
1907
diff
changeset
|
138 for ( i=0;i < (int)strlen( str );i++ ) |
6218 | 139 { |
7353
0cb951ac0133
Use the character substitution code from fntRender() / fntTextWidth()
jkeil
parents:
6218
diff
changeset
|
140 int h; |
0cb951ac0133
Use the character substitution code from fntRender() / fntTextWidth()
jkeil
parents:
6218
diff
changeset
|
141 unsigned char c = (unsigned char)str[i]; |
0cb951ac0133
Use the character substitution code from fntRender() / fntTextWidth()
jkeil
parents:
6218
diff
changeset
|
142 if ( Fonts[id]->Fnt[c].sx == -1 ) c = ' '; |
0cb951ac0133
Use the character substitution code from fntRender() / fntTextWidth()
jkeil
parents:
6218
diff
changeset
|
143 h = Fonts[id]->Fnt[c].sy; |
6218 | 144 if ( h > max ) max=h; |
145 } | |
1693 | 146 return max; |
147 } | |
148 | |
8864 | 149 txSample * fntRender( wItem * item,int px,char * fmt,... ) |
1693 | 150 { |
8883 | 151 txSample * tmp = NULL; |
152 va_list ap; | |
153 unsigned char p[512]; | |
154 unsigned int c; | |
155 int i, dx = 0, s, tw, fbw, iw, id, ofs; | |
156 int x,y,fh,fw,fyc,yc; | |
157 uint32_t * ibuf; | |
158 uint32_t * obuf; | |
8864 | 159 |
160 va_start( ap,fmt ); | |
161 vsnprintf( p,512,fmt,ap ); | |
162 va_end( ap ); | |
163 | |
8883 | 164 iw=item->width; |
165 id=item->fontid; | |
166 | |
8864 | 167 if ( ( !item )|| |
8883 | 168 ( !Fonts[id] )|| |
8864 | 169 ( !p[0] )|| |
8883 | 170 ( !fntTextWidth( id,p ) ) ) return NULL; |
8864 | 171 |
8883 | 172 tw=fntTextWidth( id,p ); |
173 fbw=Fonts[id]->Bitmap.Width; | |
8864 | 174 |
175 if ( item->Bitmap.Image == NULL ) | |
176 { | |
8883 | 177 item->Bitmap.Height=item->height=fntTextHeight( id,p ); |
9625 | 178 item->Bitmap.Width=item->width=iw; |
8883 | 179 item->Bitmap.ImageSize=item->height * iw * 4; |
8978 | 180 if ( !item->Bitmap.ImageSize ) return NULL; |
8864 | 181 item->Bitmap.BPP=32; |
182 item->Bitmap.Image=malloc( item->Bitmap.ImageSize ); | |
183 } | |
184 | |
185 obuf=(uint32_t *)item->Bitmap.Image; | |
8883 | 186 ibuf=(uint32_t *)Fonts[id]->Bitmap.Image; |
8864 | 187 |
188 for ( i=0;i < item->Bitmap.ImageSize / 4;i++ ) obuf[i]=0xff00ff; | |
189 | |
8883 | 190 if ( tw <= iw ) |
8864 | 191 { |
192 switch ( item->align ) | |
193 { | |
194 default: | |
195 case fntAlignLeft: dx=0; break; | |
8883 | 196 case fntAlignCenter: dx=( iw - fntTextWidth( id,p ) ) / 2; break; |
197 case fntAlignRight: dx=iw - fntTextWidth( id,p ); break; | |
8864 | 198 } |
199 | |
200 } else dx+=px; | |
201 | |
8883 | 202 ofs=dx; |
8864 | 203 |
4818
3473ca9ef158
new gui interface, and gtk moved into mplayer process. fork ... bleh :)
pontscho
parents:
1907
diff
changeset
|
204 for ( i=0;i < (int)strlen( p );i++ ) |
1693 | 205 { |
8883 | 206 c=(unsigned int)p[i]; |
207 fw=Fonts[id]->Fnt[c].sx; | |
8864 | 208 |
8883 | 209 if ( fw == -1 ) { c=32; fw=Fonts[id]->Fnt[c].sx; } |
8864 | 210 |
8883 | 211 fh=Fonts[id]->Fnt[c].sy; |
212 fyc=Fonts[id]->Fnt[c].y * fbw + Fonts[id]->Fnt[c].x; | |
213 yc=dx; | |
214 | |
215 if ( dx >= 0 ) | |
216 for ( y=0;y < fh;y++ ) | |
217 { | |
218 for ( x=0; x < fw;x++ ) | |
219 if ( dx + x >= 0 && dx + x < iw ) obuf[yc + x]=ibuf[ fyc + x ]; | |
220 fyc+=fbw; | |
221 yc+=iw; | |
222 } | |
223 dx+=fw; | |
1693 | 224 } |
225 | |
8883 | 226 if ( ofs > 0 && tw > item->width ) |
1693 | 227 { |
8883 | 228 dx=ofs; |
229 for ( i=(int)strlen( p );i > 0;i-- ) | |
1693 | 230 { |
8883 | 231 c=(unsigned int)p[i]; |
232 fw=Fonts[id]->Fnt[c].sx; | |
233 | |
234 if ( fw == -1 ) { c=32; fw=Fonts[id]->Fnt[c].sx; } | |
235 | |
236 fh=Fonts[id]->Fnt[c].sy; | |
237 fyc=Fonts[id]->Fnt[c].y * fbw + Fonts[id]->Fnt[c].x; | |
238 | |
239 dx-=fw; yc=dx; | |
240 if ( dx >= 0 ) | |
241 for ( y=0;y < fh;y++ ) | |
242 { | |
243 for ( x=fw - 1;x >= 0;x-- ) | |
244 if ( dx + x >= 0 && dx + x < iw ) obuf[yc + x]=ibuf[fyc + x]; | |
245 fyc+=fbw; | |
246 yc+=iw; | |
247 } | |
1693 | 248 } |
8883 | 249 } |
1693 | 250 |
8883 | 251 return &item->Bitmap; |
1693 | 252 } |