Free Support Forum - aspose.com

TableEx.getHeight does not compute table height correctly

1.) I call the TableEx.getHeight() method - it returns 24.
2.) I add more text to a cell's portion which results in the text wrapping in the cell
3.) I call the TableEx.getHeight() method again and it still returns 24

The height returned is too small compared to what the height actually is due to wrapping. It seems like the getHeight() method simply computes table height based on how high the cells are and does not factor text wrapping into account. The CellEx getOffset method also has this bug in the code as well.

Hello Dear,

I regret to share that table height/width property is not working properly, when dealing with PPTX in Aspose.Slides for Java at the moment. An issue with ID 22122 has been created in our issue tracking system to investigate and resolve this issue. This thread has also been linked with the issue, so that you may be automatically notified, once the issue is resolved.

We are sorry for your inconvenience,

This bug also exists for any type of ShapeEx object in general (ShapeEx.getHeight() returns the incorrect height). When will this fix be complete? This functionality is essential to being able to successfully create PowerPoint presentations that don’t run off the bottom of the slide. It is also essential to delivering our product to our clients on time.

Thank you,
Thomas

Hello Thomas,

FitShapeToText functionality already implemented for PPTX format in the .NET version but not ported to Java yet. Actually, there is a large list of new features and improvements which should be ported in the nearest time and will be available in our Christmas release.

Dear Thomas,

I have verified the ShapeEx getHeight() and getWidth() property by generating a presentation with AutoShape and it seems to work fine. Can you please share the scenario where you have experienced the mentioned issue, so that we may reproduce the issue on our end to help you out.

Thanks and Regards,

If I add a large amount of text to a PortionEx object, the containing AutoShapeEx object will not expand it’s height to match the entire contents. If I call AutoShapeEx.getHeight() before and after I add a large amount of text, it will stay the same. Also, there is no FitShapeToText function in Java, so the shape stays the same dimensions no matter what text you add to the shape. Why aren’t the Java and .NET functionality released at the same time?

Thank you,
Thomas

Dear Thomas,

I feel the issue shared by you is related to FitShapeToText property of TextFrame. An issue with ID 22071 has already been created in our issue tracking system to provide this feature. This thread has also been linked with the issue, so that you may be automatically notified, once the issue is resolved. Actually, the feature of FitShapeToText has been introduced in the latest release of Aspose.Slides for .NET 4.4.0 and the release for Aspose.Slides for Java is in que. Hopefully, the feature will be available in the upcoming release of Aspose.Slides for Java 2.5.0.

We are sorry for your inconvenience,

If it is related to FitShapeToText, why do the rows of a table already correctly resize themselves to encompass all of their text? After the 2.5.0 release, would we call FitShapeToText on each row in order to get the correct height of the row?

I think if you just modified the getHeight() function of a row to calculate the actual height including word wrapping, the issue would be resolved for tables at least.

Thanks,
Thomas

I’m also running into this problem. I’m adding a lot of data to a table, through various means including (a) setting the text of a text frame to a long string that wraps multiple lines, and (b) adding paragraphs to a text frame. No matter how much data I add to the table, the reported height of the table is never different, which would lead me to believe that the height is pre-calculated.


Do you have a timetable as to when this might be fixed?

Hi Liam,

I have requested our development team to share the updated status of the issues. Unfortunately, at the moment the issue is still unresolved. The same issue has been highlighted in Aspose.Slides for .NET. When it will be resolved there then it will also be ported in Aspose.Slides for Java as well. I will share further information with you as soon as some time line for the issue is shared by our development team. I really appreciate your cooperation in terms of patience for this.

Thanks and Regards,

I’ve come up with a rough approximation method of the height… it usually comes up about 50 to 100 units short so far, but it’s been good enough for me. Maybe it’ll be useful to other people as well.


p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Monaco} p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Monaco; min-height: 15.0px} span.s1 {color: #931a68} span.s2 {color: #0027cc} p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Monaco} span.s1 {color: #931a68} span.s2 {color: #0027cc}

public TableEx getTable() {

return table;

}


p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Monaco} p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Monaco; color: #4d9072} p.p3 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Monaco; min-height: 15.0px} span.s1 {color: #931a68} span.s2 {color: #000000}

public double getHeight() {

double totalHeight = 0;

int rowCount = getTable().getRows().size();

int colCount = getTable().getColumns().size();

double[] rowHeight = new double[rowCount];

// get height of each row...

for (int row = 0; row < rowCount; row++) {

// by finding the column with the max height

for (int col = 0; col < colCount; col++) {

double cellHeight = 0;

CellEx cell = getTable().get(col, row);

ParagraphsEx paragraphs = cell.getTextFrame().getParagraphs();

for (int i = 0; i < paragraphs.size(); i++) {

cellHeight += getHeight(paragraphs.get(i), (float) cell.getWidth());

}

rowHeight[row] = Math.max(rowHeight[row], cellHeight);

}

// and add them up

totalHeight += rowHeight[row];

}

return totalHeight;

}

p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Monaco} p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Monaco; color: #4d9072} p.p3 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Monaco; min-height: 15.0px} span.s1 {color: #931a68} span.s2 {color: #000000} span.s3 {color: #0027cc}

private double getHeight(ParagraphEx shape, float width) {

int height = 0;

width -= (shape.getMarginLeft() + shape.getMarginRight());

PortionEx portion = shape.getPortions().get(0);

FontDataEx font = portion.getLatinFont();

// create a java font based on the first portion in the paragraph

Font f = new Font(font.getFontName(), getFontType(portion), (int)portion.getFontHeight());

FontRenderContext frc = new FontRenderContext(null, true, true);

// create an attributed string based on this font and the text of the paragraph

String text = StringUtils.defaultString(shape.getText());

AttributedString attribText = new AttributedString(text);

attribText.addAttribute(TextAttribute.FONT, f);

// measure the height and add each line

LineBreakMeasurer measurer = new LineBreakMeasurer(attribText.getIterator(), frc);

while (measurer.getPosition() < text.length()) {

TextLayout layout = measurer.nextLayout(width);

height += layout.getAscent() + layout.getDescent()

+ layout.getLeading();

}

return height;

}

private int getFontType(PortionEx portion) {

int fontType = Font.PLAIN;

if (portion.getFontBold() == NullableBool.TRUE)

fontType |= Font.BOLD;

if (portion.getFontItalic() == NullableBool.TRUE)

fontType |= Font.ITALIC;

return fontType;

}

The issues you have found earlier (filed as SLIDESJAVA-22122) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by aspose.notifier.
(3)

Hi Liam,


I like to share that we have added the support for setting and getting autofit types for text frames. Please use the following sample code in your application with Aspose.Slides for Java 6.9.1.

TextFrameEx.setAutofitType(TextAutofitTypeEx.Normal);
byte type= TextFrameEx.getAutofitType();

Many Thanks,

The issues you have found earlier (filed as SLIDESJAVA-22071) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by aspose.notifier.
(1)