[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

gEDA-cvs: gaf.git: branch: master updated (1.5.1-20081221-101-g508ab0f)



The branch, master has been updated
       via  508ab0fd9a1e4317ee660bc9eba79fcb49329841 (commit)
      from  ec83993b811eefd66d873f4c0f861f9cc6d9aebb (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.


=========
 Summary
=========

 gschem/include/prototype.h |    2 +-
 gschem/src/gschem_cairo.c  |   10 ++++++----
 gschem/src/o_arc.c         |   22 ++++++++++++++++++----
 3 files changed, 25 insertions(+), 9 deletions(-)


=================
 Commit Messages
=================

commit 508ab0fd9a1e4317ee660bc9eba79fcb49329841
Author: Peter Clifton <pcjc2@xxxxxxxxx>
Date:   Thu Jan 1 13:56:25 2009 +0000

    gschem: Attempt better hinted alignment when drawing arcs.
    
    gschem's canvas can have a fractionally different X and Y scale factor
    in some cases, which can cause misalignment of arcs drawn assuming the
    scale factors are uniform. This manifests because at high zoom levels,
    the center of an arc can be a large distance from the drawn stroke,
    over which distance the scaling errors magnify to give a visible offset.
    
    The other adjustment made here is rather than hinting the center of the
    arc to the pixel grid, we take the case where the arc forms a full circle,
    then find the center (in floating point screen coordinates) which would
    align the tangent of the arc at 0, 90, 180 and 270 degree positions, to
    lines hinted to the pixel grid at those positions.
    
    A 0.5px offset correction made in gschem_cairo_arc() to the arc center,
    for odd stroke width accounts for lining up the those tangents with
    the hinting which is applied to odd width lines in gschem_cairo_line().

:100644 100644 126728c... fabfa85... M	gschem/include/prototype.h
:100644 100644 756f971... 6c36ac9... M	gschem/src/gschem_cairo.c
:100644 100644 6211106... c4b0f40... M	gschem/src/o_arc.c

=========
 Changes
=========

commit 508ab0fd9a1e4317ee660bc9eba79fcb49329841
Author: Peter Clifton <pcjc2@xxxxxxxxx>
Date:   Thu Jan 1 13:56:25 2009 +0000

    gschem: Attempt better hinted alignment when drawing arcs.
    
    gschem's canvas can have a fractionally different X and Y scale factor
    in some cases, which can cause misalignment of arcs drawn assuming the
    scale factors are uniform. This manifests because at high zoom levels,
    the center of an arc can be a large distance from the drawn stroke,
    over which distance the scaling errors magnify to give a visible offset.
    
    The other adjustment made here is rather than hinting the center of the
    arc to the pixel grid, we take the case where the arc forms a full circle,
    then find the center (in floating point screen coordinates) which would
    align the tangent of the arc at 0, 90, 180 and 270 degree positions, to
    lines hinted to the pixel grid at those positions.
    
    A 0.5px offset correction made in gschem_cairo_arc() to the arc center,
    for odd stroke width accounts for lining up the those tangents with
    the hinting which is applied to odd width lines in gschem_cairo_line().

diff --git a/gschem/include/prototype.h b/gschem/include/prototype.h
index 126728c..fabfa85 100644
--- a/gschem/include/prototype.h
+++ b/gschem/include/prototype.h
@@ -284,7 +284,7 @@ int main(int argc, char *argv[]);
 /* gschem_cairo.c */
 void gschem_cairo_line(cairo_t *cr, int line_end, int width, int x1, int y1, int x2, int y2);
 void gschem_cairo_box(cairo_t *cr, int width, int x1, int y1, int x2, int y2);
-void gschem_cairo_arc(cairo_t *cr, int width, int x, int y, int radius, int start_angle, int end_angle);
+void gschem_cairo_arc(cairo_t *cr, int width, double x, double y, double radius, int start_angle, int end_angle);
 void gschem_cairo_stroke(cairo_t *cr, int line_type, int line_end, int width, int length, int space);
 void gschem_cairo_set_source_color(cairo_t *cr, COLOR *color);
 /* i_basic.c */
diff --git a/gschem/src/gschem_cairo.c b/gschem/src/gschem_cairo.c
index 756f971..6c36ac9 100644
--- a/gschem/src/gschem_cairo.c
+++ b/gschem/src/gschem_cairo.c
@@ -89,16 +89,18 @@ void gschem_cairo_box (cairo_t *cr, int width,
 }
 
 
-void gschem_cairo_arc (cairo_t *cr, int width, int x, int y,
-                       int radius, int start_angle, int end_angle)
+void gschem_cairo_arc (cairo_t *cr, int width, double x, double y,
+                       double radius, int start_angle, int end_angle)
 {
+  double offset = ((width % 2) == 0) ? 0 : 0.5;
+
   cairo_new_sub_path (cr);
   if (start_angle > start_angle + end_angle) {
-    cairo_arc (cr, x + 0.5, y + 0.5, radius,
+    cairo_arc (cr, x + offset, y + offset, radius,
                -start_angle * (M_PI / 180.),
                (-start_angle - end_angle) * (M_PI / 180.));
   } else {
-    cairo_arc_negative (cr, x + 0.5, y + 0.5, radius,
+    cairo_arc_negative (cr, x + offset, y + offset, radius,
                         -start_angle * (M_PI / 180.),
                         (-start_angle - end_angle) * (M_PI / 180.));
   }
diff --git a/gschem/src/o_arc.c b/gschem/src/o_arc.c
index 6211106..c4b0f40 100644
--- a/gschem/src/o_arc.c
+++ b/gschem/src/o_arc.c
@@ -44,7 +44,7 @@
 void o_arc_draw(GSCHEM_TOPLEVEL *w_current, OBJECT *o_current)
 {
   TOPLEVEL *toplevel = w_current->toplevel;
-  int x, y, radius;
+  int sx1, sy1, sx2, sy2;
   int line_width;
   COLOR *color;
   int length, space;
@@ -77,8 +77,6 @@ void o_arc_draw(GSCHEM_TOPLEVEL *w_current, OBJECT *o_current)
    * encountered the arc is drawn as a solid arc independently of its
    * initial type.
    */
-  WORLDtoSCREEN( toplevel, o_current->arc->x, o_current->arc->y, &x, &y );
-  radius = SCREENabs( toplevel, o_current->arc->width / 2 );
 
   if (toplevel->override_color != -1 )
     color = x_color_lookup (toplevel->override_color);
@@ -93,8 +91,24 @@ void o_arc_draw(GSCHEM_TOPLEVEL *w_current, OBJECT *o_current)
   length = SCREENabs( toplevel, o_current->line_length );
   space = SCREENabs( toplevel, o_current->line_space );
 
-  gschem_cairo_arc (w_current->cr, line_width, x, y, radius,
+  WORLDtoSCREEN (toplevel, o_current->arc->x - o_current->arc->width / 2,
+                           o_current->arc->y + o_current->arc->height / 2,
+                           &sx1, &sy1);
+  WORLDtoSCREEN (toplevel, o_current->arc->x + o_current->arc->width / 2,
+                           o_current->arc->y - o_current->arc->height / 2,
+                           &sx2, &sy2);
+
+  cairo_translate (w_current->cr, (double)(sx1 + sx2) / 2.,
+                                  (double)(sy1 + sy2) / 2.);
+
+  /* Adjust for non-uniform X/Y scale factor. Note that the + 1
+     allows for the case where sx2 == sx1 or sy2 == sy1 */
+  cairo_scale (w_current->cr, (double)(sx2 - sx1 + 1) /
+                              (double)(sy2 - sy1 + 1), 1.);
+  gschem_cairo_arc (w_current->cr, line_width,
+                    0., 0., (double)(sy2 - sy1) / 2.,
                     o_current->arc->start_angle, o_current->arc->end_angle);
+  cairo_identity_matrix (w_current->cr);
 
   gschem_cairo_set_source_color (w_current->cr, color);
   gschem_cairo_stroke (w_current->cr, o_current->line_type,




_______________________________________________
geda-cvs mailing list
geda-cvs@xxxxxxxxxxxxxx
http://www.seul.org/cgi-bin/mailman/listinfo/geda-cvs