return "";
}
- if ((*i)->uri == "arial.ttf") {
+ if ((*i)->uri == "arial.ttf" || (*i)->uri == "Arial.ttf") {
return "Arial";
}
- return "";
+ return (*i)->uri;
}
DCPReader::DCPReader (istream& in)
using boost::optional;
using namespace sub;
-STLWriter::STLWriter (list<Subtitle> subtitles, ostream& out)
- : Writer (subtitles)
+STLWriter::STLWriter (list<Subtitle> subtitles, int screen_height_in_points, float frames_per_second, ostream& out)
+ : Writer (subtitles, screen_height_in_points, frames_per_second)
{
optional<string> font;
optional<int> font_size;
font = i->font;
started_new = true;
}
- if (!font_size || font_size.get() != i->font_size.points.get()) {
- out << "\n$FontSize = " << i->font_size.points.get();
- font_size = i->font_size.points.get();
+ if (!font_size || font_size.get() != i->font_size_points (screen_height_in_points)) {
+ out << "\n$FontSize = " << i->font_size_points (screen_height_in_points);
+ font_size = i->font_size_points (screen_height_in_points);
started_new = true;
}
string text;
text += i->text;
- if (from && from.get() == i->from.frame.get() && to && to.get() == i->to.frame.get() && !started_new) {
+ if (from && from.get() == i->from_frame(frames_per_second) && to && to.get() == i->to_frame(frames_per_second) && !started_new) {
for (int j = line; j < i->line; ++j) {
out << "|";
}
out << text;
line = i->line;
} else {
- out << "\n" << i->from.frame.get().timecode() << "," << i->to.frame.get().timecode() << "," << text;
- from = i->from.frame.get();
- to = i->to.frame.get();
+ out << "\n" << i->from_frame(frames_per_second).timecode() << "," << i->to_frame(frames_per_second).timecode() << "," << text;
+ from = i->from_frame (frames_per_second);
+ to = i->to_frame (frames_per_second);
line = 0;
}
}
class STLWriter : public Writer
{
public:
- STLWriter (std::list<Subtitle> subtitles, std::ostream &);
+ STLWriter (std::list<Subtitle> subtitles, int screen_height_in_points, float frames_per_second, std::ostream &);
};
}
assert (false);
}
-void
-sub::convert_font_sizes (list<Subtitle>& subs, int screen_height_in_points)
+FrameTime
+Subtitle::from_frame (float frames_per_second) const
{
- for (list<Subtitle>::iterator i = subs.begin(); i != subs.end(); ++i) {
- if (i->font_size.proportional) {
- i->font_size.points = i->font_size.proportional.get() * screen_height_in_points;
- } else {
- i->font_size.proportional = float (i->font_size.points.get()) / screen_height_in_points;
- }
+ if (from.frame) {
+ return from.frame.get ();
}
+
+ return metric_to_frame (from.metric.get(), frames_per_second);
+}
+
+FrameTime
+Subtitle::to_frame (float frames_per_second) const
+{
+ if (to.frame) {
+ return to.frame.get ();
+ }
+
+ return metric_to_frame (to.metric.get(), frames_per_second);
+}
+
+MetricTime
+Subtitle::from_metric (float frames_per_second) const
+{
+ if (from.metric) {
+ return from.metric.get ();
+ }
+
+ return frame_to_metric (from.frame.get(), frames_per_second);
}
-/** Take a list of Subtitles and convert their times either from metric to frame, or vice-versa,
- * depending on what the Subtitles currently have.
- * @param sub Subtitles.
- * @param frames_per_second Video frames-per-second value to use in the conversion.
- */
-void
-sub::convert_times (list<Subtitle>& subs, float frames_per_second)
+MetricTime
+Subtitle::to_metric (float frames_per_second) const
{
- for (list<Subtitle>::iterator i = subs.begin(); i != subs.end(); ++i) {
- if (i->from.frame) {
- i->from.metric = frame_to_metric (i->from.frame.get(), frames_per_second);
- } else {
- i->from.frame = metric_to_frame (i->from.metric.get(), frames_per_second);
- }
-
- if (i->to.frame) {
- i->to.metric = frame_to_metric (i->to.frame.get(), frames_per_second);
- } else {
- i->to.frame = metric_to_frame (i->to.metric.get(), frames_per_second);
- }
+ if (to.metric) {
+ return to.metric.get ();
}
+
+ return frame_to_metric (to.frame.get(), frames_per_second);
+}
+
+float
+Subtitle::font_size_proportional (int screen_height_in_points) const
+{
+ if (font_size.proportional) {
+ return font_size.proportional.get ();
+ }
+
+ return float (font_size.points.get ()) / screen_height_in_points;
+}
+
+int
+Subtitle::font_size_points (int screen_height_in_points) const
+{
+ if (font_size.points) {
+ return font_size.points.get ();
+ }
+
+ return font_size.proportional.get() * screen_height_in_points;
}
boost::optional<int> points;
} font_size;
+ float font_size_proportional (int screen_height_in_points) const;
+ int font_size_points (int screen_height_in_points) const;
+
/** vertical position of the baseline of the text */
struct {
/** as a proportion of screen height offset from some reference point */
boost::optional<MetricTime> metric;
} from;
+ FrameTime from_frame (float frames_per_second) const;
+ MetricTime from_metric (float frames_per_second) const;
+
/** to time */
struct {
boost::optional<FrameTime> frame;
boost::optional<MetricTime> metric;
} to;
+ FrameTime to_frame (float frames_per_second) const;
+ MetricTime to_metric (float frames_per_second) const;
+
boost::optional<MetricTime> fade_up;
boost::optional<MetricTime> fade_down;
};
bool operator< (Subtitle const & a, Subtitle const & b);
-void convert_font_sizes (std::list<Subtitle> &, int screen_height_in_points);
-void convert_times (std::list<Subtitle> &, float frames_per_second);
-
}
#endif
class Writer
{
public:
- Writer (std::list<Subtitle> subtitles)
+ Writer (std::list<Subtitle> subtitles, int screen_height_in_points, float frames_per_second)
: _subs (subtitles)
+ , _screen_height_in_points (screen_height_in_points)
+ , _frames_per_second (frames_per_second)
{}
protected:
std::list<Subtitle> _subs;
+ int _screen_height_in_points;
+ float _frames_per_second;
};
}
subs.push_back (make (".", false, false, false, 0, sub::FrameTime (0, 1, 1, 1), sub::FrameTime (0, 1, 2, 10)));
ofstream f ("build/test/test.stl");
- sub::STLWriter writer (subs, f);
+ sub::STLWriter writer (subs, 24, 72 * 11, f);
f.close ();
check_text ("test/ref/test.stl", "build/test/test.stl");