Skip to content

Resolve the emoji.json "unicodes" mess #60

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

Merged
merged 2 commits into from
Aug 7, 2014
Merged
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
28 changes: 11 additions & 17 deletions db/aliases.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<script>
const VARIATION_SELECTOR_15 = String.fromCharCode(0xfe0e);
const VARIATION_SELECTOR_16 = String.fromCharCode(0xfe0f);
const EMOJI_SIZE = 32

function detectAliases(db) {
for (var i = 0; i < db.length; ++i) {
Expand All @@ -22,23 +23,14 @@
continue;
}

var candidates = [];

if (raw.length === 1) {
candidates.push(raw + VARIATION_SELECTOR_15);
candidates.push(raw + VARIATION_SELECTOR_16);
} else if (raw[raw.length - 1] === VARIATION_SELECTOR_16) {
var base = raw.substr(0, raw.length - 1);
candidates.push(base);
candidates.push(base + VARIATION_SELECTOR_15);
if (raw.indexOf(VARIATION_SELECTOR_16) > -1) {
var candidates = [raw.replace(VARIATION_SELECTOR_16, ""), raw];
} else {
var candidates = [raw, raw + VARIATION_SELECTOR_16];
}

var aliases = candidates.filter(isColorEmoji);
if (aliases.length) {
emoji.unicodes = aliases;
} else {
delete emoji.unicodes;
}
emoji.emoji = aliases[0];
}

dump(db);
Expand All @@ -52,14 +44,16 @@
}

var canvas = document.createElement("canvas");
canvas.width = canvas.height = EMOJI_SIZE;

function color(emoji, rgb) {
var context = canvas.getContext("2d");
context.clearRect(0, 0, 32, 32);
context.clearRect(0, 0, canvas.width, canvas.height);
context.fillStyle = rgb;
context.textBaseline = "top";
context.font = "32px Arial";
context.font = EMOJI_SIZE+"px Arial";
context.fillText(emoji, 0, 0);
var data = context.getImageData(0, 0, 32, 32).data;
var data = context.getImageData(0, 0, EMOJI_SIZE, EMOJI_SIZE).data;
for (var i = 0; i < data.length; i += 4) {
if (data[i] === 0 && data[i + 1] === 0 && data[i + 2] === 0) {
continue;
Expand Down
9 changes: 2 additions & 7 deletions db/dump.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,14 @@ def add_reference(code)
trap(:PIPE) { abort }

items = []
variation = "\u{fe0f}".freeze

variation_codepoint = Emoji::VARIATION_SELECTOR_16.codepoints[0]

for emoji in Emoji.all
unicodes = emoji.unicode_aliases.dup

item = {}

unless emoji.custom?
variation_codepoint = variation.codepoints[0]
chars = emoji.raw.codepoints.map { |code| UnicodeCharacter.fetch(code) unless code == variation_codepoint }.compact
item[:emoji] = unicodes.shift
item[:unicodes] = unicodes if unicodes.any?
item[:emoji] = emoji.raw
item[:description] = chars.map(&:description).join(' + ')
end

Expand Down
Loading