<commit_before>/* -*- Mode: js; js-indent-level: 2; indent-tabs-mode: nil; tab-width: 2 -*- */
/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
/*
 * Copyright 2013 Mozilla Foundation
 *
 * 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.
 */
/*global push, fail */

var GRAPHICS_FILL_CLIPPED_BITMAP               = 65;
var GRAPHICS_FILL_FOCAL_RADIAL_GRADIENT        = 19;
var GRAPHICS_FILL_LINEAR_GRADIENT              = 16;
var GRAPHICS_FILL_NONSMOOTHED_CLIPPED_BITMAP   = 67;
var GRAPHICS_FILL_NONSMOOTHED_REPEATING_BITMAP = 66;
var GRAPHICS_FILL_RADIAL_GRADIENT              = 18;
var GRAPHICS_FILL_REPEATING_BITMAP             = 64;
var GRAPHICS_FILL_SOLID                        =  0;

function morph(start, end) {
  if (!isNaN(end) && end !== start)
    return start + '+' + (end - start) + '*r';

  return start;
}
function morphColor(color, colorMorph) {
  return '"rgba(" + (' +
    morph(color.red, colorMorph.red) + '|0) + "," + (' +
    morph(color.green, colorMorph.green) + '|0) + "," + (' +
    morph(color.blue, colorMorph.blue) + '|0) + "," + (' +
    morph(color.alpha / 255, colorMorph.alpha / 255) +
  ') + ")"';
}
function createFill(fillStyle, dictionary, dependencies) {
  var fill;
  switch (fillStyle.type) {
  case GRAPHICS_FILL_SOLID:
    if (fillStyle.colorMorph) {
      fill = morphColor(fillStyle.color, fillStyle.colorMorph);
    } else {
      var color = fillStyle.color;
      fill = '"rgba(' + [color.red, color.green, color.blue, color.alpha / 255].join(',') + ')"';
    }
    break;
  case GRAPHICS_FILL_LINEAR_GRADIENT:
  case GRAPHICS_FILL_RADIAL_GRADIENT:
  case GRAPHICS_FILL_FOCAL_RADIAL_GRADIENT:
    var records = fillStyle.records;
    var stops = [];
    for (var j = 0, n = records.length; j < n; j++) {
      var record = records[j];
      var color = record.color;
      if (record.colorMorph) {
        stops.push('f.addColorStop(' +
          morph(record.ratio / 255, record.ratioMorph / 255) + ',' +
          morphColor(color, record.colorMorph) +
        ')');
      } else {
        stops.push('f.addColorStop(' +
          (record.ratio / 255) + ',' +
          '"rgba(' + [color.red, color.green, color.blue, color.alpha / 255].join(',') + ')"' +
        ')');
      }
    }
    var isLinear = fillStyle.type === GRAPHICS_FILL_LINEAR_GRADIENT;
    fill = '(' +
      'f=c._create' + (isLinear ? 'Linear' : 'Radial') + 'Gradient(' +
        (isLinear ?
          '-1, 0, 1, 0' :
          '(' + morph(fillStyle.focalPoint, fillStyle.focalPointMorph) + ' || 0), 0, 0, 0, 0, 1'
        ) +
      '),' +
      stops.join(',') + ',' +
      'f.currentTransform=' +
        toMatrixInstance(fillStyle.matrix, fillStyle.matrixMorph, 20 * 819.2) + ',' +
    'f)';
    break;
  case GRAPHICS_FILL_REPEATING_BITMAP:
  case GRAPHICS_FILL_CLIPPED_BITMAP:
  case GRAPHICS_FILL_NONSMOOTHED_REPEATING_BITMAP:
  case GRAPHICS_FILL_NONSMOOTHED_CLIPPED_BITMAP:
    var bitmap = dictionary[fillStyle.bitmapId];
    dependencies.push(bitmap.id);
    fill = '(' +
      'f=c._createPattern(' +
        'd[' + bitmap.id + '].value.props.img,' +
        (fillStyle.repeat ? '"repeat"' : '"no-repeat"') +
      '),' +
      'f.currentTransform=' +
        toMatrixInstance(fillStyle.matrix, fillStyle.matrixMorph, 1) + ',' +
    'f)';
    break;
  default:
    fail('invalid fill style', 'shape');
  }
  return fill;
}
function toMatrixInstance(matrix, matrixMorph, scale) {<commit_msg>fixes repeating/clipped bitmap fill for SWF shape<commit_after>/* -*- Mode: js; js-indent-level: 2; indent-tabs-mode: nil; tab-width: 2 -*- */
/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
/*
 * Copyright 2013 Mozilla Foundation
 *
 * 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.
 */
/*global push, fail */

var GRAPHICS_FILL_CLIPPED_BITMAP               = 65;
var GRAPHICS_FILL_FOCAL_RADIAL_GRADIENT        = 19;
var GRAPHICS_FILL_LINEAR_GRADIENT              = 16;
var GRAPHICS_FILL_NONSMOOTHED_CLIPPED_BITMAP   = 67;
var GRAPHICS_FILL_NONSMOOTHED_REPEATING_BITMAP = 66;
var GRAPHICS_FILL_RADIAL_GRADIENT              = 18;
var GRAPHICS_FILL_REPEATING_BITMAP             = 64;
var GRAPHICS_FILL_SOLID                        =  0;

function morph(start, end) {
  if (!isNaN(end) && end !== start)
    return start + '+' + (end - start) + '*r';

  return start;
}
function morphColor(color, colorMorph) {
  return '"rgba(" + (' +
    morph(color.red, colorMorph.red) + '|0) + "," + (' +
    morph(color.green, colorMorph.green) + '|0) + "," + (' +
    morph(color.blue, colorMorph.blue) + '|0) + "," + (' +
    morph(color.alpha / 255, colorMorph.alpha / 255) +
  ') + ")"';
}
function createFill(fillStyle, dictionary, dependencies) {
  var fill;
  switch (fillStyle.type) {
  case GRAPHICS_FILL_SOLID:
    if (fillStyle.colorMorph) {
      fill = morphColor(fillStyle.color, fillStyle.colorMorph);
    } else {
      var color = fillStyle.color;
      fill = '"rgba(' + [color.red, color.green, color.blue, color.alpha / 255].join(',') + ')"';
    }
    break;
  case GRAPHICS_FILL_LINEAR_GRADIENT:
  case GRAPHICS_FILL_RADIAL_GRADIENT:
  case GRAPHICS_FILL_FOCAL_RADIAL_GRADIENT:
    var records = fillStyle.records;
    var stops = [];
    for (var j = 0, n = records.length; j < n; j++) {
      var record = records[j];
      var color = record.color;
      if (record.colorMorph) {
        stops.push('f.addColorStop(' +
          morph(record.ratio / 255, record.ratioMorph / 255) + ',' +
          morphColor(color, record.colorMorph) +
        ')');
      } else {
        stops.push('f.addColorStop(' +
          (record.ratio / 255) + ',' +
          '"rgba(' + [color.red, color.green, color.blue, color.alpha / 255].join(',') + ')"' +
        ')');
      }
    }
    var isLinear = fillStyle.type === GRAPHICS_FILL_LINEAR_GRADIENT;
    fill = '(' +
      'f=c._create' + (isLinear ? 'Linear' : 'Radial') + 'Gradient(' +
        (isLinear ?
          '-1, 0, 1, 0' :
          '(' + morph(fillStyle.focalPoint, fillStyle.focalPointMorph) + ' || 0), 0, 0, 0, 0, 1'
        ) +
      '),' +
      stops.join(',') + ',' +
      'f.currentTransform=' +
        toMatrixInstance(fillStyle.matrix, fillStyle.matrixMorph, 20 * 819.2) + ',' +
    'f)';
    break;
  case GRAPHICS_FILL_REPEATING_BITMAP:
  case GRAPHICS_FILL_CLIPPED_BITMAP:
  case GRAPHICS_FILL_NONSMOOTHED_REPEATING_BITMAP:
  case GRAPHICS_FILL_NONSMOOTHED_CLIPPED_BITMAP:
    var repeat = (fillStyle.type === GRAPHICS_FILL_REPEATING_BITMAP) || (fillStyle.type === GRAPHICS_FILL_NONSMOOTHED_REPEATING_BITMAP);
    var bitmap = dictionary[fillStyle.bitmapId];
    dependencies.push(bitmap.id);
    fill = '(' +
      'f=c._createPattern(' +
        'd[' + bitmap.id + '].value.props.img,' +
        (repeat ? '"repeat"' : '"no-repeat"') +
      '),' +
      'f.currentTransform=' +
        toMatrixInstance(fillStyle.matrix, fillStyle.matrixMorph, 1) + ',' +
    'f)';
    break;
  default:
    fail('invalid fill style', 'shape');
  }
  return fill;
}
function toMatrixInstance(matrix, matrixMorph, scale) {
{'fraction_non_alphanumeric': 0.1438330642156254, 'fraction_numerical': 0.017140727859893182, 'mean_word_length': 2.9220652703360934, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '3169660', 'n_tokens_mistral': 2962, 'n_tokens_neox': 2788, 'n_words': 606}