annotate Gui/skin/font.c @ 5817:341e246ec91d

fix warning
author arpi
date Wed, 24 Apr 2002 21:16:27 +0000
parents ad868aae2a5c
children 60cf2bca993f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1693
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
1
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
2 #include <stdlib.h>
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
3 #include <stdio.h>
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
4 #include <stdarg.h>
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
5 #include <string.h>
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
6
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
7 #include "skin.h"
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
8 #include "font.h"
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
9 #include "cut.h"
4818
3473ca9ef158 new gui interface, and gtk moved into mplayer process. fork ... bleh :)
pontscho
parents: 1907
diff changeset
10 #include "../../mp_msg.h"
1693
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
11
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
12 int items;
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
13
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
14 bmpFont * Fonts[25] = { 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 };
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
15
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
16 int fntAddNewFont( char * name )
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
17 {
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
18 int id;
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
19 for( id=0;id<25;id++ ) if ( !Fonts[id] ) break;
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
20 if ( ( Fonts[id]=malloc( sizeof( bmpFont ) ) ) == NULL ) return -1;
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
21 strcpy( Fonts[id]->name,name );
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
22 memset( Fonts[id]->Fnt,-1,256 * sizeof( fntChar ) );
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
23 return id;
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
24 }
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
25
1829
a4156c8cdd57 add font free func.
pontscho
parents: 1693
diff changeset
26 void fntFreeFont( void )
1693
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
27 {
1829
a4156c8cdd57 add font free func.
pontscho
parents: 1693
diff changeset
28 int i;
a4156c8cdd57 add font free func.
pontscho
parents: 1693
diff changeset
29 for( i=0;i<25;i++ )
a4156c8cdd57 add font free func.
pontscho
parents: 1693
diff changeset
30 {
a4156c8cdd57 add font free func.
pontscho
parents: 1693
diff changeset
31 if ( Fonts[i] )
a4156c8cdd57 add font free func.
pontscho
parents: 1693
diff changeset
32 {
a4156c8cdd57 add font free func.
pontscho
parents: 1693
diff changeset
33 if ( Fonts[i]->Bitmap.Image ) free( Fonts[i]->Bitmap.Image );
a4156c8cdd57 add font free func.
pontscho
parents: 1693
diff changeset
34 free( Fonts[i] );
a4156c8cdd57 add font free func.
pontscho
parents: 1693
diff changeset
35 Fonts[i]=NULL;
a4156c8cdd57 add font free func.
pontscho
parents: 1693
diff changeset
36 }
a4156c8cdd57 add font free func.
pontscho
parents: 1693
diff changeset
37 }
1693
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
38 }
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
39
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
40 int fntRead( char * path,char * fname,int id )
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
41 {
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
42 FILE * f;
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
43 unsigned char tmp[512];
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
44 unsigned char * ptmp;
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
45 unsigned char command[32];
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
46 unsigned char param[256];
4818
3473ca9ef158 new gui interface, and gtk moved into mplayer process. fork ... bleh :)
pontscho
parents: 1907
diff changeset
47 int c,linenumber = 0;
1693
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
48
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
49 strcpy( tmp,path ); strcat( tmp,fname ); strcat( tmp,".fnt" );
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
50 if ( ( f=fopen( tmp,"rt" ) ) == NULL ) return -1;
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
51 while ( !feof( f ) )
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
52 {
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
53 fgets( tmp,255,f ); linenumber++;
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
54
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
55 c=tmp[ strlen( tmp ) - 1 ]; if ( ( c == '\n' )||( c == '\r' ) ) tmp[ strlen( tmp ) - 1 ]=0;
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
56 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
57 for ( c=0;c < (int)strlen( tmp );c++ )
1693
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
58 if ( tmp[c] == ';' )
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
59 {
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
60 tmp[c]=0;
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
61 break;
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
62 }
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
63 if ( strlen( tmp ) == 0 ) continue;
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
64 ptmp=strdelspacesbeforecommand( tmp );
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
65 if ( strlen( ptmp ) == 0 ) continue;
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
66 ptmp=strswap( ptmp,'\t',' ' );
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
67 ptmp=strdelspaces( ptmp );
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
68 cutItem( ptmp,command,'=',0 ); cutItem( ptmp,param,'=',1 );
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
69 if ( command[0] == '"' )
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
70 {
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
71 int i;
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
72 cutItem( command,command,'"',1 );
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
73 i=(int)command[0];
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
74 cutItem( param,tmp,',',0 ); Fonts[id]->Fnt[i].x=atoi( tmp );
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
75 cutItem( param,tmp,',',1 ); Fonts[id]->Fnt[i].y=atoi( tmp );
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
76 cutItem( param,tmp,',',2 ); Fonts[id]->Fnt[i].sx=atoi( tmp );
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
77 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
78 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
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
79 }
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
80 else
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
81 {
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
82 if ( !strcmp( command,"image" ) )
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
83 {
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
84 strcpy( tmp,path ); strcat( tmp,param );
4818
3473ca9ef158 new gui interface, and gtk moved into mplayer process. fork ... bleh :)
pontscho
parents: 1907
diff changeset
85 mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"[font] font imagefile: %s\n",tmp );
1693
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
86 if ( skinBPRead( tmp,&Fonts[id]->Bitmap ) ) return -2;
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
87 }
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
88 }
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
89 }
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
90 return 0;
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
91 }
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
92
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
93 int fntFindID( char * name )
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
94 {
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
95 int i;
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
96 for ( i=0;i < 25;i++ )
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
97 if ( Fonts[i] )
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
98 if ( !strcmp( name,Fonts[i]->name ) ) return i;
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
99 return -1;
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
100 }
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
101
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
102 int fntTextWidth( int id,char * str )
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
103 {
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
104 int size = 0;
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
105 int i;
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
106 if ( !Fonts[id] ) return 0;
4818
3473ca9ef158 new gui interface, and gtk moved into mplayer process. fork ... bleh :)
pontscho
parents: 1907
diff changeset
107 for ( i=0;i < (int)strlen( str );i++ )
1693
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
108 if ( Fonts[id]->Fnt[ (int)str[i] ].sx != -1 ) size+=Fonts[id]->Fnt[ (int)str[i] ].sx;
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
109 return size;
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
110 }
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
111
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
112 int fntTextHeight( int id,char * str )
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
113 {
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
114 int max = 0,i;
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
115 if ( !Fonts[id] ) return 0;
4818
3473ca9ef158 new gui interface, and gtk moved into mplayer process. fork ... bleh :)
pontscho
parents: 1907
diff changeset
116 for ( i=0;i < (int)strlen( str );i++ )
1693
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
117 if ( Fonts[id]->Fnt[ (int)str[i] ].sy > max ) max=Fonts[id]->Fnt[ (int)str[i] ].sy;
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
118 return max;
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
119 }
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
120
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
121 txSample * fntRender( int id,int px,int sx,char * fmt,... )
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
122 {
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
123 txSample * tmp = NULL;
4848
ad868aae2a5c fix playtree bug. but ... i dont' see this ... bazmeg
pontscho
parents: 4818
diff changeset
124 txSample tmp2;
1693
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
125 char p[512];
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
126 va_list ap;
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
127 unsigned long * ibuf;
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
128 unsigned long * obuf;
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
129 int i,x,y;
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
130 int oy = 0, ox = 0, dx = 0;
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
131
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
132 va_start( ap,fmt );
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
133 vsnprintf( p,512,fmt,ap );
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
134 va_end( ap );
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
135
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
136 if ( ( !Fonts[id] )||
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
137 ( !strlen( p ) )||
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
138 ( !fntTextWidth( id,p ) )||
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
139 ( (tmp=malloc( sizeof( txSample ) )) == NULL ) ) return NULL;
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
140
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
141 tmp->Width=fntTextWidth( id,p );
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
142 tmp->Height=fntTextHeight( id,p );
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
143 tmp->BPP=32;
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
144 tmp->ImageSize=tmp->Width * tmp->Height * 4;
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
145 if ( ( tmp->Image=malloc( tmp->ImageSize ) ) == NULL ) return NULL;
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
146
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
147 obuf=(unsigned long *)tmp->Image;
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
148 ibuf=(unsigned long *)Fonts[id]->Bitmap.Image;
4818
3473ca9ef158 new gui interface, and gtk moved into mplayer process. fork ... bleh :)
pontscho
parents: 1907
diff changeset
149 for ( i=0;i < (int)strlen( p );i++ )
1693
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
150 {
4848
ad868aae2a5c fix playtree bug. but ... i dont' see this ... bazmeg
pontscho
parents: 4818
diff changeset
151 char c = p[i];
1693
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
152 if ( Fonts[id]->Fnt[c].x == -1 ) c=32;
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
153 for ( oy=0,y=Fonts[id]->Fnt[c].y;y < Fonts[id]->Fnt[c].y + Fonts[id]->Fnt[c].sy; y++,oy++ )
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
154 for ( ox=0,x=Fonts[id]->Fnt[c].x;x < Fonts[id]->Fnt[c].x + Fonts[id]->Fnt[c].sx; x++,ox++ )
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
155 {
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
156 obuf[ oy * tmp->Width + dx + ox ]=ibuf[ y * Fonts[id]->Bitmap.Width + x ];
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
157 }
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
158 dx+=Fonts[id]->Fnt[c].sx;
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
159 }
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
160
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
161 if ( ( sx > 0 )&&( sx < tmp->Width ) )
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
162 {
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
163 tmp2.ImageSize=sx * tmp->Height * 4;
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
164 if ( ( tmp2.Image=malloc( tmp2.ImageSize ) ) == NULL ) { free( tmp->Image ); return NULL; }
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
165
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
166 obuf=(unsigned long *)tmp->Image;
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
167 ibuf=(unsigned long *)tmp2.Image;
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
168
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
169 for ( y=0;y < tmp->Height;y++ )
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
170 {
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
171 ox=px;
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
172 oy=y * sx; dx=y * tmp->Width;
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
173 for ( x=0;x < sx;x++ )
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
174 {
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
175 ibuf[oy++]=obuf[dx + ox++];
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
176 if ( ox >= tmp->Width ) ox=0;
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
177 }
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
178 }
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
179
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
180 free( tmp->Image ); tmp->Width=sx; tmp->ImageSize=tmp2.ImageSize; tmp->Image=tmp2.Image;
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
181 }
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
182
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
183 return tmp;
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
184 }