|
@@ -176,7 +176,10 @@ namespace SketchAssistant
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -205,20 +208,20 @@ namespace SketchAssistant
|
|
if (windowWidth / windowHeight > sizedef.Item1 / sizedef.Item2)
|
|
if (windowWidth / windowHeight > sizedef.Item1 / sizedef.Item2)
|
|
{
|
|
{
|
|
scale = windowHeight / sizedef.Item2;
|
|
scale = windowHeight / sizedef.Item2;
|
|
- Console.WriteLine("scale: (heights) " + windowHeight + "/" + sizedef.Item2);
|
|
+
|
|
- Console.WriteLine("widths: " + windowWidth + "/" + sizedef.Item1);
|
|
+
|
|
height = (int)Math.Round(windowHeight);
|
|
height = (int)Math.Round(windowHeight);
|
|
width = (int) Math.Round(scale * sizedef.Item1);
|
|
width = (int) Math.Round(scale * sizedef.Item1);
|
|
- Console.WriteLine(width + "x" + height + " (" + scale + ")");
|
|
+
|
|
}
|
|
}
|
|
else
|
|
else
|
|
{
|
|
{
|
|
scale = windowWidth / sizedef.Item1;
|
|
scale = windowWidth / sizedef.Item1;
|
|
- Console.WriteLine("scale: (widths) " + windowWidth + "/" + sizedef.Item1);
|
|
+
|
|
- Console.WriteLine("heights: " + windowHeight + "/" + sizedef.Item2);
|
|
+
|
|
width = (int)Math.Round(windowWidth);
|
|
width = (int)Math.Round(windowWidth);
|
|
height = (int)Math.Round(scale * sizedef.Item2);
|
|
height = (int)Math.Round(scale * sizedef.Item2);
|
|
- Console.WriteLine(width + "x" + height + " (" + scale + ")");
|
|
+
|
|
}
|
|
}
|
|
for(int j=0; j < allLines.Length; j++)
|
|
for(int j=0; j < allLines.Length; j++)
|
|
{
|
|
{
|
|
@@ -280,6 +283,7 @@ namespace SketchAssistant
|
|
picture.AddRange(element);
|
|
picture.AddRange(element);
|
|
}
|
|
}
|
|
i++;
|
|
i++;
|
|
|
|
+ if (i > allLines.Length - 1) throw new FileImporterException("unterminated input file: missing </svg> tag", "the file must not contain empty lines", i + 1);
|
|
}
|
|
}
|
|
return picture;
|
|
return picture;
|
|
}
|
|
}
|
|
@@ -292,14 +296,14 @@ namespace SketchAssistant
|
|
private List<Line> ParseSingleSVGElement(string[] allLines)
|
|
private List<Line> ParseSingleSVGElement(string[] allLines)
|
|
{
|
|
{
|
|
String[] currentElement = GetCurrentElement(allLines);
|
|
String[] currentElement = GetCurrentElement(allLines);
|
|
- if (currentElement[currentElement.Length - 1].EndsWith("/>"))
|
|
+
|
|
- {
|
|
+
|
|
return ParseSingleLineSVGElement(currentElement);
|
|
return ParseSingleLineSVGElement(currentElement);
|
|
- }
|
|
+
|
|
- else
|
|
+
|
|
- {
|
|
+
|
|
- return ParseMultiLineSVGElement(currentElement, allLines);
|
|
+
|
|
- }
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -335,8 +339,8 @@ namespace SketchAssistant
|
|
element = parsePath(currentElement);
|
|
element = parsePath(currentElement);
|
|
break;
|
|
break;
|
|
default:
|
|
default:
|
|
- Console.WriteLine("unsupported element: " + currentElement[0] + currentElement[0].Length);
|
|
+
|
|
- return null;
|
|
+ return null;
|
|
}
|
|
}
|
|
if (element == null)
|
|
if (element == null)
|
|
{
|
|
{
|
|
@@ -392,7 +396,7 @@ namespace SketchAssistant
|
|
rect.Add(ScaleAndCreatePoint(x + w, y + h));
|
|
rect.Add(ScaleAndCreatePoint(x + w, y + h));
|
|
rect.Add(ScaleAndCreatePoint(x, y + h));
|
|
rect.Add(ScaleAndCreatePoint(x, y + h));
|
|
rect.Add(ScaleAndCreatePoint(x, y));
|
|
rect.Add(ScaleAndCreatePoint(x, y));
|
|
- Console.WriteLine("parsed point: " + x + ";" + y);
|
|
+
|
|
return rect;
|
|
return rect;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -553,10 +557,10 @@ namespace SketchAssistant
|
|
for (int k = 0; k < points.Length - 1; k+=2)
|
|
for (int k = 0; k < points.Length - 1; k+=2)
|
|
{
|
|
{
|
|
polygon.Add(ScaleAndCreatePoint(Convert.ToDouble(points[k], CultureInfo.InvariantCulture), Convert.ToDouble(points[k+1], CultureInfo.InvariantCulture)));
|
|
polygon.Add(ScaleAndCreatePoint(Convert.ToDouble(points[k], CultureInfo.InvariantCulture), Convert.ToDouble(points[k+1], CultureInfo.InvariantCulture)));
|
|
- Console.WriteLine("parsed point: " + points[k] + ";" + points[k + 1]);
|
|
+
|
|
}
|
|
}
|
|
polygon.Add(ScaleAndCreatePoint(Convert.ToDouble(points[0], CultureInfo.InvariantCulture), Convert.ToDouble(points[1], CultureInfo.InvariantCulture)));
|
|
polygon.Add(ScaleAndCreatePoint(Convert.ToDouble(points[0], CultureInfo.InvariantCulture), Convert.ToDouble(points[1], CultureInfo.InvariantCulture)));
|
|
- Console.WriteLine("parsed point: " + points[0] + ";" + points[1]);
|
|
+
|
|
return polygon;
|
|
return polygon;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -803,70 +807,70 @@ namespace SketchAssistant
|
|
}
|
|
}
|
|
else if ((currentElement.First() >= '0' && currentElement.First() <= '9') || currentElement.First() == '-' || currentElement.First() == '+' || currentElement.First() != 'e')
|
|
else if ((currentElement.First() >= '0' && currentElement.First() <= '9') || currentElement.First() == '-' || currentElement.First() == '+' || currentElement.First() != 'e')
|
|
{
|
|
{
|
|
- bool decimalPointEncountered = false;
|
|
+ bool repeatCommandDescriptor = false;
|
|
switch (lastCommand){
|
|
switch (lastCommand){
|
|
case 'M':
|
|
case 'M':
|
|
- if (argumentCounter >= 2) decimalPointEncountered = true;
|
|
+ if (argumentCounter >= 2) repeatCommandDescriptor = true;
|
|
break;
|
|
break;
|
|
case 'm':
|
|
case 'm':
|
|
- if (argumentCounter >= 2) decimalPointEncountered = true;
|
|
+ if (argumentCounter >= 2) repeatCommandDescriptor = true;
|
|
break;
|
|
break;
|
|
case 'L':
|
|
case 'L':
|
|
- if (argumentCounter >= 2) decimalPointEncountered = true;
|
|
+ if (argumentCounter >= 2) repeatCommandDescriptor = true;
|
|
break;
|
|
break;
|
|
case 'l':
|
|
case 'l':
|
|
- if (argumentCounter >= 2) decimalPointEncountered = true;
|
|
+ if (argumentCounter >= 2) repeatCommandDescriptor = true;
|
|
break;
|
|
break;
|
|
case 'V':
|
|
case 'V':
|
|
- if (argumentCounter >= 1) decimalPointEncountered = true;
|
|
+ if (argumentCounter >= 1) repeatCommandDescriptor = true;
|
|
break;
|
|
break;
|
|
case 'v':
|
|
case 'v':
|
|
- if (argumentCounter >= 1) decimalPointEncountered = true;
|
|
+ if (argumentCounter >= 1) repeatCommandDescriptor = true;
|
|
break;
|
|
break;
|
|
case 'H':
|
|
case 'H':
|
|
- if (argumentCounter >= 1) decimalPointEncountered = true;
|
|
+ if (argumentCounter >= 1) repeatCommandDescriptor = true;
|
|
break;
|
|
break;
|
|
case 'h':
|
|
case 'h':
|
|
- if (argumentCounter >= 1) decimalPointEncountered = true;
|
|
+ if (argumentCounter >= 1) repeatCommandDescriptor = true;
|
|
break;
|
|
break;
|
|
case 'C':
|
|
case 'C':
|
|
- if (argumentCounter >= 6) decimalPointEncountered = true;
|
|
+ if (argumentCounter >= 6) repeatCommandDescriptor = true;
|
|
break;
|
|
break;
|
|
case 'c':
|
|
case 'c':
|
|
- if (argumentCounter >= 6) decimalPointEncountered = true;
|
|
+ if (argumentCounter >= 6) repeatCommandDescriptor = true;
|
|
break;
|
|
break;
|
|
case 'S':
|
|
case 'S':
|
|
- if (argumentCounter >= 4) decimalPointEncountered = true;
|
|
+ if (argumentCounter >= 4) repeatCommandDescriptor = true;
|
|
break;
|
|
break;
|
|
case 's':
|
|
case 's':
|
|
- if (argumentCounter >= 4) decimalPointEncountered = true;
|
|
+ if (argumentCounter >= 4) repeatCommandDescriptor = true;
|
|
break;
|
|
break;
|
|
case 'Q':
|
|
case 'Q':
|
|
- if (argumentCounter >= 4) decimalPointEncountered = true;
|
|
+ if (argumentCounter >= 4) repeatCommandDescriptor = true;
|
|
break;
|
|
break;
|
|
case 'q':
|
|
case 'q':
|
|
- if (argumentCounter >= 4) decimalPointEncountered = true;
|
|
+ if (argumentCounter >= 4) repeatCommandDescriptor = true;
|
|
break;
|
|
break;
|
|
case 'T':
|
|
case 'T':
|
|
- if (argumentCounter >= 2) decimalPointEncountered = true;
|
|
+ if (argumentCounter >= 2) repeatCommandDescriptor = true;
|
|
break;
|
|
break;
|
|
case 't':
|
|
case 't':
|
|
- if (argumentCounter >= 2) decimalPointEncountered = true;
|
|
+ if (argumentCounter >= 2) repeatCommandDescriptor = true;
|
|
break;
|
|
break;
|
|
case 'A':
|
|
case 'A':
|
|
- if (argumentCounter >= 7) decimalPointEncountered = true;
|
|
+ if (argumentCounter >= 7) repeatCommandDescriptor = true;
|
|
break;
|
|
break;
|
|
case 'a':
|
|
case 'a':
|
|
- if (argumentCounter >= 7) decimalPointEncountered = true;
|
|
+ if (argumentCounter >= 7) repeatCommandDescriptor = true;
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
- if (decimalPointEncountered)
|
|
+ if (repeatCommandDescriptor)
|
|
{
|
|
{
|
|
pathElements.Insert(j, lastCommand + "");
|
|
pathElements.Insert(j, lastCommand + "");
|
|
j++;
|
|
j++;
|
|
argumentCounter = 0;
|
|
argumentCounter = 0;
|
|
}
|
|
}
|
|
- decimalPointEncountered = false;
|
|
+ bool decimalPointEncountered = false;
|
|
for (int k = 1; k < currentElement.Length; k++)
|
|
for (int k = 1; k < currentElement.Length; k++)
|
|
{
|
|
{
|
|
if (!decimalPointEncountered && currentElement.ElementAt(k) == '.')
|
|
if (!decimalPointEncountered && currentElement.ElementAt(k) == '.')
|
|
@@ -910,7 +914,7 @@ namespace SketchAssistant
|
|
}
|
|
}
|
|
else
|
|
else
|
|
{
|
|
{
|
|
- bool repeatCommandDescriptor = false;
|
|
+ bool repeatCommandDescriptor = false;
|
|
switch (lastCommand)
|
|
switch (lastCommand)
|
|
{
|
|
{
|
|
case 'M':
|
|
case 'M':
|
|
@@ -1360,7 +1364,7 @@ namespace SketchAssistant
|
|
double sin = Math.Sin(thetha / 180 * Math.PI);
|
|
double sin = Math.Sin(thetha / 180 * Math.PI);
|
|
double targetXTransformed = cos * nextPositionXRelative - sin * nextPositionYRelative;
|
|
double targetXTransformed = cos * nextPositionXRelative - sin * nextPositionYRelative;
|
|
double targetYTransformed = sin * nextPositionXRelative + cos * nextPositionYRelative;
|
|
double targetYTransformed = sin * nextPositionXRelative + cos * nextPositionYRelative;
|
|
- Console.WriteLine("distance between start and end point: " + (Math.Sqrt(nextPositionXRelative * nextPositionXRelative + nextPositionYRelative * nextPositionYRelative)) + " (old)," + Math.Sqrt(targetXTransformed * targetXTransformed + targetYTransformed * targetYTransformed) + " (new)");
|
|
+
|
|
(double[], double[]) values = sampleEllipticArcBiasedNoRotation(rx, ry, targetXTransformed, targetYTransformed, largeArcFlag, sweepFlag);
|
|
(double[], double[]) values = sampleEllipticArcBiasedNoRotation(rx, ry, targetXTransformed, targetYTransformed, largeArcFlag, sweepFlag);
|
|
List<Point> result = new List<Point>();
|
|
List<Point> result = new List<Point>();
|
|
for (int j = 0; j < values.Item1.Length; j++)
|
|
for (int j = 0; j < values.Item1.Length; j++)
|
|
@@ -1371,7 +1375,7 @@ namespace SketchAssistant
|
|
double yCoordinateAbsolute = lastPositionY + yCoordinateRelative;
|
|
double yCoordinateAbsolute = lastPositionY + yCoordinateRelative;
|
|
result.Add(ScaleAndCreatePoint(xCoordinateAbsolute, yCoordinateAbsolute));
|
|
result.Add(ScaleAndCreatePoint(xCoordinateAbsolute, yCoordinateAbsolute));
|
|
}
|
|
}
|
|
- Console.WriteLine("last point relative coordinates: (" + nextPositionXRelative + ";" + nextPositionYRelative + ") - (" + (cos * values.Item1[values.Item1.Length - 1] + sin * values.Item2[values.Item1.Length - 1]) + ";" + (cos * values.Item2[values.Item1.Length - 1] - sin * values.Item1[values.Item1.Length - 1]) + ")");
|
|
+
|
|
|
|
|
|
return result;
|
|
return result;
|
|
}
|
|
}
|
|
@@ -1685,42 +1689,42 @@ namespace SketchAssistant
|
|
List<Point> ellipse = new List<Point>();
|
|
List<Point> ellipse = new List<Point>();
|
|
double angle = ((double)2 * Math.PI) / (double)samplingRateEllipse;
|
|
double angle = ((double)2 * Math.PI) / (double)samplingRateEllipse;
|
|
double yScale = ry / rx;
|
|
double yScale = ry / rx;
|
|
- Console.WriteLine("parsing ellipse: " + x + ";" + y + "(" + rx + "x" + ry + ")" + " " + yScale + ":" + angle);
|
|
+
|
|
double[] xValues = new double[samplingRateEllipse / 4];
|
|
double[] xValues = new double[samplingRateEllipse / 4];
|
|
double[] yValues = new double[samplingRateEllipse / 4];
|
|
double[] yValues = new double[samplingRateEllipse / 4];
|
|
for (int j = 0; j < samplingRateEllipse / 4; j++)
|
|
for (int j = 0; j < samplingRateEllipse / 4; j++)
|
|
{
|
|
{
|
|
xValues[j] = Math.Sin((double)j * angle) * rx;
|
|
xValues[j] = Math.Sin((double)j * angle) * rx;
|
|
yValues[j] = Math.Cos((double)j * angle) * rx;
|
|
yValues[j] = Math.Cos((double)j * angle) * rx;
|
|
- Console.WriteLine("parsed ellipse value: " + xValues[j] + ";" + yValues[j]);
|
|
+
|
|
}
|
|
}
|
|
for (int j = 0; j < samplingRateEllipse / 4; j++)
|
|
for (int j = 0; j < samplingRateEllipse / 4; j++)
|
|
{
|
|
{
|
|
int xCoord = Convert.ToInt32(Math.Round(x + xValues[j]));
|
|
int xCoord = Convert.ToInt32(Math.Round(x + xValues[j]));
|
|
int yCoord = Convert.ToInt32(Math.Round(y - yValues[j] * yScale));
|
|
int yCoord = Convert.ToInt32(Math.Round(y - yValues[j] * yScale));
|
|
ellipse.Add(ScaleAndCreatePoint(xCoord, yCoord));
|
|
ellipse.Add(ScaleAndCreatePoint(xCoord, yCoord));
|
|
- Console.WriteLine("parsed ellipse point: " + xCoord + ";" + yCoord + " pointCount: " + (samplingRateEllipse / 4));
|
|
+
|
|
}
|
|
}
|
|
for (int j = 0; j < samplingRateEllipse / 4; j++)
|
|
for (int j = 0; j < samplingRateEllipse / 4; j++)
|
|
{
|
|
{
|
|
int xCoord = Convert.ToInt32(Math.Round(x + yValues[j]));
|
|
int xCoord = Convert.ToInt32(Math.Round(x + yValues[j]));
|
|
int yCoord = Convert.ToInt32(Math.Round(y + xValues[j] * yScale));
|
|
int yCoord = Convert.ToInt32(Math.Round(y + xValues[j] * yScale));
|
|
ellipse.Add(ScaleAndCreatePoint(xCoord, yCoord));
|
|
ellipse.Add(ScaleAndCreatePoint(xCoord, yCoord));
|
|
- Console.WriteLine("parsed ellipse point: " + xCoord + ";" + yCoord + " pointCount: " + (samplingRateEllipse / 4));
|
|
+
|
|
}
|
|
}
|
|
for (int j = 0; j < samplingRateEllipse / 4; j++)
|
|
for (int j = 0; j < samplingRateEllipse / 4; j++)
|
|
{
|
|
{
|
|
int xCoord = Convert.ToInt32(Math.Round(x - xValues[j]));
|
|
int xCoord = Convert.ToInt32(Math.Round(x - xValues[j]));
|
|
int yCoord = Convert.ToInt32(Math.Round(y + yValues[j] * yScale));
|
|
int yCoord = Convert.ToInt32(Math.Round(y + yValues[j] * yScale));
|
|
ellipse.Add(ScaleAndCreatePoint(xCoord, yCoord));
|
|
ellipse.Add(ScaleAndCreatePoint(xCoord, yCoord));
|
|
- Console.WriteLine("parsed ellipse point: " + xCoord + ";" + yCoord + " pointCount: " + (samplingRateEllipse / 4));
|
|
+
|
|
}
|
|
}
|
|
for (int j = 0; j < samplingRateEllipse / 4; j++)
|
|
for (int j = 0; j < samplingRateEllipse / 4; j++)
|
|
{
|
|
{
|
|
int xCoord = Convert.ToInt32(Math.Round(x - yValues[j]));
|
|
int xCoord = Convert.ToInt32(Math.Round(x - yValues[j]));
|
|
int yCoord = Convert.ToInt32(Math.Round(y - xValues[j] * yScale));
|
|
int yCoord = Convert.ToInt32(Math.Round(y - xValues[j] * yScale));
|
|
ellipse.Add(ScaleAndCreatePoint(xCoord, yCoord));
|
|
ellipse.Add(ScaleAndCreatePoint(xCoord, yCoord));
|
|
- Console.WriteLine("parsed ellipse point: " + xCoord + ";" + yCoord + " pointCount: " + (samplingRateEllipse / 4));
|
|
+
|
|
}
|
|
}
|
|
ellipse.Add(ScaleAndCreatePoint(Convert.ToInt32(Math.Round(x + 0)), Convert.ToInt32(Math.Round(y - rx * yScale))));
|
|
ellipse.Add(ScaleAndCreatePoint(Convert.ToInt32(Math.Round(x + 0)), Convert.ToInt32(Math.Round(y - rx * yScale))));
|
|
return ellipse;
|
|
return ellipse;
|