Font Size in portion of Textlayer

HI! I have a doubt, to change the font size to 29.45pt in a portion, how should it be changed?
Code:
ITextPortion newPortion = textData.ProducePortion();
newPortion.Style.FontSize = 29.45f;

What unit is the font size of portions set to?

@cristianortegaethofy in the common case the size is stored in the PSD file in pixels for the resolution 72 pixel/inch. So, for the example, if your font size is 48px in the image with resolution 72 px/inch, so to make the text with the same size in the PSD image with resolution 300 px/inch you need to use the following formula: size = (48/72)*300 = 200.

@Dmitriy.Sorokin Thanks for the explanation, but I have the following question:
In PS I have the font size unit in PT, and I wanted to set it in the portion at 45 pt for example, should I make that rule and pass it to pt?
For example for 15pt:
var parameterFontSize = 15;
var fontSizeConverted = ((parameterFontSize /72)300); //in px
//fontSizeConverted = 62.5
var fontSizePT = fontSizeConverted
0.75; //in pt
//fontSizePT = 46.875
But in PS I get 93.75 pt and not 15pt as I expected

@cristianortegaethofy Photoshop will convert it by itself. For example, (48 pt in 300 pixels/inch) and (48 pt in 72 pixels/inch) are very different font size. For the 300 pixels/inch your size in Aspose.PSD will be 200, for 72 pixels/inch it will be 48, but both cases will be in PS as 48pt.

ok, thanks, but where should I get the resolution of the image in Aspose.PSD?
var vertical= image.VerticalResolution;
var horizontal = image.HorizontalResolution;
In both cases I get 72 (dpi)

Could you please provice the file where you try to set the font size.

For example in this psd:
Example_FontSize.zip (24.1 KB)
The psd has 2 texts, the first one “#lsak_002#” with 58 pt in PS, and the second text “#lsak_003#” in 32 pt. What I want is to generate portions with the same size for each word respectively

In this case you can use the ProducePortions method. var textItems = textLayer.TextData.ProducePortions(new string[] { “text1”, “text2” }, textLayer.TextData.Items[0].Style, textLayer.TextData.Items[0].Paragraph);

I attach the code how I am creating the portions, and setting the font size, which comes with an input txt file where the size of the text is indicated and I have to set the style of the portion.
Code:
code.zip (1.7 KB)
input-text.txt:
input-text.zip (276 Bytes)
Psd example is same of before:
Example_FontSize.zip (24.1 KB)
how can set fontsize of a portion in 45pt for example?

portions[0].Style.FontSize = 45;

@cristianortegaethofy we need some time to investigate this. I’ll text you back soon.

ok I will wait but until that, let me ask you just to read the value of the font size, I get the value in Layer.TextData.Items[0].Style.FontSize and I want to get the same value that is displayed in PS, how do you get that value?

@cristianortegaethofy

The FontSize value is stored in the PSD file in Pixel as the default unit. This means that when we edit a PSD file and change the FontSize value, it changes in Pixel units. And if in Photoshop settings the unit type was set to Point, we don’t see the same value we set. But if we set the unit type to Pixel, it will start to display as we expect.
To change the unit type, go to:
Edit -> Preferences -> Unit & Rulers…
then in section Units change value Type.

Thanks for answering me, I have changed to pixels in PS but in the code when it is read with Aspose.Psd it brings me a different value
Reading font size in PS:
Captura de pantalla 2023-05-16 100152.png (70.1 KB)
Reading font size with Aspose.PSD:
Captura de pantalla 2023-05-16 100154.png (71.0 KB)
Psd used:
example (2).zip (9.1 MB)
Code used:
code.zip (431 Bytes)

@cristianortegaethofy

We need to investigate this issue. If it’s possible for you, please send us minimum required code for the reproducing the issue.

@Dmitriy.Sorokin ok, thank you, I opened a new topic with minimum required code: https://forum.aspose.com/t/issue-reading-font-size/265003

1 Like