pkgsrc-Users archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

editors/xournal patch for stylus/pen use on NetBSD



Dear pkgsrc users and developers,

Our wsmouse(4) drivers report absolute coordinate changes as an x-coordinate change
followed by a y-coordinate change. If a pen/stylus device is used with editors/xournal,
this leads to "steps", i.e. a horizontal line followed by a vertical line instead
of moving linearly to the new coordinate.

I have not observed the same behaviour in linux, so I guess linux is reporting
absolute x and y coordinates simultaneously. I have been using the patch below
for a few years to make notes and videos with pen(s) and it improves the visual
quality of my writing greatly. It treats coordinates from wsmouse as control
points for a Bezier curve, which smooths out the "steps" to a very large degree.
Since it is wsmouse specific, I am not sure such a patch belongs upstream.

I have been maintaining the patch locally for years, but perhaps some other users
would benefit. If there is interest and agreement, I can commit the patch. I have
a similar patch for wip/xournalpp (well, for the latest nightly version).

-- 
Kind regards,

Yorick Hardy

$NetBSD$

This patch works around the "steps" seen when using a device which
reports absolute coordinates on NetBSD, by using a Bezier curve to
obtain a smooth path which approximates the motion. This is only
seen with rapid movements.

--- src/xo-paint.c.orig	2015-08-11 03:47:11.000000000 +0000
+++ src/xo-paint.c
@@ -248,7 +248,7 @@ void create_new_stroke(GdkEvent *event)
 void continue_stroke(GdkEvent *event)
 {
   GnomeCanvasPoints seg;
-  double *pt, current_width, pressure;
+  double *pt, current_width, pressure, d, dp, t;
 
   if (ui.cur_brush->ruler) {
     pt = ui.cur_path.coords;
@@ -280,7 +280,21 @@ void continue_stroke(GdkEvent *event)
     ui.cur_path.num_points++;
   }
 
-  seg.coords = pt; 
+  if(ui.cur_path.num_points < 3)
+    return;
+
+  // treat this point as an end point
+  // treat the previous point as a control point and recalculate the "actual" point
+  dp = hypot(pt[0] - pt[-2], pt[1] - pt[-1]);
+  d = dp + hypot(pt[0] - pt[2], pt[1] - pt[3]);
+  if(d != 0) {
+    t = dp/d;
+    // Bezier curve fitting
+    pt[0] = (1-t)*(1-t)*pt[-2] + 2*t*(1-t)*pt[0] + t*t*pt[2];
+    pt[1] = (1-t)*(1-t)*pt[-1] + 2*t*(1-t)*pt[1] + t*t*pt[3];
+  }
+
+  seg.coords = pt-2; 
   seg.num_points = 2;
   seg.ref_count = 1;
   


Home | Main Index | Thread Index | Old Index