I'm there for now.
This commit is contained in:
parent
c27726a6e7
commit
87d5d3d9d6
14
Makefile
14
Makefile
|
@ -51,8 +51,12 @@ dist: mrproper
|
|||
--exclude .git lib$(NAME)-$(VERSION))
|
||||
$(call qcmd,$(RM) -r lib$(NAME)-$(VERSION))
|
||||
|
||||
# Count number of lines of code
|
||||
count:
|
||||
@cloc . $(shell [ -e .git ] && echo '--vcs=git')
|
||||
|
||||
.PHONY: all mostlyclean mclean clean fclean mrproper re
|
||||
.PHONY: dist install uninstall reinstall
|
||||
.PHONY: dist install uninstall reinstall count
|
||||
#******************************************************************************#
|
||||
# Configuration (version) checking dependencies #
|
||||
#******************************************************************************#
|
||||
|
@ -96,11 +100,11 @@ dist: mrproper
|
|||
|
||||
# Make the characters files
|
||||
$(INCDIR)/lib$(NAME)/characters.h: $(wildcard ./reference/*.yml) \
|
||||
tools/write-characters-header
|
||||
$(call bcmd,gen,$@,tools/write-characters-header --ref ./reference >$@)
|
||||
tools/fontcharacter.py tools/write-characters-header
|
||||
$(call bcmd,gen,$@,tools/write-characters-header ./reference >$@)
|
||||
$(SRCDIR)/characters.c: $(wildcard ./reference/*.yml) \
|
||||
tools/write-characters-source
|
||||
$(call bcmd,gen,$@,tools/write-characters-source --ref ./reference >$@)
|
||||
tools/fontcharacter.py tools/write-characters-source
|
||||
$(call bcmd,gen,$@,tools/write-characters-source ./reference >$@)
|
||||
|
||||
# Make a module object directory.
|
||||
$(OBJDIR)/ $(DIRS:%=$(OBJDIR)/%):
|
||||
|
|
|
@ -35,13 +35,12 @@ typedef struct {
|
|||
} fc_char_t;
|
||||
|
||||
/* set */
|
||||
typedef struct {
|
||||
typedef struct fc_locale_s {
|
||||
const char *name;
|
||||
fc_table_t *table;
|
||||
fc_char_t **chars;
|
||||
} fc_set_t;
|
||||
fc_char_t ***chars;
|
||||
} fc_locale_t;
|
||||
|
||||
/* pointer to the entry */
|
||||
extern const fc_set_t fc_sets[];
|
||||
extern const fc_locale_t fc_locales[];
|
||||
|
||||
#endif /* LIBFONTCHARACTER_INTERNALS_H */
|
||||
|
|
|
@ -21,6 +21,13 @@ class Reference:
|
|||
self.__load_characters(yaml.load(open(\
|
||||
os.path.join(path, 'characters.yml')).read()))
|
||||
|
||||
# Gather leaders [TODO: `leading` field?]
|
||||
for st in self.sets.keys():
|
||||
lead = []
|
||||
for code in self.sets[st]['characters'].keys():
|
||||
lead += [code >> 8]
|
||||
self.sets[st]['leading'] = set(lead)
|
||||
|
||||
# Utility to explore a category
|
||||
def __explore_category(self, c, id, prefix, suffix):
|
||||
# Iterate on things
|
||||
|
@ -56,12 +63,23 @@ class Reference:
|
|||
if s.get('default'): self.default_set = s['id']
|
||||
if s.get('parent'):
|
||||
if not kids.get(s['parent']): kids[s['parent']] = []
|
||||
kids[s['parent']] += s['id']
|
||||
kids[s['parent']] += [s['id']]
|
||||
|
||||
# Add kids to real elements
|
||||
for parent, k in kids.items():
|
||||
self.sets[parent]['kids'] += kids[parent]
|
||||
|
||||
# Inherit character
|
||||
def __inherit_character(self, id, code, inherit, pr):
|
||||
'''id: id of the set, code: code of the character,
|
||||
inherit: the set to inherit it from,
|
||||
pr: priority (starting from 0, the more it is, the further it is)'''
|
||||
if not self.sets[id]['characters'].get(code) \
|
||||
or self.sets[id]['characters'][code]['_pr'] > pr:
|
||||
self.sets[id]['characters'][code] = {'inherit': inherit, '_pr': pr}
|
||||
for k in self.sets[id]['kids']:
|
||||
self.__inherit_character(k, code, inherit, pr + 1)
|
||||
|
||||
# Utility to load characters
|
||||
def __load_characters(self, raw):
|
||||
# Main loop
|
||||
|
@ -78,7 +96,7 @@ class Reference:
|
|||
|
||||
# Make the character
|
||||
code = c['code']
|
||||
char = {'name': n}
|
||||
char = {'name': n, '_pr': 0}
|
||||
|
||||
# Check the multi thingy
|
||||
m = c.get('multi')
|
||||
|
@ -102,12 +120,8 @@ class Reference:
|
|||
|
||||
# Add it to the set
|
||||
self.sets[st]['characters'][code] = char
|
||||
|
||||
# Remove the private thingies
|
||||
for _, s in self.sets.items():
|
||||
for _, c in s['characters'].items():
|
||||
try: del c['_pr']
|
||||
except: True
|
||||
for k in self.sets[st]['kids']:
|
||||
self.__inherit_character(k, code, st, 1)
|
||||
|
||||
# Get the list of sets
|
||||
def list(self):
|
||||
|
|
|
@ -5,10 +5,7 @@
|
|||
from argparse import ArgumentParser
|
||||
ap = ArgumentParser(description='libfontcharacter characters headers maker')
|
||||
|
||||
ap.add_argument('--ref', dest='refpath', required=True,
|
||||
help='Reference path')
|
||||
ap.add_argument('--set', dest='set', default=None,
|
||||
help='The set to use')
|
||||
ap.add_argument('refpath', help='Reference path')
|
||||
args = ap.parse_args()
|
||||
#******************************************************************************#
|
||||
# Import the characters #
|
||||
|
@ -17,21 +14,25 @@ from fontcharacter import Reference
|
|||
ref = Reference(args.refpath)
|
||||
|
||||
# Get the set
|
||||
st = ref.get(args.set)
|
||||
|
||||
# Get the maximum multi size
|
||||
defs = {}
|
||||
maxmulsize = 0
|
||||
for _, char in st['characters'].items():
|
||||
if not char.get('multi'): continue
|
||||
lm = len(char['multi'])
|
||||
if lm > maxmulsize: maxmulsize = lm
|
||||
|
||||
# Get the maximum unicode size
|
||||
maxunisize = 0
|
||||
for _, char in st['characters'].items():
|
||||
if not char.get('unicode'): continue
|
||||
lu = len(char['unicode'])
|
||||
if lu > maxunisize: maxunisize = lu
|
||||
maxsize = 0
|
||||
for _, st in map(lambda x:(x,ref.get(x)), ref.list()):
|
||||
for code, char in st['characters'].items():
|
||||
if char['_pr'] > 0: continue
|
||||
defs[char['id']] = code
|
||||
maxsize = max(maxsize, len(char['id']))
|
||||
if char.get('multi'):
|
||||
lm = len(char['multi'])
|
||||
if lm > maxmulsize: maxmulsize = lm
|
||||
if char.get('unicode'):
|
||||
lu = len(char['unicode'])
|
||||
if lu > maxunisize: maxunisize = lu
|
||||
|
||||
# Prepare the characters
|
||||
chars = list(defs.items())
|
||||
chars.sort(key=lambda x:x[1])
|
||||
|
||||
#******************************************************************************#
|
||||
# Make the header #
|
||||
|
@ -61,18 +62,22 @@ print('''\
|
|||
* ************************************************************************** */
|
||||
#ifndef LIBFONTCHARACTER_CHARACTERS_H
|
||||
# define LIBFONTCHARACTER_CHARACTERS_H
|
||||
# define FC_MAX_MULTI %d
|
||||
# define FC_MAX_UNI %d
|
||||
# if 0
|
||||
# define FC_MAX_MULTI %2d
|
||||
# define FC_MAX_UNI %2d
|
||||
'''%(maxmulsize, maxunisize))
|
||||
|
||||
# Characters
|
||||
for code, char in st['characters'].items():
|
||||
print('# define fc_%s 0x%04X'%(char['id'], code))
|
||||
print('/* Codes */')
|
||||
for name, code in chars:
|
||||
print('# define fc_%-*s %10s'%(maxsize + 1, name, '0x%04X'%code))
|
||||
|
||||
print('\n/* Strings */')
|
||||
for name, code in chars:
|
||||
hxs = "\\x%02X" % (code & 0xFF)
|
||||
if code >= 256: hxs = "\\x%02X" % (code >> 8) + hxs
|
||||
print('# define fcs_%-*s %10s'%(maxsize, name, '"%s"'%hxs))
|
||||
|
||||
# End
|
||||
print('''
|
||||
# endif
|
||||
#endif /* LIBFONTCHARACTER_CHARACTERS_H */''')
|
||||
|
||||
# End of file.
|
||||
|
|
|
@ -5,53 +5,93 @@
|
|||
from argparse import ArgumentParser
|
||||
ap = ArgumentParser(description='libfontcharacter characters headers maker')
|
||||
|
||||
ap.add_argument('--ref', dest='refpath', required=True,
|
||||
help='Reference path')
|
||||
ap.add_argument('refpath', help='Reference path')
|
||||
args = ap.parse_args()
|
||||
#******************************************************************************#
|
||||
# Import the characters #
|
||||
#******************************************************************************#
|
||||
from fontcharacter import Reference
|
||||
import string
|
||||
ref = Reference(args.refpath)
|
||||
|
||||
# Print some characters
|
||||
def getchars(chars, size):
|
||||
return ', '.join(map(lambda x:'0x%0*X'%(size * 2, x), chars))
|
||||
|
||||
# Print a separator
|
||||
def putsep(s):
|
||||
print('/* ' + '*'*74 + ' */')
|
||||
print('/* %-72.72s */'%s)
|
||||
print('/* ' + '*'*74 + ' */')
|
||||
|
||||
# Get 'correct' name
|
||||
def getcorrect(s):
|
||||
return ''.join(filter(lambda x:x in \
|
||||
string.ascii_letters + string.digits, s))
|
||||
|
||||
#******************************************************************************#
|
||||
# Make the source #
|
||||
#******************************************************************************#
|
||||
# Beginning
|
||||
print('''#include <libfontcharacter/internals.h>
|
||||
print('#include <libfontcharacter/internals.h>\n')
|
||||
|
||||
const fc_set_t fc_sets[] = {''')
|
||||
# Prototypes
|
||||
putsep('Prototype character tables')
|
||||
for id, leads in map(lambda x: (x, ref.get(x)['leading']), ref.list()):
|
||||
for lead in leads:
|
||||
print('extern static fc_char_t const * const chars_%s_%02X[];' \
|
||||
%(getcorrect(id), lead))
|
||||
print('')
|
||||
|
||||
# Character tables
|
||||
for id, st in map(lambda x:(x,ref.get(x)), ref.list()):
|
||||
print(' {"%s", (*fc_char_t[256]){'%id)
|
||||
# Get the leading thingies [TODO: get that from the 'leading' field?]
|
||||
putsep('%s character tables'%id)
|
||||
|
||||
# Get the 'correct' name
|
||||
correct = getcorrect(id)
|
||||
|
||||
# Get the organized chars
|
||||
chars = {}
|
||||
for code, char in st['characters'].items():
|
||||
if not chars.get(code >> 8): chars[code >> 8] = {}
|
||||
chars[code >> 8][code & 0xFF] = char
|
||||
|
||||
# Make the tables
|
||||
for lead, lchars in chars.items():
|
||||
print(' [0x%02X] = (fc_char_t[256]){'%lead)
|
||||
print('/* 0x%02Xxx for %s */'%(lead, id))
|
||||
print('static fc_char_t const * const chars_%s_%02X[256] = {' \
|
||||
%(correct, lead))
|
||||
for code, char in lchars.items():
|
||||
if char.get('_pr') > 0:
|
||||
print('\t[0x%02X] = chars_%s_%02X[0x%02X],' \
|
||||
%(code, getcorrect(char['inherit']), lead, code))
|
||||
continue
|
||||
|
||||
if not char.get('multi'): f = [(lead << 8) | code]
|
||||
else: f = char['multi']
|
||||
if char.get('unicode'): u = char['unicode']
|
||||
else: u = None
|
||||
|
||||
print(' [0x%02X] = {'%code)
|
||||
print(' .multi = (FONTCHARACTER[]){%s},'%getchars(f, 2))
|
||||
if u: print(' .uni = (wchar_t[]){%s},'%getchars(u, 4))
|
||||
print(' .multisize = %d,'%len(f))
|
||||
if u: print(' .unisize = %d,'%len(u))
|
||||
print(' },')
|
||||
print(' },')
|
||||
print(' }},')
|
||||
print('\t[0x%02X] = (const fc_char_t[]){{'%code)
|
||||
if 1: print('\t\t.multi = (FONTCHARACTER[]){%s},'%getchars(f, 2))
|
||||
if 1: print('\t\t.multisize = %d,'%len(f))
|
||||
if u: print('\t\t.uni = (wchar_t[]){%s},'%getchars(u, 4))
|
||||
if u: print('\t\t.unisize = %d,'%len(u))
|
||||
print('\t}},')
|
||||
print('};\n')
|
||||
|
||||
print(' {NULL},')
|
||||
print('};')
|
||||
# Make the main table
|
||||
print('/* Main table for %s */'%id)
|
||||
print('static fc_char_t const * const * const chars_%s[256] = {'%correct)
|
||||
for lead in chars.keys():
|
||||
print('\t[0x%02X] = chars_%s_%02X,'%(lead, correct, lead))
|
||||
print('};\n')
|
||||
|
||||
putsep('All sets')
|
||||
print('fc_locale_t sets[] = {')
|
||||
for id, st in map(lambda x:(x,ref.get(x)), ref.list()):
|
||||
correct = getcorrect(id)
|
||||
print('\t{"%s", chars_%s},'%(id, correct))
|
||||
print('\t{NULL, NULL}\n};')
|
||||
|
||||
# End of file.
|
||||
|
|
|
@ -61,8 +61,8 @@ cat <<_EOF
|
|||
# define LIBFONTCHARACTER_MINOR ${version_minor}
|
||||
# define LIBFONTCHARACTER_REV ${version_rev}
|
||||
# define LIBFONTCHARACTER_INDEV ${version_indev}
|
||||
# define LIBFONTCHARACTER_MAINTAINER \
|
||||
"${maintainer}"
|
||||
# define LIBFONTCHARACTER_MAINTAINER \\
|
||||
"${maintainer}"
|
||||
|
||||
#endif /* LIBFONTCHARACTER_CONFIG_H */
|
||||
_EOF
|
||||
|
|
Reference in New Issue