]> git.lyx.org Git - lyx.git/blobdiff - src/insets/InsetIPAMacro.cpp
Rename LATEX debug level to OUTFILE and use it for DocBook, HTML, and XML messages.
[lyx.git] / src / insets / InsetIPAMacro.cpp
index f8888ce96e7b4cd021128de71826fa65cec67d69..a529d04b08ddfbf92078592dfec1bdf09f71ab87 100644 (file)
 #include "BufferParams.h"
 #include "Dimension.h"
 #include "Encoding.h"
-#include "Font.h"
+#include "FontInfo.h"
 #include "FuncRequest.h"
 #include "FuncStatus.h"
+#include "InsetLayout.h"
 #include "LaTeXFeatures.h"
 #include "Lexer.h"
 #include "MetricsInfo.h"
-#include "output_xhtml.h"
+#include "xml.h"
+#include "texstream.h"
 
 #include "frontends/FontMetrics.h"
 #include "frontends/Painter.h"
@@ -59,14 +61,16 @@ IPADecoTranslatorLoc const init_ipadecotranslator_loc()
 
 IPADecoTranslator const & ipadecotranslator()
 {
-       static IPADecoTranslator decotranslator = init_ipadecotranslator();
+       static IPADecoTranslator const decotranslator =
+                       init_ipadecotranslator();
        return decotranslator;
 }
 
 
 IPADecoTranslatorLoc const & ipadecotranslator_loc()
 {
-       static IPADecoTranslatorLoc translator = init_ipadecotranslator_loc();
+       static IPADecoTranslatorLoc const translator =
+           init_ipadecotranslator_loc();
        return translator;
 }
 
@@ -86,11 +90,12 @@ IPACharTranslator const init_ipachartranslator()
 
 IPACharTranslator const & ipachartranslator()
 {
-       static IPACharTranslator chartranslator = init_ipachartranslator();
+       static IPACharTranslator const chartranslator =
+           init_ipachartranslator();
        return chartranslator;
 }
 
-} // anon
+} // namespace
 
 
 InsetIPADecoParams::InsetIPADecoParams()
@@ -121,7 +126,7 @@ void InsetIPADecoParams::read(Lexer & lex)
 /////////////////////////////////////////////////////////////////////
 
 InsetIPADeco::InsetIPADeco(Buffer * buf, string const & label)
-       : InsetCollapsable(buf)
+       : InsetCollapsible(buf)
 {
        setDrawFrame(true);
        setFrameColor(Color_insetframe);
@@ -142,7 +147,7 @@ docstring InsetIPADeco::layoutName() const
 void InsetIPADeco::metrics(MetricsInfo & mi, Dimension & dim) const
 {
        InsetText::metrics(mi, dim);
-       
+
        if (params_.type == InsetIPADecoParams::Toptiebar) {
                // consider width of the inset label
                FontInfo font(getLayout().labelfont());
@@ -169,21 +174,18 @@ void InsetIPADeco::metrics(MetricsInfo & mi, Dimension & dim) const
                theFontMetrics(font).rectText(label, w, a, d);
                dim.des += int(d * 1.5);
        }
-
-       // cache the inset dimension
-       setDimCache(mi, dim);
 }
 
 
 void InsetIPADeco::draw(PainterInfo & pi, int x, int y) const
 {
        // draw the text
-       InsetCollapsable::draw(pi, x, y);
+       InsetCollapsible::draw(pi, x, y);
 
        // draw the inset marker
        drawMarkers(pi, x, y);
 
-       Dimension const dim = Inset::dimension(*pi.base.bv);
+       Dimension const dim = dimension(*pi.base.bv);
 
        if (params_.type == InsetIPADecoParams::Toptiebar) {
                FontInfo font(getLayout().labelfont());
@@ -222,14 +224,14 @@ void InsetIPADeco::draw(PainterInfo & pi, int x, int y) const
 void InsetIPADeco::write(ostream & os) const
 {
        params_.write(os);
-       InsetCollapsable::write(os);
+       InsetCollapsible::write(os);
 }
 
 
 void InsetIPADeco::read(Lexer & lex)
 {
        params_.read(lex);
-       InsetCollapsable::read(lex);
+       InsetCollapsible::read(lex);
 }
 
 
@@ -276,7 +278,7 @@ void InsetIPADeco::latex(otexstream & os, OutputParams const & runparams) const
                os << "\\texttoptiebar{";
        else if (params_.type == InsetIPADecoParams::Bottomtiebar)
                os << "\\textbottomtiebar{";
-       InsetCollapsable::latex(os, runparams);
+       InsetCollapsible::latex(os, runparams);
        os << "}";
 }
 
@@ -285,11 +287,11 @@ int InsetIPADeco::plaintext(odocstringstream & os,
                            OutputParams const & runparams, size_t max_length) const
 {
        odocstringstream ods;
-       int h = (int)(InsetCollapsable::plaintext(ods, runparams, max_length) / 2);
+       int h = 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());
-       
+
        if (params_.type == InsetIPADecoParams::Toptiebar) {
                os << before;
                os.put(0x0361);
@@ -304,19 +306,31 @@ int InsetIPADeco::plaintext(odocstringstream & os,
 }
 
 
-int InsetIPADeco::docbook(odocstream & os, OutputParams const & runparams) const
+void InsetIPADeco::docbook(XMLStream & xs, OutputParams const & runparams) const
 {
-       // FIXME: Any docbook option here?
-       return InsetCollapsable::docbook(os, runparams);
+       // 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());
+
+       xs << XMLStream::ESCAPE_NONE << before;
+       if (params_.type == InsetIPADecoParams::Toptiebar)
+               xs << XMLStream::ESCAPE_NONE << "&#x0361;";
+       else if (params_.type == InsetIPADecoParams::Bottomtiebar)
+               xs << XMLStream::ESCAPE_NONE << "&#x035c;";
+       xs << XMLStream::ESCAPE_NONE << after;
 }
 
 
-docstring InsetIPADeco::xhtml(XHTMLStream & 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 InsetCollapsable::xhtml(xs, runparams);
+       return InsetCollapsible::xhtml(xs, runparams);
 }
 
 
@@ -354,8 +368,7 @@ void InsetIPADeco::string2params(string const & in, InsetIPADecoParams & params)
 
 void InsetIPADeco::validate(LaTeXFeatures & features) const
 {
-       if (!buffer_->params().useNonTeXFonts)
-               features.require("tipa");
+       features.require("tipa");
        InsetText::validate(features);
 }
 
@@ -381,7 +394,7 @@ bool InsetIPADeco::insetAllowed(InsetCode code) const
 
 
 InsetIPAChar::InsetIPAChar(Kind k)
-       : Inset(0), kind_(k)
+       : Inset(nullptr), kind_(k)
 {}
 
 
@@ -410,7 +423,6 @@ void InsetIPAChar::metrics(MetricsInfo & mi, Dimension & dim) const
        }
        docstring ds(s.begin(), s.end());
        dim.wid = fm.width(ds);
-       setDimCache(mi, dim);
 }
 
 
@@ -541,45 +553,57 @@ int InsetIPAChar::plaintext(odocstringstream & os, OutputParams const &, size_t)
 }
 
 
-int InsetIPAChar::docbook(odocstream & /*os*/, OutputParams const &) const
+void InsetIPAChar::docbook(XMLStream & xs, OutputParams const &) const
 {
        switch (kind_) {
-       // FIXME
-       LYXERR0("IPA tone macros not yet implemented with DocBook!");
        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;
        }
-       return 0;
 }
 
 
-docstring InsetIPAChar::xhtml(XHTMLStream & xs, OutputParams const &) const
+docstring InsetIPAChar::xhtml(XMLStream & xs, OutputParams const &) const
 {
        switch (kind_) {
        case TONE_FALLING:
-               xs << XHTMLStream::ESCAPE_NONE << "&#x2e5;"
-                  << XHTMLStream::ESCAPE_NONE << "&#x2e9;";
+               xs << XMLStream::ESCAPE_NONE << "&#x2e5;"
+                  << XMLStream::ESCAPE_NONE << "&#x2e9;";
                break;
        case TONE_RISING:
-               xs << XHTMLStream::ESCAPE_NONE << "&#x2e9;"
-                  << XHTMLStream::ESCAPE_NONE << "&#x2e5;";
+               xs << XMLStream::ESCAPE_NONE << "&#x2e9;"
+                  << XMLStream::ESCAPE_NONE << "&#x2e5;";
                break;
        case TONE_HIGH_RISING:
-               xs << XHTMLStream::ESCAPE_NONE << "&#x2e7;"
-                  << XHTMLStream::ESCAPE_NONE << "&#x2e5;";
+               xs << XMLStream::ESCAPE_NONE << "&#x2e7;"
+                  << XMLStream::ESCAPE_NONE << "&#x2e5;";
                break;
        case TONE_LOW_RISING:
-               xs << XHTMLStream::ESCAPE_NONE << "&#x2e9;"
-                  << XHTMLStream::ESCAPE_NONE << "&#x2e7;";
+               xs << XMLStream::ESCAPE_NONE << "&#x2e9;"
+                  << XMLStream::ESCAPE_NONE << "&#x2e7;";
                break;
        case TONE_HIGH_RISING_FALLING:
-               xs << XHTMLStream::ESCAPE_NONE << "&#x2e8;"
-                  << XHTMLStream::ESCAPE_NONE << "&#x2e5;"
-                  << XHTMLStream::ESCAPE_NONE << "&#x2e8;";
+               xs << XMLStream::ESCAPE_NONE << "&#x2e8;"
+                  << XMLStream::ESCAPE_NONE << "&#x2e5;"
+                  << XMLStream::ESCAPE_NONE << "&#x2e8;";
                break;
        }
        return docstring();
@@ -594,7 +618,7 @@ void InsetIPAChar::toString(odocstream & os) const
 }
 
 
-void InsetIPAChar::forToc(docstring & os, size_t) const
+void InsetIPAChar::forOutliner(docstring & os, size_t const, bool const) const
 {
        odocstringstream ods;
        plaintext(ods, OutputParams(0));
@@ -610,8 +634,7 @@ void InsetIPAChar::validate(LaTeXFeatures & features) const
        case TONE_HIGH_RISING:
        case TONE_LOW_RISING:
        case TONE_HIGH_RISING_FALLING:
-               if (!buffer_->params().useNonTeXFonts)
-                       features.require("tone");
+               features.require("tone");
                break;
        default:
                break;
@@ -619,16 +642,4 @@ void InsetIPAChar::validate(LaTeXFeatures & features) const
 }
 
 
-bool InsetIPAChar::isLetter() const
-{
-       return true;
-}
-
-
-bool InsetIPAChar::isLineSeparator() const
-{
-       return false;
-}
-
-
 } // namespace lyx