plutext/docx4j-ImportXHTML — pull request #3 by bsl-zcs (2013-07-20 20:18:31+00:00)
Title: Real units of measures via layout context

There are two approaches to deal with units of measures. The correct one is to get calculated values from flying saucer. The downside here is that many of its methods require a cssContext, which is unavailable for now. The simplest way I found to get it is to store the LayoutContext in a field in DocxRenderer#layout and provide a getter for it. Another, quick-and-dirty, approach is possible because of hardcoded DPI in DocxRenderer – we can recalculate the units manually, possibly ripping some code from LengthValue#calcFloatProportionalValue, for real-life borders it would be enough. Though it doesn’t permit us to use flying saucer’s convenient styles API, and some units (e.g. percentage or font-size driven) stay inconvertible.

As a change for providing access to layout context lies across sub-project boundaries, the decision is up to you. I personally tend to like the first approach more, because detailed layout information will be needed anyway when overall fidelity of conversion get increased enough to take into account more subtle things like margins and font properties.

There I duplicated DocxRenderer class in local package to demonstrate how it may look like.