mirror of
https://github.com/ZoiteChat/zoitechat.git
synced 2026-09-02 21:23:04 +00:00
Require Enchant 2.8.19+ and drop win8 provider
Require Enchant 2.8.19 or newer so Windows can use upstream winspell. Remove the in-tree libenchant_win8 provider project and sources. Update runtime library probing to prefer Enchant 2 library names.
This commit is contained in:
@@ -198,14 +198,16 @@ initialize_enchant (void)
|
||||
gsize i;
|
||||
const char * const libnames[] = {
|
||||
#ifdef G_OS_WIN32
|
||||
"libenchant-2.dll",
|
||||
"libenchant-2-2.dll",
|
||||
"libenchant.dll",
|
||||
#endif
|
||||
#ifdef G_OS_UNIX
|
||||
"libenchant.so.1",
|
||||
"libenchant.so.2",
|
||||
"libenchant-2.so.2",
|
||||
#endif
|
||||
#ifdef __APPLE__
|
||||
"libenchant-2.dylib",
|
||||
"libenchant.dylib",
|
||||
#endif
|
||||
};
|
||||
|
||||
@@ -1,2 +0,0 @@
|
||||
EXPORTS
|
||||
init_enchant_provider
|
||||
@@ -1,43 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Release|x64">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>{BF0EBC16-68AD-4CD1-864C-5B56836EBE2A}</ProjectGuid>
|
||||
<Keyword>Win32Proj</Keyword>
|
||||
<RootNamespace>libenchant_win8</RootNamespace>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Label="Configuration">
|
||||
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v142</PlatformToolset>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<Import Project="..\..\win32\zoitechat.props" />
|
||||
<ImportGroup Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup>
|
||||
<OutDir>$(ZoiteChatRel)lib\enchant\</OutDir>
|
||||
<TargetName>libenchant_win8</TargetName>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup>
|
||||
<ClCompile>
|
||||
<AdditionalIncludeDirectories>..\common;$(ZoiteChatLib);$(DepsRoot)\include\enchant;$(DepsRoot)\include;$(OpenSslInclude);$(Glib);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<AdditionalDependencies>$(DepLibs);%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalLibraryDirectories>$(DepsRoot)\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
<ModuleDefinitionFile>libenchant_win8.def</ModuleDefinitionFile>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="win8_provider.cpp" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
</Project>
|
||||
@@ -1,22 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<Filter Include="Source Files">
|
||||
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
|
||||
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Header Files">
|
||||
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
|
||||
<Extensions>h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Resource Files">
|
||||
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
|
||||
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="win8_provider.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -1,340 +0,0 @@
|
||||
/* ZoiteChat
|
||||
* Copyright (c) 2015 Patrick Griffis
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <Spellcheck.h>
|
||||
#include <windows.h>
|
||||
|
||||
#include <cstdlib>
|
||||
#include <climits>
|
||||
|
||||
#include "typedef.h" // for ssize_t
|
||||
#include <enchant-provider.h>
|
||||
|
||||
ENCHANT_PLUGIN_DECLARE ("win8")
|
||||
|
||||
static int
|
||||
size_to_int (size_t value)
|
||||
{
|
||||
return value > static_cast<size_t>(INT_MAX) ? INT_MAX : static_cast<int>(value);
|
||||
}
|
||||
|
||||
static char *
|
||||
utf16_to_utf8 (const wchar_t * const str, bool from_bcp47)
|
||||
{
|
||||
if (!str)
|
||||
return nullptr;
|
||||
|
||||
int needed = WideCharToMultiByte (CP_UTF8, 0, str, -1, nullptr, 0, nullptr, nullptr);
|
||||
if (needed <= 0)
|
||||
return nullptr;
|
||||
|
||||
char *utf8 = static_cast<char*>(std::malloc (static_cast<size_t>(needed)));
|
||||
if (!utf8)
|
||||
return nullptr;
|
||||
|
||||
if (WideCharToMultiByte (CP_UTF8, 0, str, -1, utf8, needed, nullptr, nullptr) != needed)
|
||||
{
|
||||
std::free (utf8);
|
||||
return nullptr;
|
||||
}
|
||||
if (utf8 && from_bcp47)
|
||||
{
|
||||
char *p = utf8;
|
||||
/* bcp47 tags use syntax "en-US" while the myspell versions are "en_US" */
|
||||
while (*p)
|
||||
{
|
||||
if (*p == '-')
|
||||
*p = '_';
|
||||
p++;
|
||||
}
|
||||
}
|
||||
return utf8;
|
||||
}
|
||||
|
||||
static wchar_t *
|
||||
utf8_to_utf16 (const char * const str, int len, bool to_bcp47)
|
||||
{
|
||||
if (!str)
|
||||
return nullptr;
|
||||
|
||||
int needed = MultiByteToWideChar (CP_UTF8, 0, str, len, nullptr, 0);
|
||||
if (needed <= 0)
|
||||
return nullptr;
|
||||
|
||||
int alloc_len = (len == -1) ? needed : needed + 1;
|
||||
wchar_t *utf16 = static_cast<wchar_t*>(std::malloc (sizeof (wchar_t) * static_cast<size_t>(alloc_len)));
|
||||
if (!utf16)
|
||||
return nullptr;
|
||||
|
||||
if (MultiByteToWideChar (CP_UTF8, 0, str, len, utf16, needed) != needed)
|
||||
{
|
||||
std::free (utf16);
|
||||
return nullptr;
|
||||
}
|
||||
if (len != -1)
|
||||
utf16[needed] = L'\0';
|
||||
if (utf16 && to_bcp47)
|
||||
{
|
||||
wchar_t *p = utf16;
|
||||
/* bcp47 tags use syntax "en-US" while the myspell versions are "en_US" */
|
||||
while (*p)
|
||||
{
|
||||
if (*p == L'_')
|
||||
*p = L'-';
|
||||
p++;
|
||||
}
|
||||
}
|
||||
return utf16;
|
||||
}
|
||||
|
||||
static char **
|
||||
enumstring_to_chararray (IEnumString *strings, size_t *out_len, bool from_bcp47)
|
||||
{
|
||||
char **chars = static_cast<char**>(std::calloc (256, sizeof (char*)));
|
||||
LPOLESTR wstr = nullptr;
|
||||
size_t i = 0;
|
||||
|
||||
if (!chars)
|
||||
{
|
||||
*out_len = 0;
|
||||
strings->Release ();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
while (SUCCEEDED (strings->Next (1, &wstr, nullptr)) && i < 256 && wstr)
|
||||
{
|
||||
char *str = utf16_to_utf8 (wstr, from_bcp47);
|
||||
if (str)
|
||||
{
|
||||
chars[i] = str;
|
||||
i++;
|
||||
}
|
||||
CoTaskMemFree (wstr);
|
||||
}
|
||||
chars[i] = nullptr;
|
||||
strings->Release ();
|
||||
|
||||
*out_len = i;
|
||||
return chars;
|
||||
}
|
||||
|
||||
static void
|
||||
win8_dict_add_to_personal (EnchantDict *dict, const char *const word, size_t len)
|
||||
{
|
||||
auto checker = static_cast<ISpellChecker*>(dict->user_data);
|
||||
wchar_t *wword = utf8_to_utf16 (word, size_to_int (len), false);
|
||||
|
||||
checker->Add (wword);
|
||||
std::free (wword);
|
||||
}
|
||||
|
||||
static void
|
||||
win8_dict_add_to_session (EnchantDict *dict, const char *const word, size_t len)
|
||||
{
|
||||
auto checker = static_cast<ISpellChecker*>(dict->user_data);
|
||||
wchar_t *wword = utf8_to_utf16 (word, size_to_int (len), false);
|
||||
|
||||
checker->Ignore (wword);
|
||||
std::free (wword);
|
||||
}
|
||||
|
||||
static int
|
||||
win8_dict_check (EnchantDict *dict, const char *const word, size_t len)
|
||||
{
|
||||
auto checker = static_cast<ISpellChecker*>(dict->user_data);
|
||||
wchar_t *wword = utf8_to_utf16 (word, size_to_int (len), false);
|
||||
IEnumSpellingError *errors;
|
||||
ISpellingError *error = nullptr;
|
||||
HRESULT hr;
|
||||
|
||||
hr = checker->Check (wword, &errors);
|
||||
std::free (wword);
|
||||
|
||||
if (FAILED (hr))
|
||||
return -1;
|
||||
|
||||
if (errors->Next (&error) == S_OK)
|
||||
{
|
||||
error->Release ();
|
||||
errors->Release ();
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
errors->Release ();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
static char **
|
||||
win8_dict_suggest (EnchantDict *dict, const char *const word, size_t len, size_t *out_n_suggs)
|
||||
{
|
||||
auto checker = static_cast<ISpellChecker*>(dict->user_data);
|
||||
wchar_t *wword = utf8_to_utf16 (word, size_to_int (len), false);
|
||||
IEnumString *suggestions;
|
||||
HRESULT hr;
|
||||
|
||||
hr = checker->Suggest (wword, &suggestions);
|
||||
std::free (wword);
|
||||
|
||||
if (FAILED (hr))
|
||||
{
|
||||
*out_n_suggs = 0;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return enumstring_to_chararray (suggestions, out_n_suggs, false);
|
||||
}
|
||||
|
||||
static EnchantDict *
|
||||
win8_provider_request_dict (EnchantProvider *provider, const char *const tag)
|
||||
{
|
||||
auto factory = static_cast<ISpellCheckerFactory*>(provider->user_data);
|
||||
ISpellChecker *checker;
|
||||
EnchantDict *dict;
|
||||
wchar_t *wtag = utf8_to_utf16 (tag, -1, true);
|
||||
HRESULT hr;
|
||||
|
||||
hr = factory->CreateSpellChecker (wtag, &checker);
|
||||
std::free (wtag);
|
||||
|
||||
if (FAILED (hr))
|
||||
return nullptr;
|
||||
|
||||
dict = static_cast<EnchantDict*>(std::calloc (1, sizeof (EnchantDict)));
|
||||
dict->suggest = win8_dict_suggest;
|
||||
dict->check = win8_dict_check;
|
||||
dict->add_to_personal = win8_dict_add_to_personal;
|
||||
dict->add_to_exclude = win8_dict_add_to_personal;
|
||||
dict->add_to_session = win8_dict_add_to_session;
|
||||
|
||||
dict->user_data = checker;
|
||||
|
||||
return dict;
|
||||
}
|
||||
|
||||
static void
|
||||
win8_provider_dispose_dict (EnchantProvider *provider, EnchantDict *dict)
|
||||
{
|
||||
if (dict)
|
||||
{
|
||||
auto checker = static_cast<ISpellChecker*>(dict->user_data);
|
||||
|
||||
checker->Release ();
|
||||
std::free (dict);
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
win8_provider_dictionary_exists (EnchantProvider *provider, const char *const tag)
|
||||
{
|
||||
auto factory = static_cast<ISpellCheckerFactory*>(provider->user_data);
|
||||
wchar_t *wtag = utf8_to_utf16 (tag, -1, true);
|
||||
|
||||
BOOL is_supported = FALSE;
|
||||
factory->IsSupported (wtag, &is_supported);
|
||||
|
||||
std::free (wtag);
|
||||
return is_supported;
|
||||
}
|
||||
|
||||
|
||||
static char **
|
||||
win8_provider_list_dicts (EnchantProvider *provider, size_t *out_n_dicts)
|
||||
{
|
||||
auto factory = static_cast<ISpellCheckerFactory*>(provider->user_data);
|
||||
IEnumString *dicts;
|
||||
|
||||
if (FAILED(factory->get_SupportedLanguages (&dicts)))
|
||||
{
|
||||
*out_n_dicts = 0;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return enumstring_to_chararray (dicts, out_n_dicts, true);
|
||||
}
|
||||
|
||||
static void
|
||||
win8_provider_free_string_list (EnchantProvider *provider, char **str_list)
|
||||
{
|
||||
if (!str_list)
|
||||
return;
|
||||
for (size_t i = 0; str_list[i]; ++i)
|
||||
std::free (str_list[i]);
|
||||
std::free (str_list);
|
||||
}
|
||||
|
||||
static void
|
||||
win8_provider_dispose (EnchantProvider *provider)
|
||||
{
|
||||
if (provider)
|
||||
{
|
||||
auto factory = static_cast<ISpellCheckerFactory*>(provider->user_data);
|
||||
|
||||
factory->Release();
|
||||
std::free (provider);
|
||||
}
|
||||
}
|
||||
|
||||
static const char *
|
||||
win8_provider_identify (EnchantProvider *provider)
|
||||
{
|
||||
return "win8";
|
||||
}
|
||||
|
||||
static const char *
|
||||
win8_provider_describe (EnchantProvider *provider)
|
||||
{
|
||||
return "Windows 8 SpellCheck Provider";
|
||||
}
|
||||
|
||||
extern "C"
|
||||
{
|
||||
|
||||
EnchantProvider *
|
||||
init_enchant_provider (void)
|
||||
{
|
||||
EnchantProvider *provider;
|
||||
ISpellCheckerFactory *factory;
|
||||
|
||||
if (FAILED (CoCreateInstance (__uuidof(SpellCheckerFactory), nullptr,
|
||||
CLSCTX_INPROC_SERVER, IID_PPV_ARGS (&factory))))
|
||||
return nullptr;
|
||||
|
||||
provider = static_cast<EnchantProvider*>(std::calloc (1, sizeof (EnchantProvider)));
|
||||
provider->dispose = win8_provider_dispose;
|
||||
provider->request_dict = win8_provider_request_dict;
|
||||
provider->dispose_dict = win8_provider_dispose_dict;
|
||||
provider->dictionary_exists = win8_provider_dictionary_exists;
|
||||
provider->identify = win8_provider_identify;
|
||||
provider->describe = win8_provider_describe;
|
||||
provider->list_dicts = win8_provider_list_dicts;
|
||||
provider->free_string_list = win8_provider_free_string_list;
|
||||
|
||||
provider->user_data = factory;
|
||||
|
||||
return provider;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -61,7 +61,6 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "installer", "installer\inst
|
||||
ProjectSection(ProjectDependencies) = postProject
|
||||
{C2321A03-0BA7-45B3-8740-ABD82B36B0BF} = {C2321A03-0BA7-45B3-8740-ABD82B36B0BF}
|
||||
{D58924D2-1492-4AC3-B058-7A214424EEDC} = {D58924D2-1492-4AC3-B058-7A214424EEDC}
|
||||
{BF0EBC16-68AD-4CD1-864C-5B56836EBE2A} = {BF0EBC16-68AD-4CD1-864C-5B56836EBE2A}
|
||||
{17E4BE39-76F7-4A06-AD21-EFD0C5091F76} = {17E4BE39-76F7-4A06-AD21-EFD0C5091F76}
|
||||
{4C0F3940-2EEE-4646-82F7-6CE75B9A72F4} = {4C0F3940-2EEE-4646-82F7-6CE75B9A72F4}
|
||||
{B10A2C41-344C-43E0-A32D-B9587C198D8B} = {B10A2C41-344C-43E0-A32D-B9587C198D8B}
|
||||
@@ -95,11 +94,6 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "notifications-winrt", "..\s
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "external", "external", "{021EC1D0-FF67-4700-9AB2-EAABF1159C09}"
|
||||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libenchant_win8", "..\src\libenchant_win8\libenchant_win8.vcxproj", "{BF0EBC16-68AD-4CD1-864C-5B56836EBE2A}"
|
||||
ProjectSection(ProjectDependencies) = postProject
|
||||
{87554B59-006C-4D94-9714-897B27067BA3} = {87554B59-006C-4D94-9714-897B27067BA3}
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "lua", "..\plugins\lua\lua.vcxproj", "{4C0F3940-2EEE-4646-82F7-6CE75B9A72F4}"
|
||||
EndProject
|
||||
Global
|
||||
@@ -137,8 +131,6 @@ Global
|
||||
{D58924D2-1492-4AC3-B058-7A214424EEDC}.Release|x64.Build.0 = Release|x64
|
||||
{C53145CC-D021-40C9-B97C-0249AB9A43C9}.Release|x64.ActiveCfg = Release|x64
|
||||
{C53145CC-D021-40C9-B97C-0249AB9A43C9}.Release|x64.Build.0 = Release|x64
|
||||
{BF0EBC16-68AD-4CD1-864C-5B56836EBE2A}.Release|x64.ActiveCfg = Release|x64
|
||||
{BF0EBC16-68AD-4CD1-864C-5B56836EBE2A}.Release|x64.Build.0 = Release|x64
|
||||
{4C0F3940-2EEE-4646-82F7-6CE75B9A72F4}.Release|x64.ActiveCfg = Release|x64
|
||||
{4C0F3940-2EEE-4646-82F7-6CE75B9A72F4}.Release|x64.Build.0 = Release|x64
|
||||
EndGlobalSection
|
||||
@@ -161,7 +153,6 @@ Global
|
||||
{C2321A03-0BA7-45B3-8740-ABD82B36B0BF} = {D237DA6B-BD5F-46C0-8BEA-50E9A1340240}
|
||||
{D58924D2-1492-4AC3-B058-7A214424EEDC} = {D237DA6B-BD5F-46C0-8BEA-50E9A1340240}
|
||||
{C53145CC-D021-40C9-B97C-0249AB9A43C9} = {561126F4-FA18-45FC-A2BF-8F858F161D6D}
|
||||
{BF0EBC16-68AD-4CD1-864C-5B56836EBE2A} = {021EC1D0-FF67-4700-9AB2-EAABF1159C09}
|
||||
{4C0F3940-2EEE-4646-82F7-6CE75B9A72F4} = {D237DA6B-BD5F-46C0-8BEA-50E9A1340240}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
|
||||
Reference in New Issue
Block a user