diff --git a/src/frontends/qt2/QLPainter.C b/src/frontends/qt2/QLPainter.C index 1720c04017..a2da9e221d 100644 --- a/src/frontends/qt2/QLPainter.C +++ b/src/frontends/qt2/QLPainter.C @@ -227,7 +227,6 @@ void QLPainter::text(int x, int y, char const * s, size_t ls, encoding = encodings.symbol_encoding(); QString str; -#if QT_VERSION >= 300 str.setLength(ls); for (size_t i = 0; i < ls; ++i) // Brain-dead MSVC wants at(i) rather than operator[] @@ -235,20 +234,12 @@ void QLPainter::text(int x, int y, char const * s, size_t ls, // HACK: QT3 refuses to show single compose characters if (ls == 1 && str[0].unicode() >= 0x05b0 && str[0].unicode() <= 0x05c2) str = ' ' + str; -#else - for (size_t i = 0; i < ls; ++i) - str += QChar(encoding->ucs(s[i])); -#endif if (f.realShape() != LyXFont::SMALLCAPS_SHAPE) { qp_->setFont(fontloader.get(f)); -#if QT_VERSION >= 300 // We need to draw the text as LTR as we use our own bidi // code. qp_->drawText(x, y, str, -1, QPainter::LTR); -#else - qp_->drawText(x, y, str); -#endif } else { smallCapsText(x, y, str, f); } diff --git a/src/frontends/qt2/QtView.C b/src/frontends/qt2/QtView.C index 5722d8957f..ca71adeee9 100644 --- a/src/frontends/qt2/QtView.C +++ b/src/frontends/qt2/QtView.C @@ -34,7 +34,7 @@ using std::string; -qfont_loader fontloader; +FontLoader fontloader; namespace lyx { diff --git a/src/frontends/qt2/lyx_gui.C b/src/frontends/qt2/lyx_gui.C index c9a040deab..ba0408dab3 100644 --- a/src/frontends/qt2/lyx_gui.C +++ b/src/frontends/qt2/lyx_gui.C @@ -165,7 +165,7 @@ bool use_gui = true; void parse_init(int & argc, char * argv[]) { // Force adding of font path _before_ QApplication is initialized - qfont_loader::initFontPath(); + FontLoader::initFontPath(); static LQApplication app(argc, argv); diff --git a/src/frontends/qt2/qfont_loader.C b/src/frontends/qt2/qfont_loader.C index 79b8ca7506..b1e7312722 100644 --- a/src/frontends/qt2/qfont_loader.C +++ b/src/frontends/qt2/qfont_loader.C @@ -1,5 +1,5 @@ /** - * \file qfont_loader.C + * \file FontLoader.C * This file is part of LyX, the document processor. * Licence details can be found in the file COPYING. * @@ -52,27 +52,7 @@ using std::string; #endif -int qfont_loader::font_info::charwidth(Uchar val) const -{ -// 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 (USE_LYX_FONTCACHE) -#error xxx - font_info::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; -#else - return metrics.width(QChar(val)); -#endif -} - - - -void qfont_loader::initFontPath() +void FontLoader::initFontPath() { #ifdef Q_WS_MACX CFBundleRef myAppBundle = CFBundleGetMainBundle(); @@ -154,10 +134,10 @@ size_t const nr_symbol_fonts = sizeof(symbol_fonts) / sizeof(symbol_font); string getRawName(string const & family) { - for (size_t i = 0; i < nr_symbol_fonts; ++i) { + for (size_t i = 0; i < nr_symbol_fonts; ++i) if (family == symbol_fonts[i].family) return symbol_fonts[i].xlfd; - } + lyxerr[Debug::FONT] << "BUG: family not found !" << endl; return string(); } @@ -246,47 +226,32 @@ pair const getSymbolFont(string const & family) } // namespace anon -qfont_loader::qfont_loader() +FontLoader::FontLoader() { - for (int i1 = 0; i1 < LyXFont::NUM_FAMILIES; ++i1) { - for (int i2 = 0; i2 < 2; ++i2) { - for (int i3 = 0; i3 < 4; ++i3) { - for (int i4 = 0; i4 < 10; ++i4) { + for (int i1 = 0; i1 < LyXFont::NUM_FAMILIES; ++i1) + for (int i2 = 0; i2 < 2; ++i2) + for (int i3 = 0; i3 < 4; ++i3) + for (int i4 = 0; i4 < 10; ++i4) fontinfo_[i1][i2][i3][i4] = 0; - } - } - } - } } -qfont_loader::~qfont_loader() +void FontLoader::update() { -} - - -void qfont_loader::update() -{ - for (int i1 = 0; i1 < LyXFont::NUM_FAMILIES; ++i1) { - for (int i2 = 0; i2 < 2; ++i2) { - for (int i3 = 0; i3 < 4; ++i3) { + for (int i1 = 0; i1 < LyXFont::NUM_FAMILIES; ++i1) + for (int i2 = 0; i2 < 2; ++i2) + for (int i3 = 0; i3 < 4; ++i3) for (int i4 = 0; i4 < 10; ++i4) { delete fontinfo_[i1][i2][i3][i4]; fontinfo_[i1][i2][i3][i4] = 0; } - } - } - } } -QFont const & qfont_loader::get(LyXFont const & f) -{ - return getfontinfo(f)->font; -} +///////////////////////////////////////////////// -qfont_loader::font_info::font_info(LyXFont const & f) +FontInfo::FontInfo(LyXFont const & f) : metrics(font) { @@ -358,19 +323,38 @@ qfont_loader::font_info::font_info(LyXFont const & f) } -qfont_loader::font_info * qfont_loader::getfontinfo(LyXFont const & f) +int FontInfo::width(Uchar val) const { - font_info * fi = fontinfo_[f.family()][f.series()][f.realShape()][f.size()]; - if (fi) - return fi; +// 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 (USE_LYX_FONTCACHE) +#error xxx + FontInfo::WidthCache::const_iterator cit = widthcache.find(val); + if (cit != widthcache.end()) + return cit->second; - font_info * fi2 = new font_info(f); - fontinfo_[f.family()][f.series()][f.realShape()][f.size()] = fi2; - return fi2; + int const w = metrics.width(QChar(val)); + widthcache[val] = w; + return w; +#else + return metrics.width(QChar(val)); +#endif } -bool qfont_loader::available(LyXFont const & f) +FontInfo & FontLoader::fontinfo(LyXFont const & f) +{ + FontInfo * fi = fontinfo_[f.family()][f.series()][f.realShape()][f.size()]; + if (fi) + return *fi; + + FontInfo * fi2 = new FontInfo(f); + fontinfo_[f.family()][f.series()][f.realShape()][f.size()] = fi2; + return *fi2; +} + + +bool FontLoader::available(LyXFont const & f) { if (!lyx_gui::use_gui) return false; diff --git a/src/frontends/qt2/qfont_loader.h b/src/frontends/qt2/qfont_loader.h index e28bbef1c0..a640ecb31d 100644 --- a/src/frontends/qt2/qfont_loader.h +++ b/src/frontends/qt2/qfont_loader.h @@ -30,31 +30,31 @@ * Qt font loader for LyX. Matches LyXFonts against * actual QFont instances, and also caches metrics. */ -class qfont_loader { +class FontInfo { public: - /// hold info about a particular font - class font_info { - public: - font_info(LyXFont const & f); + FontInfo(LyXFont const & f); - /// return pixel width for the given unicode char - int charwidth(Uchar val) const; + /// return pixel width for the given unicode char + int width(Uchar val) const; - /// the font instance - QFont font; - /// metrics on the font - QFontMetrics metrics; + /// the font instance + QFont font; + /// metrics on the font + QFontMetrics metrics; #if defined(USE_LYX_FONTCACHE) - typedef std::map WidthCache; - /// cache of char widths - WidthCache widthcache; + typedef std::map WidthCache; + /// cache of char widths + WidthCache widthcache; #endif - }; +}; - qfont_loader(); - ~qfont_loader(); +class FontLoader { +public: + /// hold info about a particular font + /// + FontLoader(); /// update fonts after zoom, dpi, font names, or norm change void update(); @@ -63,11 +63,13 @@ public: bool available(LyXFont const & f); /// get the QFont for this LyXFont - QFont const & get(LyXFont const & f); + QFont const & get(LyXFont const & f) { + return fontinfo(f).font; + } /// get the QFont metrics for this LyXFont QFontMetrics const & metrics(LyXFont const & f) { - return getfontinfo(f)->metrics; + return fontinfo(f).metrics; } /// Called before QApplication is initialized @@ -77,13 +79,13 @@ public: static void addToFontPath(); /// get font info (font + metrics) for the given LyX font. Does not fail. - font_info * getfontinfo(LyXFont const & f); + FontInfo & fontinfo(LyXFont const & f); private: /// BUTT ugly ! - font_info * fontinfo_[LyXFont::NUM_FAMILIES][2][4][10]; + FontInfo * fontinfo_[LyXFont::NUM_FAMILIES][2][4][10]; }; -extern qfont_loader fontloader; +extern FontLoader fontloader; #endif // QFONT_LOADER_H diff --git a/src/frontends/qt2/qfont_metrics.C b/src/frontends/qt2/qfont_metrics.C index da6905eb28..8bdb81e564 100644 --- a/src/frontends/qt2/qfont_metrics.C +++ b/src/frontends/qt2/qfont_metrics.C @@ -108,7 +108,7 @@ int smallcapswidth(char const * s, size_t ls, LyXFont const & f) return 1; // handle small caps ourselves ... - LyXFont smallfont(f); + LyXFont smallfont = f; smallfont.decSize().decSize().setShape(LyXFont::UP_SHAPE); QFontMetrics const & qm = fontloader.metrics(f); @@ -139,14 +139,14 @@ int width(char const * s, size_t ls, LyXFont const & f) return smallcapswidth(s, ls, f); Encoding const * encoding = fontencoding(f); - qfont_loader::font_info * fi = fontloader.getfontinfo(f); + FontInfo & fi = fontloader.fontinfo(f); if (ls == 1) - return fi->charwidth(encoding->ucs(s[0])); + return fi.width(encoding->ucs(s[0])); int w = 0; for (size_t i = 0; i < ls; ++i) - w += fi->charwidth(encoding->ucs(s[i])); + w += fi.width(encoding->ucs(s[i])); return w; } @@ -184,3 +184,4 @@ void buttonText(string const & str, LyXFont const & f, } } // namespace font_metrics +