Forum > Ported from Delphi/Kylix

Partially Ported: Crossword/WordSearch Maker Delphi for Fun

(1/1)

Boleeman:
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  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---function TPrintPreview.PageSize : TPoint;{Physical size of page including the non-printable border area}begin//Escape(Printer.Handle, GETPHYSPAGESIZE, 0, nil, @Result);Escape(Printer.XDPI, GETPHYSPAGESIZE, 0, nil, @Result);       procedure TPrintPreview.DisplayPage(Page : Integer);var  p : TPoint;  Sc : Single;  r : TRect;  i : integer;begin  if (Page > 0) AND (Page <= PageCount) then  begin    Sc := PaintBox1.Width / PageSize.X;     PaintBox1.Canvas.Rectangle(0,0,PaintBox1.Width, PaintBox1.Height);    PaintBox1.Canvas.FillRect(Rect(1,1,PaintBox1.Width-2,PaintBox1.Height-2));//    Escape(Printer.Handle, GETPRINTINGOFFSET, 0, nil, @p);    Escape(Printer.XDPI, GETPRINTINGOFFSET, 0, nil, @p);    r.Left := Trunc(p.X * Sc);    r.Top := Trunc(p.Y * Sc);    r.Right := r.Left + Trunc(Printer.PageWidth * Sc);    r.Bottom := r.Top + Trunc(Printer.PageHeight * Sc);    if ShowgridBtn.Caption[1] = 'H' then    begin      with PaintBox1.Canvas do      begin        Pen.Style := psDash;        Rectangle(r.Left, r.Top, r.Right, r.Bottom);        for i := 1 to Self.PageSize.X div Self.pXppi do        begin          MoveTo(Trunc(i * Self.pXppi * Sc), 0);          LineTo(Trunc(i * Self.pXppi * Sc), Trunc(PageSize.Y * Sc));        end;        for i := 1 to Self.PageSize.Y div Self.pYppi do        begin          MoveTo(0, Trunc(i * Self.pYppi * Sc));          LineTo(Trunc(PageSize.X * Sc), Trunc(i * Self.pYppi * Sc));        end;        Pen.Style := psSolid;      end;    end;     PaintBox1.Canvas.StretchDraw(r, Metafiles[Page]);    Panel2.Caption := Format('Page %d of %d', [Page, PageCount]);    PageDisplaying := Page;    if Page = 1 then    begin      FirstBtn.Enabled := False;      PriorBtn.Enabled := False;    end else    begin      FirstBtn.Enabled := True;      PriorBtn.Enabled := True;    end;    if PageCount > Page then    begin      NextBtn.Enabled := True;      LastBtn.Enabled := True;    end else    begin      NextBtn.Enabled := False;      LastBtn.Enabled := False;    end;  end;end;   procedure TPrintPreview.NewJob;var i : Integer; p : TPoint; XOff : Integer; YOff : Integer;begin  for i := FMetafiles.Count - 1 downto 0 do  begin    TMetafile(FMetafiles[i]).Free;  end;  FCanvases.Clear;  FMetafiles.Clear;  FCurrentPage := 0;  FDonePrinting := False; // Escape(Printer.Handle, GETPRINTINGOFFSET, 0, nil, @p);  Escape(Printer.XDPI, GETPRINTINGOFFSET, 0, nil, @p);   XOff := p.X;  YOff := p.Y; // pXppi := GetDeviceCaps(Printer.Handle, LOGPIXELSX); // pYppi := GetDeviceCaps(Printer.Handle, LOGPIXELSY);  pXppi := GetDeviceCaps(Printer.XDPI, LOGPIXELSX);  pYppi := GetDeviceCaps(Printer.YDPI, LOGPIXELSY);   if printer.printing then printer.abort;  Printer.BeginDoc;  NewPage;end;    

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.

Navigation

[0] Message Index

Go to full version