diff options
| author | Carl Hetherington <cth@carlh.net> | 2022-11-18 10:56:42 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2022-11-21 20:09:28 +0100 |
| commit | 323b8cbb0b95297fbd027ffdc4ea5003b59ef25f (patch) | |
| tree | 9d558917b9a6ad488fc127293fba2b903c329d2b /src/lib/render_text.h | |
| parent | b9f949d688b6e9563f6350286bbbc3f169b1b9fe (diff) | |
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).
Diffstat (limited to 'src/lib/render_text.h')
| -rw-r--r-- | src/lib/render_text.h | 41 |
1 files changed, 41 insertions, 0 deletions
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 <dcp/util.h> +#include <memory> + namespace dcpomatic { class Font; } + 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; +}; + |
