Made a decision on const correctness in uiOpenTypeFeatures.
This commit is contained in:
parent
e6ee2b0dbd
commit
3e20e4670c
|
@ -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;
|
||||
|
|
1
ui.h
1
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__
|
||||
|
|
13
ui_attrstr.h
13
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.
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue