高度な検索
Developer Connection
Member Login ログイン | ご入会 ADC連絡先

Technical Q&A QA1216
How do I use PMSessionGetGraphicsContext to get a CGContextRef?


Q: PMSessionGetGraphicsContext を使用して CGContextRef を取得するにはどうしたらよいでしょうか?

A: Carbon Printing Manager ReferencePMSessionSetDocumentFormatGeneration API の説明にあるように、PMSessionGetGraphicsContextCGContextRef を返すためには、PMSessionBeginDocument を呼び出す前に、kPMGraphicsContextCoreGraphics のコンテキストタイプを指定して PMSessionSetDocumentFormatGeneration を呼び出し、その後で PMSessionBeginPage を呼び出す必要があります。CGContextRef の座標系(ページの左下隅を起点とし、イメージ可能領域ではなく、y は上方向が正)は、QuickDraw ポートの座標系(左上を起点とし、y は下方が正)とは同じではないことに注意してください。また、CarbonLib 1.1 以降でこれらの API が利用可能であるとしても、Mac OS X 10.0 以前は Quartz 2D は存在していなかったので、kPMGraphicsContextCoreGraphics の要求は、Mac OS X を実行していなければ意味がありません。下記のリスト 1 は、Carbon Printing Manager ReferencePMSessionSetDocumentFormatGeneration のセクションにあるコードの修正版です。



リスト 1. プリントのための CGContextRef の取得

    CFStringRef         strings[1];
    CFArrayRef          ourGraphicsContextsArray;
    CGContextRef        printingContext;
    OSErr               err = noErr;
    PMPrintSession      printSession;
    
    //
    // この時点では、プリントセッションはすでに作成されている
    //
    strings[0] = kPMGraphicsContextCoreGraphics; // これは重要
    ourGraphicsContextsArray = CFArrayCreate (kCFAllocatorDefault,
                        (const void **)strings,
                        1, &kCFTypeArrayCallBacks);
    if (ourGraphicsContextsArray != NULL)
    {
            err = PMSessionSetDocumentFormatGeneration (printSession,
                            kPMDocumentFormatPDF,
                            ourGraphicsContextsArray, NULL);
            CFRelease (ourGraphicsContextsArray);
    }
    
    //
    // 追加のプリントループ
    //
    
    //
    // 次に、PMSessionBeginDocument と PMSessionBeginPage を呼び出す
    //
    
    // プリントコンテキストを要求する準備ができている
    err = PMSessionGetGraphicsContext (printSession,
        kPMGraphicsContextCoreGraphics, (void **) &printingContext);
        
    //
    // Quartz 2D を使用して printingContext にコンテンツを
    // レンダリングして、プリントループを続行する
    //


PMSessionSetDocumentFormatGeneration API と PMSessionGetGraphicsContext API は「PMCore.h」ヘッダファイルにあります。これに対し、kPMGraphicsContextCoreGraphics 定数は「PMDefinitions.h」ヘッダファイルにあります。


[2003 年 2 月 25 日]