Beispiel #1
0
/*++

Routine Name:

    CRemoteDictionary::GetResURI

Routine Description:

    Method to obtain the URI of the resource being handled

Arguments:

    pbstrResURI - Pointer to a string to hold the resource URI

Return Value:

    HRESULT
    S_OK - On success
    E_*  - On error

--*/
HRESULT
CRemoteDictionary::GetResURI(
    _Outptr_ BSTR* pbstrResURI
    )
{
    HRESULT hr = S_OK;

    if (SUCCEEDED(hr = CHECK_POINTER(pbstrResURI, E_POINTER)))
    {
        *pbstrResURI = NULL;

        try
        {
            //
            // Create a unique name for the dictionary for this print session
            //
            CStringXDW cstrURI;
            cstrURI.Format(L"%s_%u.dict", m_bstrDictionaryURI, GetUniqueNumber());

            *pbstrResURI = cstrURI.AllocSysString();
        }
        catch (CXDException& e)
        {
            hr = e;
        }
    }

    ERR_ON_HR(hr);
    return hr;
}
/*++

Routine Name:

    CColorManagedImage::GetResURI

Routine Description:

    Method to obtain the URI of the resource being handled

Arguments:

    pbstrResURI - Pointer to a string to hold the resource URI

Return Value:

    HRESULT
    S_OK - On success
    E_*  - On error

--*/
HRESULT
CColorManagedImage::GetResURI(
    _Outptr_ BSTR* pbstrResURI
    )
{
    HRESULT hr = S_OK;

    if (SUCCEEDED(hr = CHECK_POINTER(pbstrResURI, E_POINTER)))
    {
        *pbstrResURI = NULL;

        if (m_bstrBitmapURI.Length() > 0)
        {
            try
            {
                //
                // Create a URI from the original bitmap URI and the current tick count
                //
                CStringXDW cstrFileName(m_bstrBitmapURI);
                CStringXDW cstrFileExt(PathFindExtension(cstrFileName));

                INT indFileExt = cstrFileName.Find(cstrFileExt);

                if (indFileExt > -1)
                {
                    cstrFileName.Delete(indFileExt, cstrFileExt.GetLength());
                }

                //
                // Create a unique name for the bitmap for this print session
                //
                CStringXDW cstrURI;
                cstrURI.Format(L"%s_%u.wdp", cstrFileName, GetUniqueNumber());

                SysFreeString(*pbstrResURI);
                *pbstrResURI = cstrURI.AllocSysString();
            }
            catch (CXDException& e)
            {
                hr = e;
            }
        }
        else
        {
            hr = E_PENDING;
        }
    }

    ERR_ON_HR(hr);
    return hr;
}
Beispiel #3
0
/*++

Routine Name:

    CNUpTransform::MatrixToXML

Routine Description:

    Method to create xml markup representing a transformation matrix

Arguments:

    pMatrix          - Pointer to a transformation matrix to convert to markup
    pbstrMatrixXForm - Pointer to a string to contain the matrix markup

Return Value:

    HRESULT
    S_OK - On success
    E_*  - On error

--*/
HRESULT
CNUpTransform::MatrixToXML(
    _In_        CONST Matrix* pMatrix,
    _Outptr_ 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)))
    {
        *pbstrMatrixXForm = NULL;
        REAL matElems[6];

        if (Ok == pMatrix->GetElements(matElems))
        {
            CStringXDW cstrMatrix;

            try
            {
                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:

    CPSHandler::CreateScoredProperty

Routine Description:

    This routine creates a scored property of type REAL.

Arguments:

    bstrPropName        - The name of the property element to be created
    realValue           - The REAL value to be set
    ppScoredPropElement - Pointer to an IXMLDOMElement that recieves the new element

Return Value:

    HRESULT
    S_OK - On success
    E_*  - On error

--*/
HRESULT
CPSHandler::CreateScoredProperty(
    _In_        CONST BSTR       bstrPropName,
    _In_        CONST REAL       realValue,
    _Outptr_ IXMLDOMElement** ppScoredPropElement
    )
{
    HRESULT hr = S_OK;

    if (SUCCEEDED(hr = CHECK_POINTER(ppScoredPropElement, E_POINTER)))
    {
        if (SysStringLen(bstrPropName) <= 0)
        {
            hr = E_INVALIDARG;
        }
    }

    if (SUCCEEDED(hr))
    {
        try
        {
            //
            // Construct the value string
            //
            CStringXDW cstrValue;
            cstrValue.Format(L"%.2f", realValue);

            //
            // Create the scored property and value node
            //
            hr = CreateScoredProperty(bstrPropName,
                                      CComBSTR(SCHEMA_DECIMAL),
                                      CComBSTR(cstrValue.AllocSysString()),
                                      ppScoredPropElement);
        }
        catch (CXDException& e)
        {
            hr = e;
        }
    }

    ERR_ON_HR(hr);
    return hr;
}
/*++

Routine Name:

    CPTHandler::CreateParamRefInitPair

Routine Description:

    This routine create a pair of DOM elements corresponding to the ParameterRef and
    the ParameterInit that describe a ScoredProperty value. This overload is INT specific

Arguments:

    bstrParam   - The name of the property
    intValue    - The integer value of the scored property
    ppParamRef  - Pointer to a IXMLDOMElement pointer that recives the new ParameterRef
    ppParamInit - Pointer to a IXMLDOMElement pointer that recives the new ParameterInit

Return Value:

    HRESULT
    S_OK - On success
    E_*  - On error

--*/
HRESULT
CPTHandler::CreateParamRefInitPair(
    _In_        CONST BSTR       bstrParam,
    _In_        CONST INT        intValue,
    _Outptr_ IXMLDOMElement** ppParamRef,
    _Outptr_ IXMLDOMElement** ppParamInit
    )
{
    HRESULT hr = S_OK;

    if (SUCCEEDED(hr = CHECK_POINTER(ppParamRef, E_POINTER)) &&
        SUCCEEDED(hr = CHECK_POINTER(ppParamInit, E_POINTER)))
    {
        if (SysStringLen(bstrParam) <= 0)
        {
            hr = E_INVALIDARG;
        }
    }

    if (SUCCEEDED(hr))
    {
        try
        {
            CStringXDW cstrValue;
            cstrValue.Format(L"%i", intValue);

            hr = CreateParamRefInitPair(bstrParam,
                                        CComBSTR(SCHEMA_INTEGER),
                                        CComBSTR(cstrValue.AllocSysString()),
                                        ppParamRef,
                                        ppParamInit);
        }
        catch (CXDException& e)
        {
            hr = e;
        }
    }

    ERR_ON_HR(hr);
    return hr;
}
/*++

Routine Name:

    CPSHandler::CPSHandler

Routine Description:

    CPSHandler class constructor

Arguments:

    pDOMDocument - Pointer to the DOM document representation of the PrintTicket/PrintCapabilities

Return Value:

    None
    Throws CXDException(HRESULT) on an error

--*/
CPSHandler::CPSHandler(
    _In_z_ BSTR bstrDocumentType,
    _In_ IXMLDOMDocument2 *pPrintDocument
    ) :
    m_bstrDocumentType(bstrDocumentType),
    m_pPrintDocument(pPrintDocument)
{
    ASSERTMSG(m_pPrintDocument != NULL, "NULL PrintDocument passed to PS manager.\n");

    HRESULT hr = S_OK;

    if (SUCCEEDED(hr = CHECK_POINTER(m_pPrintDocument, E_PENDING)))
    {
        try
        {
            //
            // Make sure XPath selection language is set
            //
            if (SUCCEEDED(hr = m_pPrintDocument->setProperty(CComBSTR(szSelectLang), CComVariant(szLangSection))))
            {
                //
                // Construct the alias namespace string
                //
                CStringXDW cstrNamespaces;
                cstrNamespaces.Format(szNSSelection, szTmpNS, FRAMEWORK_URI);

                //
                // Specify an alias PrintSchema namespace prefix to allow us to find the real ones
                //
                if (SUCCEEDED(hr = m_pPrintDocument->setProperty(CComBSTR(szSelectNS), CComVariant(cstrNamespaces))))
                {
                    if (SUCCEEDED(hr = GetPrefixFromURI(CComBSTR(FRAMEWORK_URI), &m_bstrFrameworkPrefix)) &&
                        SUCCEEDED(hr = GetPrefixFromURI(CComBSTR(KEYWORDS_URI), &m_bstrKeywordsPrefix)) &&
                        SUCCEEDED(hr = GetPrefixFromURI(CComBSTR(SCHEMA_INST_URI), &m_bstrSchemaInstPrefix)) &&
                        SUCCEEDED(hr = GetPrefixFromURI(CComBSTR(SCHEMA_DEF_URI), &m_bstrSchemaPrefix)))
                    {
                        CStringXDW cstrNSUserPrefix(L"ns0000:");
                        m_bstrUserKeywordsPrefix.Empty();
                        m_bstrUserKeywordsPrefix.Attach(cstrNSUserPrefix.AllocSysString());

                        //
                        // Restore the original namespace prefix for the PrintSchema framework
                        //
                        CComBSTR bstrOrgNamespaces;
                        CStringXDW cstrNSPrefix(m_bstrFrameworkPrefix);

                        INT iIndex = cstrNSPrefix.Find(L":");
                        if (iIndex != -1 &&
                            cstrNSPrefix.Delete(iIndex, 1) > 0)
                        {
                            CStringXDW cstrOrgNamespaces;
                            cstrOrgNamespaces.Format(szNSSelection, static_cast<LPCWSTR>(cstrNSPrefix), FRAMEWORK_URI);

                            hr = m_pPrintDocument->setProperty(CComBSTR(szSelectNS), CComVariant(cstrOrgNamespaces));
                        }
                        else
                        {
                             RIP("Could not create namespace prefix correctly\n");
                             hr = E_FAIL;
                        }
                    }
                }
                else
                {
                    ERR("Failed to set SelectionNamespaces.\n");
                }
            }
            else
            {
                RIP("Failed to set SelectionLanguage.\n");
            }
        }
        catch (CXDException& e)
        {
            hr = e;
        }
    }

    if (FAILED(hr))
    {
        throw CXDException(hr);
    }
}
/*++

Routine Name:

    CBookletFilter::CreatePadPage

Routine Description:

    Method to create a pad page which is required for odd page counts to
    ensure pages are correctly ordered for presentation as a booklet

Arguments:

    ppNewPage - Pointer to a pointer to the newly created fixed page

Return Value:

    HRESULT
    S_OK - On success
    E_*  - On error

--*/
HRESULT
CBookletFilter::CreatePadPage(
    _Outptr_ IFixedPage** ppNewPage
    )
{
    HRESULT hr = S_OK;

    //
    // Validate parameters and members before proceeding
    //
    if (SUCCEEDED(hr = CHECK_POINTER(ppNewPage, E_POINTER)) &&
        SUCCEEDED(hr = CHECK_POINTER(m_pXDWriter, E_PENDING)))
    {
        *ppNewPage = NULL;
        PCWSTR pszPageName = NULL;

        try
        {
            //
            // Create a unique name for the pad page for this print session
            //
            CStringXDW szNewPageName;
            szNewPageName.Format(L"/Pad_page_%u.xaml", GetUniqueNumber());
            pszPageName = szNewPageName.GetBuffer();

            //
            // Create a new empty page and retrieve a writer. Also get a
            // reader from the first page so we can copy the FixedPage root
            // element. This ensures the page sizes match.
            //
            CComPtr<IPrintWriteStream>  pWriter(NULL);
            CComPtr<ISAXXMLReader>      pSaxRdr(NULL);

            if (SUCCEEDED(hr) &&
                SUCCEEDED(hr = m_pXDWriter->GetNewEmptyPart(pszPageName,
                                                            IID_IFixedPage,
                                                            reinterpret_cast<PVOID*>(ppNewPage),
                                                            &pWriter)) &&
                SUCCEEDED(hr = pSaxRdr.CoCreateInstance(CLSID_SAXXMLReader60)))
            {
                //
                // We use a simple SAX handler which copies only the root
                // element and discards all other content.
                //
                CBkSaxHandler bkSaxHndlr(pWriter);
                CComPtr<IPrintReadStream> pReader(NULL);

                IFixedPage* pFP = NULL;

                pFP = m_cacheFP[0];

                if (SUCCEEDED(hr) &&
                    SUCCEEDED(hr = pSaxRdr->putContentHandler(&bkSaxHndlr)) &&
                    SUCCEEDED(hr = pFP->GetStream(&pReader)))
                {
                    CComPtr<ISequentialStream> pReadStreamToSeq(NULL);

                    pReadStreamToSeq.Attach(new(std::nothrow) pfp::PrintReadStreamToSeqStream(pReader));

                    if (SUCCEEDED(hr = CHECK_POINTER(pReadStreamToSeq, E_OUTOFMEMORY)))
                    {
                        hr = pSaxRdr->parse(CComVariant(static_cast<ISequentialStream*>(pReadStreamToSeq)));
                    }
                }

                pWriter->Close();
            }
        }
        catch (CXDException& e)
        {
            hr = e;
        }
    }

    ERR_ON_HR(hr);
    return hr;
}
Beispiel #8
0
/*++

Routine Name:

    CRasterWatermark::CreateXMLElement

Routine Description:

    Method to create the XML markup which describes the transform and properties used
    to present the watermark correctly on the page

Arguments:

    None

Return Value:

    HRESULT
    S_OK - On success
    E_*  - On error

--*/
HRESULT
CRasterWatermark::CreateXMLElement(
    VOID
    )
{
    ASSERTMSG(m_pDOMDoc != NULL, "NULL DOM document detected whilst creating text watermark\n");
    ASSERTMSG(m_bstrImageURI.Length() > 0, "Invalid image URI detected whilst creating text watermark\n");

    HRESULT hr = S_OK;

    if (SUCCEEDED(hr = CHECK_POINTER(m_pDOMDoc, E_PENDING)))
    {
        if (m_bstrImageURI.Length() == 0)
        {
            hr = E_PENDING;
        }
    }

    //
    // We need to retrieve the bitmap bounds to calculate
    // the correct render transform for the watermark
    //
    SizeF bmpDims;
    CComBSTR bstrWMOpacity;
    if (SUCCEEDED(hr) &&
        SUCCEEDED(hr = m_wmBMP.GetImageDimensions(&bmpDims)) &&
        SUCCEEDED(hr = m_WMProps.GetOpacity(&bstrWMOpacity)))
    {
        //
        // The markup will look like this (square bracketed values "[]"
        // describes content):
        //
        // <Path
        //     RenderTransform="[appropriate to scale, translate and rotate to the PT settings]"
        //     Data="M [corner coords of image] z">
        //     <Path.Fill>
        //         <ImageBrush
        //             ImageSource="[image URI from cache]"
        //             Opacity="[opacity value from PT]"
        //             ViewboxUnits="Absolute"
        //             Viewbox="[image bounds]"
        //             ViewportUnits="Absolute"
        //             Viewport="[image bounds]" />
        //     </Path.Fill>
        // </Path>
        //
        CComPtr<IXMLDOMElement> pPathFill(NULL);
        CComPtr<IXMLDOMElement> pImageBrush(NULL);
        CComPtr<IXMLDOMNode>    pInsertNode(NULL);

        CStringXDW strPathData;
        CStringXDW strViewbox;
        CStringXDW strViewport;

        CComBSTR bstrMatrixXForm;

        //
        // Create the transform and elements and add attributes
        //
        try
        {
            strPathData.Format(L"M 0,0 L 0,%.2f %.2f,%.2f %.2f,0 z", bmpDims.Height, bmpDims.Width, bmpDims.Height, bmpDims.Width);
            strViewbox.Format(L"0,0,%.2f,%.2f", bmpDims.Width, bmpDims.Height);
            strViewport.Format(L"0,0,%.2f,%.2f", bmpDims.Width, bmpDims.Height);

            if (SUCCEEDED(hr = CreateWMTransform(RectF(0, 0, bmpDims.Width, bmpDims.Height), &bstrMatrixXForm)) &&
                SUCCEEDED(hr = m_pDOMDoc->createElement(CComBSTR(L"Path"), &m_pWMElem)) &&
                SUCCEEDED(hr = m_pDOMDoc->createElement(CComBSTR(L"Path.Fill"), &pPathFill)) &&
                SUCCEEDED(hr = m_pDOMDoc->createElement(CComBSTR(L"ImageBrush"), &pImageBrush)) &&
                SUCCEEDED(hr = m_pWMElem->setAttribute(CComBSTR(L"RenderTransform"), CComVariant(bstrMatrixXForm))) &&
                SUCCEEDED(hr = m_pWMElem->setAttribute(CComBSTR(L"Data"), CComVariant(strPathData.GetBuffer()))) &&
                SUCCEEDED(hr = pImageBrush->setAttribute(CComBSTR(L"ImageSource"), CComVariant(m_bstrImageURI))) &&
                SUCCEEDED(hr = pImageBrush->setAttribute(CComBSTR(L"Opacity"), CComVariant(bstrWMOpacity))) &&
                SUCCEEDED(hr = pImageBrush->setAttribute(CComBSTR(L"ViewboxUnits"), CComVariant(L"Absolute"))) &&
                SUCCEEDED(hr = pImageBrush->setAttribute(CComBSTR(L"Viewbox"), CComVariant(strViewbox.GetBuffer()))) &&
                SUCCEEDED(hr = pImageBrush->setAttribute(CComBSTR(L"ViewportUnits"), CComVariant(L"Absolute"))) &&
                SUCCEEDED(hr = pImageBrush->setAttribute(CComBSTR(L"Viewport"), CComVariant(strViewport.GetBuffer()))) &&
                SUCCEEDED(hr = pPathFill->appendChild(pImageBrush, &pInsertNode)) &&
                SUCCEEDED(hr = m_pWMElem->appendChild(pPathFill, &pInsertNode)))
            {
                hr = m_pWMElem->appendChild(pPathFill, &pInsertNode);
            }
        }
        catch (CXDException& e)
        {
            hr = e;
        }
    }

    ERR_ON_HR(hr);
    return hr;
}
/*++

Routine Name:

    CWatermarkDMPTConv::GetPTDataSettingsFromDM

Routine Description:

    Populates the watermark data structure from the Devmode passed in.

Arguments:

    pDevmode - pointer to input devmode buffer.
    cbDevmode - size in bytes of full input devmode.
    pPrivateDevmode - pointer to input private devmode buffer.
    cbDrvPrivateSize - size in bytes of private devmode.
    pDataSettings - Pointer to watermark data structure to be updated.

Return Value:

    HRESULT
    S_OK - On success
    E_*  - On error

--*/
HRESULT
CWatermarkDMPTConv::GetPTDataSettingsFromDM(
    _In_  PDEVMODE       pDevmode,
    _In_  ULONG          cbDevmode,
    _In_  PVOID          pPrivateDevmode,
    _In_  ULONG          cbDrvPrivateSize,
    _Out_ WatermarkData* pDataSettings
    )
{
    HRESULT hr = S_OK;

    if (SUCCEEDED(hr = CHECK_POINTER(pDevmode, E_POINTER)) &&
        SUCCEEDED(hr = CHECK_POINTER(pPrivateDevmode, E_POINTER)) &&
        SUCCEEDED(hr = CHECK_POINTER(pDataSettings, E_POINTER)))
    {
        if (cbDevmode < sizeof(DEVMODE) ||
            cbDrvPrivateSize == 0)
        {
            hr = E_INVALIDARG;
        }
    }

    //
    // Retrieve the GPD and devmode controlled settings
    //
    CUIProperties uiProperties(static_cast<POEMDEV>(pPrivateDevmode));

    DWORD dwTextColor = 0;
    if (SUCCEEDED(hr) &&
        SUCCEEDED(hr = GetOptionFromGPDString<EWatermarkOption>(pDevmode,
                                                                cbDevmode,
                                                                g_pszWatermarkTypeFeature,
                                                                g_watermarkTypeOption,
                                                                g_cWatermarkTypeOption,
                                                                pDataSettings->type)) &&
        SUCCEEDED(hr = GetOptionFromGPDString<ELayeringOption>(pDevmode,
                                                               cbDevmode,
                                                               g_pszLayeringFeature,
                                                               g_watermarkLayeringOption,
                                                               g_cLayeringOption,
                                                               pDataSettings->layering)) &&
        SUCCEEDED(hr = uiProperties.GetItem(g_pszWMOffsetWidth, &pDataSettings->widthOrigin, sizeof(pDataSettings->widthOrigin))) &&
        SUCCEEDED(hr = uiProperties.GetItem(g_pszWMOffsetHeight, &pDataSettings->heightOrigin, sizeof(pDataSettings->heightOrigin))) &&
        SUCCEEDED(hr = uiProperties.GetItem(g_pszWMSizeWidth, &pDataSettings->widthExtent, sizeof(pDataSettings->widthExtent))) &&
        SUCCEEDED(hr = uiProperties.GetItem(g_pszWMSizeHeight, &pDataSettings->heightExtent, sizeof(pDataSettings->heightExtent))) &&
        SUCCEEDED(hr = uiProperties.GetItem(g_pszWMTransparency, &pDataSettings->transparency, sizeof(pDataSettings->transparency))) &&
        SUCCEEDED(hr = uiProperties.GetItem(g_pszWMAngle, &pDataSettings->angle, sizeof(pDataSettings->angle))) &&
        SUCCEEDED(hr = uiProperties.GetItem(g_pszWMFontSize, &pDataSettings->txtData.fontSize, sizeof(pDataSettings->txtData.fontSize))) &&
        SUCCEEDED(hr = uiProperties.GetItem(g_pszWMFontColor, &dwTextColor, sizeof(dwTextColor))))
    {
        //
        // Convert the color to the txtData BSTR
        //
        try
        {
            CStringXDW cstrColor;
            cstrColor.Format(L"#%08X", dwTextColor);
            pDataSettings->txtData.bstrFontColor.Empty();
            pDataSettings->txtData.bstrFontColor.Attach(cstrColor.AllocSysString());
        }
        catch (CXDException& e)
        {
            hr = e;
        }

        TCHAR text[MAX_WATERMARK_TEXT + 1] = {0};

        if (SUCCEEDED(hr) &&
            SUCCEEDED(hr = uiProperties.GetItem(g_pszWMText, text, MAX_WATERMARK_TEXT * sizeof(TCHAR))))
        {
            pDataSettings->txtData.bstrText = text;

            //
            // Convert measurements from 100ths of an inch to microns
            //
            pDataSettings->widthOrigin  = HUNDREDTH_OFINCH_TO_MICRON(pDataSettings->widthOrigin);
            pDataSettings->heightOrigin = HUNDREDTH_OFINCH_TO_MICRON(pDataSettings->heightOrigin);
            pDataSettings->widthExtent  = HUNDREDTH_OFINCH_TO_MICRON(pDataSettings->widthExtent);
            pDataSettings->heightExtent = HUNDREDTH_OFINCH_TO_MICRON(pDataSettings->heightExtent);
        }
    }

    ERR_ON_HR(hr);
    return hr;
}