public final class LayoutLine extends Boxed
lines = layout.getLinesReadonly(); x = leftMargin; y = topMargin + rect.getAscent(); for (i = 0; i < lines.length; i++) { rect = lines[i].getExtentsLogical(); y += rect.getHeight(); cr.moveTo(x, y); cr.showLayout(lines[i]); }which of course is the hard way of doing:
cr.showLayout(layout);but gives you control over the individual lines of the paragraph which is necessary when doing paginated layout and worrying about available vertical space.
Modifier and Type | Method and Description |
---|---|
Rectangle |
getExtentsInk() |
Rectangle |
getExtentsLogical()
Get a Rectangle describing the logical extents calculated for this line
of rendered text.
|
int |
getLength()
Get the width of this LayoutLine, in characters.
|
int |
getStartIndex()
Get the character position into the parent Layout that this LayoutLine
begins at.
|
public Rectangle getExtentsInk()
public Rectangle getExtentsLogical()
The x
, y
, and height
parameters
of these Rectangles are the same for each LayoutLine in a given Layout;
the width will be variable (unless you have evenly justified
the text, and even then last line of each paragraph will be less than
the width of the others).
Note
It is a common mistake to assume that the origin of the Pango
co-ordinate space is the top-right corner of an extents Rectangle. This
is not the case; the vertical origin is at the base line.
The showLayout()
method that takes a LayoutLine starts its drawing by
placing its Rectangle's origin at the current Context point. So to
render consistently spaced lines of text you will need to move the
Context point down by the value of the ascent (which is the
negative of the y
co-ordinate describing top of the
rectangle from the origin):
rect = line.getExtentsLogical(); h = leftMargin; v = topMargin + rect.getAscent() + lineNumber * rect.getHeight(); cr.moveTo(h, v); cr.showLayout(line);
public int getLength()
public int getStartIndex()
The underlying PangoLayout and PangoLayoutLine structures work in byte widths; we convert to character offsets.