1
#define __NR_TYPE_PRIMITIVES_C__
4
* Typeface and script library
7
* Lauris Kaplinski <lauris@kaplinski.com>
9
* This code is in public domain
12
/* This should be enough for approximately 10000 fonts */
13
#define NR_DICTSIZE 2777
17
#include <libnr/nr-macros.h>
18
#include "nr-type-primitives.h"
21
* An entry in a list of key->value pairs
30
* Type Dictionary, consisting of size number of key-value entries
37
static NRTDEntry *nr_td_entry_new (void);
40
* Calls the destructor for each item in list
43
nr_name_list_release (NRNameList *list)
45
if (list->destructor) {
46
list->destructor (list);
51
nr_style_list_release (NRStyleList *list)
53
if (list->destructor) {
54
list->destructor (list);
59
* Creates a new typeface dictionary of size NR_DICTSIZE
60
* and initalizes all the entries to NULL
63
nr_type_dict_new (void)
68
td = nr_new (NRTypeDict, 1);
70
td->size = NR_DICTSIZE;
71
td->entries = nr_new (NRTDEntry *, td->size);
72
for (i = 0; i < NR_DICTSIZE; i++) {
73
td->entries[i] = NULL;
80
* Hashes a string and returns the int
83
nr_str_hash (const gchar *p)
90
for (p += 1; *p; p++) h = (h << 5) - h + *p;
97
* Inserts a key/value into a typeface dictionary
100
nr_type_dict_insert (NRTypeDict *td, const gchar *key, void *val)
106
hval = nr_str_hash (key) % td->size;
108
for (tde = td->entries[hval]; tde; tde = tde->next) {
109
if (!strcmp (key, tde->key)) {
115
tde = nr_td_entry_new ();
116
tde->next = td->entries[hval];
119
td->entries[hval] = tde;
124
* Looks up the given key from the typeface dictionary
127
nr_type_dict_lookup (NRTypeDict *td, const gchar *key)
132
hval = nr_str_hash (key) % td->size;
133
for (tde = td->entries[hval]; tde; tde = tde->next) {
134
if (!strcmp (key, tde->key)) return tde->val;
141
#define NR_TDE_BLOCK_SIZE 32
143
static NRTDEntry *nr_tde_free_list;
146
* Creates a new TDEntry
149
nr_td_entry_new (void)
153
if (!nr_tde_free_list) {
155
nr_tde_free_list = nr_new (NRTDEntry, NR_TDE_BLOCK_SIZE);
156
for (i = 0; i < (NR_TDE_BLOCK_SIZE - 1); i++) {
157
nr_tde_free_list[i].next = nr_tde_free_list + i + 1;
159
nr_tde_free_list[i].next = NULL;
162
tde = nr_tde_free_list;
163
nr_tde_free_list = tde->next;