Mercurial > mplayer.hg
annotate Gui/skin/font.c @ 7927:b1767137b278
added chanegs since pre9
author | arpi |
---|---|
date | Sat, 26 Oct 2002 16:25:32 +0000 |
parents | 0cb951ac0133 |
children | b8c271750450 |
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 |
8 #include "skin.h" | |
9 #include "font.h" | |
10 #include "cut.h" | |
4818
3473ca9ef158
new gui interface, and gtk moved into mplayer process. fork ... bleh :)
pontscho
parents:
1907
diff
changeset
|
11 #include "../../mp_msg.h" |
1693 | 12 |
13 int items; | |
14 | |
6218 | 15 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 | 16 |
17 int fntAddNewFont( char * name ) | |
18 { | |
19 int id; | |
6218 | 20 int i; |
21 | |
22 for( id=0;id<26;id++ ) | |
23 if ( !Fonts[id] ) break; | |
24 | |
25 if ( id == 25 ) return -2; | |
26 | |
27 if ( ( Fonts[id]=calloc( 1,sizeof( bmpFont ) ) ) == NULL ) return -1; | |
28 | |
1693 | 29 strcpy( Fonts[id]->name,name ); |
6218 | 30 for ( i=0;i<256;i++ ) |
31 Fonts[id]->Fnt[i].x=Fonts[id]->Fnt[i].y=Fonts[id]->Fnt[i].sx=Fonts[id]->Fnt[i].sy=-1; | |
32 | |
1693 | 33 return id; |
34 } | |
35 | |
1829 | 36 void fntFreeFont( void ) |
1693 | 37 { |
1829 | 38 int i; |
6218 | 39 for( i=0;i < 25;i++ ) |
1829 | 40 { |
41 if ( Fonts[i] ) | |
42 { | |
43 if ( Fonts[i]->Bitmap.Image ) free( Fonts[i]->Bitmap.Image ); | |
44 free( Fonts[i] ); | |
45 Fonts[i]=NULL; | |
46 } | |
47 } | |
1693 | 48 } |
49 | |
6218 | 50 int fntRead( char * path,char * fname ) |
1693 | 51 { |
52 FILE * f; | |
53 unsigned char tmp[512]; | |
54 unsigned char * ptmp; | |
55 unsigned char command[32]; | |
56 unsigned char param[256]; | |
4818
3473ca9ef158
new gui interface, and gtk moved into mplayer process. fork ... bleh :)
pontscho
parents:
1907
diff
changeset
|
57 int c,linenumber = 0; |
6218 | 58 int id = fntAddNewFont( fname ); |
59 | |
60 if ( id < 0 ) return id; | |
1693 | 61 |
62 strcpy( tmp,path ); strcat( tmp,fname ); strcat( tmp,".fnt" ); | |
6218 | 63 if ( ( f=fopen( tmp,"rt" ) ) == NULL ) |
64 { free( Fonts[id] ); return -3; } | |
65 | |
1693 | 66 while ( !feof( f ) ) |
67 { | |
68 fgets( tmp,255,f ); linenumber++; | |
69 | |
70 c=tmp[ strlen( tmp ) - 1 ]; if ( ( c == '\n' )||( c == '\r' ) ) tmp[ strlen( tmp ) - 1 ]=0; | |
71 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
|
72 for ( c=0;c < (int)strlen( tmp );c++ ) |
6218 | 73 if ( tmp[c] == ';' ) { tmp[c]=0; break; } |
74 if ( !tmp[0] ) continue; | |
1693 | 75 ptmp=strdelspacesbeforecommand( tmp ); |
6218 | 76 if ( !tmp[0] ) continue; |
1693 | 77 ptmp=strswap( ptmp,'\t',' ' ); |
78 ptmp=strdelspaces( ptmp ); | |
79 cutItem( ptmp,command,'=',0 ); cutItem( ptmp,param,'=',1 ); | |
80 if ( command[0] == '"' ) | |
81 { | |
82 int i; | |
83 cutItem( command,command,'"',1 ); | |
84 i=(int)command[0]; | |
85 cutItem( param,tmp,',',0 ); Fonts[id]->Fnt[i].x=atoi( tmp ); | |
86 cutItem( param,tmp,',',1 ); Fonts[id]->Fnt[i].y=atoi( tmp ); | |
87 cutItem( param,tmp,',',2 ); Fonts[id]->Fnt[i].sx=atoi( tmp ); | |
88 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
|
89 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 | 90 } |
91 else | |
92 { | |
93 if ( !strcmp( command,"image" ) ) | |
94 { | |
95 strcpy( tmp,path ); strcat( tmp,param ); | |
4818
3473ca9ef158
new gui interface, and gtk moved into mplayer process. fork ... bleh :)
pontscho
parents:
1907
diff
changeset
|
96 mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"[font] font imagefile: %s\n",tmp ); |
6218 | 97 if ( skinBPRead( tmp,&Fonts[id]->Bitmap ) ) return -4; |
1693 | 98 } |
99 } | |
6218 | 100 } |
101 | |
1693 | 102 return 0; |
103 } | |
104 | |
105 int fntFindID( char * name ) | |
106 { | |
107 int i; | |
108 for ( i=0;i < 25;i++ ) | |
6218 | 109 if ( Fonts[i] ) |
110 if ( !strcmp( name,Fonts[i]->name ) ) return i; | |
1693 | 111 return -1; |
112 } | |
113 | |
114 int fntTextWidth( int id,char * str ) | |
115 { | |
116 int size = 0; | |
117 int i; | |
6218 | 118 |
119 if ( ( !Fonts[id] )||( !str[0] ) ) return 0; | |
120 | |
121 for ( i=0;i < (unsigned int)strlen( str );i++ ) | |
7353
0cb951ac0133
Use the character substitution code from fntRender() / fntTextWidth()
jkeil
parents:
6218
diff
changeset
|
122 { |
0cb951ac0133
Use the character substitution code from fntRender() / fntTextWidth()
jkeil
parents:
6218
diff
changeset
|
123 unsigned char c = (unsigned char)str[i]; |
0cb951ac0133
Use the character substitution code from fntRender() / fntTextWidth()
jkeil
parents:
6218
diff
changeset
|
124 if ( Fonts[id]->Fnt[c].sx == -1 ) c = ' '; |
0cb951ac0133
Use the character substitution code from fntRender() / fntTextWidth()
jkeil
parents:
6218
diff
changeset
|
125 size+= Fonts[id]->Fnt[ c ].sx; |
0cb951ac0133
Use the character substitution code from fntRender() / fntTextWidth()
jkeil
parents:
6218
diff
changeset
|
126 } |
1693 | 127 return size; |
128 } | |
129 | |
130 int fntTextHeight( int id,char * str ) | |
131 { | |
132 int max = 0,i; | |
6218 | 133 |
134 if ( ( !Fonts[id] )||( !str[0] ) ) return 0; | |
135 | |
4818
3473ca9ef158
new gui interface, and gtk moved into mplayer process. fork ... bleh :)
pontscho
parents:
1907
diff
changeset
|
136 for ( i=0;i < (int)strlen( str );i++ ) |
6218 | 137 { |
7353
0cb951ac0133
Use the character substitution code from fntRender() / fntTextWidth()
jkeil
parents:
6218
diff
changeset
|
138 int h; |
0cb951ac0133
Use the character substitution code from fntRender() / fntTextWidth()
jkeil
parents:
6218
diff
changeset
|
139 unsigned char c = (unsigned char)str[i]; |
0cb951ac0133
Use the character substitution code from fntRender() / fntTextWidth()
jkeil
parents:
6218
diff
changeset
|
140 if ( Fonts[id]->Fnt[c].sx == -1 ) c = ' '; |
0cb951ac0133
Use the character substitution code from fntRender() / fntTextWidth()
jkeil
parents:
6218
diff
changeset
|
141 h = Fonts[id]->Fnt[c].sy; |
6218 | 142 if ( h > max ) max=h; |
143 } | |
1693 | 144 return max; |
145 } | |
146 | |
147 txSample * fntRender( int id,int px,int sx,char * fmt,... ) | |
148 { | |
149 txSample * tmp = NULL; | |
4848
ad868aae2a5c
fix playtree bug. but ... i dont' see this ... bazmeg
pontscho
parents:
4818
diff
changeset
|
150 txSample tmp2; |
1693 | 151 char p[512]; |
152 va_list ap; | |
6159
dcf195b784bf
applied 64bit patch from Ulrich Hecht <uli@suse.de>
pontscho
parents:
6145
diff
changeset
|
153 uint32_t * ibuf; |
dcf195b784bf
applied 64bit patch from Ulrich Hecht <uli@suse.de>
pontscho
parents:
6145
diff
changeset
|
154 uint32_t * obuf; |
1693 | 155 int i,x,y; |
156 int oy = 0, ox = 0, dx = 0; | |
157 | |
158 va_start( ap,fmt ); | |
159 vsnprintf( p,512,fmt,ap ); | |
160 va_end( ap ); | |
161 | |
162 if ( ( !Fonts[id] )|| | |
163 ( !strlen( p ) )|| | |
164 ( !fntTextWidth( id,p ) )|| | |
165 ( (tmp=malloc( sizeof( txSample ) )) == NULL ) ) return NULL; | |
6218 | 166 |
1693 | 167 tmp->Width=fntTextWidth( id,p ); |
168 tmp->Height=fntTextHeight( id,p ); | |
169 tmp->BPP=32; | |
170 tmp->ImageSize=tmp->Width * tmp->Height * 4; | |
171 if ( ( tmp->Image=malloc( tmp->ImageSize ) ) == NULL ) return NULL; | |
6159
dcf195b784bf
applied 64bit patch from Ulrich Hecht <uli@suse.de>
pontscho
parents:
6145
diff
changeset
|
172 obuf=(uint32_t *)tmp->Image; |
dcf195b784bf
applied 64bit patch from Ulrich Hecht <uli@suse.de>
pontscho
parents:
6145
diff
changeset
|
173 ibuf=(uint32_t *)Fonts[id]->Bitmap.Image; |
4818
3473ca9ef158
new gui interface, and gtk moved into mplayer process. fork ... bleh :)
pontscho
parents:
1907
diff
changeset
|
174 for ( i=0;i < (int)strlen( p );i++ ) |
1693 | 175 { |
6218 | 176 unsigned int c = (unsigned char)p[i]; |
177 if ( Fonts[id]->Fnt[c].sx == -1 ) c=32; | |
1693 | 178 for ( oy=0,y=Fonts[id]->Fnt[c].y;y < Fonts[id]->Fnt[c].y + Fonts[id]->Fnt[c].sy; y++,oy++ ) |
6218 | 179 for ( ox=0,x=Fonts[id]->Fnt[c].x;x < Fonts[id]->Fnt[c].x + Fonts[id]->Fnt[c].sx; x++,ox++ ) |
180 obuf[ oy * tmp->Width + dx + ox ]=ibuf[ y * Fonts[id]->Bitmap.Width + x ]; | |
1693 | 181 dx+=Fonts[id]->Fnt[c].sx; |
182 } | |
183 | |
184 if ( ( sx > 0 )&&( sx < tmp->Width ) ) | |
185 { | |
186 tmp2.ImageSize=sx * tmp->Height * 4; | |
187 if ( ( tmp2.Image=malloc( tmp2.ImageSize ) ) == NULL ) { free( tmp->Image ); return NULL; } | |
188 | |
6159
dcf195b784bf
applied 64bit patch from Ulrich Hecht <uli@suse.de>
pontscho
parents:
6145
diff
changeset
|
189 obuf=(uint32_t *)tmp->Image; |
dcf195b784bf
applied 64bit patch from Ulrich Hecht <uli@suse.de>
pontscho
parents:
6145
diff
changeset
|
190 ibuf=(uint32_t *)tmp2.Image; |
5919 | 191 oy=0; |
1693 | 192 |
193 for ( y=0;y < tmp->Height;y++ ) | |
194 { | |
195 ox=px; | |
5919 | 196 dx=y * tmp->Width; |
1693 | 197 for ( x=0;x < sx;x++ ) |
198 { | |
199 ibuf[oy++]=obuf[dx + ox++]; | |
200 if ( ox >= tmp->Width ) ox=0; | |
201 } | |
202 } | |
203 | |
204 free( tmp->Image ); tmp->Width=sx; tmp->ImageSize=tmp2.ImageSize; tmp->Image=tmp2.Image; | |
205 } | |
206 | |
207 return tmp; | |
208 } |