From 702b450fd9f9f661bcc25c840d8eabf4645d1387 Mon Sep 17 00:00:00 2001 From: Jacques Distler Date: Mon, 22 Feb 2010 00:05:52 -0600 Subject: [PATCH] itex Endpoint Add a Rack Metal itex endpoint. Add an itex tool to SVG-Edit. Disable the foreignObject tool (at least, for now) as it doesn't currently play nice with the itex tool. --- app/metal/itex.rb | 36 ++ .../editor/extensions/ext-foreignobject.js | 2 +- public/svg-edit/editor/extensions/ext-itex.js | 308 ++++++++++++++++++ .../svg-edit/editor/extensions/itex-icons.xml | 125 +++++++ public/svg-edit/editor/svg-editor.html | 3 +- public/svg-edit/editor/svgcanvas.js | 1 + 6 files changed, 473 insertions(+), 2 deletions(-) create mode 100644 app/metal/itex.rb create mode 100644 public/svg-edit/editor/extensions/ext-itex.js create mode 100644 public/svg-edit/editor/extensions/itex-icons.xml diff --git a/app/metal/itex.rb b/app/metal/itex.rb new file mode 100644 index 00000000..7e27ca3a --- /dev/null +++ b/app/metal/itex.rb @@ -0,0 +1,36 @@ +# Allow the metal piece to run in isolation +require(File.dirname(__FILE__) + "/../../config/environment") unless defined?(Rails) + +require 'stringsupport' + +class Itex + def self.call(env) + if env["PATH_INFO"] =~ /^\/itex/ + [200, {"Content-Type" => "application/xml"}, [response(env)]] + else + [404, {"Content-Type" => "text/html"}, ["Not Found"]] + end + end + + private + + def self.response(env) + @params = Rack::Request.new(env).params + tex = @params['tex'].purify + display = @params['display'] || 'inline' + filter = (display + '_filter').to_sym + estart = "" + eend = "" + begin + require 'itextomml' + itex2mml_parser = Itex2MML::Parser.new + itex2mml_parser.send(filter, tex).to_utf8 + rescue LoadError + estart + "Please install the itex2MML Ruby bindings." + eend + rescue Itex2MML::Error => e + estart + e.to_s + eend + rescue + estart + "Unknown Error" + eend + end + end +end diff --git a/public/svg-edit/editor/extensions/ext-foreignobject.js b/public/svg-edit/editor/extensions/ext-foreignobject.js index 456d66fa..2156f3cd 100644 --- a/public/svg-edit/editor/extensions/ext-foreignobject.js +++ b/public/svg-edit/editor/extensions/ext-foreignobject.js @@ -144,7 +144,7 @@ $(function() { }, { type: "input", panel: "foreignObject_panel", - title: "Change foreignObject's height", + title: "Change the font-size of enclosed content", id: "foreign_font_size", label: "font-size", size: 2, diff --git a/public/svg-edit/editor/extensions/ext-itex.js b/public/svg-edit/editor/extensions/ext-itex.js new file mode 100644 index 00000000..55c0df2b --- /dev/null +++ b/public/svg-edit/editor/extensions/ext-itex.js @@ -0,0 +1,308 @@ +/* + * ext-itex.js + * + * Licensed under the Apache License, Version 2 + * + * Copyright(c) 2010 Jacques Distler + * Copyright(c) 2010 Alexis Deveria + * + */ + +$(function() { + svgCanvas.addExtension("itex", function(S) { + var svgcontent = S.svgcontent, + addElem = S.addSvgElementFromJson, + selElems, + svgns = "http://www.w3.org/2000/svg", + xlinkns = "http://www.w3.org/1999/xlink", + xmlns = "http://www.w3.org/XML/1998/namespace", + xmlnsns = "http://www.w3.org/2000/xmlns/", + se_ns = "http://svg-edit.googlecode.com", + htmlns = "http://www.w3.org/1999/xhtml", + mathns = "http://www.w3.org/1998/Math/MathML", + editingitex = false, + svgdoc = S.svgroot.parentNode.ownerDocument, + started, + newFO; + + + var properlySourceSizeTextArea = function(){ + // TODO: remove magic numbers here and get values from CSS + var height = $('#svg_source_container').height() - 80; + $('#svg_source_textarea').css('height', height); + }; + + function showPanel(on) { + var fc_rules = $('#fc_rules'); + if(!fc_rules.length) { + fc_rules = $('