Agamnentzar / ag-psd

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

Font size is incorrect #142

Closed ghost closed 1 year ago

ghost commented 1 year ago

The parsed font size is larger than the one I set in my PSD editor (Photopea).

Agamnentzar commented 1 year ago

The font size shown in the UI (in photoshop and photopea) is multiplied by transform scale so the relative sizes between text boxes still match after you transform some of them.

ghost commented 1 year ago

Thanks, could you give me the the calculation and properties to multiply by.

Agamnentzar commented 1 year ago

I don't know exact calculation but the field is text.transform I suspect they use either horizontal or vertical scale or maybe average of both. There are methods for extracting scale from a matrix.

ghost commented 1 year ago

I have found a function which extracts scale from a matrix :

`function decomposeMatrix(m) { var E = (m[0] + m[3]) / 2; var F = (m[0] - m[3]) / 2; var G = (m[2] + m[1]) / 2; var H = (m[2] - m[1]) / 2;

var Q = Math.sqrt(E E + H H); var R = Math.sqrt(F F + G G); return { scaleX: Q + R, scaleY: Q - R, }; }`

But in the transform object the first fours items are [1,0,0,1] which means the function returns 1, multiplying by this obviously doesn't change the font size.

Agamnentzar commented 1 year ago

Hmm, that's weird. If the transform doesn't have any scaling then the font sizes should match. Unless they're in different units for some reason.

ghost commented 1 year ago

No they're both using px. Would you like me to send you the PSD?

Agamnentzar commented 1 year ago

sure, that would help to find the issue.

ghost commented 1 year ago

https://frankastin.co.uk/wp-content/themes/frankastin/happy_30th_birthday.psd

Agamnentzar commented 1 year ago

I'm getting ERR_CONNECTION_REFUSED error

ghost commented 1 year ago

I am so sorry, the font size is correct, it was using a different font. I am an idiot !

Agamnentzar commented 1 year ago

No problem, glad it's working now.