Mercurial > mplayer.hg
annotate Gui/skin/font.c @ 7092:8e9607c5897e
- warning fixes from Dominik Mierzejewski <dominik@rangers.eu.org>
- wsXDNDProcessSelection return Truae fix
- add url list saving support from Morten Volden <mvolden@tdcadsl.dk>
- fix bug's in this patches
- fix some memleak and bug
author | pontscho |
---|---|
date | Mon, 26 Aug 2002 22:20:58 +0000 |
parents | 8cfddba867b4 |
children | 0cb951ac0133 |
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++ ) | |
122 size+=( Fonts[id]->Fnt[ (unsigned char)str[i] ].sx == -1? Fonts[id]->Fnt[ 32 ].sx : Fonts[id]->Fnt[ (unsigned char)str[i] ].sx ); | |
1693 | 123 return size; |
124 } | |
125 | |
126 int fntTextHeight( int id,char * str ) | |
127 { | |
128 int max = 0,i; | |
6218 | 129 |
130 if ( ( !Fonts[id] )||( !str[0] ) ) return 0; | |
131 | |
4818
3473ca9ef158
new gui interface, and gtk moved into mplayer process. fork ... bleh :)
pontscho
parents:
1907
diff
changeset
|
132 for ( i=0;i < (int)strlen( str );i++ ) |
6218 | 133 { |
134 int h = Fonts[id]->Fnt[ (unsigned char)str[i] ].sy; | |
135 if ( h > max ) max=h; | |
136 } | |
1693 | 137 return max; |
138 } | |
139 | |
140 txSample * fntRender( int id,int px,int sx,char * fmt,... ) | |
141 { | |
142 txSample * tmp = NULL; | |
4848
ad868aae2a5c
fix playtree bug. but ... i dont' see this ... bazmeg
pontscho
parents:
4818
diff
changeset
|
143 txSample tmp2; |
1693 | 144 char p[512]; |
145 va_list ap; | |
6159
dcf195b784bf
applied 64bit patch from Ulrich Hecht <uli@suse.de>
pontscho
parents:
6145
diff
changeset
|
146 uint32_t * ibuf; |
dcf195b784bf
applied 64bit patch from Ulrich Hecht <uli@suse.de>
pontscho
parents:
6145
diff
changeset
|
147 uint32_t * obuf; |
1693 | 148 int i,x,y; |
149 int oy = 0, ox = 0, dx = 0; | |
150 | |
151 va_start( ap,fmt ); | |
152 vsnprintf( p,512,fmt,ap ); | |
153 va_end( ap ); | |
154 | |
155 if ( ( !Fonts[id] )|| | |
156 ( !strlen( p ) )|| | |
157 ( !fntTextWidth( id,p ) )|| | |
158 ( (tmp=malloc( sizeof( txSample ) )) == NULL ) ) return NULL; | |
6218 | 159 |
1693 | 160 tmp->Width=fntTextWidth( id,p ); |
161 tmp->Height=fntTextHeight( id,p ); | |
162 tmp->BPP=32; | |
163 tmp->ImageSize=tmp->Width * tmp->Height * 4; | |
164 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
|
165 obuf=(uint32_t *)tmp->Image; |
dcf195b784bf
applied 64bit patch from Ulrich Hecht <uli@suse.de>
pontscho
parents:
6145
diff
changeset
|
166 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
|
167 for ( i=0;i < (int)strlen( p );i++ ) |
1693 | 168 { |
6218 | 169 unsigned int c = (unsigned char)p[i]; |
170 if ( Fonts[id]->Fnt[c].sx == -1 ) c=32; | |
1693 | 171 for ( oy=0,y=Fonts[id]->Fnt[c].y;y < Fonts[id]->Fnt[c].y + Fonts[id]->Fnt[c].sy; y++,oy++ ) |
6218 | 172 for ( ox=0,x=Fonts[id]->Fnt[c].x;x < Fonts[id]->Fnt[c].x + Fonts[id]->Fnt[c].sx; x++,ox++ ) |
173 obuf[ oy * tmp->Width + dx + ox ]=ibuf[ y * Fonts[id]->Bitmap.Width + x ]; | |
1693 | 174 dx+=Fonts[id]->Fnt[c].sx; |
175 } | |
176 | |
177 if ( ( sx > 0 )&&( sx < tmp->Width ) ) | |
178 { | |
179 tmp2.ImageSize=sx * tmp->Height * 4; | |
180 if ( ( tmp2.Image=malloc( tmp2.ImageSize ) ) == NULL ) { free( tmp->Image ); return NULL; } | |
181 | |
6159
dcf195b784bf
applied 64bit patch from Ulrich Hecht <uli@suse.de>
pontscho
parents:
6145
diff
changeset
|
182 obuf=(uint32_t *)tmp->Image; |
dcf195b784bf
applied 64bit patch from Ulrich Hecht <uli@suse.de>
pontscho
parents:
6145
diff
changeset
|
183 ibuf=(uint32_t *)tmp2.Image; |
5919 | 184 oy=0; |
1693 | 185 |
186 for ( y=0;y < tmp->Height;y++ ) | |
187 { | |
188 ox=px; | |
5919 | 189 dx=y * tmp->Width; |
1693 | 190 for ( x=0;x < sx;x++ ) |
191 { | |
192 ibuf[oy++]=obuf[dx + ox++]; | |
193 if ( ox >= tmp->Width ) ox=0; | |
194 } | |
195 } | |
196 | |
197 free( tmp->Image ); tmp->Width=sx; tmp->ImageSize=tmp2.ImageSize; tmp->Image=tmp2.Image; | |
198 } | |
199 | |
200 return tmp; | |
201 } |