mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-11 13:46:43 +00:00
00edcc582f
Basically, I replaced all methods in the font_metrics namespace by a proper virtual interface FontMetrics. The FontLoader is _the_ container for FontMetrics. This patch should also bring some optimizations in a number of place in the code. This is because we do not need any more to search for the LyXFont at each font_metrics call. In effect, the speed advantage is not as sensible and this is a bit deceiving considering that this was my primary motivation behind the patch. But I like the patch anyway as it cleans up the relation and interfacing between fonts, metrics and frontends. * frontends/FontMetrics.h: new virtual interface. Renamed from font_metrics.h * qt4/GuiFontMetrics: corresponding qt4 implememtation. Renamed from qfont_metrics.C. The smallCaps particular case treatment has been transfered here as well as the width cache for MacOSX and Windows. * qt4/QLPainter.C: the smallCapsText has been reworked to return the width of the drawn text.C all other files: replace font_metric helper function call with corresponding FontMetrics method calls. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@15265 a592a061-630c-0410-9148-cb99ea01b6c8
84 lines
2.0 KiB
C++
84 lines
2.0 KiB
C++
// -*- C++ -*-
|
|
/**
|
|
* \file FontMetrics.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 QT4_FONT_METRICS_H
|
|
#define QT4_FONT_METRICS_H
|
|
|
|
#include "frontends/FontMetrics.h"
|
|
|
|
#include "support/docstring.h"
|
|
|
|
#include <QFontMetrics>
|
|
|
|
// Starting with version 3.1.0, Qt/X11 does its own caching of
|
|
// character width, so it is not necessary to provide ours.
|
|
#if defined(Q_WS_MACX) || defined(Q_WS_WIN32)
|
|
#define USE_LYX_FONTCACHE
|
|
#include <map>
|
|
#endif
|
|
|
|
namespace lyx {
|
|
namespace frontend {
|
|
|
|
class GuiFontMetrics: public FontMetrics
|
|
{
|
|
public:
|
|
|
|
GuiFontMetrics(QFont const & font);
|
|
GuiFontMetrics(QFont const & font, QFont const & smallcaps_font);
|
|
|
|
virtual ~GuiFontMetrics() {}
|
|
|
|
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:
|
|
int smallcapsWidth(QString const & s) const;
|
|
|
|
/// Metrics on the font
|
|
QFontMetrics metrics_;
|
|
QFontMetrics smallcaps_metrics_;
|
|
|
|
bool smallcaps_shape_;
|
|
|
|
#ifndef USE_LYX_FONTCACHE
|
|
/// Return pixel width for the given unicode char
|
|
int width(unsigned short val) const { return metrics_.width(QChar(val)); }
|
|
|
|
#else
|
|
/// Return pixel width for the given unicode char
|
|
int width(unsigned short val) const;
|
|
|
|
typedef std::map<unsigned short, int> WidthCache;
|
|
/// Cache of char widths
|
|
mutable WidthCache widthcache;
|
|
#endif // USE_LYX_FONTCACHE
|
|
};
|
|
|
|
} // namespace frontend
|
|
} // namespace lyx
|
|
|
|
#endif // QT4_FONT_METRICS_H
|