I don't see your problem. What is the problem with PDFSelection? It works for me, even when the highlighted text consists of completely random parts.
Christiaan On 16 Aug 2007, at 7:58 PM, Maxwell, Adam R wrote: > I thought there was a way to do it, but I only looked for it on the > menus. > Anyway, the shift-click approach doesn't work for me, because of > limitations > in PDFSelection. Try it with multiple highlights that only cover a > single > column of a two-column page like this: > > column1 text is here and column2 text is here and > this is highlighted and this isn't highlighted and > this is highlighted and this isn't highlighted and > this isn't highlighted this isn't highlighted > > where you want to merge the highlights in column 1. I didn't try your > script, but you rightly pointed out my error in the bounds, and > this code > works as expected. I expect the selectAnnotationWithEvent: could be > modified to also create based on quad points, which should solve that > problem as well. > > static NSArray *adjustedQuadpointsToBoundsAsStrings(NSRect > newBounds, NSRect > oldBounds, NSArray *quadPoints) > { > float dx = NSMinX(oldBounds) - NSMinX(newBounds); > float dy = NSMinY(oldBounds) - NSMinY(newBounds); > unsigned i, iMax = [quadPoints count]; > NSMutableArray *newPoints = [NSMutableArray > arrayWithCapacity:iMax]; > for (i = 0; i < iMax; i++) { > NSPoint p = [[quadPoints objectAtIndex:i] pointValue]; > p.x += dx; > p.y += dy; > [newPoints addObject:NSStringFromPoint(p)]; > } > return newPoints; > } > > static NSArray *annotationsToMergeInSelection(NSArray *annotations, > const > NSRect selectionRect, int *markupType, NSRect *newBounds) > { > NSCParameterAssert(NULL != newBounds); > NSCParameterAssert(NULL != markupType); > NSMutableArray *toMerge = [NSMutableArray array]; > SKPDFAnnotationMarkup *ann = nil; > *markupType = -1; > unsigned i, iMax = [annotations count]; > for (i = 0; i < iMax; i++) { > ann = [annotations objectAtIndex:i]; > if (NSIntersectsRect([ann bounds], selectionRect) && [ann > isMarkupAnnotation]) { > if (-1 == *markupType) { > *newBounds = [ann bounds]; > *markupType = [ann markupType]; > } > else if ([ann markupType] == *markupType) { > *newBounds = NSUnionRect(*newBounds, [ann bounds]); > } > [toMerge addObject:ann]; > } > } > return toMerge; > } > > - (void)mergeAnnotationsInSelection:(id)sender { > NSRect bounds; > int markupType; > > NSArray *annotationsToMerge = annotationsToMergeInSelection([[self > currentPage] annotations], selectionRect, &markupType, &bounds); > unsigned i, iMax = [annotationsToMerge count]; > if (0 == iMax) > return NSBeep(); > > SKPDFAnnotationMarkup *ann = nil; > NSMutableArray *quadPoints = [NSMutableArray array]; > NSMutableString *newContents = [NSMutableString string]; > > for (i = 0; i < iMax; i++) { > ann = [annotationsToMerge objectAtIndex:i]; > if ([ann contents]) > [newContents appendString:[ann contents]]; > [quadPoints > addObjectsFromArray:adjustedQuadpointsToBoundsAsStrings(bounds, [ann > bounds], [ann quadrilateralPoints])]; > [self removeAnnotation:ann]; > } > > ann = [[SKPDFAnnotationMarkup alloc] initWithBounds:bounds > markupType:markupType quadrilateralPointsAsStrings:quadPoints]; > [ann setContents:newContents]; > [self addAnnotation:ann toPage:[self currentPage]]; > [ann release]; > [self setNeedsDisplayInRect:selectionRect ofPage:[self > currentPage]]; > } > > > > On 08/16/07 10:07, "Christiaan Hofman" <[EMAIL PROTECTED]> wrote: > >> Know that you can merge annotations using shift-click. So to see how >> it can be done, look at the code in selectAnnotationWithEvent:. It >> merges the selections of the annotations and creates a new annotation >> from the merged selection. Also note that quadrilateral points are >> relative to the annotation bounds, so if you use them in another >> annotation you need to shift them. But using the selection is easier. >> I also have an applescript (available on the wiki) that can merge all >> highlights, which also works by merging the selections. >> >> Christiaan >> >> On 16 Aug 2007, at 6:46 PM, Adam R. Maxwell wrote: >> >>> I've been highlighting a multi-column paper, and I agree with other >>> users that it's annoying to either have the highlight bounds extend >>> outside what I actually want to highlight, or have multiple short >>> highlights for each line (which shows up as multiple lines in the >>> outline view). >>> >>> For my own use, I thought I could merge markups together by >>> creating a new annotation in SKPDFView.m, but if I merge three >>> separate highlights (top, middle, bottom), I lose the middle line. >>> Am I missing something obvious? The only thing I can think of is >>> some restriction on ordering of quad points. >>> >>> - (void)mergeAnnotationsInSelection:(id)sender { >>> NSArray *annotations = [[self currentPage] annotations]; >>> NSMutableArray *quadPoints = [NSMutableArray array]; >>> NSRect bounds = NSZeroRect; >>> unsigned i, iMax = [annotations count]; >>> int markupType = -1; >>> SKPDFAnnotationMarkup *ann = nil; >>> >>> // don't remove while enumerating the current annotations >>> NSMutableArray *annotationsToRemove = [NSMutableArray array]; >>> >>> for (i = 0; i < iMax; i++) { >>> ann = [annotations objectAtIndex:i]; >>> if (NSIntersectsRect([ann bounds], selectionRect) && [ann >>> isMarkupAnnotation]) { >>> if (-1 == markupType) { >>> bounds = [ann bounds]; >>> markupType = [ann markupType]; >>> } >>> else if ([ann markupType] == markupType) { >>> bounds = NSUnionRect(bounds, [ann bounds]); >>> [quadPoints addObjectsFromArray:[ann >>> quadrilateralPoints]]; >>> [annotationsToRemove addObject:ann]; >>> } >>> } >>> } >>> >>> iMax = [annotationsToRemove count]; >>> for (i = 0; i < iMax; i++) >>> [self removeAnnotation:[annotationsToRemove >>> objectAtIndex:i]]; >>> >>> NSMutableArray *quadStrings = [NSMutableArray arrayWithCapacity: >>> [quadPoints count]]; >>> iMax = [quadPoints count]; >>> for (i = 0; i < iMax; i++) >>> [quadStrings addObject:NSStringFromPoint([[quadPoints >>> objectAtIndex:i] pointValue])]; >>> ann = [[SKPDFAnnotationMarkup alloc] initWithBounds:bounds >>> markupType:markupType quadrilateralPointsAsStrings:quadStrings]; >>> [self addAnnotation:ann toPage:[self currentPage]]; >>> [ann release]; >>> [self setNeedsDisplayInRect:selectionRect ofPage:[self >>> currentPage]]; >>> } >> >> >> >> --------------------------------------------------------------------- >> ---- >> This SF.net email is sponsored by: Splunk Inc. >> Still grepping through log files to find problems? Stop. >> Now Search log events and configuration files using AJAX and a >> browser. >> Download your FREE copy of Splunk now >> http://get.splunk.com/ >> _______________________________________________ >> skim-app-develop mailing list >> skim-app-develop@lists.sourceforge.net >> https://lists.sourceforge.net/lists/listinfo/skim-app-develop > > ---------------------------------------------------------------------- > --- > This SF.net email is sponsored by: Splunk Inc. > Still grepping through log files to find problems? Stop. > Now Search log events and configuration files using AJAX and a > browser. > Download your FREE copy of Splunk now >> http://get.splunk.com/ > _______________________________________________ > skim-app-develop mailing list > skim-app-develop@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/skim-app-develop ------------------------------------------------------------------------- This SF.net email is sponsored by: Splunk Inc. Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/ _______________________________________________ skim-app-develop mailing list skim-app-develop@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/skim-app-develop