]> git.lyx.org Git - lyx.git/blobdiff - src/insets/insetspace.C
* src/LyXAction.C: mark goto-clear-bookmark as working without buffer
[lyx.git] / src / insets / insetspace.C
index 0799bad7ffab7d1368524c12347085e24228f8b4..e7fc211fe57e58039ea77110956403a6d02baea1 100644 (file)
@@ -6,9 +6,9 @@
  * \author Asger Alstrup Nielsen
  * \author Jean-Marc Lasgouttes
  * \author Lars Gullik Bjønnes
- * \author Juergen Spitzmueller
+ * \author Jürgen Spitzmüller
  *
- * Full author contact details are available in file CREDITS
+ * Full author contact details are available in file CREDITS.
  */
 
 #include <config.h>
 #include "insetspace.h"
 
 #include "debug.h"
-#include "dimension.h"
-#include "LaTeXFeatures.h"
-#include "latexrunparams.h"
-#include "BufferView.h"
-#include "frontends/Painter.h"
-#include "frontends/font_metrics.h"
+#include "LColor.h"
 #include "lyxlex.h"
-#include "lyxfont.h"
+#include "metricsinfo.h"
+#include "outputparams.h"
 
-using std::ostream;
+#include "frontends/FontMetrics.h"
+#include "frontends/Painter.h"
+
+
+namespace lyx {
+
+using std::string;
 using std::max;
+using std::auto_ptr;
+using std::ostream;
+
+
+InsetSpace::InsetSpace()
+{}
 
 
 InsetSpace::InsetSpace(Kind k)
@@ -40,75 +48,77 @@ InsetSpace::Kind InsetSpace::kind() const
 }
 
 
-void InsetSpace::dimension(BufferView *, LyXFont const & font,
-                          Dimension & dim) const
+bool InsetSpace::metrics(MetricsInfo & mi, Dimension & dim) const
 {
-       dim.a = font_metrics::maxAscent(font);
-       dim.d = font_metrics::maxDescent(font);
+       frontend::FontMetrics const & fm =
+               theFontMetrics(mi.base.font);
+       dim.asc = fm.maxAscent();
+       dim.des = fm.maxDescent();
 
        switch (kind_) {
                case THIN:
                case NEGTHIN:
-                       dim.w = font_metrics::width("x", font) / 3;
+                    dim.wid = fm.width(char_type('x')) / 3;
                        break;
                case PROTECTED:
                case NORMAL:
-                       dim.w = font_metrics::width("x", font);
+                    dim.wid = fm.width(char_type('x'));
                        break;
                case QUAD:
-                       dim.w = 20;
+                       dim.wid = 20;
                        break;
                case QQUAD:
-                       dim.w = 40;
+                       dim.wid = 40;
                        break;
                case ENSPACE:
                case ENSKIP:
-                       dim.w = 10;
+                       dim.wid = 10;
                        break;
        }
+       bool const changed = dim_ != dim;
+       dim_ = dim;
+       return changed;
 }
 
 
-void InsetSpace::draw(BufferView * bv, LyXFont const & f,
-                           int baseline, float & x) const
+void InsetSpace::draw(PainterInfo & pi, int x, int y) const
 {
-       Painter & pain = bv->painter();
-       LyXFont font(f);
-
-       float w = width(bv, font);
-       int h = font_metrics::ascent('x', font);
+       int const w = width();
+       int const h = theFontMetrics(pi.base.font)
+               .ascent('x');
        int xp[4], yp[4];
 
-       xp[0] = int(x); yp[0] = baseline - max(h / 4, 1);
+       xp[0] = x;
+       yp[0] = y - max(h / 4, 1);
        if (kind_ == NORMAL) {
-               xp[1] = int(x); yp[1] = baseline;
-               xp[2] = int(x + w); yp[2] = baseline;
+               xp[1] = x;     yp[1] = y;
+               xp[2] = x + w; yp[2] = y;
        } else {
-               xp[1] = int(x); yp[1] = baseline + max(h / 4, 1);
-               xp[2] = int(x + w); yp[2] = baseline + max(h / 4, 1);
+               xp[1] = x;     yp[1] = y + max(h / 4, 1);
+               xp[2] = x + w; yp[2] = y + max(h / 4, 1);
        }
-       xp[3] = int(x + w); yp[3] = baseline - max(h / 4, 1);
+       xp[3] = x + w;
+       yp[3] = y - max(h / 4, 1);
 
        if (kind_ == PROTECTED || kind_ == ENSPACE || kind_ == NEGTHIN)
-               pain.lines(xp, yp, 4, LColor::latex);
+               pi.pain.lines(xp, yp, 4, LColor::latex);
        else
-               pain.lines(xp, yp, 4, LColor::special);
-       x += w;
+               pi.pain.lines(xp, yp, 4, LColor::special);
 }
 
 
-void InsetSpace::write(Buffer const *, ostream & os) const
+void InsetSpace::write(Buffer const &, ostream & os) const
 {
        string command;
        switch (kind_) {
        case NORMAL:
-               command = "\\space";
+               command = "\\space{}";
                break;
        case PROTECTED:
                command = "~";
                break;
        case THIN:
-               command = "\\,";
+               command = "\\thinspace{}";
                break;
        case QUAD:
                command = "\\quad{}";
@@ -130,17 +140,16 @@ void InsetSpace::write(Buffer const *, ostream & os) const
 }
 
 
-// This function will not be necessary when lyx3
-void InsetSpace::read(Buffer const *, LyXLex & lex)
+void InsetSpace::read(Buffer const &, LyXLex & lex)
 {
-       lex.nextToken();
+       lex.next();
        string const command = lex.getString();
 
-       if (command == "\\space")
+       if (command == "\\space{}")
                kind_ = NORMAL;
        else if (command == "~")
                kind_ = PROTECTED;
-       else if (command == "\\,")
+       else if (command == "\\thinspace{}")
                kind_ = THIN;
        else if (command == "\\quad{}")
                kind_ = QUAD;
@@ -157,8 +166,8 @@ void InsetSpace::read(Buffer const *, LyXLex & lex)
 }
 
 
-int InsetSpace::latex(Buffer const *, ostream & os,
-                     LatexRunParams const & runparams) const
+int InsetSpace::latex(Buffer const &, odocstream & os,
+                     OutputParams const & runparams) const
 {
        switch (kind_) {
        case NORMAL:
@@ -190,7 +199,8 @@ int InsetSpace::latex(Buffer const *, ostream & os,
 }
 
 
-int InsetSpace::ascii(Buffer const *, ostream & os, int) const
+int InsetSpace::plaintext(Buffer const &, odocstream & os,
+                     OutputParams const &) const
 {
        switch (kind_) {
        case NORMAL:
@@ -208,10 +218,10 @@ int InsetSpace::ascii(Buffer const *, ostream & os, int) const
 }
 
 
-int InsetSpace::linuxdoc(Buffer const *, ostream & os) const
+int InsetSpace::docbook(Buffer const &, odocstream & os,
+                       OutputParams const &) const
 {
        switch (kind_) {
-       // fixme: correct?
        case NORMAL:
        case QUAD:
        case QQUAD:
@@ -229,30 +239,16 @@ int InsetSpace::linuxdoc(Buffer const *, ostream & os) const
 }
 
 
-int InsetSpace::docbook(Buffer const *, ostream & os, bool) const
+int InsetSpace::textString(Buffer const & buf, odocstream & os,
+                      OutputParams const & op) const
 {
-       switch (kind_) {
-       // fixme: correct?
-       case NORMAL:
-       case QUAD:
-       case QQUAD:
-       case ENSKIP:
-               os << " ";
-               break;
-       case PROTECTED:
-       case ENSPACE:
-       case THIN:
-       case NEGTHIN:
-               os << "&nbsp;";
-               break;
-       }
-       return 0;
+       return plaintext(buf, os, op);
 }
 
 
-Inset * InsetSpace::clone(Buffer const &, bool) const
+auto_ptr<InsetBase> InsetSpace::doClone() const
 {
-       return new InsetSpace(kind_);
+       return auto_ptr<InsetBase>(new InsetSpace(kind_));
 }
 
 
@@ -271,7 +267,5 @@ bool InsetSpace::isSpace() const
        return true;
 }
 
-bool InsetSpace::isLineSeparator() const
-{
-       return false;
-}
+
+} // namespace lyx