use of org.apache.poi.sl.usermodel.TextParagraph.BulletStyle in project poi by apache.
the class DrawTextParagraph method getBullet.
protected DrawTextFragment getBullet(Graphics2D graphics, AttributedCharacterIterator firstLineAttr) {
BulletStyle bulletStyle = paragraph.getBulletStyle();
if (bulletStyle == null) {
return null;
}
String buCharacter;
AutoNumberingScheme ans = bulletStyle.getAutoNumberingScheme();
if (ans != null) {
buCharacter = ans.format(autoNbrIdx);
} else {
buCharacter = bulletStyle.getBulletCharacter();
}
if (buCharacter == null) {
return null;
}
String buFont = bulletStyle.getBulletFont();
if (buFont == null) {
buFont = paragraph.getDefaultFontFamily();
}
assert (buFont != null);
PlaceableShape<?, ?> ps = getParagraphShape();
PaintStyle fgPaintStyle = bulletStyle.getBulletFontColor();
Paint fgPaint;
if (fgPaintStyle == null) {
fgPaint = (Paint) firstLineAttr.getAttribute(TextAttribute.FOREGROUND);
} else {
fgPaint = new DrawPaint(ps).getPaint(graphics, fgPaintStyle);
}
float fontSize = (Float) firstLineAttr.getAttribute(TextAttribute.SIZE);
Double buSz = bulletStyle.getBulletFontSize();
if (buSz == null) {
buSz = 100d;
}
if (buSz > 0) {
fontSize *= buSz * 0.01;
} else {
fontSize = (float) -buSz;
}
AttributedString str = new AttributedString(mapFontCharset(buCharacter, buFont));
str.addAttribute(TextAttribute.FOREGROUND, fgPaint);
str.addAttribute(TextAttribute.FAMILY, buFont);
str.addAttribute(TextAttribute.SIZE, fontSize);
TextLayout layout = new TextLayout(str.getIterator(), graphics.getFontRenderContext());
DrawFactory fact = DrawFactory.getInstance(graphics);
return fact.getTextFragment(layout, str);
}
use of org.apache.poi.sl.usermodel.TextParagraph.BulletStyle in project poi by apache.
the class DrawTextShape method drawParagraphs.
/**
* paint the paragraphs starting from top left (x,y)
*
* @return the vertical advance, i.e. the cumulative space occupied by the text
*/
public double drawParagraphs(Graphics2D graphics, double x, double y) {
DrawFactory fact = DrawFactory.getInstance(graphics);
double y0 = y;
//noinspection RedundantCast
@SuppressWarnings("cast") Iterator<? extends TextParagraph<?, ?, ? extends TextRun>> paragraphs = (Iterator<? extends TextParagraph<?, ?, ? extends TextRun>>) getShape().iterator();
boolean isFirstLine = true;
for (int autoNbrIdx = 0; paragraphs.hasNext(); autoNbrIdx++) {
TextParagraph<?, ?, ? extends TextRun> p = paragraphs.next();
DrawTextParagraph dp = fact.getDrawable(p);
BulletStyle bs = p.getBulletStyle();
if (bs == null || bs.getAutoNumberingScheme() == null) {
autoNbrIdx = -1;
} else {
Integer startAt = bs.getAutoNumberingStartAt();
if (startAt == null)
startAt = 1;
// TODO: handle reset auto number indexes
if (startAt > autoNbrIdx)
autoNbrIdx = startAt;
}
dp.setAutoNumberingIdx(autoNbrIdx);
dp.breakText(graphics);
if (!isFirstLine) {
// the amount of vertical white space before the paragraph
Double spaceBefore = p.getSpaceBefore();
if (spaceBefore == null)
spaceBefore = 0d;
if (spaceBefore > 0) {
// positive value means percentage spacing of the height of the first line, e.g.
// the higher the first line, the bigger the space before the paragraph
y += spaceBefore * 0.01 * dp.getFirstLineHeight();
} else {
// negative value means the absolute spacing in points
y += -spaceBefore;
}
}
isFirstLine = false;
dp.setPosition(x, y);
dp.draw(graphics);
y += dp.getY();
if (paragraphs.hasNext()) {
Double spaceAfter = p.getSpaceAfter();
if (spaceAfter == null)
spaceAfter = 0d;
if (spaceAfter > 0) {
// positive value means percentage spacing of the height of the last line, e.g.
// the higher the last line, the bigger the space after the paragraph
y += spaceAfter * 0.01 * dp.getLastLineHeight();
} else {
// negative value means the absolute spacing in points
y += -spaceAfter;
}
}
}
return y - y0;
}
Aggregations