| 1 |
#include "otfcc/handle.h" |
| 2 |
#include "element-impl.h" |
| 3 |
#include "support/otfcc-alloc.h" |
| 4 |
|
| 5 |
// default constructors |
| 6 |
static INLINE void initHandle(otfcc_Handle *h) { |
| 7 |
h->state = HANDLE_STATE_EMPTY; |
| 8 |
h->index = 0; |
| 9 |
h->name = NULL; |
| 10 |
} |
| 11 |
static INLINE void disposeHandle(struct otfcc_Handle *h) { |
| 12 |
if (h->name) { |
| 13 |
sdsfree(h->name); |
| 14 |
h->name = NULL; |
| 15 |
} |
| 16 |
h->index = 0; |
| 17 |
h->state = HANDLE_STATE_EMPTY; |
| 18 |
} |
| 19 |
static void copyHandle(otfcc_Handle *dst, const otfcc_Handle *src) { |
| 20 |
dst->state = src->state; |
| 21 |
dst->index = src->index; |
| 22 |
if (src->name) { |
| 23 |
dst->name = sdsdup(src->name); |
| 24 |
} else { |
| 25 |
dst->name = NULL; |
| 26 |
} |
| 27 |
} |
| 28 |
|
| 29 |
caryll_standardValTypeFn(otfcc_Handle, initHandle, copyHandle, disposeHandle); |
| 30 |
|
| 31 |
// custom constructors |
| 32 |
static struct otfcc_Handle handle_fromIndex(glyphid_t id) { |
| 33 |
struct otfcc_Handle h = {HANDLE_STATE_INDEX, id, NULL}; |
| 34 |
return h; |
| 35 |
} |
| 36 |
static struct otfcc_Handle handle_fromName(MOVE sds s) { |
| 37 |
struct otfcc_Handle h = {HANDLE_STATE_EMPTY, 0, NULL}; |
| 38 |
if (s) { |
| 39 |
h.state = HANDLE_STATE_NAME; |
| 40 |
h.name = s; |
| 41 |
} |
| 42 |
return h; |
| 43 |
} |
| 44 |
static struct otfcc_Handle handle_fromConsolidated(glyphid_t id, sds s) { |
| 45 |
struct otfcc_Handle h = {HANDLE_STATE_CONSOLIDATED, id, sdsdup(s)}; |
| 46 |
return h; |
| 47 |
} |
| 48 |
|
| 49 |
// consolidation |
| 50 |
static void handle_consolidateTo(struct otfcc_Handle *h, glyphid_t id, sds name) { |
| 51 |
otfcc_iHandle.dispose(h); |
| 52 |
h->state = HANDLE_STATE_CONSOLIDATED; |
| 53 |
h->index = id; |
| 54 |
h->name = sdsdup(name); |
| 55 |
} |
| 56 |
|
| 57 |
const struct otfcc_HandlePackage otfcc_iHandle = { |
| 58 |
caryll_standardValTypeMethods(otfcc_Handle), // VT |
| 59 |
.fromIndex = handle_fromIndex, // custom constructor, from index |
| 60 |
.fromName = handle_fromName, // custom constructor, from name |
| 61 |
.fromConsolidated = handle_fromConsolidated, // custom constructor, from consolidated |
| 62 |
.consolidateTo = handle_consolidateTo, |
| 63 |
}; |