Menu

#82 Variable thickness lines more beautiful

Unstable_(example)
open
nobody
None
5
2016-04-10
2016-02-21
No

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:

  • I guess the pdf files produced by xournal become bigger (maybe twice as big?)
  • The files of old and new xournal are not 100% compatible. More precisely, both versions of xournal can read both versions of files, but the new version needs to know whether a file has been created by an old or new xournal, since the line thickness data in old files is not correct. To make this possible, the new files have a "with-line-ends" attribute in the "<xournal>" tag. (That's a temporary solution for me, as long as this feature is not part of the official xournal. If one would make it official, one should probably just check for the version number in the file instead.)

PS: All this has almost not yet been tested.

PPS: This time I used the newest version of xournal to do modifcations. ;-)

1 Attachments

Discussion

  • Denis Auroux

    Denis Auroux - 2016-02-21

    I have not tested carefully, but I have two concerns:

    1. 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.

    2. 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

     
  • Immanuel Halupczok

    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:

    • Draw trapezes only when the widths at the two ends of the segment differ by at least 20%. This already makes xournal almost as fast as it was previously
    • If several segments in a row have widths differing by at most 20%, then draw them in one stroke. This is what makes xournal a lot faster than before.

    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.)

     
  • Immanuel Halupczok

    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)

     

Log in to post a comment.