Overlay: Drawables and Touchables

FastPdfKit supports custom overlays over pdf pages.
Starting from version 2 some of them are rendered automatically like movies and web pages due to support for custom uri annotations.

Here we give you some suggestions on how-to add support for your own overlays.
First of all there are three different overlays: MFOverlayDrawable (that don't have any user interaction), MFOverlayTouchable (that give you a feedback when users tap on them) and views (real UIView).
In this article we are going to describe the first two.

First of all you need an objects that implements the MFDocumentOverlayDataSource protocol: particularly drawablesForPage: and touchablesForPage: methods, returning an array filled with MFOverlayDrawables and MFOverlayTouchables.

Obviously you need to create your own MFOverlayDrawable and MFOverlayTouchable subclasses to provide the right overlays. It's very simple as you need to add your drawInContext: method.

You can call reloadOverlay on your MFDocumentViewController to force the redraw or disable any overlay with the overlayEnabled property.
If you need that the overlays is maintained sharp even when zoomed, simply set to YES the useTiledOverlayView

A sample of this flow is included in the devel branch and the Simple target.

In the MenuViewController we instantiate the OverlayManager that is a sample object that implements the MFDocumentOverlayDataSource protocol in the actionOpenPlainDocument method.

OverlayManager *ovManager = [[OverlayManager alloc] init];
[aDocViewController addOverlayDataSource:ovManager];
[ovManager release];

The OverlayManager is composed of just one method as we need only one MFOverlayDrawable in the first page.

- (NSArray *)documentViewController:(MFDocumentViewController *)dvc drawablesForPage:(NSUInteger)page{
    NSArray *array;
    if(page == 1){
        array = [NSArray arrayWithObject:[[Drawable alloc] init]];
    } else
        array = [[NSArray alloc] init];
    return array;
}

In the Drawable class we add an image in the lower left corner and two lines of text near it.

-(void)drawInContext:(CGContextRef)context{
    UIImage *image = [UIImage imageNamed:@"Icon.png"];
    CGRect rect = CGRectMake(20, 80, 61, 61);

    CGContextSetGrayFillColor(context, 0.0, 1.0);
    CGContextSelectFont(context, "Courier", 12, kCGEncodingMacRoman);
    CGContextSetTextDrawingMode(context, kCGTextFill);
    CGContextSetShouldAntialias(context, true);
    char* text = "This is an overlay, check classes";
    CGContextShowTextAtPoint(context, 101, 113, text, strlen(text));
    text = "OverlayManager and Drawable";
    CGContextShowTextAtPoint(context, 101, 100, text, strlen(text));
    CGContextDrawImage(context, rect, image.CGImage);
}

Enjoy your overlays!

As you probably know you can support custom annotations, directly adding url annotations on your pdf document. Then implement the documentViewController:didReceiveURIRequest: or one of the other delegate methods to display custom overlays or views directly in page coordinates.