From cbcae6ef9b6bc0dea7841f84102b99a296b820e7 Mon Sep 17 00:00:00 2001 From: Stefano Ceccherini Date: Fri, 12 Oct 2007 07:58:33 +0000 Subject: [PATCH] StyledEdit didn't print anything if there's only one line (bug #1288). Note, though, that printing in StyledEdit is still very much broken. Often it prints only the current page, for example. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@22511 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/apps/stylededit/StyledEditWindow.cpp | 38 +++++++++++++----------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/src/apps/stylededit/StyledEditWindow.cpp b/src/apps/stylededit/StyledEditWindow.cpp index c14c6760f5..dcff088242 100644 --- a/src/apps/stylededit/StyledEditWindow.cpp +++ b/src/apps/stylededit/StyledEditWindow.cpp @@ -1115,26 +1115,30 @@ StyledEditWindow::Print(const char* documentName) lastLine = currentLine - 1; } + printJob.BeginJob(); - int32 printLine = firstLine; - while (printLine < lastLine) { - float currentHeight = 0; - int32 firstLineOnPage = printLine; - while (currentHeight < printableRect.Height() && printLine < lastLine) { - currentHeight += fTextView->LineHeight(printLine); - if (currentHeight < printableRect.Height()) - printLine++; + if (fTextView->CountLines() > 0 && fTextView->TextLength() > 0) { + int32 printLine = firstLine; + while (printLine <= lastLine) { + float currentHeight = 0; + int32 firstLineOnPage = printLine; + while (currentHeight < printableRect.Height() && printLine <= lastLine) { + currentHeight += fTextView->LineHeight(printLine); + if (currentHeight < printableRect.Height()) + printLine++; + } + + float top = 0; + if (firstLineOnPage != 0) + top = fTextView->TextHeight(0, firstLineOnPage - 1); + + float bottom = fTextView->TextHeight(0, printLine - 1); + BRect textRect(0.0, top + TEXT_INSET, printableRect.Width(), bottom + TEXT_INSET); + printJob.DrawView(fTextView, textRect, B_ORIGIN); + printJob.SpoolPage(); } - - float top = 0; - if (firstLineOnPage != 0) - top = fTextView->TextHeight(0, firstLineOnPage - 1); - - float bottom = fTextView->TextHeight(0, printLine - 1); - BRect textRect(0.0, top + TEXT_INSET, printableRect.Width(), bottom + TEXT_INSET); - printJob.DrawView(fTextView, textRect, BPoint(0.0,0.0)); - printJob.SpoolPage(); } + printJob.CommitJob(); }