From 020a92a1d225b2a84feb5dfbb8aa126801571d26 Mon Sep 17 00:00:00 2001 From: craig Date: Thu, 3 May 2012 07:40:30 +0000 Subject: Bump hunspell some more, add it some real finding/use of dicts from common locations git-svn-id: svn://scribus.net/branches/Version14x/Scribus@17490 11d20701-8431-0410-a711-e3c959e3b870 --- .../tools/hunspellcheck/hunspellpluginimpl.cpp | 106 +++++++++++++-------- 1 file changed, 65 insertions(+), 41 deletions(-) (limited to 'scribus/plugins/tools/hunspellcheck/hunspellpluginimpl.cpp') diff --git a/scribus/plugins/tools/hunspellcheck/hunspellpluginimpl.cpp b/scribus/plugins/tools/hunspellcheck/hunspellpluginimpl.cpp index 8fff975..ee4ed23 100644 --- a/scribus/plugins/tools/hunspellcheck/hunspellpluginimpl.cpp +++ b/scribus/plugins/tools/hunspellcheck/hunspellpluginimpl.cpp @@ -6,6 +6,7 @@ for which a new license (GPL+exception) is in place. */ #include "hunspellpluginimpl.h" #include "hunspelldialog.h" +#include "langmgr.h" #include "pageitem.h" #include "pageitem_textframe.h" #include "selection.h" @@ -76,60 +77,62 @@ bool HunspellPluginImpl::run(const QString & target, ScribusDoc* doc) bool HunspellPluginImpl::findDictionaries() { - QStringList dirs(ScPaths::instance().spellDirs()); - if (dirs.count()==0) + dictionaryPaths=ScPaths::instance().spellDirs(); + if (dictionaryPaths.count()==0) return false; - //for development, just take the first for now - dictPath=dirs.first(); return true; } bool HunspellPluginImpl::initHunspell() { - int errorCount=0; bool dictPathFound=findDictionaries(); if (!dictPathFound) { qDebug()<<"No preinstalled dictonary paths found"; return false; } - else - qDebug()<<"Preinstalled dictionary path selected"<::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; + } + return true; } bool HunspellPluginImpl::checkWithHunspell() @@ -174,21 +177,42 @@ bool HunspellPluginImpl::parseTextFrame(StoryText *iText) break; } QString word=iText->text(wordPos,eoWord-wordPos); + QString wordLang=iText->charStyle(wordPos).language(); + //qDebug()<getAbbrevFromLang(wordLang, true); + if (wordLang=="en") + wordLang="en_GB"; + int spellerIndex=0; + if (!dictionaryMap.contains(wordLang)) + qDebug()<<"Spelling language to match style language not installed ("<::iterator it = dictionaryMap.begin(); + while (it != dictionaryMap.end()) + { + if (it.key()==wordLang) + break; + ++i; + ++it; + } + spellerIndex=i; + } ++wordCount; ++wordNo; QStringList replacements; - if (hspellers[0]->spell(word.toUtf8().constData())==0) + if (hspellers[spellerIndex]->spell(word.toUtf8().constData())==0) { // qDebug()<suggest(&sugglist, word.toUtf8().constData()); + int suggCount=hspellers[spellerIndex]->suggest(&sugglist, word.toUtf8().constData()); for (int j=0; j < suggCount; ++j) { // qDebug()<<"Suggestion "<free_list(&sugglist, suggCount); + hspellers[spellerIndex]->free_list(&sugglist, suggCount); struct WordsFound wf; wf.start=currPos; @@ -208,7 +232,7 @@ bool HunspellPluginImpl::parseTextFrame(StoryText *iText) bool HunspellPluginImpl::openGUIForTextFrame(StoryText *iText) { HunspellDialog hsDialog(m_doc->scMW(), m_doc, iText); - hsDialog.set(&dictEntries, hspellers, &wordsToCorrect); + hsDialog.set(&dictionaryMap, hspellers, &wordsToCorrect); hsDialog.exec(); if (hsDialog.docChanged()) m_doc->changed(); @@ -219,7 +243,7 @@ bool HunspellPluginImpl::openGUIForStoryEditor(StoryText *iText) { m_SE->setSpellActive(true); HunspellDialog hsDialog(m_SE, m_doc, iText); - hsDialog.set(&dictEntries, hspellers, &wordsToCorrect); + hsDialog.set(&dictionaryMap, hspellers, &wordsToCorrect); hsDialog.exec(); m_SE->setSpellActive(false); return true; -- cgit