<commit_before>/**
 * PatternBrush class
 * @class fabric.PatternBrush
 * @extends fabric.BaseBrush
 */
fabric.PatternBrush = fabric.util.createClass(fabric.PencilBrush, /** @scope fabric.PatternBrush.prototype */ {

  createPattern: function(patternCanvas) {

    var dotWidth = 20,
        dotDistance = 5,
        patternCtx = patternCanvas.getContext('2d');

    patternCanvas.width = patternCanvas.height = dotWidth + dotDistance;

    patternCtx.fillStyle = this.color;
    patternCtx.beginPath();
    patternCtx.arc(dotWidth / 2, dotWidth / 2, dotWidth / 2, 0, Math.PI * 2, false);
    patternCtx.closePath();
    patternCtx.fill();
  },

  /**
   * Creates "pattern" instance property
   * @method createPattern
   */
  getPattern: function() {
    var patternCanvas = fabric.document.createElement('canvas');
    this.createPattern(patternCanvas);
    return this.canvas.contextTop.createPattern(patternCanvas, 'repeat');
  },

  /**
   * Sets brush styles
   * @method setBrushStyles
   */
  setBrushStyles: function() {
    this.callSuper('setBrushStyles');
    this.canvas.contextTop.strokeStyle = this.getPattern();
  }
});<commit_msg>Change pattern brush to work with fabric.Pattern<commit_after>/**
 * PatternBrush class
 * @class fabric.PatternBrush
 * @extends fabric.BaseBrush
 */
fabric.PatternBrush = fabric.util.createClass(fabric.PencilBrush, /** @scope fabric.PatternBrush.prototype */ {

  getPatternSrc: function() {

    var dotWidth = 20,
        dotDistance = 5,
        patternCanvas = fabric.document.createElement('canvas'),
        patternCtx = patternCanvas.getContext('2d');

    patternCanvas.width = patternCanvas.height = dotWidth + dotDistance;

    patternCtx.fillStyle = this.color;
    patternCtx.beginPath();
    patternCtx.arc(dotWidth / 2, dotWidth / 2, dotWidth / 2, 0, Math.PI * 2, false);
    patternCtx.closePath();
    patternCtx.fill();

    return patternCanvas;
  },

  getPatternSrcBody: function() {
    return String(this.getPatternSrc)
      .match(/function\s+\w*\s*\(.*\)\s+\{([\s\S]*)\}/)[1]
      .replace('this.color', '"' + this.color + '"');
  },

  /**
   * Creates "pattern" instance property
   * @method getPattern
   */
  getPattern: function() {
    return this.canvas.contextTop.createPattern(this.source || this.getPatternSrc(), 'repeat');
  },

  /**
   * Sets brush styles
   * @method setBrushStyles
   */
  setBrushStyles: function() {
    this.callSuper('setBrushStyles');
    this.canvas.contextTop.strokeStyle = this.getPattern();
  },

  /**
   * Creates path
   * @method createPath
   */
  createPath: function(pathData) {
    var path = this.callSuper('createPath', pathData);
    path.stroke = new fabric.Pattern({
      source: this.source || this.getPatternSrcBody()
    });
    return path;
  }
});
{'fraction_non_alphanumeric': 0.14439655172413793, 'fraction_numerical': 0.006824712643678161, 'mean_word_length': 3.3858267716535435, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6857278', 'n_tokens_mistral': 874, 'n_tokens_neox': 838, 'n_words': 160}