Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chinese addons #28

Merged
merged 1 commit into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ jobs:
- name: Build
run: |
git apply --directory=fcitx5 patches/fcitx5.patch
git apply --directory=engines/libime/src/libime/core/kenlm patches/kenlm.patch
git apply --directory=engines/libime patches/libime.patch
git apply --directory=engines/fcitx5-chinese-addons patches/chinese-addons.patch
git apply --directory=engines/fcitx5-hallelujah patches/hallelujah.patch
git apply --directory=engines/fcitx5-rime patches/rime.patch
cmake -B build -G Xcode \
Expand Down
6 changes: 6 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,9 @@
[submodule "deps/AlertToast"]
path = deps/AlertToast
url = https://github.com/fcitx-contrib/AlertToast
[submodule "engines/fcitx5-chinese-addons"]
path = engines/fcitx5-chinese-addons
url = https://github.com/fcitx/fcitx5-chinese-addons
[submodule "engines/libime"]
path = engines/libime
url = https://github.com/fcitx/libime
2 changes: 1 addition & 1 deletion .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
{
"type": "shell",
"label": "Configure",
"command": "cmake -B build -G Xcode -DHALLELUJAH=ON -DURL_SCHEME=fcitx -DRIME=ON -DCMAKE_TOOLCHAIN_FILE=cmake/ios.cmake -DIOS_PLATFORM=SIMULATOR",
"command": "cmake -B build -G Xcode -DURL_SCHEME=fcitx -DCHINESE_ADDONS=ON -DHALLELUJAH=ON -DRIME=ON -DCMAKE_TOOLCHAIN_FILE=cmake/ios.cmake -DIOS_PLATFORM=SIMULATOR",
"group": {
"kind": "build"
}
Expand Down
17 changes: 16 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ add_subdirectory(iosnotifications)
add_subdirectory(uipanel)
add_subdirectory(ipc)

option(CHINESE_ADDONS "" ON)
option(HALLELUJAH "" OFF)
option(RIME "" OFF)

Expand All @@ -99,6 +100,20 @@ function(copy_to_app cmd file relative_path)
\")
endfunction()

if (CHINESE_ADDONS)
find_package(OpenCC REQUIRED)
option(ENABLE_GUI OFF)
option(ENABLE_CLOUDPINYIN OFF)
option(ENABLE_DATA OFF)
add_definitions(-DCHINESE_ADDONS)
set(_Fcitx5Macro_SELF_DIR "${PROJECT_SOURCE_DIR}/fcitx5/src/lib/fcitx-utils")
set(HAS_STD_FILESYSTEM 1)
set(BUILD_TOOLS OFF)
add_subdirectory(engines/libime)
add_subdirectory(engines/fcitx5-chinese-addons)
list(APPEND ADDONS chttrans fullwidth pinyin pinyinhelper punctuation table)
list(APPEND DEFAULT_INPUT_METHODS pinyin shuangpin wbx)
endif()
if (HALLELUJAH)
add_library(Marisa_static STATIC IMPORTED)
set_target_properties(Marisa_static PROPERTIES
Expand Down Expand Up @@ -153,7 +168,7 @@ add_custom_command(
)
add_custom_target(gen_profile DEPENDS "${PROJECT_BINARY_DIR}/profile")

if (HALLELUJAH)
if (CHINESE_ADDONS OR HALLELUJAH)
list(APPEND ADDONS spell)
endif()

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ IOS_PLATFORM=SIMULATOR ./scripts/install-deps.sh
### Apply patches
```sh
git apply --directory=fcitx5 patches/fcitx5.patch
git apply --directory=engines/libime/src/libime/core/kenlm patches/kenlm.patch
git apply --directory=engines/fcitx5-rime patches/rime.patch # if building with Rime
```

Expand Down
1 change: 1 addition & 0 deletions cmake/FindLibIMEPinyin.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
set(LibIMEPinyin_FOUND TRUE)
1 change: 1 addition & 0 deletions cmake/FindLibIMETable.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
set(LibIMETable_FOUND TRUE)
8 changes: 8 additions & 0 deletions cmake/FindOpenCC.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
set(OPENCC_FOUND TRUE)
set(OPENCC_LIBRARY "${PREBUILDER_LIB_DIR}/libopencc.a")
set(OPENCC_INCLUDE_DIR "${PREBUILDER_INCLUDE_DIR}/opencc")
add_library(OpenCC::OpenCC UNKNOWN IMPORTED)
set_target_properties(OpenCC::OpenCC PROPERTIES
IMPORTED_LOCATION "${OPENCC_LIBRARY}"
INTERFACE_INCLUDE_DIRECTORIES "${OPENCC_INCLUDE_DIR}"
)
13 changes: 12 additions & 1 deletion common/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,16 @@ FCITX_IMPORT_ADDON_FACTORY(addons, iosfrontend);
FCITX_IMPORT_ADDON_FACTORY(addons, notifications);
FCITX_IMPORT_ADDON_FACTORY(addons, uipanel);

#ifdef HALLELUJAH
#ifdef CHINESE_ADDONS
FCITX_IMPORT_ADDON_FACTORY(addons, pinyin);
FCITX_IMPORT_ADDON_FACTORY(addons, table);
FCITX_IMPORT_ADDON_FACTORY(addons, chttrans);
FCITX_IMPORT_ADDON_FACTORY(addons, fullwidth);
FCITX_IMPORT_ADDON_FACTORY(addons, pinyinhelper);
FCITX_IMPORT_ADDON_FACTORY(addons, punctuation);
#endif

#if defined(HALLELUJAH) || defined(CHINESE_ADDONS)
FCITX_IMPORT_ADDON_FACTORY(addons, spell);
#endif

Expand All @@ -51,7 +60,9 @@ void setupEnv(const char *bundlePath, const char *appGroupPath,

fs::path bundle = bundlePath;
std::string xdg_data_dirs = bundle / "share";
std::string libime_model_dirs = bundle / "lib/libime";
setenv("XDG_DATA_DIRS", xdg_data_dirs.c_str(), 1);
setenv("LIBIME_MODEL_DIRS", libime_model_dirs.c_str(), 1);

fs::path group = appGroupPath;
std::string xdg_data_home = group / "data";
Expand Down
1 change: 1 addition & 0 deletions engines/fcitx5-chinese-addons
Submodule fcitx5-chinese-addons added at cd5a7c
1 change: 1 addition & 0 deletions engines/libime
Submodule libime added at 118dc5
2 changes: 1 addition & 1 deletion fcitx5
91 changes: 91 additions & 0 deletions patches/chinese-addons.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index bd4ce71..c048801 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -40,7 +40,7 @@ option(ENABLE_CLOUDPINYIN "Build cloud pinyin addon" On)
option(USE_QT6 "Build with Qt6" On)
option(ENABLE_DATA "Build data" On)

-if (ENABLE_OPENCC)
+if (ENABLE_OPENCC AND NOT TARGET OpenCC::OpenCC)
find_package(OpenCC 1.0.1 REQUIRED)
endif()

diff --git a/im/pinyin/CMakeLists.txt b/im/pinyin/CMakeLists.txt
index 4caf30b..ba4caa4 100644
--- a/im/pinyin/CMakeLists.txt
+++ b/im/pinyin/CMakeLists.txt
@@ -7,7 +7,7 @@ set(PINYIN_SOURCES
pinyinenginefactory.cpp
)

-add_library(pinyin MODULE ${PINYIN_SOURCES})
+add_library(pinyin STATIC ${PINYIN_SOURCES})
target_link_libraries(pinyin Fcitx5::Core Fcitx5::Config LibIME::Pinyin Boost::iostreams Fcitx5::Module::Punctuation Fcitx5::Module::QuickPhrase Fcitx5::Module::Notifications Fcitx5::Module::Spell Fcitx5::Module::PinyinHelper Pthread::Pthread ${FMT_TARGET})

if (TARGET Fcitx5::Module::LuaAddonLoader)
diff --git a/im/table/CMakeLists.txt b/im/table/CMakeLists.txt
index 7c930e9..f4b1c17 100644
--- a/im/table/CMakeLists.txt
+++ b/im/table/CMakeLists.txt
@@ -6,7 +6,7 @@ set(TABLE_SOURCES
candidate.cpp
factory.cpp
)
-add_library(table MODULE ${TABLE_SOURCES})
+add_library(table STATIC ${TABLE_SOURCES})
target_link_libraries(table Fcitx5::Core Fcitx5::Config LibIME::Table LibIME::Pinyin Boost::iostreams Fcitx5::Module::Punctuation Fcitx5::Module::QuickPhrase Fcitx5::Module::PinyinHelper ${FMT_TARGET})
target_compile_definitions(table PRIVATE FCITX_STRINGUTILS_ENABLE_BOOST_STRING_VIEW)
install(TARGETS table DESTINATION "${CMAKE_INSTALL_LIBDIR}/fcitx5")
diff --git a/modules/chttrans/CMakeLists.txt b/modules/chttrans/CMakeLists.txt
index 14351c8..d3d3bb9 100644
--- a/modules/chttrans/CMakeLists.txt
+++ b/modules/chttrans/CMakeLists.txt
@@ -4,7 +4,7 @@ set(CHTTRANS_SOURCES
if (ENABLE_OPENCC)
set(CHTTRANS_SOURCES ${CHTTRANS_SOURCES} chttrans-opencc.cpp)
endif()
-add_library(chttrans MODULE ${CHTTRANS_SOURCES})
+add_library(chttrans STATIC ${CHTTRANS_SOURCES})
target_link_libraries(chttrans Fcitx5::Core Fcitx5::Config Fcitx5::Module::Notifications Boost::iostreams ${FMT_TARGET})
if (ENABLE_OPENCC)
target_link_libraries(chttrans OpenCC::OpenCC)
diff --git a/modules/fullwidth/CMakeLists.txt b/modules/fullwidth/CMakeLists.txt
index 3fb2ee0..e5b42b7 100644
--- a/modules/fullwidth/CMakeLists.txt
+++ b/modules/fullwidth/CMakeLists.txt
@@ -1,7 +1,7 @@
set(FULLWIDTH_SOURCES
fullwidth.cpp
)
-add_library(fullwidth MODULE ${FULLWIDTH_SOURCES})
+add_library(fullwidth STATIC ${FULLWIDTH_SOURCES})
target_link_libraries(fullwidth Fcitx5::Core Fcitx5::Config Fcitx5::Module::Notifications)
install(TARGETS fullwidth DESTINATION "${CMAKE_INSTALL_LIBDIR}/fcitx5")
configure_file(fullwidth.conf.in.in fullwidth.conf.in)
diff --git a/modules/pinyinhelper/CMakeLists.txt b/modules/pinyinhelper/CMakeLists.txt
index a2ca5d9..ea0980b 100644
--- a/modules/pinyinhelper/CMakeLists.txt
+++ b/modules/pinyinhelper/CMakeLists.txt
@@ -3,7 +3,7 @@ set(PINYINHELPER_SOURCES
pinyinlookup.cpp
stroke.cpp
)
-add_library(pinyinhelper MODULE ${PINYINHELPER_SOURCES})
+add_library(pinyinhelper STATIC ${PINYINHELPER_SOURCES})
target_link_libraries(pinyinhelper
Fcitx5::Core
Fcitx5::Config
diff --git a/modules/punctuation/CMakeLists.txt b/modules/punctuation/CMakeLists.txt
index 2de1433..0263601 100644
--- a/modules/punctuation/CMakeLists.txt
+++ b/modules/punctuation/CMakeLists.txt
@@ -8,7 +8,7 @@ set(PUNCTUATION_DATA_FILES
punc.mb.zh_TW
)

-add_library(punctuation MODULE ${PUNCTUATION_SOURCES})
+add_library(punctuation STATIC ${PUNCTUATION_SOURCES})
target_link_libraries(punctuation Fcitx5::Core Fcitx5::Config Boost::iostreams Fcitx5::Module::Notifications)
install(TARGETS punctuation DESTINATION "${CMAKE_INSTALL_LIBDIR}/fcitx5")
configure_file(punctuation.conf.in.in punctuation.conf.in)
28 changes: 28 additions & 0 deletions patches/kenlm.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
diff --git a/util/usage.cc b/util/usage.cc
index 79d61c2..62edb0b 100644
--- a/util/usage.cc
+++ b/util/usage.cc
@@ -43,7 +43,6 @@ typedef WINBOOL (WINAPI *PFN_MS_EX) (lMEMORYSTATUSEX*);
#include <sys/sysctl.h>
#include <mach/task.h>
#include <mach/mach.h>
-#include <libproc.h>
#endif

namespace util {
@@ -197,6 +196,7 @@ uint64_t RSSMax() {
#endif
}

+#if 0
void PrintUsage(std::ostream &out) {
#if !defined(_WIN32) && !defined(_WIN64)
#if defined(__MACH__) || defined(__APPLE__)
@@ -238,6 +238,7 @@ void PrintUsage(std::ostream &out) {

out << "real:" << WallTime() << '\n';
}
+#endif

/* Adapted from physmem.c in gnulib 831b84c59ef413c57a36b67344467d66a8a2ba70 */
/* Calculate the size of physical memory.
48 changes: 48 additions & 0 deletions patches/libime.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
diff --git a/src/libime/core/CMakeLists.txt b/src/libime/core/CMakeLists.txt
index 35ee954..b1ada6a 100644
--- a/src/libime/core/CMakeLists.txt
+++ b/src/libime/core/CMakeLists.txt
@@ -69,7 +69,7 @@ ecm_setup_version(PROJECT
# the cmake if will
set(IMECore_SOVERSION 0)

-add_library(IMECore SHARED ${LIBIME_SRCS})
+add_library(IMECore STATIC ${LIBIME_SRCS})
set_target_properties(IMECore
PROPERTIES VERSION ${IMECore_VERSION}
SOVERSION ${IMECore_SOVERSION}
@@ -82,7 +82,7 @@ target_include_directories(IMECore PUBLIC

target_link_libraries(IMECore PUBLIC Fcitx5::Utils Boost::boost PRIVATE kenlm Boost::iostreams PkgConfig::ZSTD)

-install(TARGETS IMECore EXPORT LibIMECoreTargets LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" COMPONENT lib)
+install(TARGETS IMECore kenlm EXPORT LibIMECoreTargets LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" COMPONENT lib)
install(FILES ${LIBIME_HDRS} DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/LibIME/libime/core" COMPONENT header)

add_library(LibIME::Core ALIAS IMECore)
diff --git a/src/libime/pinyin/CMakeLists.txt b/src/libime/pinyin/CMakeLists.txt
index a5e6d35..601d559 100644
--- a/src/libime/pinyin/CMakeLists.txt
+++ b/src/libime/pinyin/CMakeLists.txt
@@ -32,7 +32,7 @@ ecm_setup_version(PROJECT
PACKAGE_VERSION_FILE "${CMAKE_CURRENT_BINARY_DIR}/LibIMEPinyinConfigVersion.cmake")
set(IMEPinyin_SOVERSION 0)

-add_library(IMEPinyin SHARED ${LIBIME_PINYIN_SRCS})
+add_library(IMEPinyin STATIC ${LIBIME_PINYIN_SRCS})
set_target_properties(IMEPinyin PROPERTIES
VERSION ${IMEPinyin_VERSION}
SOVERSION ${IMEPinyin_SOVERSION}
diff --git a/src/libime/table/CMakeLists.txt b/src/libime/table/CMakeLists.txt
index 62317bd..dd47d0b 100644
--- a/src/libime/table/CMakeLists.txt
+++ b/src/libime/table/CMakeLists.txt
@@ -23,7 +23,7 @@ ecm_setup_version(PROJECT
PACKAGE_VERSION_FILE "${CMAKE_CURRENT_BINARY_DIR}/LibIMETableConfigVersion.cmake")
set(IMETable_SOVERSION 0)

-add_library(IMETable SHARED ${LIBIME_TABLE_SRCS})
+add_library(IMETable STATIC ${LIBIME_TABLE_SRCS})
set_target_properties(IMETable
PROPERTIES VERSION ${IMETable_VERSION}
SOVERSION ${IMETable_SOVERSION}
10 changes: 9 additions & 1 deletion scripts/install-deps.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
deps=(
boost
fmt
glog
json-c
Expand All @@ -10,10 +11,12 @@ deps=(
marisa
opencc
yaml-cpp
zstd
)

EXTRACT_DIR=build/sysroot/usr
mkdir -p $EXTRACT_DIR
SPELL_DICT_DIR=$EXTRACT_DIR/share/fcitx5/spell
mkdir -p $SPELL_DICT_DIR

if [[ $IOS_PLATFORM == "SIMULATOR" ]]; then
POSTFIX=-$(uname -m)
Expand All @@ -27,7 +30,12 @@ for dep in "${deps[@]}"; do
tar xjvf cache/$file -C $EXTRACT_DIR
done

file=Fcitx5-arm64.tar.bz2
[[ -f cache/$file ]] || wget -P cache https://github.com/fcitx-contrib/fcitx5-macos/releases/download/latest/$file
tar xjvf cache/$file -C $SPELL_DICT_DIR --strip-components=5 Fcitx5.app/Contents/share/fcitx5/spell/en_dict.fscd

plugins=(
chinese-addons
rime
)

Expand Down
38 changes: 38 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,44 @@ copy_to_keyboard(copy "${PROJECT_BINARY_DIR}/uipanel/uipanel.conf" "${ADDON_PREF

set(FCITX5_MODULE_BINARY_DIR "${PROJECT_BINARY_DIR}/fcitx5/src/modules")
copy_to_keyboard(copy "${FCITX5_MODULE_BINARY_DIR}/spell/spell.conf" "${ADDON_PREFIX}/spell.conf")
copy_share_to_keyboard(copy fcitx5/spell/en_dict.fscd "share/fcitx5/spell/en_dict.fscd")

if (CHINESE_ADDONS)
set(CHINESE_ADDONS_BINARY_DIR "${PROJECT_BINARY_DIR}/engines/fcitx5-chinese-addons")

# Pinyin addon and im
copy_to_keyboard(copy "${CHINESE_ADDONS_BINARY_DIR}/im/pinyin/pinyin-addon.conf" "${ADDON_PREFIX}/pinyin.conf")
copy_to_keyboard(copy "${CHINESE_ADDONS_BINARY_DIR}/im/pinyin/pinyin.conf" "${IM_PREFIX}/pinyin.conf")
copy_to_keyboard(copy "${CHINESE_ADDONS_BINARY_DIR}/im/pinyin/shuangpin.conf" "${IM_PREFIX}/shuangpin.conf")

# Table addon, im and dict
copy_to_keyboard(copy "${CHINESE_ADDONS_BINARY_DIR}/im/table/table.conf" "share/fcitx5/addon/table.conf")
# Filter out wanfeng, erbi, cangjie and qxm.
copy_share_to_keyboard(copy "fcitx5/inputmethod/db.conf")
copy_share_to_keyboard(copy "libime/db.main.dict")
copy_share_to_keyboard(copy "fcitx5/inputmethod/wbx.conf")
copy_share_to_keyboard(copy "libime/wbx.main.dict")
copy_share_to_keyboard(copy "fcitx5/inputmethod/wbpy.conf")
copy_share_to_keyboard(copy "libime/wbpy.main.dict")
copy_share_to_keyboard(copy "fcitx5/inputmethod/zrm.conf")
copy_share_to_keyboard(copy "libime/zrm.main.dict")

# Module addons
copy_to_keyboard(copy "${CHINESE_ADDONS_BINARY_DIR}/modules/pinyinhelper/pinyinhelper.conf" "share/fcitx5/addon/pinyinhelper.conf")
copy_to_keyboard(copy "${CHINESE_ADDONS_BINARY_DIR}/modules/fullwidth/fullwidth.conf" "share/fcitx5/addon/fullwidth.conf")
copy_to_keyboard(copy "${CHINESE_ADDONS_BINARY_DIR}/modules/punctuation/punctuation.conf" "share/fcitx5/addon/punctuation.conf")
copy_to_keyboard(copy "${CHINESE_ADDONS_BINARY_DIR}/modules/chttrans/chttrans.conf" "share/fcitx5/addon/chttrans.conf")

# Shared resources
copy_to_keyboard(copy_directory "${PREBUILDER_LIB_DIR}/libime" "lib/libime")
copy_share_to_keyboard(copy_directory "fcitx5/pinyin")
copy_share_to_keyboard(copy_directory "fcitx5/pinyinhelper")
copy_share_to_keyboard(copy_directory "fcitx5/punctuation")
copy_share_to_keyboard(copy "libime/sc.dict")
copy_share_to_keyboard(copy "libime/extb.dict")
copy_share_to_keyboard(copy_directory "fcitx5/chttrans")
copy_share_to_keyboard(copy_directory "opencc")
endif()

if (HALLELUJAH)
set(HALLELUJAH_SOURCE_DIR "${PROJECT_SOURCE_DIR}/engines/fcitx5-hallelujah")
Expand Down
4 changes: 2 additions & 2 deletions uipanel/Keyboard.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ class Keyboard: UIStackView {
["1", "2", "3", "4", "5", "6", "7", "8", "9", "0"],
["q", "w", "e", "r", "t", "y", "u", "i", "o", "p"],
["a", "s", "d", "f", "g", "h", "j", "k", "l"],
["z", "x", "c", "v", "b", "n", "m"],
[" "],
["`", "z", "x", "c", "v", "b", "n", "m"],
[",", " ", "."],
]

init(_ client: FcitxProtocol) {
Expand Down