topical media & game development

talk show tell print

lib-present-graphic-svg-scale-symbols.js / js



  function scaleObject(evt,factor) {
          //reference to the currently selected object
          var element = evt.currentTarget;
  
          //query old transform value (we need the translation value)
          var curTransform = element.getAttributeNS(null,"transform");
          //no fear from Regular expressions ... just copy it, I copied it either ...
          var translateRegExp=/translate\(([-+]?[\d.]+)(\s*[\s,]\s*)([-+]?[\d.]+)\)\s*/;
  
          //This part extracts the translation-value from the whole transform-string
          if (curTransform.length != 0)
          {
            var result = curTransform.match(translateRegExp);
            if (result == null || result.index == -1)
            {
               oldTranslateX = 0;
               oldTranslateY = 0;
            }
            else
            {
               oldTranslateX = result[1];
               oldTranslateY = result[3];
            }
            //concatenate the string again, add scale-factor
            var newtransform = "translate(" + oldTranslateX + " " + oldTranslateY + ") " + "scale(" + factor + ")";
          }
          //set transform-factor
          element.setAttributeNS(null,'transform', newtransform);
  }
  


(C) Æliens 04/09/2009

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.