Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ test
test-output
npm-debug.log
node_modules
coverage
.idea
29 changes: 19 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,26 @@
"bin": {
"jeff": "./bin/jeff"
},
"scripts": {
"test": "NODE_ENV=test mocha --recursive unit-tests",
"istanbul": "istanbul cover _mocha unit-tests/**/*.test.js"
},
"main": "./src/index.js",
"dependencies": {
"async": "0.2.10",
"buffer-crc32": "^0.2.5",
"canvas": "1.1.6",
"commander": "2.2.0",
"fs-extra": "0.8.1",
"glob": "4.3.1",
"image-optim": "0.3.0",
"js-beautify": "1.4.2",
"node-pngquant-native": "0.0.12"
"async": "0.2.10",
"buffer-crc32": "^0.2.5",
"canvas": "1.6.11",
"commander": "2.2.0",
"fs-extra": "0.8.1",
"glob": "4.3.1",
"image-optim": "0.3.0",
"js-beautify": "1.4.2",
"node-pngquant-native": "1.0.5"
},
"devDependencies" : {
"chai": "4.1.2",
"mocha": "5.2.0",
"istanbul": "0.4.5"
},
"repository": {
"type": "git",
Expand All @@ -32,4 +41,4 @@
"url": "https://github.com/Wizcorp/jeff/blob/master/LICENSE"
}
]
}
}
18 changes: 8 additions & 10 deletions src/SwfObjectProcessor/createSymbols.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ var processShape = require('./processShape');

function createSymbol(swfObject) {
var symbol = { id: swfObject.id, swfObject: swfObject, parents: {} };

switch(swfObject.type) {

case 'main':
Expand All @@ -28,18 +28,16 @@ function createSymbol(swfObject) {

case 'shape':
var shapes = swfObject.edges;
var nbShapes = shapes.length;
var imagesArray = [];
for (var s = 0; s < shapes.length; s += 1) {
for (var s = 0; s < nbShapes; s++) {
var shape = shapes[s];

var fill = shape.leftFill;
var containsImage = fill ? (fill.type ? (fill.type === 'pattern') : false) : false;
if (!containsImage) {
fill = shape.rightFill;
containsImage = fill ? (fill.type ? (fill.type === 'pattern') : false) : false;
}
var isLeftFill = shape && shape.leftFill && shape.leftFill.type === 'pattern';
var isRightFill = shape && shape.rightFill && shape.rightFill.type === 'pattern';

if (containsImage) {
if (isLeftFill || isRightFill) {
var fill = isLeftFill ? shape.leftFill : shape.rightFill;
var m = fill.matrix;

// In case of an image all the components of the matrix have to be divided by 20
Expand Down Expand Up @@ -115,7 +113,7 @@ function createSymbol(swfObject) {
function createSymbols(swfObjects) {
var symbols = [];
var nbSymbols = swfObjects.length;
for (var s = 0; s < nbSymbols; s += 1) {
for (var s = 0; s < nbSymbols; s++) {
var swfObject = swfObjects[s];
symbols[swfObject.id] = createSymbol(swfObject);
}
Expand Down
60 changes: 35 additions & 25 deletions src/SwfObjectProcessor/removeSymbols.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,40 @@
'use strict';

function removeSymbols(symbols, classSymbols, removeList){
var nbClassSymbols = classSymbols.length;
for (var s = 0; s < nbClassSymbols; s += 1) {

var classSymbol = classSymbols[s];
if (!classSymbol || !classSymbol.children) {
continue;
}

var children = classSymbol.children;
for (var c = 0; c < children.length; c += 1) {

var child = children[c];
var symbol = symbols[child.id];
if (!symbol.className){
continue;
}

var idx = removeList.indexOf(symbol.className);
if (idx !== -1) {
children.splice(c, 1);
c -= 1;
}
}
}
function removeSymbols(symbols, classSymbols, removeList) {
var nbClassSymbols = classSymbols.length;

for (var s = 0; s < nbClassSymbols; s++) {
var classSymbol = classSymbols[s];

if (!classSymbol || !classSymbol.children) {
continue;
}

var children = classSymbol.children;

for (var c = 0; c < children.length; c++) {
var child = children[c];

if (!child || typeof child.id === "undefined") {
continue;
}

var symbol = symbols[child.id];

if (!symbol || !symbol.className) {
continue;
}

if (removeList && removeList.length > 0) {
var idx = removeList.indexOf(symbol.className);

if (idx !== -1) {
children.splice(c, 1);
c -= 1;
}
}
}
}
}

module.exports = removeSymbols;
33 changes: 33 additions & 0 deletions unit-tests/SwfObjectProcessor/addClassNames.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
const expect = require('chai').expect;

const addClassNames = require('../../src/SwfObjectProcessor/addClassNames');

describe('Add class names', function () {
it('add one class name', function () {
const symbols = [{}];

const classNames = {
test: [0]
};

const classNamesKeys = Object.keys(classNames);

const result = addClassNames(symbols, classNames);

expect(result[0]).to.exist;
expect(result[0]).to.have.own.property('className');
expect(result[0].className).to.eql(classNamesKeys[0]);
});

it('add no class', function () {
const symbols = [];

const classNames = {
test: [0]
};

const result = addClassNames(symbols, classNames);

expect(result).to.be.empty;
});
});
Loading