diff --git a/source/detail/serialization/xlsx_consumer.cpp b/source/detail/serialization/xlsx_consumer.cpp index 5788b78f..93a8701f 100644 --- a/source/detail/serialization/xlsx_consumer.cpp +++ b/source/detail/serialization/xlsx_consumer.cpp @@ -3026,7 +3026,7 @@ rich_text xlsx_consumer::read_rich_text(const xml::qname &parent) } else if (text_element == xml::qname(xmlns, "phoneticPr")) { - phonetic_pr ph(parser().attribute("fontId")); + phonetic_pr ph(parser().attribute("fontId")); if (parser().attribute_present("type")) { ph.type(phonetic_pr::type_from_string(parser().attribute("type"))); diff --git a/source/detail/serialization/xlsx_producer.cpp b/source/detail/serialization/xlsx_producer.cpp index 82d4f595..c477dc30 100644 --- a/source/detail/serialization/xlsx_producer.cpp +++ b/source/detail/serialization/xlsx_producer.cpp @@ -820,63 +820,97 @@ void xlsx_producer::write_rich_text(const std::string &ns, const xlnt::rich_text write_start_element(ns, "t"); write_characters(text.plain_text(), text.runs().front().preserve_space); write_end_element(ns, "t"); - return; + } + else + { + for (const auto &run : text.runs()) + { + write_start_element(ns, "r"); + + if (run.second.is_set()) + { + write_start_element(ns, "rPr"); + + if (run.second.get().bold()) + { + write_start_element(ns, "b"); + write_end_element(ns, "b"); + } + + if (run.second.get().has_size()) + { + write_start_element(ns, "sz"); + write_attribute("val", run.second.get().size()); + write_end_element(ns, "sz"); + } + + if (run.second.get().has_color()) + { + write_start_element(ns, "color"); + write_color(run.second.get().color()); + write_end_element(ns, "color"); + } + + if (run.second.get().has_name()) + { + write_start_element(ns, "rFont"); + write_attribute("val", run.second.get().name()); + write_end_element(ns, "rFont"); + } + + if (run.second.get().has_family()) + { + write_start_element(ns, "family"); + write_attribute("val", run.second.get().family()); + write_end_element(ns, "family"); + } + + if (run.second.get().has_scheme()) + { + write_start_element(ns, "scheme"); + write_attribute("val", run.second.get().scheme()); + write_end_element(ns, "scheme"); + } + + write_end_element(ns, "rPr"); + } + + write_element(ns, "t", run.first, run.preserve_space); + write_end_element(ns, "r"); + } + } + + for (const auto &run : text.phonetic_runs()) + { + write_start_element(ns, "rPh"); + write_attribute("sb", run.start); + write_attribute("eb", run.end); + write_start_element(ns, "t"); + write_characters(run.text, run.preserve_space); + write_end_element(ns, "t"); + write_end_element(ns, "rPh"); } - for (const auto &run : text.runs()) + if (text.has_phonetic_properties()) { - write_start_element(ns, "r"); + const auto &phonetic_properties = text.phonetic_properties(); - if (run.second.is_set()) + write_start_element(ns, "phoneticPr"); + write_attribute("fontId", phonetic_properties.font_id()); + + if (text.phonetic_properties().has_type()) { - write_start_element(ns, "rPr"); - - if (run.second.get().bold()) - { - write_start_element(ns, "b"); - write_end_element(ns, "b"); - } - - if (run.second.get().has_size()) - { - write_start_element(ns, "sz"); - write_attribute("val", run.second.get().size()); - write_end_element(ns, "sz"); - } - - if (run.second.get().has_color()) - { - write_start_element(ns, "color"); - write_color(run.second.get().color()); - write_end_element(ns, "color"); - } - - if (run.second.get().has_name()) - { - write_start_element(ns, "rFont"); - write_attribute("val", run.second.get().name()); - write_end_element(ns, "rFont"); - } - - if (run.second.get().has_family()) - { - write_start_element(ns, "family"); - write_attribute("val", run.second.get().family()); - write_end_element(ns, "family"); - } - - if (run.second.get().has_scheme()) - { - write_start_element(ns, "scheme"); - write_attribute("val", run.second.get().scheme()); - write_end_element(ns, "scheme"); - } - - write_end_element(ns, "rPr"); + const auto type = phonetic_properties.type(); + write_attribute("type", phonetic_properties.type_as_string(type)); } - write_element(ns, "t", run.first, run.preserve_space); - write_end_element(ns, "r"); + if (text.phonetic_properties().has_alignment()) + { + const auto alignment = phonetic_properties.alignment(); + write_attribute("alignment", phonetic_properties.alignment_as_string(alignment)); + } + + write_end_element(ns, "phoneticPr"); } }