From 81f21577b730438f7ea1b6cd673db9c38b437a81 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Andr=C3=A9=20P=C3=B6nitz?= Date: Thu, 29 Nov 2007 22:38:53 +0000 Subject: [PATCH] no need for pointers, not even leaking ones... git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@21869 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/frontends/qt4/GuiFontLoader.cpp | 39 ++++++++++++++--------------- src/frontends/qt4/GuiFontLoader.h | 5 ++-- src/frontends/qt4/GuiPainter.cpp | 12 ++++----- src/frontends/qt4/GuiViewSource.cpp | 3 +-- 4 files changed, 28 insertions(+), 31 deletions(-) diff --git a/src/frontends/qt4/GuiFontLoader.cpp b/src/frontends/qt4/GuiFontLoader.cpp index deaf5acd75..c6757809b3 100644 --- a/src/frontends/qt4/GuiFontLoader.cpp +++ b/src/frontends/qt4/GuiFontLoader.cpp @@ -24,15 +24,9 @@ #include "support/Package.h" #include "support/os.h" -#include - #include #include -using std::make_pair; - -using std::pair; -using std::vector; QString const math_fonts[] = {"cmex10", "cmmi10", "cmr10", "cmsy10", "eufm10", "msam10", "msbm10", "wasy10", "esint10"}; @@ -149,7 +143,7 @@ static bool isChosenFont(QFont & font, QString const & family) } -static pair const getSymbolFont(QString const & family) +QFont symbolFont(QString const & family, bool * ok) { LYXERR(Debug::FONT, "Looking for font family " << fromqstr(family) << " ... "); @@ -162,7 +156,8 @@ static pair const getSymbolFont(QString const & family) if (isChosenFont(font, family)) { LYXERR(Debug::FONT, "normal!"); - return make_pair(font, true); + *ok = true; + return font; } LYXERR(Debug::FONT, "Trying " << fromqstr(upper) << " ... "); @@ -170,7 +165,8 @@ static pair const getSymbolFont(QString const & family) if (isChosenFont(font, upper)) { LYXERR(Debug::FONT, "upper!"); - return make_pair(font, true); + *ok = true; + return font; } // A simple setFamily() fails on Qt 2 @@ -181,11 +177,13 @@ static pair const getSymbolFont(QString const & family) if (isChosenFont(font, family)) { LYXERR(Debug::FONT, "raw version!"); - return make_pair(font, true); + *ok = true; + return font; } LYXERR(Debug::FONT, " FAILED :-("); - return make_pair(font, false); + *ok = false; + return font; } } // namespace anon @@ -239,12 +237,13 @@ static QString makeFontName(QString const & family, QString const & foundry) GuiFontInfo::GuiFontInfo(FontInfo const & f) + : metrics(QFont()) { font.setKerning(false); QString const pat = symbolFamily(f.family()); if (!pat.isEmpty()) { - bool tmp; - boost::tie(font, tmp) = getSymbolFont(pat); + bool ok; + font = symbolFont(pat, &ok); } else { switch (f.family()) { case ROMAN_FAMILY: { @@ -312,7 +311,7 @@ GuiFontInfo::GuiFontInfo(FontInfo const & f) LYXERR(Debug::FONT, "The font has size: " << font.pointSizeF()); if (f.realShape() != SMALLCAPS_SHAPE) { - metrics.reset(new GuiFontMetrics(font)); + metrics = GuiFontMetrics(font); } else { // handle small caps ourselves ... FontInfo smallfont = f; @@ -322,16 +321,15 @@ GuiFontInfo::GuiFontInfo(FontInfo const & f) font2.setPointSizeF(convert(lyxrc.font_sizes[smallfont.size()]) * lyxrc.zoom / 100.0); - metrics.reset(new GuiFontMetrics(font, font2)); + metrics = GuiFontMetrics(font, font2); } - } bool GuiFontLoader::available(FontInfo const & f) { - static vector cache_set(NUM_FAMILIES, false); - static vector cache(NUM_FAMILIES, false); + static std::vector cache_set(NUM_FAMILIES, false); + static std::vector cache(NUM_FAMILIES, false); FontFamily family = f.family(); if (cache_set[family]) @@ -343,8 +341,9 @@ bool GuiFontLoader::available(FontInfo const & f) // We don't care about non-symbol fonts return false; - pair tmp = getSymbolFont(pat); - if (!tmp.second) + bool ok; + symbolFont(pat, &ok); + if (!ok) return false; cache[family] = true; diff --git a/src/frontends/qt4/GuiFontLoader.h b/src/frontends/qt4/GuiFontLoader.h index 4ca34b92da..867ac3dd3c 100644 --- a/src/frontends/qt4/GuiFontLoader.h +++ b/src/frontends/qt4/GuiFontLoader.h @@ -23,7 +23,6 @@ #include #include -#include namespace lyx { namespace frontend { @@ -40,7 +39,7 @@ public: /// The font instance QFont font; /// Metrics on the font - boost::scoped_ptr metrics; + GuiFontMetrics metrics; }; @@ -57,7 +56,7 @@ public: virtual void update(); virtual bool available(FontInfo const & f); inline virtual FontMetrics const & metrics(FontInfo const & f) { - return *fontinfo(f).metrics.get(); + return fontinfo(f).metrics; } /// Get the QFont for this FontInfo diff --git a/src/frontends/qt4/GuiPainter.cpp b/src/frontends/qt4/GuiPainter.cpp index a7f48682e1..dae8eda5ea 100644 --- a/src/frontends/qt4/GuiPainter.cpp +++ b/src/frontends/qt4/GuiPainter.cpp @@ -337,7 +337,7 @@ int GuiPainter::text(int x, int y, docstring const & s, // Here we use the font width cache instead of // textwidth = fontMetrics().width(str); // because the above is awfully expensive on MacOSX - textwidth = fi.metrics->width(s); + textwidth = fi.metrics.width(s); if (f.underbar() == FONT_ON) underline(f, x, y, textwidth); @@ -385,15 +385,15 @@ int GuiPainter::text(int x, int y, docstring const & s, // Only the left bearing of the first character is important // as we always write from left to right, even for // right-to-left languages. - int const lb = std::min(fi.metrics->lbearing(s[0]), 0); - int const mA = fi.metrics->maxAscent(); + int const lb = std::min(fi.metrics.lbearing(s[0]), 0); + int const mA = fi.metrics.maxAscent(); if (!QPixmapCache::find(key, pm)) { // Only the right bearing of the last character is // important as we always write from left to right, // even for right-to-left languages. - int const rb = fi.metrics->rbearing(s[s.size()-1]); + int const rb = fi.metrics.rbearing(s[s.size()-1]); int const w = textwidth + rb - lb; - int const mD = fi.metrics->maxDescent(); + int const mD = fi.metrics.maxDescent(); int const h = mA + mD; pm = QPixmap(w, h); pm.fill(Qt::transparent); @@ -531,7 +531,7 @@ void GuiPainter::dashedUnderline(FontInfo const & f, int x, int y, int width) if (height >= 2) height += below; - for (int n = 0; n < height; ++n) + for (int n = 0; n != height; ++n) line(x, y + below + n, x + width, y + below + n, f.color(), line_onoffdash); } diff --git a/src/frontends/qt4/GuiViewSource.cpp b/src/frontends/qt4/GuiViewSource.cpp index 1a36eed31e..a856d54949 100644 --- a/src/frontends/qt4/GuiViewSource.cpp +++ b/src/frontends/qt4/GuiViewSource.cpp @@ -20,15 +20,14 @@ #include "BufferView.h" #include "Buffer.h" #include "Cursor.h" -#include "support/gettext.h" #include "Paragraph.h" #include "TexRow.h" #include "support/docstream.h" +#include "support/gettext.h" #include #include -#include using std::string; -- 2.39.2