Agamnentzar / ag-psd

Javascript library for reading and writing PSD files
Other
496 stars 66 forks source link

Why is the fontSize in the styleRuns attribute smaller than the actual value after parsing? #152

Open LvHuaiSheng opened 1 year ago

LvHuaiSheng commented 1 year ago

Why is the fontSize in the styleRuns attribute smaller than the actual value after parsing?

ad-psd parse:

图片

Actual value in Photoshop

图片

FontSize without styleRuns attribute is normal.

图片 图片 May I ask why?

Agamnentzar commented 1 year ago

The font size that Photoshop shows in the UI is not the actual font size saved in the PSD file, they premultiply the font size by transform so it's easier to compare font sizes between boxes, you need to account for transform scale when interpreting font size.

LvHuaiSheng commented 1 year ago

Thank you, where can I find the specific calculation formula or documentation?

Agamnentzar commented 1 year ago

There is no documentation for it, I had to guess.

Transform is a 2d matrix and has values like this "transform": [0.8432519079124537, 0, 0, 1.036168606195403, 151.08313301198413, 233.05700446108017], where first element is scaleX and 4th one is scaleY, 5th and 6th are offsetX and offsetY

I'm not actually sure how they calculate it but I think you take the fontSize and multiply it by scaleX or scaleY or an average of both of them, you'd have to check which gives you the value that matches the one from UI.

LvHuaiSheng commented 1 year ago

There is no documentation for it, I had to guess.

Transform is a 2d matrix and has values like this "transform": [0.8432519079124537, 0, 0, 1.036168606195403, 151.08313301198413, 233.05700446108017], where first element is scaleX and 4th one is scaleY, 5th and 6th are offsetX and offsetY

I'm not actually sure how they calculate it but I think you take the fontSize and multiply it by scaleX or scaleY or an average of both of them, you'd have to check which gives you the value that matches the one from UI.

Thanks for the reply, I'll give it a try