Variable thickness lines more beautiful
Brought to you by:
andreasb123,
auroux
Variable thickness lines looked more pretty in inkscape than in xournal. (In particular, ends of lines "thin out" more beautifully.) I fixed this. More precisely:
xournal now does takes into account the pressure at the end of a stroke. (This alone produces ugly thin lines at the end of strokes.)
Line width now varies continuously. (This is done by drawing a little trapezes instead of line segments.)
Side effects:
PS: All this has almost not yet been tested.
PPS: This time I used the newest version of xournal to do modifcations. ;-)
I have not tested carefully, but I have two concerns:
Performance: Xournal uses a lot of system resources (CPU, RAM, etc.)
when editing files with say over 20 pages of handwritten notes, and
variable-width comes with a huge performance cost over fixed-width
already. Replacing lines by filled polygons (and ellipses on top of
that??) seems to me like it would incur another large performance cost
-- did you try to compare performance on a large file with lots of
handwriting in it? We don't want it to become something that only works
on the latest hardware and unusable on low-end tablet PCs from 5 years ago.
File format: I really want the nominal brush width to be present in
the stroke data at the beginning of the "width" field. This is needed
for a planned change that will allow the thickness buttons to modify the
width of variable-width strokes properly, by rescaling them relative to
the nominal brush widths -- so you can change a variable-width thin
stroke to a variable-width thick one e.g. as if it were drawn with the
thick pen in the first place.
Given this, I think you can make things work with even less of a
change to the file format -- the parser in xo-file.c could simply
recognize once the stroke element is finalized whether the number of
entries in the width attribute is 1 (constant width), number of points
(current variable-width, which I'm not sure needs much conversion except
to add maybe a 0 at the end or duplicate the last entry?), or still 1
more (your version, since you have one more width data point).
Denis
Attached is a new version of the patch. The main change is some optimization with huge performance gains: On big and complicated files, the patched version of xournal (with more beautiful lines) now is a lot faster than the unpatched one (without beautiful lines). The way it works:
A similar strategy is also used when creating pdf files. (And moreover, I changed the way trapezes are drawn; this makes the discs unnecessary in the pdf.) Result: pdf files of the new version are slightly bigger than previously (10%-20%), but they seem to open somewhat quicker in evince.
Concering the file format: I changed the way the widths are stored, so that the brush thickness is not lost. In the new file format, there are two attributes: "width" contains the brush width, and "widths" (which only exists for variable width lines) contains the widths of the line. (The old way to store widths is still supported when loading files.)
(One could also put "width" and "widths" togehter, but having them separate feels cleaner to me.)
Addendum: With the new file format, the old version of xournal cannot open files generated with the new xournal anymore. It should be possible to make the new files readable by the old xournal, but at the cost of making the file format more messy. I don't know whether that's worth it.
What I have in mind is: store the brush width in an attribute called "brush-width" and store the line widths in the attribute "width". Additionally, for fixed-width brushs, let "width" also contain the brush width.
This has one draw-back: If one creates a file with new xournal, opens it with old xournal and saves it again, then then the correct brush width gets lost.
Another addendum: xo-misc.c contains a few commented-out lines ending in "// profiling..."; commenting these in will generate some statistics about the optimizations of variable-width lines. (Total number of segments, number of strokes drawn; number of trapezes drawn)