Annotations du PDFKit

eric210766

Membre confirmé
5 Septembre 2007
47
1
Compiègne
Bonjour,

Je ne suis pas parvenu à comprendre la méthode setQuadrilateralPoint de la classe PDFAnnotationMarkup du PDFKit.
Elle est utilisée pour définir les quatre points d'une sélection multiples lignes.
Ce que je sais:

1. Je dois lui transmettre un tableau (NSArray*) dont chaque élément est un objet de la classe NSValue formaté avec une structure NSPoint.
2. Ces points sont exprimés selon le repère de la page (PDFPage) dans laquelle la notation est construite.

voici le code qui est censé surligner la sélection courante.

Bloc de code:
-(IBAction)hightlight_action:(id)sender
{
    PDFAnnotationMarkup*    annotation;
    PDFSelection*            selection = [_PDFView currentSelection];    
    PDFPage*                page = [[selection pages] lastObject];
    NSArray*                linesSelected = [selection selectionsByLine];
    NSRect                    bounds = [selection boundsForPage:page];
    NSMutableArray*            array = [NSMutableArray array];
    
    annotation = [[PDFAnnotationMarkup alloc] initWithBounds:bounds];
    [annotation setMarkupType:kPDFMarkupTypeHighlight];    
    [annotation setColor:[NSColor yellowColor]];
    if ([linesSelected count] > 1)
    {
        for (selection in linesSelected)
        {
            bounds = [selection boundsForPage:page];
            // il faut que les points soient cites dans le sens horaire
            // coin bas gauche
            [array addObject:[NSValue valueWithPoint:NSMakePoint(bounds.origin.x,bounds.origin.y)]];
            // coin haut gauche
            [array addObject:[NSValue valueWithPoint:NSMakePoint(bounds.origin.x,NSMaxY(bounds))]];
            // coin haut droit
            [array addObject:[NSValue valueWithPoint:NSMakePoint(NSMaxX(bounds),NSMaxY( bounds))]];
            // coin bas droit
            [array addObject:[NSValue valueWithPoint:NSMakePoint(NSMaxX(bounds),bounds.origin.y)]];
        }
        [annotation setQuadrilateralPoints:array];
    }
    [page addAnnotation:annotation];
    [annotation release];                
    [_PDFView clearSelection];
    [_PDFView setCurrentAnnotation:annotation];
} /* hightlight_action */

Mon problème est que la zone surlignée n'est pas celle sélectionnée. Le résultat ne correspond à rien ! ! !

Par avance, merci pour l'aide apportée.