var wordArtPopup; function initWordArt() { $("body").append(''); $("#svgfont").load("img/font.svg?"); wordArtPopup = new Popup($("#popupWordArt"),$("#popupMask")); $("#btnWordArtOk").on("onButtonClick",wordArtPopup.commit); $("#btnWordArtCancel").on("onButtonClick",wordArtPopup.cancel); $("#popupWordArt").bind("onPopupCancel", onWordArtCancel); $("#popupWordArt").bind("onPopupCommit", onWordArtOk); } function showWordArtDialog() { buttonGroupAdd.hide(); wordArtPopup.open(); $("#txtWordArt").focus(); $("#txtWordArt").val(""); //clear textbox } function onWordArtCancel() { $("#txtWordArt").blur(); } function onWordArtOk() { $("#txtWordArt").blur(); var s = $("#txtWordArt").val(); drawTextOnCanvas(s); } function drawTextOnCanvas(text) { if (typeof(text) == 'string') { var points = getStringAsPoints(text); var bounds = getBounds(points); var scaleX = (canvasWidth-50) / bounds.width; var scaleY = (canvasHeight-50) / bounds.height; var scale = Math.min(scaleX,scaleY); scalePoints(points,scale); var bounds = getBounds(points); translatePoints(points,-bounds.x,-bounds.y); //left top of text is (0,0) translatePoints(points,-bounds.width/2,-bounds.height/2); //anchor point center translatePoints(points,canvasWidth/2,canvasHeight/2); //center in canvas canvasDrawPoints(canvas,points); } } function getStringAsPoints(text) { var allPoints = []; var xPos = 0; for (var i=0; i