XPS OM 内を移動する

このトピックでは、XPS OM 内を移動し、メモリ内ドキュメントのさまざまな部分にアクセスする方法について説明します。

XPS ドキュメント API のorganizationは、XPS ドキュメントのorganizationを反映します。 次の表は、XPS ドキュメント API のインターフェイスと XPS ドキュメントのコンポーネントの関係を示しています。

XPS ドキュメント コンポーネント XPS ドキュメント API インターフェイス 階層内の次のレベルダウンを呼び出すメソッド
XPS ドキュメント ファイル (OPC パッケージを含む)
IXpsOMPackage
GetDocumentSequence
FixedDocumentSequence パーツ
IXpsOMDocumentSequence
GetDocuments
FixedDocument パーツ
IXpsOMDocument
GetPageReferences
FixedDocument マークアップの PageContent 要素
IXpsOMPageReference
GetPage
CollectPartResources
FixedPage パーツ
IXpsOMPage
GetVisuals
FixedPage マークアップの Canvas 要素
IXpsOMCanvas
GetVisuals
FixedPage マークアップの Path 要素
IXpsOMPath
ドキュメント階層の末尾。
FixedPage マークアップの Glyphs 要素
IXpsOMGlyphs
ドキュメント階層の末尾。
フォント パーツ
IXpsOMFontResource
ドキュメント階層の末尾。
画像パーツ
IXpsOMImageResource
ドキュメント階層の末尾。

プログラムで次のコード例を使用する前に、「 一般的な XPS ドキュメント プログラミング タスク」の免責事項をお読みください。

コード例

次のコード例では、初期化された XPS OM が存在することを前提としており、 パッケージ は、その XPS OM を表す IXpsOMPackage インターフェイスを指しています。 XPS OM の作成の詳細については、「 XPS ドキュメントを XPS OM に読み取る 」または 「空の XPS OM を作成する」を参照してください。

    HRESULT                        hr = S_OK;

    IXpsOMDocumentSequence         *docSeq = NULL;
    IXpsOMDocumentCollection       *docs = NULL;
    IXpsOMDocument                 *doc = NULL;
    IXpsOMPageReferenceCollection  *pages = NULL;
    IXpsOMPageReference            *pageRef = NULL;
    IXpsOMPage                     *page = NULL;
    IXpsOMCanvas                   *canvas = NULL;
    IXpsOMPath                     *path = NULL;
    IXpsOMPartResources            *pageParts = NULL;
    IXpsOMGlyphs                   *glyphs = NULL;
    IXpsOMFontResourceCollection   *fonts = NULL; 
    IXpsOMFontResource             *font = NULL;
    IXpsOMImageResourceCollection  *images = NULL;
    IXpsOMImageResource            *image = NULL;
    IXpsOMVisualCollection         *visuals = NULL;
    IXpsOMVisual                   *visual = NULL;

    UINT32  numDocs = 0;
    UINT32  thisDoc = 0;

    UINT32  numPageRefs = 0;
    UINT32  thisPageRef = 0;

    UINT32  numVisuals = 0;
    UINT32  thisVisual = 0;

    UINT32  numFonts = 0;
    UINT32  thisFont = 0;

    UINT32  numImages = 0;
    UINT32  thisImage = 0;

    XPS_OBJECT_TYPE  visualType;
 
    // package points to the IXpsOMPackage interface to walk.

    // Get the fixed document sequence of the package.
    hr = package->GetDocumentSequence(&docSeq);

    // Get the fixed documents in the fixed document sequence.
    hr = docSeq->GetDocuments(&docs);

    // Walk the collection of documents.
    hr = docs->GetCount(&numDocs);
    thisDoc = 0;
    while (thisDoc < numDocs) {
        hr = docs->GetAt(thisDoc, &doc);
        
        // Get the doc contents.
        hr = doc->GetPageReferences(&pages);
        
        // Walk the collection of page references
        hr = pages->GetCount(&numPageRefs);
        thisPageRef = 0;
        while (thisPageRef < numPageRefs) {
            // Get this page reference.
            hr = pages->GetAt(thisPageRef, &pageRef);

            // Get the page content of this page reference.
            {
                hr = pageRef->GetPage (&page);

                // Get the visual tree of this page.
                hr = page->GetVisuals (&visuals);
                
                // Walk the visuals.
                hr = visuals->GetCount (&numVisuals);
                thisVisual = 0;
                while (thisVisual < numVisuals) {
                    hr = visuals->GetAt (thisVisual, &visual);
                    // Get visual type.
                    hr = visual->GetType( &visualType );
                    
                    // Do other stuff with the visual.

                    // Release the visual.
                    if (NULL != visual) {visual->Release(); visual = NULL;}
                    thisVisual++; // Get next visual in collection.
                }
                if (NULL != visuals) {visuals->Release(); visuals = NULL;}
                if (NULL != page) {page->Release(); page = NULL;}
            }
            // Get the part resources used by this page.
            hr = pageRef->CollectPartResources (&pageParts);

            // Get the font resources.
            {
                hr = pageParts->GetFontResources (&fonts);
                
                // Walk the fonts.
                hr = fonts->GetCount (&numFonts);
                thisFont = 0;
                while (thisFont < numFonts) {
                    hr = fonts->GetAt(thisFont, &font);
                    if (NULL != font) {font->Release(); font = NULL;}

                    thisFont++; // Get the next font in collection.
                }
                if (NULL != fonts) {fonts->Release(); fonts = NULL;}
            }

            // Get the image resources.
            {
                hr = pageParts->GetImageResources (&images);

                // walk the images
                hr = images->GetCount (&numImages);
                thisImage = 0;
                while (thisImage < numImages) {
                    hr = images->GetAt(thisImage, &image);
                    thisImage++;
                    if (NULL != image) {image->Release(); image = NULL;}
                }
                if (NULL != images) {images->Release(); images = NULL;}
            }
            if (NULL != pageRef) {pageRef->Release(); pageRef = NULL;}
            thisPageRef++; // Get next page in doc.
        }
        if (NULL != pages) {pages->Release(); pages = NULL;}
        if (NULL != doc) {doc->Release(); doc = NULL;}
        thisDoc++; // Get next doc in collection.
    }

    // Release interface pointers.
    if (NULL != docs) docs->Release();
    if (NULL != docSeq) docSeq->Release();

次の手順

XPS OM へのテキストの書き込み

XPS OM でグラフィックスを描画する

XPS OM にイメージを配置する

このページで使用

IXpsOMDocument

IXpsOMDocumentCollection

IXpsOMDocumentSequence

IXpsOMFontResource

IXpsOMFontResourceCollection

IXpsOMImageResource

IXpsOMImageResourceCollection

IXpsOMPackage

IXpsOMPage

IXpsOMPageReference

IXpsOMPageReferenceCollection

IXpsOMVisual

IXpsOMVisualCollection

詳細情報

XPS OM を初期化する

XPS ドキュメントを XPS OM に読み取る

空の XPS OM を作成する

API のパッケージ化

XPS ドキュメント API リファレンス

XML Paper Specification