2 * Copyright (C) 2003-2006 Gabest
3 * http://www.gabest.org
5 * This Program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
10 * This Program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with GNU Make; see the file COPYING. If not, write to
17 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
18 * http://www.gnu.org/copyleft/gpl.html
29 typedef enum {TIME
, FRAME
} tmode
; // the meaning of STSEntry::start/end
31 //Coordinate System 2: target scale applied
34 typedef float FloatCoor2
;
35 typedef double DoubleCoor2
;
36 typedef POINT POINTCoor2
;
37 typedef CPoint CPointCoor2
;
38 typedef SIZE SIZECoor2
;
39 typedef CSize CSizeCoor2
;
40 typedef RECT RECTCoor2
;
41 typedef CRect CRectCoor2
;
42 typedef FwRect FwRectCoor2
;
48 double fontSize
; // height
54 bool operator == (const STSStyleBase
& s
)const;
57 LOGFONTA
& operator <<= (LOGFONTA
& lfa
, const STSStyleBase
& s
);
58 LOGFONTW
& operator <<= (LOGFONTW
& lfw
, const STSStyleBase
& s
);
60 struct STSStyle
: public STSStyleBase
63 FwRect marginRect
; // measured from the sides
64 int scrAlignment
; // 1 - 9: as on the numpad, 0: default
65 int borderStyle
; // 0: outline, 1: opaque box
66 double outlineWidthX
, outlineWidthY
;
67 double shadowDepthX
, shadowDepthY
;
68 COLORREF colors
[4]; // usually: {primary, secondary, outline/background, shadow}
71 double fontScaleX
, fontScaleY
; // percent
72 double fontSpacing
; // +/- pixels
76 double fontAngleZ
, fontAngleX
, fontAngleY
;
77 double fontShiftX
, fontShiftY
;
78 int relativeTo
; // 0: window, 1: video, 2: undefined (~window)
84 bool operator == (const STSStyle
& s
)const;
85 bool IsFontStyleEqual(const STSStyle
& s
) const;
87 void operator = (const LOGFONT
& lf
);
89 friend CString
& operator <<= (CString
& style
, const STSStyle
& s
);
90 friend STSStyle
& operator <<= (STSStyle
& s
, const CString
& style
);
93 typedef ::boost::flyweights::flyweight
<STSStyle
, ::boost::flyweights::no_locking
> FwSTSStyle
;
96 static inline std::size_t hash_value(const STSStyleBase
& s
)
98 std::size_t hash
= CStringElementTraits
<CString
>::Hash(s
.fontName
);
99 hash
= (hash
<<5) + (hash
) + s
.charSet
;
100 hash
= (hash
<<5) + (hash
) + hash_value(s
.fontSize
);
101 hash
= (hash
<<5) + (hash
) + s
.fontWeight
;
102 hash
= (hash
<<5) + (hash
) + s
.fItalic
; //Todo: fix me
103 hash
= (hash
<<5) + (hash
) + s
.fUnderline
;
104 hash
= (hash
<<5) + (hash
) + s
.fStrikeOut
;
108 static inline std::size_t hash_value(const STSStyle
& s
)
111 std::size_t hash
= hash_value(static_cast<const STSStyleBase
&>(s
));
112 hash
= (hash
<<5) + (hash
) + s
.colors
[0];
113 hash
= (hash
<<5) + (hash
) + s
.colors
[2];
114 hash
= (hash
<<5) + (hash
) + hash_value(s
.fontScaleX
);
115 hash
= (hash
<<5) + (hash
) + hash_value(s
.fontScaleY
);
116 hash
= (hash
<<5) + (hash
) + hash_value(s
.fontAngleX
);
117 hash
= (hash
<<5) + (hash
) + hash_value(s
.fontAngleY
);
118 hash
= (hash
<<5) + (hash
) + hash_value(s
.fontAngleZ
);
119 hash
= (hash
<<5) + (hash
) + hash_value(s
.fontShiftX
);
120 hash
= (hash
<<5) + (hash
) + hash_value(s
.fontShiftY
);
125 class CSTSStyleMap
: public CAtlMap
<CString
, STSStyle
*, CStringElementTraits
<CString
> >
129 virtual ~CSTSStyleMap() {Free();}
137 CString style
, actor
, effect
;
148 bool animated
; //if this segment has animate effect
151 STSSegment() { animated
=false; }
152 STSSegment(int s
, int e
) {start
= s
; end
= e
; animated
= false;}
153 STSSegment(const STSSegment
& stss
) {*this = stss
;}
154 void operator = (const STSSegment
& stss
) {start
= stss
.start
; end
= stss
.end
; animated
= stss
.animated
; subs
.Copy(stss
.subs
);}
157 class CSimpleTextSubtitle
159 friend class CSubtitleEditorDlg
;
162 CAtlArray
<STSEntry
> m_entries
;
163 CAtlArray
<STSSegment
> m_segments
;
164 virtual void OnChanged() {}
170 CTextFile::enc m_encoding
;
173 CSize m_dstScreenSize
;
174 int m_defaultWrapStyle
;
178 bool m_fUsingAutoGeneratedDefaultStyle
;
180 CSTSStyleMap m_styles
;
182 enum EPARCompensationType
190 EPARCompensationType m_ePARCompensationType
;
191 double m_dPARCompensation
;
205 YCbCrMatrix m_eYCbCrMatrix
;
206 YCbCrRange m_eYCbCrRange
;
208 CSimpleTextSubtitle();
209 virtual ~CSimpleTextSubtitle();
211 virtual void Copy(CSimpleTextSubtitle
& sts
);
212 virtual void Empty();
216 void Sort(bool fRestoreReadorder
= false);
217 void RemoveAllEntries();
218 void CreateSegments();
220 void Append(CSimpleTextSubtitle
& sts
, int timeoff
= -1);
222 bool Open(CString fn
, int CharSet
, CString name
= _T(""));
223 bool Open(CTextFile
* f
, int CharSet
, CString name
);
224 bool Open(BYTE
* data
, int len
, int CharSet
, CString name
);
225 bool SaveAs(CString fn
, exttype et
, double fps
= -1, CTextFile::enc
= CTextFile::ASCII
);
227 void Add(CStringW str
, bool fUnicode
, int start
, int end
, CString style
= CString(_T("Default")),
228 const CString
& actor
= CString(_T("")),
229 const CString
& effect
= CString(_T("")),
230 const CRect
& marginRect
= CRect(0,0,0,0), int layer
= 0, int readorder
= -1);
231 //void Add(CStringW str, bool fUnicode, int start, int end, const CString& style, const CString& actor, const CString& effect, const CRect& marginRect, int layer, int readorder);
232 //void Add(CStringW str, bool fUnicode, int start, int end);
234 //add an STSEntry obj to the array
235 //NO addition segments added
236 //remember to call sort when all STSEntrys are ready
237 void AddSTSEntryOnly(CStringW str
, bool fUnicode
, int start
, int end
, CString style
= _T("Default"), const CString
& actor
= _T(""), const CString
& effect
= _T(""), const CRect
& marginRect
= CRect(0,0,0,0), int layer
= 0, int readorder
= -1);
239 STSStyle
* CreateDefaultStyle(int CharSet
);
240 void ChangeUnknownStylesToDefault();
241 void AddStyle(CString name
, STSStyle
* style
); // style will be stored and freed in Empty() later
242 bool CopyStyles(const CSTSStyleMap
& styles
, bool fAppend
= false);
244 bool SetDefaultStyle(STSStyle
& s
);
245 bool GetDefaultStyle(STSStyle
& s
);
247 void ConvertToTimeBased(double fps
);
248 void ConvertToFrameBased(double fps
);
250 int TranslateStart(int i
, double fps
);
251 int TranslateEnd(int i
, double fps
);
252 int SearchSub(int t
, double fps
);
254 int TranslateSegmentStart(int i
, double fps
);
255 int TranslateSegmentEnd(int i
, double fps
);
256 void TranslateSegmentStartEnd(int i
, double fps
, /*out*/int& start
, /*out*/int& end
);
258 //find the first STSSegment with stop time > @t
259 //@iSegment: return the index, 0 based, of the STSSegment found, return STSSegments count if all STSSegments' stop time are NOT bigger than @t
260 //@nSegment: return the STSSegments count
261 //@return: the ptr to the STSSegment found, return NULL if such STSSegment not exist
262 const STSSegment
* SearchSubs(int t
, double fps
, /*[out]*/ int* iSegment
= NULL
, int* nSegments
= NULL
);
264 //find STSSegment with a duration containing @t, i.e. with a start time <= @t and a stop time > @t
265 //@iSegment: return the index, 0 based, of the STSSegment found. Return -1 if such STSSegment not exist
266 //@nSegment: return the STSSegments count
267 //@return: the ptr to the STSSegment found, return NULL if such STSSegment not exist
268 STSSegment
* SearchSubs2(int t
, double fps
, /*[out]*/ int* iSegment
=NULL
, int* nSegments
=NULL
);
270 const STSSegment
* GetSegment(int iSegment
) {return iSegment
>= 0 && iSegment
< (int)m_segments
.GetCount() ? &m_segments
[iSegment
] : NULL
;}
272 STSStyle
* GetStyle(int i
);
273 bool GetStyle(int i
, STSStyle
* const stss
);
274 int GetCharSet(int i
);
275 bool IsEntryUnicode(int i
);
276 void ConvertUnicode(int i
, bool fUnicode
);
278 CStringA
GetStrA(int i
, bool fSSA
= false);
279 CStringW
GetStrW(int i
, bool fSSA
= false);
280 CStringW
GetStrWA(int i
, bool fSSA
= false);
283 #define GetStr GetStrW
285 #define GetStr GetStrA
288 void SetStr(int i
, CStringA str
, bool fUnicode
/* ignored */);
289 void SetStr(int i
, CStringW str
, bool fUnicode
);
291 friend bool OpenMicroDVD(CTextFile
* file
, CSimpleTextSubtitle
& ret
, int CharSet
);
294 extern BYTE CharSetList
[];
295 extern TCHAR
* CharSetNames
[];
296 extern int CharSetLen
;
298 class CHtmlColorMap
: public CAtlMap
<CString
, DWORD
, CStringElementTraits
<CString
> > {public: CHtmlColorMap();};
299 extern CHtmlColorMap g_colors
;