From 2833da914e537f0026fbd37a2ffb49e68c4a4959 Mon Sep 17 00:00:00 2001 From: Christoph Feck Date: Fri, 29 Oct 2010 00:43:02 +0000 Subject: [PATCH] Fix font size calculation Use a brute force method to handle the word wrapped texts that are used by kanagram. Also make the hint text box slightly taller to center better and have more room. BUG: 219473 svn path=/trunk/KDE/kdeedu/libkdeedu/; revision=1190821 --- kdeeduui/kedufontutils.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/kdeeduui/kedufontutils.cpp b/kdeeduui/kedufontutils.cpp index b75be7d..39ae6f3 100644 --- a/kdeeduui/kedufontutils.cpp +++ b/kdeeduui/kedufontutils.cpp @@ -28,7 +28,15 @@ int fontUtils::fontSize(QPainter &p, const QString &s1, int w, int h, Flags flag if (flags & DoNotAllowWordWrap) qtFlags = qtFlags & ~Qt::TextWordWrap; aux1 = p.boundingRect(QRect(0, 0, w, h), qtFlags, s1); if (aux1.width() == 0 || aux1.height() == 0) return -1; - else if (aux1.width() > w || aux1.height() > h) size = qMin(w * size / aux1.width(), h * size / aux1.height()); + else if (aux1.width() > w || aux1.height() > h) { + if (flags & DoNotAllowWordWrap || aux1.height() == p.fontMetrics().height()) { + size = qMin(w * size / aux1.width(), h * size / aux1.height()); + } else { + // Word wrapping can completely change the + // layout of the text, so the above will not work. + size = size - 1; + } + } else done = true; } -- 2.47.3