fi
])
+# Macro to add for using enchant spellchecker libraries! -*- sh -*-
+AC_DEFUN([CHECK_WITH_ENCHANT],
+[
+ lyx_use_enchant=true
+ AC_ARG_WITH(enchant, AC_HELP_STRING([--without-enchant],[do not check for Enchant library]))
+ test "$with_enchant" = "no" && lyx_use_enchant=false
+
+ if $lyx_use_enchant; then
+ PKG_CHECK_MODULES([ENCHANT], [enchant], [], [lyx_use_enchant=false])
+ AC_MSG_CHECKING([whether to use enchant])
+ if $lyx_use_enchant ; then
+ AC_MSG_RESULT(yes)
+ AC_DEFINE(USE_ENCHANT, 1, [Define as 1 to use the enchant library])
+ lyx_flags="$lyx_flags use-enchant"
+ else
+ AC_MSG_RESULT(no)
+ fi
+ fi
+ ])
+
# Macro to add for using hunspell spellchecker libraries! -*- sh -*-
AC_DEFUN([CHECK_WITH_HUNSPELL],
[
AM_CONDITIONAL(USE_ASPELL, $lyx_use_aspell)
+ lyx_use_enchant=false
+ CHECK_WITH_ENCHANT
+
+ AM_CONDITIONAL(USE_ENCHANT, $lyx_use_enchant)
+
lyx_use_hunspell=false
CHECK_WITH_HUNSPELL
) ),
#
EnumVariable('spell', 'Choose spell checker to use.', 'auto',
- allowed_values = ('aspell', 'hunspell', 'auto', 'no') ),
+ allowed_values = ('aspell', 'enchant', 'hunspell', 'auto', 'no') ),
# packaging method
EnumVariable('packaging', 'Packaging method to use.', default_packaging_method,
allowed_values = ('windows', 'posix', 'macosx')),
# determine headers to use
spell_opt = ARGUMENTS.get('spell', 'auto')
env['USE_ASPELL'] = False
+env['USE_ENCHANT'] = False
+env['USE_HUNSPELL'] = False
if spell_opt in ['auto', 'aspell'] and conf.CheckLib(aspell_lib):
spell_engine = 'USE_ASPELL'
+elif spell_opt in ['auto', 'enchant'] and conf.CheckLib('enchant'):
+ spell_engine = 'USE_ENCHANT'
+elif spell_opt in ['auto', 'hunspell'] and conf.CheckLib('enchant'):
+ spell_engine = 'USE_HUNSPELL'
else:
spell_engine = None
)
# these keys are needed in env
-for key in ['USE_ASPELL', 'HAVE_FCNTL',\
+for key in ['USE_ASPELL', 'USE_ENCHANT', 'USE_HUNSPELL', 'HAVE_FCNTL',\
'HAVE_LIBGDI32', 'HAVE_LIBAIKSAURUS', 'AIKSAURUS_LIB']:
# USE_ASPELL etc does not go through result
if result.has_key(key):
('HAVE_LIBGDI32', 'gdi32'),
('HAVE_LIBAIKSAURUS', env['AIKSAURUS_LIB']),
('USE_ASPELL', aspell_lib),
+ ('USE_ENCHANT', 'enchant'),
+ ('USE_HUNSPELL', 'hunspell')
]
for lib in libs:
#
if env.has_key('USE_ASPELL') and env['USE_ASPELL']:
src_post_files.append('AspellChecker.cpp')
+elif env.has_key('USE_ENCHANT') and env['USE_ENCHANT']:
+ src_post_files.append('EnchantChecker.cpp')
+elif env.has_key('USE_HUNSPELL') and env['USE_HUNSPELL']:
+ src_post_files.append('HunspellChecker.cpp')
# tells scons how to get these moced files, although not all moced files are needed
# (or are actually generated).
Dimension.h
DispatchResult.h
DocIterator.h
+ EnchantChecker.h
Encoding.h
ErrorList.h
Exporter.h
src_extra_src_files = Split('''
AspellChecker.cpp
+ EnchantChecker.cpp
HunspellChecker.cpp
main.cpp
Section.cpp
--- /dev/null
+/**
+ * \file EnchantChecker.cpp
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author Caolán McNamara
+ * \author Jürgen Spitzmüller
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#include <config.h>
+
+#include <enchant++.h>
+
+#include "EnchantChecker.h"
+#include "LyXRC.h"
+#include "WordLangTuple.h"
+
+#include "support/lassert.h"
+#include "support/debug.h"
+#include "support/docstring_list.h"
+
+#include <map>
+#include <string>
+
+using namespace std;
+
+namespace lyx {
+
+namespace {
+
+struct Speller {
+ enchant::Dict * speller;
+};
+
+typedef std::map<std::string, Speller> Spellers;
+
+} // anon namespace
+
+struct EnchantChecker::Private
+{
+ Private() {}
+
+ ~Private();
+
+ /// add a speller of the given language
+ enchant::Dict * addSpeller(string const & lang);
+
+ ///
+ enchant::Dict * speller(string const & lang);
+
+ /// the spellers
+ Spellers spellers_;
+};
+
+
+EnchantChecker::Private::~Private()
+{
+ Spellers::iterator it = spellers_.begin();
+ Spellers::iterator end = spellers_.end();
+
+ for (; it != end; ++it) {
+ delete it->second.speller;
+ }
+}
+
+
+enchant::Dict * EnchantChecker::Private::addSpeller(string const & lang)
+{
+ enchant::Broker * instance = enchant::Broker::instance();
+ enchant::Dict * dict = instance->request_dict(lang);
+
+ if (dict) {
+ Speller m;
+ m.speller = dict;
+ spellers_[lang] = m;
+ return m.speller;
+ }
+ // FIXME error handling?
+ return 0;
+}
+
+
+enchant::Dict * EnchantChecker::Private::speller(string const & lang)
+{
+ Spellers::iterator it = spellers_.find(lang);
+ if (it != spellers_.end())
+ return it->second.speller;
+
+ return addSpeller(lang);
+}
+
+
+EnchantChecker::EnchantChecker(): d(new Private)
+{
+}
+
+
+EnchantChecker::~EnchantChecker()
+{
+ delete d;
+}
+
+
+SpellChecker::Result EnchantChecker::check(WordLangTuple const & word)
+{
+ enchant::Dict * m = d->speller(word.lang_code());
+
+ if (!m)
+ return OK;
+
+ std::string utf8word(to_utf8(word.word()));
+
+ if (m->check(utf8word))
+ return OK;
+
+ return UNKNOWN_WORD;
+}
+
+
+void EnchantChecker::insert(WordLangTuple const & word)
+{
+ Spellers::iterator it = d->spellers_.find(word.lang_code());
+ if (it != d->spellers_.end())
+ it->second.speller->add(to_utf8(word.word()));
+}
+
+
+void EnchantChecker::accept(WordLangTuple const & word)
+{
+ Spellers::iterator it = d->spellers_.find(word.lang_code());
+ if (it != d->spellers_.end())
+ it->second.speller->add_to_session(to_utf8(word.word()));
+}
+
+
+void EnchantChecker::suggest(WordLangTuple const & wl,
+ docstring_list & suggestions)
+{
+ suggestions.clear();
+ enchant::Dict * m = d->speller(wl.lang_code());
+
+ if (!m)
+ return;
+
+ string utf8word = to_utf8(wl.word());
+
+ vector<string> suggs = m->suggest(utf8word);
+ vector<string>::const_iterator it = suggs.begin();
+
+ for (; it != suggs.end(); ++it)
+ suggestions.push_back(from_utf8(*it));
+}
+
+
+docstring const EnchantChecker::error()
+{
+ return docstring();
+}
+
+
+} // namespace lyx
--- /dev/null
+// -*- C++ -*-
+/**
+ * \file EnchantChecker.h
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author Caolán McNamara
+ * \author Jürgen Spitzmüller
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#ifndef LYX_ENCHANT_H
+#define LYX_ENCHANT_H
+
+#include "SpellChecker.h"
+
+namespace enchant {
+ class Dict;
+}
+
+namespace lyx {
+
+class BufferParams;
+
+
+class EnchantChecker : public SpellChecker {
+public:
+ EnchantChecker();
+ ~EnchantChecker();
+
+ /// SpellChecker inherited methods.
+ ///@{
+ enum Result check(WordLangTuple const &);
+ void suggest(WordLangTuple const &, docstring_list &);
+ void insert(WordLangTuple const &);
+ void accept(WordLangTuple const &);
+ docstring const error();
+ ///@}
+
+private:
+ struct Private;
+ Private * d;
+};
+
+
+} // namespace lyx
+
+#endif // LYX_ENCHANT_H
#include "ConverterCache.h"
#include "Converter.h"
#include "CutAndPaste.h"
+#include "EnchantChecker.h"
#include "Encoding.h"
#include "ErrorList.h"
#include "Format.h"
/// The main application class private implementation.
struct LyX::Impl
{
- Impl() : spell_checker_(0), aspell_checker_(0), hunspell_checker_(0)
+ Impl() : spell_checker_(0), aspell_checker_(0), enchant_checker_(0), hunspell_checker_(0)
{
// Set the default User Interface language as soon as possible.
// The language used will be derived from the environment
~Impl()
{
delete aspell_checker_;
+ delete enchant_checker_;
delete hunspell_checker_;
}
///
SpellChecker * aspell_checker_;
///
+ SpellChecker * enchant_checker_;
+ ///
SpellChecker * hunspell_checker_;
};
return;
}
#endif
+#if defined(USE_ENCHANT)
+ if (lyxrc.spellchecker == "enchant") {
+ if (!singleton_->pimpl_->enchant_checker_)
+ singleton_->pimpl_->enchant_checker_ = new EnchantChecker();
+ singleton_->pimpl_->spell_checker_ = singleton_->pimpl_->enchant_checker_;
+ return;
+ }
+#endif
#if defined(USE_HUNSPELL)
if (lyxrc.spellchecker == "hunspell") {
if (!singleton_->pimpl_->hunspell_checker_)
DISTCLEANFILES += config.h libintl.h
-AM_CPPFLAGS += $(PCH_FLAGS) -I$(top_srcdir)/src $(BOOST_INCLUDES)
+AM_CPPFLAGS += $(PCH_FLAGS) -I$(top_srcdir)/src $(BOOST_INCLUDES) $(ENCHANT_CFLAGS)
AM_CPPFLAGS += $(QT4_CPPFLAGS) $(QT4_CORE_INCLUDES)
if BUILD_CLIENT_SUBDIR
pch.h
OTHERLIBS = $(BOOST_LIBS) $(INTLLIBS) $(MYTHES_LIBS) $(AIKSAURUS_LIBS) \
- @LIBS@ $(SOCKET_LIBS) $(LIBSHLWAPI) $(LIBPSAPI)
+ $(ENCHANT_LIBS) @LIBS@ $(SOCKET_LIBS) $(LIBSHLWAPI) $(LIBPSAPI)
noinst_LIBRARIES = liblyxcore.a
bin_PROGRAMS = lyx
ASPELL = AspellChecker.cpp AspellChecker.h
endif
+if USE_ENCHANT
+ENCHANT = EnchantChecker.cpp EnchantChecker.h
+endif
+
if USE_HUNSPELL
HUNSPELL = HunspellChecker.cpp HunspellChecker.h
endif
Compare.h \
Dimension.cpp \
Dimension.h \
+ $(ENCHANT) \
$(HUNSPELL) \
PrinterParams.cpp \
PrinterParams.h \
setupUi(this);
#if defined(USE_ASPELL)
- spellcheckerCB->addItem("aspell");
+ spellcheckerCB->addItem(qt_("aspell"), QString("aspell"));
+#endif
+#if defined(USE_ENCHANT)
+ spellcheckerCB->addItem(qt_("enchant"), QString("enchant"));
#endif
#if defined(USE_HUNSPELL)
- spellcheckerCB->addItem("hunspell");
+ spellcheckerCB->addItem(qt_("hunspell"), QString("hunspell"));
#endif
if (theSpellChecker()) {
void PrefSpellchecker::apply(LyXRC & rc) const
{
- rc.spellchecker = fromqstr(spellcheckerCB->currentText());
+ rc.spellchecker = fromqstr(spellcheckerCB->itemData(
+ spellcheckerCB->currentIndex()).toString());
rc.spellchecker_alt_lang = fromqstr(altLanguageED->text());
rc.spellchecker_esc_chars = fromqstr(escapeCharactersED->text());
rc.spellchecker_accept_compound = compoundWordCB->isChecked();
void PrefSpellchecker::update(LyXRC const & rc)
{
- spellcheckerCB->setCurrentIndex(spellcheckerCB->findText(
- toqstr(rc.spellchecker)));
+ spellcheckerCB->setCurrentIndex(
+ spellcheckerCB->findData(toqstr(rc.spellchecker)));
altLanguageED->setText(toqstr(rc.spellchecker_alt_lang));
escapeCharactersED->setText(toqstr(rc.spellchecker_esc_chars));
compoundWordCB->setChecked(rc.spellchecker_accept_compound);