summaryrefslogtreecommitdiffstats
path: root/libvo/sub.c
blob: d64862f899b6295d3ace6bfd38942f7cebe9d2d4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82

//static int vo_font_loaded=-1;
font_desc_t* vo_font=NULL;

int vo_sub_lines=2;
unsigned char* vo_sub_text[8];

unsigned char* vo_osd_text="00:00:00";

void vo_draw_text(int dxs,int dys,void (*draw_alpha)(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride)){
    int i;
    int y;

    if(!vo_font) return; // no font

    if(vo_osd_text){
        int len=strlen(vo_osd_text);
        int j;
        int y=10;
        int x=20;

        for(j=0;j<len;j++){
          int c=vo_osd_text[j];
          int font=vo_font->font[c];
          if(font>=0)
            draw_alpha(x,y,
              vo_font->width[c],
              vo_font->pic_a[font]->h,
              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;
        }
        
    }

#if 1

    if(vo_sub_lines<=0) return; // no text
    y=dys-(1+vo_sub_lines)*vo_font->height;
    
    for(i=0;i<vo_sub_lines;i++){
        unsigned char* text="Hello World! HÛDEJÓ!"; //vo_sub_text[i];
        int len=strlen(text);
        int j;
        int xsize=-vo_font->charspace;
        int x=0;

        for(j=0;j<len;j++){
          int w=vo_font->width[text[j]];
          if(w>100) printf("gazvan: %d (%d=%c)\n",w,text[j],text[j]);
          xsize+=w+vo_font->charspace;
        }
        //printf("text width = %d\n",xsize);
        
        if(xsize>dxs) printf("Warning! SUB too wide!!! (%d>%d)\n",xsize,dxs);
        
        x=dxs/2-xsize/2;
        
        for(j=0;j<len;j++){
          int c=text[j];
          int font=vo_font->font[c];
          if(x>=0 && x+vo_font->width[c]<dxs)
          if(font>=0)
            draw_alpha(x,y,
              vo_font->width[c],
              vo_font->pic_a[font]->h,
              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;
        }

        y+=vo_font->height;
    }

#endif

}