8.4 Handling reflowable documents

Some document types (such as EPUB) require the contents to be laid out before they can be rendered. This is done by calling fz_layout_document:

/* 
   fz_layout_document: Layout reflowable document types. 
 
   w, h: Page size in points. 
   em: Default font size in points. 
*/ 
void fz_layout_document(fz_context *ctx, fz_document *doc, float w, float h, float em);

Any non-reflowable document types (such as PDF) will ignore this layout request.

The results of the layout will depend both upon a target width and height, a given font size, and the CSS styles in effect. MuPDF has an inbuilt set of default CSS styles that will be used if a document does not provide its own. In addition, the user can provide a final set that will override any rules found in the default sets. In this way, the appearance of the rendered document can be changed (perhaps by changing document colours or font styles/sizes).

Documents can be laid out multiple times to allow changes in these properties to take effect.

MuPDF provides its own default CSS style sheet, but this can be overridden by the user CSS style sheet in the context:

/* 
   fz_user_css: Get the user stylesheet source text. 
*/ 
const char *fz_user_css(fz_context *ctx); 
 
/* 
   fz_set_user_css: Set the user stylesheet source text for use with HTML and EPUB. 
*/ 
void fz_set_user_css(fz_context *ctx, const char *text);

The user CSS style sheet is supplied as a null terminated C string.

When the CSS or the screen size is changed, and the document relaid out, content moves. In order for applications to be able to not lose the readers place, MuPDF offers a mechanism for making a bookmark and then looking it up again after the content has been laid out to a new position.

/* 
   Create a bookmark for the given page, which can be used to find the 
   same location after the document has been laid out with different 
   parameters. 
*/ 
fz_bookmark fz_make_bookmark(fz_context *ctx, fz_document *doc, int page); 
 
/* 
   Find a bookmark and return its page number. 
*/ 
int fz_lookup_bookmark(fz_context *ctx, fz_document *doc, fz_bookmark mark);