Index: scribus/pageitem_textframe.cpp
===================================================================
--- scribus/pageitem_textframe.cpp	(revision 19472)
+++ scribus/pageitem_textframe.cpp	(working copy)
@@ -60,6 +60,12 @@
 #include "util.h"
 #include "util_math.h"
 
+// 28Aug14 William Bader change debug from qDebug() calls controlled by comments to scDebug() calls controlled by SC_DEBUG_FILE.
+#define SC_DEBUG_FILE defined(DEBUG_PAGEITEMTEXTFRAME)
+#define SC_DEBUG_MODULE PageItem_TextFrame
+#define SC_DEBUG_LOG_TIME 0
+#include "scdebug.h"
+
 using namespace std;
 
 PageItem_TextFrame::PageItem_TextFrame(ScribusDoc *pa, double x, double y, double w, double h, double w2, QString fill, QString outline)
@@ -289,7 +295,7 @@
 		} // if(OnMasterPage.isEmpty()
 	} // if(!Embedded)
 	else
-		qDebug() << "QRegion empty";
+		scDebug() << "QRegion empty";
 	return result;
 }
 
@@ -308,19 +314,19 @@
 			if (!shadows.contains(OnMasterPage)) {
 				shadows[OnMasterPage] = itemText;
 //				const ParagraphStyle& pstyle(shadows[OnMasterPage].paragraphStyle(0));
-//				qDebug() << QString("Pageitem_Textframe: style of master: %1 align=%2").arg(pstyle.parent()).arg(pstyle.alignment());
-//				qDebug() << QString("Pageitem_Textframe: shadow itemText->%1").arg(OnMasterPage);
+//				scDebug() << QString("Pageitem_Textframe: style of master: %1 align=%2").arg(pstyle.parent()).arg(pstyle.alignment());
+//				scDebug() << QString("Pageitem_Textframe: shadow itemText->%1").arg(OnMasterPage);
 			}
 			if (newShadow != OnMasterPage) {
 				shadows[newShadow] = shadows[OnMasterPage].copy();
 //				const ParagraphStyle& pstyle(shadows[newShadow].paragraphStyle(0));
-//				qDebug() << QString("Pageitem_Textframe: style of shadow copy: %1 align=%2").arg(pstyle.parent()).arg(pstyle.alignment());
+//				scDebug() << QString("Pageitem_Textframe: style of shadow copy: %1 align=%2").arg(pstyle.parent()).arg(pstyle.alignment());
 			}
-//			qDebug() << QString("Pageitem_Textframe: shadow %1<-%2").arg(newShadow).arg(OnMasterPage);
+//			scDebug() << QString("Pageitem_Textframe: shadow %1<-%2").arg(newShadow).arg(OnMasterPage);
 		}
 		itemText = shadows[newShadow];
 //		const ParagraphStyle& pstyle(itemText.paragraphStyle(0));
-//		qDebug() << QString("Pageitem_Textframe: style of shadow: %1 align=%2").arg(pstyle.parent()).arg(pstyle.alignment());
+//		scDebug() << QString("Pageitem_Textframe: style of shadow: %1 align=%2").arg(pstyle.parent()).arg(pstyle.alignment());
 		invalid = true;
 		currentShadow = newShadow;
 	}
@@ -358,25 +364,25 @@
 
 	debugFile.close();
 }
-
+*/
 static void dumpIt(const ParagraphStyle& pstyle, QString indent = QString("->"))
 {
-	QString db = QString("%6%1/%2 @ %3: %4--%5 linespa%6: %7 align%8")
+	QString db = QString("%1%2/%3: margin %4--%5 linespa%6: %7 align%8")
+		   .arg(indent)
 		   .arg(pstyle.name())
 		   .arg(pstyle.parent())
-		   .arg( (unsigned long int) &pstyle)
+		   // .arg( (unsigned long int) &pstyle)
 		   .arg(pstyle.leftMargin())
 		   .arg(pstyle.rightMargin())
-		   .arg(indent)
 		   .arg(pstyle.lineSpacingMode())
 		   .arg(pstyle.lineSpacing())
 		   .arg(pstyle.alignment());
-	qDebug() << db;
+	scDebug() << db;
 	static QString more("  ");
 	if (pstyle.hasParent())
 		dumpIt(*dynamic_cast<const ParagraphStyle*>(pstyle.parentStyle()), more + indent);
 }
-*/
+
 static const bool legacy = true;
 
 /*
@@ -408,7 +414,7 @@
 			int count   = static_cast<int>(len / wt);
 			double sPos = -len;
 			tglyph->xoffset = sPos;
-//			qDebug() << QString("tab leaders: %1 %2 width=%3 count=%4").arg(sPos).arg(curLine.y).arg(wt).arg(count);
+//			scDebug() << QString("tab leaders: %1 %2 width=%3 count=%4").arg(sPos).arg(curLine.y).arg(wt).arg(count);
 			for (int cx = 1; cx < count; ++cx)
 			{
 				// clone fillchar
@@ -720,7 +726,7 @@
 		/*double oldEndX2 = endOfLine_old(shape, pf2, morespace, yAsc, yDesc);
 		if (oldEndX2 != qMin(EndX2, maxX))
 		{
-			qDebug() << "Different EndX : " << oldEndX2 << " (old) " << EndX2 << " (new) ";
+			scDebug() << "Different EndX : " << oldEndX2 << " (old) " << EndX2 << " (new) ";
 		}*/
 
 		return qMin(EndX2, maxX);
@@ -755,7 +761,7 @@
 				asce = obj->height() + obj->lineWidth() * (cStyle.scaleV() / 1000.0);
 			else
 				asce = cStyle.font().realCharAscent(ch, cStyle.fontSize() / 10.0);
-			//	qDebug() << QString("checking char 'x%2' with ascender %1 > %3").arg(asce).arg(ch.unicode()).arg(result);
+			scDebug() << QString("getLineAscent, checking char 'x%2' with ascender %1 > %3").arg(asce).arg(ch.unicode()).arg(result);
 			result = qMax(result, asce);
 		}
 		return result;
@@ -788,7 +794,7 @@
 				desc = 0.0;
 			else
 				desc = cStyle.font().realCharDescent(ch, cStyle.fontSize() / 10.0);
-			//	qDebug() << QString("checking char 'x%2' with ascender %1 > %3").arg(asce).arg(ch.unicode()).arg(result);
+			scDebug() << QString("getLineDescent, checking char 'x%2' with descender %1 > %3").arg(desc).arg(ch.unicode()).arg(result);
 			result = qMax(result, desc);
 		}
 		return result;
@@ -816,7 +822,7 @@
 				asce = (obj->height() + obj->lineWidth()) * (cStyle.scaleV() / 1000.0);
 			else
 				asce = cStyle.font().height (cStyle.fontSize() / 10.0);
-			//	qDebug() << QString("checking char 'x%2' with ascender %1 > %3").arg(asce).arg(ch.unicode()).arg(result);
+			scDebug() << QString("getLineHeight, checking char 'x%2' with ascender %1 > %3").arg(asce).arg(ch.unicode()).arg(result);
 			result = qMax(result, asce);
 		}
 		return result;
@@ -847,9 +853,9 @@
 				asce = cStyle.font().realCharAscent(ch, cStyle.fontSize() / 10.0) * scaleV + offset;
 				desc = cStyle.font().realCharDescent(ch, cStyle.fontSize() / 10.0) * scaleV - offset;
 			}
-			//	qDebug() << QString("checking char 'x%2' with ascender %1 > %3").arg(asce).arg(ch.unicode()).arg(result);
 			line.ascent  = qMax(line.ascent, asce);
 			line.descent = qMax(line.descent, desc);
+			scDebug() << QString("updateHeightMetrics, checking char 'x%1' asc %2, set asc %3 desc %4").arg(ch.unicode()).arg(asce).arg(line.ascent).arg(line.descent);
 		}
 	}
 
@@ -887,7 +893,7 @@
 //		double firstasce = style.lineSpacing();
 //		double currasce  = getLineHeight(itemText);
 //		double adj = firstasce - currasce;
-//		qDebug() << QString("move2 line %1.. down by %2").arg(current.line.firstItem).arg(-adj);
+//		scDebug() << QString("move2 line %1.. down by %2").arg(current.line.firstItem).arg(-adj);
 //		line.ascent = currasce;
 //		line.y -= adj;
 //		yPos -= adj;
@@ -1034,7 +1040,7 @@
 	double glyphScale = 1 + glyphExtension;
 
 /*
-	qDebug() << QString("justify: line = %7 natural = %1 + %2 = %3 (%4); spaces + %5%%; min=%8; glyphs + %6%%; min=%9")
+	scDebug() << QString("justify: line = %7 natural = %1 + %2 = %3 (%4); spaces + %5%%; min=%8; glyphs + %6%%; min=%9")
 		   .arg(spaceNatural).arg(glyphNatural).arg(spaceNatural+glyphNatural).arg(line.naturalWidth)
 		   .arg(spaceExtension).arg(glyphExtension).arg(line.width)
 		   .arg(style.minWordTracking()).arg(style.minGlyphExtension());
@@ -1184,7 +1190,7 @@
 		by = by - item->doc()->Pages->at(OwnPage)->yOffset();
 	int ol1 = qRound((by + control.yPos - item->doc()->guidesPrefs().offsetBaselineGrid) * 10000.0);
 	int ol2 = static_cast<int>(ol1 / item->doc()->guidesPrefs().valueBaselineGrid);
-//						qDebug() << QString("baseline adjust: y=%1->%2").arg(current.yPos).arg(ceil(  ol2 / 10000.0 ) * item->doc()->typographicSettings.valueBaselineGrid + item->doc()->typographicSettings.offsetBaselineGrid - by);
+	// scDebug() << QString("baseline adjust: y=%1->%2").arg(current.yPos).arg(ceil(  ol2 / 10000.0 ) * item->doc()->typographicSettings.valueBaselineGrid + item->doc()->typographicSettings.offsetBaselineGrid - by);
 
 	return ceil(  ol2 / 10000.0 ) * item->doc()->guidesPrefs().valueBaselineGrid + item->doc()->guidesPrefs().offsetBaselineGrid - by;
 }
@@ -1226,7 +1232,7 @@
 	if (!prev->incompleteLines) return false;   // no incomplete lines - nothing to do
 	int pos = textLayout.endOfFrame()-1;
 	QChar lastChar = itemText.text (pos);
-	// qDebug()<<"pos is"<<pos<<", length is"<<itemText.length()<<", incomplete is "<<prev->incompleteLines;
+	// scDebug()<<"pos is"<<pos<<", length is"<<itemText.length()<<", incomplete is "<<prev->incompleteLines;
 	if ((pos != itemText.length()-1) && (!SpecialChars::isBreak (lastChar, true)))
 		return false;  // the paragraph isn't ending yet
 	int lines = textLayout.lines();  // lines added to the current frame
@@ -1244,7 +1250,7 @@
 	// if pulling the lines would lead to the original frame having too few, pull the whole paragraph
 	if (prev->incompleteLines - pull < prevneed)
 		pull = prev->incompleteLines;
-	// qDebug()<<"pulling"<<pull<<"lines;
+	// scDebug()<<"pulling"<<pull<<"lines;
 	// Okay, move the starting/ending character
 	int startingPos = prev->incompletePositions[prev->incompleteLines - pull];
 	for (int i = 0; i < pull; ++i)
@@ -1300,10 +1306,10 @@
 
 void PageItem_TextFrame::layout()
 {
-// 	qDebug()<<"==Layout==" << itemName() ;
+ 	scDebug()<<"==Layout==" << itemName() ;
 // 	printBacktrace(24);
 	if (BackBox != NULL && BackBox->invalid) {
-//		qDebug("textframe: len=%d, going back", itemText.length());
+		scDebug() << "textframe: len=" << itemText.length() << ", going back";
 		// Why that invalid = false here? Calling prevInChain->layout() does
 		// not ensure that this box will be layouted
 		// invalid = false;
@@ -1321,13 +1327,13 @@
 			return;
 	}
 	else if (!invalid && OnMasterPage.isEmpty()) {
-//		qDebug() << QString("textframe: len=%1, invalid=%2 OnMasterPage=%3: no relayout").arg(itemText.length()).arg(invalid).arg(OnMasterPage);
+		scDebug() << QString("textframe: len=%1, invalid=%2 OnMasterPage=%3: no relayout").arg(itemText.length()).arg(invalid).arg(OnMasterPage);
 		return;
 	}
 	if (invalid && BackBox == NULL)
 		firstChar = 0;
 
-//	qDebug() << QString("textframe(%1,%2): len=%3, start relayout at %4").arg(Xpos).arg(Ypos).arg(itemText.length()).arg(firstInFrame());
+	scDebug() << QString("textframe(%1,%2): len=%3, start relayout at %4").arg(xPos()).arg(yPos()).arg(itemText.length()).arg(firstInFrame());
 	QPoint pt1, pt2;
 	QRect pt;
 	double chs, chsd = 0;
@@ -1382,15 +1388,13 @@
 	QMap<int, Mark*> noteMarksPosMap;  //maping notes marks and its position in text
 
 	// dump styles
-/*
-	for (int i=0; i < itemText.nrOfParagraphs(); ++i) {
+	for (uint i=0; i < itemText.nrOfParagraphs(); ++i) {
 		const ParagraphStyle& pstyle(itemText.paragraphStyle(itemText.endOfParagraph(i)));
-		qDebug("par %d:", i);
+		scDebug() << "par " << i << ":";
 		dumpIt(pstyle);
 	}
-	qDebug() << "default:";
+	scDebug() << "default:";
 	dumpIt(itemText.defaultStyle());
-*/
 
 	setShadow();
 	int itLen = itemText.length();
@@ -1458,8 +1462,8 @@
 			style = itemText.paragraphStyle(firstInFrame());
 			style.setLineSpacing (calculateLineSpacing (style, this));
 
-//			qDebug() << QString("style @0: %1 -- %2, %4/%5 char: %3").arg(style.leftMargin()).arg(style.rightMargin())
-//				   .arg(style.charStyle().asString()).arg(style.name()).arg(style.parent()?style.parent()->name():"");
+			scDebug() << QString("style @0: %1 -- %2, %4/%5 char: %3").arg(style.leftMargin()).arg(style.rightMargin())
+				   .arg(style.charStyle().asString()).arg(style.name()).arg(style.parent());
 			if (style.hasDropCap())
 			{
 				chs = calculateLineSpacing (style, this) * style.dropCapLines() * 10;
@@ -1468,7 +1472,7 @@
 				chs = cstyle.fontSize();
 			desc = -cstyle.font().descent(chs / 10.0);
 			current.yPos = m_textDistanceMargins.Top + lineCorr;
-//			qDebug() << QString("first line at y=%1").arg(current.yPos);
+			scDebug() << QString("first line at y=%1").arg(current.yPos);
 		}
 		else // empty itemText:
 		{
@@ -1674,6 +1678,8 @@
 			itemText.clearFlag(a, ScLayout_DropCap);
 			itemText.clearFlag(a, ScLayout_SoftHyphenVisible);
 
+			scDebug() << QString("no space at begin line, legacy=%1 current.itemsInLine=%2").arg(legacy).arg(current.itemsInLine);
+
 			// No space at begin of line,
 			if (legacy)
 			{
@@ -1685,10 +1691,12 @@
 				{
 					itemText.setFlag(a, ScLayout_SuppressSpace);
 					glyphs->xadvance = 0;
+					scDebug() << QString("legacy, no items in line but paragraph, suppress");
 					continue;
 				}
 				else
 					itemText.clearFlag(a, ScLayout_SuppressSpace);
+				scDebug() << QString("legacy, do not suppress space");
 			}
 			else // from 134 on use NBSPACE for this effect
 			{
@@ -1696,10 +1704,12 @@
 				{
 					itemText.setFlag(a, ScLayout_SuppressSpace);
 					glyphs->xadvance = 0;
+					scDebug() << QString("not legacy, no items in line but paragraph, suppress");
 					continue;
 				}
 				else
 					itemText.clearFlag(a, ScLayout_SuppressSpace);
+				scDebug() << QString("not legacy, do not suppress space");
 			}
 			if (current.itemsInLine == 0)
 			{
@@ -1732,11 +1742,12 @@
 					{
 						DropLines = style.dropCapLines();
 						DropCapDrop = calculateLineSpacing (style, this) * (DropLines - 1);
-//						qDebug() << QString("dropcapdrop: y=%1+%2").arg(current.yPos).arg(DropCapDrop);
+//						scDebug() << QString("dropcapdrop: y=%1+%2").arg(current.yPos).arg(DropCapDrop);
 					}
 				}
 			}
 			// find charsize factors
+			scDebug() << QString("DropCmode %1").arg(DropCmode);
 			if (DropCmode)
 			{
 //				DropCapDrop = calculateLineSpacing (style, this) * (DropLines - 1);
@@ -1774,6 +1785,7 @@
 					chs = qRound((currentObject->height() + currentObject->lineWidth()) * 10);
 				else
 					chs = charStyle.fontSize();
+				scDebug() << QString("not dropCapMode, HasObject=%1 chs=%2").arg(HasObject).arg(chs);
 			}
 			// set StartOfLine (and find tracking?)
 			if (current.itemsInLine == 0)
@@ -1786,6 +1798,7 @@
 				kernVal = 0; // chs * charStyle.tracking() / 10000.0;
 				itemText.clearFlag(a, ScLayout_StartOfLine);
 			}
+			scDebug() << QString("itemsInLine=%1 HasObject=%2").arg(current.itemsInLine).arg(HasObject);
 			glyphs->yadvance = 0;
 			layoutGlyphs(charStyle, chstr, itemText.flags(a), *glyphs);
 
@@ -1911,7 +1924,7 @@
 					if (realCharHeight == 0)
 						realCharHeight = font.height(style.charStyle().fontSize() / 10.0);
 					asce = font.ascent(hlcsize10);
-					// qDebug() QString("dropcaps pre: chsd=%1 realCharHeight = %2 chstr=%3").arg(chsd).arg(asce).arg(chstr2[0]);
+					scDebug() << QString("dropcaps pre: chsd=%1 realCharHeight = %2 chstr=%3").arg(chsd).arg(asce).arg(chstr[0]);
 					glyphs->scaleH /= glyphs->scaleV;
 					glyphs->scaleV = (realAsce / realCharHeight);
 					glyphs->scaleH *= glyphs->scaleV;
@@ -1939,15 +1952,18 @@
 							continue;
 						realDesc = qMax(realDesc, font.realCharDescent(chstr[i], hlcsize10));
 						realAsce = font.realCharAscent(chstr[i], hlcsize10);
+						scDebug() << QString("chstr %1='%2' Desc=%3 Asce=%4").arg(i).arg(chstr[i]).arg(realDesc).arg(realAsce);
 					}
 					realDesc =  realDesc * scaleV - offset;
 					desc = -font.descent(hlcsize10);
 					current.rememberShrinkStretch(currentCh, wide, style);
+					scDebug() << QString("scaleV=%1 offset=%2 realDesc=%3 desc=%4").arg(scaleV).arg(offset).arg(realDesc).arg(desc);
 				}
 				if (HasObject)
 				{
 					asce = currentObject->height() + currentObject->lineWidth();
 					realAsce = asce * scaleV + offset;
+					scDebug() << QString("object, asce=%1 scaleV=%2 offset=%3 realAsce=%4").arg(asce).arg(scaleV).arg(offset).arg(realAsce);
 				}
 				else
 				{
@@ -1959,6 +1975,7 @@
 						for (int i = 0; i < chstrLen; ++i)
 							realAsce = qMax(realAsce, font.realCharAscent(chstr[i], hlcsize10) * scaleV + offset);
 					}
+					scDebug() << QString("no object, HasMark=%1 BulNumMode=%2 asce=%3 scaleV=%4 offset=%5 realAsce=%6").arg(HasMark).arg(BulNumMode).arg(asce).arg(scaleV).arg(offset).arg(realAsce);
 				}
 			}
 //			if (BulNumMode)
@@ -1974,7 +1991,12 @@
 						lastLineY = qMax(lastLineY, m_textDistanceMargins.Top + lineCorr);
 						//fix for proper rendering first empty line (only with PARSEP)
 						if (chstr[0] == SpecialChars::PARSEP)
+						{
 							current.yPos += style.lineSpacing();
+							scDebug() << QString("start of col, recalculate y, parsep, fontsize=%1 stylelinespacing=%2, yPos %3")
+								.arg(font.height(style.charStyle().fontSize() / 10.0))
+								.arg(style.lineSpacing()).arg(current.yPos);
+						}
 						if (style.lineSpacingMode() == ParagraphStyle::BaselineGridLineSpacing || FlopBaseline)
 						{
 							if (current.yPos <= lastLineY)
@@ -1985,6 +2007,7 @@
 							int ol1 = qRound((by + current.yPos - m_Doc->guidesPrefs().offsetBaselineGrid) * 10000.0);
 							int ol2 = static_cast<int>(ol1 / m_Doc->guidesPrefs().valueBaselineGrid);
 							current.yPos = ceil(  ol2 / 10000.0 ) * m_Doc->guidesPrefs().valueBaselineGrid + m_Doc->guidesPrefs().offsetBaselineGrid - by;
+							scDebug() << QString("start of col, recalculate y for baselinegrid spacing or flopbaseline, yPos=%1").arg(current.yPos);
 						}
 						else if (style.lineSpacingMode() != ParagraphStyle::BaselineGridLineSpacing)
 						{
@@ -1999,6 +2022,7 @@
 								current.yPos += style.lineSpacing();
 							else
 								current.yPos += asce;
+							scDebug() << QString("start of col, recalculate y for not baselinegrid spacing, yPos=%1").arg(current.yPos);
 						}
 					}
 					else
@@ -2012,9 +2036,14 @@
 							int ol1 = qRound((by + current.yPos - m_Doc->guidesPrefs().offsetBaselineGrid) * 10000.0);
 							int ol2 = static_cast<int>(ol1 / m_Doc->guidesPrefs().valueBaselineGrid);
 							current.yPos = ceil(  ol2 / 10000.0 ) * m_Doc->guidesPrefs().valueBaselineGrid + m_Doc->guidesPrefs().offsetBaselineGrid - by;
+							scDebug() << QString("inside col, recalculate y for baselinegrid spacing, yPos=%1").arg(current.yPos);
 						}
 						else
+						{
 							current.yPos += style.lineSpacing();
+							scDebug() << QString("inside col, no parsep, increment y for style line spacing %1, yPos=%2")
+								.arg(style.lineSpacing()).arg(current.yPos);
+						}
 					}
 					if (DropCmode)
 						current.yPos += DropCapDrop;
@@ -2046,6 +2075,7 @@
 			current.recalculateY = true;
 			maxYAsc = 0.0, maxYDesc = 0.0;
 			double addAsce = 0.0;
+			scDebug() << QString("yPos=%1, startOfCol=%2").arg(current.yPos).arg(current.startOfCol);
 			if (current.startOfCol)
 			{
 				if (DropCmode)
@@ -2052,6 +2082,7 @@
 					addAsce = qMax(realAsce, asce + offset);
 				else
 					addAsce = asce + offset;
+				scDebug() << QString("after DropCmode %1, realAsce=%2 asce=%3 offset=%4 addAsce=%5").arg(DropCmode).arg(realAsce).arg(asce).arg(offset).arg(addAsce);
 				if (style.lineSpacingMode() != ParagraphStyle::BaselineGridLineSpacing)
 				{
 					if (firstLineOffset() == FLOPRealGlyphHeight)
@@ -2058,6 +2089,7 @@
 						addAsce = realAsce;
 					else if (firstLineOffset() == FLOPLineSpacing)
 						addAsce = style.lineSpacing();
+					scDebug() << QString("lineSpacingMode != BaselineGridLineSpacing, firstLineOffset=%1 (Glyph %2 Line %3), update addAsce to %4").arg(firstLineOffset()).arg(FLOPRealGlyphHeight).arg(FLOPLineSpacing).arg(addAsce);
 				}
 				maxYAsc = current.yPos - addAsce;
 			}
@@ -2066,6 +2098,7 @@
 			//fix for glyphs with negative realAsce value
 			maxYAsc = qMax(maxYAsc, 0.0);
 			maxYDesc = current.yPos + realDesc;
+			scDebug() << QString("current.yPos=%1 maxYAsc=%2 current.afterOverflow=%3").arg(current.yPos).arg(maxYAsc).arg(current.afterOverflow);
 
 			if (true||style.lineSpacingMode() == ParagraphStyle::AutomaticLineSpacing)
 			{
@@ -3080,7 +3113,7 @@
 		nextFrame->firstChar = MaxChars;
 	}
 	itemText.blockSignals(false);
-//	qDebug("textframe: len=%d, done relayout", itemText.length());
+	scDebug() << "textframe: len=" << itemText.length() << ", done relayout";
 	return;
 
 NoRoom:
@@ -3115,15 +3148,15 @@
 				next->itemText.setCursorPosition( qMax(nCP, signed(MaxChars)) );
 				//							Doc->currentPage = NextBox->OwnPage;
 				//							NextBox->OwnPage->SelectItemNr(NextBox->ItemNr);
-//				qDebug("textframe: len=%d, leaving relayout in editmode && Tinput", itemText.length());
+				scDebug() << "textframe: len=" << itemText.length() << ", leaving relayout in editmode && Tinput";
 				return;
 			}
 		}
 		// relayout next frame
-//		qDebug("textframe: len=%d, going to next", itemText.length());
+		scDebug() << "textframe: len=" << itemText.length() << ", going to next";
 		next->layout();
 	}
-//	qDebug("textframe: len=%d, done relayout (no room %d)", itemText.length(), MaxChars);
+	scDebug() << "textframe: len=" << itemText.length() << ", done relayout (no room " << MaxChars << ")";
 	itemText.blockSignals(false);
 }
 
@@ -3649,7 +3682,7 @@
 
 	if (itemText.length() != 0)
 	{
-		//		qDebug("drawing textframe: len=%d", itemText.length());
+		//		scDebug("drawing textframe: len=%d", itemText.length());
 		if (imageFlippedH())
 		{
 			p->translate(m_width, 0);
@@ -3837,7 +3870,7 @@
 			}
 		}
 	//	else {
-	//		//		qDebug("skipping textframe: len=%d", itemText.count());
+	//		//		scDebug("skipping textframe: len=%d", itemText.count());
 	//	}
 		//	pf2.end();
 	}
@@ -4656,13 +4689,13 @@
 				doUpdate = true;
 			}
 			/*
-			qDebug()<<"Key:"<<k->key();
-			qDebug()<<"Text:"<<k->text();
-			qDebug()<<"Size:"<<k->text().size();
-			qDebug()<<"Modifiers:"<<k->modifiers();
-			qDebug()<<"Native Modifiers:"<<k->nativeModifiers();
-			qDebug()<<"Native Scan Code:"<<k->nativeScanCode();
-			qDebug()<<"Native Virtual Key:"<<k->nativeVirtualKey();
+			scDebug()<<"Key:"<<k->key();
+			scDebug()<<"Text:"<<k->text();
+			scDebug()<<"Size:"<<k->text().size();
+			scDebug()<<"Modifiers:"<<k->modifiers();
+			scDebug()<<"Native Modifiers:"<<k->nativeModifiers();
+			scDebug()<<"Native Scan Code:"<<k->nativeScanCode();
+			scDebug()<<"Native Virtual Key:"<<k->nativeVirtualKey();
 			*/
 		}
 		//if ((kk == Qt::Key_Tab) || ((kk == Qt::Key_Return) && (buttonState & Qt::ShiftButton)))
Index: scribus/scdebug.h
===================================================================
--- scribus/scdebug.h	(revision 19472)
+++ scribus/scdebug.h	(working copy)
@@ -32,6 +32,12 @@
 
 #if defined(QT_NO_DEBUG_OUTPUT) || (defined(SC_DEBUG_FILE) && SC_DEBUG_FILE == 0)
 
+// 28Aug14 William Bader create SC_DEBUG_MODULE to avoid crashes if some modules have debugging and others do not.
+//  Modules can set SC_DEBUG_MODULE to something unique and valid for an identifier before including this header.
+
+#define ScNoDebug ScNoDebugClass##SC_DEBUG_MODULE
+#define scDebug scDebugFunc##SC_DEBUG_MODULE
+
 class ScNoDebug
 {
 public:
@@ -46,6 +52,18 @@
 
 #include <QDebug>
 #include <QTime>
-inline QDebug scDebug() { return QDebug(QtDebugMsg) << QTime::currentTime().toString("[hh:mm:ss.zzz]"); }
+inline QDebug scDebug()
+{
+	return QDebug(QtDebugMsg)
 
+// 28Aug14 William Bader create SC_DEBUG_LOG_TIME to allow modules to control the time stamp.
+//  Modules can set SC_DEBUG_LOG_TIME to 0 to suppress the time stamp.
+//  Suppressing the time stamp makes it easier to compare logs from different runs.
+
+#if !defined(SC_DEBUG_LOG_TIME) || SC_DEBUG_LOG_TIME
+		<< QTime::currentTime().toString("[hh:mm:ss.zzz]")
 #endif
+		;
+}
+
+#endif
