Dialogs.h
FileDialog.h
FontLoader.h
+ FontMetrics.h
Gui.h
LyXKeySym.h
LyXKeySymFactory.h
Timeout.h
Toolbars.h
WorkArea.h
- font_metrics.h
guiapi.h
key_state.h
lyx_gui.h
GuiApplication.C
GuiClipboard.C
GuiFontLoader.C
+ GuiFontMetrics.C
GuiImplementation.C
GuiSelection.C
GuiView.C
lengthcombo.C
lyx_gui.C
panelstack.C
- qfont_metrics.C
qfontexample.C
qsetborder.C
qtTimeout.C
#include "frontends/Alert.h"
#include "frontends/Application.h"
#include "frontends/FileDialog.h"
-#include "frontends/font_metrics.h"
+#include "frontends/FontLoader.h"
+#include "frontends/FontMetrics.h"
#include "graphics/Previews.h"
bool BufferView::fitCursor()
{
if (bv_funcs::status(this, cursor_) == bv_funcs::CUR_INSIDE) {
- LyXFont const font = cursor_.getFont();
- int const asc = font_metrics::maxAscent(font);
- int const des = font_metrics::maxDescent(font);
+ lyx::frontend::FontMetrics const & fm
+ = theApp->fontLoader().metrics(cursor_.getFont());
+ int const asc = fm.maxAscent();
+ int const des = fm.maxDescent();
Point const p = bv_funcs::getPos(cursor_, cursor_.boundary());
if (p.y_ - asc >= 0 && p.y_ + des < height_)
return false;
#include "support/limited_stack.h"
#include "frontends/Application.h"
-#include "frontends/font_metrics.h"
#include <boost/assert.hpp>
#include <boost/bind.hpp>
#include <config.h>
#include "dimension.h"
-#include "frontends/font_metrics.h"
+#include "frontends/Application.h"
+#include "frontends/FontLoader.h"
+#include "frontends/FontMetrics.h"
void Dimension::operator+=(Dimension const & dim)
void Dimension::clear(LyXFont const & font)
{
- asc = font_metrics::maxAscent(font);
- des = font_metrics::maxDescent(font);
+ lyx::frontend::FontMetrics const & fm = theApp->fontLoader().metrics(font);
+ asc = fm.maxAscent();
+ des = fm.maxDescent();
wid = 0;
}
namespace lyx {
namespace frontend {
+class FontMetrics;
+
/// Hold info about a particular font
class FontLoader
{
/// Is the given font available ?
virtual bool available(LyXFont const & f) = 0;
+
+ /// Get the Font metrics for this LyXFont
+ virtual FontMetrics const & metrics(LyXFont const & f) = 0;
};
} // namespace frontend
--- /dev/null
+// -*- C++ -*-
+/**
+ * \file FontMetrics.h
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author unknown
+ * \author John Levon
+ * \author Abdelrazak Younes
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#ifndef FONT_METRICS_H
+#define FONT_METRICS_H
+
+#include "support/docstring.h"
+
+/**
+ * A class holding helper functions for determining
+ * the screen dimensions of fonts.
+ *
+ * The geometry is the standard typographical geometry,
+ * as follows :
+ *
+ * --------------+------------------<maxAscent
+ * | |
+ * <-------> (right bearing)
+ * <-> (left bearing)
+ * char ascent>___ |
+ * ^ oooo | oooo
+ * origin>____ | oo oo | oo oo
+ * \| oo oo | oo oo
+ * --------------+---ooooo--|--oooo-<baseline
+ * | oo |
+ * char | oo oo |
+ * descent>______| oooo |
+ * <- width ->
+ * --------------+----------+-------<maxDescent
+ *
+ */
+
+namespace lyx {
+namespace frontend {
+
+class FontMetrics
+{
+public:
+ virtual ~FontMetrics() {}
+
+ /// return the maximum ascent of the font
+ virtual int maxAscent() const = 0;
+ /// return the maximum descent of the font
+ virtual int maxDescent() const = 0;
+ /// return the ascent of the char in the font
+ virtual int ascent(lyx::char_type c) const = 0;
+ /// return the descent of the char in the font
+ virtual int descent(lyx::char_type c) const = 0;
+ /// return the left bearing of the char in the font
+ virtual int lbearing(lyx::char_type c) const = 0;
+ /// return the right bearing of the char in the font
+ virtual int rbearing(lyx::char_type c) const = 0;
+ /// return the width of the string in the font
+ virtual int width(lyx::char_type const * s, size_t n) const = 0;
+ /// FIXME ??
+ virtual int signedWidth(lyx::docstring const & s) const = 0;
+ /**
+ * fill in width,ascent,descent with the values for the
+ * given string in the font.
+ */
+ virtual void rectText(lyx::docstring const & str,
+ int & width,
+ int & ascent,
+ int & descent) const = 0;
+ /**
+ * fill in width,ascent,descent with the values for the
+ * given string in the font for a button.
+ */
+ virtual void buttonText(lyx::docstring const & str,
+ int & width,
+ int & ascent,
+ int & descent) const = 0;
+
+ /// return the maximum descent of the font
+ inline int maxHeight() const {
+ return maxAscent() + maxDescent();
+ }
+
+ /// return the descent of the char in the font
+ inline int height(lyx::char_type c) const
+ {
+ return ascent(c) + descent(c);
+ }
+
+ /// return the inner width of the char in the font
+ inline int center(lyx::char_type c) const {
+ return (rbearing(c) - lbearing(c)) / 2;
+ }
+
+ /// return the width of the char in the font
+ inline int width(lyx::char_type c) const
+ {
+ lyx::char_type tmp[2] = { c, L'\0'};
+ return width(tmp, 1);
+ }
+
+ /// return the width of the string in the font
+ inline int width(lyx::docstring const & s) const
+ {
+ return s.empty() ? 0 : width(s.data(), s.length());
+ }
+};
+
+} // namespace frontend
+} // namespace lyx
+
+#endif // FONT_METRICS_H
Dialogs.h \
FileDialog.h \
FontLoader.h \
+ FontMetrics.h \
LyXKeySym.h \
LyXKeySymFactory.h \
LyXView.C \
Selection.h \
WorkArea.C \
WorkArea.h \
- font_metrics.h \
guiapi.h \
guiapi.C \
key_state.h \
#include <config.h>
-#include "Painter.h"
-#include "font_metrics.h"
+#include "frontends/Painter.h"
+
+#include "frontends/Application.h"
+#include "frontends/FontLoader.h"
+#include "frontends/FontMetrics.h"
#include "LColor.h"
#include "lyxfont.h"
int ascent;
int descent;
- font_metrics::rectText(str, font, width, ascent, descent);
+ FontMetrics const & fm = theApp->fontLoader().metrics(font);
+ fm.rectText(str, width, ascent, descent);
if (back != LColor::none)
fillRectangle(x + 1, y - ascent + 1, width - 1,
int ascent;
int descent;
- font_metrics::buttonText(str, font, width, ascent, descent);
+ FontMetrics const & fm = theApp->fontLoader().metrics(font);
+ fm.buttonText(str, width, ascent, descent);
button(x, y - ascent, width, descent + ascent);
text(x + 4, y, str, font);
void Painter::underline(LyXFont const & f, int x, int y, int width)
{
- int const below = max(font_metrics::maxDescent(f) / 2, 2);
- int const height = max((font_metrics::maxDescent(f) / 4) - 1, 1);
+ FontMetrics const & fm = theApp->fontLoader().metrics(f);
+
+ int const below = max(fm.maxDescent() / 2, 2);
+ int const height = max((fm.maxDescent() / 4) - 1, 1);
if (height < 2)
line(x, y + below, x + width, y + below, f.color());
#include <config.h>
-#include "WorkArea.h"
+#include "frontends/WorkArea.h"
+
+#include "frontends/Application.h"
+#include "frontends/FontLoader.h"
+#include "frontends/FontMetrics.h"
-#include "font_metrics.h"
#include "funcrequest.h"
#include "lyx_gui.h"
#include "lyxfunc.h"
shape = BAR_SHAPE;
LyXFont const font = buffer_view_->cursor().getFont();
- int const asc = font_metrics::maxAscent(font);
- int const des = font_metrics::maxDescent(font);
+ FontMetrics const & fm = theApp->fontLoader().metrics(font);
+ int const asc = fm.maxAscent();
+ int const des = fm.maxDescent();
int h = asc + des;
int x = 0;
int y = 0;
+++ /dev/null
-// -*- C++ -*-
-/**
- * \file font_metrics.h
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author unknown
- * \author John Levon
- *
- * Full author contact details are available in file CREDITS.
- */
-
-#ifndef FONT_METRICS_H
-#define FONT_METRICS_H
-
-#include "support/docstring.h"
-
-
-class LyXFont;
-
-/**
- * A namespace holding helper functions for determining
- * the screen dimensions of fonts.
- *
- * The geometry is the standard typographical geometry,
- * as follows :
- *
- * --------------+------------------<maxAscent
- * | |
- * <-------> (right bearing)
- * <-> (left bearing)
- * char ascent>___ |
- * ^ oooo | oooo
- * origin>____ | oo oo | oo oo
- * \| oo oo | oo oo
- * --------------+---ooooo--|--oooo-<baseline
- * | oo |
- * char | oo oo |
- * descent>______| oooo |
- * <- width ->
- * --------------+----------+-------<maxDescent
- *
- */
-namespace font_metrics {
- /// return the maximum ascent of the font
- int maxAscent(LyXFont const & f);
- /// return the maximum descent of the font
- int maxDescent(LyXFont const & f);
- /// return the maximum descent of the font
- inline int maxHeight(LyXFont const & f) {
- return maxAscent(f) + maxDescent(f);
- }
- /// return the ascent of the char in the font
- int ascent(lyx::char_type c, LyXFont const & f);
- /// return the descent of the char in the font
- int descent(lyx::char_type c, LyXFont const & f);
- /// return the descent of the char in the font
- inline int height(lyx::char_type c, LyXFont const & f)
- {
- return ascent(c, f) + descent(c, f);
- }
- /// return the left bearing of the char in the font
- int lbearing(lyx::char_type c, LyXFont const & f);
- /// return the right bearing of the char in the font
- int rbearing(lyx::char_type c, LyXFont const & f);
- /// return the inner width of the char in the font
- inline int center(lyx::char_type c, LyXFont const & f) {
- return (rbearing(c, f) - lbearing(c, f)) / 2;
- }
- /// return the width of the string in the font
- int width(lyx::char_type const * s, size_t n, LyXFont const & f);
- /// return the width of the char in the font
- inline int width(lyx::char_type c, LyXFont const & f)
- {
- lyx::char_type tmp[2] = { c, L'\0'};
- return width(tmp, 1, f);
- }
- /// return the width of the string in the font
- inline int width(lyx::docstring const & s, LyXFont const & f)
- {
- return s.empty() ? 0 : width(s.data(), s.length(), f);
- }
- /// FIXME ??
- int signedWidth(lyx::docstring const & s, LyXFont const & f);
- /**
- * fill in width,ascent,descent with the values for the
- * given string in the font.
- */
- void rectText(lyx::docstring const & str, LyXFont const & font,
- int & width,
- int & ascent,
- int & descent);
- /**
- * fill in width,ascent,descent with the values for the
- * given string in the font for a button.
- */
- void buttonText(lyx::docstring const & str, LyXFont const & font,
- int & width,
- int & ascent,
- int & descent);
-}
-
-#endif // FONT_METRICS_H
QLFontInfo::QLFontInfo(LyXFont const & f)
- : metrics(font)
{
-
string const pat = symbolFamily(f.family());
if (!pat.empty()) {
bool tmp;
}
}
- font.setPointSizeF(convert<double>(lyxrc.font_sizes[f.size()])
- * lyxrc.zoom / 100.0);
-
switch (f.series()) {
case LyXFont::MEDIUM_SERIES:
font.setWeight(QFont::Normal);
<< "' matched by\n" << fromqstr(font.rawName()) << endl;
}
- lyxerr[Debug::FONT] << "The font has size: "
- << font.pointSizeF() << endl;
-
// Is this an exact match?
if (font.exactMatch())
lyxerr[Debug::FONT] << "This font is an exact match" << endl;
lyxerr[Debug::FONT] << "XFLD: " << fromqstr(font.rawName()) << endl;
- metrics = QFontMetrics(font);
-}
+ font.setPointSizeF(convert<double>(lyxrc.font_sizes[f.size()])
+ * lyxrc.zoom / 100.0);
-#ifdef USE_LYX_FONTCACHE
-int QLFontInfo::width(Uchar val)
-{
- QLFontInfo::WidthCache::const_iterator cit = widthcache.find(val);
- if (cit != widthcache.end())
- return cit->second;
+ lyxerr[Debug::FONT] << "The font has size: "
+ << font.pointSizeF() << endl;
+
+ if (f.realShape() != LyXFont::SMALLCAPS_SHAPE) {
+ metrics.reset(new GuiFontMetrics(font));
+ }
+ else {
+ // handle small caps ourselves ...
+ LyXFont smallfont = f;
+ smallfont.decSize().decSize().setShape(LyXFont::UP_SHAPE);
+ QFont font2(font);
+ font2.setPointSizeF(convert<double>(lyxrc.font_sizes[smallfont.size()])
+ * lyxrc.zoom / 100.0);
+
+ metrics.reset(new GuiFontMetrics(font, font2));
+ }
- int const w = metrics.width(QChar(val));
- widthcache[val] = w;
- return w;
}
-#endif
bool GuiFontLoader::available(LyXFont const & f)
#include "frontends/FontLoader.h"
+#include "GuiFontMetrics.h"
+
#include "encoding.h"
#include "lyxfont.h"
#include <QFont>
-#include <QFontMetrics>
-
-// Starting with version 3.1.0, Qt/X11 does its own caching of
-// character width, so it is not necessary to provide ours.
-#if defined(Q_WS_MACX) || defined(Q_WS_WIN32)
-#define USE_LYX_FONTCACHE
-#include <map>
-#endif
namespace lyx {
namespace frontend {
/// The font instance
QFont font;
/// Metrics on the font
- QFontMetrics metrics;
-
-#ifndef USE_LYX_FONTCACHE
- /// Return pixel width for the given unicode char
- int width(Uchar val) { return metrics.width(QChar(val)); }
-
-#else
- /// Return pixel width for the given unicode char
- int width(Uchar val);
-
-private:
- typedef std::map<Uchar, int> WidthCache;
- /// Cache of char widths
- WidthCache widthcache;
-#endif // USE_LYX_FONTCACHE
+ boost::scoped_ptr<GuiFontMetrics> metrics;
};
/// Destructor
virtual ~GuiFontLoader();
- /// Update fonts after zoom, dpi, font names, or norm change
virtual void update();
-
- /// Do we have anything matching?
virtual bool available(LyXFont const & f);
+ inline virtual FontMetrics const & metrics(LyXFont const & f) {
+ return *fontinfo(f).metrics.get();
+ }
/// Get the QFont for this LyXFont
QFont const & get(LyXFont const & f) {
return fontinfo(f).font;
}
- /// Get the QFont metrics for this LyXFont
- QFontMetrics const & metrics(LyXFont const & f) {
- return fontinfo(f).metrics;
- }
/// Get font info (font + metrics) for the given LyX font.
QLFontInfo & fontinfo(LyXFont const & f) {
--- /dev/null
+/**
+ * \file GuiFontMetrics.C
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author unknown
+ * \author John Levon
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#include <config.h>
+
+#include "GuiFontMetrics.h"
+
+#include "qt_helpers.h"
+
+#include "language.h"
+
+#include "frontends/lyx_gui.h"
+
+#include "support/unicode.h"
+
+using lyx::char_type;
+using lyx::docstring;
+
+using std::string;
+
+
+namespace lyx {
+namespace frontend {
+
+
+GuiFontMetrics::GuiFontMetrics(QFont const & font)
+: metrics_(font), smallcaps_metrics_(font), smallcaps_shape_(false)
+{
+}
+
+
+GuiFontMetrics::GuiFontMetrics(QFont const & font, QFont const & smallcaps_font)
+: metrics_(font), smallcaps_metrics_(smallcaps_font), smallcaps_shape_(true)
+{
+}
+
+
+int GuiFontMetrics::maxAscent() const
+{
+ if (!lyx_gui::use_gui)
+ return 1;
+ return metrics_.ascent();
+}
+
+
+int GuiFontMetrics::maxDescent() const
+{
+ if (!lyx_gui::use_gui)
+ return 1;
+ // We add 1 as the value returned by QT is different than X
+ // See http://doc.trolltech.com/2.3/qfontmetrics.html#200b74
+ return metrics_.descent() + 1;
+}
+
+
+int GuiFontMetrics::ascent(char_type c) const
+{
+ if (!lyx_gui::use_gui)
+ return 1;
+ QRect const & r = metrics_.boundingRect(ucs4_to_qchar(c));
+ // Qt/Win 3.2.1nc (at least) corrects the GetGlyphOutlineA|W y
+ // value by the height: (x, -y-height, width, height).
+ // Other versions return: (x, -y, width, height)
+#if defined(Q_WS_WIN) && (QT_VERSION == 0x030201)
+ return -r.top() - r.height();
+#else
+ return -r.top();
+#endif
+}
+
+
+int GuiFontMetrics::descent(char_type c) const
+{
+ if (!lyx_gui::use_gui)
+ return 1;
+ QRect const & r = metrics_.boundingRect(ucs4_to_qchar(c));
+ // Qt/Win 3.2.1nc (at least) corrects the GetGlyphOutlineA|W y
+ // value by the height: (x, -y-height, width, height).
+ // Other versions return: (x, -y, width, height)
+#if defined(Q_WS_WIN) && (QT_VERSION == 0x030201)
+ return r.bottom() + r.height() + 1;
+#else
+ return r.bottom() + 1;
+#endif
+}
+
+
+int GuiFontMetrics::lbearing(char_type c) const
+{
+ if (!lyx_gui::use_gui)
+ return 1;
+ return metrics_.leftBearing(ucs4_to_qchar(c));
+}
+
+
+int GuiFontMetrics::rbearing(char_type c) const
+{
+ if (!lyx_gui::use_gui)
+ return 1;
+
+ // Qt rbearing is from the right edge of the char's width().
+ QChar sc = ucs4_to_qchar(c);
+ return metrics_.width(sc) - metrics_.rightBearing(sc);
+}
+
+
+int GuiFontMetrics::smallcapsWidth(QString const & s) const
+{
+ if (!lyx_gui::use_gui)
+ return 1;
+
+ int w = 0;
+ int const ls = s.size();
+
+ for (int i = 0; i < ls; ++i) {
+ QChar const & c = s[i];
+ QChar const uc = c.toUpper();
+ if (c != uc)
+ w += smallcaps_metrics_.width(uc);
+ else
+ w += metrics_.width(c);
+ }
+ return w;
+}
+
+
+int GuiFontMetrics::width(char_type const * s, size_t ls) const
+{
+ if (!lyx_gui::use_gui)
+ return ls;
+
+ QString ucs2 = ucs4_to_qstring(s, ls);
+
+ if (smallcaps_shape_)
+ return smallcapsWidth(ucs2);
+
+ if (ls == 1)
+ return width(ucs2[0].unicode());
+
+ int w = 0;
+ for (unsigned int i = 0; i < ls; ++i)
+ w += width(ucs2[i].unicode());
+
+ return w;
+}
+
+
+int GuiFontMetrics::signedWidth(docstring const & s) const
+{
+ if (s[0] == '-')
+ return -FontMetrics::width(s.substr(1, s.length() - 1));
+ else
+ return FontMetrics::width(s);
+}
+
+
+void GuiFontMetrics::rectText(docstring const & str,
+ int & w, int & ascent, int & descent) const
+{
+ static int const d = 2;
+ w = FontMetrics::width(str) + d * 2 + 2;
+ ascent = metrics_.ascent() + d;
+ descent = metrics_.descent() + d;
+}
+
+
+
+void GuiFontMetrics::buttonText(docstring const & str,
+ int & w, int & ascent, int & descent) const
+{
+ QFontMetrics const & m = metrics_;
+ static int const d = 3;
+ w = FontMetrics::width(str) + d * 2 + 2;
+ ascent = metrics_.ascent() + d;
+ descent = metrics_.descent() + d;
+}
+
+#ifdef USE_LYX_FONTCACHE
+int GuiFontMetrics::width(unsigned short val) const
+{
+ GuiFontMetrics::WidthCache::const_iterator cit = widthcache.find(val);
+ if (cit != widthcache.end())
+ return cit->second;
+
+ int const w = metrics_.width(QChar(val));
+ widthcache[val] = w;
+ return w;
+}
+#endif
+
+}
+}
--- /dev/null
+// -*- C++ -*-
+/**
+ * \file FontMetrics.h
+ * 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.
+ */
+
+#ifndef QT4_FONT_METRICS_H
+#define QT4_FONT_METRICS_H
+
+#include "frontends/FontMetrics.h"
+
+#include "support/docstring.h"
+
+#include <QFontMetrics>
+
+// Starting with version 3.1.0, Qt/X11 does its own caching of
+// character width, so it is not necessary to provide ours.
+#if defined(Q_WS_MACX) || defined(Q_WS_WIN32)
+#define USE_LYX_FONTCACHE
+#include <map>
+#endif
+
+namespace lyx {
+namespace frontend {
+
+class GuiFontMetrics: public FontMetrics
+{
+public:
+
+ GuiFontMetrics(QFont const & font);
+ GuiFontMetrics(QFont const & font, QFont const & smallcaps_font);
+
+ virtual ~GuiFontMetrics() {}
+
+ virtual int maxAscent() const;
+ virtual int maxDescent() const;
+ virtual int ascent(lyx::char_type c) const;
+ int descent(lyx::char_type c) const;
+ virtual int lbearing(lyx::char_type c) const;
+ virtual int rbearing(lyx::char_type c) const;
+ virtual int width(lyx::char_type const * s, size_t n) const;
+ virtual int signedWidth(lyx::docstring const & s) const;
+ virtual void rectText(lyx::docstring const & str,
+ int & width,
+ int & ascent,
+ int & descent) const;
+ virtual void buttonText(lyx::docstring const & str,
+ int & width,
+ int & ascent,
+ int & descent) const;
+
+private:
+ int smallcapsWidth(QString const & s) const;
+
+ /// Metrics on the font
+ QFontMetrics metrics_;
+ QFontMetrics smallcaps_metrics_;
+
+ bool smallcaps_shape_;
+
+#ifndef USE_LYX_FONTCACHE
+ /// Return pixel width for the given unicode char
+ int width(unsigned short val) const { return metrics_.width(QChar(val)); }
+
+#else
+ /// Return pixel width for the given unicode char
+ int width(unsigned short val) const;
+
+ typedef std::map<unsigned short, int> WidthCache;
+ /// Cache of char widths
+ mutable WidthCache widthcache;
+#endif // USE_LYX_FONTCACHE
+};
+
+} // namespace frontend
+} // namespace lyx
+
+#endif // QT4_FONT_METRICS_H
GuiApplication.C GuiApplication.h \
GuiClipboard.h GuiClipboard.C \
GuiFontLoader.h GuiFontLoader.C \
+ GuiFontMetrics.h GuiFontMetrics.C \
GuiSelection.h GuiSelection.C \
GuiImplementation.h GuiImplementation.C \
LyXKeySymFactory.C \
lyx_gui.C \
panelstack.h panelstack.C \
qfontexample.h qfontexample.C \
- qfont_metrics.C \
qlkey.h \
qt_helpers.h qt_helpers.C \
qtTimeout.C qtTimeout.h \
#include "language.h"
#include "LColor.h"
-#include "frontends/font_metrics.h"
+#include "frontends/FontMetrics.h"
#include "support/unicode.h"
}
-void QLPainter::smallCapsText(int x, int y,
+int QLPainter::smallCapsText(int x, int y,
QString const & s, LyXFont const & f)
{
LyXFont smallfont(f);
QFont const & qfont = guiApp->guiFontLoader().get(f);
QFont const & qsmallfont = guiApp->guiFontLoader().get(smallfont);
- QFontMetrics const & qfontm = QFontMetrics(qfont);
- QFontMetrics const & qsmallfontm = QFontMetrics(qsmallfont);
setQPainterPen(f.realColor());
- int tmpx = x;
+ int textwidth = 0;
size_t ls = s.length();
for (unsigned int i = 0; i < ls; ++i) {
QChar const c = s[i].toUpper();
if (c != s.at(i)) {
qp_->setFont(qsmallfont);
- qp_->drawText(tmpx, y, c);
- tmpx += qsmallfontm.width(c);
} else {
qp_->setFont(qfont);
- qp_->drawText(tmpx, y, c);
- tmpx += qfontm.width(c);
}
+ qp_->drawText(x + textwidth, y, c);
+ textwidth += qp_->fontMetrics().width(c);
}
+ return textwidth;
}
str = ' ' + str;
#endif
+ QLFontInfo & fi = guiApp->guiFontLoader().fontinfo(f);
+
+ int textwidth;
+
if (f.realShape() != LyXFont::SMALLCAPS_SHAPE) {
setQPainterPen(f.realColor());
- qp_->setFont(guiApp->guiFontLoader().get(f));
+ qp_->setFont(fi.font);
// We need to draw the text as LTR as we use our own bidi code.
qp_->setLayoutDirection(Qt::LeftToRight);
qp_->drawText(x, y, str);
+ textwidth = qp_->fontMetrics().width(str);
} else {
- smallCapsText(x, y, str, f);
+ textwidth = smallCapsText(x, y, str, f);
}
if (f.underbar() == LyXFont::ON) {
- underline(f, x, y, font_metrics::width(s, ls, f));
+ underline(f, x, y, textwidth);
}
}
private:
/// draw small caps text
- void smallCapsText(int x, int y,
+ /**
+ \return width of the drawn text.
+ */
+ int smallCapsText(int x, int y,
QString const & str, LyXFont const & f);
/// set pen parameters
+++ /dev/null
-/**
- * \file qfont_metrics.C
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author unknown
- * \author John Levon
- *
- * Full author contact details are available in file CREDITS.
- */
-
-#include <config.h>
-
-#include "frontends/font_metrics.h"
-#include "frontends/lyx_gui.h"
-
-#include "GuiApplication.h"
-#include "FontLoader.h"
-#include "qt_helpers.h"
-
-#include "language.h"
-
-#include "support/unicode.h"
-
-using lyx::char_type;
-using lyx::docstring;
-
-using std::string;
-
-
-namespace {
-
-int smallcapswidth(QString const & s, LyXFont const & f)
-{
- if (!lyx_gui::use_gui)
- return 1;
- // handle small caps ourselves ...
-
- LyXFont smallfont = f;
- smallfont.decSize().decSize().setShape(LyXFont::UP_SHAPE);
-
- QFontMetrics const & qm = guiApp->guiFontLoader().metrics(f);
- QFontMetrics const & qsmallm = guiApp->guiFontLoader().metrics(smallfont);
-
- int w = 0;
-
- int const ls = s.size();
-
- for (int i = 0; i < ls; ++i) {
- QChar const & c = s[i];
- QChar const uc = c.toUpper();
- if (c != uc)
- w += qsmallm.width(uc);
- else
- w += qm.width(c);
- }
- return w;
-}
-
-
-} // anon namespace
-
-
-int font_metrics::maxAscent(LyXFont const & f)
-{
- if (!lyx_gui::use_gui)
- return 1;
- return guiApp->guiFontLoader().metrics(f).ascent();
-}
-
-
-int font_metrics::maxDescent(LyXFont const & f)
-{
- if (!lyx_gui::use_gui)
- return 1;
- // We add 1 as the value returned by QT is different than X
- // See http://doc.trolltech.com/2.3/qfontmetrics.html#200b74
- return guiApp->guiFontLoader().metrics(f).descent() + 1;
-}
-
-
-int font_metrics::ascent(char_type c, LyXFont const & f)
-{
- if (!lyx_gui::use_gui)
- return 1;
- QRect const & r = guiApp->guiFontLoader().metrics(f).boundingRect(ucs4_to_qchar(c));
- // Qt/Win 3.2.1nc (at least) corrects the GetGlyphOutlineA|W y
- // value by the height: (x, -y-height, width, height).
- // Other versions return: (x, -y, width, height)
-#if defined(Q_WS_WIN) && (QT_VERSION == 0x030201)
- return -r.top() - r.height();
-#else
- return -r.top();
-#endif
-}
-
-
-int font_metrics::descent(char_type c, LyXFont const & f)
-{
- if (!lyx_gui::use_gui)
- return 1;
- QRect const & r = guiApp->guiFontLoader().metrics(f).boundingRect(ucs4_to_qchar(c));
- // Qt/Win 3.2.1nc (at least) corrects the GetGlyphOutlineA|W y
- // value by the height: (x, -y-height, width, height).
- // Other versions return: (x, -y, width, height)
-#if defined(Q_WS_WIN) && (QT_VERSION == 0x030201)
- return r.bottom() + r.height() + 1;
-#else
- return r.bottom() + 1;
-#endif
-}
-
-
-int font_metrics::lbearing(char_type c, LyXFont const & f)
-{
- if (!lyx_gui::use_gui)
- return 1;
- return guiApp->guiFontLoader().metrics(f).leftBearing(ucs4_to_qchar(c));
-}
-
-
-int font_metrics::rbearing(char_type c, LyXFont const & f)
-{
- if (!lyx_gui::use_gui)
- return 1;
- QFontMetrics const & m = guiApp->guiFontLoader().metrics(f);
-
- // Qt rbearing is from the right edge of the char's width().
- QChar sc = ucs4_to_qchar(c);
- return m.width(sc) - m.rightBearing(sc);
-}
-
-
-int font_metrics::width(char_type const * s, size_t ls, LyXFont const & f)
-{
- if (!lyx_gui::use_gui)
- return ls;
-
- QString ucs2 = ucs4_to_qstring(s, ls);
-
- if (f.realShape() == LyXFont::SMALLCAPS_SHAPE)
- return smallcapswidth(ucs2, f);
-
- lyx::frontend::QLFontInfo & fi = guiApp->guiFontLoader().fontinfo(f);
-
- if (ls == 1)
- return fi.width(ucs2[0].unicode());
-
- int w = 0;
- for (unsigned int i = 0; i < ls; ++i)
- w += fi.width(ucs2[i].unicode());
-
- return w;
-}
-
-
-int font_metrics::signedWidth(docstring const & s, LyXFont const & f)
-{
- if (s[0] == '-')
- return -width(s.substr(1, s.length() - 1), f);
- else
- return width(s, f);
-}
-
-
-void font_metrics::rectText(docstring const & str, LyXFont const & f,
- int & w, int & ascent, int & descent)
-{
- QFontMetrics const & m = guiApp->guiFontLoader().metrics(f);
- static int const d = 2;
- w = width(str, f) + d * 2 + 2;
- ascent = m.ascent() + d;
- descent = m.descent() + d;
-}
-
-
-
-void font_metrics::buttonText(docstring const & str, LyXFont const & f,
- int & w, int & ascent, int & descent)
-{
- QFontMetrics const & m = guiApp->guiFontLoader().metrics(f);
- static int const d = 3;
- w = width(str, f) + d * 2 + 2;
- ascent = m.ascent() + d;
- descent = m.descent() + d;
-}
QString const ucs4_to_qstring(char_type const * str, size_t ls)
{
QString s;
+ s.reserve(ls);
for (size_t i = 0; i < ls; ++i)
s.append(ucs4_to_qchar(str[i]));
#include "paragraph.h"
#include "ParagraphList.h"
-#include "frontends/font_metrics.h"
+#include "frontends/Application.h"
+#include "frontends/FontLoader.h"
+#include "frontends/FontMetrics.h"
#include "support/lstrings.h"
#include "support/std_ostream.h"
// Does look like a hack? It is! (but will change at 0.13)
InsetBibitem const * bitem = 0;
+ // FIXME font is used unitialized, is that correct?
LyXFont font;
+ lyx::frontend::FontMetrics const & fm =
+ theApp->fontLoader().metrics(font);
ParagraphList::const_iterator it = buffer.paragraphs().begin();
ParagraphList::const_iterator end = buffer.paragraphs().end();
docstring const dlab(label.begin(), label.end());
int const wx =
- font_metrics::width(dlab, font);
+ fm.width(dlab);
if (wx > w) {
w = wx;
bitem = it->bibitem();
#include "metricsinfo.h"
#include "paragraph.h"
-#include "frontends/font_metrics.h"
+#include "frontends/Application.h"
+#include "frontends/FontLoader.h"
+#include "frontends/FontMetrics.h"
#include "frontends/Painter.h"
#include "support/lstrings.h"
LCursor cur = mi.base.bv->cursor();
setLabel(cur);
docstring dlab(label.begin(), label.end());
- labelwidth_ = font_metrics::width(dlab, mi.base.font);
+ labelwidth_ = theApp->fontLoader().metrics(mi.base.font).width(dlab);
dim.wid = labelwidth_;
Dimension textdim;
InsetText::metrics(mi, textdim);
LCursor cur = pi.base.bv->cursor();
setLabel(cur);
docstring dlab(label.begin(), label.end());
- labelwidth_ = font_metrics::width(dlab, pi.base.font);
+ // FXIME: instead of using the fontLoader metrics, we should make
+ // painter::text() returns the drawn text witdh.
+ labelwidth_ = theApp->fontLoader().metrics(pi.base.font).width(dlab);
pi.pain.text(x, y, dlab, pi.base.font);
InsetText::draw(pi, x + labelwidth_, y);
setPosCache(pi, x, y);
#include "paragraph_funcs.h"
#include "sgml.h"
-#include "frontends/font_metrics.h"
+#include "frontends/Application.h"
+#include "frontends/FontLoader.h"
+#include "frontends/FontMetrics.h"
#include "frontends/Painter.h"
#include <sstream>
// FIXME UNICODE
s = lyx::to_utf8(_("Undef: ")) + s;
docstring ds(s.begin(), s.end());
- font_metrics::rectText(ds, font, w, a, d);
+ theApp->fontLoader().metrics(font).rectText(ds, w, a, d);
dim.wid = max(dim.wid, w);
}
dim.asc += TEXT_TO_INSET_OFFSET;
// FIXME UNICODE
s = lyx::to_utf8(_("Undef: ")) + s;
docstring ds(s.begin(), s.end());
- font_metrics::rectText(ds, font, w, a, d);
+ theApp->fontLoader().metrics(font).rectText(ds, w, a, d);
pi.pain.rectText(x + (dim_.wid - w) / 2, y + desc + a,
ds, font, LColor::none, LColor::none);
}
#include "metricsinfo.h"
#include "paragraph.h"
-#include "frontends/font_metrics.h"
+#include "frontends/Application.h"
+#include "frontends/FontLoader.h"
+#include "frontends/FontMetrics.h"
#include "frontends/Painter.h"
using lyx::docstring;
Dimension InsetCollapsable::dimensionCollapsed() const
{
Dimension dim;
- docstring dlab(label.begin(), label.end());
- font_metrics::buttonText(dlab, labelfont_, dim.wid, dim.asc, dim.des);
+ docstring dlab(label.begin(), label.end());
+ theApp->fontLoader().metrics(labelfont_).buttonText(
+ dlab, dim.wid, dim.asc, dim.des);
return dim;
}
#include "lyxrc.h"
#include "metricsinfo.h"
-#include "frontends/font_metrics.h"
+#include "frontends/Application.h"
+#include "frontends/FontLoader.h"
+#include "frontends/FontMetrics.h"
#include "frontends/Painter.h"
#include "support/lstrings.h"
void InsetLatexAccent::metrics(MetricsInfo & mi, Dimension & dim) const
{
LyXFont & font = mi.base.font;
+ lyx::frontend::FontMetrics const & fm =
+ theApp->fontLoader().metrics(font);
+
// This function is a bit too simplistic and is just a
// "try to make a fit for all accents" approach, to
// make it better we need to know what kind of accent is
// used and add to max based on that.
if (candisp) {
if (ic == ' ')
- dim.asc = font_metrics::ascent('a', font);
+ dim.asc = fm.ascent('a');
else
- dim.asc = font_metrics::ascent(ic, font);
+ dim.asc = fm.ascent(ic);
if (plusasc)
- dim.asc += (font_metrics::maxAscent(font) + 3) / 3;
+ dim.asc += (fm.maxAscent() + 3) / 3;
if (ic == ' ')
- dim.des = font_metrics::descent('a', font);
+ dim.des = fm.descent('a');
else
- dim.des = font_metrics::descent(ic, font);
+ dim.des = fm.descent(ic);
if (plusdesc)
dim.des += 3;
- dim.wid = font_metrics::width(ic, font);
+ dim.wid = fm.width(ic);
} else {
- dim.asc = font_metrics::maxAscent(font) + 4;
- dim.des = font_metrics::maxDescent(font) + 4;
+ dim.asc = fm.maxAscent() + 4;
+ dim.des = fm.maxDescent() + 4;
docstring dcon(contents.begin(), contents.end());
- dim.wid = font_metrics::width(dcon, font) + 4;
+ dim.wid = fm.width(dcon) + 4;
}
dim_ = dim;
}
-int InsetLatexAccent::lbearing(LyXFont const & font) const
-{
- return font_metrics::lbearing(ic, font);
-}
-
-
-int InsetLatexAccent::rbearing(LyXFont const & font) const
-{
- return font_metrics::rbearing(ic, font);
-}
-
-
bool InsetLatexAccent::displayISO8859_9(PainterInfo & pi, int x, int y) const
{
unsigned char tmpic = ic;
char_type accent) const
{
LyXFont const & font = pi.base.font;
- x -= font_metrics::center(accent, font);
- y -= font_metrics::ascent(ic, font);
- y -= font_metrics::descent(accent, font);
- y -= font_metrics::height(accent, font) / 2;
+ lyx::frontend::FontMetrics const & fm =
+ theApp->fontLoader().metrics(font);
+
+ x -= fm.center(accent);
+ y -= fm.ascent(ic);
+ y -= fm.descent(accent);
+ y -= fm.height(accent) / 2;
pi.pain.text(x, y, accent, font);
}
if (lyxrc.font_norm_type == LyXRC::ISO_10646_1)
font.setLanguage(english_language);
+ lyx::frontend::FontMetrics const & fm =
+ theApp->fontLoader().metrics(font);
+
if (candisp) {
- int x2 = int(x + (rbearing(font) - lbearing(font)) / 2);
+ int x2 = int(x + (fm.rbearing(ic) - fm.lbearing(ic)) / 2);
int hg;
int y;
if (plusasc) {
// mark at the top
- hg = font_metrics::maxDescent(font);
+ hg = fm.maxDescent();
y = baseline - dim_.asc;
if (font.shape() == LyXFont::ITALIC_SHAPE)
x2 += int(0.8 * hg); // italic
pi.pain.text(x, baseline, ic, font);
if (remdot) {
- int tmpvar = baseline - font_metrics::ascent('i', font);
+ int tmpvar = baseline - fm.ascent('i');
int tmpx = 0;
if (font.shape() == LyXFont::ITALIC_SHAPE)
tmpx += int(0.8 * hg); // italic
lyxerr[Debug::KEY] << "Removing dot." << endl;
// remove the dot first
pi.pain.fillRectangle(x + tmpx, tmpvar, dim_.wid,
- font_metrics::ascent('i', pi.base.font) -
- font_metrics::ascent('x', pi.base.font) - 1,
+ fm.ascent('i') -
+ fm.ascent('x') - 1,
backgroundColor());
// the five lines below is a simple hack to
// make the display of accent 'i' and 'j'
case UNDERBAR: {
char_type const underbar = 0x5F; //('\x5F');
- pi.pain.text(x2 - font_metrics::center(underbar, font),
+ pi.pain.text(x2 - fm.center(underbar),
baseline, underbar, font);
break;
}
case CEDILLA: {
char_type const cedilla = 0xB8; //('\xB8');
- pi.pain.text(x2 - font_metrics::center(cedilla, font),
+ pi.pain.text(x2 - fm.center(cedilla),
baseline, cedilla, font);
break;
}
case UNDERDOT:
- pi.pain.text(x2 - font_metrics::center('.', font),
- int(baseline + 1.5 * font_metrics::height('.', font)),
+ pi.pain.text(x2 - fm.center('.'),
+ int(baseline + 1.5 * fm.height('.')),
'.', font);
break;
}
case HUNGARIAN_UMLAUT:
- drawAccent(pi, x2 - font_metrics::center('´', font), baseline, '´');
- drawAccent(pi, x2 + font_metrics::center('´', font), baseline, '´');
+ drawAccent(pi, x2 - fm.center('´'), baseline, '´');
+ drawAccent(pi, x2 + fm.center('´'), baseline, '´');
break;
case UMLAUT:
///
void draw(PainterInfo & pi, int x, int y) const;
///
- int lbearing(LyXFont const & font) const;
- ///
- int rbearing(LyXFont const & font) const;
- ///
bool displayISO8859_9(PainterInfo & pi, int x, int y) const;
///
void write(Buffer const &, std::ostream &) const;
#include "paragraph.h"
#include "paragraph_funcs.h"
-#include "frontends/font_metrics.h"
+#include "frontends/Application.h"
+#include "frontends/FontLoader.h"
+#include "frontends/FontMetrics.h"
#include "frontends/Painter.h"
using std::endl;
void InsetNewline::metrics(MetricsInfo & mi, Dimension & dim) const
{
- LyXFont & font = mi.base.font;
- dim.asc = font_metrics::maxAscent(font);
- dim.des = font_metrics::maxDescent(font);
- dim.wid = font_metrics::width('n', font);
+ lyx::frontend::FontMetrics const & fm =
+ theApp->fontLoader().metrics(mi.base.font);
+ dim.asc = fm.maxAscent();
+ dim.des = fm.maxDescent();
+ dim.wid = fm.width('n');
dim_ = dim;
}
void InsetNewline::draw(PainterInfo & pi, int x, int y) const
{
- int const wid = font_metrics::width('n', pi.base.font);
- int const asc = font_metrics::maxAscent(pi.base.font);
+ lyx::frontend::FontMetrics const & fm =
+ theApp->fontLoader().metrics(pi.base.font);
+ int const wid = fm.width('n');
+ int const asc = fm.maxAscent();
int xp[3];
int yp[3];
#include "metricsinfo.h"
#include "gettext.h"
+#include "frontends/Application.h"
+#include "frontends/FontLoader.h"
+#include "frontends/FontMetrics.h"
#include "frontends/Painter.h"
-#include "frontends/font_metrics.h"
using lyx::docstring;
using lyx::frontend::Painter;
int w = 0;
int a = 0;
int d = 0;
- font_metrics::rectText(label, font, w, a, d);
+ theApp->fontLoader().metrics(font).rectText(label, w, a, d);
int const text_start = int(x + (dim_.wid - w) / 2);
int const text_end = text_start + w;
#include "paragraph.h"
#include "paragraph_funcs.h"
-#include "frontends/font_metrics.h"
+#include "frontends/Application.h"
+#include "frontends/FontLoader.h"
+#include "frontends/FontMetrics.h"
#include "frontends/Painter.h"
#include "support/lstrings.h"
void InsetQuotes::metrics(MetricsInfo & mi, Dimension & dim) const
{
LyXFont & font = mi.base.font;
- dim.asc = font_metrics::maxAscent(font);
- dim.des = font_metrics::maxDescent(font);
+ lyx::frontend::FontMetrics const & fm =
+ theApp->fontLoader().metrics(font);
+ dim.asc = fm.maxAscent();
+ dim.des = fm.maxDescent();
dim.wid = 0;
string const text = dispString(font.language());
for (string::size_type i = 0; i < text.length(); ++i) {
if (text[i] == ' ')
- dim.wid += font_metrics::width('i', font);
+ dim.wid += fm.width('i');
else if (i == 0 || text[i] != text[i - 1])
- dim.wid += font_metrics::width(text[i], font);
+ dim.wid += fm.width(text[i]);
else
- dim.wid += font_metrics::width(',', font);
+ dim.wid += fm.width(',');
}
dim_ = dim;
}
if (text.length() == 2 && text[0] == text[1]) {
pi.pain.text(x, y, text[0], pi.base.font);
- int const t = font_metrics::width(',', pi.base.font);
+ int const t = theApp->fontLoader().metrics(pi.base.font)
+ .width(',');
pi.pain.text(x + t, y, text[0], pi.base.font);
} else {
docstring dtext(text.begin(), text.end());
#include "metricsinfo.h"
#include "outputparams.h"
-#include "frontends/font_metrics.h"
+#include "frontends/Application.h"
+#include "frontends/FontLoader.h"
+#include "frontends/FontMetrics.h"
#include "frontends/Painter.h"
void InsetSpace::metrics(MetricsInfo & mi, Dimension & dim) const
{
- LyXFont & font = mi.base.font;
- dim.asc = font_metrics::maxAscent(font);
- dim.des = font_metrics::maxDescent(font);
+ lyx::frontend::FontMetrics const & fm =
+ theApp->fontLoader().metrics(mi.base.font);
+ dim.asc = fm.maxAscent();
+ dim.des = fm.maxDescent();
switch (kind_) {
case THIN:
case NEGTHIN:
- dim.wid = font_metrics::width(lyx::char_type('x'), font) / 3;
+ dim.wid = fm.width(lyx::char_type('x')) / 3;
break;
case PROTECTED:
case NORMAL:
- dim.wid = font_metrics::width(lyx::char_type('x'), font);
+ dim.wid = fm.width(lyx::char_type('x'));
break;
case QUAD:
dim.wid = 20;
void InsetSpace::draw(PainterInfo & pi, int x, int y) const
{
int const w = width();
- int const h = font_metrics::ascent('x', pi.base.font);
+ int const h = theApp->fontLoader().metrics(pi.base.font)
+ .ascent('x');
int xp[4], yp[4];
xp[0] = x;
#include "lyxlex.h"
#include "metricsinfo.h"
-#include "frontends/font_metrics.h"
+#include "frontends/Application.h"
+#include "frontends/FontLoader.h"
+#include "frontends/FontMetrics.h"
#include "frontends/Painter.h"
using lyx::docstring;
void InsetSpecialChar::metrics(MetricsInfo & mi, Dimension & dim) const
{
- LyXFont & font = mi.base.font;
- dim.asc = font_metrics::maxAscent(font);
- dim.des = font_metrics::maxDescent(font);
+ lyx::frontend::FontMetrics const & fm =
+ theApp->fontLoader().metrics(mi.base.font);
+ dim.asc = fm.maxAscent();
+ dim.des = fm.maxDescent();
string s;
switch (kind_) {
case HYPHENATION: s = "-"; break;
}
docstring ds(s.begin(), s.end());
- dim.wid = font_metrics::width(ds, font);
+ dim.wid = fm.width(ds);
if (kind_ == HYPHENATION && dim.wid > 5)
dim.wid -= 2; // to make it look shorter
dim_ = dim;
}
case MENU_SEPARATOR:
{
+ lyx::frontend::FontMetrics const & fm =
+ theApp->fontLoader().metrics(font);
+
// A triangle the width and height of an 'x'
- int w = font_metrics::width(lyx::char_type('x'), font);
- int ox = font_metrics::width(lyx::char_type(' '), font) + x;
- int h = font_metrics::ascent(lyx::char_type('x'), font);
+ int w = fm.width(lyx::char_type('x'));
+ int ox = fm.width(lyx::char_type(' ')) + x;
+ int h = fm.ascent(lyx::char_type('x'));
int xp[4], yp[4];
xp[0] = ox; yp[0] = y;
#include "frontends/Alert.h"
#include "frontends/Application.h"
-#include "frontends/font_metrics.h"
#include "frontends/Clipboard.h"
#include "frontends/Painter.h"
#include "frontends/Selection.h"
#include "undo.h"
#include "frontends/Alert.h"
-#include "frontends/font_metrics.h"
#include "frontends/Painter.h"
#include "support/lyxalgo.h" // lyx::count
#include "lyxtext.h"
#include "metricsinfo.h"
-#include "frontends/font_metrics.h"
+#include "frontends/Application.h"
+#include "frontends/FontLoader.h"
+#include "frontends/FontMetrics.h"
#include "frontends/Painter.h"
#include <sstream>
int d = 0;
string lab = label();
docstring dlab(lab.begin(), lab.end());
- font_metrics::rectText(dlab, font, w, a, d);
+ theApp->fontLoader().metrics(font).rectText(dlab, w, a, d);
height = max(height, a + d);
font.decSize();
string lab = label();
docstring dlab(lab.begin(), lab.end());
- font_metrics::rectText(dlab, font, w, a, d);
+ theApp->fontLoader().metrics(font).rectText(dlab, w, a, d);
pi.pain.rectText(x + 2 * arrow_size + 5,
start + (end - start) / 2 + (a - d) / 2,
#include "LColor.h"
#include "metricsinfo.h"
-#include "frontends/font_metrics.h"
+#include "frontends/Application.h"
+#include "frontends/FontLoader.h"
+#include "frontends/FontMetrics.h"
#include "frontends/Painter.h"
using lyx::docstring;
{
LyXFont font(LyXFont::ALL_SANE);
font.decSize();
-
- docstring dtext(text_.begin(), text_.end());
+ lyx::frontend::FontMetrics const & fm =
+ theApp->fontLoader().metrics(font);
+
+ docstring dtext(text_.begin(), text_.end());
if (editable_)
- font_metrics::buttonText(dtext, font, dim.wid, dim.asc, dim.des);
+ fm.buttonText(dtext, dim.wid, dim.asc, dim.des);
else
- font_metrics::rectText(dtext, font, dim.wid, dim.asc, dim.des);
+ fm.rectText(dtext, dim.wid, dim.asc, dim.des);
dim.wid += 4;
}
#include "lyxrc.h"
#include "metricsinfo.h"
-#include "frontends/font_metrics.h"
+#include "frontends/Application.h"
+#include "frontends/FontLoader.h"
+#include "frontends/FontMetrics.h"
#include "frontends/Painter.h"
#include "graphics/GraphicsImage.h"
docstring djust(justname.begin(), justname.end());
if (!justname.empty()) {
msgFont.setSize(LyXFont::SIZE_FOOTNOTE);
- font_width = font_metrics::width(djust, msgFont);
+ font_width = theApp->fontLoader().metrics(msgFont)
+ .width(djust);
}
string const msg = statusMessage(params_, loader_.status());
if (!msg.empty()) {
docstring dmsg(msg.begin(), msg.end());
msgFont.setSize(LyXFont::SIZE_TINY);
- font_width = std::max(font_width,
- font_metrics::width(dmsg, msgFont));
+ font_width = std::max(font_width, theApp->fontLoader()
+ .metrics(msgFont).width(dmsg));
}
dim.wid = std::max(50, font_width + 15);
docstring djust(justname.begin(), justname.end());
msgFont.setSize(LyXFont::SIZE_FOOTNOTE);
pi.pain.text(x + InsetOld::TEXT_TO_INSET_OFFSET + 6,
- y - font_metrics::maxAscent(msgFont) - 4,
+ y - theApp->fontLoader().metrics(msgFont).maxAscent() - 4,
djust, msgFont);
}
#include "lyxrc.h"
#include "metricsinfo.h"
-#include "frontends/font_metrics.h"
+#include "frontends/Application.h"
+#include "frontends/FontLoader.h"
+#include "frontends/FontMetrics.h"
#include "frontends/Painter.h"
#include "graphics/PreviewImage.h"
font.setSize(LyXFont::SIZE_FOOTNOTE);
string stat = statusMessage(mi.base.bv, snippet_);
docstring dstat(stat.begin(), stat.end());
- dim.wid = 15 + font_metrics::width(dstat, font);
+ dim.wid = 15 + theApp->fontLoader().metrics(font).width(dstat);
}
dim_ = dim;
string stat = statusMessage(pi.base.bv, snippet_);
docstring dstat(stat.begin(), stat.end());
pi.pain.text(x + offset + 6,
- y - font_metrics::maxAscent(font) - 4,
+ y - theApp->fontLoader().metrics(font).maxAscent() - 4,
dstat, font);
}
}
? em_width_base
: 10*(dpi/72.27)*zoom;
// A different estimate for em_width is
- // font_metrics::width('M', LyXFont(LyXFont::ALL_SANE))
+ // theApp->fontLoader().metrics(LyXFont(LyXFont::ALL_SANE)).width('M')
// but this estimate might not be more accurate as the screen font
// is different then the latex font.
#include "lyxlex.h"
#include "outputparams.h"
+#include "frontends/Application.h"
+#include "frontends/FontLoader.h"
+#include "frontends/FontMetrics.h"
#include "frontends/Painter.h"
-#include "frontends/font_metrics.h"
#include "support/lstrings.h"
tmpl()->metrics(mi, dim);
dim.asc += 5;
dim.des += 5;
- dim.wid += 10 + font_metrics::width(prefix(), mi.base.font);
+ dim.wid += 10
+ + theApp->fontLoader().metrics(mi.base.font).width(prefix());
dim_ = dim;
}
pi.pain.text(x + 2, y, prefix(), font);
// body
- tmpl()->draw(pi, x + font_metrics::width(prefix(), p.base.font) + 5, y);
+ tmpl()->draw(pi,
+ x + theApp->fontLoader().metrics(p.base.font).width(prefix()) + 5,
+ y);
setPosCache(pi, x, y);
}
#include "MathMLStream.h"
#include "MathStream.h"
+#include "frontends/Application.h"
+#include "frontends/FontLoader.h"
+#include "frontends/FontMetrics.h"
+
#include "support/lstrings.h"
void InsetMathBig::metrics(MetricsInfo & mi, Dimension & dim) const
{
- double const h = mathed_char_ascent(mi.base.font, 'I');
+ double const h
+ = theApp->fontLoader().metrics(mi.base.font).ascent('I');
double const f = increase();
dim_.wid = 6;
dim_.asc = int(h + f * h);
#include "support/lstrings.h"
#include "TextPainter.h"
+#include "frontends/Application.h"
+#include "frontends/FontLoader.h"
+#include "frontends/FontMetrics.h"
+
using std::auto_ptr;
extern bool has_math_fonts;
whichFont(font_, code_, mi);
mathed_char_dim(font_, char_, dim_);
if (isBinaryOp(char_, code_))
- width_ += 2 * font_metrics::width(' ', font_);
+ width_ += 2 * theApp->fontLoader().metrics(font_).width(' ');
lyxerr << "InsetMathChar::metrics: " << dim << endl;
#endif
width_ = dim.wid;
#include "lyxlex.h"
#include "LColor.h"
+#include "frontends/Application.h"
+#include "frontends/FontLoader.h"
+#include "frontends/FontMetrics.h"
#include "frontends/Painter.h"
-#include "frontends/font_metrics.h"
#include "support/lstrings.h"
cell(1).metrics(mi);
docstring dp = prefix();
dim.wid = cell(0).width() + cell(1).width() + 20
- + font_metrics::width(dp, mi.base.font);
+ + theApp->fontLoader().metrics(mi.base.font).width(dp);
dim.asc = std::max(cell(0).ascent(), cell(1).ascent()) + 7;
dim.des = std::max(cell(0).descent(), cell(1).descent()) + 7;
dim_ = dim;
#endif
docstring dp = prefix();
pi.pain.text(x + 2, y, dp, font);
- x += font_metrics::width(dp, pi.base.font) + 6;
+ // FIXME: Painter text should retain the drawn text width
+ x += theApp->fontLoader().metrics(font).width(dp) + 6;
int const w0 = cell(0).width();
int const w1 = cell(1).width();
#include "LColor.h"
#include "frontends/Application.h"
-#include "frontends/Painter.h"
-#include "frontends/font_metrics.h"
#include "frontends/FontLoader.h"
+#include "frontends/FontMetrics.h"
+#include "frontends/Painter.h"
#include <map>
#include <sstream>
void mathed_char_dim(LyXFont const & font, unsigned char c, Dimension & dim)
{
- dim.des = font_metrics::descent(c, font);
- dim.asc = font_metrics::ascent(c, font);
- dim.wid = mathed_char_width(font, c);
-}
-
-
-int mathed_char_ascent(LyXFont const & font, unsigned char c)
-{
- return font_metrics::ascent(c, font);
-}
-
-
-int mathed_char_descent(LyXFont const & font, unsigned char c)
-{
- return font_metrics::descent(c, font);
+ lyx::frontend::FontMetrics const & fm =
+ theApp->fontLoader().metrics(font);
+ dim.des = fm.descent(c);
+ dim.asc = fm.ascent(c);
+ dim.wid = fm.width(c);
}
int mathed_char_width(LyXFont const & font, unsigned char c)
{
- return font_metrics::width(c, font);
+ return theApp->fontLoader().metrics(font).width(c);
}
void mathed_string_dim(LyXFont const & font, string const & s, Dimension & dim)
{
+ lyx::frontend::FontMetrics const & fm =
+ theApp->fontLoader().metrics(font);
#if 1
dim.asc = 0;
dim.des = 0;
for (string::const_iterator it = s.begin(); it != s.end(); ++it) {
- dim.asc = max(dim.asc, font_metrics::ascent(*it, font));
- dim.des = max(dim.des, font_metrics::descent(*it, font));
+ dim.asc = max(dim.asc, fm.ascent(*it));
+ dim.des = max(dim.des, fm.descent(*it));
}
#else
- dim.asc = font_metrics::maxAscent(font);
- dim.des = font_metrics::maxDescent(font);
+ dim.asc = fm.maxAscent();
+ dim.des = fm.maxDescent();
#endif
- docstring ds(s.begin(), s.end());
- dim.wid = font_metrics::width(ds, font);
+ docstring ds(s.begin(), s.end());
+ dim.wid = fm.width(ds);
}
int mathed_string_width(LyXFont const & font, string const & s)
{
- docstring ds(s.begin(), s.end());
- return font_metrics::width(ds, font);
+ docstring ds(s.begin(), s.end());
+ return theApp->fontLoader().metrics(font).width(ds);
}
void math_font_max_dim(LyXFont const & font, int & asc, int & des)
{
- asc = font_metrics::maxAscent(font);
- des = font_metrics::maxDescent(font);
+ lyx::frontend::FontMetrics const & fm =
+ theApp->fontLoader().metrics(font);
+ asc = fm.maxAscent();
+ des = fm.maxDescent();
}
void mathed_char_dim(LyXFont const &, unsigned char c, Dimension & dim);
int mathed_char_width(LyXFont const &, unsigned char c);
-int mathed_char_ascent(LyXFont const &, unsigned char c);
-int mathed_char_descent(LyXFont const &, unsigned char c);
void mathed_draw_deco(PainterInfo & pi, int x, int y, int w, int h,
std::string const & name);
#include "ParagraphParameters.h"
#include "vspace.h"
-#include "frontends/font_metrics.h"
+#include "frontends/Application.h"
+#include "frontends/FontLoader.h"
+#include "frontends/FontMetrics.h"
#include "frontends/nullpainter.h"
#include "frontends/Painter.h"
using lyx::docstring;
using lyx::frontend::Painter;
using lyx::frontend::NullPainter;
+using lyx::frontend::FontMetrics;
+
using lyx::char_type;
using lyx::pos_type;
using lyx::pit_type;
str += c;
++vpos;
- int const width = font_metrics::width(c, font);
+ int const width = theApp->fontLoader().metrics(font).width(c);
int dx = 0;
for (pos_type i = pos - 1; i >= 0; --i) {
str += c;
++vpos;
- int const width = font_metrics::width(c, font);
+ int const width = theApp->fontLoader().metrics(font).width(c);
int dx = 0;
for (pos_type i = pos - 1; i >= 0; --i) {
//lyxerr << "paint row: yo_ " << yo_ << "\n";
#if 0
pain_.text(int(x_), yo_, str, font);
- x_ += font_metrics::width(str, font);
+ x_ += theApp->fontLoader().metrics(font).width(str);
#else
pain_.text(int(x_), yo_, &str[0], str.size(), font);
- x_ += font_metrics::width(&str[0], str.size(), font);
+ x_ += theApp->fontLoader().metrics(font).width(&str[0], str.size());
#endif
}
int a = 0;
int d = 0;
docstring dlab(label.begin(), label.end());
- font_metrics::rectText(dlab, pb_font, w, a, d);
+ theApp->fontLoader().metrics(pb_font).rectText(dlab, w, a, d);
int const text_start = int(xo_ + (width_ - w) / 2);
int const text_end = text_start + w;
|| is_seq)) {
LyXFont const font = getLabelFont();
+ FontMetrics const & fm =
+ theApp->fontLoader().metrics(font);
+
string const str = par_.getLabelstring();
if (!str.empty()) {
double x = x_;
spacing_val = buffer.params().spacing().getValue();
}
- int const labeladdon = int(font_metrics::maxHeight(font) * layout->spacing.getValue() * spacing_val);
+ int const labeladdon = int(fm.maxHeight() * layout->spacing.getValue() * spacing_val);
- int const maxdesc = int(font_metrics::maxDescent(font) * layout->spacing.getValue() * spacing_val)
+ int const maxdesc = int(fm.maxDescent() * layout->spacing.getValue() * spacing_val)
+ int(layout->parsep) * defaultRowHeight();
if (is_rtl) {
x = width_ - leftMargin() -
- font_metrics::width(dstr, font);
+ fm.width(dstr);
}
pain_.text(int(x), yo_ - maxdesc - labeladdon, dstr, font);
docstring dlab(lab.begin(), lab.end());
if (is_rtl) {
x = width_ - leftMargin()
- + font_metrics::width(dlab, font);
+ + fm.width(dlab);
} else {
- x = x_ - font_metrics::width(dlab, font)
- - font_metrics::width(dstr, font);
+ x = x_ - fm.width(dlab)
+ - fm.width(dstr);
}
pain_.text(int(x), yo_, dstr, font);
else
spacing_val = buffer.params().spacing().getValue();
- int const labeladdon = int(font_metrics::maxHeight(font) * layout->spacing.getValue() * spacing_val);
+ FontMetrics const & fm =
+ theApp->fontLoader().metrics(font);
+
+ int const labeladdon = int(fm.maxHeight()
+ * layout->spacing.getValue() * spacing_val);
int maxdesc =
- int(font_metrics::maxDescent(font) * layout->spacing.getValue() * spacing_val
+ int(fm.maxDescent() * layout->spacing.getValue() * spacing_val
+ (layout->labelbottomsep * defaultRowHeight()));
double x = x_;
if (is_rtl)
x = leftMargin();
x += (width_ - text_.rightMargin(par_) - leftMargin()) / 2;
- x -= font_metrics::width(dstr, font) / 2;
+ x -= fm.width(dstr) / 2;
} else if (is_rtl) {
- x = width_ - leftMargin() -
- font_metrics::width(dstr, font);
+ x = width_ - leftMargin() - fm.width(dstr);
}
pain_.text(int(x), yo_ - maxdesc - labeladdon, dstr, font);
}
case END_LABEL_BOX:
case END_LABEL_FILLED_BOX: {
LyXFont const font = getLabelFont();
- int const size = int(0.75 * font_metrics::maxAscent(font));
+ FontMetrics const & fm = theApp->fontLoader().metrics(font);
+ int const size = int(0.75 * fm.maxAscent());
int const y = yo_ - size;
int x = is_rtl ? nestMargin() + changebarMargin() : width_ - size;
case END_LABEL_STATIC: {
LyXFont font = getLabelFont();
+ FontMetrics const & fm = theApp->fontLoader().metrics(font);
string const & str = par_.layout()->endlabelstring();
docstring dstr(str.begin(), str.end());
double const x = is_rtl ?
- x_ - font_metrics::width(dstr, font)
+ x_ - fm.width(dstr)
: - text_.rightMargin(par_) - row_.width();
pain_.text(int(x), yo_, dstr, font);
break;
// We also don't paint across things like tables
if (running_strikeout && (highly_editable_inset || !is_struckout)) {
// Calculate 1/3 height of the buffer's default font
- int const middle =
- yo_ -
- font_metrics::maxAscent(bv_.buffer()->params().getFont()) / 3;
+ FontMetrics const & fm = theApp->fontLoader().metrics(
+ bv_.buffer()->params().getFont());
+ int const middle = yo_ - fm.maxAscent() / 3;
pain_.line(last_strikeout_x, middle, int(x_), middle,
LColor::strikeout, Painter::line_solid, Painter::line_thin);
running_strikeout = false;
if (body_pos > 0 && pos == body_pos - 1) {
string lab = layout->labelsep;
docstring dlab(lab.begin(), lab.end());
- int const lwidth = font_metrics::width(dlab,
- getLabelFont());
+ int const lwidth =
+ theApp->fontLoader().metrics(getLabelFont()).width(dlab);
x_ += label_hfill_ + lwidth - width_pos;
}
// if we reach the end of a struck out range, paint it
if (running_strikeout) {
// calculate 1/3 height of the buffer's default font
- int const middle =
- yo_ -
- font_metrics::maxAscent(bv_.buffer()->params().getFont()) / 3;
+ FontMetrics const & fm = theApp->fontLoader().metrics(
+ bv_.buffer()->params().getFont());
+ int const middle = yo_ - fm.maxAscent() / 3;
pain_.line(last_strikeout_x, middle, int(x_), middle,
LColor::strikeout, Painter::line_solid, Painter::line_thin);
running_strikeout = false;
#include "vspace.h"
#include "WordLangTuple.h"
-#include "frontends/font_metrics.h"
+#include "frontends/Application.h"
+#include "frontends/FontLoader.h"
+#include "frontends/FontMetrics.h"
#include "frontends/Painter.h"
#include "insets/insettext.h"
using lyx::cap::cutSelection;
using lyx::cap::pasteParagraphList;
+using lyx::frontend::FontMetrics;
+
using std::auto_ptr;
using std::advance;
using std::distance;
Encodings::isComposeChar_hebrew(c))
return 0;
}
- return font_metrics::width(c, font);
+ return theApp->fontLoader().metrics(font).width(c);
}
if (c == Paragraph::META_INSET)
return par.getInset(pos)->width();
- return font_metrics::width(c, font);
+ return theApp->fontLoader().metrics(font).width(c);
}
string leftm = tclass.leftmargin();
docstring dleft(leftm.begin(), leftm.end());
- l_margin += font_metrics::signedWidth(dleft, params.getFont());
+ l_margin += theApp->fontLoader().metrics(params.getFont()).signedWidth(dleft);
if (par.getDepth() != 0) {
// find the next level paragraph
parindent.erase();
LyXFont const labelfont = getLabelFont(par);
+ FontMetrics const & labelfont_metrics = theApp->fontLoader().metrics(labelfont);
+
switch (layout->margintype) {
case MARGIN_DYNAMIC:
if (!layout->leftmargin.empty()) {
string leftm = layout->leftmargin;
docstring dleft(leftm.begin(), leftm.end());
- l_margin += font_metrics::signedWidth(dleft,
- params.getFont());
+ l_margin += theApp->fontLoader().metrics(params.getFont()).signedWidth(dleft);
}
if (!par.getLabelstring().empty()) {
string labin = layout->labelindent;
docstring dlabin(labin.begin(), labin.end());
- l_margin += font_metrics::signedWidth(dlabin,
- labelfont);
+ l_margin += labelfont_metrics.signedWidth(dlabin);
string labstr = par.getLabelstring();
docstring dlabstr(labstr.begin(), labstr.end());
- l_margin += font_metrics::width(dlabstr,
- labelfont);
+ l_margin += labelfont_metrics.width(dlabstr);
string labsep = layout->labelsep;
docstring dlabsep(labsep.begin(), labsep.end());
- l_margin += font_metrics::width(dlabsep, labelfont);
+ l_margin += labelfont_metrics.width(dlabsep);
}
break;
case MARGIN_MANUAL: {
string labin = layout->labelindent;
docstring dlabin(labin.begin(), labin.end());
- l_margin += font_metrics::signedWidth(dlabin, labelfont);
+ l_margin += labelfont_metrics.signedWidth(dlabin);
// The width of an empty par, even with manual label, should be 0
if (!par.empty() && pos >= par.beginOfBody()) {
if (!par.getLabelWidthString().empty()) {
string labstr = par.getLabelWidthString();
docstring dlabstr(labstr.begin(), labstr.end());
- l_margin += font_metrics::width(dlabstr,
- labelfont);
+ l_margin += labelfont_metrics.width(dlabstr);
string labsep = layout->labelsep;
docstring dlabsep(labsep.begin(), labsep.end());
- l_margin += font_metrics::width(dlabsep, labelfont);
+ l_margin += labelfont_metrics.width(dlabsep);
}
}
break;
case MARGIN_STATIC: {
string leftm = layout->leftmargin;
docstring dleft(leftm.begin(), leftm.end());
- l_margin += font_metrics::signedWidth(dleft, params.getFont()) * 4
- / (par.getDepth() + 4);
+ l_margin +=
+ theApp->fontLoader().metrics(params.getFont()).signedWidth(dleft)
+ * 4 / (par.getDepth() + 4);
break;
}
if (pos >= par.beginOfBody()) {
string leftm = layout->leftmargin;
docstring dleft(leftm.begin(), leftm.end());
- l_margin += font_metrics::signedWidth(dleft,
- labelfont);
+ l_margin += labelfont_metrics.signedWidth(dleft);
} else {
string labin = layout->labelindent;
docstring dlabin(labin.begin(), labin.end());
- l_margin += font_metrics::signedWidth(dlabin,
- labelfont);
+ l_margin += labelfont_metrics.signedWidth(dlabin);
}
} else if (pos != 0
// Special case to fix problems with
&& !isFirstInSequence(pit, pars_))) {
string leftm = layout->leftmargin;
docstring dleft(leftm.begin(), leftm.end());
- l_margin += font_metrics::signedWidth(dleft,
- labelfont);
+ l_margin += labelfont_metrics.signedWidth(dleft);
} else if (layout->labeltype != LABEL_TOP_ENVIRONMENT
&& layout->labeltype != LABEL_BIBLIO
&& layout->labeltype !=
LABEL_CENTERED_TOP_ENVIRONMENT) {
string labin = layout->labelindent;
docstring dlabin(labin.begin(), labin.end());
- l_margin += font_metrics::signedWidth(dlabin,
- labelfont);
+ l_margin += labelfont_metrics.signedWidth(dlabin);
string labsep = layout->labelsep;
docstring dlabsep(labsep.begin(), labsep.end());
- l_margin += font_metrics::width(dlabsep, labelfont);
+ l_margin += labelfont_metrics.width(dlabsep);
string labstr = par.getLabelstring();
docstring dlabstr(labstr.begin(), labstr.end());
- l_margin += font_metrics::width(dlabstr, labelfont);
+ l_margin += labelfont_metrics.width(dlabstr);
}
break;
for ( ; rit != end; ++rit)
if (rit->fill() < minfill)
minfill = rit->fill();
- l_margin += font_metrics::signedWidth(layout->leftmargin,
- params.getFont());
+ l_margin += theApp->fontLoader().metrics(params.getFont()).signedWidth(layout->leftmargin);
l_margin += minfill;
#endif
// also wrong, but much shorter.
BufferParams::PARSEP_INDENT))
{
docstring din(parindent.begin(), parindent.end());
- l_margin += font_metrics::signedWidth(din, params.getFont());
+ l_margin += theApp->fontLoader().metrics(params.getFont()).signedWidth(din);
}
return l_margin;
docstring dtrmarg(trmarg.begin(), trmarg.end());
string lrmarg = par.layout()->rightmargin;
docstring dlrmarg(lrmarg.begin(), lrmarg.end());
+ FontMetrics const & fm = theApp->fontLoader().metrics(params.getFont());
int const r_margin =
::rightMargin()
- + font_metrics::signedWidth(dtrmarg,
- params.getFont())
- + font_metrics::signedWidth(dlrmarg,
- params.getFont())
+ + fm.signedWidth(dtrmarg)
+ + fm.signedWidth(dlrmarg)
* 4 / (par.getDepth() + 4);
return r_margin;
FontIterator fi = FontIterator(*this, par, pos);
pos_type point = end;
pos_type i = pos;
+ FontMetrics const & fm = theApp->fontLoader().metrics(getLabelFont(par));
for ( ; i < end; ++i, ++fi) {
char_type const c = par.getChar(i);
int thiswidth = singleWidth(par, i, c, *fi);
if (body_pos && i == body_pos) {
string lsep = layout->labelsep;
docstring dlsep(lsep.begin(), lsep.end());
- int add = font_metrics::width(dlsep, getLabelFont(par));
+ int add = fm.width(dlsep);
if (par.isLineSeparator(i - 1))
add -= singleWidth(par, i - 1);
pos_type const body_pos = par.beginOfBody();
pos_type i = row.pos();
+ FontMetrics const & fm = theApp->fontLoader().metrics(getLabelFont(par));
+
if (i < end) {
FontIterator fi = FontIterator(*this, par, i);
for ( ; i < end; ++i, ++fi) {
if (body_pos > 0 && i == body_pos) {
- w += font_metrics::width(dlsep, getLabelFont(par));
+ w += fm.width(dlsep);
if (par.isLineSeparator(i - 1))
w -= singleWidth(par, i - 1);
w = max(w, labelEnd(pit));
}
if (body_pos > 0 && body_pos >= end) {
- w += font_metrics::width(dlsep, getLabelFont(par));
+ w += fm.width(dlsep);
if (end > 0 && par.isLineSeparator(end - 1))
w -= singleWidth(par, end - 1);
w = max(w, labelEnd(pit));
return 0;
docstring dlab(label.begin(), label.end());
- return max(0, font_metrics::width(dlab, getLabelFont(par)) - w);
+
+ FontMetrics const & fm = theApp->fontLoader().metrics(getLabelFont(par));
+
+ return max(0, fm.width(dlab) - w);
}
LyXFont labelfont = getLabelFont(par);
+ FontMetrics const & labelfont_metrics = theApp->fontLoader().metrics(labelfont);
+ FontMetrics const & fontmetrics = theApp->fontLoader().metrics(font);
+
// these are minimum values
double const spacing_val = layout->spacing.getValue() * spacing(par);
//lyxerr << "spacing_val = " << spacing_val << endl;
- int maxasc = int(font_metrics::maxAscent(font) * spacing_val);
- int maxdesc = int(font_metrics::maxDescent(font) * spacing_val);
+ int maxasc = int(fontmetrics.maxAscent() * spacing_val);
+ int maxdesc = int(fontmetrics.maxDescent() * spacing_val);
// insets may be taller
InsetList::const_iterator ii = par.insetlist.begin();
par.highestFontInRange(row.pos(), pos_end, size);
if (maxsize > font.size()) {
font.setSize(maxsize);
- maxasc = max(maxasc, font_metrics::maxAscent(font));
- maxdesc = max(maxdesc, font_metrics::maxDescent(font));
+ maxasc = max(maxasc, fontmetrics.maxAscent());
+ maxdesc = max(maxdesc, fontmetrics.maxDescent());
}
// This is nicer with box insets:
// layout is printed in an extra row
if (layout->counter == "chapter"
&& !par.params().labelString().empty()) {
- labeladdon = int(font_metrics::maxHeight(labelfont)
+ labeladdon = int(labelfont_metrics.maxHeight()
* layout->spacing.getValue()
* spacing(par));
}
&& !par.getLabelstring().empty())
{
labeladdon = int(
- font_metrics::maxHeight(labelfont)
+ labelfont_metrics.maxHeight()
* layout->spacing.getValue()
* spacing(par)
+ (layout->topsep + layout->labelbottomsep) * dh);
{
string lsep = layout->labelsep;
docstring dlsep(lsep.begin(), lsep.end());
- result.x += font_metrics::width(dlsep, getLabelFont(par));
+ result.x += theApp->fontLoader().metrics(getLabelFont(par)).width(dlsep);
if (body_pos <= end)
result.x += result.label_hfill;
}
// Use font span to speed things up, see below
FontSpan font_span;
LyXFont font;
+ FontMetrics const & labelfm = theApp->fontLoader().metrics(getLabelFont(par));
for (pos_type vpos = row_pos; vpos < cursor_vpos; ++vpos) {
pos_type pos = bidi.vis2log(vpos);
if (body_pos > 0 && pos == body_pos - 1) {
string lsep = par.layout()->labelsep;
docstring dlsep(lsep.begin(), lsep.end());
- x += m.label_hfill
- + font_metrics::width(dlsep,
- getLabelFont(par));
+ x += m.label_hfill + labelfm.width(dlsep);
if (par.isLineSeparator(body_pos - 1))
x -= singleWidth(par, body_pos - 1);
}
#include "vspace.h"
#include "frontends/Application.h"
-#include "frontends/font_metrics.h"
+#include "frontends/FontLoader.h"
+#include "frontends/FontMetrics.h"
#include "insets/insetenv.h"
return 0;
}
+ lyx::frontend::FontMetrics const & fm = theApp->fontLoader().metrics(
+ getLabelFont(par));
+
while (vc < end && tmpx <= x) {
c = bidi.vis2log(vc);
last_tmpx = tmpx;
if (body_pos > 0 && c == body_pos - 1) {
string lsep = layout->labelsep;
docstring dlsep(lsep.begin(), lsep.end());
- tmpx += r.label_hfill +
- font_metrics::width(dlsep, getLabelFont(par));
+ tmpx += r.label_hfill + fm.width(dlsep);
if (par.isLineSeparator(body_pos - 1))
tmpx -= singleWidth(par, body_pos - 1);
}
int defaultRowHeight()
{
- return int(font_metrics::maxHeight(LyXFont(LyXFont::ALL_SANE)) * 1.2);
+ return int(theApp->fontLoader().metrics(LyXFont(LyXFont::ALL_SANE)).maxHeight() * 1.2);
}