diff --git a/CMakeLists.txt b/CMakeLists.txt index 6122cf2..7e1c65f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -26,8 +26,6 @@ add_subdirectory(${PROJECT_LIBCHEWING}) add_subdirectory(${PROJECT_SOURCE_DIR}/libIME) -add_subdirectory(chewingwrapper) - add_subdirectory(${PROJECT_SOURCE_DIR}/ChewingTextService) add_subdirectory(${PROJECT_SOURCE_DIR}/ChewingPreferences) diff --git a/README.md b/README.md index d2652a8..98ec800 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,6 @@ Implement chewing in Windows via Text Services Framework: * LibIME contains a library which aims to be a simple wrapper for Windows Text Service Framework (TSF). * ChewingTextService contains an implementation of Windows text service for libchewing using libIME. -* chewingwrapper contains a C++ wrapper for libchewing. All parts are licensed under GNU LGPL v2.1 license. diff --git a/chewingwrapper/CMakeLists.txt b/chewingwrapper/CMakeLists.txt deleted file mode 100644 index 9f91f45..0000000 --- a/chewingwrapper/CMakeLists.txt +++ /dev/null @@ -1,39 +0,0 @@ -project(chewingwrapper LANGUAGES CXX) - -if(NOT DEFINED PROJECT_LIBCHEWING OR NOT DEFINED CHEWING_DATA_PREFIX) - message(FATAL_ERROR "PROJECT_LIBCHEWING and CHEWING_DATA_PREFIX must be provided") -endif() - -include_directories( - ${PROJECT_SOURCE_DIR}/include - ${PROJECT_LIBCHEWING}/include -) - -add_library(chewingwrapper_static STATIC - ${PROJECT_SOURCE_DIR}/include/chewingwrapper.hpp - ${PROJECT_SOURCE_DIR}/src/chewingwrapper.cpp -) -target_link_libraries(chewingwrapper_static libchewing) - -enable_testing() -set(CHEWINGWRAPPER_TEST - test-chewingwrapper -) - -set(CHEWINGWRAPPER_TEST_BIN ${PROJECT_BINARY_DIR}/test) - -foreach(target ${CHEWINGWRAPPER_TEST}) - add_executable(${target} - ${PROJECT_SOURCE_DIR}/test/${target}.cpp - ) - target_link_libraries(${target} chewingwrapper_static) - set_target_properties(${target} PROPERTIES - RUNTIME_OUTPUT_DIRECTORY ${CHEWINGWRAPPER_TEST_BIN} - RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CHEWINGWRAPPER_TEST_BIN} - RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CHEWINGWRAPPER_TEST_BIN} - COMPILE_DEFINITIONS - "CHEWING_PATH=\"${CHEWING_DATA_PREFIX}\";CHEWING_USER_PATH=\"${CHEWINGWRAPPER_TEST_BIN}\"" - ) - - add_test(${target} ${CHEWINGWRAPPER_TEST_BIN}/${target}) -endforeach() diff --git a/chewingwrapper/include/chewingwrapper.hpp b/chewingwrapper/include/chewingwrapper.hpp deleted file mode 100644 index 0d0f571..0000000 --- a/chewingwrapper/include/chewingwrapper.hpp +++ /dev/null @@ -1,50 +0,0 @@ -#pragma once - -#include - -#include - -class ChewingWrapper { -public: - ChewingWrapper(); - ~ChewingWrapper(); - - void handle_key(int key); - void handle_enter(); - void handle_space(); - void handle_esc(); - - void handle_delete(); - void handle_backspace(); - - void handle_home(); - void handle_end(); - - void handle_ctrl_num(int code); - - void handle_up(); - void handle_down(); - void handle_left(); - void handle_right(); - - void handle_shift_left(); - void handle_shift_right(); - void handle_shift_space(); - - void handle_tab(); - - bool has_commit(); - std::unique_ptr get_commit(); - - bool has_bopomofo(); - std::unique_ptr get_bopomofo(); - - bool has_preedit(); - std::unique_ptr get_preedit(); - -private: - ChewingWrapper(const ChewingWrapper&); - ChewingWrapper& operator=(const ChewingWrapper&); - std::unique_ptr convert_utf8_to_utf16(std::unique_ptr&& input); - std::unique_ptr m_ctx; -}; diff --git a/chewingwrapper/src/chewingwrapper.cpp b/chewingwrapper/src/chewingwrapper.cpp deleted file mode 100644 index 47aae6b..0000000 --- a/chewingwrapper/src/chewingwrapper.cpp +++ /dev/null @@ -1,155 +0,0 @@ -#include - -#include -#include - -#include - -ChewingWrapper::ChewingWrapper() -:m_ctx(chewing_new(), chewing_delete) -{ - if (!m_ctx) - throw std::runtime_error("Cannot initialize chewing instance"); -} - -ChewingWrapper::~ChewingWrapper() -{ -} - -void ChewingWrapper::handle_key(int key) -{ - chewing_handle_Default(m_ctx.get(), key); -} - -void ChewingWrapper::handle_enter() -{ - chewing_handle_Enter(m_ctx.get()); -} - -void ChewingWrapper::handle_space() -{ - chewing_handle_Space(m_ctx.get()); -} - -void ChewingWrapper::handle_esc() -{ - chewing_handle_Esc(m_ctx.get()); -} - -void ChewingWrapper::handle_delete() -{ - chewing_handle_Del(m_ctx.get()); -} - -void ChewingWrapper::handle_backspace() -{ - chewing_handle_Backspace(m_ctx.get()); -} - -void ChewingWrapper::handle_home() -{ - chewing_handle_Home(m_ctx.get()); -} - -void ChewingWrapper::handle_end() -{ - chewing_handle_End(m_ctx.get()); -} - -void ChewingWrapper::handle_ctrl_num(int code) -{ - chewing_handle_CtrlNum(m_ctx.get(), code); -} - -void ChewingWrapper::handle_up() -{ - chewing_handle_Up(m_ctx.get()); -} - -void ChewingWrapper::handle_down() -{ - chewing_handle_Down(m_ctx.get()); -} - -void ChewingWrapper::handle_left() -{ - chewing_handle_Left(m_ctx.get()); -} - -void ChewingWrapper::handle_right() -{ - chewing_handle_Right(m_ctx.get()); -} - -void ChewingWrapper::handle_shift_left() -{ - chewing_handle_ShiftLeft(m_ctx.get()); -} - -void ChewingWrapper::handle_shift_right() -{ - chewing_handle_ShiftRight(m_ctx.get()); -} - -void ChewingWrapper::handle_shift_space() -{ - chewing_handle_ShiftSpace(m_ctx.get()); -} - -void ChewingWrapper::handle_tab() -{ - chewing_handle_Tab(m_ctx.get()); -} - -bool ChewingWrapper::has_commit() -{ - return !!chewing_commit_Check(m_ctx.get()); -} - -std::unique_ptr ChewingWrapper::get_commit() -{ - std::unique_ptr utf8_string(chewing_commit_String(m_ctx.get()), chewing_free); - if (!utf8_string.get()) - throw std::bad_alloc(); - return convert_utf8_to_utf16(std::move(utf8_string)); -} - -bool ChewingWrapper::has_bopomofo() -{ - return !chewing_zuin_Check(m_ctx.get()); -} - -std::unique_ptr ChewingWrapper::get_bopomofo() -{ - int dummy; - std::unique_ptr utf8_string(chewing_zuin_String(m_ctx.get(), &dummy), chewing_free); - if (!utf8_string.get()) - throw std::bad_alloc(); - return convert_utf8_to_utf16(std::move(utf8_string)); -} - -bool ChewingWrapper::has_preedit() -{ - return !!chewing_buffer_Check(m_ctx.get()); -} - -std::unique_ptr ChewingWrapper::get_preedit() -{ - std::unique_ptr utf8_string(chewing_buffer_String(m_ctx.get()), chewing_free); - if (!utf8_string.get()) - throw std::bad_alloc(); - return convert_utf8_to_utf16(std::move(utf8_string)); -} - -std::unique_ptr ChewingWrapper::convert_utf8_to_utf16(std::unique_ptr&& input) -{ - int len = MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, input.get(), -1, 0, 0); - if (len == 0) - throw std::runtime_error("MultiByteToWideChar returns 0"); - - std::unique_ptr output(new wchar_t[len]); - - MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, input.get(), -1, output.get(), len); - return output; -} - diff --git a/chewingwrapper/test/test-chewingwrapper.cpp b/chewingwrapper/test/test-chewingwrapper.cpp deleted file mode 100644 index fb6650e..0000000 --- a/chewingwrapper/test/test-chewingwrapper.cpp +++ /dev/null @@ -1,62 +0,0 @@ -#include -#include - -#include - -#include - -int main() -{ - // XXX: Use SetEnvironmentVariableA here will cause crash in Visual Studio. - _putenv("CHEWING_PATH=" CHEWING_PATH); - _putenv("CHEWING_USER_PATH=" CHEWING_USER_PATH); - - const wchar_t EXPECT[] = { 0x6e2c, 0x8a66, 0 /* 測試 */ }; - const wchar_t EXPECT_BOPOMOFO[] = { 0x3118, 0x311c, 0 /* ㄘㄜ */ }; - - ChewingWrapper ctx; - - ctx.handle_key('h'); - ctx.handle_key('k'); - - if (!ctx.has_bopomofo()) { - std::cerr << "has_bopomofo shall return true" << std::endl; - return -1; - } - - std::unique_ptr bopomofo_string(ctx.get_bopomofo()); - if (wcscmp(bopomofo_string.get(), EXPECT_BOPOMOFO)) { - std::cerr << "get_bopomofo shall return " << EXPECT_BOPOMOFO << std::endl; - return -1; - } - - ctx.handle_key('4'); - ctx.handle_key('g'); - ctx.handle_key('4'); - - if (!ctx.has_preedit()) { - std::cerr << "has_preedit shall return true" << std::endl; - return -1; - } - - std::unique_ptr preedit_string(ctx.get_preedit()); - if (wcscmp(preedit_string.get(), EXPECT)) { - std::cerr << "get_preedit shall return " << EXPECT << std::endl; - return -1; - } - - ctx.handle_enter(); - - if (!ctx.has_commit()) { - std::cerr << "has_commit shall return true" << std::endl; - return -1; - } - - std::unique_ptr commit_string(ctx.get_commit()); - if (wcscmp(commit_string.get(), EXPECT)) { - std::cerr << "get_commit shall return " << EXPECT << std::endl; - return -1; - } - - return 0; -}