]> git.lyx.org Git - features.git/commitdiff
font_metrics part 1
authorJohn Levon <levon@movementarian.org>
Fri, 24 May 2002 14:34:32 +0000 (14:34 +0000)
committerJohn Levon <levon@movementarian.org>
Fri, 24 May 2002 14:34:32 +0000 (14:34 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@4203 a592a061-630c-0410-9148-cb99ea01b6c8

37 files changed:
src/BufferView_pimpl.C
src/ChangeLog
src/LColor.C
src/Makefile.am
src/font.C [deleted file]
src/font.h [deleted file]
src/frontends/ChangeLog
src/frontends/Makefile.am
src/frontends/Painter.C
src/frontends/font_metrics.h [new file with mode: 0644]
src/frontends/screen.C
src/frontends/xforms/ChangeLog
src/frontends/xforms/Makefile.am
src/frontends/xforms/XPainter.C
src/frontends/xforms/xfont_metrics.C [new file with mode: 0644]
src/frontends/xforms/xfont_metrics.h [new file with mode: 0644]
src/insets/ChangeLog
src/insets/insetbib.C
src/insets/insetbutton.C
src/insets/insetcaption.C
src/insets/insetcollapsable.C
src/insets/inseterror.C
src/insets/insetgraphics.C
src/insets/insetlatexaccent.C
src/insets/insetquotes.C
src/insets/insetspecialchar.C
src/insets/insettabular.C
src/insets/insettext.C
src/mathed/ChangeLog
src/mathed/formulabase.C
src/mathed/formulamacro.C
src/mathed/math_charinset.C
src/mathed/math_funcinset.C
src/mathed/math_support.C
src/mathed/math_unknowninset.C
src/text.C
src/text2.C

index aef9714b7d94a76864eb9cd760d1c50eff62271d..0b52a1754e0418fb2aee1be86e1fda8a542151ed 100644 (file)
@@ -14,7 +14,6 @@
 #include "commandtags.h"
 #include "lyxfunc.h"
 #include "debug.h"
-#include "font.h"
 #include "bufferview_funcs.h"
 #include "TextCache.h"
 #include "bufferlist.h"
index 6cdba47b2dd7392cee90624e310af131ddf74824..67b686a8317150dceda5b2eab5b8db2e71666936 100644 (file)
@@ -1,3 +1,14 @@
+2002-05-24  John Levon  <moz@compsoc.man.ac.uk>
+
+       * LColor.C: remove spurious X include
+       * BufferView_pimpl.C:
+       * Makefile.am:
+       * font.h:
+       * font.C:
+       * text.C:
+       * text2.C: move font metrics to frontends/
 2002-05-24  Juergen Vigna  <jug@sad.it>
 
        * undo_funcs.C (textHandleUndo): fix the cursor selection after
index d445f313b257639c36119a7046538d99eb14a8de..e1fe8c2d1fe34aae2fcd2cd53610936d982ddc0f 100644 (file)
@@ -13,8 +13,6 @@
 #pragma implementation
 #endif
 
-#include <X11/Xlib.h>
-
 #include "debug.h"
 #include "LColor.h"
 #include "support/LAssert.h"
index 781714b83bd729d192e5bf74aa63b019f415d306..fe2609104700a4a673bf4758be3c00e5c22fee48 100644 (file)
@@ -114,8 +114,6 @@ lyx_SOURCES = \
        encoding.h \
        exporter.C \
        exporter.h \
-       font.C \
-       font.h \
        gettext.C \
        gettext.h \
        importer.C \
diff --git a/src/font.C b/src/font.C
deleted file mode 100644 (file)
index 3e63bff..0000000
+++ /dev/null
@@ -1,236 +0,0 @@
-/* This file is part of
- * ======================================================
- *
- *           LyX, The Document Processor
- *
- *           Copyright 1995 Matthias Ettrich
- *           Copyright 1995-2001 The LyX Team.
- *
- * ====================================================== */
-
-#include <config.h>
-
-#ifdef __GNUG__
-#pragma implementation
-#endif
-
-#include "support/lstrings.h"
-#include "font.h"
-#include "FontLoader.h"
-#include "lyxrc.h"
-#include "encoding.h"
-#include "language.h"
-
-#include <boost/scoped_array.hpp>
-
-namespace {
-
-inline
-XFontStruct * getXFontstruct(LyXFont const & f)
-{
-       return fontloader.load(f.family(), f.series(),
-                              f.realShape(), f.size());
-}
-
-
-inline
-XID getFontID(LyXFont const & f)
-{
-       return getXFontstruct(f)->fid;
-}
-
-} // namespace anon
-
-int lyxfont::maxAscent(LyXFont const & f)
-{
-       return getXFontstruct(f)->ascent;
-}
-
-
-int lyxfont::maxDescent(LyXFont const & f)
-{
-       return getXFontstruct(f)->descent;
-}
-
-
-int lyxfont::ascent(char c, LyXFont const & f)
-{
-       XFontStruct * finfo = getXFontstruct(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+256*finfo->max_byte1)
-               return finfo->per_char[uc - finfo->min_char_or_byte2].ascent;
-       else
-               return finfo->ascent;
-}
-
-
-int lyxfont::descent(char c, LyXFont const & f)
-{
-       XFontStruct * finfo = getXFontstruct(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+256*finfo->max_byte1)
-               return finfo->per_char[uc - finfo->min_char_or_byte2].descent;
-       else
-               return finfo->descent;
-}
-
-
-int lyxfont::lbearing(char c, LyXFont const & f)
-{
-       XFontStruct * finfo = getXFontstruct(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+256*finfo->max_byte1)
-               return finfo->per_char[uc - finfo->min_char_or_byte2].lbearing;
-       else
-               return 0;
-}
-
-
-int lyxfont::rbearing(char c, LyXFont const & f)
-{
-       XFontStruct * finfo = getXFontstruct(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+256*finfo->max_byte1)
-               return finfo->per_char[uc - finfo->min_char_or_byte2].rbearing;
-       else
-               return width(c, f);
-}
-
-
-int lyxfont::width(char const * s, size_t n, LyXFont const & f)
-{
-       if (!lyxrc.use_gui)
-               return n;
-
-       if (lyxrc.font_norm_type == LyXRC::ISO_10646_1) {
-               boost::scoped_array<XChar2b> xs(new XChar2b[n]);
-               Encoding const * encoding = f.language()->encoding();
-               LyXFont font(f);
-               if (f.isSymbolFont()) {
-#ifdef USE_UNICODE_FOR_SYMBOLS
-                       font.setFamily(LyXFont::ROMAN_FAMILY);
-                       font.setShape(LyXFont::UP_SHAPE);
-#endif
-                       encoding = encodings.symbol_encoding();
-               }
-               for (size_t i = 0; i < n; ++i) {
-                       Uchar c = encoding->ucs(s[i]);
-                       xs[i].byte1 = c >> 8;
-                       xs[i].byte2 = c & 0xff;
-               }
-               int result = width(xs.get(), n, font);
-               return result;
-       }
-
-       if (f.realShape() != LyXFont::SMALLCAPS_SHAPE) {
-               return ::XTextWidth(getXFontstruct(f), s, n);
-       } else {
-               // emulate smallcaps since X doesn't support this
-               unsigned int result = 0;
-               LyXFont smallfont(f);
-               smallfont.decSize().decSize().setShape(LyXFont::UP_SHAPE);
-               for (size_t i = 0; i < n; ++i) {
-                       char const c = uppercase(s[i]);
-                       if (c != s[i]) {
-                               result += ::XTextWidth(getXFontstruct(smallfont), &c, 1);
-                       } else {
-                               result += ::XTextWidth(getXFontstruct(f), &c, 1);
-                       }
-               }
-               return result;
-       }
-}
-
-
-int lyxfont::signedWidth(string const & s, LyXFont const & f)
-{
-       if (s.empty())
-               return 0;
-       if (s[0] == '-')
-               return -width(s.substr(1, s.length() - 1), f);
-       else
-               return width(s, f);
-}
-
-
-//int lyxfont::width(wstring const & s, int n, LyXFont const & f)
-int lyxfont::width(XChar2b const * s, int n, LyXFont const & f)
-{
-       if (!lyxrc.use_gui)
-               return n;
-
-       if (f.realShape() != LyXFont::SMALLCAPS_SHAPE) {
-               return ::XTextWidth16(getXFontstruct(f), s, n);
-       } else {
-               // emulate smallcaps since X doesn't support this
-               unsigned int result = 0;
-               static XChar2b c;
-               LyXFont smallfont(f);
-               smallfont.decSize().decSize().setShape(LyXFont::UP_SHAPE);
-               for (int i = 0; i < n; ++i) {
-                       if (s[i].byte1)
-                               c = s[i];
-                       else {
-                               c.byte1 = s[i].byte1;
-                               c.byte2 = uppercase(s[i].byte2);
-                       }
-                       if (c.byte2 != s[i].byte2) {
-                               result += ::XTextWidth16(getXFontstruct(smallfont), &c, 1);
-                       } else {
-                               result += ::XTextWidth16(getXFontstruct(f), &s[i], 1);
-               }
-               }
-               return result;
-       }
-}
-
-int lyxfont::XTextWidth(LyXFont const & f, char const * str, int count)
-{
-       return ::XTextWidth(getXFontstruct(f), str, count);
-}
-
-
-int lyxfont::XTextWidth16(LyXFont const & f, XChar2b const * str, int count)
-{
-       return ::XTextWidth16(getXFontstruct(f), str, count);
-}
-
-
-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
diff --git a/src/font.h b/src/font.h
deleted file mode 100644 (file)
index eb4b71c..0000000
+++ /dev/null
@@ -1,108 +0,0 @@
-// -*- C++ -*-
-/* This file is part of
- * ======================================================
- *
- *           LyX, The Document Processor
- *
- *           Copyright 1995 Matthias Ettrich
- *           Copyright 1995-2001 The LyX Team.
- *
- * ====================================================== */
-
-#ifndef FONT_H
-#define FONT_H
-
-#ifdef __GNUG__
-#pragma interface
-#endif
-
-#include <X11/Xlib.h>
-
-#include "LString.h"
-
-class LyXFont;
-
-//namespace lyx {
-//namespace font {
-///
-struct lyxfont {
-       ///
-       static
-       int maxAscent(LyXFont const & f);
-       ///
-       static
-       int maxDescent(LyXFont const & f);
-       ///
-       static
-       int ascent(char c, LyXFont const & f);
-       ///
-       static
-       int descent(char c, LyXFont const & f);
-       ///
-       static
-       int lbearing(char c, LyXFont const & f);
-       ///
-       static
-       int rbearing(char c, LyXFont const & f);
-       ///
-       static
-       int width(char c, LyXFont const & f) {
-               return width(&c, 1, f);
-       }
-       ///
-       static
-       int width(char const * s, size_t n, LyXFont const & f);
-       ///
-       static
-       int width(string const & s, LyXFont const & f) {
-               if (s.empty()) return 0;
-               return width(s.data(), s.length(), f);
-       }
-       ///
-       //static
-       //int width(char const * s, LyXFont const & f) {
-       //      return width(s, strlen(s), f);
-       //}
-       ///
-       static
-       int signedWidth(string const & s, LyXFont const & f);
-       ///
-       static
-       int XTextWidth(LyXFont const & f, char const * str, int count);
-       ///
-       static
-       int width(XChar2b const * s, int n, LyXFont const & f);
-       ///
-       static
-       int XTextWidth16(LyXFont const & f, XChar2b const * str, int count);
-       ///
-       static
-       void XSetFont(Display * display, GC gc, LyXFont const & f);
-       // A couple of more high-level metrics
-       ///
-       static
-       void rectText(string const & str, LyXFont const & font,
-                     int & width, int & ascent, int & descent);
-       ///
-       static
-       void buttonText(string const & str, LyXFont const & font,
-                       int & width, int & ascent, int & descent);
-};
-
-//} // end of namespace font
-
-// import into namespace lyx
-//using font::maxAscent;
-//using font::maxDescent;
-//using font::ascent;
-//using font::descent;
-//using font::lbearing;
-//using font::rbearing;
-//using font::width;
-//using font::signedWidth;
-//using font::XTextWidth;
-//using font::XSetFont;
-
-//} // end of namespace lyx
-
-#endif
index 29b57aff26067032a077e712177a1ab70670d72f..2b7be48045fd94de04e44783b398ae3c61c1b2b1 100644 (file)
@@ -1,3 +1,11 @@
+2002-05-23  John Levon  <moz@compsoc.man.ac.uk>
+
+       * Makefile.am:
+       * font_metrics.h: add placeholder
+       * Painter.C:
+       * screen.C: use placeholder
 2002-05-23  John Levon  <moz@compsoc.man.ac.uk>
 
        * WorkArea.h:
index fc6ac704053fbb61664496c521b1c4fa2c5fd445..fa8e058d2cf3a0ab4bd1a79ccc8d68dc54d27b56 100644 (file)
@@ -36,5 +36,6 @@ libfrontends_la_SOURCES = \
        LyXView.h \
        WorkArea.C \
        WorkArea.h \
+       font_metrics.h \
        screen.C \
        screen.h
index e79505e8c93d285f82e2473397b64ecd9561e44d..6787f32a1d3fedd2ffff361fd54910abfb16d698 100644 (file)
@@ -16,7 +16,7 @@
 #include "Painter.h"
 #include "lyxfont.h"
 #include "WorkArea.h"
-#include "font.h"
+#include "font_metrics.h"
 
 
 int PainterBase::paperMargin() const
@@ -97,7 +97,7 @@ PainterBase & PainterBase::rectText(int x, int baseline,
        int ascent;
        int descent;
 
-       lyxfont::rectText(str, font, width, ascent, descent);
+       font_metrics::rectText(str, font, width, ascent, descent);
        rectangle(x, baseline - ascent, width, ascent + descent, frame);
        fillRectangle(x + 1, baseline - ascent + 1, width - 1,
                      ascent + descent - 1, back);
@@ -114,7 +114,7 @@ PainterBase & PainterBase::buttonText(int x, int baseline,
        int ascent;
        int descent;
 
-       lyxfont::buttonText(str, font, width, ascent, descent);
+       font_metrics::buttonText(str, font, width, ascent, descent);
        button(x, baseline - ascent, width, descent + ascent);
        text(x + 4, baseline, str, font);
        return *this;
diff --git a/src/frontends/font_metrics.h b/src/frontends/font_metrics.h
new file mode 100644 (file)
index 0000000..71efcae
--- /dev/null
@@ -0,0 +1,3 @@
+//// temporary
+
+#include "xforms/xfont_metrics.h"
index dbf850e110414cb1afd6d314c7296f23d110fe5c..e25fc3e4c05ac3e4d348c4d942fd48ece4ef5809 100644 (file)
@@ -23,7 +23,7 @@
 #include "frontends/WorkArea.h"
 #include "buffer.h"
 #include "BufferView.h"
-#include "font.h"
+#include "font_metrics.h"
 #include "insets/insettext.h"
 #include "ColorHandler.h"
 #include "language.h"
@@ -241,8 +241,8 @@ void LyXScreen::showCursor(LyXText const * text, BufferView const * bv)
                        shape = (text->real_current_font.isVisibleRightToLeft())
                                ? REVERSED_L_SHAPE : L_SHAPE;
                showManualCursor(text, text->cursor.x(), text->cursor.y(),
-                                lyxfont::maxAscent(text->real_current_font),
-                                lyxfont::maxDescent(text->real_current_font),
+                                font_metrics::maxAscent(text->real_current_font),
+                                font_metrics::maxDescent(text->real_current_font),
                                 shape);
        }
 }
index 7699bb754c179c8d891fa8288109b185c493e4ce..1ae9c66670d9a0aa0f0496a0f6665033a1e0f77c 100644 (file)
@@ -1,3 +1,10 @@
+2002-05-23  John Levon  <moz@compsoc.man.ac.uk>
+
+       * Makefile.am:
+       * XPainter.C:
+       * xfont_metrics.h:
+       * xfont_metrics.C: moved font metrics code
 2002-05-24  Juergen Vigna  <jug@sad.it>
 
        * FormMathsBitmap.C: include local includes first (selfcontainment)
index 52b1d68cef7ddd5806b003911ed7de5c22568a40..6f4ee7dddd8cda4d6e573d3d2395021ff50042ef 100644 (file)
@@ -214,6 +214,8 @@ libxforms_la_SOURCES = \
        XFormsView.h \
        XPainter.C \
        XPainter.h \
+       xfont_metrics.C \
+       xfont_metrics.h \
        xforms_helpers.C \
        xforms_helpers.h \
        xforms_resize.C \
index 08eaf776de0e9fe1aba520921cff884902374124..5cf41b7b8ef2182c1193ac7439a06947a4eca058 100644 (file)
@@ -18,7 +18,7 @@
 #include "debug.h"
 #include "lyxfont.h"
 #include "WorkArea.h"
-#include "font.h"
+#include "xfont_metrics.h"
 #include "ColorHandler.h"
 #include "lyxrc.h"
 #include "encoding.h"
@@ -220,7 +220,7 @@ PainterBase & Painter::text(int x, int y, char const * s, size_t ls,
 
        GC gc = lyxColorHandler->getGCForeground(f.realColor());
        if (f.realShape() != LyXFont::SMALLCAPS_SHAPE) {
-               lyxfont::XSetFont(display(), gc, f);
+               font_metrics::XSetFont(display(), gc, f);
                XDrawString(display(), owner.getPixmap(), gc, x, y, s, ls);
        } else {
                LyXFont smallfont(f);
@@ -229,21 +229,21 @@ PainterBase & Painter::text(int x, int y, char const * s, size_t ls,
                for (size_t i = 0; i < ls; ++i) {
                        char const c = uppercase(s[i]);
                        if (c != s[i]) {
-                               lyxfont::XSetFont(display(), gc, smallfont);
+                               font_metrics::XSetFont(display(), gc, smallfont);
                                XDrawString(display(), owner.getPixmap(), gc,
                                            tmpx, y, &c, 1);
-                               tmpx += lyxfont::XTextWidth(smallfont, &c, 1);
+                               tmpx += font_metrics::XTextWidth(smallfont, &c, 1);
                        } else {
-                               lyxfont::XSetFont(display(), gc, f);
+                               font_metrics::XSetFont(display(), gc, f);
                                XDrawString(display(), owner.getPixmap(), gc,
                                            tmpx, y, &c, 1);
-                               tmpx += lyxfont::XTextWidth(f, &c, 1);
+                               tmpx += font_metrics::XTextWidth(f, &c, 1);
                        }
                }
        }
 
        if (f.underbar() == LyXFont::ON) {
-               underline(f, x, y, lyxfont::width(s, ls, f));
+               underline(f, x, y, font_metrics::width(s, ls, f));
        }
 
        return *this;
@@ -255,7 +255,7 @@ PainterBase & Painter::text(int x, int y, XChar2b const * s, int ls,
 {
        GC gc = lyxColorHandler->getGCForeground(f.realColor());
        if (f.realShape() != LyXFont::SMALLCAPS_SHAPE) {
-               lyxfont::XSetFont(display(), gc, f);
+               font_metrics::XSetFont(display(), gc, f);
                XDrawString16(display(), owner.getPixmap(), gc, x, y, s, ls);
        } else {
                LyXFont smallfont(f);
@@ -270,21 +270,21 @@ PainterBase & Painter::text(int x, int y, XChar2b const * s, int ls,
                                c.byte2 = uppercase(s[i].byte2);
                        }
                        if (c.byte2 != s[i].byte2) {
-                               lyxfont::XSetFont(display(), gc, smallfont);
+                               font_metrics::XSetFont(display(), gc, smallfont);
                                XDrawString16(display(), owner.getPixmap(), gc,
                                              tmpx, y, &c, 1);
-                               tmpx += lyxfont::XTextWidth16(smallfont, &c, 1);
+                               tmpx += font_metrics::XTextWidth16(smallfont, &c, 1);
                        } else {
-                               lyxfont::XSetFont(display(), gc, f);
+                               font_metrics::XSetFont(display(), gc, f);
                                XDrawString16(display(), owner.getPixmap(), gc,
                                              tmpx, y, &c, 1);
-                               tmpx += lyxfont::XTextWidth16(f, &c, 1);
+                               tmpx += font_metrics::XTextWidth16(f, &c, 1);
                        }
                }
        }
 
        if (f.underbar() == LyXFont::ON) {
-               underline(f, x, y, lyxfont::width(s, ls, f));
+               underline(f, x, y, font_metrics::width(s, ls, f));
        }
 
        return *this;
@@ -293,8 +293,8 @@ PainterBase & Painter::text(int x, int y, XChar2b const * s, int ls,
 
 void Painter::underline(LyXFont const & f, int x, int y, int width)
 {
-       int const below = max(lyxfont::maxDescent(f) / 2, 2);
-       int const height = max((lyxfont::maxDescent(f) / 4) - 1, 1);
+       int const below = max(font_metrics::maxDescent(f) / 2, 2);
+       int const height = max((font_metrics::maxDescent(f) / 4) - 1, 1);
        if (height < 2)
                line(x, y + below, x + width, y + below, f.color());
        else
diff --git a/src/frontends/xforms/xfont_metrics.C b/src/frontends/xforms/xfont_metrics.C
new file mode 100644 (file)
index 0000000..f1fce05
--- /dev/null
@@ -0,0 +1,249 @@
+/* This file is part of
+ * ======================================================
+ *
+ *           LyX, The Document Processor
+ *
+ *           Copyright 1995 Matthias Ettrich
+ *           Copyright 1995-2001 The LyX Team.
+ *
+ * ====================================================== */
+
+#include <config.h>
+
+#ifdef __GNUG__
+#pragma implementation
+#endif
+
+#include "support/lstrings.h"
+#include "xfont_metrics.h"
+#include "FontLoader.h"
+#include "lyxrc.h"
+#include "encoding.h"
+#include "language.h"
+
+#include <boost/scoped_array.hpp>
+
+namespace {
+
+inline
+XFontStruct * getXFontstruct(LyXFont const & f)
+{
+       return fontloader.load(f.family(), f.series(),
+                              f.realShape(), f.size());
+}
+
+
+inline
+XID getFontID(LyXFont const & f)
+{
+       return getXFontstruct(f)->fid;
+}
+
+} // namespace anon
+
+int font_metrics::maxAscent(LyXFont const & f)
+{
+       return getXFontstruct(f)->ascent;
+}
+
+
+int font_metrics::maxDescent(LyXFont const & f)
+{
+       return getXFontstruct(f)->descent;
+}
+
+
+int font_metrics::ascent(char c, LyXFont const & f)
+{
+       XFontStruct * finfo = getXFontstruct(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+256*finfo->max_byte1)
+               return finfo->per_char[uc - finfo->min_char_or_byte2].ascent;
+       else
+               return finfo->ascent;
+}
+
+
+int font_metrics::descent(char c, LyXFont const & f)
+{
+       XFontStruct * finfo = getXFontstruct(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+256*finfo->max_byte1)
+               return finfo->per_char[uc - finfo->min_char_or_byte2].descent;
+       else
+               return finfo->descent;
+}
+
+
+int font_metrics::lbearing(char c, LyXFont const & f)
+{
+       XFontStruct * finfo = getXFontstruct(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+256*finfo->max_byte1)
+               return finfo->per_char[uc - finfo->min_char_or_byte2].lbearing;
+       else
+               return 0;
+}
+
+
+int font_metrics::rbearing(char c, LyXFont const & f)
+{
+       XFontStruct * finfo = getXFontstruct(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+256*finfo->max_byte1)
+               return finfo->per_char[uc - finfo->min_char_or_byte2].rbearing;
+       else
+               return width(c, f);
+}
+
+
+int font_metrics::width(char c, LyXFont const & f)
+{ 
+       return width(&c, 1, f);
+}
+
+
+int font_metrics::width(string const & s, LyXFont const & f)
+{
+       if (s.empty()) return 0;
+       return width(s.data(), s.length(), f);
+}
+int font_metrics::width(char const * s, size_t n, LyXFont const & f)
+{
+       if (!lyxrc.use_gui)
+               return n;
+
+       if (lyxrc.font_norm_type == LyXRC::ISO_10646_1) {
+               boost::scoped_array<XChar2b> xs(new XChar2b[n]);
+               Encoding const * encoding = f.language()->encoding();
+               LyXFont font(f);
+               if (f.isSymbolFont()) {
+#ifdef USE_UNICODE_FOR_SYMBOLS
+                       font.setFamily(LyXFont::ROMAN_FAMILY);
+                       font.setShape(LyXFont::UP_SHAPE);
+#endif
+                       encoding = encodings.symbol_encoding();
+               }
+               for (size_t i = 0; i < n; ++i) {
+                       Uchar c = encoding->ucs(s[i]);
+                       xs[i].byte1 = c >> 8;
+                       xs[i].byte2 = c & 0xff;
+               }
+               int result = width(xs.get(), n, font);
+               return result;
+       }
+
+       if (f.realShape() != LyXFont::SMALLCAPS_SHAPE) {
+               return ::XTextWidth(getXFontstruct(f), s, n);
+       } else {
+               // emulate smallcaps since X doesn't support this
+               unsigned int result = 0;
+               LyXFont smallfont(f);
+               smallfont.decSize().decSize().setShape(LyXFont::UP_SHAPE);
+               for (size_t i = 0; i < n; ++i) {
+                       char const c = uppercase(s[i]);
+                       if (c != s[i]) {
+                               result += ::XTextWidth(getXFontstruct(smallfont), &c, 1);
+                       } else {
+                               result += ::XTextWidth(getXFontstruct(f), &c, 1);
+                       }
+               }
+               return result;
+       }
+}
+
+
+int font_metrics::signedWidth(string const & s, LyXFont const & f)
+{
+       if (s.empty())
+               return 0;
+       if (s[0] == '-')
+               return -width(s.substr(1, s.length() - 1), f);
+       else
+               return width(s, f);
+}
+
+
+//int font_metrics::width(wstring const & s, int n, LyXFont const & f)
+int font_metrics::width(XChar2b const * s, int n, LyXFont const & f)
+{
+       if (!lyxrc.use_gui)
+               return n;
+
+       if (f.realShape() != LyXFont::SMALLCAPS_SHAPE) {
+               return ::XTextWidth16(getXFontstruct(f), s, n);
+       } else {
+               // emulate smallcaps since X doesn't support this
+               unsigned int result = 0;
+               static XChar2b c;
+               LyXFont smallfont(f);
+               smallfont.decSize().decSize().setShape(LyXFont::UP_SHAPE);
+               for (int i = 0; i < n; ++i) {
+                       if (s[i].byte1)
+                               c = s[i];
+                       else {
+                               c.byte1 = s[i].byte1;
+                               c.byte2 = uppercase(s[i].byte2);
+                       }
+                       if (c.byte2 != s[i].byte2) {
+                               result += ::XTextWidth16(getXFontstruct(smallfont), &c, 1);
+                       } else {
+                               result += ::XTextWidth16(getXFontstruct(f), &s[i], 1);
+               }
+               }
+               return result;
+       }
+}
+
+int font_metrics::XTextWidth(LyXFont const & f, char const * str, int count)
+{
+       return ::XTextWidth(getXFontstruct(f), str, count);
+}
+
+
+int font_metrics::XTextWidth16(LyXFont const & f, XChar2b const * str, int count)
+{
+       return ::XTextWidth16(getXFontstruct(f), str, count);
+}
+
+
+void font_metrics::XSetFont(Display * display, GC gc, LyXFont const & f)
+{
+       ::XSetFont(display, gc, getFontID(f));
+}
+
+
+void font_metrics::rectText(string const & str, LyXFont const & font,
+             int & width, int & ascent, int & descent)
+{
+       static int const d = 2;
+       width = font_metrics::width(str, font) + d * 2 + 2;
+       ascent = font_metrics::maxAscent(font) + d;
+       descent = font_metrics::maxDescent(font) + d;
+}
+
+
+
+void font_metrics::buttonText(string const & str, LyXFont const & font,
+               int & width, int & ascent, int & descent)
+{
+       static int const d = 3;
+
+       width = font_metrics::width(str, font) + d * 2 + 2;
+       ascent = font_metrics::maxAscent(font) + d;
+       descent = font_metrics::maxDescent(font) + d;
+}
+
+
+//} // end of namespace font
+//} // end of namespace lyx
diff --git a/src/frontends/xforms/xfont_metrics.h b/src/frontends/xforms/xfont_metrics.h
new file mode 100644 (file)
index 0000000..f7e6ac1
--- /dev/null
@@ -0,0 +1,89 @@
+// -*- C++ -*-
+/* This file is part of
+ * ======================================================
+ *
+ *           LyX, The Document Processor
+ *
+ *           Copyright 1995 Matthias Ettrich
+ *           Copyright 1995-2001 The LyX Team.
+ *
+ * ====================================================== */
+
+#ifndef FONT_H
+#define FONT_H
+
+#ifdef __GNUG__
+#pragma interface
+#endif
+
+#include <X11/Xlib.h>
+
+#include "LString.h"
+
+class LyXFont;
+
+namespace font_metrics {
+//namespace lyx {
+//namespace font {
+///
+//istruct lyxfont {
+       ///
+       int maxAscent(LyXFont const & f);
+       ///
+       int maxDescent(LyXFont const & f);
+       ///
+       int ascent(char c, LyXFont const & f);
+       ///
+       int descent(char c, LyXFont const & f);
+       ///
+       int lbearing(char c, LyXFont const & f);
+       ///
+       int rbearing(char c, LyXFont const & f);
+       ///
+       int width(char const * s, size_t n, LyXFont const & f);
+       ///
+       int width(char c, LyXFont const & f);
+       ///
+       int width(string const & s, LyXFont const & f);
+       ///
+       //static
+       //int width(char const * s, LyXFont const & f) {
+       //      return width(s, strlen(s), f);
+       //}
+       ///
+       int signedWidth(string const & s, LyXFont const & f);
+       ///
+       int XTextWidth(LyXFont const & f, char const * str, int count);
+       ///
+       int width(XChar2b const * s, int n, LyXFont const & f);
+       ///
+       int XTextWidth16(LyXFont const & f, XChar2b const * str, int count);
+       ///
+       void XSetFont(Display * display, GC gc, LyXFont const & f);
+       // A couple of more high-level metrics
+       ///
+       void rectText(string const & str, LyXFont const & font,
+                     int & width, int & ascent, int & descent);
+       ///
+       void buttonText(string const & str, LyXFont const & font,
+                       int & width, int & ascent, int & descent);
+//};
+}
+
+//} // end of namespace font
+
+// import into namespace lyx
+//using font::maxAscent;
+//using font::maxDescent;
+//using font::ascent;
+//using font::descent;
+//using font::lbearing;
+//using font::rbearing;
+//using font::width;
+//using font::signedWidth;
+//using font::XTextWidth;
+//using font::XSetFont;
+
+//} // end of namespace lyx
+
+#endif
index b479158d446ba5f02ecdcbf89adcdeb8c662fb69..edfa2e5dfa94baac2a523a3b3e64c9bb2cead258 100644 (file)
@@ -1,3 +1,17 @@
+2002-05-24  John Levon  <moz@compsoc.man.ac.uk>
+
+       * insetbib.C:
+       * insetbutton.C:
+       * insetcaption.C:
+       * insetcollapsable.C:
+       * inseterror.C:
+       * insetgraphics.C:
+       * insetlatexaccent.C:
+       * insetquotes.C:
+       * insetspecialchar.C:
+       * insettabular.C:
+       * insettext.C: name change for font metrics
 2002-05-24  Juergen Vigna  <jug@sad.it>
 
        * insetgraphics.h: include inset.h first (for LString.h)
index ec4547eba20d84d592b2b56d6e8a7290f017d792..4e8c99fc596d7d56aa6efcf3ce793bdfd33a306e 100644 (file)
@@ -11,7 +11,7 @@
 #include "gettext.h"
 #include "lyxtext.h"
 #include "lyxrc.h"
-#include "font.h"
+#include "frontends/font_metrics.h"
 #include "frontends/LyXView.h"
 #include "lyxtextclasslist.h"
 
@@ -353,7 +353,7 @@ string const bibitemWidest(Buffer const * buffer)
        while (par) {
                if (par->bibkey) {
                        int const wx =
-                               lyxfont::width(par->bibkey->getBibLabel(),
+                               font_metrics::width(par->bibkey->getBibLabel(),
                                               font);
                        if (wx > w) {
                                w = wx;
index 704890110e61a92352973960d2e2d1efb7862e2a..eef13251ef0988e9704ec28d61ffd6ed8bf4d480 100644 (file)
@@ -20,7 +20,7 @@
 #include "frontends/Painter.h"
 #include "support/LAssert.h"
 #include "lyxfont.h"
-#include "font.h"
+#include "frontends/font_metrics.h"
 
 using std::ostream;
 using std::endl;
@@ -38,10 +38,10 @@ int InsetButton::ascent(BufferView * bv, LyXFont const &) const
        int descent;
        string const s = getScreenLabel(bv->buffer());
 
-       if (editable()) {
-               lyxfont::buttonText(s, font, width, ascent, descent);
+        if (editable()) {
+               font_metrics::buttonText(s, font, width, ascent, descent);
        } else {
-               lyxfont::rectText(s, font, width, ascent, descent);
+               font_metrics::rectText(s, font, width, ascent, descent);
        }
 
        return ascent;
@@ -60,10 +60,10 @@ int InsetButton::descent(BufferView * bv, LyXFont const &) const
        int descent;
        string const s = getScreenLabel(bv->buffer());
 
-       if (editable()) {
-               lyxfont::buttonText(s, font, width, ascent, descent);
+        if (editable()) {
+               font_metrics::buttonText(s, font, width, ascent, descent);
        } else {
-               lyxfont::rectText(s, font, width, ascent, descent);
+               font_metrics::rectText(s, font, width, ascent, descent);
        }
 
        return descent;
@@ -82,10 +82,10 @@ int InsetButton::width(BufferView * bv, LyXFont const &) const
        int descent;
        string const s = getScreenLabel(bv->buffer());
 
-       if (editable()) {
-               lyxfont::buttonText(s, font, width, ascent, descent);
+        if (editable()) {
+               font_metrics::buttonText(s, font, width, ascent, descent);
        } else {
-               lyxfont::rectText(s, font, width, ascent, descent);
+               font_metrics::rectText(s, font, width, ascent, descent);
        }
 
        return width + 4;
index de9f0e4f658a47c6bae0e96b8df17f1580bbffd5..f0417a212e650ed2e65f190cc3a577db8b199e4e 100644 (file)
@@ -16,7 +16,7 @@
 
 #include "insetcaption.h"
 #include "frontends/Painter.h"
-#include "font.h"
+#include "frontends/font_metrics.h"
 #include "BufferView.h"
 #include "FloatList.h"
 #include "insets/insetfloat.h"
@@ -89,7 +89,7 @@ void InsetCaption::draw(BufferView * bv, LyXFont const & f,
        string const label = _(fl) + " " + num + ":";
 
        Painter & pain = bv->painter();
-       int const w = lyxfont::width(label, f);
+       int const w = font_metrics::width(label, f);
        pain.text(int(x), baseline, label, f);
        x += w;
 
index b7e8c5df972cb297671c87639f92e7d68ce88eea..39719b90515b8a23d8a4bcfd0caa2a99c11c7012 100644 (file)
@@ -21,7 +21,7 @@
 #include "frontends/Painter.h"
 #include "debug.h"
 #include "lyxtext.h"
-#include "font.h"
+#include "frontends/font_metrics.h"
 #include "lyxlex.h"
 
 #include "insets/insettext.h"
@@ -113,7 +113,7 @@ int InsetCollapsable::ascent_collapsed() const
        int width = 0;
        int ascent = 0;
        int descent = 0;
-       lyxfont::buttonText(label, labelfont, width, ascent, descent);
+       font_metrics::buttonText(label, labelfont, width, ascent, descent);
        return ascent;
 }
 
@@ -123,7 +123,7 @@ int InsetCollapsable::descent_collapsed() const
        int width = 0;
        int ascent = 0;
        int descent = 0;
-       lyxfont::buttonText(label, labelfont, width, ascent, descent);
+       font_metrics::buttonText(label, labelfont, width, ascent, descent);
        return descent;
 }
 
@@ -134,7 +134,7 @@ int InsetCollapsable::width_collapsed() const
        int width;
        int ascent;
        int descent;
-       lyxfont::buttonText(label, labelfont, width, ascent, descent);
+       font_metrics::buttonText(label, labelfont, width, ascent, descent);
        return width + (2*TEXT_TO_INSET_OFFSET);
 }
 
index f48761c02597d9c6243a0b8765ced2cddc93a207..41928d99c566f2c46f26cbdabf5f03853859db09 100644 (file)
@@ -15,7 +15,7 @@
 #endif
 
 #include "BufferView.h"
-#include "font.h"
+#include "frontends/font_metrics.h"
 #include "lyxfont.h"
 #include "gettext.h"
 #include "inseterror.h"
@@ -36,7 +36,7 @@ int InsetError::ascent(BufferView *, LyXFont const & font) const
 {
        LyXFont efont;
        efont.setSize(font.size()).decSize();
-       return lyxfont::maxAscent(efont) + 1;
+       return font_metrics::maxAscent(efont) + 1;
 }
 
 
@@ -44,7 +44,7 @@ int InsetError::descent(BufferView *, LyXFont const & font) const
 {
        LyXFont efont;
        efont.setSize(font.size()).decSize();
-       return lyxfont::maxDescent(efont) + 1;
+       return font_metrics::maxDescent(efont) + 1;
 }
 
 
@@ -52,7 +52,7 @@ int InsetError::width(BufferView *, LyXFont const & font) const
 {
        LyXFont efont;
        efont.setSize(font.size()).decSize();
-       return 6 + lyxfont::width(_("Error"), efont);
+       return 6 + font_metrics::width(_("Error"), efont);
 }
 
 
index f440b269910f5ed49788200954c7e2705eda27e7..038a2236971628451eb05c900215542395fd7664 100644 (file)
@@ -88,7 +88,7 @@ TODO Before initial production release:
 #include "converter.h"
 #include "frontends/Painter.h"
 #include "lyxrc.h"
-#include "font.h"    // For the lyxfont class.
+#include "frontends/font_metrics.h"
 #include "debug.h"
 #include "gettext.h"
 #include "LaTeXFeatures.h"
@@ -263,13 +263,13 @@ int InsetGraphics::width(BufferView *, LyXFont const & font) const
                string const justname = OnlyFilename (params().filename);
                if (!justname.empty()) {
                        msgFont.setSize(LyXFont::SIZE_FOOTNOTE);
-                       font_width = lyxfont::width(justname, msgFont);
+                       font_width = font_metrics::width(justname, msgFont);
                }
 
                string const msg = statusMessage();
                if (!msg.empty()) {
                        msgFont.setSize(LyXFont::SIZE_TINY);
-                       int const msg_width = lyxfont::width(msg, msgFont);
+                       int const msg_width = font_metrics::width(msg, msgFont);
                        font_width = std::max(font_width, msg_width);
                }
 
@@ -328,8 +328,8 @@ void InsetGraphics::draw(BufferView * bv, LyXFont const & font,
                string const justname = OnlyFilename (params().filename);
                if (!justname.empty()) {
                        msgFont.setSize(LyXFont::SIZE_FOOTNOTE);
-                       paint.text(old_x + 8,
-                                  baseline - lyxfont::maxAscent(msgFont) - 4,
+                       paint.text(old_x + 8, 
+                                  baseline - font_metrics::maxAscent(msgFont) - 4,
                                   justname, msgFont);
                }
 
index 0fbcd32cc59d59ccc89f69a662ca3ed7d976bd1b..31834610a7615a041a6dd3c76e32d1f6813f6825 100644 (file)
@@ -20,7 +20,7 @@
 #include "support/lstrings.h"
 #include "BufferView.h"
 #include "frontends/Painter.h"
-#include "font.h"
+#include "frontends/font_metrics.h"
 #include "language.h"
 
 using std::ostream;
@@ -270,13 +270,13 @@ int InsetLatexAccent::ascent(BufferView *, LyXFont const & font) const
        int max;
        if (candisp) {
                if (ic == ' ')
-                       max = lyxfont::ascent('a', font);
+                       max = font_metrics::ascent('a', font);
                else
-                       max = lyxfont::ascent(ic, font);
-               if (plusasc)
-                       max += (lyxfont::maxAscent(font) + 3) / 3;
+                       max = font_metrics::ascent(ic, font);
+               if (plusasc) 
+                       max += (font_metrics::maxAscent(font) + 3) / 3;
        } else
-               max = lyxfont::maxAscent(font) + 4;
+               max = font_metrics::maxAscent(font) + 4;
        return max;
 }
 
@@ -285,14 +285,14 @@ int InsetLatexAccent::descent(BufferView *, LyXFont const & font) const
 {
        int max;
        if (candisp) {
-               if (ic == ' ')
-                       max = lyxfont::descent('a', font);
-               else
-               max = lyxfont::descent(ic, font);
-               if (plusdesc)
-               max += 3;
+               if (ic == ' ') 
+                       max = font_metrics::descent('a', font);
+                else
+                       max = font_metrics::descent(ic, font);
+                if (plusdesc)
+                       max += 3;
        } else
-               max = lyxfont::maxDescent(font) + 4;
+               max = font_metrics::maxDescent(font) + 4;
        return max;
 }
 
@@ -300,21 +300,21 @@ int InsetLatexAccent::descent(BufferView *, LyXFont const & font) const
 int InsetLatexAccent::width(BufferView *, LyXFont const & font) const
 {
        if (candisp)
-               return lyxfont::width(ic, font);
-       else
-               return lyxfont::width(contents, font) + 4;
+               return font_metrics::width(ic, font);
+        else
+                return font_metrics::width(contents, font) + 4;
 }
 
 
 int InsetLatexAccent::lbearing(LyXFont const & font) const
 {
-       return lyxfont::lbearing(ic, font);
+       return font_metrics::lbearing(ic, font);
 }
 
 
 int InsetLatexAccent::rbearing(LyXFont const & font) const
 {
-       return lyxfont::rbearing(ic, font);
+       return font_metrics::rbearing(ic, font);
 }
 
 
@@ -388,7 +388,7 @@ void InsetLatexAccent::draw(BufferView * bv, LyXFont const & font0,
                int y;
                if (plusasc) {
                        // mark at the top
-                       hg = lyxfont::maxDescent(font);
+                       hg = font_metrics::maxDescent(font);
                        y = baseline - asc;
 
                        if (font.shape() == LyXFont::ITALIC_SHAPE)
@@ -406,15 +406,15 @@ void InsetLatexAccent::draw(BufferView * bv, LyXFont const & font0,
                pain.text(int(x), baseline, ic, font);
 
                if (remdot) {
-                       int tmpvar = baseline - lyxfont::ascent('i', font);
+                       int tmpvar = baseline - font_metrics::ascent('i', font);
                        float tmpx = 0;
                        if (font.shape() == LyXFont::ITALIC_SHAPE)
                                tmpx += (8.0 * hg) / 10.0; // italic
                        lyxerr[Debug::KEY] << "Removing dot." << endl;
                        // remove the dot first
                        pain.fillRectangle(int(x + tmpx), tmpvar, wid,
-                                          lyxfont::ascent('i', font) -
-                                          lyxfont::ascent('x', font) - 1,
+                                          font_metrics::ascent('i', font) -
+                                          font_metrics::ascent('x', font) - 1,
                                           backgroundColor());
                        // the five lines below is a simple hack to
                        // make the display of accent 'i' and 'j'
@@ -429,58 +429,58 @@ void InsetLatexAccent::draw(BufferView * bv, LyXFont const & font0,
                // now the rest - draw within (x, y, x+wid, y+hg)
                switch (modtype) {
                case ACUTE:     // acute 0xB4
-               {
-                       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,
+               {
+                       pain.text(int(x2 - (font_metrics::rbearing(0xB4, font) - font_metrics::lbearing(0xB4, font)) / 2),
+                                 baseline - font_metrics::ascent(ic, font) - font_metrics::descent(0xB4, font) - (font_metrics::ascent(0xB4, font) + font_metrics::descent(0xB4, font)) / 2,
                                  char(0xB4), font);
                        break;
                }
                case GRAVE:     // grave 0x60
                {
-                       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),
+                       pain.text(int(x2 - (font_metrics::rbearing(0x60, font) - font_metrics::lbearing(0x60, font)) / 2),
+                                 int(baseline - font_metrics::ascent(ic, font) - font_metrics::descent(0x60, font) - (font_metrics::ascent(0x60, font) + font_metrics::descent(0x60, font)) / 2.0),
                                  char(0x60), font);
                        break;
                }
                case MACRON:     // macron
                {
-                       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)),
+                       pain.text(int(x2 - (font_metrics::rbearing(0xAF, font) - font_metrics::lbearing(0xAF, font)) / 2),
+                                 baseline - font_metrics::ascent(ic, font) - font_metrics::descent(0xAF, font) - (font_metrics::ascent(0xAF, font) + font_metrics::descent(0xAF, font)),
                                  char(0xAF), font);
                        break;
                }
                case TILDE:     // tilde
                {
-                       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,
+                       pain.text(int(x2 - (font_metrics::rbearing('~', font) - font_metrics::lbearing('~', font)) / 2),
+                                 baseline - font_metrics::ascent(ic, font) - font_metrics::descent('~', font) - (font_metrics::ascent('~', font) + font_metrics::descent('~', font)) / 2,
                                  '~', font);
                        break;
                }
                case UNDERBAR:     // underbar 0x5F
                {
-                       pain.text(int(x2 - (lyxfont::rbearing(0x5F, font) - lyxfont::lbearing(0x5F, font)) / 2), baseline,
+                       pain.text(int(x2 - (font_metrics::rbearing(0x5F, font) - font_metrics::lbearing(0x5F, font)) / 2), baseline,
                                  char(0x5F), font);
                        break;
                }
                case CEDILLA:     // cedilla
                {
-                       pain.text(int(x2 - (lyxfont::rbearing(0xB8, font) - lyxfont::lbearing(0xB8, font)) / 2), baseline,
+                       pain.text(int(x2 - (font_metrics::rbearing(0xB8, font) - font_metrics::lbearing(0xB8, font)) / 2), baseline,
                                  char(0xB8), font);
 
                        break;
                }
                case UNDERDOT:     // underdot
                {
-                       pain.text(int(x2 - (lyxfont::rbearing('.', font) - lyxfont::lbearing('.', font)) / 2.0),
-                                 int(baseline + 3.0 / 2.0 * (lyxfont::ascent('.', font) + lyxfont::descent('.', font))),
+                       pain.text(int(x2 - (font_metrics::rbearing('.', font) - font_metrics::lbearing('.', font)) / 2.0),
+                                 int(baseline + 3.0 / 2.0 * (font_metrics::ascent('.', font) + font_metrics::descent('.', font))),
                                  '.', font);
                        break;
                }
 
                case DOT:    // dot
                {
-                       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,
+                       pain.text(int(x2 - (font_metrics::rbearing('.', font) - font_metrics::lbearing('.', font)) / 2.0),
+                                 baseline - font_metrics::ascent(ic, font) - font_metrics::descent('.', font) - (font_metrics::ascent('.', font) + font_metrics::descent('.', font)) / 2,
                                  '.', font);
                        break;
                }
@@ -489,8 +489,8 @@ void InsetLatexAccent::draw(BufferView * bv, LyXFont const & font0,
                {
                        LyXFont tmpf(font);
                        tmpf.decSize().decSize();
-                       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),
+                       pain.text(int(x2 - (font_metrics::rbearing(0xB0, tmpf) - font_metrics::lbearing(0xB0, tmpf)) / 2.0),
+                                 int(baseline - font_metrics::ascent(ic, font) - font_metrics::descent(0xB0, tmpf) - (font_metrics::ascent(0xB0, tmpf) + font_metrics::descent(0xB0, tmpf)) / 3.0),
                                  char(0xB0), tmpf);
                        break;
                }
@@ -537,18 +537,18 @@ void InsetLatexAccent::draw(BufferView * bv, LyXFont const & font0,
                }
                case HUNGARIAN_UMLAUT:    // hung. umlaut
                {
-                       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,
+                       pain.text(int(x2 - (font_metrics::rbearing('´', font) - font_metrics::lbearing('´', font))),
+                                 baseline - font_metrics::ascent(ic, font) - font_metrics::descent('´', font) - (font_metrics::ascent('´', font) + font_metrics::descent('´', font)) / 2,
                                  '´', font);
                        pain.text(int(x2),
-                                 baseline - lyxfont::ascent(ic, font) - lyxfont::descent('´', font) - (lyxfont::ascent('´', font) + lyxfont::descent('´', font)) / 2,
+                                 baseline - font_metrics::ascent(ic, font) - font_metrics::descent('´', font) - (font_metrics::ascent('´', font) + font_metrics::descent('´', font)) / 2,
                                  '´', font);
                        break;
                }
                case UMLAUT:    // umlaut
                {
-                       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,
+                       pain.text(int(x2 - (font_metrics::rbearing('¨', font) - font_metrics::lbearing('¨', font)) / 2),
+                                 baseline - font_metrics::ascent(ic, font) - font_metrics::descent('¨', font) - (font_metrics::ascent('¨', font) + font_metrics::descent('¨', font)) / 2,
                                  '¨', font);
                        break;
                }
@@ -556,8 +556,8 @@ void InsetLatexAccent::draw(BufferView * bv, LyXFont const & font0,
                {
                        LyXFont tmpf(font);
                        tmpf.decSize().decSize().decSize();
-                       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),
+                       pain.text(int(x2 - (font_metrics::rbearing(0x5E, tmpf) - font_metrics::lbearing(0x5E, tmpf)) / 2),
+                                 int(baseline - font_metrics::ascent(ic, font) - font_metrics::descent(0x5E, tmpf) - (font_metrics::ascent(0x5E, tmpf) + font_metrics::descent(0x5E, tmpf)) / 3.0),
                                  char(0x5E), tmpf);
                        break;
                }
index f4ca0a9870686f6ec6917451725c502057d2c034..f001179ae9e4f3ba608a6a8109fe51133cdf25d2 100644 (file)
@@ -23,7 +23,7 @@
 #include "frontends/Painter.h"
 #include "buffer.h"
 #include "debug.h"
-#include "font.h"
+#include "frontends/font_metrics.h"
 #include "language.h"
 #include "lyxfont.h"
 #include "lyxrc.h"
@@ -186,13 +186,13 @@ string const InsetQuotes::dispString(Language const * loclang) const
 
 int InsetQuotes::ascent(BufferView *, LyXFont const & font) const
 {
-       return lyxfont::maxAscent(font);
+       return font_metrics::maxAscent(font);
 }
 
 
 int InsetQuotes::descent(BufferView *, LyXFont const & font) const
 {
-       return lyxfont::maxDescent(font);
+       return font_metrics::maxDescent(font);
 }
 
 
@@ -203,11 +203,11 @@ int InsetQuotes::width(BufferView *, LyXFont const & font) const
 
        for (string::size_type i = 0; i < text.length(); ++i) {
                if (text[i] == ' ')
-                       w += lyxfont::width('i', font);
+                       w += font_metrics::width('i', font);
                else if (i == 0 || text[i] != text[i-1])
-                       w += lyxfont::width(text[i], font);
+                       w += font_metrics::width(text[i], font);
                else
-                       w += lyxfont::width(',', font);
+                       w += font_metrics::width(',', font);
        }
 
        return w;
index c89f168a5ee617043a5918653e9d93cd2a859572..1d727042f9638005978a1d5b06119dee40841af8 100644 (file)
@@ -18,7 +18,7 @@
 #include "LaTeXFeatures.h"
 #include "BufferView.h"
 #include "frontends/Painter.h"
-#include "font.h"
+#include "frontends/font_metrics.h"
 #include "lyxlex.h"
 #include "lyxfont.h"
 
@@ -37,13 +37,13 @@ InsetSpecialChar::Kind InsetSpecialChar::kind() const
 
 int InsetSpecialChar::ascent(BufferView *, LyXFont const & font) const
 {
-       return lyxfont::maxAscent(font);
+       return font_metrics::maxAscent(font);
 }
 
 
 int InsetSpecialChar::descent(BufferView *, LyXFont const & font) const
 {
-       return lyxfont::maxDescent(font);
+       return font_metrics::maxDescent(font);
 }
 
 
@@ -52,30 +52,30 @@ int InsetSpecialChar::width(BufferView *, LyXFont const & font) const
        switch (kind_) {
        case HYPHENATION:
        {
-               int w = lyxfont::width('-', font);
-               if (w > 5)
+               int w = font_metrics::width('-', font);
+               if (w > 5) 
                        w -= 2; // to make it look shorter
                return w;
        }
        case LIGATURE_BREAK:
        {
-               return lyxfont::width('|', font);
+               return font_metrics::width('|', font);
        }
        case END_OF_SENTENCE:
        {
-               return lyxfont::width('.', font);
+               return font_metrics::width('.', font);
        }
        case LDOTS:
        {
-               return lyxfont::width(". . .", font);
+               return font_metrics::width(". . .", font);
        }
        case MENU_SEPARATOR:
        {
-               return lyxfont::width(" x ", font);
+               return font_metrics::width(" x ", font);
        }
        case PROTECTED_SEPARATOR:
        {
-               return lyxfont::width('x', font);
+               return font_metrics::width('x', font);
        }
 
        }
@@ -121,9 +121,9 @@ void InsetSpecialChar::draw(BufferView * bv, LyXFont const & f,
        case MENU_SEPARATOR:
        {
                // A triangle the width and height of an 'x'
-               int w = lyxfont::width('x', font);
-               int ox = lyxfont::width(' ', font) + int(x);
-               int h = lyxfont::ascent('x', font);
+               int w = font_metrics::width('x', font);
+               int ox = font_metrics::width(' ', font) + int(x);
+               int h = font_metrics::ascent('x', font);
                int xp[4], yp[4];
 
                xp[0] = ox;     yp[0] = baseline;
@@ -138,7 +138,7 @@ void InsetSpecialChar::draw(BufferView * bv, LyXFont const & f,
        case PROTECTED_SEPARATOR:
        {
                float w = width(bv, font);
-               int h = lyxfont::ascent('x', font);
+               int h = font_metrics::ascent('x', font);
                int xp[4], yp[4];
 
                xp[0] = int(x);
index f486a217f77922ef2955d762ae5c8466c21e6342..49eaf05a246ffb682731a1b23f33458526d8cc5b 100644 (file)
@@ -23,7 +23,7 @@
 #include "debug.h"
 #include "LaTeXFeatures.h"
 #include "frontends/Painter.h"
-#include "font.h"
+#include "frontends/font_metrics.h"
 #include "lyxtext.h"
 #include "frontends/LyXView.h"
 #include "insets/insettext.h"
@@ -1428,10 +1428,10 @@ void InsetTabular::toggleInsetCursor(BufferView * bv)
        }
 
        LyXFont font; // = the_locking_inset->GetFont(par, cursor.pos);
-
-       int const asc = lyxfont::maxAscent(font);
-       int const desc = lyxfont::maxDescent(font);
-
+       
+       int const asc = font_metrics::maxAscent(font);
+       int const desc = font_metrics::maxDescent(font);
+       
        if (isCursorVisible())
                bv->hideLockedInsetCursor();
        else
@@ -1446,9 +1446,9 @@ void InsetTabular::showInsetCursor(BufferView * bv, bool show)
                return;
        if (!isCursorVisible()) {
                LyXFont font; // = GetFont(par, cursor.pos);
-
-               int const asc = lyxfont::maxAscent(font);
-               int const desc = lyxfont::maxDescent(font);
+       
+               int const asc = font_metrics::maxAscent(font);
+               int const desc = font_metrics::maxDescent(font);
                bv->fitLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc);
                if (show)
                        bv->showLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc);
@@ -1476,10 +1476,11 @@ void InsetTabular::fitInsetCursor(BufferView * bv) const
                return;
        }
        LyXFont font;
-
-       int const asc = lyxfont::maxAscent(font);
-       int const desc = lyxfont::maxDescent(font);
+       
+       int const asc = font_metrics::maxAscent(font);
+       int const desc = font_metrics::maxDescent(font);
        resetPos(bv);
+
        if (bv->fitLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc))
                need_update = FULL;
 }
index 120e260efd34cc044f4afc3f198df48fd5cb98e1..fa3b94940b57e31110f34e792c11248098d01be4 100644 (file)
@@ -29,7 +29,7 @@
 #include "lyxtext.h"
 #include "lyxcursor.h"
 #include "CutAndPaste.h"
-#include "font.h"
+#include "frontends/font_metrics.h"
 #include "LColor.h"
 #include "lyxrow.h"
 #include "lyxrc.h"
@@ -1808,9 +1808,9 @@ void InsetText::toggleInsetCursor(BufferView * bv)
 
        LyXFont const font(getLyXText(bv)->getFont(bv->buffer(), cpar(bv), cpos(bv)));
 
-       int const asc = lyxfont::maxAscent(font);
-       int const desc = lyxfont::maxDescent(font);
-
+       int const asc = font_metrics::maxAscent(font);
+       int const desc = font_metrics::maxDescent(font);
+  
        if (isCursorVisible())
                bv->hideLockedInsetCursor();
        else
@@ -1828,9 +1828,9 @@ void InsetText::showInsetCursor(BufferView * bv, bool show)
        if (!isCursorVisible()) {
                LyXFont const font =
                        getLyXText(bv)->getFont(bv->buffer(), cpar(bv), cpos(bv));
-
-               int const asc = lyxfont::maxAscent(font);
-               int const desc = lyxfont::maxDescent(font);
+       
+               int const asc = font_metrics::maxAscent(font);
+               int const desc = font_metrics::maxDescent(font);
 
                bv->fitLockedInsetCursor(cx(bv), cy(bv), asc, desc);
                if (show)
@@ -1859,9 +1859,9 @@ void InsetText::fitInsetCursor(BufferView * bv) const
        }
        LyXFont const font =
                getLyXText(bv)->getFont(bv->buffer(), cpar(bv), cpos(bv));
-
-       int const asc = lyxfont::maxAscent(font);
-       int const desc = lyxfont::maxDescent(font);
+       
+       int const asc = font_metrics::maxAscent(font);
+       int const desc = font_metrics::maxDescent(font);
 
        if (bv->fitLockedInsetCursor(cx(bv), cy(bv), asc, desc))
                need_update |= FULL;
index 516e3701366ca8cc22d87cc0d24dae737f7cd30a..0c9d225d96b9dd61a050ad3cf59d1226c262d15a 100644 (file)
@@ -1,3 +1,12 @@
+2002-05-24  John Levon  <moz@compsoc.man.ac.uk>
+
+       * formulabase.C:
+       * formulamacro.C:
+       * math_charinset.C:
+       * math_funcinset.C:
+       * math_support.C:
+       * math_unknowninset.C: new name for font metrics
 2002-05-24  Lars Gullik Bjønnes  <larsbj@birdstep.com>
 
        * math_autocorrect.C: include vector and add a using statement.
@@ -8,7 +17,6 @@
        * math_cursor.[Ch]: subsequent changes
        * math_parser.C: somewhat better error reporting
 
-
 2002-05-23  John Levon  <moz@compsoc.man.ac.uk>
 
        * formula.C:
index e01e2c858b43cf6317aa9c6ca5dace8adabcebc6..d01d39edc7f96e4da21f322be7fbd29d1f43df6a 100644 (file)
@@ -35,7 +35,7 @@
 #include "support/lstrings.h"
 #include "frontends/LyXView.h"
 #include "frontends/Painter.h"
-#include "font.h"
+#include "frontends/font_metrics.h"
 #include "Lsstream.h"
 #include "math_arrayinset.h"
 #include "math_charinset.h"
index 51cfcdf4bd19053d6ee0691b1a4fbb91bbe592ff..8eb819d6ba1a5459a4217be3578a948da7f0ffb4 100644 (file)
@@ -28,7 +28,7 @@
 #include "BufferView.h"
 #include "gettext.h"
 #include "frontends/Painter.h"
-#include "font.h"
+#include "frontends/font_metrics.h"
 #include "support/lyxlib.h"
 #include "support/LOstream.h"
 #include "debug.h"
@@ -136,7 +136,7 @@ int InsetFormulaMacro::descent(BufferView *, LyXFont const &) const
 int InsetFormulaMacro::width(BufferView * bv, LyXFont const & f) const
 {
        metrics(bv, f);
-       return 10 + lyxfont::width(prefix(), f) + par()->width();
+       return 10 + font_metrics::width(prefix(), f) + par()->width();
 }
 
 
@@ -189,7 +189,7 @@ void InsetFormulaMacro::draw(BufferView * bv, LyXFont const & f,
        pain.text(x + 2, y, prefix(), font);
 
        // formula
-       par()->draw(pain, x + lyxfont::width(prefix(), f) + 5, y);
+       par()->draw(pain, x + font_metrics::width(prefix(), f) + 5, y);
        xx += w + 2;
        xo_ = x;
        yo_ = y;
index 85cdcc6bb9a058584ed559ae04f74aef7de442f8..e87f902c42df1f03e5501c3ba96494a61d5a2bdb 100644 (file)
@@ -7,8 +7,8 @@
 #include "math_charinset.h"
 #include "LColor.h"
 #include "frontends/Painter.h"
+#include "frontends/font_metrics.h"
 #include "support/LOstream.h"
-#include "font.h"
 #include "debug.h"
 #include "math_support.h"
 #include "math_mathmlstream.h"
@@ -67,7 +67,7 @@ void MathCharInset::metrics(MathMetricsInfo const & mi) const
        whichFont(font_, code_, mi);
        mathed_char_dim(font_, char_, ascent_, descent_, width_);
        if (isBinaryOp(char_, code_))
-               width_ += 2 * lyxfont::width(' ', font_);
+               width_ += 2 * font_metrics::width(' ', font_);
 }
 
 
@@ -75,7 +75,7 @@ void MathCharInset::draw(Painter & pain, int x, int y) const
 {
        //lyxerr << "drawing '" << char_ << "' code: " << code_ << endl;
        if (isBinaryOp(char_, code_))
-               x += lyxfont::width(' ', font_);
+               x += font_metrics::width(' ', font_);
        drawChar(pain, font_, x, y, char_);
 }
 
index ce617c6aef7e48063364da7d4590ead83d6bc686..59d4e4d7e15d2b1f3de0f0d8e39c960af50b5762 100644 (file)
@@ -5,7 +5,7 @@
 #endif
 
 #include "math_funcinset.h"
-#include "font.h"
+#include "frontends/font_metrics.h"
 #include "frontends/Painter.h"
 #include "math_support.h"
 #include "math_mathmlstream.h"
index 940d3f0dfb1dd2f2a65c3fca20baf98bac902669..624a3a8d61d4e09870b57657b3801b6bb15b677f 100644 (file)
@@ -5,7 +5,7 @@
 #include "math_support.h"
 #include "lyxfont.h"
 #include "FontLoader.h"
-#include "font.h"
+#include "frontends/font_metrics.h"
 #include "math_cursor.h"
 #include "math_defs.h"
 #include "math_inset.h"
@@ -559,27 +559,27 @@ deco_struct const * search_deco(string const & name)
 void mathed_char_dim(LyXFont const & font,
        unsigned char c, int & asc, int & des, int & wid)
 {
-       des = lyxfont::descent(c, font);
-       asc = lyxfont::ascent(c, font);
+       des = font_metrics::descent(c, font);
+       asc = font_metrics::ascent(c, font);
        wid = mathed_char_width(font, c);
 }
 
 
 int mathed_char_ascent(LyXFont const & font, unsigned char c)
 {
-       return lyxfont::ascent(c, font);
+       return font_metrics::ascent(c, font);
 }
 
 
 int mathed_char_descent(LyXFont const & font, unsigned char c)
 {
-       return lyxfont::descent(c, font);
+       return font_metrics::descent(c, font);
 }
 
 
 int mathed_char_width(LyXFont const & font, unsigned char c)
 {
-       return lyxfont::width(c, font);
+       return font_metrics::width(c, font);
 }
 
 
@@ -588,16 +588,16 @@ void mathed_string_dim(LyXFont const & font,
 {
        asc = des = 0;
        for (string::const_iterator it = s.begin(); it != s.end(); ++it) {
-               des = max(des, lyxfont::descent(*it, font));
-               asc = max(asc, lyxfont::ascent(*it, font));
+               des = max(des, font_metrics::descent(*it, font));
+               asc = max(asc, font_metrics::ascent(*it, font));
        }
-       wid = lyxfont::width(s, font);
+       wid = font_metrics::width(s, font);
 }
 
 
 int mathed_string_width(LyXFont const & font, string const & s)
 {
-       return lyxfont::width(s, font);
+       return font_metrics::width(s, font);
 }
 
 
@@ -605,7 +605,7 @@ int mathed_string_ascent(LyXFont const & font, string const & s)
 {
        int asc = 0;
        for (string::const_iterator it = s.begin(); it != s.end(); ++it)
-               asc = max(asc, lyxfont::ascent(*it, font));
+               asc = max(asc, font_metrics::ascent(*it, font));
        return asc;
 }
 
@@ -614,7 +614,7 @@ int mathed_string_descent(LyXFont const & font, string const & s)
 {
        int des = 0;
        for (string::const_iterator it = s.begin(); it != s.end(); ++it)
-               des = max(des, lyxfont::descent(*it, font));
+               des = max(des, font_metrics::descent(*it, font));
        return des;
 }
 
@@ -734,8 +734,8 @@ void smallerStyleFrac(MathMetricsInfo & st)
 
 void math_font_max_dim(LyXFont const & font, int & asc, int & des)
 {
-       asc = lyxfont::maxAscent(font);
-       des = lyxfont::maxDescent(font);
+       asc = font_metrics::maxAscent(font);
+       des = font_metrics::maxDescent(font);
 }
 
 
index 4a3088a189dff22e03f085335e2eae6d0b31f496..b58588e1fa0cb852391274200344ed414176b51d 100644 (file)
@@ -5,7 +5,6 @@
 #endif
 
 #include "math_unknowninset.h"
-#include "font.h"
 #include "frontends/Painter.h"
 #include "math_support.h"
 #include "math_mathmlstream.h"
index e376fff0af1d3c56ddc16df1c3f1a8bc17e1b8cc..55a38f7817078acb926cd3ebcff00906d4cedc86 100644 (file)
 #include "buffer.h"
 #include "debug.h"
 #include "lyxrc.h"
+#include "encoding.h"
 #include "frontends/LyXView.h"
 #include "frontends/Painter.h"
+#include "frontends/font_metrics.h"
 #include "frontends/screen.h"
-#include "tracer.h"
-#include "font.h"
-#include "encoding.h"
 #include "bufferview_funcs.h"
 #include "BufferView.h"
 #include "language.h"
 #include "ParagraphParameters.h"
 #include "undo_funcs.h"
-#include "font.h"
 
 #include "insets/insetbib.h"
 #include "insets/insettext.h"
@@ -214,7 +212,7 @@ int LyXText::singleWidth(BufferView * bview, Paragraph * par,
                                 Encodings::IsComposeChar_hebrew(c))
                                return 0;
                }
-               return lyxfont::width(c, font);
+               return font_metrics::width(c, font);
 
        } else if (IsHfillChar(c)) {
                return 3;       /* Because of the representation
@@ -236,7 +234,7 @@ int LyXText::singleWidth(BufferView * bview, Paragraph * par,
                c = ' ';
        else if (IsNewlineChar(c))
                c = 'n';
-       return lyxfont::width(c, font);
+       return font_metrics::width(c, font);
 }
 
 
@@ -440,8 +438,8 @@ void LyXText::drawNewline(DrawRowParams & p, pos_type const pos)
 {
        // Draw end-of-line marker
        LyXFont const font = getFont(p.bv->buffer(), p.row->par(), pos);
-       int const wid = lyxfont::width('n', font);
-       int const asc = lyxfont::maxAscent(font);
+       int const wid = font_metrics::width('n', font);
+       int const asc = font_metrics::maxAscent(font);
        int const y = p.yo + p.row->baseline();
        int xp[3];
        int yp[3];
@@ -548,7 +546,7 @@ void LyXText::drawHebrewComposeChar(DrawRowParams & p, pos_type & vpos)
        ++vpos;
 
        LyXFont const & font = getFont(p.bv->buffer(), p.row->par(), pos);
-       int const width = lyxfont::width(c, font);
+       int const width = font_metrics::width(c, font);
        int dx = 0;
 
        for (pos_type i = pos-1; i >= 0; --i) {
@@ -583,7 +581,7 @@ void LyXText::drawArabicComposeChar(DrawRowParams & p, pos_type & vpos)
        ++vpos;
 
        LyXFont const & font = getFont(p.bv->buffer(), p.row->par(), pos);
-       int const width = lyxfont::width(c, font);
+       int const width = font_metrics::width(c, font);
        int dx = 0;
 
        for (pos_type i = pos-1; i >= 0; --i) {
@@ -639,7 +637,7 @@ void LyXText::drawChars(DrawRowParams & p, pos_type & vpos,
 
        // Draw text and set the new x position
        p.pain->text(int(p.x), p.yo + p.row->baseline(), str, orig_font);
-       p.x += lyxfont::width(str, orig_font);
+       p.x += font_metrics::width(str, orig_font);
 }
 
 
@@ -718,8 +716,8 @@ int LyXText::leftMargin(BufferView * bview, Row const * row) const
        string parindent = layout.parindent;
 
        int x = LYX_PAPER_MARGIN;
-
-       x += lyxfont::signedWidth(tclass.leftmargin(), tclass.defaultfont());
+       
+       x += font_metrics::signedWidth(tclass.leftmargin(), tclass.defaultfont());
 
        // this is the way, LyX handles the LaTeX-Environments.
        // I have had this idea very late, so it seems to be a
@@ -769,38 +767,38 @@ int LyXText::leftMargin(BufferView * bview, Row const * row) const
        switch (layout.margintype) {
        case MARGIN_DYNAMIC:
                if (!layout.leftmargin.empty()) {
-                       x += lyxfont::signedWidth(layout.leftmargin,
+                       x += font_metrics::signedWidth(layout.leftmargin,
                                                  tclass.defaultfont());
                }
                if (!row->par()->getLabelstring().empty()) {
-                       x += lyxfont::signedWidth(layout.labelindent,
+                       x += font_metrics::signedWidth(layout.labelindent,
                                                  labelfont);
-                       x += lyxfont::width(row->par()->getLabelstring(),
+                       x += font_metrics::width(row->par()->getLabelstring(),
                                            labelfont);
-                       x += lyxfont::width(layout.labelsep, labelfont);
+                       x += font_metrics::width(layout.labelsep, labelfont);
                }
                break;
        case MARGIN_MANUAL:
-               x += lyxfont::signedWidth(layout.labelindent, labelfont);
+               x += font_metrics::signedWidth(layout.labelindent, labelfont);
                if (row->pos() >= beginningOfMainBody(bview->buffer(), row->par())) {
                        if (!row->par()->getLabelWidthString().empty()) {
-                               x += lyxfont::width(row->par()->getLabelWidthString(),
+                               x += font_metrics::width(row->par()->getLabelWidthString(),
                                               labelfont);
-                               x += lyxfont::width(layout.labelsep, labelfont);
+                               x += font_metrics::width(layout.labelsep, labelfont);
                        }
                }
                break;
        case MARGIN_STATIC:
-               x += lyxfont::signedWidth(layout.leftmargin, tclass.defaultfont()) * 4
+               x += font_metrics::signedWidth(layout.leftmargin, tclass.defaultfont()) * 4
                        / (row->par()->getDepth() + 4);
                break;
        case MARGIN_FIRST_DYNAMIC:
                if (layout.labeltype == LABEL_MANUAL) {
                        if (row->pos() >= beginningOfMainBody(bview->buffer(), row->par())) {
-                               x += lyxfont::signedWidth(layout.leftmargin,
+                               x += font_metrics::signedWidth(layout.leftmargin,
                                                          labelfont);
                        } else {
-                               x += lyxfont::signedWidth(layout.labelindent,
+                               x += font_metrics::signedWidth(layout.labelindent,
                                                          labelfont);
                        }
                } else if (row->pos()
@@ -809,16 +807,16 @@ int LyXText::leftMargin(BufferView * bview, Row const * row) const
                           || (layout.labeltype == LABEL_STATIC
                               && layout.latextype == LATEX_ENVIRONMENT
                               && ! row->par()->isFirstInSequence())) {
-                       x += lyxfont::signedWidth(layout.leftmargin,
+                       x += font_metrics::signedWidth(layout.leftmargin,
                                                  labelfont);
                } else if (layout.labeltype != LABEL_TOP_ENVIRONMENT
                           && layout.labeltype != LABEL_BIBLIO
                           && layout.labeltype !=
                           LABEL_CENTERED_TOP_ENVIRONMENT) {
-                       x += lyxfont::signedWidth(layout.labelindent,
+                       x += font_metrics::signedWidth(layout.labelindent,
                                                  labelfont);
-                       x += lyxfont::width(layout.labelsep, labelfont);
-                       x += lyxfont::width(row->par()->getLabelstring(),
+                       x += font_metrics::width(layout.labelsep, labelfont);
+                       x += font_metrics::width(row->par()->getLabelstring(),
                                            labelfont);
                }
                break;
@@ -841,9 +839,9 @@ int LyXText::leftMargin(BufferView * bview, Row const * row) const
                        if (tmprow->fill() < minfill)
                                minfill = tmprow->fill();
                }
-
-               x += lyxfont::signedWidth(layout.leftmargin,
-                                         tclass.defaultfont());
+               
+               x += font_metrics::signedWidth(layout.leftmargin,
+                       tclass.defaultfont());
                x += minfill;
        }
        break;
@@ -882,7 +880,7 @@ int LyXText::leftMargin(BufferView * bview, Row const * row) const
                    && (row->par()->layout() != tclass.defaultLayoutName() ||
                        bview->buffer()->params.paragraph_separation ==
                        BufferParams::PARSEP_INDENT)) {
-                       x += lyxfont::signedWidth(parindent,
+                       x += font_metrics::signedWidth(parindent,
                                                  tclass.defaultfont());
                } else if (layout.labeltype == LABEL_BIBLIO) {
                        // ale970405 Right width for bibitems
@@ -906,7 +904,7 @@ int LyXText::rightMargin(Buffer const * buf, Row const * row) const
        LyXLayout const & layout = tclass[row->par()->layout()];
 
        int x = LYX_PAPER_MARGIN
-               + lyxfont::signedWidth(tclass.rightmargin(),
+               + font_metrics::signedWidth(tclass.rightmargin(),
                                       tclass.defaultfont());
 
        // this is the way, LyX handles the LaTeX-Environments.
@@ -940,7 +938,7 @@ int LyXText::rightMargin(Buffer const * buf, Row const * row) const
        }
 
        //lyxerr << "rightmargin: " << layout->rightmargin << endl;
-       x += lyxfont::signedWidth(layout.rightmargin, tclass.defaultfont())
+       x += font_metrics::signedWidth(layout.rightmargin, tclass.defaultfont())
                * 4 / (row->par()->getDepth() + 4);
        return x;
 }
@@ -1057,7 +1055,7 @@ LyXText::nextBreakPoint(BufferView * bview, Row const * row, int width) const
                        }
                        ++i;
                        if (i == main_body) {
-                               x += lyxfont::width(layout.labelsep,
+                               x += font_metrics::width(layout.labelsep,
                                                    getLabelFont(bview->buffer(), par));
                                if (par->isLineSeparator(i - 1))
                                        x-= singleWidth(bview, par, i - 1);
@@ -1117,7 +1115,7 @@ int LyXText::fill(BufferView * bview, Row * row, int paper_width) const
 
        while (i <= last) {
                if (main_body > 0 && i == main_body) {
-                       w += lyxfont::width(layout.labelsep, getLabelFont(bview->buffer(), row->par()));
+                       w += font_metrics::width(layout.labelsep, getLabelFont(bview->buffer(), row->par()));
                        if (row->par()->isLineSeparator(i - 1))
                                w -= singleWidth(bview, row->par(), i - 1);
                        int left_margin = labelEnd(bview, row);
@@ -1128,7 +1126,7 @@ int LyXText::fill(BufferView * bview, Row * row, int paper_width) const
                ++i;
        }
        if (main_body > 0 && main_body > last) {
-               w += lyxfont::width(layout.labelsep, getLabelFont(bview->buffer(), row->par()));
+               w += font_metrics::width(layout.labelsep, getLabelFont(bview->buffer(), row->par()));
                if (last >= 0 && row->par()->isLineSeparator(last))
                        w -= singleWidth(bview, row->par(), last);
                int const left_margin = labelEnd(bview, row);
@@ -1168,7 +1166,7 @@ int LyXText::labelFill(BufferView * bview, Row const * row) const
 
        int fill = 0;
        if (!row->par()->params().labelWidthString().empty()) {
-               fill = max(lyxfont::width(row->par()->params().labelWidthString(),
+               fill = max(font_metrics::width(row->par()->params().labelWidthString(),
                                          getLabelFont(bview->buffer(), row->par())) - w,
                           0);
        }
@@ -1339,12 +1337,13 @@ void LyXText::setHeightOfRow(BufferView * bview, Row * row_ptr) const
        }
        //lyxerr << "spacing_val = " << spacing_val << endl;
 
-       int maxasc = int(lyxfont::maxAscent(font) *
-                        layout.spacing.getValue() *
-                        spacing_val);
-       int maxdesc = int(lyxfont::maxDescent(font) *
-                         layout.spacing.getValue() *
-                         spacing_val);
+       int maxasc = int(font_metrics::maxAscent(font) *
+                        layout.spacing.getValue() *
+                        spacing_val);
+       int maxdesc = int(font_metrics::maxDescent(font) *
+                         layout.spacing.getValue() *
+                         spacing_val);
+
        pos_type const pos_end = rowLast(row_ptr);
        int labeladdon = 0;
        int maxwidth = 0;
@@ -1377,8 +1376,8 @@ void LyXText::setHeightOfRow(BufferView * bview, Row * row_ptr) const
        if (maxsize > font.size()) {
                font.setSize(maxsize);
 
-               asc = lyxfont::maxAscent(font);
-               desc = lyxfont::maxDescent(font);
+               asc = font_metrics::maxAscent(font);
+               desc = font_metrics::maxDescent(font);
                if (asc > maxasc)
                        maxasc = asc;
                if (desc > maxdesc)
@@ -1422,9 +1421,9 @@ void LyXText::setHeightOfRow(BufferView * bview, Row * row_ptr) const
                // do not forget the DTP-lines!
                // there height depends on the font of the nearest character
                if (firstpar->params().lineTop())
-                       maxasc += 2 * lyxfont::ascent('x', getFont(bview->buffer(),
-                                                                  firstpar, 0));
 
+                       maxasc += 2 * font_metrics::ascent('x', getFont(bview->buffer(),
+                                       firstpar, 0));
                // and now the pagebreaks
                if (firstpar->params().pagebreakTop())
                        maxasc += 3 * defaultHeight();
@@ -1441,10 +1440,10 @@ void LyXText::setHeightOfRow(BufferView * bview, Row * row_ptr) const
                                spacing_val = bview->buffer()->params.spacing.getValue();
                        }
 
-                       labeladdon = int(lyxfont::maxDescent(labelfont) *
-                                        layout.spacing.getValue() *
-                                        spacing_val)
-                               + int(lyxfont::maxAscent(labelfont) *
+                       labeladdon = int(font_metrics::maxDescent(labelfont) *
+                                        layout.spacing.getValue() *
+                                        spacing_val)
+                               + int(font_metrics::maxAscent(labelfont) *
                                      layout.spacing.getValue() *
                                      spacing_val);
                }
@@ -1464,10 +1463,10 @@ void LyXText::setHeightOfRow(BufferView * bview, Row * row_ptr) const
                        }
 
                        labeladdon = int(
-                               (lyxfont::maxAscent(labelfont) *
+                               (font_metrics::maxAscent(labelfont) *
                                 layout.spacing.getValue() *
                                 spacing_val)
-                               +(lyxfont::maxDescent(labelfont) *
+                               +(font_metrics::maxDescent(labelfont) *
                                  layout.spacing.getValue() *
                                  spacing_val)
                                + layout.topsep * defaultHeight()
@@ -1532,8 +1531,8 @@ void LyXText::setHeightOfRow(BufferView * bview, Row * row_ptr) const
                // do not forget the DTP-lines!
                // there height depends on the font of the nearest character
                if (firstpar->params().lineBottom())
-                       maxdesc += 2 * lyxfont::ascent('x',
-                                                      getFont(bview->buffer(),
+                       maxdesc += 2 * font_metrics::ascent('x',
+                                                      getFont(bview->buffer(),
                                                               par,
                                                               max(pos_type(0), par->size() - 1)));
 
@@ -2219,7 +2218,7 @@ void LyXText::prepareToPrint(BufferView * bview,
                if (main_body > 0 &&
                    (main_body - 1 > last ||
                     !row->par()->isLineSeparator(main_body - 1))) {
-                       x += lyxfont::width(layout.labelsep,
+                       x += font_metrics::width(layout.labelsep,
                                            getLabelFont(bview->buffer(), row->par()));
                        if (main_body - 1 <= last)
                                x += fill_label_hfill;
@@ -3161,8 +3160,7 @@ void LyXText::paintRowSelection(DrawRowParams & p)
                                [par->layout()];
                        LyXFont const lfont = getLabelFont(buffer, par);
 
-
-                       tmpx += p.label_hfill + lyxfont::width(layout.labelsep, lfont);
+                       tmpx += p.label_hfill + font_metrics::width(layout.labelsep, lfont);
 
                        if (par->isLineSeparator(main_body - 1))
                                tmpx -= singleWidth(p.bv, par, main_body - 1);
@@ -3258,8 +3256,8 @@ int LyXText::getLengthMarkerHeight(BufferView * bv, VSpace const & vsp) const
        LyXFont font;
        font.decSize();
        int const min_size = max(3 * arrow_size,
-                                     lyxfont::maxAscent(font)
-                                     + lyxfont::maxDescent(font));
+                                     font_metrics::maxAscent(font)
+                                     + font_metrics::maxDescent(font));
 
        if (vsp.length().len().value() < 0.0)
                return min_size;
@@ -3314,7 +3312,7 @@ int LyXText::drawLengthMarker(DrawRowParams & p, string const & prefix,
 
        LyXFont font;
        font.setColor(LColor::added_space).decSize();
-       lyxfont::rectText(str, font, w, a, d);
+       font_metrics::rectText(str, font, w, a, d);
 
        p.pain->rectText(leftx + 2 * arrow_size + 5,
                         start + ((end - start) / 2) + d,
@@ -3365,7 +3363,7 @@ void LyXText::paintFirstRow(DrawRowParams & p)
 
                LyXFont pb_font;
                pb_font.setColor(LColor::pagebreak).decSize();
-               lyxfont::rectText(_("Page Break (top)"), pb_font, w, a, d);
+               font_metrics::rectText(_("Page Break (top)"), pb_font, w, a, d);
                p.pain->rectText((p.width - w)/2, y + d,
                              _("Page Break (top)"), pb_font,
                              backgroundColor(),
@@ -3406,7 +3404,7 @@ void LyXText::paintFirstRow(DrawRowParams & p)
        // draw a top line
        if (parparams.lineTop()) {
                LyXFont font(LyXFont::ALL_SANE);
-               int const asc = lyxfont::ascent('x', getFont(buffer, par, 0));
+               int const asc = font_metrics::ascent('x', getFont(buffer, par, 0));
 
                y_top += asc;
 
@@ -3445,12 +3443,12 @@ void LyXText::paintFirstRow(DrawRowParams & p)
                                        }
 
                                        int const maxdesc =
-                                               int(lyxfont::maxDescent(font) * layout.spacing.getValue() * spacing_val)
+                                               int(font_metrics::maxDescent(font) * layout.spacing.getValue() * spacing_val)
                                                + int(layout.parsep) * defaultHeight();
 
                                        if (is_rtl) {
                                                x = ww - leftMargin(p.bv, p.row) -
-                                                       lyxfont::width(str, font);
+                                                       font_metrics::width(str, font);
                                        }
 
                                        p.pain->text(int(x),
@@ -3461,10 +3459,10 @@ void LyXText::paintFirstRow(DrawRowParams & p)
                        } else {
                                if (is_rtl) {
                                        x = ww - leftMargin(p.bv, p.row)
-                                               + lyxfont::width(layout.labelsep, font);
+                                               + font_metrics::width(layout.labelsep, font);
                                } else {
-                                       x = p.x - lyxfont::width(layout.labelsep, font)
-                                               - lyxfont::width(str, font);
+                                       x = p.x - font_metrics::width(layout.labelsep, font)
+                                               - font_metrics::width(str, font);
                                }
 
                                p.pain->text(int(x), p.yo + p.row->baseline(), str, font);
@@ -3487,17 +3485,17 @@ void LyXText::paintFirstRow(DrawRowParams & p)
                        }
 
                        int maxdesc =
-                               int(lyxfont::maxDescent(font) * layout.spacing.getValue() * spacing_val
+                               int(font_metrics::maxDescent(font) * layout.spacing.getValue() * spacing_val
                                + (layout.labelbottomsep * defaultHeight()));
 
                        float x = p.x;
                        if (layout.labeltype == LABEL_CENTERED_TOP_ENVIRONMENT) {
                                x = ((is_rtl ? leftMargin(p.bv, p.row) : p.x)
                                         + ww - rightMargin(buffer, p.row)) / 2;
-                               x -= lyxfont::width(str, font) / 2;
+                               x -= font_metrics::width(str, font) / 2;
                        } else if (is_rtl) {
                                x = ww - leftMargin(p.bv, p.row) -
-                                       lyxfont::width(str, font);
+                                       font_metrics::width(str, font);
                        }
                        p.pain->text(int(x), p.yo + p.row->baseline()
                                  - p.row->ascent_of_text() - maxdesc,
@@ -3510,9 +3508,9 @@ void LyXText::paintFirstRow(DrawRowParams & p)
                float x;
                if (is_rtl) {
                        x = ww - leftMargin(p.bv, p.row)
-                               + lyxfont::width(layout.labelsep, font);
+                               + font_metrics::width(layout.labelsep, font);
                } else {
-                       x = p.x - lyxfont::width(layout.labelsep, font)
+                       x = p.x - font_metrics::width(layout.labelsep, font)
                                - par->bibkey->width(p.bv, font);
                }
                par->bibkey->draw(p.bv, font, p.yo + p.row->baseline(), x, p.cleared);
@@ -3544,7 +3542,7 @@ void LyXText::paintLastRow(DrawRowParams & p)
                int w = 0;
                int a = 0;
                int d = 0;
-               lyxfont::rectText(_("Page Break (bottom)"), pb_font, w, a, d);
+               font_metrics::rectText(_("Page Break (bottom)"), pb_font, w, a, d);
                p.pain->rectText((ww - w) / 2, y + d,
                        _("Page Break (bottom)"),
                        pb_font, backgroundColor(), backgroundColor());
@@ -3564,7 +3562,7 @@ void LyXText::paintLastRow(DrawRowParams & p)
        // draw a bottom line
        if (parparams.lineBottom()) {
                LyXFont font(LyXFont::ALL_SANE);
-               int const asc = lyxfont::ascent('x',
+               int const asc = font_metrics::ascent('x',
                        getFont(buffer, par,
                        max(pos_type(0), par->size() - 1)));
 
@@ -3588,7 +3586,7 @@ void LyXText::paintLastRow(DrawRowParams & p)
        case END_LABEL_FILLED_BOX:
        {
                LyXFont const font = getLabelFont(buffer, par);
-               int const size = int(0.75 * lyxfont::maxAscent(font));
+               int const size = int(0.75 * font_metrics::maxAscent(font));
                int const y = (p.yo + p.row->baseline()) - size;
                int x = is_rtl ? LYX_PAPER_MARGIN : ww - LYX_PAPER_MARGIN - size;
 
@@ -3610,7 +3608,7 @@ void LyXText::paintLastRow(DrawRowParams & p)
                string const str = textclasslist[buffer->params.textclass][layout].endlabelstring();
                font = getLabelFont(buffer, par);
                int const x = is_rtl ?
-                       int(p.x) - lyxfont::width(str, font)
+                       int(p.x) - font_metrics::width(str, font)
                        : ww - rightMargin(buffer, p.row) - p.row->fill();
                p.pain->text(x, p.yo + p.row->baseline(), str, font);
                break;
@@ -3648,7 +3646,7 @@ void LyXText::paintRowText(DrawRowParams & p)
                        continue;
                }
                if (main_body > 0 && pos == main_body - 1) {
-                       int const lwidth = lyxfont::width(layout.labelsep,
+                       int const lwidth = font_metrics::width(layout.labelsep,
                                getLabelFont(buffer, par));
 
                        p.x += p.label_hfill + lwidth
@@ -3758,7 +3756,7 @@ void LyXText::getVisibleRow(BufferView * bv, int y_offset, int x_offset,
 int LyXText::defaultHeight() const
 {
        LyXFont font(LyXFont::ALL_SANE);
-       return int(lyxfont::maxAscent(font) + lyxfont::maxDescent(font) * 1.5);
+       return int(font_metrics::maxAscent(font) + font_metrics::maxDescent(font) * 1.5);
 }
 
 
@@ -3797,7 +3795,7 @@ LyXText::getColumnNearX(BufferView * bview, Row * row, int & x,
                last_tmpx = tmpx;
                if (main_body > 0 && c == main_body-1) {
                        tmpx += fill_label_hfill +
-                               lyxfont::width(layout.labelsep,
+                               font_metrics::width(layout.labelsep,
                                               getLabelFont(bview->buffer(), row->par()));
                        if (row->par()->isLineSeparator(main_body - 1))
                                tmpx -= singleWidth(bview, row->par(), main_body-1);
index dd00754792007ddc06eb919d063c98cad23c6b94..98731635531f5cb8cc9f082558913b82249c20d4 100644 (file)
@@ -26,7 +26,7 @@
 #include "BufferView.h"
 #include "CutAndPaste.h"
 #include "frontends/Painter.h"
-#include "font.h"
+#include "frontends/font_metrics.h"
 #include "debug.h"
 #include "lyxrc.h"
 #include "lyxrow.h"
@@ -2145,7 +2145,7 @@ float LyXText::getCursorX(BufferView * bview, Row * row,
                pos_type pos = vis2log(vpos);
                if (main_body > 0 && pos == main_body - 1) {
                        x += fill_label_hfill +
-                               lyxfont::width(textclasslist[
+                               font_metrics::width(textclasslist[
                                                       bview->buffer()->params.textclass][
                                        row->par()->layout()]
                                               .labelsep,