#include "FontLoader.h"
#include "FontInfo.h"
-#include "GuiFontLoader.h"
+#include "GuiFontMetrics.h"
#include "qt_helpers.h"
#include "LyXRC.h"
namespace frontend {
+/**
+ * Matches Fonts against
+ * actual QFont instances, and also caches metrics.
+ */
+class GuiFontInfo
+{
+public:
+ GuiFontInfo(FontInfo const & f);
+
+ /// The font instance
+ QFont font;
+ /// Metrics on the font
+ GuiFontMetrics metrics;
+};
+
namespace {
struct SymbolFont {
// A simple setFamily() fails on Qt 2
- QString const rawName = rawName(family);
- LYXERR(Debug::FONT, "Trying " << fromqstr(rawName) << " ... ");
- font.setRawName(rawName);
+ QString const raw = rawName(family);
+ LYXERR(Debug::FONT, "Trying " << fromqstr(raw) << " ... ");
+ font.setRawName(raw);
if (isChosenFont(font, family)) {
LYXERR(Debug::FONT, "raw version!");
return true;
}
+
FontMetrics const & FontLoader::metrics(FontInfo const & f)
{
return fontinfo(f).metrics;
}
-/// Get the QFont for this FontInfo
-QFont const & getFont(FontInfo const & f)
+
+GuiFontMetrics const & getFontMetrics(FontInfo const & f)
{
- return fontinfo(f).font;
+ return fontinfo(f).metrics;
}
-/// Get the QFont for this FontInfo
-GuiFontInfo const & getFontInfo(FontInfo const & f)
+
+QFont const & getFont(FontInfo const & f)
{
- return fontinfo(f);
+ return fontinfo(f).font;
}
} // namespace frontend
#ifndef GUI_FONTLOADER_H
#define GUI_FONTLOADER_H
-#include "GuiFontMetrics.h"
-
-#include <QFont>
+class QFont;
namespace lyx {
namespace frontend {
-/**
- * Qt font loader for LyX. Matches Fonts against
- * actual QFont instances, and also caches metrics.
- */
-class GuiFontInfo
-{
-public:
- GuiFontInfo(FontInfo const & f);
-
- /// The font instance
- QFont font;
- /// Metrics on the font
- GuiFontMetrics metrics;
-};
-
+class GuiFontMetrics;
-// Load font
-GuiFontInfo const & getFontInfo(FontInfo const & f);
+/// Metrics on the font
+GuiFontMetrics const & getFontMetrics(FontInfo const & f);
/// Get the QFont for this FontInfo
QFont const & getFont(FontInfo const & f);
str = ' ' + str;
#endif
- GuiFontInfo const & fi = getFontInfo(f);
+ QFont const & ff = getFont(f);
+ GuiFontMetrics const & fm = getFontMetrics(f);
int textwidth;
// Here we use the font width cache instead of
// textwidth = fontMetrics().width(str);
// because the above is awfully expensive on MacOSX
- textwidth = fi.metrics.width(s);
+ textwidth = fm.width(s);
if (f.underbar() == FONT_ON)
underline(f, x, y, textwidth);
if (s.size() == 1 && str[0].unicode() == 0x00ad) {
setQPainterPen(computeColor(f.realColor()));
QTextLayout adsymbol(str);
- adsymbol.setFont(fi.font);
+ adsymbol.setFont(ff);
adsymbol.beginLayout();
QTextLine line = adsymbol.createLine();
line.setNumColumns(1);
// don't use the pixmap cache,
// draw directly onto the painting device
setQPainterPen(computeColor(f.realColor()));
- if (font() != fi.font)
- setFont(fi.font);
+ if (font() != ff)
+ setFont(ff);
// We need to draw the text as LTR as we use our own bidi code.
setLayoutDirection(Qt::LeftToRight);
drawText(x, y, str);
// Only the left bearing of the first character is important
// as we always write from left to right, even for
// right-to-left languages.
- int const lb = min(fi.metrics.lbearing(s[0]), 0);
- int const mA = fi.metrics.maxAscent();
+ int const lb = min(fm.lbearing(s[0]), 0);
+ int const mA = fm.maxAscent();
if (!QPixmapCache::find(key, pm)) {
// Only the right bearing of the last character is
// important as we always write from left to right,
// even for right-to-left languages.
- int const rb = fi.metrics.rbearing(s[s.size()-1]);
+ int const rb = fm.rbearing(s[s.size()-1]);
int const w = textwidth + rb - lb;
- int const mD = fi.metrics.maxDescent();
+ int const mD = fm.maxDescent();
int const h = mA + mD;
pm = QPixmap(w, h);
pm.fill(Qt::transparent);
GuiPainter p(&pm);
p.setQPainterPen(computeColor(f.realColor()));
- if (p.font() != fi.font)
- p.setFont(fi.font);
+ if (p.font() != ff)
+ p.setFont(ff);
// We need to draw the text as LTR as we use our own bidi code.
p.setLayoutDirection(Qt::LeftToRight);
p.drawText(-lb, mA, str);