diff options
| author | Carl Hetherington <cth@carlh.net> | 2026-03-07 23:48:43 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2026-03-07 23:48:43 +0100 |
| commit | daceaad12cc73404f93d5aae0dd896fcb7b9d3b9 (patch) | |
| tree | 7dc80711804d23bdcc0987d1372f326f03124c2a /src/text_string.cc | |
| parent | f0cada65396759b4be19601d8537119a1bb4fbfa (diff) | |
wip: ruby2652-ruby
Diffstat (limited to 'src/text_string.cc')
| -rw-r--r-- | src/text_string.cc | 120 |
1 files changed, 104 insertions, 16 deletions
diff --git a/src/text_string.cc b/src/text_string.cc index 12e86fce..baa7832b 100644 --- a/src/text_string.cc +++ b/src/text_string.cc @@ -40,6 +40,7 @@ #include "compose.hpp" #include "text_string.h" #include "xml.h" +#include <fmt/format.h> #include <cmath> @@ -51,6 +52,7 @@ using std::shared_ptr; using std::string; using std::vector; using boost::optional; +using boost::variant; using namespace dcp; @@ -76,8 +78,7 @@ TextString::TextString( Colour effect_colour, Time fade_up_time, Time fade_down_time, - float space_before, - vector<Ruby> rubies + float space_before ) : Text(in, out, h_position, h_align, v_position, v_align, z_position, variable_z_positions, fade_up_time, fade_down_time) , _font (font) @@ -92,7 +93,90 @@ TextString::TextString( , _effect (effect) , _effect_colour (effect_colour) , _space_before (space_before) - , _rubies(rubies) +{ + _aspect_adjust = max(min(_aspect_adjust, 4.0f), 0.25f); +} + + +TextString::TextString( + optional<string> font, + bool italic, + bool bold, + bool underline, + Colour colour, + int size, + float aspect_adjust, + Time in, + Time out, + float h_position, + HAlign h_align, + float v_position, + VAlign v_align, + float z_position, + vector<VariableZPosition> variable_z_positions, + Direction direction, + Ruby text, + Effect effect, + Colour effect_colour, + Time fade_up_time, + Time fade_down_time, + float space_before + ) + : Text(in, out, h_position, h_align, v_position, v_align, z_position, variable_z_positions, fade_up_time, fade_down_time) + , _font(font) + , _italic(italic) + , _bold(bold) + , _underline(underline) + , _colour(colour) + , _size(size) + , _aspect_adjust(aspect_adjust) + , _direction(direction) + , _text(text) + , _effect(effect) + , _effect_colour(effect_colour) + , _space_before(space_before) +{ + _aspect_adjust = max(min(_aspect_adjust, 4.0f), 0.25f); +} + + +TextString::TextString( + optional<string> font, + bool italic, + bool bold, + bool underline, + Colour colour, + int size, + float aspect_adjust, + Time in, + Time out, + float h_position, + HAlign h_align, + float v_position, + VAlign v_align, + float z_position, + vector<VariableZPosition> variable_z_positions, + Direction direction, + variant<string, Ruby> text, + Effect effect, + Colour effect_colour, + Time fade_up_time, + Time fade_down_time, + float space_before + ) + : Text(in, out, h_position, h_align, v_position, v_align, z_position, variable_z_positions, fade_up_time, fade_down_time) + , _font(font) + , _italic(italic) + , _bold(bold) + , _underline(underline) + , _colour(colour) + , _size(size) + , _aspect_adjust(aspect_adjust) + , _direction(direction) + , _text(text) + , _effect(effect) + , _effect_colour(effect_colour) + , _space_before(space_before) { _aspect_adjust = max(min(_aspect_adjust, 4.0f), 0.25f); } @@ -135,8 +219,7 @@ dcp::operator==(TextString const & a, TextString const & b) a.effect_colour() == b.effect_colour() && a.fade_up_time() == b.fade_up_time() && a.fade_down_time() == b.fade_down_time() && - fabs (a.space_before() - b.space_before()) < SPACE_BEFORE_EPSILON && - a.rubies() == b.rubies() + fabs (a.space_before() - b.space_before()) < SPACE_BEFORE_EPSILON ); } @@ -151,7 +234,15 @@ dcp::operator!=(TextString const & a, TextString const & b) ostream& dcp::operator<<(ostream& s, TextString const & sub) { - s << "\n`" << sub.text() << "' from " << sub.in() << " to " << sub.out() << ";\n" + s << "\n`"; + + if (sub.string_text()) { + s << *sub.string_text(); + } else { + s << "[Ruby]"; + } + + s << "' from " << sub.in() << " to " << sub.out() << ";\n" << "fade up " << sub.fade_up_time() << ", fade down " << sub.fade_down_time() << ";\n" << "font " << sub.font().get_value_or ("[default]") << ", "; @@ -181,10 +272,6 @@ dcp::operator<<(ostream& s, TextString const & sub) << ", effect colour (" << sub.effect_colour().r << ", " << sub.effect_colour().g << ", " << sub.effect_colour().b << ")" << ", space before " << sub.space_before(); - for (auto ruby: sub.rubies()) { - s << ", ruby " << ruby.base << " " << ruby.annotation; - } - return s; } @@ -245,7 +332,13 @@ TextString::equals(shared_ptr<const Text> other_sub, EqualityOptions const& opti } if (_text != other->_text) { - note(NoteType::ERROR, String::compose("text text differs: %1 vs %2", _text, other->_text)); + if ((!string_text() && ruby_text()) || (string_text() && !ruby_text())) { + note(NoteType::ERROR, "text text differs: one is a ruby and the other a string"); + } else if (string_text()) { + note(NoteType::ERROR, fmt::format("text text differs: {} vs {}", *string_text(), *other->string_text())); + } else { + note(NoteType::ERROR, "text text differs: rubies differ"); + } same = false; } @@ -264,11 +357,6 @@ TextString::equals(shared_ptr<const Text> other_sub, EqualityOptions const& opti same = false; } - if (_rubies != other->_rubies) { - note(NoteType::ERROR, "rubies differ"); - same = false; - } - return same; } |
