r15805 by craig - Add in StoryText::wordAt for future use

scribus-commit scribus-commit at lists.scribus.net
Sun Nov 7 19:26:26 CET 2010


Author: craig
Date: Sun Nov  7 18:26:26 2010
New Revision: 15805

URL: http://scribus.info/websvn/listing.php?repname=Scribus&sc=1&rev=15805
Log:
Add in StoryText::wordAt for future use

Modified:
    trunk/Scribus/scribus/text/storytext.cpp
    trunk/Scribus/scribus/text/storytext.h

Modified: trunk/Scribus/scribus/text/storytext.cpp
URL: http://scribus.info/websvn/diff.php?repname=Scribus&rev=15805&path=/trunk/Scribus/scribus/text/storytext.cpp
==============================================================================
--- trunk/Scribus/scribus/text/storytext.cpp (original)
+++ trunk/Scribus/scribus/text/storytext.cpp Sun Nov  7 18:26:26 2010
@@ -918,8 +918,8 @@
 // positioning. all positioning methods return char positions
 // FIXME: make that methods use correct semantic boundaries
 
-static QString wordBoundaries(" .,:;\"'!?\n");
-static QString sentenceBoundaries(".:!?\n");
+static QString wordBoundaries(" .,:;\"'!?\n\t");
+static QString sentenceBoundaries(".:!?\n\t");
 
 int StoryText::nextChar(int pos)
 {
@@ -979,6 +979,45 @@
 	while (pos > 0 && text(pos) != SpecialChars::PARSEP)
 		--pos;
 	return pos;
+}
+
+QString StoryText::wordAt(int pos) const
+{
+	if (pos < 0)
+		pos += length();
+	assert(pos >= 0);
+	assert(pos + signed(len) <= length());
+
+	int len = length();
+	//Find the previous word position
+	int tmpPosStart = qMax(0, pos-1);
+	int startWordPos=0;
+	if (tmpPosStart!=0)
+	{
+		while (tmpPosStart > 0 && wordBoundaries.indexOf(text(tmpPosStart)) < 0)
+			--tmpPosStart;
+		startWordPos= wordBoundaries.indexOf(text(tmpPosStart)) < 0 ? tmpPosStart + 1 : tmpPosStart;
+		++startWordPos;
+	}
+	qDebug ()<<"Start Word Pos:"<<startWordPos;
+	//Find the next word position
+	int tmpPosEnd = qMin(len, pos+1);
+	while (tmpPosEnd < len  && wordBoundaries.indexOf(text(tmpPosEnd)) < 0)
+	{
+		qDebug()<<tmpPosEnd<<text(tmpPosEnd)<<wordBoundaries.indexOf(text(tmpPosEnd));
+		++tmpPosEnd;
+	}
+	int endWordPos=tmpPosEnd < len ? tmpPosEnd + 1 : tmpPosEnd;
+	if (endWordPos>0)
+		--endWordPos;
+	qDebug ()<<"End Word Pos:"<<endWordPos;
+	QString result;
+	StoryText* that(const_cast<StoryText*>(this));
+	for (int i = startWordPos; i < endWordPos; ++i)
+	{
+		result += that->d->at(i)->ch;
+	}
+	return result;
 }
 
 // these need valid layout:

Modified: trunk/Scribus/scribus/text/storytext.h
URL: http://scribus.info/websvn/diff.php?repname=Scribus&rev=15805&path=/trunk/Scribus/scribus/text/storytext.h
==============================================================================
--- trunk/Scribus/scribus/text/storytext.h (original)
+++ trunk/Scribus/scribus/text/storytext.h Sun Nov  7 18:26:26 2010
@@ -116,6 +116,7 @@
  	int length() const;
  	QChar text(int pos) const;
  	QString text(int pos, uint len) const;
+	QString wordAt(int pos) const;
  	PageItem* object(int pos) const;
 	
 	int nextCharPos(int c);




More information about the scribus-commit mailing list