~ubuntu-branches/ubuntu/utopic/slic3r/utopic

« back to all changes in this revision

Viewing changes to xs/src/SVG.cpp

  • Committer: Package Import Robot
  • Author(s): Chow Loong Jin
  • Date: 2014-06-17 01:27:26 UTC
  • Revision ID: package-import@ubuntu.com-20140617012726-2wrs4zdo251nr4vg
Tags: upstream-1.1.4+dfsg
ImportĀ upstreamĀ versionĀ 1.1.4+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include "SVG.hpp"
 
2
 
 
3
namespace Slic3r {
 
4
 
 
5
SVG::SVG(const char* filename)
 
6
{
 
7
    this->f = fopen(filename, "w");
 
8
    fprintf(this->f,
 
9
        "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
 
10
        "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.0//EN\" \"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd\">\n"
 
11
        "<svg height=\"2000\" width=\"2000\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:svg=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n"
 
12
            "   <marker id=\"endArrow\" markerHeight=\"8\" markerUnits=\"strokeWidth\" markerWidth=\"10\" orient=\"auto\" refX=\"1\" refY=\"5\" viewBox=\"0 0 10 10\">\n"
 
13
                "      <polyline fill=\"darkblue\" points=\"0,0 10,5 0,10 1,5\" />\n"
 
14
            "   </marker>\n"
 
15
            );
 
16
        this->arrows = true;
 
17
}
 
18
 
 
19
float
 
20
SVG::coordinate(long c)
 
21
{
 
22
    return (float)unscale(c)*10;
 
23
}
 
24
 
 
25
void
 
26
SVG::AddLine(const Line &line)
 
27
{
 
28
    fprintf(this->f,
 
29
        "   <line x1=\"%f\" y1=\"%f\" x2=\"%f\" y2=\"%f\" style=\"stroke: black; stroke-width: 2\"",
 
30
        this->coordinate(line.a.x), this->coordinate(line.a.y), this->coordinate(line.b.x), this->coordinate(line.b.y)
 
31
        );
 
32
    if (this->arrows)
 
33
        fprintf(this->f, " marker-end=\"url(#endArrow)\"");
 
34
    fprintf(this->f, "/>\n");
 
35
}
 
36
 
 
37
void
 
38
SVG::AddLine(const IntersectionLine &line)
 
39
{
 
40
    this->AddLine(Line(line.a, line.b));
 
41
}
 
42
 
 
43
void
 
44
SVG::Close()
 
45
{
 
46
    fprintf(this->f, "</svg>\n");
 
47
    fclose(this->f);
 
48
    printf("SVG file written.\n");
 
49
}
 
50
 
 
51
}