Posts: 34
Threads: 23
Joined: Jul 2018
Reputation:
2
Location: Sweden
Hello!
I need a function to get the height and width of a string in pixels if I know the TIWFont used.
Best regards, Mikael
Posts: 2,264
Threads: 197
Joined: Mar 2018
Reputation:
86
Location: Auckland, New Zealand
When you set the size of the font in points (property Size) IntraWeb automatically calculates and updates the property PxSize which contains the font size in pixels.
You can also use
class function TIWFont.PtToPx(AFontSize: Integer): Integer;
Just use it like:
PxSize := TIWFont.PtToPx(12);
Posts: 34
Threads: 23
Joined: Jul 2018
Reputation:
2
Location: Sweden
Hello!
I Don't understand how this can help me :-) What I need is the length AND height of a string in pixels!
Your function doesn't even contain the string!
And there is no PtToPy function for calculating the height!
Best regards, Mikael
Posts: 2,264
Threads: 197
Joined: Mar 2018
Reputation:
86
Location: Auckland, New Zealand
06-20-2023, 06:09 AM
(This post was last modified: 06-20-2023, 06:09 AM by Alexandre Machado.)
There is no way to predict the size of the text when rendered in a browser using a specific font, if that's what you want.
The only way is effectively rendering the text on the browser side and retrieving the dimensions after applied the style, meaning that you first render it and then you find out the size.