]> git.lyx.org Git - lyx.git/blobdiff - src/insets/insetlatexaccent.C
Final touch 'inset display()'; fix 'is a bit silly' bug
[lyx.git] / src / insets / insetlatexaccent.C
index 5d3928ee93f89ec80236216f612a1df29f4e10eb..bcbd6ed46cb23660b41a6d4f85ba1c1c60db0063 100644 (file)
@@ -1,70 +1,67 @@
-/* This file is part of
- * ======================================================
- * 
- *           LyX, The Document Processor
- *      
- *         Copyright 1995 Matthias Ettrich
- *          Copyright 1995-1999 The LyX Team.
+/**
+ * \file insetlatexaccent.C
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
  *
- *======================================================*/
+ * \author Lars Gullik Bjønnes
+ *
+ * Full author contact details are available in file CREDITS.
+ */
 
 #include <config.h>
 
-#ifdef __GNUG__
-#pragma implementation
-#endif
-
 #include "insetlatexaccent.h"
-#include "error.h"
+
+#include "debug.h"
+#include "language.h"
+#include "LColor.h"
+#include "lyxlex.h"
 #include "lyxrc.h"
-#include "lyxdraw.h"
+#include "metricsinfo.h"
+
+#include "frontends/font_metrics.h"
+#include "frontends/Painter.h"
+
 #include "support/lstrings.h"
 
-extern LyXRC * lyxrc;
+using lyx::support::contains;
+using lyx::support::trim;
+
+using std::endl;
+using std::string;
+using std::auto_ptr;
+using std::ostream;
+
 
 /* LatexAccent. Proper handling of accented characters */
 /* This part is done by Ivan Schreter, schreter@ccsun.tuke.sk */
-/* Later modified by Lars G. Bjonnes, larsbj@ifi.uio.no */
+/* Later modified by Lars G. Bjønnes, larsbj@lyx.org */
 
 InsetLatexAccent::InsetLatexAccent()
-{
-       candisp = false;
-}
-
-
-InsetLatexAccent::InsetLatexAccent(InsetLatexAccent const & other)
-    :contents(other.contents),
-     candisp(other.candisp),
-     modtype(other.modtype),
-     remdot(other.remdot),
-     plusasc(other.plusasc),
-     plusdesc(other.plusdesc),
-     ic(other.ic)
+       : candisp(false)
 {}
 
 
-InsetLatexAccent::InsetLatexAccent(string const & string)
-       : contents(string)
+InsetLatexAccent::InsetLatexAccent(string const & str)
+       : contents(str)
 {
        checkContents();
 }
 
 
-InsetLatexAccent::~InsetLatexAccent()
-{
-}
-
-
 void InsetLatexAccent::checkContents()
-        // check, if we know the modifier and can display it ok on screen
+       // check, if we know the modifier and can display it ok on screen
 {
-        candisp = false;
+       candisp = false;
 
-       if (contents.empty() || contents.length()<2) return;
+       if (contents.empty() || contents.length() < 2) {
+               lyxerr[Debug::KEY] << "Cannot decode: " << contents << endl;
+               return;
+       }
 
        // REMOVE IN 0.13
        // Dirty Hack for backward compability. remove in 0.13 (Lgb)
-       contents = frontStrip(strip(contents));
+       contents = trim(contents);
        if (!contains(contents, "{") && !contains(contents, "}")) {
                if (contents.length() == 2) {
                        string tmp;
@@ -80,7 +77,7 @@ void InsetLatexAccent::checkContents()
                        tmp += contents[2];
                        tmp += '}';
                        contents = tmp;
-               } else if (contents.length()==4 && contents[2] == ' ') {
+               } else if (contents.length() == 4 && contents[2] == ' ') {
                        string tmp;
                        tmp += contents[0];
                        tmp += contents[1];
@@ -88,8 +85,8 @@ void InsetLatexAccent::checkContents()
                        tmp += contents[3];
                        tmp += '}';
                        contents = tmp;
-               } else if  (contents.length()==4 && contents[2] == '\\'
-                           && (contents[3]== 'i' || contents[3]== 'j')) {
+               } else if  (contents.length() == 4 && contents[2] == '\\'
+                           && (contents[3] == 'i' || contents[3] == 'j')) {
                        string tmp;
                        tmp += contents[0];
                        tmp += contents[1];
@@ -100,77 +97,82 @@ void InsetLatexAccent::checkContents()
                        contents = tmp;
                }
        }
-        if (contents[0] != '\\') return; // demand that first char is a '\\'
+       if (contents[0] != '\\') { // demand that first char is a '\\'
+               lyxerr[Debug::KEY] << "Cannot decode: " << contents << endl;
+               return;
+       }
 
-       lyxerr.debug("Decode: " + contents);
+       lyxerr[Debug::KEY] << "Decode: " << contents << endl;
 
-        remdot = false; plusasc = false; plusdesc = false;
+       remdot = false;
+       plusasc = false;
+       plusdesc = false;
 
-        switch (contents[1]) { // second char should be one of these
+       switch (contents[1]) { // second char should be one of these
        case '\'':  // acute
-                modtype = ACUTE;    // acute
-                plusasc = true;    // at the top of character
-                break;
+               modtype = ACUTE;    // acute
+               plusasc = true;    // at the top of character
+               break;
        case '`':   // grave
-                modtype = GRAVE;    // grave
-                plusasc = true;    // at the top
-                break;
+               modtype = GRAVE;    // grave
+               plusasc = true;    // at the top
+               break;
        case '=':   // macron
-                modtype = MACRON;    // macron
-                plusasc = true;    // at the top
-                break;
+               modtype = MACRON;    // macron
+               plusasc = true;    // at the top
+               break;
        case '~':   // tilde
-                modtype = TILDE;    // tilde
-                plusasc = true;    // at the top
-                break;
+               modtype = TILDE;    // tilde
+               plusasc = true;    // at the top
+               break;
        case 'b':   // underbar
-                modtype = UNDERBAR;    // underbar
-                plusdesc = true;   // at the bottom
-                break;
+               modtype = UNDERBAR;    // underbar
+               plusdesc = true;   // at the bottom
+               break;
        case 'c':   // cedilla
-                modtype = CEDILLA;    // cedilla
-                plusdesc = true;   // at the bottom
-                break;
+               modtype = CEDILLA;    // cedilla
+               plusdesc = true;   // at the bottom
+               break;
        case 'd':   // underdot
-                modtype = UNDERDOT;    // underdot
-                plusdesc = true;   // at the bottom
-                break;
+               modtype = UNDERDOT;    // underdot
+               plusdesc = true;   // at the bottom
+               break;
        case 'r':   // circle
-                modtype = CIRCLE;    // circle
-                plusasc = true;    // at the top
-                break;
+               modtype = CIRCLE;    // circle
+               plusasc = true;    // at the top
+               break;
        case 't':   // tie
-                modtype = TIE;    // tie
-                plusasc = true;    // at the top
-                break;
+               modtype = TIE;    // tie
+               plusasc = true;    // at the top
+               break;
        case 'u':   // breve
-                modtype = BREVE;    // breve
-                plusasc = true;    // at the top
-                break;
+               modtype = BREVE;    // breve
+               plusasc = true;    // at the top
+               break;
        case 'v':   // caron
-                modtype = CARON;   // caron
-                plusasc = true;    // at the top
-                break;
+               modtype = CARON;   // caron
+               plusasc = true;    // at the top
+               break;
        case 'q':   // special caron
-                modtype = SPECIAL_CARON;   // special caron
-                plusasc = true;    // at the top
-                break;
+               modtype = SPECIAL_CARON;   // special caron
+               plusasc = true;    // at the top
+               break;
        case 'H':   // hungarian umlaut
-                modtype = HUNGARIAN_UMLAUT;   // hungarian umlaut
-                plusasc = true;    // at the top
-                break;
+               modtype = HUNGARIAN_UMLAUT;   // hungarian umlaut
+               plusasc = true;    // at the top
+               break;
        case '"':   // umlaut
-                modtype = UMLAUT;   // umlaut
-                plusasc = true;    // at the top
-                break;
+               modtype = UMLAUT;   // umlaut
+               plusasc = true;    // at the top
+               break;
        case '.':   // dot
-                modtype = DOT;   // dot
-                plusasc = true;    // at the top
-                break;
+               modtype = DOT;   // dot
+               plusasc = true;    // at the top
+               break;
        case '^':   // circumflex
-                modtype = CIRCUMFLEX;   // circumflex
-                plusasc = true;    // at the top
-                break;
+               modtype = CIRCUMFLEX;   // circumflex
+               plusasc = true;    // at the top
+               break;
        case 'k':   // ogonek
                modtype = OGONEK;  // ogonek
                plusdesc = true;
@@ -185,27 +187,27 @@ void InsetLatexAccent::checkContents()
                plusasc = true; // at the top (not really needed)
                remdot = true;
                break;
-       case 'l': // lslash
-               modtype = lSLASH;
-               plusasc = true; // at the top (not really needed)
-               break;
-       case 'L': // lslash
-               modtype = LSLASH;
-               plusasc = true; // at the top (not really needed)
-               break;
+       case 'l': // lslash
+               modtype = lSLASH;
+               plusasc = true; // at the top (not really needed)
+               break;
+       case 'L': // lslash
+               modtype = LSLASH;
+               plusasc = true; // at the top (not really needed)
+               break;
        default:
-               printf ("Default\n");
+               lyxerr[Debug::KEY] << "Default" << endl;
                // unknow accent (or something else)
-                return;
-        }
+               return;
+       }
 
        // we demand that third char is a '{' (Lgb)
        if (contents[2] != '{') return;
 
        // special clause for \i{}, \j{} \l{} and \L{}
        if ((modtype == DOT_LESS_I || modtype == DOT_LESS_J
-               || modtype == lSLASH || modtype == LSLASH)
-           && contents[3] == '}' ) {
+            || modtype == lSLASH || modtype == LSLASH)
+           && contents[3] == '}') {
                switch (modtype) {
                case DOT_LESS_I: ic = 'i'; break;
                case DOT_LESS_J: ic = 'j'; break;
@@ -213,21 +215,22 @@ void InsetLatexAccent::checkContents()
                case LSLASH:     ic = 'L'; break;
                default:
                        // if this happens something is really wrong
-                       lyxerr.print("InsetLaTexAccent: weird error.");
+                       lyxerr << "InsetLaTexAccent: weird error." << endl;
                        break;
                }
                //ic = (modtype == DOT_LESS_J ? 'j' : 'i');
-               lyxerr.debug("Contents: [" + contents + "], ic: " + ic 
-                            + ", top: " + tostr(plusasc) 
-                            + ", bot: " + tostr(plusdesc) 
-                            + ", dot: " + tostr(remdot) 
-                            + ", mod: " + tostr(modtype));
-       // Special case for space
+               lyxerr[Debug::KEY] << "Contents: [" << contents << ']'
+                                  << ", ic: " << ic
+                                  << ", top: " << plusasc
+                                  << ", bot: " << plusdesc
+                                  << ", dot: " << remdot
+                                  << ", mod: " << modtype << endl;
+               // Special case for space
        } else if (contents[3] == '}') {
                ic = ' ';
        } else {
                int i = 3;
-               
+
                // now get the char
                ic = contents[3]; // i will always be 3 here
 
@@ -238,82 +241,83 @@ void InsetLatexAccent::checkContents()
                                remdot = true;
                        else
                                return;
-               } else if ( (ic=='i'|| ic=='j') && contents[4]=='}') {
-                   // Do a rewrite: \<foo>{i} --> \<foo>{\i}
-                   string temp=contents;
-                   temp.erase(3, string::npos);
-                   temp+='\\';
-                       temp+=char(ic);
-                   for(string::size_type j = 4; j < contents.length(); ++j)
-                               temp+=contents[j];
-                   contents=temp;
-                   i++;
-                       remdot=true;
-               }    
+               } else if ((ic == 'i'|| ic == 'j') && contents[4] == '}') {
+                       // Do a rewrite: \<foo>{i} --> \<foo>{\i}
+                       string temp = contents;
+                       temp.erase(3, string::npos);
+                       temp += '\\';
+                       temp += char(ic);
+                       for (string::size_type j = 4;
+                           j < contents.length(); ++j)
+                               temp+= contents[j];
+                       contents= temp;
+                       ++i;
+                       remdot = true;
+               }
 
                // demand a '}' at the end
                if (contents[++i] != '}' && contents[++i]) return;
-                                          
+
                // fine, the char is properly decoded now (hopefully)
-               lyxerr.debug("Contents: [" + contents + "], ic: " + ic
-                            + ", top: " + tostr(plusasc) 
-                            + ", bot: " + tostr(plusdesc) 
-                            + ", dot: " + tostr(remdot) 
-                            + ", mod: " + tostr(modtype));
+               lyxerr[Debug::KEY] << "Contents: [" << contents << ']'
+                                  << ", ic: " << ic
+                                  << ", top: " << plusasc
+                                  << ", bot: " << plusdesc
+                                  << ", dot: " << remdot
+                                  << ", mod: " << modtype << endl;
        }
-        candisp = true;
+       candisp = true;
 }
 
 
-int InsetLatexAccent::Ascent(LyXFont const &font) const
+void InsetLatexAccent::metrics(MetricsInfo & mi, Dimension & dim) const
 {
-       int max;
+       LyXFont & font = mi.base.font;
+       // This function is a bit too simplistic and is just a
+       // "try to make a fit for all accents" approach, to
+       // make it better we need to know what kind of accent is
+       // used and add to max based on that.
        if (candisp) {
                if (ic == ' ')
-                       max = font.ascent('a');
+                       dim.asc = font_metrics::ascent('a', font);
                else
-                       max = font.ascent(ic);
-               if (plusasc) 
-                       max += (font.maxAscent()+3) / 3;
-       } else
-               max = font.maxAscent()+4;
-       return max;
+                       dim.asc = font_metrics::ascent(ic, font);
+               if (plusasc)
+                       dim.asc += (font_metrics::maxAscent(font) + 3) / 3;
+
+               if (ic == ' ')
+                       dim.des = font_metrics::descent('a', font);
+               else
+                       dim.des = font_metrics::descent(ic, font);
+               if (plusdesc)
+                       dim.des += 3;
+
+               dim.wid = font_metrics::width(ic, font);
+       } else {
+               dim.asc = font_metrics::maxAscent(font) + 4;
+               dim.des = font_metrics::maxDescent(font) + 4;
+               dim.wid = font_metrics::width(contents, font) + 4;
+       }
+       dim_ = dim;
 }
 
 
-int InsetLatexAccent::Descent(LyXFont const &font) const
+int InsetLatexAccent::lbearing(LyXFont const & font) const
 {
-       int max;
-       if (candisp) {
-               if (ic==' ') 
-                       max = font.descent('a');
-                else 
-                       max = font.descent(ic);
-                if (plusdesc)
-                       max += 3;
-       } else
-               max = font.maxDescent() + 4;
-       return max;
+       return font_metrics::lbearing(ic, font);
 }
 
 
-int InsetLatexAccent::Width(LyXFont const &font) const
+int InsetLatexAccent::rbearing(LyXFont const & font) const
 {
-       if (candisp)
-               return font.textWidth(&ic, 1);
-        else
-                return font.stringWidth(contents) + 4;
+       return font_metrics::rbearing(ic, font);
 }
 
 
-
-bool InsetLatexAccent::DisplayISO8859_9(LyXFont font,
-                           LyXScreen &scr,
-                           int baseline, 
-                           float &x)
+bool InsetLatexAccent::displayISO8859_9(PainterInfo & pi, int x, int y) const
 {
        unsigned char tmpic = ic;
-       
+
        switch (modtype) {
        case CEDILLA:
        {
@@ -325,8 +329,8 @@ bool InsetLatexAccent::DisplayISO8859_9(LyXFont font,
        }
        case BREVE:
        {       if (ic == 'g') tmpic = 0xf0;
-               if (ic == 'G') tmpic = 0xd0;
-               break;
+       if (ic == 'G') tmpic = 0xd0;
+       break;
        }
        case UMLAUT:
        {
@@ -336,14 +340,12 @@ bool InsetLatexAccent::DisplayISO8859_9(LyXFont font,
                if (ic == 'U') tmpic = 0xdc;
                break;
        }
-       case DOT:        if (ic == 'I') tmpic = 0xdd; break;
+       case DOT:        if (ic == 'I') tmpic = 0xdd; break;
        case DOT_LESS_I: tmpic = 0xfd; break;
        default:         return false;
        }
        if (tmpic != ic) {
-               char ch = char(tmpic);
-               scr.drawText(font, &ch, 1, baseline, int(x));
-               x += Width (font);
+               pi.pain.text(x, y, char(tmpic), pi.base.font);
                return true;
        }
        else
@@ -351,211 +353,241 @@ bool InsetLatexAccent::DisplayISO8859_9(LyXFont font,
 }
 
 
-void InsetLatexAccent::Draw(LyXFont font,
-                           LyXScreen &scr,
-                           int baseline, 
-                           float &x)
+void InsetLatexAccent::draw(PainterInfo & pi, int x, int baseline) const
 {
-       if (lyxrc->font_norm=="iso8859-9")
-               if (DisplayISO8859_9 (font, scr, baseline, x))  
+       if (lyxrc.font_norm_type == LyXRC::ISO_8859_9)
+               if (displayISO8859_9(pi, x, baseline))
                        return;
-       
-       /* draw it! */ 
-  
+
+       /* draw it! */
+       // All the manually drawn accents in this function could use an
+       // overhaul. Different ways of drawing (what metrics to use)
+       // should also be considered.
+
+       LyXFont font = pi.base.font;
+       if (lyxrc.font_norm_type == LyXRC::ISO_10646_1)
+               font.setLanguage(english_language);
+
        if (candisp) {
-               int asc = Ascent(font);
-               int desc = Descent(font);
-               int wid = Width(font);
-               float x2 = x+(float(wid)/2);
-               float hg35;
-               int hg, y;
+               float x2 = x + (rbearing(font) - lbearing(font)) / 2.0;
+               float hg;
+               int y;
                if (plusasc) {
                        // mark at the top
-                       hg = font.maxDescent();
-                       y = baseline - asc;
+                       hg = font_metrics::maxDescent(font);
+                       y = baseline - dim_.asc;
 
-                       if (font.shape() == LyXFont::ITALIC_SHAPE) x2 += (4*hg)/5; // italic
+                       if (font.shape() == LyXFont::ITALIC_SHAPE)
+                               x2 += (4.0 * hg) / 5.0; // italic
                } else {
                        // at the bottom
-                       hg = desc;
+                       hg = dim_.des;
                        y = baseline;
                }
 
-               hg35 = float(hg*3)/5;
+               float hg35 = float(hg * 3.0) / 5.0;
 
                // display with proper accent mark
                // first the letter
-               scr.drawText(font, &ic, 1, baseline, int(x));
-
-               GC pgc = GetAccentGC(font, (hg+3)/5);
+               pi.pain.text(x, baseline, ic, font);
 
                if (remdot) {
-                       int tmpvar = baseline - font.ascent('i');
-                       float tmpx = 0;
-                       if (font.shape() == LyXFont::ITALIC_SHAPE) tmpx += (8*hg)/10; // italic
-                       lyxerr.debug("Removing dot.", Error::ANY);
+                       int tmpvar = baseline - font_metrics::ascent('i', font);
+                       int tmpx = 0;
+                       if (font.shape() == LyXFont::ITALIC_SHAPE)
+                               tmpx += int(0.8 * hg); // italic
+                       lyxerr[Debug::KEY] << "Removing dot." << endl;
                        // remove the dot first
-                       scr.fillRectangle(gc_clear, int(x + tmpx),
-                                         tmpvar, wid,
-                                         font.ascent('i') -
-                                         font.ascent('x')-1);
-                       
+                       pi.pain.fillRectangle(x + tmpx, tmpvar, dim_.wid,
+                                          font_metrics::ascent('i', pi.base.font) -
+                                          font_metrics::ascent('x', pi.base.font) - 1,
+                                          backgroundColor());
+                       // the five lines below is a simple hack to
+                       // make the display of accent 'i' and 'j'
+                       // better. It makes the accent be written
+                       // closer to the top of the dot-less 'i' or 'j'.
+                       char tmpic = ic; // store the ic when we
+                       ic = 'x';        // calculates the ascent of
+#warning metrics?
+                       int asc = ascent(); // the dot-less version (here: 'x')
+                       ic = tmpic;      // set the orig ic back
+                       y = baseline - asc; // update to new y coord.
                }
-               // now the rest - draw within (x,y, x+wid, y+hg)
+               // now the rest - draw within (x, y, x+wid, y+hg)
                switch (modtype) {
-               case ACUTE:     // acute
-               {
-                       scr.drawLine(pgc, int(x2), int(y+hg35),
-                                    int(x2+hg35), y);
+               case ACUTE:     // acute 0xB4
+               {
+                       pi.pain.text(int(x2 - (font_metrics::rbearing(0xB4, font)
+                                     - font_metrics::lbearing(0xB4, font)) / 2),
+                                 baseline - font_metrics::ascent(ic, font)
+                                                - font_metrics::descent(0xB4, font)
+                                                - (font_metrics::ascent(0xB4, font)
+                                                 + font_metrics::descent(0xB4, font)) / 2,
+                                 char(0xB4), font);
                        break;
                }
-               case GRAVE:     // grave
+               case GRAVE:     // grave 0x60
                {
-                       scr.drawLine(pgc,int(x2), int(y+hg35),
-                                    int(x2-hg35), y); 
+                       pi.pain.text(int(x2 - (font_metrics::rbearing(0x60, font) - font_metrics::lbearing(0x60, font)) / 2),
+                                 int(baseline - font_metrics::ascent(ic, font) - font_metrics::descent(0x60, font) - (font_metrics::ascent(0x60, font) + font_metrics::descent(0x60, font)) / 2.0),
+                                 char(0x60), font);
                        break;
                }
                case MACRON:     // macron
                {
-                       scr.drawLine(pgc,
-                                    int(x2-(3*wid/7)), int(y+(hg/2) + hg35),
-                                    int(x2+(3*wid/7)), int(y+(hg/2) + hg35));
+                       pi.pain.text(int(x2 - (font_metrics::rbearing(0xAF, font) - font_metrics::lbearing(0xAF, font)) / 2),
+                                 baseline - font_metrics::ascent(ic, font) - font_metrics::descent(0xAF, font) - (font_metrics::ascent(0xAF, font) + font_metrics::descent(0xAF, font)),
+                                 char(0xAF), font);
                        break;
                }
                case TILDE:     // tilde
                {
-                       if (hg35 > 2) --hg35;
-                       x2 += (hg35/2);
-                       XPoint p[4];
-                       p[0].x = int(x2 - 2*hg35); p[0].y = int(y + hg);
-                       p[1].x = int(x2 - hg35);   p[1].y = int(y + hg35);
-                       p[2].x = int(x2);          p[2].y = int(y + hg);
-                       p[3].x = int(x2 + hg35);   p[3].y = int(y + hg35);
-                       scr.drawLines(pgc, p, 4);
+                       pi.pain.text(int(x2 - (font_metrics::rbearing('~', font) - font_metrics::lbearing('~', font)) / 2),
+                                 baseline - font_metrics::ascent(ic, font) - font_metrics::descent('~', font) - (font_metrics::ascent('~', font) + font_metrics::descent('~', font)) / 2,
+                                 '~', font);
                        break;
                }
-               case UNDERBAR:     // underbar
+               case UNDERBAR:     // underbar 0x5F
                {
-                       scr.drawLine(pgc,
-                                    int(x2-(3*wid/7)), y+(hg/2),
-                                    int(x2+(3*wid/7)), y+(hg/2));
+                       pi.pain.text(int(x2 - (font_metrics::rbearing(0x5F, font) - font_metrics::lbearing(0x5F, font)) / 2), baseline,
+                                 char(0x5F), font);
                        break;
                }
                case CEDILLA:     // cedilla
                {
-                       XPoint p[4];
-                       p[0].x = int(x2);          p[0].y = y;
-                       p[1].x = int(x2);          p[1].y = y + (hg/3);
-                       p[2].x = int(x2 + (hg/3)); p[2].y = y + (hg/2);
-                       p[3].x = int(x2 - (hg/4)); p[3].y = y + hg;
-                       scr.drawLines(pgc, p, 4);
+                       pi.pain.text(int(x2 - (font_metrics::rbearing(0xB8, font) - font_metrics::lbearing(0xB8, font)) / 2), baseline,
+                                 char(0xB8), font);
+
                        break;
                }
                case UNDERDOT:     // underdot
+               {
+                       pi.pain.text(int(x2 - (font_metrics::rbearing('.', font) - font_metrics::lbearing('.', font)) / 2.0),
+                                 int(baseline + 3.0 / 2.0 * (font_metrics::ascent('.', font) + font_metrics::descent('.', font))),
+                                 '.', font);
+                       break;
+               }
+
                case DOT:    // dot
                {
-                       scr.drawArc(pgc,int(x2), y+(hg/2),
-                                   1, 1, 0, 360*64); 
+                       pi.pain.text(int(x2 - (font_metrics::rbearing('.', font) - font_metrics::lbearing('.', font)) / 2.0),
+                                 baseline - font_metrics::ascent(ic, font) - font_metrics::descent('.', font) - (font_metrics::ascent('.', font) + font_metrics::descent('.', font)) / 2,
+                                 '.', font);
                        break;
                }
+
                case CIRCLE:     // circle
                {
-                       scr.drawArc(pgc, int(x2-(hg/2)), y, hg, hg, 0,
-                                   360*64);
+                       LyXFont tmpf = font;
+                       tmpf.decSize().decSize();
+                       pi.pain.text(int(x2 - (font_metrics::rbearing(0xB0, tmpf) - font_metrics::lbearing(0xB0, tmpf)) / 2.0),
+                                 int(baseline - font_metrics::ascent(ic, font) - font_metrics::descent(0xB0, tmpf) - (font_metrics::ascent(0xB0, tmpf) + font_metrics::descent(0xB0, tmpf)) / 3.0),
+                                 char(0xB0), tmpf);
                        break;
                }
                case TIE:     // tie
                {
-                       scr.drawArc(pgc,
-                                   int(x2), y+(hg/4),
-                                   hg, hg, 0, 11519);
+                       pi.pain.arc(int(x2 + hg35), int(y + hg / 2.0),
+                                   int(2 * hg), int(hg), 0, 360 * 32,
+                                   LColor::foreground);
                        break;
                }
                case BREVE:     // breve
                {
-                       scr.drawArc(pgc,
-                                   int(x2-(hg/2)), y-(hg/4),
-                                   hg, hg, 0, -11519);
+                       pi.pain.arc(int(x2 - (hg / 2.0)), y,
+                                   int(hg), int(hg), 0, -360*32,
+                                   LColor::foreground);
                        break;
                }
                case CARON:    // caron
                {
-                       XPoint p[3];
-                       p[0].x = int(x2 - hg35); p[0].y = y;
-                       p[1].x = int(x2);        p[1].y = int(y+hg35);
-                       p[2].x = int(x2 + hg35); p[2].y = y;
-                       scr.drawLines(pgc, p, 3);
+                       int xp[3], yp[3];
+
+                       xp[0] = int(x2 - hg35); yp[0] = int(y + hg35);
+                       xp[1] = int(x2);        yp[1] = int(y + hg);
+                       xp[2] = int(x2 + hg35); yp[2] = int(y + hg35);
+                       pi.pain.lines(xp, yp, 3, LColor::foreground);
                        break;
                }
                case SPECIAL_CARON:    // special caron
                {
                        switch (ic) {
-                       case 'L': wid = 4*wid/5; break;
-                       case 't': y -= int(hg35/2); break;
+                       case 'L': dim_.wid = int(4.0 * dim_.wid / 5.0); break;
+                       case 't': y -= int(hg35 / 2.0); break;
                        }
-                       XPoint p[3];
-                       p[0].x = int(x+wid);          p[0].y = int(y+hg35+hg);
-                       p[1].x = int(x+wid+(hg35/2)); p[1].y = int(y+ hg+(hg35/2));
-                       p[2].x = int(x+wid+(hg35/2)); p[2].y = y + hg;
-                       scr.drawLines(pgc, p, 3);
+                       int xp[3], yp[3];
+                       xp[0] = int(x + dim_.wid);
+                       yp[0] = int(y + hg35 + hg);
+
+                       xp[1] = int(x + dim_.wid + (hg35 / 2.0));
+                       yp[1] = int(y + hg + (hg35 / 2.0));
+
+                       xp[2] = int(x + dim_.wid + (hg35 / 2.0));
+                       yp[2] = y + int(hg);
+
+                       pi.pain.lines(xp, yp, 3, LColor::foreground);
                        break;
                }
                case HUNGARIAN_UMLAUT:    // hung. umlaut
                {
-                       XSegment s[2];
-                       s[0].x1= int(x2-(hg/2));      s[0].y1 = int(y + hg35);
-                       s[0].x2= int(x2+hg35-(hg/2)); s[0].y2 = y;
-                       s[1].x1= int(x2+(hg/2));      s[1].y1 = int(y + hg35);
-                       s[1].x2= int(x2+hg35+(hg/2)); s[1].y2 = y;
-
-                       scr.drawSegments(pgc, s, 2);
+                       pi.pain.text(int(x2 - (font_metrics::rbearing('´', font) - font_metrics::lbearing('´', font))),
+                                 baseline - font_metrics::ascent(ic, font) - font_metrics::descent('´', font) - (font_metrics::ascent('´', font) + font_metrics::descent('´', font)) / 2,
+                                 '´', font);
+                       pi.pain.text(int(x2),
+                                 baseline - font_metrics::ascent(ic, font) - font_metrics::descent('´', font) - (font_metrics::ascent('´', font) + font_metrics::descent('´', font)) / 2,
+                                 '´', font);
                        break;
                }
                case UMLAUT:    // umlaut
                {
-                       int tmpadd = y;
-                       tmpadd += (remdot) ? ((19*hg)/10) : ((20*hg)/27); // if (remdot) -> i or j
-                       int rad = ((hg*4)/8);
-                       if (rad <= 1) {
-                               scr.drawPoint(pgc, int(x2-((4*hg)/7)), tmpadd);
-                               scr.drawPoint(pgc, int(x2+((4*hg)/7)), tmpadd);
-                       } else {
-                               scr.drawArc(pgc, int(x2-((2*hg)/4)), tmpadd,
-                                           rad-1, rad-1, 0, 360*64);
-                               scr.drawArc(pgc, int(x2+((2*hg)/4)), tmpadd,
-                                           rad-1, rad-1, 0, 360*64);
-                       }
+                       pi.pain.text(int(x2 - (font_metrics::rbearing('¨', font) - font_metrics::lbearing('¨', font)) / 2),
+                                 baseline - font_metrics::ascent(ic, font) - font_metrics::descent('¨', font) - (font_metrics::ascent('¨', font) + font_metrics::descent('¨', font)) / 2,
+                                 '¨', font);
                        break;
                }
                case CIRCUMFLEX:    // circumflex
                {
-                       XPoint p[3];
-                       p[0].x = int(x2 - hg35); p[0].y = y + hg;
-                       p[1].x = int(x2);        p[1].y = int(y + hg35);
-                       p[2].x = int(x2 + hg35); p[2].y = y + hg;
-                       scr.drawLines(pgc, p, 3);
+                       LyXFont tmpf(font);
+                       tmpf.decSize().decSize().decSize();
+                       pi.pain.text(int(x2 - (font_metrics::rbearing(0x5E, tmpf) - font_metrics::lbearing(0x5E, tmpf)) / 2),
+                                 int(baseline - font_metrics::ascent(ic, font) - font_metrics::descent(0x5E, tmpf) - (font_metrics::ascent(0x5E, tmpf) + font_metrics::descent(0x5E, tmpf)) / 3.0),
+                                 char(0x5E), tmpf);
                        break;
                }
                case OGONEK:    // ogonek
                {
                        // this does probably not look like an ogonek, so
                        // it should certainly be refined
-                       XPoint p[4];
-                       p[0].x = int(x2);          p[0].y = y;
-                       p[1].x = int(x2);          p[1].y = y + (hg/3);
-                       p[2].x = int(x2 - (hg/3)); p[2].y = y + (hg/2);
-                       p[3].x = int(x2 + (hg/4)); p[3].y = y + hg;
-                       scr.drawLines(pgc, p, 4);
+                       int xp[4], yp[4];
+
+                       xp[0] = int(x2);
+                       yp[0] = y;
+
+                       xp[1] = int(x2);
+                       yp[1] = y + int(hg35);
+
+                       xp[2] = int(x2 - hg35);
+                       yp[2] = y + int(hg / 2.0);
+
+                       xp[3] = int(x2 + hg / 4.0);
+                       yp[3] = y + int(hg);
+
+                       pi.pain.lines(xp, yp, 4, LColor::foreground);
                        break;
                }
                case lSLASH:
                case LSLASH:
                {
-                       XPoint p[2];
-                       p[0].x = int(x);                p[0].y = y+3*hg;
-                       p[1].x = int(x+float(wid)*.75); p[1].y = y+hg;
-                       scr.drawLines(pgc, p, 2);
-                       break;
+                       int xp[2], yp[2];
+
+                       xp[0] = int(x);
+                       yp[0] = y + int(3.0 * hg);
+
+                       xp[1] = int(x + float(dim_.wid) * 0.75);
+                       yp[1] = y + int(hg);
+
+                       pi.pain.lines(xp, yp, 2, LColor::foreground);
+                       break;
                }
                case DOT_LESS_I: // dotless-i
                case DOT_LESS_J: // dotless-j
@@ -565,101 +597,80 @@ void InsetLatexAccent::Draw(LyXFont font,
                }
                }
        } else {
-               //scr.drawFilledRectangle(int(x+1), baseline - Ascent(font)+1,
-               //                      Width(font)-2,
-               //                      Ascent(font)+Descent(font)-2,
-               //                      FL_GRAY80);
-               scr.fillRectangle(gc_lighted,
-                                 int(x+1), baseline - Ascent(font)+1,
-                                 Width(font)-2,
-                                 Ascent(font)+Descent(font)-2);
-               
-               //scr.drawRectangle(int(x), baseline - Ascent(font),
-               //                Width(font)-1,
-               //                Ascent(font)+Descent(font)-1,
-               //                FL_GRAY80);
-               scr.drawRectangle(gc_lighted,
-                                 int(x), baseline - Ascent(font),
-                                 Width(font)-1,
-                                 Ascent(font)+Descent(font)-1);
-               scr.drawString(font, contents, baseline, int(x+2));
+               pi.pain.fillRectangle(x + 1,
+                                     baseline - dim_.asc + 1, dim_.wid - 2,
+                                     dim_.asc + dim_.des - 2,
+                                     backgroundColor());
+               pi.pain.rectangle(x + 1, baseline - dim_.asc + 1,
+                                 dim_.wid - 2, dim_.asc + dim_.des - 2,
+                                 LColor::foreground);
+               pi.pain.text(x + 2, baseline, contents, font);
        }
-       x +=  Width(font);
 }
 
 
-void InsetLatexAccent::Write(FILE *file)
+void InsetLatexAccent::write(Buffer const &, ostream & os) const
 {
-       fprintf(file, "\\i %s\n", contents.c_str());
+       os << "\\i " << contents << "\n";
 }
 
 
-void InsetLatexAccent::Read(LyXLex &lex)
+void InsetLatexAccent::read(Buffer const &, LyXLex & lex)
 {
-       lex.EatLine();
-       contents = lex.GetString();
+       lex.eatLine();
+       contents = lex.getString();
        checkContents();
 }
 
 
-int InsetLatexAccent::Latex(FILE *file, signed char /*fragile*/)
+int InsetLatexAccent::latex(Buffer const &, ostream & os,
+                           LatexRunParams const &) const
 {
-       fprintf(file, "%s", contents.c_str());
+       os << contents;
        return 0;
 }
 
 
-int InsetLatexAccent::Latex(string &file, signed char /*fragile*/)
+int InsetLatexAccent::ascii(Buffer const &, ostream & os, int) const
 {
-       file += contents;
+       os << contents;
        return 0;
 }
 
 
-int InsetLatexAccent::Linuxdoc(string &file)
+int InsetLatexAccent::linuxdoc(Buffer const &, ostream & os) const
 {
-       file += contents;
+       os << contents;
        return 0;
 }
 
 
-int InsetLatexAccent::DocBook(string &file)
+int InsetLatexAccent::docbook(Buffer const &, ostream & os, bool) const
 {
-       file += contents;
+       os << contents;
        return 0;
 }
 
 
-bool InsetLatexAccent::Deletable() const
-{
-       return true;
-}
-
-
-bool InsetLatexAccent::DirectWrite() const
+bool InsetLatexAccent::directWrite() const
 {
        return true;
 }
 
 
-Inset* InsetLatexAccent::Clone()
+auto_ptr<InsetBase> InsetLatexAccent::clone() const
 {
-       InsetLatexAccent *result = new InsetLatexAccent(contents);
-       return result;
+       return auto_ptr<InsetBase>(new InsetLatexAccent(contents));
 }
 
 
-Inset::Code InsetLatexAccent::LyxCode() const
+InsetOld::Code InsetLatexAccent::lyxCode() const
 {
-       return Inset::ACCENT_CODE;
+       return InsetOld::ACCENT_CODE;
 }
 
 
-bool InsetLatexAccent::IsEqual(Inset* other)
+ostream & operator<<(ostream & o, InsetLatexAccent::ACCENT_TYPES at)
 {
-       if (other && other->LyxCode() == Inset::ACCENT_CODE){
-               InsetLatexAccent* otheraccent = (InsetLatexAccent*) other;
-               return (contents == otheraccent->contents);
-       }
-       return false;
+       return o << int(at);
 }