diff --git a/layout/generic/nsSimplePageSequence.cpp b/layout/generic/nsSimplePageSequence.cpp index 563040e1951..b37ec0d6241 100644 --- a/layout/generic/nsSimplePageSequence.cpp +++ b/layout/generic/nsSimplePageSequence.cpp @@ -38,6 +38,7 @@ #include "nsReadableUtils.h" #include "nsSimplePageSequence.h" #include "nsPresContext.h" +#include "gfxContext.h" #include "nsIRenderingContext.h" #include "nsGkAtoms.h" #include "nsIDeviceContext.h" @@ -619,6 +620,20 @@ nsSimplePageSequenceFrame::PrintNextPage() PresContext()->PresShell()-> CreateRenderingContext(mCurrentPageFrame, getter_AddRefs(renderingContext)); + +#if defined(XP_UNIX) && !defined(XP_MACOSX) + // On linux, need to rotate landscape-mode output on printed surfaces + PRInt32 orientation; + mPageData->mPrintSettings->GetOrientation(&orientation); + if (nsIPrintSettings::kLandscapeOrientation == orientation) { + // Shift up by one landscape-page-height (in points) before we rotate. + float offset = POINTS_PER_INCH_FLOAT * + (mCurrentPageFrame->GetSize().height / float(dc->AppUnitsPerInch())); + renderingContext->ThebesContext()->Translate(gfxPoint(offset, 0)); + renderingContext->ThebesContext()->Rotate(M_PI/2); + } +#endif // XP_UNIX && !XP_MACOSX + nsRect drawingRect(nsPoint(0, 0), mCurrentPageFrame->GetSize()); nsRegion drawingRegion(drawingRect); diff --git a/layout/printing/nsPrintEngine.cpp b/layout/printing/nsPrintEngine.cpp index 9778df34871..c91415541dc 100644 --- a/layout/printing/nsPrintEngine.cpp +++ b/layout/printing/nsPrintEngine.cpp @@ -1871,7 +1871,20 @@ nsPrintEngine::ReflowPrintObject(nsPrintObject * aPO) } else { nscoord pageWidth, pageHeight; mPrt->mPrintDC->GetDeviceSurfaceDimensions(pageWidth, pageHeight); +#if defined(XP_UNIX) && !defined(XP_MACOSX) + // If we're in landscape mode on Linux, the device surface will have + // been rotated, so for the purposes of reflowing content, we'll + // treat device's height as our width and its width as our height, + PRInt32 orientation; + mPrt->mPrintSettings->GetOrientation(&orientation); + if (nsIPrintSettings::kLandscapeOrientation == orientation) { + adjSize = nsSize(pageHeight, pageWidth); + } else { + adjSize = nsSize(pageWidth, pageHeight); + } +#else adjSize = nsSize(pageWidth, pageHeight); +#endif // XP_UNIX && !XP_MACOSX documentIsTopLevel = PR_TRUE; } diff --git a/widget/src/gtk2/nsDeviceContextSpecG.cpp b/widget/src/gtk2/nsDeviceContextSpecG.cpp index 1bd9fb03f47..a1cac582d5d 100644 --- a/widget/src/gtk2/nsDeviceContextSpecG.cpp +++ b/widget/src/gtk2/nsDeviceContextSpecG.cpp @@ -417,6 +417,17 @@ NS_IMETHODIMP nsDeviceContextSpecGTK::GetSurfaceForPrinter(gfxASurface **aSurfac double width, height; mPrintSettings->GetEffectivePageSize(&width, &height); + + // If we're in landscape mode, we'll be rotating the output -- + // need to swap width & height. + PRInt32 orientation; + mPrintSettings->GetOrientation(&orientation); + if (nsIPrintSettings::kLandscapeOrientation == orientation) { + double tmp = width; + width = height; + height = tmp; + } + // convert twips to points width /= TWIPS_PER_POINT_FLOAT; height /= TWIPS_PER_POINT_FLOAT;