We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Displaying text in multiple lines in a shape rendering incorrectly

If i use the code below, I can make a circle with two lots of text in it, with each segment having different styles.

 var firstLine = new TextSegment
      {
        Text = "Header Text",
        TextState = new TextState
        {
          ForegroundColor = Color.Purple,
          FontSize = 12
        }
      };
      var secondLine = new TextSegment
      {
        Text = "Child Text",
        TextState = new TextState
        {
          ForegroundColor = Color.Black,
          FontSize = 10
        }
      };

      circle.Text = new TextFragment();
      circle.Text.Segments.Add(firstLine);
      circle.Text.Segments.Add(secondLine);

Which sets the style correctly, but the two segments are concatanated rather than being on seperate lines.

I.e The output is

Header TextChild Text

, and I want it to be

Header Text
Child Text

If I add a carriage return into the header like “Header Text \r\n”, Or append a segment between the two which utilises Environment.NewLine, then the text is broken, but then all styling is ignored and it revertys back to the base documents styling.

This is clearly a bug as I cannot see this is desired behaviour? How would I break text?

I see on the forums that you can use TextParagraph for this in some scenarios, but shapes like the circle do not accept anything other than a text property (so limited to text fragments and segments)

Edit:
Also tried appending a new segment between 1 and 2, with:

 var lineBreak = new TextSegment
      {
        Text = "\r\n",
      };

Which still causes the same issue. I went down this route as it looks like line breaks create additional segments anyway.

I also tried appending styles once the segments had been “constructed”

Final edit
It appears that the behaviour is, if a text segment contains a line break, ignore any defined segment styling and adopt the parent text fragments style.
I can confirm this by setting the circle.text foreground color to red and the final output is red text.

I have also observed that the TextState is still persistant and valid at the point the document is being constructed, so this is an issue in the rendering I think.

@R_C_D_T

We were able to replicate the issue using following code snippet with Aspose.PDF for .NET 19.9:

Document doc = new Document();
// Add page to pages collection of PDF file
Page page = doc.Pages.Add();
page.PageInfo.Margin = new MarginInfo() { Bottom = 0, Left = 0, Right = 0, Top = 0 };
// Create Graph instance
Aspose.Pdf.Drawing.Graph graph = new Aspose.Pdf.Drawing.Graph((float)(page.PageInfo.Width), (float)page.PageInfo.Height);
// Add graph object to paragraphs collection of page instance
page.Paragraphs.Add(graph);
Aspose.Pdf.Drawing.Circle circle = new Aspose.Pdf.Drawing.Circle(100f, 100f, 100);
var firstLine = new TextSegment
{
 Text = "Header Text",
 TextState = new TextState
 {
  ForegroundColor = Color.Purple,
  FontSize = 12
 }
};
var secondLine = new TextSegment
{
 Text = "Child Text",
 TextState = new TextState
 {
  ForegroundColor = Color.Red,
  FontSize = 12
 }
};
circle.Text = new TextFragment();
circle.Text.Segments.Add(firstLine);
circle.Text.Segments.Add(secondLine);
graph.Shapes.Add(circle);
doc.Save(dataDir + "TextinCircle.pdf");

We have logged the issue as PDFNET-47029 in our issue tracking system. We will further look into details of it and keep you informed on its rectification status. Please be patient and spare us little time.

We are sorry for the inconvenience.

Thanks. As you do monthly releases, what is the sort of typical timeframe on things like this? Or if there is a long wait, what sort of workarounds is there to achieve a similar output? It seems like there is an issue with components with text state inheritence.

@R_C_D_T

The logged issues are resolved on first come first serve basis if they are logged under normal support model unlike priority support where issues are dealt with high precedence. The resolution time of low priority issues depends upon their complexity and number of high priority issues logged prior to it.

We will be able to offer any workaround or fix of this issue as soon as it is investigated. Sometimes, an issue is resolved sooner despite being under free support model due to common API component which is already under process of refactoring and maintenance. We will keep you posted on the status of issue resolution as soon as we have some definite updates in this regard. Please spare us little time.

We are sorry for the inconvenience.

@asad.ali this appears to also be the case for all text fragments.
If you have a collection of styled text segments in a text fragment, and insert a line break (\r\n or Environment.NewLine) it will break but not have any styling.

@R_C_D_T

We have recorded your feedback along with the logged ticket and will let you know in case of additional updates as soon as we have some.

Is there any movement on PDFNET-47029 or an estimated plan of it being resolved?

@R_C_D_T

We regret to share that the issue is not yet resolved due to other high priority issues in the queue and we are afraid that we cannot provide any reliable ETA at the moment. However, we will surely let you know as soon as some certain updates are available in this regard. Please spare us some time.

We are sorry for the inconvenience.

The issues you have found earlier (filed as PDFNET-47029) have been fixed in Aspose.PDF for .NET 20.7.