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.
Python's tempfile.mkstemp already opens files, we don't have to open
them twice. The documentation is not really clear about that but
there's a good post on Logilab's blog: https://www.logilab.org/17873Fix#396.
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.
As Pango keeps the extra trailing spaces when it splits lines, we try to
add the next word of the second line to the first line without its
trailing spaces and see if it fits. If it doesn't, we have to update
resume_at as we have split the first line at a position that may be
different from what Pango did earlier.
Fix#389.
That's how it used to work before 412aeb4, but it was replaced by font
metrics for performance issues. Font metrics seems to work well in most
cases, but it fails at least with Ahem for unknown reasons, as the
metrics defined in the font seem pretty good everywhere.
The new code introduced in this commit creates the line (as it was done
before), but doesn't go through the whole line-breaking layout as
there's no text. There's no visible performance loss.
Instead of using split_text_box, we can only call the faster
split_first_line instead.
This commit also copies the style before updating the word spacing,
avoiding a bug introduced in this branch now that the style is shared
across the lines.