Menu ▾ ▴

#658 TPrinter::Print prints only the selection whenever the printout reports one

6.44
pending
Printing (5)
1
5 days ago
5 days ago
No

TPrinter::Print asks the printout for a selection with GetDialogInfo. If the printout reports one (a non-zero selFromPage), it is always printed instead of what the user chose in the Print dialog. The page range is chosen by this condition (source/owlcore/printer.cpp):

else if ((prompt && (Data->Flags & PD_SELECTION)) || selFromPage)
{
  fromPage = selFromPage;
  toPage = selToPage;
}

The selFromPage operand makes the choice in the dialog irrelevant: "All", "Pages" and "Current page" all print the selection. The condition is from the original code (only the parentheses were added in [r2781]).

The intent seems to be that the selection is printed when the user picks "Selection" in the dialog, or by default when printing without the dialog. If so, the condition should be:

else if (prompt ? (Data->Flags & PD_SELECTION) : selFromPage != 0)

Related problem in TRichEditPrintout: TRichEditPrintout::GetDialogInfo reports a selection even when there is none. Without a selection, it returns selFromPage = 1 and selToPage = 2 (if there are at least 2 pages). With a selection, it returns the page where the selection starts and the following page, not the page where it ends. Combined with the above, printing a TRichEdit through TRichEditPrintout prints only pages 1 and 2, whatever is chosen. For a one-page document, it reports pages 1 to 0, which fails the precondition in the print loop (fromPage <= toPage) in a diagnostic build, and prints nothing otherwise. The "!BB Update to support multiple preview pages" comment there suggests the values were meant for the old preview (two pages) rather than for the selection. It should report a selection only if there is one, from the page of the start of the selection to the page of its end.

Found while fixing "Current page" in [r9534]. The RichEditor example is not affected, since its printouts do not report a selection.

Related

Commit: [r2781]
Commit: [r9534]
Commit: [r9541]
Discussion: AI assistance
Wiki: OWLNext_6.40_Series_Revision_History
Wiki: OWLNext_7_Series_Revision_History

Discussion

  • Ognyan Chernokozhev

    Fixed in trunk [r9539]:

    • TPrinter::Print: The selection is now printed only if the user chooses "Selection" in the Print dialog, or by default when printing without the dialog. A "Selection" choice left from the last time the dialog was shown is cleared if there is no selection now.
    • TRichEditPrintout::GetDialogInfo: A selection is now reported only if text is selected, from the page where it starts to the page where it ends.
    • TRichEditPrintout::SetPrintParams: While testing, I found a worse bug. The first time a printout paginated the document, it counted only every other page break. So a 26-page document came out as 13 pages, each holding the text of two, and half of the text was never printed. A one-page document had no pages at all. Now the pagination is right every time.

    Tested with the real Print dialog, recording the pages printed: no selection; a selection with All, Selection, Pages and without the dialog; a selection starting at a page break; a one-page document; and the page count. The old code fails 10 of the checks.

    The same code is probably in the branches, which I haven't checked.

     
    👍
    1

    Related

    Commit: [r9539]

  • Ognyan Chernokozhev

    • labels: --> Printing
    • status: open --> pending
     
  • Ognyan Chernokozhev

    The 7 and 6.44 branches had all three bugs. The fix is ported to branch 7 in [r9540] and to 6.44 in [r9541].

    Tested on both branches by printing to the XPS Document Writer, with the user's choice in the Print dialog simulated. The test covers the same cases as in trunk, plus a "Selection" choice left from the last time. The old code fails 11 of the checks on both branches. Built with VS 2026 (x64) only.

     
    👍
    1

    Related

    Commit: [r9540]

  • Ognyan Chernokozhev

    • Group: 8 --> 6.44
     

Log in to post a comment.