This forces to use a copy when changes are needed. Internal mutable structures
have also been changed into immutable ones (i.e. lists have been turned into
tuples).
This change is a really useful first step to greatly optimize memory and time
needed to render large documents, as allows us to cache style dicts more
safely. It's been already done in StyleDict.inherit_from, with a ~5-10% memory
benefice.
Style is not copied anymore when boxes are duplicated. Style dicts are not
modified anymore during the layout, as it was before for some properties:
- margins, borders and paddings when the box was split between two
pages (useless as these computed values are stored directly in the box),
- top borders were changed in tables (useless for the same reason),
- bookmark labels and string sets are now stored in the box.
This commit can introduce very subtle bugs that are hard to debug. In the
future, we should try to freeze the style dicts before the layout.
Related to #70.
As ::first-letter depends on white space handling, we must create the
box after collapsing spaces, not during the build of the box tree.
This commit makes WeasyPrint pass most of the W3C tests related to
first-letter (and never crash). Known problems left include:
- list markers are considered as the first letter,
- lines may break between the first letter and the rest of the text
(see #163 and #301),
- the CSS attributes are all kept, some should probably be removed (the
spec doesn't give a whole list).
Even if W3C tests makes me quite confident (some of them are crazy),
tests must be added in WeasyPrint too.
The pseudo-element is currently added at the end of the build, but it
should be done during the layout as the whitespaces at the beginning of
the tags may be skipped.
- Put line breaks after operators (that's OK)
- Don't assign lambdas, use functions (well, that's really explicit in
PEP8, it's really verbose but why not)
- Put imports at the beginning of the file (only special cases for us)
In this content-list, here are the possibilities:
- string: implemented
- counter/counters: not implemented, but easily possible
- content: implemented (but what's exactly the "string value of an element"?)
- attr: not implemented (I don't know how to do this)
Reinstate support for psuedo elements as an arugument to `content()`
Have to check if a box is a `ParentBox` when using `decendants()` in `TEXT_CONTENT_EXTRACTORS` for psuedo elements because it was returning the value twice in a row (ex. "stringstring")
Alter TEXT_CONTENT_EXTRACTORS so that string-set can use ::before/::after
- Don't allow empty string to be assigned to string set (happends with psuedo elements)
Added some documentation to explain string function resolution