mirror of
https://github.com/tfussell/xlnt.git
synced 2024-03-22 13:11:17 +08:00
Serialise phonetic runs and properties
This commit is contained in:
parent
e9c23c3fc7
commit
38f12ff846
|
@ -2999,11 +2999,34 @@ rich_text xlsx_consumer::read_rich_text(const xml::qname &parent)
|
||||||
}
|
}
|
||||||
else if (text_element == xml::qname(xmlns, "rPh"))
|
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"))
|
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
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -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_characters(string.second.plain_text(), string.second.runs().front().preserve_space);
|
||||||
|
|
||||||
write_end_element(xmlns, "t");
|
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");
|
write_end_element(xmlns, "si");
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
|
@ -927,6 +957,35 @@ void xlsx_producer::write_shared_string_table(const relationship & /*rel*/)
|
||||||
write_end_element(xmlns, "r");
|
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");
|
write_end_element(xmlns, "si");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user