zopefoundation/z3c.rml — pull request #1 by kylemacfarlane (2013-03-06 00:27:33+00:00)
Title: Fixes, forward references, evalString, and more

1) I added a `.gitignore` that ignores that files generated by tests? Maybe it should also ignore coverage files and `.pyc` files etc? I already have those as global ignores.

2) The version of `bootstrap.py` in the repo wouldn't run for me for some reason. I use buildout all the time with old bootstraps but maybe this one was just too old. I think it was some `setuptools` vs `distribute` thing so I put the newest bootstrap in to fix it.

3) There was then dependency hell when running buildout. I think `zd.receipe.scripts` is not compatible with buildout 2 or something like that. I just picked the first versions I could to install buildout without problems, and updated lxml while I was at it.

4) I then fixed up any failing tests. 1 or 2 were Windows specific, 5 or so were completely missing their expected PDFs, and some were just failing for other reasons.

5) TT and Type1 fonts weren't looking in packages for their files so I fixed that and added a test with a subsetted version of `MonoVera` (just the letter "A") to keep file size down. Maybe other font types need to be fixed too but I'm not sure how they load their files.

6) Fixed the table borders not printing or even appearing in some viewers.

7) I documented the `pageSize` vs `pagesize` difference on `template` and `pageTemplate` compared to RML2PDF. I then changed all the tests to also use `pagesize`. This way is backwards compatible unlike my other patch at launchpad. It may be confusing since it's still `pageSize` on the `pageInfo` element.

8) I improved performance by not applying a copy of the default style to every table cell and also by not even trying to initialise the attributes if lxml says they don't exist. I tried and failed to change `getAttributesValues()` to support this for all elements but it seems like the main slow down comes from way inside `zope.schema` so you can't even list the fields without hitting it. However, just fixing table cells give a big boost since it's easy to have a lot of them and they each have a lot of possible style attributes.

9) `namedString` now evaluates its contents so you can use things like `pageNumber` inside of it.

10) I implemented `evalString` using Python's `eval()` with builtins disabled. Maybe it should work the same way as elements like `doc*` elements but I don't quite understand what they're doing.

11) `getName` now checks if it has a `default` attribute. This is used as a width measurement for a first pass or as the actual value if the reference isn't resolved after the second pass. I originally had it erroring if it wasn't resolved after the second pass but returning the default instead is the behaviour I observed in `reportlab.platypus.para.Para` (this is not the same as the regular `Paragraph` flowable).

12) `getName` now supports forward references. I achieved this by inserting a dummy `IndexingFlowable` that asks for +1 pass if a name isn't defined, and then limited the number of passes to 2 (RML2PDF only does 2 passes max according to its docs). This means you can now do things like "Page X of Y". This only works in `drawString` and `para` and not everywhere that the official `rml.dtd` says that `%STRINGFORMS%` should be usable in, but that was already a problem. I did try to get it working in at least table cells where it would be most usable but the canvas isn't available yet so I'm not sure how.