Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OpenMoji on dark background - initial attempt to fix #31 #231

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
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
65 changes: 65 additions & 0 deletions helpers/add-background.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#!/usr/bin/env node


const path = require('path');
const fs = require('fs');
const SVGO = require('svgo');

const openmojis = require("../data/openmoji.json");

const {
createDoc
} = require('../test/utils/utils');

svgo = new SVGO();

openmojis.forEach(emoji => {
const svgFile = path.join("src", emoji.group, emoji.subgroups, emoji.hexcode + '.svg')
const doc = createDoc(emoji);

const root = doc.querySelector("#emoji")

// create background and insert it
const backgroundGroup = doc.createElement('g')
backgroundGroup.setAttribute('id', "white-padding")
backgroundGroup.setAttribute('stroke-linecap', "round")
backgroundGroup.setAttribute('stroke-miterlimit', "10")
backgroundGroup.setAttribute('stroke-width', "6")
backgroundGroup.setAttribute('stroke', "#fff")
backgroundGroup.setAttribute('fill', "none")
backgroundGroup.setAttribute('stroke-linejoin', "round")

const beforeNode = doc.querySelector("#grid").nextSibling
root.insertBefore(backgroundGroup, beforeNode)


// duplicate all but grid
var nongrid = doc.querySelectorAll('svg > :not(#grid):not(#white-padding)');
console.log(nongrid.length);
for (var value of nongrid.values()) {
console.log(value.id);

backgroundGroup.appendChild(value.cloneNode(true))
}

// remove fill and stroke attributes
var items = backgroundGroup.getElementsByTagName("*");
for (let item of items) {
item.removeAttribute("fill");
item.removeAttribute("stroke");
item.removeAttribute("stroke-linecap");
item.removeAttribute("stroke-linejoin");
item.removeAttribute("stroke-miterlimit");
item.removeAttribute("stroke-width");
}

svgo.optimize(doc.documentElement.querySelector("svg").outerHTML).then(function (result) {
svgo.optimize(result.data).then(function (result) {

fs.writeFile(svgFile, result.data, function (err) {
if (err) return console.log(err);
console.log('Successful');
});
});
});
})
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
"generate": "./helpers/generate.sh",
"generate-font": "./helpers/generate-fonts.sh",
"cache-clear": "for ref in export-png-618 export-png-72 export-svg-color export-svg-skintones pretty-src-svg; do git update-ref -d refs/memos/$ref; done",
"cc": "npm run cache-clear"
"cc": "npm run cache-clear",
"add-background": "node helpers/add-background.js --openmoji-src-folder $PWD/src"
},
"engines": {
"node": "8.x"
Expand Down