summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcraig <craig@11d20701-8431-0410-a711-e3c959e3b870>2012-05-04 14:26:58 +0000
committercraig <craig@11d20701-8431-0410-a711-e3c959e3b870>2012-05-04 14:26:58 +0000
commit1601800e7d74c192af89ee85c6110bd80a02453a (patch)
treee0c473e40bac26e8e56ce3d5a8e0b5c1dfda623d
parent551faae07c1a1dc272fd61a93ebffb901e382a07 (diff)
downloadscribus-1601800e7d74c192af89ee85c6110bd80a02453a.tar.gz
scribus-1601800e7d74c192af89ee85c6110bd80a02453a.tar.xz
scribus-1601800e7d74c192af89ee85c6110bd80a02453a.zip
Bump hunspell plugin, simplify a little. Allow the LibreOffice dict finder use the dict dirs properly
git-svn-id: svn://scribus.net/branches/Version14x/Scribus@17494 11d20701-8431-0410-a711-e3c959e3b870
-rw-r--r--scribus/langmgr.cpp2
-rw-r--r--scribus/plugins/tools/hunspellcheck/hunspellpluginimpl.cpp54
-rw-r--r--scribus/scpaths.cpp31
-rw-r--r--scribus/text/storytext.cpp14
-rw-r--r--scribus/text/storytext.h1
5 files changed, 61 insertions, 41 deletions
diff --git a/scribus/langmgr.cpp b/scribus/langmgr.cpp
index d05faa3..6f4b51c 100644
--- a/scribus/langmgr.cpp
+++ b/scribus/langmgr.cpp
@@ -74,8 +74,10 @@ void LanguageManager::generateLangList()
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" )) );
diff --git a/scribus/plugins/tools/hunspellcheck/hunspellpluginimpl.cpp b/scribus/plugins/tools/hunspellcheck/hunspellpluginimpl.cpp
index cbbd675..18d1a47 100644
--- a/scribus/plugins/tools/hunspellcheck/hunspellpluginimpl.cpp
+++ b/scribus/plugins/tools/hunspellcheck/hunspellpluginimpl.cpp
@@ -95,17 +95,14 @@ bool HunspellPluginImpl::initHunspell()
{
// 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())
+ foreach(dictName, dictList)
{
- dictName=dictListIterator.next();
if (!QFile::exists(dictionaryPaths.at(i)+dictName+".aff"))
dictList.removeAll(dictName);
else
@@ -127,7 +124,6 @@ bool HunspellPluginImpl::initHunspell()
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::checkWithHunspellSE()
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 @@ bool HunspellPluginImpl::parseTextFrame(StoryText *iText)
}
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);
}
}
diff --git a/scribus/scpaths.cpp b/scribus/scpaths.cpp
index 40d79ba..d9cc181 100644
--- a/scribus/scpaths.cpp
+++ b/scribus/scpaths.cpp
@@ -274,16 +274,41 @@ QStringList ScPaths::spellDirs() const
if (d.exists())
spellDirs.append(finkPath);
d.setPath(osxLibreOfficePath);
+
if (d.exists())
- spellDirs.append(osxLibreOfficePath);
+ {
+ 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())
diff --git a/scribus/text/storytext.cpp b/scribus/text/storytext.cpp
index 531744a..d85eee5 100644
--- a/scribus/text/storytext.cpp
+++ b/scribus/text/storytext.cpp
@@ -1154,6 +1154,20 @@ int StoryText::prevWord(int pos)
--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();
diff --git a/scribus/text/storytext.h b/scribus/text/storytext.h
index 381e96c..b7757be 100644
--- a/scribus/text/storytext.h
+++ b/scribus/text/storytext.h
@@ -202,6 +202,7 @@ class SCRIBUS_API StoryText : public QObject, public SaxIO
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);