[SCM] WebKit Debian packaging branch, webkit-1.2, updated. upstream/1.1.90-6072-g9a69373

bfulgham at webkit.org bfulgham at webkit.org
Thu Apr 8 01:02:33 UTC 2010


The following commit has been merged in the webkit-1.2 branch:
commit bdad318acdb2da66e4d2af4e1020c0bdff80f8b5
Author: bfulgham at webkit.org <bfulgham at webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Tue Jan 12 20:32:11 2010 +0000

    Extend WinLauncher example with better printing features.
    
    Reviewed by Darin Adler.
    
    * WinLauncher/PrintWebUIDelegate.cpp:
    (PrintWebUIDelegate::webViewPrintingMarginRect): Provide slightly
     larger margins.
    (PrintWebUIDelegate::webViewHeaderHeight): Compute header height based
     on text metrics.
    (PrintWebUIDelegate::webViewFooterHeight): Compute footer height based
     on text metrics.
    (PrintWebUIDelegate::drawHeaderInRect): Write useful header, along
     with separating line.
    (PrintWebUIDelegate::drawFooterInRect):
    * WinLauncher/PrintWebUIDelegate.h: Remove stubs.
    * WinLauncher/WinLauncher.cpp:
    (PrintView): Correct loop used to print individual pages.
     Previously it started at 0, which is a wild-card to print all
     pages at once.
    
    
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@53154 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/WebKitTools/ChangeLog b/WebKitTools/ChangeLog
index 20fb838..c8fe8a0 100644
--- a/WebKitTools/ChangeLog
+++ b/WebKitTools/ChangeLog
@@ -1,3 +1,25 @@
+2010-01-12  Brent Fulgham  <bfulgham at webkit.org>
+
+        Reviewed by Darin Adler.
+
+        Extend WinLauncher example with better printing features.
+
+        * WinLauncher/PrintWebUIDelegate.cpp:
+        (PrintWebUIDelegate::webViewPrintingMarginRect): Provide slightly
+         larger margins.
+        (PrintWebUIDelegate::webViewHeaderHeight): Compute header height based
+         on text metrics.
+        (PrintWebUIDelegate::webViewFooterHeight): Compute footer height based
+         on text metrics.
+        (PrintWebUIDelegate::drawHeaderInRect): Write useful header, along
+         with separating line.
+        (PrintWebUIDelegate::drawFooterInRect):
+        * WinLauncher/PrintWebUIDelegate.h: Remove stubs.
+        * WinLauncher/WinLauncher.cpp:
+        (PrintView): Correct loop used to print individual pages.
+         Previously it started at 0, which is a wild-card to print all
+         pages at once.
+
 2010-01-12  Alexey Proskuryakov  <ap at apple.com>
 
         Reviewed by Darin Adler.
diff --git a/WebKitTools/WinLauncher/PrintWebUIDelegate.cpp b/WebKitTools/WinLauncher/PrintWebUIDelegate.cpp
index f2f0122..ccc267b 100644
--- a/WebKitTools/WinLauncher/PrintWebUIDelegate.cpp
+++ b/WebKitTools/WinLauncher/PrintWebUIDelegate.cpp
@@ -84,11 +84,111 @@ HRESULT PrintWebUIDelegate::webViewPrintingMarginRect(IWebView* view, RECT* rect
 
     rect->left += MARGIN;
     rect->top += MARGIN;
-    rect->right -= MARGIN; 
-    rect->bottom -= MARGIN;
+    HDC dc = ::GetDC(0);
+    rect->right = (::GetDeviceCaps(dc, LOGPIXELSX) * 6.5) - MARGIN;
+    rect->bottom = (::GetDeviceCaps(dc, LOGPIXELSY) * 11) - MARGIN;
+    ::ReleaseDC(0, dc);
 
     privateFrame->Release();
     mainFrame->Release();
 
     return S_OK;
 }
+
+HRESULT PrintWebUIDelegate::webViewHeaderHeight(IWebView* webView, float* height)
+{
+   if (!webView || !height)
+      return E_POINTER;
+   
+   HDC dc = ::GetDC(0);
+
+   TEXTMETRIC textMetric;
+   ::GetTextMetrics(dc, &textMetric);
+   ::ReleaseDC(0, dc);
+
+   *height = 1.1 * textMetric.tmHeight;
+
+   return S_OK;
+}
+
+HRESULT PrintWebUIDelegate::webViewFooterHeight(IWebView* webView, float* height)
+{
+   if (!webView || !height)
+      return E_POINTER;
+
+   HDC dc = ::GetDC(0);
+
+   TEXTMETRIC textMetric;
+   ::GetTextMetrics(dc, &textMetric);
+   ::ReleaseDC(0, dc);
+
+   *height = 1.1 * textMetric.tmHeight;
+
+   return S_OK;
+}
+
+HRESULT PrintWebUIDelegate::drawHeaderInRect( 
+            /* [in] */ IWebView *webView,
+            /* [in] */ RECT *rect,
+            /* [in] */ OLE_HANDLE drawingContext)
+{
+   if (!webView || !rect)
+      return E_POINTER;
+
+   // Turn off header for now.
+   HDC dc = reinterpret_cast<HDC>(drawingContext);
+
+   HFONT hFont = (HFONT)::GetStockObject(ANSI_VAR_FONT);
+   HFONT hOldFont = (HFONT)::SelectObject(dc, hFont);
+
+   LPCTSTR header(_T("[Sample Header]"));
+   int length = _tcslen(header);
+
+   int rc = ::DrawText(dc, header, length, rect, DT_LEFT | DT_NOCLIP | DT_VCENTER  | DT_SINGLELINE);
+   ::SelectObject(dc, hOldFont);
+
+   if (!rc)
+      return E_FAIL;
+
+   ::MoveToEx(dc, rect->left, rect->bottom, 0);
+   HPEN hPen = (HPEN)::GetStockObject(BLACK_PEN);
+   HPEN hOldPen = (HPEN)::SelectObject(dc, hPen);
+   ::LineTo(dc, rect->right, rect->bottom);
+   ::SelectObject(dc, hOldPen);
+
+   return S_OK;
+}
+
+HRESULT PrintWebUIDelegate::drawFooterInRect( 
+            /* [in] */ IWebView *webView,
+            /* [in] */ RECT *rect,
+            /* [in] */ OLE_HANDLE drawingContext,
+            /* [in] */ UINT pageIndex,
+            /* [in] */ UINT pageCount)
+{
+   if (!webView || !rect)
+      return E_POINTER;
+
+   HDC dc = reinterpret_cast<HDC>(drawingContext);
+
+   HFONT hFont = (HFONT)::GetStockObject(ANSI_VAR_FONT);
+   HFONT hOldFont = (HFONT)::SelectObject(dc, hFont);
+
+   LPCTSTR footer(_T("[Sample Footer]"));
+   int length = _tcslen(footer);
+
+   // Add a line, 1/10th inch above the footer text from left margin to right margin.
+   ::MoveToEx(dc, rect->left, rect->top, 0);
+   HPEN hPen = (HPEN)::GetStockObject(BLACK_PEN);
+   HPEN hOldPen = (HPEN)::SelectObject(dc, hPen);
+   ::LineTo(dc, rect->right, rect->top);
+   ::SelectObject(dc, hOldPen);
+
+   int rc = ::DrawText(dc, footer, length, rect, DT_LEFT | DT_NOCLIP | DT_VCENTER  | DT_SINGLELINE);
+   ::SelectObject(dc, hOldFont);
+
+   if (!rc)
+      return E_FAIL;
+
+   return S_OK;
+}
diff --git a/WebKitTools/WinLauncher/PrintWebUIDelegate.h b/WebKitTools/WinLauncher/PrintWebUIDelegate.h
index 1d7d701..9749a98 100644
--- a/WebKitTools/WinLauncher/PrintWebUIDelegate.h
+++ b/WebKitTools/WinLauncher/PrintWebUIDelegate.h
@@ -88,10 +88,10 @@ public:
     virtual HRESULT STDMETHODCALLTYPE canRedo(BOOL*) { return E_NOTIMPL; }
     virtual HRESULT STDMETHODCALLTYPE printFrame(IWebView*, IWebFrame *) { return E_NOTIMPL; }
     virtual HRESULT STDMETHODCALLTYPE ftpDirectoryTemplatePath(IWebView*, BSTR*) { return E_NOTIMPL; }
-    virtual HRESULT STDMETHODCALLTYPE webViewHeaderHeight(IWebView*, float*) { return E_NOTIMPL; }
-    virtual HRESULT STDMETHODCALLTYPE webViewFooterHeight(IWebView*, float*) { return E_NOTIMPL; }
-    virtual HRESULT STDMETHODCALLTYPE drawHeaderInRect(IWebView*, RECT*, OLE_HANDLE) { return E_NOTIMPL; }
-    virtual HRESULT STDMETHODCALLTYPE drawFooterInRect(IWebView*, RECT*, OLE_HANDLE, UINT, UINT) { return E_NOTIMPL; }
+    virtual HRESULT STDMETHODCALLTYPE webViewHeaderHeight(IWebView*, float*);
+    virtual HRESULT STDMETHODCALLTYPE webViewFooterHeight(IWebView*, float*);
+    virtual HRESULT STDMETHODCALLTYPE drawHeaderInRect(IWebView*, RECT*, OLE_HANDLE);
+    virtual HRESULT STDMETHODCALLTYPE drawFooterInRect(IWebView*, RECT*, OLE_HANDLE, UINT, UINT);
     virtual HRESULT STDMETHODCALLTYPE webViewPrintingMarginRect(IWebView*, RECT*);
     virtual HRESULT STDMETHODCALLTYPE canRunModal(IWebView*, BOOL*) { return E_NOTIMPL; }
     virtual HRESULT STDMETHODCALLTYPE createModalDialog(IWebView*, IWebURLRequest*, IWebView**) { return E_NOTIMPL; }
diff --git a/WebKitTools/WinLauncher/WinLauncher.cpp b/WebKitTools/WinLauncher/WinLauncher.cpp
index 04051ea..08b7ed9 100644
--- a/WebKitTools/WinLauncher/WinLauncher.cpp
+++ b/WebKitTools/WinLauncher/WinLauncher.cpp
@@ -355,7 +355,7 @@ void PrintView(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
 
     // FIXME: Need CoreGraphics implementation
     void* graphicsContext = 0;
-    for (size_t page = 0; page < pageCount; ++page) {
+    for (size_t page = 1; page <= pageCount; ++page) {
         ::StartPage(printDC);
         framePrivate->spoolPages(printDC, page, page, graphicsContext);
         ::EndPage(printDC);

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list