Welcome to mirror list, hosted at ThFree Co, Russian Federation.

Subtitle.h « libssf « Subtitles « src - github.com/mpc-hc/mpc-hc.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: a1cedc3c01aacce6dce33b586037b59dc4248eb7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/* 
 *	Copyright (C) 2003-2006 Gabest
 *	http://www.gabest.org
 *
 *  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, 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 GNU Make; see the file COPYING.  If not, write to
 *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 
 *  http://www.gnu.org/copyleft/gpl.html
 *
 */

#pragma once

#include "File.h"

namespace ssf
{
	struct Point {float x, y;};
	struct PointAuto : public Point {bool auto_x, auto_y;};
	struct Size {float cx, cy;};
	struct Rect {float t, r, b, l;};
	struct Align {float v, h;};
	struct Angle {float x, y, z;};
	struct Color {float a, r, g, b; operator DWORD(); void operator = (DWORD c);};
	struct Frame {CStringW reference; Size resolution;};
	struct Direction {CStringW primary, secondary;};
	struct Time {float start, stop;};
	struct Background {Color color; float size, blur; CStringW type;};
	struct Shadow {Color color; float depth, angle, blur;};

	class Path : public CAtlArray<Point>
	{
	public: 
		Path() {} 
		Path(const Path& path) {*this = path;} 
		Path& operator = (const Path& path) {Copy(path); return *this;} 
		Path(LPCWSTR str) {*this = str;} 
		Path& operator = (LPCWSTR str);
		CStringW ToString();
	};

	struct Placement 
	{
		Rect clip, margin; 
		Align align; 
		PointAuto pos; 
		Point offset;
		Angle angle; 
		PointAuto org;
		Path path;
	};

	struct Font
	{
		CStringW face;
		float size, weight;
		Color color;
		bool underline, strikethrough, italic;
		float spacing;
		Size scale;
		bool kerning;
	};

	struct Fill
	{
		static unsigned int gen_id;
		int id;
		Color color;
		float width;
		struct Fill() : id(0) {}
	};

	struct Style
	{
		CStringW linebreak;
		Placement placement;
		Font font;
		Background background;
		Shadow shadow;
		Fill fill;

		bool IsSimilar(const Style& s);
	};

	struct Text
	{
		enum {SP = 0x20, NBSP = 0xa0, LSEP = 0x0a};
		Style style;
		CStringW str;
	};

	class Subtitle
	{
		static struct n2n_t {StringMapW<float> align[2], weight, transition;} m_n2n;

		File* m_pFile;

		void GetStyle(Definition* pDef, Style& style);
		float GetMixWeight(Definition* pDef, float at, StringMapW<float>& offset, int default_id);
		template<class T> bool MixValue(Definition& def, T& value, float t);
		template<> bool MixValue(Definition& def, float& value, float t);
		template<class T> bool MixValue(Definition& def, T& value, float t, StringMapW<T>* n2n);
		template<> bool MixValue(Definition& def, float& value, float t, StringMapW<float>* n2n);
		template<> bool MixValue(Definition& def, Path& value, float t);
		void MixStyle(Definition* pDef, Style& dst, float t);

		void Parse(InputStream& s, Style style, float at, StringMapW<float> offset, Reference* pParentRef);

		void AddChar(Text& t, WCHAR c);
		void AddText(Text& t);

	public:
		CStringW m_name;
		bool m_animated;
		Frame m_frame;
		Direction m_direction;
		CStringW m_wrap;
		float m_layer;
		Time m_time;
		CAtlList<Text> m_text;

	public:
		Subtitle(File* pFile);
		virtual ~Subtitle();

		bool Parse(Definition* pDef, float start, float stop, float at);
	};
};