1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219 |
- /**
- * Copyright (c) 2006-2015, JGraph Ltd
- * Copyright (c) 2006-2015, Gaudenz Alder
- */
- /**
- * Class: mxXmlCanvas2D
- *
- * Base class for all canvases. The following methods make up the public
- * interface of the canvas 2D for all painting in mxGraph:
- *
- * - <save>, <restore>
- * - <scale>, <translate>, <rotate>
- * - <setAlpha>, <setFillAlpha>, <setStrokeAlpha>, <setFillColor>, <setGradient>,
- * <setStrokeColor>, <setStrokeWidth>, <setDashed>, <setDashPattern>, <setLineCap>,
- * <setLineJoin>, <setMiterLimit>
- * - <setFontColor>, <setFontBackgroundColor>, <setFontBorderColor>, <setFontSize>,
- * <setFontFamily>, <setFontStyle>
- * - <setShadow>, <setShadowColor>, <setShadowAlpha>, <setShadowOffset>
- * - <rect>, <roundrect>, <ellipse>, <image>, <text>
- * - <begin>, <moveTo>, <lineTo>, <quadTo>, <curveTo>
- * - <stroke>, <fill>, <fillAndStroke>
- *
- * <mxAbstractCanvas2D.arcTo> is an additional method for drawing paths. This is
- * a synthetic method, meaning that it is turned into a sequence of curves by
- * default. Subclassers may add native support for arcs.
- *
- * Constructor: mxXmlCanvas2D
- *
- * Constructs a new abstract canvas.
- */
- function mxXmlCanvas2D(root)
- {
- mxAbstractCanvas2D.call(this);
- /**
- * Variable: root
- *
- * Reference to the container for the SVG content.
- */
- this.root = root;
- // Writes default settings;
- this.writeDefaults();
- };
- /**
- * Extends mxAbstractCanvas2D
- */
- mxUtils.extend(mxXmlCanvas2D, mxAbstractCanvas2D);
- /**
- * Variable: textEnabled
- *
- * Specifies if text output should be enabled. Default is true.
- */
- mxXmlCanvas2D.prototype.textEnabled = true;
- /**
- * Variable: compressed
- *
- * Specifies if the output should be compressed by removing redundant calls.
- * Default is true.
- */
- mxXmlCanvas2D.prototype.compressed = true;
- /**
- * Function: writeDefaults
- *
- * Writes the rendering defaults to <root>:
- */
- mxXmlCanvas2D.prototype.writeDefaults = function()
- {
- var elem;
-
- // Writes font defaults
- elem = this.createElement('fontfamily');
- elem.setAttribute('family', mxConstants.DEFAULT_FONTFAMILY);
- this.root.appendChild(elem);
-
- elem = this.createElement('fontsize');
- elem.setAttribute('size', mxConstants.DEFAULT_FONTSIZE);
- this.root.appendChild(elem);
-
- // Writes shadow defaults
- elem = this.createElement('shadowcolor');
- elem.setAttribute('color', mxConstants.SHADOWCOLOR);
- this.root.appendChild(elem);
-
- elem = this.createElement('shadowalpha');
- elem.setAttribute('alpha', mxConstants.SHADOW_OPACITY);
- this.root.appendChild(elem);
-
- elem = this.createElement('shadowoffset');
- elem.setAttribute('dx', mxConstants.SHADOW_OFFSET_X);
- elem.setAttribute('dy', mxConstants.SHADOW_OFFSET_Y);
- this.root.appendChild(elem);
- };
- /**
- * Function: format
- *
- * Returns a formatted number with 2 decimal places.
- */
- mxXmlCanvas2D.prototype.format = function(value)
- {
- return parseFloat(parseFloat(value).toFixed(2));
- };
- /**
- * Function: createElement
- *
- * Creates the given element using the owner document of <root>.
- */
- mxXmlCanvas2D.prototype.createElement = function(name)
- {
- return this.root.ownerDocument.createElement(name);
- };
- /**
- * Function: save
- *
- * Saves the drawing state.
- */
- mxXmlCanvas2D.prototype.save = function()
- {
- if (this.compressed)
- {
- mxAbstractCanvas2D.prototype.save.apply(this, arguments);
- }
-
- this.root.appendChild(this.createElement('save'));
- };
- /**
- * Function: restore
- *
- * Restores the drawing state.
- */
- mxXmlCanvas2D.prototype.restore = function()
- {
- if (this.compressed)
- {
- mxAbstractCanvas2D.prototype.restore.apply(this, arguments);
- }
-
- this.root.appendChild(this.createElement('restore'));
- };
- /**
- * Function: scale
- *
- * Scales the output.
- *
- * Parameters:
- *
- * scale - Number that represents the scale where 1 is equal to 100%.
- */
- mxXmlCanvas2D.prototype.scale = function(value)
- {
- var elem = this.createElement('scale');
- elem.setAttribute('scale', value);
- this.root.appendChild(elem);
- };
- /**
- * Function: translate
- *
- * Translates the output.
- *
- * Parameters:
- *
- * dx - Number that specifies the horizontal translation.
- * dy - Number that specifies the vertical translation.
- */
- mxXmlCanvas2D.prototype.translate = function(dx, dy)
- {
- var elem = this.createElement('translate');
- elem.setAttribute('dx', this.format(dx));
- elem.setAttribute('dy', this.format(dy));
- this.root.appendChild(elem);
- };
- /**
- * Function: rotate
- *
- * Rotates and/or flips the output around a given center. (Note: Due to
- * limitations in VML, the rotation cannot be concatenated.)
- *
- * Parameters:
- *
- * theta - Number that represents the angle of the rotation (in degrees).
- * flipH - Boolean indicating if the output should be flipped horizontally.
- * flipV - Boolean indicating if the output should be flipped vertically.
- * cx - Number that represents the x-coordinate of the rotation center.
- * cy - Number that represents the y-coordinate of the rotation center.
- */
- mxXmlCanvas2D.prototype.rotate = function(theta, flipH, flipV, cx, cy)
- {
- var elem = this.createElement('rotate');
-
- if (theta != 0 || flipH || flipV)
- {
- elem.setAttribute('theta', this.format(theta));
- elem.setAttribute('flipH', (flipH) ? '1' : '0');
- elem.setAttribute('flipV', (flipV) ? '1' : '0');
- elem.setAttribute('cx', this.format(cx));
- elem.setAttribute('cy', this.format(cy));
- this.root.appendChild(elem);
- }
- };
- /**
- * Function: setAlpha
- *
- * Sets the current alpha.
- *
- * Parameters:
- *
- * value - Number that represents the new alpha. Possible values are between
- * 1 (opaque) and 0 (transparent).
- */
- mxXmlCanvas2D.prototype.setAlpha = function(value)
- {
- if (this.compressed)
- {
- if (this.state.alpha == value)
- {
- return;
- }
-
- mxAbstractCanvas2D.prototype.setAlpha.apply(this, arguments);
- }
-
- var elem = this.createElement('alpha');
- elem.setAttribute('alpha', this.format(value));
- this.root.appendChild(elem);
- };
- /**
- * Function: setFillAlpha
- *
- * Sets the current fill alpha.
- *
- * Parameters:
- *
- * value - Number that represents the new fill alpha. Possible values are between
- * 1 (opaque) and 0 (transparent).
- */
- mxXmlCanvas2D.prototype.setFillAlpha = function(value)
- {
- if (this.compressed)
- {
- if (this.state.fillAlpha == value)
- {
- return;
- }
-
- mxAbstractCanvas2D.prototype.setFillAlpha.apply(this, arguments);
- }
-
- var elem = this.createElement('fillalpha');
- elem.setAttribute('alpha', this.format(value));
- this.root.appendChild(elem);
- };
- /**
- * Function: setStrokeAlpha
- *
- * Sets the current stroke alpha.
- *
- * Parameters:
- *
- * value - Number that represents the new stroke alpha. Possible values are between
- * 1 (opaque) and 0 (transparent).
- */
- mxXmlCanvas2D.prototype.setStrokeAlpha = function(value)
- {
- if (this.compressed)
- {
- if (this.state.strokeAlpha == value)
- {
- return;
- }
-
- mxAbstractCanvas2D.prototype.setStrokeAlpha.apply(this, arguments);
- }
-
- var elem = this.createElement('strokealpha');
- elem.setAttribute('alpha', this.format(value));
- this.root.appendChild(elem);
- };
- /**
- * Function: setFillColor
- *
- * Sets the current fill color.
- *
- * Parameters:
- *
- * value - Hexadecimal representation of the color or 'none'.
- */
- mxXmlCanvas2D.prototype.setFillColor = function(value)
- {
- if (value == mxConstants.NONE)
- {
- value = null;
- }
-
- if (this.compressed)
- {
- if (this.state.fillColor == value)
- {
- return;
- }
-
- mxAbstractCanvas2D.prototype.setFillColor.apply(this, arguments);
- }
-
- var elem = this.createElement('fillcolor');
- elem.setAttribute('color', (value != null) ? value : mxConstants.NONE);
- this.root.appendChild(elem);
- };
- /**
- * Function: setGradient
- *
- * Sets the gradient. Note that the coordinates may be ignored by some implementations.
- *
- * Parameters:
- *
- * color1 - Hexadecimal representation of the start color.
- * color2 - Hexadecimal representation of the end color.
- * x - X-coordinate of the gradient region.
- * y - y-coordinate of the gradient region.
- * w - Width of the gradient region.
- * h - Height of the gradient region.
- * direction - One of <mxConstants.DIRECTION_NORTH>, <mxConstants.DIRECTION_EAST>,
- * <mxConstants.DIRECTION_SOUTH> or <mxConstants.DIRECTION_WEST>.
- * alpha1 - Optional alpha of the start color. Default is 1. Possible values
- * are between 1 (opaque) and 0 (transparent).
- * alpha2 - Optional alpha of the end color. Default is 1. Possible values
- * are between 1 (opaque) and 0 (transparent).
- */
- mxXmlCanvas2D.prototype.setGradient = function(color1, color2, x, y, w, h, direction, alpha1, alpha2)
- {
- if (color1 != null && color2 != null)
- {
- mxAbstractCanvas2D.prototype.setGradient.apply(this, arguments);
-
- var elem = this.createElement('gradient');
- elem.setAttribute('c1', color1);
- elem.setAttribute('c2', color2);
- elem.setAttribute('x', this.format(x));
- elem.setAttribute('y', this.format(y));
- elem.setAttribute('w', this.format(w));
- elem.setAttribute('h', this.format(h));
-
- // Default direction is south
- if (direction != null)
- {
- elem.setAttribute('direction', direction);
- }
-
- if (alpha1 != null)
- {
- elem.setAttribute('alpha1', alpha1);
- }
-
- if (alpha2 != null)
- {
- elem.setAttribute('alpha2', alpha2);
- }
-
- this.root.appendChild(elem);
- }
- };
- /**
- * Function: setStrokeColor
- *
- * Sets the current stroke color.
- *
- * Parameters:
- *
- * value - Hexadecimal representation of the color or 'none'.
- */
- mxXmlCanvas2D.prototype.setStrokeColor = function(value)
- {
- if (value == mxConstants.NONE)
- {
- value = null;
- }
-
- if (this.compressed)
- {
- if (this.state.strokeColor == value)
- {
- return;
- }
-
- mxAbstractCanvas2D.prototype.setStrokeColor.apply(this, arguments);
- }
-
- var elem = this.createElement('strokecolor');
- elem.setAttribute('color', (value != null) ? value : mxConstants.NONE);
- this.root.appendChild(elem);
- };
- /**
- * Function: setStrokeWidth
- *
- * Sets the current stroke width.
- *
- * Parameters:
- *
- * value - Numeric representation of the stroke width.
- */
- mxXmlCanvas2D.prototype.setStrokeWidth = function(value)
- {
- if (this.compressed)
- {
- if (this.state.strokeWidth == value)
- {
- return;
- }
-
- mxAbstractCanvas2D.prototype.setStrokeWidth.apply(this, arguments);
- }
-
- var elem = this.createElement('strokewidth');
- elem.setAttribute('width', this.format(value));
- this.root.appendChild(elem);
- };
- /**
- * Function: setDashed
- *
- * Enables or disables dashed lines.
- *
- * Parameters:
- *
- * value - Boolean that specifies if dashed lines should be enabled.
- * value - Boolean that specifies if the stroke width should be ignored
- * for the dash pattern. Default is false.
- */
- mxXmlCanvas2D.prototype.setDashed = function(value, fixDash)
- {
- if (this.compressed)
- {
- if (this.state.dashed == value)
- {
- return;
- }
-
- mxAbstractCanvas2D.prototype.setDashed.apply(this, arguments);
- }
-
- var elem = this.createElement('dashed');
- elem.setAttribute('dashed', (value) ? '1' : '0');
-
- if (fixDash != null)
- {
- elem.setAttribute('fixDash', (fixDash) ? '1' : '0');
- }
-
- this.root.appendChild(elem);
- };
- /**
- * Function: setDashPattern
- *
- * Sets the current dash pattern. Default is '3 3'.
- *
- * Parameters:
- *
- * value - String that represents the dash pattern, which is a sequence of
- * numbers defining the length of the dashes and the length of the spaces
- * between the dashes. The lengths are relative to the line width - a length
- * of 1 is equals to the line width.
- */
- mxXmlCanvas2D.prototype.setDashPattern = function(value)
- {
- if (this.compressed)
- {
- if (this.state.dashPattern == value)
- {
- return;
- }
-
- mxAbstractCanvas2D.prototype.setDashPattern.apply(this, arguments);
- }
-
- var elem = this.createElement('dashpattern');
- elem.setAttribute('pattern', value);
- this.root.appendChild(elem);
- };
- /**
- * Function: setLineCap
- *
- * Sets the line cap. Default is 'flat' which corresponds to 'butt' in SVG.
- *
- * Parameters:
- *
- * value - String that represents the line cap. Possible values are flat, round
- * and square.
- */
- mxXmlCanvas2D.prototype.setLineCap = function(value)
- {
- if (this.compressed)
- {
- if (this.state.lineCap == value)
- {
- return;
- }
-
- mxAbstractCanvas2D.prototype.setLineCap.apply(this, arguments);
- }
-
- var elem = this.createElement('linecap');
- elem.setAttribute('cap', value);
- this.root.appendChild(elem);
- };
- /**
- * Function: setLineJoin
- *
- * Sets the line join. Default is 'miter'.
- *
- * Parameters:
- *
- * value - String that represents the line join. Possible values are miter,
- * round and bevel.
- */
- mxXmlCanvas2D.prototype.setLineJoin = function(value)
- {
- if (this.compressed)
- {
- if (this.state.lineJoin == value)
- {
- return;
- }
-
- mxAbstractCanvas2D.prototype.setLineJoin.apply(this, arguments);
- }
-
- var elem = this.createElement('linejoin');
- elem.setAttribute('join', value);
- this.root.appendChild(elem);
- };
- /**
- * Function: setMiterLimit
- *
- * Sets the miter limit. Default is 10.
- *
- * Parameters:
- *
- * value - Number that represents the miter limit.
- */
- mxXmlCanvas2D.prototype.setMiterLimit = function(value)
- {
- if (this.compressed)
- {
- if (this.state.miterLimit == value)
- {
- return;
- }
-
- mxAbstractCanvas2D.prototype.setMiterLimit.apply(this, arguments);
- }
-
- var elem = this.createElement('miterlimit');
- elem.setAttribute('limit', value);
- this.root.appendChild(elem);
- };
- /**
- * Function: setFontColor
- *
- * Sets the current font color. Default is '#000000'.
- *
- * Parameters:
- *
- * value - Hexadecimal representation of the color or 'none'.
- */
- mxXmlCanvas2D.prototype.setFontColor = function(value)
- {
- if (this.textEnabled)
- {
- if (value == mxConstants.NONE)
- {
- value = null;
- }
-
- if (this.compressed)
- {
- if (this.state.fontColor == value)
- {
- return;
- }
-
- mxAbstractCanvas2D.prototype.setFontColor.apply(this, arguments);
- }
-
- var elem = this.createElement('fontcolor');
- elem.setAttribute('color', (value != null) ? value : mxConstants.NONE);
- this.root.appendChild(elem);
- }
- };
- /**
- * Function: setFontBackgroundColor
- *
- * Sets the current font background color.
- *
- * Parameters:
- *
- * value - Hexadecimal representation of the color or 'none'.
- */
- mxXmlCanvas2D.prototype.setFontBackgroundColor = function(value)
- {
- if (this.textEnabled)
- {
- if (value == mxConstants.NONE)
- {
- value = null;
- }
-
- if (this.compressed)
- {
- if (this.state.fontBackgroundColor == value)
- {
- return;
- }
-
- mxAbstractCanvas2D.prototype.setFontBackgroundColor.apply(this, arguments);
- }
- var elem = this.createElement('fontbackgroundcolor');
- elem.setAttribute('color', (value != null) ? value : mxConstants.NONE);
- this.root.appendChild(elem);
- }
- };
- /**
- * Function: setFontBorderColor
- *
- * Sets the current font border color.
- *
- * Parameters:
- *
- * value - Hexadecimal representation of the color or 'none'.
- */
- mxXmlCanvas2D.prototype.setFontBorderColor = function(value)
- {
- if (this.textEnabled)
- {
- if (value == mxConstants.NONE)
- {
- value = null;
- }
-
- if (this.compressed)
- {
- if (this.state.fontBorderColor == value)
- {
- return;
- }
-
- mxAbstractCanvas2D.prototype.setFontBorderColor.apply(this, arguments);
- }
-
- var elem = this.createElement('fontbordercolor');
- elem.setAttribute('color', (value != null) ? value : mxConstants.NONE);
- this.root.appendChild(elem);
- }
- };
- /**
- * Function: setFontSize
- *
- * Sets the current font size. Default is <mxConstants.DEFAULT_FONTSIZE>.
- *
- * Parameters:
- *
- * value - Numeric representation of the font size.
- */
- mxXmlCanvas2D.prototype.setFontSize = function(value)
- {
- if (this.textEnabled)
- {
- if (this.compressed)
- {
- if (this.state.fontSize == value)
- {
- return;
- }
-
- mxAbstractCanvas2D.prototype.setFontSize.apply(this, arguments);
- }
-
- var elem = this.createElement('fontsize');
- elem.setAttribute('size', value);
- this.root.appendChild(elem);
- }
- };
- /**
- * Function: setFontFamily
- *
- * Sets the current font family. Default is <mxConstants.DEFAULT_FONTFAMILY>.
- *
- * Parameters:
- *
- * value - String representation of the font family. This handles the same
- * values as the CSS font-family property.
- */
- mxXmlCanvas2D.prototype.setFontFamily = function(value)
- {
- if (this.textEnabled)
- {
- if (this.compressed)
- {
- if (this.state.fontFamily == value)
- {
- return;
- }
-
- mxAbstractCanvas2D.prototype.setFontFamily.apply(this, arguments);
- }
-
- var elem = this.createElement('fontfamily');
- elem.setAttribute('family', value);
- this.root.appendChild(elem);
- }
- };
- /**
- * Function: setFontStyle
- *
- * Sets the current font style.
- *
- * Parameters:
- *
- * value - Numeric representation of the font family. This is the sum of the
- * font styles from <mxConstants>.
- */
- mxXmlCanvas2D.prototype.setFontStyle = function(value)
- {
- if (this.textEnabled)
- {
- if (value == null)
- {
- value = 0;
- }
-
- if (this.compressed)
- {
- if (this.state.fontStyle == value)
- {
- return;
- }
-
- mxAbstractCanvas2D.prototype.setFontStyle.apply(this, arguments);
- }
-
- var elem = this.createElement('fontstyle');
- elem.setAttribute('style', value);
- this.root.appendChild(elem);
- }
- };
- /**
- * Function: setShadow
- *
- * Enables or disables shadows.
- *
- * Parameters:
- *
- * value - Boolean that specifies if shadows should be enabled.
- */
- mxXmlCanvas2D.prototype.setShadow = function(value)
- {
- if (this.compressed)
- {
- if (this.state.shadow == value)
- {
- return;
- }
-
- mxAbstractCanvas2D.prototype.setShadow.apply(this, arguments);
- }
-
- var elem = this.createElement('shadow');
- elem.setAttribute('enabled', (value) ? '1' : '0');
- this.root.appendChild(elem);
- };
- /**
- * Function: setShadowColor
- *
- * Sets the current shadow color. Default is <mxConstants.SHADOWCOLOR>.
- *
- * Parameters:
- *
- * value - Hexadecimal representation of the color or 'none'.
- */
- mxXmlCanvas2D.prototype.setShadowColor = function(value)
- {
- if (this.compressed)
- {
- if (value == mxConstants.NONE)
- {
- value = null;
- }
-
- if (this.state.shadowColor == value)
- {
- return;
- }
-
- mxAbstractCanvas2D.prototype.setShadowColor.apply(this, arguments);
- }
-
- var elem = this.createElement('shadowcolor');
- elem.setAttribute('color', (value != null) ? value : mxConstants.NONE);
- this.root.appendChild(elem);
- };
- /**
- * Function: setShadowAlpha
- *
- * Sets the current shadows alpha. Default is <mxConstants.SHADOW_OPACITY>.
- *
- * Parameters:
- *
- * value - Number that represents the new alpha. Possible values are between
- * 1 (opaque) and 0 (transparent).
- */
- mxXmlCanvas2D.prototype.setShadowAlpha = function(value)
- {
- if (this.compressed)
- {
- if (this.state.shadowAlpha == value)
- {
- return;
- }
-
- mxAbstractCanvas2D.prototype.setShadowAlpha.apply(this, arguments);
- }
-
- var elem = this.createElement('shadowalpha');
- elem.setAttribute('alpha', value);
- this.root.appendChild(elem);
-
- };
- /**
- * Function: setShadowOffset
- *
- * Sets the current shadow offset.
- *
- * Parameters:
- *
- * dx - Number that represents the horizontal offset of the shadow.
- * dy - Number that represents the vertical offset of the shadow.
- */
- mxXmlCanvas2D.prototype.setShadowOffset = function(dx, dy)
- {
- if (this.compressed)
- {
- if (this.state.shadowDx == dx && this.state.shadowDy == dy)
- {
- return;
- }
-
- mxAbstractCanvas2D.prototype.setShadowOffset.apply(this, arguments);
- }
-
- var elem = this.createElement('shadowoffset');
- elem.setAttribute('dx', dx);
- elem.setAttribute('dy', dy);
- this.root.appendChild(elem);
-
- };
- /**
- * Function: rect
- *
- * Puts a rectangle into the drawing buffer.
- *
- * Parameters:
- *
- * x - Number that represents the x-coordinate of the rectangle.
- * y - Number that represents the y-coordinate of the rectangle.
- * w - Number that represents the width of the rectangle.
- * h - Number that represents the height of the rectangle.
- */
- mxXmlCanvas2D.prototype.rect = function(x, y, w, h)
- {
- var elem = this.createElement('rect');
- elem.setAttribute('x', this.format(x));
- elem.setAttribute('y', this.format(y));
- elem.setAttribute('w', this.format(w));
- elem.setAttribute('h', this.format(h));
- this.root.appendChild(elem);
- };
- /**
- * Function: roundrect
- *
- * Puts a rounded rectangle into the drawing buffer.
- *
- * Parameters:
- *
- * x - Number that represents the x-coordinate of the rectangle.
- * y - Number that represents the y-coordinate of the rectangle.
- * w - Number that represents the width of the rectangle.
- * h - Number that represents the height of the rectangle.
- * dx - Number that represents the horizontal rounding.
- * dy - Number that represents the vertical rounding.
- */
- mxXmlCanvas2D.prototype.roundrect = function(x, y, w, h, dx, dy)
- {
- var elem = this.createElement('roundrect');
- elem.setAttribute('x', this.format(x));
- elem.setAttribute('y', this.format(y));
- elem.setAttribute('w', this.format(w));
- elem.setAttribute('h', this.format(h));
- elem.setAttribute('dx', this.format(dx));
- elem.setAttribute('dy', this.format(dy));
- this.root.appendChild(elem);
- };
- /**
- * Function: ellipse
- *
- * Puts an ellipse into the drawing buffer.
- *
- * Parameters:
- *
- * x - Number that represents the x-coordinate of the ellipse.
- * y - Number that represents the y-coordinate of the ellipse.
- * w - Number that represents the width of the ellipse.
- * h - Number that represents the height of the ellipse.
- */
- mxXmlCanvas2D.prototype.ellipse = function(x, y, w, h)
- {
- var elem = this.createElement('ellipse');
- elem.setAttribute('x', this.format(x));
- elem.setAttribute('y', this.format(y));
- elem.setAttribute('w', this.format(w));
- elem.setAttribute('h', this.format(h));
- this.root.appendChild(elem);
- };
- /**
- * Function: image
- *
- * Paints an image.
- *
- * Parameters:
- *
- * x - Number that represents the x-coordinate of the image.
- * y - Number that represents the y-coordinate of the image.
- * w - Number that represents the width of the image.
- * h - Number that represents the height of the image.
- * src - String that specifies the URL of the image.
- * aspect - Boolean indicating if the aspect of the image should be preserved.
- * flipH - Boolean indicating if the image should be flipped horizontally.
- * flipV - Boolean indicating if the image should be flipped vertically.
- */
- mxXmlCanvas2D.prototype.image = function(x, y, w, h, src, aspect, flipH, flipV)
- {
- src = this.converter.convert(src);
-
- // LATER: Add option for embedding images as base64.
- var elem = this.createElement('image');
- elem.setAttribute('x', this.format(x));
- elem.setAttribute('y', this.format(y));
- elem.setAttribute('w', this.format(w));
- elem.setAttribute('h', this.format(h));
- elem.setAttribute('src', src);
- elem.setAttribute('aspect', (aspect) ? '1' : '0');
- elem.setAttribute('flipH', (flipH) ? '1' : '0');
- elem.setAttribute('flipV', (flipV) ? '1' : '0');
- this.root.appendChild(elem);
- };
- /**
- * Function: begin
- *
- * Starts a new path and puts it into the drawing buffer.
- */
- mxXmlCanvas2D.prototype.begin = function()
- {
- this.root.appendChild(this.createElement('begin'));
- this.lastX = 0;
- this.lastY = 0;
- };
- /**
- * Function: moveTo
- *
- * Moves the current path the given point.
- *
- * Parameters:
- *
- * x - Number that represents the x-coordinate of the point.
- * y - Number that represents the y-coordinate of the point.
- */
- mxXmlCanvas2D.prototype.moveTo = function(x, y)
- {
- var elem = this.createElement('move');
- elem.setAttribute('x', this.format(x));
- elem.setAttribute('y', this.format(y));
- this.root.appendChild(elem);
- this.lastX = x;
- this.lastY = y;
- };
- /**
- * Function: lineTo
- *
- * Draws a line to the given coordinates.
- *
- * Parameters:
- *
- * x - Number that represents the x-coordinate of the endpoint.
- * y - Number that represents the y-coordinate of the endpoint.
- */
- mxXmlCanvas2D.prototype.lineTo = function(x, y)
- {
- var elem = this.createElement('line');
- elem.setAttribute('x', this.format(x));
- elem.setAttribute('y', this.format(y));
- this.root.appendChild(elem);
- this.lastX = x;
- this.lastY = y;
- };
- /**
- * Function: quadTo
- *
- * Adds a quadratic curve to the current path.
- *
- * Parameters:
- *
- * x1 - Number that represents the x-coordinate of the control point.
- * y1 - Number that represents the y-coordinate of the control point.
- * x2 - Number that represents the x-coordinate of the endpoint.
- * y2 - Number that represents the y-coordinate of the endpoint.
- */
- mxXmlCanvas2D.prototype.quadTo = function(x1, y1, x2, y2)
- {
- var elem = this.createElement('quad');
- elem.setAttribute('x1', this.format(x1));
- elem.setAttribute('y1', this.format(y1));
- elem.setAttribute('x2', this.format(x2));
- elem.setAttribute('y2', this.format(y2));
- this.root.appendChild(elem);
- this.lastX = x2;
- this.lastY = y2;
- };
- /**
- * Function: curveTo
- *
- * Adds a bezier curve to the current path.
- *
- * Parameters:
- *
- * x1 - Number that represents the x-coordinate of the first control point.
- * y1 - Number that represents the y-coordinate of the first control point.
- * x2 - Number that represents the x-coordinate of the second control point.
- * y2 - Number that represents the y-coordinate of the second control point.
- * x3 - Number that represents the x-coordinate of the endpoint.
- * y3 - Number that represents the y-coordinate of the endpoint.
- */
- mxXmlCanvas2D.prototype.curveTo = function(x1, y1, x2, y2, x3, y3)
- {
- var elem = this.createElement('curve');
- elem.setAttribute('x1', this.format(x1));
- elem.setAttribute('y1', this.format(y1));
- elem.setAttribute('x2', this.format(x2));
- elem.setAttribute('y2', this.format(y2));
- elem.setAttribute('x3', this.format(x3));
- elem.setAttribute('y3', this.format(y3));
- this.root.appendChild(elem);
- this.lastX = x3;
- this.lastY = y3;
- };
- /**
- * Function: close
- *
- * Closes the current path.
- */
- mxXmlCanvas2D.prototype.close = function()
- {
- this.root.appendChild(this.createElement('close'));
- };
- /**
- * Function: text
- *
- * Paints the given text. Possible values for format are empty string for
- * plain text and html for HTML markup. Background and border color as well
- * as clipping is not available in plain text labels for VML. HTML labels
- * are not available as part of shapes with no foreignObject support in SVG
- * (eg. IE9, IE10).
- *
- * Parameters:
- *
- * x - Number that represents the x-coordinate of the text.
- * y - Number that represents the y-coordinate of the text.
- * w - Number that represents the available width for the text or 0 for automatic width.
- * h - Number that represents the available height for the text or 0 for automatic height.
- * str - String that specifies the text to be painted.
- * align - String that represents the horizontal alignment.
- * valign - String that represents the vertical alignment.
- * wrap - Boolean that specifies if word-wrapping is enabled. Requires w > 0.
- * format - Empty string for plain text or 'html' for HTML markup.
- * overflow - Specifies the overflow behaviour of the label. Requires w > 0 and/or h > 0.
- * clip - Boolean that specifies if the label should be clipped. Requires w > 0 and/or h > 0.
- * rotation - Number that specifies the angle of the rotation around the anchor point of the text.
- * dir - Optional string that specifies the text direction. Possible values are rtl and lrt.
- */
- mxXmlCanvas2D.prototype.text = function(x, y, w, h, str, align, valign, wrap, format, overflow, clip, rotation, dir)
- {
- if (this.textEnabled && str != null)
- {
- if (mxUtils.isNode(str))
- {
- str = mxUtils.getOuterHtml(str);
- }
-
- var elem = this.createElement('text');
- elem.setAttribute('x', this.format(x));
- elem.setAttribute('y', this.format(y));
- elem.setAttribute('w', this.format(w));
- elem.setAttribute('h', this.format(h));
- elem.setAttribute('str', str);
-
- if (align != null)
- {
- elem.setAttribute('align', align);
- }
-
- if (valign != null)
- {
- elem.setAttribute('valign', valign);
- }
-
- elem.setAttribute('wrap', (wrap) ? '1' : '0');
-
- if (format == null)
- {
- format = '';
- }
-
- elem.setAttribute('format', format);
-
- if (overflow != null)
- {
- elem.setAttribute('overflow', overflow);
- }
-
- if (clip != null)
- {
- elem.setAttribute('clip', (clip) ? '1' : '0');
- }
-
- if (rotation != null)
- {
- elem.setAttribute('rotation', rotation);
- }
-
- if (dir != null)
- {
- elem.setAttribute('dir', dir);
- }
-
- this.root.appendChild(elem);
- }
- };
- /**
- * Function: stroke
- *
- * Paints the outline of the current drawing buffer.
- */
- mxXmlCanvas2D.prototype.stroke = function()
- {
- this.root.appendChild(this.createElement('stroke'));
- };
- /**
- * Function: fill
- *
- * Fills the current drawing buffer.
- */
- mxXmlCanvas2D.prototype.fill = function()
- {
- this.root.appendChild(this.createElement('fill'));
- };
- /**
- * Function: fillAndStroke
- *
- * Fills the current drawing buffer and its outline.
- */
- mxXmlCanvas2D.prototype.fillAndStroke = function()
- {
- this.root.appendChild(this.createElement('fillstroke'));
- };
- __mxOutput.mxXmlCanvas2D = typeof mxXmlCanvas2D !== 'undefined' ? mxXmlCanvas2D : undefined;
|