📄 tsubtitletext.cpp
字号:
/*
* Copyright (c) 2003-2006 Milan Cutka
* subtitles fixing code from SubRip by MJQ (subrip@divx.pl)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "stdafx.h"
#include "TsubtitleText.h"
#include "Tfont.h"
#include "Tsubreader.h"
#include "TsubtitlesSettings.h"
#include "Tconfig.h"
#include "ThtmlColors.h"
//========================== TtextFixBase =========================
strings TtextFixBase::getDicts(const Tconfig *cfg)
{
char_t msk[MAX_PATH];
_makepath(msk,NULL,cfg->pth,_l("dict\\*"),_l("dic"));
strings dicts;
findFiles(msk,dicts,false);
for (strings::iterator d=dicts.begin();d!=dicts.end();d++)
d->erase(d->find('.'),MAX_PATH);
return dicts;
}
//============================= TtextFix ==========================
template<class tchar> TtextFix<tchar>::TtextFix(const TsubtitlesSettings *scfg,const Tconfig *ffcfg):
cfg(scfg),
EndOfPrevSentence(true),
inHearing(false)
{
if (scfg->fix&fixOrtography)
{
char_t dictflnm[MAX_PATH];_makepath(dictflnm,NULL,ffcfg->pth,(::ffstring(_l("dict\\"))+scfg->fixDict).c_str(),_l("dic"));
TstreamFile fs(dictflnm,false,false);
if (fs)
{
tchar ln[1000];
while (fs.fgets(ln,1000))
{
tchar *eoln=strchr(ln,'\n');if (eoln) *eoln='\0';
odict.push_back(ln);
}
if (odd(odict.size()))
odict.erase(odict.end()-1);
if (!odict.empty())
for (typename strings::iterator s=odict.begin();s+1!=odict.end();s++)
if (strstr((s+1)->c_str(),s->c_str()))
{
s=odict.erase(s);
s=odict.erase(s);
}
}
}
}
template<class tchar> bool TtextFix<tchar>::process(ffstring &text,ffstring &fixed)
{
if (cfg->fix==0) return false;
int W1;
passtring<tchar> S1=text;
if (cfg->fix&fixAP) //AP
{
S1=stringreplace(S1,_L("`") , _L("'") ,rfReplaceAll);
S1=stringreplace(S1,_L("\264"), _L("'") ,rfReplaceAll);
S1=stringreplace(S1,_L("''") , _L("\""),rfReplaceAll);
S1=stringreplace(S1,_L("\"\""), _L("\""),rfReplaceAll);
}
if (cfg->fix&fixIl) // Il
{
#define TrChar(n) St1[W1+(n)]
bool TakeI=false,Takel=false;
passtring<tchar> St1=_L(" ")+S1+_L(" ");
for (W1=1 + 2;W1<=St1.size() - 2;W1++)
{
//small L --> big i
if (St1[W1] == 'l')
{
TakeI = false;
//_lll trio
if ((TrChar(-1)==' ' || TrChar(-1)=='#') && (TrChar(+1) == 'l') && (TrChar(+2) == 'l'))
{
//_lllx --> _Illx (Illinois, Illegal etc.) + _Ill-
if (in(TrChar(+3),_L("-abehinopstuy"))) TakeI = true;
//._Ill_ (=bedridden) + ._Ill. (Ill. = Illustriert, Illustration [German])
//other than BoL cases not reflected
if (in(TrChar(-2),_L(".[")) && (in(TrChar(+3),_L(" .")))) TakeI = true;
//Godfather III / Godfather III.
if (!(in(TrChar(-2),_L(".[")) && (in(TrChar(+3),_L(" .!?,")))))
{
TakeI = true;
St1[W1 + 1] = 'I';
St1[W1 + 2] = 'I';
}
}
//_lgelit _lglu _lgnition _lgrafpapier _lguana
if (in(TrChar(-1),_L(" [(#")) && (TrChar(+1) == 'g') && in(TrChar(+2),_L("elnru")))
TakeI = true;
//ME LOVES MAKARONl! (MY TO SLYSELl. (!?) [cz; no others affected])
if (in(TrChar(+1),_L(".!?")) &&
(TrChar(-1) == toupper(TrChar(-1))) &&
(TrChar(-1) != '.') && //籶丒n.l.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -