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