#include "language.h"
#include "LColor.h"
#include "xftFontLoader.h"
-#include "frontends/font_metrics.h"
+
+#include "frontends/Application.h"
+#include "frontends/FontMetrics.h"
#include "support/lstrings.h"
x, y,
reinterpret_cast<FcChar32 const *>(s),
ls);
- textwidth = font_metrics::width(s, ls, f);
+ textwidth = theApp->fontLoader().metrics(f).width(s, ls);
} else {
LyXFont smallfont(f);
smallfont.decSize().decSize().setShape(LyXFont::UP_SHAPE);
x + textwidth, y,
reinterpret_cast<FcChar32 *>(&c),
1);
- textwidth += font_metrics::width(c, smallfont);
+ textwidth += theApp->fontLoader().metrics(smallfont).width(c);
} else {
XftDrawString32(draw,
xftClr,
x + textwidth, y,
reinterpret_cast<FcChar32 *>(&c),
1);
- textwidth += font_metrics::width(c, f);
+ textwidth += theApp->fontLoader().metrics(f).width(c);
}
}
}
#undef _GLIBCPP_CONCEPT_CHECKS
#endif
+#include "xftFontMetrics.h"
+
#include "GtkmmX.h"
#include "xftFontLoader.h"
-#include "font_metrics.h"
#include "lyxrc.h"
#include "encoding.h"
#include "language.h"
namespace {
-inline XftFont * getXftFont(LyXFont const & f)
-{
- return fontLoader.load(f.family(), f.series(),
- f.realShape(), f.size());
-}
-
-
inline int XGlyphAscent(XGlyphInfo const & info)
{
return info.y;
} // namespace anon
-int font_metrics::maxAscent(LyXFont const & f)
+font_metrics::font_metrics(XftFont * f, XftFont * scf)
+ : font(f), fontS(scf)
+{
+}
+
+
+int font_metrics::maxAscent() const
{
- XftFont * font = getXftFont(f);
return font->ascent;
}
-int font_metrics::maxDescent(LyXFont const & f)
+int font_metrics::maxDescent() const
{
- XftFont * font = getXftFont(f);
return font->descent;
}
-int font_metrics::ascent(char_type c,LyXFont const & f)
+int font_metrics::ascent(char_type c) const
{
- XftFont * font = getXftFont(f);
XGlyphInfo glyph;
XftTextExtents32(getDisplay(), font,
reinterpret_cast<FcChar32 *>(&c),
}
-int font_metrics::descent(char_type c,LyXFont const & f)
+int font_metrics::descent(char_type c) const
{
- XftFont * font = getXftFont(f);
XGlyphInfo glyph;
XftTextExtents32(getDisplay(), font,
reinterpret_cast<FcChar32 *>(&c),
}
-int font_metrics::lbearing(char_type c,LyXFont const & f)
+int font_metrics::lbearing(char_type c) const
{
- XftFont * font = getXftFont(f);
XGlyphInfo glyph;
XftTextExtents32(getDisplay(), font,
reinterpret_cast<FcChar32 *>(&c),
}
-int font_metrics::rbearing(char_type c,LyXFont const & f)
+int font_metrics::rbearing(char_type c) const
{
- XftFont * font = getXftFont(f);
XGlyphInfo glyph;
XftTextExtents32(getDisplay(), font,
reinterpret_cast<FcChar32 *>(&c),
}
-int font_metrics::width(char_type const * s, size_t n, LyXFont const & f)
+int font_metrics::width(char_type const * s, size_t n) const
{
- XftFont * font = getXftFont(f);
XGlyphInfo glyph;
- if (f.realShape() != LyXFont::SMALLCAPS_SHAPE){
+ if (!fontS){
XftTextExtents32(getDisplay(),
font,
reinterpret_cast<FcChar32 const *>(s),
return XGlyphLogWidth(glyph);
} else {
int result = 0;
- LyXFont smallfont(f);
- smallfont.decSize().decSize().setShape(LyXFont::UP_SHAPE);
- XftFont * fontS = getXftFont(smallfont);
for (size_t i = 0; i < n; ++i) {
char_type c = lyx::support::uppercase(s[i]);
if (c != s[i]) {
}
-int font_metrics::signedWidth(docstring const & s, LyXFont const & f)
+int font_metrics::signedWidth(docstring const & s) const
{
if (s.empty())
return 0;
if (s[0] == '-')
- return width(s.substr(1, s.length() - 1), f);
+ return width(s.substr(1, s.length() - 1).c_str(), s.length() - 1);
else
- return width(s, f);
+ return width(s.c_str(), s.length());
}
-void font_metrics::rectText(docstring const & str, LyXFont const & font,
+void font_metrics::rectText(docstring const & str,
int & width,
int & ascent,
- int & descent)
+ int & descent) const
{
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;
+ width = font_metrics::width(str.c_str(), str.length()) + d * 2 + 2;
+ ascent = font_metrics::maxAscent() + d;
+ descent = font_metrics::maxDescent() + d;
}
-void font_metrics::buttonText(docstring const & str, LyXFont const & font,
+void font_metrics::buttonText(docstring const & str,
int & width,
int & ascent,
- int & descent)
+ int & descent) const
{
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;
+ width = font_metrics::width(str.c_str(), str.length()) + d * 2 + 2;
+ ascent = font_metrics::maxAscent() + d;
+ descent = font_metrics::maxDescent() + d;
}
--- /dev/null
+// -*- C++ -*-
+/**
+ * \file xftFontMetrics.h
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author Abdelrazak Younes
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#ifndef XFT_FONT_METRICS_H
+#define XFT_FONT_METRICS_H
+
+#include "frontends/FontMetrics.h"
+
+#include <gtkmm.h>
+#include <X11/Xft/Xft.h>
+
+class font_metrics: public lyx::frontend::FontMetrics
+{
+public:
+
+ font_metrics(XftFont * f, XftFont * scf);
+
+ virtual ~font_metrics() {}
+
+ virtual int maxAscent() const;
+ virtual int maxDescent() const;
+ virtual int ascent(lyx::char_type c) const;
+ int descent(lyx::char_type c) const;
+ virtual int lbearing(lyx::char_type c) const;
+ virtual int rbearing(lyx::char_type c) const;
+ virtual int width(lyx::char_type const * s, size_t n) const;
+ virtual int signedWidth(lyx::docstring const & s) const;
+ virtual void rectText(lyx::docstring const & str,
+ int & width,
+ int & ascent,
+ int & descent) const;
+ virtual void buttonText(lyx::docstring const & str,
+ int & width,
+ int & ascent,
+ int & descent) const;
+private:
+ XftFont * font;
+ XftFont * fontS;
+};
+#endif // XFT_FONT_METRICS_H