From 7b7c9cb4183651b496501e89deb497490199b320 Mon Sep 17 00:00:00 2001 From: Alexandru Croitor Date: Fri, 9 Sep 2016 17:09:42 +0200 Subject: Fix spellchecking for macOS The change fixes spellchecking to work on macOS. A new WebEngine configure option is available to allow spellchecking on macOS to use either Hunspell like the other platforms, or the native spellchecker that comes with the OS. The default is to use Hunspell. Task-number: QTBUG-53135 Change-Id: I3e45b2e0d728b1bf2659c35f3d0a042b0ecd6239 Reviewed-by: Leena Miettinen Reviewed-by: Michal Klocek --- examples/examples.pro | 8 ++++++-- .../spellchecker/doc/src/spellchecker.qdoc | 21 +++++++++++++-------- .../webenginewidgets/spellchecker/spellchecker.pro | 22 +++++++++++++++++++++- 3 files changed, 40 insertions(+), 11 deletions(-) (limited to 'examples') diff --git a/examples/examples.pro b/examples/examples.pro index f15007e83..0e222de73 100644 --- a/examples/examples.pro +++ b/examples/examples.pro @@ -15,8 +15,12 @@ qtHaveModule(webenginewidgets) { webenginewidgets/markdowneditor \ webenginewidgets/simplebrowser - !contains(WEBENGINE_CONFIG, no_spellcheck):!osx:!cross_compile { - SUBDIRS += webenginewidgets/spellchecker + !contains(WEBENGINE_CONFIG, no_spellcheck):!cross_compile { + !contains(WEBENGINE_CONFIG, use_native_spellchecker) { + SUBDIRS += webenginewidgets/spellchecker + } else { + message("Spellcheck example will not be built because it depends on usage of Hunspell dictionaries.") + } } } diff --git a/examples/webenginewidgets/spellchecker/doc/src/spellchecker.qdoc b/examples/webenginewidgets/spellchecker/doc/src/spellchecker.qdoc index d5b972b93..b0240cd4d 100644 --- a/examples/webenginewidgets/spellchecker/doc/src/spellchecker.qdoc +++ b/examples/webenginewidgets/spellchecker/doc/src/spellchecker.qdoc @@ -41,12 +41,12 @@ \section1 Dictionaries To be able to check the spelling, we need to provide the spellchecker with - dictionaries. In this example, we want to support the English and German - languages. + dictionaries. The Qt WebEngine spellchecker supports dictionaries provided by the + \l {Hunspell project} on all platforms and native dictionaries provided by macOS. + In this example, we want to support the English and German languages. - The Qt WebEngine spellchecker supports dictionaries from the - \l{Hunspell project}, but they have to be compiled into a special binary - format. A Hunspell dictionary consists of two files: + For Hunspell dictionaries to be supported they have to be compiled into a special binary format. + A Hunspell dictionary consists of two files: \list @@ -78,7 +78,12 @@ When a specific spellchecking language is requested, Qt WebEngine will try to load the already compiled matching \c .bdic file first from \e qtwebengine_dictionaries directories relative to the executable, - then it will look in \c QT_INSTALL_PREFIX/qtwebengines_dictionaries. + then it will look in \c QT_INSTALL_PREFIX/qtwebengine_dictionaries. + + On macOS, because this example was configured to use Hunspell dictionaries, Qt WebEngine will + look in the \e qtwebengine_dictionaries directory located inside the application bundle + \c Resources directory, and also in the \c Resources directory located inside the + Qt framework bundle. We specify the QMAKE_EXTRA_COMPILERS parameter in the project file to add a conversion step to the build process: @@ -87,11 +92,11 @@ \skipto CONVERT_TOOL \printuntil QMAKE_EXTRA_COMPILERS - To set up a dictionary, we run \c qwebengine_convert_dic passing the + To set up a dictionary, we run \c qwebengine_convert_dict passing the file path of the dictionary \c dic and \c bdic files. The \c aff file and optional \c delta file are also picked up by the \c convert process. The output \c bdic file is placed into the \e qtwebengine_dictionaries local - directory, which the application binary will run from. + directory (or Resources directory), which the application binary will run from. \section1 Setting the Spellchecker diff --git a/examples/webenginewidgets/spellchecker/spellchecker.pro b/examples/webenginewidgets/spellchecker/spellchecker.pro index c7bee6584..c6031a36d 100644 --- a/examples/webenginewidgets/spellchecker/spellchecker.pro +++ b/examples/webenginewidgets/spellchecker/spellchecker.pro @@ -3,6 +3,10 @@ TARGET = spellchecker QT += webenginewidgets CONFIG += c++11 +contains(WEBENGINE_CONFIG, use_native_spellchecker) { + error("Spellcheck example can not be built when using native OS dictionaries.") +} + HEADERS += \ webview.h @@ -33,7 +37,11 @@ debug_and_release { DICTIONARIES_DIR = qtwebengine_dictionaries } -dict.files = $$PWD/dict/en/en-US.dic $$PWD/dict/de/de-DE.dic +dict_base_paths = en/en-US de/de-DE +for (base_path, dict_base_paths) { + dict.files += $$PWD/dict/$${base_path}.dic +} + dictoolbuild.input = dict.files dictoolbuild.output = $${DICTIONARIES_DIR}/${QMAKE_FILE_BASE}.bdic dictoolbuild.depends = ${QMAKE_FILE_PATH}/${QMAKE_FILE_BASE}.aff @@ -41,3 +49,15 @@ dictoolbuild.commands = $${CONVERT_TOOL} ${QMAKE_FILE_IN} ${QMAKE_FILE_OUT} dictoolbuild.name = Build ${QMAKE_FILE_IN_BASE} dictoolbuild.CONFIG = no_link target_predeps QMAKE_EXTRA_COMPILERS += dictoolbuild + +# When the example is compiled as a bundle, WebEngine expects to find the dictionaries in +# bundle.app/Contents/Resources/qtwebengine_dictionaries +macos:app_bundle { + for (base_path, dict_base_paths) { + base_path_splitted = $$split(base_path, /) + base_name = $$last(base_path_splitted) + binary_dict_files.files += $${DICTIONARIES_DIR}/$${base_name}.bdic + } + binary_dict_files.path = Contents/Resources/$$DICTIONARIES_DIR + QMAKE_BUNDLE_DATA += binary_dict_files +} -- cgit v1.2.3