Mercurial > mplayer.hg
changeset 1591:86a192179276
draw speedups, cut text if too many lines
author | atlka |
---|---|
date | Mon, 20 Aug 2001 09:14:28 +0000 |
parents | e49685127514 |
children | 80cbe17e0f58 |
files | libvo/sub.c |
diffstat | 1 files changed, 51 insertions(+), 56 deletions(-) [+] |
line wrap: on
line diff
--- a/libvo/sub.c Mon Aug 20 09:05:12 2001 +0000 +++ b/libvo/sub.c Mon Aug 20 09:14:28 2001 +0000 @@ -112,6 +112,7 @@ #define MAX_UCS 1600 #define MAX_UCSLINES 16 + inline static void vo_draw_text_sub(int dxs,int dys,void (*draw_alpha)(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride)){ static int utbl[MAX_UCS+1]; static int xtbl[MAX_UCSLINES]; @@ -120,37 +121,31 @@ static int memy; static int memdxs; static int memdys; + unsigned char *t; - int i; - int j; - int k; - int l; - int x; - int y; - - int c; + int c,i,j,l,x,y,font; int len; - int line; - int font; + int k,lastk; int lastStripPosition; - int xsize; - int lastxsize; - int lastk; + int xsize,lastxsize; + int h,lasth; if ((memsub!=vo_sub)||(memdxs!=dxs)||(memdys!=dys)){ + memsub=vo_sub; memdxs=dxs; - memdys=dys; - - memy=dys; + memdys=memy=dys; // too long lines divide into smaller ones - i=k=lines=y=0; l=vo_sub->lines; + i=k=lines=lasth=0; + h=vo_font->height; + xsize=-vo_font->charspace; + lastStripPosition=-1; + l=vo_sub->lines; + while (l--){ t=vo_sub->text[i++]; len=strlen(t)-1; - xsize=lastxsize=-vo_font->charspace; - lastStripPosition=-1; for (j=0;j<=len;j++){ if ((c=t[j])>=0x80){ @@ -166,50 +161,56 @@ } } if (k==MAX_UCS){ - utbl[k]=l=0; - break; - } else - utbl[k++]=c; + utbl[k]=l=0; break; + } + utbl[k++]=c; if (c==' '){ lastk=k; lastStripPosition=j; lastxsize=xsize; - } else if (!l && ((font=vo_font->font[c])>=0)){ - if (vo_font->pic_a[font]->h > y) - y=vo_font->pic_a[font]->h; + } else if ((font=vo_font->font[c])>=0){ + if (vo_font->pic_a[font]->h > h){ + h=vo_font->pic_a[font]->h; + } } xsize+=vo_font->width[c]+vo_font->charspace; - if (dxs<xsize && lastStripPosition>0){ - j=lastStripPosition; - k=lastk; - y=vo_font->height; - } else if (j==len){ - lastxsize=xsize; - } else - continue; + if (dxs<xsize){ + if (lastStripPosition>0){ + j=lastStripPosition; + xsize=lastxsize; + k=lastk; + } else { + xsize -=vo_font->width[c]+vo_font->charspace; // go back + k--; // cut line here + while (t[j] && t[j]!=' ') j++; // jump to the nearest space + } + } else if (j<len) + continue; + if (h>memy){ // out of the screen so end parsing + memy +=vo_font->height-lasth; // correct y position + l=0; break; + } utbl[k++]=0; - xtbl[lines++]=(dxs-lastxsize)/2; + xtbl[lines++]=(dxs-xsize)/2; if (lines==MAX_UCSLINES||k>MAX_UCS){ - l=0; - break; - } else if(l || j<len){ // not last line or there is no eol - y=0; - xsize=lastxsize=-vo_font->charspace; - memy -=vo_font->height; - } else - memy-=y; // according to max of vo_font->pic_a[font]->h - } // in last line + l=0; break; + } else if(l || j<len){ // not last line or not last char + lastStripPosition=-1; + xsize=-vo_font->charspace; + lasth=h; + h=vo_font->height; + } + memy -=h; // according to max of vo_font->pic_a[font]->h + } } } y = memy; - k=i=0; l=lines; + i=j=0; l=lines; while (l--){ - if (y>=0){ x= xtbl[i++]; - while ((c=utbl[k++])){ - if (x>=0 && x+vo_font->width[c]<=dxs) + while ((c=utbl[j++])){ if ((font=vo_font->font[c])>=0) draw_alpha(x,y, vo_font->width[c], @@ -217,18 +218,12 @@ vo_font->pic_b[font]->bmp+vo_font->start[c], vo_font->pic_a[font]->bmp+vo_font->start[c], vo_font->pic_a[font]->w); - x+=vo_font->width[c]+vo_font->charspace; + x+=vo_font->width[c]+vo_font->charspace; } - } else { - while (utbl[k++]) ; // skip lines with negative y value - i++; // seldom case but who knows ;-) - } - y+=vo_font->height; + y+=vo_font->height; } } - - static int draw_alpha_init_flag=0; extern void vo_draw_alpha_init();