// this script creates subtitle in two lines // first line is shorter than second! // made by kugi, edited : 21.12.05 // only one loop through subtitles // fill free to modify this version program NiceSubLines; // ---------------------------------------------- // procedure that creates single line subtitles, function RemoveNewLine (title : String) : String; var CRLFIndex : Integer; begin CRLFIndex := Pos(''#13''#10, title); if(CRLFIndex <> 0) then begin Delete(title,CRLFIndex,2); Insert(' ',title,CRLFIndex); result := title; end; result := title; end; // ---------------------------------------------- // procedure to remove space after dash ('-') // and in some cases before dash function RemoveDashSpace (title : String) : String; var startIndex : Integer; len : Integer; begin len := Length(title); for startIndex := 1 to len-1 do begin if((Copy(title,startIndex,1) = '-') and (Copy(title,startIndex+1,1) = ' ')) then begin Delete(title,startIndex+1,1); len := len - 1; end; if((Copy(title,startIndex,1) = ' ') and (Copy(title,startIndex+1,1) = '-')) then begin if((startIndex > 1) and (Copy(title,startIndex-1,1) > #96)) then begin Delete(title,startIndex,1); len := len - 1; startIndex := startIndex - 1; end; end; end; result := title; end; // ---------------------------------------------- // function to find the best space (blank) where // the subtitle will be splited into two lines // return zero if title is too short to split function DivideSpaceIndex(title : String): Integer; var titleLength : Integer; maxLength : Integer; begin maxLength := 42; titleLength := Length(title); if(titleLength < maxLength) then begin result := 0; // no need to divide end else begin titleLength := titleLength / 2; while (Copy(title,titleLength,1) <> ' ') do begin titleLength := titleLength - 1; end; result := titleLength; end; end; // ---------------------------------------------- // main // ---------------------------------------------- var divideIndex : Integer; titleIndex : Integer; title : String; begin for titleIndex := 0 to GetSubtitleCount - 1 do begin title := GetSubtitleText(titleIndex); title := RemoveNewLine(title); title := RemoveDashSpace(title); divideIndex := DivideSpaceIndex(title); if(divideIndex <> 0) then begin Delete(title,divideIndex,1); Insert(''#13''#10,title,divideIndex); SetSubtitleTrans(titleIndex,title); end else begin SetSubtitleTrans(titleIndex,title); end; end; end.
Страница 1 из 1
Форматирование текста
#1
Отправлено 17 Апрель 2007 - 02:14
Переформатирование текста таким образом, чтобы первая строка была короче второй.
Страница 1 из 1