2002-09-25 14:26:13 +00:00
|
|
|
|
/**
|
|
|
|
|
* \file insetlatexaccent.C
|
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
|
* Licence details can be found in the file COPYING.
|
2002-03-21 17:09:55 +00:00
|
|
|
|
*
|
2002-09-25 14:26:13 +00:00
|
|
|
|
* \author Lars Gullik Bj<EFBFBD>nnes
|
2002-03-21 17:09:55 +00:00
|
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
|
* Full author contact details are available in file CREDITS.
|
2002-09-25 14:26:13 +00:00
|
|
|
|
*/
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
|
|
#include "insetlatexaccent.h"
|
2003-05-16 07:44:00 +00:00
|
|
|
|
|
1999-10-07 18:44:17 +00:00
|
|
|
|
#include "debug.h"
|
2001-04-05 12:26:41 +00:00
|
|
|
|
#include "language.h"
|
2003-09-16 09:44:34 +00:00
|
|
|
|
#include "LColor.h"
|
2002-07-21 21:21:06 +00:00
|
|
|
|
#include "lyxlex.h"
|
2003-09-05 09:01:27 +00:00
|
|
|
|
#include "lyxrc.h"
|
2003-05-30 06:48:24 +00:00
|
|
|
|
#include "metricsinfo.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2006-10-07 16:15:06 +00:00
|
|
|
|
#include "frontends/FontMetrics.h"
|
2003-09-05 09:01:27 +00:00
|
|
|
|
#include "frontends/Painter.h"
|
|
|
|
|
|
|
|
|
|
#include "support/lstrings.h"
|
|
|
|
|
|
2006-08-13 22:54:59 +00:00
|
|
|
|
using lyx::char_type;
|
|
|
|
|
using lyx::docstring;
|
2006-10-19 16:51:30 +00:00
|
|
|
|
using lyx::odocstream;
|
2003-09-09 22:13:45 +00:00
|
|
|
|
using lyx::support::contains;
|
|
|
|
|
using lyx::support::trim;
|
2003-06-30 23:56:22 +00:00
|
|
|
|
|
2000-03-28 02:18:55 +00:00
|
|
|
|
using std::endl;
|
2003-10-06 15:43:21 +00:00
|
|
|
|
using std::string;
|
2003-07-25 17:11:25 +00:00
|
|
|
|
using std::auto_ptr;
|
2003-09-05 09:01:27 +00:00
|
|
|
|
using std::ostream;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2003-05-16 07:44:00 +00:00
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
/* LatexAccent. Proper handling of accented characters */
|
|
|
|
|
/* This part is done by Ivan Schreter, schreter@ccsun.tuke.sk */
|
1999-12-16 06:43:25 +00:00
|
|
|
|
/* Later modified by Lars G. Bj<42>nnes, larsbj@lyx.org */
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
InsetLatexAccent::InsetLatexAccent()
|
2000-07-15 23:51:46 +00:00
|
|
|
|
: candisp(false)
|
|
|
|
|
{}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
|
2000-07-15 23:51:46 +00:00
|
|
|
|
InsetLatexAccent::InsetLatexAccent(string const & str)
|
|
|
|
|
: contents(str)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
|
|
|
|
checkContents();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-11-23 23:04:52 +00:00
|
|
|
|
auto_ptr<InsetBase> InsetLatexAccent::doClone() const
|
2003-10-28 11:18:40 +00:00
|
|
|
|
{
|
|
|
|
|
return auto_ptr<InsetBase>(new InsetLatexAccent(contents));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
void InsetLatexAccent::checkContents()
|
2002-03-21 17:09:55 +00:00
|
|
|
|
// check, if we know the modifier and can display it ok on screen
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2002-03-21 17:09:55 +00:00
|
|
|
|
candisp = false;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2001-08-07 08:48:27 +00:00
|
|
|
|
if (contents.empty() || contents.length() < 2) {
|
|
|
|
|
lyxerr[Debug::KEY] << "Cannot decode: " << contents << endl;
|
|
|
|
|
return;
|
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2002-07-28 22:50:13 +00:00
|
|
|
|
contents = trim(contents);
|
2002-03-21 17:09:55 +00:00
|
|
|
|
if (contents[0] != '\\') { // demand that first char is a '\\'
|
2001-08-07 08:48:27 +00:00
|
|
|
|
lyxerr[Debug::KEY] << "Cannot decode: " << contents << endl;
|
|
|
|
|
return;
|
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2000-01-25 12:35:27 +00:00
|
|
|
|
lyxerr[Debug::KEY] << "Decode: " << contents << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2003-05-16 07:44:00 +00:00
|
|
|
|
remdot = false;
|
|
|
|
|
plusasc = false;
|
|
|
|
|
plusdesc = false;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2002-03-21 17:09:55 +00:00
|
|
|
|
switch (contents[1]) { // second char should be one of these
|
1999-09-27 18:44:28 +00:00
|
|
|
|
case '\'': // acute
|
2002-03-21 17:09:55 +00:00
|
|
|
|
modtype = ACUTE; // acute
|
|
|
|
|
plusasc = true; // at the top of character
|
|
|
|
|
break;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
case '`': // grave
|
2002-03-21 17:09:55 +00:00
|
|
|
|
modtype = GRAVE; // grave
|
|
|
|
|
plusasc = true; // at the top
|
|
|
|
|
break;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
case '=': // macron
|
2002-03-21 17:09:55 +00:00
|
|
|
|
modtype = MACRON; // macron
|
|
|
|
|
plusasc = true; // at the top
|
|
|
|
|
break;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
case '~': // tilde
|
2002-03-21 17:09:55 +00:00
|
|
|
|
modtype = TILDE; // tilde
|
|
|
|
|
plusasc = true; // at the top
|
|
|
|
|
break;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
case 'b': // underbar
|
2002-03-21 17:09:55 +00:00
|
|
|
|
modtype = UNDERBAR; // underbar
|
|
|
|
|
plusdesc = true; // at the bottom
|
|
|
|
|
break;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
case 'c': // cedilla
|
2002-03-21 17:09:55 +00:00
|
|
|
|
modtype = CEDILLA; // cedilla
|
|
|
|
|
plusdesc = true; // at the bottom
|
|
|
|
|
break;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
case 'd': // underdot
|
2002-03-21 17:09:55 +00:00
|
|
|
|
modtype = UNDERDOT; // underdot
|
|
|
|
|
plusdesc = true; // at the bottom
|
|
|
|
|
break;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
case 'r': // circle
|
2002-03-21 17:09:55 +00:00
|
|
|
|
modtype = CIRCLE; // circle
|
|
|
|
|
plusasc = true; // at the top
|
|
|
|
|
break;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
case 't': // tie
|
2002-03-21 17:09:55 +00:00
|
|
|
|
modtype = TIE; // tie
|
|
|
|
|
plusasc = true; // at the top
|
|
|
|
|
break;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
case 'u': // breve
|
2002-03-21 17:09:55 +00:00
|
|
|
|
modtype = BREVE; // breve
|
|
|
|
|
plusasc = true; // at the top
|
|
|
|
|
break;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
case 'v': // caron
|
2002-03-21 17:09:55 +00:00
|
|
|
|
modtype = CARON; // caron
|
|
|
|
|
plusasc = true; // at the top
|
|
|
|
|
break;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
case 'q': // special caron
|
2002-03-21 17:09:55 +00:00
|
|
|
|
modtype = SPECIAL_CARON; // special caron
|
|
|
|
|
plusasc = true; // at the top
|
|
|
|
|
break;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
case 'H': // hungarian umlaut
|
2002-03-21 17:09:55 +00:00
|
|
|
|
modtype = HUNGARIAN_UMLAUT; // hungarian umlaut
|
|
|
|
|
plusasc = true; // at the top
|
|
|
|
|
break;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
case '"': // umlaut
|
2002-03-21 17:09:55 +00:00
|
|
|
|
modtype = UMLAUT; // umlaut
|
|
|
|
|
plusasc = true; // at the top
|
|
|
|
|
break;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
case '.': // dot
|
2002-03-21 17:09:55 +00:00
|
|
|
|
modtype = DOT; // dot
|
|
|
|
|
plusasc = true; // at the top
|
|
|
|
|
break;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
case '^': // circumflex
|
2002-03-21 17:09:55 +00:00
|
|
|
|
modtype = CIRCUMFLEX; // circumflex
|
|
|
|
|
plusasc = true; // at the top
|
|
|
|
|
break;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
case 'k': // ogonek
|
|
|
|
|
modtype = OGONEK; // ogonek
|
|
|
|
|
plusdesc = true;
|
|
|
|
|
break;
|
|
|
|
|
case 'i': // dot-less-i
|
|
|
|
|
modtype = DOT_LESS_I; // dot-less-i
|
|
|
|
|
plusasc = true; // at the top (not really needed)
|
|
|
|
|
remdot = true;
|
|
|
|
|
break;
|
|
|
|
|
case 'j': // dot-less-j
|
|
|
|
|
modtype = DOT_LESS_J; // dot-less-j
|
|
|
|
|
plusasc = true; // at the top (not really needed)
|
|
|
|
|
remdot = true;
|
|
|
|
|
break;
|
2002-03-21 17:09:55 +00:00
|
|
|
|
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;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
default:
|
2000-04-11 16:57:16 +00:00
|
|
|
|
lyxerr[Debug::KEY] << "Default" << endl;
|
2005-05-17 11:11:45 +00:00
|
|
|
|
// unknown accent (or something else)
|
2002-03-21 17:09:55 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
// 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
|
1999-12-16 06:43:25 +00:00
|
|
|
|
|| modtype == lSLASH || modtype == LSLASH)
|
2000-11-04 10:00:12 +00:00
|
|
|
|
&& contents[3] == '}') {
|
1999-09-27 18:44:28 +00:00
|
|
|
|
switch (modtype) {
|
|
|
|
|
case DOT_LESS_I: ic = 'i'; break;
|
|
|
|
|
case DOT_LESS_J: ic = 'j'; break;
|
|
|
|
|
case lSLASH: ic = 'l'; break;
|
|
|
|
|
case LSLASH: ic = 'L'; break;
|
|
|
|
|
default:
|
|
|
|
|
// if this happens something is really wrong
|
1999-10-07 18:44:17 +00:00
|
|
|
|
lyxerr << "InsetLaTexAccent: weird error." << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
//ic = (modtype == DOT_LESS_J ? 'j' : 'i');
|
2002-11-27 10:30:28 +00:00
|
|
|
|
lyxerr[Debug::KEY] << "Contents: [" << contents << ']'
|
2002-03-21 17:09:55 +00:00
|
|
|
|
<< ", ic: " << ic
|
|
|
|
|
<< ", top: " << plusasc
|
|
|
|
|
<< ", bot: " << plusdesc
|
|
|
|
|
<< ", dot: " << remdot
|
2000-01-25 12:35:27 +00:00
|
|
|
|
<< ", mod: " << modtype << endl;
|
1999-12-16 06:43:25 +00:00
|
|
|
|
// Special case for space
|
1999-09-27 18:44:28 +00:00
|
|
|
|
} else if (contents[3] == '}') {
|
|
|
|
|
ic = ' ';
|
|
|
|
|
} else {
|
|
|
|
|
int i = 3;
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
// now get the char
|
|
|
|
|
ic = contents[3]; // i will always be 3 here
|
|
|
|
|
|
|
|
|
|
// ic should now be a alfa-char or '\\'
|
|
|
|
|
if (ic == '\\') {
|
|
|
|
|
ic = contents[++i]; // will only allow \<foo>{\i} and \<foo>{\j}
|
|
|
|
|
if (ic == 'i' || ic == 'j')
|
|
|
|
|
remdot = true;
|
|
|
|
|
else
|
|
|
|
|
return;
|
2000-11-04 10:00:12 +00:00
|
|
|
|
} else if ((ic == 'i'|| ic == 'j') && contents[4] == '}') {
|
1999-12-16 06:43:25 +00:00
|
|
|
|
// Do a rewrite: \<foo>{i} --> \<foo>{\i}
|
|
|
|
|
string temp = contents;
|
|
|
|
|
temp.erase(3, string::npos);
|
|
|
|
|
temp += '\\';
|
|
|
|
|
temp += char(ic);
|
2000-11-04 10:00:12 +00:00
|
|
|
|
for (string::size_type j = 4;
|
1999-12-16 06:43:25 +00:00
|
|
|
|
j < contents.length(); ++j)
|
1999-11-15 10:58:38 +00:00
|
|
|
|
temp+= contents[j];
|
1999-12-16 06:43:25 +00:00
|
|
|
|
contents= temp;
|
|
|
|
|
++i;
|
1999-11-04 01:40:20 +00:00
|
|
|
|
remdot = true;
|
2002-03-21 17:09:55 +00:00
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
// demand a '}' at the end
|
|
|
|
|
if (contents[++i] != '}' && contents[++i]) return;
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
// fine, the char is properly decoded now (hopefully)
|
2002-11-27 10:30:28 +00:00
|
|
|
|
lyxerr[Debug::KEY] << "Contents: [" << contents << ']'
|
2000-01-25 12:35:27 +00:00
|
|
|
|
<< ", ic: " << ic
|
2002-03-21 17:09:55 +00:00
|
|
|
|
<< ", top: " << plusasc
|
|
|
|
|
<< ", bot: " << plusdesc
|
2000-01-25 12:35:27 +00:00
|
|
|
|
<< ", dot: " << remdot
|
|
|
|
|
<< ", mod: " << modtype << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2002-03-21 17:09:55 +00:00
|
|
|
|
candisp = true;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-06-02 10:03:27 +00:00
|
|
|
|
void InsetLatexAccent::metrics(MetricsInfo & mi, Dimension & dim) const
|
2000-02-10 17:53:36 +00:00
|
|
|
|
{
|
2003-06-02 10:03:27 +00:00
|
|
|
|
LyXFont & font = mi.base.font;
|
2006-10-11 17:24:46 +00:00
|
|
|
|
lyx::frontend::FontMetrics const & fm = theFontMetrics(font);
|
2006-10-07 16:15:06 +00:00
|
|
|
|
|
2003-05-19 17:03:12 +00:00
|
|
|
|
// This function is a bit too simplistic and is just a
|
2000-02-10 17:53:36 +00:00
|
|
|
|
// "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 == ' ')
|
2006-10-07 16:15:06 +00:00
|
|
|
|
dim.asc = fm.ascent('a');
|
2000-02-10 17:53:36 +00:00
|
|
|
|
else
|
2006-10-07 16:15:06 +00:00
|
|
|
|
dim.asc = fm.ascent(ic);
|
2002-07-28 22:50:13 +00:00
|
|
|
|
if (plusasc)
|
2006-10-07 16:15:06 +00:00
|
|
|
|
dim.asc += (fm.maxAscent() + 3) / 3;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2002-07-28 22:50:13 +00:00
|
|
|
|
if (ic == ' ')
|
2006-10-07 16:15:06 +00:00
|
|
|
|
dim.des = fm.descent('a');
|
2002-07-28 22:50:13 +00:00
|
|
|
|
else
|
2006-10-07 16:15:06 +00:00
|
|
|
|
dim.des = fm.descent(ic);
|
2002-07-28 22:50:13 +00:00
|
|
|
|
if (plusdesc)
|
2003-05-27 13:55:03 +00:00
|
|
|
|
dim.des += 3;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2006-10-07 16:15:06 +00:00
|
|
|
|
dim.wid = fm.width(ic);
|
2003-05-19 17:03:12 +00:00
|
|
|
|
} else {
|
2006-10-07 16:15:06 +00:00
|
|
|
|
dim.asc = fm.maxAscent() + 4;
|
|
|
|
|
dim.des = fm.maxDescent() + 4;
|
2006-08-13 22:54:59 +00:00
|
|
|
|
docstring dcon(contents.begin(), contents.end());
|
2006-10-07 16:15:06 +00:00
|
|
|
|
dim.wid = fm.width(dcon) + 4;
|
2003-05-19 17:03:12 +00:00
|
|
|
|
}
|
2003-06-02 10:03:27 +00:00
|
|
|
|
dim_ = dim;
|
2000-02-10 17:53:36 +00:00
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
|
2003-05-30 06:48:24 +00:00
|
|
|
|
bool InsetLatexAccent::displayISO8859_9(PainterInfo & pi, int x, int y) const
|
2000-02-10 17:53:36 +00:00
|
|
|
|
{
|
|
|
|
|
unsigned char tmpic = ic;
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
2000-02-10 17:53:36 +00:00
|
|
|
|
switch (modtype) {
|
2003-10-28 11:18:40 +00:00
|
|
|
|
|
|
|
|
|
case CEDILLA: {
|
2005-02-15 11:51:55 +00:00
|
|
|
|
if (ic == 'c') tmpic = '\xe7';
|
|
|
|
|
if (ic == 'C') tmpic = '\xc7';
|
|
|
|
|
if (ic == 's') tmpic = '\xfe';
|
|
|
|
|
if (ic == 'S') tmpic = '\xde';
|
2000-02-10 17:53:36 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
2003-10-28 11:18:40 +00:00
|
|
|
|
|
|
|
|
|
case BREVE: {
|
2005-02-15 11:51:55 +00:00
|
|
|
|
if (ic == 'g') tmpic = '\xf0';
|
|
|
|
|
if (ic == 'G') tmpic = '\xd0';
|
2003-10-28 11:18:40 +00:00
|
|
|
|
break;
|
2000-02-10 17:53:36 +00:00
|
|
|
|
}
|
2003-10-28 11:18:40 +00:00
|
|
|
|
|
|
|
|
|
case UMLAUT: {
|
2005-02-15 11:51:55 +00:00
|
|
|
|
if (ic == 'o') tmpic = '\xf6';
|
|
|
|
|
if (ic == 'O') tmpic = '\xd6';
|
|
|
|
|
if (ic == 'u') tmpic = '\xfc';
|
|
|
|
|
if (ic == 'U') tmpic = '\xdc';
|
2000-02-10 17:53:36 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
2003-10-28 11:18:40 +00:00
|
|
|
|
|
|
|
|
|
case DOT:
|
2005-02-15 11:51:55 +00:00
|
|
|
|
if (ic == 'I') tmpic = '\xdd';
|
2003-10-28 11:18:40 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case DOT_LESS_I:
|
2005-02-15 11:51:55 +00:00
|
|
|
|
tmpic = '\xfd';
|
2003-10-28 11:18:40 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
return false;
|
2000-02-10 17:53:36 +00:00
|
|
|
|
}
|
2003-10-28 11:18:40 +00:00
|
|
|
|
|
|
|
|
|
if (tmpic == ic)
|
2000-02-10 17:53:36 +00:00
|
|
|
|
return false;
|
2003-10-28 11:18:40 +00:00
|
|
|
|
|
|
|
|
|
pi.pain.text(x, y, char(tmpic), pi.base.font);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void InsetLatexAccent::drawAccent(PainterInfo const & pi, int x, int y,
|
2006-08-13 22:54:59 +00:00
|
|
|
|
char_type accent) const
|
2003-10-28 11:18:40 +00:00
|
|
|
|
{
|
|
|
|
|
LyXFont const & font = pi.base.font;
|
2006-10-11 17:24:46 +00:00
|
|
|
|
lyx::frontend::FontMetrics const & fm = theFontMetrics(font);
|
2006-10-07 16:15:06 +00:00
|
|
|
|
|
|
|
|
|
x -= fm.center(accent);
|
|
|
|
|
y -= fm.ascent(ic);
|
|
|
|
|
y -= fm.descent(accent);
|
|
|
|
|
y -= fm.height(accent) / 2;
|
2003-10-28 11:18:40 +00:00
|
|
|
|
pi.pain.text(x, y, accent, font);
|
2000-02-10 17:53:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-05-30 06:48:24 +00:00
|
|
|
|
void InsetLatexAccent::draw(PainterInfo & pi, int x, int baseline) const
|
2000-02-10 17:53:36 +00:00
|
|
|
|
{
|
2000-10-30 21:53:29 +00:00
|
|
|
|
if (lyxrc.font_norm_type == LyXRC::ISO_8859_9)
|
2003-05-30 06:48:24 +00:00
|
|
|
|
if (displayISO8859_9(pi, x, baseline))
|
2000-02-10 17:53:36 +00:00
|
|
|
|
return;
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
2000-02-10 17:53:36 +00:00
|
|
|
|
// All the manually drawn accents in this function could use an
|
|
|
|
|
// overhaul. Different ways of drawing (what metrics to use)
|
|
|
|
|
// should also be considered.
|
2000-10-30 21:53:29 +00:00
|
|
|
|
|
2003-05-30 06:48:24 +00:00
|
|
|
|
LyXFont font = pi.base.font;
|
2000-10-30 21:53:29 +00:00
|
|
|
|
if (lyxrc.font_norm_type == LyXRC::ISO_10646_1)
|
|
|
|
|
font.setLanguage(english_language);
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
2006-10-11 17:24:46 +00:00
|
|
|
|
lyx::frontend::FontMetrics const & fm = theFontMetrics(font);
|
2006-10-07 16:15:06 +00:00
|
|
|
|
|
2000-02-10 17:53:36 +00:00
|
|
|
|
if (candisp) {
|
2006-10-07 16:15:06 +00:00
|
|
|
|
int x2 = int(x + (fm.rbearing(ic) - fm.lbearing(ic)) / 2);
|
2003-10-28 11:18:40 +00:00
|
|
|
|
int hg;
|
2000-02-10 17:53:36 +00:00
|
|
|
|
int y;
|
|
|
|
|
if (plusasc) {
|
|
|
|
|
// mark at the top
|
2006-10-07 16:15:06 +00:00
|
|
|
|
hg = fm.maxDescent();
|
2003-06-02 10:03:27 +00:00
|
|
|
|
y = baseline - dim_.asc;
|
2000-02-10 17:53:36 +00:00
|
|
|
|
if (font.shape() == LyXFont::ITALIC_SHAPE)
|
2003-10-28 11:18:40 +00:00
|
|
|
|
x2 += int(0.8 * hg); // italic
|
2000-02-10 17:53:36 +00:00
|
|
|
|
} else {
|
|
|
|
|
// at the bottom
|
2003-06-02 10:03:27 +00:00
|
|
|
|
hg = dim_.des;
|
2000-02-10 17:53:36 +00:00
|
|
|
|
y = baseline;
|
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2003-10-28 11:18:40 +00:00
|
|
|
|
double hg35 = hg * 0.6;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2000-02-10 17:53:36 +00:00
|
|
|
|
// display with proper accent mark
|
|
|
|
|
// first the letter
|
2003-05-30 06:48:24 +00:00
|
|
|
|
pi.pain.text(x, baseline, ic, font);
|
2000-02-10 17:53:36 +00:00
|
|
|
|
|
|
|
|
|
if (remdot) {
|
2006-10-07 16:15:06 +00:00
|
|
|
|
int tmpvar = baseline - fm.ascent('i');
|
2003-05-30 06:48:24 +00:00
|
|
|
|
int tmpx = 0;
|
2000-02-10 17:53:36 +00:00
|
|
|
|
if (font.shape() == LyXFont::ITALIC_SHAPE)
|
2003-05-30 06:48:24 +00:00
|
|
|
|
tmpx += int(0.8 * hg); // italic
|
2000-02-10 17:53:36 +00:00
|
|
|
|
lyxerr[Debug::KEY] << "Removing dot." << endl;
|
|
|
|
|
// remove the dot first
|
2003-06-02 10:03:27 +00:00
|
|
|
|
pi.pain.fillRectangle(x + tmpx, tmpvar, dim_.wid,
|
2006-10-07 16:15:06 +00:00
|
|
|
|
fm.ascent('i') -
|
|
|
|
|
fm.ascent('x') - 1,
|
2001-07-24 10:13:19 +00:00
|
|
|
|
backgroundColor());
|
2000-02-10 17:53:36 +00:00
|
|
|
|
// 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
|
2004-04-05 09:36:28 +00:00
|
|
|
|
#ifdef WITH_WARNINGS
|
2003-07-18 07:47:07 +00:00
|
|
|
|
#warning metrics?
|
2004-04-05 09:36:28 +00:00
|
|
|
|
#endif
|
2003-07-18 07:47:07 +00:00
|
|
|
|
int asc = ascent(); // the dot-less version (here: 'x')
|
2000-02-10 17:53:36 +00:00
|
|
|
|
ic = tmpic; // set the orig ic back
|
|
|
|
|
y = baseline - asc; // update to new y coord.
|
|
|
|
|
}
|
2003-10-28 11:18:40 +00:00
|
|
|
|
|
|
|
|
|
// now the rest - draw within (x, y, x + wid, y + hg)
|
2000-02-10 17:53:36 +00:00
|
|
|
|
switch (modtype) {
|
2003-10-28 11:18:40 +00:00
|
|
|
|
case ACUTE:
|
2006-08-13 22:54:59 +00:00
|
|
|
|
//drawAccent(pi, x2, baseline, '\xB4');
|
|
|
|
|
drawAccent(pi, x2, baseline, 0xB4);
|
2000-02-10 17:53:36 +00:00
|
|
|
|
break;
|
2003-10-29 10:47:21 +00:00
|
|
|
|
|
|
|
|
|
case GRAVE:
|
2006-08-13 22:54:59 +00:00
|
|
|
|
//drawAccent(pi, x2, baseline, '\x60');
|
|
|
|
|
drawAccent(pi, x2, baseline, 0x60);
|
2000-02-10 17:53:36 +00:00
|
|
|
|
break;
|
2003-10-28 11:18:40 +00:00
|
|
|
|
|
|
|
|
|
case MACRON:
|
2006-08-13 22:54:59 +00:00
|
|
|
|
//drawAccent(pi, x2, baseline, '\xAF');
|
|
|
|
|
drawAccent(pi, x2, baseline, 0xAF);
|
2000-02-10 17:53:36 +00:00
|
|
|
|
break;
|
2003-10-28 11:18:40 +00:00
|
|
|
|
|
|
|
|
|
case TILDE:
|
|
|
|
|
drawAccent(pi, x2, baseline, '~');
|
2000-02-10 17:53:36 +00:00
|
|
|
|
break;
|
2003-10-28 11:18:40 +00:00
|
|
|
|
|
2005-02-15 09:50:49 +00:00
|
|
|
|
case UNDERBAR: {
|
2006-08-13 22:54:59 +00:00
|
|
|
|
char_type const underbar = 0x5F; //('\x5F');
|
2006-10-07 16:15:06 +00:00
|
|
|
|
pi.pain.text(x2 - fm.center(underbar),
|
2005-02-15 09:50:49 +00:00
|
|
|
|
baseline, underbar, font);
|
2000-02-10 17:53:36 +00:00
|
|
|
|
break;
|
2005-02-15 09:50:49 +00:00
|
|
|
|
}
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
2005-02-15 09:50:49 +00:00
|
|
|
|
case CEDILLA: {
|
2006-08-13 22:54:59 +00:00
|
|
|
|
char_type const cedilla = 0xB8; //('\xB8');
|
2006-10-07 16:15:06 +00:00
|
|
|
|
pi.pain.text(x2 - fm.center(cedilla),
|
2005-02-15 09:50:49 +00:00
|
|
|
|
baseline, cedilla, font);
|
2000-02-10 17:53:36 +00:00
|
|
|
|
break;
|
2005-02-15 09:50:49 +00:00
|
|
|
|
}
|
2003-10-28 11:18:40 +00:00
|
|
|
|
|
|
|
|
|
case UNDERDOT:
|
2006-10-07 16:15:06 +00:00
|
|
|
|
pi.pain.text(x2 - fm.center('.'),
|
|
|
|
|
int(baseline + 1.5 * fm.height('.')),
|
2000-02-17 19:59:08 +00:00
|
|
|
|
'.', font);
|
2000-02-10 17:53:36 +00:00
|
|
|
|
break;
|
|
|
|
|
|
2003-10-28 11:18:40 +00:00
|
|
|
|
case DOT:
|
|
|
|
|
drawAccent(pi, x2, baseline, '.');
|
2000-02-10 17:53:36 +00:00
|
|
|
|
break;
|
|
|
|
|
|
2003-10-29 10:47:21 +00:00
|
|
|
|
case CIRCLE:
|
2006-08-13 22:54:59 +00:00
|
|
|
|
//drawAccent(pi, x2, baseline, '\xB0');
|
|
|
|
|
drawAccent(pi, x2, baseline, 0xB0);
|
2000-02-10 17:53:36 +00:00
|
|
|
|
break;
|
2003-10-28 11:18:40 +00:00
|
|
|
|
|
|
|
|
|
case TIE:
|
|
|
|
|
pi.pain.arc(int(x2 + hg35), y + hg / 2, 2 * hg, hg, 0, 360 * 32,
|
2003-09-15 10:08:01 +00:00
|
|
|
|
LColor::foreground);
|
2000-02-10 17:53:36 +00:00
|
|
|
|
break;
|
2003-10-28 11:18:40 +00:00
|
|
|
|
|
|
|
|
|
case BREVE:
|
|
|
|
|
pi.pain.arc(int(x2 - hg / 2), y, hg, hg, 0, -360*32,
|
2003-09-15 10:08:01 +00:00
|
|
|
|
LColor::foreground);
|
2000-02-10 17:53:36 +00:00
|
|
|
|
break;
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
2003-10-28 11:18:40 +00:00
|
|
|
|
case CARON: {
|
|
|
|
|
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);
|
2003-09-15 10:08:01 +00:00
|
|
|
|
pi.pain.lines(xp, yp, 3, LColor::foreground);
|
2000-02-10 17:53:36 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
2003-10-28 11:18:40 +00:00
|
|
|
|
|
|
|
|
|
case SPECIAL_CARON: {
|
2000-02-10 17:53:36 +00:00
|
|
|
|
switch (ic) {
|
2003-10-28 11:18:40 +00:00
|
|
|
|
case 'L': dim_.wid = int(4.0 * dim_.wid / 5.0); break;
|
|
|
|
|
case 't': y -= int(hg35 / 2.0); break;
|
2000-02-10 17:53:36 +00:00
|
|
|
|
}
|
|
|
|
|
int xp[3], yp[3];
|
2003-06-02 10:03:27 +00:00
|
|
|
|
xp[0] = int(x + dim_.wid);
|
2000-02-10 17:53:36 +00:00
|
|
|
|
yp[0] = int(y + hg35 + hg);
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
2003-06-02 10:03:27 +00:00
|
|
|
|
xp[1] = int(x + dim_.wid + (hg35 / 2.0));
|
2000-02-10 17:53:36 +00:00
|
|
|
|
yp[1] = int(y + hg + (hg35 / 2.0));
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
2003-06-02 10:03:27 +00:00
|
|
|
|
xp[2] = int(x + dim_.wid + (hg35 / 2.0));
|
2000-02-10 17:53:36 +00:00
|
|
|
|
yp[2] = y + int(hg);
|
|
|
|
|
|
2003-09-15 10:08:01 +00:00
|
|
|
|
pi.pain.lines(xp, yp, 3, LColor::foreground);
|
2000-02-10 17:53:36 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
2003-10-28 11:18:40 +00:00
|
|
|
|
|
|
|
|
|
case HUNGARIAN_UMLAUT:
|
2006-10-07 16:15:06 +00:00
|
|
|
|
drawAccent(pi, x2 - fm.center('<EFBFBD>'), baseline, '<EFBFBD>');
|
|
|
|
|
drawAccent(pi, x2 + fm.center('<EFBFBD>'), baseline, '<EFBFBD>');
|
2000-02-10 17:53:36 +00:00
|
|
|
|
break;
|
2003-10-28 11:18:40 +00:00
|
|
|
|
|
|
|
|
|
case UMLAUT:
|
|
|
|
|
drawAccent(pi, x2, baseline, '"');
|
2000-02-10 17:53:36 +00:00
|
|
|
|
break;
|
2003-10-28 11:18:40 +00:00
|
|
|
|
|
|
|
|
|
case CIRCUMFLEX:
|
2005-02-15 11:51:55 +00:00
|
|
|
|
drawAccent(pi, x2, baseline, '\x5E');
|
2000-02-10 17:53:36 +00:00
|
|
|
|
break;
|
2003-10-28 11:18:40 +00:00
|
|
|
|
|
|
|
|
|
case OGONEK: {
|
2000-02-10 17:53:36 +00:00
|
|
|
|
// this does probably not look like an ogonek, so
|
|
|
|
|
// it should certainly be refined
|
|
|
|
|
int xp[4], yp[4];
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
2003-10-28 11:18:40 +00:00
|
|
|
|
xp[0] = x2;
|
2000-02-10 17:53:36 +00:00
|
|
|
|
yp[0] = y;
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
2003-10-28 11:18:40 +00:00
|
|
|
|
xp[1] = x2;
|
2000-02-10 17:53:36 +00:00
|
|
|
|
yp[1] = y + int(hg35);
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
2000-02-10 17:53:36 +00:00
|
|
|
|
xp[2] = int(x2 - hg35);
|
2003-10-28 11:18:40 +00:00
|
|
|
|
yp[2] = y + hg / 2;
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
2003-10-28 11:18:40 +00:00
|
|
|
|
xp[3] = x2 + hg / 4;
|
2000-02-10 17:53:36 +00:00
|
|
|
|
yp[3] = y + int(hg);
|
|
|
|
|
|
2003-09-15 10:08:01 +00:00
|
|
|
|
pi.pain.lines(xp, yp, 4, LColor::foreground);
|
2000-02-10 17:53:36 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
2003-10-28 11:18:40 +00:00
|
|
|
|
|
2000-02-10 17:53:36 +00:00
|
|
|
|
case lSLASH:
|
2003-10-28 11:18:40 +00:00
|
|
|
|
case LSLASH: {
|
2000-02-10 17:53:36 +00:00
|
|
|
|
int xp[2], yp[2];
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
2003-10-28 11:18:40 +00:00
|
|
|
|
xp[0] = x;
|
|
|
|
|
yp[0] = y + int(3 * hg);
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
2003-10-28 11:18:40 +00:00
|
|
|
|
xp[1] = int(x + dim_.wid * 0.75);
|
2000-02-10 17:53:36 +00:00
|
|
|
|
yp[1] = y + int(hg);
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
2003-09-15 10:08:01 +00:00
|
|
|
|
pi.pain.lines(xp, yp, 2, LColor::foreground);
|
2002-03-21 17:09:55 +00:00
|
|
|
|
break;
|
2000-02-10 17:53:36 +00:00
|
|
|
|
}
|
2003-10-28 11:18:40 +00:00
|
|
|
|
|
2000-02-10 17:53:36 +00:00
|
|
|
|
case DOT_LESS_I: // dotless-i
|
|
|
|
|
case DOT_LESS_J: // dotless-j
|
|
|
|
|
// nothing to do for these
|
|
|
|
|
break;
|
|
|
|
|
}
|
2003-10-28 11:18:40 +00:00
|
|
|
|
|
2000-02-10 17:53:36 +00:00
|
|
|
|
} else {
|
2003-05-30 06:48:24 +00:00
|
|
|
|
pi.pain.fillRectangle(x + 1,
|
2003-09-15 10:08:01 +00:00
|
|
|
|
baseline - dim_.asc + 1, dim_.wid - 2,
|
|
|
|
|
dim_.asc + dim_.des - 2,
|
|
|
|
|
backgroundColor());
|
2003-06-02 10:03:27 +00:00
|
|
|
|
pi.pain.rectangle(x + 1, baseline - dim_.asc + 1,
|
2003-09-15 10:08:01 +00:00
|
|
|
|
dim_.wid - 2, dim_.asc + dim_.des - 2,
|
|
|
|
|
LColor::foreground);
|
2006-08-13 22:54:59 +00:00
|
|
|
|
docstring dcon(contents.begin(), contents.end());
|
|
|
|
|
pi.pain.text(x + 2, baseline, dcon, font);
|
2000-02-10 17:53:36 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
|
2003-08-28 07:41:31 +00:00
|
|
|
|
void InsetLatexAccent::write(Buffer const &, ostream & os) const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
1999-12-07 00:44:53 +00:00
|
|
|
|
os << "\\i " << contents << "\n";
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-08-28 07:41:31 +00:00
|
|
|
|
void InsetLatexAccent::read(Buffer const &, LyXLex & lex)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2001-08-06 19:13:25 +00:00
|
|
|
|
lex.eatLine();
|
|
|
|
|
contents = lex.getString();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
checkContents();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-10-19 16:51:30 +00:00
|
|
|
|
int InsetLatexAccent::latex(Buffer const &, odocstream & os,
|
2003-11-05 12:06:20 +00:00
|
|
|
|
OutputParams const &) const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2006-10-19 16:51:30 +00:00
|
|
|
|
os << lyx::from_ascii(contents);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-10-19 16:51:30 +00:00
|
|
|
|
int InsetLatexAccent::plaintext(Buffer const &, odocstream & os,
|
2003-11-05 12:06:20 +00:00
|
|
|
|
OutputParams const &) const
|
2000-04-24 20:58:23 +00:00
|
|
|
|
{
|
2006-10-11 19:40:50 +00:00
|
|
|
|
os << lyx::from_ascii(contents);
|
2000-04-24 20:58:23 +00:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-10-31 18:45:43 +00:00
|
|
|
|
int InsetLatexAccent::docbook(Buffer const &, ostream & os,
|
2003-11-05 12:06:20 +00:00
|
|
|
|
OutputParams const &) const
|
2000-03-06 02:42:40 +00:00
|
|
|
|
{
|
|
|
|
|
os << contents;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2006-10-19 16:51:30 +00:00
|
|
|
|
int InsetLatexAccent::textString(Buffer const & buf, odocstream & os,
|
2005-11-25 14:40:34 +00:00
|
|
|
|
OutputParams const & op) const
|
|
|
|
|
{
|
|
|
|
|
return plaintext(buf, os, op);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
|
bool InsetLatexAccent::directWrite() const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-11-25 19:13:07 +00:00
|
|
|
|
InsetBase::Code InsetLatexAccent::lyxCode() const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2004-11-25 19:13:07 +00:00
|
|
|
|
return InsetBase::ACCENT_CODE;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
1999-10-07 18:44:17 +00:00
|
|
|
|
ostream & operator<<(ostream & o, InsetLatexAccent::ACCENT_TYPES at)
|
|
|
|
|
{
|
|
|
|
|
return o << int(at);
|
|
|
|
|
}
|