Serialise phonetic runs and properties

This commit is contained in:
Kostas Dizas 2018-11-21 12:58:48 +00:00
parent e9c23c3fc7
commit 38f12ff846
No known key found for this signature in database
GPG Key ID: 8D3074191407AC9E
2 changed files with 84 additions and 2 deletions

View File

@ -2999,11 +2999,34 @@ rich_text xlsx_consumer::read_rich_text(const xml::qname &parent)
}
else if (text_element == xml::qname(xmlns, "rPh"))
{
skip_remaining_content(text_element);
phonetic_run pr;
pr.start = parser().attribute<std::uint32_t>("sb");
pr.end = parser().attribute<std::uint32_t>("eb");
expect_start_element(xml::qname(xmlns, "t"), xml::content::simple);
pr.text = read_text();
if (parser().attribute_present(xml_space))
{
pr.preserve_space = parser().attribute(xml_space) == "preserve";
}
expect_end_element(xml::qname(xmlns, "t"));
t.add_phonetic_run(pr);
}
else if (text_element == xml::qname(xmlns, "phoneticPr"))
{
skip_remaining_content(text_element);
phonetic_pr ph(parser().attribute<std::uint32_t>("fontId"));
if (parser().attribute_present("type"))
{
ph.type(phonetic_pr::type_from_string(parser().attribute("type")));
}
if (parser().attribute_present("alignment"))
{
ph.alignment(phonetic_pr::alignment_from_string(parser().attribute("alignment")));
}
t.phonetic_properties(ph);
}
else
{

View File

@ -862,6 +862,36 @@ void xlsx_producer::write_shared_string_table(const relationship & /*rel*/)
write_characters(string.second.plain_text(), string.second.runs().front().preserve_space);
write_end_element(xmlns, "t");
for (const auto &run : string.second.phonetic_runs())
{
write_start_element(xmlns, "rPh");
write_attribute("eb", run.end);
write_attribute("sb", run.start);
write_start_element(xmlns, "t");
write_characters(run.text, run.preserve_space);
write_end_element(xmlns, "t");
write_end_element(xmlns, "rPh");
}
if (string.second.has_phonetic_properties())
{
write_start_element(xmlns, phonetic_pr::Serialised_ID());
const auto &ph_props = string.second.phonetic_properties();
write_attribute("fontId", ph_props.font_id());
if (ph_props.has_type())
{
write_attribute("type", phonetic_pr::type_as_string(ph_props.type()));
}
if (ph_props.has_alignment())
{
write_attribute("alignment", phonetic_pr::alignment_as_string(ph_props.alignment()));
}
write_end_element(xmlns, phonetic_pr::Serialised_ID());
}
write_end_element(xmlns, "si");
continue;
@ -927,6 +957,35 @@ void xlsx_producer::write_shared_string_table(const relationship & /*rel*/)
write_end_element(xmlns, "r");
}
for (const auto &run : string.second.phonetic_runs())
{
write_start_element(xmlns, "rPh");
write_attribute("sb", run.start);
write_attribute("eb", run.end);
write_start_element(xmlns, "t");
write_characters(run.text, run.preserve_space);
write_end_element(xmlns, "t");
write_end_element(xmlns, "rPh");
}
if (string.second.has_phonetic_properties())
{
write_start_element(xmlns, phonetic_pr::Serialised_ID());
const auto &ph_props = string.second.phonetic_properties();
write_attribute("fontId", ph_props.font_id());
if (ph_props.has_type())
{
write_attribute("type", phonetic_pr::type_as_string(ph_props.type()));
}
if (ph_props.has_alignment())
{
write_attribute("alignment", phonetic_pr::alignment_as_string(ph_props.alignment()));
}
write_end_element(xmlns, phonetic_pr::Serialised_ID());
}
write_end_element(xmlns, "si");
}