Skip to content

Commit

Permalink
Merge pull request #11 from deton/mazeadjust
Browse files Browse the repository at this point in the history
後置型交ぜ書き変換を、読みの文字数指定無しでも開始可能に
  • Loading branch information
deton authored Oct 24, 2016
2 parents 2373d54 + fd39823 commit 9381f07
Show file tree
Hide file tree
Showing 24 changed files with 668 additions and 40 deletions.
29 changes: 24 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

# tsf-tutcode ver. 0.5.0
# tsf-tutcode ver. 0.6.0

Windowsで動作する漢字直接入力用のIMEです。

Expand Down Expand Up @@ -127,6 +127,16 @@ IMR_DOCUMENTFEEDにも対応していないアプリの場合は、tsf-tutcode
例) 「あお」の後ろでn2(MazeK2機能。「あお―」で検索)→「▼仰」
参考)「あお」の後ろでm2(Maze2機能)→「▼青」

### 後置型交ぜ書き変換における、読み/語幹の伸縮
後置型交ぜ書き変換候補表示中は、`<``>`キーにより、読み/語幹(活用語尾以外の部分)の伸縮が可能です(ただし、読み文字数を指定した場合、伸ばせるのは指定した文字数まで)。

活用する語に関しては、語幹が長いものを優先して変換します。
(なお、不要な候補が表示されないように、活用する語の語尾は最大4文字までとしています)

例)「あおい」`>`「おい」`>`「い」
さらに縮めると活用する語として変換
`>`「あおい―」`>`「あお―」`>`「おい―」`>`「あ―」`>`「お―」`>`「い―」`

### 後置型カタカナ変換
#### 指定した文字数をカタカナに置換
例)「あぷり」の後ろでk3(Kata3機能に割り当てたシーケンス)→「アプリ」
Expand Down Expand Up @@ -541,14 +551,18 @@ Visual C++ 2015 の 正規表現で、文法は ECMAScript を使用していま
| Help2 | カーソル直前の2文字の打鍵ヘルプ表示 |
| ... | |
| Help9 | カーソル直前の9文字の打鍵ヘルプ表示 |
| Maze0 | 後置型交ぜ書き変換開始。最長一致 |
| Maze1 | 後置型交ぜ書き変換開始。読み1文字 |
| Maze2 | 後置型交ぜ書き変換開始。読み2文字 |
| ... | |
| Maze9 | 後置型交ぜ書き変換開始。読み9文字 |
| MazeK0 | 後置型交ぜ書き変換開始(活用する語。読みに―を追加)。最長一致 |
| MazeK1 | 後置型交ぜ書き変換開始(活用する語。読みに―を追加)。読み1文字 |
| MazeK2 | 後置型交ぜ書き変換開始(活用する語。読みに―を追加)。読み2文字 |
| ... | |
| MazeK9 | 後置型交ぜ書き変換開始(活用する語。読みに―を追加)。読み9文字 |
| Mazek0 | 後置型交ぜ書き変換開始(読みを縮めた際に活用する語としての変換は試みない)。最長一致 |
| Mazek1 | 後置型交ぜ書き変換開始(読みを縮めた際に活用する語としての変換は試みない)。読み1文字 |
| ... | |
| Mazek9 | 後置型交ぜ書き変換開始(読みを縮めた際に活用する語としての変換は試みない)。読み9文字 |
| Kata0 | 後置型カタカナ変換。連続するひらがなをカタカナに置換 |
| Kata1 | 後置型カタカナ変換。1文字をカタカナに置換 |
| Kata2 | 後置型カタカナ変換。2文字をカタカナに置換 |
Expand Down Expand Up @@ -830,8 +844,7 @@ ASCII, JIS X 0201, JIS X 0213に変換できない文字が含まれていた場

以上の状況があてはまらない場合は、漢直Winを選ぶ方が良いです。
tsf-tutcodeは未実装機能が多いため。
(ヘルプ表示、前置型部首合成、熟語ヘルプ、ヒストリ入力、
活用する語の交ぜ書き変換、交ぜ書き変換での語幹の伸縮、強制練習モード等)
(ヘルプ表示、前置型部首合成、熟語ヘルプ、ヒストリ入力、強制練習モード等)

### ソースに関して

Expand Down Expand Up @@ -886,6 +899,12 @@ pandoc 1.17.2

### 履歴

#### v0.6.0 (2016-10-24)
* 後置型交ぜ書き変換を、読みの文字数指定無しでも開始可能に:`Maze0`,`MazeK0`
+ 候補表示中に`>``<`キーにより、読み/語幹の伸縮可能
+ 活用しない語を縮めていくと、活用する語としての変換を試行
+ 活用しない語を縮めていった際に、活用する語としての変換を試行しない「機能」追加:`Mazek0`

#### v0.5.0 (2016-09-12)
* 仮想鍵盤表示機能を追加。
* ベースのCorvusSKKを2.4.5に更新。
Expand Down
6 changes: 3 additions & 3 deletions common/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
#define TEXTSERVICE_DESC TEXTSERVICE_NAME L"_DEBUG"
#endif
#define TEXTSERVICE_DIR L"IMTSFTUTCODE"
#define TEXTSERVICE_VER L"0.5.0"
#define TEXTSERVICE_VER L"0.6.0"

//for resource
#define RC_AUTHOR "KIHARA Hideto"
#define RC_PRODUCT "tsf-tutcode"
#define RC_VERSION "0.5.0"
#define RC_VERSION_D 0,5,0,0
#define RC_VERSION "0.6.0"
#define RC_VERSION_D 0,6,0,0

#endif
2 changes: 2 additions & 0 deletions imcrvcnf/convtable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const ROMAN_KANA_CONV roman_kana_conv_default[ROMAN_KANA_TBL_DEF_NUM] =
{L"alj", L"maze", L"maze", L"maze", FALSE, FALSE, TRUE},
{L"ald", L"Bushu", L"Bushu", L"Bushu", FALSE, FALSE, TRUE},
{L"al?", L"Help4", L"Help4", L"Help4", FALSE, FALSE, TRUE},
{L"m0", L"Maze0", L"Maze0", L"Maze0", FALSE, FALSE, TRUE},
{L"m1", L"Maze1", L"Maze1", L"Maze1", FALSE, FALSE, TRUE},
{L"m2", L"Maze2", L"Maze2", L"Maze2", FALSE, FALSE, TRUE},
{L"m3", L"Maze3", L"Maze3", L"Maze3", FALSE, FALSE, TRUE},
Expand All @@ -19,6 +20,7 @@ const ROMAN_KANA_CONV roman_kana_conv_default[ROMAN_KANA_TBL_DEF_NUM] =
{L"m7", L"Maze7", L"Maze7", L"Maze7", FALSE, FALSE, TRUE},
{L"m8", L"Maze8", L"Maze8", L"Maze8", FALSE, FALSE, TRUE},
{L"m9", L"Maze9", L"Maze9", L"Maze9", FALSE, FALSE, TRUE},
{L"n0", L"MazeK0", L"MazeK0", L"MazeK0", FALSE, FALSE, TRUE},
{L"n1", L"MazeK1", L"MazeK1", L"MazeK1", FALSE, FALSE, TRUE},
{L"n2", L"MazeK2", L"MazeK2", L"MazeK2", FALSE, FALSE, TRUE},
{L"n3", L"MazeK3", L"MazeK3", L"MazeK3", FALSE, FALSE, TRUE},
Expand Down
2 changes: 1 addition & 1 deletion imcrvcnf/convtable.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#include "convtype.h"

#define ROMAN_KANA_TBL_DEF_NUM 3133
#define ROMAN_KANA_TBL_DEF_NUM 3135

//変換テーブル
extern const ROMAN_KANA_CONV roman_kana_conv_default[ROMAN_KANA_TBL_DEF_NUM];
Expand Down
9 changes: 9 additions & 0 deletions imcrvtip/CandidateList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,15 @@ void CCandidateList::_SetText(const std::wstring &text, BOOL fixed, int mode)
}
}

//辞書登録時後置型交ぜ書き変換で読みから外した部分をセット。表示用
void CCandidateList::_SetTextExcludedPostyomi(const std::wstring &text)
{
if(_pCandidateWindow != nullptr)
{
_pCandidateWindow->_SetTextExcludedPostyomi(text);
}
}

void CCandidateList::_GetPrecedingText(std::wstring *text)
{
if(_pCandidateWindow != NULL)
Expand Down
2 changes: 2 additions & 0 deletions imcrvtip/CandidateList.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ class CCandidateList :
void _InvokeSfHandler(BYTE sf);
void _Show(BOOL bShow);
void _SetText(const std::wstring &text, BOOL fixed, int mode);
//辞書登録時後置型交ぜ書き変換で読みから外した部分をセット。表示用
void _SetTextExcludedPostyomi(const std::wstring &text);
void _GetPrecedingText(std::wstring *text);
void _DeletePrecedingText(size_t delete_count);
void _Move(LPRECT lpr, TfEditCookie ec = TF_INVALID_EDIT_COOKIE, ITfContext *pContext = nullptr);
Expand Down
1 change: 1 addition & 0 deletions imcrvtip/CandidatePaint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ std::wstring CCandidateWindow::_MakeRegWordString()

s.append(_regtext.substr(0, _regtextpos));

s.append(_regexcpostyomi);
s.append(_regcomp + markCursor);

s.append(_regtext.substr(_regtextpos) + markNBSP);
Expand Down
21 changes: 18 additions & 3 deletions imcrvtip/CandidateWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,7 @@ void CCandidateWindow::_SetText(const std::wstring &text, BOOL fixed, int mode)
if(fixed)
{
_regcomp.clear();
_regexcpostyomi.clear();
_regtext.insert(_regtextpos, text);
_regtextpos += text.size();
}
Expand All @@ -421,16 +422,26 @@ void CCandidateWindow::_SetText(const std::wstring &text, BOOL fixed, int mode)
_Update();
}

//辞書登録時後置型交ぜ書き変換で読みから外した部分をセット。表示用
void CCandidateWindow::_SetTextExcludedPostyomi(const std::wstring &text)
{
if(_pCandidateWindow != nullptr && !_preEnd)
{
_pCandidateWindow->_SetTextExcludedPostyomi(text);
return;
}

_regexcpostyomi.assign(text);
}

void CCandidateWindow::_GetPrecedingText(std::wstring *text)
{
if(_pCandidateWindow != NULL && !_preEnd)
{
_pCandidateWindow->_GetPrecedingText(text);
return;
}

text->clear();
text->append(_regtext.substr(0, _regtextpos));
text->assign(_regtext, 0, _regtextpos);
}

void CCandidateWindow::_DeletePrecedingText(size_t delete_count)
Expand Down Expand Up @@ -837,6 +848,7 @@ void CCandidateWindow::_BackUpStatus()
candidates_bak = _pTextService->candidates;
candidx_bak = _pTextService->candidx;
candorgcnt_bak = _pTextService->candorgcnt;
postmazeContext_bak = _pTextService->postmazeContext;
}

void CCandidateWindow::_ClearStatus()
Expand All @@ -851,6 +863,7 @@ void CCandidateWindow::_ClearStatus()
_pTextService->candidates.clear();
_pTextService->candidx = 0;
_pTextService->candorgcnt = 0;
_pTextService->postmazeContext.Deactivate();
_pTextService->showcandlist = FALSE;
_pTextService->showentry = FALSE;
_pTextService->inputkey = FALSE;
Expand All @@ -869,6 +882,7 @@ void CCandidateWindow::_RestoreStatusReg()
_pTextService->candidates = candidates_bak;
_pTextService->candidx = candidx_bak;
_pTextService->candorgcnt = candorgcnt_bak;
_pTextService->postmazeContext = postmazeContext_bak;
_pTextService->showcandlist = TRUE;
_pTextService->showentry = TRUE;
_pTextService->inputkey = TRUE;
Expand All @@ -886,6 +900,7 @@ void CCandidateWindow::_ClearStatusReg()
candidates_bak.clear();
candidx_bak = 0;
candorgcnt_bak = 0;
postmazeContext_bak.Deactivate();
}

void CCandidateWindow::_PreEndReq()
Expand Down
4 changes: 4 additions & 0 deletions imcrvtip/CandidateWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ class CCandidateWindow : public ITfCandidateListUIElementBehavior
BOOL _CanShowUIElement();
void _Redraw();
void _SetText(const std::wstring &text, BOOL fixed, int mode);
//辞書登録時後置型交ぜ書き変換で読みから外した部分をセット。表示用
void _SetTextExcludedPostyomi(const std::wstring &text);
void _GetPrecedingText(std::wstring *text);
void _DeletePrecedingText(size_t delete_count);
void _PreEnd();
Expand Down Expand Up @@ -141,6 +143,7 @@ class CCandidateWindow : public ITfCandidateListUIElementBehavior
std::wstring _regtext; //確定文字列
size_t _regtextpos; //カーソルインデックス
std::wstring _regcomp; //未確定文字列
std::wstring _regexcpostyomi; //後置型交ぜ書き変換で読みから外した部分

CANDIDATES candidates; //描画用候補
size_t candidx; //描画用候補インデックス
Expand All @@ -159,6 +162,7 @@ class CCandidateWindow : public ITfCandidateListUIElementBehavior
CANDIDATES candidates_bak;
size_t candidx_bak;
size_t candorgcnt_bak;
CPostMazeContext postmazeContext_bak;
};

#endif //CANDIDATEWINDOW_H
24 changes: 24 additions & 0 deletions imcrvtip/KeyHandlerChar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "imcrvtip.h"
#include "TextService.h"
#include "CandidateList.h"
#include "moji.h"

HRESULT CTextService::_HandleChar(TfEditCookie ec, ITfContext *pContext, WPARAM wParam, WCHAR ch, WCHAR chO)
{
Expand All @@ -11,6 +12,29 @@ HRESULT CTextService::_HandleChar(TfEditCookie ec, ITfContext *pContext, WPARAM

if(showentry)
{
//後置型交ぜ書き変換の候補表示時
if(postmazeContext.IsActive())
{
if(ch == L'>') //読みを縮める操作が行われた
{
std::wstring yomi;
if(postmazeContext.Shrink(&yomi))
{
_StartConvWithYomi(ec, pContext, yomi);
}
return S_OK;
}
else if(ch == L'<') //読みを伸ばす操作が行われた
{
std::wstring yomi;
if(postmazeContext.Extend(&yomi))
{
_StartConvWithYomi(ec, pContext, yomi);
}
return S_OK;
}
}

_HandleCharShift(ec, pContext);
}

Expand Down
46 changes: 44 additions & 2 deletions imcrvtip/KeyHandlerComposition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "imcrvtip.h"
#include "TextService.h"
#include "CandidateList.h"
#include "moji.h"

HRESULT CTextService::_Update(TfEditCookie ec, ITfContext *pContext, BOOL fixed, BOOL back)
{
Expand Down Expand Up @@ -45,6 +46,13 @@ HRESULT CTextService::_Update(TfEditCookie ec, ITfContext *pContext, std::wstrin
comptext.append(kana.substr(okuriidx + 1));
useraddmode = REQ_USER_ADD_0;
}
//活用する語の語尾
std::wstring gobi;
if(postmazeContext.GetGobi(&gobi))
{
cchOkuri = (LONG)comptext.size();
comptext.append(gobi);
}

cchCursor = (LONG)comptext.size();

Expand Down Expand Up @@ -115,6 +123,14 @@ HRESULT CTextService::_Update(TfEditCookie ec, ITfContext *pContext, std::wstrin

cchCursor = (LONG)comptext.size();

//読みを縮め/伸ばしながらの後置型交ぜ書き変換。変換可能な候補無し時
std::wstring yomi;
if(postmazeContext.Resize(&yomi))
{
_StartConvWithYomi(ec, pContext, yomi);
return S_OK;
}

if(pContext == nullptr && _pCandidateList != nullptr) //辞書登録用
{
_pCandidateList->_SetText(comptext, FALSE, wm_register);
Expand Down Expand Up @@ -296,6 +312,7 @@ HRESULT CTextService::_Update(TfEditCookie ec, ITfContext *pContext, std::wstrin
}

_EndInputModeWindow();
postmazeContext.EndResizing();

if(inputkey && !fixed && !showcandlist && showentry &&
(((cx_untilcandlist != 1) && (candidx + 1 == cx_untilcandlist)) || (cx_untilcandlist == 1)) &&
Expand All @@ -320,6 +337,17 @@ HRESULT CTextService::_Update(TfEditCookie ec, ITfContext *pContext, std::wstrin

if(pContext == nullptr && _pCandidateList != nullptr) //辞書登録用
{
//文字数指定無し後置型交ぜ書き変換で読みを縮め/伸ばした場合
std::wstring excluded;
if(postmazeContext.GetExcluded(&excluded) && fixed)
{
//読みから外した部分は確定(fixed=TRUEで_SetText())
_pCandidateList->_SetText(excluded, TRUE, wm_none);
postmazeContext.EraseExcluded();
excluded.clear();
}
//読み伸ばし/縮め途中で、読みから外した部分は表示用の値を更新する
_pCandidateList->_SetTextExcludedPostyomi(excluded);
_pCandidateList->_SetText(comptext, fixed, wm_none);
return S_OK;
}
Expand All @@ -329,15 +357,15 @@ HRESULT CTextService::_Update(TfEditCookie ec, ITfContext *pContext, std::wstrin
}
}

HRESULT CTextService::_SetText(TfEditCookie ec, ITfContext *pContext, const std::wstring &text, LONG cchCursor, LONG cchOkuri, BOOL fixed)
HRESULT CTextService::_SetText(TfEditCookie ec, ITfContext *pContext, const std::wstring &comptext, LONG cchCursor, LONG cchOkuri, BOOL fixed)
{
TF_SELECTION tfSelection;
ULONG cFetched = 0;
LONG cch, cchRes;

if(pContext == nullptr && _pCandidateList != nullptr) //辞書登録用
{
_pCandidateList->_SetText(text, fixed, wm_none);
_pCandidateList->_SetText(comptext, fixed, wm_none);
return S_OK;
}

Expand All @@ -349,6 +377,20 @@ HRESULT CTextService::_SetText(TfEditCookie ec, ITfContext *pContext, const std:
}
}

std::wstring text(comptext);
//文字数指定無し後置型交ぜ書き変換で読みを縮め/伸ばした場合
std::wstring excluded;
if(postmazeContext.GetExcluded(&excluded))
{ //外した部分が表示されるように、textに挿入
text.insert(0, excluded);
cchCursor += (LONG)excluded.size();
//確定時の後始末(しないと以降の入力で常にpostyomiが付いてしまう)
if(fixed)
{
postmazeContext.Deactivate();
}
}

if(pContext->GetSelection(ec, TF_DEFAULT_SELECTION, 1, &tfSelection, &cFetched) != S_OK)
{
return S_FALSE;
Expand Down
Loading

0 comments on commit 9381f07

Please sign in to comment.