From 72f5b680f23e8dde26e0795af868f53fda2a1d2d Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Fri, 19 May 2017 14:12:04 -0400 Subject: [PATCH] Filled in darwin/opentype.m. --- darwin/CMakeLists.txt | 1 + darwin/opentype.m | 58 ++++++++++++++++++++++++++++++++++++++----- 2 files changed, 53 insertions(+), 6 deletions(-) diff --git a/darwin/CMakeLists.txt b/darwin/CMakeLists.txt index 96db9c09..e260f266 100644 --- a/darwin/CMakeLists.txt +++ b/darwin/CMakeLists.txt @@ -31,6 +31,7 @@ list(APPEND _LIBUI_SOURCES darwin/map.m darwin/menu.m darwin/multilineentry.m + darwin/opentype.m darwin/progressbar.m darwin/radiobuttons.m darwin/scrollview.m diff --git a/darwin/opentype.m b/darwin/opentype.m index 4273b80f..c8158356 100644 --- a/darwin/opentype.m +++ b/darwin/opentype.m @@ -1,8 +1,8 @@ // 11 may 2017 -#include "uipriv_windows.hpp" +#import "uipriv_darwin.h" struct uiOpenTypeFeatures { - xxxx; + NSMutableDictionary *tags; }; uiOpenTypeFeatures *uiNewOpenTypeFeatures(void) @@ -10,13 +10,13 @@ uiOpenTypeFeatures *uiNewOpenTypeFeatures(void) uiOpenTypeFeatures *otf; otf = uiNew(uiOpenTypeFeatures); - xxxx; + otf->tags = [NSMutableDictionary new]; return otf; } void uiFreeOpenTypeFeatures(uiOpenTypeFeatures *otf) { - xxxxxx; + [otf->tags release]; uiFree(otf); } @@ -25,28 +25,74 @@ uiOpenTypeFeatures *uiOpenTypeFeaturesClone(uiOpenTypeFeatures *otf) uiOpenTypeFeatures *out; out = uiNew(uiOpenTypeFeatures); - xxxxxx; + out->tags = [otf->tags mutableCopy]; return out; } +// TODO provide to aat.m too; remove x8tox32() when doing so +#define x8to32(x) ((uint32_t) (((uint8_t) (x)) & 0xFF)) +#define mkTag(a, b, c, d) \ + ((x8tox32(a) << 24) | \ + (x8tox32(b) << 16) | \ + (x8tox32(c) << 8) | \ + x8tox32(d)) + +// 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]) + void uiOpenTypeFeaturesAdd(uiOpenTypeFeatures *otf, char a, char b, char c, char d, uint32_t value) { + NSNumber *tn, *vn; + + tn = mkMapObject(mkTag(a, b, c, d)); + vn = mkMapObject(value); + [otf->tags setObject:vn forKey:tn]; } void uiOpenTypeFeaturesRemove(uiOpenTypeFeatures *otf, char a, char b, char c, char d) { + NSNumber *tn; + + tn = mkMapObject(mkTag(a, b, c, d)); + [otf->tags removeObjectForKey:tn]; } int uiOpenTypeFeaturesGet(uiOpenTypeFeatures *otf, char a, char b, char c, char d, uint32_t *value) { + 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; } void uiOpenTypeFeaturesForEach(uiOpenTypeFeatures *otf, uiOpenTypeFeaturesForEachFunc f, void *data) { + [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); + }]; } int uiOpenTypeFeaturesEqual(uiOpenTypeFeatures *a, uiOpenTypeFeatures *b) { + return [a->tags isEqualToDictionary:b->tags]; } -// TODO put the internal function to produce a backend object from one here +// actual conversion to a feature dictionary is handled in aat.m; see there for details