Handled uiOpenTypeFeatures NULL equality. This only added more TODOs elsewhere :|

This commit is contained in:
Pietro Gagliardi 2017-06-09 19:59:48 -04:00
parent b73721905f
commit d63a5b23b1
7 changed files with 18 additions and 13 deletions

View File

@ -113,13 +113,7 @@ struct foreachParams {
return NO;
if (self.stretch != b.stretch)
return NO;
// TODO make this part of uiOpenTypeFeaturesEqual() on all platforms
if (self.features == NULL && b.features == NULL)
return YES;
if (self.features != NULL && b.features == NULL)
return NO;
if (self.features == NULL && b.features != NULL)
return NO;
// this also handles NULL cases
if (!uiOpenTypeFeaturesEqual(self.features, b.features))
return NO;
return YES;

View File

@ -87,6 +87,10 @@ void uiOpenTypeFeaturesForEach(const uiOpenTypeFeatures *otf, uiOpenTypeFeatures
int uiOpenTypeFeaturesEqual(const uiOpenTypeFeatures *a, const uiOpenTypeFeatures *b)
{
if (a == NULL && b == NULL)
return 1;
if (a == NULL || b == NULL)
return 0;
return [a->tags isEqualToDictionary:b->tags];
}

View File

@ -142,11 +142,8 @@ _UI_EXTERN int uiOpenTypeFeaturesGet(uiOpenTypeFeatures *otf, char a, char b, ch
_UI_EXTERN void uiOpenTypeFeaturesForEach(const uiOpenTypeFeatures *otf, uiOpenTypeFeaturesForEachFunc f, void *data);
// uiOpenTypeFeaturesEqual() returns nonzero if a is equal to b.
// a is defined as equal to b if and only if both
// - contain the same tags, without any extras or missing tags
// either way, and
// - have each tag have the same values
// TODO what if either or both are NULL?
// a is defined as equal to b if and only if both have exactly the same
// tags with exactly the same values, or if both are NULL.
_UI_EXTERN int uiOpenTypeFeaturesEqual(const uiOpenTypeFeatures *a, const uiOpenTypeFeatures *b);
typedef struct uiAttributeSpec uiAttributeSpec;

View File

@ -154,7 +154,7 @@ static uiForEach processAttribute(uiAttributedString *s, uiAttributeSpec *spec,
}
break;
case uiAttributeFeatures:
// TODO handle NULLs properly on all platforms
// TODO make sure NULLs are handled properly on all platforms in this part of the code
featurestr = otfToPangoCSSString(spec->Features);
addattr(p, start, end,
FUTURE_pango_attr_font_features_new(featurestr));

View File

@ -133,6 +133,11 @@ int uiOpenTypeFeaturesEqual(const uiOpenTypeFeatures *a, const uiOpenTypeFeature
guint i;
int equal = 0;
if (a == NULL && b == NULL)
return 1;
if (a == NULL || b == NULL)
return 0;
ak = copySortedKeys(a->tags);
bk = copySortedKeys(b->tags);

View File

@ -174,6 +174,7 @@ static uiForEach processAttribute(uiAttributedString *s, uiAttributeSpec *spec,
}
break;
case uiAttributeFeatures:
// TODO make sure this behaves properly if spec->Features is NULL
dt = otfToDirectWrite(spec->Features);
hr = p->layout->SetTypography(dt, range);
if (hr != S_OK)

View File

@ -79,6 +79,10 @@ void uiOpenTypeFeaturesForEach(const uiOpenTypeFeatures *otf, uiOpenTypeFeatures
int uiOpenTypeFeaturesEqual(const uiOpenTypeFeatures *a, const uiOpenTypeFeatures *b)
{
if (a == NULL && b == NULL)
return 1;
if (a == NULL || b == NULL)
return 0;
// TODO make sure this is correct
return *(a->tags) == *(b->tags);
}