We have made many afforts to draw paper tapes on computer screens. This subproject is surely one of the biggest and most complex programs in the complete paper tape project. It hasn't be simply written down in some days but has gone throught various development generations, from simply two C files up to the current bunch of a dozen C++ files. This is the structure we are targetting:
The files lochstreifen.c and lochstreifen.h implement the
drawing of paper tapes by using the cairo graphics library.
These routines only need cairo, so they can be compiled
by using `pkg-config --cflags --libs cairo`. They do not
need neither GTK nor Glib (this is a special feature! :-) )
The routines only implement the drawing routines - the
cairo object (cairo_t) must be given from the implementing
programs. In this way you have full freedom to choose a
cairo surface -- among others PNG, SVG, PDF, ...).
See lochstreifen.h for the structure of the object
`LOCHSTREIFEN'. See lochstreifen.c for help with the usage
of the functions.
There are two generations of this file: The one before I learned that there's a standard for paper tapes and the one after I learned that there's such a standard, called ECMA 10. When I read about this ECMA standard, I've rewritten the routines completely, cleaning the programming interface and making it more flexible and robust. The new code is stable right now.
Features of this library:
LOCHSTREIFEN *papertape = lochstreifen_new(); printf( "%d", lochstreifen_get_width(papertape) ); lochstreifen_set_d(papertape, 42); int dir = lochstreifen_get_orientation(papertape); lochstreifen_draw(papertape, cairo_context); // ...
The file cli.c uses the LOCHSTREIFEN structure directly. It only depends on the two lochstreifen.c/h files. For argument parsing, it uses the argp.h, from the GNU C library. Unfortunately argp.h doesn't seem to be present in other c librarys, that's still an issue. Apart from that the CLI program is complete platform independent and only has to be linked against libcairo: gcc cli.c lochstreifen.c `pkg-config --cflags --libs cairo`.
Features of the command line frontend:
We actually have developed a web frontend in PHP which uses
the command line interface to generate the results. It
recieves the user input by an huge HTML form. Using a lot
of AJAX magic, it even caches already created images and
creates reports which contain the input data and all
settings and which are finally available for the client.
To avoid denial of service attacks (DoS), the PHP frontend
will deny creating paper tapes if the input file exceeds
some MB because the resulting file will be very big
(most web browsers reject rendering such big files which are,
for example, 400.000px in width).
This progam is an own sub project, see
../web-frontend/ for the
sources and it's documentation.
The library GtkPaperTape is a typical and unexpected result of the growth of the complete program. Whereas the GTK visualisatoin frontend initlally consisted of only one C file (corresponding to cli.c), gtk.c, it rapidly got very big and confusing so I decided to write divide the sourcecode into a Gtk+ widget, called GtkPaperTape and the program around it, still called gtk.c. Well, I developed this widget, and it got even much bigger than the former gtk.c program (about 1200 lines pure C and Glib code). There occured quite some problems (the sourcecode was badly maintainable and confusing, and there wer some drawing bugs that I could not solve), but the program was working quite fine.
Well, there was the issue about the Windows version and the
implementation of punching/reading features. This made the
things much more complex, as it requires more features from
both LOCHSTREIFEN and GtkPaperTape. I therefore
decided to learn C++ and Gtkmm to produce a new program from
the scratch with a cleaner interface and a better documentation.
As was only to be expected, the sourcecode is now much more
bulky, we have now more than a dozen Cpp/header files with
more than 2400 lines of code (still growing). The third generation
of the GtkPaperTape is still supposed to be called
GtkPaperTape, but uses the gtkmm namespace Gtk,
so it's actually Gtk::PaperTape.
There's a meta header file, gtkpapertape.h. Include
this file when you want to use the GtkPaperTape widget.
This is an overview of the features of the current generation of GtkPaperTape:
There is still a bug while scrolling over really big paper tapes, but I've managed to get solved who's the guilty library: It's a Gtk+ bug, commited on the GNOME bugzilla by me.
Compared to the widget, there's a quite trivial and simple frontend programm called gtk.cc that replaces the old gtk.c.