]> git.lyx.org Git - features.git/commitdiff
Handle negative values gracefully.
authorJean-Marc Lasgouttes <lasgouttes@lyx.org>
Tue, 6 Dec 2016 15:06:03 +0000 (16:06 +0100)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Tue, 6 Dec 2016 15:16:57 +0000 (16:16 +0100)
It may happen (for example with on the fly spell checking) that
GuiFontMetrics::pos2x is called with a negative pos value. Add a
special case for this situation.

Fixes bug #10506

src/frontends/qt4/GuiFontMetrics.cpp

index 77cda8043409223c62a0b4dc39a24d57ec1025d6..d3c89f1a593b6d9ae8f3b4dc3e08d574b62ffa2c 100644 (file)
@@ -205,6 +205,8 @@ GuiFontMetrics::getTextLayout(docstring const & s, QFont font,
 int GuiFontMetrics::pos2x(docstring const & s, int const pos, bool const rtl,
                           double const wordspacing) const
 {
+       if (pos <= 0)
+               return rtl ? width(s) : 0;
        QTextLayout const & tl = getTextLayout(s, font_, rtl, wordspacing);
        /* Since QString is UTF-16 and docstring is UCS-4, the offsets may
         * not be the same when there are high-plan unicode characters