r17494 by craig - Bump hunspell plugin, simplify a little. Allow the LibreOffice dict finder use the dict dirs properly

scribus-commit scribus-commit at lists.scribus.net
Fri May 4 14:26:58 UTC 2012


Author: craig
Date: Fri May  4 14:26:58 2012
New Revision: 17494

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=17494
Log:
Bump hunspell plugin, simplify a little. Allow the LibreOffice dict finder use the dict dirs properly

Modified:
    branches/Version14x/Scribus/scribus/langmgr.cpp
    branches/Version14x/Scribus/scribus/plugins/tools/hunspellcheck/hunspellpluginimpl.cpp
    branches/Version14x/Scribus/scribus/scpaths.cpp
    branches/Version14x/Scribus/scribus/text/storytext.cpp
    branches/Version14x/Scribus/scribus/text/storytext.h

Modified: branches/Version14x/Scribus/scribus/langmgr.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17494&path=/branches/Version14x/Scribus/scribus/langmgr.cpp
==============================================================================
--- branches/Version14x/Scribus/scribus/langmgr.cpp (original)
+++ branches/Version14x/Scribus/scribus/langmgr.cpp Fri May  4 14:26:58 2012
@@ -74,8 +74,10 @@
 	langList.insert("nl",       langPair("Dutch",               QObject::tr( "Dutch" )) );
 	langList.insert("en",       langPair("English",             QObject::tr( "English" )) );
 	langList.insert("en_AU",    langPair("English (Australian)",QObject::tr( "English (Australian)" )) );
+	langList.insert("en_CA",    langPair("English (Canadian)",  QObject::tr( "English (Canadian)" )) );
 	langList.insert("en_GB",    langPair("English (British)",   QObject::tr( "English (British)" )) );
 	langList.insert("en_US",    langPair("English (American)",  QObject::tr( "English (American)" )) );
+	langList.insert("en_ZA",    langPair("English (South African)",  QObject::tr( "English (South African)" )) );
 	langList.insert("eo",       langPair("Esperanto",           QObject::tr( "Esperanto" )) );
 	langList.insert("et",       langPair("Estonian",            QObject::tr( "Estonian" )) );
 	langList.insert("de",       langPair("German",              QObject::tr( "German" )) );

Modified: branches/Version14x/Scribus/scribus/plugins/tools/hunspellcheck/hunspellpluginimpl.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17494&path=/branches/Version14x/Scribus/scribus/plugins/tools/hunspellcheck/hunspellpluginimpl.cpp
==============================================================================
--- branches/Version14x/Scribus/scribus/plugins/tools/hunspellcheck/hunspellpluginimpl.cpp (original)
+++ branches/Version14x/Scribus/scribus/plugins/tools/hunspellcheck/hunspellpluginimpl.cpp Fri May  4 14:26:58 2012
@@ -95,17 +95,14 @@
 	{
 		// Find the dic and aff files in the location
 		QDir dictLocation(dictionaryPaths.at(i));
-		QStringList dictFilters;
-		dictFilters << "*.dic";
+		QStringList dictFilters("*.dic");
 		QStringList dictList(dictLocation.entryList(dictFilters, QDir::Files, QDir::Name));
 		dictList.replaceInStrings(".dic","");
 
 		//Ensure we have aff+dic file pairs, remove any hyphenation dictionaries from the list
 		QString dictName;
-		QStringListIterator dictListIterator(dictList);
-		while (dictListIterator.hasNext())
-		{
-			dictName=dictListIterator.next();
+		foreach(dictName, dictList)
+		{
 			if (!QFile::exists(dictionaryPaths.at(i)+dictName+".aff"))
 				dictList.removeAll(dictName);
 			else
@@ -127,7 +124,6 @@
 	QMap<QString, QString>::iterator it = dictionaryMap.begin();
 	while (it != dictionaryMap.end())
 	{
-		qDebug() << it.key()<< it.value();
 		hspellers[i++] = new Hunspell((it.value()+".aff").toLocal8Bit().constData(),
 									  (it.value()+".dic").toLocal8Bit().constData());
 		++it;
@@ -162,26 +158,17 @@
 bool HunspellPluginImpl::parseTextFrame(StoryText *iText)
 {
 	int len=iText->length();
-	int wordCount=0,wordNo=0,errorCount=0;
-	int currPos=0, wordPos=0;
+	int currPos=0, wordStart=0;
 	while (currPos<len)
 	{
-		wordPos=iText->nextWord(currPos);
-		currPos=wordPos;
-		int eoWord=wordPos;
-		while(eoWord < len)
-		{
-			if (iText->text(eoWord).isLetter())
-			{
-				++eoWord;
-			}
-			else
-				break;
-		}
-		QString word=iText->text(wordPos,eoWord-wordPos);
-		QString wordLang=iText->charStyle(wordPos).language();
+		wordStart=iText->nextWord(currPos);
+		int wordEnd=iText->endOfWord(wordStart);
+		currPos=wordStart;
+		QString word=iText->text(wordStart,wordEnd-wordStart);
+		QString wordLang=iText->charStyle(wordStart).language();
 		//qDebug()<<word<<"is set to be in language"<<wordLang;
 		wordLang=LanguageManager::instance()->getAbbrevFromLang(wordLang, true);
+		//A little hack as for some reason our en dictionary from the aspell plugin was not called en_GB or en_US but en, content was en_GB though. Meh.
 		if (wordLang=="en")
 			wordLang="en_GB";
 		int spellerIndex=0;
@@ -200,31 +187,22 @@
 			}
 			spellerIndex=i;
 		}
-		++wordCount;
-		++wordNo;
-		QStringList replacements;
 		if (hspellers[spellerIndex]->spell(word.toUtf8().constData())==0)
 		{
-//			qDebug()<<word<<wordLang;
-			++errorCount;
-			char **sugglist = NULL;
-			int suggCount=hspellers[spellerIndex]->suggest(&sugglist, word.toUtf8().constData());
-			for (int j=0; j < suggCount; ++j)
-			{
-//				qDebug()<<"Suggestion "<<j<<":"<<sugglist[j];
-				replacements << QString::fromUtf8(sugglist[j]);
-			}
-			hspellers[spellerIndex]->free_list(&sugglist, suggCount);
-
 			struct WordsFound wf;
 			wf.start=currPos;
-			wf.end=eoWord;
+			wf.end=wordEnd;
 			wf.w=word;
-			wf.replacements=replacements;
 			wf.changed=false;
 			wf.ignore=false;
 			wf.changeOffset=0;
 			wf.lang=wordLang;
+			wf.replacements.clear();
+			char **sugglist = NULL;
+			int suggCount=hspellers[spellerIndex]->suggest(&sugglist, word.toUtf8().constData());
+			for (int j=0; j < suggCount; ++j)
+				wf.replacements << QString::fromUtf8(sugglist[j]);
+			hspellers[spellerIndex]->free_list(&sugglist, suggCount);
 			wordsToCorrect.append(wf);
 		}
 	}

Modified: branches/Version14x/Scribus/scribus/scpaths.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17494&path=/branches/Version14x/Scribus/scribus/scpaths.cpp
==============================================================================
--- branches/Version14x/Scribus/scribus/scpaths.cpp (original)
+++ branches/Version14x/Scribus/scribus/scpaths.cpp Fri May  4 14:26:58 2012
@@ -274,16 +274,41 @@
 	if (d.exists())
 		spellDirs.append(finkPath);
 	d.setPath(osxLibreOfficePath);
-	if (d.exists())
-		spellDirs.append(osxLibreOfficePath);
+
+	if (d.exists())
+	{
+		QStringList dictDirFilters;
+		dictDirFilters << "dict-*";
+		QStringList dictDirList(d.entryList(dictDirFilters, QDir::Dirs, QDir::Name));
+		QString dir;
+		foreach (dir, dictDirList)
+			spellDirs.append(osxLibreOfficePath + "/" + dir + "/");
+	}
 	d.setPath(osxUserLibreOfficePath);
 	if (d.exists())
-		spellDirs.append(osxUserLibreOfficePath);
+	{
+		QStringList dictDirFilters;
+		dictDirFilters << "dict-*";
+		QStringList dictDirList(d.entryList(dictDirFilters, QDir::Dirs, QDir::Name));
+		QString dir;
+		foreach (dir, dictDirList)
+			spellDirs.append(osxUserLibreOfficePath + "/" + dir + "/");
+	}
+
 #elif defined(_WIN32)
 	QString progFiles = getSpecialDir(CSIDL_PROGRAM_FILES);
 	d.setPath(progFiles+windowsLOPath);
 	if (d.exists())
-		spellDirs.append(progFiles+windowsLOPath);
+	{
+		QStringList dictDirFilters;
+		dictDirFilters << "dict-*";
+		QStringList dictDirList(d.entryList(dictDirFilters, QDir::Dirs, QDir::Name));
+		QString dir;
+		foreach (dir, dictDirList)
+			spellDirs.append(progFiles+windowsLOPath + "/" + dir + "/");
+	}
+	if (d.exists())
+		spellDirs.append(progFiles+windowsLOPath + "/" + dir + "/");
 #elif defined(Q_WS_X11)
 	d.setPath(linuxPath);
 	if (d.exists())

Modified: branches/Version14x/Scribus/scribus/text/storytext.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17494&path=/branches/Version14x/Scribus/scribus/text/storytext.cpp
==============================================================================
--- branches/Version14x/Scribus/scribus/text/storytext.cpp (original)
+++ branches/Version14x/Scribus/scribus/text/storytext.cpp Fri May  4 14:26:58 2012
@@ -1154,6 +1154,20 @@
 		--pos;
 	return wordBoundaries.indexOf(text(pos)) < 0 ? pos + 1 : pos;
 }
+
+int StoryText::endOfWord(int pos) const
+{
+	int len = length();
+	while (pos < len)
+	{
+		if(text(pos).isLetter())
+			++pos;
+		else
+			break;
+	}
+	return pos;
+}
+
 int StoryText::nextSentence(int pos)
 {
 	int len = length();

Modified: branches/Version14x/Scribus/scribus/text/storytext.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17494&path=/branches/Version14x/Scribus/scribus/text/storytext.h
==============================================================================
--- branches/Version14x/Scribus/scribus/text/storytext.h (original)
+++ branches/Version14x/Scribus/scribus/text/storytext.h Fri May  4 14:26:58 2012
@@ -202,6 +202,7 @@
 	int prevChar(int pos);
 	int nextWord(int pos);
 	int prevWord(int pos);
+	int endOfWord(int pos) const;
 	int nextSentence(int pos);
 	int prevSentence(int pos);
 	int nextParagraph(int pos);




More information about the scribus-commit mailing list