Board index » delphi » Printer.Canvas.TextHeight - unexpected results

Printer.Canvas.TextHeight - unexpected results

This test code illustrates my problem:

procedure TForm1.Button1Click(Sender: TObject);
begin
  with TFontDialog.Create(Self) do try
    if Execute then begin
      Printer.Canvas.Font.Assign(Font);
      Label1.Caption := Format(
          'An A is %d pixels high',[Printer.Canvas.TextHeight('A')]);
      end;
  finally
    free
    end
end;

I have compiled with D1 and D3.

The D3 version gives me an answer of 88 on NT and 95.
The D1 version gives me an answer of 83 on NT, 95 and 3.1
(These figures obtained selecting Courier New, regular, 10).

All three systems have the same printer installed.
I select the same font on each.
So why the different answers ?
(The problem is the same with true type and printer fonts.)

My code needs to run on various platforms, and print exactly the same
from each.  It doesn't, but I don't know what to do next.

Any advice is welcome.

 

Re:Printer.Canvas.TextHeight - unexpected results


The problem is the Win3.1 API..
Font size data was reuturned differently and thus treated differently then
the
WIn32.
 if its a 16 bit program then the 16 bit API is used and maintains the same
information reporting as it did in Windows3.1.
 a 32 bit program uses the WIn32 for its API calls, since the the berth of
the
Win32 API the font data return has been corrected..
 values returned by the 16 bit API were not always correct!..
 plus you had to SubTract the return value from $FFFF to get the correct
size
since the values were returned in -values, now they are returned as Pos..

Duncan McNiven <duncan.mcni...@lecs.inet.fi> wrote in article
<35b0c540.81482...@news.inet.fi>...

Quote
> This test code illustrates my problem:

> procedure TForm1.Button1Click(Sender: TObject);
> begin
>   with TFontDialog.Create(Self) do try
>     if Execute then begin
>       Printer.Canvas.Font.Assign(Font);
>       Label1.Caption := Format(
>           'An A is %d pixels high',[Printer.Canvas.TextHeight('A')]);
>       end;
>   finally
>     free
>     end
> end;

> I have compiled with D1 and D3.

> The D3 version gives me an answer of 88 on NT and 95.
> The D1 version gives me an answer of 83 on NT, 95 and 3.1
> (These figures obtained selecting Courier New, regular, 10).

> All three systems have the same printer installed.
> I select the same font on each.
> So why the different answers ?
> (The problem is the same with true type and printer fonts.)

> My code needs to run on various platforms, and print exactly the same
> from each.  It doesn't, but I don't know what to do next.

> Any advice is welcome.

Other Threads