Issue reading font size

The issue is when I want to try to read the font size value. On the one hand, I have a textlayer in the PSD with a text that has 50.07px (pixels), opening it with PS, but when I want to read the psd with aspose.psd, I get 25.0368 px, wich is different from PS.
Font size in PSD:
print1.png (38.1 KB)
Font size with Aspose.Psd:
print2.png (46.9 KB)
Psd used:
example.zip (8.9 MB)
Code used (minimum required code):
code.zip (320 Bytes)

@cristianortegaethofy please take into account that your Text Layer was resized manually in PS.

Please check API Reference psd text transform matrix

I’ve updated your code to get the correct size if the Transform Matrix is changed.

 using (PsdImage image = (PsdImage)Aspose.PSD.Image.Load(input))
 {
      foreach (var layerItem in image.Layers)
      {
           if (layerItem.GetType() != typeof(TextLayer)) continue;
           var layerToReadText = (TextLayer)layerItem;

           var matrix = layerToReadText.TransformMatrix;

           foreach (var item in layerToReadText.TextData.Items)
           {
                var size = item.Style.FontSize;
                var sizeInPs = size * matrix[3];
                Console.WriteLine(sizeInPs);
           }
        }
    }

@Dmitriy.Sorokin thank you a lot, it worked perfectly. A query about Transform Matrix, you used position number 3, (FontSize = (item.Style.FontSize * matrix[3]) why this position and not another?

@cristianortegaethofy transformation matrix can be different, so m[3] works only for your case where you haven’t any rotation

Here is your transformation matrix:

| a b 0|
| c d 0|
| tX tY 0|

a = cos(q)
b = sin(q)
c = –sin(q)
d = cos(q)
tx - Text Position X
ty - Text Position Y
zeros - only foor the 3d transformation. PSD doesn’t use it in this case

so, the length of matrix is 6 in Aspose.PSD,

The full formula will be:
realSize = c * size + d * size; or realSize = m[2] * size + m[3] * size;

1 Like

ok thanks for the explanation!, works perfect

@Dmitriy.Sorokin I come with another example with 3 texts layers where I make the formula as we had discussed before:
realSize = m[2] * size + m[3] * size;
but in this case in this PSD where there are 3 textlayers in the textlayer with #text_003# gives an erroneous result with 36.031433117378 instaed of 18 px
PSD used:
example-ticket-textFontSize.zip (1.4 MB)
Code used:

using (PsdImage image = (PsdImage)Aspose.PSD.Image.Load(input))
{
foreach (var layerItem in image.Layers)
{
if (layerItem.GetType() != typeof(TextLayer)) continue;
var layerToReadText = (TextLayer)layerItem;

       var matrix = layerToReadText.TransformMatrix;

       foreach (var item in layerToReadText.TextData.Items)
       {
            var size = item.Style.FontSize;
            var sizeInPs =  size * matrix[2] + size * matrix[3];
            Console.WriteLine(sizeInPs);
       }
    }
}

Aspose.PSD will check it and I’ll write you back

@Dmitriy.Sorokin ok thank you I wait for the answer

@Dmitriy.Sorokin is there any news about this font size problem?

We made additional investigation, and I can’t conrirm the issue. Formula gives the correct size in Pt that is similar to the data in the PS UI. If you need to get the size in Pixels, you can use:
layerToReadText.Font.Size property. It’ll be ~18.86. Also, you can use https://reference.aspose.com/psd/net/aspose.psd.fileformats.psd.layers.text/itextportion/style/ FontSize property.

picture (5.6 KB)

@Dmitriy.Sorokin ok, the formula that gives me ~36 is (size * matrix[2] + size * matrix[3])
where size come from (item.Style.FontSize) with ~18 giving the different result.
I tried with the following code, with the formula provided above and on the other hand separately with FontSize property.
Code:

foreach (var layerItem in image.Layers)
{
        if (layerItem.GetType() != typeof(TextLayer)) continue;
        var layerToReadText = (TextLayer)layerItem; 
        var matrix = layerToReadText.TransformMatrix;

        foreach (var item in layerToReadText ) 
       {
	         var sizeProp = item.TextData.Items[0].Style.FontSize;
             var sizeWithFormula = sizeProp * matrix[2] + sizeProp * matrix[3];
             Console.WriteLine("Textlayer content: " + item.TextData.Items[0].Text);
             Console.WriteLine("sizeProp: " + sizeProp);
             Console.WriteLine("sizeWithFormula: " + sizeWithFormula);
       }      
    }
}

This is what the console write of the above code gives me:
2023-07-18 162220.png (4.3 KB)
They do not give the expected results as is in the PS UI. Both using only FontSize prop and formula.

@cristianortegaethofy I can not confirm your issue. Did you try the file that was sent to us or any other? Could you please clarify what’s result you want to get?
picture.png (42.9 KB)

Your screen is also similar to my result

It gives me a different result using the same PSD. I don’t know why but there must be something different.
In the “Textlayer content: #text_003#” gives me “sizeProp: 18” but “sizeWithFormula: 36.03143311737804” instaed of 18, as you showed in the image with the results:
2023-07-18 162220.png (4.6 KB)

@cristianortegaethofy
Could you please provide additional information?

  1. Have you installed font Segoe UI Variable Static Display?
  2. Operating system details
  3. Version of Aspose.PSD for .Net with the Net Framework version

And any additional details that can help us to find the reason of issue.

Could you please check additionally that you used the same file that was sent for us? It’s possible, that file can be corrupted in the runtime.

Hello, I answer you the questions

  1. Have you installed font Segoe UI Variable Static Display?
    Yes, I have it installed

  2. Operating system details
    Pc_info_.png (68.5 KB)

  3. Version of Aspose.PSD for .Net with the Net Framework version
    I have tried with the versions “23.7.0” and “23.6.0” with Net Framework "netstandard2.0"

-Could you please check additionally that you used the same file that was sent for us?
-I have used the same psd that I sent before, I upload it again with the name of v2
example-ticket-textFontSize-v2.zip (1.4 MB)

And any additional details that can help us to find the reason of issue.
I have tried it with the same code that I have sent before, I will leave it here again just in case:
code_v2.zip (469 Bytes)
Result:
result.png (4.4 KB)
I keep in touch for any questions

@cristianortegaethofy I checked this on Win 11, still can not confirm issue. I’ll write you back on 7/08/2023, after the addiotinal checks on Win 11.