]> git.lyx.org Git - features.git/commitdiff
* InsetNomencl.cpp (nomenclWidest):
authorJürgen Spitzmüller <spitz@lyx.org>
Fri, 22 May 2009 09:25:31 +0000 (09:25 +0000)
committerJürgen Spitzmüller <spitz@lyx.org>
Fri, 22 May 2009 09:25:31 +0000 (09:25 +0000)
- use FontMetrics to determine widest string.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@29776 a592a061-630c-0410-9148-cb99ea01b6c8

src/insets/InsetNomencl.cpp

index 92d5bad9f1c3a99cc582d7ba3305fd924a12e884..0389afe7fe34d72bee32a4bc85b8670ac96857af 100644 (file)
@@ -17,6 +17,7 @@
 
 #include "Buffer.h"
 #include "DispatchResult.h"
+#include "Font.h"
 #include "FuncRequest.h"
 #include "InsetIterator.h"
 #include "InsetList.h"
@@ -24,6 +25,8 @@
 #include "MetricsInfo.h"
 #include "sgml.h"
 
+#include "frontends/FontMetrics.h"
+
 #include "support/docstream.h"
 #include "support/gettext.h"
 #include "support/lstrings.h"
@@ -190,19 +193,19 @@ docstring nomenclWidest(Buffer const & buffer)
                        if (inset->lyxCode() != NOMENCL_CODE)
                                continue;
                        nomencl = static_cast<InsetNomencl const *>(inset);
-                       docstring const symbol = nomencl->getParam("symbol");
-                       // we can only check for the number of characters, since it is
-                       // impossible to get the info that "iiiii" is smaller than "WW"
-                       // we therefore output w times "W" as string ("W" is always the
-                       // widest character)
-                       int const wx = symbol.size();
-                       if (wx > w)
+                       docstring const symbol =
+                               nomencl->getParam("symbol");
+                       // This is only an approximation,
+                       // but the best we can get.
+                       int const wx =
+                               theFontMetrics(Font()).width(symbol);
+                       if (wx > w) {
                                w = wx;
+                               symb = symbol;
+                       }
                }
        }
-       // return the widest symbol as w times a "W"
-       for (int n = 1; n <= w; ++n)
-               symb = symb + "W";
+       // return the widest (or an empty) string
        return symb;
 }
 }
@@ -219,6 +222,7 @@ int InsetPrintNomencl::latex(odocstream & os, OutputParams const &) const
                if (!widest.empty()) {
                        // assure that the width is never below the
                        // predefined value of 1 cm
+                       // FIXME: Why this?
                        os << "\\settowidth{\\nomlabelwidth}{"
                           << widest
                           << "}\n";