|
From: Roode, E. <er...@ba...> - 2008-07-18 12:46:27
|
On 17 July 2008, Sean Healy wrote:
>
> ($x, $y) = $Label->GetTextExtentPoint32($string);
Upon further experimentation, there is something not quite right with
that. The width it returns is too wide. There seems to be some sort
of per-character skew -- short strings are very accurate; longer
strings get progressively worse.
Here is a sample program to demonstrate the problem. I have attached
a screenshot of the resulting output.
use strict;
use warnings;
use Win32::GUI();
my $main = Win32::GUI::Window->new (-name => 'Main', -width => 300,
-height => 150);
my $top = 0;
for my $str ('', 'A', 'AAAAA', 'This is a test')
{
# Demonstrate the width as computed
my $demo = $main->AddLabel(-text => 'dummy', -top => $top,
-left => 150, -background => 0xFF80FF);
my ($w, $h) = $demo->GetTextExtentPoint32($str);
$demo->Text($str);
$demo->Width($w);
# Label the demo output
my $info = $main->AddLabel(-text => "'$str' => w=$w",
-top => $top, -left => 0);
$top += $info->Height;
}
$main->Show;
Win32::GUI::Dialog;
exit;
sub Main_Terminate { -1; }
Why do the longer fields have a large error in the computed width?
Thanks,
Eric
|