From 050bf5dec6aa042b9db13b5badd786ca3ce07486 Mon Sep 17 00:00:00 2001 From: dsward2 Date: Tue, 10 Oct 2017 00:18:16 -0500 Subject: [PATCH] The interactive controls for transform attribute editing are improved in this commit. The editing should now work better with the current transform matrix (CTM) of the selected element. Improvements are still needed for rotate transforms, including an interactive control to show and change the center-of-rotation point. --- .../TransformAttributeEditor.m | 54 ++++++++++-- macSVG/MacSVG-Info.plist | 2 +- .../DOMSelectionControlsManager.m | 21 +++-- .../MacSVGPluginCallbacks.h | 1 + .../MacSVGPluginCallbacks.m | 14 ++++ macSVG/SVGDocument Classes/SVGLineEditor.m | 8 +- macSVG/SVGDocument Classes/SVGPathEditor.m | 36 +++++--- .../SVGDocument Classes/SVGPolylineEditor.m | 3 +- .../SVGDocument Classes/SVGWebKitController.h | 2 + .../SVGDocument Classes/SVGWebKitController.m | 82 +++++++++++++++++++ .../XMLAttributesTableController.m | 35 +++++--- 11 files changed, 218 insertions(+), 40 deletions(-) diff --git a/MacSVG Plugin Projects/macSVG Plugins/TransformAttributeEditorPlugin/TransformAttributeEditorPlugin/TransformAttributeEditor.m b/MacSVG Plugin Projects/macSVG Plugins/TransformAttributeEditorPlugin/TransformAttributeEditorPlugin/TransformAttributeEditor.m index d462521..8e4b53d 100644 --- a/MacSVG Plugin Projects/macSVG Plugins/TransformAttributeEditorPlugin/TransformAttributeEditorPlugin/TransformAttributeEditor.m +++ b/MacSVG Plugin Projects/macSVG Plugins/TransformAttributeEditorPlugin/TransformAttributeEditorPlugin/TransformAttributeEditor.m @@ -248,7 +248,7 @@ float getAngleABC( NSPoint a, NSPoint b, NSPoint c ) } //================================================================================== -// translatePoint +// translatePoint:targetElement: //================================================================================== -(NSPoint) translatePoint:(NSPoint)aMousePoint targetElement:(DOMElement *)targetElement @@ -899,6 +899,16 @@ float getAngleABC( NSPoint a, NSPoint b, NSPoint c ) [transformsTableView selectRowIndexes:rowIndex byExtendingSelection:NO]; } + + if ([xString isEqualToString:@"inf"] == YES) + { + yString = @"1"; + } + + if ([yString isEqualToString:@"inf"] == YES) + { + yString = @"1"; + } [label1TextField setHidden:NO]; label1TextField.stringValue = @"x"; @@ -960,8 +970,6 @@ float getAngleABC( NSPoint a, NSPoint b, NSPoint c ) float scaleX = scaleXString.floatValue; float scaleY = scaleYString.floatValue; - - NSRect offsetRect = NSMakeRect(self.pluginTargetDOMElement.offsetLeft, self.pluginTargetDOMElement.offsetTop, self.pluginTargetDOMElement.offsetWidth, self.pluginTargetDOMElement.offsetHeight); @@ -1002,6 +1010,10 @@ float getAngleABC( NSPoint a, NSPoint b, NSPoint c ) if ([elementTagName isEqualToString:@"path"] == YES) useBoundingBox = YES; if ([elementTagName isEqualToString:@"text"] == YES) useBoundingBox = YES; + if ([elementTagName isEqualToString:@"g"] == YES) useBoundingBox = YES; + if ([elementTagName isEqualToString:@"foreignObject"] == YES) useBoundingBox = YES; + if ([elementTagName isEqualToString:@"use"] == YES) useBoundingBox = YES; + if (useXY == YES) { NSString * xAttributeString = [self.pluginTargetDOMElement getAttribute:@"x"]; @@ -1512,7 +1524,6 @@ float getAngleABC( NSPoint a, NSPoint b, NSPoint c ) handleDegrees = currentDegrees; } - //================================================================================== // handleMouseMoveEventForSkewX: //================================================================================== @@ -2068,8 +2079,23 @@ float getAngleABC( NSPoint a, NSPoint b, NSPoint c ) DOMElement * eventTargetElement = event.target; DOMMouseEvent * mouseEvent = (DOMMouseEvent *)event; - CGFloat zoomFactor = (self.macSVGPluginCallbacks).zoomFactor; - currentMousePoint = NSMakePoint(mouseEvent.pageX * (1.0f / zoomFactor), mouseEvent.pageY * (1.0f / zoomFactor)); + + //CGFloat zoomFactor = (self.macSVGPluginCallbacks).zoomFactor; + //currentMousePoint = NSMakePoint(mouseEvent.pageX * (1.0f / zoomFactor), mouseEvent.pageY * (1.0f / zoomFactor)); + + NSPoint mouseEventPoint = NSMakePoint(mouseEvent.pageX, mouseEvent.pageY); + + //NSPoint transformedMousePoint = [webKitInterface transformPoint:aMousePoint fromElement:svgElement toElement:targetElement]; + NSPoint transformedMousePoint = [self translatePoint:mouseEventPoint targetElement:eventTargetElement.parentElement]; + + //NSLog(@"event mouse: %f,%f transformed %f,%f", mouseEventPoint.x, mouseEventPoint.y, transformedMousePoint.x, transformedMousePoint.y); + + currentMousePoint = transformedMousePoint; + + CGFloat zoomFactor = [self.macSVGPluginCallbacks scaleForDOMElementHandles:eventTargetElement]; + + + /* float clientX = mouseEvent.clientX; @@ -2221,8 +2247,20 @@ float getAngleABC( NSPoint a, NSPoint b, NSPoint c ) previousMousePoint = currentMousePoint; - CGFloat zoomFactor = (self.macSVGPluginCallbacks).zoomFactor; - currentMousePoint = NSMakePoint(mouseEvent.pageX * (1.0f / zoomFactor), mouseEvent.pageY * (1.0f / zoomFactor)); + //CGFloat zoomFactor = (self.macSVGPluginCallbacks).zoomFactor; + //currentMousePoint = NSMakePoint(mouseEvent.pageX * (1.0f / zoomFactor), mouseEvent.pageY * (1.0f / zoomFactor)); + + NSPoint mouseEventPoint = NSMakePoint(mouseEvent.pageX, mouseEvent.pageY); + + NSPoint transformedMousePoint = [self translatePoint:mouseEventPoint targetElement:targetElement.parentElement]; + + //NSLog(@"event mouse: %f,%f transformed %f,%f", mouseEventPoint.x, mouseEventPoint.y, transformedMousePoint.x, transformedMousePoint.y); + + currentMousePoint = transformedMousePoint; + + CGFloat zoomFactor = [self.macSVGPluginCallbacks scaleForDOMElementHandles:targetElement]; + + [event preventDefault]; [event stopPropagation]; diff --git a/macSVG/MacSVG-Info.plist b/macSVG/MacSVG-Info.plist index 547f735..053b87f 100644 --- a/macSVG/MacSVG-Info.plist +++ b/macSVG/MacSVG-Info.plist @@ -105,7 +105,7 @@ CFBundleSignature ???? CFBundleVersion - 0851 + 0878 LSApplicationCategoryType public.app-category.graphics-design LSMinimumSystemVersion diff --git a/macSVG/SVGDocument Classes/DOMSelectionControlsManager.m b/macSVG/SVGDocument Classes/DOMSelectionControlsManager.m index 1ef0212..b550af9 100644 --- a/macSVG/SVGDocument Classes/DOMSelectionControlsManager.m +++ b/macSVG/SVGDocument Classes/DOMSelectionControlsManager.m @@ -829,7 +829,10 @@ NSString * selectionStrokeColor = toolSettingsPopoverViewController.selectionStrokeColor; NSString * selectionStrokeWidth = toolSettingsPopoverViewController.selectionStrokeWidth; - CGFloat reciprocalZoomFactor = 1.0f / svgWebView.zoomFactor; + //CGFloat reciprocalZoomFactor = 1.0f / svgWebView.zoomFactor; + //CGFloat reciprocalZoomFactor = [svgWebKitController scaleForDOMElementHandles:controlParentElement]; + CGFloat reciprocalZoomFactor = [svgWebKitController scaleForDOMElementHandles:aSelectedSvgElement]; + CGFloat selectionStrokeWidthFloat = selectionStrokeWidth.floatValue; selectionStrokeWidthFloat = selectionStrokeWidthFloat * reciprocalZoomFactor; selectionStrokeWidth = [self allocPxString:selectionStrokeWidthFloat]; @@ -906,7 +909,9 @@ NSString * selectionHandleColor = toolSettingsPopoverViewController.selectionHandleColor; NSString * selectionHandleSize = toolSettingsPopoverViewController.selectionHandleSize; - CGFloat reciprocalZoomFactor = 1.0f / svgWebView.zoomFactor; + //CGFloat reciprocalZoomFactor = 1.0f / svgWebView.zoomFactor; + CGFloat reciprocalZoomFactor = [svgWebKitController scaleForDOMElementHandles:handleOwnerElement]; + CGFloat handleStrokeWidthFloat = 0.0625f * reciprocalZoomFactor; NSString * handleStrokeWidth = [self allocPxString:handleStrokeWidthFloat]; @@ -1385,7 +1390,9 @@ // pathSegmentString is basically a moveto, and a cubic curve NSString * selectionHandleColor = self.segmentStrokeHexColor; - CGFloat reciprocalZoomFactor = 1.0f / svgWebView.zoomFactor; + //CGFloat reciprocalZoomFactor = 1.0f / svgWebView.zoomFactor; + CGFloat reciprocalZoomFactor = [svgWebKitController scaleForDOMElementHandles:polylineDOMElement]; + CGFloat reciprocalStrokeWidthFloat = self.segmentStrokeWidth * reciprocalZoomFactor; NSString * selectionStrokeWidth = [self allocPxString:reciprocalStrokeWidthFloat]; @@ -1677,7 +1684,9 @@ { NSString * selectionHandleColor = self.segmentStrokeHexColor; - CGFloat reciprocalZoomFactor = 1.0f / svgWebView.zoomFactor; + //CGFloat reciprocalZoomFactor = 1.0f / svgWebView.zoomFactor; + CGFloat reciprocalZoomFactor = [svgWebKitController scaleForDOMElementHandles:lineDOMElement]; + CGFloat reciprocalStrokeWidthFloat = self.segmentStrokeWidth * reciprocalZoomFactor; NSString * selectionStrokeWidth = [self allocPxString:reciprocalStrokeWidthFloat]; @@ -1922,7 +1931,9 @@ // pathSegmentString is basically a moveto, and a cubic curve NSString * selectionHandleColor = self.segmentStrokeHexColor; - CGFloat reciprocalZoomFactor = 1.0f / svgWebView.zoomFactor; + //CGFloat reciprocalZoomFactor = 1.0f / svgWebView.zoomFactor; + CGFloat reciprocalZoomFactor = [svgWebKitController scaleForDOMElementHandles:pathDOMElement]; + CGFloat reciprocalStrokeWidthFloat = self.segmentStrokeWidth * reciprocalZoomFactor; NSString * selectionStrokeWidth = [self allocPxString:reciprocalStrokeWidthFloat]; diff --git a/macSVG/SVGDocument Classes/MacSVGPluginCallbacks.h b/macSVG/SVGDocument Classes/MacSVGPluginCallbacks.h index 4eac9ab..6d8a243 100644 --- a/macSVG/SVGDocument Classes/MacSVGPluginCallbacks.h +++ b/macSVG/SVGDocument Classes/MacSVGPluginCallbacks.h @@ -97,6 +97,7 @@ cx:(CGFloat)cx cy:(CGFloat)cy rx:(CGFloat)rx ry:(CGFloat)ry; - (NSDictionary *) convertArcToCenterPointWithStart:(CGPoint)start end:(CGPoint)end rx:(CGFloat)rx ry:(CGFloat)ry rotation:(CGFloat)rotation isLarge:(BOOL)isLarge isCounterClockwise:(BOOL)isCounterClockwise; +- (CGFloat)scaleForDOMElementHandles:(NSXMLElement *)aXMLElement; @end diff --git a/macSVG/SVGDocument Classes/MacSVGPluginCallbacks.m b/macSVG/SVGDocument Classes/MacSVGPluginCallbacks.m index 0b036a0..4e3644e 100644 --- a/macSVG/SVGDocument Classes/MacSVGPluginCallbacks.m +++ b/macSVG/SVGDocument Classes/MacSVGPluginCallbacks.m @@ -90,6 +90,20 @@ } + +- (CGFloat)scaleForDOMElementHandles:(NSXMLElement *)aXMLElement +{ + id macSVGDocumentWindowController = [self.macSVGDocument macSVGDocumentWindowController]; + id svgWebKitController = [macSVGDocumentWindowController svgWebKitController]; + + CGFloat scaleFactor = [svgWebKitController scaleForDOMElementHandles:aXMLElement]; + return scaleFactor; +} + + + + + //@interface SVGWebKitController - (id)svgWebView diff --git a/macSVG/SVGDocument Classes/SVGLineEditor.m b/macSVG/SVGDocument Classes/SVGLineEditor.m index 117a5d9..6361f08 100644 --- a/macSVG/SVGDocument Classes/SVGLineEditor.m +++ b/macSVG/SVGDocument Classes/SVGLineEditor.m @@ -192,8 +192,9 @@ //NSString * x2PxString = [x2String stringByAppendingString:@"px"]; //NSString * y2PxString = [y2String stringByAppendingString:@"px"]; - CGFloat reciprocalZoomFactor = 1.0f / svgWebKitController.svgWebView.zoomFactor; - + //CGFloat reciprocalZoomFactor = 1.0f / svgWebKitController.svgWebView.zoomFactor; + CGFloat reciprocalZoomFactor = [svgWebKitController scaleForDOMElementHandles:lineHandlesGroup]; + NSString * linePointStrokeWidthString = toolSettingsPopoverViewController.pathEndpointStrokeWidth; CGFloat linePointStrokeWidthFloat = linePointStrokeWidthString.floatValue; linePointStrokeWidthFloat *= reciprocalZoomFactor; @@ -271,7 +272,8 @@ //NSString * x2PxString = [x2String stringByAppendingString:@"px"]; //NSString * y2PxString = [y2String stringByAppendingString:@"px"]; - CGFloat reciprocalZoomFactor = 1.0f / svgWebKitController.svgWebView.zoomFactor; + //CGFloat reciprocalZoomFactor = 1.0f / svgWebKitController.svgWebView.zoomFactor; + CGFloat reciprocalZoomFactor = [svgWebKitController scaleForDOMElementHandles:lineHandlesGroup]; NSString * linePointStrokeWidthString = toolSettingsPopoverViewController.pathEndpointStrokeWidth; CGFloat linePointStrokeWidthFloat = linePointStrokeWidthString.floatValue; diff --git a/macSVG/SVGDocument Classes/SVGPathEditor.m b/macSVG/SVGDocument Classes/SVGPathEditor.m index 2035e9f..e2e20ff 100644 --- a/macSVG/SVGDocument Classes/SVGPathEditor.m +++ b/macSVG/SVGDocument Classes/SVGPathEditor.m @@ -1492,7 +1492,8 @@ NSString * selectedPathMode = macSVGDocumentWindowController.selectedPathMode; - CGFloat reciprocalZoomFactor = 1.0f / svgWebKitController.svgWebView.zoomFactor; + //CGFloat reciprocalZoomFactor = 1.0f / svgWebKitController.svgWebView.zoomFactor; + CGFloat reciprocalZoomFactor = [svgWebKitController scaleForDOMElementHandles:pathHandlesGroup]; NSString * pathEndpointStrokeWidthString = toolSettingsPopoverViewController.pathEndpointStrokeWidth; CGFloat pathEndpointStrokeWidthFloat = pathEndpointStrokeWidthString.floatValue; @@ -1637,7 +1638,8 @@ NSString * segmentIndexString = [NSString stringWithFormat:@"%ld", segmentIndex]; - CGFloat reciprocalZoomFactor = 1.0f / svgWebKitController.svgWebView.zoomFactor; + //CGFloat reciprocalZoomFactor = 1.0f / svgWebKitController.svgWebView.zoomFactor; + CGFloat reciprocalZoomFactor = [svgWebKitController scaleForDOMElementHandles:pathHandlesGroup]; NSString * pathEndpointStrokeWidthString = toolSettingsPopoverViewController.pathEndpointStrokeWidth; CGFloat pathEndpointStrokeWidthFloat = pathEndpointStrokeWidthString.floatValue; @@ -1682,8 +1684,9 @@ NSString * yPxString = [self allocPxString:currentPoint.y]; - CGFloat reciprocalZoomFactor = 1.0f / svgWebKitController.svgWebView.zoomFactor; - + //CGFloat reciprocalZoomFactor = 1.0f / svgWebKitController.svgWebView.zoomFactor; + CGFloat reciprocalZoomFactor = [svgWebKitController scaleForDOMElementHandles:pathHandlesGroup]; + NSString * pathEndpointStrokeWidthString = toolSettingsPopoverViewController.pathEndpointStrokeWidth; CGFloat pathEndpointStrokeWidthFloat = pathEndpointStrokeWidthString.floatValue; pathEndpointStrokeWidthFloat *= reciprocalZoomFactor; @@ -1727,8 +1730,8 @@ NSString * yString = pathSegmentDictionary[@"y"]; NSString * yPxString = [yString stringByAppendingString:@"px"]; - - CGFloat reciprocalZoomFactor = 1.0f / svgWebKitController.svgWebView.zoomFactor; + //CGFloat reciprocalZoomFactor = 1.0f / svgWebKitController.svgWebView.zoomFactor; + CGFloat reciprocalZoomFactor = [svgWebKitController scaleForDOMElementHandles:pathHandlesGroup]; NSString * pathEndpointStrokeWidthString = toolSettingsPopoverViewController.pathEndpointStrokeWidth; CGFloat pathEndpointStrokeWidthFloat = pathEndpointStrokeWidthString.floatValue; @@ -1768,7 +1771,14 @@ if (pathSegmentDictionary != NULL) { - CGFloat reciprocalZoomFactor = 1.0f / svgWebKitController.svgWebView.zoomFactor; + //CGFloat reciprocalZoomFactor = 1.0f / svgWebKitController.svgWebView.zoomFactor; + + //CGPoint currentCTMScalePoint = CGPointMake(1, 1); + //[self getCTMScaleForDOMElement:pathHandlesGroup resultPoint:¤tCTMScalePoint]; + //reciprocalZoomFactor *= (1.0f / currentCTMScalePoint.x); + + CGFloat reciprocalZoomFactor = [svgWebKitController scaleForDOMElementHandles:pathHandlesGroup]; + NSString * pathEndpointStrokeWidthString = toolSettingsPopoverViewController.pathEndpointStrokeWidth; CGFloat pathEndpointStrokeWidthFloat = pathEndpointStrokeWidthString.floatValue; @@ -1977,7 +1987,8 @@ currentPoint = [self absoluteXYPointAtPathSegmentIndex:(segmentIndex - 1)]; } - CGFloat reciprocalZoomFactor = 1.0f / svgWebKitController.svgWebView.zoomFactor; + //CGFloat reciprocalZoomFactor = 1.0f / svgWebKitController.svgWebView.zoomFactor; + CGFloat reciprocalZoomFactor = [svgWebKitController scaleForDOMElementHandles:pathHandlesGroup]; NSString * pathEndpointStrokeWidthString = toolSettingsPopoverViewController.pathEndpointStrokeWidth; CGFloat pathEndpointStrokeWidthFloat = pathEndpointStrokeWidthString.floatValue; @@ -2064,7 +2075,8 @@ NSString * currentYPxString = [self allocPxString:currentPoint.y]; - CGFloat reciprocalZoomFactor = 1.0f / svgWebKitController.svgWebView.zoomFactor; + //CGFloat reciprocalZoomFactor = 1.0f / svgWebKitController.svgWebView.zoomFactor; + CGFloat reciprocalZoomFactor = [svgWebKitController scaleForDOMElementHandles:pathHandlesGroup]; NSString * pathEndpointStrokeWidthString = toolSettingsPopoverViewController.pathEndpointStrokeWidth; CGFloat pathEndpointStrokeWidthFloat = pathEndpointStrokeWidthString.floatValue; @@ -2139,7 +2151,8 @@ currentPoint = [self absoluteXYPointAtPathSegmentIndex:(segmentIndex - 1)]; } - CGFloat reciprocalZoomFactor = 1.0f / svgWebKitController.svgWebView.zoomFactor; + //CGFloat reciprocalZoomFactor = 1.0f / svgWebKitController.svgWebView.zoomFactor; + CGFloat reciprocalZoomFactor = [svgWebKitController scaleForDOMElementHandles:pathHandlesGroup]; NSString * pathEndpointStrokeWidthString = toolSettingsPopoverViewController.pathEndpointStrokeWidth; CGFloat pathEndpointStrokeWidthFloat = pathEndpointStrokeWidthString.floatValue; @@ -2199,7 +2212,8 @@ currentPoint = [self absoluteXYPointAtPathSegmentIndex:(segmentIndex - 1)]; } - CGFloat reciprocalZoomFactor = 1.0f / svgWebKitController.svgWebView.zoomFactor; + //CGFloat reciprocalZoomFactor = 1.0f / svgWebKitController.svgWebView.zoomFactor; + CGFloat reciprocalZoomFactor = [svgWebKitController scaleForDOMElementHandles:pathHandlesGroup]; NSString * pathEndpointStrokeWidthString = toolSettingsPopoverViewController.pathEndpointStrokeWidth; CGFloat pathEndpointStrokeWidthFloat = pathEndpointStrokeWidthString.floatValue; diff --git a/macSVG/SVGDocument Classes/SVGPolylineEditor.m b/macSVG/SVGDocument Classes/SVGPolylineEditor.m index a119f92..c3d965c 100644 --- a/macSVG/SVGDocument Classes/SVGPolylineEditor.m +++ b/macSVG/SVGDocument Classes/SVGPolylineEditor.m @@ -261,7 +261,8 @@ NSString * xPxString = [xString stringByAppendingString:@"px"]; NSString * yPxString = [yString stringByAppendingString:@"px"]; - CGFloat reciprocalZoomFactor = 1.0f / svgWebKitController.svgWebView.zoomFactor; + //CGFloat reciprocalZoomFactor = 1.0f / svgWebKitController.svgWebView.zoomFactor; + CGFloat reciprocalZoomFactor = [svgWebKitController scaleForDOMElementHandles:polylineHandlesGroup]; NSString * polylinePointStrokeWidthString = toolSettingsPopoverViewController.pathEndpointStrokeWidth; CGFloat polylinePointStrokeWidthFloat = polylinePointStrokeWidthString.floatValue; diff --git a/macSVG/SVGDocument Classes/SVGWebKitController.h b/macSVG/SVGDocument Classes/SVGWebKitController.h index cc7e10d..89591d3 100644 --- a/macSVG/SVGDocument Classes/SVGWebKitController.h +++ b/macSVG/SVGDocument Classes/SVGWebKitController.h @@ -46,6 +46,8 @@ @property (assign) DOMTimeStamp lastMouseUpDOMTimeStamp; +- (CGFloat) scaleForDOMElementHandles:(DOMElement *)domElement; + - (IBAction)showWebKitInspectorAction:(id)sender; - (IBAction)detachWebKitInspectorAction:(id)sender; - (IBAction)disableJavaScriptAction:(id)sender; diff --git a/macSVG/SVGDocument Classes/SVGWebKitController.m b/macSVG/SVGDocument Classes/SVGWebKitController.m index abe3737..008f415 100644 --- a/macSVG/SVGDocument Classes/SVGWebKitController.m +++ b/macSVG/SVGDocument Classes/SVGWebKitController.m @@ -1310,6 +1310,88 @@ return result; } +/* from svg.js - https://github.com/svgdotjs/svg.js/ + // Extract individual transformations + extract: function() { + // find delta transform points + var px = deltaTransformPoint(this, 0, 1) + , py = deltaTransformPoint(this, 1, 0) + , skewX = 180 / Math.PI * Math.atan2(px.y, px.x) - 90 + + return { + // translation + x: this.e + , y: this.f + , transformedX:(this.e * Math.cos(skewX * Math.PI / 180) + this.f * Math.sin(skewX * Math.PI / 180)) / Math.sqrt(this.a * this.a + this.b * this.b) + , transformedY:(this.f * Math.cos(skewX * Math.PI / 180) + this.e * Math.sin(-skewX * Math.PI / 180)) / Math.sqrt(this.c * this.c + this.d * this.d) + // skew + , skewX: -skewX + , skewY: 180 / Math.PI * Math.atan2(py.y, py.x) + // scale + , scaleX: Math.sqrt(this.a * this.a + this.b * this.b) + , scaleY: Math.sqrt(this.c * this.c + this.d * this.d) + // rotation + , rotation: skewX + , a: this.a + , b: this.b + , c: this.c + , d: this.d + , e: this.e + , f: this.f + , matrix: new SVG.Matrix(this) + } + } +*/ + +//================================================================================== +// scaleForDOMElementHandles: +//================================================================================== + +- (CGFloat) scaleForDOMElementHandles:(DOMElement *)domElement +{ + CGFloat reciprocalZoomFactor = 1.0f / self.svgWebView.zoomFactor; + + // decompose the CTM to extract scale values + CGPoint scalePoint = CGPointMake(1, 1); + + if (domElement != NULL) + { + id ctmMatrix = [domElement callWebScriptMethod:@"getCTM" withArguments:NULL]; // call JavaScript function + + if (ctmMatrix != NULL) + { + NSString * ctmMatrixAString = [ctmMatrix valueForKey:@"a"]; + NSString * ctmMatrixBString = [ctmMatrix valueForKey:@"b"]; + NSString * ctmMatrixCString = [ctmMatrix valueForKey:@"c"]; + NSString * ctmMatrixDString = [ctmMatrix valueForKey:@"d"]; + NSString * ctmMatrixEString = [ctmMatrix valueForKey:@"e"]; + NSString * ctmMatrixFString = [ctmMatrix valueForKey:@"f"]; + + CGFloat ctmMatrixA = ctmMatrixAString.floatValue; + CGFloat ctmMatrixB = ctmMatrixBString.floatValue; + CGFloat ctmMatrixC = ctmMatrixCString.floatValue; + CGFloat ctmMatrixD = ctmMatrixDString.floatValue; + CGFloat ctmMatrixE = ctmMatrixEString.floatValue; + CGFloat ctmMatrixF = ctmMatrixFString.floatValue; + + scalePoint.x = sqrtf((ctmMatrixA * ctmMatrixA) + (ctmMatrixB * ctmMatrixB)); + scalePoint.y = sqrtf((ctmMatrixC * ctmMatrixC) + (ctmMatrixD * ctmMatrixD)); + + //NSLog(@"scalePoint %f, %f", scalePoint.x, scalePoint.y); + } + } + + CGFloat largerScale = scalePoint.x; + if (scalePoint.y > scalePoint.x) + { + largerScale = scalePoint.y; + } + + CGFloat result = reciprocalZoomFactor * (1.0f / largerScale); + + return result; +} + //================================================================================== // findSVGElementInElement: //================================================================================== diff --git a/macSVG/SVGDocument Classes/XMLAttributesTableController.m b/macSVG/SVGDocument Classes/XMLAttributesTableController.m index 7f15cf2..d85c2bb 100644 --- a/macSVG/SVGDocument Classes/XMLAttributesTableController.m +++ b/macSVG/SVGDocument Classes/XMLAttributesTableController.m @@ -211,9 +211,15 @@ NSComparisonResult nameSort(id attribute1, id attribute2, void *context) { //[self.xmlAttributesTableView beginUpdates]; - NSInteger rowCount = [self.xmlAttributesTableView.dataSource numberOfRowsInTableView:self.xmlAttributesTableView]; - NSIndexSet * allRowsIndexSet = [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, rowCount)]; - [self.xmlAttributesTableView removeRowsAtIndexes:allRowsIndexSet withAnimation:NO]; + @try { + NSInteger rowCount = [self.xmlAttributesTableView.dataSource numberOfRowsInTableView:self.xmlAttributesTableView]; + NSIndexSet * allRowsIndexSet = [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, rowCount)]; + [self.xmlAttributesTableView removeRowsAtIndexes:allRowsIndexSet withAnimation:NO]; + } @catch (NSException *exception) { + // + } @finally { + // + } //[self.xmlAttributesTableView endUpdates]; } @@ -244,15 +250,22 @@ NSComparisonResult nameSort(id attribute1, id attribute2, void *context) NSTableRowView * tableRowView = [self.xmlAttributesTableView rowViewAtRow:i makeIfNecessary:NO]; if (tableRowView != NULL) { - NSDictionary * attributeRecordDictionary = (self.xmlAttributesArray)[i]; - NSString * attributeName = [attributeRecordDictionary objectForKey:@"name"]; - NSString * attributeValue = [attributeRecordDictionary objectForKey:@"value"]; - - NSTextField * attributeNameTextField = [tableRowView viewAtColumn:0]; - attributeNameTextField.stringValue = attributeName; + if (i < self.xmlAttributesArray.count) + { + NSDictionary * attributeRecordDictionary = (self.xmlAttributesArray)[i]; + NSString * attributeName = [attributeRecordDictionary objectForKey:@"name"]; + NSString * attributeValue = [attributeRecordDictionary objectForKey:@"value"]; + + NSTextField * attributeNameTextField = [tableRowView viewAtColumn:0]; + attributeNameTextField.stringValue = attributeName; - NSTextField * attributeValueTextField = [tableRowView viewAtColumn:1]; - attributeValueTextField.stringValue = attributeValue; + NSTextField * attributeValueTextField = [tableRowView viewAtColumn:1]; + attributeValueTextField.stringValue = attributeValue; + } + else + { + NSLog(@"XMLAttributesTableController reloadData - error on row %ld, xmlAttributesArray.count %ld", i, self.xmlAttributesArray.count); + } } }