]> git.lyx.org Git - lyx.git/blobdiff - src/insets/InsetIPAMacro.cpp
Fix bug #12795
[lyx.git] / src / insets / InsetIPAMacro.cpp
index a529d04b08ddfbf92078592dfec1bdf09f71ab87..2d4b1fb13c2d25e516f66fb462f5862c2dde3bd1 100644 (file)
@@ -283,14 +283,27 @@ void InsetIPADeco::latex(otexstream & os, OutputParams const & runparams) const
 }
 
 
-int InsetIPADeco::plaintext(odocstringstream & os,
-                           OutputParams const & runparams, size_t max_length) const
+namespace {
+std::pair<docstring, docstring> splitPlainTextInHalves(
+               const InsetIPADeco * inset, OutputParams const & runparams,
+               size_t max_length = INT_MAX)
 {
        odocstringstream ods;
-       int h = InsetCollapsible::plaintext(ods, runparams, max_length) / 2;
+       int h = inset->InsetCollapsible::plaintext(ods, runparams, max_length) / 2;
        docstring result = ods.str();
        docstring const before = result.substr(0, h);
        docstring const after = result.substr(h, result.size());
+       return {before, after};
+}
+}
+
+
+int InsetIPADeco::plaintext(odocstringstream & os,
+                           OutputParams const & runparams, size_t max_length) const
+{
+       docstring before;
+       docstring after;
+       tie(before, after) = splitPlainTextInHalves(this, runparams, max_length);
 
        if (params_.type == InsetIPADecoParams::Toptiebar) {
                os << before;
@@ -302,7 +315,7 @@ int InsetIPADeco::plaintext(odocstringstream & os,
                os.put(0x035c);
                os << after;
        }
-       return result.size();
+       return before.size() + after.size();
 }
 
 
@@ -310,11 +323,9 @@ void InsetIPADeco::docbook(XMLStream & xs, OutputParams const & runparams) const
 {
        // The special combining character must be put in the middle, between the two other characters.
        // It will not work if there is anything else than two pure characters, so going back to plaintext.
-       odocstringstream ods;
-       int h = InsetText::plaintext(ods, runparams) / 2;
-       docstring result = ods.str();
-       docstring const before = result.substr(0, h);
-       docstring const after = result.substr(h, result.size());
+       docstring before;
+       docstring after;
+       tie(before, after) = splitPlainTextInHalves(this, runparams);
 
        xs << XMLStream::ESCAPE_NONE << before;
        if (params_.type == InsetIPADecoParams::Toptiebar)
@@ -327,10 +338,10 @@ void InsetIPADeco::docbook(XMLStream & xs, OutputParams const & runparams) const
 
 docstring InsetIPADeco::xhtml(XMLStream & xs, OutputParams const & runparams) const
 {
-       // FIXME: Like in plaintext, the combining characters "&#x361;" (toptiebar)
-       // or "&#x35c;" (bottomtiebar) would need to be inserted just in the mid
-       // of the text string. (How) can this be done with the xhtml stream?
-       return InsetCollapsible::xhtml(xs, runparams);
+       // The DocBook encoding for this inset has no DocBook tag, but sheer XML (relying on a plaintext
+       // transformation of the inset).
+       docbook(xs, runparams);
+       return docstring();
 }
 
 
@@ -553,59 +564,34 @@ int InsetIPAChar::plaintext(odocstringstream & os, OutputParams const &, size_t)
 }
 
 
+namespace {
+std::string ipaCharToXMLEntity(InsetIPAChar::Kind kind) {
+       switch (kind) {
+       case InsetIPAChar::Kind::TONE_FALLING:
+               return "&#x2e5;&#x2e9;";
+       case InsetIPAChar::Kind::TONE_RISING:
+               return "&#x2e9;&#x2e5;";
+       case InsetIPAChar::Kind::TONE_HIGH_RISING:
+               return "&#x2e7;&#x2e5;";
+       case InsetIPAChar::Kind::TONE_LOW_RISING:
+               return "&#x2e9;&#x2e7;";
+       case InsetIPAChar::Kind::TONE_HIGH_RISING_FALLING:
+               return "&#x2e8;&#x2e5;&#x2e8;";
+       }
+       return "";
+}
+}
+
+
 void InsetIPAChar::docbook(XMLStream & xs, OutputParams const &) const
 {
-       switch (kind_) {
-       case TONE_FALLING:
-               xs << XMLStream::ESCAPE_NONE << "&#x2e5;";
-               xs << XMLStream::ESCAPE_NONE << "&#x2e9;";
-               break;
-       case TONE_RISING:
-               xs << XMLStream::ESCAPE_NONE << "&#x2e9;";
-               xs << XMLStream::ESCAPE_NONE << "&#x2e5;";
-               break;
-       case TONE_HIGH_RISING:
-               xs << XMLStream::ESCAPE_NONE << "&#x2e7;";
-               xs << XMLStream::ESCAPE_NONE << "&#x2e5;";
-               break;
-       case TONE_LOW_RISING:
-               xs << XMLStream::ESCAPE_NONE << "&#x2e9;";
-               xs << XMLStream::ESCAPE_NONE << "&#x2e7;";
-               break;
-       case TONE_HIGH_RISING_FALLING:
-               xs << XMLStream::ESCAPE_NONE << "&#x2e8;";
-               xs << XMLStream::ESCAPE_NONE << "&#x2e5;";
-               xs << XMLStream::ESCAPE_NONE << "&#x2e8;";
-               break;
-       }
+       xs << XMLStream::ESCAPE_NONE << from_ascii(ipaCharToXMLEntity(kind()));
 }
 
 
 docstring InsetIPAChar::xhtml(XMLStream & xs, OutputParams const &) const
 {
-       switch (kind_) {
-       case TONE_FALLING:
-               xs << XMLStream::ESCAPE_NONE << "&#x2e5;"
-                  << XMLStream::ESCAPE_NONE << "&#x2e9;";
-               break;
-       case TONE_RISING:
-               xs << XMLStream::ESCAPE_NONE << "&#x2e9;"
-                  << XMLStream::ESCAPE_NONE << "&#x2e5;";
-               break;
-       case TONE_HIGH_RISING:
-               xs << XMLStream::ESCAPE_NONE << "&#x2e7;"
-                  << XMLStream::ESCAPE_NONE << "&#x2e5;";
-               break;
-       case TONE_LOW_RISING:
-               xs << XMLStream::ESCAPE_NONE << "&#x2e9;"
-                  << XMLStream::ESCAPE_NONE << "&#x2e7;";
-               break;
-       case TONE_HIGH_RISING_FALLING:
-               xs << XMLStream::ESCAPE_NONE << "&#x2e8;"
-                  << XMLStream::ESCAPE_NONE << "&#x2e5;"
-                  << XMLStream::ESCAPE_NONE << "&#x2e8;";
-               break;
-       }
+       xs << XMLStream::ESCAPE_NONE << from_ascii(ipaCharToXMLEntity(kind()));
        return docstring();
 }