42 #include "compose.hpp"
48 using std::shared_ptr;
52 order::Font::Font(shared_ptr<TextString> s, Standard standard)
55 if (standard == Standard::SMPTE) {
56 _values[
"ID"] = s->font().get ();
58 _values[
"Id"] = s->font().get ();
61 _values[
"Italic"] = s->italic() ?
"yes" :
"no";
62 _values[
"Color"] = s->colour().to_argb_string();
63 _values[
"Size"] = raw_convert<string> (s->size());
64 _values[
"AspectAdjust"] = raw_convert<string>(s->aspect_adjust(), 1,
true);
65 _values[
"Effect"] = effect_to_string (s->effect());
66 _values[
"EffectColor"] = s->effect_colour().to_argb_string();
67 _values[
"Script"] =
"normal";
68 if (standard == Standard::SMPTE) {
69 _values[
"Underline"] = s->underline() ?
"yes" :
"no";
71 _values[
"Underlined"] = s->underline() ?
"yes" :
"no";
73 _values[
"Weight"] = s->bold() ?
"bold" :
"normal";
78 order::Font::as_xml (xmlpp::Element* parent,
Context&)
const
80 auto e = cxml::add_child(parent,
"Font");
81 for (
const auto& i: _values) {
82 e->set_attribute (i.first, i.second);
94 map<string, string> inter;
96 for (
auto const& i: other._values) {
97 auto t = _values.find (i.first);
98 if (t != _values.end() && t->second == i.second) {
111 map<string, string> diff;
112 for (
auto const& i: _values) {
113 if (other._values.find (i.first) == other._values.end()) {
123 order::Font::empty ()
const
125 return _values.empty ();
130 order::Part::as_xml (xmlpp::Element* parent,
Context &)
const
137 order::String::as_xml (xmlpp::Element* parent,
Context& context)
const
140 auto space = cxml::add_child(parent,
"Space");
141 auto size = raw_convert<string>(_space_before, 2);
142 if (context.standard == Standard::INTEROP) {
145 space->set_attribute(
"Size", size);
147 parent->add_child_text (_text);
153 order::Part::write_xml (xmlpp::Element* parent,
order::Context& context)
const
155 if (!font.empty ()) {
156 parent = font.as_xml (parent, context);
159 parent = as_xml (parent, context);
161 for (
auto i: children) {
162 i->write_xml (parent, context);
168 position_align (xmlpp::Element* e,
order::Context& context,
HAlign h_align,
float h_position,
VAlign v_align,
float v_position,
float z_position)
171 if (context.standard == Standard::SMPTE) {
172 e->set_attribute (
"Halign", halign_to_string (h_align));
174 e->set_attribute (
"HAlign", halign_to_string (h_align));
179 if (context.standard == Standard::SMPTE) {
180 e->set_attribute (
"Hposition", raw_convert<string> (h_position * 100, 6));
182 e->set_attribute (
"HPosition", raw_convert<string> (h_position * 100, 6));
186 if (context.standard == Standard::SMPTE) {
187 e->set_attribute (
"Valign", valign_to_string (v_align));
189 e->set_attribute (
"VAlign", valign_to_string (v_align));
193 if (context.standard == Standard::SMPTE) {
194 e->set_attribute (
"Vposition", raw_convert<string> (v_position * 100, 6));
196 e->set_attribute (
"VPosition", raw_convert<string> (v_position * 100, 6));
199 if (context.standard == Standard::SMPTE) {
200 e->set_attribute (
"Vposition",
"0");
202 e->set_attribute (
"VPosition",
"0");
206 if (fabs(z_position) >
ALIGN_EPSILON && context.standard == Standard::SMPTE) {
207 e->set_attribute(
"Zposition", raw_convert<string>(z_position * 100, 6));
213 order::Text::as_xml (xmlpp::Element* parent,
Context& context)
const
215 auto e = cxml::add_child(parent,
"Text");
217 position_align(e, context, _h_align, _h_position, _v_align, _v_position, _z_position);
222 if (_direction !=
Direction::LTR && context.standard == Standard::SMPTE) {
223 e->set_attribute (
"Direction", direction_to_string (_direction));
226 for (
auto const& ruby: _rubies) {
227 auto xml = cxml::add_child(e,
"Ruby");
228 cxml::add_child(xml,
"Rb")->add_child_text(ruby.base);
229 auto rt = cxml::add_child(xml,
"Rt");
230 rt->add_child_text(ruby.annotation);
231 rt->set_attribute(
"Size", dcp::raw_convert<string>(ruby.size, 6));
232 rt->set_attribute(
"Position", ruby.position == RubyPosition::BEFORE ?
"before" :
"after");
233 rt->set_attribute(
"Offset", dcp::raw_convert<string>(ruby.offset, 6));
234 rt->set_attribute(
"Spacing", dcp::raw_convert<string>(ruby.spacing, 6));
235 rt->set_attribute(
"AspectAdjust", dcp::raw_convert<string>(ruby.aspect_adjust, 6));
243 order::Subtitle::as_xml (xmlpp::Element* parent,
Context& context)
const
245 auto e = cxml::add_child(parent,
"Subtitle");
246 e->set_attribute (
"SpotNumber", raw_convert<string> (context.spot_number++));
247 e->set_attribute (
"TimeIn", _in.rebase(context.time_code_rate).as_string(context.standard));
248 e->set_attribute (
"TimeOut", _out.rebase(context.time_code_rate).as_string(context.standard));
249 if (context.standard == Standard::SMPTE) {
250 e->set_attribute (
"FadeUpTime", _fade_up.rebase(context.time_code_rate).as_string(context.standard));
251 e->set_attribute (
"FadeDownTime", _fade_down.rebase(context.time_code_rate).as_string(context.standard));
253 e->set_attribute (
"FadeUpTime", raw_convert<string> (_fade_up.as_editable_units_ceil(context.time_code_rate)));
254 e->set_attribute (
"FadeDownTime", raw_convert<string> (_fade_down.as_editable_units_ceil(context.time_code_rate)));
261 order::Font::operator== (Font
const & other)
const
263 return _values == other._values;
268 order::Font::clear ()
275 order::Image::as_xml (xmlpp::Element* parent,
Context& context)
const
277 auto e = cxml::add_child(parent,
"Image");
279 position_align(e, context, _h_align, _h_position, _v_align, _v_position, _z_position);
280 if (context.standard == Standard::SMPTE) {
281 e->add_child_text (
"urn:uuid:" + _id);
283 e->add_child_text (_id +
".png");
void take_difference(Font other)
void take_intersection(Font other)
Namespace for everything in libdcp.
@ CENTER
horizontal position is distance from centre of screen to centre of subtitle
constexpr float SPACE_BEFORE_EPSILON
constexpr float ALIGN_EPSILON
Internal TextAsset helpers.