]> git.lyx.org Git - lyx.git/blobdiff - src/paragraph.C
reduce number of calls to LyXText::getFont
[lyx.git] / src / paragraph.C
index b1a9a60f826163e2e79ad46ffe1829df46fb10fb..dc5205a9e5f79dc82739d5a9763013327bc0ef44 100644 (file)
@@ -27,6 +27,7 @@
 #include "debug.h"
 #include "gettext.h"
 #include "language.h"
+#include "LaTeXFeatures.h"
 #include "lyxfont.h"
 #include "lyxrc.h"
 #include "lyxrow.h"
@@ -42,7 +43,7 @@
 
 #include "support/lstrings.h"
 #include "support/textutils.h"
-#include "support/tostr.h"
+#include "support/convert.h"
 
 #include <boost/tuple/tuple.hpp>
 #include <boost/bind.hpp>
@@ -156,10 +157,6 @@ void Paragraph::write(Buffer const & buf, ostream & os,
 
        int column = 0;
        for (pos_type i = 0; i < size(); ++i) {
-               if (!i) {
-                       os << '\n';
-                       column = 0;
-               }
 
                Change change = pimpl_->lookupChangeFull(i);
                Changes::lyxMarkChange(os, column, curtime, running_change, change);
@@ -185,7 +182,9 @@ void Paragraph::write(Buffer const & buf, ostream & os,
                                        // the file
                                        inset->write(buf, os);
                                } else {
-                                       os << "\n\\begin_inset ";
+                                       if (i)
+                                               os << '\n';
+                                       os << "\\begin_inset ";
                                        inset->write(buf, os);
                                        os << "\n\\end_inset\n\n";
                                        column = 0;
@@ -347,20 +346,23 @@ LyXFont const Paragraph::getFontSettings(BufferParams const & bparams,
 }
 
 
-lyx::pos_type Paragraph::getEndPosOfFontSpan(lyx::pos_type pos) const
+std::pair<lyx::pos_type, lyx::pos_type> Paragraph::getFontSpan(lyx::pos_type pos) const
 {
        BOOST_ASSERT(pos <= size());
+       lyx::pos_type start = 0;
 
        Pimpl::FontList::const_iterator cit = pimpl_->fontlist.begin();
        Pimpl::FontList::const_iterator end = pimpl_->fontlist.end();
-       for (; cit != end; ++cit)
+       for (; cit != end; ++cit) {
                if (cit->pos() >= pos)
-                       return cit->pos();
+                       return std::make_pair(start, cit->pos());
+               start = cit->pos() + 1;
+       }
 
        // This should not happen, but if so, we take no chances.
        //lyxerr << "Paragraph::getEndPosOfFontSpan: This should not happen!"
        //      << endl;
-       return pos;
+       return std::make_pair(pos, pos);
 }
 
 
@@ -579,7 +581,9 @@ int Paragraph::stripLeadingSpaces()
 
        int i = 0;
        while (!empty() && (isNewline(0) || isLineSeparator(0))) {
-               pimpl_->eraseIntern(0);
+               // Set Change::Type to Change::INSERTED to quietly remove it
+               setChange(0, Change::INSERTED);
+               erase(0);
                ++i;
        }
 
@@ -703,7 +707,7 @@ InsetBibitem * Paragraph::bibitem() const
 {
        if (!insetlist.empty()) {
                InsetBase * inset = insetlist.begin()->inset;
-               if (inset->lyxCode() == InsetBase::BIBTEX_CODE)
+               if (inset->lyxCode() == InsetBase::BIBITEM_CODE)
                        return static_cast<InsetBibitem *>(inset);
        }
        return 0;
@@ -903,6 +907,15 @@ bool Paragraph::simpleTeXOnePar(Buffer const & buf,
 
        LyXFont basefont;
 
+       LaTeXFeatures features(buf, bparams, runparams.nice);
+
+       // output change tracking marks only if desired,
+       // if dvipost is installed,
+       // and with dvi/ps (other formats don't work)
+       bool const output = bparams.output_changes
+               && runparams.flavor == OutputParams::LATEX
+               && features.isAvailable("dvipost");
+
        // Maybe we have to create a optional argument.
        pos_type body_pos = beginOfBody();
        unsigned int column = 0;
@@ -1012,23 +1025,28 @@ bool Paragraph::simpleTeXOnePar(Buffer const & buf,
 
                Change::Type change = pimpl_->lookupChange(i);
 
-               column += Changes::latexMarkChange(os, running_change, change);
+               column += Changes::latexMarkChange(os, running_change,
+                       change, output);
                running_change = change;
 
-               OutputParams rp = runparams;
-               rp.free_spacing = style->free_spacing;
-               rp.local_language = font.language()->babel();
-               rp.intitle = style->intitle;
-               pimpl_->simpleTeXSpecialChars(buf, bparams,
-                                             os, texrow, rp,
-                                             font, running_font,
-                                             basefont, outerfont, open_font,
-                                             running_change,
-                                             *style, i, column, c);
+               // do not output text which is marked deleted
+               // if change tracking output is not desired
+               if (output || running_change != Change::DELETED) {
+                       OutputParams rp = runparams;
+                       rp.free_spacing = style->free_spacing;
+                       rp.local_language = font.language()->babel();
+                       rp.intitle = style->intitle;
+                       pimpl_->simpleTeXSpecialChars(buf, bparams,
+                                               os, texrow, rp,
+                                               font, running_font,
+                                               basefont, outerfont, open_font,
+                                               running_change,
+                                               *style, i, column, c);
+               }
        }
 
        column += Changes::latexMarkChange(os,
-                       running_change, Change::UNCHANGED);
+                       running_change, Change::UNCHANGED, output);
 
        // If we have an open font definition, we have to close it
        if (open_font) {
@@ -1054,7 +1072,7 @@ bool Paragraph::simpleTeXOnePar(Buffer const & buf,
 
        // Needed if there is an optional argument but no contents.
        if (body_pos > 0 && body_pos == size()) {
-               os << "]~";
+               os << "}]~";
                return_value = false;
        }
 
@@ -1782,6 +1800,8 @@ bool Paragraph::allowEmpty() const
 
 Row & Paragraph::getRow(pos_type pos)
 {
+       BOOST_ASSERT(!rows().empty());
+
        RowList::iterator rit = rows_.end();
        RowList::iterator const begin = rows_.begin();
 
@@ -1794,6 +1814,8 @@ Row & Paragraph::getRow(pos_type pos)
 
 Row const & Paragraph::getRow(pos_type pos) const
 {
+       BOOST_ASSERT(!rows().empty());
+
        RowList::const_iterator rit = rows_.end();
        RowList::const_iterator const begin = rows_.begin();
 
@@ -1806,6 +1828,8 @@ Row const & Paragraph::getRow(pos_type pos) const
 
 size_t Paragraph::pos2row(pos_type pos) const
 {
+       BOOST_ASSERT(!rows().empty());
+
        RowList::const_iterator rit = rows_.end();
        RowList::const_iterator const begin = rows_.begin();
 
@@ -1859,12 +1883,3 @@ void Paragraph::dump() const
                rows_[i].dump();
        }
 }
-
-//void Paragraph::metrics(MetricsInfo & mi, Dimension & dim, LyXText & text)
-//{
-//}
-//
-//
-//void draw(PainterInfo & pi, int x, int y, LyXText & text) const
-//{
-//}