Text rendering errors with THMGDIPaintPanel

This section is for programmers. Please use it for all discussons on interfacing help with your applications and related subjects.

Moderators: Alexander Halser, Michael Schwarzl

Post Reply
Mason Wheeler
Posts: 3
Joined: Tue Feb 11, 2014 9:00 pm

Text rendering errors with THMGDIPaintPanel

Unread post by Mason Wheeler »

I'm having some serious problems using THMGDIPaintPanel.

I create a THMTileItem and try to render text on it, using code based on the demo, but instead of truncating the text with an ellipsis, it draws the entire thing out, far beyond the bounds of the THMTileItem. It appears that when the Canvas.Font.Size property is about 14 or higher, the HMEllipsifyText routine works correctly, but when it's smaller than that, no actual ellipsifying takes place.

Sample code:

Code: Select all

procedure TStartupScreen.InternalCreateWhatsNewItem(const aScale, aIndex: Integer; const aitem: TInputItem);
var
  tmpX: Integer;
  tmpY: Integer;
  tmpW: Integer;
  header: String;
  description: String;
  result: THMTileItem;
begin
  tmpX := _x(0); //
  tmpY := _y2(AIndex + 3);
  tmpW := _w(2);

  Canvas.Font.Size := 14;
  header := HMEllipsifyText(False, aItem.title, Canvas, tmpW - _dpi(20));
  Canvas.Font.Size := 10;
  description := HMEllipsifyText(True, aItem.description, Canvas, tmpW - _dpi(20), _y2(1));

  Result := THMTileItem.CreateEx(GDIPaintPanel, tmpX, tmpY, tmpW, _h2(1), AScale, AScale, FColorSet[2], clBlack, header, description, nil, clGreen, taLeftJustify, 1);
  Result.HeaderVerticalAlign := taAlignTop;
  Result.TextGap := 7;
  Result.DescriptionFontSize := Canvas.Font.Size;
  Result.TitleFontSize := 14;
  Result.PrepareItem;
end;
When the description string is long enough that it should be truncated, it instead appears to draw the entire text, aligned so that the bottom of the rendered text will be at the bottom of the THMTileItem's position and working its way up from there, so that the top several lines are drawn above the top of the THMTileItem.

If I decrease the font sizes to 12 and 8, respectively, then the title line doesn't get ellipsified either.

Does anyone have any idea what's going on here and how I can fix it?
User avatar
Michael Schwarzl
Posts: 39
Joined: Tue Apr 10, 2007 4:44 pm
Location: Golling, Austria

Re: Text rendering errors with THMGDIPaintPanel

Unread post by Michael Schwarzl »

Hello Mason,

I tested your code snippet and it works fine for me. During the development of the component I experienced some rendering differences between GDI and GDIplus. The ellipsify method uses the "old" GDI API and the panel is rendered using GDIplus. So the calculated width differs from the rendered. The difference increases with smaller fonts.
I also had troubles with an self created font which has not been installed correctly. Here is a link for it: http://support.microsoft.com/kb/307208

You can modify the right margin to "optimize" the visual experience.

Best regards,
Michael
-----------------------------
Michael Schwarzl
Senior Developer, EC Software
Mason Wheeler
Posts: 3
Joined: Tue Feb 11, 2014 9:00 pm

Re: Text rendering errors with THMGDIPaintPanel

Unread post by Mason Wheeler »

I've created a simple test case that reproduces this. It's a modified version of the sample project shipped with the component set.

http://pastebin.com/VbSXneVf

The result can be seen at http://i.imgur.com/Bt1vGuj.png. Look along the left edge.

Are you able to reproduce this at your end?
User avatar
Michael Schwarzl
Posts: 39
Joined: Tue Apr 10, 2007 4:44 pm
Location: Golling, Austria

Re: Text rendering errors with THMGDIPaintPanel

Unread post by Michael Schwarzl »

Yes I can reproduce the problem. Please do not use Path eillipsify for normal texts. Please change the first Parameter to false in method InternalCreateWhatsNewItem:

Code: Select all

  desc := HMEllipsifyText(False, desc, Canvas, tmpW - _dpi(20));
Best regards,
Michael
-----------------------------
Michael Schwarzl
Senior Developer, EC Software
Mason Wheeler
Posts: 3
Joined: Tue Feb 11, 2014 9:00 pm

Re: Text rendering errors with THMGDIPaintPanel

Unread post by Mason Wheeler »

Aha! That fixes it. Thank you! :D
Post Reply