Class PdfMeasurer
- All Implemented Interfaces:
Measurer
Measures with the fonts a PDF is drawn in, so a document paginates identically on screen and on paper.
Out of the box every style maps to one of the standard PDF fonts: serif families to Times, monospaced ones to Courier and everything else to Helvetica. Those cover only Western European characters, so a document in any other script should register a TrueType font for each family it uses:
PdfMeasurer m = new PdfMeasurer();
try {
// fonts bundled with the application, in its resources
InputStream regular = CN.getResourceAsStream("/NotoSerif-Regular.ttf");
InputStream bold = CN.getResourceAsStream("/NotoSerif-Bold.ttf");
if (regular != null && bold != null) {
m.register("Serif", false, false, PdfFont.loadTrueType(Util.readInputStream(regular)));
m.register("Serif", true, false, PdfFont.loadTrueType(Util.readInputStream(bold)));
}
} catch (IOException e) {
Log.e(e);
}
DocumentLayout layout = new DocumentLayout(new Document(), m);
Log.p("pages: " + layout.getPageCount());
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfloatThe distance from the top of a line of this style to its baseline.floatThe distance from the baseline to the bottom of a line of this style.static floatThe size text of a style is drawn at: smaller for superscript and subscript.The font a style is drawn in.voidRegisters a font for a family and face.floatThe advance width of text drawn in a style.
-
Constructor Details
-
PdfMeasurer
public PdfMeasurer()
-
-
Method Details
-
register
Registers a font for a family and face. A face without its own registration falls back to the family's regular font, and a family without any to a standard font.
Parameters
-
family: the family name aTextStyleuses, such asSeriforCalibri -
bold: whether this is the bold face -
italic: whether this is the italic face -
font: the font
-
-
font
-
drawnSize
The size text of a style is drawn at: smaller for superscript and subscript.
Parameters
style: the style
Returns
the size in points
-
width
-
ascent
-
descent
-