Commit 3a7f5754 authored by bfulgham@webkit.org's avatar bfulgham@webkit.org

Properly handle margin settings in WinCairo.

https://bugs.webkit.org/show_bug.cgi?id=34545

Reviewed by Adam Roben.

* WebFrame.cpp:
(scaleFactor): Require the margin information as an input
  parameter, and use them when computing the scaling factor.
(WebFrame::drawHeader): Pass margin size to scaleFactor.
(WebFrame::drawFooter): Pass margin size to scaleFactor.
(WebFrame::spoolPage):
  1. Pass margin size to scaleFactor.
  2. Recognize that the return value of printerMarginRect is
     already in device units, and therefore scale it so that
     the Cairo drawing is correct.
  3. Remove scaling call for margins in GDI code, as it is
     already in scaled units.



git-svn-id: svn://svn.chromium.org/blink/trunk@54356 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 2bcb88af
2010-02-04 Brent Fulgham <bfulgham@webkit.org>
Reviewed by Adam Roben.
Properly handle margin settings in WinCairo.
https://bugs.webkit.org/show_bug.cgi?id=34545
* WebFrame.cpp:
(scaleFactor): Require the margin information as an input
parameter, and use them when computing the scaling factor.
(WebFrame::drawHeader): Pass margin size to scaleFactor.
(WebFrame::drawFooter): Pass margin size to scaleFactor.
(WebFrame::spoolPage):
1. Pass margin size to scaleFactor.
2. Recognize that the return value of printerMarginRect is
already in device units, and therefore scale it so that
the Cairo drawing is correct.
3. Remove scaling call for margins in GDI code, as it is
already in scaled units.
2010-02-03 Brian Weinstein <bweinstein@apple.com> 2010-02-03 Brian Weinstein <bweinstein@apple.com>
Reviewed by Steve Falkenburg. Reviewed by Steve Falkenburg.
......
...@@ -2018,11 +2018,17 @@ void WebFrame::spoolPage(PlatformGraphicsContext* pctx, GraphicsContext* spoolCt ...@@ -2018,11 +2018,17 @@ void WebFrame::spoolPage(PlatformGraphicsContext* pctx, GraphicsContext* spoolCt
CGContextRestoreGState(pctx); CGContextRestoreGState(pctx);
} }
#elif PLATFORM(CAIRO) #elif PLATFORM(CAIRO)
static float scaleFactor(HDC printDC, const IntRect& pageRect) static float scaleFactor(HDC printDC, const IntRect& marginRect, const IntRect& pageRect)
{ {
const IntRect& printRect = printerRect(printDC); const IntRect& printRect = printerRect(printDC);
float scale = static_cast<float>(printRect.width()) / static_cast<float>(pageRect.width()); IntRect adjustedRect = IntRect(
printRect.x() + marginRect.x(),
printRect.y() + marginRect.y(),
printRect.width() - marginRect.x() - marginRect.right(),
printRect.height() - marginRect.y() - marginRect.bottom());
float scale = static_cast<float>(adjustedRect.width()) / static_cast<float>(pageRect.width());
if (!scale) if (!scale)
scale = 1.0; scale = 1.0;
...@@ -2038,8 +2044,9 @@ static HDC hdcFromContext(PlatformGraphicsContext* pctx) ...@@ -2038,8 +2044,9 @@ static HDC hdcFromContext(PlatformGraphicsContext* pctx)
void WebFrame::drawHeader(PlatformGraphicsContext* pctx, IWebUIDelegate* ui, const IntRect& pageRect, float headerHeight) void WebFrame::drawHeader(PlatformGraphicsContext* pctx, IWebUIDelegate* ui, const IntRect& pageRect, float headerHeight)
{ {
HDC hdc = hdcFromContext(pctx); HDC hdc = hdcFromContext(pctx);
const IntRect& marginRect = printerMarginRect(hdc);
const float scale = scaleFactor(hdc, pageRect); const float scale = scaleFactor(hdc, marginRect, pageRect);
int x = static_cast<int>(scale * pageRect.x()); int x = static_cast<int>(scale * pageRect.x());
int y = 0; int y = 0;
RECT headerRect = {x, y, x + static_cast<int>(scale * pageRect.width()), y + static_cast<int>(scale * headerHeight)}; RECT headerRect = {x, y, x + static_cast<int>(scale * pageRect.width()), y + static_cast<int>(scale * headerHeight)};
...@@ -2050,8 +2057,9 @@ void WebFrame::drawHeader(PlatformGraphicsContext* pctx, IWebUIDelegate* ui, con ...@@ -2050,8 +2057,9 @@ void WebFrame::drawHeader(PlatformGraphicsContext* pctx, IWebUIDelegate* ui, con
void WebFrame::drawFooter(PlatformGraphicsContext* pctx, IWebUIDelegate* ui, const IntRect& pageRect, UINT page, UINT pageCount, float headerHeight, float footerHeight) void WebFrame::drawFooter(PlatformGraphicsContext* pctx, IWebUIDelegate* ui, const IntRect& pageRect, UINT page, UINT pageCount, float headerHeight, float footerHeight)
{ {
HDC hdc = hdcFromContext(pctx); HDC hdc = hdcFromContext(pctx);
const IntRect& marginRect = printerMarginRect(hdc);
const float scale = scaleFactor(hdc, pageRect); const float scale = scaleFactor(hdc, marginRect, pageRect);
int x = static_cast<int>(scale * pageRect.x()); 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))); 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)}; RECT footerRect = {x, y, x + static_cast<int>(scale * pageRect.width()), y + static_cast<int>(scale * footerHeight)};
...@@ -2064,24 +2072,27 @@ void WebFrame::spoolPage(PlatformGraphicsContext* pctx, GraphicsContext* spoolCt ...@@ -2064,24 +2072,27 @@ void WebFrame::spoolPage(PlatformGraphicsContext* pctx, GraphicsContext* spoolCt
Frame* coreFrame = core(this); Frame* coreFrame = core(this);
const IntRect& pageRect = m_pageRects[page]; const IntRect& pageRect = m_pageRects[page];
IntRect marginRect = printerMarginRect(printDC); const IntRect& marginRect = printerMarginRect(printDC);
cairo_save(pctx); cairo_save(pctx);
float scale = scaleFactor(printDC, pageRect); float scale = scaleFactor(printDC, marginRect, pageRect);
cairo_scale(pctx, scale, scale); cairo_scale(pctx, scale, scale);
cairo_translate(pctx, -pageRect.x() + marginRect.x(), -pageRect.y() + marginRect.y() + headerHeight); IntRect cairoMarginRect (marginRect);
cairoMarginRect.scale (1 / scale);
cairo_translate(pctx, -pageRect.x() + cairoMarginRect.x(), -pageRect.y() + cairoMarginRect.y() + headerHeight);
coreFrame->view()->paintContents(spoolCtx, pageRect); coreFrame->view()->paintContents(spoolCtx, pageRect);
cairo_translate(pctx, pageRect.x() - marginRect.x(), pageRect.y() - marginRect.y() - headerHeight); cairo_translate(pctx, pageRect.x() - cairoMarginRect.x(), pageRect.y() - cairoMarginRect.y() - headerHeight);
XFORM originalWorld; XFORM originalWorld;
::GetWorldTransform(printDC, &originalWorld); ::GetWorldTransform(printDC, &originalWorld);
// Position world transform to account for margin // Position world transform to account for margin
XFORM newWorld = originalWorld; XFORM newWorld = originalWorld;
newWorld.eDx = scale * marginRect.x(); newWorld.eDx = marginRect.x();
newWorld.eDy = scale * marginRect.y(); newWorld.eDy = marginRect.y();
::SetWorldTransform(printDC, &newWorld); ::SetWorldTransform(printDC, &newWorld);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment