Completion of Phase One

When I began working on phase one of my Google Summer of Code project, Inkscape’s unit handling code was scattered between multiple implementations with different files using different, incompatible implementations. I since consolidated this code into one implementation, residing in util/units.*, eliminating SPUnit, SPMetric, and unit-constants.h.

I also started to replace the SVGLength class but then changed my mind about doing so as the class is specific to the SVG specification, not general units. For example, common units, e.g. feet, are not part of the specification. I still may make it a child class of Util::Unit during phase two, depending on how I end up implementing things, but will leave it alone for now.

With these changes, I have consolidated Inkscape’s unit handling code, completing phase one of my Google Summer of Code project. Although there are only some minor user-facing changes, mostly bug fixes, the internal changes will facilitate the addition of user-facing changes both in phase two and beyond. As an example, pixels per inch are no longer hard-coded, so I plan on adding an option both in Inkscape preferences and document properties to configure the relationship between pixels and physical units early on in phase two. To begin phase two, I plan on hand-crafting SVG files with various types of unit configurations and then implementing support for them starting with a default document-wide unit.

Posted in | Tagged , , , | Leave a comment

Removal of SPUnit and SPMetric

As I have never used GTK+/gtkmm before, I spent a few days reading documentation to familiarize myself with the library, after getting stuck on transitioning parts of the UI to Inkscape::Util::Unit. With a better understanding of how the UI worked, I was able to make good progress and have completely eliminated SPUnit and SPMetric from the code base.

This leaves one significant section of unit code to port, SVGLength, which I hope to finish by the end of the week, as well as a couple other minor sections of code. I’m a few weeks behind schedule but hope to finish the refactor before the end of the month.

Posted in | Tagged , , , | Leave a comment

Refactoring Progress

Based on suggestions on inkscape-devel, I took a look at Boost Units. At first it looked promising, but then I decided it’s more trouble than it’s worth as it’s aimed at compile time dimensional analysis, and Inkscape only deals with distance anyway. However, I did use Boost Units’ naming scheme of calling a measurement with its unit a “quantity” instead of a “length,” as Inkscape also uses angles, not just lengths.

In addition, I began porting the code base away from helper/units.cpp. In the process, I fixed a bug that appears to have been there for years; the CSE paper size didn’t have units displayed next to it in the page size selector dialog. There were if statements checking if each paper size unit was millimeters, inches, or pixels and adding the units on. As CSE paper is Inkscape’s only paper size defined in points, its units weren’t displayed as there wasn’t a specific check for points. Now the page size selector just displays the unit’s abbreviation, no individual checks required.

Posted in | Tagged , , , , | Leave a comment

Length Class and Refactoring

Since my last update, I have implemented a Length class. This allows one to store a length with its unit as well as to perform unit conversions. These conversions include functions similar to those found in helper/units.cpp where a length, a “from” unit, and a “to” unit are specified as well as additional functions that allow conversions of the form length.value("to_unit"), where length is a variable of type Length and to_unit is the unit that one wants the value of the length in.

Over the past few days, I have been working on transitioning over from conversions using SPUnit and the conversion functions in helper/units.cpp to conversions using the new Length class. While I originally planned on working incrementally by converting one file at a time, the code is more interconnected than I originally believed, turning the porting of one file at a time to the porting of quite a few more at a time.

Posted in | Tagged , , , , | Leave a comment

Current State of Units

Inkscape’s main unit handling code is in helper/units.cpp and util/units.cpp. The code in helper is originally from libgnomeprint, and the code in util is the start of a rewrite; I plan on moving everything to util. In addition, there is separate code for handling units within an SVG file, for live effects, and for display, as well as a few other miscellaneous header files related to units. Based on these files, I have developed a list of major unit support requirements.

  • Listing units
  • Handling unit names and abbreviations
  • Unit conversion
  • Reading units from SVG files

To start, I plan on making the existing code more readable, then moving all unit handling into util/units.cpp, starting with the functions in helper/units.cpp.

Posted in | Tagged , , , | Leave a comment