http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/e2cad6e6/externs/GCL/externs/goog/graphics/groupelement.js ---------------------------------------------------------------------- diff --git a/externs/GCL/externs/goog/graphics/groupelement.js b/externs/GCL/externs/goog/graphics/groupelement.js new file mode 100644 index 0000000..9e60cd7 --- /dev/null +++ b/externs/GCL/externs/goog/graphics/groupelement.js @@ -0,0 +1,58 @@ +// Copyright 2007 The Closure Library Authors. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS-IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + + +/** + * @fileoverview A thin wrapper around the DOM element for graphics groups. + * @author [email protected] (Erik Arvidsson) + */ + + +goog.provide('goog.graphics.GroupElement'); + +goog.require('goog.graphics.Element'); + + + +/** + * Interface for a graphics group element. + * You should not construct objects from this constructor. The graphics + * will return the object for you. + * @param {Element} element The DOM element to wrap. + * @param {goog.graphics.AbstractGraphics} graphics The graphics creating + * this element. + * @constructor + * @extends {goog.graphics.Element} + * @deprecated goog.graphics is deprecated. It existed to abstract over browser + * differences before the canvas tag was widely supported. See + * http://en.wikipedia.org/wiki/Canvas_element for details. + */ +goog.graphics.GroupElement = function(element, graphics) { + goog.graphics.Element.call(this, element, graphics); +}; +goog.inherits(goog.graphics.GroupElement, goog.graphics.Element); + + +/** + * Remove all drawing elements from the group. + */ +goog.graphics.GroupElement.prototype.clear = goog.abstractMethod; + + +/** + * Set the size of the group element. + * @param {number|string} width The width of the group element. + * @param {number|string} height The height of the group element. + */ +goog.graphics.GroupElement.prototype.setSize = goog.abstractMethod;
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/e2cad6e6/externs/GCL/externs/goog/graphics/imageelement.js ---------------------------------------------------------------------- diff --git a/externs/GCL/externs/goog/graphics/imageelement.js b/externs/GCL/externs/goog/graphics/imageelement.js new file mode 100644 index 0000000..2f2d9b7 --- /dev/null +++ b/externs/GCL/externs/goog/graphics/imageelement.js @@ -0,0 +1,70 @@ +// Copyright 2007 The Closure Library Authors. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS-IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + + +/** + * @fileoverview A thin wrapper around the DOM element for images. + */ + + +goog.provide('goog.graphics.ImageElement'); + +goog.require('goog.graphics.Element'); + + + +/** + * Interface for a graphics image element. + * You should not construct objects from this constructor. Instead, + * you should use {@code goog.graphics.Graphics.drawImage} and it + * will return an implementation of this interface for you. + * + * @param {Element} element The DOM element to wrap. + * @param {goog.graphics.AbstractGraphics} graphics The graphics creating + * this element. + * @constructor + * @extends {goog.graphics.Element} + * @deprecated goog.graphics is deprecated. It existed to abstract over browser + * differences before the canvas tag was widely supported. See + * http://en.wikipedia.org/wiki/Canvas_element for details. + */ +goog.graphics.ImageElement = function(element, graphics) { + goog.graphics.Element.call(this, element, graphics); +}; +goog.inherits(goog.graphics.ImageElement, goog.graphics.Element); + + +/** + * Update the position of the image. + * + * @param {number} x X coordinate (left). + * @param {number} y Y coordinate (top). + */ +goog.graphics.ImageElement.prototype.setPosition = goog.abstractMethod; + + +/** + * Update the size of the image. + * + * @param {number} width Width of image. + * @param {number} height Height of image. + */ +goog.graphics.ImageElement.prototype.setSize = goog.abstractMethod; + + +/** + * Update the source of the image. + * @param {string} src Source of the image. + */ +goog.graphics.ImageElement.prototype.setSource = goog.abstractMethod; http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/e2cad6e6/externs/GCL/externs/goog/graphics/lineargradient.js ---------------------------------------------------------------------- diff --git a/externs/GCL/externs/goog/graphics/lineargradient.js b/externs/GCL/externs/goog/graphics/lineargradient.js new file mode 100644 index 0000000..df59cbf --- /dev/null +++ b/externs/GCL/externs/goog/graphics/lineargradient.js @@ -0,0 +1,175 @@ +// Copyright 2007 The Closure Library Authors. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS-IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + + +/** + * @fileoverview Represents a gradient to be used with a Graphics implementor. + * @author [email protected] (Erik Arvidsson) + */ + + +goog.provide('goog.graphics.LinearGradient'); + + +goog.require('goog.asserts'); +goog.require('goog.graphics.Fill'); + + + +/** + * Creates an immutable linear gradient fill object. + * + * @param {number} x1 Start X position of the gradient. + * @param {number} y1 Start Y position of the gradient. + * @param {number} x2 End X position of the gradient. + * @param {number} y2 End Y position of the gradient. + * @param {string} color1 Start color of the gradient. + * @param {string} color2 End color of the gradient. + * @param {?number=} opt_opacity1 Start opacity of the gradient, both or neither + * of opt_opacity1 and opt_opacity2 have to be set. + * @param {?number=} opt_opacity2 End opacity of the gradient. + * @constructor + * @extends {goog.graphics.Fill} + * @deprecated goog.graphics is deprecated. It existed to abstract over browser + * differences before the canvas tag was widely supported. See + * http://en.wikipedia.org/wiki/Canvas_element for details. + * @final + */ +goog.graphics.LinearGradient = + function(x1, y1, x2, y2, color1, color2, opt_opacity1, opt_opacity2) { + /** + * Start X position of the gradient. + * @type {number} + * @private + */ + this.x1_ = x1; + + /** + * Start Y position of the gradient. + * @type {number} + * @private + */ + this.y1_ = y1; + + /** + * End X position of the gradient. + * @type {number} + * @private + */ + this.x2_ = x2; + + /** + * End Y position of the gradient. + * @type {number} + * @private + */ + this.y2_ = y2; + + /** + * Start color of the gradient. + * @type {string} + * @private + */ + this.color1_ = color1; + + /** + * End color of the gradient. + * @type {string} + * @private + */ + this.color2_ = color2; + + goog.asserts.assert( + goog.isNumber(opt_opacity1) == goog.isNumber(opt_opacity2), + 'Both or neither of opt_opacity1 and opt_opacity2 have to be set.'); + + /** + * Start opacity of the gradient. + * @type {?number} + * @private + */ + this.opacity1_ = goog.isDef(opt_opacity1) ? opt_opacity1 : null; + + /** + * End opacity of the gradient. + * @type {?number} + * @private + */ + this.opacity2_ = goog.isDef(opt_opacity2) ? opt_opacity2 : null; +}; +goog.inherits(goog.graphics.LinearGradient, goog.graphics.Fill); + + +/** + * @return {number} The start X position of the gradient. + */ +goog.graphics.LinearGradient.prototype.getX1 = function() { + return this.x1_; +}; + + +/** + * @return {number} The start Y position of the gradient. + */ +goog.graphics.LinearGradient.prototype.getY1 = function() { + return this.y1_; +}; + + +/** + * @return {number} The end X position of the gradient. + */ +goog.graphics.LinearGradient.prototype.getX2 = function() { + return this.x2_; +}; + + +/** + * @return {number} The end Y position of the gradient. + */ +goog.graphics.LinearGradient.prototype.getY2 = function() { + return this.y2_; +}; + + +/** + * @override + */ +goog.graphics.LinearGradient.prototype.getColor1 = function() { + return this.color1_; +}; + + +/** + * @override + */ +goog.graphics.LinearGradient.prototype.getColor2 = function() { + return this.color2_; +}; + + +/** + * @return {?number} The start opacity of the gradient. + */ +goog.graphics.LinearGradient.prototype.getOpacity1 = function() { + return this.opacity1_; +}; + + +/** + * @return {?number} The end opacity of the gradient. + */ +goog.graphics.LinearGradient.prototype.getOpacity2 = function() { + return this.opacity2_; +}; http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/e2cad6e6/externs/GCL/externs/goog/graphics/path.js ---------------------------------------------------------------------- diff --git a/externs/GCL/externs/goog/graphics/path.js b/externs/GCL/externs/goog/graphics/path.js new file mode 100644 index 0000000..c19f2d9 --- /dev/null +++ b/externs/GCL/externs/goog/graphics/path.js @@ -0,0 +1,511 @@ +// Copyright 2007 The Closure Library Authors. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS-IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + + +/** + * @fileoverview Represents a path used with a Graphics implementation. + * @author [email protected] (Erik Arvidsson) + */ + +goog.provide('goog.graphics.Path'); +goog.provide('goog.graphics.Path.Segment'); + +goog.require('goog.array'); +goog.require('goog.math'); + + + +/** + * Creates a path object. A path is a sequence of segments and may be open or + * closed. Path uses the EVEN-ODD fill rule for determining the interior of the + * path. A path must start with a moveTo command. + * + * A "simple" path does not contain any arcs and may be transformed using + * the {@code transform} method. + * + * @constructor + */ +goog.graphics.Path = function() { + /** + * The segment types that constitute this path. + * @type {!Array<number>} + * @private + */ + this.segments_ = []; + + /** + * The number of repeated segments of the current type. + * @type {!Array<number>} + * @private + */ + this.count_ = []; + + /** + * The arguments corresponding to each of the segments. + * @type {!Array<number>} + * @private + */ + this.arguments_ = []; +}; + + +/** + * The coordinates of the point which closes the path (the point of the + * last moveTo command). + * @type {Array<number>?} + * @private + */ +goog.graphics.Path.prototype.closePoint_ = null; + + +/** + * The coordinates most recently added to the end of the path. + * @type {Array<number>?} + * @private + */ +goog.graphics.Path.prototype.currentPoint_ = null; + + +/** + * Flag for whether this is a simple path (contains no arc segments). + * @type {boolean} + * @private + */ +goog.graphics.Path.prototype.simple_ = true; + + +/** + * Path segment types. + * @enum {number} + */ +goog.graphics.Path.Segment = { + MOVETO: 0, + LINETO: 1, + CURVETO: 2, + ARCTO: 3, + CLOSE: 4 +}; + + +/** + * The number of points for each segment type. + * @type {!Array<number>} + * @private + */ +goog.graphics.Path.segmentArgCounts_ = (function() { + var counts = []; + counts[goog.graphics.Path.Segment.MOVETO] = 2; + counts[goog.graphics.Path.Segment.LINETO] = 2; + counts[goog.graphics.Path.Segment.CURVETO] = 6; + counts[goog.graphics.Path.Segment.ARCTO] = 6; + counts[goog.graphics.Path.Segment.CLOSE] = 0; + return counts; +})(); + + +/** + * Returns the number of points for a segment type. + * + * @param {number} segment The segment type. + * @return {number} The number of points. + */ +goog.graphics.Path.getSegmentCount = function(segment) { + return goog.graphics.Path.segmentArgCounts_[segment]; +}; + + +/** + * Appends another path to the end of this path. + * + * @param {!goog.graphics.Path} path The path to append. + * @return {!goog.graphics.Path} This path. + */ +goog.graphics.Path.prototype.appendPath = function(path) { + if (path.currentPoint_) { + Array.prototype.push.apply(this.segments_, path.segments_); + Array.prototype.push.apply(this.count_, path.count_); + Array.prototype.push.apply(this.arguments_, path.arguments_); + this.currentPoint_ = path.currentPoint_.concat(); + this.closePoint_ = path.closePoint_.concat(); + this.simple_ = this.simple_ && path.simple_; + } + return this; +}; + + +/** + * Clears the path. + * + * @return {!goog.graphics.Path} The path itself. + */ +goog.graphics.Path.prototype.clear = function() { + this.segments_.length = 0; + this.count_.length = 0; + this.arguments_.length = 0; + delete this.closePoint_; + delete this.currentPoint_; + delete this.simple_; + return this; +}; + + +/** + * Adds a point to the path by moving to the specified point. Repeated moveTo + * commands are collapsed into a single moveTo. + * + * @param {number} x X coordinate of destination point. + * @param {number} y Y coordinate of destination point. + * @return {!goog.graphics.Path} The path itself. + */ +goog.graphics.Path.prototype.moveTo = function(x, y) { + if (goog.array.peek(this.segments_) == goog.graphics.Path.Segment.MOVETO) { + this.arguments_.length -= 2; + } else { + this.segments_.push(goog.graphics.Path.Segment.MOVETO); + this.count_.push(1); + } + this.arguments_.push(x, y); + this.currentPoint_ = this.closePoint_ = [x, y]; + return this; +}; + + +/** + * Adds points to the path by drawing a straight line to each point. + * + * @param {...number} var_args The coordinates of each destination point as x, y + * value pairs. + * @return {!goog.graphics.Path} The path itself. + */ +goog.graphics.Path.prototype.lineTo = function(var_args) { + var lastSegment = goog.array.peek(this.segments_); + if (lastSegment == null) { + throw Error('Path cannot start with lineTo'); + } + if (lastSegment != goog.graphics.Path.Segment.LINETO) { + this.segments_.push(goog.graphics.Path.Segment.LINETO); + this.count_.push(0); + } + for (var i = 0; i < arguments.length; i += 2) { + var x = arguments[i]; + var y = arguments[i + 1]; + this.arguments_.push(x, y); + } + this.count_[this.count_.length - 1] += i / 2; + this.currentPoint_ = [x, y]; + return this; +}; + + +/** + * Adds points to the path by drawing cubic Bezier curves. Each curve is + * specified using 3 points (6 coordinates) - two control points and the end + * point of the curve. + * + * @param {...number} var_args The coordinates specifiying each curve in sets of + * 6 points: {@code [x1, y1]} the first control point, {@code [x2, y2]} the + * second control point and {@code [x, y]} the end point. + * @return {!goog.graphics.Path} The path itself. + */ +goog.graphics.Path.prototype.curveTo = function(var_args) { + var lastSegment = goog.array.peek(this.segments_); + if (lastSegment == null) { + throw Error('Path cannot start with curve'); + } + if (lastSegment != goog.graphics.Path.Segment.CURVETO) { + this.segments_.push(goog.graphics.Path.Segment.CURVETO); + this.count_.push(0); + } + for (var i = 0; i < arguments.length; i += 6) { + var x = arguments[i + 4]; + var y = arguments[i + 5]; + this.arguments_.push(arguments[i], arguments[i + 1], + arguments[i + 2], arguments[i + 3], x, y); + } + this.count_[this.count_.length - 1] += i / 6; + this.currentPoint_ = [x, y]; + return this; +}; + + +/** + * Adds a path command to close the path by connecting the + * last point to the first point. + * + * @return {!goog.graphics.Path} The path itself. + */ +goog.graphics.Path.prototype.close = function() { + var lastSegment = goog.array.peek(this.segments_); + if (lastSegment == null) { + throw Error('Path cannot start with close'); + } + if (lastSegment != goog.graphics.Path.Segment.CLOSE) { + this.segments_.push(goog.graphics.Path.Segment.CLOSE); + this.count_.push(1); + this.currentPoint_ = this.closePoint_; + } + return this; +}; + + +/** + * Adds a path command to draw an arc centered at the point {@code (cx, cy)} + * with radius {@code rx} along the x-axis and {@code ry} along the y-axis from + * {@code startAngle} through {@code extent} degrees. Positive rotation is in + * the direction from positive x-axis to positive y-axis. + * + * @param {number} cx X coordinate of center of ellipse. + * @param {number} cy Y coordinate of center of ellipse. + * @param {number} rx Radius of ellipse on x axis. + * @param {number} ry Radius of ellipse on y axis. + * @param {number} fromAngle Starting angle measured in degrees from the + * positive x-axis. + * @param {number} extent The span of the arc in degrees. + * @param {boolean} connect If true, the starting point of the arc is connected + * to the current point. + * @return {!goog.graphics.Path} The path itself. + * @deprecated Use {@code arcTo} or {@code arcToAsCurves} instead. + */ +goog.graphics.Path.prototype.arc = function(cx, cy, rx, ry, + fromAngle, extent, connect) { + var startX = cx + goog.math.angleDx(fromAngle, rx); + var startY = cy + goog.math.angleDy(fromAngle, ry); + if (connect) { + if (!this.currentPoint_ || startX != this.currentPoint_[0] || + startY != this.currentPoint_[1]) { + this.lineTo(startX, startY); + } + } else { + this.moveTo(startX, startY); + } + return this.arcTo(rx, ry, fromAngle, extent); +}; + + +/** + * Adds a path command to draw an arc starting at the path's current point, + * with radius {@code rx} along the x-axis and {@code ry} along the y-axis from + * {@code startAngle} through {@code extent} degrees. Positive rotation is in + * the direction from positive x-axis to positive y-axis. + * + * This method makes the path non-simple. + * + * @param {number} rx Radius of ellipse on x axis. + * @param {number} ry Radius of ellipse on y axis. + * @param {number} fromAngle Starting angle measured in degrees from the + * positive x-axis. + * @param {number} extent The span of the arc in degrees. + * @return {!goog.graphics.Path} The path itself. + */ +goog.graphics.Path.prototype.arcTo = function(rx, ry, fromAngle, extent) { + var cx = this.currentPoint_[0] - goog.math.angleDx(fromAngle, rx); + var cy = this.currentPoint_[1] - goog.math.angleDy(fromAngle, ry); + var ex = cx + goog.math.angleDx(fromAngle + extent, rx); + var ey = cy + goog.math.angleDy(fromAngle + extent, ry); + this.segments_.push(goog.graphics.Path.Segment.ARCTO); + this.count_.push(1); + this.arguments_.push(rx, ry, fromAngle, extent, ex, ey); + this.simple_ = false; + this.currentPoint_ = [ex, ey]; + return this; +}; + + +/** + * Same as {@code arcTo}, but approximates the arc using bezier curves. +.* As a result, this method does not affect the simplified status of this path. + * The algorithm is adapted from {@code java.awt.geom.ArcIterator}. + * + * @param {number} rx Radius of ellipse on x axis. + * @param {number} ry Radius of ellipse on y axis. + * @param {number} fromAngle Starting angle measured in degrees from the + * positive x-axis. + * @param {number} extent The span of the arc in degrees. + * @return {!goog.graphics.Path} The path itself. + */ +goog.graphics.Path.prototype.arcToAsCurves = function( + rx, ry, fromAngle, extent) { + var cx = this.currentPoint_[0] - goog.math.angleDx(fromAngle, rx); + var cy = this.currentPoint_[1] - goog.math.angleDy(fromAngle, ry); + var extentRad = goog.math.toRadians(extent); + var arcSegs = Math.ceil(Math.abs(extentRad) / Math.PI * 2); + var inc = extentRad / arcSegs; + var angle = goog.math.toRadians(fromAngle); + for (var j = 0; j < arcSegs; j++) { + var relX = Math.cos(angle); + var relY = Math.sin(angle); + var z = 4 / 3 * Math.sin(inc / 2) / (1 + Math.cos(inc / 2)); + var c0 = cx + (relX - z * relY) * rx; + var c1 = cy + (relY + z * relX) * ry; + angle += inc; + relX = Math.cos(angle); + relY = Math.sin(angle); + this.curveTo(c0, c1, + cx + (relX + z * relY) * rx, + cy + (relY - z * relX) * ry, + cx + relX * rx, + cy + relY * ry); + } + return this; +}; + + +/** + * Iterates over the path calling the supplied callback once for each path + * segment. The arguments to the callback function are the segment type and + * an array of its arguments. + * + * The {@code LINETO} and {@code CURVETO} arrays can contain multiple + * segments of the same type. The number of segments is the length of the + * array divided by the segment length (2 for lines, 6 for curves). + * + * As a convenience the {@code ARCTO} segment also includes the end point as the + * last two arguments: {@code rx, ry, fromAngle, extent, x, y}. + * + * @param {function(number, Array)} callback The function to call with each + * path segment. + */ +goog.graphics.Path.prototype.forEachSegment = function(callback) { + var points = this.arguments_; + var index = 0; + for (var i = 0, length = this.segments_.length; i < length; i++) { + var seg = this.segments_[i]; + var n = goog.graphics.Path.segmentArgCounts_[seg] * this.count_[i]; + callback(seg, points.slice(index, index + n)); + index += n; + } +}; + + +/** + * Returns the coordinates most recently added to the end of the path. + * + * @return {Array<number>?} An array containing the ending coordinates of the + * path of the form {@code [x, y]}. + */ +goog.graphics.Path.prototype.getCurrentPoint = function() { + return this.currentPoint_ && this.currentPoint_.concat(); +}; + + +/** + * @return {!goog.graphics.Path} A copy of this path. + */ +goog.graphics.Path.prototype.clone = function() { + var path = new this.constructor(); + path.segments_ = this.segments_.concat(); + path.count_ = this.count_.concat(); + path.arguments_ = this.arguments_.concat(); + path.closePoint_ = this.closePoint_ && this.closePoint_.concat(); + path.currentPoint_ = this.currentPoint_ && this.currentPoint_.concat(); + path.simple_ = this.simple_; + return path; +}; + + +/** + * Returns true if this path contains no arcs. Simplified paths can be + * created using {@code createSimplifiedPath}. + * + * @return {boolean} True if the path contains no arcs. + */ +goog.graphics.Path.prototype.isSimple = function() { + return this.simple_; +}; + + +/** + * A map from segment type to the path function to call to simplify a path. + * @type {!Object} + * @private + * @suppress {deprecated} goog.graphics.Path is deprecated. + */ +goog.graphics.Path.simplifySegmentMap_ = (function() { + var map = {}; + map[goog.graphics.Path.Segment.MOVETO] = goog.graphics.Path.prototype.moveTo; + map[goog.graphics.Path.Segment.LINETO] = goog.graphics.Path.prototype.lineTo; + map[goog.graphics.Path.Segment.CLOSE] = goog.graphics.Path.prototype.close; + map[goog.graphics.Path.Segment.CURVETO] = + goog.graphics.Path.prototype.curveTo; + map[goog.graphics.Path.Segment.ARCTO] = + goog.graphics.Path.prototype.arcToAsCurves; + return map; +})(); + + +/** + * Creates a copy of the given path, replacing {@code arcTo} with + * {@code arcToAsCurves}. The resulting path is simplified and can + * be transformed. + * + * @param {!goog.graphics.Path} src The path to simplify. + * @return {!goog.graphics.Path} A new simplified path. + * @suppress {deprecated} goog.graphics is deprecated. + */ +goog.graphics.Path.createSimplifiedPath = function(src) { + if (src.isSimple()) { + return src.clone(); + } + var path = new goog.graphics.Path(); + src.forEachSegment(function(segment, args) { + goog.graphics.Path.simplifySegmentMap_[segment].apply(path, args); + }); + return path; +}; + + +// TODO(chrisn): Delete this method +/** + * Creates a transformed copy of this path. The path is simplified + * {@see #createSimplifiedPath} prior to transformation. + * + * @param {!goog.graphics.AffineTransform} tx The transformation to perform. + * @return {!goog.graphics.Path} A new, transformed path. + */ +goog.graphics.Path.prototype.createTransformedPath = function(tx) { + var path = goog.graphics.Path.createSimplifiedPath(this); + path.transform(tx); + return path; +}; + + +/** + * Transforms the path. Only simple paths are transformable. Attempting + * to transform a non-simple path will throw an error. + * + * @param {!goog.graphics.AffineTransform} tx The transformation to perform. + * @return {!goog.graphics.Path} The path itself. + */ +goog.graphics.Path.prototype.transform = function(tx) { + if (!this.isSimple()) { + throw Error('Non-simple path'); + } + tx.transform(this.arguments_, 0, this.arguments_, 0, + this.arguments_.length / 2); + if (this.closePoint_) { + tx.transform(this.closePoint_, 0, this.closePoint_, 0, 1); + } + if (this.currentPoint_ && this.closePoint_ != this.currentPoint_) { + tx.transform(this.currentPoint_, 0, this.currentPoint_, 0, 1); + } + return this; +}; + + +/** + * @return {boolean} Whether the path is empty. + */ +goog.graphics.Path.prototype.isEmpty = function() { + return this.segments_.length == 0; +}; http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/e2cad6e6/externs/GCL/externs/goog/graphics/pathelement.js ---------------------------------------------------------------------- diff --git a/externs/GCL/externs/goog/graphics/pathelement.js b/externs/GCL/externs/goog/graphics/pathelement.js new file mode 100644 index 0000000..b58b8c6 --- /dev/null +++ b/externs/GCL/externs/goog/graphics/pathelement.js @@ -0,0 +1,54 @@ +// Copyright 2007 The Closure Library Authors. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS-IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + + +/** + * @fileoverview A thin wrapper around the DOM element for paths. + * @author [email protected] (Erik Arvidsson) + */ + + +goog.provide('goog.graphics.PathElement'); + +goog.require('goog.graphics.StrokeAndFillElement'); + + + +/** + * Interface for a graphics path element. + * You should not construct objects from this constructor. The graphics + * will return an implementation of this interface for you. + * @param {Element} element The DOM element to wrap. + * @param {goog.graphics.AbstractGraphics} graphics The graphics creating + * this element. + * @param {goog.graphics.Stroke?} stroke The stroke to use for this element. + * @param {goog.graphics.Fill?} fill The fill to use for this element. + * @constructor + * @extends {goog.graphics.StrokeAndFillElement} + * @deprecated goog.graphics is deprecated. It existed to abstract over browser + * differences before the canvas tag was widely supported. See + * http://en.wikipedia.org/wiki/Canvas_element for details. + */ +goog.graphics.PathElement = function(element, graphics, stroke, fill) { + goog.graphics.StrokeAndFillElement.call(this, element, graphics, stroke, + fill); +}; +goog.inherits(goog.graphics.PathElement, goog.graphics.StrokeAndFillElement); + + +/** + * Update the underlying path. + * @param {!goog.graphics.Path} path The path object to draw. + */ +goog.graphics.PathElement.prototype.setPath = goog.abstractMethod; http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/e2cad6e6/externs/GCL/externs/goog/graphics/paths.js ---------------------------------------------------------------------- diff --git a/externs/GCL/externs/goog/graphics/paths.js b/externs/GCL/externs/goog/graphics/paths.js new file mode 100644 index 0000000..37b53d9 --- /dev/null +++ b/externs/GCL/externs/goog/graphics/paths.js @@ -0,0 +1,86 @@ +// Copyright 2010 The Closure Library Authors. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS-IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + + +/** + * @fileoverview Factories for common path types. + * @author [email protected] (Nick Santos) + */ + + +goog.provide('goog.graphics.paths'); + +goog.require('goog.graphics.Path'); +goog.require('goog.math.Coordinate'); + + +/** + * Defines a regular n-gon by specifing the center, a vertex, and the total + * number of vertices. + * @param {goog.math.Coordinate} center The center point. + * @param {goog.math.Coordinate} vertex The vertex, which implicitly defines + * a radius as well. + * @param {number} n The number of vertices. + * @return {!goog.graphics.Path} The path. + */ +goog.graphics.paths.createRegularNGon = function(center, vertex, n) { + var path = new goog.graphics.Path(); + path.moveTo(vertex.x, vertex.y); + + var startAngle = Math.atan2(vertex.y - center.y, vertex.x - center.x); + var radius = goog.math.Coordinate.distance(center, vertex); + for (var i = 1; i < n; i++) { + var angle = startAngle + 2 * Math.PI * (i / n); + path.lineTo(center.x + radius * Math.cos(angle), + center.y + radius * Math.sin(angle)); + } + path.close(); + return path; +}; + + +/** + * Defines an arrow. + * @param {goog.math.Coordinate} a Point A. + * @param {goog.math.Coordinate} b Point B. + * @param {?number} aHead The size of the arrow head at point A. + * 0 omits the head. + * @param {?number} bHead The size of the arrow head at point B. + * 0 omits the head. + * @return {!goog.graphics.Path} The path. + */ +goog.graphics.paths.createArrow = function(a, b, aHead, bHead) { + var path = new goog.graphics.Path(); + path.moveTo(a.x, a.y); + path.lineTo(b.x, b.y); + + var angle = Math.atan2(b.y - a.y, b.x - a.x); + if (aHead) { + path.appendPath( + goog.graphics.paths.createRegularNGon( + new goog.math.Coordinate( + a.x + aHead * Math.cos(angle), + a.y + aHead * Math.sin(angle)), + a, 3)); + } + if (bHead) { + path.appendPath( + goog.graphics.paths.createRegularNGon( + new goog.math.Coordinate( + b.x + bHead * Math.cos(angle + Math.PI), + b.y + bHead * Math.sin(angle + Math.PI)), + b, 3)); + } + return path; +}; http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/e2cad6e6/externs/GCL/externs/goog/graphics/rectelement.js ---------------------------------------------------------------------- diff --git a/externs/GCL/externs/goog/graphics/rectelement.js b/externs/GCL/externs/goog/graphics/rectelement.js new file mode 100644 index 0000000..9a6e9a1 --- /dev/null +++ b/externs/GCL/externs/goog/graphics/rectelement.js @@ -0,0 +1,63 @@ +// Copyright 2007 The Closure Library Authors. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS-IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + + +/** + * @fileoverview A thin wrapper around the DOM element for rectangles. + * @author [email protected] (Erik Arvidsson) + */ + + +goog.provide('goog.graphics.RectElement'); + +goog.require('goog.graphics.StrokeAndFillElement'); + + + +/** + * Interface for a graphics rectangle element. + * You should not construct objects from this constructor. The graphics + * will return an implementation of this interface for you. + * @param {Element} element The DOM element to wrap. + * @param {goog.graphics.AbstractGraphics} graphics The graphics creating + * this element. + * @param {goog.graphics.Stroke?} stroke The stroke to use for this element. + * @param {goog.graphics.Fill?} fill The fill to use for this element. + * @constructor + * @extends {goog.graphics.StrokeAndFillElement} + * @deprecated goog.graphics is deprecated. It existed to abstract over browser + * differences before the canvas tag was widely supported. See + * http://en.wikipedia.org/wiki/Canvas_element for details. + */ +goog.graphics.RectElement = function(element, graphics, stroke, fill) { + goog.graphics.StrokeAndFillElement.call(this, element, graphics, stroke, + fill); +}; +goog.inherits(goog.graphics.RectElement, goog.graphics.StrokeAndFillElement); + + +/** + * Update the position of the rectangle. + * @param {number} x X coordinate (left). + * @param {number} y Y coordinate (top). + */ +goog.graphics.RectElement.prototype.setPosition = goog.abstractMethod; + + +/** + * Update the size of the rectangle. + * @param {number} width Width of rectangle. + * @param {number} height Height of rectangle. + */ +goog.graphics.RectElement.prototype.setSize = goog.abstractMethod; http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/e2cad6e6/externs/GCL/externs/goog/graphics/solidfill.js ---------------------------------------------------------------------- diff --git a/externs/GCL/externs/goog/graphics/solidfill.js b/externs/GCL/externs/goog/graphics/solidfill.js new file mode 100644 index 0000000..fae3fc4 --- /dev/null +++ b/externs/GCL/externs/goog/graphics/solidfill.js @@ -0,0 +1,74 @@ +// Copyright 2007 The Closure Library Authors. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS-IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + + +/** + * @fileoverview Represents a solid color fill goog.graphics. + * @author [email protected] (Erik Arvidsson) + */ + + +goog.provide('goog.graphics.SolidFill'); + + +goog.require('goog.graphics.Fill'); + + + +/** + * Creates an immutable solid color fill object. + * + * @param {string} color The color of the background. + * @param {number=} opt_opacity The opacity of the background fill. The value + * must be greater than or equal to zero (transparent) and less than or + * equal to 1 (opaque). + * @constructor + * @extends {goog.graphics.Fill} + * @deprecated goog.graphics is deprecated. It existed to abstract over browser + * differences before the canvas tag was widely supported. See + * http://en.wikipedia.org/wiki/Canvas_element for details. + */ +goog.graphics.SolidFill = function(color, opt_opacity) { + /** + * The color with which to fill. + * @type {string} + * @private + */ + this.color_ = color; + + + /** + * The opacity of the fill. + * @type {number} + * @private + */ + this.opacity_ = opt_opacity == null ? 1.0 : opt_opacity; +}; +goog.inherits(goog.graphics.SolidFill, goog.graphics.Fill); + + +/** + * @return {string} The color of this fill. + */ +goog.graphics.SolidFill.prototype.getColor = function() { + return this.color_; +}; + + +/** + * @return {number} The opacity of this fill. + */ +goog.graphics.SolidFill.prototype.getOpacity = function() { + return this.opacity_; +}; http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/e2cad6e6/externs/GCL/externs/goog/graphics/stroke.js ---------------------------------------------------------------------- diff --git a/externs/GCL/externs/goog/graphics/stroke.js b/externs/GCL/externs/goog/graphics/stroke.js new file mode 100644 index 0000000..ae1eb8e --- /dev/null +++ b/externs/GCL/externs/goog/graphics/stroke.js @@ -0,0 +1,86 @@ +// Copyright 2007 The Closure Library Authors. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS-IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + + +/** + * @fileoverview Represents a stroke object for goog.graphics. + * @author [email protected] (Erik Arvidsson) + */ + + +goog.provide('goog.graphics.Stroke'); + + + +/** + * Creates an immutable stroke object. + * + * @param {number|string} width The width of the stroke. + * @param {string} color The color of the stroke. + * @param {number=} opt_opacity The opacity of the background fill. The value + * must be greater than or equal to zero (transparent) and less than or + * equal to 1 (opaque). + * @constructor + * @deprecated goog.graphics is deprecated. It existed to abstract over browser + * differences before the canvas tag was widely supported. See + * http://en.wikipedia.org/wiki/Canvas_element for details. + */ +goog.graphics.Stroke = function(width, color, opt_opacity) { + /** + * The width of the stroke. + * @type {number|string} + * @private + */ + this.width_ = width; + + + /** + * The color with which to fill. + * @type {string} + * @private + */ + this.color_ = color; + + + /** + * The opacity of the fill. + * @type {number} + * @private + */ + this.opacity_ = opt_opacity == null ? 1.0 : opt_opacity; +}; + + +/** + * @return {number|string} The width of this stroke. + */ +goog.graphics.Stroke.prototype.getWidth = function() { + return this.width_; +}; + + +/** + * @return {string} The color of this stroke. + */ +goog.graphics.Stroke.prototype.getColor = function() { + return this.color_; +}; + + +/** + * @return {number} The opacity of this fill. + */ +goog.graphics.Stroke.prototype.getOpacity = function() { + return this.opacity_; +}; http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/e2cad6e6/externs/GCL/externs/goog/graphics/strokeandfillelement.js ---------------------------------------------------------------------- diff --git a/externs/GCL/externs/goog/graphics/strokeandfillelement.js b/externs/GCL/externs/goog/graphics/strokeandfillelement.js new file mode 100644 index 0000000..e3b50f9 --- /dev/null +++ b/externs/GCL/externs/goog/graphics/strokeandfillelement.js @@ -0,0 +1,114 @@ +// Copyright 2007 The Closure Library Authors. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS-IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + + +/** + * @fileoverview A thin wrapper around the DOM element for elements with a + * stroke and fill. + * @author [email protected] (Erik Arvidsson) + */ + + +goog.provide('goog.graphics.StrokeAndFillElement'); + +goog.require('goog.graphics.Element'); + + + +/** + * Interface for a graphics element with a stroke and fill. + * This is the base interface for ellipse, rectangle and other + * shape interfaces. + * You should not construct objects from this constructor. The graphics + * will return an implementation of this interface for you. + * + * @param {Element} element The DOM element to wrap. + * @param {goog.graphics.AbstractGraphics} graphics The graphics creating + * this element. + * @param {goog.graphics.Stroke?} stroke The stroke to use for this element. + * @param {goog.graphics.Fill?} fill The fill to use for this element. + * @constructor + * @extends {goog.graphics.Element} + * @deprecated goog.graphics is deprecated. It existed to abstract over browser + * differences before the canvas tag was widely supported. See + * http://en.wikipedia.org/wiki/Canvas_element for details. + */ +goog.graphics.StrokeAndFillElement = function(element, graphics, stroke, fill) { + goog.graphics.Element.call(this, element, graphics); + this.setStroke(stroke); + this.setFill(fill); +}; +goog.inherits(goog.graphics.StrokeAndFillElement, goog.graphics.Element); + + +/** + * The latest fill applied to this element. + * @type {goog.graphics.Fill?} + * @protected + */ +goog.graphics.StrokeAndFillElement.prototype.fill = null; + + +/** + * The latest stroke applied to this element. + * @type {goog.graphics.Stroke?} + * @private + */ +goog.graphics.StrokeAndFillElement.prototype.stroke_ = null; + + +/** + * Sets the fill for this element. + * @param {goog.graphics.Fill?} fill The fill object. + */ +goog.graphics.StrokeAndFillElement.prototype.setFill = function(fill) { + this.fill = fill; + this.getGraphics().setElementFill(this, fill); +}; + + +/** + * @return {goog.graphics.Fill?} fill The fill object. + */ +goog.graphics.StrokeAndFillElement.prototype.getFill = function() { + return this.fill; +}; + + +/** + * Sets the stroke for this element. + * @param {goog.graphics.Stroke?} stroke The stroke object. + */ +goog.graphics.StrokeAndFillElement.prototype.setStroke = function(stroke) { + this.stroke_ = stroke; + this.getGraphics().setElementStroke(this, stroke); +}; + + +/** + * @return {goog.graphics.Stroke?} stroke The stroke object. + */ +goog.graphics.StrokeAndFillElement.prototype.getStroke = function() { + return this.stroke_; +}; + + +/** + * Re-strokes the element to react to coordinate size changes. + */ +goog.graphics.StrokeAndFillElement.prototype.reapplyStroke = function() { + if (this.stroke_) { + this.setStroke(this.stroke_); + } +}; http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/e2cad6e6/externs/GCL/externs/goog/graphics/svgelement.js ---------------------------------------------------------------------- diff --git a/externs/GCL/externs/goog/graphics/svgelement.js b/externs/GCL/externs/goog/graphics/svgelement.js new file mode 100644 index 0000000..eddcbb5 --- /dev/null +++ b/externs/GCL/externs/goog/graphics/svgelement.js @@ -0,0 +1,284 @@ +// Copyright 2007 The Closure Library Authors. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS-IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + + +/** + * @fileoverview Thin wrappers around the DOM element returned from + * the different draw methods of the graphics. This is the SVG implementation. + * @author [email protected] (Erik Arvidsson) + */ + +goog.provide('goog.graphics.SvgEllipseElement'); +goog.provide('goog.graphics.SvgGroupElement'); +goog.provide('goog.graphics.SvgImageElement'); +goog.provide('goog.graphics.SvgPathElement'); +goog.provide('goog.graphics.SvgRectElement'); +goog.provide('goog.graphics.SvgTextElement'); + + +goog.require('goog.dom'); +goog.require('goog.graphics.EllipseElement'); +goog.require('goog.graphics.GroupElement'); +goog.require('goog.graphics.ImageElement'); +goog.require('goog.graphics.PathElement'); +goog.require('goog.graphics.RectElement'); +goog.require('goog.graphics.TextElement'); + + + +/** + * Thin wrapper for SVG group elements. + * You should not construct objects from this constructor. The graphics + * will return the object for you. + * @param {Element} element The DOM element to wrap. + * @param {goog.graphics.SvgGraphics} graphics The graphics creating + * this element. + * @constructor + * @extends {goog.graphics.GroupElement} + * @deprecated goog.graphics is deprecated. It existed to abstract over browser + * differences before the canvas tag was widely supported. See + * http://en.wikipedia.org/wiki/Canvas_element for details. + * @final + */ +goog.graphics.SvgGroupElement = function(element, graphics) { + goog.graphics.GroupElement.call(this, element, graphics); +}; +goog.inherits(goog.graphics.SvgGroupElement, goog.graphics.GroupElement); + + +/** + * Remove all drawing elements from the group. + * @override + */ +goog.graphics.SvgGroupElement.prototype.clear = function() { + goog.dom.removeChildren(this.getElement()); +}; + + +/** + * Set the size of the group element. + * @param {number|string} width The width of the group element. + * @param {number|string} height The height of the group element. + * @override + */ +goog.graphics.SvgGroupElement.prototype.setSize = function(width, height) { + this.getGraphics().setElementAttributes(this.getElement(), + {'width': width, 'height': height}); +}; + + + +/** + * Thin wrapper for SVG ellipse elements. + * This is an implementation of the goog.graphics.EllipseElement interface. + * You should not construct objects from this constructor. The graphics + * will return the object for you. + * @param {Element} element The DOM element to wrap. + * @param {goog.graphics.SvgGraphics} graphics The graphics creating + * this element. + * @param {goog.graphics.Stroke?} stroke The stroke to use for this element. + * @param {goog.graphics.Fill?} fill The fill to use for this element. + * @constructor + * @extends {goog.graphics.EllipseElement} + * @final + */ +goog.graphics.SvgEllipseElement = function(element, graphics, stroke, fill) { + goog.graphics.EllipseElement.call(this, element, graphics, stroke, fill); +}; +goog.inherits(goog.graphics.SvgEllipseElement, goog.graphics.EllipseElement); + + +/** + * Update the center point of the ellipse. + * @param {number} cx Center X coordinate. + * @param {number} cy Center Y coordinate. + * @override + */ +goog.graphics.SvgEllipseElement.prototype.setCenter = function(cx, cy) { + this.getGraphics().setElementAttributes(this.getElement(), + {'cx': cx, 'cy': cy}); +}; + + +/** + * Update the radius of the ellipse. + * @param {number} rx Radius length for the x-axis. + * @param {number} ry Radius length for the y-axis. + * @override + */ +goog.graphics.SvgEllipseElement.prototype.setRadius = function(rx, ry) { + this.getGraphics().setElementAttributes(this.getElement(), + {'rx': rx, 'ry': ry}); +}; + + + +/** + * Thin wrapper for SVG rectangle elements. + * This is an implementation of the goog.graphics.RectElement interface. + * You should not construct objects from this constructor. The graphics + * will return the object for you. + * @param {Element} element The DOM element to wrap. + * @param {goog.graphics.SvgGraphics} graphics The graphics creating + * this element. + * @param {goog.graphics.Stroke?} stroke The stroke to use for this element. + * @param {goog.graphics.Fill?} fill The fill to use for this element. + * @constructor + * @extends {goog.graphics.RectElement} + * @final + */ +goog.graphics.SvgRectElement = function(element, graphics, stroke, fill) { + goog.graphics.RectElement.call(this, element, graphics, stroke, fill); +}; +goog.inherits(goog.graphics.SvgRectElement, goog.graphics.RectElement); + + +/** + * Update the position of the rectangle. + * @param {number} x X coordinate (left). + * @param {number} y Y coordinate (top). + * @override + */ +goog.graphics.SvgRectElement.prototype.setPosition = function(x, y) { + this.getGraphics().setElementAttributes(this.getElement(), {'x': x, 'y': y}); +}; + + +/** + * Update the size of the rectangle. + * @param {number} width Width of rectangle. + * @param {number} height Height of rectangle. + * @override + */ +goog.graphics.SvgRectElement.prototype.setSize = function(width, height) { + this.getGraphics().setElementAttributes(this.getElement(), + {'width': width, 'height': height}); +}; + + + +/** + * Thin wrapper for SVG path elements. + * This is an implementation of the goog.graphics.PathElement interface. + * You should not construct objects from this constructor. The graphics + * will return the object for you. + * @param {Element} element The DOM element to wrap. + * @param {goog.graphics.SvgGraphics} graphics The graphics creating + * this element. + * @param {goog.graphics.Stroke?} stroke The stroke to use for this element. + * @param {goog.graphics.Fill?} fill The fill to use for this element. + * @constructor + * @extends {goog.graphics.PathElement} + * @final + */ +goog.graphics.SvgPathElement = function(element, graphics, stroke, fill) { + goog.graphics.PathElement.call(this, element, graphics, stroke, fill); +}; +goog.inherits(goog.graphics.SvgPathElement, goog.graphics.PathElement); + + +/** + * Update the underlying path. + * @param {!goog.graphics.Path} path The path object to draw. + * @override + */ +goog.graphics.SvgPathElement.prototype.setPath = function(path) { + this.getGraphics().setElementAttributes(this.getElement(), + {'d': /** @suppress {missingRequire} */ + goog.graphics.SvgGraphics.getSvgPath(path)}); +}; + + + +/** + * Thin wrapper for SVG text elements. + * This is an implementation of the goog.graphics.TextElement interface. + * You should not construct objects from this constructor. The graphics + * will return the object for you. + * @param {Element} element The DOM element to wrap. + * @param {goog.graphics.SvgGraphics} graphics The graphics creating + * this element. + * @param {goog.graphics.Stroke?} stroke The stroke to use for this element. + * @param {goog.graphics.Fill?} fill The fill to use for this element. + * @constructor + * @extends {goog.graphics.TextElement} + * @final + */ +goog.graphics.SvgTextElement = function(element, graphics, stroke, fill) { + goog.graphics.TextElement.call(this, element, graphics, stroke, fill); +}; +goog.inherits(goog.graphics.SvgTextElement, goog.graphics.TextElement); + + +/** + * Update the displayed text of the element. + * @param {string} text The text to draw. + * @override + */ +goog.graphics.SvgTextElement.prototype.setText = function(text) { + this.getElement().firstChild.data = text; +}; + + + +/** + * Thin wrapper for SVG image elements. + * This is an implementation of the goog.graphics.ImageElement interface. + * You should not construct objects from this constructor. The graphics + * will return the object for you. + * @param {Element} element The DOM element to wrap. + * @param {goog.graphics.SvgGraphics} graphics The graphics creating + * this element. + * @constructor + * @extends {goog.graphics.ImageElement} + * @final + */ +goog.graphics.SvgImageElement = function(element, graphics) { + goog.graphics.ImageElement.call(this, element, graphics); +}; +goog.inherits(goog.graphics.SvgImageElement, goog.graphics.ImageElement); + + +/** + * Update the position of the image. + * @param {number} x X coordinate (left). + * @param {number} y Y coordinate (top). + * @override + */ +goog.graphics.SvgImageElement.prototype.setPosition = function(x, y) { + this.getGraphics().setElementAttributes(this.getElement(), {'x': x, 'y': y}); +}; + + +/** + * Update the size of the image. + * @param {number} width Width of image. + * @param {number} height Height of image. + * @override + */ +goog.graphics.SvgImageElement.prototype.setSize = function(width, height) { + this.getGraphics().setElementAttributes(this.getElement(), + {'width': width, 'height': height}); +}; + + +/** + * Update the source of the image. + * @param {string} src Source of the image. + * @override + */ +goog.graphics.SvgImageElement.prototype.setSource = function(src) { + this.getGraphics().setElementAttributes(this.getElement(), + {'xlink:href': src}); +}; http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/e2cad6e6/externs/GCL/externs/goog/graphics/svggraphics.js ---------------------------------------------------------------------- diff --git a/externs/GCL/externs/goog/graphics/svggraphics.js b/externs/GCL/externs/goog/graphics/svggraphics.js new file mode 100644 index 0000000..59db4a2 --- /dev/null +++ b/externs/GCL/externs/goog/graphics/svggraphics.js @@ -0,0 +1,878 @@ +// Copyright 2007 The Closure Library Authors. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS-IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + + +/** + * @fileoverview SvgGraphics sub class that uses SVG to draw the graphics. + * @author [email protected] (Erik Arvidsson) + */ + +goog.provide('goog.graphics.SvgGraphics'); + +goog.require('goog.Timer'); +goog.require('goog.dom'); +goog.require('goog.events.EventHandler'); +goog.require('goog.events.EventType'); +goog.require('goog.graphics.AbstractGraphics'); +goog.require('goog.graphics.LinearGradient'); +goog.require('goog.graphics.Path'); +goog.require('goog.graphics.SolidFill'); +goog.require('goog.graphics.Stroke'); +goog.require('goog.graphics.SvgEllipseElement'); +goog.require('goog.graphics.SvgGroupElement'); +goog.require('goog.graphics.SvgImageElement'); +goog.require('goog.graphics.SvgPathElement'); +goog.require('goog.graphics.SvgRectElement'); +goog.require('goog.graphics.SvgTextElement'); +goog.require('goog.math'); +goog.require('goog.math.Size'); +goog.require('goog.style'); +goog.require('goog.userAgent'); + + + +/** + * A Graphics implementation for drawing using SVG. + * @param {string|number} width The width in pixels. Strings + * expressing percentages of parent with (e.g. '80%') are also accepted. + * @param {string|number} height The height in pixels. Strings + * expressing percentages of parent with (e.g. '80%') are also accepted. + * @param {?number=} opt_coordWidth The coordinate width - if + * omitted or null, defaults to same as width. + * @param {?number=} opt_coordHeight The coordinate height - if + * omitted or null, defaults to same as height. + * @param {goog.dom.DomHelper=} opt_domHelper The DOM helper object for the + * document we want to render in. + * @constructor + * @extends {goog.graphics.AbstractGraphics} + * @deprecated goog.graphics is deprecated. It existed to abstract over browser + * differences before the canvas tag was widely supported. See + * http://en.wikipedia.org/wiki/Canvas_element for details. + * @final + */ +goog.graphics.SvgGraphics = function(width, height, + opt_coordWidth, opt_coordHeight, + opt_domHelper) { + goog.graphics.AbstractGraphics.call(this, width, height, + opt_coordWidth, opt_coordHeight, + opt_domHelper); + + /** + * Map from def key to id of def root element. + * Defs are global "defines" of svg that are used to share common attributes, + * for example gradients. + * @type {Object} + * @private + */ + this.defs_ = {}; + + /** + * Whether to manually implement viewBox by using a coordinate transform. + * As of 1/11/08 this is necessary for Safari 3 but not for the nightly + * WebKit build. Apply to webkit versions < 526. 525 is the + * last version used by Safari 3.1. + * @type {boolean} + * @private + */ + this.useManualViewbox_ = goog.userAgent.WEBKIT && + !goog.userAgent.isVersionOrHigher(526); + + /** + * Event handler. + * @type {goog.events.EventHandler<!goog.graphics.SvgGraphics>} + * @private + */ + this.handler_ = new goog.events.EventHandler(this); +}; +goog.inherits(goog.graphics.SvgGraphics, goog.graphics.AbstractGraphics); + + +/** + * The SVG namespace URN + * @private + * @type {string} + */ +goog.graphics.SvgGraphics.SVG_NS_ = 'http://www.w3.org/2000/svg'; + + +/** + * The name prefix for def entries + * @private + * @type {string} + */ +goog.graphics.SvgGraphics.DEF_ID_PREFIX_ = '_svgdef_'; + + +/** + * The next available unique identifier for a def entry. + * This is a static variable, so that when multiple graphics are used in one + * document, the same def id can not be re-defined by another SvgGraphics. + * @type {number} + * @private + */ +goog.graphics.SvgGraphics.nextDefId_ = 0; + + +/** + * Svg element for definitions for other elements, e.g. linear gradients. + * @type {Element} + * @private + */ +goog.graphics.SvgGraphics.prototype.defsElement_; + + +/** + * Creates an SVG element. Used internally and by different SVG classes. + * @param {string} tagName The type of element to create. + * @param {Object=} opt_attributes Map of name-value pairs for attributes. + * @return {!Element} The created element. + * @private + */ +goog.graphics.SvgGraphics.prototype.createSvgElement_ = function(tagName, + opt_attributes) { + var element = this.dom_.getDocument().createElementNS( + goog.graphics.SvgGraphics.SVG_NS_, tagName); + + if (opt_attributes) { + this.setElementAttributes(element, opt_attributes); + } + + return element; +}; + + +/** + * Sets properties to an SVG element. Used internally and by different + * SVG elements. + * @param {Element} element The svg element. + * @param {Object} attributes Map of name-value pairs for attributes. + */ +goog.graphics.SvgGraphics.prototype.setElementAttributes = function(element, + attributes) { + for (var key in attributes) { + element.setAttribute(key, attributes[key]); + } +}; + + +/** + * Appends an element. + * + * @param {goog.graphics.Element} element The element wrapper. + * @param {goog.graphics.GroupElement=} opt_group The group wrapper element + * to append to. If not specified, appends to the main canvas. + * @private + */ +goog.graphics.SvgGraphics.prototype.append_ = function(element, opt_group) { + var parent = opt_group || this.canvasElement; + parent.getElement().appendChild(element.getElement()); +}; + + +/** + * Sets the fill of the given element. + * @param {goog.graphics.StrokeAndFillElement} element The element wrapper. + * @param {goog.graphics.Fill?} fill The fill object. + * @override + */ +goog.graphics.SvgGraphics.prototype.setElementFill = function(element, fill) { + var svgElement = element.getElement(); + if (fill instanceof goog.graphics.SolidFill) { + svgElement.setAttribute('fill', fill.getColor()); + svgElement.setAttribute('fill-opacity', fill.getOpacity()); + } else if (fill instanceof goog.graphics.LinearGradient) { + // create a def key which is just a concat of all the relevant fields + var defKey = 'lg-' + + fill.getX1() + '-' + fill.getY1() + '-' + + fill.getX2() + '-' + fill.getY2() + '-' + + fill.getColor1() + '-' + fill.getColor2(); + // It seems that the SVG version accepts opacity where the VML does not + + var id = this.getDef(defKey); + + if (!id) { // No def for this yet, create it + // Create the gradient def entry (only linear gradient are supported) + var gradient = this.createSvgElement_('linearGradient', { + 'x1': fill.getX1(), + 'y1': fill.getY1(), + 'x2': fill.getX2(), + 'y2': fill.getY2(), + 'gradientUnits': 'userSpaceOnUse' + }); + + var gstyle = 'stop-color:' + fill.getColor1(); + if (goog.isNumber(fill.getOpacity1())) { + gstyle += ';stop-opacity:' + fill.getOpacity1(); + } + var stop1 = this.createSvgElement_( + 'stop', {'offset': '0%', 'style': gstyle}); + gradient.appendChild(stop1); + + // LinearGradients don't have opacity in VML so implement that before + // enabling the following code. + // if (fill.getOpacity() != null) { + // gstyles += 'opacity:' + fill.getOpacity() + ';' + // } + gstyle = 'stop-color:' + fill.getColor2(); + if (goog.isNumber(fill.getOpacity2())) { + gstyle += ';stop-opacity:' + fill.getOpacity2(); + } + var stop2 = this.createSvgElement_( + 'stop', {'offset': '100%', 'style': gstyle}); + gradient.appendChild(stop2); + + // LinearGradients don't have opacity in VML so implement that before + // enabling the following code. + // if (fill.getOpacity() != null) { + // gstyles += 'opacity:' + fill.getOpacity() + ';' + // } + + id = this.addDef(defKey, gradient); + } + + // Link element to linearGradient definition + svgElement.setAttribute('fill', 'url(#' + id + ')'); + } else { + svgElement.setAttribute('fill', 'none'); + } +}; + + +/** + * Sets the stroke of the given element. + * @param {goog.graphics.StrokeAndFillElement} element The element wrapper. + * @param {goog.graphics.Stroke?} stroke The stroke object. + * @override + */ +goog.graphics.SvgGraphics.prototype.setElementStroke = function(element, + stroke) { + var svgElement = element.getElement(); + if (stroke) { + svgElement.setAttribute('stroke', stroke.getColor()); + svgElement.setAttribute('stroke-opacity', stroke.getOpacity()); + + var width = stroke.getWidth(); + if (goog.isString(width) && width.indexOf('px') != -1) { + svgElement.setAttribute('stroke-width', + parseFloat(width) / this.getPixelScaleX()); + } else { + svgElement.setAttribute('stroke-width', width); + } + } else { + svgElement.setAttribute('stroke', 'none'); + } +}; + + +/** + * Set the translation and rotation of an element. + * + * If a more general affine transform is needed than this provides + * (e.g. skew and scale) then use setElementAffineTransform. + * @param {goog.graphics.Element} element The element wrapper. + * @param {number} x The x coordinate of the translation transform. + * @param {number} y The y coordinate of the translation transform. + * @param {number} angle The angle of the rotation transform. + * @param {number} centerX The horizontal center of the rotation transform. + * @param {number} centerY The vertical center of the rotation transform. + * @override + */ +goog.graphics.SvgGraphics.prototype.setElementTransform = function(element, x, + y, angle, centerX, centerY) { + element.getElement().setAttribute('transform', 'translate(' + x + ',' + y + + ') rotate(' + angle + ' ' + centerX + ' ' + centerY + ')'); +}; + + +/** + * Set the transformation of an element. + * @param {goog.graphics.Element} element The element wrapper. + * @param {!goog.graphics.AffineTransform} affineTransform The + * transformation applied to this element. + * @override + */ +goog.graphics.SvgGraphics.prototype.setElementAffineTransform = function( + element, affineTransform) { + var t = affineTransform; + var substr = [t.getScaleX(), t.getShearY(), t.getShearX(), t.getScaleY(), + t.getTranslateX(), t.getTranslateY()].join(','); + element.getElement().setAttribute('transform', 'matrix(' + substr + ')'); +}; + + +/** + * Creates the DOM representation of the graphics area. + * @override + */ +goog.graphics.SvgGraphics.prototype.createDom = function() { + // Set up the standard attributes. + var attributes = { + 'width': this.width, + 'height': this.height, + 'overflow': 'hidden' + }; + + var svgElement = this.createSvgElement_('svg', attributes); + + var groupElement = this.createSvgElement_('g'); + + this.defsElement_ = this.createSvgElement_('defs'); + this.canvasElement = new goog.graphics.SvgGroupElement(groupElement, this); + + svgElement.appendChild(this.defsElement_); + svgElement.appendChild(groupElement); + + // Use the svgElement as the root element. + this.setElementInternal(svgElement); + + // Set up the coordinate system. + this.setViewBox_(); +}; + + +/** + * Changes the coordinate system position. + * @param {number} left The coordinate system left bound. + * @param {number} top The coordinate system top bound. + * @override + */ +goog.graphics.SvgGraphics.prototype.setCoordOrigin = function(left, top) { + this.coordLeft = left; + this.coordTop = top; + + this.setViewBox_(); +}; + + +/** + * Changes the coordinate size. + * @param {number} coordWidth The coordinate width. + * @param {number} coordHeight The coordinate height. + * @override + */ +goog.graphics.SvgGraphics.prototype.setCoordSize = function(coordWidth, + coordHeight) { + goog.graphics.SvgGraphics.superClass_.setCoordSize.apply( + this, arguments); + this.setViewBox_(); +}; + + +/** + * @return {string} The view box string. + * @private + */ +goog.graphics.SvgGraphics.prototype.getViewBox_ = function() { + return this.coordLeft + ' ' + this.coordTop + ' ' + + (this.coordWidth ? this.coordWidth + ' ' + this.coordHeight : ''); +}; + + +/** + * Sets up the view box. + * @private + */ +goog.graphics.SvgGraphics.prototype.setViewBox_ = function() { + if (this.coordWidth || this.coordLeft || this.coordTop) { + this.getElement().setAttribute('preserveAspectRatio', 'none'); + if (this.useManualViewbox_) { + this.updateManualViewBox_(); + } else { + this.getElement().setAttribute('viewBox', this.getViewBox_()); + } + } +}; + + +/** + * Updates the transform of the root element to fake a viewBox. Should only + * be called when useManualViewbox_ is set. + * @private + */ +goog.graphics.SvgGraphics.prototype.updateManualViewBox_ = function() { + if (!this.isInDocument() || + !(this.coordWidth || this.coordLeft || !this.coordTop)) { + return; + } + + var size = this.getPixelSize(); + if (size.width == 0) { + // In Safari, invisible SVG is sometimes shown. Explicitly hide it. + this.getElement().style.visibility = 'hidden'; + return; + } + + this.getElement().style.visibility = ''; + + var offsetX = - this.coordLeft; + var offsetY = - this.coordTop; + var scaleX = size.width / this.coordWidth; + var scaleY = size.height / this.coordHeight; + + this.canvasElement.getElement().setAttribute('transform', + 'scale(' + scaleX + ' ' + scaleY + ') ' + + 'translate(' + offsetX + ' ' + offsetY + ')'); +}; + + +/** + * Change the size of the canvas. + * @param {number} pixelWidth The width in pixels. + * @param {number} pixelHeight The height in pixels. + * @override + */ +goog.graphics.SvgGraphics.prototype.setSize = function(pixelWidth, + pixelHeight) { + goog.style.setSize(this.getElement(), pixelWidth, pixelHeight); +}; + + +/** @override */ +goog.graphics.SvgGraphics.prototype.getPixelSize = function() { + if (!goog.userAgent.GECKO) { + return this.isInDocument() ? + goog.style.getSize(this.getElement()) : + goog.graphics.SvgGraphics.base(this, 'getPixelSize'); + } + + // In Gecko, goog.style.getSize does not work for SVG elements. We have to + // compute the size manually if it is percentage based. + var width = this.width; + var height = this.height; + var computeWidth = goog.isString(width) && width.indexOf('%') != -1; + var computeHeight = goog.isString(height) && height.indexOf('%') != -1; + + if (!this.isInDocument() && (computeWidth || computeHeight)) { + return null; + } + + var parent; + var parentSize; + + if (computeWidth) { + parent = /** @type {Element} */ (this.getElement().parentNode); + parentSize = goog.style.getSize(parent); + width = parseFloat(/** @type {string} */ (width)) * parentSize.width / 100; + } + + if (computeHeight) { + parent = parent || /** @type {Element} */ (this.getElement().parentNode); + parentSize = parentSize || goog.style.getSize(parent); + height = parseFloat(/** @type {string} */ (height)) * parentSize.height / + 100; + } + + return new goog.math.Size(/** @type {number} */ (width), + /** @type {number} */ (height)); +}; + + +/** + * Remove all drawing elements from the graphics. + * @override + */ +goog.graphics.SvgGraphics.prototype.clear = function() { + this.canvasElement.clear(); + goog.dom.removeChildren(this.defsElement_); + this.defs_ = {}; +}; + + +/** + * Draw an ellipse. + * + * @param {number} cx Center X coordinate. + * @param {number} cy Center Y coordinate. + * @param {number} rx Radius length for the x-axis. + * @param {number} ry Radius length for the y-axis. + * @param {goog.graphics.Stroke?} stroke Stroke object describing the + * stroke. + * @param {goog.graphics.Fill?} fill Fill object describing the fill. + * @param {goog.graphics.GroupElement=} opt_group The group wrapper element + * to append to. If not specified, appends to the main canvas. + * + * @return {!goog.graphics.EllipseElement} The newly created element. + * @override + */ +goog.graphics.SvgGraphics.prototype.drawEllipse = function( + cx, cy, rx, ry, stroke, fill, opt_group) { + var element = this.createSvgElement_('ellipse', + {'cx': cx, 'cy': cy, 'rx': rx, 'ry': ry}); + var wrapper = new goog.graphics.SvgEllipseElement(element, this, stroke, + fill); + this.append_(wrapper, opt_group); + return wrapper; +}; + + +/** + * Draw a rectangle. + * + * @param {number} x X coordinate (left). + * @param {number} y Y coordinate (top). + * @param {number} width Width of rectangle. + * @param {number} height Height of rectangle. + * @param {goog.graphics.Stroke?} stroke Stroke object describing the + * stroke. + * @param {goog.graphics.Fill?} fill Fill object describing the fill. + * @param {goog.graphics.GroupElement=} opt_group The group wrapper element + * to append to. If not specified, appends to the main canvas. + * + * @return {!goog.graphics.RectElement} The newly created element. + * @override + */ +goog.graphics.SvgGraphics.prototype.drawRect = function(x, y, width, height, + stroke, fill, opt_group) { + var element = this.createSvgElement_('rect', + {'x': x, 'y': y, 'width': width, 'height': height}); + var wrapper = new goog.graphics.SvgRectElement(element, this, stroke, fill); + this.append_(wrapper, opt_group); + return wrapper; +}; + + +/** + * Draw an image. + * + * @param {number} x X coordinate (left). + * @param {number} y Y coordinate (top). + * @param {number} width Width of the image. + * @param {number} height Height of the image. + * @param {string} src The source fo the image. + * @param {goog.graphics.GroupElement=} opt_group The group wrapper element + * to append to. If not specified, appends to the main canvas. + * + * @return {!goog.graphics.ImageElement} The newly created image wrapped in a + * rectangle element. + */ +goog.graphics.SvgGraphics.prototype.drawImage = function(x, y, width, height, + src, opt_group) { + var element = this.createSvgElement_('image', { + 'x': x, + 'y': y, + 'width': width, + 'height': height, + 'image-rendering': 'optimizeQuality', + 'preserveAspectRatio': 'none' + }); + element.setAttributeNS('http://www.w3.org/1999/xlink', 'href', src); + var wrapper = new goog.graphics.SvgImageElement(element, this); + this.append_(wrapper, opt_group); + return wrapper; +}; + + +/** + * Draw a text string vertically centered on a given line. + * + * @param {string} text The text to draw. + * @param {number} x1 X coordinate of start of line. + * @param {number} y1 Y coordinate of start of line. + * @param {number} x2 X coordinate of end of line. + * @param {number} y2 Y coordinate of end of line. + * @param {string} align Horizontal alignment: left (default), center, right. + * @param {goog.graphics.Font} font Font describing the font properties. + * @param {goog.graphics.Stroke?} stroke Stroke object describing the + * stroke. + * @param {goog.graphics.Fill?} fill Fill object describing the fill. + * @param {goog.graphics.GroupElement=} opt_group The group wrapper element + * to append to. If not specified, appends to the main canvas. + * + * @return {!goog.graphics.TextElement} The newly created element. + * @override + */ +goog.graphics.SvgGraphics.prototype.drawTextOnLine = function( + text, x1, y1, x2, y2, align, font, stroke, fill, opt_group) { + var angle = Math.round(goog.math.angle(x1, y1, x2, y2)); + var dx = x2 - x1; + var dy = y2 - y1; + var lineLength = Math.round(Math.sqrt(dx * dx + dy * dy)); // Length of line + + // SVG baseline is on the glyph's base line. We estimate it as 85% of the + // font height. This is just a rough estimate, but do not have a better way. + var fontSize = font.size; + var attributes = {'font-family': font.family, 'font-size': fontSize}; + var baseline = Math.round(fontSize * 0.85); + var textY = Math.round(y1 - (fontSize / 2) + baseline); + var textX = x1; + if (align == 'center') { + textX += Math.round(lineLength / 2); + attributes['text-anchor'] = 'middle'; + } else if (align == 'right') { + textX += lineLength; + attributes['text-anchor'] = 'end'; + } + attributes['x'] = textX; + attributes['y'] = textY; + if (font.bold) { + attributes['font-weight'] = 'bold'; + } + if (font.italic) { + attributes['font-style'] = 'italic'; + } + if (angle != 0) { + attributes['transform'] = 'rotate(' + angle + ' ' + x1 + ' ' + y1 + ')'; + } + + var element = this.createSvgElement_('text', attributes); + element.appendChild(this.dom_.getDocument().createTextNode(text)); + + // Bypass a Firefox-Mac bug where text fill is ignored. If text has no stroke, + // set a stroke, otherwise the text will not be visible. + if (stroke == null && goog.userAgent.GECKO && goog.userAgent.MAC) { + var color = 'black'; + // For solid fills, use the fill color + if (fill instanceof goog.graphics.SolidFill) { + color = fill.getColor(); + } + stroke = new goog.graphics.Stroke(1, color); + } + + var wrapper = new goog.graphics.SvgTextElement(element, this, stroke, fill); + this.append_(wrapper, opt_group); + return wrapper; +}; + + +/** + * Draw a path. + * + * @param {!goog.graphics.Path} path The path object to draw. + * @param {goog.graphics.Stroke?} stroke Stroke object describing the + * stroke. + * @param {goog.graphics.Fill?} fill Fill object describing the fill. + * @param {goog.graphics.GroupElement=} opt_group The group wrapper element + * to append to. If not specified, appends to the main canvas. + * + * @return {!goog.graphics.PathElement} The newly created element. + * @override + */ +goog.graphics.SvgGraphics.prototype.drawPath = function( + path, stroke, fill, opt_group) { + + var element = this.createSvgElement_('path', + {'d': goog.graphics.SvgGraphics.getSvgPath(path)}); + var wrapper = new goog.graphics.SvgPathElement(element, this, stroke, fill); + this.append_(wrapper, opt_group); + return wrapper; +}; + + +/** + * Returns a string representation of a logical path suitable for use in + * an SVG element. + * + * @param {goog.graphics.Path} path The logical path. + * @return {string} The SVG path representation. + * @suppress {deprecated} goog.graphics is deprecated. + */ +goog.graphics.SvgGraphics.getSvgPath = function(path) { + var list = []; + path.forEachSegment(function(segment, args) { + switch (segment) { + case goog.graphics.Path.Segment.MOVETO: + list.push('M'); + Array.prototype.push.apply(list, args); + break; + case goog.graphics.Path.Segment.LINETO: + list.push('L'); + Array.prototype.push.apply(list, args); + break; + case goog.graphics.Path.Segment.CURVETO: + list.push('C'); + Array.prototype.push.apply(list, args); + break; + case goog.graphics.Path.Segment.ARCTO: + var extent = args[3]; + list.push('A', args[0], args[1], + 0, Math.abs(extent) > 180 ? 1 : 0, extent > 0 ? 1 : 0, + args[4], args[5]); + break; + case goog.graphics.Path.Segment.CLOSE: + list.push('Z'); + break; + } + }); + return list.join(' '); +}; + + +/** + * Create an empty group of drawing elements. + * + * @param {goog.graphics.GroupElement=} opt_group The group wrapper element + * to append to. If not specified, appends to the main canvas. + * + * @return {!goog.graphics.GroupElement} The newly created group. + * @override + */ +goog.graphics.SvgGraphics.prototype.createGroup = function(opt_group) { + var element = this.createSvgElement_('g'); + var parent = opt_group || this.canvasElement; + parent.getElement().appendChild(element); + return new goog.graphics.SvgGroupElement(element, this); +}; + + +/** + * Measure and return the width (in pixels) of a given text string. + * Text measurement is needed to make sure a text can fit in the allocated area. + * The way text length is measured is by writing it into a div that is after + * the visible area, measure the div width, and immediatly erase the written + * value. + * + * @param {string} text The text string to measure. + * @param {goog.graphics.Font} font The font object describing the font style. + * @override + */ +goog.graphics.SvgGraphics.prototype.getTextWidth = function(text, font) { + // TODO(user) Implement +}; + + +/** + * Adds a defintion of an element to the global definitions. + * @param {string} defKey This is a key that should be unique in a way that + * if two definitions are equal the should have the same key. + * @param {Element} defElement DOM element to add as a definition. It must + * have an id attribute set. + * @return {string} The assigned id of the defElement. + */ +goog.graphics.SvgGraphics.prototype.addDef = function(defKey, defElement) { + if (defKey in this.defs_) { + return this.defs_[defKey]; + } + var id = goog.graphics.SvgGraphics.DEF_ID_PREFIX_ + + goog.graphics.SvgGraphics.nextDefId_++; + defElement.setAttribute('id', id); + this.defs_[defKey] = id; + + // Add the def defElement of the defs list. + var defs = this.defsElement_; + defs.appendChild(defElement); + return id; +}; + + +/** + * Returns the id of a definition element. + * @param {string} defKey This is a key that should be unique in a way that + * if two definitions are equal the should have the same key. + * @return {?string} The id of the found definition element or null if + * not found. + */ +goog.graphics.SvgGraphics.prototype.getDef = function(defKey) { + return defKey in this.defs_ ? this.defs_[defKey] : null; +}; + + +/** + * Removes a definition of an elemnt from the global definitions. + * @param {string} defKey This is a key that should be unique in a way that + * if two definitions are equal they should have the same key. + */ +goog.graphics.SvgGraphics.prototype.removeDef = function(defKey) { + var id = this.getDef(defKey); + if (id) { + var element = this.dom_.getElement(id); + this.defsElement_.removeChild(element); + delete this.defs_[defKey]; + } +}; + + +/** @override */ +goog.graphics.SvgGraphics.prototype.enterDocument = function() { + var oldPixelSize = this.getPixelSize(); + goog.graphics.SvgGraphics.superClass_.enterDocument.call(this); + + // Dispatch a resize if this is the first time the size value is accurate. + if (!oldPixelSize) { + this.dispatchEvent(goog.events.EventType.RESIZE); + } + + + // For percentage based heights, listen for changes to size. + if (this.useManualViewbox_) { + var width = this.width; + var height = this.height; + + if (typeof width == 'string' && width.indexOf('%') != -1 && + typeof height == 'string' && height.indexOf('%') != -1) { + // SVG elements don't behave well with respect to size events, so we + // resort to polling. + this.handler_.listen(goog.graphics.SvgGraphics.getResizeCheckTimer_(), + goog.Timer.TICK, this.updateManualViewBox_); + } + + this.updateManualViewBox_(); + } +}; + + +/** @override */ +goog.graphics.SvgGraphics.prototype.exitDocument = function() { + goog.graphics.SvgGraphics.superClass_.exitDocument.call(this); + + // Stop polling. + if (this.useManualViewbox_) { + this.handler_.unlisten(goog.graphics.SvgGraphics.getResizeCheckTimer_(), + goog.Timer.TICK, this.updateManualViewBox_); + } +}; + + +/** + * Disposes of the component by removing event handlers, detacing DOM nodes from + * the document body, and removing references to them. + * @override + * @protected + */ +goog.graphics.SvgGraphics.prototype.disposeInternal = function() { + delete this.defs_; + delete this.defsElement_; + delete this.canvasElement; + this.handler_.dispose(); + delete this.handler_; + goog.graphics.SvgGraphics.superClass_.disposeInternal.call(this); +}; + + +/** + * The centralized resize checking timer. + * @type {goog.Timer|undefined} + * @private + */ +goog.graphics.SvgGraphics.resizeCheckTimer_; + + +/** + * @return {goog.Timer} The centralized timer object used for interval timing. + * @private + */ +goog.graphics.SvgGraphics.getResizeCheckTimer_ = function() { + if (!goog.graphics.SvgGraphics.resizeCheckTimer_) { + goog.graphics.SvgGraphics.resizeCheckTimer_ = new goog.Timer(400); + goog.graphics.SvgGraphics.resizeCheckTimer_.start(); + } + + return /** @type {goog.Timer} */ ( + goog.graphics.SvgGraphics.resizeCheckTimer_); +}; + + +/** @override */ +goog.graphics.SvgGraphics.prototype.isDomClonable = function() { + return true; +}; http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/e2cad6e6/externs/GCL/externs/goog/graphics/textelement.js ---------------------------------------------------------------------- diff --git a/externs/GCL/externs/goog/graphics/textelement.js b/externs/GCL/externs/goog/graphics/textelement.js new file mode 100644 index 0000000..c96ae6d --- /dev/null +++ b/externs/GCL/externs/goog/graphics/textelement.js @@ -0,0 +1,55 @@ +// Copyright 2007 The Closure Library Authors. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS-IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + + +/** + * @fileoverview A thin wrapper around the DOM element for text elements. + * @author [email protected] (Erik Arvidsson) + */ + + +goog.provide('goog.graphics.TextElement'); + +goog.require('goog.graphics.StrokeAndFillElement'); + + + +/** + * Interface for a graphics text element. + * You should not construct objects from this constructor. The graphics + * will return an implementation of this interface for you. + * + * @param {Element} element The DOM element to wrap. + * @param {goog.graphics.AbstractGraphics} graphics The graphics creating + * this element. + * @param {goog.graphics.Stroke?} stroke The stroke to use for this element. + * @param {goog.graphics.Fill?} fill The fill to use for this element. + * @constructor + * @extends {goog.graphics.StrokeAndFillElement} + * @deprecated goog.graphics is deprecated. It existed to abstract over browser + * differences before the canvas tag was widely supported. See + * http://en.wikipedia.org/wiki/Canvas_element for details. + */ +goog.graphics.TextElement = function(element, graphics, stroke, fill) { + goog.graphics.StrokeAndFillElement.call(this, element, graphics, stroke, + fill); +}; +goog.inherits(goog.graphics.TextElement, goog.graphics.StrokeAndFillElement); + + +/** + * Update the displayed text of the element. + * @param {string} text The text to draw. + */ +goog.graphics.TextElement.prototype.setText = goog.abstractMethod;
