Paragraph.Justification broken

This is somewhat related to Paragraph.Justification not working as expected - Free Support Forum - aspose.com

Hi,
It seems Paragraph.Justification is broken.
When creating a PSD from scratch, I’m unable to horizontally align my text and all text move both horizontally and vertically (1px) when edited in Photoshop.

When opening the file it looks like this:
justOpened.png (4.6 KB)
…after editing them (not making any actual change, just click it with the text tool):
afterUpdate.png (1.8 KB)
(both images have lines to help visualice the issue, that are not in the code sample, if you need the code WITH the lines code included, I can provide).
Please advice.

Framework: net8.0
Aspose.Drawing: 25.2.0
Aspose.PSD: 25.1.0

using Aspose.PSD;
using Aspose.PSD.FileFormats.Psd;

new License().SetLicense("XXXX");

var CreateText = (PsdImage psd, string text, int y, Color fontColor, JustificationMode hAlign) =>
{
    var textLayer = psd.AddTextLayer(text, new Rectangle(75, y, 225, 75));

    textLayer.TextData.Items.ToList().ForEach(i =>
    {
        i.Style.FontName = FontSettings.GetAdobeFontName("Arial");
        i.Style.FontSize = 48;
        i.Style.FillColor = fontColor;
        i.Paragraph.Justification = hAlign;
    });

    textLayer.TextData.UpdateLayerData();
};

using (var psd = new PsdImage(400, 400))
{
    var graphics = new Graphics(psd);
    {
        graphics.Clear(Color.White);
    }

    // LEFT ALIGNMENT TEST (red)
    CreateText(psd, "I(left)", 50, Color.Red, JustificationMode.Left);

    // CENTER ALIGNMENT TEST (green)
    CreateText(psd, "I(center)", 150, Color.Green, JustificationMode.Center);

    // RIGHT ALIGNMENT TEST (blue)
    CreateText(psd, "I(right)", 250, Color.Blue, JustificationMode.Right);

    psd.Save("myRevisitedTest.psd");
}

@gonzalo.gatti.ethofy

It seems you are experiencing issues with the Paragraph.Justification feature in Aspose.PSD, particularly when creating a PSD file from scratch. The text alignment appears to be misaligned after editing in Photoshop, which is not the expected behavior.

To address this, you can refer to the following example that demonstrates how to set the justification for text layers correctly. This example shows how to create a PSD file with text layers that have different justification modes (left, center, right):

using Aspose.PSD;
using Aspose.PSD.FileFormats.Psd;
using System.Drawing;

var CreateText = (PsdImage psd, string text, int y, Color fontColor, JustificationMode hAlign) =>
{
    var textLayer = psd.AddTextLayer(text, new Rectangle(75, y, 225, 75));

    textLayer.TextData.Items.ToList().ForEach(i =>
    {
        i.Style.FontName = FontSettings.GetAdobeFontName("Arial");
        i.Style.FontSize = 48;
        i.Style.FillColor = fontColor;
        i.Paragraph.Justification = hAlign;
    });

    textLayer.TextData.UpdateLayerData();
};

using (var psd = new PsdImage(400, 400))
{
    var graphics = new Graphics(psd);
    graphics.Clear(Color.White);

    // Create text layers with different alignments
    CreateText(psd, "I(left)", 50, Color.Red, JustificationMode.Left);
    CreateText(psd, "I(center)", 150, Color.Green, JustificationMode.Center);
    CreateText(psd, "I(right)", 250, Color.Blue, JustificationMode.Right);

    psd.Save("myRevisitedTest.psd");
}

Make sure to check the justification settings for each text portion in your code. If the justification is set correctly but the issue persists after editing in Photoshop, it may be worth checking the version compatibility of Aspose.PSD with Photoshop, as rendering discrepancies can sometimes occur between different software versions.

If you continue to face issues, consider providing the specific code that includes the lines for better context, as it may help in diagnosing the problem further.

For additional insights, you might want to look at the example that demonstrates the support of the JustificationMode enum for setting text alignment in text portions, which can be found in the Aspose.PSD GitHub repository here.

If you have any further questions or need more assistance, feel free to ask!

Sources:
[1]: SupportTextStyleJustificationMode.cs

Hi.

I fail to spot the relevant change between my code and the updated code you’ve provided.

Regarding the GitHub’s sample, I haven’t test it yet, but my understanding is that is not the same scenario as GitHub’s has different alignments within the same layer, I have different layers.

@gonzalo.gatti.ethofy
I checked the previous related issue and this one. At this moment Aspose.PSD has issues with the updating of resources with the Text Layer Position and can not render Text pixel perfect. For fixing these types of issues was created a list of tickets:

Issue ID(s): PSDNET-2345,PSDNET-2092

Aspose.PSD team work on this, but the issue is complex.