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 <glib/gmem.h>
18
#include <libnr/nr-macros.h>
19
#include "nr-type-primitives.h"
22
* An entry in a list of key->value pairs
31
* Type Dictionary, consisting of size number of key-value entries
38
static NRTDEntry *nr_td_entry_new (void);
41
* Calls the destructor for each item in list
44
nr_name_list_release (NRNameList *list)
46
if (list->destructor) {
47
list->destructor (list);
52
nr_style_list_release (NRStyleList *list)
54
if (list->destructor) {
55
list->destructor (list);
60
* Creates a new typeface dictionary of size NR_DICTSIZE
61
* and initalizes all the entries to NULL
64
nr_type_dict_new (void)
69
td = g_new (NRTypeDict, 1);
71
td->size = NR_DICTSIZE;
72
td->entries = g_new (NRTDEntry *, td->size);
73
for (i = 0; i < NR_DICTSIZE; i++) {
74
td->entries[i] = NULL;
81
* Hashes a string and returns the int
84
nr_str_hash (const gchar *p)
91
for (p += 1; *p; p++) h = (h << 5) - h + *p;
98
* Inserts a key/value into a typeface dictionary
101
nr_type_dict_insert (NRTypeDict *td, const gchar *key, void *val)
107
hval = nr_str_hash (key) % td->size;
109
for (tde = td->entries[hval]; tde; tde = tde->next) {
110
if (!strcmp (key, tde->key)) {
116
tde = nr_td_entry_new ();
117
tde->next = td->entries[hval];
120
td->entries[hval] = tde;
125
* Looks up the given key from the typeface dictionary
128
nr_type_dict_lookup (NRTypeDict *td, const gchar *key)
133
hval = nr_str_hash (key) % td->size;
134
for (tde = td->entries[hval]; tde; tde = tde->next) {
135
if (!strcmp (key, tde->key)) return tde->val;
142
#define NR_TDE_BLOCK_SIZE 32
144
static NRTDEntry *nr_tde_free_list;
147
* Creates a new TDEntry
150
nr_td_entry_new (void)
154
if (!nr_tde_free_list) {
156
nr_tde_free_list = g_new (NRTDEntry, NR_TDE_BLOCK_SIZE);
157
for (i = 0; i < (NR_TDE_BLOCK_SIZE - 1); i++) {
158
nr_tde_free_list[i].next = nr_tde_free_list + i + 1;
160
nr_tde_free_list[i].next = NULL;
163
tde = nr_tde_free_list;
164
nr_tde_free_list = tde->next;