From e0f55f374caa90ab946bd48bdf8770d51930047b Mon Sep 17 00:00:00 2001 From: leo60228 Date: Mon, 8 Jun 2020 18:12:20 -0400 Subject: Add emojis:generate_borders Rake task (#13773) * Add emojis:generate_borders Rake task * Address review * Border all dark emoji * Combine stroke with filter to reduce artifacting * Cleanup Camera with Flash * Add stroke-linejoin="round" The previous filter and tweaks were effectively a poor imitation of it. There are no artifacts for any dark emoji now! * Set stroke-width using property This fixes old versions of Firefox. * Store emoji in string instead of array * Use separate arguments for each path segment * Remove "background: black;" --- lib/tasks/emojis.rake | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'lib/tasks') diff --git a/lib/tasks/emojis.rake b/lib/tasks/emojis.rake index 70919fbdb..0e7921ffc 100644 --- a/lib/tasks/emojis.rake +++ b/lib/tasks/emojis.rake @@ -1,5 +1,35 @@ # frozen_string_literal: true +def gen_border(codepoint) + input = Rails.root.join('public', 'emoji', "#{codepoint}.svg") + dest = Rails.root.join('public', 'emoji', "#{codepoint}_border.svg") + doc = File.open(input) { |f| Nokogiri::XML(f) } + svg = doc.at_css('svg') + if svg.key?('viewBox') + view_box = svg['viewBox'].split(' ').map(&:to_i) + view_box[0] -= 2 + view_box[1] -= 2 + view_box[2] += 4 + view_box[3] += 4 + svg['viewBox'] = view_box.join(' ') + end + g = Nokogiri::XML::Node.new 'g', doc + doc.css('svg > *').each do |elem| + border_elem = elem.dup + + border_elem.delete('fill') + + border_elem['stroke'] = 'white' + border_elem['stroke-linejoin'] = 'round' + border_elem['stroke-width'] = '4px' + + g.add_child(border_elem) + end + svg.prepend_child(g) + File.write(dest, doc.to_xml) + puts "Wrote bordered #{codepoint}.svg to #{dest}!" +end + def codepoints_to_filename(codepoints) codepoints.downcase.gsub(/\A[0]+/, '').tr(' ', '-') end @@ -23,8 +53,10 @@ namespace :emojis do HTTP.get(source).to_s.split("\n").each do |line| next if line.start_with? '#' + parts = line.split(';').map(&:strip) next if parts.size < 2 + codes << [parts[0], parts[1].start_with?('fully-qualified')] end @@ -55,4 +87,16 @@ namespace :emojis do File.write(dest, Oj.dump(map)) puts "Wrote emojo to destination! (#{dest})" end + + desc 'Generate emoji variants with white borders' + task :generate_borders do + src = Rails.root.join('app', 'javascript', 'mastodon', 'features', 'emoji', 'emoji_map.json') + emojis = '🎱🐜âšĢ🖤âŦ›â—ŧī¸â—žâ—ŧī¸âœ’ī¸â–Ēī¸đŸ’ŖđŸŽŗ📷📸â™Ŗī¸đŸ•ļī¸âœ´ī¸đŸ”ŒđŸ’‚‍♀ī¸đŸ“Ŋī¸đŸŗđŸĻđŸ’‚đŸ”ĒđŸ•ŗī¸đŸ•šī¸đŸ•‹đŸ–Šī¸đŸ–‹ī¸đŸ’‚‍♂ī¸đŸŽ¤đŸŽ“đŸŽĨđŸŽŧ♠ī¸đŸŽŠđŸĻƒđŸ“ŧ📹🎮🐃🏴đŸ‘Ŋ⚾🐔☁ī¸đŸ’¨đŸ•Šī¸đŸ‘€đŸĨđŸ‘ģ🐐❕❔⛸ī¸đŸŒŠī¸đŸ”ŠđŸ”‡đŸ“ƒđŸŒ§ī¸đŸđŸšđŸ™đŸ“đŸ‘đŸ’€â˜ ī¸đŸŒ¨ī¸đŸ”‰đŸ”ˆđŸ’Ŧ💭🏐đŸŗī¸âšĒâŦœâ—Ŋâ—ģī¸â–Ģī¸' + + map = Oj.load(File.read(src)) + + emojis.each_grapheme_cluster do |emoji| + gen_border map[emoji] + end + end end -- cgit