]> git.lyx.org Git - lyx.git/blobdiff - src/Changes.cpp
Remove hardcoded values
[lyx.git] / src / Changes.cpp
index 877c3f104281fec2c8cee5b3f4b31b10e67be6a6..90ad07501add91569ae11984c7b1e5361e91e59b 100644 (file)
 #include "BufferParams.h"
 #include "Encoding.h"
 #include "LaTeXFeatures.h"
+#include "MetricsInfo.h"
 #include "OutputParams.h"
 #include "Paragraph.h"
+#include "texstream.h"
 #include "TocBackend.h"
 
 #include "support/debug.h"
@@ -30,6 +32,8 @@
 #include "support/mutex.h"
 
 #include "frontends/alert.h"
+#include "frontends/FontMetrics.h"
+#include "frontends/Painter.h"
 
 #include <ostream>
 
@@ -37,6 +41,9 @@ using namespace std;
 
 namespace lyx {
 
+using frontend::Painter;
+using frontend::FontMetrics;
+
 /*
  * Class Change has a changetime field that specifies the exact time at which
  * a specific change was made. The change time is used as a guidance for the
@@ -421,7 +428,7 @@ int Changes::latexMarkChange(otexstream & os, BufferParams const & bparams,
                // close \lyxadded or \lyxdeleted
                os << '}';
                column++;
-               if (oldChange.type == Change::DELETED)
+               if (oldChange.type == Change::DELETED && !runparams.wasDisplayMath)
                        --runparams.inulemcmd;
        }
 
@@ -433,7 +440,8 @@ int Changes::latexMarkChange(otexstream & os, BufferParams const & bparams,
        docstring macro_beg;
        if (change.type == Change::DELETED) {
                macro_beg = from_ascii("\\lyxdeleted{");
-               ++runparams.inulemcmd;
+               if (!runparams.inDisplayMath)
+                       ++runparams.inulemcmd;
        }
        else if (change.type == Change::INSERTED)
                macro_beg = from_ascii("\\lyxadded{");
@@ -442,6 +450,17 @@ int Changes::latexMarkChange(otexstream & os, BufferParams const & bparams,
                                       bparams.authors().get(change.author).name(),
                                       chgTime, runparams);
        
+       // signature needed by \lyxsout to correctly strike out display math
+       if (change.type == Change::DELETED && runparams.inDisplayMath
+           && (!LaTeXFeatures::isAvailable("dvipost")
+               || (runparams.flavor != OutputParams::LATEX
+                   && runparams.flavor != OutputParams::DVILUATEX))) {
+               if (os.afterParbreak())
+                       str += from_ascii("\\\\\\noindent\n");
+               else
+                       str += from_ascii("\\\\\\\\\n");
+       }
+
        os << str;
        column += str.size();
 
@@ -523,16 +542,14 @@ void Changes::addToToc(DocIterator const & cdit, Buffer const & buffer,
                Toc::iterator it = TocBackend::findItem(*change_list, 0, author);
                if (it == change_list->end()) {
                        change_list->push_back(TocItem(dit, 0, author, true));
-                       change_list->push_back(TocItem(dit, 1, str, output_active,
-                               support::wrapParas(str, 4)));
+                       change_list->push_back(TocItem(dit, 1, str, output_active));
                        continue;
                }
                for (++it; it != change_list->end(); ++it) {
                        if (it->depth() == 0 && it->str() != author)
                                break;
                }
-               change_list->insert(it, TocItem(dit, 1, str, output_active,
-                       support::wrapParas(str, 4)));
+               change_list->insert(it, TocItem(dit, 1, str, output_active));
        }
 }
 
@@ -545,6 +562,49 @@ void Changes::updateBuffer(Buffer const & buf)
 }
 
 
+void Change::paintCue(PainterInfo & pi, double const x1, double const y,
+                      double const x2, FontInfo const & font) const
+{
+       if (!changed())
+               return;
+       // Calculate 1/3 height of font
+       FontMetrics const & fm = theFontMetrics(font);
+       double const y_bar = deleted() ? y - fm.maxAscent() / 3
+               : y + 2 * pi.base.solidLineOffset() + pi.base.solidLineThickness();
+       pi.pain.line(int(x1), int(y_bar), int(x2), int(y_bar), color(),
+                    Painter::line_solid, pi.base.solidLineThickness());
+}
+
+
+void Change::paintCue(PainterInfo & pi, double const x1, double const y1,
+                      double const x2, double const y2) const
+{
+       /*
+        * y1      /
+        *        /
+        *       /
+        *      /
+        *     /
+        * y2 /_____
+        *    x1  x2
+        */
+       switch(type) {
+       case UNCHANGED:
+               return;
+       case INSERTED:
+               pi.pain.line(int(x1), int(y2) + 1, int(x2), int(y2) + 1,
+                            color(), Painter::line_solid,
+                            pi.base.solidLineThickness());
+               return;
+       case DELETED:
+               // FIXME: we cannot use antialias since we keep drawing on the same
+               // background with the current painting mechanism.
+               pi.pain.line(int(x1), int(y2), int(x2), int(y1),
+                            color(), Painter::line_solid_aliased,
+                            pi.base.solidLineThickness());
+               return;
+       }
+}
 
 
 } // namespace lyx