1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
| | https://github.com/fcitx/fcitx5/commit/a2b09de92a73dfa4ae43d3ac8a4ffa1aa791f6c5.patch
https://github.com/fcitx/fcitx5/issues/154
From a2b09de92a73dfa4ae43d3ac8a4ffa1aa791f6c5 Mon Sep 17 00:00:00 2001
From: Weng Xuetian <wengxt@gmail.com>
Date: Sun, 22 Nov 2020 23:42:44 -0800
Subject: [PATCH] Allow set CLDR dir
Fix #154
---
CMakeLists.txt | 22 +++++++++++++++++++---
config.h.in | 2 +-
src/modules/emoji/CMakeLists.txt | 2 +-
src/modules/emoji/emoji.cpp | 8 +++-----
4 files changed, 24 insertions(+), 10 deletions(-)
diff --git a/CMakeLists.txt b/CMakeLists.txt
index e6763dd..fc84b4b 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -29,6 +29,19 @@ option(ENABLE_WAYLAND "Enable wayland support" On)
option(ENABLE_DOC "Build doxygen" Off)
option(USE_SYSTEMD "Use systemd for event loop and dbus, will fallback to libevent/libdbus if not found." On)
option(ENABLE_XDGAUTOSTART "Enable xdg autostart desktop file installation" On)
+set(CLDR_DIR "" CACHE STRING "Unicode CLDR (Common Locale Data Repository) directory")
+
+if (CLDR_DIR STREQUAL "")
+ if (IS_DIRECTORY "${CMAKE_INSTALL_FULL_DATADIR}/unicode/cldr")
+ set(CLDR_DIR "${CMAKE_INSTALL_FULL_DATADIR}/unicode/cldr")
+ else(IS_DIRECTORY "/usr/share/unicode/cldr")
+ set(CLDR_DIR "/usr/share/unicode/cldr")
+ endif()
+endif()
+
+if (NOT IS_DIRECTORY "${CLDR_DIR}")
+ message(FATAL_ERROR "Could not find Unicode CLDR directory")
+endif()
#######################################################################
# Find packages
@@ -73,7 +86,6 @@ pkg_check_modules(CairoXCB IMPORTED_TARGET cairo-xcb)
pkg_check_modules(Pango IMPORTED_TARGET pango pangocairo)
pkg_check_modules(GdkPixbuf IMPORTED_TARGET gdk-pixbuf-2.0)
pkg_check_modules(GioUnix IMPORTED_TARGET gio-unix-2.0)
-pkg_check_modules(CldrEmojiAnnotation REQUIRED IMPORTED_TARGET cldr-emoji-annotation)
if (ENABLE_WAYLAND)
find_package(Wayland REQUIRED COMPONENTS Client Egl)
@@ -106,10 +118,14 @@ else()
set(WAYLAND_FOUND FALSE)
endif()
+if (NOT EXISTS "${CLDR_DIR}")
+ message(FATAL_ERROR "Could not find Unicode CLDR directory: ${CLDR_DIR}")
+endif()
+
set(DEFAULT_XKB_RULES_FILES "${XKEYBOARDCONFIG_XKBBASE}/rules/${DEFAULT_XKB_RULES}.xml")
if (NOT EXISTS "${DEFAULT_XKB_RULES_FILES}")
-message(FATAL_ERROR "Could not find default xkb rules file: ${DEFAULT_XKB_RULES_FILES}")
-endif ()
+ message(FATAL_ERROR "Could not find default xkb rules file: ${DEFAULT_XKB_RULES_FILES}")
+endif()
# directory needed by bsd
if(NOT CMAKE_INSTALL_LIBDATADIR)
diff --git a/config.h.in b/config.h.in
index 09bf002..4291152 100644
--- a/config.h.in
+++ b/config.h.in
@@ -33,7 +33,7 @@
#cmakedefine HAS_DLMOPEN
#define XKEYBOARDCONFIG_DATADIR "@XKEYBOARDCONFIG_DATADIR@"
#define DBUS_SYSTEM_BUS_DEFAULT_ADDRESS "@DBUS_SYSTEM_BUS_DEFAULT_ADDRESS@"
-#define CLDR_EMOJI_ANNOTATION_PREFIX "@CldrEmojiAnnotation_PREFIX@"
+#define CLDR_DIR "@CLDR_DIR@"
#ifndef _GNU_SOURCE
#define _GNU_SOURCE
diff --git a/src/modules/emoji/CMakeLists.txt b/src/modules/emoji/CMakeLists.txt
index 9fa84bb..57ae48b 100644
--- a/src/modules/emoji/CMakeLists.txt
+++ b/src/modules/emoji/CMakeLists.txt
@@ -1,4 +1,4 @@
-if (NOT IS_DIRECTORY ${CldrEmojiAnnotation_PREFIX}/share/unicode/cldr/common/annotations)
+if ("${CLDR_DIR}" STREQUAL "" OR NOT IS_DIRECTORY "${CLDR_DIR}/common/annotations")
return()
endif()
diff --git a/src/modules/emoji/emoji.cpp b/src/modules/emoji/emoji.cpp
index 5606a37..805aef7 100644
--- a/src/modules/emoji/emoji.cpp
+++ b/src/modules/emoji/emoji.cpp
@@ -126,7 +126,7 @@ bool noSpace(const std::string &str) {
const EmojiMap *Emoji::loadEmoji(const std::string &language,
bool fallbackToEn) {
- // This is to match the file in cldr-emoji-annotation.
+ // This is to match the file in CLDR.
static const std::unordered_map<std::string, std::string> languageMap = {
{"zh_TW", "zh_Hant"}, {"zh_CN", "zh"}, {"zh_HK", "zh_Hant_HK"}};
@@ -172,10 +172,8 @@ const EmojiMap *Emoji::loadEmoji(const std::string &language,
return utf8::lengthValidated(str) > 2;
}}};
const auto *filter = findValue(filterMap, lang);
- const auto file =
- stringutils::joinPath(CLDR_EMOJI_ANNOTATION_PREFIX,
- "/share/unicode/cldr/common/annotations",
- stringutils::concat(lang, ".xml"));
+ const auto file = stringutils::joinPath(
+ CLDR_DIR, "/common/annotations", stringutils::concat(lang, ".xml"));
EmojiParser parser(filter ? *filter : nullptr);
if (parser.parse(file)) {
emojiMap = &(langToEmojiMap_[lang] = std::move(parser.emojiMap_));
|