Class 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);
}
-
Constructor Summary
ConstructorsConstructorDescriptionLayoutPainter(Measurer measurer) A painter for items laid out with a measurer. -
Method Summary
Modifier and TypeMethodDescriptionvoiddrawWords(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 platform font text of a style is drawn in, at a pixel size.The measurer items are positioned with.The decoded image of a picture, decoded once; null when it is linked or not an image the platform reads.intoffset(LayoutItem it, int chars, float scale) Where the firstcharscharacters of an item end, in pixels from its left edge, by the measurer the item was laid out with.voidpaint(Graphics g, List<LayoutItem> items, int left, int top, float scale) Paints items.voidpaintItem(Graphics g, LayoutItem it, int left, int top, float scale, boolean lastOnLine) Paints one item.voidpaintPicture(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.voidpaintText(Graphics g, LayoutItem it, int x, int baseline, float scale, boolean lastOnLine) Paints a text item: its words, underline, strike line and revision marks.
-
Constructor Details
-
LayoutPainter
A painter for items laid out with a measurer.
Parameters
measurer: the measurer the items were laid out with; word positions are computed with it
-
-
Method Details
-
getMeasurer
The measurer items are positioned with.
Returns
the measurer
-
font
-
paint
Paints items.
Parameters
-
g: the graphics -
items: the items, in points relative to their page -
left: where the page's left edge is, in pixels -
top: where the page's top edge is, in pixels -
scale: pixels per point
-
-
paintItem
public void paintItem(Graphics g, LayoutItem it, int left, int top, float scale, boolean lastOnLine) Paints one item.
Parameters
-
g: the graphics -
it: the item -
left: the page's left edge in pixels -
top: the page's top edge in pixels -
scale: pixels per point -
lastOnLine: 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
-
g: the graphics -
it: aLayoutItem.TEXTitem -
x: its left edge in pixels -
baseline: its baseline in pixels -
scale: pixels per point -
lastOnLine: true when it ends its line
-
-
paintPicture
-
image
-
offset
Where the first
charscharacters of an item end, in pixels from its left edge, by the measurer the item was laid out with.Parameters
-
it: a text item -
chars: the number of characters -
scale: pixels per point
Returns
the offset in pixels
-
-
drawWords
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
-
g: the graphics -
it: a text item -
x: its left edge in pixels -
y: the top of its glyphs in pixels -
scale: pixels per point
-
-