Client API. The Codename One framework your app is built on: this runs on the device, not in a backend.
public class LayoutPainter
- Object
- LayoutPainter
Paints laid out items on a Graphics, the way DocumentView paints its pages.
Anything that shows text laid out by DocumentLayout – a slide’s text box, a thumbnail,
a print preview – paints it with this class, so it looks exactly as it does in the word
processor: each word is drawn where the layout measured it, underlines and strike lines
follow the measured text, and pictures are decoded once and kept.
void paintFirstPage(Graphics g, Document doc, int x, int y) {
DocumentLayout layout = new DocumentLayout(doc, new ScreenMeasurer());
LayoutPainter painter = new LayoutPainter(layout.getMeasurer());
painter.paint(g, layout.getPage(0).getItems(), x, y, 2f);
}Constructors
public LayoutPainter(Measurer measurer) | A painter for items laid out with a measurer. |
Methods
Inherited methods
Constructor details
LayoutPainter
public LayoutPainter(Measurer measurer)A painter for items laid out with a measurer.
Parameters
measurerMeasurer- the measurer the items were laid out with; word positions are computed with it
Method details
getMeasurer
public Measurer getMeasurer()The measurer items are positioned with.
Returns
the measurer
font
public Font font(TextStyle style, int px)The platform font text of a style is drawn in, at a pixel size.
Parameters
styleTextStyle- the style
pxint- the size in pixels
Returns
the font
paint
public void paint(Graphics g, List<LayoutItem> items, int left, int top, float scale)Paints items.
Parameters
gGraphics- the graphics
itemsList<LayoutItem>- the items, in points relative to their page
leftint- where the page’s left edge is, in pixels
topint- where the page’s top edge is, in pixels
scalefloat- pixels per point
paintItem
public void paintItem(Graphics g, LayoutItem it, int left, int top, float scale, boolean lastOnLine)Paints one item.
Parameters
gGraphics- the graphics
itLayoutItem- the item
leftint- the page’s left edge in pixels
topint- the page’s top edge in pixels
scalefloat- pixels per point
lastOnLineboolean- true when it is the last item of its line, whose underline stops at its last glyph instead of running through its trailing spaces
paintText
public void paintText(Graphics g, LayoutItem it, int x, int baseline, float scale, boolean lastOnLine)Paints a text item: its words, underline, strike line and revision marks.
Parameters
gGraphics- the graphics
itLayoutItem- a
LayoutItem.TEXTitem xint- its left edge in pixels
baselineint- its baseline in pixels
scalefloat- pixels per point
lastOnLineboolean- true when it ends its line
paintPicture
public void paintPicture(Graphics g, Picture p, int x, int y, int w, int h)Paints a picture scaled into a box, or a frame when it cannot be decoded.
Parameters
gGraphics- the graphics
pPicture- the picture
xint- the box’s left edge
yint- its top edge
wint- its width
hint- its height
image
public Image image(Picture p)The decoded image of a picture, decoded once; null when it is linked or not an image
the platform reads.
Parameters
pPicture- the picture
Returns
the image or null
offset
public int offset(LayoutItem it, int chars, float scale)Where the first
chars characters of an item end, in pixels from its left edge, by
the measurer the item was laid out with.Parameters
itLayoutItem- a text item
charsint- the number of characters
scalefloat- pixels per point
Returns
the offset in pixels
drawWords
public void drawWords(Graphics g, LayoutItem it, int x, int y, float scale)Draws an item a word at a time, each where the layout put it, in the graphics’ current
font and color. The font drawn at a whole pixel size is never exactly the one
measured, and drawn in one piece the difference would add up along the run; this way
it stays inside the space after each word.
Parameters
gGraphics- the graphics
itLayoutItem- a text item
xint- its left edge in pixels
yint- the top of its glyphs in pixels
scalefloat- pixels per point