From 2d469508cd8cd9f00c8925dd0834747211d26680 Mon Sep 17 00:00:00 2001 From: "Hong Jen Yee (PCMan)" Date: Wed, 25 Sep 2013 12:17:17 +0800 Subject: [PATCH] Optionally output simplified Chinese characters on the fly. --- ChewingPreferences/ChewingPreferences.rc | Bin 30246 -> 30208 bytes ChewingPreferences/resource.h | Bin 14430 -> 14522 bytes ChewingTextService/ChewingTextService.cpp | 23 ++++++++++++++++++++++ ChewingTextService/ChewingTextService.h | 2 ++ ChewingTextService/ChewingTextService.rc | Bin 9794 -> 9958 bytes ChewingTextService/resource.h | Bin 5706 -> 5894 bytes libIME/Utils.cpp | 10 ++++++++++ libIME/Utils.h | 3 +++ 8 files changed, 38 insertions(+) diff --git a/ChewingPreferences/ChewingPreferences.rc b/ChewingPreferences/ChewingPreferences.rc index 4eb0654ddf6b35ae0cf272bb5eb613a6a5539ad0..7b671e187df1814d17c3b6a20f0336261c4da9ef 100644 GIT binary patch delta 85 zcmZ4XhOyxd=OM*3IOqt8#Dj_ delta 61 zcmV-D0K)%(>;b0i0kE=J3OJAYQ6YTPnpazseoY(&X#i~iaFd};Ig_9rRFiC32njg= TFaRt7H2^S^&r2DzZd#HX_$3wz diff --git a/ChewingPreferences/resource.h b/ChewingPreferences/resource.h index e3b78a4786c9085e380cedddcfc8c8374774a608..01890e500081ec7f229f154fb5043467941de67b 100644 GIT binary patch delta 72 zcmcatu&Z!GgY4uPq5^`R489Bj4Dk%k3?2-g41Nr*lMNNcC&{Wz)({a84h9NgN{ddC LHQM}2wnPd5vEmW8 delta 23 fcmdm0c&}hXgY4uBTwIfLWb`J<8f|uyE0F>Kew+yn diff --git a/ChewingTextService/ChewingTextService.cpp b/ChewingTextService/ChewingTextService.cpp index 385562e6d..6d8fbdb8a 100644 --- a/ChewingTextService/ChewingTextService.cpp +++ b/ChewingTextService/ChewingTextService.cpp @@ -60,6 +60,7 @@ TextService::TextService(ImeModule* module): showingCandidates_(false), langMode_(-1), shapeMode_(-1), + outputSimpChinese_(false), lastKeyDownCode_(0), messageWindow_(NULL), messageTimerId_(0), @@ -354,6 +355,11 @@ bool TextService::onKeyDown(Ime::KeyEvent& keyEvent, Ime::EditSession* session) char* buf = ::chewing_commit_String(chewingContext_); std::wstring wbuf = utf8ToUtf16(buf); ::chewing_free(buf); + + // FIXME: this should be per-instance rather than a global setting. + if(outputSimpChinese_) // convert output to simplified Chinese + wbuf = tradToSimpChinese(wbuf); + // commit the text, replace currently selected text with our commit string setCompositionString(session, wbuf.c_str(), wbuf.length()); @@ -481,6 +487,9 @@ bool TextService::onCommand(UINT id, CommandType type) { onConfigure(HWND_DESKTOP); } break; + case ID_OUTPUT_SIMP_CHINESE: // toggle output traditional or simplified Chinese + toggleSimplifiedChinese(); + break; case ID_ABOUT: // show about dialog if(!isImmersive()) { // only do this in desktop app mode // show about dialog @@ -584,6 +593,12 @@ void TextService::initChewingContext() { if(cfg.defaultFullSpace) ::chewing_set_ShapeMode(chewingContext_, FULLSHAPE_MODE); } + + outputSimpChinese_ = config().outputSimpChinese; + // update popup menu to check/uncheck the simplified Chinese item + DWORD checkFlags = outputSimpChinese_ ? MF_CHECKED : MF_UNCHECKED; + ::CheckMenuItem(popupMenu_, ID_OUTPUT_SIMP_CHINESE, MF_BYCOMMAND|checkFlags); + applyConfig(); } @@ -661,6 +676,14 @@ void TextService::toggleShapeMode() { } } +// toggle output traditional or simplified Chinese +void TextService::toggleSimplifiedChinese() { + outputSimpChinese_ = !outputSimpChinese_; + // update popup menu to check/uncheck the simplified Chinese item + DWORD checkFlags = outputSimpChinese_ ? MF_CHECKED : MF_UNCHECKED; + ::CheckMenuItem(popupMenu_, ID_OUTPUT_SIMP_CHINESE, MF_BYCOMMAND|checkFlags); +} + void TextService::updateCandidates(Ime::EditSession* session) { assert(candidateWindow_); candidateWindow_->clear(); diff --git a/ChewingTextService/ChewingTextService.h b/ChewingTextService/ChewingTextService.h index 49a8765b5..fb13bf8e9 100644 --- a/ChewingTextService/ChewingTextService.h +++ b/ChewingTextService/ChewingTextService.h @@ -100,6 +100,7 @@ class TextService: public Ime::TextService { void toggleLanguageMode(); // toggle between English and Chinese void toggleShapeMode(); // toggle between full shape and half shape + void toggleSimplifiedChinese(); // toggle output traditional or simplified Chinese private: ChewingContext* chewingContext_; @@ -114,6 +115,7 @@ class TextService: public Ime::TextService { Ime::LangBarButton* imeModeIcon_; // IME mode icon, a special language button (Windows 8 only) HMENU popupMenu_; + bool outputSimpChinese_; // output simplified Chinese int langMode_; int shapeMode_; UINT lastKeyDownCode_; diff --git a/ChewingTextService/ChewingTextService.rc b/ChewingTextService/ChewingTextService.rc index bb3ee00e8ffd396202357195a743e1e392f1963e..7ff5eb2e75106b566fb1942610e78b32a23ae761 100644 GIT binary patch delta 121 zcmX@)^UQa{F7e3?Vj`36q@yPD$=FOjApK;ro{ZGwC^5CoyTrYiMU@yV`hNu~)?AsT z>(`#Dz@WjP#t=ODpq%F93u0`V{tTfEAq)XvGM*ur!IQxk$ctxiX7B*A{TN( +#include std::wstring utf8ToUtf16(const char* text) { std::wstring wtext; @@ -41,3 +42,12 @@ std::string utf16ToUtf8(const wchar_t* wtext) { } return text; } + +std::wstring tradToSimpChinese(const std::wstring& trad) { + int len = ::LCMapStringW(0x0404, LCMAP_SIMPLIFIED_CHINESE, trad.c_str(), trad.length(), NULL, 0); + std::wstring simp; + simp.resize(len); + if(::LCMapStringW(0x0404, LCMAP_SIMPLIFIED_CHINESE, trad.c_str(), trad.length(), &simp[0], len)) + return simp; + return trad; +} diff --git a/libIME/Utils.h b/libIME/Utils.h index c055f5216..5171d3ead 100644 --- a/libIME/Utils.h +++ b/libIME/Utils.h @@ -27,4 +27,7 @@ std::wstring utf8ToUtf16(const char* text); std::string utf16ToUtf8(const wchar_t* wtext); +// convert traditional Chinese to simplified Chinese +std::wstring tradToSimpChinese(const std::wstring& trad); + #endif