Mailing Lists: Apple Mailing Lists
Image of Mac OS face in stamp
PDFKit on 10.12
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

PDFKit on 10.12



PDFKit seems a bit disturbed on Sierra.
The 10.12 beta 3 seems to improve things but there are still some rendering stutters etc.

Has PDFKit been reworked - there doesn’t seem to be any mention of it in the release notes?
If so it might be a question of waiting for the internal gremlins to be hunted down rather than me wasting too much time on this.

Before 10.12 PDFPage -(void)drawWithBox:(PDFDisplayBox)box was called.

In 10.12 PDFPage -(void)drawWithBox:(PDFDisplayBox)box toContext:(CGContextRef)context was defined.

However, on 10.12.0 when printing NSPrintThumbnailView calls drawWithBox:(PDFDisplayBox)box inContext:(CGContextRef)context not toContext:.
My only solution here has been to override the private  PDFPage -(void)drawWithBox:(PDFDisplayBox)box inContext:(CGContextRef)context

In addition screen rendering seems to be suffering.
Rendering now has to target the CGContextRef given in PDFPage drawWithBox:toContext:

I render additional text onto the PDF using NSLayoutManager using a flipped NSGraphicsContext.

Pre 10.12 this worked fine. Now it is flakey - often I just get a PDFPage rect filled with red (printing seems okay).
Perhaps I am not handling the context correctly.

It would seem that the actual generation is now called on a background thread and that [NSGraphicsContext currentContext] can be nil.
I try to deal with this but all is still not quite what it was.

- (void)drawWithBox:(PDFDisplayBox)box inContext:(CGContextRef)context
{
    [super drawWithBox:box inContext:context];

  BOOL hasInitialNSGraphicsContext = NO;

    if ([NSGraphicsContext currentContext]) {
        [NSGraphicsContext saveGraphicsState];
        hasInitialNSGraphicsContext = YES;
    }
    else {
        CGContextSaveGState(context);
    }

    // life is much easier if we use a flipped co-ordinate system.
    // NSLayoutManager expects a flipped NSGraphicsContext to be present.
    NSGraphicsContext *flippedGC = [NSGraphicsContext graphicsContextWithGraphicsPort:context flipped:YES];
    [NSGraphicsContext setCurrentContext:flippedGC];

    // define the flip transform
    NSAffineTransform* xform = [NSAffineTransform transform];
    [xform translateXBy:0.0 yBy:self.mediaBoxRect.size.height];
    [xform scaleXBy:1.0 yBy:-1.0];
    [xform concat];

    // draw all map items
    … do my drawing here

    if (hasInitialNSGraphicsContext) {
        [NSGraphicsContext restoreGraphicsState];
    }
    else {
        CGContextRestoreGState(context);
    }

}

Jonathan
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden




Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2011 Apple Inc. All rights reserved.