FIX: get suitable font size to draw the texts

jira: [STUDIO-10067]
Change-Id: I589fd6a271ae177e4630e403b64c18090aab9471
(cherry picked from commit d036c92a3793e8c0c758432b52f2af8ffeff751f)
This commit is contained in:
xin.zhang
2025-02-19 18:25:14 +08:00
committed by Noisyfox
parent fc64cc8451
commit 6b6b5aa49e
5 changed files with 61 additions and 15 deletions

View File

@@ -297,6 +297,40 @@ bool WxFontUtils::is_bold(const wxFont &font) {
return wx_weight != wxFONTWEIGHT_NORMAL;
}
void Slic3r::GUI::WxFontUtils::get_suitable_font_size(int max_height, wxDC &dc)
{
wxFont font = dc.GetFont();
if (!font.IsOk()) return;
int font_size = font.GetPointSize();
int height = dc.GetFontMetrics().height;
if (height < max_height) /*go smaller*/
{
while (height < max_height) {
font_size++;
font.SetPointSize(font_size);
dc.SetFont(font);
height = dc.GetFontMetrics().height;
}
if (height > max_height)
{
font_size--;
font.SetPointSize(font_size);
dc.SetFont(font);
}
}
else if (height > max_height) /*go bigger*/
{
while (height > max_height && font_size > 1) {
font_size--;
font.SetPointSize(font_size);
dc.SetFont(font);
height = dc.GetFontMetrics().height;
}
}
}
std::unique_ptr<Emboss::FontFile> WxFontUtils::set_italic(wxFont &font, const Emboss::FontFile &font_file)
{
static std::vector<wxFontStyle> italic_styles = {