summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2014-05-25 21:25:33 +0100
committerCarl Hetherington <cth@carlh.net>2014-05-25 21:25:33 +0100
commit8181d97d7f9ef0d44af748a5bd5666cf575955fe (patch)
treed27502e2c9e1acf554796d94987620804d5a25c9 /src
parentb5dc08b66bc7e2340dd5a8a0156036a65a49f269 (diff)
Change API for alternate representations of time / font size etc. Fix Arial recognition.
Diffstat (limited to 'src')
-rw-r--r--src/dcp_reader.cc4
-rw-r--r--src/stl_writer.cc18
-rw-r--r--src/stl_writer.h2
-rw-r--r--src/subtitle.cc79
-rw-r--r--src/subtitle.h12
-rw-r--r--src/writer.h6
6 files changed, 78 insertions, 43 deletions
diff --git a/src/dcp_reader.cc b/src/dcp_reader.cc
index dd40c97..4c3384e 100644
--- a/src/dcp_reader.cc
+++ b/src/dcp_reader.cc
@@ -236,11 +236,11 @@ DCPReader::font_id_to_name (string id) const
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)
diff --git a/src/stl_writer.cc b/src/stl_writer.cc
index 2266732..126ad76 100644
--- a/src/stl_writer.cc
+++ b/src/stl_writer.cc
@@ -26,8 +26,8 @@ using std::string;
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;
@@ -45,9 +45,9 @@ STLWriter::STLWriter (list<Subtitle> subtitles, ostream& out)
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;
@@ -66,16 +66,16 @@ STLWriter::STLWriter (list<Subtitle> subtitles, ostream& out)
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;
}
}
diff --git a/src/stl_writer.h b/src/stl_writer.h
index 712aaa5..7e37f16 100644
--- a/src/stl_writer.h
+++ b/src/stl_writer.h
@@ -25,7 +25,7 @@ namespace sub {
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 &);
};
}
diff --git a/src/subtitle.cc b/src/subtitle.cc
index 105bf31..6d3360f 100644
--- a/src/subtitle.cc
+++ b/src/subtitle.cc
@@ -37,37 +37,62 @@ sub::operator< (Subtitle const & a, Subtitle const & b)
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;
}
diff --git a/src/subtitle.h b/src/subtitle.h
index 7729064..70a8eb6 100644
--- a/src/subtitle.h
+++ b/src/subtitle.h
@@ -53,6 +53,9 @@ public:
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 */
@@ -76,21 +79,24 @@ public:
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
diff --git a/src/writer.h b/src/writer.h
index 274c455..057214e 100644
--- a/src/writer.h
+++ b/src/writer.h
@@ -27,12 +27,16 @@ class Subtitle;
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;
};
}