From d362b886c2c32ba3a9aa83b474f3cf7154e7e9bc Mon Sep 17 00:00:00 2001 From: Jacques Distler Date: Wed, 10 Feb 2010 00:11:14 -0600 Subject: [PATCH] Make Embedded MathML Visible Thanks to Jeff Schiller for tracking down the problem (and committing preliminary MathML support to SVG-Edit). --- .../editor/extensions/ext-closepath.js | 75 ++++++ public/svg-edit/editor/svg-editor.css | 4 +- public/svg-edit/editor/svg-editor.html | 1 + public/svg-edit/editor/svg-editor.js | 30 +-- public/svg-edit/editor/svgcanvas.js | 233 +++++++++++++----- 5 files changed, 259 insertions(+), 84 deletions(-) create mode 100644 public/svg-edit/editor/extensions/ext-closepath.js diff --git a/public/svg-edit/editor/extensions/ext-closepath.js b/public/svg-edit/editor/extensions/ext-closepath.js new file mode 100644 index 00000000..2f943d02 --- /dev/null +++ b/public/svg-edit/editor/extensions/ext-closepath.js @@ -0,0 +1,75 @@ +/* + * ext-closepath.js + * + * Licensed under the Apache License, Version 2 + * + * Copyright(c) 2010 Jeff Schiller + * + */ + +// This extension adds a simple button to the contextual panel for paths +// The button toggles whether the path is open or closed +$(function() { + svgCanvas.addExtension("ClosePath", function(S) { + var selElems, + updateButton = function(path) { + var seglist = path.pathSegList, + button = $('#closepath_panel > div.tool_button')[0]; + $(button).html(seglist.getItem(seglist.numberOfItems - 1).pathSegType==1 ? "open":"close"); + }, + showPanel = function(on) { + $('#closepath_panel').toggle(on); + if (on) { + var path = selElems[0]; + if (path) updateButton(path); + } + }, + + toggleClosed = function() { + var path = selElems[0]; + if (path) { + var seglist = path.pathSegList, + last = seglist.numberOfItems - 1; + // is closed + if(seglist.getItem(last).pathSegType == 1) { + seglist.removeItem(last); + } + else { + seglist.appendItem(path.createSVGPathSegClosePath()); + } + updateButton(path); + } + }; + + return { + name: "ClosePath", + context_tools: [{ + type: "tool_button", + panel: "closepath_panel", + title: "Open or Close path", + id: "close", + events: { mousedown: toggleClosed } + }], + callback: function() { + $('#closepath_panel').hide(); + }, + selectedChanged: function(opts) { + selElems = opts.elems; + var i = selElems.length; + + while(i--) { + var elem = selElems[i]; + if(elem && elem.tagName == 'path') { + if(opts.selectedElement && !opts.multiselected) { + showPanel(true); + } else { + showPanel(false); + } + } else { + showPanel(false); + } + } + }, + }; + }); +}); diff --git a/public/svg-edit/editor/svg-editor.css b/public/svg-edit/editor/svg-editor.css index da5dbfee..00e5c941 100644 --- a/public/svg-edit/editor/svg-editor.css +++ b/public/svg-edit/editor/svg-editor.css @@ -1,4 +1,4 @@ -body { +body { background: #E8E8E8; } @@ -35,6 +35,7 @@ vertical-align: middle; width: 640px; height: 480px; + line-height:normal; -apple-dashboard-region:dashboard-region(control rectangle 0px 0px 0px 0px); /* for widget regions that shouldn't react to dragging */ position: relative; /* @@ -957,3 +958,4 @@ button#tool_docprops_cancel { -webkit-border-radius: 0px; } +foreignObject { line-height:1.0; } \ No newline at end of file diff --git a/public/svg-edit/editor/svg-editor.html b/public/svg-edit/editor/svg-editor.html index b5ae50e3..891172b9 100644 --- a/public/svg-edit/editor/svg-editor.html +++ b/public/svg-edit/editor/svg-editor.html @@ -18,6 +18,7 @@ + diff --git a/public/svg-edit/editor/svg-editor.js b/public/svg-edit/editor/svg-editor.js index ed6919a4..8a03440a 100644 --- a/public/svg-edit/editor/svg-editor.js +++ b/public/svg-edit/editor/svg-editor.js @@ -166,8 +166,6 @@ function svg_edit_setup() { var multiselected = false; var editingsource = false; var docprops = false; - var length_attrs = ['x','y','x1','x2','y1','y2','cx','cy','width','height','r','rx','ry','width','height','radius']; - var length_types = ['em','ex','px','cm','mm','in','pt','pc','%']; var fillPaint = new $.jGraduate.Paint({solidColor: "FF0000"}); // solid red var strokePaint = new $.jGraduate.Paint({solidColor: "000000"}); // solid black @@ -177,7 +175,7 @@ function svg_edit_setup() { // with a gradient will appear black in Firefox, etc. See bug 308590 // https://bugzilla.mozilla.org/show_bug.cgi?id=308590 var saveHandler = function(window,svg) { - window.opener.postMessage(svg, window.location.protocol + '//' + window.location.host); + window.opener.postMessage(svg, window.location.protocol + '//' + window.location.host); }; // called when we've selected a different element @@ -542,6 +540,15 @@ function svg_edit_setup() { // TODO: Allow support for other types, or adding to existing tool switch (tool.type) { + case 'tool_button': + var html = '
' + tool.id + '
'; + var div = $(html).appendTo(panel); + if (tool.events) { + $.each(tool.events, function(evt, func) { + $(div).bind(evt, func); + }); + } + break; case 'select': var html = '' + '