X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Finsets%2Finsetlatexaccent.C;h=01bd28aea7d8ace358914129450bdbf70593b221;hb=3c8aba3b556871fb1100a2f98cd93d5d4e3f70c9;hp=53df124be154231dec531760ec1b2188e8fc6323;hpb=7c6267e4b10364cc892776e0a426eb32ade6b0b4;p=lyx.git diff --git a/src/insets/insetlatexaccent.C b/src/insets/insetlatexaccent.C index 53df124be1..01bd28aea7 100644 --- a/src/insets/insetlatexaccent.C +++ b/src/insets/insetlatexaccent.C @@ -4,7 +4,7 @@ * LyX, The Document Processor * * Copyright 1995 Matthias Ettrich - * Copyright 1995-1999 The LyX Team. + * Copyright 1995-2000 The LyX Team. * * ====================================================== */ @@ -17,10 +17,12 @@ #include "insetlatexaccent.h" #include "debug.h" #include "lyxrc.h" -#include "lyxdraw.h" #include "support/lstrings.h" +#include "Painter.h" +#include "font.h" -extern LyXRC * lyxrc; +using std::ostream; +using std::endl; /* LatexAccent. Proper handling of accented characters */ /* This part is done by Ivan Schreter, schreter@ccsun.tuke.sk */ @@ -32,17 +34,6 @@ InsetLatexAccent::InsetLatexAccent() } -InsetLatexAccent::InsetLatexAccent(InsetLatexAccent const & other) - : Inset(), contents(other.contents), - candisp(other.candisp), - modtype(other.modtype), - remdot(other.remdot), - plusasc(other.plusasc), - plusdesc(other.plusdesc), - ic(other.ic) -{} - - InsetLatexAccent::InsetLatexAccent(string const & string) : contents(string) { @@ -97,7 +88,7 @@ void InsetLatexAccent::checkContents() } if (contents[0] != '\\') return; // demand that first char is a '\\' - lyxerr.debug() << "Decode: " << contents << endl; + lyxerr[Debug::KEY] << "Decode: " << contents << endl; remdot = false; plusasc = false; plusdesc = false; @@ -189,7 +180,7 @@ void InsetLatexAccent::checkContents() plusasc = true; // at the top (not really needed) break; default: - printf ("Default\n"); + lyxerr[Debug::KEY] << "Default" << endl; // unknow accent (or something else) return; } @@ -212,12 +203,12 @@ void InsetLatexAccent::checkContents() break; } //ic = (modtype == DOT_LESS_J ? 'j' : 'i'); - lyxerr.debug() << "Contents: [" << contents << "]" - << ", ic: " << ic - << ", top: " << plusasc - << ", bot: " << plusdesc - << ", dot: " << remdot - << ", mod: " << modtype << endl; + 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 = ' '; @@ -252,18 +243,18 @@ void InsetLatexAccent::checkContents() if (contents[++i] != '}' && contents[++i]) return; // fine, the char is properly decoded now (hopefully) - lyxerr.debug() << "Contents: [" << contents << "]" - << ", ic: " << ic - << ", top: " << plusasc - << ", bot: " << plusdesc - << ", dot: " << remdot - << ", mod: " << modtype << endl; + lyxerr[Debug::KEY] << "Contents: [" << contents << "]" + << ", ic: " << ic + << ", top: " << plusasc + << ", bot: " << plusdesc + << ", dot: " << remdot + << ", mod: " << modtype << endl; } candisp = true; } -int InsetLatexAccent::Ascent(LyXFont const & font) const +int InsetLatexAccent::ascent(Painter &, LyXFont const & font) const { // This function is a bit too simplistix and is just a // "try to make a fit for all accents" approach, to @@ -272,58 +263,57 @@ int InsetLatexAccent::Ascent(LyXFont const & font) const int max; if (candisp) { if (ic == ' ') - max = font.ascent('a'); + max = lyxfont::ascent('a', font); else - max = font.ascent(ic); + max = lyxfont::ascent(ic, font); if (plusasc) - max += (font.maxAscent() + 3) / 3; + max += (lyxfont::maxAscent(font) + 3) / 3; } else - max = font.maxAscent() + 4; + max = lyxfont::maxAscent(font) + 4; return max; } -int InsetLatexAccent::Descent(LyXFont const & font) const +int InsetLatexAccent::descent(Painter &, LyXFont const & font) const { int max; if (candisp) { if (ic == ' ') - max = font.descent('a'); - else - max = font.descent(ic); + max = lyxfont::descent('a', font); + else + max = lyxfont::descent(ic, font); if (plusdesc) max += 3; } else - max = font.maxDescent() + 4; + max = lyxfont::maxDescent(font) + 4; return max; } -int InsetLatexAccent::Width(LyXFont const & font) const +int InsetLatexAccent::width(Painter &, LyXFont const & font) const { if (candisp) - return font.textWidth(&ic, 1); + return lyxfont::width(ic, font); else - return font.stringWidth(contents) + 4; + return lyxfont::width(contents, font) + 4; } int InsetLatexAccent::Lbearing(LyXFont const & font) const { - return font.lbearing(ic); + return lyxfont::lbearing(ic, font); } int InsetLatexAccent::Rbearing(LyXFont const & font) const { - return font.rbearing(ic); + return lyxfont::rbearing(ic, font); } -bool InsetLatexAccent::DisplayISO8859_9(LyXFont font, - LyXScreen & scr, +bool InsetLatexAccent::DisplayISO8859_9(Painter & pain, LyXFont const & font, int baseline, - float & x) + float & x) const { unsigned char tmpic = ic; @@ -355,8 +345,8 @@ bool InsetLatexAccent::DisplayISO8859_9(LyXFont font, } if (tmpic != ic) { char ch = char(tmpic); - scr.drawText(font, &ch, 1, baseline, int(x)); - x += Width (font); + pain.text(x, baseline, ch, font); + x += width(pain, font); return true; } else @@ -364,13 +354,11 @@ bool InsetLatexAccent::DisplayISO8859_9(LyXFont font, } -void InsetLatexAccent::Draw(LyXFont font, - LyXScreen & scr, - int baseline, - float & x) +void InsetLatexAccent::draw(Painter & pain, LyXFont const & font, + int baseline, float & x) const { - if (lyxrc->font_norm == "iso8859-9") - if (DisplayISO8859_9 (font, scr, baseline, x)) + if (lyxrc.font_norm == "iso8859-9") + if (DisplayISO8859_9(pain, font, baseline, x)) return; /* draw it! */ @@ -379,16 +367,15 @@ void InsetLatexAccent::Draw(LyXFont font, // should also be considered. if (candisp) { - int asc = Ascent(font); - int desc = Descent(font); - int wid = Width(font); + int asc = ascent(pain, font); + int desc = descent(pain, font); + int wid = width(pain, font); float x2 = x + (Rbearing(font) - Lbearing(font)) / 2.0; - float hg35; float hg; int y; if (plusasc) { // mark at the top - hg = font.maxDescent(); + hg = lyxfont::maxDescent(font); y = baseline - asc; if (font.shape() == LyXFont::ITALIC_SHAPE) @@ -399,116 +386,121 @@ void InsetLatexAccent::Draw(LyXFont font, y = baseline; } - hg35 = float(hg * 3.0) / 5.0; + 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, int((hg + 3.0) / 5.0)); + pain.text(int(x), baseline, ic, font); if (remdot) { - int tmpvar = baseline - font.ascent('i'); + int tmpvar = baseline - lyxfont::ascent('i', font); float tmpx = 0; if (font.shape() == LyXFont::ITALIC_SHAPE) tmpx += (8.0 * hg) / 10.0; // italic - lyxerr.debug() << "Removing dot." << endl; + 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); + pain.fillRectangle(int(x + tmpx), tmpvar, wid, + lyxfont::ascent('i', font) - + lyxfont::ascent('x', font) - 1, + LColor::background); + // 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 + asc = ascent(pain, font); // 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) switch (modtype) { - case ACUTE: // acute + case ACUTE: // acute 0xB4 { - scr.drawLine(pgc, int(x2), int(y + hg35), - int(x2 + hg35), y); + pain.text(x2 - (lyxfont::rbearing(0xB4, font) - lyxfont::lbearing(0xB4, font)) / 2, + baseline - lyxfont::ascent(ic, font) - lyxfont::descent(0xB4, font) - (lyxfont::ascent(0xB4, font) + lyxfont::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); + pain.text(x2 - (lyxfont::rbearing(0x60, font) - lyxfont::lbearing(0x60, font)) / 2, + baseline - lyxfont::ascent(ic, font) - lyxfont::descent(0x60, font) - (lyxfont::ascent(0x60, font) + lyxfont::descent(0x60, font)) / 2.0, + char(0x60), font); break; } case MACRON: // macron { - scr.drawLine(pgc, - int(x2 - (3.0 * wid / 7.0)), - int(y + (hg / 2.0) + hg35), - int(x2 + (3.0 * wid / 7.0)), - int(y + (hg / 2.0) + hg35)); + pain.text(x2 - (lyxfont::rbearing(0xAF, font) - lyxfont::lbearing(0xAF, font)) / 2, + baseline - lyxfont::ascent(ic, font) - lyxfont::descent(0xAF, font) - (lyxfont::ascent(0xAF, font) + lyxfont::descent(0xAF, font)), + char(0xAF), font); break; } case TILDE: // tilde { - if (hg35 > 2.0) hg35 -= 1.0; - x2 += (hg35 / 2.0); - XPoint p[4]; - p[0].x = int(x2 - 2.0 * 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); + pain.text(x2 - (lyxfont::rbearing('~', font) - lyxfont::lbearing('~', font)) / 2, + baseline - lyxfont::ascent(ic, font) - lyxfont::descent('~', font) - (lyxfont::ascent('~', font) + lyxfont::descent('~', font)) / 2, + '~', font); break; } - case UNDERBAR: // underbar + case UNDERBAR: // underbar 0x5F { - scr.drawLine(pgc, - int(x2 - (3.0 * wid / 7.0)), - y + (hg / 2.0), - int(x2 + (3.0 * wid / 7.0)), - y + (hg / 2.0)); + pain.text(x2 - (lyxfont::rbearing(0x5F, font) - lyxfont::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 + int(hg / 3.0); - p[2].x = int(x2 + (hg / 3.0)); - p[2].y = y + int(hg / 2.0); - p[3].x = int(x2 - (hg / 4.0)); p[3].y = y + int(hg); - scr.drawLines(pgc, p, 4); + pain.text(x2 - (lyxfont::rbearing(0xB8, font) - lyxfont::lbearing(0xB8, font)) / 2, baseline, + char(0xB8), font); + break; } case UNDERDOT: // underdot + { + pain.text(x2 - (lyxfont::rbearing('.', font) - lyxfont::lbearing('.', font)) / 2.0, + baseline + 3.0 / 2.0 * (lyxfont::ascent('.', font) + lyxfont::descent('.', font)), + '.', font); + break; + } + case DOT: // dot { - scr.fillArc(pgc, int(x2), y + (hg / 2.0), - 1, 1, 0, 360*64); + pain.text(x2 - (lyxfont::rbearing('.', font) - lyxfont::lbearing('.', font)) / 2.0, + baseline - lyxfont::ascent(ic, font) - lyxfont::descent('.', font) - (lyxfont::ascent('.', font) + lyxfont::descent('.', font)) / 2, + '.', font); break; } + case CIRCLE: // circle { - scr.drawArc(pgc, int(x2 - (hg / 2.0)), - y + (hg / 2.0), hg, hg, 0, - 360*64); + LyXFont tmpf(font); + tmpf.decSize().decSize(); + pain.text(x2 - (lyxfont::rbearing(0xB0, tmpf) - lyxfont::lbearing(0xB0, tmpf)) / 2.0, + baseline - lyxfont::ascent(ic, font) - lyxfont::descent(0xB0, tmpf) - (lyxfont::ascent(0xB0, tmpf) + lyxfont::descent(0xB0, tmpf)) / 3.0, + char(0xB0), tmpf); break; } case TIE: // tie { - scr.drawArc(pgc, - int(x2), y + (hg / 4.0), - hg, hg, 0, 11519); + pain.arc(int(x2 + hg35), y + hg / 2.0, + 2 * hg, hg, 0, 360 * 32); break; } case BREVE: // breve { - scr.drawArc(pgc, - int(x2 - (hg / 2.0)), y - (hg / 4.0), - hg, hg, 0, -11519); + pain.arc(int(x2 - (hg / 2.0)), y, + hg, hg, 0, -360*32); 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); + pain.lines(xp, yp, 3); break; } case SPECIAL_CARON: // special caron @@ -517,85 +509,78 @@ void InsetLatexAccent::Draw(LyXFont font, case 'L': wid = int(4.0 * 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.0)); - p[1].y = int(y + hg + (hg35 / 2.0)); - p[2].x = int(x + wid + (hg35 / 2.0)); - p[2].y = y + int(hg); - scr.drawLines(pgc, p, 3); + int xp[3], yp[3]; + xp[0] = int(x + wid); + yp[0] = int(y + hg35 + hg); + + xp[1] = int(x + wid + (hg35 / 2.0)); + yp[1] = int(y + hg + (hg35 / 2.0)); + + xp[2] = int(x + wid + (hg35 / 2.0)); + yp[2] = y + int(hg); + + pain.lines(xp, yp, 3); break; } case HUNGARIAN_UMLAUT: // hung. umlaut { - XSegment s[2]; - s[0].x1= int(x2 - (hg / 2.0)); s[0].y1 = int(y + hg35); - s[0].x2= int(x2 + hg35 - (hg / 2.0)); s[0].y2 = y; - s[1].x1= int(x2 + (hg / 2.0)); - s[1].y1 = int(y + hg35); - s[1].x2= int(x2 + hg35 + (hg / 2.0)); s[1].y2 = y; - - scr.drawSegments(pgc, s, 2); + pain.text(x2 - (lyxfont::rbearing('´', font) - lyxfont::lbearing('´', font)), + baseline - lyxfont::ascent(ic, font) - lyxfont::descent('´', font) - (lyxfont::ascent('´', font) + lyxfont::descent('´', font)) / 2, + '´', font); + pain.text(x2, + baseline - lyxfont::ascent(ic, font) - lyxfont::descent('´', font) - (lyxfont::ascent('´', font) + lyxfont::descent('´', font)) / 2, + '´', font); break; } case UMLAUT: // umlaut { - float tmpadd = y; - tmpadd += (remdot) ? - asc / 3.0 : - asc / 5.0; // if (remdot) -> i or j - float rad = hg / 2.0; - if (rad <= 1.0) { - scr.drawPoint(pgc, - int(x2 - ((4.0 * hg) / 7.0)), - tmpadd); - scr.drawPoint(pgc, - int(x2 + ((4.0 * hg) / 7.0)), - tmpadd); - } else { - rad += .5; // this ensures that f.ex. 1.5 will - // not be rounded down to .5 and then - // converted to int = 0 - scr.fillArc(pgc, int(x2 - ((2.0 * hg) / 4.0)), - tmpadd, - rad, rad, 0, 360*64); - scr.fillArc(pgc, int(x2 + ((2.0 * hg) / 4.0)), - tmpadd, - rad, rad, 0, 360*64); - } + pain.text(x2 - (lyxfont::rbearing('¨', font) - lyxfont::lbearing('¨', font)) / 2, + baseline - lyxfont::ascent(ic, font) - lyxfont::descent('¨', font) - ( lyxfont::ascent('¨', font) + lyxfont::descent('¨', font)) / 2, + '¨', font); break; } case CIRCUMFLEX: // circumflex { - XPoint p[3]; - p[0].x = int(x2 - hg35); p[0].y = y + int(hg); - p[1].x = int(x2); p[1].y = int(y + hg35); - p[2].x = int(x2 + hg35); p[2].y = y + int(hg); - scr.drawLines(pgc, p, 3); + LyXFont tmpf(font); + tmpf.decSize().decSize().decSize(); + pain.text(x2 - (lyxfont::rbearing(0x5E, tmpf) - lyxfont::lbearing(0x5E, tmpf)) / 2, + baseline - lyxfont::ascent(ic, font) - lyxfont::descent(0x5E, tmpf) - (lyxfont::ascent(0x5E, tmpf) + lyxfont::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 + int(hg / 3.0); - p[2].x = int(x2 - (hg / 3.0)); - p[2].y = y + int(hg / 2.0); - p[3].x = int(x2 + (hg / 4.0)); p[3].y = y + int(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); + + pain.lines(xp, yp, 4); break; } case lSLASH: case LSLASH: { - XPoint p[2]; - p[0].x = int(x); - p[0].y = y + int(3.0 * hg); - p[1].x = int(x + float(wid) * 0.75); - p[1].y = y + int(hg); - scr.drawLines(pgc, p, 2); + int xp[2], yp[2]; + + xp[0] = int(x); + yp[0] = y + int(3.0 * hg); + + xp[1] = int(x + float(wid) * 0.75); + yp[1] = y + int(hg); + + pain.lines(xp, yp, 2); break; } case DOT_LESS_I: // dotless-i @@ -606,22 +591,21 @@ void InsetLatexAccent::Draw(LyXFont font, } } } else { - scr.fillRectangle(gc_lighted, - int(x + 1), baseline - Ascent(font) + 1, - Width(font) - 2, - Ascent(font) + Descent(font) - 2); - - 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)); + pain.fillRectangle(int(x + 1), + baseline - ascent(pain, font) + 1, + width(pain, font) - 2, + ascent(pain, font) + + descent(pain, font) - 2); + pain.rectangle(int(x + 1), baseline - ascent(pain, font) + 1, + width(pain, font) - 2, + ascent(pain, font) + descent(pain, font) - 2); + pain.text(int(x + 2), baseline, contents, font); } - x += Width(font); + x += width(pain, font); } -void InsetLatexAccent::Write(ostream & os) +void InsetLatexAccent::Write(ostream & os) const { os << "\\i " << contents << "\n"; } @@ -635,30 +619,31 @@ void InsetLatexAccent::Read(LyXLex & lex) } -int InsetLatexAccent::Latex(ostream & os, signed char /*fragile*/) +int InsetLatexAccent::Latex(ostream & os, + bool /*fragile*/, bool/*fs*/) const { os << contents; return 0; } -int InsetLatexAccent::Latex(string & file, signed char /*fragile*/) +int InsetLatexAccent::Ascii(ostream & os) const { - file += contents; + os << contents; return 0; } -int InsetLatexAccent::Linuxdoc(string & file) +int InsetLatexAccent::Linuxdoc(ostream & os) const { - file += contents; + os << contents; return 0; } -int InsetLatexAccent::DocBook(string & file) +int InsetLatexAccent::DocBook(ostream & os) const { - file += contents; + os << contents; return 0; }