PeterPanino / thtmlviewer

Automatically exported from code.google.com/p/thtmlviewer
Other
0 stars 0 forks source link

Erroneous calculation of "MaxVertical" / Printing variable height page headers and footers #155

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Faced with this situation. Load the file "Ace.htm" the example "HeaderFooter". 
Window width is clearly smaller than the width of a sheet of paper of A4. 
Counting the value of "MaxVertical" text in the window is about 14 cm, which 
corresponds to a visual reality. When you click on "Print Preview" calculate 
the value of "MaxVertical" HFViewer events OnPrintHTMLHeader. This value is 
approximately 44 cm. But in fact, this size is much smaller.
It turns out that one can not correctly calculate the height of the header, 
depending on the loaded data.

This can somehow fix this???

Original issue reported on code.google.com by SchwarzK...@yandex.ru on 14 May 2012 at 5:34

Attachments:

GoogleCodeExporter commented 9 years ago
In your example code MaxVertical is calculated for the HtmlViewer's default 
size of 150px width. Of course this is smaller than paper size A4 and is 
smaller than the default width of the application, resulting in a heigher 
header.

Currently the page header is placed bottom aligned above the PrintMarginTop 
into the printable area and the page footer is placed top aligned below the 
PrintMarginBottom into the remaining printable area.

If I understand you right, you'd like to place the page header top aligned 
below the PrintMarginTop and start the document area at the bottom of the page 
header. Same with page footer accordingly.

Sounds acceptable as long as page header and page footer are smaller than 1 
page. 
Variable height headers and footers should be optional to preserve existing 
layouts.

Original comment by OrphanCat on 14 May 2012 at 8:53

GoogleCodeExporter commented 9 years ago
Yes, that's about it.

Advanced.
Could you make when using PrintScale <> 1 of the main document would be able to 
optionally specify the coefficient PrintScale for the Header/Footer???
Something like the picture.

Original comment by SchwarzK...@yandex.ru on 14 May 2012 at 9:17

Attachments:

GoogleCodeExporter commented 9 years ago
Yeah, that's reasonable.

Original comment by OrphanCat on 14 May 2012 at 9:20

GoogleCodeExporter commented 9 years ago
Thanks, it was-would be good for some purposes. :)

Original comment by SchwarzK...@yandex.ru on 14 May 2012 at 9:30

GoogleCodeExporter commented 9 years ago
I corrected the situation with the wrong calculation MaxVertical.
If desired, it can be made to the source.

htmlview.pas

...
    function CreateHeaderFooter: THtmlViewer;
{!!!}    procedure UpdateWidthHeaderFooter(HFHtmlViewer: THtmlViewer; Width: 
Integer);
    function GetBase: ThtString;
...

...
{!!!}procedure THtmlViewer.UpdateWidthHeaderFooter(HFHtmlViewer: THtmlViewer; 
Width: Integer);
begin
  if HFHtmlViewer <> nil then
   HFHtmlViewer.Width := Width;
end;

{$ifndef NoMetafile}

procedure THtmlViewer.Print(FromPage, ToPage: Integer; Prn: TvwPrinter);
...

...
{.$Region 'HeaderFooter'}
            SelectClipRgn(DC, 0);
            if (FPage <= ToPage) then {print header and footer}
            begin
              Prn.Canvas.Pen.Assign(savedPen);
              Align := SetTextAlign(DC, TA_Top or TA_Left or TA_NOUPDATECP);
              SelectClipRgn(DC, hrgnClip2);

{!!!}              UpdateWidthHeaderFooter(HeadViewer, ScaledPgWid);
              UpdateWidthHeaderFooter(FootViewer, ScaledPgWid);

              if Assigned(OnPrintHeader) then
              begin
                SetWindowOrgEx(DC, XOrigin, 0, nil);
                OnPrintHeader(Self, Prn.Canvas, FPage, ScaledPgWid, TopPixels, Done);
              end;
...

Original comment by SchwarzK...@yandex.ru on 29 Jan 2013 at 2:48

GoogleCodeExporter commented 9 years ago
I'm very sorry, but I cannot see, what was going wrong before the fix and what 
is going to become well after the fix. Which print/preview calculation takes 
into account the HeadViewer.Width resp. FootViewer.Width?

Actually DoHTMLHeaderFooter() uses W, the scaled pageWidth without margins (== 
width of used paper area) to prepare the layout (HFCopyList.DoLogic()). 

The out-commented code in TForm1.ViewerPrintHTMLHeader() in your example unit 
HFUnit.pas tries to save space for a larger header using Viewer.MaxVertical, 
but it is not a figure for the calculated length of the printed/previewed page. 

Furthermore HtmlViewer renders the header after the main page and thus you 
cannot know and use the actual header height of this page to determine the 
height of the main page. 

Since r352 (committed today) after calling THtmlViewer.Print() (or 
PrintPreview() or NumPrinterPages()) property PrintedSize:TPoint gives you the 
size of the entire document in pixels. So HeadViewer.PrintedSize.Y is the 
header height in pixels. But still it is not available before the main page is 
rendered.

Original comment by OrphanCat on 29 Jan 2013 at 8:18