Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add parameter for chance to avoid linespacing flickering #1177

Merged
merged 1 commit into from
Apr 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions RimeWithWeasel/RimeWithWeasel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1223,6 +1223,10 @@ static void _UpdateUIStyle(RimeConfig* config, UI* ui, bool initialize) {
style.layout_type = UIStyle::LAYOUT_VERTICAL_TEXT;
_RimeGetStringWithFunc(config, "style/label_format", style.label_text_format);
_RimeGetStringWithFunc(config, "style/mark_text", style.mark_text);
_RimeGetIntWithFallback(config, "style/layout/baseline", &style.baseline,
NULL, _abs);
_RimeGetIntWithFallback(config, "style/layout/linespacing",
&style.linespacing, NULL, _abs);
_RimeGetIntWithFallback(config, "style/layout/min_width", &style.min_width,
NULL, _abs);
_RimeGetIntWithFallback(config, "style/layout/max_width", &style.max_width,
Expand Down
19 changes: 19 additions & 0 deletions WeaselUI/DirectWriteResources.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ HRESULT DirectWriteResources::InitResources(
const std::wstring _mainFontFace = L"_InvalidFontName_";
DWRITE_FONT_WEIGHT fontWeight = DWRITE_FONT_WEIGHT_NORMAL;
DWRITE_FONT_STYLE fontStyle = DWRITE_FONT_STYLE_NORMAL;
// convert percentage to float
float linespacing = dpiScaleX_ * ((float)_style.linespacing / 100.0f);
float baseline = dpiScaleX_ * ((float)_style.baseline / 100.0f);
// setup font weight and font style by the first unit of font_face setting
// string
_ParseFontFace(font_face, fontWeight, fontStyle);
Expand All @@ -143,6 +146,10 @@ HRESULT DirectWriteResources::InitResources(
pTextFormat->SetParagraphAlignment(DWRITE_PARAGRAPH_ALIGNMENT_CENTER);
pTextFormat->SetWordWrapping(wrapping);
_SetFontFallback(pTextFormat, fontFaceStrVector);
if (_style.linespacing && _style.baseline)
pTextFormat->SetLineSpacing(DWRITE_LINE_SPACING_METHOD_UNIFORM,
font_point * linespacing,
font_point * baseline);
}
decltype(fontFaceStrVector)().swap(fontFaceStrVector);

Expand All @@ -167,6 +174,10 @@ HRESULT DirectWriteResources::InitResources(
DWRITE_PARAGRAPH_ALIGNMENT_CENTER);
pPreeditTextFormat->SetWordWrapping(wrapping);
_SetFontFallback(pPreeditTextFormat, fontFaceStrVector);
if (_style.linespacing && _style.baseline)
pPreeditTextFormat->SetLineSpacing(DWRITE_LINE_SPACING_METHOD_UNIFORM,
font_point * linespacing,
font_point * baseline);
}
decltype(fontFaceStrVector)().swap(fontFaceStrVector);

Expand All @@ -192,6 +203,10 @@ HRESULT DirectWriteResources::InitResources(
pLabelTextFormat->SetParagraphAlignment(DWRITE_PARAGRAPH_ALIGNMENT_CENTER);
pLabelTextFormat->SetWordWrapping(wrapping);
_SetFontFallback(pLabelTextFormat, fontFaceStrVector);
if (_style.linespacing && _style.baseline)
pLabelTextFormat->SetLineSpacing(DWRITE_LINE_SPACING_METHOD_UNIFORM,
label_font_point * linespacing,
label_font_point * baseline);
}
decltype(fontFaceStrVector)().swap(fontFaceStrVector);

Expand All @@ -218,6 +233,10 @@ HRESULT DirectWriteResources::InitResources(
DWRITE_PARAGRAPH_ALIGNMENT_CENTER);
pCommentTextFormat->SetWordWrapping(wrapping);
_SetFontFallback(pCommentTextFormat, fontFaceStrVector);
if (_style.linespacing && _style.baseline)
pCommentTextFormat->SetLineSpacing(DWRITE_LINE_SPACING_METHOD_UNIFORM,
comment_font_point * linespacing,
comment_font_point * baseline);
}
decltype(fontFaceStrVector)().swap(fontFaceStrVector);
return hResult;
Expand Down
4 changes: 2 additions & 2 deletions WeaselUI/WeaselPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1126,8 +1126,8 @@ void WeaselPanel::_TextOut(const CRect& rc,
if (pDWR->pTextLayout != NULL) {
pDWR->DrawTextLayoutAt({offsetx, offsety});
#if 0
D2D1_RECT_F rectf = D2D1::RectF(offsetx, offsety, offsetx + rc.Width(), offsety + rc.Height());
pDWR->DrawRect(&rectf);
D2D1_RECT_F rectf = D2D1::RectF(offsetx, offsety, offsetx + rc.Width(), offsety + rc.Height());
pDWR->DrawRect(&rectf);
#endif
}
pDWR->ResetLayout();
Expand Down
7 changes: 7 additions & 0 deletions include/WeaselCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,8 @@ struct UIStyle {
int nextpage_color;
// per client
int client_caps;
int baseline;
int linespacing;

UIStyle()
: font_face(),
Expand Down Expand Up @@ -358,6 +360,8 @@ struct UIStyle {
hilited_mark_color(0),
prevpage_color(0),
nextpage_color(0),
baseline(0),
linespacing(0),
client_caps(0) {}
bool operator!=(const UIStyle& st) {
return (
Expand Down Expand Up @@ -396,6 +400,7 @@ struct UIStyle {
shadow_offset_x != st.shadow_offset_x ||
shadow_offset_y != st.shadow_offset_y ||
vertical_auto_reverse != st.vertical_auto_reverse ||
baseline != st.baseline || linespacing != st.linespacing ||
text_color != st.text_color ||
candidate_text_color != st.candidate_text_color ||
candidate_back_color != st.candidate_back_color ||
Expand Down Expand Up @@ -494,6 +499,8 @@ void serialize(Archive& ar, weasel::UIStyle& s, const unsigned int version) {
ar & s.nextpage_color;
// per client
ar & s.client_caps;
ar & s.baseline;
ar & s.linespacing;
}

template <typename Archive>
Expand Down
2 changes: 2 additions & 0 deletions output/data/weasel.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ style:
shadow_radius: 0
shadow_offset_x: 4
shadow_offset_y: 4
linespacing: 0 # percentage of font point, 0 to disable
baseline: 0 # percentage of font point, 0 to disable

preset_color_schemes:
aqua:
Expand Down