mirror of
https://git.lyx.org/repos/lyx.git
synced 2025-01-11 19:14:51 +00:00
fontloader for gtk, probably not efficient
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@15363 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
39acc2260d
commit
e343febe0b
@ -28,7 +28,9 @@
|
|||||||
#include "language.h"
|
#include "language.h"
|
||||||
#include "LColor.h"
|
#include "LColor.h"
|
||||||
#include "xftFontLoader.h"
|
#include "xftFontLoader.h"
|
||||||
#include "frontends/font_metrics.h"
|
|
||||||
|
#include "frontends/Application.h"
|
||||||
|
#include "frontends/FontMetrics.h"
|
||||||
|
|
||||||
#include "support/lstrings.h"
|
#include "support/lstrings.h"
|
||||||
|
|
||||||
@ -213,7 +215,7 @@ int GPainter::text(int x, int y,
|
|||||||
x, y,
|
x, y,
|
||||||
reinterpret_cast<FcChar32 const *>(s),
|
reinterpret_cast<FcChar32 const *>(s),
|
||||||
ls);
|
ls);
|
||||||
textwidth = font_metrics::width(s, ls, f);
|
textwidth = theApp->fontLoader().metrics(f).width(s, ls);
|
||||||
} else {
|
} else {
|
||||||
LyXFont smallfont(f);
|
LyXFont smallfont(f);
|
||||||
smallfont.decSize().decSize().setShape(LyXFont::UP_SHAPE);
|
smallfont.decSize().decSize().setShape(LyXFont::UP_SHAPE);
|
||||||
@ -228,7 +230,7 @@ int GPainter::text(int x, int y,
|
|||||||
x + textwidth, y,
|
x + textwidth, y,
|
||||||
reinterpret_cast<FcChar32 *>(&c),
|
reinterpret_cast<FcChar32 *>(&c),
|
||||||
1);
|
1);
|
||||||
textwidth += font_metrics::width(c, smallfont);
|
textwidth += theApp->fontLoader().metrics(smallfont).width(c);
|
||||||
} else {
|
} else {
|
||||||
XftDrawString32(draw,
|
XftDrawString32(draw,
|
||||||
xftClr,
|
xftClr,
|
||||||
@ -236,7 +238,7 @@ int GPainter::text(int x, int y,
|
|||||||
x + textwidth, y,
|
x + textwidth, y,
|
||||||
reinterpret_cast<FcChar32 *>(&c),
|
reinterpret_cast<FcChar32 *>(&c),
|
||||||
1);
|
1);
|
||||||
textwidth += font_metrics::width(c, f);
|
textwidth += theApp->fontLoader().metrics(f).width(c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -146,4 +146,5 @@ libgtk_la_SOURCES = \
|
|||||||
io_callback.h \
|
io_callback.h \
|
||||||
xftFontLoader.C \
|
xftFontLoader.C \
|
||||||
xftFontLoader.h \
|
xftFontLoader.h \
|
||||||
xftFontMetrics.C
|
xftFontMetrics.C \
|
||||||
|
xftFontMetrics.h
|
||||||
|
@ -14,6 +14,8 @@
|
|||||||
|
|
||||||
#include "frontends/FontLoader.h"
|
#include "frontends/FontLoader.h"
|
||||||
|
|
||||||
|
#include "xftFontMetrics.h"
|
||||||
|
|
||||||
#include "lyxfont.h"
|
#include "lyxfont.h"
|
||||||
|
|
||||||
#include <gtkmm.h>
|
#include <gtkmm.h>
|
||||||
@ -34,6 +36,15 @@ public:
|
|||||||
virtual void update();
|
virtual void update();
|
||||||
|
|
||||||
virtual bool available(LyXFont const & f);
|
virtual bool available(LyXFont const & f);
|
||||||
|
virtual lyx::frontend::FontMetrics const & metrics(LyXFont const & f)
|
||||||
|
{
|
||||||
|
if (f.realShape() != LyXFont::SMALLCAPS_SHAPE)
|
||||||
|
return font_metrics(load(f.family(), f.series(), f.realShape(), f.size()), 0);
|
||||||
|
LyXFont scf(f);
|
||||||
|
scf.decSize().decSize().setShape(LyXFont::UP_SHAPE);
|
||||||
|
return font_metrics(load(f.family(), f.series(), f.realShape(), f.size()),
|
||||||
|
load(scf.family(), scf.series(), scf.realShape(), scf.size()));
|
||||||
|
}
|
||||||
|
|
||||||
/// Load font
|
/// Load font
|
||||||
XftFont * load(LyXFont::FONT_FAMILY family,
|
XftFont * load(LyXFont::FONT_FAMILY family,
|
||||||
|
@ -18,9 +18,10 @@
|
|||||||
#undef _GLIBCPP_CONCEPT_CHECKS
|
#undef _GLIBCPP_CONCEPT_CHECKS
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include "xftFontMetrics.h"
|
||||||
|
|
||||||
#include "GtkmmX.h"
|
#include "GtkmmX.h"
|
||||||
#include "xftFontLoader.h"
|
#include "xftFontLoader.h"
|
||||||
#include "font_metrics.h"
|
|
||||||
#include "lyxrc.h"
|
#include "lyxrc.h"
|
||||||
#include "encoding.h"
|
#include "encoding.h"
|
||||||
#include "language.h"
|
#include "language.h"
|
||||||
@ -43,13 +44,6 @@ using std::string;
|
|||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
|
||||||
inline XftFont * getXftFont(LyXFont const & f)
|
|
||||||
{
|
|
||||||
return fontLoader.load(f.family(), f.series(),
|
|
||||||
f.realShape(), f.size());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
inline int XGlyphAscent(XGlyphInfo const & info)
|
inline int XGlyphAscent(XGlyphInfo const & info)
|
||||||
{
|
{
|
||||||
return info.y;
|
return info.y;
|
||||||
@ -82,23 +76,26 @@ inline int XGlyphLogWidth(XGlyphInfo const & info)
|
|||||||
} // namespace anon
|
} // 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;
|
return font->ascent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int font_metrics::maxDescent(LyXFont const & f)
|
int font_metrics::maxDescent() const
|
||||||
{
|
{
|
||||||
XftFont * font = getXftFont(f);
|
|
||||||
return font->descent;
|
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;
|
XGlyphInfo glyph;
|
||||||
XftTextExtents32(getDisplay(), font,
|
XftTextExtents32(getDisplay(), font,
|
||||||
reinterpret_cast<FcChar32 *>(&c),
|
reinterpret_cast<FcChar32 *>(&c),
|
||||||
@ -108,9 +105,8 @@ int font_metrics::ascent(char_type c,LyXFont const & f)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int font_metrics::descent(char_type c,LyXFont const & f)
|
int font_metrics::descent(char_type c) const
|
||||||
{
|
{
|
||||||
XftFont * font = getXftFont(f);
|
|
||||||
XGlyphInfo glyph;
|
XGlyphInfo glyph;
|
||||||
XftTextExtents32(getDisplay(), font,
|
XftTextExtents32(getDisplay(), font,
|
||||||
reinterpret_cast<FcChar32 *>(&c),
|
reinterpret_cast<FcChar32 *>(&c),
|
||||||
@ -120,9 +116,8 @@ int font_metrics::descent(char_type c,LyXFont const & f)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int font_metrics::lbearing(char_type c,LyXFont const & f)
|
int font_metrics::lbearing(char_type c) const
|
||||||
{
|
{
|
||||||
XftFont * font = getXftFont(f);
|
|
||||||
XGlyphInfo glyph;
|
XGlyphInfo glyph;
|
||||||
XftTextExtents32(getDisplay(), font,
|
XftTextExtents32(getDisplay(), font,
|
||||||
reinterpret_cast<FcChar32 *>(&c),
|
reinterpret_cast<FcChar32 *>(&c),
|
||||||
@ -132,9 +127,8 @@ int font_metrics::lbearing(char_type c,LyXFont const & f)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int font_metrics::rbearing(char_type c,LyXFont const & f)
|
int font_metrics::rbearing(char_type c) const
|
||||||
{
|
{
|
||||||
XftFont * font = getXftFont(f);
|
|
||||||
XGlyphInfo glyph;
|
XGlyphInfo glyph;
|
||||||
XftTextExtents32(getDisplay(), font,
|
XftTextExtents32(getDisplay(), font,
|
||||||
reinterpret_cast<FcChar32 *>(&c),
|
reinterpret_cast<FcChar32 *>(&c),
|
||||||
@ -144,11 +138,10 @@ int font_metrics::rbearing(char_type c,LyXFont const & f)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
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;
|
XGlyphInfo glyph;
|
||||||
if (f.realShape() != LyXFont::SMALLCAPS_SHAPE){
|
if (!fontS){
|
||||||
XftTextExtents32(getDisplay(),
|
XftTextExtents32(getDisplay(),
|
||||||
font,
|
font,
|
||||||
reinterpret_cast<FcChar32 const *>(s),
|
reinterpret_cast<FcChar32 const *>(s),
|
||||||
@ -157,9 +150,6 @@ int font_metrics::width(char_type const * s, size_t n, LyXFont const & f)
|
|||||||
return XGlyphLogWidth(glyph);
|
return XGlyphLogWidth(glyph);
|
||||||
} else {
|
} else {
|
||||||
int result = 0;
|
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) {
|
for (size_t i = 0; i < n; ++i) {
|
||||||
char_type c = lyx::support::uppercase(s[i]);
|
char_type c = lyx::support::uppercase(s[i]);
|
||||||
if (c != s[i]) {
|
if (c != s[i]) {
|
||||||
@ -183,37 +173,37 @@ int font_metrics::width(char_type const * s, size_t n, LyXFont const & f)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int font_metrics::signedWidth(docstring const & s, LyXFont const & f)
|
int font_metrics::signedWidth(docstring const & s) const
|
||||||
{
|
{
|
||||||
if (s.empty())
|
if (s.empty())
|
||||||
return 0;
|
return 0;
|
||||||
if (s[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
|
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 & width,
|
||||||
int & ascent,
|
int & ascent,
|
||||||
int & descent)
|
int & descent) const
|
||||||
{
|
{
|
||||||
static int const d = 2;
|
static int const d = 2;
|
||||||
width = font_metrics::width(str, font) + d * 2 + 2;
|
width = font_metrics::width(str.c_str(), str.length()) + d * 2 + 2;
|
||||||
ascent = font_metrics::maxAscent(font) + d;
|
ascent = font_metrics::maxAscent() + d;
|
||||||
descent = font_metrics::maxDescent(font) + 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 & width,
|
||||||
int & ascent,
|
int & ascent,
|
||||||
int & descent)
|
int & descent) const
|
||||||
{
|
{
|
||||||
static int const d = 3;
|
static int const d = 3;
|
||||||
|
|
||||||
width = font_metrics::width(str, font) + d * 2 + 2;
|
width = font_metrics::width(str.c_str(), str.length()) + d * 2 + 2;
|
||||||
ascent = font_metrics::maxAscent(font) + d;
|
ascent = font_metrics::maxAscent() + d;
|
||||||
descent = font_metrics::maxDescent(font) + d;
|
descent = font_metrics::maxDescent() + d;
|
||||||
}
|
}
|
||||||
|
48
src/frontends/gtk/xftFontMetrics.h
Normal file
48
src/frontends/gtk/xftFontMetrics.h
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
// -*- 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
|
Loading…
Reference in New Issue
Block a user