Skip to content
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

Support cross references by target-counter()/target-counters() #248

Merged
merged 24 commits into from
Jun 8, 2016

Conversation

kwkbtr
Copy link
Contributor

@kwkbtr kwkbtr commented Jun 8, 2016

kwkbtr added 24 commits June 1, 2016 21:15
- `target-counter()`/`target-counters()` support for counters on elements, i.e., defined by `counter-reset`/`counter-increment` specified on elements.
- Page-based counters are not yet taken into account in this implementation.
- `attr()` function cannot be used inside `target-counter()`/`target-counters()` yet.
- If target element is in a source document other than the current one (on which `target-counter()`/`target-counters()` is specified), the target counter cannot be retrieved and fallback to 0.
…vliostyle.counters.CounterStore`

- `adapt.csscasc.PageCounterResolver` interface has been removed. Its methods are merged into `adapt.csscasc.CounterResolver`.
- `vivliostyle.page.PageCounterStore` class has bee removed. Its functionalities are merged into `vivliostyle.counters.CounterStore`.
…ounters

- Only effective for a target ID such that the corresponding element is already laid out before the referring pseudoelement (i.e. the pseudoelement on which `target-counter()`/`target-counters()` is specified)
…the target element is laid out

- Added `vivliostyle.counters.TargetCounterReference` class. If no element-based counter id defined on the element specified by ID in `target-counter()` and the element has not been laid out yet, a `TargetCounterReference` object is saved in `CounterStore`.
- When finishing layout of a page, elements with IDs and unresolved references that appeared on the page are collected. After that, it is deteremined that whether any unresolved references appeared so far can be resolved by the elements with IDs in the page. If there are any, each page containing such references are re-laid out, calling `renderSinglePage` method recursively.
 - Note that in this commit only a single page is re-laid out at a time, i.e., even if the end position of the page is changed as a result of the re-layout, the next page is not re-laid out.
- TODO: take unresolved element-based (non page-based) counters into account (when the referenced element is in another source document in EPUB)
- TODO: support `target-counters()` too.
- TODO: control visibility of the re-laid out page appropriately.
If an element with an ID does not fit in a page, the view node is removed and deferred to the next page.
However, the ID and the element are registered to an `adapt.vtree.Page` object during creation of the view node and the regitration has not been removed even if the element does not fit in the page.
This has been causing incorrect page references.
In this commit, the registered IDs are checked after layout of the page.
If the page container does not contain an element (elements) corresponding to a registered ID, the registration of the ID is removed.
… source document in EPUB and does not have a fragment
…s reference resolution *only if the next page has been already laid out*
…rence resolution

If a reference target is allowed to go back to a page earlier than one on which it was placed previously, reference resolution can lead to an infinite loop.
To avoid infinite loops, a reference target is allowed to go to a page later than one on which it was placed previously, but it is not allowed to go back to an earlier page.
If the target can fit in an earlier page, a page break is inserted just before the target and the target is laid out on the page on which it was placed previously.

To represent the influence reference resolution has on layout, `adapt.layout.LayoutConstraint` interface is introduced.
`allowLayout` method of `LayoutConstraint` receives a `NodeContext` and returns whether it can be laid out at the current position.
In this case, a `NodeContext` is not allowed to be laid out at the current position if the page index of the current position is earlier than the index of the page on which the target was placed previously.
@kwkbtr kwkbtr merged commit e3af108 into master Jun 8, 2016
@kwkbtr kwkbtr deleted the target-counter-r#131 branch June 8, 2016 12:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant