FLTK logo

[master] e5c3cae - Fix text drawn by pango is offset +1 pixel on x and y) (#568)

FLTK matrix user chat room
(using Element browser app)   FLTK gitter user chat room   GitHub FLTK Project   FLTK News RSS Feed  
  FLTK Apps      FLTK Library      Forums      Links     Login 
 All Forums  |  Back to fltk.commit  ]
 
Previous Message ]Next Message ]

[master] e5c3cae - Fix text drawn by pango is offset +1 pixel on x and y) (#568) "ManoloFLTK" Dec 02, 2022  
 
commit e5c3caeb6b3824eb933cbb3acc57365d9b2ed6d4
Author:     ManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com>
AuthorDate: Fri Dec 2 16:14:38 2022 +0100
Commit:     ManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com>
CommitDate: Fri Dec 2 16:14:38 2022 +0100

    Fix text drawn by pango is offset +1 pixel on x and y) (#568)

 src/drivers/Cairo/Fl_Cairo_Graphics_Driver.cxx | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git src/drivers/Cairo/Fl_Cairo_Graphics_Driver.cxx src/drivers/Cairo/Fl_Cairo_Graphics_Driver.cxx
index 1bf5d2a..26eb5bc 100644
--- src/drivers/Cairo/Fl_Cairo_Graphics_Driver.cxx
+++ src/drivers/Cairo/Fl_Cairo_Graphics_Driver.cxx
@@ -1199,8 +1199,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 -0.5 below makes underscores visible in Fl_Text_Display at scale = 1
-  cairo_translate(cairo_, x, y - height() + descent() -0.5);
+  Fl_Cairo_Font_Descriptor *fd = (Fl_Cairo_Font_Descriptor*)font_descriptor();
+  cairo_translate(cairo_, x - 1, y - (fd->line_height - fd->descent) / float(PANGO_SCALE) - 1);
   pango_layout_set_text(pango_layout_, str, n);
   pango_cairo_show_layout(cairo_, pango_layout_); // 1.1O
   cairo_restore(cairo_);
@@ -1278,8 +1278,8 @@ void Fl_Cairo_Graphics_Driver::text_extents(const char* txt, int n, int& dx, int
   pango_layout_get_extents(pango_layout_, &ink_rect, NULL);
   double f = PANGO_SCALE;
   Fl_Cairo_Font_Descriptor *fd = (Fl_Cairo_Font_Descriptor*)font_descriptor();
-  dx = ink_rect.x / f;
-  dy = (ink_rect.y - fd->line_height + fd->descent) / f;
+  dx = ink_rect.x / f - 1;
+  dy = (ink_rect.y - fd->line_height + fd->descent) / f - 1;
   w = ceil(ink_rect.width / f);
   h = ceil(ink_rect.height / f);
 }
Direct Link to Message ]
 
     
Previous Message ]Next Message ]
 
 

Comments are owned by the poster. All other content is copyright 1998-2024 by Bill Spitzak and others. This project is hosted by The FLTK Team. Please report site problems to 'erco@seriss.com'.