Recent

Author Topic: Partially Ported: Crossword/WordSearch Maker Delphi for Fun  (Read 1182 times)

Boleeman

  • Hero Member
  • *****
  • Posts: 721
I partially ported the Crossword/WordSearch Maker from Delphi for Fun.


It compiles, but the print to pdf and print preview does not work correctly. The word placements work correctly.
I also made the TSpinedits accept larger sizes (up to 30 rows and columns).

I wonder if someone knowledgeable can help to fix the print/print preview part ?


The small.txt file needs to be in the root directory where the exe is compiled, as it needs to load it on startup.

W.P. helped me with previous Delphi printer conversions (which I went back to look at but this conversion is a bit different)

I used mymetafilepkg.lpk for the metafile component part. I installed that component (from the attached TMetafile.zip ).

In unit UPrintPreview; i made these changes as printer.handle was not recognized (the original part has // and under that are the changes:

Code: Pascal  [Select][+][-]
  1. function TPrintPreview.PageSize : TPoint;
  2. {Physical size of page including the non-printable border area}
  3. begin
  4. //Escape(Printer.Handle, GETPHYSPAGESIZE, 0, nil, @Result);
  5. Escape(Printer.XDPI, GETPHYSPAGESIZE, 0, nil, @Result);      
  6.  
  7. procedure TPrintPreview.DisplayPage(Page : Integer);
  8. var
  9.   p : TPoint;
  10.   Sc : Single;
  11.   r : TRect;
  12.   i : integer;
  13. begin
  14.   if (Page > 0) AND (Page <= PageCount) then
  15.   begin
  16.     Sc := PaintBox1.Width / PageSize.X;
  17.  
  18.     PaintBox1.Canvas.Rectangle(0,0,PaintBox1.Width, PaintBox1.Height);
  19.     PaintBox1.Canvas.FillRect(Rect(1,1,PaintBox1.Width-2,PaintBox1.Height-2));
  20. //    Escape(Printer.Handle, GETPRINTINGOFFSET, 0, nil, @p);
  21.     Escape(Printer.XDPI, GETPRINTINGOFFSET, 0, nil, @p);
  22.     r.Left := Trunc(p.X * Sc);
  23.     r.Top := Trunc(p.Y * Sc);
  24.     r.Right := r.Left + Trunc(Printer.PageWidth * Sc);
  25.     r.Bottom := r.Top + Trunc(Printer.PageHeight * Sc);
  26.     if ShowgridBtn.Caption[1] = 'H' then
  27.     begin
  28.       with PaintBox1.Canvas do
  29.       begin
  30.         Pen.Style := psDash;
  31.         Rectangle(r.Left, r.Top, r.Right, r.Bottom);
  32.         for i := 1 to Self.PageSize.X div Self.pXppi do
  33.         begin
  34.           MoveTo(Trunc(i * Self.pXppi * Sc), 0);
  35.           LineTo(Trunc(i * Self.pXppi * Sc), Trunc(PageSize.Y * Sc));
  36.         end;
  37.         for i := 1 to Self.PageSize.Y div Self.pYppi do
  38.         begin
  39.           MoveTo(0, Trunc(i * Self.pYppi * Sc));
  40.           LineTo(Trunc(PageSize.X * Sc), Trunc(i * Self.pYppi * Sc));
  41.         end;
  42.         Pen.Style := psSolid;
  43.       end;
  44.     end;
  45.  
  46.     PaintBox1.Canvas.StretchDraw(r, Metafiles[Page]);
  47.     Panel2.Caption := Format('Page %d of %d', [Page, PageCount]);
  48.     PageDisplaying := Page;
  49.     if Page = 1 then
  50.     begin
  51.       FirstBtn.Enabled := False;
  52.       PriorBtn.Enabled := False;
  53.     end else
  54.     begin
  55.       FirstBtn.Enabled := True;
  56.       PriorBtn.Enabled := True;
  57.     end;
  58.     if PageCount > Page then
  59.     begin
  60.       NextBtn.Enabled := True;
  61.       LastBtn.Enabled := True;
  62.     end else
  63.     begin
  64.       NextBtn.Enabled := False;
  65.       LastBtn.Enabled := False;
  66.     end;
  67.   end;
  68. end;  
  69.  
  70. procedure TPrintPreview.NewJob;
  71. var
  72.  i : Integer;
  73.  p : TPoint;
  74.  XOff : Integer;
  75.  YOff : Integer;
  76. begin
  77.   for i := FMetafiles.Count - 1 downto 0 do
  78.   begin
  79.     TMetafile(FMetafiles[i]).Free;
  80.   end;
  81.   FCanvases.Clear;
  82.   FMetafiles.Clear;
  83.   FCurrentPage := 0;
  84.   FDonePrinting := False;
  85.  // Escape(Printer.Handle, GETPRINTINGOFFSET, 0, nil, @p);
  86.   Escape(Printer.XDPI, GETPRINTINGOFFSET, 0, nil, @p);
  87.  
  88.   XOff := p.X;
  89.   YOff := p.Y;
  90.  // pXppi := GetDeviceCaps(Printer.Handle, LOGPIXELSX);
  91.  // pYppi := GetDeviceCaps(Printer.Handle, LOGPIXELSY);
  92.   pXppi := GetDeviceCaps(Printer.XDPI, LOGPIXELSX);
  93.   pYppi := GetDeviceCaps(Printer.YDPI, LOGPIXELSY);
  94.  
  95.   if printer.printing then printer.abort;
  96.   Printer.BeginDoc;
  97.   NewPage;
  98. end;  
  99.  


Hope that someone can help out.

I also attached the original Delphi for Fun source code, just in case you need it.

Thanks in advance.
« Last Edit: July 16, 2024, 02:14:32 pm by Boleeman »

 

TinyPortal © 2005-2018