#include "lyxrc.h"
#include "metricsinfo.h"
-#include "frontends/font_metrics.h"
+#include "frontends/FontMetrics.h"
#include "frontends/Painter.h"
#include "support/lstrings.h"
-using lyx::support::contains;
-using lyx::support::trim;
+
+namespace lyx {
+
+using support::contains;
+using support::trim;
using std::endl;
using std::string;
}
-auto_ptr<InsetBase> InsetLatexAccent::clone() const
+auto_ptr<InsetBase> InsetLatexAccent::doClone() const
{
return auto_ptr<InsetBase>(new InsetLatexAccent(contents));
}
return;
}
- // REMOVE IN 0.13
- // Dirty Hack for backward compability. remove in 0.13 (Lgb)
contents = trim(contents);
- if (!contains(contents, "{") && !contains(contents, "}")) {
- if (contents.length() == 2) {
- string tmp;
- tmp += contents[0];
- tmp += contents[1];
- tmp += "{}";
- contents = tmp;
- } else if (contents.length() == 3) {
- string tmp;
- tmp += contents[0];
- tmp += contents[1];
- tmp += '{';
- tmp += contents[2];
- tmp += '}';
- contents = tmp;
- } else if (contents.length() == 4 && contents[2] == ' ') {
- string tmp;
- tmp += contents[0];
- tmp += contents[1];
- tmp += '{';
- tmp += contents[3];
- tmp += '}';
- contents = tmp;
- } else if (contents.length() == 4 && contents[2] == '\\'
- && (contents[3] == 'i' || contents[3] == 'j')) {
- string tmp;
- tmp += contents[0];
- tmp += contents[1];
- tmp += '{';
- tmp += contents[2];
- tmp += contents[3];
- tmp += '}';
- contents = tmp;
- }
- }
if (contents[0] != '\\') { // demand that first char is a '\\'
lyxerr[Debug::KEY] << "Cannot decode: " << contents << endl;
return;
break;
default:
lyxerr[Debug::KEY] << "Default" << endl;
- // unknow accent (or something else)
+ // unknown accent (or something else)
return;
}
}
-void InsetLatexAccent::metrics(MetricsInfo & mi, Dimension & dim) const
+bool InsetLatexAccent::metrics(MetricsInfo & mi, Dimension & dim) const
{
LyXFont & font = mi.base.font;
+ frontend::FontMetrics const & fm = theFontMetrics(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 == ' ')
- dim.asc = font_metrics::ascent('a', font);
+ dim.asc = fm.ascent('a');
else
- dim.asc = font_metrics::ascent(ic, font);
+ dim.asc = fm.ascent(ic);
if (plusasc)
- dim.asc += (font_metrics::maxAscent(font) + 3) / 3;
+ dim.asc += (fm.maxAscent() + 3) / 3;
if (ic == ' ')
- dim.des = font_metrics::descent('a', font);
+ dim.des = fm.descent('a');
else
- dim.des = font_metrics::descent(ic, font);
+ dim.des = fm.descent(ic);
if (plusdesc)
dim.des += 3;
- dim.wid = font_metrics::width(ic, font);
+ dim.wid = fm.width(ic);
} else {
- dim.asc = font_metrics::maxAscent(font) + 4;
- dim.des = font_metrics::maxDescent(font) + 4;
- dim.wid = font_metrics::width(contents, font) + 4;
+ dim.asc = fm.maxAscent() + 4;
+ dim.des = fm.maxDescent() + 4;
+ docstring dcon(contents.begin(), contents.end());
+ dim.wid = fm.width(dcon) + 4;
}
+ bool const changed = dim_ != dim;
dim_ = dim;
-}
-
-
-int InsetLatexAccent::lbearing(LyXFont const & font) const
-{
- return font_metrics::lbearing(ic, font);
-}
-
-
-int InsetLatexAccent::rbearing(LyXFont const & font) const
-{
- return font_metrics::rbearing(ic, font);
+ return changed;
}
switch (modtype) {
case CEDILLA: {
- if (ic == 'c') tmpic = 0xe7;
- if (ic == 'C') tmpic = 0xc7;
- if (ic == 's') tmpic = 0xfe;
- if (ic == 'S') tmpic = 0xde;
+ if (ic == 'c') tmpic = '\xe7';
+ if (ic == 'C') tmpic = '\xc7';
+ if (ic == 's') tmpic = '\xfe';
+ if (ic == 'S') tmpic = '\xde';
break;
}
case BREVE: {
- if (ic == 'g') tmpic = 0xf0;
- if (ic == 'G') tmpic = 0xd0;
+ if (ic == 'g') tmpic = '\xf0';
+ if (ic == 'G') tmpic = '\xd0';
break;
}
case UMLAUT: {
- if (ic == 'o') tmpic = 0xf6;
- if (ic == 'O') tmpic = 0xd6;
- if (ic == 'u') tmpic = 0xfc;
- if (ic == 'U') tmpic = 0xdc;
+ if (ic == 'o') tmpic = '\xf6';
+ if (ic == 'O') tmpic = '\xd6';
+ if (ic == 'u') tmpic = '\xfc';
+ if (ic == 'U') tmpic = '\xdc';
break;
}
case DOT:
- if (ic == 'I') tmpic = 0xdd;
+ if (ic == 'I') tmpic = '\xdd';
break;
case DOT_LESS_I:
- tmpic = 0xfd;
+ tmpic = '\xfd';
break;
default:
void InsetLatexAccent::drawAccent(PainterInfo const & pi, int x, int y,
- char accent) const
+ char_type accent) const
{
LyXFont const & font = pi.base.font;
- x -= font_metrics::center(accent, font);
- y -= font_metrics::ascent(ic, font);
- y -= font_metrics::descent(accent, font);
- y -= font_metrics::height(accent, font) / 2;
+ frontend::FontMetrics const & fm = theFontMetrics(font);
+
+ x -= fm.center(accent);
+ y -= fm.ascent(ic);
+ y -= fm.descent(accent);
+ y -= fm.height(accent) / 2;
pi.pain.text(x, y, accent, font);
}
if (lyxrc.font_norm_type == LyXRC::ISO_10646_1)
font.setLanguage(english_language);
+ frontend::FontMetrics const & fm = theFontMetrics(font);
+
if (candisp) {
- int x2 = int(x + (rbearing(font) - lbearing(font)) / 2);
+ int x2 = int(x + (fm.rbearing(ic) - fm.lbearing(ic)) / 2);
int hg;
int y;
if (plusasc) {
// mark at the top
- hg = font_metrics::maxDescent(font);
+ hg = fm.maxDescent();
y = baseline - dim_.asc;
if (font.shape() == LyXFont::ITALIC_SHAPE)
x2 += int(0.8 * hg); // italic
pi.pain.text(x, baseline, ic, font);
if (remdot) {
- int tmpvar = baseline - font_metrics::ascent('i', font);
+ int tmpvar = baseline - fm.ascent('i');
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
pi.pain.fillRectangle(x + tmpx, tmpvar, dim_.wid,
- font_metrics::ascent('i', pi.base.font) -
- font_metrics::ascent('x', pi.base.font) - 1,
+ fm.ascent('i') -
+ fm.ascent('x') - 1,
backgroundColor());
// the five lines below is a simple hack to
// make the display of accent 'i' and 'j'
// 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
+#ifdef WITH_WARNINGS
#warning metrics?
+#endif
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)
switch (modtype) {
case ACUTE:
- drawAccent(pi, x2, baseline, char(0xB4));
+ //drawAccent(pi, x2, baseline, '\xB4');
+ drawAccent(pi, x2, baseline, 0xB4);
break;
case GRAVE:
- drawAccent(pi, x2, baseline, char(0x60));
+ //drawAccent(pi, x2, baseline, '\x60');
+ drawAccent(pi, x2, baseline, 0x60);
break;
case MACRON:
- drawAccent(pi, x2, baseline, char(0xAF));
+ //drawAccent(pi, x2, baseline, '\xAF');
+ drawAccent(pi, x2, baseline, 0xAF);
break;
case TILDE:
drawAccent(pi, x2, baseline, '~');
break;
- case UNDERBAR: // underbar 0x5F
- pi.pain.text(x2 - font_metrics::center(0x5F, font), baseline,
- char(0x5F), font);
+ case UNDERBAR: {
+ char_type const underbar = 0x5F; //('\x5F');
+ pi.pain.text(x2 - fm.center(underbar),
+ baseline, underbar, font);
break;
+ }
- case CEDILLA:
- pi.pain.text(x2 - font_metrics::center(0xB8, font), baseline,
- char(0xB8), font);
+ case CEDILLA: {
+ char_type const cedilla = 0xB8; //('\xB8');
+ pi.pain.text(x2 - fm.center(cedilla),
+ baseline, cedilla, font);
break;
+ }
case UNDERDOT:
- pi.pain.text(x2 - font_metrics::center('.', font),
- int(baseline + 1.5 * font_metrics::height('.', font)),
+ pi.pain.text(x2 - fm.center('.'),
+ int(baseline + 1.5 * fm.height('.')),
'.', font);
break;
break;
case CIRCLE:
- drawAccent(pi, x2, baseline, char(0xB0));
+ //drawAccent(pi, x2, baseline, '\xB0');
+ drawAccent(pi, x2, baseline, 0xB0);
break;
case TIE:
}
case HUNGARIAN_UMLAUT:
- drawAccent(pi, x2 - font_metrics::center('´', font), baseline, '´');
- drawAccent(pi, x2 + font_metrics::center('´', font), baseline, '´');
+ drawAccent(pi, x2, baseline, 0x02DD);
break;
case UMLAUT:
break;
case CIRCUMFLEX:
- drawAccent(pi, x2, baseline, 0x5E);
+ drawAccent(pi, x2, baseline, '\x5E');
break;
case OGONEK: {
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);
+ docstring dcon(contents.begin(), contents.end());
+ pi.pain.text(x + 2, baseline, dcon, font);
}
}
}
-int InsetLatexAccent::latex(Buffer const &, ostream & os,
- LatexRunParams const &) const
+int InsetLatexAccent::latex(Buffer const &, odocstream & os,
+ OutputParams const &) const
{
- os << contents;
+ os << from_ascii(contents);
return 0;
}
-int InsetLatexAccent::ascii(Buffer const &, ostream & os,
- LatexRunParams const &) const
+int InsetLatexAccent::plaintext(Buffer const &, odocstream & os,
+ OutputParams const &) const
{
- os << contents;
+ os << from_ascii(contents);
return 0;
}
-int InsetLatexAccent::linuxdoc(Buffer const &, ostream & os,
- LatexRunParams const &) const
+int InsetLatexAccent::docbook(Buffer const &, odocstream & os,
+ OutputParams const &) const
{
- os << contents;
+ // FIXME UNICODE
+ os << from_ascii(contents);
return 0;
}
-int InsetLatexAccent::docbook(Buffer const &, ostream & os,
- LatexRunParams const &) const
+int InsetLatexAccent::textString(Buffer const & buf, odocstream & os,
+ OutputParams const & op) const
{
- os << contents;
- return 0;
+ return plaintext(buf, os, op);
}
}
-InsetOld::Code InsetLatexAccent::lyxCode() const
+InsetBase::Code InsetLatexAccent::lyxCode() const
{
- return InsetOld::ACCENT_CODE;
+ return InsetBase::ACCENT_CODE;
}
{
return o << int(at);
}
+
+
+} // namespace lyx