-GC LyXFont::getGC() const
-{
- GC gc;
- if (latex() == ON)
- gc = ::getGC(gc_latex);
- else {
- if (color() == NONE)
- gc = ::getGC(gc_copy);
- else if (color() == MATH)
- gc = ::getGC(gc_math);
- else if (color() == INSET)
- gc = ::getGC(gc_foot);
- else
- gc = ::GetColorGC(color());
- }
-
- XSetFont(fl_display, gc, getXFontstruct()->fid);
- return gc;
-}
-
-
-XFontStruct * LyXFont::getXFontstruct() const
-{
- return fontloader.load(family(), series(), realShape(), size());
-}
-
-
-int LyXFont::maxAscent() const
-{
- return getXFontstruct()->ascent;
-}
-
-
-int LyXFont::maxDescent() const
-{
- return getXFontstruct()->descent;
-}
-
-
-int LyXFont::ascent(char c) const
-{
- XFontStruct * finfo = getXFontstruct();
- if (finfo->per_char
- && static_cast<unsigned char>(c) >= finfo->min_char_or_byte2
- && static_cast<unsigned char>(c) <= finfo->max_char_or_byte2) {
- unsigned int index = c - finfo->min_char_or_byte2;
- return finfo->per_char[index].ascent;
- } else
- return finfo->ascent;
-}
-
-
-int LyXFont::descent(char c) const
-{
- XFontStruct * finfo = getXFontstruct();
- if (finfo->per_char
- && static_cast<unsigned char>(c) >= finfo->min_char_or_byte2
- && static_cast<unsigned char>(c) <= finfo->max_char_or_byte2) {
- unsigned int index = c - finfo->min_char_or_byte2;
- return finfo->per_char[index].descent;
- } else
- return finfo->descent;
-}
-
-
-// Specialized after profiling. (Asger)
-int LyXFont::width(char c) const
-{
- if (realShape() != LyXFont::SMALLCAPS_SHAPE){
- return XTextWidth(getXFontstruct(), &c, 1);
- } else {
- return textWidth(&c, 1);
- }
-}
-
-
-int LyXFont::lbearing(char c) const
-{
- XFontStruct * finfo = getXFontstruct();
- if (finfo->per_char
- && static_cast<unsigned char>(c) >= finfo->min_char_or_byte2
- && static_cast<unsigned char>(c) <= finfo->max_char_or_byte2) {
- unsigned int index = c - finfo->min_char_or_byte2;
- return finfo->per_char[index].lbearing;
- } else
- return 0;
-}
-
-
-int LyXFont::rbearing(char c) const
-{
- XFontStruct * finfo = getXFontstruct();
- if (finfo->per_char
- && static_cast<unsigned char>(c) >= finfo->min_char_or_byte2
- && static_cast<unsigned char>(c) <= finfo->max_char_or_byte2) {
- unsigned int index = c - finfo->min_char_or_byte2;
- return finfo->per_char[index].rbearing;
- } else
- return width(c);
-}
-
-
-int LyXFont::textWidth(char const * s, int n) const
-{
- if (realShape() != LyXFont::SMALLCAPS_SHAPE){
- return XTextWidth(getXFontstruct(), s, n);
- } else {
- // emulate smallcaps since X doesn't support this
- unsigned int result = 0;
- char c;
- LyXFont smallfont = *this;
- smallfont.decSize();
- smallfont.decSize();
- smallfont.setShape(LyXFont::UP_SHAPE);
- for (int i = 0; i < n; ++i) {
- c = s[i];
- if (islower(c)){
- c = toupper(c);
- result += XTextWidth(smallfont.getXFontstruct(), &c, 1);
- } else {
- result += XTextWidth(getXFontstruct(), &c, 1);
- }
- }
- return result;
- }
-}
-
-
-int LyXFont::stringWidth(string const & s) const
-{
- if (s.empty()) return 0;
- return textWidth(s.c_str(), s.length());
-}
-
-
-int LyXFont::signedStringWidth(string const & s) const
-{
- if (s.empty()) return 0;
- if (s.c_str()[0] == '-')
- return -textWidth(s.c_str()+1, s.length()-1);
- else
- return textWidth(s.c_str(), s.length());
-}
-
-
-int LyXFont::drawText(char const * s, int n, Pixmap pm,
- int baseline, int x) const
-{
- if (realShape() != LyXFont::SMALLCAPS_SHAPE) {
- XDrawString(fl_display,
- pm,
- getGC(),
- x, baseline,
- s, n);
- XFlush(fl_display);
- return XTextWidth(getXFontstruct(), s, n);
-
- } else {
- // emulate smallcaps since X doesn't support this
- char c;
- int sx = x;
- LyXFont smallfont = *this;
- smallfont.decSize();
- smallfont.decSize();
- smallfont.setShape(LyXFont::UP_SHAPE);
- for (int i = 0; i < n; ++i) {
- c = s[i];
- if (islower(c)){
- c = toupper(c);
- XDrawString(fl_display,
- pm,
- smallfont.getGC(),
- x, baseline,
- &c, 1);
- x += XTextWidth(smallfont.getXFontstruct(),
- &c, 1);
- XFlush(fl_display);
- } else {
- XDrawString(fl_display,
- pm,
- getGC(),
- x, baseline,
- &c, 1);
- x += XTextWidth(getXFontstruct(), &c, 1);
- XFlush(fl_display);
- }
- }
- return x - sx;
- }
-}
-
-
-int LyXFont::drawString(string const & s, Pixmap pm, int baseline, int x) const
-{
- return drawText(s.c_str(), s.length(), pm, baseline, x);
-}
-
-