Mercurial > mplayer.hg
annotate Gui/skin/font.c @ 9913:88fe89b46786
Add suffix support to the object list type.
So now -vf-clr destroy the list -vf-add filer1=blah,filter append
these 2 filters, -vf-pre ... will 'prepend' them.
Finnaly -vf-del 2,3,-1 will delete the filters at at given indexs
It start from 0, negative number start from the end of the list
(so -1 is the last one).
author | albeu |
---|---|
date | Sat, 12 Apr 2003 13:45:43 +0000 |
parents | bc24dd70c6e2 |
children | 9a495bdc3a1e |
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 | |
1693 | 30 strcpy( Fonts[id]->name,name ); |
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 |
63 strcpy( tmp,path ); strcat( tmp,fname ); strcat( tmp,".fnt" ); | |
6218 | 64 if ( ( f=fopen( tmp,"rt" ) ) == NULL ) |
65 { free( Fonts[id] ); return -3; } | |
66 | |
1693 | 67 while ( !feof( f ) ) |
68 { | |
69 fgets( tmp,255,f ); linenumber++; | |
70 | |
71 c=tmp[ strlen( tmp ) - 1 ]; if ( ( c == '\n' )||( c == '\r' ) ) tmp[ strlen( tmp ) - 1 ]=0; | |
72 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
|
73 for ( c=0;c < (int)strlen( tmp );c++ ) |
6218 | 74 if ( tmp[c] == ';' ) { tmp[c]=0; break; } |
75 if ( !tmp[0] ) continue; | |
8973 | 76 ptmp=trimleft( tmp ); |
6218 | 77 if ( !tmp[0] ) continue; |
1693 | 78 ptmp=strswap( ptmp,'\t',' ' ); |
8973 | 79 ptmp=trim( ptmp ); |
1693 | 80 cutItem( ptmp,command,'=',0 ); cutItem( ptmp,param,'=',1 ); |
81 if ( command[0] == '"' ) | |
82 { | |
83 int i; | |
84 cutItem( command,command,'"',1 ); | |
85 i=(int)command[0]; | |
86 cutItem( param,tmp,',',0 ); Fonts[id]->Fnt[i].x=atoi( tmp ); | |
87 cutItem( param,tmp,',',1 ); Fonts[id]->Fnt[i].y=atoi( tmp ); | |
88 cutItem( param,tmp,',',2 ); Fonts[id]->Fnt[i].sx=atoi( tmp ); | |
89 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
|
90 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 | 91 } |
92 else | |
93 { | |
94 if ( !strcmp( command,"image" ) ) | |
95 { | |
96 strcpy( tmp,path ); strcat( tmp,param ); | |
4818
3473ca9ef158
new gui interface, and gtk moved into mplayer process. fork ... bleh :)
pontscho
parents:
1907
diff
changeset
|
97 mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"[font] font imagefile: %s\n",tmp ); |
6218 | 98 if ( skinBPRead( tmp,&Fonts[id]->Bitmap ) ) return -4; |
1693 | 99 } |
100 } | |
6218 | 101 } |
102 | |
1693 | 103 return 0; |
104 } | |
105 | |
106 int fntFindID( char * name ) | |
107 { | |
108 int i; | |
109 for ( i=0;i < 25;i++ ) | |
6218 | 110 if ( Fonts[i] ) |
111 if ( !strcmp( name,Fonts[i]->name ) ) return i; | |
1693 | 112 return -1; |
113 } | |
114 | |
115 int fntTextWidth( int id,char * str ) | |
116 { | |
117 int size = 0; | |
118 int i; | |
6218 | 119 |
120 if ( ( !Fonts[id] )||( !str[0] ) ) return 0; | |
121 | |
8864 | 122 for ( i=0;i < (int)strlen( str );i++ ) |
7353
0cb951ac0133
Use the character substitution code from fntRender() / fntTextWidth()
jkeil
parents:
6218
diff
changeset
|
123 { |
0cb951ac0133
Use the character substitution code from fntRender() / fntTextWidth()
jkeil
parents:
6218
diff
changeset
|
124 unsigned char c = (unsigned char)str[i]; |
0cb951ac0133
Use the character substitution code from fntRender() / fntTextWidth()
jkeil
parents:
6218
diff
changeset
|
125 if ( Fonts[id]->Fnt[c].sx == -1 ) c = ' '; |
0cb951ac0133
Use the character substitution code from fntRender() / fntTextWidth()
jkeil
parents:
6218
diff
changeset
|
126 size+= Fonts[id]->Fnt[ c ].sx; |
0cb951ac0133
Use the character substitution code from fntRender() / fntTextWidth()
jkeil
parents:
6218
diff
changeset
|
127 } |
1693 | 128 return size; |
129 } | |
130 | |
131 int fntTextHeight( int id,char * str ) | |
132 { | |
133 int max = 0,i; | |
6218 | 134 |
135 if ( ( !Fonts[id] )||( !str[0] ) ) return 0; | |
136 | |
4818
3473ca9ef158
new gui interface, and gtk moved into mplayer process. fork ... bleh :)
pontscho
parents:
1907
diff
changeset
|
137 for ( i=0;i < (int)strlen( str );i++ ) |
6218 | 138 { |
7353
0cb951ac0133
Use the character substitution code from fntRender() / fntTextWidth()
jkeil
parents:
6218
diff
changeset
|
139 int h; |
0cb951ac0133
Use the character substitution code from fntRender() / fntTextWidth()
jkeil
parents:
6218
diff
changeset
|
140 unsigned char c = (unsigned char)str[i]; |
0cb951ac0133
Use the character substitution code from fntRender() / fntTextWidth()
jkeil
parents:
6218
diff
changeset
|
141 if ( Fonts[id]->Fnt[c].sx == -1 ) c = ' '; |
0cb951ac0133
Use the character substitution code from fntRender() / fntTextWidth()
jkeil
parents:
6218
diff
changeset
|
142 h = Fonts[id]->Fnt[c].sy; |
6218 | 143 if ( h > max ) max=h; |
144 } | |
1693 | 145 return max; |
146 } | |
147 | |
8864 | 148 txSample * fntRender( wItem * item,int px,char * fmt,... ) |
1693 | 149 { |
8883 | 150 txSample * tmp = NULL; |
151 va_list ap; | |
152 unsigned char p[512]; | |
153 unsigned int c; | |
154 int i, dx = 0, s, tw, fbw, iw, id, ofs; | |
155 int x,y,fh,fw,fyc,yc; | |
156 uint32_t * ibuf; | |
157 uint32_t * obuf; | |
8864 | 158 |
159 va_start( ap,fmt ); | |
160 vsnprintf( p,512,fmt,ap ); | |
161 va_end( ap ); | |
162 | |
8883 | 163 iw=item->width; |
164 id=item->fontid; | |
165 | |
8864 | 166 if ( ( !item )|| |
8883 | 167 ( !Fonts[id] )|| |
8864 | 168 ( !p[0] )|| |
8883 | 169 ( !fntTextWidth( id,p ) ) ) return NULL; |
8864 | 170 |
8883 | 171 tw=fntTextWidth( id,p ); |
172 fbw=Fonts[id]->Bitmap.Width; | |
8864 | 173 |
174 if ( item->Bitmap.Image == NULL ) | |
175 { | |
8883 | 176 item->Bitmap.Height=item->height=fntTextHeight( id,p ); |
9625 | 177 item->Bitmap.Width=item->width=iw; |
8883 | 178 item->Bitmap.ImageSize=item->height * iw * 4; |
8978 | 179 if ( !item->Bitmap.ImageSize ) return NULL; |
8864 | 180 item->Bitmap.BPP=32; |
181 item->Bitmap.Image=malloc( item->Bitmap.ImageSize ); | |
182 } | |
183 | |
184 obuf=(uint32_t *)item->Bitmap.Image; | |
8883 | 185 ibuf=(uint32_t *)Fonts[id]->Bitmap.Image; |
8864 | 186 |
187 for ( i=0;i < item->Bitmap.ImageSize / 4;i++ ) obuf[i]=0xff00ff; | |
188 | |
8883 | 189 if ( tw <= iw ) |
8864 | 190 { |
191 switch ( item->align ) | |
192 { | |
193 default: | |
194 case fntAlignLeft: dx=0; break; | |
8883 | 195 case fntAlignCenter: dx=( iw - fntTextWidth( id,p ) ) / 2; break; |
196 case fntAlignRight: dx=iw - fntTextWidth( id,p ); break; | |
8864 | 197 } |
198 | |
199 } else dx+=px; | |
200 | |
8883 | 201 ofs=dx; |
8864 | 202 |
4818
3473ca9ef158
new gui interface, and gtk moved into mplayer process. fork ... bleh :)
pontscho
parents:
1907
diff
changeset
|
203 for ( i=0;i < (int)strlen( p );i++ ) |
1693 | 204 { |
8883 | 205 c=(unsigned int)p[i]; |
206 fw=Fonts[id]->Fnt[c].sx; | |
8864 | 207 |
8883 | 208 if ( fw == -1 ) { c=32; fw=Fonts[id]->Fnt[c].sx; } |
8864 | 209 |
8883 | 210 fh=Fonts[id]->Fnt[c].sy; |
211 fyc=Fonts[id]->Fnt[c].y * fbw + Fonts[id]->Fnt[c].x; | |
212 yc=dx; | |
213 | |
214 if ( dx >= 0 ) | |
215 for ( y=0;y < fh;y++ ) | |
216 { | |
217 for ( x=0; x < fw;x++ ) | |
218 if ( dx + x >= 0 && dx + x < iw ) obuf[yc + x]=ibuf[ fyc + x ]; | |
219 fyc+=fbw; | |
220 yc+=iw; | |
221 } | |
222 dx+=fw; | |
1693 | 223 } |
224 | |
8883 | 225 if ( ofs > 0 && tw > item->width ) |
1693 | 226 { |
8883 | 227 dx=ofs; |
228 for ( i=(int)strlen( p );i > 0;i-- ) | |
1693 | 229 { |
8883 | 230 c=(unsigned int)p[i]; |
231 fw=Fonts[id]->Fnt[c].sx; | |
232 | |
233 if ( fw == -1 ) { c=32; fw=Fonts[id]->Fnt[c].sx; } | |
234 | |
235 fh=Fonts[id]->Fnt[c].sy; | |
236 fyc=Fonts[id]->Fnt[c].y * fbw + Fonts[id]->Fnt[c].x; | |
237 | |
238 dx-=fw; yc=dx; | |
239 if ( dx >= 0 ) | |
240 for ( y=0;y < fh;y++ ) | |
241 { | |
242 for ( x=fw - 1;x >= 0;x-- ) | |
243 if ( dx + x >= 0 && dx + x < iw ) obuf[yc + x]=ibuf[fyc + x]; | |
244 fyc+=fbw; | |
245 yc+=iw; | |
246 } | |
1693 | 247 } |
8883 | 248 } |
1693 | 249 |
8883 | 250 return &item->Bitmap; |
1693 | 251 } |