Problem with TppMemo's leading
Hi,
I've encountered a bug with TppMemo's Leading property. We were getting a
"Division by zero" with the following callstack info.
[00E67C09] Ppviewr.TppScreenDevice.DrawStandardText
[40005F5B] System.@HandleAnyException
The problem comes from the following part of the DrawStandardText procedure.
procedure TppScreenDevice.DrawStandardText(aDrawText: TppDrawText);
[...]
begin
[...]
FCanvas.Font.Name :=
TppDeviceSubstitutions.SubstituteFont(aDrawText.Font.Name);
{set font height}
FCanvas.Font.Height := Round(aDrawText.Font.Height * FScaleY);
lbTruncTheText := False;
{font size must at least be one}
if (FCanvas.Font.Height = 0) then
FCanvas.Font.Height := -1;
[...]
GetTextMetrics(FCanvas.Handle, lTextMetric);
{get leading for this font}
if not(aDrawText.IsMemo) then
liLeading := lTextMetric.tmExternalLeading
else
liLeading := Trunc(ppFromMMThousandths(aDrawText.Leading,
utScreenPixels, pprtVertical, nil));
liLineHeight := lTextMetric.tmHeight + liLeading;
if (aDrawText.WrappedText.Count > 0) then
liCalcHeight := Round((lDrawRect.Bottom - lDrawRect.Top) /
aDrawText.WrappedText.Count)
else
liCalcHeight := 0;
if ((Abs(liCalcHeight - liLineHeight) / liLineHeight) <= 0.10) then
{!!!!!!!!!!!!Div by 0 here!!!!!!!!!!!!}
liLineHeight := liCalcHeight
[...]
end;
Here's what happens. aDrawText.Font.Name = 'Arial Narrow',
aDrawText.Font.Size = 8, aDrawText.Font.Height = -11, FScaleY =
0.14962121212
So, on line
FCanvas.Font.Height := Round(aDrawText.Font.Height * FScaleY);
FCanvas.Font.Height := Round(-11 * 0.14962....) //(Round(-1.64) = -2
Setting this sets the FCanvas.Font.Size to 2.
The call to
GetTextMetrics(FCanvas.Handle, lTextMetric);
Returns a value of lTextMetric.tmHeight of 2.
so
liLineHeight := lTextMetric.tmHeight + liLeading; //( liLineHeight =
0)
then on line
if ((Abs(liCalcHeight - liLineHeight) / liLineHeight) <= 0.10) then
{!!!!!!!!!!!!Div by 0 here!!!!!!!!!!!!}
If I use a Leading of -3 or -1 I don't have any problem. But -3 is a little
too much, and -1 is not enough...
Why is this happening?
Is it considered a bug?
if not, why, and what "rules" should I follow to avoid receiving this
error?
if yes, when could we expect it to be fixed?
Info:
Delphi 2006
ReportBuilder 10.03 Standard
OS : Windows 2k
Printer : InfoPrint 1130 with driver version 7.4
I've encountered a bug with TppMemo's Leading property. We were getting a
"Division by zero" with the following callstack info.
[00E67C09] Ppviewr.TppScreenDevice.DrawStandardText
[40005F5B] System.@HandleAnyException
The problem comes from the following part of the DrawStandardText procedure.
procedure TppScreenDevice.DrawStandardText(aDrawText: TppDrawText);
[...]
begin
[...]
FCanvas.Font.Name :=
TppDeviceSubstitutions.SubstituteFont(aDrawText.Font.Name);
{set font height}
FCanvas.Font.Height := Round(aDrawText.Font.Height * FScaleY);
lbTruncTheText := False;
{font size must at least be one}
if (FCanvas.Font.Height = 0) then
FCanvas.Font.Height := -1;
[...]
GetTextMetrics(FCanvas.Handle, lTextMetric);
{get leading for this font}
if not(aDrawText.IsMemo) then
liLeading := lTextMetric.tmExternalLeading
else
liLeading := Trunc(ppFromMMThousandths(aDrawText.Leading,
utScreenPixels, pprtVertical, nil));
liLineHeight := lTextMetric.tmHeight + liLeading;
if (aDrawText.WrappedText.Count > 0) then
liCalcHeight := Round((lDrawRect.Bottom - lDrawRect.Top) /
aDrawText.WrappedText.Count)
else
liCalcHeight := 0;
if ((Abs(liCalcHeight - liLineHeight) / liLineHeight) <= 0.10) then
{!!!!!!!!!!!!Div by 0 here!!!!!!!!!!!!}
liLineHeight := liCalcHeight
[...]
end;
Here's what happens. aDrawText.Font.Name = 'Arial Narrow',
aDrawText.Font.Size = 8, aDrawText.Font.Height = -11, FScaleY =
0.14962121212
So, on line
FCanvas.Font.Height := Round(aDrawText.Font.Height * FScaleY);
FCanvas.Font.Height := Round(-11 * 0.14962....) //(Round(-1.64) = -2
Setting this sets the FCanvas.Font.Size to 2.
The call to
GetTextMetrics(FCanvas.Handle, lTextMetric);
Returns a value of lTextMetric.tmHeight of 2.
so
liLineHeight := lTextMetric.tmHeight + liLeading; //( liLineHeight =
0)
then on line
if ((Abs(liCalcHeight - liLineHeight) / liLineHeight) <= 0.10) then
{!!!!!!!!!!!!Div by 0 here!!!!!!!!!!!!}
If I use a Leading of -3 or -1 I don't have any problem. But -3 is a little
too much, and -1 is not enough...
Why is this happening?
Is it considered a bug?
if not, why, and what "rules" should I follow to avoid receiving this
error?
if yes, when could we expect it to be fixed?
Info:
Delphi 2006
ReportBuilder 10.03 Standard
OS : Windows 2k
Printer : InfoPrint 1130 with driver version 7.4
This discussion has been closed.
Comments
Thanks for reporting this issue, it will be fixed for the next maintenance
(RB 10.04) which will be available soon.
--
Nard Moseley
Digital Metaphors
www.digital-metaphors.com
Best regards,
Nard Moseley
Digital Metaphors
www.digital-metaphors.com