Works. But is heavy...
This commit is contained in:
parent
87d5d3d9d6
commit
bd5c75737c
|
@ -43,4 +43,7 @@ typedef struct fc_locale_s {
|
|||
/* pointer to the entry */
|
||||
extern const fc_locale_t fc_locales[];
|
||||
|
||||
/* get an entry */
|
||||
const fc_char_t *fc_get_char(FONTCHARACTER opcode);
|
||||
|
||||
#endif /* LIBFONTCHARACTER_INTERNALS_H */
|
||||
|
|
|
@ -23,8 +23,6 @@
|
|||
* fc_tomulti:
|
||||
* Get the complete multi-character content behind a content.
|
||||
*
|
||||
* TODO: single common function to get a character's entry?
|
||||
*
|
||||
* @arg dest the destination buffer (at least FC_MULTI_MAX bytes).
|
||||
* @arg opcode the FONTCHARACTER opcode.
|
||||
* @return the number of characters in the opcode.
|
||||
|
@ -32,13 +30,10 @@
|
|||
|
||||
int fc_tomulti(FONTCHARACTER *dest, FONTCHARACTER opcode)
|
||||
{
|
||||
const fc_table_t * const table = &fc_tables[opcode >> 8];
|
||||
if (!table->chars) return (-1);
|
||||
|
||||
const fc_char_t * const character = &table->chars[opcode & 0xFF];
|
||||
if (!character->multi) return (-1);
|
||||
|
||||
memcpy(dest, character->multi,
|
||||
character->multisize * sizeof(FONTCHARACTER));
|
||||
return ((int)character->multisize);
|
||||
const fc_char_t *chr = fc_get_char(opcode);
|
||||
if (!chr || !chr->multi)
|
||||
return (-1);
|
||||
memcpy(dest, chr->multi,
|
||||
chr->multisize * sizeof(FONTCHARACTER));
|
||||
return ((int)chr->multisize);
|
||||
}
|
||||
|
|
|
@ -23,23 +23,18 @@
|
|||
* to_unicode:
|
||||
* Get the unicode thing of a character.
|
||||
*
|
||||
* TODO: single common function to get a character's entry?
|
||||
*
|
||||
* @arg dest the destination buffer (at least FC_UNI_MAX bytes).
|
||||
* @arg wc the FONTCHARACTER character.
|
||||
* @arg opcode the FONTCHARACTER character.
|
||||
* @return the number of unicode characters in the opcode.
|
||||
*/
|
||||
|
||||
static int to_unicode(wchar_t *dest, FONTCHARACTER wc)
|
||||
static int to_unicode(wchar_t *dest, FONTCHARACTER opcode)
|
||||
{
|
||||
const fc_table_t * const table = &fc_tables[wc >> 8];
|
||||
if (!table->chars) return (-1);
|
||||
|
||||
const fc_char_t * const character = &table->chars[wc & 0xFF];
|
||||
if (!character->uni) return (-1);
|
||||
|
||||
memcpy(dest, character->uni, character->unisize * sizeof(wchar_t));
|
||||
return ((int)character->unisize);
|
||||
const fc_char_t *chr;
|
||||
if (!(chr = fc_get_char(opcode)) || !chr->uni)
|
||||
return (-1);
|
||||
memcpy(dest, chr->uni, chr->unisize * sizeof(wchar_t));
|
||||
return ((int)chr->unisize);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
/* *****************************************************************************
|
||||
* utils/getchar.c -- get a FONTCHARACTER character entry.
|
||||
* Copyright (C) 2017 Thomas "Cakeisalie5" Touhey
|
||||
*
|
||||
* This file is part of libfontcharacter.
|
||||
* libfontcharacter is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation; either version 3.0 of the License,
|
||||
* or (at your option) any later version.
|
||||
*
|
||||
* libfontcharacter is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
* See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with libfontcharacter; if not, see <http://www.gnu.org/licenses/>.
|
||||
* ************************************************************************** */
|
||||
#include <libfontcharacter/internals.h>
|
||||
|
||||
/**
|
||||
* fc_get_char:
|
||||
* Get a FONTCHARACTER entry.
|
||||
*
|
||||
* @arg opcode the opcode
|
||||
* @return the entry address
|
||||
*/
|
||||
|
||||
const fc_char_t *fc_get_char(FONTCHARACTER opcode)
|
||||
{
|
||||
const fc_locale_t *locale = &fc_locales[0];
|
||||
const fc_char_t **chars = locale->chars[opcode >> 8];
|
||||
if (!chars) return (NULL);
|
||||
|
||||
const fc_char_t *chr = chars[opcode & 0xFF];
|
||||
return (chr);
|
||||
}
|
|
@ -35,13 +35,22 @@ def getcorrect(s):
|
|||
# Beginning
|
||||
print('#include <libfontcharacter/internals.h>\n')
|
||||
|
||||
# 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('')
|
||||
# Characters
|
||||
putsep('Make characters')
|
||||
for id, st in map(lambda x:(x,ref.get(x)), ref.list()):
|
||||
correct = getcorrect(id)
|
||||
for code, char in st['characters'].items():
|
||||
if char['_pr'] > 0: continue
|
||||
if not char.get('multi'): f = [code]
|
||||
else: f = char['multi']
|
||||
if char.get('unicode'): u = char['unicode']
|
||||
else: u = None
|
||||
|
||||
print('static fc_char_t chars_%s_%04X = {'%(correct, code))
|
||||
if u: print('\t.uni = (wchar_t[]){%s},'%getchars(u, 4))
|
||||
if u: print('\t.unisize = %d,'%len(u))
|
||||
if 1: print('\t.multi = (FONTCHARACTER[]){%s},'%getchars(f, 2))
|
||||
if 1: print('\t.multisize = %d};'%len(f))
|
||||
|
||||
# Character tables
|
||||
for id, st in map(lambda x:(x,ref.get(x)), ref.list()):
|
||||
|
@ -59,36 +68,23 @@ for id, st in map(lambda x:(x,ref.get(x)), ref.list()):
|
|||
# Make the tables
|
||||
for lead, lchars in chars.items():
|
||||
print('/* 0x%02Xxx for %s */'%(lead, id))
|
||||
print('static fc_char_t const * const chars_%s_%02X[256] = {' \
|
||||
print('static fc_char_t *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('\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}},')
|
||||
cr = correct if char.get('_pr') == 0 \
|
||||
else getcorrect(char['inherit'])
|
||||
print('\t[0x%02X] = &chars_%s_%02X%02X,'%(code, cr, lead, code))
|
||||
print('};\n')
|
||||
|
||||
# Make the main table
|
||||
print('/* Main table for %s */'%id)
|
||||
print('static fc_char_t const * const * const chars_%s[256] = {'%correct)
|
||||
print('static fc_char_t **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[] = {')
|
||||
print('const fc_locale_t fc_locales[] = {')
|
||||
for id, st in map(lambda x:(x,ref.get(x)), ref.list()):
|
||||
correct = getcorrect(id)
|
||||
print('\t{"%s", chars_%s},'%(id, correct))
|
||||
|
|
Reference in New Issue