This commit has several changes for transform operations.

The new center-of-rotation handle for rotate transform is now interactive in the web view.  You can use the mouse to click-and-drag the center-of-rotation handle, with live updates displayed for the rotated objects.

Some partial support is added for drawing tools to create objects into a selected group with the group's current transform, initially the path, polyline, polygon and line drawing tools.  The rect, circle, ellipse, text and image elements remain to be done in a future commit.  For most objects, editing an existing objects should use transforms better now.
This commit is contained in:
dsward2
2017-10-13 23:54:50 -05:00
committed by dsward2
parent 268e5936f7
commit df522aa843
18 changed files with 444 additions and 268 deletions
@@ -298,7 +298,9 @@
NSString * pathIDAttributeString = pathIDAttributeNode.stringValue;
NSString * pathLengthFunction = [NSString stringWithFormat:
@"function f() {var path = document.getElementById('%@'); return path.getTotalLength();} f();",
//@"function f() {var path = document.getElementById('%@'); return path.getTotalLength();} f();",
//@"function f() {var pathLength = 0; var path = document.getElementById('%@'); if (typeof path !== 'undefined') { pathLength = path.getTotalLength(); } return pathLength;} f();",
@"function f() {var pathLength = 0; var path = document.getElementById('%@'); if (typeof path !== null) { pathLength = path.getTotalLength(); } return pathLength;} f();",
pathIDAttributeString];
NSString * totalLengthString = [self.svgWebView stringByEvaluatingJavaScriptFromString:pathLengthFunction];
@@ -955,7 +955,9 @@ height=\"269px\" viewBox=\"0 0 744 744\" preserveAspectRatio=\"xMidYMid meet\">"
NSString * pathIDAttributeString = pathIDAttributeNode.stringValue;
NSString * pathLengthFunction = [NSString stringWithFormat:
@"function f() {var path = document.getElementById('%@'); return path.getTotalLength();} f();",
//@"function f() {var path = document.getElementById('%@'); return path.getTotalLength();} f();",
//@"function f() {var pathLength = 0; var path = document.getElementById('%@'); if (typeof path !== 'undefined') { pathLength = path.getTotalLength(); } return pathLength;} f();",
@"function f() {var pathLength = 0; var path = document.getElementById('%@'); if (typeof path !== null) { pathLength = path.getTotalLength(); } return pathLength;} f();",
pathIDAttributeString];
NSString * totalLengthString = [textPathPreviewWebView stringByEvaluatingJavaScriptFromString:pathLengthFunction];
@@ -44,7 +44,7 @@
NSPoint clickPoint;
NSPoint currentMousePoint;
NSPoint previousMousePoint;
DOMNode * clickTarget;
DOMElement * clickTarget;
BOOL selectionHandleClicked;
NSString * handle_orientation; // static string, e.g. @"topLeft"
@@ -1231,7 +1231,8 @@ float getAngleABC( NSPoint a, NSPoint b, NSPoint c )
if ([selectedFunction isEqualToString:@"rotate"] == YES)
{
NSString * degreesString = rotateTransformDictionary[@"degrees"];
// for rotate transforms, add editing handle for center of rotation
//NSString * degreesString = rotateTransformDictionary[@"degrees"];
NSString * xString = rotateTransformDictionary[@"x"];
NSString * yString = rotateTransformDictionary[@"y"];
@@ -1247,7 +1248,7 @@ float getAngleABC( NSPoint a, NSPoint b, NSPoint c )
CGFloat x = xString.floatValue;
CGFloat y = yString.floatValue;
NSString * handleName = @"_macsvg_center_of_rotation";
[self.macSVGPluginCallbacks addPluginSelectionHandleWithDOMElement:aDomElement
@@ -1395,8 +1396,9 @@ float getAngleABC( NSPoint a, NSPoint b, NSPoint c )
//NSLog(@"rotate a=%f,%f b=%f,%f c=%f,%f", pointA.x, pointA.y, pointB.x, pointB.y, pointC.x, pointC.y);
handleDegrees = getAngleABC(pointA, pointB, pointC);
CGFloat angleDegrees = getAngleABC(pointA, pointB, pointC);
handleDegrees = angleDegrees - degreesString.floatValue; // angle between handle and top handle
}
@@ -1414,47 +1416,67 @@ float getAngleABC( NSPoint a, NSPoint b, NSPoint c )
{
NSMutableDictionary * rotateDictionary = (self.transformsArray)[selectedRow];
NSString * xString = [rotateDictionary objectForKey:@"x"];
NSString * yString = [rotateDictionary objectForKey:@"y"];
//DOMElement * pluginHandleElement = event.target;
NSPoint pointA = NSMakePoint(xString.floatValue, yString.floatValue - 1000);
pointA = [self translatePoint:pointA targetElement:self.pluginTargetDOMElement.parentElement];
NSPoint pointB = NSMakePoint(xString.floatValue, yString.floatValue);
pointB = [self translatePoint:pointB targetElement:self.pluginTargetDOMElement.parentElement];
NSString * handleOrientation = [clickTarget getAttribute:@"_macsvg_handle_orientation"]; // use target from mousedown event
NSPoint pointC = [self translatePoint:currentMousePoint targetElement:self.pluginTargetDOMElement.parentElement];
//NSLog(@"rotate a=%f,%f b=%f,%f c=%f,%f", pointA.x, pointA.y, pointB.x, pointB.y, pointC.x, pointC.y);
float newHandleDegrees = getAngleABC(pointA, pointB, pointC);
float rotateDegrees = newHandleDegrees - handleDegrees;
if (mouseMoveCount == 1)
if ([handleOrientation isEqualToString:@"plugin"] == YES)
{
[self.macSVGPluginCallbacks pushUndoRedoDocumentChanges];
}
// update the positions of the selected SVG elements
DOMElement * aSvgElement = self.pluginTargetDOMElement;
NSString * elementName = aSvgElement.nodeName;
if ((self.validElementsForTransformDictionary)[elementName] != NULL)
{
NSString * transformAttributeString = [aSvgElement getAttribute:@"transform"];
if ((transformAttributeString != NULL))
{
NSString * newDegreeString = [self allocFloatString:rotateDegrees];
rotateDictionary[@"degrees"] = newDegreeString;
value1TextField.stringValue = newDegreeString;
}
NSString * xString = [self allocFloatString:currentMousePoint.x];
NSString * yString = [self allocFloatString:currentMousePoint.y];
rotateDictionary[@"x"] = xString;
rotateDictionary[@"y"] = yString;
value2TextField.stringValue = xString;
value3TextField.stringValue = yString;
[self setTransformAttribute];
}
else
{
NSString * xString = [rotateDictionary objectForKey:@"x"]; // center of rotation
NSString * yString = [rotateDictionary objectForKey:@"y"];
NSPoint pointA = NSMakePoint(xString.floatValue, yString.floatValue - 1000);
pointA = [self translatePoint:pointA targetElement:self.pluginTargetDOMElement.parentElement];
NSPoint pointB = NSMakePoint(xString.floatValue, yString.floatValue);
pointB = [self translatePoint:pointB targetElement:self.pluginTargetDOMElement.parentElement];
NSPoint pointC = [self translatePoint:currentMousePoint targetElement:self.pluginTargetDOMElement.parentElement];
//NSLog(@"rotate a=%f,%f b=%f,%f c=%f,%f", pointA.x, pointA.y, pointB.x, pointB.y, pointC.x, pointC.y);
float newHandleDegrees = getAngleABC(pointA, pointB, pointC);
float rotateDegrees = newHandleDegrees - handleDegrees;
if (mouseMoveCount == 1)
{
[self.macSVGPluginCallbacks pushUndoRedoDocumentChanges];
}
// update the positions of the selected SVG elements
DOMElement * aSvgElement = self.pluginTargetDOMElement;
NSString * elementName = aSvgElement.nodeName;
if ((self.validElementsForTransformDictionary)[elementName] != NULL)
{
NSString * transformAttributeString = [aSvgElement getAttribute:@"transform"];
if ((transformAttributeString != NULL))
{
NSString * newDegreeString = [self allocFloatString:rotateDegrees];
rotateDictionary[@"degrees"] = newDegreeString;
value1TextField.stringValue = newDegreeString;
}
[self setTransformAttribute];
}
}
}
}
@@ -2118,6 +2140,7 @@ float getAngleABC( NSPoint a, NSPoint b, NSPoint c )
mouseMode = MOUSE_DRAGGING;
DOMElement * eventTargetElement = event.target;
clickTarget = eventTargetElement;
DOMMouseEvent * mouseEvent = (DOMMouseEvent *)event;
@@ -2128,7 +2151,7 @@ float getAngleABC( NSPoint a, NSPoint b, NSPoint c )
//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;
@@ -2169,7 +2192,6 @@ float getAngleABC( NSPoint a, NSPoint b, NSPoint c )
handle_orientation = NULL;
NSString * newHandleOrientation = [eventTargetElement getAttribute:@"_macsvg_handle_orientation"];
// assign a static value to handle_orientation
if ([newHandleOrientation isEqualToString:@"top"] == YES)
{
handle_orientation = @"top";
@@ -2301,8 +2323,6 @@ float getAngleABC( NSPoint a, NSPoint b, NSPoint c )
CGFloat zoomFactor = [self.macSVGPluginCallbacks scaleForDOMElementHandles:targetElement];
[event preventDefault];
[event stopPropagation];
@@ -590,5 +590,4 @@
// override to customize handles for plugin
}
@end
+1 -1
View File
@@ -105,7 +105,7 @@
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>0926</string>
<string>1008</string>
<key>LSApplicationCategoryType</key>
<string>public.app-category.graphics-design</string>
<key>LSMinimumSystemVersion</key>
@@ -75,4 +75,6 @@ enum {
-(void) handleCrosshairToolSelectionForLineXMLElement:(NSXMLElement *)polylineXMLElement
handleDOMElement:(DOMElement *)handleDOMElement;
-(NSPoint) translatePoint:(NSPoint)aMousePoint targetElement:(DOMElement *)targetElement;
@end
@@ -50,9 +50,9 @@
{
// Initialization code here.
self.mouseMode = MOUSE_DISENGAGED;
self.clickPoint = NSMakePoint(0, 0);
self.currentMousePoint = self.clickPoint;
self.previousMousePoint = self.clickPoint;
self.clickPoint = NSZeroPoint;
self.currentMousePoint = NSZeroPoint;
self.previousMousePoint = NSZeroPoint;
self.clickTarget = NULL;
mouseMoveCount = 0;
selectionHandleClicked = NO;
@@ -297,9 +297,11 @@
}
NSUInteger pointsArrayCount = pointsArray.count;
NSPoint translatedCurrentMousePoint = [self translatePoint:self.currentMousePoint targetElement:polylineElement.parentElement];
NSString * newXString = [self allocFloatString:self.currentMousePoint.x];
NSString * newYString = [self allocFloatString:self.currentMousePoint.y];
NSString * newXString = [self allocFloatString:translatedCurrentMousePoint.x];
NSString * newYString = [self allocFloatString:translatedCurrentMousePoint.y];
pointsArray[(pointsArrayCount - 2)] = newXString;
pointsArray[(pointsArrayCount - 1)] = newYString;
@@ -1326,24 +1328,49 @@
[domSelectionControlsManager removeDOMSelectionRectsAndHandles];
[macSVGDocument pushUndoRedoDocumentChanges];
//NSXMLElement * newXMLElement = [macSVGDocument createElement:newElementTagName atPoint:self.clickPoint];
NSXMLElement * newXMLElement = [macSVGDocument createElement:newElementTagName atPoint:self.clickPoint];
NSPoint translatedClickPoint = self.clickPoint;
if ([newElementTagName isEqualToString:@"line"] == YES)
{
NSXMLElement * tempLineElement = [[NSXMLElement alloc] initWithName:@"line"];
NSDictionary * parentDictionary = [macSVGDocument validParentForNewElement:tempLineElement];
if (parentDictionary != NULL)
{
NSXMLElement * parentXMLElement = parentDictionary[@"parentElement"];
NSXMLNode * parentMacsvgidAttribute = [parentXMLElement attributeForName:@"macsvgid"];
NSString * parentMacsvgid = parentMacsvgidAttribute.stringValue;
DOMElement * parentDOMElement = [svgWebKitController domElementForMacsvgid:parentMacsvgid];
translatedClickPoint = [self translatePoint:self.clickPoint targetElement:parentDOMElement];
}
}
NSXMLElement * newXMLElement = [macSVGDocument createElement:newElementTagName atPoint:translatedClickPoint];
if (newXMLElement != NULL)
{
NSXMLElement * parentXMLElement = (NSXMLElement *)newXMLElement.parent;
NSXMLNode * parentMacsvgidNode = [parentXMLElement attributeForName:@"macsvgid"];
NSString * parentMacsvgid = parentMacsvgidNode.stringValue;
DOMElement * parentDOMElement = [svgWebKitController domElementForMacsvgid:parentMacsvgid];
[self.svgXMLDOMSelectionManager selectXMLElement:newXMLElement];
if (currentToolMode == toolModePath)
{
[self.svgPathEditor startPath]; // set the moveto path segment
[self.svgPathEditor startPathWithParentDOMElement:parentDOMElement]; // set the moveto path segment
}
else if (currentToolMode == toolModePolyline)
{
[self.svgPolylineEditor startPolyline];
[self.svgPolylineEditor startPolylineWithParentDOMElement:parentDOMElement];
}
else if (currentToolMode == toolModePolygon)
{
[self.svgPolylineEditor startPolyline];
[self.svgPolylineEditor startPolylineWithParentDOMElement:parentDOMElement];
}
self.svgXMLDOMSelectionManager.activeXMLElement = newXMLElement;
@@ -1375,7 +1402,7 @@
-(void) dragHandleForDOMElement:(DOMElement *)aDomElement
{
//NSLog(@"dragHandleForDOMElement:%@", aDomElement);
NSString * tagName = aDomElement.tagName;
NSString * elementName = aDomElement.nodeName;
@@ -1391,10 +1418,22 @@
NSString * widthString = [aDomElement getAttribute:@"width"];
NSString * heightString = [aDomElement getAttribute:@"height"];
NSPoint xyPoint = NSMakePoint(xString.floatValue, yString.floatValue);
NSPoint sizePoint = NSMakePoint(widthString.floatValue, heightString.floatValue);
NSPoint translatedXyPoint = [self translatePoint:xyPoint targetElement:aDomElement];
NSPoint translatedSizePoint = [self translatePoint:sizePoint targetElement:aDomElement];
NSString * translatedXString = [self allocPxString:translatedXyPoint.x];
NSString * translatedYString = [self allocPxString:translatedXyPoint.y];
NSString * translatedWidthString = [self allocPxString:translatedSizePoint.x];
NSString * translatedHeightString = [self allocPxString:translatedSizePoint.y];
if ((xString != NULL) && (yString != NULL) &&
(widthString != NULL) && (heightString != NULL) &&
(handle_orientation != NULL))
{
// clicked in selection handle for rect, image or foreignObject element
float x = xString.floatValue;
float y = yString.floatValue;
float width = widthString.floatValue;
@@ -1402,7 +1441,6 @@
float deltaX = self.currentMousePoint.x - x;
float deltaY = self.currentMousePoint.y - y;
if ([handle_orientation isEqualToString:@"left"] == YES)
{
@@ -1606,8 +1644,7 @@
[macSVGDocumentWindowController reloadAttributesTableData];
}
if ([tagName isEqualToString:@"circle"] == YES)
else if ([tagName isEqualToString:@"circle"] == YES)
{
NSString * cxString = [aDomElement getAttribute:@"cx"];
NSString * cyString = [aDomElement getAttribute:@"cy"];
@@ -1749,8 +1786,7 @@
[macSVGDocumentWindowController reloadAttributesTableData];
}
if ([tagName isEqualToString:@"ellipse"] == YES)
else if ([tagName isEqualToString:@"ellipse"] == YES)
{
NSString * cxString = [aDomElement getAttribute:@"cx"];
NSString * cyString = [aDomElement getAttribute:@"cy"];
@@ -1886,31 +1922,30 @@
[macSVGDocumentWindowController reloadAttributesTableData];
}
if ([tagName isEqualToString:@"line"] == YES)
else if ([tagName isEqualToString:@"line"] == YES)
{
}
if ([tagName isEqualToString:@"polyline"] == YES)
else if ([tagName isEqualToString:@"polyline"] == YES)
{
}
if ([tagName isEqualToString:@"polygon"] == YES)
else if ([tagName isEqualToString:@"polygon"] == YES)
{
}
if ([tagName isEqualToString:@"path"] == YES)
else if ([tagName isEqualToString:@"path"] == YES)
{
}
else
{
}
// apply update selection rectangles
// TEST 20130709
NSUInteger currentToolMode = macSVGDocumentWindowController.currentToolMode;
if (currentToolMode != toolModeCrosshairCursor)
{
[domSelectionControlsManager updateDOMSelectionRectsAndHandles];
}
}
}
//==================================================================================
@@ -2090,6 +2125,16 @@
DOMElement * updateDOMElement = [self.svgXMLDOMSelectionManager activeDOMElement];
CGFloat zoomFactor = svgWebView.zoomFactor;
DOMMouseEvent * mouseEvent = (DOMMouseEvent *)event;
self.currentMousePoint = NSMakePoint((float)mouseEvent.pageX * (1.0f / zoomFactor), (float)mouseEvent.pageY * (1.0f / zoomFactor));
if (updateDOMElement != NULL)
{
// update the element, projected to current mouse position
@@ -2104,13 +2149,13 @@
if (objectWidth < 0)
{
objectOriginX = self.currentMousePoint.x;
objectWidth = self.clickPoint.x - self.currentMousePoint.x;
objectWidth = fabs(self.clickPoint.x - self.currentMousePoint.x);
}
if (objectHeight < 0)
{
objectOriginY = self.currentMousePoint.y;
objectHeight = self.clickPoint.y - self.currentMousePoint.y;
objectHeight = fabs(self.clickPoint.y - self.currentMousePoint.y);
}
NSUInteger currentToolMode = macSVGDocumentWindowController.currentToolMode;
@@ -2201,9 +2246,10 @@
}
case toolModeLine:
{
/*
float diffx = self.currentMousePoint.x - self.clickPoint.x;
float diffy = self.currentMousePoint.y - self.clickPoint.y;
NSString * x2String = [self allocPxString:self.currentMousePoint.x];
NSString * y2String = [self allocPxString:self.currentMousePoint.y];
@@ -2212,6 +2258,23 @@
objectWidth = diffx;
objectHeight = diffy;
*/
NSPoint translatedCurrentMousePoint = [self translatePoint:self.currentMousePoint targetElement:updateDOMElement];
NSPoint translatedClickPoint = [self translatePoint:self.clickPoint targetElement:updateDOMElement];
float diffx = translatedCurrentMousePoint.x - translatedClickPoint.x;
float diffy = translatedCurrentMousePoint.y - translatedClickPoint.y;
NSString * x2String = [self allocPxString:translatedCurrentMousePoint.x];
NSString * y2String = [self allocPxString:translatedCurrentMousePoint.y];
[updateDOMElement setAttribute:@"x2" value:x2String];
[updateDOMElement setAttribute:@"y2" value:y2String];
objectWidth = diffx;
objectHeight = diffy;
break;
}
case toolModePolyline:
@@ -2341,9 +2404,9 @@
DOMMouseEvent * mouseEvent = (DOMMouseEvent *)event;
self.previousMousePoint = self.currentMousePoint;
CGFloat zoomFactor = svgWebView.zoomFactor;
self.currentMousePoint = NSMakePoint(mouseEvent.pageX * (1.0f / zoomFactor), mouseEvent.pageY * (1.0f / zoomFactor));
NSPoint newCurrentMousePoint = NSMakePoint(mouseEvent.pageX * (1.0f / zoomFactor), mouseEvent.pageY * (1.0f / zoomFactor));
self.currentMousePoint = [self translatePoint:self.currentMousePoint targetElement:targetElement];
self.currentMousePoint = [self translatePoint:newCurrentMousePoint targetElement:targetElement];
[event preventDefault];
[event stopPropagation];
@@ -2475,9 +2538,9 @@
DOMMouseEvent * mouseEvent = (DOMMouseEvent *)event;
self.previousMousePoint = self.currentMousePoint;
CGFloat zoomFactor = svgWebView.zoomFactor;
self.currentMousePoint = NSMakePoint(mouseEvent.pageX * (1.0f / zoomFactor), mouseEvent.pageY * (1.0f / zoomFactor));
NSPoint newCurrentMousePoint = NSMakePoint(mouseEvent.pageX * (1.0f / zoomFactor), mouseEvent.pageY * (1.0f / zoomFactor));
self.currentMousePoint = [self translatePoint:self.currentMousePoint targetElement:targetElement];
self.currentMousePoint = [self translatePoint:newCurrentMousePoint targetElement:targetElement];
[event preventDefault];
[event stopPropagation];
@@ -2534,9 +2597,9 @@
DOMMouseEvent * mouseEvent = (DOMMouseEvent *)event;
self.previousMousePoint = self.currentMousePoint;
CGFloat zoomFactor = svgWebView.zoomFactor;
self.currentMousePoint = NSMakePoint(mouseEvent.pageX * (1.0f / zoomFactor), mouseEvent.pageY * (1.0f / zoomFactor));
NSPoint newCurrentMousePoint = NSMakePoint(mouseEvent.pageX * (1.0f / zoomFactor), mouseEvent.pageY * (1.0f / zoomFactor));
self.currentMousePoint = [self translatePoint:self.currentMousePoint targetElement:targetElement];
self.currentMousePoint = [self translatePoint:newCurrentMousePoint targetElement:targetElement];
[event preventDefault];
[event stopPropagation];
@@ -55,6 +55,7 @@
- (DOMElement *)getMacsvgTopGroupChildByID:(NSString *)idString createIfNew:(BOOL)createIfNew;
- (void)setMacsvgTopGroupChild:(DOMElement *)childElement;
- (void)removeMacsvgTopGroupChildByID:(NSString *)idString;
- (void)removeMacsvgTopGroupChildByClass:(NSString *)classString;
- (void)addPluginSelectionHandleWithDOMElement:(DOMElement *)aDomElement
handlesGroup:(DOMElement *)newSelectionHandlesGroup
@@ -268,6 +268,51 @@
}
}
//==================================================================================
// removeMacsvgTopGroupChildByClass:
//==================================================================================
- (void)removeMacsvgTopGroupChildByClass:(NSString *)classString
{
DOMElement * macsvgTopGroupElement = [self macsvgTopGroupElement];
DOMNodeList * childNodes = macsvgTopGroupElement.childNodes;
unsigned int childCount = childNodes.length;
BOOL searchCompleted = NO;
for (int i = 0; i < childCount; i++)
{
DOMNode * aChildNode = [childNodes item:i];
unsigned short childNodeType = aChildNode.nodeType;
if (childNodeType == DOM_ELEMENT_NODE)
{
DOMElement * aChildElement = (DOMElement *)aChildNode;
NSString * childClassesString = [aChildElement getAttribute:@"class"];
NSArray * childClassesArray = [childClassesString componentsSeparatedByString:@" "];
for (NSString * childClassString in childClassesArray)
{
if ([classString isEqualToString:childClassString] == YES)
{
[aChildElement.parentElement removeChild:aChildElement];
searchCompleted = YES;
break;
}
}
if (searchCompleted == YES)
{
break;
}
}
}
}
//==================================================================================
// copyChildAnimationFromDOMElement:toDOMElement:
//==================================================================================
@@ -1111,11 +1156,11 @@
// inject new selectionHandlesGroup into DOM
//[svgElement appendChild:newSelectionHandlesGroup]; // test 20160904 - moved to end
DOMElement * handleParentElement = NULL;
if (aDomElement != NULL)
{
DOMElement * handleParentElement = NULL;
NSString * elementName = aDomElement.nodeName;
NSString * validSVGLocatableName = (self.validElementsForTransformDictionary)[elementName];
@@ -1348,8 +1393,12 @@
//NSLog(@"makeDOMSelectionHandles aDomElement is NULL");
}
[self addPluginSelectionHandlesWithDOMElement:aDomElement handlesGroup:newSelectionHandlesGroup];
//[self addPluginSelectionHandlesWithDOMElement:aDomElement handlesGroup:newSelectionHandlesGroup];
if (handleParentElement != NULL)
{
[self addPluginSelectionHandlesWithDOMElement:aDomElement handlesGroup:handleParentElement];
}
// inject new selectionHandlesGroup into DOM
//[svgElement appendChild:newSelectionHandlesGroup]; // test 20160904 - moved to end
@@ -1373,7 +1422,7 @@
}
//==================================================================================
// addPluginSelectionHandlesWithDOMElement:handlesGroup:x:y:handleName:
// addPluginSelectionHandleWithDOMElement:handlesGroup:x:y:handleName:
//==================================================================================
- (void)addPluginSelectionHandleWithDOMElement:(DOMElement *)aDomElement
@@ -73,13 +73,18 @@
{
MacSVGPlugin * currentPlugin = NULL;
if ([_currentEditorKind isEqualToString:@"attribute"] == YES)
NSInteger editorPanelFrameViewSubviewsCount = self.editorPanelFrameView.subviews.count;
if (editorPanelFrameViewSubviewsCount > 0)
{
currentPlugin = self.attributeEditorPlugInController.currentPlugin;
}
else if ([_currentEditorKind isEqualToString:@"element"] == YES)
{
currentPlugin = self.elementEditorPlugInController.currentPlugin;
if ([_currentEditorKind isEqualToString:@"attribute"] == YES)
{
currentPlugin = self.attributeEditorPlugInController.currentPlugin;
}
else if ([_currentEditorKind isEqualToString:@"element"] == YES)
{
currentPlugin = self.elementEditorPlugInController.currentPlugin;
}
}
return currentPlugin;
+48 -29
View File
@@ -20,6 +20,7 @@
#import "SelectedElementsManager.h"
#import "NetworkConnectionManager.h"
#import "SVGWebView.h"
#import "DOMMouseEventsController.h"
@implementation MacSVGDocument
@@ -1270,8 +1271,7 @@ style=\"zoom: 1;\">";
attributesDictionary[@"fill"] = fillColorString;
attributesDictionary[@"transform"] = @"";
}
if ([tagName isEqualToString:@"circle"] == YES)
else if ([tagName isEqualToString:@"circle"] == YES)
{
attributesDictionary[@"id"] = elementID;
attributesDictionary[@"cx"] = xString;
@@ -1282,8 +1282,7 @@ style=\"zoom: 1;\">";
attributesDictionary[@"fill"] = fillColorString;
attributesDictionary[@"transform"] = @"";
}
if ([tagName isEqualToString:@"ellipse"] == YES)
else if ([tagName isEqualToString:@"ellipse"] == YES)
{
attributesDictionary[@"id"] = elementID;
attributesDictionary[@"cx"] = xString;
@@ -1295,8 +1294,7 @@ style=\"zoom: 1;\">";
attributesDictionary[@"fill"] = fillColorString;
attributesDictionary[@"transform"] = @"";
}
if ([tagName isEqualToString:@"line"] == YES)
else if ([tagName isEqualToString:@"line"] == YES)
{
attributesDictionary[@"id"] = elementID;
attributesDictionary[@"x1"] = xString;
@@ -1307,8 +1305,23 @@ style=\"zoom: 1;\">";
attributesDictionary[@"stroke-width"] = strokeWidthString;
attributesDictionary[@"transform"] = @"";
}
if ([tagName isEqualToString:@"polyline"] == YES)
else if ([tagName isEqualToString:@"polyline"] == YES)
{
attributesDictionary[@"id"] = elementID;
NSString * x1String = [self allocFloatString:aPoint.x];
NSString * y1String = [self allocFloatString:aPoint.y];
NSString * pointsString = [[NSString alloc] initWithFormat:
@"%@,%@ %@,%@", x1String, y1String, x1String, y1String];
attributesDictionary[@"points"] = pointsString;
attributesDictionary[@"stroke"] = strokeColorString;
attributesDictionary[@"stroke-width"] = strokeWidthString;
attributesDictionary[@"fill"] = fillColorString;
attributesDictionary[@"transform"] = @"";
}
else if ([tagName isEqualToString:@"polygon"] == YES)
{
attributesDictionary[@"id"] = elementID;
NSString * x1String = [self allocFloatString:aPoint.x];
@@ -1322,23 +1335,7 @@ style=\"zoom: 1;\">";
attributesDictionary[@"fill"] = fillColorString;
attributesDictionary[@"transform"] = @"";
}
if ([tagName isEqualToString:@"polygon"] == YES)
{
attributesDictionary[@"id"] = elementID;
NSString * x1String = [self allocFloatString:aPoint.x];
NSString * y1String = [self allocFloatString:aPoint.y];
NSString * pointsString = [[NSString alloc] initWithFormat:
@"%@,%@ %@,%@", x1String, y1String, x1String, y1String];
attributesDictionary[@"points"] = pointsString;
attributesDictionary[@"stroke"] = strokeColorString;
attributesDictionary[@"stroke-width"] = strokeWidthString;
attributesDictionary[@"fill"] = fillColorString;
attributesDictionary[@"transform"] = @"";
}
if ([tagName isEqualToString:@"path"] == YES)
else if ([tagName isEqualToString:@"path"] == YES)
{
attributesDictionary[@"id"] = elementID;
NSString * x1String = [self allocFloatString:aPoint.x];
@@ -1353,8 +1350,7 @@ style=\"zoom: 1;\">";
attributesDictionary[@"fill"] = fillColorString;
attributesDictionary[@"transform"] = @"";
}
if ([tagName isEqualToString:@"text"] == YES)
else if ([tagName isEqualToString:@"text"] == YES)
{
attributesDictionary[@"id"] = elementID;
attributesDictionary[@"font-family"] = @"Helvetica";
@@ -1372,8 +1368,7 @@ style=\"zoom: 1;\">";
NSString * newTextValue = [NSString stringWithFormat:@"Text Element %@", elementID];
newElement.stringValue = newTextValue;
}
if ([tagName isEqualToString:@"image"] == YES)
else if ([tagName isEqualToString:@"image"] == YES)
{
NSMutableDictionary * imageDictionary = (self.macSVGDocumentWindowController).imageDictionary;
@@ -1452,6 +1447,30 @@ style=\"zoom: 1;\">";
if (parentDictionary != NULL)
{
NSXMLElement * parentElement = parentDictionary[@"parentElement"];
if (([tagName isEqualToString:@"polyline"] == YES) ||
([tagName isEqualToString:@"polyline"] == YES))
{
// transform polyline coordinates
NSXMLNode * parentElementMacsvgidAttributeNode = [parentElement attributeForName:@"macsvgid"];
NSString * parentElementMacsvgid = parentElementMacsvgidAttributeNode.stringValue;
DOMElement * parentDOMElement = [self.macSVGDocumentWindowController.svgWebKitController domElementForMacsvgid:parentElementMacsvgid];
NSPoint transformedPoint = [self.macSVGDocumentWindowController.svgWebKitController.domMouseEventsController translatePoint:aPoint targetElement:parentDOMElement];
NSString * x1String = [self allocFloatString:transformedPoint.x];
NSString * y1String = [self allocFloatString:transformedPoint.y];
NSString * pointsString = [[NSString alloc] initWithFormat:
@"%@,%@ %@,%@", x1String, y1String, x1String, y1String];
attributesDictionary[@"points"] = pointsString;
NSXMLNode * pointsAttributeNode = [[NSXMLNode alloc] initWithKind:NSXMLAttributeKind];
pointsAttributeNode.name = @"points";
pointsAttributeNode.stringValue = pointsString;
[newElement addAttribute:pointsAttributeNode];
}
NSNumber * insertIndexNumber = parentDictionary[@"insertIndex"];
NSUInteger insertIndex = insertIndexNumber.unsignedIntValue;
+1 -1
View File
@@ -33,7 +33,7 @@
@property(assign) NSInteger linePointIndex;
@property(strong) DOMElement * activeHandleDOMElement;
- (void)startLine;
- (void)startLineWithParentDOMElement:(DOMElement *)parentDOMElement;
- (void)editLine;
- (void)updateActiveLineInDOM;
+10 -6
View File
@@ -402,7 +402,8 @@
if (transformValueString.length > 0)
{
DOMElement * transformGroupElement = [domDocument createElementNS:svgNamespace qualifiedName:@"g"];
[transformGroupElement setAttributeNS:NULL qualifiedName:@"id" value:@"_macsvg_line_transform_group"];
NSString * groupIDString = [NSString stringWithFormat:@"_macsvg_line_transform_group-%ld", groupIndex + 1];
[transformGroupElement setAttributeNS:NULL qualifiedName:@"id" value:groupIDString];
[transformGroupElement setAttributeNS:NULL qualifiedName:@"class" value:@"_macsvg_line_transform_group"];
[transformGroupElement setAttributeNS:NULL qualifiedName:@"transform" value:transformValueString];
@@ -520,8 +521,11 @@
if (lineElement != NULL)
{
NSString * newXString = [self allocFloatString:domMouseEventsController.currentMousePoint.x];
NSString * newYString = [self allocFloatString:domMouseEventsController.currentMousePoint.y];
DOMElement * activeDOMElement = [svgXMLDOMSelectionManager activeDOMElement];
NSPoint translatedMousePoint = [domMouseEventsController translatePoint:domMouseEventsController.currentMousePoint targetElement:activeDOMElement];
NSString * newXString = [self allocFloatString:translatedMousePoint.x];
NSString * newYString = [self allocFloatString:translatedMousePoint.y];
if (self.linePointIndex == 0)
{
@@ -550,7 +554,7 @@
removeMacsvgTopGroupChildByID:@"_macsvg_lineHandlesGroup"];
[svgXMLDOMSelectionManager.domSelectionControlsManager
removeMacsvgTopGroupChildByID:@"_macsvg_line_transform_group"];
removeMacsvgTopGroupChildByClass:@"_macsvg_line_transform_group"];
}
//==================================================================================
@@ -567,10 +571,10 @@
}
//==================================================================================
// startLine
// startLineWithParentDOMElement
//==================================================================================
- (void)startLine
- (void)startLineWithParentDOMElement:(DOMElement *)parentDOMElement
{
[self resetLinePoints];
+1 -1
View File
@@ -60,7 +60,7 @@
@property(strong) DOMElement * activeHandleDOMElement;
- (void) startPath;
- (void) startPathWithParentDOMElement:(DOMElement *)parentDOMElement;
- (void) extendPath;
- (void) modifyPath;
- (void) editPath;
+132 -79
View File
@@ -1475,12 +1475,14 @@
}
//==================================================================================
// addHandleForMoveto:segmentIndex:pathHandlesGroup
// addHandleForMoveto:segmentIndex:pathHandlesGroup:pathXMLElement:
//==================================================================================
-(void) addHandleForMoveto:(NSDictionary *)pathSegmentDictionary
segmentIndex:(NSUInteger)segmentIndex pathHandlesGroup:(DOMElement *)pathHandlesGroup
pathXMLElement:(NSXMLElement *)pathXMLElement
{
// path commands M,m
NSString * xString = pathSegmentDictionary[@"x"];
NSString * yString = pathSegmentDictionary[@"y"];
@@ -1559,16 +1561,27 @@
if (isMovetoForCubic == YES)
{
// reflect a control point for the first segment
NSString * x1PxString = [self allocPxString:domMouseEventsController.clickPoint.x];
NSString * y1PxString = [self allocPxString:domMouseEventsController.clickPoint.y];
NSString * x2PxString = [self allocPxString:domMouseEventsController.currentMousePoint.x];
NSString * y2PxString = [self allocPxString:domMouseEventsController.currentMousePoint.y];
NSPoint clickPoint = domMouseEventsController.clickPoint;
NSPoint currentMousePoint = domMouseEventsController.currentMousePoint;
float deltaX = domMouseEventsController.currentMousePoint.x - domMouseEventsController.clickPoint.x;
float deltaY = domMouseEventsController.currentMousePoint.y - domMouseEventsController.clickPoint.y;
NSXMLNode * macsvgidAttributeNode = [pathXMLElement attributeForName:@"macsvgid"];
NSString * pathMacsvgidString = macsvgidAttributeNode.stringValue;
DOMElement * pathDOMElement = [svgWebKitController domElementForMacsvgid:pathMacsvgidString];
clickPoint = [domMouseEventsController translatePoint:clickPoint targetElement:pathDOMElement];
currentMousePoint = [domMouseEventsController translatePoint:currentMousePoint targetElement:pathDOMElement];
float reflectX2 = domMouseEventsController.clickPoint.x - deltaX;
float reflectY2 = domMouseEventsController.clickPoint.y - deltaY;
NSString * x1PxString = [self allocPxString:clickPoint.x];
NSString * y1PxString = [self allocPxString:clickPoint.y];
NSString * x2PxString = [self allocPxString:currentMousePoint.x];
NSString * y2PxString = [self allocPxString:currentMousePoint.y];
float deltaX = currentMousePoint.x - clickPoint.x;
float deltaY = currentMousePoint.y - clickPoint.y;
float reflectX2 = clickPoint.x - deltaX;
float reflectY2 = clickPoint.y - deltaY;
NSString * reflectX2PxString = [self allocPxString:reflectX2];
NSString * reflectY2PxString = [self allocPxString:reflectY2];
@@ -1606,6 +1619,11 @@
handlePoint:@"x2y2"];
[pathHandlesGroup appendChild:handleX2Y2CircleElement];
//NSLog(@"Line 1 %@", handleLine1Element.outerHTML);
//NSLog(@"Line 2 %@", handleLine2Element.outerHTML);
//NSLog(@"x1y1 %@", handleX1Y1CircleElement.outerHTML);
//NSLog(@"x2y2 %@", handleX2Y2CircleElement.outerHTML);
}
}
@@ -1624,6 +1642,7 @@
-(void) addHandleForLineto:(NSDictionary *)pathSegmentDictionary
segmentIndex:(NSUInteger)segmentIndex pathHandlesGroup:(DOMElement *)pathHandlesGroup
pathXMLElement:(NSXMLElement *)pathXMLElement
{
// path commands L,l
@@ -1671,6 +1690,7 @@
-(void) addHandleForHorizontalLineto:(NSDictionary *)pathSegmentDictionary
segmentIndex:(NSUInteger)segmentIndex pathHandlesGroup:(DOMElement *)pathHandlesGroup
pathXMLElement:(NSXMLElement *)pathXMLElement
{
// path commands H,h
NSPoint currentPoint = NSZeroPoint;
@@ -1717,6 +1737,7 @@
-(void) addHandleForVerticalLineto:(NSDictionary *)pathSegmentDictionary
segmentIndex:(NSUInteger)segmentIndex pathHandlesGroup:(DOMElement *)pathHandlesGroup
pathXMLElement:(NSXMLElement *)pathXMLElement
{
// path commands V,v
NSPoint currentPoint = NSZeroPoint;
@@ -1766,6 +1787,7 @@
reflectX1Y1:(BOOL)reflectX1Y1
reflectX2Y2:(BOOL)reflectX2Y2
pathHandlesGroup:(DOMElement *)pathHandlesGroup
pathXMLElement:(NSXMLElement *)pathXMLElement
{
// path commands C,c
@@ -1825,6 +1847,17 @@
float y1 = y1Number.floatValue;
float x2 = x2Number.floatValue; // second curve control point
float y2 = y2Number.floatValue;
NSPoint xyPoint = [domMouseEventsController translatePoint:NSMakePoint(x, y) targetElement:pathHandlesGroup];
NSPoint x1y1Point = [domMouseEventsController translatePoint:NSMakePoint(x1, y1) targetElement:pathHandlesGroup];
NSPoint x2y2Point = [domMouseEventsController translatePoint:NSMakePoint(x2, y2) targetElement:pathHandlesGroup];
x = xyPoint.x;
y = xyPoint.y;
x1 = x1y1Point.x;
y1 = x1y1Point.y;
x2 = x2y2Point.x;
y2 = x2y2Point.y;
NSString * xPxString = [self allocPxString:x];
NSString * yPxString = [self allocPxString:y];
@@ -1833,14 +1866,14 @@
NSString * x2PxString = [self allocPxString:x2];
NSString * y2PxString = [self allocPxString:y2];
NSPoint currentPoint = NSMakePoint(x, y);
NSPoint startPoint = NSMakePoint(x, y);
if (segmentIndex > 0)
{
currentPoint = [self absoluteXYPointAtPathSegmentIndex:(segmentIndex - 1)];
startPoint = [self absoluteXYPointAtPathSegmentIndex:(segmentIndex - 1)];
}
NSString * currentXPxString = [self allocPxString:currentPoint.x];
NSString * currentYPxString = [self allocPxString:currentPoint.y];
NSString * currentXPxString = [self allocPxString:startPoint.x];
NSString * currentYPxString = [self allocPxString:startPoint.y];
NSString * reflectX1PxString = xPxString;
NSString * reflectY1PxString = yPxString;
@@ -1897,11 +1930,11 @@
if (reflectX1Y1 == YES)
{
// draw line to reflected control point for x1, y1
float deltaX = x1 - currentPoint.x;
float deltaY = y1 - currentPoint.y;
float deltaX = x1 - startPoint.x;
float deltaY = y1 - startPoint.y;
float reflectX1 = currentPoint.x - deltaX;
float reflectY1 = currentPoint.y - deltaY;
float reflectX1 = startPoint.x - deltaX;
float reflectY1 = startPoint.y - deltaY;
reflectX1PxString = [self allocPxString:reflectX1];
reflectY1PxString = [self allocPxString:reflectY1];
@@ -1961,6 +1994,7 @@
-(void) addHandleForSmoothCubicCurveto:(NSDictionary *)pathSegmentDictionary
segmentIndex:(NSUInteger)segmentIndex pathHandlesGroup:(DOMElement *)pathHandlesGroup
pathXMLElement:(NSXMLElement *)pathXMLElement
{
// path commands S,s
@@ -2045,6 +2079,7 @@
-(void) addHandleForQuadraticCurveto:(NSDictionary *)pathSegmentDictionary
segmentIndex:(NSUInteger)segmentIndex pathHandlesGroup:(DOMElement *)pathHandlesGroup
pathXMLElement:(NSXMLElement *)pathXMLElement
{
// path commands Q,q
@@ -2131,6 +2166,7 @@
-(void) addHandleForSmoothQuadraticCurveto:(NSDictionary *)pathSegmentDictionary
segmentIndex:(NSUInteger)segmentIndex pathHandlesGroup:(DOMElement *)pathHandlesGroup
pathXMLElement:(NSXMLElement *)pathXMLElement
{
// path commands T,t
@@ -2192,6 +2228,7 @@
-(void) addHandleForEllipicalArc:(NSDictionary *)pathSegmentDictionary
segmentIndex:(NSUInteger)segmentIndex pathHandlesGroup:(DOMElement *)pathHandlesGroup
pathXMLElement:(NSXMLElement *)pathXMLElement
{
// path commands A,a
@@ -2253,6 +2290,7 @@
-(void) addHandleForClosePath:(NSDictionary *)pathSegmentDictionary
segmentIndex:(NSUInteger)segmentIndex pathHandlesGroup:(DOMElement *)pathHandlesGroup
pathXMLElement:(NSXMLElement *)pathXMLElement
{
// path commands Z,z
}
@@ -2417,22 +2455,22 @@
{
case 'M': // moveto
case 'm': // moveto
[self addHandleForMoveto:pathSegmentDictionary segmentIndex:segmentIdx pathHandlesGroup:newPathHandlesGroup];
[self addHandleForMoveto:pathSegmentDictionary segmentIndex:segmentIdx pathHandlesGroup:newPathHandlesGroup pathXMLElement:pathXMLElement];
break;
case 'L': // lineto
case 'l': // lineto
[self addHandleForLineto:pathSegmentDictionary segmentIndex:segmentIdx pathHandlesGroup:newPathHandlesGroup];
[self addHandleForLineto:pathSegmentDictionary segmentIndex:segmentIdx pathHandlesGroup:newPathHandlesGroup pathXMLElement:pathXMLElement];
break;
case 'H': // horizontal lineto
case 'h': // horizontal lineto
[self addHandleForHorizontalLineto:pathSegmentDictionary segmentIndex:segmentIdx pathHandlesGroup:newPathHandlesGroup];
[self addHandleForHorizontalLineto:pathSegmentDictionary segmentIndex:segmentIdx pathHandlesGroup:newPathHandlesGroup pathXMLElement:pathXMLElement];
break;
case 'V': // vertical lineto
case 'v': // vertical lineto
[self addHandleForVerticalLineto:pathSegmentDictionary segmentIndex:segmentIdx pathHandlesGroup:newPathHandlesGroup];
[self addHandleForVerticalLineto:pathSegmentDictionary segmentIndex:segmentIdx pathHandlesGroup:newPathHandlesGroup pathXMLElement:pathXMLElement];
break;
case 'C': // cubic Bezier curveto
@@ -2458,32 +2496,32 @@
[self addHandleForCubicCurveto:pathSegmentDictionary segmentIndex:segmentIdx
reflectX1Y1:reflectX1Y1
reflectX2Y2:reflectX2Y2
pathHandlesGroup:newPathHandlesGroup];
pathHandlesGroup:newPathHandlesGroup pathXMLElement:pathXMLElement];
break;
}
case 'S': // smooth cubic Bezier curveto
case 's': // smooth cubic Bezier curveto
[self addHandleForSmoothCubicCurveto:pathSegmentDictionary segmentIndex:segmentIdx pathHandlesGroup:newPathHandlesGroup];
[self addHandleForSmoothCubicCurveto:pathSegmentDictionary segmentIndex:segmentIdx pathHandlesGroup:newPathHandlesGroup pathXMLElement:pathXMLElement];
break;
case 'Q': // quadratic Bezier curve
case 'q': // quadratic Bezier curve
[self addHandleForQuadraticCurveto:pathSegmentDictionary segmentIndex:segmentIdx pathHandlesGroup:newPathHandlesGroup];
[self addHandleForQuadraticCurveto:pathSegmentDictionary segmentIndex:segmentIdx pathHandlesGroup:newPathHandlesGroup pathXMLElement:pathXMLElement];
break;
case 'T': // smooth quadratic Bezier curve
case 't': // smooth quadratic Bezier curve
[self addHandleForSmoothQuadraticCurveto:pathSegmentDictionary segmentIndex:segmentIdx pathHandlesGroup:newPathHandlesGroup];
[self addHandleForSmoothQuadraticCurveto:pathSegmentDictionary segmentIndex:segmentIdx pathHandlesGroup:newPathHandlesGroup pathXMLElement:pathXMLElement];
break;
case 'A': // elliptical arc
case 'a': // elliptical arc
[self addHandleForEllipicalArc:pathSegmentDictionary segmentIndex:segmentIdx pathHandlesGroup:newPathHandlesGroup];
[self addHandleForEllipicalArc:pathSegmentDictionary segmentIndex:segmentIdx pathHandlesGroup:newPathHandlesGroup pathXMLElement:pathXMLElement];
break;
case 'Z': // closepath
case 'z': // closepath
[self addHandleForClosePath:pathSegmentDictionary segmentIndex:segmentIdx pathHandlesGroup:newPathHandlesGroup];
[self addHandleForClosePath:pathSegmentDictionary segmentIndex:segmentIdx pathHandlesGroup:newPathHandlesGroup pathXMLElement:pathXMLElement];
break;
}
@@ -2505,7 +2543,8 @@
if (transformValueString.length > 0)
{
DOMElement * transformGroupElement = [domDocument createElementNS:svgNamespace qualifiedName:@"g"];
[transformGroupElement setAttributeNS:NULL qualifiedName:@"id" value:@"_macsvg_path_transform_group"];
NSString * groupIDString = [NSString stringWithFormat:@"_macsvg_path_transform_group-%ld", groupIndex + 1];
[transformGroupElement setAttributeNS:NULL qualifiedName:@"id" value:groupIDString];
[transformGroupElement setAttributeNS:NULL qualifiedName:@"class" value:@"_macsvg_path_transform_group"];
[transformGroupElement setAttributeNS:NULL qualifiedName:@"transform" value:transformValueString];
@@ -2956,7 +2995,7 @@
removeMacsvgTopGroupChildByID:@"_macsvg_pathHandlesGroup"];
[svgXMLDOMSelectionManager.domSelectionControlsManager
removeMacsvgTopGroupChildByID:@"_macsvg_path_transform_group"];
removeMacsvgTopGroupChildByClass:@"_macsvg_path_transform_group"];
}
//==================================================================================
@@ -2975,21 +3014,25 @@
}
//==================================================================================
// startPath
// startPathWithParentDOMElement:
//==================================================================================
- (void)startPath
- (void)startPathWithParentDOMElement:(DOMElement *)parentDOMElement
{
// we start paths with an absolute moveto
//NSLog(@"startPath");
[self resetPathSegmentsArray];
NSString * clickXString = [self allocFloatString:domMouseEventsController.clickPoint.x];
NSString * clickYString = [self allocFloatString:domMouseEventsController.clickPoint.y];
NSNumber * clickAbsoluteXNumber = [NSNumber numberWithFloat:domMouseEventsController.clickPoint.x];
NSNumber * clickAbsoluteYNumber = [NSNumber numberWithFloat:domMouseEventsController.clickPoint.y];
NSPoint mouseEventClickPoint = domMouseEventsController.clickPoint;
mouseEventClickPoint = [domMouseEventsController translatePoint:mouseEventClickPoint targetElement:parentDOMElement];
NSString * clickXString = [self allocFloatString:mouseEventClickPoint.x];
NSString * clickYString = [self allocFloatString:mouseEventClickPoint.y];
NSNumber * clickAbsoluteXNumber = [NSNumber numberWithFloat:mouseEventClickPoint.x];
NSNumber * clickAbsoluteYNumber = [NSNumber numberWithFloat:mouseEventClickPoint.y];
NSMutableDictionary * movetoSegmentDictionary = [[NSMutableDictionary alloc] init];
@@ -3325,6 +3368,11 @@ NSPoint bezierMidPoint(NSPoint p0, NSPoint p1, NSPoint p2)
NSString * pathCommandString = pathSegmentDictionary[@"command"];
unichar pathCommand = [pathCommandString characterAtIndex:0];
DOMElement * activeDOMElement = [svgWebKitController.svgXMLDOMSelectionManager activeDOMElement]; // the path element
NSPoint translatedCurrentMousePoint = [domMouseEventsController translatePoint:domMouseEventsController.currentMousePoint targetElement:activeDOMElement];
NSPoint translatedPreviousMousePoint = [domMouseEventsController translatePoint:domMouseEventsController.previousMousePoint targetElement:activeDOMElement];
switch (pathCommand)
{
case 'M': // moveto absolute
@@ -3375,8 +3423,8 @@ NSPoint bezierMidPoint(NSPoint p0, NSPoint p1, NSPoint p2)
float x = xString.floatValue;
float y = yString.floatValue;
float deltaX = domMouseEventsController.currentMousePoint.x - x;
float deltaY = domMouseEventsController.currentMousePoint.y - y;
float deltaX = translatedCurrentMousePoint.x - x;
float deltaY = translatedCurrentMousePoint.y - y;
float newX2 = x - deltaX;
float newY2 = y - deltaY;
@@ -3399,8 +3447,8 @@ NSPoint bezierMidPoint(NSPoint p0, NSPoint p1, NSPoint p2)
float x = xString.floatValue;
float y = yString.floatValue;
float mouseRelX = domMouseEventsController.currentMousePoint.x - currentPathPoint.x;
float mouseRelY = domMouseEventsController.currentMousePoint.y - currentPathPoint.y;
float mouseRelX = translatedCurrentMousePoint.x - currentPathPoint.x;
float mouseRelY = translatedCurrentMousePoint.y - currentPathPoint.y;
float deltaX = x - mouseRelX;
float deltaY = y - mouseRelY;
@@ -3424,8 +3472,8 @@ NSPoint bezierMidPoint(NSPoint p0, NSPoint p1, NSPoint p2)
float x = xString.floatValue;
float y = yString.floatValue;
float deltaX = domMouseEventsController.currentMousePoint.x - x;
float deltaY = domMouseEventsController.currentMousePoint.y - y;
float deltaX = translatedCurrentMousePoint.x - x;
float deltaY = translatedCurrentMousePoint.y - y;
float newX2 = x - deltaX;
float newY2 = y - deltaY;
@@ -3448,8 +3496,8 @@ NSPoint bezierMidPoint(NSPoint p0, NSPoint p1, NSPoint p2)
float x = xString.floatValue;
float y = yString.floatValue;
float mouseRelX = domMouseEventsController.currentMousePoint.x - currentPathPoint.x;
float mouseRelY = domMouseEventsController.currentMousePoint.y - currentPathPoint.y;
float mouseRelX = translatedCurrentMousePoint.x - currentPathPoint.x;
float mouseRelY = translatedCurrentMousePoint.y - currentPathPoint.y;
float deltaX = x - mouseRelX;
float deltaY = y - mouseRelY;
@@ -3473,8 +3521,8 @@ NSPoint bezierMidPoint(NSPoint p0, NSPoint p1, NSPoint p2)
float x1 = x1String.floatValue;
float y1 = y1String.floatValue;
float deltaX = domMouseEventsController.currentMousePoint.x - domMouseEventsController.previousMousePoint.x;
float deltaY = domMouseEventsController.currentMousePoint.y - domMouseEventsController.previousMousePoint.y;
float deltaX = translatedCurrentMousePoint.x - translatedPreviousMousePoint.x;
float deltaY = translatedCurrentMousePoint.y - translatedPreviousMousePoint.y;
float newX1 = x1 - deltaX;
float newY1 = y1 - deltaY;
@@ -3495,8 +3543,8 @@ NSPoint bezierMidPoint(NSPoint p0, NSPoint p1, NSPoint p2)
float x1 = x1String.floatValue;
float y1 = y1String.floatValue;
float deltaX = domMouseEventsController.currentMousePoint.x - domMouseEventsController.previousMousePoint.x;
float deltaY = domMouseEventsController.currentMousePoint.y - domMouseEventsController.previousMousePoint.y;
float deltaX = translatedCurrentMousePoint.x - translatedPreviousMousePoint.x;
float deltaY = translatedCurrentMousePoint.y - translatedPreviousMousePoint.y;
float newX1 = x1 - deltaX;
float newY1 = y1 - deltaY;
@@ -3511,8 +3559,8 @@ NSPoint bezierMidPoint(NSPoint p0, NSPoint p1, NSPoint p2)
}
case 'T': // smooth quadratic curveto absolute
{
NSString * newXString = [self allocFloatString:domMouseEventsController.currentMousePoint.x];
NSString * newYString = [self allocFloatString:domMouseEventsController.currentMousePoint.y];
NSString * newXString = [self allocFloatString:translatedCurrentMousePoint.x];
NSString * newYString = [self allocFloatString:translatedCurrentMousePoint.y];
pathSegmentDictionary[@"x"] = newXString;
pathSegmentDictionary[@"y"] = newYString;
@@ -3527,8 +3575,8 @@ NSPoint bezierMidPoint(NSPoint p0, NSPoint p1, NSPoint p2)
float x = xString.floatValue;
float y = yString.floatValue;
float deltaX = domMouseEventsController.currentMousePoint.x - domMouseEventsController.previousMousePoint.x;
float deltaY = domMouseEventsController.currentMousePoint.y - domMouseEventsController.previousMousePoint.y;
float deltaX = translatedCurrentMousePoint.x - translatedPreviousMousePoint.x;
float deltaY = translatedCurrentMousePoint.y - translatedPreviousMousePoint.y;
float newX = x - deltaX;
float newY = y - deltaY;
@@ -3550,8 +3598,8 @@ NSPoint bezierMidPoint(NSPoint p0, NSPoint p1, NSPoint p2)
float x = xString.floatValue;
float y = yString.floatValue;
float deltaX = domMouseEventsController.currentMousePoint.x - x;
float deltaY = domMouseEventsController.currentMousePoint.y - y;
float deltaX = translatedCurrentMousePoint.x - x;
float deltaY = translatedCurrentMousePoint.y - y;
deltaX = fabs(deltaX);
deltaY = fabs(deltaY);
@@ -3591,8 +3639,8 @@ NSPoint bezierMidPoint(NSPoint p0, NSPoint p1, NSPoint p2)
float x = xString.floatValue;
float y = yString.floatValue;
float deltaX = domMouseEventsController.currentMousePoint.x - x;
float deltaY = domMouseEventsController.currentMousePoint.y - y;
float deltaX = translatedCurrentMousePoint.x - x;
float deltaY = translatedCurrentMousePoint.y - y;
deltaX = fabs(deltaX);
deltaY = fabs(deltaY);
@@ -3794,8 +3842,13 @@ NSPoint bezierMidPoint(NSPoint p0, NSPoint p1, NSPoint p2)
NSString * previousXString = pathSegmentDictionary[@"x"]; // endpoint x
NSString * previousYString = pathSegmentDictionary[@"y"]; // endpoint y
NSString * newXString = [self allocFloatString:domMouseEventsController.currentMousePoint.x];
NSString * newYString = [self allocFloatString:domMouseEventsController.currentMousePoint.y];
DOMElement * activeDOMElement = [svgWebKitController.svgXMLDOMSelectionManager activeDOMElement]; // the path element
NSPoint currentMousePoint = domMouseEventsController.currentMousePoint;
currentMousePoint = [domMouseEventsController translatePoint:currentMousePoint targetElement:activeDOMElement];
NSString * newXString = [self allocFloatString:currentMousePoint.x];
NSString * newYString = [self allocFloatString:currentMousePoint.y];
newPathSegmentDictionary = [[NSMutableDictionary alloc] init];
@@ -3813,8 +3866,8 @@ NSPoint bezierMidPoint(NSPoint p0, NSPoint p1, NSPoint p2)
{
NSPoint currentPathPoint = [self absoluteXYPointAtPathSegmentIndex:self.pathSegmentIndex];
float newRelX = domMouseEventsController.currentMousePoint.x - currentPathPoint.x;
float newRelY = domMouseEventsController.currentMousePoint.y - currentPathPoint.y;
float newRelX = currentMousePoint.x - currentPathPoint.x;
float newRelY = currentMousePoint.y - currentPathPoint.y;
NSString * newRelXString = [self allocFloatString:newRelX];
NSString * newRelYString = [self allocFloatString:newRelY];
@@ -3837,8 +3890,8 @@ NSPoint bezierMidPoint(NSPoint p0, NSPoint p1, NSPoint p2)
if (self.useRelativePathCoordinates == YES)
{
NSPoint currentPathPoint = [self absoluteXYPointAtPathSegmentIndex:self.pathSegmentIndex];
float newRelX = domMouseEventsController.currentMousePoint.x - currentPathPoint.x;
float newRelY = domMouseEventsController.currentMousePoint.y - currentPathPoint.y;
float newRelX = currentMousePoint.x - currentPathPoint.x;
float newRelY = currentMousePoint.y - currentPathPoint.y;
NSString * newRelXString = [self allocFloatString:newRelX];
NSString * newRelYString = [self allocFloatString:newRelY];
@@ -3861,7 +3914,7 @@ NSPoint bezierMidPoint(NSPoint p0, NSPoint p1, NSPoint p2)
if (self.useRelativePathCoordinates == YES)
{
NSPoint currentPathPoint = [self absoluteXYPointAtPathSegmentIndex:self.pathSegmentIndex];
float newRelX = domMouseEventsController.currentMousePoint.x - currentPathPoint.x;
float newRelX = currentMousePoint.x - currentPathPoint.x;
NSString * newRelXString = [self allocFloatString:newRelX];
@@ -3881,7 +3934,7 @@ NSPoint bezierMidPoint(NSPoint p0, NSPoint p1, NSPoint p2)
if (self.useRelativePathCoordinates == YES)
{
NSPoint currentPathPoint = [self absoluteXYPointAtPathSegmentIndex:self.pathSegmentIndex];
float newRelY = domMouseEventsController.currentMousePoint.y - currentPathPoint.y;
float newRelY = currentMousePoint.y - currentPathPoint.y;
NSString * newRelYString = [self allocFloatString:newRelY];
@@ -4029,8 +4082,8 @@ NSPoint bezierMidPoint(NSPoint p0, NSPoint p1, NSPoint p2)
if (self.useRelativePathCoordinates == YES)
{
NSPoint currentPathPoint = [self absoluteXYPointAtPathSegmentIndex:self.pathSegmentIndex];
float newRelX = domMouseEventsController.currentMousePoint.x - currentPathPoint.x;
float newRelY = domMouseEventsController.currentMousePoint.y - currentPathPoint.y;
float newRelX = currentMousePoint.x - currentPathPoint.x;
float newRelY = currentMousePoint.y - currentPathPoint.y;
NSString * newRelXString = [self allocFloatString:newRelX];
NSString * newRelYString = [self allocFloatString:newRelY];
@@ -4053,8 +4106,8 @@ NSPoint bezierMidPoint(NSPoint p0, NSPoint p1, NSPoint p2)
if (self.useRelativePathCoordinates == YES)
{
NSPoint currentPathPoint = [self absoluteXYPointAtPathSegmentIndex:self.pathSegmentIndex];
float newRelX = domMouseEventsController.currentMousePoint.x - currentPathPoint.x;
float newRelY = domMouseEventsController.currentMousePoint.y - currentPathPoint.y;
float newRelX = currentMousePoint.x - currentPathPoint.x;
float newRelY = currentMousePoint.y - currentPathPoint.y;
NSString * newRelXString = [self allocFloatString:newRelX];
NSString * newRelYString = [self allocFloatString:newRelY];
@@ -4091,8 +4144,8 @@ NSPoint bezierMidPoint(NSPoint p0, NSPoint p1, NSPoint p2)
if (self.useRelativePathCoordinates == YES)
{
NSPoint currentPathPoint = [self absoluteXYPointAtPathSegmentIndex:self.pathSegmentIndex];
float newRelX = domMouseEventsController.currentMousePoint.x - currentPathPoint.x;
float newRelY = domMouseEventsController.currentMousePoint.y - currentPathPoint.y;
float newRelX = currentMousePoint.x - currentPathPoint.x;
float newRelY = currentMousePoint.y - currentPathPoint.y;
NSString * newRelXString = [self allocFloatString:newRelX];
NSString * newRelYString = [self allocFloatString:newRelY];
@@ -4121,8 +4174,8 @@ NSPoint bezierMidPoint(NSPoint p0, NSPoint p1, NSPoint p2)
if (self.useRelativePathCoordinates == YES)
{
NSPoint currentPathPoint = [self absoluteXYPointAtPathSegmentIndex:self.pathSegmentIndex];
float newRelX = domMouseEventsController.currentMousePoint.x - currentPathPoint.x;
float newRelY = domMouseEventsController.currentMousePoint.y - currentPathPoint.y;
float newRelX = currentMousePoint.x - currentPathPoint.x;
float newRelY = currentMousePoint.y - currentPathPoint.y;
NSString * newRelXString = [self allocFloatString:newRelX];
NSString * newRelYString = [self allocFloatString:newRelY];
@@ -4151,8 +4204,8 @@ NSPoint bezierMidPoint(NSPoint p0, NSPoint p1, NSPoint p2)
if (self.useRelativePathCoordinates == YES)
{
NSPoint currentPathPoint = [self absoluteXYPointAtPathSegmentIndex:self.pathSegmentIndex];
float newRelX = domMouseEventsController.currentMousePoint.x - currentPathPoint.x;
float newRelY = domMouseEventsController.currentMousePoint.y - currentPathPoint.y;
float newRelX = currentMousePoint.x - currentPathPoint.x;
float newRelY = currentMousePoint.y - currentPathPoint.y;
NSString * newRelXString = [self allocFloatString:newRelX];
NSString * newRelYString = [self allocFloatString:newRelY];
@@ -4177,8 +4230,8 @@ NSPoint bezierMidPoint(NSPoint p0, NSPoint p1, NSPoint p2)
if (self.useRelativePathCoordinates == YES)
{
NSPoint currentPathPoint = [self absoluteXYPointAtPathSegmentIndex:self.pathSegmentIndex];
float newRelX = domMouseEventsController.currentMousePoint.x - currentPathPoint.x;
float newRelY = domMouseEventsController.currentMousePoint.y - currentPathPoint.y;
float newRelX = currentMousePoint.x - currentPathPoint.x;
float newRelY = currentMousePoint.y - currentPathPoint.y;
NSString * newRelXString = [self allocFloatString:newRelX];
NSString * newRelYString = [self allocFloatString:newRelY];
@@ -4245,8 +4298,8 @@ NSPoint bezierMidPoint(NSPoint p0, NSPoint p1, NSPoint p2)
if (self.useRelativePathCoordinates == YES)
{
NSPoint currentPathPoint = [self absoluteXYPointAtPathSegmentIndex:self.pathSegmentIndex];
float newRelX = domMouseEventsController.currentMousePoint.x - currentPathPoint.x;
float newRelY = domMouseEventsController.currentMousePoint.y - currentPathPoint.y;
float newRelX = currentMousePoint.x - currentPathPoint.x;
float newRelY = currentMousePoint.y - currentPathPoint.y;
NSString * newRelXString = [self allocFloatString:newRelX];
NSString * newRelYString = [self allocFloatString:newRelY];
@@ -37,7 +37,7 @@
@property(assign) DOMElement * activeHandleDOMElement;
@property(assign) BOOL highlightSelectedPoint;
- (void)startPolyline;
- (void)startPolylineWithParentDOMElement:(DOMElement *)parentDOMElement;
- (void)editPolyline;
- (void)updateActivePolylineInDOM;
+16 -59
View File
@@ -12,12 +12,9 @@
#import "MacSVGDocumentWindowController.h"
#import "DOMMouseEventsController.h"
#import "SVGXMLDOMSelectionManager.h"
//#import "WebKitInterface.h"
//#import "MacSVGAppDelegate.h"
#import "SelectedElementsManager.h"
#import "ToolSettingsPopoverViewController.h"
#import "EditorUIFrameController.h"
//#import "ElementEditorPluginController.h"
#import "MacSVGPlugin/MacSVGPlugin.h"
#import "MacSVGDocument.h"
#import "DOMSelectionControlsManager.h"
@@ -247,17 +244,18 @@
}
//==================================================================================
// addHandleForPoint:pointIndex:polylineHandlesGroup:
// addHandleForPoint:pointIndex:polylineHandlesGroup:polylineXMLElement:
//==================================================================================
-(void) addHandleForPoint:(NSDictionary *)polylinePointDictionary
pointIndex:(NSUInteger)pointIndex polylineHandlesGroup:(DOMElement *)polylineHandlesGroup
polylineXMLElement:(NSXMLElement *)polylineXMLElement
{
DOMDocument * domDocument = (svgWebKitController.svgWebView).mainFrame.DOMDocument;
NSString * xString = polylinePointDictionary[@"x"];
NSString * yString = polylinePointDictionary[@"y"];
NSString * xPxString = [xString stringByAppendingString:@"px"];
NSString * yPxString = [yString stringByAppendingString:@"px"];
@@ -307,47 +305,6 @@
[polylineHandlesGroup appendChild:handleCircleElement];
}
//==================================================================================
// makePolylineHandles
//==================================================================================
/*
-(void) makePolylineHandles
{
DOMDocument * domDocument = (svgWebKitController.svgWebView).mainFrame.DOMDocument;
DOMSelectionControlsManager * domSelectionControlsManager =
svgXMLDOMSelectionManager.domSelectionControlsManager;
DOMElement * newPolylineHandlesGroup = [domDocument createElementNS:svgNamespace
qualifiedName:@"g"];
[newPolylineHandlesGroup setAttributeNS:NULL qualifiedName:@"id" value:@"_macsvg_polylineHandlesGroup"];
[newPolylineHandlesGroup setAttributeNS:NULL qualifiedName:@"class" value:@"_macsvg_polylineHandlesGroup"];
NSUInteger polylinePointsCount = (self.polylinePointsArray).count;
for (NSUInteger pointIdx = 0; pointIdx < polylinePointsCount; pointIdx++)
{
NSDictionary * polylinePointDictionary = (self.polylinePointsArray)[pointIdx];
[self addHandleForPoint:polylinePointDictionary pointIndex:pointIdx polylineHandlesGroup:newPolylineHandlesGroup];
}
[domSelectionControlsManager setMacsvgTopGroupChild:newPolylineHandlesGroup];
[domSelectionControlsManager highlightPolylinePoint];
if (self.highlightSelectedPoint == YES)
{
[domSelectionControlsManager highlightPolylinePoint];
}
else
{
[domSelectionControlsManager removeDOMPolylinePointHighlight];
}
}
*/
//==================================================================================
// makePolylineHandlesForXMLElement
//==================================================================================
@@ -377,12 +334,10 @@
{
NSDictionary * polylinePointDictionary = (self.polylinePointsArray)[pointIdx];
[self addHandleForPoint:polylinePointDictionary pointIndex:pointIdx polylineHandlesGroup:newPolylineHandlesGroup];
[self addHandleForPoint:polylinePointDictionary pointIndex:pointIdx polylineHandlesGroup:newPolylineHandlesGroup polylineXMLElement:polylineXMLElement];
}
// create parent group elements to match transforms for selected element
// create parent group elements for handles to match transforms for selected element
DOMElement * topGroupChild = newPolylineHandlesGroup;
NSXMLElement * pathParentElement = (NSXMLElement *)polylineXMLElement.parent;
NSInteger groupIndex = 0;
@@ -397,7 +352,8 @@
if (transformValueString.length > 0)
{
DOMElement * transformGroupElement = [domDocument createElementNS:svgNamespace qualifiedName:@"g"];
[transformGroupElement setAttributeNS:NULL qualifiedName:@"id" value:@"_macsvg_polyline_transform_group"];
NSString * groupIDString = [NSString stringWithFormat:@"_macsvg_polyline_transform_group-%ld", groupIndex + 1];
[transformGroupElement setAttributeNS:NULL qualifiedName:@"id" value:groupIDString];
[transformGroupElement setAttributeNS:NULL qualifiedName:@"class" value:@"_macsvg_polyline_transform_group"];
[transformGroupElement setAttributeNS:NULL qualifiedName:@"transform" value:transformValueString];
@@ -458,6 +414,8 @@
- (void)updatePolylineInDOMForElement:(DOMElement *)polylineElement polylinePointsArray:(NSArray *)aPolylinePointsArray
{
//NSLog(@"aPolylinePointsArray %@", aPolylinePointsArray);
NSString * newPointsString = [self buildStringWithPolylinePointsArray:aPolylinePointsArray];
[polylineElement setAttribute:@"points" value:newPointsString];
@@ -611,7 +569,7 @@
removeMacsvgTopGroupChildByID:@"_macsvg_polylineHandlesGroup"];
[svgXMLDOMSelectionManager.domSelectionControlsManager
removeMacsvgTopGroupChildByID:@"_macsvg_polyline_transform_group"];
removeMacsvgTopGroupChildByClass:@"_macsvg_polyline_transform_group"];
}
//==================================================================================
@@ -629,18 +587,17 @@
}
//==================================================================================
// startPolyline
// startPolylineWithParentDOMElement
//==================================================================================
- (void)startPolyline
- (void)startPolylineWithParentDOMElement:(DOMElement *)parentDOMElement
{
// we start paths with an absolute moveto
//NSLog(@"startPath");
[self resetPolylinePointsArray];
NSString * clickXString = [self allocFloatString:domMouseEventsController.clickPoint.x];
NSString * clickYString = [self allocFloatString:domMouseEventsController.clickPoint.y];
NSPoint clickPoint = [domMouseEventsController translatePoint:domMouseEventsController.clickPoint targetElement:parentDOMElement];
NSString * clickXString = [self allocFloatString:clickPoint.x];
NSString * clickYString = [self allocFloatString:clickPoint.y];
NSMutableDictionary * pointDictionary = [[NSMutableDictionary alloc] init];