大网数据广告活动
打印与设备

XPS OM Canvas and Visual Interfaces

· 52CE 我爱测

This topic describes how to use the canvas-related interfaces of the XPS Document API in an XPS OM.

This topic describes how to use the canvas-related interfaces of the XPS Document API in an XPS OM.

Interface name Logical child interfaces Description
IXpsOMVisual IXpsOMCanvas IXpsOMGlyphs IXpsOMPath The base class of the interfaces that define visual objects, such as text and graphics. Visual objects can be collected in an IXpsOMVisualCollection interface.
IXpsOMCanvas IXpsOMCanvas IXpsOMGlyphs IXpsOMPath A collection of visual objects that can be treated as a single visual object.

IXpsOMVisual is the base interface; the visible objects of a page inherit from it. IXpsOMCanvas inherits from IXpsOMVisual and enables many other visual elements to be grouped and acted upon as a single visual element. For example, you could use an IXpsOMCanvas interface to create a page banner that contains a collection of text and graphical elements. Such a banner might contain a logo, the company slogan, and the company address. You could place all these elements into the IXpsOMVisualCollection of an IXpsOMCanvas interface, and then apply a single transform to the IXpsOMCanvas object to resize it to a particular page. This is much simpler than computing and applying a transform to each individual visual component in the banner.

You can also use a canvas to resize the page contents to fit the current page size. To accomplish this, place all contents of the page into a single canvas, then apply the appropriate transform to fit the canvas to the current page size. This is also much simpler than trying to resize each visual element in the collection of visuals in the page.

Move page contents to a canvas

The following code example moves the contents of a page to a canvas.

    HRESULT                   hr = S_OK;

    IXpsOMVisualCollection    *pageVisuals;
    IXpsOMVisualCollection    *canvasVisuals;
    IXpsOMVisual              *oneVisual;
    IXpsOMCanvas              *newPageCanvas;

    UINT32 numVisuals = 0;
    UINT32 thisVisual;

    // get the page's visual collection
    // and how many objects it contains
    hr = page->GetVisuals( &pageVisuals );
    hr = pageVisuals->GetCount ( &numVisuals );

    // create the new canvas object and
    // its (empty) visual collection
    hr = xpsFactory->CreateCanvas ( &newPageCanvas );
    hr = newPageCanvas->GetVisuals ( &canvasVisuals );

    // go through the page's list of visual objects,
    //  move each one from the page's list to the canvas' list
    //  release the local pointer
    //  remove it from the page's collection
    thisVisual = 0;
    while (thisVisual < numVisuals) {
        hr = pageVisuals->GetAt (0, &oneVisual);
        hr = canvasVisuals->Append (oneVisual);
        hr = pageVisuals->RemoveAt (0);
        thisVisual++;
    }
    // the page's visual collection should be empty
    hr = pageVisuals->GetCount (&numVisuals);
    _ASSERT (0 == numVisuals);

    // add the new canvas to the page's visual collection
    pageVisuals->Append ( newPageCanvas );

Related topics

IXpsOMCanvas Interface IXpsOMVisual Interface IXpsOMVisualCollection Interface

Source: Microsoft Learn / Windows Win32 documentation by Microsoft and contributors. Documentation licensed CC BY 4.0. Code samples are covered by the MIT License. Converted from Markdown, with links normalized and embedded media omitted.

资料来源与适用范围

资料来源
Microsoft Learn / Windows Win32 documentation
适用范围
Windows Win32 API · Source date 05/31/2018
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY 4.0 (documentation), MIT (code samples)

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。