var wordArtPopup; function initWordArt() { $("body").append(''); $("#svgfont").load("img/font.svg?"); $("#btnWordArtOk").on("onButtonClick",onWordArtOk); $("#btnWordArtCancel").on("onButtonClick",onWordArtCancel); wordArtPopup = new Popup($("#popupWordArt"),$("#popupMask")); wordArtPopup.setEscapeKeyHandler(onWordArtCancel); wordArtPopup.setEnterKeyHandler(onWordArtOk); } function showWordArtDialog() { buttonGroupAdd.hide(); wordArtPopup.open(); $("#txtWordArt").focus(); $("#txtWordArt").val(""); //clear textbox } function onWordArtCancel() { wordArtPopup.close(); } function onWordArtOk() { wordArtPopup.close(); 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