Inconsistent text wrapping between Aspose and PowerPoint


#1

We’re seeing sometimes inconsistent text wrapping in a table cell between Aspose and PowerPoint. A similar issue has been reported in this post: https://www.aspose.com/community/forums/thread/488739/text-wrap-does-not-match-powerpoint-text-wrap.aspx. Has this defect been fixed?


If you take a look at the attached the pptx file. The bar in the last row is out of the cell’s boundary. We used the TableCell’s offSetY and Table’s Y property to calculate where to place the bar in each cell. However we believe when Aspose renders the 3rd data row, it didn’t have the third line of text, it only has two lines of text (as opposed to three lines of text being displayed in PowerPoint) which caused the 4th data row’s TableCell’s offSetY is not the same as what’s displaying in a PowerPoint because in the PowerPoint the 3rd data row has three lines instead of 2 lines. As a result, the bar in the last row’s position is off. For now, we only see this issue ocassionally happening to PPTX in non-English language. Can you look into it and let me know if there is a way to get the text wrapping the same between Aspose and PowerPoint?

Thank you!




#2

Hi Nan,


Can you please share generated result with us so that we can investigate issue in details on our end.

Best Regards,

#3

Thank you for the quick response. The aspose generated pptx file is the sample pptx file I attached to the original thread. As you can see in the sample file, the bar in the second column is perfectly placed on top of each cell except for the last row. Since the code is the same for rendering the bar, so the best theory we can come up with for the misplaced fourth bar is that in the first column of the third data row, Aspose renders it with only two lines (as opposed to three lines you saw being actually displayed in the powerpoint software), so in the Aspose code, the third row’s height is shorter than how it’s being rendered in PowerPoint. As a result, the bar in the fourth row is out of the alignment, because we use the combination of each table row’s height and table’s X value to calculate the X value for each bar graph. If you manually make the first column of the third data row two lines, you will see the bar in the fourth row will be placed perfectly in its cell. And this only happens if the powerpoint content is in non-English.


#4

Hi Nan,


I have observed your comments. Can you please share sample code and environment details with us so that we can investigate more to resolve issue.

Best Regards,

#5

Here is the complete code that you can use to reproduce the issue.
Please modify the variable “filePath”'s value according to your own
environment.

using (Presentation pres = new Presentation())
{
var tableWidth = (float)691.2;
var fontSize = (float)8;
var headerData = new string[] { “Élément ou catégorie”, “ToptopTopTopTo 2020 : superposition de favorabilité”, “Différence entre TopTopTopTopTo 2020 et Norme de haute performance TestingValueV [TestingVale], score Favorable” };
var rowData = new List<string[]>
{
new []
{
“1. Les personnes avec travaille se montrent coopératives lorsqu’il s’agit d’accomplir le travail.”,
“92”, “14”
},
new []
{
“48. Je suis habilité(e) à prendre les mesures nécessaires pour répondre aux besoins des clients.”,
“59”, “30”
},
new [] {“49. Mon gestionnaire apprécie et reconnait ma contribution au travail.”, “75”, “N/A”}
};
var tableX = (float)111.168;
var tableY = (float)128.519928;
double[] rows = new double[] { 1 };
var baseColWidths = new double[] { (double)tableWidth / 100 * 30, (double)tableWidth / 100 * 20, (double)tableWidth / 100 * 22 };
ISlide sld = pres.Slides[0];
//Add table shape to slide
ITable tbl = sld.Shapes.AddTable(tableX, tableY, baseColWidths.ToArray(), rows);
var i = 0;
foreach (var header in headerData)
{
var cell = tbl.Rows[0][i];
var textFrame = cell.TextFrame;
textFrame.Paragraphs.Clear();
textFrame.Paragraphs.AddFromHtml(header);
cell.BorderBottom.FillFormat.FillType = FillType.Solid;
cell.BorderBottom.FillFormat.SolidFillColor.Color = Color.Gray;
cell.BorderBottom.Width = 3.0;
cell.BorderTop.FillFormat.FillType = FillType.Solid;
cell.BorderTop.FillFormat.SolidFillColor.Color = Color.Gray;
cell.BorderTop.Width = 3.0;
cell.BorderLeft.FillFormat.FillType = FillType.Solid;
cell.BorderLeft.FillFormat.SolidFillColor.Color = Color.Gray;
cell.BorderLeft.Width = 3.0;
cell.BorderRight.FillFormat.FillType = FillType.Solid;
cell.BorderRight.FillFormat.SolidFillColor.Color = Color.Gray;
cell.BorderRight.Width = 3.0;
                <span style="color:#2b91af;">IParagraph</span> p = textFrame.Paragraphs[0];
                p.ParagraphFormat.DefaultPortionFormat.FillFormat.FillType = <span style="color:#2b91af;">FillType</span>.Solid;
                p.ParagraphFormat.DefaultPortionFormat.FontHeight = fontSize;
                p.ParagraphFormat.DefaultPortionFormat.FillFormat.SolidFillColor.Color = <span style="color:#2b91af;">Color</span>.White;
                p.ParagraphFormat.Alignment = <span style="color:#2b91af;">TextAlignment</span>.Center;
                p.ParagraphFormat.DefaultPortionFormat.LatinFont = <span style="color:blue;">new</span> <span style="color:#2b91af;">FontData</span>(<span style="color:#a31515;">"Segoe UI"</span>);
                i++;
            }

            <span style="color:blue;">var</span> rowIndex = 1;
            <span style="color:blue;">foreach</span> (<span style="color:blue;">var</span> row <span style="color:blue;">in</span> rowData)
            {
                i = 0;
                <span style="color:blue;">var</span> tblRow = tbl.Rows.AddClone(tbl.Rows[0], <span style="color:blue;">false</span>)[0];
                <span style="color:blue;">foreach</span> (<span style="color:blue;">var</span> currentRowData <span style="color:blue;">in</span> row)
                {
                    <span style="color:blue;">var</span> cell = tbl.Rows[rowIndex][i];
                    <span style="color:blue;">var</span> textFrame = cell.TextFrame;
                    textFrame.Paragraphs.Clear();
                    <span style="color:blue;">if</span> (i == 1)
                    {
                        <span style="color:green;">//Add bar here</span>
                        <span style="color:blue;">float</span> horizontalPadding = 7f;
                        <span style="color:blue;">float</span> verticalPadding = 5f;
                        <span style="color:blue;">int</span> height = 12;
                        <span style="color:blue;">var</span> width = (<span style="color:blue;">float</span>)cell.Width - (2 * horizontalPadding);
                        <span style="color:blue;">var</span> x = (<span style="color:blue;">float</span>)(cell.OffsetX + cell.Table.X);
                        <span style="color:blue;">var</span> y = (<span style="color:blue;">float</span>)(cell.OffsetY + cell.Table.Y);
                        <span style="color:#2b91af;">Func</span><<span style="color:blue;">double</span>, <span style="color:blue;">float</span>> calculateWidth = val => (width / 100) * (<span style="color:blue;">float</span>)val;

                        <span style="color:blue;">var</span> rectX = x + horizontalPadding;
                        <span style="color:blue;">var</span> currentRect = sld.Shapes.AddAutoShape(<span style="color:#2b91af;">ShapeType</span>.Rectangle,
                                rectX, y + verticalPadding,
                                calculateWidth(<span style="color:#2b91af;">Double</span>.Parse(currentRowData)), height);
                        currentRect.FillFormat.FillType = <span style="color:#2b91af;">FillType</span>.Solid;

                        <span style="color:#2b91af;">Color</span> foreColor = <span style="color:#2b91af;">Color</span>.Black;
                        <span style="color:#2b91af;">Color</span> backgroundColor = <span style="color:#2b91af;">Color</span>.Green;
                        currentRect.FillFormat.SolidFillColor.Color = backgroundColor;
                        currentRect.LineFormat.FillFormat.FillType = <span style="color:#2b91af;">FillType</span>.NoFill;
                        currentRect.LineFormat.Width = 0;

                        <span style="color:blue;">var</span> valueTextFrame = currentRect.AddTextFrame(<span style="color:blue;">string</span>.Format(<span style="color:#a31515;">"</span><span style="color:mediumseagreen;">{0:F0}</span><span style="color:#a31515;">%"</span>, <span style="color:#2b91af;">Double</span>.Parse(currentRowData)));
                        valueTextFrame.TextFrameFormat.CenterText = <span style="color:#2b91af;">NullableBool</span>.True;
                        valueTextFrame.OnEachPortion(portion =>
                        {
                            <span style="color:blue;">var</span> portionFormat = portion.PortionFormat;
                            portionFormat.FillFormat.FillType = <span style="color:#2b91af;">FillType</span>.Solid;
                            portionFormat.FillFormat.SolidFillColor.Color = foreColor;
                            portionFormat.FontHeight = fontSize;

                        });

                        valueTextFrame.OnEachParagraph(para =>
                        {
                            para.ParagraphFormat.DefaultPortionFormat.LatinFont = <span style="color:blue;">new</span> <span style="color:#2b91af;">FontData</span>(<span style="color:#a31515;">"Segoe UI"</span>);
                        });
                    }
                    <span style="color:blue;">else</span>
                    {
                        textFrame.Paragraphs.AddFromHtml(currentRowData);
                        cell.BorderBottom.FillFormat.FillType = <span style="color:#2b91af;">FillType</span>.Solid;
                        cell.BorderBottom.FillFormat.SolidFillColor.Color = <span style="color:#2b91af;">Color</span>.Gray;
                        cell.BorderBottom.Width = 3.0;
                        cell.BorderTop.FillFormat.FillType = <span style="color:#2b91af;">FillType</span>.Solid;
                        cell.BorderTop.FillFormat.SolidFillColor.Color = <span style="color:#2b91af;">Color</span>.Gray;
                        cell.BorderTop.Width = 3.0;
                        cell.BorderLeft.FillFormat.FillType = <span style="color:#2b91af;">FillType</span>.Solid;
                        cell.BorderLeft.FillFormat.SolidFillColor.Color = <span style="color:#2b91af;">Color</span>.Gray;
                        cell.BorderLeft.Width = 3.0;
                        cell.BorderRight.FillFormat.FillType = <span style="color:#2b91af;">FillType</span>.Solid;
                        cell.BorderRight.FillFormat.SolidFillColor.Color = <span style="color:#2b91af;">Color</span>.Gray;
                        cell.BorderRight.Width = 3.0;

                        <span style="color:#2b91af;">IParagraph</span> p = textFrame.Paragraphs[0];
                        p.ParagraphFormat.DefaultPortionFormat.FillFormat.FillType = <span style="color:#2b91af;">FillType</span>.Solid;
                        p.ParagraphFormat.DefaultPortionFormat.FontHeight = fontSize;
                        p.ParagraphFormat.DefaultPortionFormat.FillFormat.SolidFillColor.Color = <span style="color:#2b91af;">Color</span>.Black;
                        p.ParagraphFormat.Alignment = <span style="color:#2b91af;">TextAlignment</span>.Left;
                        textFrame.TextFrameFormat.AnchoringType = <span style="color:#2b91af;">TextAnchorType</span>.Top;
                        textFrame.OnEachParagraph(
                            paragraph =>
                            {
                                paragraph.ParagraphFormat.MarginLeft = 15F;
                            });
                        p.ParagraphFormat.DefaultPortionFormat.LatinFont = <span style="color:blue;">new</span> <span style="color:#2b91af;">FontData</span>(<span style="color:#a31515;">"Segoe UI"</span>);
                    }
                    i++;
                }

                rowIndex++;
            }

            <span style="color:green;">//Write PPTX to Disk</span>
            <span style="color:blue;">string</span> filePath = <span style="color:#a31515;">@"Your file path goes here..."</span>;
            <span style="color:#2b91af;">Guid</span> guid = <span style="color:#2b91af;">Guid</span>.NewGuid();
            pres.Save(filePath + <span style="color:#a31515;">"table_"</span> + guid.ToString() +"<span style="color:#a31515;">.pptx"</span>, <span style="color:#2b91af;">SaveFormat</span>.Pptx);
        }</pre>

#6

Hi Nan,


Can you please share environment details and which Aspose.Slides version you are using on your end so that we can further investigate.

Best Regards,

#7

The code is written in the project where the target framework is .Net 4.5. And the Aspose.Slide’s version is 14.8.


#8

Hi Nan,


Can you please try to use Aspose.Slides latest version 16.12.0 on your end. Please share feedback with us if there is still an issue.

Best Regards,

#9

The latest Aspose.Slide.dll (16.12) didn’t fix the issue. Can you try reproducing the problem using the code I provided and look into it?


#10
Hi Nan,

I have observed your comments. A ticket with ID SLIDESNET-38238 has been created in our issue tracking system to investigate and resolve the issue. This thread has been associated with the ticket so that we may share the notification with you once issue will be fixed.

We are sorry for your inconvenience,

#11

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