FLTK logo

[master] 206d9b1 - Fix issue #509: Cairo drawing: unexpected behaviour This commit fixes " "drawing an fl_pie() with dimension 1x1". But it does not change "drawing fl_line() with begin position = end position does not show" because the same behaviour is observed with Windows and macOS.

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] 206d9b1 - Fix issue #509: Cairo drawing: unexpected behaviour This commit fixes " "drawing an fl_pie() with dimension 1x1". But it does not change "drawing fl_line() with begin position = end position does not show" because the same behaviour is observed with Windows and macOS. "ManoloFLTK" Oct 05, 2022  
 
commit 206d9b17e0e2c2a66c3352787b067ab172dad778
Author:     ManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com>
AuthorDate: Wed Oct 5 08:52:30 2022 +0200
Commit:     ManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com>
CommitDate: Wed Oct 5 08:52:30 2022 +0200

    Fix issue #509: Cairo drawing: unexpected behaviour
    This commit fixes " "drawing an fl_pie() with dimension 1x1".
    But it does not change "drawing fl_line() with begin position = end position does not show"
    because the same behaviour is observed with Windows and macOS.

 src/drivers/Cairo/Fl_Cairo_Graphics_Driver.cxx | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git src/drivers/Cairo/Fl_Cairo_Graphics_Driver.cxx src/drivers/Cairo/Fl_Cairo_Graphics_Driver.cxx
index 3d61bd6..ebe7c51 100644
--- src/drivers/Cairo/Fl_Cairo_Graphics_Driver.cxx
+++ src/drivers/Cairo/Fl_Cairo_Graphics_Driver.cxx
@@ -122,11 +122,22 @@ void Fl_Cairo_Graphics_Driver::rect(int x, int y, int w, int h) {
   surface_needs_commit();
 }
 
+static bool need_antialias_none(cairo_t *cairo_, int style) {
+  cairo_matrix_t matrix;
+  cairo_get_matrix(cairo_, &matrix);
+  double width = cairo_get_line_width(cairo_) * matrix.xx;
+  bool needit = (style == FL_SOLID && width < 1.5);
+  if (needit) cairo_set_antialias(cairo_, CAIRO_ANTIALIAS_NONE);
+  return needit;
+}
+
 void Fl_Cairo_Graphics_Driver::line(int x1, int y1, int x2, int y2) {
   cairo_new_path(cairo_);
   cairo_move_to(cairo_, x1, y1);
   cairo_line_to(cairo_, x2, y2);
+  bool needit = need_antialias_none(cairo_, linestyle_);
   cairo_stroke(cairo_);
+  if (needit) cairo_set_antialias(cairo_, CAIRO_ANTIALIAS_DEFAULT);
   surface_needs_commit();
 }
 
@@ -135,7 +146,9 @@ void Fl_Cairo_Graphics_Driver::line(int x0, int y0, int x1, int y1, int x2, int
   cairo_move_to(cairo_, x0, y0);
   cairo_line_to(cairo_, x1, y1);
   cairo_line_to(cairo_, x2, y2);
+  bool needit = need_antialias_none(cairo_, linestyle_);
   cairo_stroke(cairo_);
+  if (needit) cairo_set_antialias(cairo_, CAIRO_ANTIALIAS_DEFAULT);
   surface_needs_commit();
 }
 
@@ -477,12 +490,11 @@ void Fl_Cairo_Graphics_Driver::pie(int x, int y, int w, int h, double a1, double
   cairo_save(cairo_);
   begin_polygon();
   cairo_translate(cairo_, x + w/2.0 -0.5 , y + h/2.0 - 0.5);
-  cairo_scale(cairo_, (w-1)/2.0 , (h-1)/2.0);
+  cairo_scale(cairo_, w/2.0 , h/2.0);
   vertex(0,0);
   arc(0.0,0.0, 1, a2, a1);
   end_polygon();
   cairo_restore(cairo_);
-  surface_needs_commit();
 }
 
 void Fl_Cairo_Graphics_Driver::end_points() {
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'.