diff options
author | elfmz <fenix1905@tut.by> | 2022-11-12 22:23:53 +0300 |
---|---|---|
committer | elfmz <fenix1905@tut.by> | 2022-11-12 22:24:28 +0300 |
commit | b6cf3b5e983407b719466cb8e3035b9dfc2202b7 (patch) | |
tree | 067bdf4366a4a528380e2a8d189043d0f151d49d | |
parent | 839724f788af6f3bcf60db9fa927c0e644e9da2b (diff) |
wx: tweaking font selection logic
-rw-r--r-- | WinPort/src/Backend/WX/Paint.cpp | 45 | ||||
-rw-r--r-- | WinPort/src/Backend/WX/Paint.h | 2 |
2 files changed, 22 insertions, 25 deletions
diff --git a/WinPort/src/Backend/WX/Paint.cpp b/WinPort/src/Backend/WX/Paint.cpp index 8aa7580f..0670fd0d 100644 --- a/WinPort/src/Backend/WX/Paint.cpp +++ b/WinPort/src/Backend/WX/Paint.cpp @@ -275,7 +275,7 @@ void ConsolePaintContext::ShowFontDialog() SetFont(font); } -uint8_t ConsolePaintContext::CharFitTest(wxPaintDC &dc, const wchar_t *wcz) +uint8_t ConsolePaintContext::CharFitTest(wxPaintDC &dc, const wchar_t *wcz, unsigned int nx) { #ifdef DYNAMIC_FONTS const bool cacheable = (size_t(wcz[0]) <= _char_fit_cache.checked.size() && wcz[1] == 0); @@ -285,37 +285,34 @@ uint8_t ConsolePaintContext::CharFitTest(wxPaintDC &dc, const wchar_t *wcz) uint8_t font_index = 0; _cft_tmp = wcz; - wxCoord w, h = _font_height, d = _font_descent; - dc.GetTextExtent(_cft_tmp, &w, &h, &d); - for (uint8_t try_index = 1; try_index != 0xff && (unsigned)h > _font_height + std::max(0, int(d) - int(_font_descent)); ++try_index) { - - if (try_index >= _fonts.size()) { - wxFont smallest = _fonts.back(); - wxSize px_size = smallest.GetPixelSize(); - if (px_size.GetHeight() <= 4) { + for (font_index = 0; font_index != 0xff; ++font_index) { + if (font_index >= _fonts.size()) { + wxSize px_size = _fonts.front().GetPixelSize(); + if (px_size.GetHeight() <= (int)unsigned(font_index) + 4) break; - } - px_size.SetHeight(px_size.GetHeight() - 1); + + px_size.SetHeight(px_size.GetHeight() - font_index); px_size.SetWidth(0); - smallest.SetPixelSize(px_size); - _fonts.emplace_back(smallest); + + _fonts.emplace_back(_fonts.front()); + _fonts.back().SetPixelSize(px_size); + } + assert(font_index < _fonts.size()); + + wxCoord w = _font_width, h = _font_height, d = _font_descent; + dc.GetTextExtent(_cft_tmp, &w, &h, &d, NULL, &_fonts[font_index]); + const unsigned limh = _font_height + std::max(0, int(d) - int(_font_descent)); + const unsigned limw = _font_width * nx; + if (unsigned(h) <= limh && unsigned(w) <= limw) { + break; } - assert(try_index < _fonts.size()); - dc.SetFont(_fonts[try_index]); - dc.GetTextExtent(_cft_tmp, &w, &h, &d); - font_index = try_index; - } - if (font_index != 0) { -// fprintf(stderr, "Changed[%d] point size = %u -> %u for '%ls'\n", -// font_index, _fonts[0].GetPointSize(), _fonts[font_index].GetPointSize(), wcz); - ApplyFont(dc); } if (cacheable) { _char_fit_cache.result[ size_t(wcz[0]) - 1 ] = font_index; _char_fit_cache.checked[ size_t(wcz[0]) - 1 ] = true; } - + return font_index; #else @@ -741,7 +738,7 @@ void ConsolePainter::NextChar(unsigned int cx, DWORD64 attributes, const wchar_t return; } - uint8_t fit_font_index = _context->CharFitTest(_dc, wcz); + uint8_t fit_font_index = _context->CharFitTest(_dc, wcz, nx); if (fit_font_index == _prev_fit_font_index && _prev_underlined == underlined && _prev_strikeout == strikeout && _start_cx != (unsigned int)-1 && _clr_text == clr_text && _context->IsPaintBuffered()) { diff --git a/WinPort/src/Backend/WX/Paint.h b/WinPort/src/Backend/WX/Paint.h index 5127e2ab..9598f2ca 100644 --- a/WinPort/src/Backend/WX/Paint.h +++ b/WinPort/src/Backend/WX/Paint.h @@ -45,7 +45,7 @@ public: ConsolePaintContext(wxWindow *window); void ShowFontDialog(); - uint8_t CharFitTest(wxPaintDC &dc, const wchar_t *wcz); + uint8_t CharFitTest(wxPaintDC &dc, const wchar_t *wcz, unsigned int nx); void ApplyFont(wxPaintDC &dc, uint8_t index = 0); void OnPaint(SMALL_RECT *qedit = NULL); void RefreshArea( const SMALL_RECT &area ); |