DELPHI AREA
MESSAGE BOARD
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   Favorites   Watched Topics     RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

PrintPreview vs. TMemo (and bug in TPrintPreview)
Goto page 1, 2  Next
 
   Reply to topic       DELPHI AREA Forum Index -> DELPHI AREA's Products
View previous topic :: View next topic  
Author Message
Johnny_Bit
Moderator


Joined: 15 Jun 2003
Posts: 170

PostPosted: 15/06/03 20:33    Post subject: PrintPreview vs. TMemo (and bug in TPrintPreview) Reply with quote

Hi @ll

I've tried to make print prevew of memo by richedit, but nothing shows on preview.

My question: How make PrintPreview of TMemo including margins, footer and header of page?


Last edited by Johnny_Bit on 18/06/03 17:49; edited 1 time in total
Back to top
View user's profile
richardchaven
Member


Joined: 30 May 2003
Posts: 20

PostPosted: 17/06/03 07:02    Post subject: Printing a TMemo Reply with quote

Code:
NewPage;

Canvas.DrawRect(..., WordWrap);


I'm really tired, but does this help at all?
Back to top
View user's profile Send e-mail Yahoo Messenger
Johnny_Bit
Moderator


Joined: 15 Jun 2003
Posts: 170

PostPosted: 17/06/03 14:55    Post subject: Reply with quote

well, I don't know I've got this code for printing on printer canvas, but i want to change it so it be compatible with PrintPreview:
Code:

procedure TMainForm.PrintFooter(var R: TRect; LineHeight: Integer);
var
  S : String;
begin
  with Printer do begin

    { utwórz łańcuch zawierający numer strony }
    S := Format('Page %d', [PageNumber]);


    { ustal współrzędne prostokąta, którym wyświetlany będzie łańcuch }
    { zawierający numer strony }

    R.Top := PageHeight - (lineHeight * 2);
    R.Bottom := R.Top + lineHeight;


    { wyświetl centrycznie łańcuch zawierający numer strony }
    DrawText(Handle, PChar(S), -1, R, DT_CENTER);

    { podkreśl tekst zawierający numer strony }
    Canvas.MoveTo(0, R.Top - 2);
    Canvas.LineTo(R.Right, R.Top - 2);
  end;
end;

procedure TMainForm.FilePrintClick(Sender: TObject);
var
  I            : Integer;
  LineHeight   : Integer;
  LinesPerPage : Integer;
  LineCount    : Integer;
  R            : TRect;
  S            : string;
begin
  { wyświetl dialog drukowania }
  if PrintDialog.Execute then begin

    { ustal tytuł drukowanego obiektu }
    Printer.Title := 'Scratch - ' + OpenDialog.FileName;

    { ustaw czcionkę drukarkową zgodnie z czcionką Memo }
    Printer.Canvas.Font := Memo.Font;



    { Oblicz wysokość linii - na podstawie rozmiaru czcionki }
    { i rozdzielczości drukarki. Dodaj 40% na odstęp między liniami }

    LineHeight := Abs(
      MulDiv(Printer.Canvas.Font.Size,
      GetDeviceCaps(Printer.Handle, LOGPIXELSY), 72));
    Inc(LineHeight, (LineHeight * 4) div 10);

    { oblicz, ile linii zmieści się na stronie; uwzględnij }
    { trójliniowy margines                                 }

    LinesPerPage := (Printer.PageHeight div lineHeight) - 4;

    { rozpocznij drukowanie w 4. linii, by zostawić miejsce }
    { na nagłówek }
    LineCount := 4;

    { wydrukuj nagłówek }
    Printer.BeginDoc;
    R.Top    := LineHeight;
    R.Left   := 20;
    R.Right  := Printer.PageWidth;
    R.Bottom := LineHeight * 2;
    DrawText(Printer.Handle,
      PChar(OpenDialog.FileName), -1, R, DT_CENTER);

    { drukowanie poszczególnych linii }
    for I := 0 to Pred(Memo.Lines.Count) do
    begin

      { po dojściu do końca strony zresetuj licznik linii }
      { i przejdź do nowej strony                         }

      Inc(LineCount);
      if LineCount = LinesPerPage then begin
        PrintFooter(R, LineHeight);
        LineCount := 4;
        Printer.NewPage;
      end;

      { pobierz kolejną linię Memo }
      S := Memo.Lines.Strings[I];
      Printer.Canvas.TextOut(0, LineCount * LineHeight, S);
    end;

    { zakończ drukowanie }
    PrintFooter(R, LineHeight);
    Printer.EndDoc;
  end;
end;


(comments are in Polish, don't care 'bout them)
Back to top
View user's profile
richardchaven
Member


Joined: 30 May 2003
Posts: 20

PostPosted: 17/06/03 15:37    Post subject: Reply with quote

Looking at the Preview.pas source code, I think if you do not use PrintPreview.Canvas, it will not show up.

Replace 'Printer.' with 'PrintPreview.' and 'Printer.BeginDoc' with 'PrintPreview.NewPage' and see what happens.

Cheers
Back to top
View user's profile Send e-mail Yahoo Messenger
Johnny_Bit
Moderator


Joined: 15 Jun 2003
Posts: 170

PostPosted: 17/06/03 16:01    Post subject: Reply with quote

I did so, but page widith and height are incorrect. also DPI.
Back to top
View user's profile
richardchaven
Member


Joined: 30 May 2003
Posts: 20

PostPosted: 18/06/03 06:31    Post subject: Reply with quote

PageHeight and PageWidth are in the .Units measure, not necessarily Pixels. You can use ConvertUnit or change the .Units property to mmPixels

Cheers
Back to top
View user's profile Send e-mail Yahoo Messenger
Johnny_Bit
Moderator


Joined: 15 Jun 2003
Posts: 170

PostPosted: 18/06/03 17:46    Post subject: Reply with quote

Thanks, but I found solution just few minutes after disconect (by RichEdit way), but I've found bug in TPrintPreview: when I tried to change zoom to 100% then ecteption EOutOfResources raised, when I chenged Zoom to 50% it looked like zoom 500% or more! whats wrong 'bout it? [it hepend not only in my program, aslo in RichEdit print demo but it doesn't hapend in General demo.

And one more thing: why pages can't be scroled like in M$ word or Adobe Acrobat Reader(next page under previous)?
Back to top
View user's profile
richardchaven
Member


Joined: 30 May 2003
Posts: 20

PostPosted: 18/06/03 18:17    Post subject: Reply with quote

Look in their demo for paging: you have to set the CurrentPage property
Back to top
View user's profile Send e-mail Yahoo Messenger
Johnny_Bit
Moderator


Joined: 15 Jun 2003
Posts: 170

PostPosted: 19/06/03 09:33    Post subject: Reply with quote

OK, but what 'bout bug in zoom?

ps. CurrentPage sucks!
Back to top
View user's profile
richardchaven
Member


Joined: 30 May 2003
Posts: 20

PostPosted: 19/06/03 15:39    Post subject: Reply with quote

I don't know why you would get OutOfResources; I think you need to email the vendor so they take a look at it.

Why does .CurrentPage suck? If they have one canvas, how elese are they supposed to keep track?
Back to top
View user's profile Send e-mail Yahoo Messenger
Johnny_Bit
Moderator


Joined: 15 Jun 2003
Posts: 170

PostPosted: 19/06/03 18:46    Post subject: Reply with quote

I don't know what you mean by sending mail to vendor (exacly this part. mail to vendor of what?), besides try out the RichText print demo and change zoom to 100%

It might be caused by MulDiv (in UpdateZoom procedure)...

It's strange but when i changed zoom to 8 it looks like 100% in Word or Acrobat. and i can bet that it's bug in Update zoom
Back to top
View user's profile
Johnny_Bit
Moderator


Joined: 15 Jun 2003
Posts: 170

PostPosted: 21/06/03 14:16    Post subject: Reply with quote

I found finally reason of bug! It was in CalculateViewSize function, in zsZoomOther section, whole function should be:
Code:

function TPrintPreview.CalculateViewSize(const Space: TPoint): TPoint;
begin
  with FPaperView do
    case FZoomState of
      zsZoomOther:
      begin
        Result.X := ActualWidth(MulDiv(FPixels.X, FZoom*Screen.PixelsPerInch,GetDeviceCaps(Printer.Handle, LOGPIXELSX) * 100));{ActualWidth(MulDiv(FPixels.X, FZoom, 100));}
        Result.Y := ActualWidth(MulDiv(FPixels.Y, FZoom*Screen.PixelsPerInch,GetDeviceCaps(Printer.Handle, LOGPIXELSY) * 100));{ActualHeight(MulDiv(FPixels.Y, FZoom, 100));}
      end;
      zsZoomToWidth:
      begin
        Result.X := Space.X;
        Result.Y := ActualHeight(MulDiv(ActualWidth(Result.X), FPixels.Y, FPixels.X));
      end;
      zsZoomToHeight:
      begin
        Result.Y := Space.Y;
        Result.X := ActualWidth(MulDiv(ActualHeight(Result.Y), FPixels.X, FPixels.Y));
      end;
      zsZoomToFit:
      begin
        if (FPixels.Y / FPixels.X) < (Space.Y / Space.X) then
        begin
          Result.X := Space.X;
          Result.Y := ActualHeight(MulDiv(ActualWidth(Result.X), FPixels.Y, FPixels.X));
        end
        else
        begin
          Result.Y := Space.Y;
          Result.X := ActualWidth(MulDiv(ActualHeight(Result.Y), FPixels.X, FPixels.Y));
        end;
      end;
    end;
end;
Back to top
View user's profile
richardchaven
Member


Joined: 30 May 2003
Posts: 20

PostPosted: 24/06/03 17:59    Post subject: Reply with quote

Please summarize the changes you made.
Back to top
View user's profile Send e-mail Yahoo Messenger
Johnny_Bit
Moderator


Joined: 15 Jun 2003
Posts: 170

PostPosted: 24/06/03 19:02    Post subject: Reply with quote

orginal code is in comment. changes ware maded only for
Code:

Result.X := ActualWidth(MulDiv(FPixels.X, FZoom*Screen.PixelsPerInch,GetDeviceCaps(Printer.Handle, LOGPIXELSX) * 100));{ActualWidth(MulDiv(FPixels.X, FZoom, 100));<-orginal}
        Result.Y := ActualWidth(MulDiv(FPixels.Y, FZoom*Screen.PixelsPerInch,GetDeviceCaps(Printer.Handle, LOGPIXELSY) * 100));{ActualHeight(MulDiv(FPixels.Y, FZoom, 100));<-orginal}


it was in lines 1767 and 1768 of unit preview.pas in function CalculateViewSize (protected function of TPrintPreview). Is it enought?
Back to top
View user's profile
richardchaven
Member


Joined: 30 May 2003
Posts: 20

PostPosted: 25/06/03 00:15    Post subject: Reply with quote

Thank you
Back to top
View user's profile Send e-mail Yahoo Messenger
Display posts from previous:   
   Reply to topic       DELPHI AREA Forum Index -> DELPHI AREA's Products All times are GMT
Goto page 1, 2  Next
Page 1 of 2

Add to favorites

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group