//add list to combine all in categorized order public SVGelement addLine(point start, point end, string[] matricies) { transformMatrix finalMatrix = transform.combineMatricies(matricies); start = transform.multiplyPointByMatrix(start, finalMatrix); end = transform.multiplyPointByMatrix(end, finalMatrix); return(new SVGline(start, end)); }
public static point multiplyPointByMatrix(point origionalPoint, transformMatrix matricix) { point newPoint = new point(); newPoint.x = matricix.a * origionalPoint.x + matricix.c * origionalPoint.y + matricix.e; newPoint.y = matricix.b * origionalPoint.x + matricix.d * origionalPoint.y + matricix.f; return(newPoint); }
public SVGcurve(point point1, point point2, point handle1, point handle2, transformMatrix transform) { this.point1 = point1; this.point2 = point2; this.handle1 = handle1; this.handle2 = handle2; this.transform = transform; }
public static SVGElementArray path(attributeArray attributeValues) { //0 = d's : 1 = points //takes in d and points to make an SVGElementArray //!!ADD SUPPORT FOR POINTS TO POLYLINE CONVERSION!! SVGElementArray returnElements = new SVGElementArray(); List <char> allCMD = new List <char>(); //transforming string[] matricies = new string[0]; int numTransforms = attributeValues.atributes.Count - allElementAttributes.path.Count(); //seporate the transform matricies from the other attributes for (int transformNum = 0; transformNum < numTransforms; transformNum++) { Array.Resize(ref matricies, matricies.Length + 1); matricies[transformNum] = attributeValues.atributes [allElementAttributes.path.Count() + transformNum]; } transformMatrix finalMatrix = transform.combineMatricies(matricies); string dVal = attributeValues.atributes[0]; string[] seporateDVals = dVal.Split(new char[2] { ' ', ',' }); char CMD = ' '; point handle0 = new point(); point handle1 = new point(); point startPoint = new point(); point currentPoint = new point(); point previousPoint = new point(); QuadCode quadCode = new QuadCode(); List <point> moveTos = new List <point>(); //going through the loop for (int dValIndex = 0; dValIndex < seporateDVals.Length - 1; dValIndex++) { //look for a cmd char firstChar = seporateDVals[dValIndex][0]; if (char.IsLetter(firstChar) == true) { CMD = firstChar; if (seporateDVals[dValIndex].Length > 1) { seporateDVals[dValIndex] = seporateDVals[dValIndex].Substring(1); } else { dValIndex++; } allCMD.Add(CMD); } double firstVal = double.Parse(seporateDVals[dValIndex]); switch (CMD) { case 'M': //move to point absolute startPoint.x = firstVal; dValIndex++; startPoint.y = double.Parse(seporateDVals[dValIndex]); currentPoint = startPoint; moveTos.Add(startPoint); break; case 'm': //move to point relative startPoint.x = currentPoint.x + firstVal; dValIndex++; startPoint.y = currentPoint.y + double.Parse(seporateDVals[dValIndex]); currentPoint = startPoint; moveTos.Add(startPoint); break; case 'L': //line to point absolute currentPoint.x = firstVal; dValIndex++; currentPoint.y = double.Parse(seporateDVals[dValIndex]); returnElements.SVGelement.Add(quadCode.addLine(previousPoint, currentPoint, matricies)); break; case 'l': //line to point relative currentPoint.x += firstVal; dValIndex++; currentPoint.y += double.Parse(seporateDVals[dValIndex]); returnElements.SVGelement.Add(quadCode.addLine(previousPoint, currentPoint, matricies)); break; case 'H': //horizontal line absolute currentPoint.x = firstVal; currentPoint.y = 0; returnElements.SVGelement.Add(quadCode.addLine(previousPoint, currentPoint, matricies)); break; case 'h': //horizontal line relative currentPoint.x += firstVal; returnElements.SVGelement.Add(quadCode.addLine(previousPoint, currentPoint, matricies)); break; case 'V': //vertical line absolute currentPoint.x = 0; currentPoint.y = firstVal; returnElements.SVGelement.Add(quadCode.addLine(previousPoint, currentPoint, matricies)); break; case 'v': //vertical line relative currentPoint.y += firstVal; returnElements.SVGelement.Add(quadCode.addLine(previousPoint, currentPoint, matricies)); break; case 'C': // Cubic bezier curve absolute case 'S': handle0.x = firstVal; dValIndex++; handle0.y = double.Parse(seporateDVals[dValIndex]); dValIndex++; handle1.x = double.Parse(seporateDVals[dValIndex]); dValIndex++; handle1.y = double.Parse(seporateDVals[dValIndex]); dValIndex++; currentPoint.x = double.Parse(seporateDVals[dValIndex]); dValIndex++; currentPoint.y = double.Parse(seporateDVals[dValIndex]); returnElements.SVGelement.Add(quadCode.addCurve(previousPoint, handle0, handle1, currentPoint, matricies)); break; case 'c': // Cubic bezier curve relative case 's': handle0.x = previousPoint.x + firstVal; dValIndex++; handle0.y = previousPoint.y + double.Parse(seporateDVals[dValIndex]); dValIndex++; handle1.x = previousPoint.x + double.Parse(seporateDVals[dValIndex]); dValIndex++; handle1.y = previousPoint.y + double.Parse(seporateDVals[dValIndex]); dValIndex++; currentPoint.x += double.Parse(seporateDVals[dValIndex]); dValIndex++; currentPoint.y += double.Parse(seporateDVals[dValIndex]); returnElements.SVGelement.Add(quadCode.addCurve(previousPoint, handle0, handle1, currentPoint, matricies)); break; case 'Q': // Cubic bezier curve absolute case 'T': handle0.x = firstVal; dValIndex++; handle0.y = double.Parse(seporateDVals[dValIndex]); dValIndex++; currentPoint.x = double.Parse(seporateDVals[dValIndex]); dValIndex++; currentPoint.y = double.Parse(seporateDVals[dValIndex]); returnElements.SVGelement.Add(quadCode.addCurve(previousPoint, handle0, handle0, currentPoint, matricies)); break; case 'q': // Cubic bezier curve relative case 't': handle0.x = previousPoint.x + firstVal; dValIndex++; handle0.y = previousPoint.y + double.Parse(seporateDVals[dValIndex]); dValIndex++; currentPoint.x += double.Parse(seporateDVals[dValIndex]); dValIndex++; currentPoint.y += double.Parse(seporateDVals[dValIndex]); returnElements.SVGelement.Add(quadCode.addCurve(previousPoint, handle0, handle0, currentPoint, matricies)); break; case 'A': //Arcto absolute //???????????????????? break; case 'a': //Arcto relative //???????????????????? break; case 'Z': //closing line to start point case 'z': returnElements.SVGelement.Add(quadCode.addLine(startPoint, currentPoint, matricies)); break; } previousPoint = currentPoint; } if (allCMD.Count == 2) { if (allCMD[0].ToString().ToUpper() == "M" & allCMD[1].ToString().ToUpper() == "Z") { return(Quadify.polylineToQuadLine(moveTos.ToArray(), matricies, true)); } } else if (allCMD.Count == 1) { if (allCMD[0].ToString().ToUpper() == "M") { return(Quadify.polylineToQuadLine(moveTos.ToArray(), matricies, true)); } } return(returnElements); }
public static transformMatrix combineMatricies(string[] matricieStrings) { //NEED TO ADD CODE TO HANDLE MORE THAN "MATRIX(A,B,C,D,E,F)" ADD TRANSLATE, SKEW, SCALE, & ROTATE ///<summary> ///combineMatricies combines the values of many matricie strings into one matrix ///</summary> List <transformMatrix> matricies = new List <transformMatrix>(); for (int matrixNumber = 0; matrixNumber < matricieStrings.Length; matrixNumber++) { //trim off the ) matricieStrings[matrixNumber] = matricieStrings[matrixNumber].TrimEnd(')'); char[] stringSplitChars = { ',', ' ' }; string[] stringVals = matricieStrings[matrixNumber].Split(stringSplitChars); switch (matricieStrings[matrixNumber].Substring(0, 5)) { case "trans": double Xtrans = double.Parse(stringVals[0].Substring(10)); double Ytrans = 0; try { Ytrans = double.Parse(stringVals[1]); } catch { } matricies.Add(new transformMatrix(1, 0, 0, 1, Xtrans, Ytrans)); break; case "skewX": /* | 1 , tan(a) | * skeyX(a) = | 0 , 1 | | 0 , 0 | */ double angleX = double.Parse(stringVals[0].Substring(6)); matricies.Add(new transformMatrix(1, Math.Tan(angleX), 0, 1, 0, 0)); break; case "skewY": /* | 1 , 0 | * skeyX(a) = | tan(a), 1 | | 0 , 0 | */ double angleY = double.Parse(stringVals[0].Substring(6)); matricies.Add(new transformMatrix(1, 0, Math.Tan(angleY), 1, 0, 0)); break; case "scale": double Xscale = double.Parse(stringVals[0].Substring(6)); double Yscale = 0; try { Yscale = double.Parse(stringVals[1]); matricies.Add(new transformMatrix(Xscale, 0, 0, Yscale, 0, 0)); } catch { Yscale = 0; matricies.Add(new transformMatrix(Xscale, 0, 0, Xscale, 0, 0)); } break; case "rotat": /* | 1 , 0 | |cos(a) ,-sin(a)| | 1 , 0 | * rotate(a,x,y) = | 0 , 1 |+|+sin(a) , cos(a)|+| 0 , 1 | | x , y | | 0 , 0 | |-x ,-y | */ double angle = double.Parse(stringVals[0].Substring(7)); double Xorigin = 0; double Yorigin = 0; try { Xorigin = double.Parse(stringVals[1]); Yorigin = double.Parse(stringVals[2]); } catch { } matricies.Add(new transformMatrix(1, 0, 0, 1, Xorigin, Yorigin)); matricies.Add(new transformMatrix(Math.Cos(angle), -Math.Sin(angle), Math.Sin(angle), Math.Cos(angle), 0, 0)); matricies.Add(new transformMatrix(1, 0, 0, 1, -Xorigin, -Yorigin)); break; case "matri": //matrix transformation transformMatrix currentTransformMatrix = new transformMatrix(1, 0, 0, 1, 0, 0); currentTransformMatrix.a = double.Parse(stringVals[0].Substring(7)); currentTransformMatrix.b = double.Parse(stringVals[1]); currentTransformMatrix.c = double.Parse(stringVals[2]); currentTransformMatrix.d = double.Parse(stringVals[3]); currentTransformMatrix.e = double.Parse(stringVals[4]); currentTransformMatrix.f = double.Parse(stringVals[5]); matricies.Add(currentTransformMatrix); break; } } if (matricies.Count >= 1) { //now do the multiplying stuff to make one big matricie transformMatrix previousMatrix = new transformMatrix(1, 0, 0, 1, 0, 0); transformMatrix currentMatrix = new transformMatrix(1, 0, 0, 1, 0, 0); transformMatrix nextMatrix = matricies[0]; for (int matrixNumber = 1; matrixNumber < matricies.Count; matrixNumber++) { previousMatrix = currentMatrix; currentMatrix = matricies[matrixNumber]; /* prev. current next |A,B| |G,H| | GA+IB , HA+JB | |C,D| * |I,J| = | GC+ID , HC+JD | |E,F| |K,L| |GE+IF+K , HE+JF+L| */ nextMatrix.a = currentMatrix.a * previousMatrix.a + currentMatrix.c * previousMatrix.b; nextMatrix.b = currentMatrix.b * previousMatrix.a + currentMatrix.d * previousMatrix.b; nextMatrix.c = currentMatrix.a * previousMatrix.c + currentMatrix.c * previousMatrix.d; nextMatrix.d = currentMatrix.b * previousMatrix.c + currentMatrix.d * previousMatrix.d; nextMatrix.e = currentMatrix.a * previousMatrix.e + currentMatrix.c * previousMatrix.f + currentMatrix.e; nextMatrix.f = currentMatrix.b * previousMatrix.e + currentMatrix.d * previousMatrix.f + currentMatrix.f; currentMatrix = nextMatrix; } return(nextMatrix); } else { return(new transformMatrix(1, 0, 0, 1, 0, 0)); } }
public SVGelement addEllipse(point center, point radius, string[] matricies) { transformMatrix finalMatrix = transform.combineMatricies(matricies); return(new SVGellipse(center, radius, finalMatrix)); }
public SVGelement addCurve(point point1, point point2, point handle1, point handle2, string[] matricies) { transformMatrix finalMatrix = transform.combineMatricies(matricies); return(new SVGcurve(point1, point2, handle1, handle2, finalMatrix)); }
public SVGellipse(point center, point radius, transformMatrix transform) { this.center = center; this.radius = radius; this.transform = transform; }