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
|
|
|
|
2005-06-21 13:10:59 +00:00
|
|
|
#include "encoding.h"
|
|
|
|
#include "lyxfont.h"
|
|
|
|
|
|
|
|
#include <qfont.h>
|
|
|
|
#include <qfontmetrics.h>
|
|
|
|
|
2005-06-10 14:53:42 +00:00
|
|
|
#if QT_VERSION < 0x030100
|
|
|
|
#define USE_LYX_FONTCACHE
|
|
|
|
#endif
|
2002-06-19 03:38:44 +00:00
|
|
|
|
2005-06-10 14:53:42 +00:00
|
|
|
#if defined(USE_LYX_FONTCACHE)
|
2002-12-11 00:22:37 +00:00
|
|
|
#include <map>
|
2005-06-10 14:53:42 +00:00
|
|
|
#endif
|
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.
|
|
|
|
*/
|
2005-07-17 23:03:01 +00:00
|
|
|
class QLFontInfo {
|
2002-06-19 03:38:44 +00:00
|
|
|
public:
|
2005-07-17 23:03:01 +00:00
|
|
|
QLFontInfo(LyXFont const & f);
|
2005-07-16 14:53:18 +00:00
|
|
|
|
2005-07-16 18:25:58 +00:00
|
|
|
/// Return pixel width for the given unicode char
|
2005-07-16 15:43:33 +00:00
|
|
|
int width(Uchar val) const;
|
2005-07-16 14:53:18 +00:00
|
|
|
|
2005-07-16 18:25:58 +00:00
|
|
|
/// The font instance
|
2005-07-16 15:43:33 +00:00
|
|
|
QFont font;
|
2005-07-16 18:25:58 +00:00
|
|
|
/// Metrics on the font
|
2005-07-16 15:43:33 +00:00
|
|
|
QFontMetrics metrics;
|
2005-07-16 14:53:18 +00:00
|
|
|
|
|
|
|
#if defined(USE_LYX_FONTCACHE)
|
2005-07-16 15:43:33 +00:00
|
|
|
typedef std::map<Uchar, int> WidthCache;
|
2005-07-16 18:25:58 +00:00
|
|
|
/// Cache of char widths
|
2005-07-16 15:43:33 +00:00
|
|
|
WidthCache widthcache;
|
2005-07-16 14:53:18 +00:00
|
|
|
#endif
|
2005-07-16 15:43:33 +00:00
|
|
|
};
|
2005-07-16 14:53:18 +00:00
|
|
|
|
2002-06-19 03:38:44 +00:00
|
|
|
|
2005-07-16 18:25:58 +00:00
|
|
|
/// Hold info about a particular font
|
2005-07-16 15:43:33 +00:00
|
|
|
class FontLoader {
|
|
|
|
public:
|
|
|
|
///
|
|
|
|
FontLoader();
|
2002-06-19 03:38:44 +00:00
|
|
|
|
2005-07-16 18:25:58 +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
|
|
|
|
2005-07-16 18:25:58 +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
|
|
|
|
2005-07-16 18:25:58 +00:00
|
|
|
/// Get the QFont for this LyXFont
|
2005-07-16 15:43:33 +00:00
|
|
|
QFont const & get(LyXFont const & f) {
|
|
|
|
return fontinfo(f).font;
|
|
|
|
}
|
2002-06-19 03:38:44 +00:00
|
|
|
|
2005-07-16 18:25:58 +00:00
|
|
|
/// Get the QFont metrics for this LyXFont
|
2002-06-19 03:38:44 +00:00
|
|
|
QFontMetrics const & metrics(LyXFont const & f) {
|
2005-07-16 15:43:33 +00:00
|
|
|
return fontinfo(f).metrics;
|
2002-06-19 03:38:44 +00:00
|
|
|
}
|
2002-12-11 00:22:37 +00:00
|
|
|
|
2004-10-13 16:14:57 +00:00
|
|
|
/// Called before QApplication is initialized
|
|
|
|
static void initFontPath();
|
2004-10-26 21:16:44 +00:00
|
|
|
|
2004-10-13 16:14:57 +00:00
|
|
|
/// Called the first time when available() can't load a symbol font
|
|
|
|
static void addToFontPath();
|
|
|
|
|
2005-07-16 18:25:58 +00:00
|
|
|
/// Get font info (font + metrics) for the given LyX font.
|
2005-07-17 23:03:01 +00:00
|
|
|
QLFontInfo & fontinfo(LyXFont const & f) {
|
|
|
|
QLFontInfo * & fi =
|
2005-07-16 16:13:08 +00:00
|
|
|
fontinfo_[f.family()][f.series()][f.realShape()][f.size()];
|
|
|
|
if (!fi)
|
2005-07-17 23:03:01 +00:00
|
|
|
fi = new QLFontInfo(f);
|
2005-07-16 16:13:08 +00:00
|
|
|
return *fi;
|
|
|
|
}
|
2002-09-24 13:57:09 +00:00
|
|
|
|
2005-07-16 14:53:18 +00:00
|
|
|
private:
|
2002-06-19 03:38:44 +00:00
|
|
|
/// BUTT ugly !
|
2005-07-17 23:03:01 +00:00
|
|
|
QLFontInfo * fontinfo_[LyXFont::NUM_FAMILIES][2][4][10];
|
2002-06-19 03:38:44 +00:00
|
|
|
};
|
|
|
|
|
2005-07-16 15:43:33 +00:00
|
|
|
extern FontLoader fontloader;
|
2002-09-24 13:57:09 +00:00
|
|
|
|
2002-06-19 03:38:44 +00:00
|
|
|
#endif // QFONT_LOADER_H
|