void PrintContext::computePageRects(const FloatRect& printRect, float headerHeight, float footerHeight, float userScaleFactor, float& outPageHeight) { m_pageRects.clear(); outPageHeight = 0; if (!m_frame->document() || !m_frame->view() || !m_frame->document()->renderView()) return; if (userScaleFactor <= 0) { WTF_LOG_ERROR("userScaleFactor has bad value %.2f", userScaleFactor); return; } RenderView* view = m_frame->document()->renderView(); const IntRect& documentRect = view->documentRect(); FloatSize pageSize = m_frame->resizePageRectsKeepingRatio(FloatSize(printRect.width(), printRect.height()), FloatSize(documentRect.width(), documentRect.height())); float pageWidth = pageSize.width(); float pageHeight = pageSize.height(); outPageHeight = pageHeight; // this is the height of the page adjusted by margins pageHeight -= headerHeight + footerHeight; if (pageHeight <= 0) { WTF_LOG_ERROR("pageHeight has bad value %.2f", pageHeight); return; } computePageRectsWithPageSizeInternal(FloatSize(pageWidth / userScaleFactor, pageHeight / userScaleFactor), false); }
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; const IntRect& documentRect = view->documentRect(); if (isHorizontal) { float ratio = printRect.height() / printRect.width(); pageWidth = documentRect.width(); pageHeight = floorf(pageWidth * ratio); } else { float ratio = printRect.width() / printRect.height(); pageHeight = documentRect.height(); 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) { m_pageRects.clear(); outPageHeight = 0; if (!m_frame->document() || !m_frame->view() || m_frame->document()->layoutViewItem().isNull()) return; if (userScaleFactor <= 0) { DLOG(ERROR) << "userScaleFactor has bad value " << userScaleFactor; return; } LayoutViewItem view = m_frame->document()->layoutViewItem(); const IntRect& documentRect = view.documentRect(); FloatSize pageSize = m_frame->resizePageRectsKeepingRatio( FloatSize(printRect.width(), printRect.height()), FloatSize(documentRect.width(), documentRect.height())); float pageWidth = pageSize.width(); float pageHeight = pageSize.height(); outPageHeight = pageHeight; // this is the height of the page adjusted by margins pageHeight -= headerHeight + footerHeight; if (pageHeight <= 0) { DLOG(ERROR) << "pageHeight has bad value " << pageHeight; return; } computePageRectsWithPageSizeInternal( FloatSize(pageWidth / userScaleFactor, pageHeight / userScaleFactor)); }
void PrintContext::computePageRectsWithPageSize(const FloatSize& pageSizeInPixels, bool allowHorizontalTiling) { m_pageRects.clear(); computePageRectsWithPageSizeInternal(pageSizeInPixels, allowHorizontalTiling); }
void PrintContext::computePageRectsWithPageSize(const FloatSize& pageSizeInPixels) { m_pageRects.clear(); computePageRectsWithPageSizeInternal(pageSizeInPixels); }