From 02c04763c2acaa56f9f7852de60c305f367b2c10 Mon Sep 17 00:00:00 2001 From: KIHARA Hideto Date: Thu, 20 Oct 2016 19:22:28 +0900 Subject: [PATCH] =?UTF-8?q?=E6=B4=BB=E7=94=A8=E3=81=97=E3=81=AA=E3=81=84?= =?UTF-8?q?=E8=AA=9E=E3=82=92=E7=B8=AE=E3=82=81=E3=81=9F=E6=99=82=E3=81=AB?= =?UTF-8?q?=E6=B4=BB=E7=94=A8=E3=81=99=E3=82=8B=E8=AA=9E=E3=81=AB=E7=A7=BB?= =?UTF-8?q?=E8=A1=8C=E3=81=97=E3=81=AA=E3=81=84=E4=BA=A4=E3=81=9C=E6=9B=B8?= =?UTF-8?q?=E3=81=8D=E5=A4=89=E6=8F=9B=E9=96=8B=E5=A7=8B=E3=82=B7=E3=83=BC?= =?UTF-8?q?=E3=82=B1=E3=83=B3=E3=82=B9=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- imcrvtip/KeyHandlerControl.cpp | 22 ++- imcrvtip/KeyHandlerPostConv.cpp | 10 +- imcrvtip/PostMazeContext.cpp | 301 ++++++++++++++++---------------- imcrvtip/PostMazeContext.h | 4 +- imcrvtip/TextService.h | 2 +- 5 files changed, 180 insertions(+), 159 deletions(-) diff --git a/imcrvtip/KeyHandlerControl.cpp b/imcrvtip/KeyHandlerControl.cpp index 70e6bc75..9bf09546 100644 --- a/imcrvtip/KeyHandlerControl.cpp +++ b/imcrvtip/KeyHandlerControl.cpp @@ -1103,15 +1103,21 @@ void CTextService::_HandleFunc(TfEditCookie ec, ITfContext *pContext, const ROMA //後置型交ぜ書き変換 else if(wcsncmp(rkc.hiragana, L"Maze", 4) == 0) { - int offset = 4; - BOOL isKatuyo = FALSE; - if(rkc.hiragana[4] == L'K') - { - offset = 5; - isKatuyo = TRUE; - } if(postconvctx != PCC_COMPOSITION) { + int offset = 4; + bool isKatuyo = false; + bool resizeWithInflection = true; + if(rkc.hiragana[4] == L'K') + { + offset = 5; + isKatuyo = true; + } + else if(rkc.hiragana[4] == L'k') + { + offset = 5; + resizeWithInflection = false; + } //前置型交ぜ書き変換で入力中の読みの一部に対する後置型交ぜ書き変換 //は未対応。候補表示等の制御が面倒なので。 int count = _wtoi(rkc.hiragana + offset); @@ -1119,7 +1125,7 @@ void CTextService::_HandleFunc(TfEditCookie ec, ITfContext *pContext, const ROMA { count = 1; } - _HandlePostMaze(ec, pContext, count, postconvctx, isKatuyo); + _HandlePostMaze(ec, pContext, count, postconvctx, isKatuyo, resizeWithInflection); } else { diff --git a/imcrvtip/KeyHandlerPostConv.cpp b/imcrvtip/KeyHandlerPostConv.cpp index 3442d2ea..48636fb7 100644 --- a/imcrvtip/KeyHandlerPostConv.cpp +++ b/imcrvtip/KeyHandlerPostConv.cpp @@ -6,8 +6,12 @@ #include "mozc/win32/base/input_state.h" #include "moji.h" -//後置型交ぜ書き変換 -HRESULT CTextService::_HandlePostMaze(TfEditCookie ec, ITfContext *pContext, int count, PostConvContext postconvctx, BOOL isKatuyo) +/** + * 後置型交ぜ書き変換を開始する + * @param isKatuyo 活用する語として変換を開始するか + * @param resizeWithInflection 活用しない語を縮めた時に、活用する語としての変換を試みるか + */ +HRESULT CTextService::_HandlePostMaze(TfEditCookie ec, ITfContext *pContext, int count, PostConvContext postconvctx, bool isKatuyo, bool resizeWithInflection) { postmazeContext.Deactivate(); //カーソル直前の文字列を取得 @@ -28,7 +32,7 @@ HRESULT CTextService::_HandlePostMaze(TfEditCookie ec, ITfContext *pContext, int } std::wstring yomi(text); //count==0:文字数指定無しの場合は縮めながら変換 - postmazeContext.Activate(yomi, (isKatuyo == TRUE), (count == 0)); + postmazeContext.Activate(yomi, isKatuyo, (count == 0), resizeWithInflection); if(isKatuyo) { //TODO:読みに含まれる語尾を―に置き換えて変換 diff --git a/imcrvtip/PostMazeContext.cpp b/imcrvtip/PostMazeContext.cpp index 93f00418..8a56e324 100644 --- a/imcrvtip/PostMazeContext.cpp +++ b/imcrvtip/PostMazeContext.cpp @@ -6,7 +6,7 @@ const int MAX_SUFFIX = 4; //活用語尾の最大文字数 TODO:imtutcnfで設 CPostMazeContext::CPostMazeContext() { - Deactivate(); + Deactivate(); } CPostMazeContext::~CPostMazeContext() @@ -22,15 +22,17 @@ void CPostMazeContext::Deactivate() postyomist = 0; postyomied = 0; postyomiResizing = PYR_NO; + resizeWithInflection = false; } /** * 後置型交ぜ書き変換状態を有効化 * @param yomi 読み - * @param isKatuyo 活用する語として変換するか + * @param isKatuyo 活用する語として変換を開始するか * @param startResizing yomiが変換できなかった場合、縮めながらの変換を試みるか + * @param _resizeWithInflection 活用しない語を縮めた時に、活用する語としての変換を試みるか */ -void CPostMazeContext::Activate(const std::wstring yomi, bool isKatuyo, bool startResizing) +void CPostMazeContext::Activate(const std::wstring& yomi, bool isKatuyo, bool startResizing, bool _resizeWithInflection) { postyomi.assign(yomi); postyomist = 0; @@ -43,6 +45,7 @@ void CPostMazeContext::Activate(const std::wstring yomi, bool isKatuyo, bool sta { postyomiResizing = PYR_SHRINKING; } + resizeWithInflection = _resizeWithInflection; } /** @@ -50,7 +53,7 @@ void CPostMazeContext::Activate(const std::wstring yomi, bool isKatuyo, bool sta */ bool CPostMazeContext::IsActive() { - return !postyomi.empty(); + return !postyomi.empty(); } /** @@ -162,79 +165,82 @@ bool CPostMazeContext::Resize(std::wstring *yomi) */ bool CPostMazeContext::Shrink(std::wstring *yomi) { - yomi->clear(); - if(postyomist >= postyomied) - { - return false; - } - if(IsYomiInflection()) //活用する語 - { - //語幹の長さは保持したまま読みを縮める。対象読みを右にずらしたものに - //例: 「あおい」に対し、「あお」→「おい」 - size_t ed = ForwardMoji(postyomi, postyomied, 1); - if(ed > postyomied && ed < postyomi.size()) - { - //(postyomi末尾は'―'なのでed==postyomi.size()は不可) - size_t st = ForwardMoji(postyomi, postyomist, 1); - if(st > postyomist) - { - postyomist = st; - postyomied = ed; - yomi->assign(postyomi, st, ed - st); - yomi->append(L"―"); - postyomiResizing = PYR_SHRINKING; - return true; - } - } - size_t curlen = CountMoji(postyomi.substr(postyomist, postyomied - postyomist)); - //ずらせない場合、語幹を縮めて、postyomiの最初から試行 - //例: 「あおい」に対し、「おい」→「あ」 - if(curlen > 1) - { - size_t alllen = CountMoji(postyomi) - 1; //-1:'―' - size_t newlen = curlen - 1; - size_t st = 0; - //語尾が長くなりすぎて、余分な候補が表示されるのを回避 - if(alllen - newlen > MAX_SUFFIX) - { - size_t n = alllen - newlen - MAX_SUFFIX; - st = ForwardMoji(postyomi, st, n); - } - ed = ForwardMoji(postyomi, st, newlen); - if(ed > st && ed < postyomi.size()) - { - postyomist = st; - postyomied = ed; - yomi->assign(postyomi, st, ed - st); - yomi->append(L"―"); - postyomiResizing = PYR_SHRINKING; - return true; - } - } - } - else //活用しない語:読みを縮める。例:「あおい」に対して「おい」 - { - size_t st = ForwardMoji(postyomi, postyomist, 1); - if(st > postyomist && st < postyomied) - { - std::wstring s(postyomi.substr(st)); - if(s != L"―") //活用する語を示すマーカだけ? - { - postyomist = st; - yomi->assign(s); - postyomiResizing = PYR_SHRINKING; - return true; - } - } - //活用しない語として変換できなかったので、 - //活用する語として変換を試みる - postyomist = 0; - postyomi.append(L"―"); - yomi->assign(postyomi); - postyomiResizing = PYR_SHRINKING; - return true; - } - return false; + yomi->clear(); + if(postyomist >= postyomied) + { + return false; + } + if(IsYomiInflection()) //活用する語 + { + //語幹の長さは保持したまま読みを縮める。対象読みを右にずらしたものに + //例: 「あおい」に対し、「あお」→「おい」 + size_t ed = ForwardMoji(postyomi, postyomied, 1); + if(ed > postyomied && ed < postyomi.size()) + { + //(postyomi末尾は'―'なのでed==postyomi.size()は不可) + size_t st = ForwardMoji(postyomi, postyomist, 1); + if(st > postyomist) + { + postyomist = st; + postyomied = ed; + yomi->assign(postyomi, st, ed - st); + yomi->append(L"―"); + postyomiResizing = PYR_SHRINKING; + return true; + } + } + size_t curlen = CountMoji(postyomi.substr(postyomist, postyomied - postyomist)); + //ずらせない場合、語幹を縮めて、postyomiの最初から試行 + //例: 「あおい」に対し、「おい」→「あ」 + if(curlen > 1) + { + size_t alllen = CountMoji(postyomi) - 1; //-1:'―' + size_t newlen = curlen - 1; + size_t st = 0; + //語尾が長くなりすぎて、余分な候補が表示されるのを回避 + if(alllen - newlen > MAX_SUFFIX) + { + size_t n = alllen - newlen - MAX_SUFFIX; + st = ForwardMoji(postyomi, st, n); + } + ed = ForwardMoji(postyomi, st, newlen); + if(ed > st && ed < postyomi.size()) + { + postyomist = st; + postyomied = ed; + yomi->assign(postyomi, st, ed - st); + yomi->append(L"―"); + postyomiResizing = PYR_SHRINKING; + return true; + } + } + } + else //活用しない語:読みを縮める。例:「あおい」に対して「おい」 + { + size_t st = ForwardMoji(postyomi, postyomist, 1); + if(st > postyomist && st < postyomied) + { + std::wstring s(postyomi.substr(st)); + if(s != L"―") //活用する語を示すマーカだけ? + { + postyomist = st; + yomi->assign(s); + postyomiResizing = PYR_SHRINKING; + return true; + } + } + if(resizeWithInflection) + { + //活用しない語として変換できなかったので、 + //活用する語として変換を試みる + postyomist = 0; + postyomi.append(L"―"); + yomi->assign(postyomi); + postyomiResizing = PYR_SHRINKING; + return true; + } + } + return false; } /** @@ -244,74 +250,77 @@ bool CPostMazeContext::Shrink(std::wstring *yomi) */ bool CPostMazeContext::Extend(std::wstring *yomi) { - yomi->clear(); - if(IsYomiInflection()) //活用する語 - { - size_t suffixlen = CountMoji(postyomi.substr(postyomied)) - 1;//-1:'―' - //語尾を長くしすぎて、余分な候補が表示されるのを回避 - if(suffixlen < MAX_SUFFIX) - { - //語幹の長さは保持したまま読みを伸ばす。対象読みを左にずらしたものに - //例: 「あおい」に対し、「おい」→「あお」 - size_t st = BackwardMoji(postyomi, postyomist, 1); - if(st < postyomist) - { - size_t ed = BackwardMoji(postyomi, postyomied, 1); - if(ed < postyomied) - { - postyomist = st; - postyomied = ed; - yomi->assign(postyomi, st, ed - st); - yomi->append(L"―"); + yomi->clear(); + if(IsYomiInflection()) //活用する語 + { + size_t suffixlen = CountMoji(postyomi.substr(postyomied)) - 1;//-1:'―' + //語尾を長くしすぎて、余分な候補が表示されるのを回避 + if(suffixlen < MAX_SUFFIX) + { + //語幹の長さは保持したまま読みを伸ばす。対象読みを左にずらしたものに + //例: 「あおい」に対し、「おい」→「あお」 + size_t st = BackwardMoji(postyomi, postyomist, 1); + if(st < postyomist) + { + size_t ed = BackwardMoji(postyomi, postyomied, 1); + if(ed < postyomied) + { + postyomist = st; + postyomied = ed; + yomi->assign(postyomi, st, ed - st); + yomi->append(L"―"); postyomiResizing = PYR_EXTENDING; - return true; - } - } - } - size_t alllen = CountMoji(postyomi) - 1;//-1:'―' - size_t curlen = CountMoji(postyomi.substr(postyomist, postyomied - postyomist)); - //ずらせない場合、語幹を伸ばして、postyomiの末尾から試行 - //例: 「あおい」に対し、「あ」→「おい」 - if(curlen < alllen) - { - size_t ed = postyomi.size() - 1; //-1:'―' - size_t st = BackwardMoji(postyomi, ed, curlen + 1); - if(st < ed) - { - postyomist = st; - postyomied = ed; - yomi->assign(postyomi, st, ed - st); - yomi->append(L"―"); - postyomiResizing = PYR_EXTENDING; - return true; - } - } - //さらに伸ばす場合、活用しない語として変換を試みる - postyomi.erase(postyomi.size() - 1); - postyomied = postyomi.size(); - size_t st = BackwardMoji(postyomi, postyomied, 1); - if(st < postyomied) - { - postyomist = st; - yomi->assign(postyomi, st, postyomied - st); - postyomiResizing = PYR_EXTENDING; - return true; - } - } - else //活用しない語:読みを伸ばす。例:「あおい」に対して、「い」→「おい」 - { - if(postyomist == 0) - { - return false; - } - size_t st = BackwardMoji(postyomi, postyomist, 1); - if(st < postyomist) - { - postyomist = st; - yomi->assign(postyomi.substr(st)); - postyomiResizing = PYR_EXTENDING; - return true; - } - } - return false; + return true; + } + } + } + size_t alllen = CountMoji(postyomi) - 1;//-1:'―' + size_t curlen = CountMoji(postyomi.substr(postyomist, postyomied - postyomist)); + //ずらせない場合、語幹を伸ばして、postyomiの末尾から試行 + //例: 「あおい」に対し、「あ」→「おい」 + if(curlen < alllen) + { + size_t ed = postyomi.size() - 1; //-1:'―' + size_t st = BackwardMoji(postyomi, ed, curlen + 1); + if(st < ed) + { + postyomist = st; + postyomied = ed; + yomi->assign(postyomi, st, ed - st); + yomi->append(L"―"); + postyomiResizing = PYR_EXTENDING; + return true; + } + } + if(resizeWithInflection) + { + //さらに伸ばす場合、活用しない語として変換を試みる + postyomi.erase(postyomi.size() - 1); + postyomied = postyomi.size(); + size_t st = BackwardMoji(postyomi, postyomied, 1); + if(st < postyomied) + { + postyomist = st; + yomi->assign(postyomi, st, postyomied - st); + postyomiResizing = PYR_EXTENDING; + return true; + } + } + } + else //活用しない語:読みを伸ばす。例:「あおい」に対して、「い」→「おい」 + { + if(postyomist == 0) + { + return false; + } + size_t st = BackwardMoji(postyomi, postyomist, 1); + if(st < postyomist) + { + postyomist = st; + yomi->assign(postyomi.substr(st)); + postyomiResizing = PYR_EXTENDING; + return true; + } + } + return false; } diff --git a/imcrvtip/PostMazeContext.h b/imcrvtip/PostMazeContext.h index 9489ab17..3d631b82 100644 --- a/imcrvtip/PostMazeContext.h +++ b/imcrvtip/PostMazeContext.h @@ -12,7 +12,7 @@ class CPostMazeContext //XXX:コピー代入演算子は自動生成されるものでOK //CPostMazeContext& operator=(const CPostMazeContext& from); - void Activate(const std::wstring yomi, bool isKatuyo, bool startResizing); + void Activate(const std::wstring& yomi, bool isKatuyo, bool startResizing, bool resizeWithInflection); void Deactivate(); bool IsActive(); void EndResizing(); @@ -37,4 +37,6 @@ class CPostMazeContext PYR_EXTENDING, }; PostYomiResizing postyomiResizing; //読みを縮め/伸ばしながらの変換試行中かどうか + /** 活用しない語を縮めた時に、活用する語としての変換を試みる(逆も) */ + bool resizeWithInflection; }; diff --git a/imcrvtip/TextService.h b/imcrvtip/TextService.h index 018bc49c..bb316e64 100644 --- a/imcrvtip/TextService.h +++ b/imcrvtip/TextService.h @@ -195,7 +195,7 @@ class CTextService : BOOL _SearchRomanByKana(const ROMAN_KANA_NODE &tree, int srcmode, const WCHAR *src, std::wstring &dst); // KeyHandlerPostConv - HRESULT _HandlePostMaze(TfEditCookie ec, ITfContext *pContext, int count, PostConvContext postconvctx, BOOL isKatuyo); + HRESULT _HandlePostMaze(TfEditCookie ec, ITfContext *pContext, int count, PostConvContext postconvctx, bool isKatuyo, bool resizeWithInflection); void _AcquirePrecedingYomi(ITfContext *pContext, PostConvContext postconvctx, std::wstring *yomi, size_t count); HRESULT _HandlePostKata(TfEditCookie ec, ITfContext *pContext, int count, PostConvContext postconvctx); HRESULT _HandlePostKataShrink(TfEditCookie ec, ITfContext *pContext, int count, PostConvContext postconvctx);