📄 tsubreadermplayer.cpp
字号:
}
if(line[j]=='<') {
skip=1;
continue;
}*/
if(skip) {
continue;
}
*curptr=line[j];
curptr++;
}
*curptr='\0';
current.add(curptr0);
} else {
break;
}
}
}
end:
return current.empty()?NULL:store(current);
}
template<class tchar> Tsubtitle* TsubtitleParserSubviewer2<tchar>::parse(Tstream &fd,int flags) {
tchar line[this->LINE_LEN+1];
int a1,a2,a3,a4;
tchar *p=NULL;
int len;
TsubtitleTextBase<tchar> current(this->format);
while (!current.size()) {
if (!fd.fgets (line, this->LINE_LEN)) return NULL;
if (line[0]!='{')
continue;
if ((len=tchar_traits<tchar>::sscanf() (line, _L("{T %d:%d:%d:%d"),&a1,&a2,&a3,&a4)) < 4)
continue;
current.start = this->hmsToTime(a1,a2,a3,a4);
for (/*i=0*/;;) {
if (!fd.fgets (line, this->LINE_LEN)) goto end;//break;
if (line[0]=='}') break;
len=0;
for (p=line; *p!='\n' && *p!='\r' && *p; ++p,++len);
if (len) {
current.add(line,len);
} else {
break;
}
}
//current->lines=i;
}
end:
return current.empty()?NULL:store(current);
}
template<class tchar> Tsubtitle* TsubtitleParserVplayer<tchar>::parse(Tstream &fd,int flags) {
tchar line[this->LINE_LEN+1];
int a1,a2,a3,a4;
const tchar *p=NULL, *next;tchar separator1,separator2;
int plen;
TsubtitleTextBase<tchar> current(this->format);
while (current.empty()) {
if (!fd.fgets (line, this->LINE_LEN)) return NULL;
int ret=tchar_traits<tchar>::sscanf() (line, T_L<tchar>("%d:%d:%d%c%d%c%n",L"%d:%d:%d%c%d%lc%n"),&a1,&a2,&a3,&separator1,&a4,&separator2,&plen);
if (ret!=6)
{
a4=0;
ret=tchar_traits<tchar>::sscanf() (line, T_L<tchar>("%d:%d:%d%c%n",L"%d:%d:%d%lc%n"),&a1,&a2,&a3,&separator1,&plen);
if (ret!=4)
continue;
}
if ((current.start = this->hmsToTime(a1,a2,a3,a4*10))==NULL)
continue;
/* removed by wodzu
p=line;
// finds the body of the subtitle
for (i=0; i<3; i++){
p=strchr(p,':');
if (p==NULL) break;
++p;
}
if (p==NULL) {
printf("SUB: Skipping incorrect subtitle line!\n");
continue;
}
*/
// by wodzu: hey! this time we know what length it has! what is
// that magic for? it can't deal with space instead of third
// colon! look, what simple it can be:
p = &line[ plen ];
if (*p!='|') {
//
next = p;
while ((next =sub_readtext (next, current))!=NULL)
;
}
}
return store(current);
}
template<class tchar> Tsubtitle* TsubtitleParserRt<tchar>::parse(Tstream &fd,int flags) {
//TODO: This format uses quite rich (sub/super)set of xhtml
// I couldn't check it since DTD is not included.
// WARNING: full XML parses can be required for proper parsing
tchar line[this->LINE_LEN+1];
int a1,a2,a3,a4,b1,b2,b3,b4;
const tchar *p=NULL,*next=NULL;
int plen;
TsubtitleTextBase<tchar> current(this->format);
while (current.empty()) {
if (!fd.fgets (line, this->LINE_LEN)) return NULL;
//TODO: it seems that format of time is not easily determined, it may be 1:12, 1:12.0 or 0:1:12.0
//to describe the same moment in time. Maybe there are even more formats in use.
//if ((len=tchar_traits<tchar>::sscanf() (line, "<Time Begin=\"%d:%d:%d.%d\" End=\"%d:%d:%d.%d\"",&a1,&a2,&a3,&a4,&b1,&b2,&b3,&b4)) < 8)
plen=a1=a2=a3=a4=b1=b2=b3=b4=0;
if (
(tchar_traits<tchar>::sscanf() (line, _L("<%*[tT]ime %*[bB]egin=\"%d.%d\" %*[Ee]nd=\"%d.%d\"%*[^<]<clear/>%n"),&a3,&a4,&b3,&b4,&plen) < 4) &&
(tchar_traits<tchar>::sscanf() (line, _L("<%*[tT]ime %*[bB]egin=\"%d.%d\" %*[Ee]nd=\"%d:%d.%d\"%*[^<]<clear/>%n"),&a3,&a4,&b2,&b3,&b4,&plen) < 5) &&
(tchar_traits<tchar>::sscanf() (line, _L("<%*[tT]ime %*[bB]egin=\"%d:%d\" %*[Ee]nd=\"%d:%d\"%*[^<]<clear/>%n"),&a2,&a3,&b2,&b3,&plen) < 4) &&
(tchar_traits<tchar>::sscanf() (line, _L("<%*[tT]ime %*[bB]egin=\"%d:%d\" %*[Ee]nd=\"%d:%d.%d\"%*[^<]<clear/>%n"),&a2,&a3,&b2,&b3,&b4,&plen) < 5) &&
// (tchar_traits<tchar>::sscanf() (line, _L("<%*[tT]ime %*[bB]egin=\"%d:%d.%d\" %*[Ee]nd=\"%d:%d\"%*[^<]<clear/>%n"),&a2,&a3,&a4,&b2,&b3,&plen) < 5) &&
(tchar_traits<tchar>::sscanf() (line, _L("<%*[tT]ime %*[bB]egin=\"%d:%d.%d\" %*[Ee]nd=\"%d:%d.%d\"%*[^<]<clear/>%n"),&a2,&a3,&a4,&b2,&b3,&b4,&plen) < 6) &&
(tchar_traits<tchar>::sscanf() (line, _L("<%*[tT]ime %*[bB]egin=\"%d:%d:%d.%d\" %*[Ee]nd=\"%d:%d:%d.%d\"%*[^<]<clear/>%n"),&a1,&a2,&a3,&a4,&b1,&b2,&b3,&b4,&plen) < 8) &&
//now try it without end time
(tchar_traits<tchar>::sscanf() (line, _L("<%*[tT]ime %*[bB]egin=\"%d.%d\"%*[^<]<clear/>%n"),&a3,&a4,&plen) < 2) &&
(tchar_traits<tchar>::sscanf() (line, _L("<%*[tT]ime %*[bB]egin=\"%d:%d\"%*[^<]<clear/>%n"),&a2,&a3,&plen) < 2) &&
(tchar_traits<tchar>::sscanf() (line, _L("<%*[tT]ime %*[bB]egin=\"%d:%d.%d\"%*[^<]<clear/>%n"),&a2,&a3,&a4,&plen) < 3) &&
(tchar_traits<tchar>::sscanf() (line, _L("<%*[tT]ime %*[bB]egin=\"%d:%d:%d.%d\"%*[^<]<clear/>%n"),&a1,&a2,&a3,&a4,&plen) < 4)
)
continue;
current.start = this->hmsToTime(a1,a2,a3,a4);
current.stop = this->hmsToTime(a1,a2,a3,a4);
if (b1 == 0 && b2 == 0 && b3 == 0 && b4 == 0)
current.stop = current.start+this->frameToTime(200);
p=line; p+=plen;
// TODO: I don't know what kind of convention is here for marking multiline subs, maybe <br/> like in xml?
next = strstr(line,_L("<clear/>"));
if(next && strlen(next)>8){
next+=8;
while ((next =sub_readtext (next, current))!=NULL)
;
}
}
return store(current);
}
template<class tchar> TsubtitleParserSSA<tchar>::TsubtitleParserSSA(int Iformat,double Ifps,const TsubtitlesSettings *Icfg,const Tconfig *Iffcfg,Tsubreader *Isubreader,bool isEmbedded0):
TsubtitleParser<tchar>(Iformat,Ifps,Icfg,Iffcfg,Isubreader),
inV4styles(0),inEvents(0),inInfo(0),
playResX(0),playResY(0),
timer(1,1),
isEmbedded(isEmbedded0)
{
}
template<class tchar> void TsubtitleParserSSA<tchar>::strToInt(const ffstring &str,int *i)
{
if (!str.empty())
{
tchar *end;
int val=strtol(str.c_str(),&end,10);
if (*end=='\0' && val>=0) *i=val;
}
}
template<class tchar> void TsubtitleParserSSA<tchar>::strToIntMargin(const ffstring &str,int *i)
{
if (!str.empty() /*str.size()==4 && str.compare(_L("0000"))!=0*/)
{
tchar *end;
int val=strtol(str.c_str(),&end,10);
if (*end=='\0' && val>0) *i=val;
}
}
template<class tchar> void TsubtitleParserSSA<tchar>::strToDouble(const ffstring &str,double *d)
{
if (!str.empty())
{
tchar *end;
double val=strtod(str.c_str(),&end);
if (*end=='\0' && val>=0) *d=val;
}
}
template<class tchar> void TsubtitleParserSSA<tchar>::Tstyle::toProps(void)
{
if (fontname)
text<char_t>(fontname.c_str(), -1, props.fontname, countof(props.fontname));
if (int size=atoi(fontsize.c_str()))
props.size=size;
const tchar *colorS=primaryColour.c_str();
int radix;
if (strnicmp(colorS,_L("&h"),2)==0)
{
colorS+=2;radix=16;
}
else
radix=10;
tchar *endcolor;
COLORREF color=strtol(colorS,&endcolor,radix);
if (*endcolor=='\0')
{
props.color=color;
props.isColor=true;
}
if (bold==_L("-1"))
props.bold=true;
else
props.bold=false;
if (italic==_L("-1")) props.italic=true;
if (underline==_L("-1")) props.underline=true;
if (strikeout==_L("-1")) props.strikeout=true;
strToInt(encoding,&props.encoding);
strToInt(spacing,&props.spacing);
strToInt(fontScaleX,&props.scaleX);
strToInt(fontScaleY,&props.scaleY);
strToInt(alignment,&props.alignment);
strToInt(marginLeft,&props.marginL);
strToInt(marginRight,&props.marginR);
strToInt(marginV,&props.marginV);
strToInt(marginTop,&props.marginTop);
strToInt(marginBottom,&props.marginBottom);
strToInt(borderStyle,&props.borderStyle);
strToDouble(outlineWidth,&props.outlineWidth);
strToDouble(shadowDepth,&props.shadowDepth);
if (alignment && this->version != SSA)
props.alignment=TSubtitleProps::alignASS2SSA(props.alignment);
}
template<class tchar> void TsubtitleParserSSA<tchar>::Tstyles::add(Tstyle &s)
{
s.toProps();
insert(std::make_pair(s.name,s));
}
template<class tchar> const TSubtitleProps* TsubtitleParserSSA<tchar>::Tstyles::getProps(const ffstring &style)
{
typename std::map<ffstring,Tstyle,ffstring_iless>::const_iterator si=this->find(style);
return si!=this->end()?&si->second.props:NULL;
}
template<class tchar> Tsubtitle* TsubtitleParserSSA<tchar>::parse(Tstream &fd,int flags) {
/*
* Sub Station Alpha v4 (and v2?) scripts have 9 commas before subtitle
* other Sub Station Alpha scripts have only 8 commas before subtitle
* Reading the "ScriptType:" field is not reliable since many scripts appear
* w/o it
*
* http://www.scriptclub.org is a good place to find more examples
* http://www.eswat.demon.co.uk is where the SSA specs can be found
*/
tchar line0[this->LINE_LEN+1];
tchar *line=line0;
while (fd.fgets(line,this->LINE_LEN))
{
#if 0
text<char_t> lineD0(line);
const char_t* lineD1=(const char_t*)lineD0;
DPRINTF(_l("%s"),lineD1);
#endif
if (line[0]==';')
continue;
tchar *cr=strrchr(line,'\n');if (cr) *cr='\0';
cr=strrchr(line,'\r');if (cr) *cr='\0';
if (strnicmp(line,_L("[Script Info]"),13)==0)
{
inV4styles=0;
inEvents=0;
inInfo=1;
}
else if (inInfo && strnicmp(line,_L("PlayResX:"),8)==0)
strToInt(line+9,&playResX);
else if (inInfo && strnicmp(line,_L("PlayResY:"),8)==0)
strToInt(line+9,&playResY);
else if (inInfo && strnicmp(line,_L("Timer:"),6)==0)
{
tchar *end;
double t=strtod(line+7,&end);
if (*end=='\0' && t!=0)
timer=Rational(t/100.0,INT32_MAX);
}
else if (strnicmp(line,_L("[V4 Styles]"),11)==0)
{
version=SSA;
inV4styles=2;
inEvents=0;
inInfo=0;
}
else if (strnicmp(line,_L("[V4+ Styles]"),11)==0)
{
version=ASS;
inV4styles=2;
inEvents=0;
inInfo=0;
}
else if (strnicmp(line,_L("[V4++ Styles]"),11)==0)
{
version=ASS2;
inV4styles=2;
inEvents=0;
inInfo=0;
}
else if (strnicmp(line,_L("[Events]"),8)==0)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -