Canvas.TextWidth is not correct!
Posted on 2000-04-19
Problems with exactly scaling a Font:
I tried to fit a text into an Image, so that it starts on the left side and ends on the right side of the Image (as excactly as possible; I know, that
Font.Size is not available for all integer values!).
I used the following simple code:
while ((tw>=Image.Width) and (cvs.Font.Size>3)) do begin
end; // while ...
(Hereby I will assume, that the Image is high enough to contain
the text, so I do not have to check this here).
The result: the text starts on the left, but does only fill about 80%
of the window leaving blanks on the right side. So it seems to me, that cvs.TextWidth returns a value,
which is too small (I can always find an existing Font.Size, which has a better fit!).
I could solve the problem this way:
tw:=round(1.2 * cvs.TextWidth(ed_Text.Text);
but I think, there must be a more exact way to get the correct
size of the Font on the canvas to ensure exact scaling.
100 Points for a different approach to solve the problem of fitting
the text in width (or also in height), which results in a more exact
Thanks for any help