00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #pragma once
00023
00024 #include <afxtempl.h>
00025 #include <wxutil.h>
00026 #include "TextFile.h"
00027 #include "GFN.h"
00028
00029 typedef enum {TIME, FRAME} tmode;
00030
00031 class STSStyle
00032 {
00033 public:
00034 CRect marginRect;
00035 int scrAlignment;
00036 int borderStyle;
00037 double outlineWidth;
00038 double shadowDepth;
00039 COLORREF colors[4];
00040 BYTE alpha[4];
00041 int charSet;
00042 CString fontName;
00043 double fontSize;
00044 double fontScaleX, fontScaleY;
00045 double fontSpacing;
00046 int fontWeight;
00047 bool fItalic;
00048 bool fUnderline;
00049 bool fStrikeOut;
00050 bool fBlur;
00051 double fontAngleZ, fontAngleX, fontAngleY;
00052 int relativeTo;
00053
00054 STSStyle();
00055
00056 void SetDefault();
00057
00058 bool operator == (STSStyle& s);
00059 bool IsFontStyleEqual(STSStyle& s);
00060
00061 void operator = (LOGFONT& lf);
00062
00063 friend LOGFONTA& operator <<= (LOGFONTA& lfa, STSStyle& s);
00064 friend LOGFONTW& operator <<= (LOGFONTW& lfw, STSStyle& s);
00065
00066 friend CString& operator <<= (CString& style, STSStyle& s);
00067 friend STSStyle& operator <<= (STSStyle& s, CString& style);
00068 };
00069
00070 class CSTSStyleMap : public CMapStringToPtr
00071 {
00072 public:
00073 CSTSStyleMap() {}
00074 virtual ~CSTSStyleMap() {Free();}
00075 void Free();
00076 };
00077
00078 typedef struct
00079 {
00080 CStringW str;
00081 bool fUnicode;
00082 CString style, actor, effect;
00083 CRect marginRect;
00084 int layer;
00085 int start, end;
00086 int readorder;
00087 } STSEntry;
00088
00089 typedef CArray<STSEntry> CSTSArray;
00090
00091 typedef CArray<int> CSubArray;
00092
00093 class STSSegment
00094 {
00095 public:
00096 int start, end;
00097 CSubArray subs;
00098
00099 STSSegment() {};
00100 STSSegment(int s, int e) {start = s; end = e;}
00101 STSSegment(const STSSegment& stss) {*this = stss;}
00102 void operator = (const STSSegment& stss) {start = stss.start; end = stss.end; subs.Copy(stss.subs);}
00103 };
00104
00105 typedef CArray<STSSegment> CSTSSegmentArray;
00106
00107 class CSimpleTextSubtitle : public CSTSArray
00108 {
00109 friend class CSubtitleEditorDlg;
00110
00111 protected:
00112 CSTSSegmentArray m_segments;
00113 virtual void OnChanged() {}
00114
00115 public:
00116 CString m_name;
00117 tmode m_mode;
00118 CTextFile::enc m_encoding;
00119 CString m_path;
00120
00121 CSize m_dstScreenSize;
00122 int m_defaultWrapStyle;
00123 int m_collisions;
00124 bool m_fScaledBAS;
00125
00126 bool m_fUsingAutoGeneratedDefaultStyle;
00127
00128 CSTSStyleMap m_styles;
00129
00130 public:
00131 CSimpleTextSubtitle();
00132 virtual ~CSimpleTextSubtitle();
00133
00134 virtual void Copy(CSimpleTextSubtitle& sts);
00135 virtual void Empty();
00136
00137 void Sort(bool fRestoreReadorder = false);
00138 void CreateSegments();
00139
00140 void Append(CSimpleTextSubtitle& sts, int timeoff = -1);
00141
00142 bool Open(CString fn, int CharSet, CString name = _T(""));
00143 bool Open(CTextFile* f, int CharSet, CString name);
00144 bool Open(BYTE* data, int len, int CharSet, CString name);
00145 bool SaveAs(CString fn, exttype et, double fps = -1, CTextFile::enc = CTextFile::ASCII);
00146
00147 void Add(CStringW str, bool fUnicode, int start, int end, CString style = _T("Default"), CString actor = _T(""), CString effect = _T(""), CRect marginRect = CRect(0,0,0,0), int layer = 0, int readorder = -1);
00148
00149 void CreateDefaultStyle(int CharSet);
00150 void ChangeUnknownStylesToDefault();
00151 void AddStyle(CString name, STSStyle* style);
00152 bool CopyStyles(const CSTSStyleMap& styles, bool fAppend = false);
00153
00154 bool SetDefaultStyle(STSStyle& s);
00155 bool GetDefaultStyle(STSStyle& s);
00156
00157 void ConvertToTimeBased(double fps);
00158 void ConvertToFrameBased(double fps);
00159
00160 int TranslateStart(int i, double fps);
00161 int TranslateEnd(int i, double fps);
00162 int SearchSub(int t, double fps);
00163
00164 int TranslateSegmentStart(int i, double fps);
00165 int TranslateSegmentEnd(int i, double fps);
00166 const STSSegment* SearchSubs(int t, double fps, int* iSegment = NULL, int* nSegments = NULL);
00167 const STSSegment* GetSegment(int iSegment) {return(iSegment >= 0 && iSegment < m_segments.GetSize() ? &m_segments[iSegment] : NULL);}
00168
00169 STSStyle* GetStyle(int i);
00170 bool GetStyle(int i, STSStyle& stss);
00171 int GetCharSet(int i);
00172 bool IsEntryUnicode(int i);
00173 void ConvertUnicode(int i, bool fUnicode);
00174
00175 CStringA GetStrA(int i, bool fSSA = false);
00176 CStringW GetStrW(int i, bool fSSA = false);
00177 CStringW GetStrWA(int i, bool fSSA = false);
00178
00179 #ifdef UNICODE
00180 #define GetStr GetStrW
00181 #else
00182 #define GetStr GetStrA
00183 #endif
00184
00185 void SetStr(int i, CStringA str, bool fUnicode );
00186 void SetStr(int i, CStringW str, bool fUnicode);
00187 };
00188
00189 extern BYTE CharSetList[];
00190 extern TCHAR* CharSetNames[];
00191 extern int CharSetLen;
00192
00193 class CHtmlColorMap : public CMapStringToPtr {public: CHtmlColorMap();};
00194 extern CHtmlColorMap g_colors;
00195