diff --git a/darwin/opentype.m b/darwin/opentype.m index 1a2f3ab1..890aa02a 100644 --- a/darwin/opentype.m +++ b/darwin/opentype.m @@ -51,7 +51,8 @@ void uiOpenTypeFeaturesRemove(uiOpenTypeFeatures *otf, char a, char b, char c, c [otf->tags removeObjectForKey:tn]; } -int uiOpenTypeFeaturesGet(uiOpenTypeFeatures *otf, char a, char b, char c, char d, uint32_t *value) +// TODO will the const wreck stuff up? +int uiOpenTypeFeaturesGet(const uiOpenTypeFeatures *otf, char a, char b, char c, char d, uint32_t *value) { NSNumber *tn, *vn; @@ -78,7 +79,7 @@ void uiOpenTypeFeaturesForEach(const uiOpenTypeFeatures *otf, uiOpenTypeFeatures b = (uint8_t) ((tag >> 16) & 0xFF); c = (uint8_t) ((tag >> 8) & 0xFF); d = (uint8_t) (tag & 0xFF); - ret = (*f)((char) a, (char) b, (char) c, (char) d, + ret = (*f)(otf, (char) a, (char) b, (char) c, (char) d, mapObjectValue(vn), data); // TODO for all: require exact match? if (ret == uiForEachStop) @@ -98,7 +99,7 @@ int uiOpenTypeFeaturesEqual(const uiOpenTypeFeatures *a, const uiOpenTypeFeature // TODO explain all this // TODO rename outerArray and innerDict (the names made sense when this was part of fontdescAppendFeatures(), but not here) // TODO make all this use enumerateKeysAndObjects (which requires duplicating code)? -static uiForEach otfArrayForEachAAT(char a, char b, char c, char d, uint32_t value, void *data) +static uiForEach otfArrayForEachAAT(const uiOpenTypeFeatures *otf, char a, char b, char c, char d, uint32_t value, void *data) { CFMutableArrayRef outerArray = (CFMutableArrayRef) data; @@ -133,7 +134,7 @@ static uiForEach otfArrayForEachAAT(char a, char b, char c, char d, uint32_t val } // TODO find out which fonts differ in AAT small caps and test them with this -static uiForEach otfArrayForEachOT(char a, char b, char c, char d, uint32_t value, void *data) +static uiForEach otfArrayForEachOT(const uiOpenTypeFeatures *otf, char a, char b, char c, char d, uint32_t value, void *data) { CFMutableArrayRef outerArray = (CFMutableArrayRef) data; CFDictionaryRef innerDict; diff --git a/ui.h b/ui.h index 1a875cab..039d45f4 100644 --- a/ui.h +++ b/ui.h @@ -4,6 +4,7 @@ // TODOs // - make getters that return whether something exists accept a NULL pointer to discard the value (and thus only return that the thing exists?) +// - const-correct everything #ifndef __LIBUI_UI_H__ #define __LIBUI_UI_H__ diff --git a/ui_attrstr.h b/ui_attrstr.h index 835cee39..430d65d0 100644 --- a/ui_attrstr.h +++ b/ui_attrstr.h @@ -104,8 +104,10 @@ _UI_ENUM(uiDrawUnderlineColor) { // TODO invalid features typedef struct uiOpenTypeFeatures uiOpenTypeFeatures; -// TODO pass the feature set? (resolve const struct issue below first) -typedef uiForEach (*uiOpenTypeFeaturesForEachFunc)(char a, char b, char c, char d, uint32_t value, void *data); +// uiOpenTypeFeaturesForEachFunc is the type of the function +// invoked by uiOpenTypeFeaturesForEach() for every OpenType +// feature in otf. +typedef uiForEach (*uiOpenTypeFeaturesForEachFunc)(const uiOpenTypeFeatures *otf, char a, char b, char c, char d, uint32_t value, void *data); // @role uiOpenTypeFeatures constructor // uiNewOpenTypeFeatures() returns a new uiOpenTypeFeatures @@ -143,12 +145,11 @@ _UI_EXTERN void uiOpenTypeFeaturesRemove(uiOpenTypeFeatures *otf, char a, char b // for a feature. You should likewise not treat a missing feature as // having a value of zero either. Instead, a missing feature should // be treated as having some unspecified default value. -// TODO const-correct this function (can we do that given the members of the struct on some platforms being full blown objects that may or may not themselves be const-correct?) -_UI_EXTERN int uiOpenTypeFeaturesGet(uiOpenTypeFeatures *otf, char a, char b, char c, char d, uint32_t *value); +_UI_EXTERN int uiOpenTypeFeaturesGet(const uiOpenTypeFeatures *otf, char a, char b, char c, char d, uint32_t *value); // uiOpenTypeFeaturesForEach() executes f for every tag-value -// pair in otf. The enumeration order is unspecified. -// TODO make other enumerators const (and in general const-correct everything) (but see the const struct TODO below and the const struct object member TODO above) +// pair in otf. The enumeration order is unspecified. You cannot +// modify otf while uiOpenTypeFeaturesForEach() is running. _UI_EXTERN void uiOpenTypeFeaturesForEach(const uiOpenTypeFeatures *otf, uiOpenTypeFeaturesForEachFunc f, void *data); // uiOpenTypeFeaturesEqual() returns nonzero if a is equal to b. diff --git a/unix/opentype.c b/unix/opentype.c index 764da50a..30933ea8 100644 --- a/unix/opentype.c +++ b/unix/opentype.c @@ -60,9 +60,8 @@ void uiOpenTypeFeaturesRemove(uiOpenTypeFeatures *otf, char a, char b, char c, c g_hash_table_remove(otf->tags, mkTag(a, b, c, d)); } -// TODO should this be before Add and Remove? -// TODO better name than Get? -int uiOpenTypeFeaturesGet(uiOpenTypeFeatures *otf, char a, char b, char c, char d, uint32_t *value) +// TODO will the const wreck stuff up? +int uiOpenTypeFeaturesGet(const uiOpenTypeFeatures *otf, char a, char b, char c, char d, uint32_t *value) { gboolean found; gpointer gv; @@ -77,6 +76,7 @@ int uiOpenTypeFeaturesGet(uiOpenTypeFeatures *otf, char a, char b, char c, char } struct otfForEach { + const uiOpenTypeFeatures *otf; uiOpenTypeFeaturesForEachFunc f; void *data; uiForEach ret; @@ -96,7 +96,7 @@ static void foreach(gpointer key, gpointer value, gpointer data) b = (uint8_t) ((tag >> 16) & 0xFF); c = (uint8_t) ((tag >> 8) & 0xFF); d = (uint8_t) (tag & 0xFF); - ofe->ret = (*(ofe->f))((char) a, (char) b, (char) c, (char) d, GPOINTER_TO_INT(value), ofe->data); + ofe->ret = (*(ofe->f))(ofe->otf, (char) a, (char) b, (char) c, (char) d, GPOINTER_TO_INT(value), ofe->data); } void uiOpenTypeFeaturesForEach(const uiOpenTypeFeatures *otf, uiOpenTypeFeaturesForEachFunc f, void *data) @@ -104,6 +104,7 @@ void uiOpenTypeFeaturesForEach(const uiOpenTypeFeatures *otf, uiOpenTypeFeatures struct otfForEach ofe; memset(&ofe, 0, sizeof (struct otfForEach)); + ofe.otf = otf; ofe.f = f; ofe.data = data; g_hash_table_foreach(otf->tags, foreach, &ofe); @@ -183,7 +184,7 @@ out: // see https://developer.mozilla.org/en/docs/Web/CSS/font-feature-settings // TODO make this a g_hash_table_foreach() function (which requires duplicating code)? -static uiForEach toCSS(char a, char b, char c, char d, uint32_t value, void *data) +static uiForEach toCSS(const uiOpenTypeFeatures *otf, char a, char b, char c, char d, uint32_t value, void *data) { // TODO is there a G_STRING()? GString *s = (GString *) data; diff --git a/windows/opentype.cpp b/windows/opentype.cpp index 8fc37175..235f0388 100644 --- a/windows/opentype.cpp +++ b/windows/opentype.cpp @@ -45,7 +45,8 @@ void uiOpenTypeFeaturesRemove(uiOpenTypeFeatures *otf, char a, char b, char c, c otf->tags->erase(mktag(a, b, c, d)); } -int uiOpenTypeFeaturesGet(uiOpenTypeFeatures *otf, char a, char b, char c, char d, uint32_t *value) +// TODO will the const wreck stuff up? +int uiOpenTypeFeaturesGet(const uiOpenTypeFeatures *otf, char a, char b, char c, char d, uint32_t *value) { tagmap::const_iterator iter; @@ -69,7 +70,7 @@ void uiOpenTypeFeaturesForEach(const uiOpenTypeFeatures *otf, uiOpenTypeFeatures b = (uint8_t) ((iter->first >> 8) & 0xFF); c = (uint8_t) ((iter->first >> 16) & 0xFF); d = (uint8_t) ((iter->first >> 24) & 0xFF); - ret = (*f)((char) a, (char) b, (char) c, (char) d, + ret = (*f)(otf, (char) a, (char) b, (char) c, (char) d, iter->second, data); if (ret == uiForEachStop) return;