From f3403971efbfd72c8a59eb1957292cf534f1233b Mon Sep 17 00:00:00 2001 From: craig Date: Thu, 12 Apr 2012 21:33:03 +0000 Subject: Add hunspell based spell checker - not enabled, backup only for now, not enabled in the build git-svn-id: svn://scribus.net/branches/Version14x/Scribus@17437 11d20701-8431-0410-a711-e3c959e3b870 --- .../tools/hunspellcheck/hunspellpluginimpl.cpp | 251 +++++++++++++++++++++ 1 file changed, 251 insertions(+) create mode 100644 scribus/plugins/tools/hunspellcheck/hunspellpluginimpl.cpp (limited to 'scribus/plugins/tools/hunspellcheck/hunspellpluginimpl.cpp') diff --git a/scribus/plugins/tools/hunspellcheck/hunspellpluginimpl.cpp b/scribus/plugins/tools/hunspellcheck/hunspellpluginimpl.cpp new file mode 100644 index 0000000..7d3c7da --- /dev/null +++ b/scribus/plugins/tools/hunspellcheck/hunspellpluginimpl.cpp @@ -0,0 +1,251 @@ +/* +For general Scribus (>=1.3.2) copyright and licensing information please refer +to the COPYING file provided with the program. Following this notice may exist +a copyright and/or license notice that predates the release of Scribus 1.3.2 +for which a new license (GPL+exception) is in place. +*/ +#include "hunspellpluginimpl.h" +#include "hunspelldialog.h" +#include "pageitem.h" +#include "pageitem_textframe.h" +#include "selection.h" +#include "scribusdoc.h" +#include "scribus.h" +#include "text/specialchars.h" +#include "util.h" + +#include +#include +#include +#include + +#ifdef Q_OS_WIN32 +#include +#include +#endif + + +// Initialize members here, if any +HunspellPluginImpl::HunspellPluginImpl() : QObject(0) +{ + hspellers=NULL; + numDicts=0; +} + +HunspellPluginImpl::~HunspellPluginImpl() +{ + if (hspellers) + { + for (int i = 0; i < numDicts; ++i) + { + delete hspellers[i]; + hspellers[i] = NULL; + } + delete[] hspellers; + } + hspellers = NULL; + numDicts = 0; +} + +bool HunspellPluginImpl::run(const QString & target, ScribusDoc* doc) +{ + m_doc=doc; + bool initOk=initHunspell(); + qDebug()<<"Hunspell Init Ok:"<m_Selection->count(); ++i ) + { + frameToCheck = m_doc->m_Selection->itemAt(i); + parseTextFrame(frameToCheck); + openGUIForTextFrame(frameToCheck); + m_doc->view()->DrawNew(); + } + return true; +} + +bool HunspellPluginImpl::parseTextFrame(PageItem *frameToCheck) +{ + static QString wordBoundaries(" .,:;\"'!?\n"); + + StoryText *iText=&frameToCheck->itemText; + int len=iText->length(); + QString text=iText->text(0,len); +// qDebug()<nextWord(currPos); + currPos=wordPos; + int eoWord=wordPos; + while(eoWord < len) + { + if (iText->text(eoWord).isLetterOrNumber()) + ++eoWord; + else + break; + } + QString word=iText->text(wordPos,eoWord-wordPos); + ++wordCount; + ++wordNo; + QStringList replacements; + if (hspellers[0]->spell(word.toLocal8Bit().constData())==0) + { +// qDebug()<suggest(&sugglist, word.toLocal8Bit().constData()); + for (int j=0; j < suggCount; ++j) + { +// qDebug()<<"Suggestion "<free_list(&sugglist, suggCount); + + struct WordsFound wf; + wf.start=currPos; + wf.end=eoWord; + wf.w=word; + wf.replacements=replacements; + wf.changed=false; + wf.ignore=false; + wordsToCorrect.append(wf); + } + } +// qDebug()<<"Errors found:"<scMW(), m_doc, frameToCheck); + hsDialog.set(&dictEntries, hspellers, &wordsToCorrect); + hsDialog.exec(); + if (hsDialog.docChanged()) + m_doc->changed(); + return true; +} + -- cgit