2002-06-19 03:38:44 +00:00
|
|
|
// -*- C++ -*-
|
|
|
|
/**
|
|
|
|
* \file qfont_loader.h
|
2002-09-24 13:57:09 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
2002-06-19 03:38:44 +00:00
|
|
|
*
|
2002-09-24 13:57:09 +00:00
|
|
|
* \author John Levon
|
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
* Full author contact details are available in file CREDITS.
|
2002-06-19 03:38:44 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef QFONTLOADER_H
|
2002-09-24 13:57:09 +00:00
|
|
|
#define QFONTLOADER_H
|
2002-06-19 03:38:44 +00:00
|
|
|
|
|
|
|
|
2002-12-11 00:22:37 +00:00
|
|
|
#include <map>
|
2003-02-25 13:35:26 +00:00
|
|
|
|
2002-12-11 00:22:37 +00:00
|
|
|
#include "encoding.h"
|
2002-06-19 03:38:44 +00:00
|
|
|
#include "lyxfont.h"
|
|
|
|
|
|
|
|
#include <qfont.h>
|
|
|
|
#include <qfontmetrics.h>
|
2003-02-25 13:35:26 +00:00
|
|
|
|
2002-06-19 03:38:44 +00:00
|
|
|
/**
|
|
|
|
* Qt font loader for LyX. Matches LyXFonts against
|
|
|
|
* actual QFont instances, and also caches metrics.
|
|
|
|
*/
|
|
|
|
class qfont_loader {
|
|
|
|
public:
|
|
|
|
qfont_loader();
|
|
|
|
|
2002-07-12 03:05:13 +00:00
|
|
|
~qfont_loader();
|
2002-06-19 03:38:44 +00:00
|
|
|
|
|
|
|
/// update fonts after zoom, dpi, font names, or norm change
|
2002-07-12 03:05:13 +00:00
|
|
|
void update();
|
2002-06-19 03:38:44 +00:00
|
|
|
|
|
|
|
/// do we have anything matching?
|
2002-07-12 03:05:13 +00:00
|
|
|
bool available(LyXFont const & f);
|
2002-09-24 13:57:09 +00:00
|
|
|
|
2002-06-19 03:38:44 +00:00
|
|
|
/// get the QFont for this LyXFont
|
2002-09-07 19:51:58 +00:00
|
|
|
QFont const & get(LyXFont const & f);
|
2002-06-19 03:38:44 +00:00
|
|
|
|
|
|
|
/// get the QFont metrics for this LyXFont
|
|
|
|
QFontMetrics const & metrics(LyXFont const & f) {
|
|
|
|
return getfontinfo(f)->metrics;
|
|
|
|
}
|
2002-12-11 00:22:37 +00:00
|
|
|
|
|
|
|
/// return pixel width for the given unicode char
|
|
|
|
int charwidth(LyXFont const & f, Uchar val);
|
|
|
|
|
2002-06-19 03:38:44 +00:00
|
|
|
private:
|
|
|
|
/// hold info about a particular font
|
|
|
|
struct font_info {
|
|
|
|
font_info(LyXFont const & f);
|
|
|
|
|
|
|
|
/// the font instance
|
|
|
|
QFont font;
|
|
|
|
/// metrics on the font
|
|
|
|
QFontMetrics metrics;
|
2002-12-11 00:22:37 +00:00
|
|
|
|
|
|
|
typedef std::map<Uchar, int> WidthCache;
|
2003-02-25 13:35:26 +00:00
|
|
|
/// cache of char widths
|
2002-12-11 00:22:37 +00:00
|
|
|
WidthCache widthcache;
|
2002-06-19 03:38:44 +00:00
|
|
|
};
|
2002-09-24 13:57:09 +00:00
|
|
|
|
2002-06-19 03:38:44 +00:00
|
|
|
/// get font info (font + metrics) for the given LyX font. Does not fail.
|
2002-12-11 00:22:37 +00:00
|
|
|
font_info * getfontinfo(LyXFont const & f);
|
2002-09-24 13:57:09 +00:00
|
|
|
|
2002-06-19 03:38:44 +00:00
|
|
|
/// BUTT ugly !
|
2002-12-11 00:22:37 +00:00
|
|
|
font_info * fontinfo_[LyXFont::NUM_FAMILIES][2][4][10];
|
2002-06-19 03:38:44 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
extern qfont_loader fontloader;
|
2002-09-24 13:57:09 +00:00
|
|
|
|
2002-06-19 03:38:44 +00:00
|
|
|
#endif // QFONT_LOADER_H
|