Recent

Author Topic: TGridPrinter and Bold Fonts being truncated  (Read 1402 times)

sfeinst

  • Full Member
  • ***
  • Posts: 235
TGridPrinter and Bold Fonts being truncated
« on: January 29, 2024, 07:53:45 pm »
I am using v0.5 of TGridPrinter on Lazarus 3.99 on Debian Bookworm.  I am printing to cups-pdf.  When I view my stringgrid on-screen, looks fine.  When viewed in print preview, it looks fine.  But when printed, cells with a font that is bold truncates the data if the cell is too close.

I fixed the problem for now by making by cell widths even larger.

What I wanted to know is if this is most likely due to how visual font widths are determined vs printer font widths (ie, the cups-pdf printer's font rendering makes the items larger than the preview and actual stringgrids - while another printer might not have this problem)?

I'm guessing, because of differences in printers, it might not be possible to fix programmitcally and was more curious if that is the likely reason.  Or, there might be something I can set that would match the printer font size better to the original stringgrid?

wp

  • Hero Member
  • *****
  • Posts: 12696
Re: TGridPrinter and Bold Fonts being truncated
« Reply #1 on: January 29, 2024, 11:38:11 pm »
I am using v0.5 of TGridPrinter on Lazarus 3.99 on Debian Bookworm.  I am printing to cups-pdf.  When I view my stringgrid on-screen, looks fine.  When viewed in print preview, it looks fine.  But when printed, cells with a font that is bold truncates the data if the cell is too close.
How did you make the cells bold?

sfeinst

  • Full Member
  • ***
  • Posts: 235
Re: TGridPrinter and Bold Fonts being truncated
« Reply #2 on: January 30, 2024, 01:06:51 am »
OnprepareCanvas event.  I assign the same on prepare event to the grid and the gridprinter and that part works since the colors and boldface are displaying in the print out.

Code: Pascal  [Select][+][-]
  1. procedure TfrmReport.gridSummaryPrepareCanvas(Sender: TObject; aCol, aRow: Integer;
  2.   aState: TGridDrawState);
  3. var
  4.   DispCanvas: TCanvas;
  5. begin
  6.   if not Assigned(self.FGrid) then
  7.     exit;
  8.  
  9.   if Sender is TStringGrid then
  10.     DispCanvas := TStringGrid(Sender).Canvas
  11.   else if Sender is TGridPrinter then
  12.     DispCanvas := TGridPrinter(Sender).Canvas
  13.   else
  14.     exit;
  15.  
  16.   if (aRow > 0) and (Pos('Total for', self.FGrid.Cells[0, aRow]) > 0) then
  17.     DispCanvas.Font.Style := [fsBold]
  18.   else if (aRow > 0) and (Pos('Total Value', self.FGrid.Cells[0, aRow]) > 0) then
  19.   begin
  20.     DispCanvas.Font.Style := [fsBold];
  21.     DispCanvas.Font.Color := clGreen;
  22.   end
  23.   else if (aRow > 0) and (Pos('Total', self.FGrid.Cells[0, aRow]) > 0) then
  24.   begin
  25.     DispCanvas.Font.Style := [fsBold];
  26.     DispCanvas.Font.Color := clBlue;
  27.   end;
  28. end;    
  29.  

wp

  • Hero Member
  • *****
  • Posts: 12696
Re: TGridPrinter and Bold Fonts being truncated
« Reply #3 on: January 30, 2024, 09:41:55 am »
OnprepareCanvas event.
Yes, this is the way it is intended.

What I wanted to know is if this is most likely due to how visual font widths are determined vs printer font widths (ie, the cups-pdf printer's font rendering makes the items larger than the preview and actual stringgrids - while another printer might not have this problem)?
Could be... Or maybe the pdf printer is using a different font?

How much is the difference when bold text is truncated? GridPrinter calculates the magnfication factor from the ratio of printer-to-screen pixels per inch. It could be that the same text at the high printer resolution does not have the same width as the text at screen resolution multiplied by this factor - I don't know...

I fixed the problem for now by making by cell widths even larger.
That's the way how I would do it, too.

sfeinst

  • Full Member
  • ***
  • Posts: 235
Re: TGridPrinter and Bold Fonts being truncated
« Reply #4 on: January 30, 2024, 01:49:53 pm »
Thanks for the replies.  It's what I was guessing, but just wanted confirmation.  To answer your question.  A number like 545,123.99 will display about 1/4 of the 5 maybe less and the rest displays.

Larger cell width from the start is the way I'll go.

BTW, doing this under Windows (using its PDF printer) doesn't have the problem (so far).  I also noticed under Windows, I get my entire grid on 1 page but on Linux using cups-pdf I have to reduce the scale factor from 1 to .9 to get it to fit on one page.

I know under gnome/gtk my app looks larger as a whole.  So font differences and rendering of those fonts is the most likely cause.

 

TinyPortal © 2005-2018