QtPrintContext.cpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /*
  2. * Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
  3. *
  4. * This library is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU Library General Public
  6. * License as published by the Free Software Foundation; either
  7. * version 2 of the License, or (at your option) any later version.
  8. *
  9. * This library is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * Library General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Library General Public License
  15. * along with this library; see the file COPYING.LIB. If not, write to
  16. * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  17. * Boston, MA 02110-1301, USA.
  18. *
  19. */
  20. #include "config.h"
  21. #include "QtPrintContext.h"
  22. #include "GraphicsContext.h"
  23. #include "IntRect.h"
  24. #include "PrintContext.h"
  25. #include "QWebFrameAdapter.h"
  26. using namespace WebCore;
  27. QtPrintContext::QtPrintContext(QPainter* painter, const QRect& pageRect, QWebFrameAdapter* frameAdapter)
  28. : m_graphicsContext(new GraphicsContext(painter))
  29. , m_printContext(new PrintContext(frameAdapter->frame))
  30. {
  31. m_printContext->begin(pageRect.width(), pageRect.height());
  32. float pageHeight = 0;
  33. m_printContext->computePageRects(IntRect(pageRect), /* headerHeight */ 0, /* footerHeight */ 0, /* userScaleFactor */ 1.0, pageHeight);
  34. }
  35. QtPrintContext::~QtPrintContext()
  36. {
  37. m_printContext->end();
  38. delete m_graphicsContext;
  39. delete m_printContext;
  40. }
  41. int QtPrintContext::pageCount() const
  42. {
  43. return m_printContext->pageCount();
  44. }
  45. void QtPrintContext::spoolPage(int pageNumber, float width)
  46. {
  47. m_printContext->spoolPage(*m_graphicsContext, pageNumber, width);
  48. }