misc improvements in slide rendering

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@649798 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Yegor Kozlov 2008-04-19 11:17:37 +00:00
parent 4ff1e84247
commit 6e96462b0e
3 changed files with 59 additions and 27 deletions

View File

@ -273,7 +273,7 @@ public class ShapeGroup extends Shape{
AffineTransform at = graphics.getTransform();
if(!anchor.equals(coords)){
graphics.scale(coords.getWidth()/anchor.getWidth(), coords.getHeight()/anchor.getHeight());
graphics.scale(anchor.getWidth()/coords.getWidth(), anchor.getHeight()/coords.getHeight());
graphics.translate(
anchor.getX()*coords.getWidth()/anchor.getWidth() - coords.getX(),

View File

@ -103,13 +103,12 @@ public class TextPainter {
int startIndex = measurer.getPosition();
int nextBreak = text.indexOf('\n', measurer.getPosition() + 1);
int rtIdx = startIndex == 0 ? 0 : startIndex + 1;
if(startIndex == 0 || startIndex == text.length() - 1) rtIdx = startIndex;
else rtIdx = startIndex + 1;
boolean prStart = text.charAt(startIndex) == '\n';
if(prStart) measurer.setPosition(startIndex++);
RichTextRun rt = getRichTextRunAt(rtIdx);
RichTextRun rt = getRichTextRunAt(startIndex);
if(rt == null) {
logger.log(POILogger.WARN, "RichTextRun not found at pos" + (startIndex + 1) + "; text.length: " + text.length());
logger.log(POILogger.WARN, "RichTextRun not found at pos" + startIndex + "; text.length: " + text.length());
break;
}
@ -135,21 +134,24 @@ public class TextPainter {
int endIndex = measurer.getPosition();
TextElement el = new TextElement();
el.ascent = textLayout.getAscent();
el._startIndex = startIndex;
el._endIndex = endIndex;
el._align = rt.getAlignment();
el._text = textLayout;
el._textOffset = rt.getTextOffset();
boolean prStart = text.charAt(startIndex) == '\n' || startIndex == 0;
if (text.charAt(startIndex) == '\n'){
textHeight += textLayout.getAscent();
if (prStart || startIndex == 0){
int spaceBefore = rt.getSpaceBefore();
if (spaceBefore != 0) {
float val = (textLayout.getAscent() + textLayout.getDescent()) * spaceBefore/100;
float val = (float)(textLayout.getAscent() + textLayout.getDescent())* spaceBefore/100;
textHeight += val;
el.ascent += val;
}
}
if(rt.isBullet() && prStart){
if(rt.isBullet() && (prStart || startIndex == 0)){
it.setIndex(startIndex);
AttributedString bat = new AttributedString(Character.toString(rt.getBulletChar()), it.getAttributes());
@ -166,13 +168,22 @@ public class TextPainter {
}
}
textHeight += textLayout.getAscent() + textLayout.getDescent();
float descent = textLayout.getDescent();
int lineSpacing = rt.getLineSpacing();
if(lineSpacing != 0) el._spacing = textLayout.getLeading()*lineSpacing/100;
else el._spacing = textLayout.getLeading();
if(lineSpacing != 0) descent += textLayout.getLeading()*lineSpacing/100;
else descent = textLayout.getLeading();
textHeight += descent;
textHeight += el._spacing;
el.descent = descent;
if (prStart){
int spaceAfter = rt.getSpaceAfter();
if (spaceAfter != 0) {
float val = (float)(textLayout.getAscent() + textLayout.getDescent())* spaceAfter/100;
textHeight += val;
el.descent += val;
}
}
lines.add(el);
}
@ -180,15 +191,15 @@ public class TextPainter {
int valign = _shape.getVerticalAlignment();
double y0 = anchor.getY();
switch (valign){
case TextBox.AnchorTopBaseline:
case TextBox.AnchorTop:
case TextShape.AnchorTopBaseline:
case TextShape.AnchorTop:
y0 += _shape.getMarginTop();
break;
case TextBox.AnchorBottom:
case TextShape.AnchorBottom:
y0 += anchor.getHeight() - textHeight - _shape.getMarginBottom();
break;
default:
case TextBox.AnchorMiddle:
case TextShape.AnchorMiddle:
float delta = (float)anchor.getHeight() - textHeight - _shape.getMarginTop() - _shape.getMarginBottom();
y0 += _shape.getMarginTop() + delta/2;
break;
@ -197,11 +208,12 @@ public class TextPainter {
//finally draw the text fragments
for (int i = 0; i < lines.size(); i++) {
TextElement elem = (TextElement)lines.get(i);
y0 += elem._text.getAscent();
y0 += elem.ascent;
Point2D.Double pen = new Point2D.Double();
pen.y = y0;
switch (elem._align) {
default:
case TextShape.AlignLeft:
pen.x = anchor.getX() + _shape.getMarginLeft();
break;
@ -213,24 +225,18 @@ public class TextPainter {
pen.x = anchor.getX() + _shape.getMarginLeft() +
(anchor.getWidth() - elem._text.getAdvance() - _shape.getMarginLeft() - _shape.getMarginRight());
break;
default:
pen.x = anchor.getX() + _shape.getMarginLeft();
break;
}
if(elem._bullet != null){
elem._bullet.draw(graphics, (float)(pen.x + elem._bulletOffset), (float)pen.y);
}
elem._text.draw(graphics, (float)(pen.x + elem._textOffset), (float)pen.y);
y0 += elem._text.getDescent();
y0 += elem._text.getLeading();
y0 += elem._spacing;
y0 += elem.descent;
}
}
public static class TextElement {
static class TextElement {
public TextLayout _text;
public int _textOffset;
public TextLayout _bullet;
@ -239,5 +245,6 @@ public class TextPainter {
public int _startIndex;
public int _endIndex;
public float _spacing;
public float ascent, descent;
}
}

View File

@ -716,6 +716,31 @@ public class RichTextRun {
int val = getParaTextPropVal("spacebefore");
return val == -1 ? 0 : val;
}
/**
* Sets spacing after a paragraph.
* <p>
* If spaceafter >= 0, then spaceafter is a percentage of normal line height.
* If spaceafter < 0, the absolute value of spaceafter is the spacing in master coordinates.
* </p>
*/
public void setSpaceAfter(int val) {
setParaTextPropVal("spaceafter", val);
}
/**
* Returns spacing after a paragraph
* <p>
* If spaceafter >= 0, then spaceafter is a percentage of normal line height.
* If spaceafter < 0, the absolute value of spaceafter is the spacing in master coordinates.
* </p>
*
* @return the spacing before a paragraph
*/
public int getSpaceAfter() {
int val = getParaTextPropVal("spaceafter");
return val == -1 ? 0 : val;
}
// --------------- Internal HSLF methods, not intended for end-user use! -------
/**