Skip to content

Commit

Permalink
Add backward match complement option
Browse files Browse the repository at this point in the history
  • Loading branch information
nathancorvussolis committed Jul 8, 2016
1 parent c2309d3 commit ce113f5
Show file tree
Hide file tree
Showing 21 changed files with 128 additions and 48 deletions.
10 changes: 0 additions & 10 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -244,16 +244,6 @@ ModelManifest.xml
# FAKE - F# Make
.fake/



# WiX Toolset files
*.msi
*.wixobj
*.wixpdb

# Archive files
*.zip

# Backup files
*.BAK
*.bak
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,14 @@ IME ON/OFF のキーのみ、IME ON → OFF のときにも反映されます。
| config.xml | 各種設定 |
| skkdict.txt | 取込済SKK辞書 |

各種設定の config.xml ファイルは、UTF-8 の XML フォーマットのテキストファイルとなっており、テキストエディタで編集可能です。変更した後は、IME OFF → ON で新しい設定が反映されます。
各種設定の config.xml ファイルは、UTF-8 の XML フォーマットのテキストファイルとなっています。

設定ダイアログで OK ボタンまたは適用ボタンを押すと config.xml ファイルが保存されます。テキストエディタなどでも編集可能です。変更した後は、IME OFF → ON で新しい設定が反映されます。

取込済SKK辞書の skkdict.txt ファイルは、UTF-16 (LE, BOMあり) のSKK辞書フォーマットとなっています。

設定ダイアログのリストにSKK辞書を追加して取込ボタンを押すと取込済SKK辞書に変換されます。後述の[SKK辞書](#skk辞書)の項を参照してください。

SKK辞書サーバーを使用するなどでローカルのSKK辞書を使用したくないときは、設定ダイアログのSKK辞書のリストが空またはチェック無しの状態で取込処理をおこなってください。空の取込済SKK辞書が生成されます。

下記のディレクトリの優先順位で各ファイルが読み込まれます。
Expand Down Expand Up @@ -216,6 +220,7 @@ SKK辞書のダウンロード機能では HTTP, HTTPS が使用可能です。
| 動的補完を使用する | 見出し語が入力されたとき、ユーザー辞書から補完された見出し語を表示します。<br>「▽表示属性」の「\*送り」の色が使用されます。 |
| 複数動的補完を使用する | 見出し語が入力されたとき、ユーザー辞書から補完された見出し語を一覧で表示します。<br>補完対象は「候補一覧の色」の「選択」、補完部分は「候補」の色が使用されます。 |
| 補完された見出し語の候補を表示する | 補完/複数補完/動的補完/複数動的補完のとき、ユーザー辞書の検索結果を追加して表示します。<br>表示する候補の数は最大で「候補一覧表示に要する変換回数」-1 です。<br>補完/動的補完では「▽表示属性」の「\*送り」の色が使用されます。<br>複数補完/複数動的補完では「候補一覧の色」の「注釈」の色が使用されます。 |
| 前方一致と後方一致で補完する | 通常の前方一致での補完に加えて後方一致でも補完します。 |


###表示
Expand Down
1 change: 1 addition & 0 deletions common/configxml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ LPCWSTR ValueStaCompMulti = L"stacompmulti";
LPCWSTR ValueDynamicComp = L"dynamiccomp";
LPCWSTR ValueDynCompMulti = L"dyncompmulti";
LPCWSTR ValueCompUserDic = L"compuserdic";
LPCWSTR ValueCompIncBack = L"compincback";

//font section

Expand Down
1 change: 1 addition & 0 deletions common/configxml.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ extern LPCWSTR ValueStaCompMulti;
extern LPCWSTR ValueDynamicComp;
extern LPCWSTR ValueDynCompMulti;
extern LPCWSTR ValueCompUserDic;
extern LPCWSTR ValueCompIncBack;

//font section

Expand Down
3 changes: 3 additions & 0 deletions imcrvcnf/DlgProcBehavior2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ INT_PTR CALLBACK DlgProcBehavior2(HWND hDlg, UINT message, WPARAM wParam, LPARAM
LoadCheckButton(hDlg, IDC_CHECKBOX_DYNAMINCOMP, SectionBehavior, ValueDynamicComp);
LoadCheckButton(hDlg, IDC_CHECKBOX_DYNCOMPMULTI, SectionBehavior, ValueDynCompMulti);
LoadCheckButton(hDlg, IDC_CHECKBOX_COMPUSERDIC, SectionBehavior, ValueCompUserDic);
LoadCheckButton(hDlg, IDC_CHECKBOX_COMPINCBACK, SectionBehavior, ValueCompIncBack);

return TRUE;

Expand All @@ -53,6 +54,7 @@ INT_PTR CALLBACK DlgProcBehavior2(HWND hDlg, UINT message, WPARAM wParam, LPARAM
case IDC_CHECKBOX_DYNAMINCOMP:
case IDC_CHECKBOX_DYNCOMPMULTI:
case IDC_CHECKBOX_COMPUSERDIC:
case IDC_CHECKBOX_COMPINCBACK:

PropSheet_Changed(GetParent(hDlg), hDlg);

Expand All @@ -78,6 +80,7 @@ INT_PTR CALLBACK DlgProcBehavior2(HWND hDlg, UINT message, WPARAM wParam, LPARAM
SaveCheckButton(hDlg, IDC_CHECKBOX_DYNAMINCOMP, ValueDynamicComp);
SaveCheckButton(hDlg, IDC_CHECKBOX_DYNCOMPMULTI, ValueDynCompMulti);
SaveCheckButton(hDlg, IDC_CHECKBOX_COMPUSERDIC, ValueCompUserDic);
SaveCheckButton(hDlg, IDC_CHECKBOX_COMPINCBACK, ValueCompIncBack);

WriterEndSection(pXmlWriter); //End of SectionBehavior

Expand Down
1 change: 1 addition & 0 deletions imcrvcnf/imcrvcnf.rc
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ FONT 10, "MS Gothic"
AUTOCHECKBOX "動的補完を使用する", IDC_CHECKBOX_DYNAMINCOMP, 24, 50, 220, 8
AUTOCHECKBOX "複数動的補完を使用する", IDC_CHECKBOX_DYNCOMPMULTI, 24, 65, 220, 8
AUTOCHECKBOX "補完された見出し語の候補を表示する", IDC_CHECKBOX_COMPUSERDIC, 24, 80, 220, 8
AUTOCHECKBOX "前方一致と後方一致で補完する", IDC_CHECKBOX_COMPINCBACK, 24, 95, 220, 8
}

IDD_DIALOG_DISPLAY DIALOG 0, 0, 268, 244
Expand Down
1 change: 1 addition & 0 deletions imcrvcnf/resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
#define IDC_CHECKBOX_DYNAMINCOMP 1303
#define IDC_CHECKBOX_DYNCOMPMULTI 1304
#define IDC_CHECKBOX_COMPUSERDIC 1305
#define IDC_CHECKBOX_COMPINCBACK 1306

#define IDC_EDIT_FONTNAME 2001
#define IDC_EDIT_FONTPOINT 2002
Expand Down
8 changes: 8 additions & 0 deletions imcrvmgr/ConfigMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ DWORD encoding = 0; //エンコーディング
DWORD timeout = 1000; //タイムアウト

BOOL precedeokuri = FALSE; //送り仮名が一致した候補を優先する
BOOL compincback = FALSE; //前方一致と後方一致で補完する

const luaL_Reg luaFuncs[] =
{
Expand Down Expand Up @@ -237,6 +238,13 @@ void LoadConfig()
{
precedeokuri = FALSE;
}

ReadValue(pathconfigxml, SectionBehavior, ValueCompIncBack, strxmlval);
compincback = _wtoi(strxmlval.c_str());
if(compincback != TRUE && compincback != FALSE)
{
compincback = FALSE;
}
}

BOOL IsFileModified(LPCWSTR path, FILETIME *ft)
Expand Down
19 changes: 15 additions & 4 deletions imcrvmgr/SearchUserDictionary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,22 @@ void SearchComplement(const std::wstring &searchkey, SKKDICCANDIDATES &sc)
break;
}

if(keyorder_ritr->compare(0, searchkey.size(), searchkey) == 0 &&
searchkey.size() < keyorder_ritr->size())
if(searchkey.size() < keyorder_ritr->size())
{
sc.push_back(SKKDICCANDIDATE(*keyorder_ritr, L""));
++count;
if(keyorder_ritr->compare(0, searchkey.size(), searchkey) == 0)
{
//前方一致
sc.push_back(SKKDICCANDIDATE(*keyorder_ritr, L""));
++count;
}
else if(compincback &&
keyorder_ritr->compare((keyorder_ritr->size() - searchkey.size()),
searchkey.size(), searchkey) == 0)
{
//後方一致
sc.push_back(SKKDICCANDIDATE(*keyorder_ritr, L""));
++count;
}
}
}
}
Expand Down
1 change: 1 addition & 0 deletions imcrvmgr/imcrvmgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,5 +117,6 @@ extern DWORD encoding; //エンコーディング
extern DWORD timeout; //タイムアウト

extern BOOL precedeokuri; //送り仮名が一致した候補を優先する
extern BOOL compincback; //前方一致と後方一致で補完する

#endif //IMCRVMGR_H
86 changes: 59 additions & 27 deletions imcrvtip/CandidatePaint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
#define MERGIN_X 2
#define MERGIN_Y 4

const int colors_compback[DISPLAY_COLOR_NUM] =
{
CL_COLOR_BG, CL_COLOR_FR, CL_COLOR_CA, CL_COLOR_CO,
CL_COLOR_SE, CL_COLOR_SC, CL_COLOR_AN, CL_COLOR_NO
};

void CCandidateWindow::_WindowProcPaint(HWND hWnd)
{
PAINTSTRUCT ps;
Expand All @@ -18,7 +24,7 @@ void CCandidateWindow::_WindowProcPaint(HWND hWnd)
HGDIOBJ bmp = nullptr, font = nullptr, pen, brush;
RECT r, rc;
POINT pt;
int cx, cy, cycle;
int cx, cy;
UINT page, count, i;
std::wstring s;
WCHAR strPage[32];
Expand Down Expand Up @@ -97,7 +103,7 @@ void CCandidateWindow::_WindowProcPaint(HWND hWnd)
for(i = 0; i < _CandCount[page]; i++)
{
s.clear();
for(cycle = CL_COLOR_BG; cycle < DISPLAY_COLOR_NUM; cycle++)
for(int cycle = 0; cycle < DISPLAY_COLOR_NUM; cycle++)
{
s += _MakeCandidateString(page, count, i, cycle);
}
Expand Down Expand Up @@ -284,8 +290,17 @@ void CCandidateWindow::_PaintRegWord(HDC hdc, LPRECT lpr)
std::wstring CCandidateWindow::_MakeCandidateString(UINT page, UINT count, UINT idx, int cycle)
{
std::wstring s;
std::wstring ca = candidates[count + _uShowedCount + idx].first.first;
std::wstring an = candidates[count + _uShowedCount + idx].first.second;

int color_cycle = cycle;
if(_comp && ca.compare(0, searchkey.size(), searchkey) != 0)
{
//補完かつ後方一致
color_cycle = colors_compback[cycle];
}

switch(cycle)
switch(color_cycle)
{
case CL_COLOR_BG:
s.append(markNBSP);
Expand Down Expand Up @@ -315,30 +330,40 @@ std::wstring CCandidateWindow::_MakeCandidateString(UINT page, UINT count, UINT
case CL_COLOR_CA:
if(!_comp)
{
s.append(
std::regex_replace(candidates[ count + _uShowedCount + idx ].first.first,
s.append(std::regex_replace(ca,
std::wregex(markSP), std::wstring(markNBSP)));
}
else
{
s.append(
std::regex_replace(candidates[ count + _uShowedCount + idx ].first.first.substr(searchkey.size()),
std::wregex(markSP), std::wstring(markNBSP)));
if(searchkey.size() < ca.size())
{
if(ca.compare(0, searchkey.size(), searchkey) == 0)
{
//前方一致
s.append(std::regex_replace(ca.substr(searchkey.size()),
std::wregex(markSP), std::wstring(markNBSP)));
}
else
{
//後方一致
s.append(std::regex_replace(ca.substr(0, ca.size() - searchkey.size()),
std::wregex(markSP), std::wstring(markNBSP)));
}
}
}
break;

case CL_COLOR_SC:
if(!_comp)
{
if(_pTextService->cx_annotation &&
!candidates[count + _uShowedCount + idx].first.second.empty())
if(_pTextService->cx_annotation && !an.empty())
{
s.append(markAnnotation);
}
}
else
{
if(!candidates[count + _uShowedCount + idx].first.second.empty())
if(!an.empty())
{
s.append(markNBSP);
}
Expand All @@ -348,20 +373,17 @@ std::wstring CCandidateWindow::_MakeCandidateString(UINT page, UINT count, UINT
case CL_COLOR_AN:
if(!_comp)
{
if(_pTextService->cx_annotation &&
!candidates[count + _uShowedCount + idx].first.second.empty())
if(_pTextService->cx_annotation && !an.empty())
{
s.append(
std::regex_replace(candidates[count + _uShowedCount + idx].first.second,
s.append(std::regex_replace(an,
std::wregex(markSP), std::wstring(markNBSP)));
}
}
else
{
if(!candidates[count + _uShowedCount + idx].first.second.empty())
if(!an.empty())
{
s.append(
std::regex_replace(candidates[count + _uShowedCount + idx].first.second,
s.append(std::regex_replace(an,
std::wregex(markSP), std::wstring(markNBSP)));
}
}
Expand All @@ -381,7 +403,6 @@ std::wstring CCandidateWindow::_MakeCandidateString(UINT page, UINT count, UINT

void CCandidateWindow::_PaintCandidate(HDC hdc, LPRECT lpr, UINT page, UINT count, UINT idx)
{
int cycle;
std::wstring s;
RECT r, r_ex;
D2D1_RECT_F rd2d;
Expand All @@ -391,10 +412,19 @@ void CCandidateWindow::_PaintCandidate(HDC hdc, LPRECT lpr, UINT page, UINT coun
r_ex = *lpr;
r_ex.right = r_ex.left;

for(cycle = CL_COLOR_BG; cycle < DISPLAY_COLOR_NUM; cycle++)
std::wstring ca = candidates[count + _uShowedCount + idx].first.first;

for(int cycle = 0; cycle < DISPLAY_COLOR_NUM; cycle++)
{
s = _MakeCandidateString(page, count, idx, cycle);

int color_cycle = cycle;
if(_comp && ca.compare(0, searchkey.size(), searchkey) != 0)
{
//補完かつ後方一致
color_cycle = colors_compback[cycle];
}

if(_pD2DDCRT != nullptr && _pDWTF != nullptr)
{
if(_GetTextMetrics(s.c_str(), &dwTM) == S_OK)
Expand All @@ -411,7 +441,8 @@ void CCandidateWindow::_PaintCandidate(HDC hdc, LPRECT lpr, UINT page, UINT coun

rd2d = D2D1::RectF((FLOAT)r.left, (FLOAT)r.top, (FLOAT)r.right, (FLOAT)r.bottom);

if(_comp && (count + _uShowedCount + idx == candidx) && (cycle == CL_COLOR_SE || cycle == CL_COLOR_CA))
if(_comp && (count + _uShowedCount + idx == candidx) &&
(color_cycle == CL_COLOR_SE || color_cycle == CL_COLOR_CA))
{
_pD2DDCRT->FillRectangle(&rd2d, _pD2DBrush[CL_COLOR_SE]);
_pD2DDCRT->DrawText(s.c_str(), (UINT32)s.size(),
Expand All @@ -420,7 +451,7 @@ void CCandidateWindow::_PaintCandidate(HDC hdc, LPRECT lpr, UINT page, UINT coun
else
{
_pD2DDCRT->DrawText(s.c_str(), (UINT32)s.size(),
_pDWTF, &rd2d, _pD2DBrush[cycle], _drawtext_option);
_pDWTF, &rd2d, _pD2DBrush[color_cycle], _drawtext_option);
}
}
else
Expand All @@ -433,15 +464,16 @@ void CCandidateWindow::_PaintCandidate(HDC hdc, LPRECT lpr, UINT page, UINT coun

r_ex.right = r.right;

if(_comp && (count + _uShowedCount + idx == candidx) && (cycle == CL_COLOR_SE || cycle == CL_COLOR_CA))
if(_comp && (count + _uShowedCount + idx == candidx) &&
(color_cycle == CL_COLOR_SE || color_cycle == CL_COLOR_CA))
{
SetTextColor(hdc, _pTextService->cx_colors[CL_COLOR_BG]);
SetBkColor(hdc, _pTextService->cx_colors[CL_COLOR_SE]);
SetBkMode(hdc, OPAQUE);
}
else
{
SetTextColor(hdc, _pTextService->cx_colors[cycle]);
SetTextColor(hdc, _pTextService->cx_colors[color_cycle]);
SetBkMode(hdc, TRANSPARENT);
}

Expand All @@ -459,7 +491,7 @@ void CCandidateWindow::_CalcWindowRect()
HGDIOBJ font = nullptr;
RECT r, rw;
POINT pt;
int x, y, cx = 0, cy = 0, xmax = 0, cycle;
int x, y, cx = 0, cy = 0, xmax = 0;
UINT page, count, i;
std::wstring s;
WCHAR strPage[32];
Expand Down Expand Up @@ -538,7 +570,7 @@ void CCandidateWindow::_CalcWindowRect()
for(i = 0; i < _CandCount[page]; i++)
{
s.clear();
for(cycle = CL_COLOR_BG; cycle < DISPLAY_COLOR_NUM; cycle++)
for(int cycle = 0; cycle < DISPLAY_COLOR_NUM; cycle++)
{
s += _MakeCandidateString(page, count, i, cycle);
}
Expand Down Expand Up @@ -596,7 +628,7 @@ void CCandidateWindow::_CalcWindowRect()
for(i = 0; i < _CandCount[page]; i++)
{
s.clear();
for(cycle = CL_COLOR_BG; cycle < DISPLAY_COLOR_NUM; cycle++)
for(int cycle = 0; cycle < DISPLAY_COLOR_NUM; cycle++)
{
s += _MakeCandidateString(page, count, i, cycle);
}
Expand Down
2 changes: 1 addition & 1 deletion imcrvtip/FnConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ static const TF_PRESERVEDKEY configpreservedkey[] =
static const struct {
LPCWSTR value;
COLORREF color;
} colorsxmlvalue[8] =
} colorsxmlvalue[DISPLAY_COLOR_NUM] =
{
{ValueColorBG, RGB(0xFF,0xFF,0xFF)},
{ValueColorFR, RGB(0x00,0x00,0x00)},
Expand Down
3 changes: 2 additions & 1 deletion imcrvtip/KeyHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ HRESULT CTextService::_HandleKey(TfEditCookie ec, ITfContext *pContext, WPARAM w
if(complement)
{
complement = FALSE; //補完終了
kana = kana.erase(cursoridx);
kana = searchkey;
cursoridx = kana.size();

if(cx_dynamiccomp || cx_dyncompmulti)
{
Expand Down
Loading

0 comments on commit ce113f5

Please sign in to comment.