]> git.lyx.org Git - lyx.git/blobdiff - src/paragraph.C
fix crash in mathhullinset
[lyx.git] / src / paragraph.C
index 72d73583033b0ce91ed46b8099d425093533fa38..d39d43403975ae77404bfc57d963b5c3f1df4c42 100644 (file)
@@ -53,7 +53,6 @@
 
 using lyx::pos_type;
 
-using lyx::support::contains;
 using lyx::support::subst;
 
 using std::distance;
@@ -929,8 +928,6 @@ bool Paragraph::simpleTeXOnePar(Buffer const & buf,
                basefont = getLayoutFont(bparams, outerfont);
        }
 
-       bool const moving_arg = runparams.moving_arg | style->needprotect;
-
        // Which font is currently active?
        LyXFont running_font(basefont);
        // Do we have an open font change?
@@ -947,7 +944,8 @@ bool Paragraph::simpleTeXOnePar(Buffer const & buf,
                        ++column;
                }
                if (!asdefault)
-                       column += startTeXParParams(bparams, os, moving_arg);
+                       column += startTeXParParams(bparams, os, 
+                                                   runparams.moving_arg);
        }
 
        for (pos_type i = 0; i < size(); ++i) {
@@ -971,7 +969,7 @@ bool Paragraph::simpleTeXOnePar(Buffer const & buf,
 
                        if (!asdefault)
                                column += startTeXParParams(bparams, os,
-                                                           moving_arg);
+                                                           runparams.moving_arg);
                }
 
                value_type c = getChar(i);
@@ -1029,7 +1027,6 @@ bool Paragraph::simpleTeXOnePar(Buffer const & buf,
                running_change = change;
 
                OutputParams rp = runparams;
-               rp.moving_arg = moving_arg;
                rp.free_spacing = style->free_spacing;
                rp.local_language = font.language()->babel();
                rp.intitle = style->intitle;
@@ -1073,7 +1070,7 @@ bool Paragraph::simpleTeXOnePar(Buffer const & buf,
        }
 
        if (!asdefault) {
-               column += endTeXParParams(bparams, os, moving_arg);
+               column += endTeXParParams(bparams, os, runparams.moving_arg);
        }
 
        lyxerr[Debug::LATEX] << "SimpleTeXOnePar...done " << this << endl;
@@ -1331,14 +1328,40 @@ void Paragraph::simpleLinuxDocOnePar(Buffer const & buf,
 }
 
 
-string Paragraph::getDocbookId() const
+bool Paragraph::emptyTag() const
+{
+       for (pos_type i = 0; i < size(); ++i) {
+               if (isInset(i)) {
+                       InsetBase const * inset = getInset(i);
+                       InsetBase::Code lyx_code = inset->lyxCode();
+                       if (lyx_code != InsetBase::TOC_CODE and
+                           lyx_code != InsetBase::INCLUDE_CODE and
+                           lyx_code != InsetBase::GRAPHICS_CODE and
+                           lyx_code != InsetBase::ERT_CODE and
+                           lyx_code != InsetBase::FLOAT_CODE and
+                           lyx_code != InsetBase::TABULAR_CODE) {
+                               return false;
+                       }
+               } else {
+                       char c = getChar(i);
+                       if(c!= ' ' and c!= '\t')
+                               return false;
+               }
+
+       }
+       return true;
+}
+
+
+string Paragraph::getID(Buffer const & buf, OutputParams const & runparams) const
 {
        for (pos_type i = 0; i < size(); ++i) {
                if (isInset(i)) {
                        InsetBase const * inset = getInset(i);
                        InsetBase::Code lyx_code = inset->lyxCode();
                        if (lyx_code == InsetBase::LABEL_CODE) {
-                               return static_cast<InsetCommand const *>(inset)->getContents();
+                               string const id = static_cast<InsetCommand const *>(inset)->getContents();
+                               return "id=\"" + sgml::cleanID(buf, runparams, id) + "\"";
                        }
                }
 
@@ -1350,7 +1373,6 @@ string Paragraph::getDocbookId() const
 pos_type Paragraph::getFirstWord(Buffer const & buf, ostream & os, OutputParams const & runparams) const
 {
        pos_type i;
-       LyXLayout_ptr const & style = layout();
        for (i = 0; i < size(); ++i) {
                if (isInset(i)) {
                        InsetBase const * inset = getInset(i);
@@ -1363,15 +1385,31 @@ pos_type Paragraph::getFirstWord(Buffer const & buf, ostream & os, OutputParams
                        string str;
                        boost::tie(ws, str) = sgml::escapeChar(c);
 
-                       if (style->pass_thru)
-                               os << c;
-                       else
-                               os << str;
+                       os << str;
                }
        }
        return i;
 }
 
+
+bool Paragraph::onlyText(Buffer const & buf, LyXFont const & outerfont, pos_type initial) const
+{
+       LyXLayout_ptr const & style = layout();
+       LyXFont font_old;
+
+       for (pos_type i = initial; i < size(); ++i) {
+               LyXFont font = getFont(buf.params(), i, outerfont);
+               if (isInset(i))
+                       return false;
+               if ( i != initial and font != font_old)
+                       return false;
+               font_old = font;
+       }
+
+       return true;
+}
+
+
 void Paragraph::simpleDocBookOnePar(Buffer const & buf,
                                    ostream & os,
                                    OutputParams const & runparams,
@@ -1384,7 +1422,8 @@ void Paragraph::simpleDocBookOnePar(Buffer const & buf,
        LyXFont font_old =
                style->labeltype == LABEL_MANUAL ? style->labelfont : style->font;
 
-       bool cdata = (style->latexparam() == "CDATA");
+       if (style->pass_thru and not onlyText(buf, outerfont, initial))
+               os << "]]>";
        // parsing main loop
        for (pos_type i = initial; i < size(); ++i) {
                LyXFont font = getFont(buf.params(), i, outerfont);
@@ -1392,29 +1431,17 @@ void Paragraph::simpleDocBookOnePar(Buffer const & buf,
                // handle <emphasis> tag
                if (font_old.emph() != font.emph()) {
                        if (font.emph() == LyXFont::ON) {
-                               if (cdata)
-                                       os << "]]>";
                                os << "<emphasis>";
-                               if (cdata)
-                                       os << "<![CDATA[";
                                emph_flag = true;
                        } else if (i != initial) {
-                               if (cdata)
-                                       os << "]]>";
                                os << "</emphasis>";
-                               if (cdata)
-                                       os << "<![CDATA[";
                                emph_flag = false;
                        }
                }
 
                if (isInset(i)) {
                        InsetBase const * inset = getInset(i);
-                       if (cdata)
-                               os << "]]>";
                        inset->docbook(buf, os, runparams);
-                       if (cdata)
-                               os << "<![CDATA[";
                } else {
                        char c = getChar(i);
                        bool ws;
@@ -1430,15 +1457,13 @@ void Paragraph::simpleDocBookOnePar(Buffer const & buf,
        }
 
        if (emph_flag) {
-               if (cdata)
-                       os << "]]>";
                os << "</emphasis>";
-               if (cdata)
-                       os << "<![CDATA[";
        }
 
        if (style->free_spacing)
                os << '\n';
+       if (style->pass_thru and not onlyText(buf, outerfont, initial))
+               os << "<![CDATA[";
 }
 
 
@@ -1484,34 +1509,15 @@ bool Paragraph::isLineSeparator(pos_type pos) const
 }
 
 
-bool Paragraph::isKomma(pos_type pos) const
-{
-       return IsKommaChar(getChar(pos));
-}
-
-
 /// Used by the spellchecker
 bool Paragraph::isLetter(pos_type pos) const
-{
-       value_type const c = getChar(pos);
-       if (IsLetterChar(c))
-               return true;
-       if (isInset(pos))
-               return getInset(pos)->isLetter();
-       // We want to pass the ' and escape chars to ispell
-       string const extra = lyxrc.isp_esc_chars + '\'';
-       return contains(extra, c);
-}
-
-
-bool Paragraph::isWord(pos_type pos) const
 {
        if (isInset(pos))
                return getInset(pos)->isLetter();
-       value_type const c = getChar(pos);
-       return !(IsSeparatorChar(c)
-                 || IsKommaChar(c)
-                 || IsInsetChar(c));
+       else {
+               value_type const c = getChar(pos);
+               return IsLetterChar(c) || IsDigit(c);
+       }
 }