]> git.lyx.org Git - lyx.git/blobdiff - src/insets/insetspecialchar.C
* src/LyXAction.C: mark goto-clear-bookmark as working without buffer
[lyx.git] / src / insets / insetspecialchar.C
index da11a2350fc6fcf9d2800b04531dd24fceb0779e..7ed1ea8489cbae9250b301601e10480647e119c3 100644 (file)
 #include "lyxlex.h"
 #include "metricsinfo.h"
 
-#include "frontends/font_metrics.h"
+#include "frontends/FontMetrics.h"
 #include "frontends/Painter.h"
 
 
+namespace lyx {
+
 using std::string;
 using std::auto_ptr;
 using std::ostream;
@@ -40,11 +42,12 @@ InsetSpecialChar::Kind InsetSpecialChar::kind() const
 }
 
 
-void InsetSpecialChar::metrics(MetricsInfo & mi, Dimension & dim) const
+bool InsetSpecialChar::metrics(MetricsInfo & mi, Dimension & dim) const
 {
-       LyXFont & font = mi.base.font;
-       dim.asc = font_metrics::maxAscent(font);
-       dim.des = font_metrics::maxDescent(font);
+       frontend::FontMetrics const & fm =
+               theFontMetrics(mi.base.font);
+       dim.asc = fm.maxAscent();
+       dim.des = fm.maxDescent();
 
        string s;
        switch (kind_) {
@@ -54,10 +57,13 @@ void InsetSpecialChar::metrics(MetricsInfo & mi, Dimension & dim) const
                case MENU_SEPARATOR:      s = " x ";   break;
                case HYPHENATION:      s = "-";   break;
        }
-       dim.wid = font_metrics::width(s, font);
+        docstring ds(s.begin(), s.end());
+       dim.wid = fm.width(ds);
        if (kind_ == HYPHENATION && dim.wid > 5)
                dim.wid -= 2; // to make it look shorter
+       bool const changed = dim_ != dim;
        dim_ = dim;
+       return changed;
 }
 
 
@@ -69,33 +75,38 @@ void InsetSpecialChar::draw(PainterInfo & pi, int x, int y) const
        case HYPHENATION:
        {
                font.setColor(LColor::special);
-               pi.pain.text(x, y, '-', font);
+               pi.pain.text(x, y, char_type('-'), font);
                break;
        }
        case LIGATURE_BREAK:
        {
                font.setColor(LColor::special);
-               pi.pain.text(x, y, '|', font);
+               pi.pain.text(x, y, char_type('|'), font);
                break;
        }
        case END_OF_SENTENCE:
        {
                font.setColor(LColor::special);
-               pi.pain.text(x, y, '.', font);
+               pi.pain.text(x, y, char_type('.'), font);
                break;
        }
        case LDOTS:
        {
                font.setColor(LColor::special);
-               pi.pain.text(x, y, ". . .", font);
+                string ell = ". . . ";
+                docstring dell(ell.begin(), ell.end());
+               pi.pain.text(x, y, dell, font);
                break;
        }
        case MENU_SEPARATOR:
        {
+               frontend::FontMetrics const & fm =
+                       theFontMetrics(font);
+
                // A triangle the width and height of an 'x'
-               int w = font_metrics::width('x', font);
-               int ox = font_metrics::width(' ', font) + x;
-               int h = font_metrics::ascent('x', font);
+                int w = fm.width(char_type('x'));
+               int ox = fm.width(char_type(' ')) + x;
+               int h = fm.ascent(char_type('x'));
                int xp[4], yp[4];
 
                xp[0] = ox;     yp[0] = y;
@@ -138,7 +149,7 @@ void InsetSpecialChar::write(Buffer const &, ostream & os) const
 // This function will not be necessary when lyx3
 void InsetSpecialChar::read(Buffer const &, LyXLex & lex)
 {
-       lex.nextToken();
+       lex.next();
        string const command = lex.getString();
 
        if (command == "\\-")
@@ -156,8 +167,8 @@ void InsetSpecialChar::read(Buffer const &, LyXLex & lex)
 }
 
 
-int InsetSpecialChar::latex(Buffer const &, ostream & os,
-                           LatexRunParams const &) const
+int InsetSpecialChar::latex(Buffer const &, odocstream & os,
+                           OutputParams const &) const
 {
        switch (kind_) {
        case HYPHENATION:
@@ -180,8 +191,8 @@ int InsetSpecialChar::latex(Buffer const &, ostream & os,
 }
 
 
-int InsetSpecialChar::ascii(Buffer const &, ostream & os,
-                           LatexRunParams const &) const
+int InsetSpecialChar::plaintext(Buffer const &, odocstream & os,
+                           OutputParams const &) const
 {
        switch (kind_) {
        case HYPHENATION:
@@ -201,8 +212,8 @@ int InsetSpecialChar::ascii(Buffer const &, ostream & os,
 }
 
 
-int InsetSpecialChar::linuxdoc(Buffer const &, ostream & os,
-                              LatexRunParams const &) const
+int InsetSpecialChar::docbook(Buffer const &, odocstream & os,
+                             OutputParams const &) const
 {
        switch (kind_) {
        case HYPHENATION:
@@ -222,28 +233,14 @@ int InsetSpecialChar::linuxdoc(Buffer const &, ostream & os,
 }
 
 
-int InsetSpecialChar::docbook(Buffer const &, ostream & os,
-                             LatexRunParams const &) const
+int InsetSpecialChar::textString(Buffer const & buf, odocstream & os,
+                      OutputParams const & op) const
 {
-       switch (kind_) {
-       case HYPHENATION:
-       case LIGATURE_BREAK:
-               break;
-       case END_OF_SENTENCE:
-               os << '.';
-               break;
-       case LDOTS:
-               os << "...";
-               break;
-       case MENU_SEPARATOR:
-               os << "&lyxarrow;";
-               break;
-       }
-       return 0;
+       return plaintext(buf, os, op);
 }
 
 
-auto_ptr<InsetBase> InsetSpecialChar::clone() const
+auto_ptr<InsetBase> InsetSpecialChar::doClone() const
 {
        return auto_ptr<InsetBase>(new InsetSpecialChar(kind_));
 }
@@ -269,12 +266,6 @@ bool InsetSpecialChar::isLetter() const
 }
 
 
-bool InsetSpecialChar::isSpace() const
-{
-       return false;
-}
-
-
 bool InsetSpecialChar::isLineSeparator() const
 {
 #if 0
@@ -287,3 +278,6 @@ bool InsetSpecialChar::isLineSeparator() const
        return false;
 #endif
 }
+
+
+} // namespace lyx