How to use the fabric.util function in fabric

To help you get started, we’ve selected a few fabric examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github concord-consortium / drawing-tool / app / scripts / drawing-tool.js View on Github external
function loadImage() {
    // Note we cannot use fabric.Image.fromURL, as then we would always get
    // fabric.Image instance and we couldn't guess whether load failed or not.
    // util.loadImage provides null to callback when loading fails.
    fabric.util.loadImage(imageSrc, callback, null, options.crossOrigin);
  }
  function callback (img) {
github concord-consortium / drawing-tool / app / scripts / tools / clone-tool.js View on Github external
CloneTool.prototype.copy = function (callback) {
  var activeObject = this.canvas.getActiveGroup() || this.canvas.getActiveObject();
  if (!activeObject) {
    return;
  }
  // We don't want to copy control point, but the source object instead.
  // See: line-custom-control-points.js
  if (activeObject._dt_sourceObj) {
    activeObject = activeObject._dt_sourceObj;
  }
  var klass = fabric.util.getKlass(activeObject.type);
  var propsToInclude = this.master.ADDITIONAL_PROPS_TO_SERIALIZE;
  if (klass.async) {
    activeObject.clone(function (clonedObject) {
      this._updateClipboard(clonedObject);
      if (typeof callback === 'function') {
        callback();
      }
    }.bind(this), propsToInclude);
  } else {
    this._updateClipboard(activeObject.clone(null, propsToInclude));
    if (typeof callback === 'function') {
      callback();
    }
  }
};
github concord-consortium / drawing-tool / app / scripts / fabric-extensions / arrow.js View on Github external
  'use strict';

  var extend = fabric.util.object.extend;

  if (fabric.Arrow) {
    fabric.warn('fabric.Arrow is already defined');
    return;
  }

  /**
   * Arrow class
   * @class fabric.Arrow
   * @extends fabric.Line
   * @see {@link fabric.Arrow#initialize} for constructor definition
   */
  fabric.Arrow = fabric.util.createClass(fabric.Line, /** @lends fabric.Arrow.prototype */ {

    /**
     * Type of an object
     * @type String
     * @default
     */
    type: 'arrow',

    /**
     * Type of the arrow (double or single)
     * @type Boolean
     * @default
     */
    doubleArrowhead: false,

    /**
github concord-consortium / drawing-tool / app / scripts / tools / shape-tools / stamp-tool.js View on Github external
StampTool.prototype._loadNonSVGImage = function (url, callback) {
  fabric.util.loadImage(url, function (img) {
    var fabricObj = new fabric.Image(img, {
      crossOrigin: img.crossOrigin
    });
    fabricObj._dt_sourceURL = url;
    callback(fabricObj, img)
  }, null, 'anonymous');
};
github concord-consortium / drawing-tool / app / scripts / tools / shape-tools / line-tool.js View on Github external
function LineTool(name, drawTool, lineType, lineOptions) {
  ShapeTool.call(this, name, drawTool);

  lineType = lineType || 'line';
  this._lineKlass = fabric.util.getKlass(lineType);
  this._lineOptions = lineOptions;

  lineCustomControlPoints(this.canvas);
}
github concord-consortium / drawing-tool / app / scripts / tools / shape-tools / stamp-tool.js View on Github external
fabric.loadSVGFromURL(url, function (objects, options) {
    var fabricObj = fabric.util.groupSVGElements(objects, options);
    fabricObj._dt_sourceURL = url;
    callback(fabricObj, this._renderToImage(fabricObj));
  }.bind(this));
};
github concord-consortium / drawing-tool / app / scripts / tools / shape-tools / basic-shape-tool.js View on Github external
function BasicShapeTool(name, drawTool, type) {
  ShapeTool.call(this, name, drawTool);

  this._type = SUPPORTED_SHAPES[type];
  this._shapeKlass = fabric.util.getKlass(this._type.fabricType);
}
github concord-consortium / drawing-tool / app / scripts / fabric-extensions / arrow.js View on Github external
(function() {

  'use strict';

  var extend = fabric.util.object.extend;

  if (fabric.Arrow) {
    fabric.warn('fabric.Arrow is already defined');
    return;
  }

  /**
   * Arrow class
   * @class fabric.Arrow
   * @extends fabric.Line
   * @see {@link fabric.Arrow#initialize} for constructor definition
   */
  fabric.Arrow = fabric.util.createClass(fabric.Line, /** @lends fabric.Arrow.prototype */ {

    /**
     * Type of an object