Fix subtitle vertical position (#2367).
[dcpomatic.git] / src / lib / render_text.h
index d1c8c7aee9b357be8252f86ba26b7821af634b2a..762d794466e9747984dbf3be5d6e11ea153c9b15 100644 (file)
 
 */
 
+
 #include "position_image.h"
 #include "dcpomatic_time.h"
 #include "string_text.h"
 #include <dcp/util.h>
+#include <memory>
+
 
 namespace dcpomatic {
        class Font;
 }
 
-std::string marked_up (std::list<StringText> subtitles, int target_height, float fade_factor);
-std::list<PositionImage> render_text (
-       std::list<StringText>, std::list<std::shared_ptr<dcpomatic::Font> > fonts, dcp::Size, dcpomatic::DCPTime, int
-       );
+
+std::string marked_up (std::list<StringText> subtitles, int target_height, float fade_factor, std::string font_name);
+std::list<PositionImage> render_text (std::list<StringText>, dcp::Size, dcpomatic::DCPTime, int);
+
+
+class FontMetrics
+{
+public:
+       FontMetrics(int target_height)
+               : _target_height(target_height)
+       {}
+
+       float baseline_to_bottom(StringText const& subtitle);
+       float height(StringText const& subtitle);
+
+private:
+       /** Class to collect the properties of a subtitle which affect the metrics we care about
+        *  i.e. baseline position and height.
+        */
+       class Identifier
+       {
+       public:
+               Identifier(StringText const& subtitle);
+
+               std::shared_ptr<dcpomatic::Font> font;
+               int size;
+               float aspect_adjust;
+
+               bool operator<(Identifier const& other) const;
+       };
+
+       using Cache = std::map<Identifier, std::pair<float, float>>;
+
+       Cache::iterator get(StringText const& subtitle);
+
+       Cache _cache;
+
+       int _target_height;
+};
+