mirror of
https://github.com/ONLYOFFICE/desktop-apps.git
synced 2026-02-10 18:05:16 +08:00
[win] online installer: fix text width measurement for RTL
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
#include "abstractbutton.h"
|
||||
#include "palette.h"
|
||||
#include "metrics.h"
|
||||
#include <gdiplus.h>
|
||||
|
||||
|
||||
AbstractButton::AbstractButton(Widget *parent, const std::wstring &text) :
|
||||
@ -24,13 +25,15 @@ void AbstractButton::setText(const std::wstring &text)
|
||||
void AbstractButton::adjustSizeBasedOnContent()
|
||||
{
|
||||
HDC hdc = GetDC(nativeWindowHandle());
|
||||
HFONT hOldFont = (HFONT)SelectObject(hdc, m_hFont);
|
||||
SIZE textSize{0, 0};
|
||||
GetTextExtentPoint32(hdc, m_text.c_str(), m_text.length(), &textSize);
|
||||
SelectObject(hdc, hOldFont);
|
||||
Gdiplus::Graphics gr(hdc);
|
||||
LOGFONTW logFont = {0};
|
||||
GetObject(m_hFont, sizeof(LOGFONTW), &logFont);
|
||||
Gdiplus::Font font(hdc, &logFont);
|
||||
Gdiplus::RectF lutRc, boxRc;
|
||||
gr.MeasureString(m_text.c_str(), m_text.length(), &font, lutRc, &boxRc);
|
||||
ReleaseDC(nativeWindowHandle(), hdc);
|
||||
int w = textSize.cx + 2*metrics()->value(Metrics::IconWidth) + metrics()->value(Metrics::TextMarginLeft) + metrics()->value(Metrics::TextMarginRight);
|
||||
int h = max(textSize.cy + metrics()->value(Metrics::TextMarginTop) + metrics()->value(Metrics::TextMarginBottom), metrics()->value(Metrics::IconHeight)) + 1;
|
||||
int w = boxRc.Width + 2*metrics()->value(Metrics::IconWidth) + metrics()->value(Metrics::TextMarginLeft) + metrics()->value(Metrics::TextMarginRight);
|
||||
int h = max(boxRc.Height + metrics()->value(Metrics::TextMarginTop) + metrics()->value(Metrics::TextMarginBottom), metrics()->value(Metrics::IconHeight));
|
||||
resize(w, h);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user