r14928 by jghali - #8964 : 100% CPU usage when editing drop caps in layout view. Happens when drop cap character has zero ascent or descent (space for eg...), division by zero follows, avoid them

scribus-commit scribus-commit at lists.scribus.net
Wed Mar 24 21:50:20 CET 2010


Revision: 14928
Author: jghali
Date: 2010-03-24T20:47:41.289756Z
Commit message: #8964 : 100% CPU usage when editing drop caps in layout view.
Happens when drop cap character has zero ascent or descent (space for eg...), division by zero follows, avoid them

Changeset: 
M  /branches/Version135/Scribus/scribus/pageitem_textframe.cpp

Diffs:
Index: scribus/pageitem_textframe.cpp
===================================================================
--- scribus/pageitem_textframe.cpp	(revision 14927)
+++ scribus/pageitem_textframe.cpp	(revision 14928)
@@ -1154,6 +1154,10 @@
 				double realCharHeight = charStyle.font().realCharHeight(chstr[0], 1);
 				double realCharAscent = charStyle.font().realCharAscent(chstr[0], 1);
 				double fontAscent     = charStyle.font().ascent(style.charStyle().fontSize() / 10.0);
+				if (realCharHeight == 0.0)
+					realCharHeight = charStyle.font().height(style.charStyle().fontSize() / 10.0);
+				if (realCharAscent == 0.0)
+					realCharAscent = fontAscent;
 				if (style.lineSpacingMode() == ParagraphStyle::BaselineGridLineSpacing)
 				{
 					chsd = (10 * ((m_Doc->typographicSettings.valueBaseGrid * (DropLines-1) + fontAscent) / realCharHeight));
@@ -1219,6 +1223,9 @@
 				// drop caps are wider...
 				if ((hl->ch == SpecialChars::OBJECT) && (hl->embedded.hasItem()))
 				{
+					double itemHeight = hl->embedded.getItem()->gHeight + hl->embedded.getItem()->lineWidth();
+					if (itemHeight == 0)
+						itemHeight = charStyle.font().height(style.charStyle().fontSize() / 10.0);
 					wide = hl->embedded.getItem()->gWidth + hl->embedded.getItem()->lineWidth();
 					if (style.lineSpacingMode() == ParagraphStyle::BaselineGridLineSpacing)
 						asce = m_Doc->typographicSettings.valueBaseGrid * DropLines;
@@ -1230,16 +1237,19 @@
 							asce = charStyle.font().height(style.charStyle().fontSize() / 10.0) * DropLines;
 					}
 					hl->glyph.scaleH /= hl->glyph.scaleV;
-					hl->glyph.scaleV = (asce / (hl->embedded.getItem()->gHeight + hl->embedded.getItem()->lineWidth()));
+					hl->glyph.scaleV = (asce / itemHeight);
 					hl->glyph.scaleH *= hl->glyph.scaleV;
 				}
 				else
 				{
+					double realCharHeight = charStyle.font().realCharHeight(chstr[0], charStyle.fontSize() / 10.0);
+					if (realCharHeight == 0)
+						realCharHeight = charStyle.font().height(style.charStyle().fontSize() / 10.0);
 					wide = charStyle.font().realCharWidth(chstr[0], chsd / 10.0);
 					asce = charStyle.font().realCharHeight(chstr[0], chsd / 10.0);
 //					qDebug() QString("dropcaps pre: chsd=%1 realCharHeight = %2 chstr=%3").arg(chsd).arg(asce).arg(chstr2[0]);
 					hl->glyph.scaleH /= hl->glyph.scaleV;
-					hl->glyph.scaleV = (asce / charStyle.font().realCharHeight(chstr[0], charStyle.fontSize() / 10.0));
+					hl->glyph.scaleV = (asce / realCharHeight);
 					hl->glyph.scaleH *= hl->glyph.scaleV;
 				}
 				hl->glyph.xadvance = wide;




More information about the scribus-commit mailing list