mirror of https://github.com/zulip/zulip.git
build_emoji: Generate CSS files for all the emoji sets.
Modify the `build_emoji` tool to copy spritesheets for all the emojisets to emoji cache and generate CSS files for them.
This commit is contained in:
parent
e52f2b5aba
commit
c70cfa2188
|
@ -16,7 +16,8 @@ from typing import Dict, Text, Union
|
||||||
from os.path import dirname
|
from os.path import dirname
|
||||||
from PIL import Image, ImageDraw, ImageFont
|
from PIL import Image, ImageDraw, ImageFont
|
||||||
|
|
||||||
from emoji_setup_utils import generate_emoji_catalog, emoji_names_for_picker
|
from emoji_setup_utils import generate_emoji_catalog, emoji_names_for_picker, \
|
||||||
|
EMOJISETS
|
||||||
|
|
||||||
ZULIP_PATH = os.path.join(os.path.dirname(os.path.abspath(__file__)), '../../../')
|
ZULIP_PATH = os.path.join(os.path.dirname(os.path.abspath(__file__)), '../../../')
|
||||||
sys.path.append(ZULIP_PATH)
|
sys.path.append(ZULIP_PATH)
|
||||||
|
@ -59,7 +60,7 @@ div.emoji,
|
||||||
span.emoji
|
span.emoji
|
||||||
{
|
{
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
background-image: url('sheet_google_32.png');
|
background-image: url('sheet_%(emojiset)s_32.png');
|
||||||
-webkit-background-size: 1025px 1025px;
|
-webkit-background-size: 1025px 1025px;
|
||||||
-moz-background-size: 1025px 1025px;
|
-moz-background-size: 1025px 1025px;
|
||||||
background-size: 1025px 1025px;
|
background-size: 1025px 1025px;
|
||||||
|
@ -265,8 +266,7 @@ def dump_emojis(cache_path):
|
||||||
os.path.join(cache_emoji, fn)
|
os.path.join(cache_emoji, fn)
|
||||||
)
|
)
|
||||||
|
|
||||||
sprite_sheet_google = os.path.join(EMOJI_DATA_PATH, 'sheet_google_32.png')
|
# Spritesheet CSS generation code.
|
||||||
run(['cp', sprite_sheet_google, cache_path], shell=True)
|
|
||||||
emoji_positions = ""
|
emoji_positions = ""
|
||||||
for emoji in emoji_data:
|
for emoji in emoji_data:
|
||||||
if emoji["has_img_google"]:
|
if emoji["has_img_google"]:
|
||||||
|
@ -274,10 +274,15 @@ def dump_emojis(cache_path):
|
||||||
'pos_x': (emoji["sheet_x"] * 100) / 40,
|
'pos_x': (emoji["sheet_x"] * 100) / 40,
|
||||||
'pos_y': (emoji["sheet_y"] * 100) / 40,
|
'pos_y': (emoji["sheet_y"] * 100) / 40,
|
||||||
}
|
}
|
||||||
SPRITE_CSS_PATH = os.path.join(cache_path, 'google_sprite.css')
|
for emojiset in EMOJISETS:
|
||||||
sprite_css_file = open(SPRITE_CSS_PATH, 'w')
|
sprite_sheet = os.path.join(EMOJI_DATA_PATH, 'sheet_%s_32.png' % (emojiset,))
|
||||||
sprite_css_file.write(SPRITE_CSS_FILE_TEMPLATE % {'emoji_positions': emoji_positions, })
|
run(['cp', sprite_sheet, cache_path], shell=True)
|
||||||
sprite_css_file.close()
|
SPRITE_CSS_PATH = os.path.join(cache_path, '%s_sprite.css' % (emojiset,))
|
||||||
|
sprite_css_file = open(SPRITE_CSS_PATH, 'w')
|
||||||
|
sprite_css_file.write(SPRITE_CSS_FILE_TEMPLATE % {'emojiset': emojiset,
|
||||||
|
'emoji_positions': emoji_positions,
|
||||||
|
})
|
||||||
|
sprite_css_file.close()
|
||||||
|
|
||||||
# Add zulip emoji to `emoji_map` so that we can avoid
|
# Add zulip emoji to `emoji_map` so that we can avoid
|
||||||
# adding unnecessary exceptions to the rendering logic.
|
# adding unnecessary exceptions to the rendering logic.
|
||||||
|
|
|
@ -15,6 +15,9 @@ import ujson
|
||||||
from six.moves import range, zip
|
from six.moves import range, zip
|
||||||
from typing import Any, Dict, List, Text
|
from typing import Any, Dict, List, Text
|
||||||
|
|
||||||
|
# Emojisets that we currently support.
|
||||||
|
EMOJISETS = ['apple', 'emojione', 'google', 'twitter']
|
||||||
|
|
||||||
# the corresponding code point will be set to exactly these names as a
|
# the corresponding code point will be set to exactly these names as a
|
||||||
# final pass, overriding any other rules. This is useful for cases
|
# final pass, overriding any other rules. This is useful for cases
|
||||||
# where the two names are very different, users might reasonably type
|
# where the two names are very different, users might reasonably type
|
||||||
|
@ -249,8 +252,7 @@ def generate_emoji_catalog(emoji_data):
|
||||||
# the emoji sets so that we can switch emoji sets seemlessly.
|
# the emoji sets so that we can switch emoji sets seemlessly.
|
||||||
def emoji_is_universal(emoji_dict):
|
def emoji_is_universal(emoji_dict):
|
||||||
# type: (Dict[Text, Any]) -> bool
|
# type: (Dict[Text, Any]) -> bool
|
||||||
emoji_sets = ['apple', 'emojione', 'google', 'twitter']
|
for emoji_set in EMOJISETS:
|
||||||
for emoji_set in emoji_sets:
|
|
||||||
if not emoji_dict['has_img_' + emoji_set]:
|
if not emoji_dict['has_img_' + emoji_set]:
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
Loading…
Reference in New Issue