Merge with MPC-HC 6d1472b2f18266d92e5bc068667de348c0cd3b3b.
[xy_vsfilter.git] / src / subtitles / libssf / Subtitle.h
bloba1cedc3c01aacce6dce33b586037b59dc4248eb7
1 /*
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)
8 * any later version.
9 *
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
22 #pragma once
24 #include "File.h"
26 namespace ssf
28 struct Point {float x, y;};
29 struct PointAuto : public Point {bool auto_x, auto_y;};
30 struct Size {float cx, cy;};
31 struct Rect {float t, r, b, l;};
32 struct Align {float v, h;};
33 struct Angle {float x, y, z;};
34 struct Color {float a, r, g, b; operator DWORD(); void operator = (DWORD c);};
35 struct Frame {CStringW reference; Size resolution;};
36 struct Direction {CStringW primary, secondary;};
37 struct Time {float start, stop;};
38 struct Background {Color color; float size, blur; CStringW type;};
39 struct Shadow {Color color; float depth, angle, blur;};
41 class Path : public CAtlArray<Point>
43 public:
44 Path() {}
45 Path(const Path& path) {*this = path;}
46 Path& operator = (const Path& path) {Copy(path); return *this;}
47 Path(LPCWSTR str) {*this = str;}
48 Path& operator = (LPCWSTR str);
49 CStringW ToString();
52 struct Placement
54 Rect clip, margin;
55 Align align;
56 PointAuto pos;
57 Point offset;
58 Angle angle;
59 PointAuto org;
60 Path path;
63 struct Font
65 CStringW face;
66 float size, weight;
67 Color color;
68 bool underline, strikethrough, italic;
69 float spacing;
70 Size scale;
71 bool kerning;
74 struct Fill
76 static unsigned int gen_id;
77 int id;
78 Color color;
79 float width;
80 struct Fill() : id(0) {}
83 struct Style
85 CStringW linebreak;
86 Placement placement;
87 Font font;
88 Background background;
89 Shadow shadow;
90 Fill fill;
92 bool IsSimilar(const Style& s);
95 struct Text
97 enum {SP = 0x20, NBSP = 0xa0, LSEP = 0x0a};
98 Style style;
99 CStringW str;
102 class Subtitle
104 static struct n2n_t {StringMapW<float> align[2], weight, transition;} m_n2n;
106 File* m_pFile;
108 void GetStyle(Definition* pDef, Style& style);
109 float GetMixWeight(Definition* pDef, float at, StringMapW<float>& offset, int default_id);
110 template<class T> bool MixValue(Definition& def, T& value, float t);
111 template<> bool MixValue(Definition& def, float& value, float t);
112 template<class T> bool MixValue(Definition& def, T& value, float t, StringMapW<T>* n2n);
113 template<> bool MixValue(Definition& def, float& value, float t, StringMapW<float>* n2n);
114 template<> bool MixValue(Definition& def, Path& value, float t);
115 void MixStyle(Definition* pDef, Style& dst, float t);
117 void Parse(InputStream& s, Style style, float at, StringMapW<float> offset, Reference* pParentRef);
119 void AddChar(Text& t, WCHAR c);
120 void AddText(Text& t);
122 public:
123 CStringW m_name;
124 bool m_animated;
125 Frame m_frame;
126 Direction m_direction;
127 CStringW m_wrap;
128 float m_layer;
129 Time m_time;
130 CAtlList<Text> m_text;
132 public:
133 Subtitle(File* pFile);
134 virtual ~Subtitle();
136 bool Parse(Definition* pDef, float start, float stop, float at);