From 72ae399fad99fb5f8f000c52ce64f333f14949e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrgen=20Spitzm=C3=BCller?= Date: Fri, 22 May 2009 09:25:31 +0000 Subject: [PATCH] * InsetNomencl.cpp (nomenclWidest): - 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 | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/insets/InsetNomencl.cpp b/src/insets/InsetNomencl.cpp index 92d5bad9f1..0389afe7fe 100644 --- a/src/insets/InsetNomencl.cpp +++ b/src/insets/InsetNomencl.cpp @@ -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(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";