2017-05-11 09:27:34 -05:00
|
|
|
// 11 may 2017
|
2017-05-19 13:12:04 -05:00
|
|
|
#import "uipriv_darwin.h"
|
2017-05-11 09:27:34 -05:00
|
|
|
|
|
|
|
struct uiOpenTypeFeatures {
|
2017-05-19 13:12:04 -05:00
|
|
|
NSMutableDictionary *tags;
|
2017-05-11 09:27:34 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
uiOpenTypeFeatures *uiNewOpenTypeFeatures(void)
|
|
|
|
{
|
|
|
|
uiOpenTypeFeatures *otf;
|
|
|
|
|
|
|
|
otf = uiNew(uiOpenTypeFeatures);
|
2017-05-19 13:12:04 -05:00
|
|
|
otf->tags = [NSMutableDictionary new];
|
2017-05-11 09:27:34 -05:00
|
|
|
return otf;
|
|
|
|
}
|
|
|
|
|
|
|
|
void uiFreeOpenTypeFeatures(uiOpenTypeFeatures *otf)
|
|
|
|
{
|
2017-05-19 13:12:04 -05:00
|
|
|
[otf->tags release];
|
2017-05-11 09:27:34 -05:00
|
|
|
uiFree(otf);
|
|
|
|
}
|
|
|
|
|
2017-05-30 08:52:38 -05:00
|
|
|
uiOpenTypeFeatures *uiOpenTypeFeaturesClone(const uiOpenTypeFeatures *otf)
|
2017-05-11 09:27:34 -05:00
|
|
|
{
|
|
|
|
uiOpenTypeFeatures *out;
|
|
|
|
|
|
|
|
out = uiNew(uiOpenTypeFeatures);
|
2017-05-19 13:12:04 -05:00
|
|
|
out->tags = [otf->tags mutableCopy];
|
2017-05-11 09:27:34 -05:00
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
2017-05-19 13:12:04 -05:00
|
|
|
// why are there no NSNumber methods for stdint.h or the equivalent core foundation types?...
|
|
|
|
#define mkMapObject(tag) [NSNumber numberWithUnsignedLongLong:((unsigned long long) tag)]
|
|
|
|
#define mapObjectValue(num) ((uint32_t) [num unsignedLongLongValue])
|
|
|
|
|
2017-05-11 09:27:34 -05:00
|
|
|
void uiOpenTypeFeaturesAdd(uiOpenTypeFeatures *otf, char a, char b, char c, char d, uint32_t value)
|
|
|
|
{
|
2017-05-19 13:12:04 -05:00
|
|
|
NSNumber *tn, *vn;
|
|
|
|
|
|
|
|
tn = mkMapObject(mkTag(a, b, c, d));
|
|
|
|
vn = mkMapObject(value);
|
|
|
|
[otf->tags setObject:vn forKey:tn];
|
2017-05-11 09:27:34 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void uiOpenTypeFeaturesRemove(uiOpenTypeFeatures *otf, char a, char b, char c, char d)
|
|
|
|
{
|
2017-05-19 13:12:04 -05:00
|
|
|
NSNumber *tn;
|
|
|
|
|
|
|
|
tn = mkMapObject(mkTag(a, b, c, d));
|
|
|
|
[otf->tags removeObjectForKey:tn];
|
2017-05-11 09:27:34 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
int uiOpenTypeFeaturesGet(uiOpenTypeFeatures *otf, char a, char b, char c, char d, uint32_t *value)
|
|
|
|
{
|
2017-05-19 13:12:04 -05:00
|
|
|
NSNumber *tn, *vn;
|
|
|
|
|
|
|
|
tn = mkMapObject(mkTag(a, b, c, d));
|
|
|
|
vn = (NSNumber *) [otf->tags objectForKey:tn];
|
|
|
|
if (vn == nil)
|
|
|
|
return 0;
|
|
|
|
*value = mapObjectValue(vn);
|
|
|
|
// TODO release vn?
|
|
|
|
return 1;
|
2017-05-11 09:27:34 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void uiOpenTypeFeaturesForEach(uiOpenTypeFeatures *otf, uiOpenTypeFeaturesForEachFunc f, void *data)
|
|
|
|
{
|
2017-05-19 13:12:04 -05:00
|
|
|
[otf->tags enumerateKeysAndObjectsUsingBlock:^(id key, id value, BOOL *stop) {
|
|
|
|
NSNumber *tn = (NSNumber *) key;
|
|
|
|
NSNumber *vn = (NSNumber *) value;
|
|
|
|
uint32_t tag;
|
|
|
|
uint8_t a, b, c, d;
|
|
|
|
|
|
|
|
tag = mapObjectValue(tn);
|
|
|
|
a = (uint8_t) ((tag >> 24) & 0xFF);
|
|
|
|
b = (uint8_t) ((tag >> 16) & 0xFF);
|
|
|
|
c = (uint8_t) ((tag >> 8) & 0xFF);
|
|
|
|
d = (uint8_t) (tag & 0xFF);
|
|
|
|
// TODO handle return value
|
|
|
|
(*f)((char) a, (char) b, (char) c, (char) d,
|
|
|
|
mapObjectValue(vn), data);
|
|
|
|
}];
|
2017-05-11 09:27:34 -05:00
|
|
|
}
|
|
|
|
|
2017-05-30 08:52:38 -05:00
|
|
|
int uiOpenTypeFeaturesEqual(const uiOpenTypeFeatures *a, const uiOpenTypeFeatures *b)
|
2017-05-11 09:27:34 -05:00
|
|
|
{
|
2017-05-19 13:12:04 -05:00
|
|
|
return [a->tags isEqualToDictionary:b->tags];
|
2017-05-11 09:27:34 -05:00
|
|
|
}
|
|
|
|
|
2017-05-19 13:12:04 -05:00
|
|
|
// actual conversion to a feature dictionary is handled in aat.m; see there for details
|