Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2015-09

GetTextExtent on Windows

5 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Jürgen Hestermann

I use "LCLIntf.DrawText" for drawing text on the screen and "Canvas.TextWidth" to determine its width to increment a TRect for the next text output. But these functions cause some trouble with drawing (UTF-8-) text on Windows. In general it works okay but sometimes peculiar clipping or other pixel differences occur. Are the functions above the correct ones to draw and measure text?

After looking a bit at the code I saw that in the file "intfbasewinapi.inc" almost everywhere the Windows API function "GetTextExtentPoint" is used to determine text metrics. But
https://msdn.microsoft.com/en-us/library/windows/desktop/dd144937%28v=vs.85%29.aspx says:
"This function is provided only for compatibility with 16-bit versions of Windows. Applications should call the *GetTextExtentPoint32* <https://msdn.microsoft.com/en-us/library/windows/desktop/dd144938%28v=vs.85%29.aspx> function, which provides more accurate results."

I think many of my problems come from using this deprecated API function. Are there any plans to change this?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20150912/a307f86b/attachment.html>

Reply by email

Marc Weustink
to Jürgen Hestermann
"J?rgen Hestermann" wrote 25 lines
I use "LCLIntf.DrawText" for drawing text on the screen and "Canvas.TextWidth" to determine its width to increment a TRect for the next text output. But these functions cause some trouble with drawing (UTF-8-) text on Windows. In general it works okay but sometimes peculiar clipping or other pixel differences occur. Are the functions above the correct ones to draw and measure text? After looking a bit at the code I saw that in the file "intfbasewinapi.inc" almost everywhere the Windows API function "GetTextExtentPoint" is used to determine text metrics. But https://msdn.microsoft.com/en-us/library/windows/desktop/dd144937%28v=vs.85%29.aspx says: "This function is provided only for compatibility with 16-bit versions of Windows. Applications should call the *GetTextExtentPoint32* <https://msdn.microsoft.com/en-us/library/windows/desktop/dd144938%28v=vs.85%29.aspx> function, which provides more accurate results." I think many of my problems come from using this deprecated API function. Are there any plans to change this?

If you had a look at the win32 implementation of GetTextExtentPoint then you would have seen that GetTextExtentPoint32 is used internally.

Marc

Reply by email

Jürgen Hestermann
to Marc Weustink
Marc Weustink wrote 7 lines
On September 12, 2015 2:12:32 PM GMT+02:00, "J?rgen Hestermann" wrote: > I think many of my problems come from using this deprecated API > function. > Are there any plans to change this? If you had a look at the win32 implementation of GetTextExtentPoint then you would have seen that GetTextExtentPoint32 is used internally.

Realy?
Where do you find this?
I only find the opposite.
When I follow where Canvas.TextWidth comes from
I end up on in this function from "canvas.inc" (line 1763):

function TCanvas.TextExtent(const Text: string): TSize;
begin
Result.cX := 0;
Result.cY := 0;
if Text='' then exit;
RequiredState([csHandleValid, csFontValid]);
GetTextExtentPoint(FHandle, PChar(Text), Length(Text), Result);
end;

Even more, there is a function declaration for "GetTextExtendPoint32" but it still uses "GetTextExtendPoint" (line 1162 in "intfbasewinapi.inc"):

function TWidgetSet.GetTextExtentPoint32(DC: HDC; Str: PChar; Count: Integer; var Size: TSize): Boolean;
begin
Result := GetTextExtentPoint(DC,Str,Count,Size);
end;

Reply by email

Mattias Gaertner
to Jürgen Hestermann
Show quoted text 25 lines
[...] > If you had a look at the win32 implementation of GetTextExtentPoint then you would have seen that GetTextExtentPoint32 is used internally. > Realy? Where do you find this? I only find the opposite. When I follow where Canvas.TextWidth comes from I end up on in this function from "canvas.inc" (line 1763): function TCanvas.TextExtent(const Text: string): TSize; begin Result.cX := 0; Result.cY := 0; if Text='' then exit; RequiredState([csHandleValid, csFontValid]); GetTextExtentPoint(FHandle, PChar(Text), Length(Text), Result); end; Even more, there is a function declaration for "GetTextExtendPoint32" but it still uses "GetTextExtendPoint" (line 1162 in "intfbasewinapi.inc"): function TWidgetSet.GetTextExtentPoint32(DC: HDC; Str: PChar; Count: Integer; var Size: TSize): Boolean; begin Result := GetTextExtentPoint(DC,Str,Count,Size); end;

TWidgetSet is the base class.
TWin32WidgetSet overrides the base class TWidgetSet.

Mattias

Reply by email

Marc Weustink
to Jürgen Hestermann: Realy? Where do you find this? I only find the opposite. When I follow where…
"J?rgen Hestermann" wrote 24 lines
Am 2015-09-13 um 22:09 schrieb Marc Weustink: > > On September 12, 2015 2:12:32 PM GMT+02:00, "J?rgen Hestermann" wrote: >> I think many of my problems come from using this deprecated API >> function. >> Are there any plans to change this? > If you had a look at the win32 implementation of GetTextExtentPoint then you would have seen that GetTextExtentPoint32 is used internally. > Realy? Where do you find this? I only find the opposite. When I follow where Canvas.TextWidth comes from I end up on in this function from "canvas.inc" (line 1763): function TCanvas.TextExtent(const Text: string): TSize; begin Result.cX := 0; Result.cY := 0; if Text='' then exit; RequiredState([csHandleValid, csFontValid]); GetTextExtentPoint(FHandle, PChar(Text), Length(Text), Result); end;

If you set a breakpoint and start stepping, you will see that you end up in TWin32WidgetSet. The codetools cannot jump to the real widgetset.

Marc

Reply by email