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"
|
|
|
|
|
|
|
|
#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);
|
|
|
|
GuiFontMetrics(QFont const & font, QFont const & smallcaps_font);
|
|
|
|
|
|
|
|
virtual ~GuiFontMetrics() {}
|
|
|
|
|
|
|
|
virtual int maxAscent() const;
|
|
|
|
virtual int maxDescent() const;
|
2006-12-04 10:09:22 +00:00
|
|
|
virtual Dimension const defaultDimension() 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;
|
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:
|
2007-05-31 12:48:42 +00:00
|
|
|
int smallcapsWidth(char_type c) const;
|
2006-10-07 16:15:06 +00:00
|
|
|
|
|
|
|
/// Metrics on the font
|
|
|
|
QFontMetrics metrics_;
|
|
|
|
QFontMetrics smallcaps_metrics_;
|
|
|
|
|
|
|
|
bool smallcaps_shape_;
|
|
|
|
|
|
|
|
/// Cache of char widths
|
2006-12-02 15:54:49 +00:00
|
|
|
mutable QHash<char_type, int> width_cache_;
|
|
|
|
|
|
|
|
struct AscendDescend {
|
|
|
|
short int ascent;
|
|
|
|
short int descent;
|
|
|
|
};
|
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
|