-
-
Notifications
You must be signed in to change notification settings - Fork 710
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
introduce TARGET_COLLECTOR for target-counter, -counters and -text #572
Conversation
Thanks a lot for your contribution! The overall logic is OK and there's a lot of interesting code in this PR! The main problem is the use of global variables, because it's not safe when WeasyPrint's used to render multiple documents as a library. I'll merge it in a separate branch, clean a couple of things and add tests (and check the W3C testing suite). Thanks again! |
Don't like the global variable either. When assimilating the source code I often was tempted to create something like the Concerning counter manipulation in |
This PR, besides being just a raw proof of concept, makes the At the moment the validation of content and strings and the layout/computation of involved elements is done by different functions, doing almost the same. Volunteering to eliminate the redundant code, I'm uncertain: Shall I wait until you merged and cleaned up my PR or would you like me to do that beforehand or do you prefer to do it by yourself? |
You can update the PR, I'll merge it as soon as you feel it's ready to be cleaned. |
caused by wrong parameters for LOGGER.debug -- relicts from using print()
Ok. Gimmi a few days... |
Modified function `validate_content_list_token()` in weasyprint/css/validation.py so that it can be used to validate the css properties `content`, `string-set` and `bookmark-label`.
OMG! I really hate this nitpicking Travis! |
Preparation for code-reduction in the box-building steps and allowing target-*() not only in `content` but also in `string-set` and `bookmark-label`. Therefore weasyprint/css/computed_values.py now computes the `<content-list>`s of `string-set` and `bookmark-label` in the same way as it already does for `content`.
What's wrong with "dejavu.tar.bz2" in Travis Build Job for OSX? BTW: The WeasyPrint unit test suite isn't suitable for my Win64 Laptop, running with 120 dpi screen and having no "ahem" font. Indeed, I was shocked, when pytest reported "32 failed" for the first time... |
The Sourceforge site is currently in "Disaster Recovery mode" (sic), static files cannot be downloaded anymore without JavaScript. If the problem doesn't disappear soon, we'll have to change the testing script to download it from somewhere else.
The 120 dpi screen shouldn't be a problem or it's a bug. Ahem needs to be installed, we could use |
With Ahem installed only 22 tests fail (instead of 32). Most errors seem to originate from
Python is Python 3.6.4 (v3.6.4:d48eceb, Dec 19 2017, 06:54:40) on Windows (64 bits). |
You can try to update cairo to the current unstable version (1.15.10) and see if it fixes the problem. (I don't know how to do this, or even if it's easily possible.)
If you almost always get the same error, having one traceback ending with |
In the box building and page layout steps, the CSS properties `content`, `string-set` and `bookmark-label` now use the same code to evaluate their <content-list> values. As a concequence the target-* functions work for all three properties.
Next step should be the replacement of the global TARGET_COLLECTOR with something multi-thread-safe. Promoting a local instance through all the functions called during box building and layout is a fiddly task. I guess, my 10 fingers won't be enough to count all the The only sensible solution I can think of -- making the whole formatting thing an object-oriented job of the |
Ok. Will create an issue and try my luck with Cairo. |
Replaced by #604. |
See #23 -- implements target-counter, target-counters and target-text. But (due to the current limits of WeasyPrint) a TOC-with-page-numbers is not included...
After at least 5 different approaches (oh my! Python is not my favorite language!) I eventually came up with a
TARGET_COLLECTOR
-- new moduleweasyprint.css.targets
-- which is prepared byanchor()
andcontent()
incss.computed_values
.In
formatting_structure.build
the anchor elements callTARGET_COLLECTOR.store_target()
to store theircounter_values
in theTARGET_COLLECTOR
and the pseudo-elements callTARGET_COLLECTOR.lookup_target()
to fetch them.If the target comes later in the document -- aka `PENDING' -- the creation of the content box is suppressed. Instead the stuff required to create it later is kept.
Finally
TARGET_COLLECTOR.check_peding_targets()
is called to fill thePENDING
content boxes.The fist step of course was impelmenting the
target-*
tokens incss.validation.validate_content_token()
.There is not (yet) a unit test...in the meantime you may run it with
LOGGER.setLevel(logging.DEBUG)
Tried my best to conform to the coding style of WeasyPrint, not shure whether I succeeded...