Content-Type of Cached Files with Period in Name
Monkey patch to prevent ActionCache from overriding the correct content-type header, when serving cached pages with a "." in the name. (Thanks to Jason Blevins) Also sync with latest SVG-Edit.
This commit is contained in:
parent
324cc12320
commit
79a2299363
9 changed files with 2414 additions and 46 deletions
|
@ -286,3 +286,17 @@ end
|
|||
class Hash
|
||||
alias_method(:key, :index) unless method_defined?(:key)
|
||||
end
|
||||
|
||||
# Monkey patch, to ensure ActionCache doesn't muck with the content-type header.
|
||||
module ActionController #:nodoc:
|
||||
module Caching
|
||||
module Actions
|
||||
class ActionCacheFilter
|
||||
private
|
||||
def set_content_type!(controller, extension)
|
||||
return
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
1451
public/svg-edit/editor/canvg/canvg.js
Normal file
1451
public/svg-edit/editor/canvg/canvg.js
Normal file
File diff suppressed because it is too large
Load diff
288
public/svg-edit/editor/canvg/rgbcolor.js
Normal file
288
public/svg-edit/editor/canvg/rgbcolor.js
Normal file
|
@ -0,0 +1,288 @@
|
|||
/**
|
||||
* A class to parse color values
|
||||
* @author Stoyan Stefanov <sstoo@gmail.com>
|
||||
* @link http://www.phpied.com/rgb-color-parser-in-javascript/
|
||||
* @license Use it if you like it
|
||||
*/
|
||||
function RGBColor(color_string)
|
||||
{
|
||||
this.ok = false;
|
||||
|
||||
// strip any leading #
|
||||
if (color_string.charAt(0) == '#') { // remove # if any
|
||||
color_string = color_string.substr(1,6);
|
||||
}
|
||||
|
||||
color_string = color_string.replace(/ /g,'');
|
||||
color_string = color_string.toLowerCase();
|
||||
|
||||
// before getting into regexps, try simple matches
|
||||
// and overwrite the input
|
||||
var simple_colors = {
|
||||
aliceblue: 'f0f8ff',
|
||||
antiquewhite: 'faebd7',
|
||||
aqua: '00ffff',
|
||||
aquamarine: '7fffd4',
|
||||
azure: 'f0ffff',
|
||||
beige: 'f5f5dc',
|
||||
bisque: 'ffe4c4',
|
||||
black: '000000',
|
||||
blanchedalmond: 'ffebcd',
|
||||
blue: '0000ff',
|
||||
blueviolet: '8a2be2',
|
||||
brown: 'a52a2a',
|
||||
burlywood: 'deb887',
|
||||
cadetblue: '5f9ea0',
|
||||
chartreuse: '7fff00',
|
||||
chocolate: 'd2691e',
|
||||
coral: 'ff7f50',
|
||||
cornflowerblue: '6495ed',
|
||||
cornsilk: 'fff8dc',
|
||||
crimson: 'dc143c',
|
||||
cyan: '00ffff',
|
||||
darkblue: '00008b',
|
||||
darkcyan: '008b8b',
|
||||
darkgoldenrod: 'b8860b',
|
||||
darkgray: 'a9a9a9',
|
||||
darkgreen: '006400',
|
||||
darkkhaki: 'bdb76b',
|
||||
darkmagenta: '8b008b',
|
||||
darkolivegreen: '556b2f',
|
||||
darkorange: 'ff8c00',
|
||||
darkorchid: '9932cc',
|
||||
darkred: '8b0000',
|
||||
darksalmon: 'e9967a',
|
||||
darkseagreen: '8fbc8f',
|
||||
darkslateblue: '483d8b',
|
||||
darkslategray: '2f4f4f',
|
||||
darkturquoise: '00ced1',
|
||||
darkviolet: '9400d3',
|
||||
deeppink: 'ff1493',
|
||||
deepskyblue: '00bfff',
|
||||
dimgray: '696969',
|
||||
dodgerblue: '1e90ff',
|
||||
feldspar: 'd19275',
|
||||
firebrick: 'b22222',
|
||||
floralwhite: 'fffaf0',
|
||||
forestgreen: '228b22',
|
||||
fuchsia: 'ff00ff',
|
||||
gainsboro: 'dcdcdc',
|
||||
ghostwhite: 'f8f8ff',
|
||||
gold: 'ffd700',
|
||||
goldenrod: 'daa520',
|
||||
gray: '808080',
|
||||
green: '008000',
|
||||
greenyellow: 'adff2f',
|
||||
honeydew: 'f0fff0',
|
||||
hotpink: 'ff69b4',
|
||||
indianred : 'cd5c5c',
|
||||
indigo : '4b0082',
|
||||
ivory: 'fffff0',
|
||||
khaki: 'f0e68c',
|
||||
lavender: 'e6e6fa',
|
||||
lavenderblush: 'fff0f5',
|
||||
lawngreen: '7cfc00',
|
||||
lemonchiffon: 'fffacd',
|
||||
lightblue: 'add8e6',
|
||||
lightcoral: 'f08080',
|
||||
lightcyan: 'e0ffff',
|
||||
lightgoldenrodyellow: 'fafad2',
|
||||
lightgrey: 'd3d3d3',
|
||||
lightgreen: '90ee90',
|
||||
lightpink: 'ffb6c1',
|
||||
lightsalmon: 'ffa07a',
|
||||
lightseagreen: '20b2aa',
|
||||
lightskyblue: '87cefa',
|
||||
lightslateblue: '8470ff',
|
||||
lightslategray: '778899',
|
||||
lightsteelblue: 'b0c4de',
|
||||
lightyellow: 'ffffe0',
|
||||
lime: '00ff00',
|
||||
limegreen: '32cd32',
|
||||
linen: 'faf0e6',
|
||||
magenta: 'ff00ff',
|
||||
maroon: '800000',
|
||||
mediumaquamarine: '66cdaa',
|
||||
mediumblue: '0000cd',
|
||||
mediumorchid: 'ba55d3',
|
||||
mediumpurple: '9370d8',
|
||||
mediumseagreen: '3cb371',
|
||||
mediumslateblue: '7b68ee',
|
||||
mediumspringgreen: '00fa9a',
|
||||
mediumturquoise: '48d1cc',
|
||||
mediumvioletred: 'c71585',
|
||||
midnightblue: '191970',
|
||||
mintcream: 'f5fffa',
|
||||
mistyrose: 'ffe4e1',
|
||||
moccasin: 'ffe4b5',
|
||||
navajowhite: 'ffdead',
|
||||
navy: '000080',
|
||||
oldlace: 'fdf5e6',
|
||||
olive: '808000',
|
||||
olivedrab: '6b8e23',
|
||||
orange: 'ffa500',
|
||||
orangered: 'ff4500',
|
||||
orchid: 'da70d6',
|
||||
palegoldenrod: 'eee8aa',
|
||||
palegreen: '98fb98',
|
||||
paleturquoise: 'afeeee',
|
||||
palevioletred: 'd87093',
|
||||
papayawhip: 'ffefd5',
|
||||
peachpuff: 'ffdab9',
|
||||
peru: 'cd853f',
|
||||
pink: 'ffc0cb',
|
||||
plum: 'dda0dd',
|
||||
powderblue: 'b0e0e6',
|
||||
purple: '800080',
|
||||
red: 'ff0000',
|
||||
rosybrown: 'bc8f8f',
|
||||
royalblue: '4169e1',
|
||||
saddlebrown: '8b4513',
|
||||
salmon: 'fa8072',
|
||||
sandybrown: 'f4a460',
|
||||
seagreen: '2e8b57',
|
||||
seashell: 'fff5ee',
|
||||
sienna: 'a0522d',
|
||||
silver: 'c0c0c0',
|
||||
skyblue: '87ceeb',
|
||||
slateblue: '6a5acd',
|
||||
slategray: '708090',
|
||||
snow: 'fffafa',
|
||||
springgreen: '00ff7f',
|
||||
steelblue: '4682b4',
|
||||
tan: 'd2b48c',
|
||||
teal: '008080',
|
||||
thistle: 'd8bfd8',
|
||||
tomato: 'ff6347',
|
||||
turquoise: '40e0d0',
|
||||
violet: 'ee82ee',
|
||||
violetred: 'd02090',
|
||||
wheat: 'f5deb3',
|
||||
white: 'ffffff',
|
||||
whitesmoke: 'f5f5f5',
|
||||
yellow: 'ffff00',
|
||||
yellowgreen: '9acd32'
|
||||
};
|
||||
for (var key in simple_colors) {
|
||||
if (color_string == key) {
|
||||
color_string = simple_colors[key];
|
||||
}
|
||||
}
|
||||
// emd of simple type-in colors
|
||||
|
||||
// array of color definition objects
|
||||
var color_defs = [
|
||||
{
|
||||
re: /^rgb\((\d{1,3}),\s*(\d{1,3}),\s*(\d{1,3})\)$/,
|
||||
example: ['rgb(123, 234, 45)', 'rgb(255,234,245)'],
|
||||
process: function (bits){
|
||||
return [
|
||||
parseInt(bits[1]),
|
||||
parseInt(bits[2]),
|
||||
parseInt(bits[3])
|
||||
];
|
||||
}
|
||||
},
|
||||
{
|
||||
re: /^(\w{2})(\w{2})(\w{2})$/,
|
||||
example: ['#00ff00', '336699'],
|
||||
process: function (bits){
|
||||
return [
|
||||
parseInt(bits[1], 16),
|
||||
parseInt(bits[2], 16),
|
||||
parseInt(bits[3], 16)
|
||||
];
|
||||
}
|
||||
},
|
||||
{
|
||||
re: /^(\w{1})(\w{1})(\w{1})$/,
|
||||
example: ['#fb0', 'f0f'],
|
||||
process: function (bits){
|
||||
return [
|
||||
parseInt(bits[1] + bits[1], 16),
|
||||
parseInt(bits[2] + bits[2], 16),
|
||||
parseInt(bits[3] + bits[3], 16)
|
||||
];
|
||||
}
|
||||
}
|
||||
];
|
||||
|
||||
// search through the definitions to find a match
|
||||
for (var i = 0; i < color_defs.length; i++) {
|
||||
var re = color_defs[i].re;
|
||||
var processor = color_defs[i].process;
|
||||
var bits = re.exec(color_string);
|
||||
if (bits) {
|
||||
channels = processor(bits);
|
||||
this.r = channels[0];
|
||||
this.g = channels[1];
|
||||
this.b = channels[2];
|
||||
this.ok = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// validate/cleanup values
|
||||
this.r = (this.r < 0 || isNaN(this.r)) ? 0 : ((this.r > 255) ? 255 : this.r);
|
||||
this.g = (this.g < 0 || isNaN(this.g)) ? 0 : ((this.g > 255) ? 255 : this.g);
|
||||
this.b = (this.b < 0 || isNaN(this.b)) ? 0 : ((this.b > 255) ? 255 : this.b);
|
||||
|
||||
// some getters
|
||||
this.toRGB = function () {
|
||||
return 'rgb(' + this.r + ', ' + this.g + ', ' + this.b + ')';
|
||||
}
|
||||
this.toHex = function () {
|
||||
var r = this.r.toString(16);
|
||||
var g = this.g.toString(16);
|
||||
var b = this.b.toString(16);
|
||||
if (r.length == 1) r = '0' + r;
|
||||
if (g.length == 1) g = '0' + g;
|
||||
if (b.length == 1) b = '0' + b;
|
||||
return '#' + r + g + b;
|
||||
}
|
||||
|
||||
// help
|
||||
this.getHelpXML = function () {
|
||||
|
||||
var examples = new Array();
|
||||
// add regexps
|
||||
for (var i = 0; i < color_defs.length; i++) {
|
||||
var example = color_defs[i].example;
|
||||
for (var j = 0; j < example.length; j++) {
|
||||
examples[examples.length] = example[j];
|
||||
}
|
||||
}
|
||||
// add type-in colors
|
||||
for (var sc in simple_colors) {
|
||||
examples[examples.length] = sc;
|
||||
}
|
||||
|
||||
var xml = document.createElement('ul');
|
||||
xml.setAttribute('id', 'rgbcolor-examples');
|
||||
for (var i = 0; i < examples.length; i++) {
|
||||
try {
|
||||
var list_item = document.createElement('li');
|
||||
var list_color = new RGBColor(examples[i]);
|
||||
var example_div = document.createElement('div');
|
||||
example_div.style.cssText =
|
||||
'margin: 3px; '
|
||||
+ 'border: 1px solid black; '
|
||||
+ 'background:' + list_color.toHex() + '; '
|
||||
+ 'color:' + list_color.toHex()
|
||||
;
|
||||
example_div.appendChild(document.createTextNode('test'));
|
||||
var list_item_value = document.createTextNode(
|
||||
' ' + examples[i] + ' -> ' + list_color.toRGB() + ' -> ' + list_color.toHex()
|
||||
);
|
||||
list_item.appendChild(example_div);
|
||||
list_item.appendChild(list_item_value);
|
||||
xml.appendChild(list_item);
|
||||
|
||||
} catch(e){}
|
||||
}
|
||||
return xml;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -345,6 +345,25 @@
|
|||
</svg>
|
||||
</g>
|
||||
|
||||
<g id="export">
|
||||
<svg width="24" height="24" xmlns="http://www.w3.org/2000/svg">
|
||||
<defs>
|
||||
<linearGradient id="svg_5" x1="0.77734" y1="0.51172" x2="0.09375" y2="0.53516">
|
||||
<stop offset="0" stop-color="#81bbf4"/>
|
||||
<stop offset="1" stop-color="#376eb7"/>
|
||||
</linearGradient>
|
||||
</defs>
|
||||
<g>
|
||||
<rect x="7.22599" y="1.3603" width="15.76465" height="21.51735" id="svg_55" fill="#eaeaea" stroke="#606060"/>
|
||||
<circle fill="#31abed" stroke-width="0.5" cx="17.4206" cy="11.1278" r="4.69727" id="svg_3"/>
|
||||
<path fill="#ffcc00" stroke-width="0.5" d="m9.67673,20.24302l7.38701,-6.80778l2.91746,6.71323" id="svg_4"/>
|
||||
<rect fill="#ff5555" stroke-width="0.5" x="9.5385" y="2.94914" width="5.74652" height="5.74652" id="svg_2"/>
|
||||
<path d="m6.13727,17.94236l5.77328,-4.91041l-5.86949,-5.1832l-0.09622,2.36426l-4.64805,-0.06751l-0.04665,5.54694l4.79093,-0.02342l0.09623,2.27334z" id="svg_45" fill="url(#svg_5)" stroke="#285582"/>
|
||||
<title>Layer 1</title>
|
||||
</g>
|
||||
</svg>
|
||||
</g>
|
||||
|
||||
<g id="open">
|
||||
<svg viewBox="0 0 22 22" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
|
||||
<defs>
|
||||
|
@ -618,6 +637,34 @@
|
|||
</svg>
|
||||
</g>
|
||||
|
||||
<g id="width">
|
||||
<svg width="100" height="100" xmlns="http://www.w3.org/2000/svg">
|
||||
<path id="svg_6" d="m19,42.5l-7.5,7.5l7.5,7.5l0,-15zm0,7.5l62,0l0,-7.5l7.5,7.5l-7.5,7.5l0,-7.5" stroke-width="8" stroke="#000000" fill="#000000"/>
|
||||
</svg>
|
||||
</g>
|
||||
|
||||
<g id="height">
|
||||
<svg width="100" height="100" xmlns="http://www.w3.org/2000/svg">
|
||||
<path transform="rotate(90, 50, 50)" fill="#000000" stroke="#000000" stroke-width="8" d="m19,42.5l-7.5,7.5l7.5,7.5l0,-15zm0,7.5l62,0l0,-7.5l7.5,7.5l-7.5,7.5l0,-7.5" id="svg_6"/>
|
||||
</svg>
|
||||
</g>
|
||||
|
||||
<g id="c_radius">
|
||||
<svg width="20" height="20" xmlns="http://www.w3.org/2000/svg">
|
||||
<rect stroke="#404040" fill="none" stroke-width="0.5" x="2.37501" y="2.4375" width="43.9375" height="43.9375" id="svg_1" rx="13" ry="13"/>
|
||||
<path fill="none" stroke="#000000" d="m2.43674,15.88952l13.73722,0l0.08978,-13.46483m0.08978,14.08493" id="svg_3"/>
|
||||
<line fill="none" stroke="#000000" x1="16.35107" y1="15.88934" x2="5.20504" y2="5.20504" id="svg_4" stroke-dasharray="2,2"/>
|
||||
</svg>
|
||||
</g>
|
||||
|
||||
<g id="align">
|
||||
<svg width="22" height="22" xmlns="http://www.w3.org/2000/svg">
|
||||
<rect stroke="#606060" fill="#c0c0c0" id="svg_4" height="7" width="12" y="7.5" x="4.5"/>
|
||||
<rect stroke="#c15909" fill="#ef9a23" id="svg_2" height="40" width="2" y="-10" x="9.5"/>
|
||||
<rect stroke="#ffffff" fill="none" id="svg_5" height="5" width="10" y="8.5" x="5.5"/>
|
||||
</svg>
|
||||
</g>
|
||||
|
||||
<g id="align_left">
|
||||
<svg xmlns:xlink="http://www.w3.org/1999/xlink" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 22 22">
|
||||
<rect stroke="#606060" fill="#ffffff" id="svg_4" height="7" width="12" y="2.5" x="2.5"/>
|
||||
|
|
|
@ -601,6 +601,16 @@ span.zoom_tool {
|
|||
|
||||
}
|
||||
|
||||
#svg_editor .icon_label {
|
||||
float: left;
|
||||
padding-top: 3px;
|
||||
padding-right: 3px;
|
||||
}
|
||||
|
||||
#svg_editor .width_label {
|
||||
padding-right: 5px;
|
||||
}
|
||||
|
||||
#tool_bold, #tool_italic {
|
||||
font: bold 2.1em/1.1em serif;
|
||||
text-align: center;
|
||||
|
@ -608,6 +618,11 @@ span.zoom_tool {
|
|||
position: relative;
|
||||
}
|
||||
|
||||
#text {
|
||||
position: absolute;
|
||||
left: -9999px;
|
||||
}
|
||||
|
||||
#tool_bold span, #tool_italic span {
|
||||
position: absolute;
|
||||
width: 100%;
|
||||
|
@ -736,7 +751,8 @@ span.zoom_tool {
|
|||
}
|
||||
|
||||
#svg_editor .stroke_tool.down div div,
|
||||
#svg_editor .stroke_tool.down button {
|
||||
#svg_editor .stroke_tool.down button,
|
||||
#tools_top .dropdown.down > * {
|
||||
border: 1px inset gray;
|
||||
background: #F4E284;
|
||||
}
|
||||
|
@ -749,6 +765,12 @@ span.zoom_tool {
|
|||
float: left;
|
||||
}
|
||||
|
||||
|
||||
#tools_top .dropdown div {
|
||||
border: 1px solid transparent;
|
||||
margin-top: 3px;
|
||||
}
|
||||
|
||||
#option_lists ul {
|
||||
display: none;
|
||||
position: absolute;
|
||||
|
@ -759,6 +781,15 @@ span.zoom_tool {
|
|||
padding-left: 0;
|
||||
}
|
||||
|
||||
#option_lists #position_opts {
|
||||
width: 90px;
|
||||
margin-left: -32px;
|
||||
}
|
||||
|
||||
#option_lists #position_opts li {
|
||||
float: left;
|
||||
}
|
||||
|
||||
#svg_editor ul li.current {
|
||||
background-color: #F4E284;
|
||||
}
|
||||
|
|
|
@ -112,6 +112,11 @@ script type="text/javascript" src="locale/locale.min.js"></script-->
|
|||
Save Image [S]
|
||||
</li>
|
||||
|
||||
<li id="tool_export">
|
||||
<div></div>
|
||||
Export as PNG
|
||||
</li>
|
||||
|
||||
<li id="tool_docprops">
|
||||
<div></div>
|
||||
Document Properties [I]
|
||||
|
@ -181,6 +186,11 @@ script type="text/javascript" src="locale/locale.min.js"></script-->
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<div class="dropdown toolset" id="tool_position" title="Align Element to Page">
|
||||
<div id="cur_position" class="icon_label"></div>
|
||||
<button></button>
|
||||
</div>
|
||||
|
||||
<div id="xy_panel" class="toolset">
|
||||
<label>
|
||||
x: <input id="selected_x" class="attr_changer" title="Change X coordinate" size="3" data-attr="x"/>
|
||||
|
@ -225,25 +235,26 @@ script type="text/javascript" src="locale/locale.min.js"></script-->
|
|||
<div id="rect_panel">
|
||||
<div class="toolset">
|
||||
<label>
|
||||
<span id="rwidthLabel">width:</span>
|
||||
<span id="rwidthLabel" class="icon_label"></span>
|
||||
<input id="rect_width" class="attr_changer" title="Change rectangle width" size="3" data-attr="width"/>
|
||||
</label>
|
||||
<label>
|
||||
<span id="rheightLabel">height:</span>
|
||||
<span id="rheightLabel" class="icon_label"></span>
|
||||
<input id="rect_height" class="attr_changer" title="Change rectangle height" size="3" data-attr="height"/>
|
||||
</label>
|
||||
</div>
|
||||
<label id="cornerRadiusLabel">Corner Radius:
|
||||
<input id="rect_rx" size="3" value="0" type="text" title="Change Rectangle Corner Radius" data-attr="Corner Radius"/>
|
||||
<label id="cornerRadiusLabel" title="Change Rectangle Corner Radius">
|
||||
<span class="icon_label"></span>
|
||||
<input id="rect_rx" size="3" value="0" type="text" data-attr="Corner Radius"/>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div id="image_panel">
|
||||
<div class="toolset">
|
||||
<label><span id="iwidthLabel">width:</span>
|
||||
<label><span id="iwidthLabel" class="icon_label"></span>
|
||||
<input id="image_width" class="attr_changer" title="Change image width" size="3" data-attr="width"/>
|
||||
</label>
|
||||
<label><span id="iheightLabel">height:</span>
|
||||
<label><span id="iheightLabel" class="icon_label"></span>
|
||||
<input id="image_height" class="attr_changer" title="Change image height" size="3" data-attr="height"/>
|
||||
</label>
|
||||
</div>
|
||||
|
@ -339,10 +350,9 @@ script type="text/javascript" src="locale/locale.min.js"></script-->
|
|||
<span id="font_sizeLabel">size:</span>
|
||||
<input id="font_size" title="Change Font Size" size="3" value="0" type="text"/>
|
||||
</label>
|
||||
<label>
|
||||
<!-- Text content -->
|
||||
<input id="text" type="text" title="Change text contents" size="35"/>
|
||||
</label>
|
||||
|
||||
<!-- Not visible, but still used -->
|
||||
<input id="text" type="text" size="35"/>
|
||||
</div>
|
||||
|
||||
<div id="path_node_panel">
|
||||
|
@ -516,6 +526,15 @@ script type="text/javascript" src="locale/locale.min.js"></script-->
|
|||
<li class="tool_button" id="linecap_square" title="Linecap: Square"></li>
|
||||
<li class="tool_button" id="linecap_round" title="Linecap: Round"></li>
|
||||
</ul>
|
||||
|
||||
<ul id="position_opts">
|
||||
<li class="push_button" id="tool_posleft" title="Align Left"></li>
|
||||
<li class="push_button" id="tool_poscenter" title="Align Center"></li>
|
||||
<li class="push_button" id="tool_posright" title="Align Right"></li>
|
||||
<li class="push_button" id="tool_postop" title="Align Top"></li>
|
||||
<li class="push_button" id="tool_posmiddle" title="Align Middle"></li>
|
||||
<li class="push_button" id="tool_posbottom" title="Align Bottom"></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
|
||||
|
@ -556,9 +575,9 @@ script type="text/javascript" src="locale/locale.min.js"></script-->
|
|||
<fieldset id="change_resolution">
|
||||
<legend id="svginfo_dim">Canvas Dimensions</legend>
|
||||
|
||||
<label><span id="svginfo_width">Width:</span> <input type="text" id="canvas_width" size="6"/></label>
|
||||
<label><span id="svginfo_width">width:</span> <input type="text" id="canvas_width" size="6"/></label>
|
||||
|
||||
<label><span id="svginfo_height">Height:</span> <input type="text" id="canvas_height" size="6"/></label>
|
||||
<label><span id="svginfo_height">height:</span> <input type="text" id="canvas_height" size="6"/></label>
|
||||
|
||||
<label>
|
||||
<select id="resolution">
|
||||
|
|
|
@ -177,7 +177,8 @@
|
|||
svgEditor.setConfig(urldata);
|
||||
|
||||
var src = urldata.source;
|
||||
|
||||
var qstr = $.param.querystring();
|
||||
|
||||
if(src) {
|
||||
if(src.indexOf("data:") === 0) {
|
||||
// plusses get replaced by spaces, so re-insert
|
||||
|
@ -186,6 +187,9 @@
|
|||
} else {
|
||||
Editor.loadFromString(src);
|
||||
}
|
||||
} else if(qstr.indexOf('paramurl=') !== -1) {
|
||||
// Get paramater URL (use full length of remaining location.href)
|
||||
svgEditor.loadFromURL(qstr.substr(9));
|
||||
} else if(urldata.url) {
|
||||
svgEditor.loadFromURL(urldata.url);
|
||||
}
|
||||
|
@ -268,6 +272,7 @@
|
|||
|
||||
'#tool_clear div,#layer_new':'new_image',
|
||||
'#tool_save div':'save',
|
||||
'#tool_export div':'export',
|
||||
'#tool_open div div':'open',
|
||||
'#tool_import div div':'import',
|
||||
'#tool_source':'source',
|
||||
|
@ -303,12 +308,13 @@
|
|||
'#tool_group':'group',
|
||||
'#tool_ungroup':'ungroup',
|
||||
|
||||
'#tool_alignleft':'align_left',
|
||||
'#tool_aligncenter':'align_center',
|
||||
'#tool_alignright':'align_right',
|
||||
'#tool_aligntop':'align_top',
|
||||
'#tool_alignmiddle':'align_middle',
|
||||
'#tool_alignbottom':'align_bottom',
|
||||
'#tool_alignleft, #tool_posleft':'align_left',
|
||||
'#tool_aligncenter, #tool_poscenter':'align_center',
|
||||
'#tool_alignright, #tool_posright':'align_right',
|
||||
'#tool_aligntop, #tool_postop':'align_top',
|
||||
'#tool_alignmiddle, #tool_posmiddle':'align_middle',
|
||||
'#tool_alignbottom, #tool_posbottom':'align_bottom',
|
||||
'#cur_position':'align',
|
||||
|
||||
'#linecap_butt,#cur_linecap':'linecap_butt',
|
||||
'#linecap_round':'linecap_round',
|
||||
|
@ -327,6 +333,10 @@
|
|||
'#tool_source_save,#tool_docprops_save':'ok',
|
||||
'#tool_source_cancel,#tool_docprops_cancel':'cancel',
|
||||
|
||||
'#rwidthLabel, #iwidthLabel':'width',
|
||||
'#rheightLabel, #iheightLabel':'height',
|
||||
'#cornerRadiusLabel span':'c_radius',
|
||||
|
||||
'.flyout_arrow_horiz':'arrow_right',
|
||||
'.dropdown button, #main_button .dropdown':'arrow_down',
|
||||
'#palette .palette_item:first, #fill_bg, #stroke_bg':'no_color'
|
||||
|
@ -472,8 +482,7 @@
|
|||
// can just provide their own custom save handler and might not want the XML prolog
|
||||
svg = "<?xml version='1.0'?>\n" + svg;
|
||||
|
||||
// Creates and opens an HTML page that provides a link to the SVG, a preview, and the markup.
|
||||
// Also includes warning about Mozilla bug #308590 when applicable
|
||||
// Opens the SVG in new window, with warning about Mozilla bug #308590 when applicable
|
||||
|
||||
var win = window.open("data:image/svg+xml;base64," + Utils.encode64(svg));
|
||||
|
||||
|
@ -502,6 +511,32 @@
|
|||
}
|
||||
};
|
||||
|
||||
var exportHandler = function(window, data) {
|
||||
|
||||
var issues = data.issues;
|
||||
|
||||
if(!$('#export_canvas').length) {
|
||||
$('<canvas>', {id: 'export_canvas'}).hide().appendTo('body');
|
||||
}
|
||||
var c = $('#export_canvas')[0];
|
||||
|
||||
c.width = svgCanvas.contentW;
|
||||
c.height = svgCanvas.contentH;
|
||||
canvg(c, data.svg);
|
||||
var datauri = c.toDataURL('image/png');
|
||||
var win = window.open(datauri);
|
||||
|
||||
var note = 'Select "Save As..." in your browser to save this image as a PNG file.';
|
||||
|
||||
// Check if there's issues
|
||||
|
||||
if(issues.length) {
|
||||
var pre = "\n \u2022 ";
|
||||
note += ("\n\nAlso note these issues:" + pre + issues.join(pre));
|
||||
}
|
||||
win.alert(note);
|
||||
};
|
||||
|
||||
// called when we've selected a different element
|
||||
var selectedChanged = function(window,elems) {
|
||||
var mode = svgCanvas.getMode();
|
||||
|
@ -1219,8 +1254,10 @@
|
|||
svgCanvas.bind("selected", selectedChanged);
|
||||
svgCanvas.bind("changed", elementChanged);
|
||||
svgCanvas.bind("saved", saveHandler);
|
||||
svgCanvas.bind("exported", exportHandler);
|
||||
svgCanvas.bind("zoomed", zoomChanged);
|
||||
svgCanvas.bind("extension_added", extAdded);
|
||||
svgCanvas.textActions.setInputElem($("#text")[0]);
|
||||
|
||||
var str = '<div class="palette_item" data-rgb="none"></div>'
|
||||
$.each(palette, function(i,item){
|
||||
|
@ -1615,17 +1652,19 @@
|
|||
}
|
||||
|
||||
// TODO: Combine this with addDropDown or find other way to optimize
|
||||
var addAltDropDown = function(elem, list, callback, dropUp) {
|
||||
var addAltDropDown = function(elem, list, callback, opts) {
|
||||
var button = $(elem);
|
||||
var list = $(list);
|
||||
var on_button = false;
|
||||
var dropUp = opts.dropUp;
|
||||
if(dropUp) {
|
||||
$(elem).addClass('dropup');
|
||||
}
|
||||
|
||||
list.find('li').bind('mouseup', function() {
|
||||
callback.apply(this, arguments);
|
||||
$(this).addClass('current').siblings().removeClass('current');
|
||||
if(!opts.multiclick) {
|
||||
$(this).addClass('current').siblings().removeClass('current');
|
||||
}
|
||||
});
|
||||
|
||||
$(window).mouseup(function(evt) {
|
||||
|
@ -1641,8 +1680,12 @@
|
|||
|
||||
$(elem).bind('mousedown',function() {
|
||||
var off = $(elem).offset();
|
||||
off.top -= list.height();
|
||||
off.left += 8;
|
||||
if(dropUp) {
|
||||
off.top -= list.height();
|
||||
off.left += 8;
|
||||
} else {
|
||||
off.top += $(elem).height();
|
||||
}
|
||||
$(list).offset(off);
|
||||
|
||||
if (!button.hasClass('down')) {
|
||||
|
@ -1661,6 +1704,12 @@
|
|||
}).mouseout(function() {
|
||||
on_button = false;
|
||||
});
|
||||
|
||||
if(opts.multiclick) {
|
||||
list.mousedown(function() {
|
||||
on_button = true;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
addDropDown('#font_family_dropdown', function() {
|
||||
|
@ -1722,7 +1771,7 @@
|
|||
var icon = $.getSvgIcon(this.id).clone();
|
||||
$('#cur_linecap').empty().append(icon);
|
||||
$.resizeSvgIcons({'#cur_linecap .svg_icon': 20});
|
||||
}, true);
|
||||
}, {dropUp: true});
|
||||
|
||||
addAltDropDown('#stroke_linejoin', '#linejoin_opts', function() {
|
||||
var val = this.id.split('_')[1];
|
||||
|
@ -1731,7 +1780,12 @@
|
|||
var icon = $.getSvgIcon(this.id).clone();
|
||||
$('#cur_linejoin').empty().append(icon);
|
||||
$.resizeSvgIcons({'#cur_linejoin .svg_icon': 20});
|
||||
}, true);
|
||||
}, {dropUp: true});
|
||||
|
||||
addAltDropDown('#tool_position', '#position_opts', function() {
|
||||
var letter = this.id.replace('tool_pos','').charAt(0);
|
||||
svgCanvas.alignSelectedElements(letter, 'page');
|
||||
}, {multiclick: true});
|
||||
|
||||
/*
|
||||
|
||||
|
@ -1958,6 +2012,35 @@
|
|||
svgCanvas.save(saveOpts);
|
||||
};
|
||||
|
||||
var clickExport = function() {
|
||||
if(window.canvg) {
|
||||
svgCanvas.rasterExport();
|
||||
return;
|
||||
} else {
|
||||
$.getScript('canvg/rgbcolor.js', function() {
|
||||
$.getScript('canvg/canvg.js');
|
||||
// Would normally run svgCanvas.rasterExport() here,
|
||||
// but that causes popup dialog box
|
||||
});
|
||||
}
|
||||
var count = 0;
|
||||
|
||||
// Run export when window.canvg is created
|
||||
var timer = setInterval(function() {
|
||||
count++;
|
||||
if(window.canvg) {
|
||||
clearInterval(timer);
|
||||
svgCanvas.rasterExport();
|
||||
return;
|
||||
}
|
||||
|
||||
if(count > 100) { // 5 seconds
|
||||
clearInterval(timer);
|
||||
$.alert("Error: Failed to load CanVG script");
|
||||
}
|
||||
}, 50);
|
||||
}
|
||||
|
||||
// by default, svgCanvas.open() is a no-op.
|
||||
// it is up to an extension mechanism (opera widget, etc)
|
||||
// to call setCustomHandlers() which will make it do something
|
||||
|
@ -2067,7 +2150,7 @@
|
|||
var res = svgCanvas.getResolution();
|
||||
$('#canvas_width').val(res.w);
|
||||
$('#canvas_height').val(res.h);
|
||||
$('#canvas_title').val(svgCanvas.getImageTitle());
|
||||
$('#canvas_title').val(svgCanvas.getDocumentTitle());
|
||||
|
||||
// Update background color with current one
|
||||
var blocks = $('#bg_blocks div');
|
||||
|
@ -2103,7 +2186,7 @@
|
|||
hideSourceEditor();
|
||||
zoomImage();
|
||||
populateLayers();
|
||||
setTitle(svgCanvas.getImageTitle());
|
||||
setTitle(svgCanvas.getDocumentTitle());
|
||||
}
|
||||
|
||||
if (!svgCanvas.setSvgString($('#svg_source_textarea').val())) {
|
||||
|
@ -2127,7 +2210,7 @@
|
|||
// set title
|
||||
var new_title = $('#canvas_title').val();
|
||||
setTitle(new_title);
|
||||
svgCanvas.setImageTitle(new_title);
|
||||
svgCanvas.setDocumentTitle(new_title);
|
||||
|
||||
// update resolution
|
||||
var width = $('#canvas_width'), w = width.val();
|
||||
|
@ -2192,7 +2275,7 @@
|
|||
var size_num = icon_sizes[size];
|
||||
|
||||
// Change icon size
|
||||
$('.tool_button, .push_button, .tool_button_current, .disabled, #url_notice, #tool_open')
|
||||
$('.tool_button, .push_button, .tool_button_current, .disabled, .icon_label, #url_notice, #tool_open')
|
||||
.find('> svg, > img').each(function() {
|
||||
this.setAttribute('width',size_num);
|
||||
this.setAttribute('height',size_num);
|
||||
|
@ -2213,6 +2296,7 @@
|
|||
.tool_button_current,\
|
||||
.push_button_pressed,\
|
||||
.disabled,\
|
||||
.icon_label,\
|
||||
.tools_flyout .tool_button": {
|
||||
'width': {s: '16px', l: '32px', xl: '48px'},
|
||||
'height': {s: '16px', l: '32px', xl: '48px'},
|
||||
|
@ -2313,6 +2397,9 @@
|
|||
},
|
||||
"input.spin-button.down": {
|
||||
'background-position': {l: '100% -85px', xl: '100% -82px'}
|
||||
},
|
||||
"#position_opts": {
|
||||
'width': {all: (size_num*4) +'px'}
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -2329,8 +2416,8 @@
|
|||
selector = '#svg_editor ' + selector.replace(/,/g,', #svg_editor');
|
||||
style_str += selector + '{';
|
||||
$.each(rules, function(prop, values) {
|
||||
if(values[size]) {
|
||||
style_str += (prop + ':' + values[size] + ';');
|
||||
if(values[size] || values.all) {
|
||||
style_str += (prop + ':' + (values[size] || values.all) + ';');
|
||||
}
|
||||
});
|
||||
style_str += '}';
|
||||
|
@ -2994,6 +3081,7 @@
|
|||
{sel:'#tool_zoom', fn: clickZoom, evt: 'mouseup', key: 9},
|
||||
{sel:'#tool_clear', fn: clickClear, evt: 'mouseup', key: [modKey+'N', true]},
|
||||
{sel:'#tool_save', fn: function() { editingsource?saveSourceEditor():clickSave()}, evt: 'mouseup', key: [modKey+'S', true]},
|
||||
{sel:'#tool_export', fn: clickExport, evt: 'mouseup'},
|
||||
{sel:'#tool_open', fn: clickOpen, evt: 'mouseup', key: [modKey+'O', true]},
|
||||
{sel:'#tool_import', fn: clickImport, evt: 'mouseup'},
|
||||
{sel:'#tool_source', fn: showSourceEditor, evt: 'click', key: ['U', true]},
|
||||
|
@ -3316,7 +3404,7 @@
|
|||
updateCanvas(true);
|
||||
// });
|
||||
|
||||
// var revnums = "svg-editor.js ($Rev: 1514 $) ";
|
||||
// var revnums = "svg-editor.js ($Rev: 1526 $) ";
|
||||
// revnums += svgCanvas.getVersion();
|
||||
// $('#copyright')[0].setAttribute("title", revnums);
|
||||
|
||||
|
|
|
@ -1603,7 +1603,6 @@ function BatchCommand(text) {
|
|||
if(elem.id == 'svgcontent') {
|
||||
// Process root element separately
|
||||
var res = canvas.getResolution();
|
||||
// console.log('res',res);
|
||||
out.push(' width="' + res.w + '" height="' + res.h + '" xmlns="'+svgns+'"');
|
||||
|
||||
var nsuris = {};
|
||||
|
@ -3183,7 +3182,7 @@ function BatchCommand(text) {
|
|||
"xml:space": "preserve"
|
||||
}
|
||||
});
|
||||
newText.textContent = "text";
|
||||
// newText.textContent = "text";
|
||||
break;
|
||||
case "path":
|
||||
// Fall through
|
||||
|
@ -3193,6 +3192,12 @@ function BatchCommand(text) {
|
|||
pathActions.mouseDown(evt, mouse_target, start_x, start_y);
|
||||
started = true;
|
||||
break;
|
||||
case "textedit":
|
||||
start_x *= current_zoom;
|
||||
start_y *= current_zoom;
|
||||
textActions.mouseDown(evt, mouse_target, start_x, start_y);
|
||||
started = true;
|
||||
break;
|
||||
case "rotate":
|
||||
started = true;
|
||||
// we are starting an undoable change (a drag-rotation)
|
||||
|
@ -3495,6 +3500,21 @@ function BatchCommand(text) {
|
|||
|
||||
pathActions.mouseMove(mouse_x, mouse_y);
|
||||
|
||||
break;
|
||||
case "textedit":
|
||||
x *= current_zoom;
|
||||
y *= current_zoom;
|
||||
// if(rubberBox && rubberBox.getAttribute('display') != 'none') {
|
||||
// assignAttributes(rubberBox, {
|
||||
// 'x': Math.min(start_x,x),
|
||||
// 'y': Math.min(start_y,y),
|
||||
// 'width': Math.abs(x-start_x),
|
||||
// 'height': Math.abs(y-start_y)
|
||||
// },100);
|
||||
// }
|
||||
|
||||
textActions.mouseMove(mouse_x, mouse_y);
|
||||
|
||||
break;
|
||||
case "rotate":
|
||||
var box = canvas.getBBox(selected),
|
||||
|
@ -3588,6 +3608,9 @@ function BatchCommand(text) {
|
|||
if (selectedElements[0].nodeName == "path" && selectedElements[1] == null) {
|
||||
pathActions.select(t);
|
||||
} // if it was a path
|
||||
else if (selectedElements[0].nodeName == "text" && selectedElements[1] == null) {
|
||||
textActions.select(t, x, y);
|
||||
} // if it was a path
|
||||
// else, if it was selected and this is a shift-click, remove it from selection
|
||||
else if (evt.shiftKey) {
|
||||
if(tempJustSelected != t) {
|
||||
|
@ -3685,7 +3708,8 @@ function BatchCommand(text) {
|
|||
break;
|
||||
case "text":
|
||||
keep = true;
|
||||
canvas.clearSelection();
|
||||
canvas.addToSelection([element]);
|
||||
textActions.start(element);
|
||||
break;
|
||||
case "path":
|
||||
// set element to null here so that it is not removed nor finalized
|
||||
|
@ -3702,6 +3726,11 @@ function BatchCommand(text) {
|
|||
element = null;
|
||||
pathActions.mouseUp(evt);
|
||||
break;
|
||||
case "textedit":
|
||||
keep = false;
|
||||
element = null;
|
||||
textActions.mouseUp(evt, mouse_x, mouse_y);
|
||||
break;
|
||||
case "rotate":
|
||||
keep = true;
|
||||
element = null;
|
||||
|
@ -3836,6 +3865,356 @@ function BatchCommand(text) {
|
|||
|
||||
}());
|
||||
|
||||
var textActions = canvas.textActions = function() {
|
||||
var curtext;
|
||||
var textinput;
|
||||
var cursor;
|
||||
var selblock;
|
||||
var blinker;
|
||||
var chardata = [];
|
||||
var textbb, transbb;
|
||||
var xform, imatrix;
|
||||
var last_x, last_y;
|
||||
var allow_dbl;
|
||||
|
||||
function setCursor(index) {
|
||||
var empty = (textinput.value === "");
|
||||
|
||||
if(!arguments.length) {
|
||||
if(empty) {
|
||||
index = 0;
|
||||
} else {
|
||||
if(textinput.selectionEnd !== textinput.selectionStart) return;
|
||||
index = textinput.selectionEnd;
|
||||
}
|
||||
}
|
||||
|
||||
var charbb;
|
||||
charbb = chardata[index];
|
||||
if(!empty) {
|
||||
textinput.setSelectionRange(index, index);
|
||||
}
|
||||
cursor = getElem("text_cursor");
|
||||
if (!cursor) {
|
||||
cursor = document.createElementNS(svgns, "line");
|
||||
assignAttributes(cursor, {
|
||||
'id': "text_cursor",
|
||||
'stroke': "#333",
|
||||
'stroke-width': 1
|
||||
});
|
||||
cursor = getElem("selectorParentGroup").appendChild(cursor);
|
||||
}
|
||||
|
||||
if(!blinker) {
|
||||
blinker = setInterval(function() {
|
||||
var show = (cursor.getAttribute('display') === 'none');
|
||||
cursor.setAttribute('display', show?'inline':'none');
|
||||
}, 600);
|
||||
|
||||
}
|
||||
|
||||
assignAttributes(cursor, {
|
||||
x1: charbb.x * current_zoom,
|
||||
y1: textbb.y * current_zoom,
|
||||
x2: charbb.x * current_zoom,
|
||||
y2: (textbb.y + textbb.height) * current_zoom,
|
||||
visibility: 'visible',
|
||||
display: 'inline',
|
||||
transform: (xform || '')
|
||||
});
|
||||
|
||||
if(selblock) selblock.setAttribute('width', 0);
|
||||
}
|
||||
|
||||
function setSelection(start, end, skipInput) {
|
||||
if(start === end) {
|
||||
setCursor(end);
|
||||
return;
|
||||
}
|
||||
|
||||
if(!skipInput) {
|
||||
textinput.setSelectionRange(start, end);
|
||||
}
|
||||
|
||||
selblock = getElem("text_selectblock");
|
||||
if (!selblock) {
|
||||
selblock = document.createElementNS(svgns, "rect");
|
||||
assignAttributes(selblock, {
|
||||
'id': "text_selectblock",
|
||||
'fill': "green",
|
||||
'opacity': .5,
|
||||
'style': "pointer-events:none"
|
||||
});
|
||||
selblock = getElem("selectorParentGroup").appendChild(selblock);
|
||||
}
|
||||
|
||||
var startbb = chardata[start];
|
||||
|
||||
var endbb = chardata[end];
|
||||
|
||||
cursor.setAttribute('visibility', 'hidden');
|
||||
assignAttributes(selblock, {
|
||||
'x': startbb.x * current_zoom,
|
||||
'y': textbb.y * current_zoom,
|
||||
'width': (endbb.x - startbb.x) * current_zoom,
|
||||
'height': textbb.height * current_zoom,
|
||||
'display': 'inline',
|
||||
'transform': (xform || '')
|
||||
});
|
||||
}
|
||||
|
||||
function getIndexFromPoint(mouse_x, mouse_y) {
|
||||
// Position cursor here
|
||||
var pt = svgroot.createSVGPoint();
|
||||
pt.x = mouse_x;
|
||||
pt.y = mouse_y;
|
||||
|
||||
// No content, so return 0
|
||||
if(chardata.length == 1) return 0;
|
||||
|
||||
// Determine if cursor should be on left or right of character
|
||||
var charpos = curtext.getCharNumAtPosition(pt);
|
||||
if(charpos < 0) {
|
||||
// Out of text range, look at mouse coords
|
||||
charpos = chardata.length - 2;
|
||||
if(mouse_x <= chardata[0].x) {
|
||||
charpos = 0;
|
||||
}
|
||||
} else if(charpos >= chardata.length - 2) {
|
||||
charpos = chardata.length - 2;
|
||||
}
|
||||
var charbb = chardata[charpos];
|
||||
var mid = charbb.x + (charbb.width/2);
|
||||
if(mouse_x > mid) {
|
||||
charpos++;
|
||||
}
|
||||
return charpos;
|
||||
}
|
||||
|
||||
function setCursorFromPoint(mouse_x, mouse_y) {
|
||||
setCursor(getIndexFromPoint(mouse_x, mouse_y));
|
||||
}
|
||||
|
||||
function setEndSelectionFromPoint(x, y, apply) {
|
||||
var i1 = textinput.selectionStart;
|
||||
var i2 = getIndexFromPoint(x, y);
|
||||
|
||||
var start = Math.min(i1, i2);
|
||||
var end = Math.max(i1, i2);
|
||||
setSelection(start, end, !apply);
|
||||
}
|
||||
|
||||
function screenToPt(x_in, y_in) {
|
||||
var out = {
|
||||
x: x_in,
|
||||
y: y_in
|
||||
}
|
||||
|
||||
if(xform) {
|
||||
var pt = transformPoint(out.x, out.y, imatrix);
|
||||
out.x = pt.x;
|
||||
out.y = pt.y;
|
||||
}
|
||||
|
||||
out.x /= current_zoom;
|
||||
out.y /= current_zoom;
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
function hideCursor() {
|
||||
if(cursor) {
|
||||
cursor.setAttribute('visibility', 'hidden');
|
||||
}
|
||||
}
|
||||
|
||||
function selectAll(evt) {
|
||||
setSelection(0, curtext.textContent.length);
|
||||
$(this).unbind(evt);
|
||||
}
|
||||
|
||||
function selectWord(evt) {
|
||||
if(!allow_dbl) return;
|
||||
|
||||
var ept = transformPoint( evt.pageX, evt.pageY, root_sctm ),
|
||||
mouse_x = ept.x * current_zoom,
|
||||
mouse_y = ept.y * current_zoom;
|
||||
var pt = screenToPt(mouse_x, mouse_y);
|
||||
|
||||
var index = getIndexFromPoint(pt.x, pt.y);
|
||||
var str = curtext.textContent;
|
||||
var first = str.substr(0, index).replace(/[a-z0-9]+$/i, '').length;
|
||||
var m = str.substr(index).match(/^[a-z0-9]+/i);
|
||||
var last = (m?m[0].length:0) + index;
|
||||
setSelection(first, last);
|
||||
|
||||
// Set tripleclick
|
||||
$(evt.target).click(selectAll);
|
||||
setTimeout(function() {
|
||||
$(evt.target).unbind('click', selectAll);
|
||||
}, 300);
|
||||
|
||||
}
|
||||
|
||||
return {
|
||||
select: function(target, x, y) {
|
||||
if (curtext == target) {
|
||||
textActions.toEditMode(x, y);
|
||||
} // going into pathedit mode
|
||||
else {
|
||||
curtext = target;
|
||||
}
|
||||
},
|
||||
start: function(elem) {
|
||||
curtext = elem;
|
||||
textActions.toEditMode();
|
||||
},
|
||||
mouseDown: function(evt, mouse_target, start_x, start_y) {
|
||||
var pt = screenToPt(start_x, start_y);
|
||||
|
||||
textinput.focus();
|
||||
setCursorFromPoint(pt.x, pt.y);
|
||||
last_x = start_x;
|
||||
last_y = start_y;
|
||||
|
||||
// TODO: Find way to block native selection
|
||||
},
|
||||
mouseMove: function(mouse_x, mouse_y) {
|
||||
var pt = screenToPt(mouse_x, mouse_y);
|
||||
setEndSelectionFromPoint(pt.x, pt.y);
|
||||
},
|
||||
mouseUp: function(evt, mouse_x, mouse_y) {
|
||||
var pt = screenToPt(mouse_x, mouse_y);
|
||||
setEndSelectionFromPoint(pt.x, pt.y, true);
|
||||
|
||||
// TODO: Find a way to make this work: Use transformed BBox instead of evt.target
|
||||
// if(last_x === mouse_x && last_y === mouse_y
|
||||
// && !Utils.rectsIntersect(transbb, {x: pt.x, y: pt.y, width:0, height:0})) {
|
||||
// textActions.toSelectMode(true);
|
||||
// }
|
||||
if(last_x === mouse_x && last_y === mouse_y && evt.target !== curtext) {
|
||||
textActions.toSelectMode(true);
|
||||
}
|
||||
|
||||
},
|
||||
setCursor: setCursor,
|
||||
toEditMode: function(x, y) {
|
||||
allow_dbl = false;
|
||||
current_mode = "textedit";
|
||||
selectorManager.requestSelector(curtext).showGrips(false);
|
||||
|
||||
textActions.init();
|
||||
$(curtext).css('cursor', 'text');
|
||||
|
||||
if(!arguments.length) {
|
||||
setCursor();
|
||||
} else {
|
||||
var pt = screenToPt(x, y);
|
||||
setCursorFromPoint(pt.x, pt.y);
|
||||
}
|
||||
|
||||
setTimeout(function() {
|
||||
allow_dbl = true;
|
||||
}, 300);
|
||||
},
|
||||
toSelectMode: function(selectElem) {
|
||||
current_mode = "select";
|
||||
clearInterval(blinker);
|
||||
blinker = null;
|
||||
if(selblock) $(selblock).attr('display','none');
|
||||
if(cursor) $(cursor).attr('visibility','hidden');
|
||||
$(curtext).css('cursor', 'move');
|
||||
|
||||
if(selectElem) {
|
||||
canvas.clearSelection();
|
||||
$(curtext).css('cursor', 'move');
|
||||
|
||||
call("selected", [curtext]);
|
||||
canvas.addToSelection([curtext], true);
|
||||
}
|
||||
if(!curtext.textContent.length) {
|
||||
// No content, so delete
|
||||
canvas.deleteSelectedElements();
|
||||
}
|
||||
|
||||
curtext = false;
|
||||
},
|
||||
setInputElem: function(elem) {
|
||||
textinput = elem;
|
||||
$(textinput).blur(hideCursor);
|
||||
},
|
||||
clear: function() {
|
||||
if(current_mode == "textedit") {
|
||||
textActions.toSelectMode();
|
||||
}
|
||||
},
|
||||
init: function(inputElem) {
|
||||
if(!curtext) return;
|
||||
|
||||
if(!curtext.parentNode) {
|
||||
// Result of the ffClone, need to get correct element
|
||||
curtext = selectedElements[0];
|
||||
selectorManager.requestSelector(curtext).showGrips(false);
|
||||
}
|
||||
|
||||
var str = curtext.textContent;
|
||||
var len = str.length;
|
||||
|
||||
xform = curtext.getAttribute('transform');
|
||||
|
||||
textbb = canvas.getBBox(curtext);
|
||||
|
||||
if(xform) {
|
||||
var tlist = canvas.getTransformList(curtext);
|
||||
var matrix = transformListToTransform(tlist).matrix;
|
||||
imatrix = matrix.inverse();
|
||||
// var tbox = transformBox(textbb.x, textbb.y, textbb.width, textbb.height, matrix);
|
||||
// transbb = {
|
||||
// width: tbox.tr.x - tbox.tl.x,
|
||||
// height: tbox.bl.y - tbox.tl.y,
|
||||
// x: tbox.tl.x,
|
||||
// y: tbox.tl.y
|
||||
// }
|
||||
} else {
|
||||
// transbb = textbb;
|
||||
}
|
||||
|
||||
chardata = Array(len);
|
||||
textinput.focus();
|
||||
|
||||
$(curtext).unbind('dblclick', selectWord).dblclick(selectWord);
|
||||
|
||||
if(!len) {
|
||||
var end = {x: textbb.x + (textbb.width/2), width: 0};
|
||||
}
|
||||
|
||||
for(var i=0; i<len; i++) {
|
||||
var start = curtext.getStartPositionOfChar(i);
|
||||
var end = curtext.getEndPositionOfChar(i);
|
||||
|
||||
// Get a "bbox" equivalent for each character. Uses the
|
||||
// bbox data of the actual text for y, height purposes
|
||||
|
||||
// TODO: Decide if y, width and height are actually necessary
|
||||
chardata[i] = {
|
||||
x: start.x,
|
||||
y: textbb.y, // start.y?
|
||||
width: end.x - start.x,
|
||||
height: textbb.height
|
||||
};
|
||||
}
|
||||
|
||||
// Add a last bbox for cursor at end of text
|
||||
chardata.push({
|
||||
x: end.x,
|
||||
width: 0
|
||||
});
|
||||
|
||||
setSelection(textinput.selectionStart, textinput.selectionEnd, true);
|
||||
}
|
||||
}
|
||||
}();
|
||||
|
||||
var pathActions = function() {
|
||||
|
||||
var subpath = false;
|
||||
|
@ -5814,6 +6193,35 @@ function BatchCommand(text) {
|
|||
call("saved", str);
|
||||
};
|
||||
|
||||
this.rasterExport = function() {
|
||||
// remove the selected outline before serializing
|
||||
this.clearSelection();
|
||||
|
||||
// Check for known CanVG issues
|
||||
var issues = [];
|
||||
|
||||
// Selector and notice
|
||||
var issue_list = {
|
||||
'feGaussianBlur': 'Blurred elements will appear as un-blurred',
|
||||
'text': 'Text may not appear as expected',
|
||||
'image': 'Image elements will not appear',
|
||||
'foreignObject': 'foreignObject elements will not appear',
|
||||
'marker': 'Marker elements (arrows, etc) will not appear',
|
||||
'[stroke-dasharray]': 'Strokes will appear filled',
|
||||
'[stroke^=url]': 'Strokes with gradients will not appear'
|
||||
};
|
||||
var content = $(svgcontent);
|
||||
|
||||
$.each(issue_list, function(sel, descr) {
|
||||
if(content.find(sel).length) {
|
||||
issues.push(descr);
|
||||
}
|
||||
});
|
||||
|
||||
var str = svgCanvasToString();
|
||||
call("exported", {svg: str, issues: issues});
|
||||
};
|
||||
|
||||
// Walks the tree and executes the callback on each element in a top-down fashion
|
||||
var walkTree = function(elem, cbFn){
|
||||
if (elem && elem.nodeType == 1) {
|
||||
|
@ -6688,7 +7096,7 @@ function BatchCommand(text) {
|
|||
};
|
||||
};
|
||||
|
||||
this.getImageTitle = function() {
|
||||
this.getDocumentTitle = function() {
|
||||
var childs = svgcontent.childNodes;
|
||||
for (var i=0; i<childs.length; i++) {
|
||||
if(childs[i].nodeName == 'title') {
|
||||
|
@ -6698,7 +7106,7 @@ function BatchCommand(text) {
|
|||
return '';
|
||||
}
|
||||
|
||||
this.setImageTitle = function(newtitle) {
|
||||
this.setDocumentTitle = function(newtitle) {
|
||||
var childs = svgcontent.childNodes, doc_title = false, old_title = '';
|
||||
|
||||
var batchCmd = new BatchCommand("Change Image Title");
|
||||
|
@ -6852,6 +7260,7 @@ function BatchCommand(text) {
|
|||
|
||||
this.setMode = function(name) {
|
||||
pathActions.clear(true);
|
||||
textActions.clear();
|
||||
|
||||
cur_properties = (selectedElements[0] && selectedElements[0].nodeName == 'text') ? cur_text : cur_shape;
|
||||
current_mode = name;
|
||||
|
@ -7431,8 +7840,10 @@ function BatchCommand(text) {
|
|||
|
||||
this.setTextContent = function(val) {
|
||||
this.changeSelectedAttribute("#text", val);
|
||||
textActions.init(val);
|
||||
textActions.setCursor();
|
||||
};
|
||||
|
||||
|
||||
this.setImageURL = function(val) {
|
||||
var elem = selectedElements[0];
|
||||
if(!elem) return;
|
||||
|
@ -8413,8 +8824,8 @@ function BatchCommand(text) {
|
|||
if (relative_to == 'page') {
|
||||
minx = 0;
|
||||
miny = 0;
|
||||
maxx = svgcontent.getAttribute('width');
|
||||
maxy = svgcontent.getAttribute('height');
|
||||
maxx = canvas.contentW;
|
||||
maxy = canvas.contentH;
|
||||
}
|
||||
|
||||
var dx = new Array(len);
|
||||
|
@ -8453,7 +8864,7 @@ function BatchCommand(text) {
|
|||
// Function: getVersion
|
||||
// Returns a string which describes the revision number of SvgCanvas.
|
||||
this.getVersion = function() {
|
||||
return "svgcanvas.js ($Rev: 1514 $)";
|
||||
return "svgcanvas.js ($Rev: 1526 $)";
|
||||
};
|
||||
|
||||
this.setUiStrings = function(strs) {
|
||||
|
|
|
@ -23,7 +23,26 @@
|
|||
return [m.a,m.b,m.c,m.d,m.e,m.f].join(',');
|
||||
}
|
||||
|
||||
var svgCanvas = new SvgCanvas(document.getElementById("svgcanvas")),
|
||||
var svgCanvas = new $.SvgCanvas(document.getElementById("svgcanvas"), {
|
||||
canvas_expansion: 3,
|
||||
dimensions: [640,480],
|
||||
initFill: {
|
||||
color: 'FF0000', // solid red
|
||||
opacity: 1
|
||||
},
|
||||
initStroke: {
|
||||
width: 5,
|
||||
color: '000000', // solid black
|
||||
opacity: 1
|
||||
},
|
||||
initOpacity: 1,
|
||||
imgPath: 'images/',
|
||||
langPath: 'locale/',
|
||||
extPath: 'extensions/',
|
||||
extensions: ['ext-arrows.js', 'ext-connector.js', 'ext-eyedropper.js'],
|
||||
initTool: 'select',
|
||||
wireframe: false
|
||||
}),
|
||||
svgroot = document.getElementById("svgroot"),
|
||||
svgdoc = svgroot.documentElement,
|
||||
svgns = "http://www.w3.org/2000/svg",
|
||||
|
|
Loading…
Reference in a new issue