r21738 by craig - #14466: Move hunspell finder to pkgconfig to remove version checks. Allow version check in hunspell code and use new API when available

scribus-commit scribus-commit at lists.scribus.net
Fri Jan 20 16:48:01 UTC 2017


Author: craig
Date: Fri Jan 20 16:48:01 2017
New Revision: 21738

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=21738
Log:
#14466: Move hunspell finder to pkgconfig to remove version checks. Allow version check in hunspell code and use new API when available

Modified:
    trunk/Scribus/cmake/modules/FindHUNSPELL.cmake
    trunk/Scribus/config.h.cmake
    trunk/Scribus/scribus/plugins/tools/hunspellcheck/hunspelldict.cpp

Modified: trunk/Scribus/cmake/modules/FindHUNSPELL.cmake
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=21738&path=/trunk/Scribus/cmake/modules/FindHUNSPELL.cmake
==============================================================================
--- trunk/Scribus/cmake/modules/FindHUNSPELL.cmake	(original)
+++ trunk/Scribus/cmake/modules/FindHUNSPELL.cmake	Fri Jan 20 16:48:01 2017
@@ -8,16 +8,32 @@
 
 #Based on examples at http://www.vtk.org/Wiki/CMake:How_To_Find_Libraries
 
-find_path(HUNSPELL_INCLUDE_DIR hunspell/hunspell.hxx )
-find_library(HUNSPELL_LIBRARIES NAMES hunspell-1.6 hunspell-1.5 hunspell-1.4 hunspell-1.3 hunspell-1.2 PATHS /opt/local/lib /usr/local/lib /usr/lib )
+include(FindPkgConfig)
+pkg_search_module(HUNSPELL REQUIRED hunspell)
 
-include(FindPackageHandleStandardArgs)
-# handle the QUIETLY and REQUIRED arguments and set HUNSPELL_FOUND to TRUE
-# if all listed variables are TRUE
+find_path(HUNSPELL
+  NAMES hunspell.h
+  PATHS ${PKG_HUNSPELL_INCLUDE_DIRS} ${HUNSPELL_INCLUDE_DIRS} /usr/local/include /usr/include
+  PATH_SUFFIXES hunspell
+  NO_DEFAULT_PATH
+)
 
-#find_package(HUNSPELL QUIET NO_MODULE HINTS /opt/local/bin/hunspell)
-#FIND_PACKAGE_HANDLE_STANDARD_ARGS(HUNSPELL  CONFIG_MODE)
+find_library(HUNSPELL_LIBRARIES
+  NAMES libhunspell
+  PATHS ${PKG_HUNSPELL_LIBRARIES} ${HUNSPELL_LIBRARY_DIRS} /usr/local/lib /usr/lib
+  NO_DEFAULT_PATH
+)
 
-FIND_PACKAGE_HANDLE_STANDARD_ARGS(HUNSPELL DEFAULT_MSG HUNSPELL_LIBRARIES HUNSPELL_INCLUDE_DIR )
+string(REGEX MATCH "1\.([1-6])\.." HUNSPELL_MATCH ${HUNSPELL_VERSION})
+#set(HUNSPELL_MINOR_VERSION ${CMAKE_MATCH_1})
+if(CMAKE_MATCH_1 GREATER 3)
+	set(HUNSPELL_NEWAPI 1)
+	message(STATUS "New HUNSPELL API found")
+endif()
+
+#find_path(HUNSPELL_INCLUDE_DIR hunspell/hunspell.hxx )
+#find_library(HUNSPELL_LIBRARIES NAMES hunspell-1.5 hunspell-1.4 hunspell-1.3 hunspell-1.2 PATHS /opt/local/lib /usr/local/lib /usr/lib )
+#include(FindPackageHandleStandardArgs)
+#FIND_PACKAGE_HANDLE_STANDARD_ARGS(HUNSPELL DEFAULT_MSG HUNSPELL_LIBRARIES HUNSPELL_INCLUDE_DIR )
 
 mark_as_advanced(HUNSPELL_INCLUDE_DIR HUNSPELL_LIBRARIES)

Modified: trunk/Scribus/config.h.cmake
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=21738&path=/trunk/Scribus/config.h.cmake
==============================================================================
--- trunk/Scribus/config.h.cmake	(original)
+++ trunk/Scribus/config.h.cmake	Fri Jan 20 16:48:01 2017
@@ -38,3 +38,4 @@
 #cmakedefine GMAGICK_FOUND 1
 #cmakedefine WITH_TESTS 1
 #cmakedefine HAVE_REVENGE 1
+#cmakedefine HUNSPELL_NEWAPI "@HUNSPELL_NEWAPI@"

Modified: trunk/Scribus/scribus/plugins/tools/hunspellcheck/hunspelldict.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=21738&path=/trunk/Scribus/scribus/plugins/tools/hunspellcheck/hunspelldict.cpp
==============================================================================
--- trunk/Scribus/scribus/plugins/tools/hunspellcheck/hunspelldict.cpp	(original)
+++ trunk/Scribus/scribus/plugins/tools/hunspellcheck/hunspelldict.cpp	Fri Jan 20 16:48:01 2017
@@ -8,7 +8,10 @@
 #include "hunspelldict.h"
 
 #include <hunspell/hunspell.hxx>
+#include <QDebug>
 #include <QTextCodec>
+
+#include "scconfig.h"
 
 HunspellDict::HunspellDict(const QString& affPath, const QString& dictPath)
 {
@@ -38,6 +41,7 @@
 	}
 }
 
+#ifndef HUNSPELL_NEWAPI
 int HunspellDict::spell(QString word)
 {
 	if (m_hunspell)
@@ -57,3 +61,24 @@
 
 	return replacements;
 }
+#else
+int HunspellDict::spell(QString word)
+{
+	if (!m_hunspell)
+		return -1;
+	std::string s = word.toStdString();
+	return m_hunspell->spell(s);
+}
+
+QStringList HunspellDict::suggest(QString word)
+{
+	QStringList replacements;
+	if (!m_hunspell)
+		return replacements;
+	std::string s = word.toStdString();
+	std::vector<std::string> sugglist = m_hunspell->suggest(s);
+	for (uint i = 0; i < sugglist.size(); ++i)
+		replacements << QString::fromStdString(sugglist[i]);
+	return replacements;
+}
+#endif




More information about the scribus-commit mailing list