summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2022-07-06 10:08:55 +0200
committerCarl Hetherington <cth@carlh.net>2022-07-20 10:22:55 +0200
commit58c63c02bc26209f42f42bccbe4a587f9df6f05f (patch)
tree4f9a0cb2285d5e23a164e647e20eb934962b8c81
parenta6507c95d19b434275e2a28f0bc37f06912f467f (diff)
Tidy up font rendering for subtitles.
Here was use get_ink_extents() rather than get_pixel_size() to find out how big the rendered subtitle will be, then use the x/y values of this extents rectangle to offset the rendering within the image. This allows the removal of some hacks to make accents visible.
-rw-r--r--src/lib/render_text.cc12
1 files changed, 4 insertions, 8 deletions
diff --git a/src/lib/render_text.cc b/src/lib/render_text.cc
index 284e4fa88..a379ab180 100644
--- a/src/lib/render_text.cc
+++ b/src/lib/render_text.cc
@@ -290,8 +290,8 @@ render_line (list<StringText> subtitles, dcp::Size target, DCPTime time, int fra
auto const markup = marked_up (subtitles, target.height, fade_factor, font_name);
auto layout = create_layout ();
setup_layout (layout, font_name, markup);
- dcp::Size size;
- layout->get_pixel_size (size.width, size.height);
+ auto ink = layout->get_ink_extents();
+ dcp::Size size{ink.get_width() / Pango::SCALE, ink.get_height() / Pango::SCALE};
/* Calculate x and y scale factors. These are only used to stretch
the font away from its normal aspect ratio.
@@ -316,12 +316,8 @@ render_line (list<StringText> subtitles, dcp::Size target, DCPTime time, int fra
size.height *= y_scale;
/* Shuffle the subtitle over by the border width (if we have any) so it's not cut off */
- int const x_offset = ceil (border_width);
- /* Move down a bit so that accents on capital letters can be seen */
- int const y_offset = target.height / 100.0;
-
- size.width += x_offset;
- size.height += y_offset;
+ int const x_offset = (-ink.get_x() / Pango::SCALE) + ceil(border_width);
+ int const y_offset = -ink.get_y() / Pango::SCALE + ceil(border_width);
auto image = create_image (size);
auto surface = create_surface (image);