[SCM] WebKit Debian packaging branch, webkit-1.1, updated. upstream/1.1.17-1283-gcf603cf
bfulgham at webkit.org
bfulgham at webkit.org
Tue Jan 5 23:49:31 UTC 2010
The following commit has been merged in the webkit-1.1 branch:
commit d7a253f3be380651046d9b1a1cd869bd349dc851
Author: bfulgham at webkit.org <bfulgham at webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date: Mon Dec 14 22:23:43 2009 +0000
Provide working printing support for WinCairo port.
Reviewed by Adam Roben.
* WebFrame.cpp:
(WebFrame::spoolPage): Conditionalize initialization of
PlatformGraphicsContext handling for CG vs. Cairo.
(scaleFactor): Add helper function.
(hdcFromContext): Add helper function.
(WebFrame::drawHeader): Correct Cairo variation.
(WebFrame::drawFooter): Correct Cairo variation.
(WebFrame::spoolPages): Correct Cairo variation.
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@52121 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/WebKit/win/ChangeLog b/WebKit/win/ChangeLog
index 4658fc7..f426ad3 100644
--- a/WebKit/win/ChangeLog
+++ b/WebKit/win/ChangeLog
@@ -1,3 +1,18 @@
+2009-12-14 Brent Fulgham <bfulgham at webkit.org>
+
+ Reviewed by Adam Roben.
+
+ Provide working printing support for WinCairo port.
+
+ * WebFrame.cpp:
+ (WebFrame::spoolPage): Conditionalize initialization of
+ PlatformGraphicsContext handling for CG vs. Cairo.
+ (scaleFactor): Add helper function.
+ (hdcFromContext): Add helper function.
+ (WebFrame::drawHeader): Correct Cairo variation.
+ (WebFrame::drawFooter): Correct Cairo variation.
+ (WebFrame::spoolPages): Correct Cairo variation.
+
2009-12-13 Sam Weinig <sam at webkit.org>
Reviewed by Dan Bernstein.
diff --git a/WebKit/win/WebFrame.cpp b/WebKit/win/WebFrame.cpp
index 9063fde..ff40b65 100644
--- a/WebKit/win/WebFrame.cpp
+++ b/WebKit/win/WebFrame.cpp
@@ -1952,6 +1952,7 @@ HRESULT STDMETHODCALLTYPE WebFrame::getPrintedPageCount(
return S_OK;
}
+#if PLATFORM(CG)
void WebFrame::drawHeader(PlatformGraphicsContext* pctx, IWebUIDelegate* ui, const IntRect& pageRect, float headerHeight)
{
int x = pageRect.x();
@@ -1968,7 +1969,6 @@ void WebFrame::drawFooter(PlatformGraphicsContext* pctx, IWebUIDelegate* ui, con
ui->drawFooterInRect(d->webView, &footerRect, static_cast<OLE_HANDLE>(reinterpret_cast<LONG64>(pctx)), page+1, pageCount);
}
-#if PLATFORM(CG)
void WebFrame::spoolPage(PlatformGraphicsContext* pctx, GraphicsContext* spoolCtx, HDC printDC, IWebUIDelegate* ui, float headerHeight, float footerHeight, UINT page, UINT pageCount)
{
Frame* coreFrame = core(this);
@@ -1985,7 +1985,6 @@ void WebFrame::spoolPage(PlatformGraphicsContext* pctx, GraphicsContext* spoolCt
CGContextBeginPage(pctx, &mediaBox);
- // FIXME: Could some of this coordinate space manipulation be shared with Cairo?
CGFloat scale = static_cast<float>(mediaBox.size.width)/static_cast<float>(pageRect.width());
CGAffineTransform ctm = CGContextGetBaseCTM(pctx);
ctm = CGAffineTransformScale(ctm, -scale, -scale);
@@ -2008,30 +2007,57 @@ void WebFrame::spoolPage(PlatformGraphicsContext* pctx, GraphicsContext* spoolCt
CGContextRestoreGState(pctx);
}
#elif PLATFORM(CAIRO)
+static float scaleFactor(HDC printDC, const IntRect& pageRect)
+{
+ const IntRect& printRect = printerRect(printDC);
+
+ return static_cast<float>(printRect.width()) / static_cast<float>(pageRect.width());
+}
+
+static HDC hdcFromContext(PlatformGraphicsContext* pctx)
+{
+ cairo_surface_t* surface = cairo_get_target(pctx);
+ return cairo_win32_surface_get_dc(surface);
+}
+
+void WebFrame::drawHeader(PlatformGraphicsContext* pctx, IWebUIDelegate* ui, const IntRect& pageRect, float headerHeight)
+{
+ HDC hdc = hdcFromContext(pctx);
+
+ const float scale = scaleFactor(hdc, pageRect);
+ int x = static_cast<int>(scale * pageRect.x());
+ int y = 0;
+ RECT headerRect = {x, y, x + static_cast<int>(scale * pageRect.width()), y + static_cast<int>(scale * headerHeight)};
+
+ ui->drawHeaderInRect(d->webView, &headerRect, static_cast<OLE_HANDLE>(reinterpret_cast<LONG64>(hdc)));
+}
+
+void WebFrame::drawFooter(PlatformGraphicsContext* pctx, IWebUIDelegate* ui, const IntRect& pageRect, UINT page, UINT pageCount, float headerHeight, float footerHeight)
+{
+ HDC hdc = hdcFromContext(pctx);
+
+ const float scale = scaleFactor(hdc, pageRect);
+ int x = static_cast<int>(scale * pageRect.x());
+ int y = static_cast<int>(scale * max(static_cast<int>(headerHeight) + pageRect.height(), m_pageHeight-static_cast<int>(footerHeight)));
+ RECT footerRect = {x, y, x + static_cast<int>(scale * pageRect.width()), y + static_cast<int>(scale * footerHeight)};
+
+ ui->drawFooterInRect(d->webView, &footerRect, static_cast<OLE_HANDLE>(reinterpret_cast<LONG64>(hdc)), page+1, pageCount);
+}
+
void WebFrame::spoolPage(PlatformGraphicsContext* pctx, GraphicsContext* spoolCtx, HDC printDC, IWebUIDelegate* ui, float headerHeight, float footerHeight, UINT page, UINT pageCount)
{
Frame* coreFrame = core(this);
IntRect pageRect = m_pageRects[page];
-
- cairo_save(pctx);
-
IntRect printRect = printerRect(printDC);
- IntRect mediaBox(0, 0, printRect.width(), printRect.height());
- ::StartPage(printDC);
-
- // FIXME: Could some of this coordinate space manipulation be shared with CG?
- float scale = static_cast<float>(mediaBox.size().width())/static_cast<float>(pageRect.width());
- cairo_scale(pctx, -scale, -scale);
- cairo_translate(pctx, -pageRect.x(), -pageRect.y()+headerHeight);
+ cairo_save(pctx);
+ float scale = static_cast<float>(printRect.width()) / static_cast<float>(pageRect.width());
cairo_scale(pctx, scale, scale);
- cairo_translate(pctx, -pageRect.x(), -pageRect.y()+headerHeight); // reserves space for header
+ cairo_translate(pctx, -pageRect.x(), -pageRect.y()+headerHeight);
coreFrame->view()->paintContents(spoolCtx, pageRect);
- cairo_translate(pctx, pageRect.x(), pageRect.y()-headerHeight);
-
if (headerHeight)
drawHeader(pctx, ui, pageRect, headerHeight);
@@ -2039,7 +2065,6 @@ void WebFrame::spoolPage(PlatformGraphicsContext* pctx, GraphicsContext* spoolCt
drawFooter(pctx, ui, pageRect, page, pageCount, headerHeight, footerHeight);
cairo_show_page(pctx);
- ::EndPage(printDC);
cairo_restore(pctx);
}
#endif
@@ -2050,10 +2075,25 @@ HRESULT STDMETHODCALLTYPE WebFrame::spoolPages(
/* [in] */ UINT endPage,
/* [retval][out] */ void* ctx)
{
+#if PLATFORM(CG)
if (!printDC || !ctx) {
ASSERT_NOT_REACHED();
return E_POINTER;
}
+#elif PLATFORM(CAIRO)
+ if (!printDC) {
+ ASSERT_NOT_REACHED();
+ return E_POINTER;
+ }
+
+ cairo_surface_t* printSurface = cairo_win32_printing_surface_create(printDC);
+ ctx = cairo_create(printSurface);
+ if (!ctx) {
+ cairo_surface_destroy(printSurface);
+ return E_FAIL;
+ }
+ cairo_surface_set_fallback_resolution(printSurface, 72.0, 72.0);
+#endif
if (!m_inPrintingMode) {
ASSERT_NOT_REACHED();
@@ -2089,7 +2129,12 @@ HRESULT STDMETHODCALLTYPE WebFrame::spoolPages(
for (UINT ii = startPage; ii < endPage; ii++)
spoolPage(pctx, &spoolCtx, printDC, ui.get(), headerHeight, footerHeight, ii, pageCount);
-
+
+#if PLATFORM(CAIRO)
+ cairo_destroy(pctx);
+ cairo_surface_destroy(printSurface);
+#endif
+
return S_OK;
}
--
WebKit Debian packaging
More information about the Pkg-webkit-commits
mailing list