Quick Report

QuickReports FONT Problems

From: max@newlook.co.nz (Max Nilson)

artemik@ix.netcom.com (Bill Artemik) wrote:

I'm using Delphi 2.0 and QuickReports 1.1

>I created a VERY complex (graphically, anyway) report and just found
>out that ALTHOUGH it previews fine in design mode, does NOT display or
>print correctly in runtime. The error appears to be that I'm running
>with LARGE fonts in Windows 95! What a crock!
I too was getting this problem _very_ seriously, but only when printing from Win 95 to the office HP 4M, or when viewing the report under NT 4.0. The _exact_ same application when run under NT 3.51 SP5 worked perfectly.

I had seen discussion of one other bug in the NT 4.0 GDI code, so I wasn't suprised when the above test showed that there seemed to be another. I looked very closely at the QuickReports code and noticed that the primary text output routine alters its ouput font for every field. Its does this via the following code segment in TQRCustomControl.Print:


  QRPrinter.Canvas.Font:=Font;
  QRPrinter.Canvas.Font.size:=trunc(abs(parentreport.xpos(font.size)));
  QRPrinter.Canvas.brush.Color:=Color;

Now those of us who have spent far too much time reading the VCL will know that the VCL maintains a resource cache via a handle manager in Graphics.pas, and that this attempts to lower the number of Windows resources allocated by using a reference counted approach to reusing old resource handles. The code above manages to circumvent this most excellently! Every time the printers canvas is set to the fields font, thus lowering the printer's old font resource count to zero and releasing it, and then scaling the fonts size to match the printer metrics, thus requiring a new font resource to be allocated.

The upshot of all this is that _every_ field of the report was being drawn using a newly alocated font resource, and probably driving the meta file recorder into spasms trying to keep track of all this choping and changing of font resources.

A quick hack where by I created a non printing label of the same size as the scaled printer font, thereby keeping the resource cached, made the bug go away! This proved that there is some sort of problem with the NT 4.0 ehnanced meta file recorder and too many font changes.

A better hack has been introduced into QuickReports as follows:


  // MRN Save the printer font while setting new font
  SaveFont := TFont.Create;
  SaveFont.Assign(QRPrinter.Canvas.Font);

  QRPrinter.Canvas.Font:=Font;
  QRPrinter.Canvas.Font.size:=trunc(abs(parentreport.xpos(font.size)));
  QRPrinter.Canvas.brush.Color:=Color;

  // MRN Free the saved printer font. Its done its work now.
  SaveFont.Free;
  SaveFont := nil;

This manages to ensure that the printer font is reused if the same font is selected into the printer canvas. This works perfectly and produces correct reports on NT 4.0. By some strange coincidence 8-) this also stopped the wierd bold, out sized fonts being printed under Win95.

So if you have a registered version of QuickReports thaen you simply make this patch and things will run faster, smother and no more font corruptions will occur due to the limitations of the enhanced meta file code and the GDI.

Preview Form Caption

Bruno Sonnino [sonnino@netmogi.com.br]

You can set QRPrinter PreviewCaption to your caption like this:


  
QRPrinter.PreviewCaption := 'My Caption';

QRPrinter is a global variable defined in Quickrep.pas

QuickReports on different paper sizes

From: cannibal@bigfoot.com

Hi! Have you looked at the TPrinter-object?
You can set the printer you want to use with the Printer.PrinterIndex.
For example:

               Printer.PrinterIndex:=0; Sets the first printer you have installed

               Printer.PrinterIndex:=-1; Sets the printer to the default printer


Observe! That this function don't make an global change to your system, it's just for the time being.


Please email me and tell me if you liked this page.

This page has been created with