I need to draw some text in a table cell with fixed width (in pixels) and fixed number of text lines. If the text is clipped by cell rectangle, it must end with ellipsis. The problem is I can't calculate the text rectangle correctly (or the TextRect/DrawText procedure isn't working correctly, I'm not sure).
I tried to use this method of calculating text rectangle:
var
TextRect: TRect;
tm: TEXTMETRIC;
...
GetTextMetrics(Canvas.Handle, tm);
TextLineHeight := tm.tmHeight + tm.tmExternalLeading;
TextRect.Bottom := TextRect.Top + TextLineHeight * NumberOfLines;
Canvas.TextRect(TextRect, 'some long long long text',
[tfTop, tfLeft, tfEndEllipsis, tfWordBreak]);
The clipping rectangle has been calculated correctly, but the ellipsis isn't appearing.
Ellipsis appearing when I decrease the height of clipping rectangle by 1 pixel:
TextRect.Bottom := TextRect.Top + TextLineHeight * NumberOfLines - 1;
But some pixels of the bottom line of my text are clipped then.
How to do it correctly?