]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/xforms/xfont_metrics.C
Introduce LFUN_PRINT.
[lyx.git] / src / frontends / xforms / xfont_metrics.C
index f1fce05a85b233e7e56d0b4c4f51db8cdecf954e..eba8c5f4dac5533577cd26cd69263a21ed038c52 100644 (file)
@@ -1,35 +1,43 @@
-/* This file is part of
- * ======================================================
+/**
+ * \file xfont_metrics.C
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
  *
- *           LyX, The Document Processor
+ * \author unknown
+ * \author John Levon
  *
- *           Copyright 1995 Matthias Ettrich
- *           Copyright 1995-2001 The LyX Team.
- *
- * ====================================================== */
+ * Full author contact details are available in file CREDITS.
+ */
 
 #include <config.h>
 
-#ifdef __GNUG__
-#pragma implementation
-#endif
-
-#include "support/lstrings.h"
 #include "xfont_metrics.h"
-#include "FontLoader.h"
-#include "lyxrc.h"
+#include "font_metrics.h"
+#include "xfont_loader.h"
+
 #include "encoding.h"
 #include "language.h"
+#include "lyxrc.h"
+
+#include "frontends/lyx_gui.h"
+
+#include "support/lstrings.h"
 
 #include <boost/scoped_array.hpp>
 
+using lyx::support::uppercase;
+
+using std::string;
+
+
 namespace {
 
 inline
 XFontStruct * getXFontstruct(LyXFont const & f)
 {
-       return fontloader.load(f.family(), f.series(),
-                              f.realShape(), f.size());
+       return fontloader.load
+               (f.family(), f.series(),
+               f.realShape(), f.size());
 }
 
 
@@ -41,19 +49,22 @@ XID getFontID(LyXFont const & f)
 
 } // namespace anon
 
-int font_metrics::maxAscent(LyXFont const & f)
+
+namespace font_metrics {
+
+int maxAscent(LyXFont const & f)
 {
        return getXFontstruct(f)->ascent;
 }
 
 
-int font_metrics::maxDescent(LyXFont const & f)
+int maxDescent(LyXFont const & f)
 {
        return getXFontstruct(f)->descent;
 }
 
 
-int font_metrics::ascent(char c, LyXFont const & f)
+int ascent(char c, LyXFont const & f)
 {
        XFontStruct * finfo = getXFontstruct(f);
        unsigned int uc = static_cast<unsigned char>(c);
@@ -66,7 +77,7 @@ int font_metrics::ascent(char c, LyXFont const & f)
 }
 
 
-int font_metrics::descent(char c, LyXFont const & f)
+int descent(char c, LyXFont const & f)
 {
        XFontStruct * finfo = getXFontstruct(f);
        unsigned int uc = static_cast<unsigned char>(c);
@@ -79,7 +90,7 @@ int font_metrics::descent(char c, LyXFont const & f)
 }
 
 
-int font_metrics::lbearing(char c, LyXFont const & f)
+int lbearing(char c, LyXFont const & f)
 {
        XFontStruct * finfo = getXFontstruct(f);
        unsigned int uc = static_cast<unsigned char>(c);
@@ -92,7 +103,7 @@ int font_metrics::lbearing(char c, LyXFont const & f)
 }
 
 
-int font_metrics::rbearing(char c, LyXFont const & f)
+int rbearing(char c, LyXFont const & f)
 {
        XFontStruct * finfo = getXFontstruct(f);
        unsigned int uc = static_cast<unsigned char>(c);
@@ -105,22 +116,9 @@ int font_metrics::rbearing(char c, LyXFont const & 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)
+int width(char const * s, size_t n, LyXFont const & f)
 {
-       if (!lyxrc.use_gui)
+       if (!lyx_gui::use_gui)
                return n;
 
        if (lyxrc.font_norm_type == LyXRC::ISO_10646_1) {
@@ -139,7 +137,7 @@ int font_metrics::width(char const * s, size_t n, LyXFont const & f)
                        xs[i].byte1 = c >> 8;
                        xs[i].byte2 = c & 0xff;
                }
-               int result = width(xs.get(), n, font);
+               int result = xfont_metrics::width(xs.get(), n, font);
                return result;
        }
 
@@ -147,7 +145,7 @@ int font_metrics::width(char const * s, size_t n, LyXFont const & f)
                return ::XTextWidth(getXFontstruct(f), s, n);
        } else {
                // emulate smallcaps since X doesn't support this
-               unsigned int result = 0;
+               int result = 0;
                LyXFont smallfont(f);
                smallfont.decSize().decSize().setShape(LyXFont::UP_SHAPE);
                for (size_t i = 0; i < n; ++i) {
@@ -163,7 +161,7 @@ int font_metrics::width(char const * s, size_t n, LyXFont const & f)
 }
 
 
-int font_metrics::signedWidth(string const & s, LyXFont const & f)
+int signedWidth(string const & s, LyXFont const & f)
 {
        if (s.empty())
                return 0;
@@ -174,17 +172,45 @@ int font_metrics::signedWidth(string const & s, LyXFont const & 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)
+void rectText(string const & str, LyXFont const & font,
+       int & width,
+       int & ascent,
+       int & descent)
 {
-       if (!lyxrc.use_gui)
+       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 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;
+}
+
+} // namespace font_metrics
+
+namespace xfont_metrics {
+
+int width(XChar2b const * s, int n, LyXFont const & f)
+{
+       if (!lyx_gui::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;
+               int result = 0;
                static XChar2b c;
                LyXFont smallfont(f);
                smallfont.decSize().decSize().setShape(LyXFont::UP_SHAPE);
@@ -205,45 +231,23 @@ int font_metrics::width(XChar2b const * s, int n, LyXFont const & f)
        }
 }
 
-int font_metrics::XTextWidth(LyXFont const & f, char const * str, int count)
+
+int 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)
+int 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)
+/// hmm, not a metric !
+void 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
+} // namespace xfont_metrics