summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com>2022-12-02 16:14:38 +0100
committerManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com>2022-12-02 16:14:38 +0100
commite5c3caeb6b3824eb933cbb3acc57365d9b2ed6d4 (patch)
treed0fd384638884a5440e8047c5c1a68dde0c2972e /src
parent8b7021ba8b94680099f8f739f79dcea72729eeb7 (diff)
Fix text drawn by pango is offset +1 pixel on x and y) (#568)
Diffstat (limited to 'src')
-rw-r--r--src/drivers/Cairo/Fl_Cairo_Graphics_Driver.cxx8
1 files changed, 4 insertions, 4 deletions
diff --git a/src/drivers/Cairo/Fl_Cairo_Graphics_Driver.cxx b/src/drivers/Cairo/Fl_Cairo_Graphics_Driver.cxx
index 1bf5d2a98..26eb5bccf 100644
--- a/src/drivers/Cairo/Fl_Cairo_Graphics_Driver.cxx
+++ b/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);
}