File indexing completed on 2024-12-22 04:40:08
0001 /* 0002 SPDX-FileCopyrightText: 2007-2009 Sergio Pistone <sergio_pistone@yahoo.com.ar> 0003 SPDX-FileCopyrightText: 2010-2022 Mladen Milinkovic <max@smoothware.net> 0004 0005 SPDX-License-Identifier: GPL-2.0-or-later 0006 */ 0007 0008 #ifndef SUBVIEWER2OUTPUTFORMAT_H 0009 #define SUBVIEWER2OUTPUTFORMAT_H 0010 0011 #include "formats/outputformat.h" 0012 #include "core/richtext/richdocument.h" 0013 #include "core/subtitleiterator.h" 0014 0015 namespace SubtitleComposer { 0016 class SubViewer2OutputFormat : public OutputFormat 0017 { 0018 friend class FormatManager; 0019 0020 protected: 0021 QString dumpSubtitles(const Subtitle &subtitle, bool primary) const override 0022 { 0023 QString ret(QStringLiteral("[INFORMATION]\n[TITLE]\n[AUTHOR]\n[SOURCE]\n[PRG]\n[FILEPATH]\n[DELAY]0\n[CD TRACK]0\n" "[COMMENT]\n[END INFORMATION]\n[SUBTITLE]\n[COLF]&HFFFFFF,[STYLE]bd,[SIZE]24,[FONT]Tahoma\n")); 0024 0025 for(SubtitleIterator it(subtitle); it.current(); ++it) { 0026 const SubtitleLine *line = it.current(); 0027 0028 Time showTime = line->showTime(); 0029 Time hideTime = line->hideTime(); 0030 ret += QString::asprintf("%02d:%02d:%02d.%02d,%02d:%02d:%02d.%02d\n", showTime.hours(), showTime.minutes(), showTime.seconds(), (showTime.millis() + 5) / 10, hideTime.hours(), hideTime.minutes(), hideTime.seconds(), (hideTime.millis() + 5) / 10); 0031 0032 const RichString text = (primary ? line->primaryDoc() : line->secondaryDoc())->toRichText(); 0033 ret += m_stylesMap[text.cummulativeStyleFlags()]; 0034 ret += text.string().replace("\n", "[br]"); 0035 0036 ret += QStringLiteral("\n\n"); 0037 } 0038 return ret; 0039 } 0040 0041 SubViewer2OutputFormat() : 0042 OutputFormat(QStringLiteral("SubViewer 2.0"), QStringList(QStringLiteral("sub"))), 0043 m_stylesMap() 0044 { 0045 m_stylesMap[RichString::Bold] = QStringLiteral("{Y:b}"); 0046 m_stylesMap[RichString::Italic] = QStringLiteral("{Y:i}"); 0047 m_stylesMap[RichString::Underline] = QStringLiteral("{Y:u}"); 0048 m_stylesMap[RichString::Bold | RichString::Italic] = QStringLiteral("{Y:bi}"); 0049 m_stylesMap[RichString::Bold | RichString::Underline] = QStringLiteral("{Y:ub}"); 0050 m_stylesMap[RichString::Italic | RichString::Underline] = QStringLiteral("{Y:ui}"); 0051 m_stylesMap[RichString::Bold | RichString::Italic | RichString::Underline] = QStringLiteral("{Y:ubi}"); 0052 } 0053 0054 mutable QMap<int, QString> m_stylesMap; 0055 }; 0056 } 0057 0058 #endif