void PrintContext::computePageRects(const FloatRect& printRect, float headerHeight, float footerHeight, float userScaleFactor, float& outPageHeight, bool allowHorizontalTiling) { m_pageRects.clear(); outPageHeight = 0; if (!m_frame->document() || !m_frame->view() || !m_frame->document()->renderer()) return; if (userScaleFactor <= 0) { LOG_ERROR("userScaleFactor has bad value %.2f", userScaleFactor); return; } RenderView* view = toRenderView(m_frame->document()->renderer()); bool isHorizontal = view->style()->isHorizontalWritingMode(); float pageWidth; float pageHeight; if (isHorizontal) { pageWidth = view->docWidth(); ///NOTE: if we do not reuse the previously set logical page height, /// we can end up with off-by-one erros in the page height, /// leading to rendering issues (e.g. rows overlap pagebreaks) if (view->pageLogicalHeight() == 0) { float ratio = printRect.height() / printRect.width(); pageHeight = floorf(pageWidth * ratio); } else { pageHeight = view->pageLogicalHeight(); } } else { float ratio = printRect.width() / printRect.height(); pageHeight = view->docHeight(); pageWidth = floorf(pageHeight * ratio); } outPageHeight = pageHeight; // this is the height of the page adjusted by margins pageHeight -= headerHeight + footerHeight; if (pageHeight <= 0) { LOG_ERROR("pageHeight has bad value %.2f", pageHeight); return; } computePageRectsWithPageSizeInternal(FloatSize(pageWidth / userScaleFactor, pageHeight / userScaleFactor), allowHorizontalTiling); }
void PrintContext::computePageRects(const FloatRect& printRect, float headerHeight, float footerHeight, float userScaleFactor, float& outPageHeight, bool allowHorizontalTiling) { m_pageRects.clear(); outPageHeight = 0; if (!m_frame->document() || !m_frame->view() || !m_frame->document()->renderer()) return; if (userScaleFactor <= 0) { LOG_ERROR("userScaleFactor has bad value %.2f", userScaleFactor); return; } RenderView* view = toRenderView(m_frame->document()->renderer()); bool isHorizontal = view->style()->isHorizontalWritingMode(); float pageWidth; float pageHeight; if (isHorizontal) { float ratio = printRect.height() / printRect.width(); pageWidth = view->docWidth(); pageHeight = floorf(pageWidth * ratio); } else { float ratio = printRect.width() / printRect.height(); pageHeight = view->docHeight(); pageWidth = floorf(pageHeight * ratio); } outPageHeight = pageHeight; // this is the height of the page adjusted by margins pageHeight -= headerHeight + footerHeight; if (pageHeight <= 0) { LOG_ERROR("pageHeight has bad value %.2f", pageHeight); return; } computePageRectsWithPageSizeInternal(FloatSize(pageWidth / userScaleFactor, pageHeight / userScaleFactor), allowHorizontalTiling); }