Client API. The Codename One framework your app is built on: this runs on the device, not in a backend.
public final class DocumentLayout
- Object
- DocumentLayout
A document broken into pages: every line, table, picture and footnote placed, in points.
Layout is pure: it reads a Document and a Measurer and touches no user interface, so the
same result paints DocumentView, is written by the PDF export, and can run on a server.
DocumentModel model = new DocumentModel(new Document());
model.insertBlock(0, new Paragraph(model.newId('p'), RichText.of("Quarterly review")));
DocumentLayout layout = new DocumentLayout(model.getDocument(), new PdfMeasurer());
for (int i = 0; i < layout.getPageCount(); i++) {
for (LayoutItem item : layout.getPage(i).getItems()) {
Log.p("page " + i + ": item at " + item.x + ", " + item.y);
}
}Paragraphs break at spaces (a word wider than the line breaks between letters) and honor
alignment, justification, indents, spacing, line spacing, page breaks and keep-with-next.
List items get bullets or numbers, restarted where the paragraph says so. Table rows move to
the next page whole, repeating the header rows; a row taller than a page is split. Footnotes
are placed at the bottom of the page that references them and endnotes after the text. PAGE
and NUMPAGES fields show the real page number and count.
Constructors
public DocumentLayout(Document doc, Measurer measurer) | Lays a document out. |
Methods
public PageSpec getPageSpec() | The page geometry used. |
public int getPageCount() | The number of pages; at least one. |
public LayoutPage getPage(int index) | A page. |
public Measurer getMeasurer() | The measurer this layout was made with. |
public TextPosition positionAt(int page, float x, float y) | The caret position nearest a point on a page. |
public float[] caretRect(TextPosition position) | Where the caret for a position is drawn. |
Inherited methods
Constructor details
DocumentLayout
public DocumentLayout(Document doc, Measurer measurer)Parameters
docDocument- the document
measurerMeasurer- measures text; use the same one for everything that must match
Method details
getPageSpec
public PageSpec getPageSpec()Returns
getPageCount
public int getPageCount()Returns
getPage
public LayoutPage getPage(int index)Parameters
indexint- from zero
Returns
getMeasurer
public Measurer getMeasurer()Returns
positionAt
public TextPosition positionAt(int page, float x, float y)Parameters
pageint- the page index
xfloat- from the page’s left edge, in points
yfloat- from the page’s top edge, in points
Returns
caretRect
public float[] caretRect(TextPosition position)Parameters
positionTextPosition- the position
Returns
{page, x, top, height} in points, or null when the paragraph is not laid out