diff options
| author | ManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com> | 2022-04-29 16:34:47 +0200 |
|---|---|---|
| committer | ManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com> | 2022-04-29 16:34:47 +0200 |
| commit | 5341f0e45ead688a0bef59d2a6a30afcd02fadf1 (patch) | |
| tree | d45c40f06d99ee19ff485c772cface4753df37e3 /src | |
| parent | 1b513d3f00dd42465fd8a067800b2da0b6dcff81 (diff) | |
Add explanatory comments about text size and vertical position.
Diffstat (limited to 'src')
| -rw-r--r-- | src/drivers/Cairo/Fl_Cairo_Graphics_Driver.cxx | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/src/drivers/Cairo/Fl_Cairo_Graphics_Driver.cxx b/src/drivers/Cairo/Fl_Cairo_Graphics_Driver.cxx index 4f36bb246..813917392 100644 --- a/src/drivers/Cairo/Fl_Cairo_Graphics_Driver.cxx +++ b/src/drivers/Cairo/Fl_Cairo_Graphics_Driver.cxx @@ -1051,7 +1051,9 @@ int Fl_Cairo_Graphics_Driver::get_font_sizes(Fl_Font fnum, int*& sizep) { Fl_Cairo_Font_Descriptor::Fl_Cairo_Font_Descriptor(const char* name, Fl_Fontsize size) : Fl_Font_Descriptor(name, size) { char string[70]; strcpy(string, name); - sprintf(string + strlen(string), " %d", int(size * 0.75 + 0.5) ); // why reduce size? + // The factor of 0.75 below gives cairo-produced text the same size as + // Xft-produced text for the same FLTK font size. + sprintf(string + strlen(string), " %d", int(size * 0.75 + 0.5) ); fontref = pango_font_description_from_string(string); width = NULL; static PangoFontMap *def_font_map = pango_cairo_font_map_get_default(); // 1.10 @@ -1122,6 +1124,8 @@ void Fl_Cairo_Graphics_Driver::font(Fl_Font fnum, Fl_Fontsize s) { void Fl_Cairo_Graphics_Driver::draw(const char* str, int n, float x, float y) { if (!n) return; cairo_save(cairo_); + // The vertical offset size()/21. below vertically positions output text adequately + // relatively to the baseline (empirical observation). cairo_translate(cairo_, x, y - height() + descent() + size()/21.); pango_layout_set_text(pango_layout_, str, n); pango_cairo_show_layout(cairo_, pango_layout_); |
