X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Finsets%2Finsetlatexaccent.C;h=a7cc82eb0a2061db79a51636950434e99e42336f;hb=4a5b7a5952ad2381fcdf4830511293e184c7c5a1;hp=01bd28aea7d8ace358914129450bdbf70593b221;hpb=c6150425e56563ab9bb311b5785efc5e9d4928da;p=lyx.git diff --git a/src/insets/insetlatexaccent.C b/src/insets/insetlatexaccent.C index 01bd28aea7..a7cc82eb0a 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-2000 The LyX Team. + * Copyright 1995-2001 The LyX Team. * * ====================================================== */ @@ -18,8 +18,10 @@ #include "debug.h" #include "lyxrc.h" #include "support/lstrings.h" +#include "BufferView.h" #include "Painter.h" #include "font.h" +#include "language.h" using std::ostream; using std::endl; @@ -29,13 +31,12 @@ using std::endl; /* Later modified by Lars G. Bjønnes, larsbj@lyx.org */ InsetLatexAccent::InsetLatexAccent() -{ - candisp = false; -} + : candisp(false) +{} -InsetLatexAccent::InsetLatexAccent(string const & string) - : contents(string) +InsetLatexAccent::InsetLatexAccent(string const & str) + : contents(str) { checkContents(); } @@ -46,7 +47,10 @@ void InsetLatexAccent::checkContents() { 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) @@ -86,7 +90,10 @@ 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::KEY] << "Decode: " << contents << endl; @@ -191,7 +198,7 @@ void InsetLatexAccent::checkContents() // special clause for \i{}, \j{} \l{} and \L{} if ((modtype == DOT_LESS_I || modtype == DOT_LESS_J || modtype == lSLASH || modtype == LSLASH) - && contents[3] == '}' ) { + && contents[3] == '}') { switch (modtype) { case DOT_LESS_I: ic = 'i'; break; case DOT_LESS_J: ic = 'j'; break; @@ -225,13 +232,13 @@ void InsetLatexAccent::checkContents() remdot = true; else return; - } else if ( (ic == 'i'|| ic == 'j') && contents[4] == '}') { + } else if ((ic == 'i'|| ic == 'j') && contents[4] == '}') { // Do a rewrite: \{i} --> \{\i} string temp = contents; temp.erase(3, string::npos); temp += '\\'; temp += char(ic); - for(string::size_type j = 4; + for (string::size_type j = 4; j < contents.length(); ++j) temp+= contents[j]; contents= temp; @@ -254,7 +261,7 @@ void InsetLatexAccent::checkContents() } -int InsetLatexAccent::ascent(Painter &, LyXFont const & font) const +int InsetLatexAccent::ascent(BufferView *, 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 @@ -274,7 +281,7 @@ int InsetLatexAccent::ascent(Painter &, LyXFont const & font) const } -int InsetLatexAccent::descent(Painter &, LyXFont const & font) const +int InsetLatexAccent::descent(BufferView *, LyXFont const & font) const { int max; if (candisp) { @@ -290,7 +297,7 @@ int InsetLatexAccent::descent(Painter &, LyXFont const & font) const } -int InsetLatexAccent::width(Painter &, LyXFont const & font) const +int InsetLatexAccent::width(BufferView *, LyXFont const & font) const { if (candisp) return lyxfont::width(ic, font); @@ -299,19 +306,19 @@ int InsetLatexAccent::width(Painter &, LyXFont const & font) const } -int InsetLatexAccent::Lbearing(LyXFont const & font) const +int InsetLatexAccent::lbearing(LyXFont const & font) const { return lyxfont::lbearing(ic, font); } -int InsetLatexAccent::Rbearing(LyXFont const & font) const +int InsetLatexAccent::rbearing(LyXFont const & font) const { return lyxfont::rbearing(ic, font); } -bool InsetLatexAccent::DisplayISO8859_9(Painter & pain, LyXFont const & font, +bool InsetLatexAccent::displayISO8859_9(BufferView * bv, LyXFont const & font, int baseline, float & x) const { @@ -345,8 +352,8 @@ bool InsetLatexAccent::DisplayISO8859_9(Painter & pain, LyXFont const & font, } if (tmpic != ic) { char ch = char(tmpic); - pain.text(x, baseline, ch, font); - x += width(pain, font); + bv->painter().text(int(x), baseline, ch, font); + x += width(bv, font); return true; } else @@ -354,23 +361,29 @@ bool InsetLatexAccent::DisplayISO8859_9(Painter & pain, LyXFont const & font, } -void InsetLatexAccent::draw(Painter & pain, LyXFont const & font, - int baseline, float & x) const +void InsetLatexAccent::draw(BufferView * bv, LyXFont const & font0, + int baseline, float & x, bool) const { - if (lyxrc.font_norm == "iso8859-9") - if (DisplayISO8859_9(pain, font, baseline, x)) + Painter & pain = bv->painter(); + + if (lyxrc.font_norm_type == LyXRC::ISO_8859_9) + if (displayISO8859_9(bv, font0, baseline, x)) return; /* 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(font0); + if (lyxrc.font_norm_type == LyXRC::ISO_10646_1) + font.setLanguage(english_language); if (candisp) { - int asc = ascent(pain, font); - int desc = descent(pain, font); - int wid = width(pain, font); - float x2 = x + (Rbearing(font) - Lbearing(font)) / 2.0; + int asc = ascent(bv, font); + int desc = descent(bv, font); + int wid = width(bv, font); + float x2 = x + (rbearing(font) - lbearing(font)) / 2.0; float hg; int y; if (plusasc) { @@ -402,14 +415,14 @@ void InsetLatexAccent::draw(Painter & pain, LyXFont const & font, pain.fillRectangle(int(x + tmpx), tmpvar, wid, lyxfont::ascent('i', font) - lyxfont::ascent('x', font) - 1, - LColor::background); + 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 - asc = ascent(pain, font); // the dot-less version (here: 'x') + asc = ascent(bv, font); // the dot-less version (here: 'x') ic = tmpic; // set the orig ic back y = baseline - asc; // update to new y coord. } @@ -417,56 +430,56 @@ void InsetLatexAccent::draw(Painter & pain, LyXFont const & font, switch (modtype) { case ACUTE: // acute 0xB4 { - pain.text(x2 - (lyxfont::rbearing(0xB4, font) - lyxfont::lbearing(0xB4, font)) / 2, + pain.text(int(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 0x60 { - 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, + pain.text(int(x2 - (lyxfont::rbearing(0x60, font) - lyxfont::lbearing(0x60, font)) / 2), + int(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 { - pain.text(x2 - (lyxfont::rbearing(0xAF, font) - lyxfont::lbearing(0xAF, font)) / 2, + pain.text(int(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 { - pain.text(x2 - (lyxfont::rbearing('~', font) - lyxfont::lbearing('~', font)) / 2, + pain.text(int(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 0x5F { - pain.text(x2 - (lyxfont::rbearing(0x5F, font) - lyxfont::lbearing(0x5F, font)) / 2, baseline, + pain.text(int(x2 - (lyxfont::rbearing(0x5F, font) - lyxfont::lbearing(0x5F, font)) / 2), baseline, char(0x5F), font); break; } case CEDILLA: // cedilla { - pain.text(x2 - (lyxfont::rbearing(0xB8, font) - lyxfont::lbearing(0xB8, font)) / 2, baseline, + pain.text(int(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)), + pain.text(int(x2 - (lyxfont::rbearing('.', font) - lyxfont::lbearing('.', font)) / 2.0), + int(baseline + 3.0 / 2.0 * (lyxfont::ascent('.', font) + lyxfont::descent('.', font))), '.', font); break; } case DOT: // dot { - pain.text(x2 - (lyxfont::rbearing('.', font) - lyxfont::lbearing('.', font)) / 2.0, + pain.text(int(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; @@ -476,21 +489,21 @@ void InsetLatexAccent::draw(Painter & pain, LyXFont const & font, { 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, + pain.text(int(x2 - (lyxfont::rbearing(0xB0, tmpf) - lyxfont::lbearing(0xB0, tmpf)) / 2.0), + int(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 { - pain.arc(int(x2 + hg35), y + hg / 2.0, - 2 * hg, hg, 0, 360 * 32); + pain.arc(int(x2 + hg35), int(y + hg / 2.0), + int(2 * hg), int(hg), 0, 360 * 32); break; } case BREVE: // breve { pain.arc(int(x2 - (hg / 2.0)), y, - hg, hg, 0, -360*32); + int(hg), int(hg), 0, -360*32); break; } case CARON: // caron @@ -524,18 +537,18 @@ void InsetLatexAccent::draw(Painter & pain, LyXFont const & font, } case HUNGARIAN_UMLAUT: // hung. umlaut { - pain.text(x2 - (lyxfont::rbearing('´', font) - lyxfont::lbearing('´', font)), + pain.text(int(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, + pain.text(int(x2), baseline - lyxfont::ascent(ic, font) - lyxfont::descent('´', font) - (lyxfont::ascent('´', font) + lyxfont::descent('´', font)) / 2, '´', font); break; } case UMLAUT: // umlaut { - 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, + pain.text(int(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; } @@ -543,8 +556,8 @@ void InsetLatexAccent::draw(Painter & pain, LyXFont const & font, { 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, + pain.text(int(x2 - (lyxfont::rbearing(0x5E, tmpf) - lyxfont::lbearing(0x5E, tmpf)) / 2), + int(baseline - lyxfont::ascent(ic, font) - lyxfont::descent(0x5E, tmpf) - (lyxfont::ascent(0x5E, tmpf) + lyxfont::descent(0x5E, tmpf)) / 3.0), char(0x5E), tmpf); break; } @@ -592,34 +605,35 @@ void InsetLatexAccent::draw(Painter & pain, LyXFont const & font, } } else { 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); + baseline - ascent(bv, font) + 1, + width(bv, font) - 2, + ascent(bv, font) + + descent(bv, font) - 2, + backgroundColor()); + pain.rectangle(int(x + 1), baseline - ascent(bv, font) + 1, + width(bv, font) - 2, + ascent(bv, font) + descent(bv, font) - 2); pain.text(int(x + 2), baseline, contents, font); } - x += width(pain, font); + x += width(bv, font); } -void InsetLatexAccent::Write(ostream & os) const +void InsetLatexAccent::write(Buffer const *, ostream & os) const { 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(ostream & os, +int InsetLatexAccent::latex(Buffer const *, ostream & os, bool /*fragile*/, bool/*fs*/) const { os << contents; @@ -627,46 +641,46 @@ int InsetLatexAccent::Latex(ostream & os, } -int InsetLatexAccent::Ascii(ostream & os) const +int InsetLatexAccent::ascii(Buffer const *, ostream & os, int) const { os << contents; return 0; } -int InsetLatexAccent::Linuxdoc(ostream & os) const +int InsetLatexAccent::linuxdoc(Buffer const *, ostream & os) const { os << contents; return 0; } -int InsetLatexAccent::DocBook(ostream & os) const +int InsetLatexAccent::docbook(Buffer const *, ostream & os) const { os << contents; return 0; } -bool InsetLatexAccent::Deletable() const +bool InsetLatexAccent::deletable() const { return true; } -bool InsetLatexAccent::DirectWrite() const +bool InsetLatexAccent::directWrite() const { return true; } -Inset * InsetLatexAccent::Clone() const +Inset * InsetLatexAccent::clone(Buffer const &, bool) const { return new InsetLatexAccent(contents); } -Inset::Code InsetLatexAccent::LyxCode() const +Inset::Code InsetLatexAccent::lyxCode() const { return Inset::ACCENT_CODE; }