2006-03-05 17:24:44 +00:00
|
|
|
// -*- C++ -*-
|
|
|
|
/**
|
2006-10-03 16:17:32 +00:00
|
|
|
* \file GuiFontLoader.h
|
2006-03-05 17:24:44 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
|
|
|
* \author John Levon
|
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
*/
|
|
|
|
|
2006-10-03 16:17:32 +00:00
|
|
|
#ifndef QT4_FONTLOADER_H
|
|
|
|
#define QT4_FONTLOADER_H
|
|
|
|
|
|
|
|
#include "frontends/FontLoader.h"
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2007-10-28 18:51:54 +00:00
|
|
|
#include "FontInfo.h"
|
|
|
|
|
2006-10-07 16:15:06 +00:00
|
|
|
#include "GuiFontMetrics.h"
|
|
|
|
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "Encoding.h"
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
#include <QFont>
|
|
|
|
|
2007-11-02 16:43:24 +00:00
|
|
|
#include <boost/assert.hpp>
|
2007-10-25 12:41:02 +00:00
|
|
|
|
2006-10-03 16:17:32 +00:00
|
|
|
namespace lyx {
|
|
|
|
namespace frontend {
|
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
/**
|
2007-04-29 18:17:15 +00:00
|
|
|
* Qt font loader for LyX. Matches Fonts against
|
2006-03-05 17:24:44 +00:00
|
|
|
* actual QFont instances, and also caches metrics.
|
|
|
|
*/
|
2007-09-15 22:56:09 +00:00
|
|
|
class GuiFontInfo
|
2007-09-05 20:33:29 +00:00
|
|
|
{
|
2006-03-05 17:24:44 +00:00
|
|
|
public:
|
2007-10-28 18:51:54 +00:00
|
|
|
GuiFontInfo(FontInfo const & f);
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
/// The font instance
|
|
|
|
QFont font;
|
|
|
|
/// Metrics on the font
|
2007-11-29 22:38:53 +00:00
|
|
|
GuiFontMetrics metrics;
|
2006-03-05 17:24:44 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/// Hold info about a particular font
|
2007-05-28 22:27:45 +00:00
|
|
|
class GuiFontLoader : public FontLoader
|
2006-10-03 16:17:32 +00:00
|
|
|
{
|
2006-03-05 17:24:44 +00:00
|
|
|
public:
|
|
|
|
///
|
2006-10-03 16:17:32 +00:00
|
|
|
GuiFontLoader();
|
2007-05-28 22:27:45 +00:00
|
|
|
|
2006-05-20 08:21:58 +00:00
|
|
|
/// Destructor
|
2007-09-12 19:07:22 +00:00
|
|
|
virtual ~GuiFontLoader() {}
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2006-10-03 16:17:32 +00:00
|
|
|
virtual void update();
|
2007-10-28 18:51:54 +00:00
|
|
|
virtual bool available(FontInfo const & f);
|
|
|
|
inline virtual FontMetrics const & metrics(FontInfo const & f) {
|
2007-11-29 22:38:53 +00:00
|
|
|
return fontinfo(f).metrics;
|
2006-10-07 16:15:06 +00:00
|
|
|
}
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2007-10-28 18:51:54 +00:00
|
|
|
/// Get the QFont for this FontInfo
|
|
|
|
QFont const & get(FontInfo const & f) {
|
2006-03-05 17:24:44 +00:00
|
|
|
return fontinfo(f).font;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-04-05 23:56:29 +00:00
|
|
|
/// Get font info (font + metrics) for the given LyX font.
|
2007-10-28 18:51:54 +00:00
|
|
|
GuiFontInfo & fontinfo(FontInfo const & f) {
|
2007-11-02 16:43:24 +00:00
|
|
|
BOOST_ASSERT(f.family() < NUM_FAMILIES);
|
|
|
|
BOOST_ASSERT(f.series() < 2);
|
|
|
|
BOOST_ASSERT(f.realShape() < 4);
|
|
|
|
BOOST_ASSERT(f.size() < 10);
|
2007-09-15 22:56:09 +00:00
|
|
|
// fi is a reference to the pointer type (GuiFontInfo *) in the
|
2006-05-25 10:02:01 +00:00
|
|
|
// fontinfo_ table.
|
2007-09-15 22:56:09 +00:00
|
|
|
GuiFontInfo * & fi =
|
2006-03-05 17:24:44 +00:00
|
|
|
fontinfo_[f.family()][f.series()][f.realShape()][f.size()];
|
2006-05-25 10:02:01 +00:00
|
|
|
if (!fi)
|
2007-09-15 22:56:09 +00:00
|
|
|
fi = new GuiFontInfo(f);
|
2006-03-05 17:24:44 +00:00
|
|
|
return *fi;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
/// BUTT ugly !
|
2007-10-28 18:51:54 +00:00
|
|
|
GuiFontInfo * fontinfo_[NUM_FAMILIES][2][4][10];
|
2006-03-05 17:24:44 +00:00
|
|
|
};
|
|
|
|
|
2006-10-03 16:17:32 +00:00
|
|
|
|
|
|
|
} // namespace frontend
|
|
|
|
} // namespace lyx
|
|
|
|
|
|
|
|
#endif // QT4_FONTLOADER_H
|