Skip to content

Commit

Permalink
Dictionary Panel
Browse files Browse the repository at this point in the history
  • Loading branch information
graphemecluster committed Jul 19, 2023
1 parent 9e21945 commit ee5e4eb
Show file tree
Hide file tree
Showing 13 changed files with 644 additions and 62 deletions.
47 changes: 43 additions & 4 deletions RimeWithWeasel/RimeWithWeasel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -792,10 +792,21 @@ static void _UpdateUIStyle(RimeConfig* config, weasel::UI* ui, bool initialize)
processFontFaceConfig("style/urd_font_face", style.urd_font_face);
processFontFaceConfig("style/nep_font_face", style.nep_font_face);
processFontFaceConfig("style/ind_font_face", style.ind_font_face);
processFontFaceConfig("style/page_mark_font_face", style.page_mark_font_face);

processFontFaceConfig("style/dictionary_panel/entry_font_face", style.dictionary_panel_style.entry_font_face);
processFontFaceConfig("style/dictionary_panel/pron_face", style.dictionary_panel_style.pron_face);
processFontFaceConfig("style/dictionary_panel/pron_type_font_face", style.dictionary_panel_style.pron_type_font_face);
processFontFaceConfig("style/dictionary_panel/pos_font_face", style.dictionary_panel_style.pos_font_face);
processFontFaceConfig("style/dictionary_panel/register_font_face", style.dictionary_panel_style.register_font_face);
processFontFaceConfig("style/dictionary_panel/lbl_font_face", style.dictionary_panel_style.lbl_font_face);
processFontFaceConfig("style/dictionary_panel/field_key_font_face", style.dictionary_panel_style.field_key_font_face);
processFontFaceConfig("style/dictionary_panel/field_value_font_face", style.dictionary_panel_style.field_value_font_face);
processFontFaceConfig("style/dictionary_panel/more_languages_head_font_face", style.dictionary_panel_style.more_languages_head_font_face);

const auto processFontPointConfig = [&config](const char* key, int* value) {
if (RimeConfigGetInt(config, key, value) || RimeConfigGetInt(config, "style/font_point", value)) {
if (value <= 0) *value = 12;
if (*value <= 0) *value = 12;
}
};
processFontPointConfig("style/font_point", &style.font_point);
Expand All @@ -808,6 +819,17 @@ static void _UpdateUIStyle(RimeConfig* config, weasel::UI* ui, bool initialize)
processFontPointConfig("style/urd_font_point", &style.urd_font_point);
processFontPointConfig("style/nep_font_point", &style.nep_font_point);
processFontPointConfig("style/ind_font_point", &style.ind_font_point);
processFontPointConfig("style/page_mark_font_point", &style.page_mark_font_point);

processFontPointConfig("style/dictionary_panel/entry_font_point", &style.dictionary_panel_style.entry_font_point);
processFontPointConfig("style/dictionary_panel/pron_point", &style.dictionary_panel_style.pron_point);
processFontPointConfig("style/dictionary_panel/pron_type_font_point", &style.dictionary_panel_style.pron_type_font_point);
processFontPointConfig("style/dictionary_panel/pos_font_point", &style.dictionary_panel_style.pos_font_point);
processFontPointConfig("style/dictionary_panel/register_font_point", &style.dictionary_panel_style.register_font_point);
processFontPointConfig("style/dictionary_panel/lbl_font_point", &style.dictionary_panel_style.lbl_font_point);
processFontPointConfig("style/dictionary_panel/field_key_font_point", &style.dictionary_panel_style.field_key_font_point);
processFontPointConfig("style/dictionary_panel/field_value_font_point", &style.dictionary_panel_style.field_value_font_point);
processFontPointConfig("style/dictionary_panel/more_languages_head_font_point", &style.dictionary_panel_style.more_languages_head_font_point);

Bool inline_preedit = False;
if (RimeConfigGetBool(config, "style/inline_preedit", &inline_preedit) || initialize)
Expand Down Expand Up @@ -901,9 +923,20 @@ static void _UpdateUIStyle(RimeConfig* config, weasel::UI* ui, bool initialize)
style.margin_y = style.hilite_padding;
else if (style.hilite_padding > -style.margin_y && style.margin_y < 0)
style.margin_y = -(style.hilite_padding);
RimeConfigGetInt(config, "style/layout/dictionary_panel_padding", &style.dictionary_panel_padding);
RimeConfigGetInt(config, "style/layout/dictionary_entry_gap", &style.dictionary_entry_gap);
RimeConfigGetInt(config, "style/layout/dictionary_spacing", &style.dictionary_spacing);
// dictionary panel
RimeConfigGetInt(config, "style/dictionary_panel/layout/padding", &style.dictionary_panel_style.padding);
RimeConfigGetInt(config, "style/dictionary_panel/layout/title_gap", &style.dictionary_panel_style.title_gap);
RimeConfigGetInt(config, "style/dictionary_panel/layout/spacing", &style.dictionary_panel_style.spacing);
RimeConfigGetInt(config, "style/dictionary_panel/layout/pos_border_width", &style.dictionary_panel_style.pos_border_width);
RimeConfigGetInt(config, "style/dictionary_panel/layout/pos_border_radius", &style.dictionary_panel_style.pos_border_radius);
RimeConfigGetInt(config, "style/dictionary_panel/layout/pos_padding", &style.dictionary_panel_style.pos_padding);
RimeConfigGetInt(config, "style/dictionary_panel/layout/pos_gap", &style.dictionary_panel_style.pos_gap);
RimeConfigGetInt(config, "style/dictionary_panel/layout/lbl_gap", &style.dictionary_panel_style.lbl_gap);
RimeConfigGetInt(config, "style/dictionary_panel/layout/definition_gap", &style.dictionary_panel_style.definition_gap);
RimeConfigGetInt(config, "style/dictionary_panel/layout/field_spacing", &style.dictionary_panel_style.field_spacing);
RimeConfigGetInt(config, "style/dictionary_panel/layout/field_gap", &style.dictionary_panel_style.field_gap);
RimeConfigGetInt(config, "style/dictionary_panel/layout/more_languages_spacing", &style.dictionary_panel_style.more_languages_spacing);
RimeConfigGetInt(config, "style/dictionary_panel/layout/entry_spacing", &style.dictionary_panel_style.entry_spacing);
// color scheme
#ifdef USE_THEME_DARK
bool is_light = IsThemeLight();
Expand Down Expand Up @@ -1082,6 +1115,12 @@ static bool _UpdateUIStyleColor(RimeConfig* config, weasel::UIStyle& style, bool
style.hint_text_color &= 0xffffffff;
RimeConfigGetColor32b(config, (prefix + "/hilited_hint_text_color").c_str(), &style.hilited_hint_text_color, fmt);
style.hilited_hint_text_color &= 0xffffffff;

if (!RimeConfigGetColor32b(config, (prefix + "/dictionary_panel/pos_border_color").c_str(), &style.dictionary_panel_style.pos_border_color, fmt))
{
style.dictionary_panel_style.pos_border_color = style.border_color;
}
style.dictionary_panel_style.pos_border_color &= 0xffffffff;
#ifdef USE_HILITE_MARK
if (!RimeConfigGetColor32b(config, (prefix + "/hilited_mark_color").c_str(), &style.hilited_mark_color, fmt))
{
Expand Down
14 changes: 12 additions & 2 deletions WeaselUI/Layout.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,17 @@ namespace weasel
{}
};

struct DictionaryPanelRects
{
CRect entryLabel, pronLabel, pronTypeLabel;
std::vector<CRect> posLabels, lblLabels;
CRect registerLabel, definitionLabel;
std::vector<std::vector<CRect> > fieldLabels;
CRect moreLanguagesHeadLabel;
std::vector<std::pair<CRect, CRect> > moreLanguageLabels;
DictionaryPanelRects() {}
};

class Layout
{
public:
Expand All @@ -59,8 +70,7 @@ namespace weasel
virtual CRect GetAuxiliaryRect() const = 0;
virtual CRect GetHighlightRect() const = 0;
virtual CRect GetDictionaryRect() const = 0;
virtual CRect GetDictionaryEntryRect() const = 0;
virtual CRect GetDictionaryPronRect() const = 0;
virtual std::vector<DictionaryPanelRects> GetDictionaryPanelRects() const = 0;
virtual CRect GetCandidateLabelRect(int id) const = 0;
virtual CRect GetCandidateTextRect(int id) const = 0;
virtual CRect GetCandidateRect(int id) const = 0;
Expand Down
98 changes: 96 additions & 2 deletions WeaselUI/MultiHintPanel.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#include "stdafx.h"
#include "stdafx.h"
#include "MultiHintPanel.h"
#include <unordered_set>
#include <regex>
#include <map>
#include <StringAlgorithm.hpp>

MultiHintPanel* volatile MultiHintPanel::instance = nullptr;
Expand Down Expand Up @@ -85,7 +86,7 @@ InfoMultiHint::InfoMultiHint(const std::wstring& input) {
/* 5 */ Properties.Label = *column++;
/* 6 */ Properties.Normalized = *column++;
/* 7 */ Properties.Written = *column++;
/* 8 */ Properties.Colloquial = *column++;
/* 8 */ Properties.Vernacular = *column++;
/* 9 */ Properties.Collocation = *column++;
Properties.Definition = InfoDefinition();
/* 10 */ Properties.Definition.Eng = *column++;
Expand All @@ -96,3 +97,96 @@ InfoMultiHint::InfoMultiHint(const std::wstring& input) {
Jyutping = std::regex_replace(Jyutping, std::wregex(L"\\d"), L"$& ");
Jyutping.pop_back();
}

const static std::vector<std::pair<std::wstring, std::wstring InfoProperties::*> > otherData = {
{ L"Standard Form", &InfoProperties::Normalized },
{ L"Written Form", &InfoProperties::Written },
{ L"Vernacular Form", &InfoProperties::Vernacular },
{ L"Word Form", &InfoProperties::Collocation },
};

const static std::map<std::wstring, std::wstring> litColReadings = {
{ L"lit", L"literary reading 文讀" },
{ L"col", L"colloquial reading 白讀" },
};

const static std::map<std::wstring, std::wstring> registers = {
{ L"wri", L"written" },
{ L"ver", L"vernacular" },
{ L"for", L"formal" },
{ L"lzh", L"archaic" },
};

const static std::map<std::wstring, std::wstring> partsOfSpeech = {
{ L"n", L"noun 名詞" },
{ L"v", L"verb 動詞" },
{ L"adj", L"adjective 形容詞" },
{ L"adv", L"adverb 副詞" },
{ L"conj", L"conjunction 連接詞" },
{ L"prep", L"preposition 前置詞" },
{ L"pron", L"pronoun 代名詞" },
{ L"morph", L"morpheme 語素" },
{ L"mw", L"measure word 量詞" },
{ L"part", L"particle 助詞" },
{ L"oth", L"other 其他" },
{ L"x", L"non-morpheme 非語素" },
};

std::wstring InfoMultiHint::GetPronType() const {
std::wstring pronType = L"";
if (Sandhi == L"1") pronType += L"changed tone 變音, ";
auto it = litColReadings.find(LitColReading);
if (it != litColReadings.end()) pronType += it->second + L", ";
if (pronType.empty()) return pronType;
pronType.pop_back();
pronType.pop_back();
return L"(" + pronType + L")";
}

std::vector<std::wstring> InfoProperties::GetPartsOfSpeech() const {
std::vector<std::wstring> posSplitted, posFiltered;
split(posSplitted, PartOfSpeech, L" ");
for (const std::wstring pos : posSplitted) {
if (pos.empty()) continue;
auto it = partsOfSpeech.find(pos);
posFiltered.push_back(it == partsOfSpeech.end() ? pos : it->second);
}
return posFiltered;
}

std::wstring InfoProperties::GetRegister() const {
auto it = registers.find(Register);
return it == registers.end() ? L"" : it->second;
}

std::vector<std::wstring> InfoProperties::GetLabels() const {
std::vector<std::wstring> labelSplitted, labelFiltered;
split(labelSplitted, Label, L" ");
for (const std::wstring label : labelSplitted) {
if (label.empty()) continue;
labelFiltered.push_back(L"(" + label + L")");
}
return labelFiltered;
}

std::vector<std::vector<std::wstring> > InfoProperties::GetOtherData() const {
std::vector<std::vector<std::wstring> > data;
for (const auto& field : otherData) {
std::wstring str = this->*field.second;
if (str.empty()) continue;
std::vector<std::wstring> item = { field.first };
split(item, str, L"", false);
data.push_back(item);
}
return data;
}

std::vector<InfoLanguage> InfoDefinition::Get(MultiHintPanel* panel, DirectWriteResources* pDWR) const {
std::vector<InfoLanguage> info;
if (panel->isHintEnabled(StatusHintColumn::Eng) && !Eng.empty()) info.push_back({ L"English", Eng, pDWR->pEngTextFormat });
if (panel->isHintEnabled(StatusHintColumn::Eng) && !Urd.empty()) info.push_back({ L"Urdu", Urd, pDWR->pUrdTextFormat });
if (panel->isHintEnabled(StatusHintColumn::Eng) && !Nep.empty()) info.push_back({ L"Nepali", Nep, pDWR->pNepTextFormat });
if (panel->isHintEnabled(StatusHintColumn::Eng) && !Hin.empty()) info.push_back({ L"Hindi", Hin, pDWR->pHinTextFormat });
if (panel->isHintEnabled(StatusHintColumn::Eng) && !Ind.empty()) info.push_back({ L"Indonesian", Ind, pDWR->pIndTextFormat });
return info;
}
17 changes: 16 additions & 1 deletion WeaselUI/MultiHintPanel.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,23 @@

#include <WeaselCommon.h>
#include <boost/tokenizer.hpp>
#include "fontClasses.h"

class MultiHintPanel;

struct InfoLanguage {
std::wstring Key;
std::wstring Value;
IDWriteTextFormat1* TextFormat;
};

struct InfoDefinition {
std::wstring Eng;
std::wstring Urd;
std::wstring Nep;
std::wstring Hin;
std::wstring Ind;
std::vector<InfoLanguage> Get(MultiHintPanel* panel, DirectWriteResources* pDWR) const;
};

struct InfoProperties {
Expand All @@ -17,8 +27,12 @@ struct InfoProperties {
std::wstring Label;
std::wstring Normalized;
std::wstring Written;
std::wstring Colloquial;
std::wstring Vernacular;
std::wstring Collocation;
std::vector<std::wstring> GetPartsOfSpeech() const;
std::wstring GetRegister() const;
std::vector<std::wstring> GetLabels() const;
std::vector<std::vector<std::wstring> > GetOtherData() const;
InfoDefinition Definition;
};

Expand All @@ -28,6 +42,7 @@ struct InfoMultiHint {
std::wstring Jyutping;
std::wstring Sandhi;
std::wstring LitColReading;
std::wstring GetPronType() const;
InfoProperties Properties;
};

Expand Down
6 changes: 3 additions & 3 deletions WeaselUI/StandardLayout.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ namespace weasel
virtual CRect GetAuxiliaryRect() const { return _auxiliaryRect; }
virtual CRect GetHighlightRect() const { return _highlightRect; }
virtual CRect GetDictionaryRect() const { return _dictionaryRect; }
virtual CRect GetDictionaryEntryRect() const { return _dictionaryEntryRect; }
virtual CRect GetDictionaryPronRect() const { return _dictionaryPronRect; }
virtual std::vector<DictionaryPanelRects> GetDictionaryPanelRects() const { return _dictionaryPanelRects; }
virtual CRect GetCandidateLabelRect(int id) const { return _candidateLabelRects[id]; }
virtual CRect GetCandidateTextRect(int id) const { return _candidateTextRects[id]; }
virtual CRect GetCandidateCommentRect(int id) const { return _candidateCommentRects[id]; }
Expand Down Expand Up @@ -74,7 +73,8 @@ namespace weasel
CRect _statusIconRect;
CRect _bgRect;
CRect _contentRect;
CRect _dictionaryRect, _dictionaryEntryRect, _dictionaryPronRect;
CRect _dictionaryRect;
std::vector<DictionaryPanelRects> _dictionaryPanelRects;
IsToRoundStruct _roundInfo[MAX_CANDIDATES_COUNT];
IsToRoundStruct _textRoundInfo;
MultiHintPanel* _multiHintPanel;
Expand Down
Loading

0 comments on commit ee5e4eb

Please sign in to comment.