From c8a829d273020d10ae5a22eb8a9fabafe7b81e6e Mon Sep 17 00:00:00 2001 From: Jean-Marc Lasgouttes Date: Tue, 6 Dec 2016 16:06:03 +0100 Subject: [PATCH] Handle negative values gracefully. 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 | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/frontends/qt4/GuiFontMetrics.cpp b/src/frontends/qt4/GuiFontMetrics.cpp index 77cda80434..d3c89f1a59 100644 --- a/src/frontends/qt4/GuiFontMetrics.cpp +++ b/src/frontends/qt4/GuiFontMetrics.cpp @@ -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 -- 2.39.2