]> git.lyx.org Git - lyx.git/blobdiff - src/font.C
whitespace changes;
[lyx.git] / src / font.C
index a66b9ebafd55f2cddc0ddaa02ce7044cc5a7208b..c2cb085c084769d93be1a918cbe878d510987dc2 100644 (file)
@@ -4,7 +4,7 @@
  *           LyX, The Document Processor
  *        
  *           Copyright 1995 Matthias Ettrich
- *           Copyright 1995-2000 The LyX Team.
+ *           Copyright 1995-2001 The LyX Team.
  *
  * ====================================================== */
 
 #include "FontLoader.h"
 #include "lyxrc.h"
 #include "encoding.h"
+#include "language.h"
 
-// namespace {
-static inline
+namespace {
+
+inline
 XFontStruct * getXFontstruct(LyXFont const & f)
 {
        return fontloader.load(f.family(), f.series(),
@@ -30,12 +32,13 @@ XFontStruct * getXFontstruct(LyXFont const & f)
 }
 
 
-static inline
+inline
 XID getFontID(LyXFont const & f)
 {
        return getXFontstruct(f)->fid;
 }
-// } // end of anon namespace
+
+} // namespace anon
 
 int lyxfont::maxAscent(LyXFont const & f)
 {
@@ -55,7 +58,7 @@ int lyxfont::ascent(char c, LyXFont const & f)
        unsigned int uc = static_cast<unsigned char>(c);
        if (finfo->per_char
            && uc >= finfo->min_char_or_byte2
-           && uc <= finfo->max_char_or_byte2) 
+           && uc <= finfo->max_char_or_byte2+256*finfo->max_byte1
                return finfo->per_char[uc - finfo->min_char_or_byte2].ascent;
        else
                return finfo->ascent;
@@ -68,7 +71,7 @@ int lyxfont::descent(char c, LyXFont const & f)
        unsigned int uc = static_cast<unsigned char>(c);
        if (finfo->per_char
            && uc >= finfo->min_char_or_byte2
-           && uc <= finfo->max_char_or_byte2) 
+           && uc <= finfo->max_char_or_byte2+256*finfo->max_byte1
                return finfo->per_char[uc - finfo->min_char_or_byte2].descent;
        else
                return finfo->descent;
@@ -81,7 +84,7 @@ int lyxfont::lbearing(char c, LyXFont const & f)
        unsigned int uc = static_cast<unsigned char>(c);
        if (finfo->per_char
            && uc >= finfo->min_char_or_byte2
-           && uc <= finfo->max_char_or_byte2) 
+           && uc <= finfo->max_char_or_byte2+256*finfo->max_byte1
                return finfo->per_char[uc - finfo->min_char_or_byte2].lbearing;
        else
                return 0;
@@ -94,7 +97,7 @@ int lyxfont::rbearing(char c, LyXFont const & f)
        unsigned int uc = static_cast<unsigned char>(c);
        if (finfo->per_char
            && uc >= finfo->min_char_or_byte2
-           && uc <= finfo->max_char_or_byte2) 
+           && uc <= finfo->max_char_or_byte2+256*finfo->max_byte1
                return finfo->per_char[uc - finfo->min_char_or_byte2].rbearing;
        else
                return width(c, f);
@@ -109,13 +112,14 @@ int lyxfont::width(char const * s, size_t n, LyXFont const & f)
        if (lyxrc.font_norm_type == LyXRC::ISO_10646_1) {
                XChar2b * xs = new XChar2b[n];
                Encoding const * encoding = f.language()->encoding();
-               LyXFont const * font = &f; 
-               if (f.family() == LyXFont::SYMBOL_FAMILY) {
+               //LyXFont const * font = &f;
+               LyXFont font(f);
+               if (f.isSymbolFont()) {
 #ifdef USE_UNICODE_FOR_SYMBOLS
-                       LyXFont font2 = f;
-                       font2.setFamily(LyXFont::ROMAN_FAMILY);
-                       font2.setShape(LyXFont::UP_SHAPE);
-                       font = &font2;
+                       //LyXFont font2 = f;
+                       font.setFamily(LyXFont::ROMAN_FAMILY);
+                       font.setShape(LyXFont::UP_SHAPE);
+                       //font = &font2;
 #endif
                        encoding = encodings.symbol_encoding();
                }
@@ -124,7 +128,7 @@ int lyxfont::width(char const * s, size_t n, LyXFont const & f)
                        xs[i].byte1 = c >> 8;
                        xs[i].byte2 = c & 0xff;
                 }
-               int result = width(xs, n, *font);
+               int result = width(xs, n, font);
                delete[] xs;
                return result;
        }
@@ -173,7 +177,7 @@ int lyxfont::width(XChar2b const * s, int n, LyXFont const & f)
        } else {
                // emulate smallcaps since X doesn't support this
                unsigned int result = 0;
-               static XChar2b c = {0, 0};
+               static XChar2b c;
                LyXFont smallfont(f);
                smallfont.decSize().decSize().setShape(LyXFont::UP_SHAPE);
                for (int i = 0; i < n; ++i) {
@@ -182,7 +186,7 @@ int lyxfont::width(XChar2b const * s, int n, LyXFont const & f)
                                result += ::XTextWidth16(getXFontstruct(smallfont), &c, 1);
                        } else {
                                result += ::XTextWidth16(getXFontstruct(f), &s[i], 1);
-                       }
+               }
                }
                return result;
        }
@@ -205,5 +209,28 @@ void lyxfont::XSetFont(Display * display, GC gc, LyXFont const & f)
        ::XSetFont(display, gc, getFontID(f));
 }
 
+
+void lyxfont::rectText(string const & str, LyXFont const & font,
+             int & width, int & ascent, int & descent)
+{
+       static int const d = 2;
+       width = lyxfont::width(str, font) + d * 2 + 2;
+       ascent = lyxfont::maxAscent(font) + d;
+       descent = lyxfont::maxDescent(font) + d;
+}
+
+
+
+void lyxfont::buttonText(string const & str, LyXFont const & font,
+               int & width, int & ascent, int & descent)
+{
+       static int const d = 3;
+       
+       width = lyxfont::width(str, font) + d * 2 + 2;
+       ascent = lyxfont::maxAscent(font) + d;
+       descent = lyxfont::maxDescent(font) + d;
+}
+
+
 //} // end of namespace font
 //} // end of namespace lyx