Merge pull request #9 from syncfusion/development

Added support for partial webpage conversion
This commit is contained in:
George Livingston 2016-07-04 14:07:59 +05:30 коммит произвёл GitHub
Родитель dad47c2d74 2ece32591f
Коммит 57ff720d8f
6 изменённых файлов: 73 добавлений и 7 удалений

Просмотреть файл

@ -55,6 +55,15 @@ PrintContext::~PrintContext()
end();
}
/*!
Set element to render
*/
WebCore::Element* renderElement;
void PrintContext::setElementToDraw(WebCore::Element* element)
{
renderElement = element;
}
void PrintContext::computePageRects(const FloatRect& printRect, float headerHeight, float footerHeight, float userScaleFactor, float& outPageHeight, bool allowHorizontalTiling)
{
m_pageRects.clear();
@ -70,7 +79,15 @@ void PrintContext::computePageRects(const FloatRect& printRect, float headerHeig
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()));
FloatSize pageSize;
if (renderElement != NULL)
{
IntRect renderElementBounds = renderElement->pixelSnappedBoundingBox();
pageSize = m_frame->resizePageRectsKeepingRatio(FloatSize(printRect.width(), printRect.height()), FloatSize(documentRect.width(), renderElementBounds.height()));
}
else
pageSize = m_frame->resizePageRectsKeepingRatio(FloatSize(printRect.width(), printRect.height()), FloatSize(documentRect.width(), documentRect.height()));
float pageWidth = pageSize.width();
float pageHeight = pageSize.height();
@ -104,8 +121,14 @@ void PrintContext::computePageRectsWithPageSizeInternal(const FloatSize& pageSiz
int pageHeight = pageSizeInPixels.height();
bool isHorizontal = view->style()->isHorizontalWritingMode();
int docLogicalHeight = isHorizontal ? docRect.height() : docRect.width();
int docLogicalHeight;
if (renderElement != NULL)
{
IntRect renderElementBounds = renderElement->pixelSnappedBoundingBox();
docLogicalHeight = isHorizontal ? renderElementBounds.height() : docRect.width();
}
else
docLogicalHeight = isHorizontal ? docRect.height() : docRect.width();
int pageLogicalHeight = isHorizontal ? pageHeight : pageWidth;
int pageLogicalWidth = isHorizontal ? pageWidth : pageHeight;
@ -201,12 +224,22 @@ void PrintContext::spoolPage(GraphicsContext& ctx, int pageNumber, float width)
{
// FIXME: Not correct for vertical text.
IntRect pageRect = m_pageRects[pageNumber];
if (renderElement != NULL)
{
IntRect renderElementBounds = renderElement->pixelSnappedBoundingBox();
if (pageNumber > 0)
pageRect = IntRect(renderElementBounds.x(), renderElementBounds.y() + pageRect.y(), pageRect.width(), renderElementBounds.height());
else
pageRect = IntRect(renderElementBounds.x(), renderElementBounds.y(), pageRect.width(), renderElementBounds.height());
}
float scale = width / pageRect.width();
ctx.save();
ctx.scale(FloatSize(scale, scale));
ctx.translate(-pageRect.x(), -pageRect.y());
ctx.clip(pageRect);
//Set element to render
m_frame->view()->setNodeToDraw(renderElement);
m_frame->view()->paintContents(&ctx, pageRect);
ctx.restore();
}

Просмотреть файл

@ -64,6 +64,7 @@ public:
// FIXME: eliminate width argument.
void spoolPage(GraphicsContext& ctx, int pageNumber, float width);
void setElementToDraw(WebCore::Element*);
void spoolRect(GraphicsContext& ctx, const IntRect&);

Просмотреть файл

@ -39,10 +39,14 @@ using namespace WebCore;
QT_BEGIN_NAMESPACE
extern Q_GUI_EXPORT int qt_defaultDpi();
QT_END_NAMESPACE
QtPrintContext::QtPrintContext(QPainter* painter, const QRect& pageRect, QWebFrameAdapter* frameAdapter)
WebCore::Element* renderElement;
QtPrintContext::QtPrintContext(QPainter* painter, const QRect& pageRect, QWebFrameAdapter* frameAdapter, WebCore::Element* element)
: m_graphicsContext(new GraphicsContext(painter))
, m_printContext(new PrintContext(frameAdapter->frame))
{
m_printContext->setElementToDraw(element);
renderElement = element;
totalPageLayoutSize = m_printContext->begin(pageRect.width(), pageRect.height());
printStatus = true;
float pageHeight = 0;
@ -105,9 +109,20 @@ QPair<int, QRectF> QtPrintContext::QGetRectangle(QWebFrameAdapter* frameAdapter,
// WebCore::RenderView *root = toRenderView(frameAdapter->frame->document()->renderer());
//float scale = (float)printWidth / (float)root->width();
QRectF r(const_cast<WebCore::RenderObject *>(ro)->absoluteBoundingBoxRect());
IntRect renderElementBounds;
if (renderElement != NULL)
renderElementBounds = renderElement->pixelSnappedBoundingBox();
int low=0;
int high=pageRects.size();
int c = r.y() + r.height() / 2;
int elementMaxWidth = r.x() + r.width() / 2;
if (renderElement == NULL || r.x() >= renderElementBounds.x() && elementMaxWidth <= renderElementBounds.x() + renderElementBounds.width() && r.y() >= renderElementBounds.y() && c <= renderElementBounds.y() + renderElementBounds.height())
{
if (renderElement != NULL)
{
r = QRectF(r.x() - renderElementBounds.x(), r.y() - renderElementBounds.y(), r.width(), r.height());
c = r.y() + r.height();
}
while(low <= high)
{
int m = (low + high)/2;
@ -120,6 +135,7 @@ QPair<int, QRectF> QtPrintContext::QGetRectangle(QWebFrameAdapter* frameAdapter,
return QPair<int, QRectF>(m+1, QRect(tr.x() , tr.y(), tr.width(), tr.height()));
}
}
}
return QPair<int,QRectF>(-1, QRectF());
}
Vector<IntRect> QtPrintContext::pageRects() const
@ -133,6 +149,8 @@ int QtPrintContext::pageCount() const
void QtPrintContext::spoolPage(int pageNumber, float width)
{
//Set element to draw
m_printContext->setElementToDraw(renderElement);
m_printContext->spoolPage(*m_graphicsContext, pageNumber, width);
}

Просмотреть файл

@ -36,7 +36,7 @@ class QWebFrameAdapter;
class WEBKIT_EXPORTDATA QtPrintContext {
public:
QtPrintContext(QPainter*, const QRect& pageRect, QWebFrameAdapter*);
QtPrintContext(QPainter*, const QRect& pageRect, QWebFrameAdapter*, WebCore::Element*);
QtPrintContext(QPainter* painter, const QRect& pageRect, QWebFrameAdapter* frameAdapter, bool status);
QtPrintContext(QPainter* painter, QWebFrameAdapter* frameAdapter);
~QtPrintContext();

Просмотреть файл

@ -946,6 +946,15 @@ QPair<int, QRectF> QWebFrame::GetHyperlinkLocation(QPrinter *printer,const QWebE
QtPrintContext printContext(&painter, d);
return printContext.QGetRectangle(d,pe.d->pageRect ,e);
}
/*!
Set element to render
*/
WebCore::Element* element;
void QWebFrame::setElementToRender(WebCore::Element* renderElement)
{
element = renderElement;
}
void QWebFrame::print(QPrinter *printer) const
{
#if HAVE(QTPRINTSUPPORT)
@ -959,9 +968,13 @@ void QWebFrame::print(QPrinter *printer) const
QRect qprinterRect = printer->pageRect();
QRect pageRect(0, 0, int(qprinterRect.width() / zoomFactorX), int(qprinterRect.height() / zoomFactorY));
QtPrintContext printContext(&painter, pageRect, d);
QtPrintContext printContext(&painter, pageRect, d,element);
IntRect m_totalPageLayoutSize = printContext.totalPageLayoutSize;
if (element != NULL)
{
IntRect elementBounds = element->pixelSnappedBoundingBox();
m_totalPageLayoutSize = IntRect(m_totalPageLayoutSize.x(), m_totalPageLayoutSize.y(), m_totalPageLayoutSize.width(), elementBounds.height());
}
QString sc = m_str;
std::string filePathString = sc.toStdString();
const char * filePath = filePathString.c_str();

Просмотреть файл

@ -199,6 +199,7 @@ public:
qreal textSizeMultiplier() const;
void createMhtmlDocument();
void setElementToRender(WebCore::Element*);
qreal zoomFactor() const;
void setZoomFactor(qreal factor);