View Issue Details
ID | Project | Category | View Status | Date Submitted | Last Update |
---|---|---|---|---|---|
0037682 | Lazarus | Other | public | 2020-09-01 23:47 | 2021-01-10 00:49 |
Reporter | Bob Richardson | Assigned To | Juha Manninen | ||
Priority | normal | Severity | minor | Reproducibility | always |
Status | resolved | Resolution | fixed | ||
OS | Windows | ||||
Summary | 0037682: Printer.PageNumber initialization error | ||||
Description | In Printer.BeginDoc, fPageNumber is set to 1. It is immediately increased to 2 when BeginPage is executed. Thus the very first page number is 2, not 1. This is easily fixed by initializing fPageNumber to 0, not 1. Works for me, although I'm not sure if there are other ramifications I don't know about. Perhaps very few use PageNumber in the Printer object. | ||||
Tags | No tags attached. | ||||
Fixed in Revision | r64072, r64104, r64367 | ||||
LazTarget | - | ||||
Widgetset | |||||
Attached Files |
|
related to | 0038027 | closed | Juha Manninen | [Patch] Unix Print Dialogs (Printer4Lazarus) |
|
Isn't this Lazarus? |
|
Well if being in the LCL\printers.pas means this I guess I would be... Fixable on the Lazarus side but maybe someone could fix the heading to correct the post but in any case I think it should be fixed. |
|
I seem to have misfiled this report. The error is with Lazarus, not FPC. |
|
I changed it in r64072. Please also test TPostScript in unit PostScriptPrinter. It initialized fPageNumber in many places. |
|
Hi Juha, TPostScript is a separate class not inherited from TPrinter and it handles updating fPageNumber well. I think it is best that we pattern TPrinter after it. Initialize fPageNumber to 1 in BeginDoc() and increment it in NewPage() instead of doing it in BeginPage(). Same applies to TPrinterCanvas class. It also has a fPageNum that is being incremented inside BeginPage(). In one of its descendant, TCairoPrinterCanvas, the inherited BeginPage() is not being called, thus fPageNum is not being incremented. Now, if we make BeginPage() call its inherited method, the resulting fPageNum will be wrong (greater), since TPrinterCanvas.BeginPage() is also called by TPrinter.BeginPage(). Attached is a patch containing the proposed changes. Browsed through the code (not tested :) of the following and I think these will not be affected by the change, except for TCairoPrinterCanvas where a call to its inherited method was added to NewPage(). Classes derived from TPrinter: TWinPrinter, TCUPSPrinter, TCarbonPRinter, TQtPrinter Classes derived from TPrinterCanvas: TFilePrinterCanvas, TCocoaPrinterCanvas, TPostScriptPrinterCanvas, TCairoPrinterCanvas and descendants printer-pagenumber-init.patch (1,319 bytes)
--- components/cairocanvas/cairocanvas.pas.64102 +++ components/cairocanvas/cairocanvas.pas @@ -362,6 +362,7 @@ procedure TCairoPrinterCanvas.NewPage; begin + inherited NewPage; EndPage; BeginPage; end; --- lcl/printers.pas.64102 +++ lcl/printers.pas @@ -376,7 +376,7 @@ Include(fFlags, pfPrinting); Exclude(fFlags, pfAborted); - fPageNumber := 0; + fPageNumber := 1; if not RawMode then begin Canvas.Refresh; @@ -414,6 +414,7 @@ //Create an new page procedure TPrinter.NewPage; begin + Inc(fPageNumber); if TMethod(@Self.DoNewPage).Code = Pointer(@TPrinter.DoNewPage) then begin // DoNewPage has not been overriden, use the new method @@ -423,7 +424,6 @@ begin // Use the old method as DoNewPage has been overriden in descendat TPrinter CheckPrinting(True); - Inc(fPageNumber); if not RawMode then TPrinterCanvas(Canvas).NewPage; DoNewPage; @@ -433,7 +433,6 @@ procedure TPrinter.BeginPage; begin CheckPrinting(True); - inc(fPageNumber); if not RawMode then TPrinterCanvas(Canvas).BeginPage; DoBeginPage; @@ -1397,12 +1396,12 @@ procedure TPrinterCanvas.NewPage; begin - BeginPage; + Inc(fPageNum); end; procedure TPrinterCanvas.BeginPage; begin - Inc(fPageNum); + end; procedure TPrinterCanvas.EndPage; |
|
Update: Restored TPrinterCanvas.NewPage() call to BeginPage() printer-pagenumber-init-v2.patch (1,319 bytes)
--- components/cairocanvas/cairocanvas.pas.64102 +++ components/cairocanvas/cairocanvas.pas @@ -362,6 +362,7 @@ procedure TCairoPrinterCanvas.NewPage; begin + inherited NewPage; EndPage; BeginPage; end; --- lcl/printers.pas.64102 +++ lcl/printers.pas @@ -376,7 +376,7 @@ Include(fFlags, pfPrinting); Exclude(fFlags, pfAborted); - fPageNumber := 0; + fPageNumber := 1; if not RawMode then begin Canvas.Refresh; @@ -414,6 +414,7 @@ //Create an new page procedure TPrinter.NewPage; begin + Inc(fPageNumber); if TMethod(@Self.DoNewPage).Code = Pointer(@TPrinter.DoNewPage) then begin // DoNewPage has not been overriden, use the new method @@ -423,7 +424,6 @@ begin // Use the old method as DoNewPage has been overriden in descendat TPrinter CheckPrinting(True); - Inc(fPageNumber); if not RawMode then TPrinterCanvas(Canvas).NewPage; DoNewPage; @@ -433,7 +433,6 @@ procedure TPrinter.BeginPage; begin CheckPrinting(True); - inc(fPageNumber); if not RawMode then TPrinterCanvas(Canvas).BeginPage; DoBeginPage; @@ -1397,12 +1396,13 @@ procedure TPrinterCanvas.NewPage; begin + Inc(fPageNum); BeginPage; end; procedure TPrinterCanvas.BeginPage; begin - Inc(fPageNum); + end; procedure TPrinterCanvas.EndPage; |
|
Thanks, I applied the last patch in r64104. I will keep this open for a week or so. Maybe the reporter Bob Richardson wants to test and comment, too. |
|
Resolving. I guess it works. |
|
BeginPage called twice in TCairoPrinterCanvas (first time on Inherited, before endpage), making all pages blank, excet the last. cairocanvasbug.diff (417 bytes)
Index: components/cairocanvas/cairocanvas.pas =================================================================== --- components/cairocanvas/cairocanvas.pas (revisão 64356) +++ components/cairocanvas/cairocanvas.pas (cópia de trabalho) @@ -367,9 +367,8 @@ procedure TCairoPrinterCanvas.NewPage; begin + EndPage; inherited NewPage; - EndPage; - BeginPage; end; procedure TCairoPrinterCanvas.BeginPage; |
|
Applied the last patch, thanks. Fortunately I noticed a resolved report was changed. |
Date Modified | Username | Field | Change |
---|---|---|---|
2020-09-01 23:47 | Bob Richardson | New Issue | |
2020-09-02 00:43 | Bart Broersma | Note Added: 0125288 | |
2020-09-02 12:42 | jamie philbrook | Note Added: 0125292 | |
2020-09-02 16:47 | Bob Richardson | Note Added: 0125296 | |
2020-09-02 19:02 | Jonas Maebe | Project | FPC => Lazarus |
2020-10-25 01:18 | Juha Manninen | Assigned To | => Juha Manninen |
2020-10-25 01:18 | Juha Manninen | Status | new => assigned |
2020-10-25 09:25 | Juha Manninen | Status | assigned => feedback |
2020-10-25 09:25 | Juha Manninen | LazTarget | => - |
2020-10-25 09:25 | Juha Manninen | Note Added: 0126533 | |
2020-11-03 09:17 | Juha Manninen | Relationship added | related to 0038027 |
2020-11-04 07:19 | Joeny Ang | Note Added: 0126718 | |
2020-11-04 07:19 | Joeny Ang | File Added: printer-pagenumber-init.patch | |
2020-11-04 07:33 | Joeny Ang | Note Added: 0126719 | |
2020-11-04 07:33 | Joeny Ang | File Added: printer-pagenumber-init-v2.patch | |
2020-11-04 18:50 | Juha Manninen | Note Added: 0126731 | |
2020-11-04 18:50 | Juha Manninen | Product Version | 3.2.0 => |
2020-11-04 18:50 | Juha Manninen | Fixed in Revision | => r64072, r64104 |
2020-11-15 18:52 | Juha Manninen | Status | feedback => resolved |
2020-11-15 18:52 | Juha Manninen | Resolution | open => fixed |
2020-11-15 18:52 | Juha Manninen | Note Added: 0126972 | |
2021-01-09 18:24 | Percy Van Den Bylaardt | Note Added: 0128208 | |
2021-01-09 18:24 | Percy Van Den Bylaardt | File Added: cairocanvasbug.diff | |
2021-01-09 20:15 | Juha Manninen | Status | resolved => assigned |
2021-01-09 20:15 | Juha Manninen | Resolution | fixed => open |
2021-01-09 21:43 | Juha Manninen | Status | assigned => resolved |
2021-01-09 21:43 | Juha Manninen | Resolution | open => fixed |
2021-01-09 21:43 | Juha Manninen | Fixed in Revision | r64072, r64104 => r64072, r64104, r64367 |
2021-01-09 21:43 | Juha Manninen | Note Added: 0128221 |