ngmsoftware / will2svg

Python program that reads Wacom WILL file and converts it to SVG.
9 stars 5 forks source link

Incomplete Paths on Intuos Pro Paper WILL Files #3

Open ristflo opened 4 years ago

ristflo commented 4 years ago

I noticed a problem with paths from the Intuos Pro Paper Edition tablet. It seams that interpreting the path description in the WILL file as a list of control points of a Cubic Bézier curve is not correct. My impression is that it’s actually just poly-line and fitting a curve through the points would have to be done by the converter. The fact that pressure information is stored for all points makes this more plausible than the Bézier interpretation. This would change the processing of the pint list at line 89 to something like this:

        svgStr += f' L'
        for x, y, idx in zip(arrayX[1:], arrayY[1:], idxr[1:]):
            svgStr += f'{x} {y},'

Anyway, thank you very much for publishing this. Right now it’s the only way for me to get sketches from my new Paper Edition tablet to Illustrator as vectors because the Inkscape App is not working properly. Did you do any work on the line thickness already? If I understand the SVG specification correctly a varying path width is not supported, so a different file format would be required (EPS?). I’ll attach a WILL file from my Intuos Pro Paper Edition, just in case you want to look into the issue. will_file_from_intuos_pro_paper.zip

martinsallandm commented 4 years ago

Hello,

You're welcome. I only have experience with the WILL file from Wacom but your comment about having only a sequence of points looks familiar to me. I remember thinking something like that when I extracted the data. But I think the point is that if the points are multiple of 4 in quantity, then can be viewed as coordinate points followed by control points to fit a bezier or spline (I think).

Thanks!

[]'s

On Sun, Jun 21, 2020 at 2:54 PM ristflo notifications@github.com wrote:

I noticed a problem with paths from the Intuos Pro Paper Edition tablet. It seams they miss the last control point under some circumstances. This results in an invalid SVG path with a ‘curveto’ command with only two instand of three points specified at the end. Illustrator will just ignore these paths on import. For such a path it is necessary to use the ‘shorthand’ or ‘smooth curveto’ command for the last point of the path. A quick and dirty fix is to test if the path is lacking one point and then inserting the ‘S’ command by adding this at line 90:

        if idx==(len(arrayX)-len(arrayX)%3):

            svgStr = svgStr[:-1] + f’ S’

Now, as far as I can see, all path from my Intuos Pro Paper are visible in Illustrator, however I’m not 100% sure if my assessment of the problem and the proposed solution are correct, I did not look into the WILL file specifications, the Wacom SDK or perform extensive tests. Actually, I have some doubts whether interpreting the path description in the WILL file as a list of control points of a Cubic Bézier curve is correct. My impression is that it’s actually a poly-line and fitting a curve through the points would have to be done by the converter. The fact that pressure information is stored for all points makes this more plausible than the Bézier interpretation. Anyway, thank you very much for publishing this. Right now it’s the only way for me to get sketches from my new Paper Edition tablet to Illustrator as vectors because the Inkscape App is not working properly. I’ll attach a WILL file from my Intuos Pro Paper Edition, just in case you want to look into the issue. The first three paths are the numbers ‘1’, ‘2’ and ‘3’. ‘1’ and ‘2’ show the described ‘missing point problem’, ‘3’ converts fine with the existing code. will_file_from_intuos_pro_paper.zip https://github.com/ngmsoftware/will2svg/files/4809970/will_file_from_intuos_pro_paper.zip

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/ngmsoftware/will2svg/issues/3, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACEY4UJY7A5HMWG7J2JX433RXZCMZANCNFSM4OD6UE2Q .

ristflo commented 4 years ago

Hi, I’m also talking of WILL files from Wacom, just from a different tablet, in my case a Intuos Pro L Paper Edition, model PHT-860. And on this tablet the point list contains not only multiples of 4 entries but any number. This leads me to believe that ist a polygon and further processing would be good. A (old) algorithmischem is describe for example by Schneider in Schneider, P. J. (1990). "An Algorithm for Automatically Fitting Digitized Curves." in "Graphics gems." San Diego, CA, USA: Academic Press Professional, Inc: 612-626. There are better curve fitting algorithms out there but even this would be by fare better than anything that Wacom give us.

The biggest problem however is figuring out a nice way to get the thickness information to other programs.

martinsallandm commented 4 years ago

Hello,

yes, you are right. If you think about it, its like a "raw" storing of the data from the tablet. The tablet doesn't care about the curve fitting algorithm. What it can do is to sample the points where the pen passes (together with the pressure). So, indeed, it must be a polygon. The algorithm is up to the user.

[]'s

On Tue, Jun 23, 2020 at 1:36 PM ristflo notifications@github.com wrote:

Hi, I’m also talking of WILL files from Wacom, just from a different tablet, in my case a Intuos Pro L Paper Edition, model PHT-860. And on this tablet the point list contains not only multiples of 4 entries but any number. This leads me to believe that ist a polygon and further processing would be good. A (old) algorithmischem is describe for example by Schneider in Schneider, P. J. (1990). "An Algorithm for Automatically Fitting Digitized Curves." in "Graphics gems." San Diego, CA, USA: Academic Press Professional, Inc: 612-626. There are better curve fitting algorithms out there but even this would be by fare better than anything that Wacom give us.

The biggest problem however is figuring out a nice way to get the thickness information to other programs.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/ngmsoftware/will2svg/issues/3#issuecomment-648277745, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACEY4UIOH45B46VYXU7FKSDRYDKXPANCNFSM4OD6UE2Q .

v217 commented 4 years ago

Hi @ristflo maybe you could pull request you modifications e.g. the single thickness poly-line in a separate file? Thanks

ristflo commented 4 years ago

Hi V217

maybe you could pull request you modifications

I just created the pull request for this very small modification of creating polylines not Beziers. These polylines usually have a very large number of nodes, but they can be cleaned-up nicely in Illustrators by using the Path/Simplify... command.

And I included a test .will file from my Intuos Pro Paper.

v217 commented 4 years ago

Hi @ristflo @allanninguem Great! Thank you for your pull request! I am not the owner of the repository but maybe you could just add the poly-line files as separate copies so people have both options Bezier and Poly-line? Even though I understand your reasoning that in most graphics programs it's easy to convert a poly-line to a Bezier curve I am in favor of separate files and not options so a single person can easily read the code and modify it? Probably someone will find an interesting way how to deal with changing line thickness in a third modification/group of files. Thanks!

v217 commented 4 years ago

@ristflo e.g. just copies of the poly-line versions:

code/will_reader_polyline.py
code/will_reader_slate_A4_polyline.py
code/will_reader_slate_A4_cairo_polyline.py

and the test .will file from the Intuos Pro Paper. Thanks!

martinsallandm commented 4 years ago

All,

I dont see any new pull request. I accepted one a couple of weeks ago, is that the one you are talking about?

[]'s

On Fri, Jun 26, 2020 at 2:40 PM v217 notifications@github.com wrote:

@ristflo https://github.com/ristflo e.g. just copies of the poly-line versions:

code/will_reader_polyline.py code/will_reader_slate_A4_polyline.py code/will_reader_slate_A4_cairo_polyline.py

and the test .will file from the Intuos Pro Paper. Thanks!

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/ngmsoftware/will2svg/issues/3#issuecomment-650308608, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACEY4UNJCVHU76EF63VTDNLRYTMRXANCNFSM4OD6UE2Q .

ristflo commented 4 years ago

Hi allanninguem, sorry for the confusion, I closed the pull request again, after reading v217 suggestion to keep both possibilities, the spline and the polygon version. I'll add a command line parameter (-p/polygon) and submit a new pull request.

Flo

martinsallandm commented 4 years ago

Ok! No problem!

On Sat, Jun 27, 2020 at 2:03 PM ristflo notifications@github.com wrote:

Hi allanninguem, sorry for the confusion, I closed the pull request again, after reading v217 suggestion to keep both possibilities, the spline and the polygon version. I'll add a command line parameter (-p/polygon) and submit a new pull request.

Flo

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/ngmsoftware/will2svg/issues/3#issuecomment-650586460, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACEY4UNU325IK74J63VCOE3RYYQ6NANCNFSM4OD6UE2Q .

ristflo commented 4 years ago

Hi v217

It seems that the will format stores the the strokes not as polylines but as Catmull-Rom splines.

Thanks for looking this up and for posting the link.

I'd still consider the polygon to be the better solution, for now, at least the polygon, just like the Catmull-Rom spline passes through all pints. However it makes sens to assume that the pen motion is better approximated by fitting some curve though the captured points - for example a Catmull-Rom spline.

Unfortunately SVG does not seem to support Catmll-Rom splines so to get the same curve one would have to convert it to a Bezier Spline by calculating the control point positions. I didn't really think about it yet, but is should be easy to do so.

See you Flo