svg2pdf and svg2eps (convert svg to pdf or eps from the command line)

I’ve been working on a new makefile for my latex projects. The goal is to have single-source builds of dvi, pdf, and xhtml documents. I ran into a problem of generating figures. latex expects eps graphics, pdflatex expects pdf figures, and latexml expects png figures (or will try to generate them). In order to generate documents with make, I need a way to generate eps and pdf figures from svg sources (I usually use inkscape to make my figures). Inkscape can be run from the command line, but I dont want to install inkscape on my server because that will require installing a ton of libraries that don’t make sense to have on a server with no graphical interface.

As it turns out, writing such a command line tool is very easy with librsvg and cairo. Carl Worth of redhat has produced a nice demo of svg2pdf which can be found at freedesktop.org. I cloned his project, create a cmake project out of it, and made a trivial modification to turn it into svg2eps as well.

You can find my code at git://git.cheshirekow.com/svg2x.git and there’s some doxygen documentation Doxygen documentation.

3 Comments

Throw: A Compiz Plugin

One feature that I’ve really been wanting from compiz is to give windows a bit of momentum when I’m moving them around. In other words, if I flick a window with the pointer and then let go, I want it to continue moving, so that it can be “thrown” across the screen. Thankfully, someone involved in compiz wrote such a plugin, found on his blog here. Unfortunately, the strategy that he uses doesn’t work well for me. There are essentially three problems with it:

  1. In order to calculate the velocity of the window after it is released, he compares the window position at the time it is released to the window position at the time it was grabbed, and calculates the delta. This leads to weird behavior when the users is indecisive and moving the window around sporadically before releasing it.
  2. The velocity of the window has an unnatural association to the actual “velocity” that the user was moving it with.
  3. The velocity appears to be zero when using a pen-tablet (wacom) input because my hand generally stops before the pen moves out of range of the tablet.

While the compiz API documentation is in a very sad state, Sam’s plugin showed me all the parts of the API that I needed. I rewrote the plugin to essentially low-pass the velocity of the window, sampled at the compiz frame rate. At each “movement” event, I update the delta in the x direction and the y direction. At each “frame” of compiz, I bake the accumulated deltas, along with the time (in ms) since the last sample. The accumulated deltas and the number of milliseconds are stored in a ring buffer. When the window is released, the buffer is averaged to get a window velocity in pixels-per-millisecond.

I also augmented the window structure to store a floating point representation of the window location. Together with the low-pass on the velocity, the outcome seems to be a lot smoother.

The window velocity exactly matches what I “feel” like the velocity of the window is when I let go of it. Also, the filter only has enough history for a couple of frames so weird movement of the window prior to release is “forgotten”, and only the “most recent velocity” is used.

The code for the plugin can be found in my redmine

No Comments

Ubuntu Stopwatch Applet

It has occured to me several times that I would like to have a small stopwatch utility with quick access (particularly for time tracking on various projects). I figured the Ubuntu timer applet would have this function, but alas, it did not. To my surprise, there wasn’t any applet in the ubuntu repositories that does this. I decided it would be sufficiently useful to look into writing one myself. As usual, documentation was pretty sparse but I managed to find a good starting point and cobbled together a simple proof of concept. I’d tell you how much time it took, but I didn’t have a handy stop-watch applet for me to time myself.

You can find the code in my redmine here. Compile with gcc or just run make.sh (it’s only one line). The .server file needs to go in /usr/lib/bonobo/servers. It also needs to be edited to point to wherever it is that you put the binary. After moving it, log out and then back in. Right click on the panel you want to add it to and select “add to panel”. You should see “Stopwatch Applet” in the list.

Add To Panel

Add To Panel Dialog

It’ll drop the simple applet on your panel. The applet steals the “timer-applet.png” image from the timer applet package so you might need that in /usr/share/pixmaps in order for the entry to show up in your list of available applets. The applet looks like this:

Panel

The Stopwatch Applet

There are basically no features. It starts counting when it’s loaded. You can click on it to reset it. I do have some planned improvements for when I get around to it.

  • Ability to control multiple timers from one instance
  • Ability to choose which timer is displayed in the panel
  • Ability to pause/lap/resume by clicking on it (configurable)

Also, just in case you were wondering, I spent a total of 23 minutes and 49 seconds on putting this code in version control, adding the project to redmine, and writing this post.

3 Comments