Skip to content
Victor B edited this page Nov 9, 2023 · 1 revision

How it is working

The points listed in this chapter are not the exact algorithm but provide some common ideas, concepts and main entry points for further research. The core functions are concentrated in these two classes:

Tile map

Tile map is the core concept which allows asynchronous loading, smooth scrolling and animations of the view.

The PDF-file is divided into tiles:

  • The PDF-file is represented as a scroll: a long sheet of paper, where the pages are placed one under another.
    • For a multipage PDF it turns out to be a narrow and extremely high rectangle.
  • This rectangle is divided into smaller rectangles. The main limitation per rectangle is screen canvas limitations - e.g. 8192 by 8192 px.
  • These rectangles are called tiles.
  • Tiles are different for different zoom levels:
    • The smallest zoom is only one tile wide, in higher zooms there is a grid of tiles, e.g. 4 tiles wide.
    • Each next zoom is twice higher than the previous one.
    • The minimum zoom is one page per screen, maximum zoom is double of the original size.
    • Zooms are represented as samples.
  • On initialising tile positions in the global image rectangle for all zoom levels are calculated and saved.
  • List of all combinations zoom level and tiles is called a tile map.

See details SubsamplingScaleImageView -> initialiseTileMap for initialising the tile map.

Initializing

On setting the file path TilesInitTask is called:

  • TilesInitTask performs initial opening of the PDF via standard Android PdfRenderer to retrieve PDF properties (height and width).
  • Limitation note: only details of the first page are read and all other pages assumed the same size.

See details in TilesInitTask.

Rendering

On draw and on touch of the view rendering is triggered:

  • All tiles are checked if they are visible on the screen and either unloaded or rendering is triggered.
  • Rendering is performed in TileLoadTask for a single tile.
  • For each tile all relevant PDF pages are rendered (drawn on a bitmap).
  • Technically rendering is performed via the standard PdfRender -> openPage -> render.
  • The result bitmap is recorded to a tile and screen redraw is triggered .

See details in TileLoadTask.

Drawing

On draw:

  • All loaded tiles are drawn on the canvas.
  • Tiles are drawn from lower resolution to higher resolution.
  • Absolute position of the scroll is defined by the position of the top left corner vTranslate and scale, which are changed via touch

Practical information

Debug information can be turned on by calling setDebug. Then tile rectangles, their details and animation helpers will be displayed.

Questions

Question: What happens, if the current zoom is between the zooms of tiles?

Guess: The both neighbor zooms will be loaded and the higher zoom will be scaled down on redraw.

Animation

A special mode, which automatically changes position and scale of the scroll based on time. It can be triggered by fling (scroll) or double click (zoom).

Clone this wiki locally