|
@@ -2747,27 +2747,70 @@ static inline CPDFAreaOfInterest CAreaOfInterestForResizeHandle(CRectEdges mask,
|
|
|
}
|
|
|
} else if (CAnnotationTypeFreeText == self.annotationType ||
|
|
|
CAnnotationTypeSignText == self.annotationType) {
|
|
|
- CPDFAnnotationModel *annotationModel = [[CPDFAnnotationModel alloc] initWithAnnotationType:self.annotationType];
|
|
|
-
|
|
|
- CGFloat defaultWidth = annotationModel.fontSize;
|
|
|
- CGFloat defaultHeight = annotationModel.fontSize;
|
|
|
- NSSize defaultSize = ([page rotation] % 180 == 0) ? NSMakeSize(defaultWidth, defaultHeight) : NSMakeSize(defaultHeight, defaultWidth);
|
|
|
- CGRect bounds = CPDFListViewRectFromRightAndSize(pagePoint, defaultSize);
|
|
|
- CGFloat fontSize = annotationModel.fontSize;
|
|
|
- NSString *fontName = annotationModel.fontName;
|
|
|
- CGFloat opacity = annotationModel.opacity;
|
|
|
-
|
|
|
- bounds = CGRectMake(pagePoint.x, pagePoint.y - (fontSize+2), defaultSize.width, (fontSize+2));
|
|
|
-
|
|
|
- bounds = CPDFListViewConstrainRect(bounds, page.bounds,[CPDFListViewConfig defaultManager].annotationBorderOffset.floatValue);
|
|
|
- annotation = [self addAnnotationWithType:self.annotationType selection:nil page:page bounds:bounds];
|
|
|
- if (self.annotationType == CAnnotationTypeFreeText) {
|
|
|
- ((CPDFFreeTextAnnotation *)annotation).font = [NSFont fontWithName:fontName size:fontSize];
|
|
|
- annotation.opacity = opacity;
|
|
|
- }
|
|
|
- originalBounds = [annotation bounds];
|
|
|
- if (annotation) {
|
|
|
- [self updateActiveAnnotations:@[annotation]];
|
|
|
+ BOOL draggedAnnotation = NO;
|
|
|
+ originalBounds = CPDFListViewRectFromCenterAndSquareSize(CPDFListViewIntegralPoint(pagePoint), 0.0);
|
|
|
+ NSEvent *lastMouseEvent = theEvent;
|
|
|
+ CRectEdges resizeHandle = CMaxXEdgeMask | CMinYEdgeMask;
|
|
|
+ NSUInteger eventMask = NSEventMaskLeftMouseUp | NSEventMaskLeftMouseDragged;
|
|
|
+ while (YES) {
|
|
|
+ theEvent = [[self window] nextEventMatchingMask:eventMask];
|
|
|
+ if ([theEvent type] == NSEventTypeLeftMouseUp) {
|
|
|
+ if (draggedAnnotation) {
|
|
|
+ if (annotation) {
|
|
|
+ CPDFAnnotationModel *annotationModel = [[CPDFAnnotationModel alloc] initWithAnnotationType:self.annotationType];
|
|
|
+
|
|
|
+ CGFloat fontSize = annotationModel.fontSize;
|
|
|
+ NSString *fontName = annotationModel.fontName;
|
|
|
+ CGFloat opacity = annotationModel.opacity;
|
|
|
+ ((CPDFFreeTextAnnotation *)annotation).font = [NSFont fontWithName:fontName size:fontSize];
|
|
|
+ annotation.opacity = opacity;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ CPDFAnnotationModel *annotationModel = [[CPDFAnnotationModel alloc] initWithAnnotationType:self.annotationType];
|
|
|
+
|
|
|
+ CGFloat defaultWidth = 200;
|
|
|
+ CGFloat defaultHeight = 64.0;
|
|
|
+ NSSize defaultSize = ([page rotation] % 180 == 0) ? NSMakeSize(defaultWidth, defaultHeight) : NSMakeSize(defaultHeight, defaultWidth);
|
|
|
+ CGRect bounds = CPDFListViewRectFromRightAndSize(pagePoint, defaultSize);
|
|
|
+ CGFloat fontSize = annotationModel.fontSize;
|
|
|
+ NSString *fontName = annotationModel.fontName;
|
|
|
+ CGFloat opacity = annotationModel.opacity;
|
|
|
+
|
|
|
+ bounds = CGRectMake(pagePoint.x, pagePoint.y - (fontSize+2), defaultSize.width, (fontSize+2));
|
|
|
+
|
|
|
+ bounds = CPDFListViewConstrainRect(bounds, page.bounds,[CPDFListViewConfig defaultManager].annotationBorderOffset.floatValue);
|
|
|
+ annotation = [self addAnnotationWithType:self.annotationType selection:nil page:page bounds:bounds];
|
|
|
+ if (self.annotationType == CAnnotationTypeFreeText) {
|
|
|
+ ((CPDFFreeTextAnnotation *)annotation).font = [NSFont fontWithName:fontName size:fontSize];
|
|
|
+ annotation.opacity = opacity;
|
|
|
+ }
|
|
|
+ originalBounds = [annotation bounds];
|
|
|
+ if (annotation) {
|
|
|
+ [self updateActiveAnnotations:@[annotation]];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ } else if ([theEvent type] == NSEventTypeLeftMouseDragged) {
|
|
|
+ CGPoint zPoint = pagePoint;
|
|
|
+ [self pageAndPoint:&zPoint forEvent:theEvent nearest:YES];
|
|
|
+ CGRect zRect = CGRectMake(pagePoint.x-2*mouseOffset, pagePoint.y-2*mouseOffset, 4*mouseOffset, 4*mouseOffset);
|
|
|
+ if (CGRectContainsPoint(zRect, zPoint)) {continue;}
|
|
|
+
|
|
|
+ if (annotation == nil)
|
|
|
+ annotation = [self addAnnotationWithType:self.annotationType selection:nil page:page bounds:CPDFListViewRectFromCenterAndSquareSize(originalBounds.origin, 0.0)];
|
|
|
+
|
|
|
+ lastMouseEvent = theEvent;
|
|
|
+ draggedAnnotation = YES;
|
|
|
+
|
|
|
+ if(annotation) {
|
|
|
+ [self updateActiveAnnotations:@[annotation]];
|
|
|
+ }
|
|
|
+
|
|
|
+ [annotation updateAppearanceStream];
|
|
|
+ [self doResizeAnnotationWithEvent:lastMouseEvent fromPoint:pagePoint originalBounds:originalBounds resizeHandle:&resizeHandle];
|
|
|
+
|
|
|
+ [self setNeedsDisplayAnnotationViewForPage:page];
|
|
|
+ }
|
|
|
}
|
|
|
} else if((CAnnotationTypeStamp == self.annotationType ||
|
|
|
CAnnotationTypeSignSignature == self.annotationType) && self.stampObject) {
|
|
@@ -3681,7 +3724,30 @@ static inline CPDFAreaOfInterest CAreaOfInterestForResizeHandle(CRectEdges mask,
|
|
|
newBounds.size.width = minWidth;
|
|
|
}
|
|
|
}
|
|
|
- newBounds = [self adjustFreetText:activeAnnotation rect:newBounds];
|
|
|
+
|
|
|
+ if ((resizeHandle & CMaxYEdgeMask)) {
|
|
|
+ newBounds.size.height += relPoint.y;
|
|
|
+ if (NSMaxY(newBounds)+ offsetPageSet > NSMaxY(pageBounds)) {
|
|
|
+ newBounds.size.height = NSMaxY(pageBounds) - NSMinY(newBounds)- offsetPageSet;
|
|
|
+ }
|
|
|
+ if (NSHeight(newBounds) < minHeight) {
|
|
|
+ newBounds.size.height = minHeight;
|
|
|
+ }
|
|
|
+
|
|
|
+ } else if ((resizeHandle & CMinYEdgeMask)) {
|
|
|
+ newBounds.origin.y += relPoint.y;
|
|
|
+ newBounds.size.height -= relPoint.y;
|
|
|
+ if (NSMinY(newBounds)-offsetPageSet < NSMinY(pageBounds)) {
|
|
|
+ newBounds.size.height = NSMaxY(newBounds) - NSMinY(pageBounds)-offsetPageSet;
|
|
|
+ newBounds.origin.y = NSMinY(pageBounds)+offsetPageSet;
|
|
|
+ }
|
|
|
+ if (NSHeight(newBounds) < minHeight) {
|
|
|
+ newBounds.origin.y = NSMaxY(newBounds) - minHeight;
|
|
|
+ newBounds.size.height = minHeight;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+// newBounds = [self adjustFreetText:activeAnnotation rect:newBounds];
|
|
|
} else {
|
|
|
CGFloat minWidth = MIN_NOTE_SIZE;
|
|
|
CGFloat minHeight = MIN_NOTE_SIZE;
|