diff options
| author | Carl Hetherington <cth@carlh.net> | 2023-01-20 23:53:45 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2023-02-27 14:47:25 +0100 |
| commit | eef23108ceb07b56cde9f0393aeaca5b429444e6 (patch) | |
| tree | 9c4a2a70f6b136bfd5768aa439962ab7d9e53bac /src/lib | |
| parent | b1583bb7f1821f466fb2cb18af1259c62adc75fa (diff) | |
Add bounding_box().
Diffstat (limited to 'src/lib')
| -rw-r--r-- | src/lib/render_text.cc | 30 | ||||
| -rw-r--r-- | src/lib/render_text.h | 4 |
2 files changed, 33 insertions, 1 deletions
diff --git a/src/lib/render_text.cc b/src/lib/render_text.cc index 0b6a30e80..0e2b024d6 100644 --- a/src/lib/render_text.cc +++ b/src/lib/render_text.cc @@ -427,6 +427,36 @@ render_text (list<StringText> subtitles, dcp::Size target, DCPTime time, int fra } +list<dcpomatic::Rect<int>> +bounding_box(list<StringText> subtitles, dcp::Size target) +{ + list<StringText> pending; + list<dcpomatic::Rect<int>> rects; + + auto use_pending = [&pending, &rects, target]() { + /* We can provide dummy values for time and frame rate here as they are only used to calculate fades */ + auto layout = setup_layout(pending, target, DCPTime(), 24); + int const x = x_position(pending.front(), target.width, layout.size.width); + int const y = y_position(pending.front(), target.height, layout.position.y, layout.size.height); + rects.push_back({Position<int>(x, y), layout.size.width, layout.size.height}); + }; + + for (auto const& i: subtitles) { + if (!pending.empty() && (i.v_align() != pending.back().v_align() || fabs(i.v_position() - pending.back().v_position()) > 1e-4)) { + use_pending(); + pending.clear(); + } + pending.push_back(i); + } + + if (!pending.empty()) { + use_pending(); + } + + return rects; +} + + float FontMetrics::height(StringText const& subtitle) { diff --git a/src/lib/render_text.h b/src/lib/render_text.h index 762d79446..bceee964e 100644 --- a/src/lib/render_text.h +++ b/src/lib/render_text.h @@ -19,8 +19,9 @@ */ -#include "position_image.h" #include "dcpomatic_time.h" +#include "position_image.h" +#include "rect.h" #include "string_text.h" #include <dcp/util.h> #include <memory> @@ -33,6 +34,7 @@ namespace dcpomatic { 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); +std::list<dcpomatic::Rect<int>> bounding_box(std::list<StringText> subtitles, dcp::Size target); class FontMetrics |
