Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ The release run heads these entries with the version and opens a fresh
and a deck of 600 slides after 150 ms, not 570 ms.
`HtmlConfig::lazy_layout` (on by default, also in the bindings) turns
this off.
- The npm package takes `lazyLayout` in its html config too.
- The find of the browser does not reach a part that is far from the
viewport, but `odr.search` does. A host that offers the find of its web
view needs `odr.search` instead, or `lazy_layout` off
Expand Down Expand Up @@ -68,6 +69,9 @@ The release run heads these entries with the version and opens a fresh
give the final count.
- `odr.search` no longer finds the row numbers and the column letters of a
sheet, because they label the cells and are not their content.
- The HTTP server looks up the linked files of a pdf under a lock of their
own. A render of another view of the same pdf added to that list while it
was read, which could crash the server.
- With `HtmlConfig::embed_images` off, an image loads once the reader comes
near it (`loading="lazy"`), so a page fetches 3 of the 187 images of a
long docx at the start. A print still shows every image.
Expand Down
5 changes: 3 additions & 2 deletions apple/include/OdrCoreObjC/ODRHtml.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,10 @@ NS_SWIFT_NAME(HtmlConfig)
/// The zoom the view opens at, 1 being actual size; `nil` follows the fit.
@property(nonatomic, strong, nullable)
NSNumber *initialZoom NS_REFINED_FOR_SWIFT;
/// Lay out only the lines, rows and pages near the viewport.
/// Lay out only the lines, rows, pages and slides near the viewport.
@property(nonatomic) BOOL lazyLayout;
/// Load the chunks of a text file after the first as the reader comes near.
/// Load the chunks of a text file, a sheet and a pdf after the first as the
/// reader comes near, and write a search index of their text beside them.
@property(nonatomic) BOOL lazyLoading;

/// The least distance the generated content keeps from the view's border. A
Expand Down
35 changes: 32 additions & 3 deletions docs/design/lazy-loading.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,13 +182,42 @@ without them.
them is a decision of its own.
3. **Text documents** (decision 6), once a measured file asks for it.

## Known limits

- **Sheets.** A merge that stays open, such as a sidebar merged over the
whole sheet, ends no chunk, so the sheet is one chunk. The page render
still renders the rows of a later chunk to find its end, so a sheet costs
core as much as before. A copy of a whole column or of the sheet holds
only the rows that have loaded.
- **The index and the DOM.** A list marker in a sheet cell and a U+0000 in
a text file are in one and not in the other. The DOM count of a chunk
wins once it loads.
- **pdf page scripts.** A page script carries its images inline, so the
browser cannot cache an image that repeats from page to page. A font that
only a pattern, a soft mask, a Type 3 font or an annotation uses has no
shared file, so each page that uses it carries it. Each script states the
faces and the `.fvN` rules of its fonts again, which is why its rules
outrank a single class; stating them once in the head would let the
registry stay plain. The numbers of the shared fonts follow the order of
an `unordered_map`, so they may differ between standard libraries.
- **Resources.** A chunk resource holds a bare pointer to its service, so
it must not outlive the service.

## Open questions

- **Print at level 3.** A chunk that has not loaded prints as empty space
of its height. `beforeprint` cannot wait for a script to load.
- **A pdf in the single layer at level 3.** Each script carries its fonts
inline (about 0.5 MB a page of `Core_v5.1.pdf`), or the service votes
once over every page for the code points of each font.
- **A pdf in the single layer at level 3.** The single layer votes over
the runs it meets for the code point of each glyph, and re-encodes the
font with the winners, so a page rendered alone has fonts of its own.
That works: each page script re-encodes its fonts for its own runs and
carries them with suffixed face names, as a page view (`pageN.html`)
already does today. On `Core_v5.1.pdf` such a page carries about 300 KB of
fonts, as much as in the dual layer, because neither subsets. The cost is
that the browser loads a font again for each page. Two ways to cut it:
name each re-encoded font file by a digest of its bytes, so the pages
whose votes agree share one file, as the images of a pdf do; and subset a
font to the glyphs of its page.
- **Eviction at level 3.** Whether the page drops a far chunk and asks for
it again, or keeps its string.
- **The find of the browser.** `hidden="until-found"` lets it reach a hidden
Expand Down
7 changes: 5 additions & 2 deletions jni/java/app/opendocument/core/HtmlConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,12 @@ public final class HtmlConfig {
public Integer viewportWidth;
/** The zoom the view opens at, 1 being actual size; {@code null} follows the fit. */
public Double initialZoom;
/** Lay out only the lines, rows and pages near the viewport. */
/** Lay out only the lines, rows, pages and slides near the viewport. */
public boolean lazyLayout = true;
/** Load the chunks of a text file after the first as the reader comes near. */
/**
* Load the chunks of a text file, a sheet and a pdf after the first as the reader comes near,
* and write a search index of their text beside them.
*/
public boolean lazyLoading = false;

/**
Expand Down
18 changes: 10 additions & 8 deletions src/odr/html.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,15 +194,17 @@ struct HtmlConfig {
std::optional<std::uint32_t> viewport_width;
/// The zoom the view opens at, 1 being actual size; unset follows the fit.
std::optional<double> initial_zoom;
/// Lay out only the lines, rows and pages near the viewport. Off, the
/// browser lays out all of them, which a large file may not survive, but its
/// own find and a screen reader reach every one.
/// Lay out only the lines, rows, pages and slides near the viewport. Off,
/// the browser lays out all of them, which a large file may not survive, but
/// its own find and a screen reader reach every one.
bool lazy_layout{true};
/// Write the chunks of a text file after the first as scripts of their own,
/// which the page loads once the reader comes near. `bring_offline` writes
/// them beside the page, and the HTTP server serves them. Needs
/// @ref lazy_layout. An editable render, and a file the page cannot spell in
/// UTF-8, write every line into the page.
/// Write the chunks of a text file, a sheet and a pdf after the first as
/// scripts of their own, which the page loads once the reader comes near,
/// and the text of those chunks as a search index beside them.
/// `bring_offline` writes them beside the page, and the HTTP server serves
/// them. Needs @ref lazy_layout. An editable render, a text file the page
/// cannot spell in UTF-8, and a pdf in the single layer write everything
/// into the page.
bool lazy_loading{false};

/// The least distance the generated content keeps from the view's border. A
Expand Down
3 changes: 0 additions & 3 deletions src/odr/internal/html/document_element.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,6 @@ constexpr double gutter_padding_pixels = 14;
constexpr double estimated_row_pixels = 20;
/// A chunk of a sheet holds about as many cells (`lazy-loading.md` decision 3).
constexpr std::uint32_t chunk_cells = 4096;
/// The chunks of a sheet that one script of its search index holds the text
/// of (`lazy-loading.md` decision 4).
constexpr std::uint32_t chunks_per_index = 64;

/// Whether a reader sees anything. A bookmark marks a place rather than filling
/// one, and a span or a link is a style around what it holds, so a paragraph
Expand Down
4 changes: 4 additions & 0 deletions src/odr/internal/html/frontend.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <odr/html.hpp>

#include <cstdint>
#include <string_view>

namespace odr::internal::html {
Expand Down Expand Up @@ -38,6 +39,9 @@ void write_chunk_style(const WritingState &state);
/// @p near where it is near the viewport before the script runs. Empty where
/// `HtmlConfig::lazy_layout` is off.
[[nodiscard]] std::string chunk_classes(const HtmlConfig &config, bool near);
/// The chunks that one script of a search index holds the text of, in every
/// view (`lazy-loading.md` decision 4).
constexpr std::uint32_t chunks_per_index = 64;
/// A json string that cannot end the `<script>` it sits in.
[[nodiscard]] std::string script_string(const std::string &value);

Expand Down
2 changes: 2 additions & 0 deletions src/odr/internal/html/frontend/pdf-annotation.js
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,8 @@
scheduleMark();
});
window.addEventListener("resize", redraw);
// a page that loads replaces what its empty box held, the marks too
document.addEventListener("odr-chunk-filled", redraw);
applyOptions();

odr.annotation = {
Expand Down
Loading
Loading