📄 pagescale.cpp
字号:
/*++
Copyright (c) 2005 Microsoft Corporation
All rights reserved.
THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
PARTICULAR PURPOSE.
File Name:
pagescale.cpp
Abstract:
Page Scaling class implementation. The Page Scaling class provides
functionality required to perform page Scaling. This includes methods for converting a GDI matrix object
into the appropriate XPS matrix mark-up and intialising the matrix according to
the Page Scaling options.
--*/
#include "precomp.h"
#include "debug.h"
#include "globals.h"
#include "xdstring.h"
#include "pagescale.h"
using XDPrintSchema::PageScaling::EScaleOption;
using XDPrintSchema::PageScaling::Custom;
using XDPrintSchema::PageScaling::CustomSquare;
using XDPrintSchema::PageScaling::FitBleedToImageable;
using XDPrintSchema::PageScaling::FitContentToImageable;
using XDPrintSchema::PageScaling::FitMediaToImageable;
using XDPrintSchema::PageScaling::FitMediaToMedia;
using XDPrintSchema::PageScaling::OffsetAlignment::EScaleOffsetOption;
using XDPrintSchema::PageScaling::OffsetAlignment::BottomCenter;
using XDPrintSchema::PageScaling::OffsetAlignment::BottomLeft;
using XDPrintSchema::PageScaling::OffsetAlignment::BottomRight;
using XDPrintSchema::PageScaling::OffsetAlignment::Center;
using XDPrintSchema::PageScaling::OffsetAlignment::LeftCenter;
using XDPrintSchema::PageScaling::OffsetAlignment::RightCenter;
using XDPrintSchema::PageScaling::OffsetAlignment::TopCenter;
using XDPrintSchema::PageScaling::OffsetAlignment::TopLeft;
using XDPrintSchema::PageScaling::OffsetAlignment::TopRight;
/*++
Routine Name:
CPageScaling::CPageScaling
Routine Description:
CPageScaling class constructor
Arguments:
pgscProps - Reference to the page scaling PrintTicket properties.
Return Value:
None
--*/
CPageScaling::CPageScaling(
__in CONST CPGSCPTProperties& pgscProps
) :
m_pageDimensions(0.0f, 0.0f),
m_PGSCProps(pgscProps),
m_bAddCanvas(FALSE),
m_contentBox(0.0f, 0.0f, 0.0f, 0.0f),
m_bleedBox(0.0f, 0.0f, 0.0f, 0.0f)
{
}
/*++
Routine Name:
CPageScaling::~CPageScaling
Routine Description:
CPageScaling class destructor
Arguments:
None
Return Value:
None
--*/
CPageScaling::~CPageScaling()
{
}
/*++
Routine Name:
CPageScaling::GetFixedPageWidth
Routine Description:
Creates a string containing the page width in 1/96 Inch
(Not applicable to Custom Scaling options).
Arguments:
pbstrWidth - Address of a pointer that will be modified to point to a string
that is filled out with the fixed page width.
Return Value:
HRESULT
S_OK - On success
E_* - On error
--*/
HRESULT
CPageScaling::GetFixedPageWidth(
__deref_out BSTR* pbstrWidth
)
{
HRESULT hr = S_OK;
if (SUCCEEDED(hr = CHECK_POINTER(pbstrWidth, E_POINTER)))
{
try
{
SizeF targetPage;
if (SUCCEEDED(hr = m_PGSCProps.GetPageSize(&targetPage)))
{
CStringXDW cstrValue;
cstrValue.Format(L"%.2f", targetPage.Width);
*pbstrWidth = cstrValue.AllocSysString();
}
}
catch (CXDException& e)
{
hr = e;
}
}
ERR_ON_HR(hr);
return hr;
}
/*++
Routine Name:
CPageScaling::GetFixedPageHeight
Routine Description:
Creates a string containing the page height in 1/96 Inch
(Not applicable to Custom Scaling options).
Arguments:
pbstrHeight - Address of a pointer that will be modified to point to a string
that is filled out with the fixed page height.
Return Value:
HRESULT
S_OK - On success
E_* - On error
--*/
HRESULT
CPageScaling::GetFixedPageHeight(
__deref_out BSTR* pbstrHeight
)
{
HRESULT hr = S_OK;
if (SUCCEEDED(hr = CHECK_POINTER(pbstrHeight, E_POINTER)))
{
try
{
SizeF targetPage;
if (SUCCEEDED(hr = m_PGSCProps.GetPageSize(&targetPage)))
{
CStringXDW cstrValue;
cstrValue.Format(L"%.2f", targetPage.Height);
*pbstrHeight = cstrValue.AllocSysString();
}
}
catch (CXDException& e)
{
hr = e;
}
}
ERR_ON_HR(hr);
return hr;
}
/*++
Routine Name:
CPageScaling::MatrixToXML
Routine Description:
Creates a string representation of a Matrix class object.
The string is suitable for use in XPS markup with the 'RenderTransform' keyword.
Arguments:
pMatrix - Pointer to a Matrix class object.
pbstrMatrixXForm - Address of a pointer that will be modified to point to a string
that is filled out with the matrix.
Return Value:
HRESULT
S_OK - On success
E_* - On error
--*/
HRESULT
CPageScaling::MatrixToXML(
__in CONST Matrix* pMatrix,
__deref_out BSTR* pbstrMatrixXForm
)
{
//
// Construct the matric mark-up from a GDI+ matrix
//
HRESULT hr = S_OK;
if (SUCCEEDED(hr = CHECK_POINTER(pbstrMatrixXForm, E_POINTER)) &&
SUCCEEDED(hr = CHECK_POINTER(pMatrix, E_POINTER)))
{
REAL matElems[6];
if (Ok == pMatrix->GetElements(matElems))
{
try
{
CStringXDW cstrMatrix;
cstrMatrix.Format(L"%.2f,%.2f,%.2f,%.2f,%.2f,%.2f",
matElems[0],
matElems[1],
matElems[2],
matElems[3],
matElems[4],
matElems[5]);
*pbstrMatrixXForm = cstrMatrix.AllocSysString();
}
catch (CXDException& e)
{
hr = e;
}
}
else
{
*pbstrMatrixXForm = NULL;
hr = E_FAIL;
}
}
ERR_ON_HR(hr);
return hr;
}
/*++
Routine Name:
CPageScaling::SetPageDimensions
Routine Description:
Used to set the XPS page width and height in the page scaling interface.
Arguments:
width - Width of the XPS fixed page in 1/96 Inch.
height - Height of the XPS fixed page in 1/96 Inch.
Return Value:
HRESULT
S_OK - On success
E_* - On error
--*/
HRESULT
CPageScaling::SetPageDimensions(
__in CONST REAL width,
__in CONST REAL height
)
{
m_pageDimensions.Width = width;
m_pageDimensions.Height = height;
return S_OK;
}
/*++
Routine Name:
CPageScaling::SetBleedBox
Routine Description:
Used to set the XPS BleedBox in the page scaling interface.
Arguments:
pBleedBox - pointer to a rectangle defining the BleedBox of the XPS page in 1/96 Inch.
Return Value:
HRESULT
S_OK - On success
E_* - On error
--*/
HRESULT
CPageScaling::SetBleedBox(
__in RectF* pBleedBox
)
{
HRESULT hr = S_OK;
if (SUCCEEDED(hr = CHECK_POINTER(pBleedBox, E_POINTER)))
{
m_bleedBox = *pBleedBox;
}
ERR_ON_HR(hr);
return hr;
}
/*++
Routine Name:
CPageScaling::SetContentBox
Routine Description:
Used to set the XPS ContentBox in the page scaling interface.
Arguments:
pContentBox - pointer to a rectangle defining the ContentBox of the XPS page in 1/96 Inch.
Return Value:
HRESULT
S_OK - On success
E_* - On error
--*/
HRESULT
CPageScaling::SetContentBox(
__in RectF* pContentBox
)
{
HRESULT hr = S_OK;
if (SUCCEEDED(hr = CHECK_POINTER(pContentBox, E_POINTER)))
{
m_contentBox = *pContentBox;
}
ERR_ON_HR(hr);
return hr;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -