Last active
June 4, 2020 05:45
-
-
Save fecf/286d823a8cae58505df0bdf1c65a0966 to your computer and use it in GitHub Desktop.
convert remixicon .css to c++ header
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import re | |
css = os.path.abspath(os.path.join(os.path.dirname(__file__), 'remixicon.css')) | |
f = open(css, "r") | |
found = False | |
defines = [] | |
smin = "" | |
smax = "" | |
for line in f: | |
if not line.startswith('.'): | |
continue | |
m1 = re.match('.ri-(.*):before', line) | |
m2 = re.match('.*content: "\\\\(.*)"', line) | |
if m1 and m2: | |
s1 = "ICON_REMIX_" + m1.group(1).upper().replace("-", "_") | |
s2 = m2.group(1).upper() | |
s = "#define " + s1 + " u8\"\\u" + s2 + "\"" | |
if not found: | |
found = True | |
smin = s2 | |
defines.append(s) | |
smax = s2 | |
header = os.path.abspath(os.path.join(os.path.dirname(__file__), 'remixicon.h')) | |
fw = open(header, "w") | |
fw.write("#ifndef RESOURCE_REMIXICON_H_" + "\n") | |
fw.write("#define RESOURCE_REMIXICON_H_" + "\n\n") | |
fw.write("#define ICON_REMIX_RANGE_MIN 0x" + smin + "\n") | |
fw.write("#define ICON_REMIX_RANGE_MAX 0x" + smax + "\n\n") | |
for s in defines: | |
fw.write(s + "\n") | |
fw.write("\n#endif" + "\n") | |
fw.close() | |
f.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment