From 323b8cbb0b95297fbd027ffdc4ea5003b59ef25f Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Fri, 18 Nov 2022 10:56:42 +0100 Subject: Fix subtitle vertical position (#2367). Previously we would not account for the differences in what vertical position means between Interop and SMPTE. For interop, vertical position is the distance from the reference point to the text baseline, whereas for SMPTE it is the distance from the reference point to the top/middle/bottom of the subtitle (depending on the reference). This caused differences between the preview and the DCP for some cases (notably, using SRT/SSA and making Interop DCPs, or converting Interop DCP subs to SMPTE, or vice versa). --- src/lib/render_text.h | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'src/lib/render_text.h') diff --git a/src/lib/render_text.h b/src/lib/render_text.h index 6ff91dce1..762d79446 100644 --- a/src/lib/render_text.h +++ b/src/lib/render_text.h @@ -18,14 +18,55 @@ */ + #include "position_image.h" #include "dcpomatic_time.h" #include "string_text.h" #include +#include + namespace dcpomatic { class Font; } + std::string marked_up (std::list subtitles, int target_height, float fade_factor, std::string font_name); std::list render_text (std::list, 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 font; + int size; + float aspect_adjust; + + bool operator<(Identifier const& other) const; + }; + + using Cache = std::map>; + + Cache::iterator get(StringText const& subtitle); + + Cache _cache; + + int _target_height; +}; + -- cgit v1.2.3