This commit is a big rework of the FontLoader/FontMetrics interaction. Only Qt4 for now, I would be grateful is somebody steps up for qt3 and gtk.

Basically, I replaced all methods in the font_metrics namespace by a proper virtual interface FontMetrics. The FontLoader is _the_ container for FontMetrics.

This patch should also bring some optimizations in a number of place in the code. This is because we do not need any more to search for the LyXFont at each font_metrics call. In effect, the speed advantage is not as sensible and this is a bit deceiving considering that this was my primary motivation behind the patch. But I like the patch anyway as it cleans up the relation and interfacing between fonts, metrics and frontends.

* frontends/FontMetrics.h: new virtual interface. Renamed from font_metrics.h

* qt4/GuiFontMetrics: corresponding qt4 implememtation. Renamed from qfont_metrics.C. The smallCaps particular case treatment has been transfered here as well as the width cache for MacOSX and Windows.

* qt4/QLPainter.C: the smallCapsText has been reworked to return the width of the drawn text.C

all other files: replace font_metric helper function call with corresponding FontMetrics method calls.



git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@15265 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Abdelrazak Younes 2006-10-07 16:15:06 +00:00
parent 99fc6935a5
commit 00edcc582f
45 changed files with 713 additions and 533 deletions

View File

@ -433,6 +433,7 @@ src_frontends_header_files = Split('''
Dialogs.h Dialogs.h
FileDialog.h FileDialog.h
FontLoader.h FontLoader.h
FontMetrics.h
Gui.h Gui.h
LyXKeySym.h LyXKeySym.h
LyXKeySymFactory.h LyXKeySymFactory.h
@ -443,7 +444,6 @@ src_frontends_header_files = Split('''
Timeout.h Timeout.h
Toolbars.h Toolbars.h
WorkArea.h WorkArea.h
font_metrics.h
guiapi.h guiapi.h
key_state.h key_state.h
lyx_gui.h lyx_gui.h
@ -1236,6 +1236,7 @@ src_frontends_qt4_files = Split('''
GuiApplication.C GuiApplication.C
GuiClipboard.C GuiClipboard.C
GuiFontLoader.C GuiFontLoader.C
GuiFontMetrics.C
GuiImplementation.C GuiImplementation.C
GuiSelection.C GuiSelection.C
GuiView.C GuiView.C
@ -1335,7 +1336,6 @@ src_frontends_qt4_files = Split('''
lengthcombo.C lengthcombo.C
lyx_gui.C lyx_gui.C
panelstack.C panelstack.C
qfont_metrics.C
qfontexample.C qfontexample.C
qsetborder.C qsetborder.C
qtTimeout.C qtTimeout.C

View File

@ -62,7 +62,8 @@
#include "frontends/Alert.h" #include "frontends/Alert.h"
#include "frontends/Application.h" #include "frontends/Application.h"
#include "frontends/FileDialog.h" #include "frontends/FileDialog.h"
#include "frontends/font_metrics.h" #include "frontends/FontLoader.h"
#include "frontends/FontMetrics.h"
#include "graphics/Previews.h" #include "graphics/Previews.h"
@ -330,9 +331,10 @@ void BufferView::resize()
bool BufferView::fitCursor() bool BufferView::fitCursor()
{ {
if (bv_funcs::status(this, cursor_) == bv_funcs::CUR_INSIDE) { if (bv_funcs::status(this, cursor_) == bv_funcs::CUR_INSIDE) {
LyXFont const font = cursor_.getFont(); lyx::frontend::FontMetrics const & fm
int const asc = font_metrics::maxAscent(font); = theApp->fontLoader().metrics(cursor_.getFont());
int const des = font_metrics::maxDescent(font); int const asc = fm.maxAscent();
int const des = fm.maxDescent();
Point const p = bv_funcs::getPos(cursor_, cursor_.boundary()); Point const p = bv_funcs::getPos(cursor_, cursor_.boundary());
if (p.y_ - asc >= 0 && p.y_ + des < height_) if (p.y_ - asc >= 0 && p.y_ + des < height_)
return false; return false;

View File

@ -44,7 +44,6 @@
#include "support/limited_stack.h" #include "support/limited_stack.h"
#include "frontends/Application.h" #include "frontends/Application.h"
#include "frontends/font_metrics.h"
#include <boost/assert.hpp> #include <boost/assert.hpp>
#include <boost/bind.hpp> #include <boost/bind.hpp>

View File

@ -11,7 +11,9 @@
#include <config.h> #include <config.h>
#include "dimension.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::operator+=(Dimension const & dim)
@ -26,7 +28,8 @@ void Dimension::operator+=(Dimension const & dim)
void Dimension::clear(LyXFont const & font) void Dimension::clear(LyXFont const & font)
{ {
asc = font_metrics::maxAscent(font); lyx::frontend::FontMetrics const & fm = theApp->fontLoader().metrics(font);
des = font_metrics::maxDescent(font); asc = fm.maxAscent();
des = fm.maxDescent();
wid = 0; wid = 0;
} }

View File

@ -17,6 +17,8 @@ class LyXFont;
namespace lyx { namespace lyx {
namespace frontend { namespace frontend {
class FontMetrics;
/// Hold info about a particular font /// Hold info about a particular font
class FontLoader class FontLoader
{ {
@ -31,6 +33,9 @@ public:
/// Is the given font available ? /// Is the given font available ?
virtual bool available(LyXFont const & f) = 0; virtual bool available(LyXFont const & f) = 0;
/// Get the Font metrics for this LyXFont
virtual FontMetrics const & metrics(LyXFont const & f) = 0;
}; };
} // namespace frontend } // namespace frontend

View File

@ -1,11 +1,12 @@
// -*- C++ -*- // -*- C++ -*-
/** /**
* \file font_metrics.h * \file FontMetrics.h
* This file is part of LyX, the document processor. * This file is part of LyX, the document processor.
* Licence details can be found in the file COPYING. * Licence details can be found in the file COPYING.
* *
* \author unknown * \author unknown
* \author John Levon * \author John Levon
* \author Abdelrazak Younes
* *
* Full author contact details are available in file CREDITS. * Full author contact details are available in file CREDITS.
*/ */
@ -15,11 +16,8 @@
#include "support/docstring.h" #include "support/docstring.h"
class LyXFont;
/** /**
* A namespace holding helper functions for determining * A class holding helper functions for determining
* the screen dimensions of fonts. * the screen dimensions of fonts.
* *
* The geometry is the standard typographical geometry, * The geometry is the standard typographical geometry,
@ -41,63 +39,79 @@ class LyXFont;
* --------------+----------+-------<maxDescent * --------------+----------+-------<maxDescent
* *
*/ */
namespace font_metrics {
namespace lyx {
namespace frontend {
class FontMetrics
{
public:
virtual ~FontMetrics() {}
/// return the maximum ascent of the font /// return the maximum ascent of the font
int maxAscent(LyXFont const & f); virtual int maxAscent() const = 0;
/// return the maximum descent of the font /// return the maximum descent of the font
int maxDescent(LyXFont const & f); virtual int maxDescent() const = 0;
/// 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 /// return the ascent of the char in the font
int ascent(lyx::char_type c, LyXFont const & f); virtual int ascent(lyx::char_type c) const = 0;
/// return the descent of the char in the font /// return the descent of the char in the font
int descent(lyx::char_type c, LyXFont const & f); virtual int descent(lyx::char_type c) const = 0;
/// 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 /// return the left bearing of the char in the font
int lbearing(lyx::char_type c, LyXFont const & f); virtual int lbearing(lyx::char_type c) const = 0;
/// return the right bearing of the char in the font /// return the right bearing of the char in the font
int rbearing(lyx::char_type c, LyXFont const & f); virtual int rbearing(lyx::char_type c) const = 0;
/// 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 /// return the width of the string in the font
int width(lyx::char_type const * s, size_t n, LyXFont const & f); virtual int width(lyx::char_type const * s, size_t n) const = 0;
/// 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 ?? /// FIXME ??
int signedWidth(lyx::docstring const & s, LyXFont const & f); virtual int signedWidth(lyx::docstring const & s) const = 0;
/** /**
* fill in width,ascent,descent with the values for the * fill in width,ascent,descent with the values for the
* given string in the font. * given string in the font.
*/ */
void rectText(lyx::docstring const & str, LyXFont const & font, virtual void rectText(lyx::docstring const & str,
int & width, int & width,
int & ascent, int & ascent,
int & descent); int & descent) const = 0;
/** /**
* fill in width,ascent,descent with the values for the * fill in width,ascent,descent with the values for the
* given string in the font for a button. * given string in the font for a button.
*/ */
void buttonText(lyx::docstring const & str, LyXFont const & font, virtual void buttonText(lyx::docstring const & str,
int & width, int & width,
int & ascent, int & ascent,
int & descent); 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 #endif // FONT_METRICS_H

View File

@ -22,6 +22,7 @@ libfrontends_la_SOURCES = \
Dialogs.h \ Dialogs.h \
FileDialog.h \ FileDialog.h \
FontLoader.h \ FontLoader.h \
FontMetrics.h \
LyXKeySym.h \ LyXKeySym.h \
LyXKeySymFactory.h \ LyXKeySymFactory.h \
LyXView.C \ LyXView.C \
@ -38,7 +39,6 @@ libfrontends_la_SOURCES = \
Selection.h \ Selection.h \
WorkArea.C \ WorkArea.C \
WorkArea.h \ WorkArea.h \
font_metrics.h \
guiapi.h \ guiapi.h \
guiapi.C \ guiapi.C \
key_state.h \ key_state.h \

View File

@ -11,8 +11,11 @@
#include <config.h> #include <config.h>
#include "Painter.h" #include "frontends/Painter.h"
#include "font_metrics.h"
#include "frontends/Application.h"
#include "frontends/FontLoader.h"
#include "frontends/FontMetrics.h"
#include "LColor.h" #include "LColor.h"
#include "lyxfont.h" #include "lyxfont.h"
@ -59,7 +62,8 @@ void Painter::rectText(int x, int y,
int ascent; int ascent;
int descent; 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) if (back != LColor::none)
fillRectangle(x + 1, y - ascent + 1, width - 1, fillRectangle(x + 1, y - ascent + 1, width - 1,
@ -78,7 +82,8 @@ void Painter::buttonText(int x, int y, docstring const & str, LyXFont const & fo
int ascent; int ascent;
int descent; 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); button(x, y - ascent, width, descent + ascent);
text(x + 4, y, str, font); text(x + 4, y, str, font);
@ -87,8 +92,10 @@ void Painter::buttonText(int x, int y, docstring const & str, LyXFont const & fo
void Painter::underline(LyXFont const & f, int x, int y, int width) void Painter::underline(LyXFont const & f, int x, int y, int width)
{ {
int const below = max(font_metrics::maxDescent(f) / 2, 2); FontMetrics const & fm = theApp->fontLoader().metrics(f);
int const height = max((font_metrics::maxDescent(f) / 4) - 1, 1);
int const below = max(fm.maxDescent() / 2, 2);
int const height = max((fm.maxDescent() / 4) - 1, 1);
if (height < 2) if (height < 2)
line(x, y + below, x + width, y + below, f.color()); line(x, y + below, x + width, y + below, f.color());

View File

@ -13,9 +13,12 @@
#include <config.h> #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 "funcrequest.h"
#include "lyx_gui.h" #include "lyx_gui.h"
#include "lyxfunc.h" #include "lyxfunc.h"
@ -372,8 +375,9 @@ void WorkArea::showCursor()
shape = BAR_SHAPE; shape = BAR_SHAPE;
LyXFont const font = buffer_view_->cursor().getFont(); LyXFont const font = buffer_view_->cursor().getFont();
int const asc = font_metrics::maxAscent(font); FontMetrics const & fm = theApp->fontLoader().metrics(font);
int const des = font_metrics::maxDescent(font); int const asc = fm.maxAscent();
int const des = fm.maxDescent();
int h = asc + des; int h = asc + des;
int x = 0; int x = 0;
int y = 0; int y = 0;

View File

@ -220,9 +220,7 @@ void GuiFontLoader::update()
QLFontInfo::QLFontInfo(LyXFont const & f) QLFontInfo::QLFontInfo(LyXFont const & f)
: metrics(font)
{ {
string const pat = symbolFamily(f.family()); string const pat = symbolFamily(f.family());
if (!pat.empty()) { if (!pat.empty()) {
bool tmp; bool tmp;
@ -246,9 +244,6 @@ QLFontInfo::QLFontInfo(LyXFont const & f)
} }
} }
font.setPointSizeF(convert<double>(lyxrc.font_sizes[f.size()])
* lyxrc.zoom / 100.0);
switch (f.series()) { switch (f.series()) {
case LyXFont::MEDIUM_SERIES: case LyXFont::MEDIUM_SERIES:
font.setWeight(QFont::Normal); font.setWeight(QFont::Normal);
@ -274,9 +269,6 @@ QLFontInfo::QLFontInfo(LyXFont const & f)
<< "' matched by\n" << fromqstr(font.rawName()) << endl; << "' matched by\n" << fromqstr(font.rawName()) << endl;
} }
lyxerr[Debug::FONT] << "The font has size: "
<< font.pointSizeF() << endl;
// Is this an exact match? // Is this an exact match?
if (font.exactMatch()) if (font.exactMatch())
lyxerr[Debug::FONT] << "This font is an exact match" << endl; lyxerr[Debug::FONT] << "This font is an exact match" << endl;
@ -286,21 +278,27 @@ QLFontInfo::QLFontInfo(LyXFont const & f)
lyxerr[Debug::FONT] << "XFLD: " << fromqstr(font.rawName()) << 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 lyxerr[Debug::FONT] << "The font has size: "
int QLFontInfo::width(Uchar val) << font.pointSizeF() << endl;
{
QLFontInfo::WidthCache::const_iterator cit = widthcache.find(val); if (f.realShape() != LyXFont::SMALLCAPS_SHAPE) {
if (cit != widthcache.end()) metrics.reset(new GuiFontMetrics(font));
return cit->second; }
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) bool GuiFontLoader::available(LyXFont const & f)

View File

@ -14,18 +14,12 @@
#include "frontends/FontLoader.h" #include "frontends/FontLoader.h"
#include "GuiFontMetrics.h"
#include "encoding.h" #include "encoding.h"
#include "lyxfont.h" #include "lyxfont.h"
#include <QFont> #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 lyx {
namespace frontend { namespace frontend {
@ -41,21 +35,7 @@ public:
/// The font instance /// The font instance
QFont font; QFont font;
/// Metrics on the font /// Metrics on the font
QFontMetrics metrics; boost::scoped_ptr<GuiFontMetrics> 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
}; };
@ -69,21 +49,17 @@ public:
/// Destructor /// Destructor
virtual ~GuiFontLoader(); virtual ~GuiFontLoader();
/// Update fonts after zoom, dpi, font names, or norm change
virtual void update(); virtual void update();
/// Do we have anything matching?
virtual bool available(LyXFont const & f); 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 /// Get the QFont for this LyXFont
QFont const & get(LyXFont const & f) { QFont const & get(LyXFont const & f) {
return fontinfo(f).font; 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. /// Get font info (font + metrics) for the given LyX font.
QLFontInfo & fontinfo(LyXFont const & f) { QLFontInfo & fontinfo(LyXFont const & f) {

View File

@ -0,0 +1,200 @@
/**
* \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
}
}

View File

@ -0,0 +1,83 @@
// -*- 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

View File

@ -37,6 +37,7 @@ libqt4_la_SOURCES = \
GuiApplication.C GuiApplication.h \ GuiApplication.C GuiApplication.h \
GuiClipboard.h GuiClipboard.C \ GuiClipboard.h GuiClipboard.C \
GuiFontLoader.h GuiFontLoader.C \ GuiFontLoader.h GuiFontLoader.C \
GuiFontMetrics.h GuiFontMetrics.C \
GuiSelection.h GuiSelection.C \ GuiSelection.h GuiSelection.C \
GuiImplementation.h GuiImplementation.C \ GuiImplementation.h GuiImplementation.C \
LyXKeySymFactory.C \ LyXKeySymFactory.C \
@ -86,7 +87,6 @@ libqt4_la_SOURCES = \
lyx_gui.C \ lyx_gui.C \
panelstack.h panelstack.C \ panelstack.h panelstack.C \
qfontexample.h qfontexample.C \ qfontexample.h qfontexample.C \
qfont_metrics.C \
qlkey.h \ qlkey.h \
qt_helpers.h qt_helpers.C \ qt_helpers.h qt_helpers.C \
qtTimeout.C qtTimeout.h \ qtTimeout.C qtTimeout.h \

View File

@ -25,7 +25,7 @@
#include "language.h" #include "language.h"
#include "LColor.h" #include "LColor.h"
#include "frontends/font_metrics.h" #include "frontends/FontMetrics.h"
#include "support/unicode.h" #include "support/unicode.h"
@ -196,7 +196,7 @@ void QLPainter::text(int x, int y, char_type c, LyXFont const & f)
} }
void QLPainter::smallCapsText(int x, int y, int QLPainter::smallCapsText(int x, int y,
QString const & s, LyXFont const & f) QString const & s, LyXFont const & f)
{ {
LyXFont smallfont(f); LyXFont smallfont(f);
@ -204,24 +204,21 @@ void QLPainter::smallCapsText(int x, int y,
QFont const & qfont = guiApp->guiFontLoader().get(f); QFont const & qfont = guiApp->guiFontLoader().get(f);
QFont const & qsmallfont = guiApp->guiFontLoader().get(smallfont); QFont const & qsmallfont = guiApp->guiFontLoader().get(smallfont);
QFontMetrics const & qfontm = QFontMetrics(qfont);
QFontMetrics const & qsmallfontm = QFontMetrics(qsmallfont);
setQPainterPen(f.realColor()); setQPainterPen(f.realColor());
int tmpx = x; int textwidth = 0;
size_t ls = s.length(); size_t ls = s.length();
for (unsigned int i = 0; i < ls; ++i) { for (unsigned int i = 0; i < ls; ++i) {
QChar const c = s[i].toUpper(); QChar const c = s[i].toUpper();
if (c != s.at(i)) { if (c != s.at(i)) {
qp_->setFont(qsmallfont); qp_->setFont(qsmallfont);
qp_->drawText(tmpx, y, c);
tmpx += qsmallfontm.width(c);
} else { } else {
qp_->setFont(qfont); 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;
} }
@ -250,18 +247,23 @@ void QLPainter::text(int x, int y, char_type const * s, size_t ls,
str = ' ' + str; str = ' ' + str;
#endif #endif
QLFontInfo & fi = guiApp->guiFontLoader().fontinfo(f);
int textwidth;
if (f.realShape() != LyXFont::SMALLCAPS_SHAPE) { if (f.realShape() != LyXFont::SMALLCAPS_SHAPE) {
setQPainterPen(f.realColor()); 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. // We need to draw the text as LTR as we use our own bidi code.
qp_->setLayoutDirection(Qt::LeftToRight); qp_->setLayoutDirection(Qt::LeftToRight);
qp_->drawText(x, y, str); qp_->drawText(x, y, str);
textwidth = qp_->fontMetrics().width(str);
} else { } else {
smallCapsText(x, y, str, f); textwidth = smallCapsText(x, y, str, f);
} }
if (f.underbar() == LyXFont::ON) { if (f.underbar() == LyXFont::ON) {
underline(f, x, y, font_metrics::width(s, ls, f)); underline(f, x, y, textwidth);
} }
} }

View File

@ -125,7 +125,10 @@ public:
private: private:
/// draw small caps text /// 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); QString const & str, LyXFont const & f);
/// set pen parameters /// set pen parameters

View File

@ -1,186 +0,0 @@
/**
* \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;
}

View File

@ -123,6 +123,7 @@ QString const toqstr(string const & str)
QString const ucs4_to_qstring(char_type const * str, size_t ls) QString const ucs4_to_qstring(char_type const * str, size_t ls)
{ {
QString s; QString s;
s.reserve(ls);
for (size_t i = 0; i < ls; ++i) for (size_t i = 0; i < ls; ++i)
s.append(ucs4_to_qchar(str[i])); s.append(ucs4_to_qchar(str[i]));

View File

@ -20,7 +20,9 @@
#include "paragraph.h" #include "paragraph.h"
#include "ParagraphList.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/lstrings.h"
#include "support/std_ostream.h" #include "support/std_ostream.h"
@ -136,7 +138,10 @@ string const bibitemWidest(Buffer const & buffer)
// Does look like a hack? It is! (but will change at 0.13) // Does look like a hack? It is! (but will change at 0.13)
InsetBibitem const * bitem = 0; InsetBibitem const * bitem = 0;
// FIXME font is used unitialized, is that correct?
LyXFont font; LyXFont font;
lyx::frontend::FontMetrics const & fm =
theApp->fontLoader().metrics(font);
ParagraphList::const_iterator it = buffer.paragraphs().begin(); ParagraphList::const_iterator it = buffer.paragraphs().begin();
ParagraphList::const_iterator end = buffer.paragraphs().end(); ParagraphList::const_iterator end = buffer.paragraphs().end();
@ -147,7 +152,7 @@ string const bibitemWidest(Buffer const & buffer)
docstring const dlab(label.begin(), label.end()); docstring const dlab(label.begin(), label.end());
int const wx = int const wx =
font_metrics::width(dlab, font); fm.width(dlab);
if (wx > w) { if (wx > w) {
w = wx; w = wx;
bitem = it->bibitem(); bitem = it->bibitem();

View File

@ -26,7 +26,9 @@
#include "metricsinfo.h" #include "metricsinfo.h"
#include "paragraph.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 "frontends/Painter.h"
#include "support/lstrings.h" #include "support/lstrings.h"
@ -125,7 +127,7 @@ void InsetCaption::metrics(MetricsInfo & mi, Dimension & dim) const
LCursor cur = mi.base.bv->cursor(); LCursor cur = mi.base.bv->cursor();
setLabel(cur); setLabel(cur);
docstring dlab(label.begin(), label.end()); 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_; dim.wid = labelwidth_;
Dimension textdim; Dimension textdim;
InsetText::metrics(mi, textdim); InsetText::metrics(mi, textdim);
@ -153,7 +155,9 @@ void InsetCaption::draw(PainterInfo & pi, int x, int y) const
LCursor cur = pi.base.bv->cursor(); LCursor cur = pi.base.bv->cursor();
setLabel(cur); setLabel(cur);
docstring dlab(label.begin(), label.end()); 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); pi.pain.text(x, y, dlab, pi.base.font);
InsetText::draw(pi, x + labelwidth_, y); InsetText::draw(pi, x + labelwidth_, y);
setPosCache(pi, x, y); setPosCache(pi, x, y);

View File

@ -31,7 +31,9 @@
#include "paragraph_funcs.h" #include "paragraph_funcs.h"
#include "sgml.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 "frontends/Painter.h"
#include <sstream> #include <sstream>
@ -157,7 +159,7 @@ void InsetCharStyle::metrics(MetricsInfo & mi, Dimension & dim) const
// FIXME UNICODE // FIXME UNICODE
s = lyx::to_utf8(_("Undef: ")) + s; s = lyx::to_utf8(_("Undef: ")) + s;
docstring ds(s.begin(), s.end()); 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.wid = max(dim.wid, w);
} }
dim.asc += TEXT_TO_INSET_OFFSET; dim.asc += TEXT_TO_INSET_OFFSET;
@ -205,7 +207,7 @@ void InsetCharStyle::draw(PainterInfo & pi, int x, int y) const
// FIXME UNICODE // FIXME UNICODE
s = lyx::to_utf8(_("Undef: ")) + s; s = lyx::to_utf8(_("Undef: ")) + s;
docstring ds(s.begin(), s.end()); 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, pi.pain.rectText(x + (dim_.wid - w) / 2, y + desc + a,
ds, font, LColor::none, LColor::none); ds, font, LColor::none, LColor::none);
} }

View File

@ -26,7 +26,9 @@
#include "metricsinfo.h" #include "metricsinfo.h"
#include "paragraph.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 "frontends/Painter.h"
using lyx::docstring; using lyx::docstring;
@ -121,8 +123,9 @@ void InsetCollapsable::read(Buffer const & buf, LyXLex & lex)
Dimension InsetCollapsable::dimensionCollapsed() const Dimension InsetCollapsable::dimensionCollapsed() const
{ {
Dimension dim; Dimension dim;
docstring dlab(label.begin(), label.end()); docstring dlab(label.begin(), label.end());
font_metrics::buttonText(dlab, labelfont_, dim.wid, dim.asc, dim.des); theApp->fontLoader().metrics(labelfont_).buttonText(
dlab, dim.wid, dim.asc, dim.des);
return dim; return dim;
} }

View File

@ -19,7 +19,9 @@
#include "lyxrc.h" #include "lyxrc.h"
#include "metricsinfo.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 "frontends/Painter.h"
#include "support/lstrings.h" #include "support/lstrings.h"
@ -244,48 +246,39 @@ void InsetLatexAccent::checkContents()
void InsetLatexAccent::metrics(MetricsInfo & mi, Dimension & dim) const void InsetLatexAccent::metrics(MetricsInfo & mi, Dimension & dim) const
{ {
LyXFont & font = mi.base.font; 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 // This function is a bit too simplistic and is just a
// "try to make a fit for all accents" approach, to // "try to make a fit for all accents" approach, to
// make it better we need to know what kind of accent is // make it better we need to know what kind of accent is
// used and add to max based on that. // used and add to max based on that.
if (candisp) { if (candisp) {
if (ic == ' ') if (ic == ' ')
dim.asc = font_metrics::ascent('a', font); dim.asc = fm.ascent('a');
else else
dim.asc = font_metrics::ascent(ic, font); dim.asc = fm.ascent(ic);
if (plusasc) if (plusasc)
dim.asc += (font_metrics::maxAscent(font) + 3) / 3; dim.asc += (fm.maxAscent() + 3) / 3;
if (ic == ' ') if (ic == ' ')
dim.des = font_metrics::descent('a', font); dim.des = fm.descent('a');
else else
dim.des = font_metrics::descent(ic, font); dim.des = fm.descent(ic);
if (plusdesc) if (plusdesc)
dim.des += 3; dim.des += 3;
dim.wid = font_metrics::width(ic, font); dim.wid = fm.width(ic);
} else { } else {
dim.asc = font_metrics::maxAscent(font) + 4; dim.asc = fm.maxAscent() + 4;
dim.des = font_metrics::maxDescent(font) + 4; dim.des = fm.maxDescent() + 4;
docstring dcon(contents.begin(), contents.end()); docstring dcon(contents.begin(), contents.end());
dim.wid = font_metrics::width(dcon, font) + 4; dim.wid = fm.width(dcon) + 4;
} }
dim_ = dim; 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 bool InsetLatexAccent::displayISO8859_9(PainterInfo & pi, int x, int y) const
{ {
unsigned char tmpic = ic; unsigned char tmpic = ic;
@ -338,10 +331,13 @@ void InsetLatexAccent::drawAccent(PainterInfo const & pi, int x, int y,
char_type accent) const char_type accent) const
{ {
LyXFont const & font = pi.base.font; LyXFont const & font = pi.base.font;
x -= font_metrics::center(accent, font); lyx::frontend::FontMetrics const & fm =
y -= font_metrics::ascent(ic, font); theApp->fontLoader().metrics(font);
y -= font_metrics::descent(accent, font);
y -= font_metrics::height(accent, font) / 2; x -= fm.center(accent);
y -= fm.ascent(ic);
y -= fm.descent(accent);
y -= fm.height(accent) / 2;
pi.pain.text(x, y, accent, font); pi.pain.text(x, y, accent, font);
} }
@ -360,13 +356,16 @@ void InsetLatexAccent::draw(PainterInfo & pi, int x, int baseline) const
if (lyxrc.font_norm_type == LyXRC::ISO_10646_1) if (lyxrc.font_norm_type == LyXRC::ISO_10646_1)
font.setLanguage(english_language); font.setLanguage(english_language);
lyx::frontend::FontMetrics const & fm =
theApp->fontLoader().metrics(font);
if (candisp) { 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 hg;
int y; int y;
if (plusasc) { if (plusasc) {
// mark at the top // mark at the top
hg = font_metrics::maxDescent(font); hg = fm.maxDescent();
y = baseline - dim_.asc; y = baseline - dim_.asc;
if (font.shape() == LyXFont::ITALIC_SHAPE) if (font.shape() == LyXFont::ITALIC_SHAPE)
x2 += int(0.8 * hg); // italic x2 += int(0.8 * hg); // italic
@ -383,15 +382,15 @@ void InsetLatexAccent::draw(PainterInfo & pi, int x, int baseline) const
pi.pain.text(x, baseline, ic, font); pi.pain.text(x, baseline, ic, font);
if (remdot) { if (remdot) {
int tmpvar = baseline - font_metrics::ascent('i', font); int tmpvar = baseline - fm.ascent('i');
int tmpx = 0; int tmpx = 0;
if (font.shape() == LyXFont::ITALIC_SHAPE) if (font.shape() == LyXFont::ITALIC_SHAPE)
tmpx += int(0.8 * hg); // italic tmpx += int(0.8 * hg); // italic
lyxerr[Debug::KEY] << "Removing dot." << endl; lyxerr[Debug::KEY] << "Removing dot." << endl;
// remove the dot first // remove the dot first
pi.pain.fillRectangle(x + tmpx, tmpvar, dim_.wid, pi.pain.fillRectangle(x + tmpx, tmpvar, dim_.wid,
font_metrics::ascent('i', pi.base.font) - fm.ascent('i') -
font_metrics::ascent('x', pi.base.font) - 1, fm.ascent('x') - 1,
backgroundColor()); backgroundColor());
// the five lines below is a simple hack to // the five lines below is a simple hack to
// make the display of accent 'i' and 'j' // make the display of accent 'i' and 'j'
@ -430,21 +429,21 @@ void InsetLatexAccent::draw(PainterInfo & pi, int x, int baseline) const
case UNDERBAR: { case UNDERBAR: {
char_type const underbar = 0x5F; //('\x5F'); 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); baseline, underbar, font);
break; break;
} }
case CEDILLA: { case CEDILLA: {
char_type const cedilla = 0xB8; //('\xB8'); 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); baseline, cedilla, font);
break; break;
} }
case UNDERDOT: case UNDERDOT:
pi.pain.text(x2 - font_metrics::center('.', font), pi.pain.text(x2 - fm.center('.'),
int(baseline + 1.5 * font_metrics::height('.', font)), int(baseline + 1.5 * fm.height('.')),
'.', font); '.', font);
break; break;
@ -496,8 +495,8 @@ void InsetLatexAccent::draw(PainterInfo & pi, int x, int baseline) const
} }
case HUNGARIAN_UMLAUT: case HUNGARIAN_UMLAUT:
drawAccent(pi, x2 - font_metrics::center('´', font), baseline, '´'); drawAccent(pi, x2 - fm.center('´'), baseline, '´');
drawAccent(pi, x2 + font_metrics::center('´', font), baseline, '´'); drawAccent(pi, x2 + fm.center('´'), baseline, '´');
break; break;
case UMLAUT: case UMLAUT:

View File

@ -37,10 +37,6 @@ public:
/// ///
void draw(PainterInfo & pi, int x, int y) const; 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; bool displayISO8859_9(PainterInfo & pi, int x, int y) const;
/// ///
void write(Buffer const &, std::ostream &) const; void write(Buffer const &, std::ostream &) const;

View File

@ -19,7 +19,9 @@
#include "paragraph.h" #include "paragraph.h"
#include "paragraph_funcs.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 "frontends/Painter.h"
using std::endl; using std::endl;
@ -40,10 +42,11 @@ void InsetNewline::write(Buffer const &, ostream & os) const
void InsetNewline::metrics(MetricsInfo & mi, Dimension & dim) const void InsetNewline::metrics(MetricsInfo & mi, Dimension & dim) const
{ {
LyXFont & font = mi.base.font; lyx::frontend::FontMetrics const & fm =
dim.asc = font_metrics::maxAscent(font); theApp->fontLoader().metrics(mi.base.font);
dim.des = font_metrics::maxDescent(font); dim.asc = fm.maxAscent();
dim.wid = font_metrics::width('n', font); dim.des = fm.maxDescent();
dim.wid = fm.width('n');
dim_ = dim; dim_ = dim;
} }
@ -74,8 +77,10 @@ int InsetNewline::docbook(Buffer const &, std::ostream & os,
void InsetNewline::draw(PainterInfo & pi, int x, int y) const void InsetNewline::draw(PainterInfo & pi, int x, int y) const
{ {
int const wid = font_metrics::width('n', pi.base.font); lyx::frontend::FontMetrics const & fm =
int const asc = font_metrics::maxAscent(pi.base.font); theApp->fontLoader().metrics(pi.base.font);
int const wid = fm.width('n');
int const asc = fm.maxAscent();
int xp[3]; int xp[3];
int yp[3]; int yp[3];

View File

@ -18,8 +18,10 @@
#include "metricsinfo.h" #include "metricsinfo.h"
#include "gettext.h" #include "gettext.h"
#include "frontends/Application.h"
#include "frontends/FontLoader.h"
#include "frontends/FontMetrics.h"
#include "frontends/Painter.h" #include "frontends/Painter.h"
#include "frontends/font_metrics.h"
using lyx::docstring; using lyx::docstring;
using lyx::frontend::Painter; using lyx::frontend::Painter;
@ -60,7 +62,7 @@ void InsetPagebreak::draw(PainterInfo & pi, int x, int y) const
int w = 0; int w = 0;
int a = 0; int a = 0;
int d = 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_start = int(x + (dim_.wid - w) / 2);
int const text_end = text_start + w; int const text_end = text_start + w;

View File

@ -24,7 +24,9 @@
#include "paragraph.h" #include "paragraph.h"
#include "paragraph_funcs.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 "frontends/Painter.h"
#include "support/lstrings.h" #include "support/lstrings.h"
@ -199,18 +201,20 @@ string const InsetQuotes::dispString(Language const * loclang) const
void InsetQuotes::metrics(MetricsInfo & mi, Dimension & dim) const void InsetQuotes::metrics(MetricsInfo & mi, Dimension & dim) const
{ {
LyXFont & font = mi.base.font; LyXFont & font = mi.base.font;
dim.asc = font_metrics::maxAscent(font); lyx::frontend::FontMetrics const & fm =
dim.des = font_metrics::maxDescent(font); theApp->fontLoader().metrics(font);
dim.asc = fm.maxAscent();
dim.des = fm.maxDescent();
dim.wid = 0; dim.wid = 0;
string const text = dispString(font.language()); string const text = dispString(font.language());
for (string::size_type i = 0; i < text.length(); ++i) { for (string::size_type i = 0; i < text.length(); ++i) {
if (text[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]) else if (i == 0 || text[i] != text[i - 1])
dim.wid += font_metrics::width(text[i], font); dim.wid += fm.width(text[i]);
else else
dim.wid += font_metrics::width(',', font); dim.wid += fm.width(',');
} }
dim_ = dim; dim_ = dim;
} }
@ -235,7 +239,8 @@ void InsetQuotes::draw(PainterInfo & pi, int x, int y) const
if (text.length() == 2 && text[0] == text[1]) { if (text.length() == 2 && text[0] == text[1]) {
pi.pain.text(x, y, text[0], pi.base.font); 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); pi.pain.text(x + t, y, text[0], pi.base.font);
} else { } else {
docstring dtext(text.begin(), text.end()); docstring dtext(text.begin(), text.end());

View File

@ -21,7 +21,9 @@
#include "metricsinfo.h" #include "metricsinfo.h"
#include "outputparams.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" #include "frontends/Painter.h"
@ -48,18 +50,19 @@ InsetSpace::Kind InsetSpace::kind() const
void InsetSpace::metrics(MetricsInfo & mi, Dimension & dim) const void InsetSpace::metrics(MetricsInfo & mi, Dimension & dim) const
{ {
LyXFont & font = mi.base.font; lyx::frontend::FontMetrics const & fm =
dim.asc = font_metrics::maxAscent(font); theApp->fontLoader().metrics(mi.base.font);
dim.des = font_metrics::maxDescent(font); dim.asc = fm.maxAscent();
dim.des = fm.maxDescent();
switch (kind_) { switch (kind_) {
case THIN: case THIN:
case NEGTHIN: case NEGTHIN:
dim.wid = font_metrics::width(lyx::char_type('x'), font) / 3; dim.wid = fm.width(lyx::char_type('x')) / 3;
break; break;
case PROTECTED: case PROTECTED:
case NORMAL: case NORMAL:
dim.wid = font_metrics::width(lyx::char_type('x'), font); dim.wid = fm.width(lyx::char_type('x'));
break; break;
case QUAD: case QUAD:
dim.wid = 20; dim.wid = 20;
@ -79,7 +82,8 @@ void InsetSpace::metrics(MetricsInfo & mi, Dimension & dim) const
void InsetSpace::draw(PainterInfo & pi, int x, int y) const void InsetSpace::draw(PainterInfo & pi, int x, int y) const
{ {
int const w = width(); 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]; int xp[4], yp[4];
xp[0] = x; xp[0] = x;

View File

@ -20,7 +20,9 @@
#include "lyxlex.h" #include "lyxlex.h"
#include "metricsinfo.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 "frontends/Painter.h"
using lyx::docstring; using lyx::docstring;
@ -43,9 +45,10 @@ InsetSpecialChar::Kind InsetSpecialChar::kind() const
void InsetSpecialChar::metrics(MetricsInfo & mi, Dimension & dim) const void InsetSpecialChar::metrics(MetricsInfo & mi, Dimension & dim) const
{ {
LyXFont & font = mi.base.font; lyx::frontend::FontMetrics const & fm =
dim.asc = font_metrics::maxAscent(font); theApp->fontLoader().metrics(mi.base.font);
dim.des = font_metrics::maxDescent(font); dim.asc = fm.maxAscent();
dim.des = fm.maxDescent();
string s; string s;
switch (kind_) { switch (kind_) {
@ -56,7 +59,7 @@ void InsetSpecialChar::metrics(MetricsInfo & mi, Dimension & dim) const
case HYPHENATION: s = "-"; break; case HYPHENATION: s = "-"; break;
} }
docstring ds(s.begin(), s.end()); docstring ds(s.begin(), s.end());
dim.wid = font_metrics::width(ds, font); dim.wid = fm.width(ds);
if (kind_ == HYPHENATION && dim.wid > 5) if (kind_ == HYPHENATION && dim.wid > 5)
dim.wid -= 2; // to make it look shorter dim.wid -= 2; // to make it look shorter
dim_ = dim; dim_ = dim;
@ -96,10 +99,13 @@ void InsetSpecialChar::draw(PainterInfo & pi, int x, int y) const
} }
case MENU_SEPARATOR: case MENU_SEPARATOR:
{ {
lyx::frontend::FontMetrics const & fm =
theApp->fontLoader().metrics(font);
// A triangle the width and height of an 'x' // A triangle the width and height of an 'x'
int w = font_metrics::width(lyx::char_type('x'), font); int w = fm.width(lyx::char_type('x'));
int ox = font_metrics::width(lyx::char_type(' '), font) + x; int ox = fm.width(lyx::char_type(' ')) + x;
int h = font_metrics::ascent(lyx::char_type('x'), font); int h = fm.ascent(lyx::char_type('x'));
int xp[4], yp[4]; int xp[4], yp[4];
xp[0] = ox; yp[0] = y; xp[0] = ox; yp[0] = y;

View File

@ -38,7 +38,6 @@
#include "frontends/Alert.h" #include "frontends/Alert.h"
#include "frontends/Application.h" #include "frontends/Application.h"
#include "frontends/font_metrics.h"
#include "frontends/Clipboard.h" #include "frontends/Clipboard.h"
#include "frontends/Painter.h" #include "frontends/Painter.h"
#include "frontends/Selection.h" #include "frontends/Selection.h"

View File

@ -43,7 +43,6 @@
#include "undo.h" #include "undo.h"
#include "frontends/Alert.h" #include "frontends/Alert.h"
#include "frontends/font_metrics.h"
#include "frontends/Painter.h" #include "frontends/Painter.h"
#include "support/lyxalgo.h" // lyx::count #include "support/lyxalgo.h" // lyx::count

View File

@ -23,7 +23,9 @@
#include "lyxtext.h" #include "lyxtext.h"
#include "metricsinfo.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 "frontends/Painter.h"
#include <sstream> #include <sstream>
@ -131,7 +133,7 @@ void InsetVSpace::metrics(MetricsInfo & mi, Dimension & dim) const
int d = 0; int d = 0;
string lab = label(); string lab = label();
docstring dlab(lab.begin(), lab.end()); 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); height = max(height, a + d);
@ -183,7 +185,7 @@ void InsetVSpace::draw(PainterInfo & pi, int x, int y) const
font.decSize(); font.decSize();
string lab = label(); string lab = label();
docstring dlab(lab.begin(), lab.end()); 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, pi.pain.rectText(x + 2 * arrow_size + 5,
start + (end - start) / 2 + (a - d) / 2, start + (end - start) / 2 + (a - d) / 2,

View File

@ -15,7 +15,9 @@
#include "LColor.h" #include "LColor.h"
#include "metricsinfo.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 "frontends/Painter.h"
using lyx::docstring; using lyx::docstring;
@ -46,13 +48,15 @@ void RenderButton::metrics(MetricsInfo &, Dimension & dim) const
{ {
LyXFont font(LyXFont::ALL_SANE); LyXFont font(LyXFont::ALL_SANE);
font.decSize(); font.decSize();
lyx::frontend::FontMetrics const & fm =
theApp->fontLoader().metrics(font);
docstring dtext(text_.begin(), text_.end()); docstring dtext(text_.begin(), text_.end());
if (editable_) if (editable_)
font_metrics::buttonText(dtext, font, dim.wid, dim.asc, dim.des); fm.buttonText(dtext, dim.wid, dim.asc, dim.des);
else else
font_metrics::rectText(dtext, font, dim.wid, dim.asc, dim.des); fm.rectText(dtext, dim.wid, dim.asc, dim.des);
dim.wid += 4; dim.wid += 4;
} }

View File

@ -20,7 +20,9 @@
#include "lyxrc.h" #include "lyxrc.h"
#include "metricsinfo.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 "frontends/Painter.h"
#include "graphics/GraphicsImage.h" #include "graphics/GraphicsImage.h"
@ -163,15 +165,16 @@ void RenderGraphic::metrics(MetricsInfo & mi, Dimension & dim) const
docstring djust(justname.begin(), justname.end()); docstring djust(justname.begin(), justname.end());
if (!justname.empty()) { if (!justname.empty()) {
msgFont.setSize(LyXFont::SIZE_FOOTNOTE); 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()); string const msg = statusMessage(params_, loader_.status());
if (!msg.empty()) { if (!msg.empty()) {
docstring dmsg(msg.begin(), msg.end()); docstring dmsg(msg.begin(), msg.end());
msgFont.setSize(LyXFont::SIZE_TINY); msgFont.setSize(LyXFont::SIZE_TINY);
font_width = std::max(font_width, font_width = std::max(font_width, theApp->fontLoader()
font_metrics::width(dmsg, msgFont)); .metrics(msgFont).width(dmsg));
} }
dim.wid = std::max(50, font_width + 15); dim.wid = std::max(50, font_width + 15);
@ -216,7 +219,7 @@ void RenderGraphic::draw(PainterInfo & pi, int x, int y) const
docstring djust(justname.begin(), justname.end()); docstring djust(justname.begin(), justname.end());
msgFont.setSize(LyXFont::SIZE_FOOTNOTE); msgFont.setSize(LyXFont::SIZE_FOOTNOTE);
pi.pain.text(x + InsetOld::TEXT_TO_INSET_OFFSET + 6, 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); djust, msgFont);
} }

View File

@ -21,7 +21,9 @@
#include "lyxrc.h" #include "lyxrc.h"
#include "metricsinfo.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 "frontends/Painter.h"
#include "graphics/PreviewImage.h" #include "graphics/PreviewImage.h"
@ -133,7 +135,7 @@ void RenderPreview::metrics(MetricsInfo & mi, Dimension & dim) const
font.setSize(LyXFont::SIZE_FOOTNOTE); font.setSize(LyXFont::SIZE_FOOTNOTE);
string stat = statusMessage(mi.base.bv, snippet_); string stat = statusMessage(mi.base.bv, snippet_);
docstring dstat(stat.begin(), stat.end()); 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; dim_ = dim;
@ -168,7 +170,7 @@ void RenderPreview::draw(PainterInfo & pi, int x, int y) const
string stat = statusMessage(pi.base.bv, snippet_); string stat = statusMessage(pi.base.bv, snippet_);
docstring dstat(stat.begin(), stat.end()); docstring dstat(stat.begin(), stat.end());
pi.pain.text(x + offset + 6, pi.pain.text(x + offset + 6,
y - font_metrics::maxAscent(font) - 4, y - theApp->fontLoader().metrics(font).maxAscent() - 4,
dstat, font); dstat, font);
} }
} }

View File

@ -136,7 +136,7 @@ int LyXLength::inPixels(int text_width, int em_width_base) const
? em_width_base ? em_width_base
: 10*(dpi/72.27)*zoom; : 10*(dpi/72.27)*zoom;
// A different estimate for em_width is // 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 // but this estimate might not be more accurate as the screen font
// is different then the latex font. // is different then the latex font.

View File

@ -24,8 +24,10 @@
#include "lyxlex.h" #include "lyxlex.h"
#include "outputparams.h" #include "outputparams.h"
#include "frontends/Application.h"
#include "frontends/FontLoader.h"
#include "frontends/FontMetrics.h"
#include "frontends/Painter.h" #include "frontends/Painter.h"
#include "frontends/font_metrics.h"
#include "support/lstrings.h" #include "support/lstrings.h"
@ -127,7 +129,8 @@ void InsetFormulaMacro::metrics(MetricsInfo & mi, Dimension & dim) const
tmpl()->metrics(mi, dim); tmpl()->metrics(mi, dim);
dim.asc += 5; dim.asc += 5;
dim.des += 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; dim_ = dim;
} }
@ -162,7 +165,9 @@ void InsetFormulaMacro::draw(PainterInfo & p, int x, int y) const
pi.pain.text(x + 2, y, prefix(), font); pi.pain.text(x + 2, y, prefix(), font);
// body // 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); setPosCache(pi, x, y);
} }

View File

@ -15,6 +15,10 @@
#include "MathMLStream.h" #include "MathMLStream.h"
#include "MathStream.h" #include "MathStream.h"
#include "frontends/Application.h"
#include "frontends/FontLoader.h"
#include "frontends/FontMetrics.h"
#include "support/lstrings.h" #include "support/lstrings.h"
@ -61,7 +65,8 @@ double InsetMathBig::increase() const
void InsetMathBig::metrics(MetricsInfo & mi, Dimension & dim) const 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(); double const f = increase();
dim_.wid = 6; dim_.wid = 6;
dim_.asc = int(h + f * h); dim_.asc = int(h + f * h);

View File

@ -20,6 +20,10 @@
#include "support/lstrings.h" #include "support/lstrings.h"
#include "TextPainter.h" #include "TextPainter.h"
#include "frontends/Application.h"
#include "frontends/FontLoader.h"
#include "frontends/FontMetrics.h"
using std::auto_ptr; using std::auto_ptr;
extern bool has_math_fonts; extern bool has_math_fonts;
@ -76,7 +80,7 @@ void InsetMathChar::metrics(MetricsInfo & mi, Dimension & dim) const
whichFont(font_, code_, mi); whichFont(font_, code_, mi);
mathed_char_dim(font_, char_, dim_); mathed_char_dim(font_, char_, dim_);
if (isBinaryOp(char_, code_)) if (isBinaryOp(char_, code_))
width_ += 2 * font_metrics::width(' ', font_); width_ += 2 * theApp->fontLoader().metrics(font_).width(' ');
lyxerr << "InsetMathChar::metrics: " << dim << endl; lyxerr << "InsetMathChar::metrics: " << dim << endl;
#endif #endif
width_ = dim.wid; width_ = dim.wid;

View File

@ -21,8 +21,10 @@
#include "lyxlex.h" #include "lyxlex.h"
#include "LColor.h" #include "LColor.h"
#include "frontends/Application.h"
#include "frontends/FontLoader.h"
#include "frontends/FontMetrics.h"
#include "frontends/Painter.h" #include "frontends/Painter.h"
#include "frontends/font_metrics.h"
#include "support/lstrings.h" #include "support/lstrings.h"
@ -117,7 +119,7 @@ void MathMacroTemplate::metrics(MetricsInfo & mi, Dimension & dim) const
cell(1).metrics(mi); cell(1).metrics(mi);
docstring dp = prefix(); docstring dp = prefix();
dim.wid = cell(0).width() + cell(1).width() + 20 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.asc = std::max(cell(0).ascent(), cell(1).ascent()) + 7;
dim.des = std::max(cell(0).descent(), cell(1).descent()) + 7; dim.des = std::max(cell(0).descent(), cell(1).descent()) + 7;
dim_ = dim; dim_ = dim;
@ -155,7 +157,8 @@ void MathMacroTemplate::draw(PainterInfo & p, int x, int y) const
#endif #endif
docstring dp = prefix(); docstring dp = prefix();
pi.pain.text(x + 2, y, dp, font); 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 w0 = cell(0).width();
int const w1 = cell(1).width(); int const w1 = cell(1).width();

View File

@ -21,9 +21,9 @@
#include "LColor.h" #include "LColor.h"
#include "frontends/Application.h" #include "frontends/Application.h"
#include "frontends/Painter.h"
#include "frontends/font_metrics.h"
#include "frontends/FontLoader.h" #include "frontends/FontLoader.h"
#include "frontends/FontMetrics.h"
#include "frontends/Painter.h"
#include <map> #include <map>
#include <sstream> #include <sstream>
@ -368,52 +368,44 @@ deco_struct const * search_deco(string const & name)
void mathed_char_dim(LyXFont const & font, unsigned char c, Dimension & dim) void mathed_char_dim(LyXFont const & font, unsigned char c, Dimension & dim)
{ {
dim.des = font_metrics::descent(c, font); lyx::frontend::FontMetrics const & fm =
dim.asc = font_metrics::ascent(c, font); theApp->fontLoader().metrics(font);
dim.wid = mathed_char_width(font, c); dim.des = fm.descent(c);
} dim.asc = fm.ascent(c);
dim.wid = fm.width(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);
} }
int mathed_char_width(LyXFont const & font, unsigned char 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) void mathed_string_dim(LyXFont const & font, string const & s, Dimension & dim)
{ {
lyx::frontend::FontMetrics const & fm =
theApp->fontLoader().metrics(font);
#if 1 #if 1
dim.asc = 0; dim.asc = 0;
dim.des = 0; dim.des = 0;
for (string::const_iterator it = s.begin(); it != s.end(); ++it) { for (string::const_iterator it = s.begin(); it != s.end(); ++it) {
dim.asc = max(dim.asc, font_metrics::ascent(*it, font)); dim.asc = max(dim.asc, fm.ascent(*it));
dim.des = max(dim.des, font_metrics::descent(*it, font)); dim.des = max(dim.des, fm.descent(*it));
} }
#else #else
dim.asc = font_metrics::maxAscent(font); dim.asc = fm.maxAscent();
dim.des = font_metrics::maxDescent(font); dim.des = fm.maxDescent();
#endif #endif
docstring ds(s.begin(), s.end()); docstring ds(s.begin(), s.end());
dim.wid = font_metrics::width(ds, font); dim.wid = fm.width(ds);
} }
int mathed_string_width(LyXFont const & font, string const & s) int mathed_string_width(LyXFont const & font, string const & s)
{ {
docstring ds(s.begin(), s.end()); docstring ds(s.begin(), s.end());
return font_metrics::width(ds, font); return theApp->fontLoader().metrics(font).width(ds);
} }
@ -507,8 +499,10 @@ void drawStrBlack(PainterInfo & pi, int x, int y, string const & str)
void math_font_max_dim(LyXFont const & font, int & asc, int & des) void math_font_max_dim(LyXFont const & font, int & asc, int & des)
{ {
asc = font_metrics::maxAscent(font); lyx::frontend::FontMetrics const & fm =
des = font_metrics::maxDescent(font); theApp->fontLoader().metrics(font);
asc = fm.maxAscent();
des = fm.maxDescent();
} }

View File

@ -25,8 +25,6 @@ class InsetMath;
void mathed_char_dim(LyXFont const &, unsigned char c, Dimension & dim); void mathed_char_dim(LyXFont const &, unsigned char c, Dimension & dim);
int mathed_char_width(LyXFont const &, unsigned char c); 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, void mathed_draw_deco(PainterInfo & pi, int x, int y, int w, int h,
std::string const & name); std::string const & name);

View File

@ -32,7 +32,9 @@
#include "ParagraphParameters.h" #include "ParagraphParameters.h"
#include "vspace.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/nullpainter.h"
#include "frontends/Painter.h" #include "frontends/Painter.h"
@ -45,6 +47,8 @@
using lyx::docstring; using lyx::docstring;
using lyx::frontend::Painter; using lyx::frontend::Painter;
using lyx::frontend::NullPainter; using lyx::frontend::NullPainter;
using lyx::frontend::FontMetrics;
using lyx::char_type; using lyx::char_type;
using lyx::pos_type; using lyx::pos_type;
using lyx::pit_type; using lyx::pit_type;
@ -198,7 +202,7 @@ void RowPainter::paintHebrewComposeChar(pos_type & vpos, LyXFont const & font)
str += c; str += c;
++vpos; ++vpos;
int const width = font_metrics::width(c, font); int const width = theApp->fontLoader().metrics(font).width(c);
int dx = 0; int dx = 0;
for (pos_type i = pos - 1; i >= 0; --i) { for (pos_type i = pos - 1; i >= 0; --i) {
@ -233,7 +237,7 @@ void RowPainter::paintArabicComposeChar(pos_type & vpos, LyXFont const & font)
str += c; str += c;
++vpos; ++vpos;
int const width = font_metrics::width(c, font); int const width = theApp->fontLoader().metrics(font).width(c);
int dx = 0; int dx = 0;
for (pos_type i = pos - 1; i >= 0; --i) { for (pos_type i = pos - 1; i >= 0; --i) {
@ -313,10 +317,10 @@ void RowPainter::paintChars(pos_type & vpos, LyXFont font,
//lyxerr << "paint row: yo_ " << yo_ << "\n"; //lyxerr << "paint row: yo_ " << yo_ << "\n";
#if 0 #if 0
pain_.text(int(x_), yo_, str, font); pain_.text(int(x_), yo_, str, font);
x_ += font_metrics::width(str, font); x_ += theApp->fontLoader().metrics(font).width(str);
#else #else
pain_.text(int(x_), yo_, &str[0], str.size(), font); 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 #endif
} }
@ -460,7 +464,7 @@ int RowPainter::paintAppendixStart(int y)
int a = 0; int a = 0;
int d = 0; int d = 0;
docstring dlab(label.begin(), label.end()); 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_start = int(xo_ + (width_ - w) / 2);
int const text_end = text_start + w; int const text_end = text_start + w;
@ -515,6 +519,9 @@ void RowPainter::paintFirst()
|| is_seq)) { || is_seq)) {
LyXFont const font = getLabelFont(); LyXFont const font = getLabelFont();
FontMetrics const & fm =
theApp->fontLoader().metrics(font);
string const str = par_.getLabelstring(); string const str = par_.getLabelstring();
if (!str.empty()) { if (!str.empty()) {
double x = x_; double x = x_;
@ -531,14 +538,14 @@ void RowPainter::paintFirst()
spacing_val = buffer.params().spacing().getValue(); 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(); + int(layout->parsep) * defaultRowHeight();
if (is_rtl) { if (is_rtl) {
x = width_ - leftMargin() - x = width_ - leftMargin() -
font_metrics::width(dstr, font); fm.width(dstr);
} }
pain_.text(int(x), yo_ - maxdesc - labeladdon, dstr, font); pain_.text(int(x), yo_ - maxdesc - labeladdon, dstr, font);
@ -547,10 +554,10 @@ void RowPainter::paintFirst()
docstring dlab(lab.begin(), lab.end()); docstring dlab(lab.begin(), lab.end());
if (is_rtl) { if (is_rtl) {
x = width_ - leftMargin() x = width_ - leftMargin()
+ font_metrics::width(dlab, font); + fm.width(dlab);
} else { } else {
x = x_ - font_metrics::width(dlab, font) x = x_ - fm.width(dlab)
- font_metrics::width(dstr, font); - fm.width(dstr);
} }
pain_.text(int(x), yo_, dstr, font); pain_.text(int(x), yo_, dstr, font);
@ -573,10 +580,14 @@ void RowPainter::paintFirst()
else else
spacing_val = buffer.params().spacing().getValue(); 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 maxdesc =
int(font_metrics::maxDescent(font) * layout->spacing.getValue() * spacing_val int(fm.maxDescent() * layout->spacing.getValue() * spacing_val
+ (layout->labelbottomsep * defaultRowHeight())); + (layout->labelbottomsep * defaultRowHeight()));
double x = x_; double x = x_;
@ -584,10 +595,9 @@ void RowPainter::paintFirst()
if (is_rtl) if (is_rtl)
x = leftMargin(); x = leftMargin();
x += (width_ - text_.rightMargin(par_) - leftMargin()) / 2; x += (width_ - text_.rightMargin(par_) - leftMargin()) / 2;
x -= font_metrics::width(dstr, font) / 2; x -= fm.width(dstr) / 2;
} else if (is_rtl) { } else if (is_rtl) {
x = width_ - leftMargin() - x = width_ - leftMargin() - fm.width(dstr);
font_metrics::width(dstr, font);
} }
pain_.text(int(x), yo_ - maxdesc - labeladdon, dstr, font); pain_.text(int(x), yo_ - maxdesc - labeladdon, dstr, font);
} }
@ -605,7 +615,8 @@ void RowPainter::paintLast()
case END_LABEL_BOX: case END_LABEL_BOX:
case END_LABEL_FILLED_BOX: { case END_LABEL_FILLED_BOX: {
LyXFont const font = getLabelFont(); 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 const y = yo_ - size;
int x = is_rtl ? nestMargin() + changebarMargin() : width_ - size; int x = is_rtl ? nestMargin() + changebarMargin() : width_ - size;
@ -621,10 +632,11 @@ void RowPainter::paintLast()
case END_LABEL_STATIC: { case END_LABEL_STATIC: {
LyXFont font = getLabelFont(); LyXFont font = getLabelFont();
FontMetrics const & fm = theApp->fontLoader().metrics(font);
string const & str = par_.layout()->endlabelstring(); string const & str = par_.layout()->endlabelstring();
docstring dstr(str.begin(), str.end()); docstring dstr(str.begin(), str.end());
double const x = is_rtl ? double const x = is_rtl ?
x_ - font_metrics::width(dstr, font) x_ - fm.width(dstr)
: - text_.rightMargin(par_) - row_.width(); : - text_.rightMargin(par_) - row_.width();
pain_.text(int(x), yo_, dstr, font); pain_.text(int(x), yo_, dstr, font);
break; break;
@ -695,9 +707,9 @@ void RowPainter::paintText()
// We also don't paint across things like tables // We also don't paint across things like tables
if (running_strikeout && (highly_editable_inset || !is_struckout)) { if (running_strikeout && (highly_editable_inset || !is_struckout)) {
// Calculate 1/3 height of the buffer's default font // Calculate 1/3 height of the buffer's default font
int const middle = FontMetrics const & fm = theApp->fontLoader().metrics(
yo_ - bv_.buffer()->params().getFont());
font_metrics::maxAscent(bv_.buffer()->params().getFont()) / 3; int const middle = yo_ - fm.maxAscent() / 3;
pain_.line(last_strikeout_x, middle, int(x_), middle, pain_.line(last_strikeout_x, middle, int(x_), middle,
LColor::strikeout, Painter::line_solid, Painter::line_thin); LColor::strikeout, Painter::line_solid, Painter::line_thin);
running_strikeout = false; running_strikeout = false;
@ -706,8 +718,8 @@ void RowPainter::paintText()
if (body_pos > 0 && pos == body_pos - 1) { if (body_pos > 0 && pos == body_pos - 1) {
string lab = layout->labelsep; string lab = layout->labelsep;
docstring dlab(lab.begin(), lab.end()); docstring dlab(lab.begin(), lab.end());
int const lwidth = font_metrics::width(dlab, int const lwidth =
getLabelFont()); theApp->fontLoader().metrics(getLabelFont()).width(dlab);
x_ += label_hfill_ + lwidth - width_pos; x_ += label_hfill_ + lwidth - width_pos;
} }
@ -751,9 +763,9 @@ void RowPainter::paintText()
// if we reach the end of a struck out range, paint it // if we reach the end of a struck out range, paint it
if (running_strikeout) { if (running_strikeout) {
// calculate 1/3 height of the buffer's default font // calculate 1/3 height of the buffer's default font
int const middle = FontMetrics const & fm = theApp->fontLoader().metrics(
yo_ - bv_.buffer()->params().getFont());
font_metrics::maxAscent(bv_.buffer()->params().getFont()) / 3; int const middle = yo_ - fm.maxAscent() / 3;
pain_.line(last_strikeout_x, middle, int(x_), middle, pain_.line(last_strikeout_x, middle, int(x_), middle,
LColor::strikeout, Painter::line_solid, Painter::line_thin); LColor::strikeout, Painter::line_solid, Painter::line_thin);
running_strikeout = false; running_strikeout = false;

View File

@ -51,7 +51,9 @@
#include "vspace.h" #include "vspace.h"
#include "WordLangTuple.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 "frontends/Painter.h"
#include "insets/insettext.h" #include "insets/insettext.h"
@ -89,6 +91,8 @@ using lyx::support::uppercase;
using lyx::cap::cutSelection; using lyx::cap::cutSelection;
using lyx::cap::pasteParagraphList; using lyx::cap::pasteParagraphList;
using lyx::frontend::FontMetrics;
using std::auto_ptr; using std::auto_ptr;
using std::advance; using std::advance;
using std::distance; using std::distance;
@ -462,13 +466,13 @@ int LyXText::singleWidth(Paragraph const & par,
Encodings::isComposeChar_hebrew(c)) Encodings::isComposeChar_hebrew(c))
return 0; return 0;
} }
return font_metrics::width(c, font); return theApp->fontLoader().metrics(font).width(c);
} }
if (c == Paragraph::META_INSET) if (c == Paragraph::META_INSET)
return par.getInset(pos)->width(); return par.getInset(pos)->width();
return font_metrics::width(c, font); return theApp->fontLoader().metrics(font).width(c);
} }
@ -501,7 +505,7 @@ int LyXText::leftMargin(pit_type const pit, pos_type const pos) const
string leftm = tclass.leftmargin(); string leftm = tclass.leftmargin();
docstring dleft(leftm.begin(), leftm.end()); 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) { if (par.getDepth() != 0) {
// find the next level paragraph // find the next level paragraph
@ -527,43 +531,41 @@ int LyXText::leftMargin(pit_type const pit, pos_type const pos) const
parindent.erase(); parindent.erase();
LyXFont const labelfont = getLabelFont(par); LyXFont const labelfont = getLabelFont(par);
FontMetrics const & labelfont_metrics = theApp->fontLoader().metrics(labelfont);
switch (layout->margintype) { switch (layout->margintype) {
case MARGIN_DYNAMIC: case MARGIN_DYNAMIC:
if (!layout->leftmargin.empty()) { if (!layout->leftmargin.empty()) {
string leftm = layout->leftmargin; string leftm = layout->leftmargin;
docstring dleft(leftm.begin(), leftm.end()); docstring dleft(leftm.begin(), leftm.end());
l_margin += font_metrics::signedWidth(dleft, l_margin += theApp->fontLoader().metrics(params.getFont()).signedWidth(dleft);
params.getFont());
} }
if (!par.getLabelstring().empty()) { if (!par.getLabelstring().empty()) {
string labin = layout->labelindent; string labin = layout->labelindent;
docstring dlabin(labin.begin(), labin.end()); docstring dlabin(labin.begin(), labin.end());
l_margin += font_metrics::signedWidth(dlabin, l_margin += labelfont_metrics.signedWidth(dlabin);
labelfont);
string labstr = par.getLabelstring(); string labstr = par.getLabelstring();
docstring dlabstr(labstr.begin(), labstr.end()); docstring dlabstr(labstr.begin(), labstr.end());
l_margin += font_metrics::width(dlabstr, l_margin += labelfont_metrics.width(dlabstr);
labelfont);
string labsep = layout->labelsep; string labsep = layout->labelsep;
docstring dlabsep(labsep.begin(), labsep.end()); docstring dlabsep(labsep.begin(), labsep.end());
l_margin += font_metrics::width(dlabsep, labelfont); l_margin += labelfont_metrics.width(dlabsep);
} }
break; break;
case MARGIN_MANUAL: { case MARGIN_MANUAL: {
string labin = layout->labelindent; string labin = layout->labelindent;
docstring dlabin(labin.begin(), labin.end()); 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 // The width of an empty par, even with manual label, should be 0
if (!par.empty() && pos >= par.beginOfBody()) { if (!par.empty() && pos >= par.beginOfBody()) {
if (!par.getLabelWidthString().empty()) { if (!par.getLabelWidthString().empty()) {
string labstr = par.getLabelWidthString(); string labstr = par.getLabelWidthString();
docstring dlabstr(labstr.begin(), labstr.end()); docstring dlabstr(labstr.begin(), labstr.end());
l_margin += font_metrics::width(dlabstr, l_margin += labelfont_metrics.width(dlabstr);
labelfont);
string labsep = layout->labelsep; string labsep = layout->labelsep;
docstring dlabsep(labsep.begin(), labsep.end()); docstring dlabsep(labsep.begin(), labsep.end());
l_margin += font_metrics::width(dlabsep, labelfont); l_margin += labelfont_metrics.width(dlabsep);
} }
} }
break; break;
@ -572,8 +574,9 @@ int LyXText::leftMargin(pit_type const pit, pos_type const pos) const
case MARGIN_STATIC: { case MARGIN_STATIC: {
string leftm = layout->leftmargin; string leftm = layout->leftmargin;
docstring dleft(leftm.begin(), leftm.end()); docstring dleft(leftm.begin(), leftm.end());
l_margin += font_metrics::signedWidth(dleft, params.getFont()) * 4 l_margin +=
/ (par.getDepth() + 4); theApp->fontLoader().metrics(params.getFont()).signedWidth(dleft)
* 4 / (par.getDepth() + 4);
break; break;
} }
@ -582,13 +585,11 @@ int LyXText::leftMargin(pit_type const pit, pos_type const pos) const
if (pos >= par.beginOfBody()) { if (pos >= par.beginOfBody()) {
string leftm = layout->leftmargin; string leftm = layout->leftmargin;
docstring dleft(leftm.begin(), leftm.end()); docstring dleft(leftm.begin(), leftm.end());
l_margin += font_metrics::signedWidth(dleft, l_margin += labelfont_metrics.signedWidth(dleft);
labelfont);
} else { } else {
string labin = layout->labelindent; string labin = layout->labelindent;
docstring dlabin(labin.begin(), labin.end()); docstring dlabin(labin.begin(), labin.end());
l_margin += font_metrics::signedWidth(dlabin, l_margin += labelfont_metrics.signedWidth(dlabin);
labelfont);
} }
} else if (pos != 0 } else if (pos != 0
// Special case to fix problems with // Special case to fix problems with
@ -598,22 +599,20 @@ int LyXText::leftMargin(pit_type const pit, pos_type const pos) const
&& !isFirstInSequence(pit, pars_))) { && !isFirstInSequence(pit, pars_))) {
string leftm = layout->leftmargin; string leftm = layout->leftmargin;
docstring dleft(leftm.begin(), leftm.end()); docstring dleft(leftm.begin(), leftm.end());
l_margin += font_metrics::signedWidth(dleft, l_margin += labelfont_metrics.signedWidth(dleft);
labelfont);
} else if (layout->labeltype != LABEL_TOP_ENVIRONMENT } else if (layout->labeltype != LABEL_TOP_ENVIRONMENT
&& layout->labeltype != LABEL_BIBLIO && layout->labeltype != LABEL_BIBLIO
&& layout->labeltype != && layout->labeltype !=
LABEL_CENTERED_TOP_ENVIRONMENT) { LABEL_CENTERED_TOP_ENVIRONMENT) {
string labin = layout->labelindent; string labin = layout->labelindent;
docstring dlabin(labin.begin(), labin.end()); docstring dlabin(labin.begin(), labin.end());
l_margin += font_metrics::signedWidth(dlabin, l_margin += labelfont_metrics.signedWidth(dlabin);
labelfont);
string labsep = layout->labelsep; string labsep = layout->labelsep;
docstring dlabsep(labsep.begin(), labsep.end()); docstring dlabsep(labsep.begin(), labsep.end());
l_margin += font_metrics::width(dlabsep, labelfont); l_margin += labelfont_metrics.width(dlabsep);
string labstr = par.getLabelstring(); string labstr = par.getLabelstring();
docstring dlabstr(labstr.begin(), labstr.end()); docstring dlabstr(labstr.begin(), labstr.end());
l_margin += font_metrics::width(dlabstr, labelfont); l_margin += labelfont_metrics.width(dlabstr);
} }
break; break;
@ -630,8 +629,7 @@ int LyXText::leftMargin(pit_type const pit, pos_type const pos) const
for ( ; rit != end; ++rit) for ( ; rit != end; ++rit)
if (rit->fill() < minfill) if (rit->fill() < minfill)
minfill = rit->fill(); minfill = rit->fill();
l_margin += font_metrics::signedWidth(layout->leftmargin, l_margin += theApp->fontLoader().metrics(params.getFont()).signedWidth(layout->leftmargin);
params.getFont());
l_margin += minfill; l_margin += minfill;
#endif #endif
// also wrong, but much shorter. // also wrong, but much shorter.
@ -671,7 +669,7 @@ int LyXText::leftMargin(pit_type const pit, pos_type const pos) const
BufferParams::PARSEP_INDENT)) BufferParams::PARSEP_INDENT))
{ {
docstring din(parindent.begin(), parindent.end()); 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; return l_margin;
@ -693,12 +691,11 @@ int LyXText::rightMargin(Paragraph const & par) const
docstring dtrmarg(trmarg.begin(), trmarg.end()); docstring dtrmarg(trmarg.begin(), trmarg.end());
string lrmarg = par.layout()->rightmargin; string lrmarg = par.layout()->rightmargin;
docstring dlrmarg(lrmarg.begin(), lrmarg.end()); docstring dlrmarg(lrmarg.begin(), lrmarg.end());
FontMetrics const & fm = theApp->fontLoader().metrics(params.getFont());
int const r_margin = int const r_margin =
::rightMargin() ::rightMargin()
+ font_metrics::signedWidth(dtrmarg, + fm.signedWidth(dtrmarg)
params.getFont()) + fm.signedWidth(dlrmarg)
+ font_metrics::signedWidth(dlrmarg,
params.getFont())
* 4 / (par.getDepth() + 4); * 4 / (par.getDepth() + 4);
return r_margin; return r_margin;
@ -772,6 +769,7 @@ void LyXText::rowBreakPoint(pit_type const pit, Row & row) const
FontIterator fi = FontIterator(*this, par, pos); FontIterator fi = FontIterator(*this, par, pos);
pos_type point = end; pos_type point = end;
pos_type i = pos; pos_type i = pos;
FontMetrics const & fm = theApp->fontLoader().metrics(getLabelFont(par));
for ( ; i < end; ++i, ++fi) { for ( ; i < end; ++i, ++fi) {
char_type const c = par.getChar(i); char_type const c = par.getChar(i);
int thiswidth = singleWidth(par, i, c, *fi); int thiswidth = singleWidth(par, i, c, *fi);
@ -780,7 +778,7 @@ void LyXText::rowBreakPoint(pit_type const pit, Row & row) const
if (body_pos && i == body_pos) { if (body_pos && i == body_pos) {
string lsep = layout->labelsep; string lsep = layout->labelsep;
docstring dlsep(lsep.begin(), lsep.end()); docstring dlsep(lsep.begin(), lsep.end());
int add = font_metrics::width(dlsep, getLabelFont(par)); int add = fm.width(dlsep);
if (par.isLineSeparator(i - 1)) if (par.isLineSeparator(i - 1))
add -= singleWidth(par, i - 1); add -= singleWidth(par, i - 1);
@ -860,11 +858,13 @@ void LyXText::setRowWidth(pit_type const pit, Row & row) const
pos_type const body_pos = par.beginOfBody(); pos_type const body_pos = par.beginOfBody();
pos_type i = row.pos(); pos_type i = row.pos();
FontMetrics const & fm = theApp->fontLoader().metrics(getLabelFont(par));
if (i < end) { if (i < end) {
FontIterator fi = FontIterator(*this, par, i); FontIterator fi = FontIterator(*this, par, i);
for ( ; i < end; ++i, ++fi) { for ( ; i < end; ++i, ++fi) {
if (body_pos > 0 && i == body_pos) { if (body_pos > 0 && i == body_pos) {
w += font_metrics::width(dlsep, getLabelFont(par)); w += fm.width(dlsep);
if (par.isLineSeparator(i - 1)) if (par.isLineSeparator(i - 1))
w -= singleWidth(par, i - 1); w -= singleWidth(par, i - 1);
w = max(w, labelEnd(pit)); w = max(w, labelEnd(pit));
@ -875,7 +875,7 @@ void LyXText::setRowWidth(pit_type const pit, Row & row) const
} }
if (body_pos > 0 && body_pos >= end) { 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)) if (end > 0 && par.isLineSeparator(end - 1))
w -= singleWidth(par, end - 1); w -= singleWidth(par, end - 1);
w = max(w, labelEnd(pit)); w = max(w, labelEnd(pit));
@ -908,7 +908,10 @@ int LyXText::labelFill(Paragraph const & par, Row const & row) const
return 0; return 0;
docstring dlab(label.begin(), label.end()); 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);
} }
@ -943,11 +946,14 @@ void LyXText::setHeightOfRow(pit_type const pit, Row & row)
LyXFont labelfont = getLabelFont(par); LyXFont labelfont = getLabelFont(par);
FontMetrics const & labelfont_metrics = theApp->fontLoader().metrics(labelfont);
FontMetrics const & fontmetrics = theApp->fontLoader().metrics(font);
// these are minimum values // these are minimum values
double const spacing_val = layout->spacing.getValue() * spacing(par); double const spacing_val = layout->spacing.getValue() * spacing(par);
//lyxerr << "spacing_val = " << spacing_val << endl; //lyxerr << "spacing_val = " << spacing_val << endl;
int maxasc = int(font_metrics::maxAscent(font) * spacing_val); int maxasc = int(fontmetrics.maxAscent() * spacing_val);
int maxdesc = int(font_metrics::maxDescent(font) * spacing_val); int maxdesc = int(fontmetrics.maxDescent() * spacing_val);
// insets may be taller // insets may be taller
InsetList::const_iterator ii = par.insetlist.begin(); InsetList::const_iterator ii = par.insetlist.begin();
@ -969,8 +975,8 @@ void LyXText::setHeightOfRow(pit_type const pit, Row & row)
par.highestFontInRange(row.pos(), pos_end, size); par.highestFontInRange(row.pos(), pos_end, size);
if (maxsize > font.size()) { if (maxsize > font.size()) {
font.setSize(maxsize); font.setSize(maxsize);
maxasc = max(maxasc, font_metrics::maxAscent(font)); maxasc = max(maxasc, fontmetrics.maxAscent());
maxdesc = max(maxdesc, font_metrics::maxDescent(font)); maxdesc = max(maxdesc, fontmetrics.maxDescent());
} }
// This is nicer with box insets: // This is nicer with box insets:
@ -1000,7 +1006,7 @@ void LyXText::setHeightOfRow(pit_type const pit, Row & row)
// layout is printed in an extra row // layout is printed in an extra row
if (layout->counter == "chapter" if (layout->counter == "chapter"
&& !par.params().labelString().empty()) { && !par.params().labelString().empty()) {
labeladdon = int(font_metrics::maxHeight(labelfont) labeladdon = int(labelfont_metrics.maxHeight()
* layout->spacing.getValue() * layout->spacing.getValue()
* spacing(par)); * spacing(par));
} }
@ -1013,7 +1019,7 @@ void LyXText::setHeightOfRow(pit_type const pit, Row & row)
&& !par.getLabelstring().empty()) && !par.getLabelstring().empty())
{ {
labeladdon = int( labeladdon = int(
font_metrics::maxHeight(labelfont) labelfont_metrics.maxHeight()
* layout->spacing.getValue() * layout->spacing.getValue()
* spacing(par) * spacing(par)
+ (layout->topsep + layout->labelbottomsep) * dh); + (layout->topsep + layout->labelbottomsep) * dh);
@ -1390,7 +1396,7 @@ LyXText::computeRowMetrics(pit_type const pit, Row const & row) const
{ {
string lsep = layout->labelsep; string lsep = layout->labelsep;
docstring dlsep(lsep.begin(), lsep.end()); 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) if (body_pos <= end)
result.x += result.label_hfill; result.x += result.label_hfill;
} }
@ -2294,15 +2300,14 @@ int LyXText::cursorX(CursorSlice const & sl, bool boundary) const
// Use font span to speed things up, see below // Use font span to speed things up, see below
FontSpan font_span; FontSpan font_span;
LyXFont font; LyXFont font;
FontMetrics const & labelfm = theApp->fontLoader().metrics(getLabelFont(par));
for (pos_type vpos = row_pos; vpos < cursor_vpos; ++vpos) { for (pos_type vpos = row_pos; vpos < cursor_vpos; ++vpos) {
pos_type pos = bidi.vis2log(vpos); pos_type pos = bidi.vis2log(vpos);
if (body_pos > 0 && pos == body_pos - 1) { if (body_pos > 0 && pos == body_pos - 1) {
string lsep = par.layout()->labelsep; string lsep = par.layout()->labelsep;
docstring dlsep(lsep.begin(), lsep.end()); docstring dlsep(lsep.begin(), lsep.end());
x += m.label_hfill x += m.label_hfill + labelfm.width(dlsep);
+ font_metrics::width(dlsep,
getLabelFont(par));
if (par.isLineSeparator(body_pos - 1)) if (par.isLineSeparator(body_pos - 1))
x -= singleWidth(par, body_pos - 1); x -= singleWidth(par, body_pos - 1);
} }

View File

@ -51,7 +51,8 @@
#include "vspace.h" #include "vspace.h"
#include "frontends/Application.h" #include "frontends/Application.h"
#include "frontends/font_metrics.h" #include "frontends/FontLoader.h"
#include "frontends/FontMetrics.h"
#include "insets/insetenv.h" #include "insets/insetenv.h"
@ -804,14 +805,16 @@ pos_type LyXText::getColumnNearX(pit_type const pit,
return 0; return 0;
} }
lyx::frontend::FontMetrics const & fm = theApp->fontLoader().metrics(
getLabelFont(par));
while (vc < end && tmpx <= x) { while (vc < end && tmpx <= x) {
c = bidi.vis2log(vc); c = bidi.vis2log(vc);
last_tmpx = tmpx; last_tmpx = tmpx;
if (body_pos > 0 && c == body_pos - 1) { if (body_pos > 0 && c == body_pos - 1) {
string lsep = layout->labelsep; string lsep = layout->labelsep;
docstring dlsep(lsep.begin(), lsep.end()); docstring dlsep(lsep.begin(), lsep.end());
tmpx += r.label_hfill + tmpx += r.label_hfill + fm.width(dlsep);
font_metrics::width(dlsep, getLabelFont(par));
if (par.isLineSeparator(body_pos - 1)) if (par.isLineSeparator(body_pos - 1))
tmpx -= singleWidth(par, body_pos - 1); tmpx -= singleWidth(par, body_pos - 1);
} }
@ -1342,5 +1345,5 @@ void LyXText::recUndo(pit_type par) const
int defaultRowHeight() 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);
} }