⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 scalesax.cpp

📁 WDK 下的XPSDrv 中filter 例子之scaling
💻 CPP
📖 第 1 页 / 共 2 页
字号:
                                    resToken = str.Tokenize(L",",curPos);

                                    if (resToken != "")
                                    {
                                        bleedBox.Y = static_cast<REAL>(_wtof(resToken));
                                    }

                                    resToken = str.Tokenize(L",",curPos);

                                    if (resToken != "")
                                    {
                                        bleedBox.Width = static_cast<REAL>(_wtof(resToken));
                                    }

                                    resToken = str.Tokenize(L",",curPos);

                                    if (resToken != "")
                                    {
                                        bleedBox.Height = static_cast<REAL>(_wtof(resToken));
                                    }
                                }
                            }

                            //
                            // As we are applying scaling we need to remove the bleedBox and contentBox
                            //
                            if (bstrAttName != L"BleedBox" &&
                                bstrAttName != L"ContentBox")
                            {
                                //
                                // Replace the Width and Height aValues with the target papersize
                                //
                                if (bstrAttName == L"Width")
                                {
                                    CComBSTR bstrWidthValue;
                                    if (SUCCEEDED(hr = m_pPageScaling->GetFixedPageWidth(&bstrWidthValue)))
                                    {
                                        if (bstrWidthValue.Length() > 0)
                                        {
                                            bstrAttValue = bstrWidthValue;
                                        }
                                    }
                                }
                                else if (bstrAttName == L"Height")
                                {
                                    CComBSTR bstrHeightValue;
                                    if (SUCCEEDED(hr = m_pPageScaling->GetFixedPageHeight(&bstrHeightValue)))
                                    {
                                        if (bstrHeightValue.Length() > 0)
                                        {
                                            bstrAttValue = bstrHeightValue;
                                        }
                                    }
                                }

                                if (SUCCEEDED(hr))
                                {
                                    //
                                    // Delimit attributes with a space
                                    //
                                    cstrOut.Append(L" ");

                                    //
                                    // Reconstruct the attribute and write back to
                                    // the fixed page
                                    //
                                    cstrOut.Append(bstrAttName);
                                    cstrOut.Append(L"=\"");

                                    //
                                    // If this is a UnicodeString we may need to escape entities
                                    //
                                    if (bstrAttName == L"UnicodeString")
                                    {
                                        hr = EscapeEntity(&bstrAttValue);
                                    }

                                    cstrOut.Append(bstrAttValue);
                                    cstrOut.Append(L"\"");
                                }
                            }
                        }
                        catch (CXDException& e)
                        {
                            hr = e;
                        }
                    }
                }
            }
        }

        //
        // If bleedbox hasn't been set, set it to the page dimensions
        //
        if (bBleedBoxSet == FALSE)
        {
            bleedBox.Width = widthPage;
            bleedBox.Height = heightPage;
        }

        //
        // If contentbox hasn't been set, set it to the page dimensions
        //
        if (bContentBoxSet == FALSE)
        {
            contentBox.Width = widthPage;
            contentBox.Height = heightPage;
        }

        if (SUCCEEDED(hr = m_pPageScaling->SetPageDimensions(widthPage, heightPage)) &&
            SUCCEEDED(hr = m_pPageScaling->SetBleedBox(&bleedBox)) &&
            SUCCEEDED(hr = m_pPageScaling->SetContentBox(&contentBox)))
        {
            if (bIsFixedPage)
            {
                try
                {
                    //
                    // Close the fixed page tag
                    //
                    cstrOut.Append(L">");

                    //
                    // Create and retrieve the markup for the Canvas
                    //
                    CComBSTR bstrCanvasText;
                    if (SUCCEEDED(hr = m_pPageScaling->GetOpenTagXML(&bstrCanvasText)))
                    {
                        //
                        // Insert the mark-up by writing after the opening fixed page
                        // remembering to close the tag first
                        //
                        cstrOut.Append(bstrCanvasText);
                    }
                }
                catch (CXDException& e)
                {
                    hr = e;
                }
            }
        }

        if (SUCCEEDED(hr))
        {
            hr = WriteToPrintStream(&cstrOut, m_pWriter);
        }
    }

    ERR_ON_HR(hr);
    return hr;
}

/*++

Routine Name:

    CScaleSaxHandler::endElement

Routine Description:

    Receives notification of the end of an XML element in the XPS page.
    The page scaling filter parses each element, applies any changes
    and writes out the resultant XPS markup.

    A corresponding startElement method is invoked for every endElement method, even when the element is empty.

Arguments:

    pwchQName - The XML 1.0 qualified name (QName), with prefix, or an empty string
                (if QNames are not available).
    cchQName - The length of the QName.

Return Value:

    HRESULT
    S_OK - On success
    E_*  - On error

--*/
HRESULT STDMETHODCALLTYPE
CScaleSaxHandler::endElement(
    CONST wchar_t*,
    INT,
    CONST wchar_t*,
    INT,
    __in_ecount(cchQName) CONST wchar_t* pwchQName,
    __in                  INT            cchQName
    )
{
    HRESULT hr = S_OK;
    CStringXDW cstrClose;
    BOOL bIsFixedPage = FALSE;

    try
    {
        CComBSTR bstrElement(cchQName, pwchQName);

        bIsFixedPage = (bstrElement == L"FixedPage");

        //
        // If this is a root element with child nodes, the open
        // element will not match the last startElement. In this case
        // we need to add an appropriate closing tag
        //
        if (bstrElement == m_bstrOpenElement)
        {
            //
            // Names match so just add a closing bracket
            //
            if (m_bOpenTag)
            {
                cstrClose.Append(L"/>\n");
            }
        }
        else
        {
            //
            // Close Canvas if previously opened.
            //
            if (bIsFixedPage)
            {
                //
                // Insert the closing canvas mark-up before closing the fixed page
                //
                CComBSTR bstrCloseCanvasText;
                if (SUCCEEDED(hr = m_pPageScaling->GetCloseTagXML(&bstrCloseCanvasText)))
                {
                    cstrClose.Append(bstrCloseCanvasText);
                }
            }

            //
            // Add a full closing tag
            //
            cstrClose.Append(L"</");
            cstrClose.Append(bstrElement);
            cstrClose.Append(L">\n");
        }

        m_bOpenTag = FALSE;
    }
    catch (CXDException& e)
    {
        hr = e;
    }

    if (SUCCEEDED(hr))
    {
        hr = WriteToPrintStream(&cstrClose, m_pWriter);
    }

    ERR_ON_HR(hr);
    return hr;
}

/*++

Routine Name:

    CScaleSaxHandler::startDocument

Routine Description:

    This method writes out the header markup for the XPS page.

Arguments:

    None

Return Value:

    HRESULT
    S_OK - On success
    E_*  - On error

--*/
HRESULT STDMETHODCALLTYPE
CScaleSaxHandler::startDocument()
{
    HRESULT hr = S_OK;

    try
    {
        CStringXDW cstrXMLVersion(L"<?xml version=\"1.0\" encoding=\"utf-8\"?>");
        hr = WriteToPrintStream(&cstrXMLVersion, m_pWriter);
    }
    catch (CXDException& e)
    {
        hr = e;
    }

    ERR_ON_HR(hr);
    return hr;
}


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -