From d63a5b23b1725bd53504f952eca1cd887b685773 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Fri, 9 Jun 2017 19:59:48 -0400 Subject: [PATCH] Handled uiOpenTypeFeatures NULL equality. This only added more TODOs elsewhere :| --- darwin/attrstr.m | 8 +------- darwin/opentype.m | 4 ++++ ui_attrstr.h | 7 ++----- unix/attrstr.c | 2 +- unix/opentype.c | 5 +++++ windows/attrstr.cpp | 1 + windows/opentype.cpp | 4 ++++ 7 files changed, 18 insertions(+), 13 deletions(-) diff --git a/darwin/attrstr.m b/darwin/attrstr.m index c3b8b0b3..4d166fb0 100644 --- a/darwin/attrstr.m +++ b/darwin/attrstr.m @@ -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; diff --git a/darwin/opentype.m b/darwin/opentype.m index 24f35f63..46bdaf19 100644 --- a/darwin/opentype.m +++ b/darwin/opentype.m @@ -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]; } diff --git a/ui_attrstr.h b/ui_attrstr.h index c7ab225c..b39b39a2 100644 --- a/ui_attrstr.h +++ b/ui_attrstr.h @@ -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; diff --git a/unix/attrstr.c b/unix/attrstr.c index 7dc83a6e..4d384daf 100644 --- a/unix/attrstr.c +++ b/unix/attrstr.c @@ -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)); diff --git a/unix/opentype.c b/unix/opentype.c index 9b90d0ba..79b1d93a 100644 --- a/unix/opentype.c +++ b/unix/opentype.c @@ -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); diff --git a/windows/attrstr.cpp b/windows/attrstr.cpp index 7bcd5e53..9dceaea6 100644 --- a/windows/attrstr.cpp +++ b/windows/attrstr.cpp @@ -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) diff --git a/windows/opentype.cpp b/windows/opentype.cpp index 21833e2c..89b5913c 100644 --- a/windows/opentype.cpp +++ b/windows/opentype.cpp @@ -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); }