Menu

#496 TPrintPreviewDC is broken

unspecified
pending
nobody
1
2026-03-27
2021-04-23
No

The initial call to SyncFont from the constructor fails (GetObject for PrnFont fails), and attempts to delete an object it has not created (calls DeleteObject on the previously selected font).

Further more, the class assumes that it owns any selected font (in the screen preview DC) in its lifetime, and will try to delete the previous selection in every call to SyncFont and finally in its destructor. This is not a safe assumption, and in particular, does not work well with SaveDC/RestoreDC.

Also, the member CurrentPreviewFont makes no sense. It would make sense as the screen preview font, which is created as a scaled version of the printer font in SyncFont, and this seems to be the design intention, judging by the naming and code comments referring to the "preview font". However, CurrentPreviewFont is just a seemingly pointless copy of the currently selected printer font, and no reference to the created screen preview font is retained.

This also makes the test in SelectObject, to see if PrnFont matches CurrentPreviewFont, completely pointless, since the latter is always a new font created just prior to the test. The intended test seems to be whether the selected printer font (newFont) matches PrnFont, which is not what is tested here.

void
TPrintPreviewDC::SelectObject(const TFont& newFont)
{
  if ((HFONT)newFont) {
    LOGFONT lf = newFont.GetObject();

    TFont*  oldPreviewF = CurrentPreviewFont;
    CurrentPreviewFont = new TFont(lf);

    PrnDC.SelectObject(*CurrentPreviewFont);
    delete oldPreviewF;

    if ((HFONT)(*CurrentPreviewFont) != PrnFont) {
      PrnFont = (HFONT)(*CurrentPreviewFont);
      SyncFont();
    }
  }
}

It seems something went wrong during the development of this code, which by the way, hasn't changed much since OWL 5.

Discussion

  • Vidar Hasfjord

    Vidar Hasfjord - 2021-04-23
    • status: open --> pending
     
  • Vidar Hasfjord

    Vidar Hasfjord - 2021-04-23

    This issue has been fixed in Owlet [r5483].

     

    Related

    Commit: [r5483]


    Last edit: Vidar Hasfjord 1 day ago
  • Vidar Hasfjord

    Vidar Hasfjord - 2026-03-27
    • Labels: Printing, GDI --> Printing, GDI, Owlet
    • Group: Owlet --> unspecified
     
  • Vidar Hasfjord

    Vidar Hasfjord - 2026-03-27
    • assigned_to: Vidar Hasfjord --> nobody
     

Log in to post a comment.