From 13f2ea664a9c5e3fdf318ef75914e2e876b5aaef Mon Sep 17 00:00:00 2001 From: ManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com> Date: Wed, 4 Jan 2023 17:23:13 +0100 Subject: Cairo/Pango: compute character widths fast and string widths accurately This commit has Fl_Cairo_Graphics_Driver compute string widths in 2 ways: 1) when the string contains several unicode characters, the width of the whole string is computed, accounting for kerning when it occurs; 2) when the string contains a single unicode character, its width is computed, memorised, and re-used next time it's necessary. The effect of this approach is - Fl_Text_Display is fast because it uses memorised single character widths repeatedly - Fl_Input is drawn accurately because the cursor position is determined by string widths, not by sums of character widths. --- src/drivers/Cairo/Fl_Cairo_Graphics_Driver.H | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/drivers/Cairo/Fl_Cairo_Graphics_Driver.H') diff --git a/src/drivers/Cairo/Fl_Cairo_Graphics_Driver.H b/src/drivers/Cairo/Fl_Cairo_Graphics_Driver.H index 0b5eee198..c6fa15403 100644 --- a/src/drivers/Cairo/Fl_Cairo_Graphics_Driver.H +++ b/src/drivers/Cairo/Fl_Cairo_Graphics_Driver.H @@ -50,7 +50,7 @@ private: bool *needs_commit_tag_; // NULL or points to whether cairo surface was drawn to cairo_t *dummy_cairo_; // used to measure text width before showing a window int linestyle_; - int width_unscaled_(unsigned int c); + int do_width_unscaled_(const char* str, int n); protected: cairo_t *cairo_; PangoContext *pango_context_; -- cgit v1.2.3