kooloveme / thtmlviewer

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

Code change request to vwPrint and HtmlView #240

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Hi All,

I've been using HTMLView for a while in my projects and wanted to ask if would 
be possible to get a small code change to the project please?

I would like to modify ThtPrinter to make the following private variables 
protected

    FOffsetX: Integer;      // Physical Printable Area x margin
    FOffsetY: Integer;      // Physical Printable Area y margin
    FPaperHeight: Integer;  // Physical Height in device units
    FPaperWidth: Integer;   // Physical Width in device units
    FPgHeight: Integer;     // Vertical height in pixels
    FPgWidth: Integer;      // Horizontal width in pixels
    FPPIX: Integer;         // Logical pixels per inch in X
    FPPIY: Integer;         // Logical pixels per inch in Y
    FPrinting: Boolean;
    FTitle: ThtString;      // Printed Document's Title

Then could I have a small modification to the THTMLViewer. At the start of 
function Print(Prn: ThtPrinter; FromPage: Integer; ToPage: Integer; Mode: 
ThtPrintPreviewMode): Integer you check to see if the Prn object supplied is 
TMetaFilePrinter. My proposed code change is as follows:

  case Mode of
    ppAuto:
      if not (Prn is ThtPrinter) then
        Mode := ppMultiPrint
      else
        Mode := ppPreview;

    ppPreview:
      if not (Prn is ThtPrinter) then
        raise EIllegalArgument.CreateFmt('Previewing a print requires a printer based on TMetaFilePrinter but not a %s', [Prn.ClassName]);

    ppNoOutput:
      if not (Prn is ThtPrinter) then
        raise EIllegalArgument.CreateFmt('Getting the total number of pages to print requires a printer based on TMetaFilePrinter but not a %s', [Prn.ClassName]);
  end;

If you check to see if the Prn object is derived from ThtPrinter instead it 
would allow alternative printing objects to be used.

I ask because I have had trouble getting HTMLHeaders and Footers working with 
Synopse PDF Engine. The samples they use rely on MakePagedMetaFiles function. 
This function doesn't process HTML headers and footers. By making these changes 
I can create a custom PDF printer object derived from ThtPrinter which HTMLView 
can then render to.

For the printing code please see my posting to the Synopse Form 
http://synopse.info/forum/viewtopic.php?id=1230

Take care,
Ryan

Original issue reported on code.google.com by rcdr...@googlemail.com on 22 Apr 2013 at 1:12

GoogleCodeExporter commented 9 years ago
We would like to help including the SynPDF library as potential export back end 
for your great engine!

Original comment by arn...@gmail.com on 23 Apr 2013 at 6:16

GoogleCodeExporter commented 9 years ago
Hi Ryan and Arnaud,

contributers are welcome at http://github.com/BerndGabriel/HtmlViewer

Please consider:
1) prefer a ThtPrinter.Init() method over protected members and 
2) replacing TMetaFilePrinter with ThtPrinter in the above 'case Mode of' code 
is not correct as Prn *is* of type ThtPrinter. TvwPrinter is a ThtPrinter as 
well and the code aims for distinguishing TvwPrinter from TMetaFilePrinter. 
Replacing

not (Prn is TMetaFilePrinter)

with 

Prn is TvwPrinter

would be better, but why do you need this change at all? Isn't a TPdfPrinter 
more like TvwPrinter, that prints to a printer?

OrphanCat

Original comment by OrphanCat on 23 Apr 2013 at 9:47