Bug 1315121 - OS X Remote printing (print_via_parent) scaled prints don't fill page; r=mconley

Send the size from PMGetAdjustedPaperRect to the child to use as the page size.
Add an Mac implementation of GetEffectivePageSize that returns the adjusted dimensions.
Add an Mac implementation of SetPaperWidth and SetPaperHeight so that adjusted dimensions can be manually set for reftest-print.

MozReview-Commit-ID: GgTFgBzkxTy

--HG--
extra : rebase_source : 66d5b2f8216ebd28401aec9bbb78c5ad32dd666c
This commit is contained in:
Haik Aftandilian 2016-11-17 15:29:08 -08:00
parent 03916132bb
commit 9caed1b4c8
5 changed files with 95 additions and 2 deletions

View File

@ -118,6 +118,8 @@ struct PrintData {
*/
float widthScale;
float heightScale;
double adjustedPaperWidth;
double adjustedPaperHeight;
};
} // namespace embedding

View File

@ -145,7 +145,18 @@ nsPrintDialogServiceX::Show(nsPIDOMWindowOuter *aParent, nsIPrintSettings *aSett
[dict setObject: [NSNumber numberWithFloat: 1]
forKey: NSPrintScalingFactor];
}
// Set the scaling factor to 100% in the NSPrintInfo
// object so that it will not affect the paper size
// retrieved from the PMPageFormat routines.
[copy setScalingFactor:1.0];
} else {
aSettings->SetScaling([copy scalingFactor]);
}
// Set the adjusted paper size now that we've updated
// the scaling factor.
settingsX->InitAdjustedPaperSize();
[copy release];
int16_t pageRange;

View File

@ -71,6 +71,11 @@ nsPrintOptionsX::SerializeToPrintData(nsIPrintSettings* aSettings,
return NS_ERROR_FAILURE;
}
double adjustedWidth, adjustedHeight;
settingsX->GetAdjustedPaperSize(&adjustedWidth, &adjustedHeight);
data->adjustedPaperWidth() = adjustedWidth;
data->adjustedPaperHeight() = adjustedHeight;
NSDictionary* dict = [printInfo dictionary];
if (NS_WARN_IF(!dict)) {
return NS_ERROR_FAILURE;
@ -285,6 +290,9 @@ nsPrintOptionsX::DeserializeToPrintSettings(const PrintData& data,
settingsX->SetCocoaPrintInfo(newPrintInfo);
[newPrintInfo release];
settingsX->SetAdjustedPaperSize(data.adjustedPaperWidth(),
data.adjustedPaperHeight());
return NS_OK;
}

View File

@ -25,6 +25,15 @@ public:
void SetCocoaPrintInfo(NSPrintInfo* aPrintInfo);
virtual nsresult ReadPageFormatFromPrefs();
virtual nsresult WritePageFormatToPrefs();
virtual nsresult GetEffectivePageSize(double *aWidth,
double *aHeight) override;
// In addition to setting the paper width and height, these
// overrides set the adjusted width and height returned from
// GetEffectivePageSize. This is needed when a paper size is
// set manually without using a print dialog a la reftest-print.
virtual nsresult SetPaperWidth(double aPaperWidth) override;
virtual nsresult SetPaperHeight(double aPaperWidth) override;
PMPrintSettings GetPMPrintSettings();
PMPrintSession GetPMPrintSession();
@ -35,9 +44,16 @@ public:
// Should be called whenever mPageFormat is initialized or overwritten.
nsresult InitUnwriteableMargin();
// Re-initialize mAdjustedPaper{Width,Height} with values from mPageFormat.
// Should be called whenever mPageFormat is initialized or overwritten.
nsresult InitAdjustedPaperSize();
void SetInchesScale(float aWidthScale, float aHeightScale);
void GetInchesScale(float *aWidthScale, float *aHeightScale);
void SetAdjustedPaperSize(double aWidth, double aHeight);
void GetAdjustedPaperSize(double *aWidth, double *aHeight);
protected:
virtual ~nsPrintSettingsX();
@ -57,6 +73,8 @@ protected:
// paper size units to inches
float mWidthScale;
float mHeightScale;
double mAdjustedPaperWidth;
double mAdjustedPaperHeight;
};
NS_DEFINE_STATIC_IID_ACCESSOR(nsPrintSettingsX, NS_PRINTSETTINGSX_IID)

View File

@ -68,6 +68,7 @@ nsresult nsPrintSettingsX::Init()
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
InitUnwriteableMargin();
InitAdjustedPaperSize();
return NS_OK;
@ -94,6 +95,23 @@ NS_IMETHODIMP nsPrintSettingsX::InitUnwriteableMargin()
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
}
NS_IMETHODIMP nsPrintSettingsX::InitAdjustedPaperSize()
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
PMPageFormat pageFormat = GetPMPageFormat();
PMRect paperRect;
::PMGetAdjustedPaperRect(pageFormat, &paperRect);
mAdjustedPaperWidth = paperRect.right - paperRect.left;
mAdjustedPaperHeight = paperRect.bottom - paperRect.top;
return NS_OK;
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
}
void
nsPrintSettingsX::SetCocoaPrintInfo(NSPrintInfo* aPrintInfo)
{
@ -206,8 +224,10 @@ nsPrintSettingsX::SetPMPageFormat(PMPageFormat aPageFormat)
void
nsPrintSettingsX::SetInchesScale(float aWidthScale, float aHeightScale)
{
mWidthScale = aWidthScale;
mHeightScale = aHeightScale;
if (aWidthScale > 0 && aHeightScale > 0) {
mWidthScale = aWidthScale;
mHeightScale = aHeightScale;
}
}
void
@ -216,3 +236,37 @@ nsPrintSettingsX::GetInchesScale(float *aWidthScale, float *aHeightScale)
*aWidthScale = mWidthScale;
*aHeightScale = mHeightScale;
}
NS_IMETHODIMP nsPrintSettingsX::SetPaperWidth(double aPaperWidth)
{
mPaperWidth = aPaperWidth;
mAdjustedPaperWidth = aPaperWidth * mWidthScale;
return NS_OK;
}
NS_IMETHODIMP nsPrintSettingsX::SetPaperHeight(double aPaperHeight)
{
mPaperHeight = aPaperHeight;
mAdjustedPaperHeight = aPaperHeight * mHeightScale;
return NS_OK;
}
NS_IMETHODIMP
nsPrintSettingsX::GetEffectivePageSize(double *aWidth, double *aHeight)
{
*aWidth = NS_INCHES_TO_TWIPS(mAdjustedPaperWidth / mWidthScale);
*aHeight = NS_INCHES_TO_TWIPS(mAdjustedPaperHeight / mHeightScale);
return NS_OK;
}
void nsPrintSettingsX::SetAdjustedPaperSize(double aWidth, double aHeight)
{
mAdjustedPaperWidth = aWidth;
mAdjustedPaperHeight = aHeight;
}
void nsPrintSettingsX::GetAdjustedPaperSize(double *aWidth, double *aHeight)
{
*aWidth = mAdjustedPaperWidth;
*aHeight = mAdjustedPaperHeight;
}