mirror of
https://github.com/mpv-player/mpv
synced 2025-03-15 03:14:30 +01:00
better .smi support and display two-byte characters- patch by Sunjin Yang
git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@707 b3059339-0415-0410-9bf9-f77b7e298cf2
This commit is contained in:
parent
d087b3eb2a
commit
e3d4468a24
@ -174,7 +174,8 @@ while(fgets(sor,1020,f)){
|
|||||||
int chr=p[0][0];
|
int chr=p[0][0];
|
||||||
int start=atoi(p[1]);
|
int start=atoi(p[1]);
|
||||||
int end=atoi(p[2]);
|
int end=atoi(p[2]);
|
||||||
if(strlen(p[0])!=1) chr=strtol(p[0],NULL,0);
|
if(chr>=0x80) chr=(chr<<8)+p[0][1];
|
||||||
|
else if(strlen(p[0])!=1) chr=strtol(p[0],NULL,0);
|
||||||
if(end<start) {
|
if(end<start) {
|
||||||
printf("error in font desc: end<start for char '%c'\n",chr);
|
printf("error in font desc: end<start for char '%c'\n",chr);
|
||||||
} else {
|
} else {
|
||||||
|
@ -14,9 +14,9 @@ typedef struct {
|
|||||||
// char *fname_b;
|
// char *fname_b;
|
||||||
raw_file* pic_a[16];
|
raw_file* pic_a[16];
|
||||||
raw_file* pic_b[16];
|
raw_file* pic_b[16];
|
||||||
short font[512];
|
short font[65536];
|
||||||
short start[512];
|
short start[65536];
|
||||||
short width[512];
|
short width[65536];
|
||||||
} font_desc_t;
|
} font_desc_t;
|
||||||
|
|
||||||
raw_file* load_raw(char *name,int verbose);
|
raw_file* load_raw(char *name,int verbose);
|
||||||
|
11
libvo/sub.c
11
libvo/sub.c
@ -104,19 +104,22 @@ void vo_draw_text_sub(int dxs,int dys,void (*draw_alpha)(int x0,int y0, int w,in
|
|||||||
int x=0;
|
int x=0;
|
||||||
|
|
||||||
for(j=0;j<len;j++){
|
for(j=0;j<len;j++){
|
||||||
int w=vo_font->width[text[j]];
|
int c=text[j];
|
||||||
if(w>100) printf("gazvan: %d (%d=%c)\n",w,text[j],text[j]);
|
int w = vo_font->width[(c<0x80)?c:(c<<8)+text[++j]];
|
||||||
|
if(w>100) printf("gazvan: %d (%d=%c)\n",w,c,c);
|
||||||
xsize+=w+vo_font->charspace;
|
xsize+=w+vo_font->charspace;
|
||||||
}
|
}
|
||||||
//printf("text width = %d\n",xsize);
|
//printf("text width = %d\n",xsize);
|
||||||
|
|
||||||
if(xsize>dxs) printf("Warning! SUB too wide!!! (%d>%d)\n",xsize,dxs);
|
//if(xsize>dxs) printf("Warning! SUB too wide!!! (%d>%d)\n",xsize,dxs);
|
||||||
|
|
||||||
x=dxs/2-xsize/2;
|
x=dxs/2-xsize/2;
|
||||||
|
|
||||||
for(j=0;j<len;j++){
|
for(j=0;j<len;j++){
|
||||||
int c=text[j];
|
int c=text[j];
|
||||||
int font=vo_font->font[c];
|
int font;
|
||||||
|
if (c>=0x80) c=(c<<8)+text[++j];
|
||||||
|
font = vo_font->font[c];
|
||||||
if(x>=0 && x+vo_font->width[c]<dxs)
|
if(x>=0 && x+vo_font->width[c]<dxs)
|
||||||
if(font>=0)
|
if(font>=0)
|
||||||
draw_alpha(x,y,
|
draw_alpha(x,y,
|
||||||
|
110
subreader.c
110
subreader.c
@ -9,6 +9,7 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <ctype.h>
|
||||||
|
|
||||||
#include "subreader.h"
|
#include "subreader.h"
|
||||||
|
|
||||||
@ -27,47 +28,78 @@ int eol(char p) {
|
|||||||
return (p=='\r' || p=='\n' || p=='\0');
|
return (p=='\r' || p=='\n' || p=='\0');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline void trail_space(char *s) {
|
||||||
|
int i;
|
||||||
|
while (isspace(*s)) strcpy(s, s + 1);
|
||||||
|
i = strlen(s) - 1;
|
||||||
|
while (i > 0 && isspace(s[i])) s[i--] = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
subtitle *sub_read_line_sami(FILE *fd, subtitle *current) {
|
subtitle *sub_read_line_sami(FILE *fd, subtitle *current) {
|
||||||
char line[1001];
|
static char line[1001];
|
||||||
int i;
|
static char *s = NULL;
|
||||||
char *s, *p;
|
char text[1000], *p, *q;
|
||||||
|
int state;
|
||||||
|
|
||||||
current->start=0;
|
current->lines = current->start = current->end = 0;
|
||||||
do {
|
state = 0;
|
||||||
if (! (fgets (line, 1000, fd))) return 0;
|
|
||||||
s= strstr(line, "Start=");
|
/* read the first line */
|
||||||
if (s) {
|
if (!s)
|
||||||
sscanf (s, "Start=%d", ¤t->start);
|
if (!(s = fgets(line, 1000, fd))) return 0;
|
||||||
if (strstr (s, "<P><br>")) current->start=0;
|
|
||||||
}
|
|
||||||
} while ( !current->start );
|
|
||||||
|
|
||||||
if (! (fgets (line, 1000, fd))) return 0;
|
|
||||||
s=strstr (line, "<P>")+3;
|
|
||||||
|
|
||||||
i=0;
|
|
||||||
do {
|
do {
|
||||||
for (p=s; !eol(*p) && strncmp(p,"<br>",4); p++);
|
switch (state) {
|
||||||
if (p==s) {
|
|
||||||
s+=4;
|
case 0: /* find "START=" */
|
||||||
|
s = strstr (s, "Start=");
|
||||||
|
if (s) {
|
||||||
|
current->start = strtol (s + 6, &s, 0) / 10;
|
||||||
|
state = 1; continue;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 1: /* find "<P" */
|
||||||
|
if ((s = strstr (s, "<P"))) { s += 2; state = 2; continue; }
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 2: /* find ">" */
|
||||||
|
if ((s = strchr (s, '>'))) { s++; state = 3; p = text; continue; }
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 3: /* get all text until '<' appears */
|
||||||
|
if (*s == '\0') { break; }
|
||||||
|
else if (*s == '<') { state = 4; }
|
||||||
|
else if (!strncasecmp (s, " ", 6)) { *p++ = ' '; s += 6; }
|
||||||
|
else if (*s == '\r') { s++; }
|
||||||
|
else if (!strncasecmp (s, "<br>", 4) || *s == '\n') {
|
||||||
|
*p = '\0'; p = text; trail_space (text);
|
||||||
|
if (text[0] != '\0')
|
||||||
|
current->text[current->lines++] = strdup (text);
|
||||||
|
if (*s == '\n') s++; else s += 4;
|
||||||
|
}
|
||||||
|
else *p++ = *s++;
|
||||||
continue;
|
continue;
|
||||||
}
|
|
||||||
current->text[i]=(char *)malloc(p-s+1);
|
|
||||||
strncpy (current->text[i], s, p-s);
|
|
||||||
current->text[i++][p-s]='\0';
|
|
||||||
if (!strncmp(p,"<br>",4)) s=p+4;
|
|
||||||
else s=p;
|
|
||||||
} while (!eol (*p));
|
|
||||||
|
|
||||||
current->lines=i;
|
|
||||||
|
|
||||||
if (! (fgets (line, 1000, fd))) return 0;
|
case 4: /* get current->end or skip <TAG> */
|
||||||
s= strstr(line, "Start=");
|
q = strstr (s, "Start=");
|
||||||
if (s) {
|
if (q) {
|
||||||
sscanf (s, "Start=%d", ¤t->end);
|
current->end = strtol (q + 6, &q, 0) / 10 - 1;
|
||||||
if (!strstr (s, "<P><br>")) return ERR;
|
*p = '\0'; trail_space (text);
|
||||||
} else return ERR;
|
if (text[0] != '\0')
|
||||||
|
current->text[current->lines++] = strdup (text);
|
||||||
|
if (current->lines > 0) { state = 99; break; }
|
||||||
|
state = 0; continue;
|
||||||
|
}
|
||||||
|
s = strchr (s, '>');
|
||||||
|
if (s) { s++; state = 3; continue; }
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* read next line */
|
||||||
|
if (state != 99 && !(s = fgets (line, 1000, fd))) return 0;
|
||||||
|
|
||||||
|
} while (state != 99);
|
||||||
|
|
||||||
return current;
|
return current;
|
||||||
}
|
}
|
||||||
@ -200,7 +232,7 @@ int sub_autodetect (FILE *fd) {
|
|||||||
if (sscanf (line, "%d:%d:%d,%d --> %d:%d:%d,%d", &i, &i, &i, &i, &i, &i, &i, &i)==8)
|
if (sscanf (line, "%d:%d:%d,%d --> %d:%d:%d,%d", &i, &i, &i, &i, &i, &i, &i, &i)==8)
|
||||||
{sub_uses_time=1;return 2;}
|
{sub_uses_time=1;return 2;}
|
||||||
if (strstr (line, "<SAMI>"))
|
if (strstr (line, "<SAMI>"))
|
||||||
{sub_uses_time=0; return 3;}
|
{sub_uses_time=1; return 3;}
|
||||||
}
|
}
|
||||||
|
|
||||||
return -1; // too many bad lines
|
return -1; // too many bad lines
|
||||||
@ -268,12 +300,14 @@ char * sub_filename( char * fname )
|
|||||||
char * sub_name = NULL;
|
char * sub_name = NULL;
|
||||||
char * sub_tmp = NULL;
|
char * sub_tmp = NULL;
|
||||||
int i;
|
int i;
|
||||||
#define SUB_EXTS 4
|
#define SUB_EXTS 6
|
||||||
char * sub_exts[SUB_EXTS] =
|
char * sub_exts[SUB_EXTS] =
|
||||||
{ ".sub",
|
{ ".sub",
|
||||||
".SUB",
|
".SUB",
|
||||||
".srt",
|
".srt",
|
||||||
".SRT" };
|
".SRT",
|
||||||
|
".smi",
|
||||||
|
".SMI"};
|
||||||
|
|
||||||
if ( fname == NULL ) return NULL;
|
if ( fname == NULL ) return NULL;
|
||||||
for( i=strlen( fname );i>0;i-- )
|
for( i=strlen( fname );i>0;i-- )
|
||||||
@ -335,4 +369,4 @@ int main(int argc, char **argv) { // for testing
|
|||||||
printf ("Read %i subtitles, %i errors.\n", sub_num, sub_errs);
|
printf ("Read %i subtitles, %i errors.\n", sub_num, sub_errs);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user