Vector Export

This commit is contained in:
Devine Lu Linvega 2017-01-25 16:39:17 -07:00
parent 6dba090b1f
commit 761f04d72f
2 changed files with 43 additions and 24 deletions

View File

@ -19,19 +19,18 @@ function FileSave(rune)
{ {
var d = null; var d = null;
var w = window.open('about:blank','image from canvas');
if(cmd.variable("format") && cmd.variable("format").value == "svg"){ if(cmd.variable("format") && cmd.variable("format").value == "svg"){
// TODO w.document.write("<title>Untitled</title><body>"+ronin.vector.create_svg()+"</body>");
return;
} }
else if(cmd.variable("format") && cmd.variable("format").value == "jpg"){ else if(cmd.variable("format") && cmd.variable("format").value == "jpg"){
var d = this.merge().element.toDataURL('image/jpeg'); w.document.write("<title>Untitled</title><body><img src='"+this.merge().element.toDataURL('image/jpeg')+"' width='"+ronin.surface.size.width+"px' height='"+ronin.surface.size.height+"px'/></body>");
} }
else{ else{
var d = this.merge().element.toDataURL('image/png'); w.document.write("<title>Untitled</title><body><img src='"+this.merge().element.toDataURL('image/png')+"' width='"+ronin.surface.size.width+"px' height='"+ronin.surface.size.height+"px'/></body>");
} }
var w = window.open('about:blank','image from canvas');
w.document.write("<title>Untitled</title><body><img src='"+d+"' width='"+ronin.surface.size.width+"px' height='"+ronin.surface.size.height+"px'/></body>");
this.layer.clear(); this.layer.clear();
} }

View File

@ -8,6 +8,7 @@ function Vector(rune)
this.layer = null; this.layer = null;
this.coordinates = []; this.coordinates = [];
this.last_pos = null; this.last_pos = null;
this.paths = [];
this.install = function() this.install = function()
{ {
@ -21,22 +22,51 @@ function Vector(rune)
this.passive = function(cmd) this.passive = function(cmd)
{ {
this.layer.clear(); this.layer.clear();
this.layer.context().lineCap = cmd.variable("line_cap") ? cmd.variable("line_cap").value : "round"; this.layer.context().lineCap = cmd.variable("line_cap") ? cmd.variable("line_cap").value : "square";
this.layer.context().lineWidth = cmd.variable("stroke_width") ? cmd.variable("stroke_width").value : 5; this.layer.context().lineWidth = cmd.variable("stroke_width") ? cmd.variable("stroke_width").value : 10;
this.layer.context().strokeStyle = cmd.variable("stroke_color") ? cmd.variable("stroke_color").value : "#ffffff"; this.layer.context().strokeStyle = cmd.variable("stroke_color") ? cmd.variable("stroke_color").value : "#ffffff";
this.layer.context().stroke(new Path2D(cmd.content.join(" "))); this.layer.context().stroke(new Path2D(cmd.content.join(" ")));
} }
this.active = function(cmd) this.active = function(cmd)
{ {
this.paths.push(this.create_path());
this.coordinates = []; this.coordinates = [];
this.layer.clear(); this.layer.clear();
ronin.surface.active_layer.context().lineCap = cmd.variable("line_cap") ? cmd.variable("line_cap").value : "round"; ronin.surface.active_layer.context().lineCap = cmd.variable("line_cap") ? cmd.variable("line_cap").value : "square";
ronin.surface.active_layer.context().lineWidth = cmd.variable("stroke_width") ? cmd.variable("stroke_width").value : 5; ronin.surface.active_layer.context().lineWidth = cmd.variable("stroke_width") ? cmd.variable("stroke_width").value : 10;
ronin.surface.active_layer.context().strokeStyle = cmd.variable("stroke_color") ? cmd.variable("stroke_color").value : "#ffffff"; ronin.surface.active_layer.context().strokeStyle = cmd.variable("stroke_color") ? cmd.variable("stroke_color").value : "#ffffff";
ronin.surface.active_layer.context().stroke(new Path2D(cmd.content.join(" "))); ronin.surface.active_layer.context().stroke(new Path2D(cmd.content.join(" ")));
} }
// Tools
this.create_path = function()
{
var command = "";
for (var i = 0; i < this.coordinates.length; i++) {
command += this.coordinates[i]+" ";
}
return command;
}
this.create_svg = function()
{
var s = "";
s += "<svg width='"+ronin.surface.size.width+"' height='"+ronin.surface.size.height+"' xmlns='http://www.w3.org/2000/svg' baseProfile='full' version='1.1' style='fill:none;stroke:red;stroke-width:2px'>";
for (var i = 0; i < this.paths.length; i++) {
s += "<path d='"+this.paths[i]+"' />";
}
s += "</svg>";
console.log(s);
return s;
}
// Mouse // Mouse
this.click = null; this.click = null;
@ -57,21 +87,11 @@ function Vector(rune)
} }
} }
this.create_command = function()
{
var command = "+ ";
for (var i = 0; i < this.coordinates.length; i++) {
command += this.coordinates[i]+" ";
}
return command;
}
this.mouse_down = function(position) this.mouse_down = function(position)
{ {
this.click = true; this.click = true;
commander.element_input.value = this.create_command(); commander.element_input.value = "+ "+this.create_path();
commander.hint.update(); commander.hint.update();
this.passive(commander.cmd()); this.passive(commander.cmd());
} }
@ -79,7 +99,7 @@ function Vector(rune)
this.mouse_move = function(position) this.mouse_move = function(position)
{ {
if(!this.click){ return; } if(!this.click){ return; }
commander.element_input.value = this.create_command(); commander.element_input.value = "+ "+this.create_path();
commander.element_input.value += "L"+position.render(); commander.element_input.value += "L"+position.render();
commander.hint.update(); commander.hint.update();
this.passive(commander.cmd()); this.passive(commander.cmd());
@ -110,7 +130,7 @@ function Vector(rune)
} }
} }
commander.element_input.value = this.create_command(); commander.element_input.value = "+ "+this.create_path();
commander.hint.update(); commander.hint.update();
this.passive(commander.cmd()); this.passive(commander.cmd());
this.last_pos = position; this.last_pos = position;