Welcome to mirror list, hosted at ThFree Co, Russian Federation.

extract-emojione-flags.py « scripts - github.com/mumble-voip/mumble.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 66960ff6353d375615a02196a4172145e8ba1d4a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/usr/bin/env python
#
# Copyright 2005-2019 The Mumble Developers. All rights reserved.
# Use of this source code is governed by a BSD-style license
# that can be found in the LICENSE file at the root of the
# Mumble source tree or at <https://www.mumble.info/LICENSE>.
#
#
# extract-emojione-flags.py
# Extract SVG flags from the Emoji One emoji collection.
#
# This script walks the Emoji One SVG collection and extracts
# flag emojis.
#
# Emoji One's emojis all use the Unicode code points (base 16) as
# their on-disk names. If a character consists of multiple code points,
# they are separated by a dash ('-').
#
# This script walks all the Emoji One SVGs, and finds the ones which
# only contain symbols in the Regional Indicator Symbol range.
# These are flag emojis.
#
# The flags are then copied to the destination directory, and named
# as the region's lower case ISO_3166-1_alpha-2 code with the ".svg"
# extension.

from __future__ import (unicode_literals, print_function, division)

import os
import shutil
import sys

# Beginning and end of the Regional Indicator Symbol range,
# as defined by Unicode 6.0's emoji support.
#
# See https://en.wikipedia.org/wiki/Regional_Indicator_Symbol
# for more information.
REGIONAL_INDICATOR_SYMBOL_LETTER_A = 0x1F1E6
REGIONAL_INDICATOR_SYMBOL_LETTER_Z = 0x1F1FF

def is_region(points):
	for point in points:
		if point > REGIONAL_INDICATOR_SYMBOL_LETTER_Z \
		   or point < REGIONAL_INDICATOR_SYMBOL_LETTER_A:
			return False	
	return True

def region_name(points):
	name = ''
	for point in points:
		name += chr(point - REGIONAL_INDICATOR_SYMBOL_LETTER_A + ord('a'))
	return name

def main():
	if len(sys.argv) < 3:
		print('''Usage: extract-emojione-flags.py [emojione-svg-dir] [dst-dir]

emojione-svg-dir: point this to the directory containing Emoji One SVGs, such as
                  $EMOJIONE_SRC_TREE/assets/svg.

dst-dir: point this to the directory you want the resulting SVGs to be written to.

''')
		sys.exit(1)

	emojiOneSvgDir = sys.argv[1]
	dstDir = sys.argv[2]

	files = os.listdir(emojiOneSvgDir)
	for fn in files:
		base, ext = os.path.splitext(fn.lower())
		if not ext == '.svg':
			continue
		
		pointsStr = base.split('-')
		points = [int(p, 16) for p in pointsStr]
		
		if is_region(points):
			name = region_name(points)
			svgName = name + '.svg'
			shutil.copy(os.path.join(emojiOneSvgDir, fn),
			            os.path.join(dstDir, svgName))

if __name__ == '__main__':
	main()