diff options
| author | Carl Hetherington <cth@carlh.net> | 2022-11-30 22:08:00 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2022-12-01 09:21:38 +0100 |
| commit | 99cb0937e54340fa20c594aaa501276b8321cbf0 (patch) | |
| tree | 2528f0ad27d870c33c76d0cb11892c81f1ab3a69 /src/lib | |
| parent | efb1172f51bbe15cd1f90b25a032bbe858453f5f (diff) | |
Escape entities just before Pango rendering (#2382).v2.16.35
Previously, text coming out of the player would have things like
& escaped to &. This escaping is also done by libxml++ when
writing XML, so doing it in the player would mean it was done
twice.
We do, however, need to escape things before passing them to Pango
as otherwise it gives errors and renders nothing for the line.
Here we move the escaping to just before the rendering, meaning
that in the reset of DoM we should pass unescaped strings around.
Diffstat (limited to 'src/lib')
| -rw-r--r-- | src/lib/render_text.cc | 5 | ||||
| -rw-r--r-- | src/lib/text_decoder.cc | 18 |
2 files changed, 7 insertions, 16 deletions
diff --git a/src/lib/render_text.cc b/src/lib/render_text.cc index d3db4ac19..2338bde97 100644 --- a/src/lib/render_text.cc +++ b/src/lib/render_text.cc @@ -103,6 +103,11 @@ marked_up (list<StringText> subtitles, int target_height, float fade_factor, str span += " " + extra_attribute; } span += ">"; + + boost::algorithm::replace_all(text, "&", "&"); + boost::algorithm::replace_all(text, "<", "<"); + boost::algorithm::replace_all(text, ">", ">"); + span += text; span += "</span>"; return span; diff --git a/src/lib/text_decoder.cc b/src/lib/text_decoder.cc index 4b521ede7..750deb9b3 100644 --- a/src/lib/text_decoder.cc +++ b/src/lib/text_decoder.cc @@ -66,20 +66,6 @@ TextDecoder::emit_bitmap_start (ContentBitmapText const& bitmap) static -string -escape_text (string text) -{ - /* We must escape some things, otherwise they might confuse our subtitle - renderer (which uses entities and some HTML-esque markup to do bold/italic etc.) - */ - boost::algorithm::replace_all(text, "&", "&"); - boost::algorithm::replace_all(text, "<", "<"); - boost::algorithm::replace_all(text, ">", ">"); - return text; -} - - -static void set_forced_appearance(shared_ptr<const TextContent> content, StringText& subtitle) { @@ -113,7 +99,7 @@ TextDecoder::emit_plain_start (ContentTime from, vector<dcp::SubtitleString> sub content()->get_font(subtitle.font().get_value_or("")), valign_standard ); - string_text.set_text(escape_text(string_text.text())); + string_text.set_text(string_text.text()); set_forced_appearance(content(), string_text); string_texts.push_back(string_text); } @@ -257,7 +243,7 @@ TextDecoder::emit_plain_start (ContentTime from, sub::Subtitle const & sub_subti v_align, 0, dcp::Direction::LTR, - escape_text(block.text), + block.text, dcp::Effect::NONE, block.effect_colour.get_value_or(sub::Colour(0, 0, 0)).dcp(), /* Hack: we should use subtitle.fade_up and subtitle.fade_down here |
