2006-10-07 16:15:06 +00:00
|
|
|
// -*- C++ -*-
|
|
|
|
/**
|
2007-08-31 22:16:11 +00:00
|
|
|
* \file GuiFontMetrics.h
|
2006-10-07 16:15:06 +00:00
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2007-08-31 22:16:11 +00:00
|
|
|
#ifndef GUI_FONT_METRICS_H
|
|
|
|
#define GUI_FONT_METRICS_H
|
2006-10-07 16:15:06 +00:00
|
|
|
|
|
|
|
#include "frontends/FontMetrics.h"
|
|
|
|
|
|
|
|
#include "support/docstring.h"
|
|
|
|
|
2013-06-25 06:18:25 +00:00
|
|
|
#include <map>
|
|
|
|
|
2014-05-14 15:46:43 +00:00
|
|
|
#include <QFont>
|
2006-10-07 16:15:06 +00:00
|
|
|
#include <QFontMetrics>
|
2006-12-02 15:54:49 +00:00
|
|
|
#include <QHash>
|
2006-10-07 16:15:06 +00:00
|
|
|
|
|
|
|
namespace lyx {
|
|
|
|
namespace frontend {
|
|
|
|
|
2007-08-31 22:16:11 +00:00
|
|
|
class GuiFontMetrics : public FontMetrics
|
2006-10-07 16:15:06 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
GuiFontMetrics(QFont const & font);
|
|
|
|
|
|
|
|
virtual ~GuiFontMetrics() {}
|
|
|
|
|
|
|
|
virtual int maxAscent() const;
|
|
|
|
virtual int maxDescent() const;
|
2006-12-04 10:09:22 +00:00
|
|
|
virtual Dimension const defaultDimension() const;
|
2015-03-26 15:55:19 +00:00
|
|
|
virtual int em() const;
|
2006-12-01 16:12:24 +00:00
|
|
|
virtual int width(char_type c) const;
|
|
|
|
virtual int ascent(char_type c) const;
|
|
|
|
virtual int descent(char_type c) const;
|
|
|
|
virtual int lbearing(char_type c) const;
|
|
|
|
virtual int rbearing(char_type c) const;
|
2007-02-26 15:13:08 +00:00
|
|
|
virtual int width(docstring const & s) const;
|
2006-12-01 16:12:24 +00:00
|
|
|
virtual int signedWidth(docstring const & s) const;
|
2015-07-18 23:22:10 +00:00
|
|
|
virtual int pos2x(docstring const & s, int pos, bool rtl, double ws) const;
|
|
|
|
virtual int x2pos(docstring const & s, int & x, bool rtl, double ws) const;
|
2015-07-18 23:22:10 +00:00
|
|
|
virtual bool breakAt(docstring & s, int & x, bool rtl, bool force) const;
|
2006-12-04 10:09:22 +00:00
|
|
|
virtual Dimension const dimension(char_type c) const;
|
|
|
|
|
2006-12-01 16:12:24 +00:00
|
|
|
virtual void rectText(docstring const & str,
|
2006-10-07 16:15:06 +00:00
|
|
|
int & width,
|
|
|
|
int & ascent,
|
|
|
|
int & descent) const;
|
2006-12-01 16:12:24 +00:00
|
|
|
virtual void buttonText(docstring const & str,
|
2006-10-07 16:15:06 +00:00
|
|
|
int & width,
|
|
|
|
int & ascent,
|
|
|
|
int & descent) const;
|
2006-10-27 21:27:03 +00:00
|
|
|
///
|
|
|
|
int width(QString const & str) const;
|
2006-10-07 16:15:06 +00:00
|
|
|
|
|
|
|
private:
|
2014-05-14 15:46:43 +00:00
|
|
|
/// The font
|
|
|
|
QFont font_;
|
|
|
|
|
2006-10-07 16:15:06 +00:00
|
|
|
/// Metrics on the font
|
|
|
|
QFontMetrics metrics_;
|
|
|
|
|
|
|
|
/// Cache of char widths
|
2006-12-02 15:54:49 +00:00
|
|
|
mutable QHash<char_type, int> width_cache_;
|
|
|
|
|
2013-06-25 06:18:25 +00:00
|
|
|
/// Cache of string widths
|
|
|
|
/// FIXME Try to use a QHash (this requires to define qHash(docstring))
|
|
|
|
mutable std::map<docstring, int> strwidth_cache_;
|
|
|
|
|
2006-12-02 15:54:49 +00:00
|
|
|
struct AscendDescend {
|
2012-01-07 18:29:07 +00:00
|
|
|
int ascent;
|
|
|
|
int descent;
|
2006-12-02 15:54:49 +00:00
|
|
|
};
|
2006-12-02 21:55:28 +00:00
|
|
|
/// Cache of char ascends and descends
|
2006-12-02 15:54:49 +00:00
|
|
|
mutable QHash<char_type, AscendDescend> metrics_cache_;
|
|
|
|
/// fill in \c metrics_cache_ at specified value.
|
2007-08-13 13:56:54 +00:00
|
|
|
AscendDescend const fillMetricsCache(char_type) const;
|
2007-03-21 23:13:32 +00:00
|
|
|
|
|
|
|
/// Cache of char right bearings
|
|
|
|
mutable QHash<char_type, int> rbearing_cache_;
|
2006-10-07 16:15:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace frontend
|
|
|
|
} // namespace lyx
|
|
|
|
|
2007-08-31 22:16:11 +00:00
|
|
|
#endif // GUI_FONT_METRICS_H
|