Supporters update.
[dcpomatic.git] / src / lib / subtitle_analysis.cc
index 91fec90b06cc70231de683da718bd51a081ad4de..ff1969a3a37c227cd32fde4a2dc793760648908a 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2020 Carl Hetherington <cth@carlh.net>
+    Copyright (C) 2020-2021 Carl Hetherington <cth@carlh.net>
 
     This file is part of DCP-o-matic.
 
 
 */
 
+
 #include "subtitle_analysis.h"
 #include "exceptions.h"
 #include <libcxml/cxml.h>
+#include <dcp/filesystem.h>
 #include <dcp/raw_convert.h>
+#include <dcp/warnings.h>
+LIBDCP_DISABLE_WARNINGS
 #include <libxml++/libxml++.h>
+LIBDCP_ENABLE_WARNINGS
+
 
+using std::make_shared;
+using std::shared_ptr;
 using std::string;
 using dcp::raw_convert;
-using boost::shared_ptr;
+
 
 int const SubtitleAnalysis::_current_state_version = 1;
 
@@ -35,11 +43,11 @@ SubtitleAnalysis::SubtitleAnalysis (boost::filesystem::path path)
 {
        cxml::Document f ("SubtitleAnalysis");
 
-       f.read_file (path);
+       f.read_file(dcp::filesystem::fix_long_path(path));
 
        if (f.optional_number_child<int>("Version").get_value_or(1) < _current_state_version) {
                /* Too old.  Throw an exception so that this analysis is re-run. */
-               throw OldFormatError ("Audio analysis file is too old");
+               throw OldFormatError ("Subtitle analysis file is too old");
        }
 
        cxml::NodePtr bounding_box = f.optional_node_child("BoundingBox");
@@ -50,26 +58,31 @@ SubtitleAnalysis::SubtitleAnalysis (boost::filesystem::path path)
                _bounding_box->width = bounding_box->number_child<double>("Width");
                _bounding_box->height = bounding_box->number_child<double>("Height");
        }
+
+       _analysis_x_offset = f.number_child<double>("AnalysisXOffset");
+       _analysis_y_offset = f.number_child<double>("AnalysisYOffset");
 }
 
 
 void
 SubtitleAnalysis::write (boost::filesystem::path path) const
 {
-       shared_ptr<xmlpp::Document> doc (new xmlpp::Document);
+       auto doc = make_shared<xmlpp::Document>();
        xmlpp::Element* root = doc->create_root_node ("SubtitleAnalysis");
 
        root->add_child("Version")->add_child_text (raw_convert<string>(_current_state_version));
 
        if (_bounding_box) {
-               xmlpp::Element* bounding_box = root->add_child("BoundingBox");
+               auto bounding_box = root->add_child("BoundingBox");
                bounding_box->add_child("X")->add_child_text(raw_convert<string>(_bounding_box->x));
                bounding_box->add_child("Y")->add_child_text(raw_convert<string>(_bounding_box->y));
                bounding_box->add_child("Width")->add_child_text(raw_convert<string>(_bounding_box->width));
                bounding_box->add_child("Height")->add_child_text(raw_convert<string>(_bounding_box->height));
        }
 
+       root->add_child("AnalysisXOffset")->add_child_text(raw_convert<string>(_analysis_x_offset));
+       root->add_child("AnalysisYOffset")->add_child_text(raw_convert<string>(_analysis_y_offset));
+
        doc->write_to_file_formatted (path.string());
 }
 
-